Content
    Boolean Circuits

Models of Computation

Boolean Circuits

  • AND/OR/NOT gates
  • Gate: function
  • Inputs: arguments to function
  • In-/Outputs: wires
  • Circuits: combination of gates
  • Truth table: all possible combination (look-up table)

XOR

  • Parity: odd/even
    • 0: even
    • 1: odd
    • 0 is even number, 1 is odd number
  • works with more than 2 inputs
XYZXOR
0000
0011
0101
0110
1001
1010
1100
1111
  • Cost of circuit: number of
    • AND gates and
    • OR gates
    • usually NOT gates are not counted (they are too simple)

Truth table:

  • for nn inputs: 2n2^n combinations

Number of functions:

  • for nn inputs: 22n2^{2^n} functions (circuits)

General of XOR:

  • for nn inputs 2n1+12^{n-1}+1 gates needed

Finite State Machines (FSM)

  • Also called Finite State Automaton (FSA)

See also Tutorialspoint

Can be represented as a 5-touple (Q,Σ,δ,q0,F)(Q, \Sigma, \delta, q_0, F):

  • QQ: finite set of states
  • Σ\Sigma: alphabet (finite set of symbols)
  • δ\delta: transition function
  • q0q_0: initial state (q0Qq_0 \in Q)
  • FF: set of final states (FQF \subseteq Q)

Deterministic / Non-Deterministic FSM

  • Deterministic

    • For each arriving event it’s clear what the next state is
  • Non-deterministic

    • For some (or all) events the next state can be more than one (it’s not clear to which state the machine will change)
  • Any non-deterministic FSM can be turned into a deterministic FSM

Acceptor (Recognizer)

  • Calculates a Boolean function
  • All states are either accepting or rejecting for a given input
  • In graphical notation the accepting states have a double circle
  • Non-deterministic Acceptor
    • accepts if there is any way to accept
    • methodically try all possibilities
    • ‘Parallel World’ - try all possibilities simultaneously in separate copies of the machine (for complexity theory)

Classifier

  • Has more than two final states
  • gives single output when it terminates

Transducer

  • Produces outputs based on current input and on previous state
  • 2 different types
    • Mealy Machine: output depends only on current state
    • Moore Machine: output depends on current state and current input
    • They can be transformed into each other

Register Machines

  • A register machine has multiple registers that store positive integers
  • There are only two possible operations on these registers
    1. incrementing (+1+1)
    2. decrementing (1-1)
    • Decrementing a register that holds 00 fails
  • There are other (slightly different) definitions of register machines that allow different operations (e.g checking for 00)
  • Register Machines can be graphically represented like FSMs or as a simple list of instructions (programming language)

Example of list of instructions for a Register Machine:

ActionNext InstructionAlternative Instruction (if actual instruction fails)
1.x-24
2.y+3-
3.x-18
4.y-56
5.x+4-
6.x-75
7.x-9HALT
8.y-93
9.x+10-
10.x+11-
11.x+8-
  • Register Machines and Turing Machines can simulate each other in polynomial time
  • For each Register Machine with more than 2 registers (NN) there is an equivalent Register Machine with only 2 registers
    • The NN registers need to be encoded
  • Whenever a loop ends (in a 2 Register Machine)
    • one register is 00
    • in the other register is some information available

Fractran

See also Wikipedia:Fractran

Example PRIMEGAME:

1791,7885,1951,2338,2933,7729,9523,7719,117,1113,1311,152,17,551{\frac {17}{91}},{\frac {78}{85}},{\frac {19}{51}},{\frac {23}{38}},{\frac {29}{33}},{\frac {77}{29}},{\frac {95}{23}},{\frac {77}{19}},{\frac {1}{17}},{\frac {11}{13}},{\frac {13}{11}},{\frac {15}{2}},{\frac {1}{7}},{\frac {55}{1}}

State/Memory: an Integer

Computation: multiply by first fraction that yields an integer

Start with 22: calculate primes.

Implementation in racket:

Fractran is similar to stack machines.

