A Haskell Implementation of Turing Machines Lim Shao En Zhang - - PowerPoint PPT Presentation

a haskell implementation of
SMART_READER_LITE
LIVE PREVIEW

A Haskell Implementation of Turing Machines Lim Shao En Zhang - - PowerPoint PPT Presentation

A Haskell Implementation of Turing Machines Lim Shao En Zhang Licheng Computer Science Computability Theory A Haskell Implementation of Turing Machines Computability Theory Turing Machine Recursion theory Lambda-calculus Post


slide-1
SLIDE 1

A Haskell Implementation of Turing Machines

Lim Shao En Zhang Licheng

slide-2
SLIDE 2

Computer Science Computability Theory

A Haskell Implementation of Turing Machines

slide-3
SLIDE 3

Computability Theory

A Haskell Implementation of Turing Machines

  • Turing Machine
  • Recursion theory
  • Lambda-calculus
  • Post system
slide-4
SLIDE 4

A Haskell Implementation of Turing Machines

Aim and Hypothesis

Bridging the theory – practice gap

slide-5
SLIDE 5

Aim and Hypothesis

Computability Theory

A Haskell Implementation of Turing Machines

Abstract Descriptions Computer programs

Our Aim

Turing Machines Haskell Codes

slide-6
SLIDE 6

A Haskell Implementation of Turing Machines

Turing Machine

Tape (Infinite Length)

Cells

slide-7
SLIDE 7

A Haskell Implementation of Turing Machines

Turing Machine

1 1 1 1 1

Symbols (0,1 or Blank)

slide-8
SLIDE 8

A Haskell Implementation of Turing Machines

Turing Machine

1 1 1 1 1

q1

Head

slide-9
SLIDE 9

A Haskell Implementation of Turing Machines

Turing Machine

1 1 1 1 1

q1 q2 q3 q4 q5

1

State Read and Write Symbols

slide-10
SLIDE 10

A Haskell Implementation of Turing Machines

Turing Machine -- -- Transitions

slide-11
SLIDE 11

A Haskell Implementation of Turing Machines

Haskell

slide-12
SLIDE 12

A Haskell Implementation of Turing Machines

Haskell

  • Typed , Functional Programming

Language

  • Typed - Data types in haskell are built up from

the basic data types: Int, Bool, (a,b) and X->Y

  • Functional - functions can be passed as data

types, data is passed recursively from function to function

slide-13
SLIDE 13

A Haskell Implementation of Turing Machines

Methods

5 Major Stages

Learn Haskell 1 2 Create ‘Types’ 3 Construct ‘UTM’ Prototype 4 Test - Functions 5 Refine & Debug

slide-14
SLIDE 14

A Haskell Implementation of Turing Machines

Results and Discussion

Translating knowledge of Turing Machines into Haskell

slide-15
SLIDE 15

Typ ypes Construction

type pe Dir Dir = Int Int

  • - {-1,0,1}

type pe Sta State te = Int Int

  • - state numbers
  • - start at q(0);
  • - halts at q(-1)

type pe Sym Sym = Int Int

  • - {0,1,2} cell symbols;
  • - 2 represents Blank

type pe Hdp Hdp = Int Int

  • - head position

type pe Tap Tape = [Sym Sym]

  • - strings on tape

type pe Tmac mac = Stat tate

  • >

Sym Sym

  • >

(Stat State,S ,Sym,Di m,Dir)

  • - generic TM
  • - (a set of transitions)

Results and Discussion:

Translating knowledge of Turing Machines into Haskell

slide-16
SLIDE 16

Ma Main Program ram

  • f UT

f UTM proto totyp type

tu turr rr :: :: Tmac Tmac -> Tap Tape -> Ta Tape pe turr m t = fst (auxt m 0 (t,0)) au auxt xt :: :: Tmac Tmac -> Sta State te -> (Tap Tape, e,Hdp Hdp) -> (Tap Tape,H e,Hdp dp) auxt m (-1) (t,i) = (t,i) auxt m q (t,i) = let t2 = edit (i,mysnd(m q (t!!i)),t) in auxt m (myfst(m q (t!!i))) (t2,i + mythd(m q (t!!i))) ed edit it :: :: (Hdp Hdp,S ,Sym, ym,Ta Tape pe) -> Tape Tape edit (i,x,t) = (take i t) ++ [x] ++ (drop (i+1) t) ++ [2] myfst :: (State,Sym,Dir) -> State myfst (q,x,d) = q mysnd :: (State,Sym,Dir) -> Sym mysnd (q,x,d) = x mythd :: (State,Sym,Dir) -> Dir mythd (q,x,d) = d

Results and Discussion:

Translating knowledge of Turing Machines into Haskell

slide-17
SLIDE 17

Test – Function: Addition

add add :: :: Tmac mac add 0 2 = (1,2,1) add 1 1 = (1,1,1) add 1 0 = (2,1,1) add 2 1 = (2,1,1) add 2 2 = (3,2,-1) add 3 1 = (4,2,-1) add 4 1 = (4,1,-1) add 4 2 = (-1,2,0)

3 + 2 = 5

slide-18
SLIDE 18

Test – Function: Multiplication

mult lt :: :: Tmac Tmac mult 0 0 = (7,0,1) mult 0 2 = (0,2,1) mult 1 1 = (2,2,1) mult 1 0 = (6,0,-1) mult 2 0 = (3,0,1) mult 2 1 = (2,1,1) mult 3 1 = (3,1,1) mult 3 2 = (4,1,-1) mult 4 0 = (5,0,-1) mult 4 1 = (4,1,-1) mult 5 1 = (5,1,-1) mult 5 2 = (1,2,1) mult 6 2 = (6,1,-1) mult 6 0 = (9,0,-1) mult 7 0 = (10,2,1) mult 7 1 = (8,2,1) mult 8 0 = (1,0,1) mult 8 1 = (8,1,1) mult 9 1 = (9,1,-1) mult 9 2 = (7,2,1)

  • mult 10 1 = (10,2,1)

mult 10 0 = (11,2,-1) mult 11 2 = (11,2,-1) mult 11 0 = (-1,2,0)

3 x 2 = 6

slide-19
SLIDE 19

UTM Prototype

Results and Discussion:

Translating knowledge of Turing Machines into Haskell

Successful !

slide-20
SLIDE 20

A Haskell Implementation of Turing Machines

Conclusion

1 2 3

State-transition table / diagram Haskell Codes Prototype of UTM Theory-Practice Gap

slide-21
SLIDE 21

A Haskell Implementation of Turing Machines

Future Work

1 2 3

More Functions (e.g. Logarithm, Factorial) Visualise operation of Turing Machine Multi-tape Turing Machine

slide-22
SLIDE 22

Thank You !