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
| X | Y | Z | XOR |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
- Cost of circuit: number of
- AND gates and
- OR gates
- usually NOT gates are not counted (they are too simple)
Truth table:
- for inputs: combinations
Number of functions:
- for inputs: functions (circuits)
General of XOR:
- for inputs gates needed
Finite State Machines (FSM)
- Also called Finite State Automaton (FSA)
See also Tutorialspoint
Can be represented as a 5-touple :
- : finite set of states
- : alphabet (finite set of symbols)
- : transition function
- : initial state ()
- : set of final states ()
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
- incrementing ()
- decrementing ()
- Decrementing a register that holds fails
- There are other (slightly different) definitions of register machines that allow different operations (e.g checking for )
- 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:
| Action | Next Instruction | Alternative Instruction (if actual instruction fails) | |
|---|---|---|---|
| 1. | x- | 2 | 4 |
| 2. | y+ | 3 | - |
| 3. | x- | 1 | 8 |
| 4. | y- | 5 | 6 |
| 5. | x+ | 4 | - |
| 6. | x- | 7 | 5 |
| 7. | x- | 9 | HALT |
| 8. | y- | 9 | 3 |
| 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 () there is an equivalent Register Machine with only 2 registers
- The registers need to be encoded
- Whenever a loop ends (in a 2 Register Machine)
- one register is
- in the other register is some information available
Fractran
See also Wikipedia:Fractran
Example PRIMEGAME:
State/Memory: an Integer
Computation: multiply by first fraction that yields an integer
Start with : 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 Tile | Use |
|---|---|
| TAPE | One for each symbol in the alphabet |
| ACTION | One tile for each transition of the TM |
| PREPARE | Two 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
- -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
- Conway’s Game of Life
- Toom’s rule
- asymetrc rule
Lambda Calculus
- Meta-Mathematics
- Turing Machines simulate a person that calculate (State: Mind, Tape: Paper)
- Lambda Calculus: about functions
Syntax
Traditional Syntax:
Lambda Syntax:
-
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:
- Can get rid of
- function names
- multi-argument functions
Main Operations
- -reduction: apply a function to an argument using substitution
- Reduction is an optimistic term since the result of the -reduction can be bigger then the expression before
- -conversion: changing a functions ‘argument symbol’ ()
- -conversion: because
Church Numerals
- Numbers can be encoded as functions
- Arbitrary encoding of numbers suggested by church
Each number is a function that takes 2 arguments: and :
The number is a function that takes a function as argument and applies it -times to the second argument
Example: : apply function -times to
Lambda Calculus Expressions
- Using just substitution step to calculate
- seems complex, but only one operation needed: substitution
Variables
- , , …
- representing functions
Function Application
: applied to
Function Creation
Evaluation
Example:
Examples
Increment
Example:
increment
Addition
Multiplication
Boolean Logic
If-Then-Else
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 -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:
Y-Combinator
See Wikipedia
and The Y Combinator (no, not that one).
Beta recursion gives:
- 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.
- Decimal
- Roman Numerals
- Binary
- Two’s complement
- Binary with digits up to 2 (Redundant binary representation)
- Addition can be faster
- Logical operation are slower
- Ternary
- Church Numerals
- Prime Factorization:
- Multiplication and Factorization is easy
- Increment by one is hard
- Chinese remainder theorem
- Comparing two numbers is hard
- p-adic number
- related to two’s complement
Tag Systems
- Tape with a starting string
- Reading and deleting at the beginning (left)
- Appending (writing) at the end (right)
2-Tag System
- reads 1 symbol at the beginning of the tape
- appends a string at the end of the type
- appended string depends on read symbol
- removes 2 symbols at the beginning of the tape
Example: Test for odd/even number
-
Alphabet:
-
Rules:
-
: empty word
-
: Odd
-
: Even
-
-
: symbol a is repeated times
-
the given rules show if is odd or even
Example even:
Example odd:
Example: Power of Two
Starting with:
For :
Simulation of Turing Machines with Tag Systems
Some of the notes here are taken from ‘Understanding Computation’ by Tom Stuart.
- Tape uses only 2 characters: and
- is the blank character
- 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
- left part
- Interpret left part as binary number
- Interpret right part as binary number written backwards
- Encode those 2 numbers as string (suitable to be used for Tag System)
- 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
- : incrementing number
- : decrementing number
- move head to right:
- Simulate
- Current state of simulated Turing machine represented by different encoding
- e. g
- State 1: use a, b, c
- State 2: use d, e, f
- …
- e. g
- Convert each Turing Machine rule into a Tag Systems that rewrites the current string in the expected way
- 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 and
- A string is only appended if a is read
- The rules for appending strings is ordered
- The deletion number is
Algorithm:
In each round:
- Read next rule in rule-set
- Read next symbol on tape
- if : append the string from the rule set to the tape
- if : 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:
- Definition for argument
- General definition
| Function | Name | Definition () | Definition () |
|---|---|---|---|
| Successor | intrinsic/primitive | - | |
| Addition | |||
| Multiplication | |||
| Exponentiation | |||
| Positivity | |||
| Predecessor | |||
| Subtraction | |||
| Remainder | |||
| ‘mod Product’ | |||
| if prime ; else | Primality |
- 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
- Nondeterministic: any reaction can happen at any time
- Primitive Recursive Functions can always compute this in bounded time, even if answer is .
- 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
| A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|
| -1 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | -1 | 1 | 0 | 0 | 0 |
| 1 | -1 | -1 | 0 | 0 | 0 | 0 |
| -1 | 0 | 0 | -1 | 0 | 1 | 0 |
| 1 | 0 | 0 | -1 | 0 | 1 | 0 |
| 0 | -1 | 0 | 0 | -1 | 0 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 | -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 , and decide wether a TM with the given table will ever halt, if started on the given tape.
This is impossible!
Idea (proof):
- Make a machine that does the opposite of whatever machine you give it (halt or not halt)
- The goal is to feed this machine to itself
- 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.
- a programmable Turing Machine
- see Universal Turing machine