Tilings

See also Wikipedia:Wang tile

  • Graphical model of computation
  • The edges of each tile have special form/color
  • Tiles can be arranged on plain so that edges match

Tiles as Turing Machine

  • Tiled plain can be seen as Turing Machine over time
    • one dimension (horizontal, x) is tape
    • other dimension (vertical, y) is time
    • so each row shows the tape at a given time

3 kind of tiles needed

Kind of TileUse
TAPEOne for each symbol in the alphabet
ACTIONOne tile for each transition of the TM
PREPARETwo for each (symbol, state) pair
  • Seed row: initial configuration
  • We can tile the floor with the tiles if TM halts

Cellular Automata

  • Inspired by natural cells
  • World is grid of cells
  • Cells have state (e.g. dead/alive)
  • Next state of a cell is calculated by
    • actual state of the cell
    • actual state of the neighbor cells
  • All cells work with same rules
  • Time is discrete (round based)
  • Often used in physics
  • Good model for unreliability
  • parallel, local comuptation
  • can model a Turing Machine

The Model

  • NN-dimensional array of cells (infinitely large)
  • Finite number of states
    • each cell is in some state
  • At each time step, each cell updates its state based on
    • it’s own state
    • the states of its neighbors
  • Variations:
    • number of dimensions
    • neighborhood size (and geometry)
    • asynchronouns
    • error-prone (add randomness)
    • finite size
    • grid type

Variants

Lambda Calculus

  • Meta-Mathematics
  • Turing Machines simulate a person that calculate (State: Mind, Tape: Paper)
  • Lambda Calculus: about functions

Syntax

Traditional Syntax:

f(x)=exsin(x)x+3f(x) = \frac{e^x - sin(x)}{x+3}

Lambda Syntax:

λx.exsin(x)x+3\lambda x. \frac{e^x - sin(x)}{x+3}
  • Functions in lambda calculus don’t have names

    • Just put the function completely, where it is used
    • Anonymous functions
  • Functions: ‘Plugging in’ arguments

  • Functions return other functions (Currying)

For example:

((λxy.2x+y)2)3=(λy.4+y)3=4+3=7((\lambda xy. 2x + y) 2 ) 3 = (\lambda y. 4 + y) 3 = 4 + 3 = 7
  • Can get rid of
    • function names
    • multi-argument functions

Main Operations

  • β\beta-reduction: apply a function to an argument using substitution
    • Reduction is an optimistic term since the result of the β\beta-reduction can be bigger then the expression before
  • α\alpha-conversion: changing a functions ‘argument symbol’ (λx.xλy.y\lambda x.x \equiv \lambda y.y)
  • η\eta-conversion: λv.fvf\lambda v. f v \equiv f because (λv.fv)afa(\lambda v. f v) a \equiv f a

Church Numerals

  • Numbers can be encoded as functions
  • Arbitrary encoding of numbers suggested by church

Each number is a function that takes 2 arguments: ff and xx:

0:=λf.λx.x1:=λf.λx.fx2:=λf.λx.f(fx)3:=λf.λx.f(f(fx))n:=λf.λx.fnx\begin{align*} 0 :&= \lambda f.\lambda x. x\\ 1 :&= \lambda f.\lambda x. f x\\ 2 :&= \lambda f.\lambda x. f (f x)\\ 3 :&= \lambda f.\lambda x. f (f (f x))\\ \cdots \\ n :&= \lambda f.\lambda x. f^n x \end{align*}

The number nn is a function that takes a function ff as argument and applies it nn-times to the second argument xx

Example: (5inc)x(5 inc) x: apply function incinc 55-times to xx

Church Numerals

Lambda Calculus Expressions

  • Using just substitution step to calculate
    • seems complex, but only one operation needed: substitution
Variables
  • aa, bb, cc
  • representing functions
Function Application

(ab)(a b): aa applied to bb

Function Application

Function Creation

λa.aa\lambda a. aa

Function Creation

Evaluation

Evaluation

Example:

Evaluation Example

