assoc-list/wolfram [ Classes ]
[ Top ] [ assoc-list ] [ Classes ]
NAME
rhythm File: wolfram.lsp Class Hierarchy: named-object -> linked-named-object -> sclist -> circular-sclist -> assoc-list -> wolfram Version: 1.1.0 Project: slippery chicken (algorithmic composition) Purpose: Implementation of the wolfram class for one-dimensional binary cellular automata introduced by Stephen Wolfram in 1983. The rule number is the decimal representation of the binary number indicated by the eight transition rules (i.e. the results given the triplet test cases; see the rules slot below). Author: Michael Edwards: m@michael-edwards.org Creation date: 7th June 2017, Edinburgh $$ Last modified: 10:56:40 Sat Aug 24 2024 CEST SVN ID: $Id: wolfram.lsp 6210 2017-04-07 11:42:29Z medward2 $
wolfram/defwolfram [ Methods ]
[ Top ] [ wolfram ] [ Methods ]
DATE
June 6th 2017, Edinburgh
DESCRIPTION
Define your own Wolfram function to create an object with the flavour in the rules passed. See below for several examples. In addition, the name of the newly created function will be added to an internal list of all functions defined by this macro, so that (try-all) can be called (see below).
ARGUMENTS
- the name of the function you're defining (symbol) - the list of rules
OPTIONAL ARGUMENTS
- the default width (integer>0) for the Wolfram object that will be created - the default initial-state: 1 or 0.
RETURN VALUE
the name of the function (symbol), just as with defun.
SYNOPSIS
(defmacro defwolfram (fun rules &optional (w 100) (is 0))
wolfram/generate [ Methods ]
[ Top ] [ wolfram ] [ Methods ]
DATE
June 6th 2017, Edinburgh
DESCRIPTION
Generate the cellular automata rows using the given rules. N.B. Each time this method is called, the results (data slot) of the previous calls are deleted. At the beginning, we hava a row. This is a list of length <width>, with all elements being <initial-state>. However, we set the middle element to the <start> argument given to this method. We then loop through the elements of the list and make a triplet out of the element to the left of the current element (or <initial-state> when we begin the loop), the current element, and the element to the right of current (or, again, <initial-state> if we're at the last element of the row). The we loop through the <rules> and when the current triplet matches the rule we return the 0 or 1 associated with the triplet in the rule (i.e. the second element of the matching rule). so e.g. we start with: (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) set the middle element to default of 1 (first generation) (0 0 0 0 0 0 0 1 0 0 0 0 0 0 0) then proceed with the loop. Using e.g. the r30 rules: (((1 1 1) 0) ((1 1 0) 0) ((1 0 1) 0) ((1 0 0) 1) ((0 1 1) 1) ((0 1 0) 1) ((0 0 1) 1) ((0 0 0) 0)) all those triplet 0s return 0 (because of the last rule) but when we get to the 1 we first of all have (0 0 1) which returns 1, then (0 1 0) which also returns 1, and finally--before we only have 0 triplets again--(1 0 0), also returning 1. So we end up with this as the second generation: (0 0 0 0 0 0 1 1 1 0 0 0 0 0 0) (0 0 0 0 0 1 1 0 0 1 0 0 0 0 0)
ARGUMENTS
- the wolfram object - the number of generations (rows) to generate
OPTIONAL ARGUMENTS
<start> is the value of the middle cell of the first row (or just to the left of middle, if width is an even number). All cells to the left and right of it will be in <initial-state>. This should be 0 or 1 only.
RETURN VALUE
The data slot, which will be the rows in the form of a list of named-objects containing the ID (starting from 1) and the list of cell values.
SYNOPSIS
(defmethod generate ((w wolfram) generations &optional (start 1))
wolfram/make-wolfram-r110 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 7th 2017, Edinburgh.
DESCRIPTION
#b01101110 = 110 This is the one Wolfram suggests might be Turing complete. This was proved in 2000. "Rule 110, like the Game of Life, exhibits what Wolfram calls "Class 4 behavior", which is neither completely stable nor completely chaotic. Localized structures appear and interact in various complicated-looking ways" (https://en.wikipedia.org/wiki/Rule_110)
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
so this one only goes up to column 7 when called with width of 12: . .. ... .. . ..... .. . ... .. . . ... ..... . . ... . .. . . ..... ... . . . .. ... ... . ... . then the last 2 lines repeat but called with width of 60: . .. ... .. . ..... .. . ... .. .. . ... ....... . .. ... ... .. . .. . ..... ..... .. . .. . ... .. ... .... . ... .. . .. ..... . ........ .. ... .. .... .. . ... .. . ..... .. . ... .... . ..... .. ... . .. .. . ..... . .. ... ... .. .. ........ . .. . ...... .. ... ....... . ... .. . .. . .... . ..... ... .. .. ... .. . .. . ... ... .. . ... .. ..... .. ... ...... .. . ... .. . ..... ... ........ . ... .... ... . .. ... . . .. . .. ... ... .. . ...... .. ..... . .. . ..... . ...... ........ .. . . .. . .. . ... .. . ... .. ... .. .. . ... . .. . ..... . .......... . ...... .. ... .. ... . .... .. . ... .. . . .. . ..... .. . ..... . ... .... ...... .. . . .. ... . .. . ... .. ...... . .. ... .. .. . ... . ........ . ... ....... . . .. ... .. . .. ... . ... .. ......... .. . . .. . ..... . ..... ...... .. . .. .. . . . ... .. ... ... .. . .. .. . ... .. ... . ... . .......... . ..... ..... . . .. ... .. ... ... .... .. . ... .. . .. . . . ....... . ..... ..... . .. .. ..... ... . |# (defwolfram make-wolfram-r110 '(((1 1 1) 0) ((1 1 0) 1) ((1 0 1) 1) ((1 0 0) 0) ((0 1 1) 1) ((0 1 0) 1) ((0 0 1) 1) ((0 0 0) 0)))
wolfram/make-wolfram-r126 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 6th 2017, Edinburgh.
DESCRIPTION
#b01111110 = 126
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
width: 12, initial-state: 0 . ... .. .. ....... .. .. .... .... .. .. .. . ............ . . .. .. ... ... . .. .. . ..... ..... . .... . .. .. .. .. ............ using 1, the following repeats but not forever ............ . . .. .. .. .. .... .... .. .. . ........ . ... ... .. .. ..... ..... .... . .. .. .
SYNOPSIS
(defwolfram make-wolfram-r126 '(((1 1 1) 0) ((1 1 0) 1) ((1 0 1) 1) ((1 0 0) 1) ((0 1 1) 1) ((0 1 0) 1) ((0 0 1) 1) ((0 0 0) 0)))
wolfram/make-wolfram-r150 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 7th 2017, Edinburgh.
DESCRIPTION
#b10010110 = 150
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
width: 12, initial-state: 0 non-repeating but lovely patterns . ... . . . .. . .. . . . ... ... ... . . . . . .. ... ... . . . .. ... ... . . . . .. . .. ... . . . .. ... ... . . . . .. . . .. . . . ... .. .. . . . . .. ... . . . . .. ... .. .. . ... . . . .. . .. . . . .. ... ... . . . ... .. .. . . .. .. . . .. ... . . . . .. . . .. . . . . .. .. .. ... . ... . . .. .. . ... . . . .. . .. . . . ... ... ...
SYNOPSIS
(defwolfram make-wolfram-r150 '(((1 1 1) 1) ((1 1 0) 0) ((1 0 1) 0) ((1 0 0) 1) ((0 1 1) 0) ((0 1 0) 1) ((0 0 1) 1) ((0 0 0) 0)))
wolfram/make-wolfram-r151 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 7th 2017, Edinburgh.
DESCRIPTION
#b10010111 = 151
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
. ............ .......... . ........ . . ...... . ... .... ... . .. . ..... ..... ... .. ... . . . . . ........ . . ...... . then the last 7 lines repeat |# (defwolfram make-wolfram-r151 '(((1 1 1) 1) ((1 1 0) 0) ((1 0 1) 0) ((1 0 0) 1) ((0 1 1) 0) ((0 1 0) 1) ((0 0 1) 1) ((0 0 0) 1)))
wolfram/make-wolfram-r159 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 7th 2017, Edinburgh.
DESCRIPTION
#b10011111 = 159
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
. ............ ........... .......... . ......... . ........ ... ....... .. ...... ... . ..... .. . .... ... ... ... .. .. .. ... ... . . .. .. . then the last 4 lines repeat |# (defwolfram make-wolfram-r159 '(((1 1 1) 1) ((1 1 0) 0) ((1 0 1) 0) ((1 0 0) 1) ((0 1 1) 1) ((0 1 0) 1) ((0 0 1) 1) ((0 0 0) 1)))
wolfram/make-wolfram-r190 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 6th 2017, Edinburgh.
DESCRIPTION
#b10111110 = 190
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
width: 12, initial-state: 0 . ... ... . ... ... ... ... . ... ... ... ... ... ... .. ... ... . . ... ... .. .... ... .. ... ... .. . .. ... .. .. . ... .. .. .... .. .. . ... .. .. .. .. .. .. .. . .. .. .. . then last three rows repeat
SYNOPSIS
(defwolfram make-wolfram-r190 '(((1 1 1) 1) ((1 1 0) 0) ((1 0 1) 1) ((1 0 0) 1) ((0 1 1) 1) ((0 1 0) 1) ((0 0 1) 1) ((0 0 0) 0)))
wolfram/make-wolfram-r25 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 6th 2017, Edinburgh.
DESCRIPTION
#b00011001 = 25
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
width: 12, initial-state: 0 . ..... ..... . . . ... .... . ... . . . ... . ... . ... . .. . ... . ... . . . . ... ... . .. .. . . . . ... . .. . ... . . . .. .. . . . . ... . . ... ... . . .. . . . . . ... . . . ... . . . .. ... . . . ... . . . ... . . . .. then last four rows repeat also very nice starting with 0 instead of 1 (no obvious repeats): (generate w 100 0) ............ . ........... . .......... . . ......... .. . . ........ .. . . ....... .. . . . ...... .. . .. . ..... . .. . .. . .... . .. . .. . ... . . .. . .. . .. .. . .. . . .. . . .. . .. . .. . .. .. . . . . ... . .. . . .. . . .. . .. . . .. . . . . ... .... . .. . . . . .... . .. . ...
SYNOPSIS
(defwolfram make-wolfram-r25 '(((1 1 1) 0) ((1 1 0) 0) ((1 0 1) 0) ((1 0 0) 1) ((0 1 1) 1) ((0 1 0) 0) ((0 0 1) 0) ((0 0 0) 1)))
wolfram/make-wolfram-r30 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 6th 2017, Edinburgh.
DESCRIPTION
This is the default Wolfgram object: #b00011110 = 30
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
;; so width: 12, initial-state: 0 (let ((w (make-wolfram-r30 12 0))) (generate w 100) (print-matrix w :row-number nil :off "." :on 'X) (print-matrix w :row-number nil)) . ... .. . .. .... .. . . .. .... ... .. . . . .... ... . . ... . . .. .. ... . . . ... . .... . . . . ..... . .. .. . . ... . . . . .. . . .. .. . . . . . .. . . ....... . . . . . . .. .. . . . . .. . . . .... . . . . . . . . . .. .. . . . . ... . . . . . . . . . . .... . . . . . . . . . .. . . . . . . . . . . . .. then last two rows repeat
SYNOPSIS
(defwolfram make-wolfram-r30 '(((1 1 1) 0) ((1 1 0) 0) ((1 0 1) 0) ((1 0 0) 1) ((0 1 1) 1) ((0 1 0) 1) ((0 0 1) 1) ((0 0 0) 0)))
wolfram/make-wolfram-r62 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 7th 2017, Edinburgh.
DESCRIPTION
#b00111110 = 62
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
. ... .. . .. .... .. .. . .. .. . ... .. .. .... . .. .. . ... .. . ... . .. .... .... .. . . .. . ... .. .. .... . .. .. . ... .. . ... . .. .... then the last 6 lines repeat |# (defwolfram make-wolfram-r62 '(((1 1 1) 0) ((1 1 0) 0) ((1 0 1) 1) ((1 0 0) 1) ((0 1 1) 1) ((0 1 0) 1) ((0 0 1) 1) ((0 0 0) 0)))
wolfram/make-wolfram-r73 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 8th 2017, Edinburgh.
DESCRIPTION
#b01001001 = 73 Suggested by Orestis Papadopoulos
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
. ..... .... . . . . . . . ........ . . . . .... ... . . . . . . ...... ..... . . . . .. . . .. . then the last 2 lines repeat |# (defwolfram make-wolfram-r73 '(((1 1 1) 0) ((1 1 0) 1) ((1 0 1) 0) ((1 0 0) 0) ((0 1 1) 1) ((0 1 0) 0) ((0 0 1) 0) ((0 0 0) 1)))
wolfram/make-wolfram-r82 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 6th 2017, Edinburgh.
DESCRIPTION
#b01010010 = 82
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
width: 12, initial-state: 0 non-repeating but lovely patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SYNOPSIS
(defwolfram make-wolfram-r82 '(((1 1 1) 0) ((1 1 0) 1) ((1 0 1) 0) ((1 0 0) 1) ((0 1 1) 0) ((0 1 0) 0) ((0 0 1) 1) ((0 0 0) 0)))
wolfram/make-wolfram-r93 [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 7th 2017, Edinburgh.
DESCRIPTION
#b01011101 = 93
ARGUMENTS
none required
OPTIONAL ARGUMENTS
- the width of a row. Default = 100. - the initial state of the object. Default = 0.
RETURN VALUE
the function name as a symbol but when called a wolfram object with the given rules.
EXAMPLE
. ..... ...... . ... . ... . .... . . ..... ... ... .. . . . ... ...... ... ... . . ... .... . ... ... ... . ... .. . . ... ........ . ... . ... ...... . . ... ... ... .... . . . ... ..... ... .. . . . ........ . ... ... . ...... . . ... ..... . .... . . ... ..... . . .. . ... ........ . . . ..... ...... . . . ..... . .... . ... . ..... . . .. . ..... ...... . . . ..... . then the last 5 lines repeat |# (defwolfram make-wolfram-r93 '(((1 1 1) 0) ((1 1 0) 0) ((1 0 1) 0) ((1 0 0) 1) ((0 1 1) 1) ((0 1 0) 1) ((0 0 1) 0) ((0 0 0) 1)))
wolfram/print-matrix [ Methods ]
[ Top ] [ wolfram ] [ Methods ]
DATE
June 6th 2017, Edinburgh
DESCRIPTION
Print the state of the cells to the terminal or another open stream . On and off could theoretically be any object but of course single characters are clearest. See the defwolfram definitions below for examples.
ARGUMENTS
- the wolfram object
OPTIONAL ARGUMENTS
keyword arguments: - :stream. The stream to print to. Default t which means it prints to the terminal. - :on. what to print when a cell has the value 1. Default: the . character - :off. what to print when a cell has the value 0. Default: space - :row-number: whether to print row numbers. Default t.
RETURN VALUE
T
SYNOPSIS
(defmethod print-matrix ((w wolfram) &key (stream t) (on #\.) (off #\ ) (row-number nil))
wolfram/try-all [ Functions ]
[ Top ] [ wolfram ] [ Functions ]
DATE
June 10th 2017, Edinburgh
DESCRIPTION
Try all of the Wolfram rules defined via defwolfram. An instance of each rule set defined will be created, the rows will be generated, and print-matrix will be called. This allows you to see and compare the results of each rule set using the same parameters.
ARGUMENTS
none required
OPTIONAL ARGUMENTS
keyword arguments: :width. The width slot (number of columns) for the Wolfram objects. Any positive ingeger. Default = 100. :initial-state. The initial-state (i.e. default) slot for the Wolfram objects. 0 or 1. Default = 0. :start. The value of the middle cell of the first row. See generate method for more details. 0 or 1. Default = 1. :generations. The number of rows to generate. Any positive integer. Default = 30. :stream, :on, :off, :row-number: see print-matrix method.
RETURN VALUE
T
SYNOPSIS
(defun try-all (&key (width 100) (initial-state 0) (start 1) (generations 30) (stream t) (on #\.) (off #\ ) (row-number nil))