a haskell implementation of
play

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


  1. A Haskell Implementation of Turing Machines Lim Shao En Zhang Licheng

  2. Computer Science Computability Theory A Haskell Implementation of Turing Machines

  3. Computability Theory • Turing Machine • Recursion theory • Lambda-calculus • Post system A Haskell Implementation of Turing Machines

  4. Aim and Hypothesis Bridging the theory – practice gap A Haskell Implementation of Turing Machines

  5. Aim and Hypothesis Abstract Turing Descriptions Machines Computability Our Aim Theory Computer Haskell programs Codes A Haskell Implementation of Turing Machines

  6. Turing Machine Cells Tape (Infinite Length) A Haskell Implementation of Turing Machines

  7. Turing Machine Symbols (0,1 or Blank) 0 1 1 1 0 1 1 0 0 0 0 A Haskell Implementation of Turing Machines

  8. Turing Machine Head q1 0 1 1 1 0 1 1 0 0 0 0 A Haskell Implementation of Turing Machines

  9. Turing Machine State q1 q2 q5 q3 q4 0 0 1 0 1 0 1 0 1 1 1 0 0 0 0 Read and Write Symbols A Haskell Implementation of Turing Machines

  10. Turing Machine -- -- Transitions A Haskell Implementation of Turing Machines

  11. Haskell A Haskell Implementation of Turing Machines

  12. 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 A Haskell Implementation of Turing Machines

  13. Learn Haskell 1 Methods Create ‘Types’ 2 5 Construct ‘UTM’ Prototype 3 Major Stages Test - Functions 4 Refine & Debug 5 A Haskell Implementation of Turing Machines

  14. Results and Discussion Translating knowledge of Turing Machines into Haskell A Haskell Implementation of Turing Machines

  15. 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 Typ ypes Construction -- {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

  16. tu turr rr :: :: Tmac Tmac -> Tap Tape -> Ta Tape pe turr m t = fst (auxt m 0 (t,0)) auxt au 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 Main Program Ma ram auxt m (myfst(m q (t!!i))) (t2,i + mythd(m q (t!!i))) of UT f UTM edit ed it :: :: (Hdp Hdp,S ,Sym, ym,Ta Tape pe) -> Tape Tape edit (i,x,t) = (take i t) ++ [x] ++ (drop (i+1) t) ++ [2] proto totyp type 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

  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

  18. Test – Function: Multiplication 3 x 2 = 6 mult lt :: :: Tmac Tmac mult 0 0 = (7,0,1) mult 0 2 = (0,2,1) mult 7 0 = (10,2,1) mult 1 1 = (2,2,1) mult 7 1 = (8,2,1) mult 1 0 = (6,0,-1) mult 8 0 = (1,0,1) mult 2 0 = (3,0,1) mult 8 1 = (8,1,1) mult 2 1 = (2,1,1) mult 9 1 = (9,1,-1) mult 3 1 = (3,1,1) mult 9 2 = (7,2,1) mult 3 2 = (4,1,-1) -- mult 4 0 = (5,0,-1) mult 10 1 = (10,2,1) mult 4 1 = (4,1,-1) mult 10 0 = (11,2,-1) mult 5 1 = (5,1,-1) mult 11 2 = (11,2,-1) mult 5 2 = (1,2,1) mult 11 0 = (-1,2,0) mult 6 2 = (6,1,-1) mult 6 0 = (9,0,-1)

  19. UTM Prototype Successful ! Results and Discussion: Translating knowledge of Turing Machines into Haskell

  20. Conclusion State-transition Haskell 1 table / diagram Codes 2 Prototype of UTM 3 Theory-Practice Gap A Haskell Implementation of Turing Machines

  21. Future Work 1 More Functions (e.g. Logarithm, Factorial) 2 Visualise operation of Turing Machine 3 Multi-tape Turing Machine A Haskell Implementation of Turing Machines

  22. Thank You !

Recommend


More recommend