Examples
Increment
λkfx.f(kfx)\lambda k f x. f ( k f x)

Example:

increment 22

(λkfx.f(kfx))inc(λfx.f(fx))2=(λfx.f((λfx.f(fx))fx))=(λfx.f(f(fx)))\begin{align*} \underbrace{(\lambda k f x. f ( k f x))}_{inc}\underbrace{(\lambda f x. f ( f x))}_{2} &= \\ (\lambda f x. f ( (\lambda f x. f ( f x)) f x)) &= \\ (\lambda f x. f ( f ( f x))) \end{align*}

Increment

Addition

Addition

Multiplication

Multiplication

Boolean Logic

Boolean Logic

If-Then-Else

If Then Else

Pair

Pair

Shift Pair

Conclusion

  • No distinction between code and data: everything is code!
  • No structure is safe from substitution (safety issue)
  • Data has to be run, can’t be examined

Recursion

  • in λ\lambda-calculus a function can’t reference (call) itself since there are no names for functions

  • Tail-call recursion: in some cases the same stack frame can be reused for recursive functions

  • How can we build an infinite loop (recursion)?

This structure rebuilds itself infinitely:

Ω=(λw.ww)(λw.ww)\Omega = (\lambda w. w w) (\lambda w. w w)
Y-Combinator

See Wikipedia

and The Y Combinator (no, not that one).

Y=λf.(λx.f(x  x))(λx.f(x  x))Y = \lambda f. (\lambda x. f (x\; x))(\lambda x. f (x \;x))

Beta recursion gives:

Yg=λf.(λx.f(x  x))(λx.f(x  x))g=(λx.g(x  x))(λx.g(x  x))=g((λx.g(x  x))(λx.g(x  x)))=g(Y  g)\begin{align*} Y g &= \lambda f. (\lambda x. f (x\; x))(\lambda x. f (x\; x)) g \\ &= (\lambda x. g (x\; x)) (\lambda x. g (x\; x)) \\ &= g ((\lambda x. g (x\; x)) (\lambda x. g (x\; x))) \\ &= g (Y\; g) \end{align*}
  • Only way to do a loop if you don’t know in advance how many iterations the loop needs to be done
  • Functions can’t see their own structure
    • Needs to be provided as argument so the function can reproduce itself: ‘twin’-functions

Numbers

  • Numbers are an abstract concept
  • It’s only possible to manipulate representations of numbers

There Are a lot of different representations of numbers.

Each representation has it’s pros and cons.

Tag Systems

  • Tape with a starting string
  • Reading and deleting at the beginning (left)
  • Appending (writing) at the end (right)

2-Tag System

  1. reads 1 symbol at the beginning of the tape
  2. appends a string at the end of the type
    • appended string depends on read symbol
  3. removes 2 symbols at the beginning of the tape
Example: Test for odd/even number
  • Alphabet: Σ={C1,C2,C3}\Sigma = \{C_1, C_2,C_3\}

  • Rules:

    • C3ϵC_3 \rightarrow \epsilon
    • C1C2  OC_1 \rightarrow C_2 \; O
    • C2EC_2 \rightarrow E
  • ϵ\epsilon: empty word

  • OO: Odd

  • EE: Even

  • C1  C1  (C3)xC_1 \; C_1 \; (C_3)^x

  • axa^x: symbol a is repeated xx times

  • the given rules show if xx is odd or even

Example even:

C1C1C3C3C3C3C3C3C3C3C2OC3C3C2OC2OE\begin{align*} C_1 C_1 C_3 C_3 C_3 C_3 \rightarrow \\ C_3 C_3 C_3 C_3 C_2 O \rightarrow \\ C_3 C_3 C_2 O \rightarrow \\ C_2 O \rightarrow \\ E \end{align*}

Example odd:

