Turing Machine Scripts?

Anyone have any clear examples of Turing Machine scripts? Preferably in Lua? :slight_smile:

1 Like

That javascript implementation isn’t a good example, i’d just throw that away… The Hemispheres code is pretty straightforward, would be a good way to learn some lua and C, start by trying to decipher what each function does on it’s own… There are a couple variables you start with, reg, length, and fav, they are set up with defaults if they don’t exist in a saved state in the Init() function.

Take a look at bitwise operations in C to grok what they’re doing with the bits that are used to create the output.

Functions are fairly straightforward, a function takes parameters, and returns a value. Post questions as you run into them here and I can try to help.

1 Like

I think it might help to think of it in functional blocks, or if you have a lot of modules you can probably patch one up from scratch! Sorry if this is not what you were after, but it is a pleasant way to spend my coffee break this morning :laughing:

“Turing Machine” is a misnomer, btw, so wikipedia is not going to help you there :slight_smile:

The TM’s core is an analog shift register (ASR). This is basically just a ring of sample & hold (S&H) circuits in which each S&H samples the output of the previous S&H. :elephant::elephant::elephant: The sampling occurs at a clock tick or trigger. Let’s say there are 8 S&H, making 8 steps. So whatever the initial value of S&H #1, it will come around again in 8 clock ticks (very much like a bucket brigade delay!).

Let’s say the TM is tapped to give you the output from S&H #1. Where do new values go in? S&H #1 either samples the value of S&H #8, or it sample a random value from a noise circuit. A voltage-controlled switch picks between those two sources. That’s where your TM “decides” whether to introduce deviations to the stored pattern.

This switch has a voltage threshold: above the threshold flips it to the noise input, below the threshold flips it to S&H #8. Let’s say this threshold is 0V. If you hook the switch to a bipolar noise source (or more likely a noise source feeding a S&H), you will have a 50% chance of switching. That probability can be adjusted by biasing the noise voltage up or down. If you lower it enough, it will never cross the threshold and the sampling will always be from S&H #8’s stored value. If you raise it enough, you will get a fresh random value into your ASR at every clock tick.

2 Likes

@forrest I’m afraid of bitwise operators. I guess it is time to foritfy and learn. Thank you for offering to help. I’ll post some stuff back here for sure.

@desolationjones Thank you for this description!! And glad to have been a part of your coffee break. :slight_smile:

1 Like

20 characters of I believe in you :v:

Update: Yeah I didn’t look at this closely enough, it’s a pretty simple set of operations as desolationjones has outlined. You can write new values to a table using table.insert

-- set up some random values to start
tm = {}

function makeRandomTable( t, l )
    for i=1,l do
        t[i] = math.random (1, 256)
    end
end

makeRandomTable(tm, 16)

function rotate( table, l )
    for i = 1, l do
        table.insert( t, 1, table.remove( t, #t ) )
    end
end

rotate(tm, 1) 
-- rotate it once, put this in a clock loop to rotate through
-- then set up a function to check if you want to randomize, if so, table.insert a new value using math.random
1 Like
-- 42921
-- 1001010111100101
-- 85843
-- 11001010111100101
-- 171686
-- 011001010111100101
-- 343373
-- 1011001010111100101
-- 686746
-- 01011001010111100101
-- 1373492
-- 001011001010111100101
-- 2746985
-- 1001011001010111100101
-- 5493971
-- 11001011001010111100101

Progress so far!

Edit: I need to cap the length of the output at 16 right?

2 Likes

So the code you shared here makes perfect sense to me and is how I thought ASR’s worked. I thought there was some arcane but necessary reason to do all the bitwise stuff I just shared. Is that essentially just doing the same thing with primitive operations and binary instead of tables?

Well since you’re not constrained to binary as you might be in a simpler system, it’s essentially the same thing.

The Grayscale permutation manual pages 5&6 detail it pretty well, they even provide the equation used to derive the CV output value : (8-bit byte / 256) * LEVEL = SEQ where LEVEL is the level knob, or an attenuator basically… It’s just another way to arrive at a random number output per step… One nice thing about doing this in code is that you could pseudo-randomize it by allowing choice from a set of quantized values, essentially adding a quantizer to your TM without much fuss, just set up some tables of values to choose from and randomly select them that way.

2 Likes

AMAZING! Thank you for sharing this doc. Very helpful.

Yeah all I need is truth-y and false-y values in my register and it’s only 16 steps/bits. So I’ll have a chance attribute which when is set to zero it will freeze the sequence and when it is set to 100% will always invert.

Thank you so much for your hlep.

2 Likes