Python Compiler from Turedo to Oritatami

root / python

Turedo to oritatami compiler: Source files

The source files

The demo file compute_examples.py is the python demo file to be executed using the command

python3 compute_examples.py

to produce the .os files for some examples of Turedo found in the turedo_examples.py file.

The source files are:

  • oritatami_class.py: class definition of an OritatamiSystem object
  • turedo.py: class definition of a Turedo object
  • turedo_examples.py: define some Turedo examples used by the demonstration program compute_examples.py
  • turedo2oritatami.py: compiler from a Turedo object to an OritatamiSystem object
  • turedo2oritatami_beadtypes.py: definition of the bead types used in the oritatami system simulating any turedo
  • turedo2oritatami_modules.py: class definitions of the different oritatami modules used by the Turedo-to-Oritatami system compiler
  • turedo2oritatami_speedbump.py: class definition of the speedbump oritatami module used by the Turedo-to-Oritatami system compiler

Running examples

Run the program compute_examples.py to produce the .os files from some Turedo examples with various densities:

python3 compute_examples.py

This will produce various .os files, one for each Turedo and density declared in the file.

The .os files must then be executed by the iOS program:

Simple Oritatami Simulator 1.2+ [ direct free download link on the iOS app store ]

in any iPad or iOS simulator for running.

How to build a Turedo

In order to build your own Turedo, you need to define using the Turedoclass in turedo.py by passing the arguments:

  • q: the number of state bits
  • bit_weigths: an array of 6 arrays of q integers which are the weights for each of the q bits on the 6 sides NW, SW, S, SE, NE and N.
  • transition_function: a function that takes two arguments (i,s) which returns the state (as an integer) to be written on side i when the total sum of the bits read is s
  • transition_function: a TuredoTransitionFunction object defined by 4 parameters:
  • q: the number of bits per state
  • sum_of_bit_weights: the total sum of the bit weights
  • state_function: a function that takes two arguments (i,s) which returns the state (as an integer) to be written on side i when the total sum of the bits read is s
  • exit_function: a function that takes one argument s which returns the side number (as an integer: 0:NW, 1:SW, 2:S, 3:SE, 4:NE) to exit from when the total sum of the bits read is s
  • seed_path: a possibily empty array containing a list of pairs of integers (i,d) where i is a state to be writen in the current cell and d is the direction to the next seed cell (encoded as an integer: 0:NW, 1:SW, 2:S, 3:SE, 4:NE, assuming that N is the entry point).
  • number_of_steps: the number of steps of turedos to be simulated

Refer to turedo_examples.py for examples.

How to compile a Turedo

Once you a have built a Turedo turedo, just call the function OritatamiSystem_for(turedo, density) to obtain an OritatamiSystem object simulating the turedo. The density parameter is an integer which extends the macrocell side to accomodate a hexagon which increases the macrocell density (the hexagon is not filled for performance).

Refer to the compute_examples.py file for an example.

Examples of Turedo

The file turedo_examples.py defines some Turedo (beware that some of them generate huge oritatami systems that require a lot of time to process in the oritatami simulator):

  • Right_hand(count, extra_bits): creates a Turedo that applies the right hand algorithm to explore the plane. count is the number of steps to be simulated. For this algorithm 1 bit is enough, extra_bits is an integer that creates an internal state in 0..2^(extra_bits-1) that is incremented at each step modulo 2^(extra_bits-1). Here is an example of execution with extra_bits=2:
Turedo Righ_hand(extra_bits=2)

Turedo Righ_hand(extra_bits=2)

Oritatami simulation of Turedo Righ_hand(extra_bits=2)

Oritatami simulation of Turedo Righ_hand(extra_bits=2)

  • Bouncing_right_hand(count, extra_bits): creates a Turedo that applies the bouncing right hand algorithm to explore the plane where. count is the number of steps to be simulated. For this algorithm 1 bit is enough, extra_bits is an integer that creates an internal state in 0..2^(extra_bits-1) that is incremented at each step modulo 2^(extra_bits-1). Here is an example of execution with extra_bits=2:
Bouncing_righ_hand(extra_bits=2)

Bouncing_righ_hand(extra_bits=2)

Oritatami simulation of Turedo Bouncing_righ_hand(extra_bits=2)

Oritatami simulation of Turedo Bouncing_righ_hand(extra_bits=2)

  • Sierpinski_2_bits(count): creates a Turedo that runs the Sierpinski triangle cellular automata. Because the bit weights are exponentially increasing, beware that the resulting oritatami is huge and that the .os file will be very slow to load and run. count is the number of steps to be simulated:
The Turedo Sierpinski_2_bits()

The Turedo Sierpinski_2_bits()

Oritatami simulation of Turedo Sierpinski_2_bits()

Oritatami simulation of Turedo Sierpinski_2_bits()

  • Sierpinski_bit_sum_8(count): creates a Turedo that runs the Sierpinski triangle cellular automata with a clever encoding of the state into bits and bit weight so that the sum of bit weight never exceed 8. count is the number of steps to be simulated:
Turedo Sierpinski_bit_sum_8()

Turedo Sierpinski_bit_sum_8()

Oritatami simulation of Turedo Sierpinski_bit_sum_8()

Oritatami simulation of Turedo Sierpinski_bit_sum_8()

Increasing the macrocell density

We increase the macrocell density by extending its edges to fit an filled hexagon at its core (the hexagon is not filled in the .os file for performance):

Oritatami simulation of Turedo Bouncing_righ_hand(extra_bits=2)() with density extension 10

Oritatami simulation of Turedo Bouncing_righ_hand(extra_bits=2)() with density extension 10

Oritatami simulation of Turedo Bouncing_righ_hand(extra_bits=2)() with density extension 50

Oritatami simulation of Turedo Bouncing_righ_hand(extra_bits=2)() with density extension 50

Oritatami simulation of Turedo Bouncing_righ_hand(extra_bits=2)() with density extension 100

Oritatami simulation of Turedo Bouncing_righ_hand(extra_bits=2)() with density extension 100

Oritatami simulation of Turedo Bouncing_righ_hand(extra_bits=2)() with density extension 200

Oritatami simulation of Turedo Bouncing_righ_hand(extra_bits=2)() with density extension 200