C1C1C3C3C3C3C3C3C2OC3C2OO\begin{align*} C_1 C_1 C_3 C_3 C_3 \rightarrow \\ C_3 C_3 C_3 C_2 O \rightarrow \\ C_3 C_2 O \rightarrow \\ O \end{align*}
Example: Power of Two
2nnC1C1C2C4C5C2ϵC3C3C4C4C5C5C6\begin{align*} 2^n &\rightarrow n \\ C_1 &\rightarrow C_1 C_2 C_4 C_5 \\ C_2 &\rightarrow \epsilon \\ C_3 &\rightarrow C_3 \\ C_4 &\rightarrow C_4 C_5 \\ C_5 &\rightarrow C_6 \end{align*}

Starting with:

(C3)2nC1C1(C6)n(C_3)^{2n}C_1C_1 \rightarrow (C_6)^n

For n=2n=2:

C3C3C3C3C1C1C3C3C1C1C3C1C1C3C3C3C3C1C2C4C5C1C2C4C5C3C4C5C3C1C2C4C5C2C4C5C4C5C3C5C4C5C3C5C3C6C6C6\begin{align*} C_3 C_3 C_3 C_3 C_1 C_1 \rightarrow \\ C_3 C_3 C_1 C_1 C_3 \rightarrow \\ C_1 C_1 C_3 C_3 \rightarrow \\ C_3 C_3 C_1 C_2 C_4 C_5\rightarrow \\ C_1 C_2 C_4 C_5 C_3 \rightarrow \\ C_4 C_5 C_3 C_1 C_2 C_4 C_5 \rightarrow \\ C_2 C_4 C_5 C_4 C_5 C_3 \rightarrow \\ C_5 C_4 C_5 C_3 \rightarrow \\ C_5 C_3 C_6 \rightarrow \\ C_6 C_6 \end{align*}
Simulation of Turing Machines with Tag Systems

Some of the notes here are taken from ‘Understanding Computation’ by Tom Stuart.

  1. Tape uses only 2 characters: 00 and 11
    • 00 is the blank character
  2. Split the tape into two pieces
    • left part
      • character under the head
      • all characters left of the head
    • right part
      • all characters right of the head
  3. Interpret left part as binary number
  4. Interpret right part as binary number written backwards
  5. Encode those 2 numbers as string (suitable to be used for Tag System)
  6. Simple operations:
    • Simulate
      • reading from tape
      • writing to tape
      • moving the head
    • with simple operations
      • doubling / halfing
      • incrementing / decrementing
      • odd / even (parity) check
    • e.g
      • move head to right:
        • doubling left number
        • halving right number
      • reading from tape
        • check if left number is even/odd
      • writing
        • 11: incrementing number
        • 00: decrementing number
  7. Current state of simulated Turing machine represented by different encoding
    • e. g
      • State 1: use a, b, c
      • State 2: use d, e, f
  8. Convert each Turing Machine rule into a Tag Systems that rewrites the current string in the expected way
  9. Combine all the Tag Systems to make a large one the simulates every rule of the Turing Machine
Cyclic Tag Systems

This are simplified Tag Systems

  • The tape is allowed only to have 2 symbols 00 and 11
  • A string is only appended if a 11 is read
  • The rules for appending strings is ordered
  • The deletion number is 11

Algorithm:

In each round:

  • Read next rule in rule-set
  • Read next symbol on tape
    • if 11: append the string from the rule set to the tape
    • if 00: ignore the rule
  • Remove the last read symbol from the tape
  • Start from the beginning with reading the next rule

A Cyclic Tag System can simulate a normal Tag System. See ‘Understanding Computation’ by Tom Stuart on how to do that.

Diophantine Equations

See also Wikipedia:Diophantine equation

  • Polynomal equations
  • Only integer solutions are sought
  • Properties
    • no state
    • no dynamics
    • no time
    • no loops
    • no ‘IF’/‘THEN’
    • just equations which all must be true

How to compute?

  • Consider a space-time history
  • Solve it in the digits of a large number
  • Use equations to force it to be valid

Primitive Recursive Functions

  • Recursion can do a lot!
  • Functions are defined using itselves or other functions
  • Each function has 2 definition:
    1. Definition for argument 00
    2. General definition
FunctionNameDefinition (if n=0\text{if } n=0)Definition (if n=S(m)\text{if } n=S(m))
S(n)=n+1S(n) = n + 1Successorintrinsic/primitive-
A(n,a)=n+aA(n,a)=n+aAdditionaaS(A(m,a))S(A(m,a))
M(n,a)=naM(n,a)=n\cdot aMultiplication00A(a,M(m,a))A(a,M(m,a))
E(n,a)=anE(n,a)=a^nExponentiation11M(a,E(m,a))M(a,E(m,a))
V(n)=sign(n)V(n)=sign(n)Positivity0011
P(n)=n1P(n) = n-1Predecessor00mm
D(a,n)=anD(a,n) = a-nSubtractionaaP(D(n,m))P(D(n,m))
R(n,a)=nmodaR(n,a)=n \bmod aRemainder00M(S(R(m,a)),V(D(P(a),R(m,a))))M(S(R(m,a)),V(D(P(a),R(m,a))))
C(n,a)=i=2n+1amodiC(n,a)=\prod_{i=2}^{n+1} a \bmod i‘mod Product’00M(C(m,a),R(a,(S(S(m)))))M(C(m,a),R(a,(S(S(m)))))
Z(n)=1Z(n)=1 if prime ; 00 elsePrimality00V(M(m,(P(m),S(m))))V(M(m,(P(m),S(m))))
  • Infinite loops not possible
  • Can simulate a Turing Machine only for a given number of steps (weaker than TM’s)
    • Number of iterations of a loop need to be known from beginning
    • Infinite loops are not possible
  • Not considierd as universal system

Some Simple Models

Chemical Reaction Networks

  • Inspired by chemical reaction equations
ABCDB+CAA+DA+2EB+EB+D\begin{matrix} A & \rightarrow & B \\ C & \rightarrow & D \\ B + C & \rightarrow & A \\ A + D & \rightarrow & A + 2E\\ B + E & \rightarrow & B + D \end{matrix}
  • Nondeterministic: any reaction can happen at any time
  • Primitive Recursive Functions can always compute this in bounded time, even if answer is \infty.
  • Chemical Reaction Networks are not stronger than Primitive Recursive Functions.

Petri Nets

  • A lot of different form of Petri Nets
  • Components
    • Transition (edges)
    • Places (nodes)
    • Tokens (arcs) travel from transitions to places (or vice versa)
  • Nondeterministic
  • Similar to (and as powerful as) Chemical Transition Networks
  • Used to simulate concurrency in distributed systems (but not turing-complete)

Vector Addition Systems

  • Rules: Starting position and list of possible moves (like a knight in chess)
  • no coordinate ca go negative
  • N-dimensional is posible
ABCDEFG
-1100000
00-11000
1-1-10000
-100-1010
100-1010
0-100-101
011000-1
  • 7 moves for 7 dimensions
  • Non-deterministic
  • Same as Chemical Reduction Networks
    • Put equations in vectors (linear combination)

Unordered Fractran

  • Similar to fractran
  • Choose any fraction randomly that yields an integer when multiplied with given number
  • non-deterministic

Broken Register Machine

  • decrementing a register might fail even if register could be decremented

General Notes

  • A lot of these systems get more powerful if they allow prioritizing
  • determinism: turing complete

Halting Problem

Suppose a Turing Machine “A” can take Enc1(table)Enc_1(table), Enc2(tape)Enc_2(tape) and decide wether a TM with the given table will ever halt, if started on the given tape.

This is impossible!

Idea (proof):

  1. Make a machine that does the opposite of whatever machine you give it (halt or not halt)
  2. The goal is to feed this machine to itself
  3. Analyze what machines do when they are fed to themselves

Universal Machine

It’s possible to create a “universal” machine, which just (slowly) does the same thing that the machine described to it would do.



  • Category

  • Programming

  • Tags

  • Computer Science
    ETH

  • Created

  • 29. February 2016


  • Modified

  • 3. June 2023