annotate agda/turing.agda @ 89:e919e82e95a2

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 10 Nov 2019 12:21:44 +0900
parents 964e4bd0272a
children 3be1afb87f82
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 module turing where
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level renaming ( suc to succ ; zero to Zero )
18
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
4 open import Data.Nat hiding ( erase )
17
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Data.List
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Data.Maybe
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
7 open import Data.Bool using ( Bool ; true ; false ) renaming ( not to negate )
17
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Relation.Binary.PropositionalEquality hiding ( [_] )
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Relation.Nullary using (¬_; Dec; yes; no)
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Level renaming ( suc to succ ; zero to Zero )
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import Data.Product
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
18
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
14 data Write ( Σ : Set ) : Set where
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
15 write : Σ → Write Σ
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
16 wnone : Write Σ
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
17 -- erase write tnone
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
18
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
19 data Move : Set where
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
20 left : Move
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
21 right : Move
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
22 mnone : Move
18
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
23
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
24 -- at tδ both stack is poped
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
25
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
26 -- write S push S , push SR
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
27 -- erase push SL , push tone
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
28 -- none push SL , push SR
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
29 -- left push SR , pop
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
30 -- right pop , push SL
17
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
39
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
32 {-# TERMINATING #-}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
33 move : {Q Σ : Set } → { tone : Σ} → {tδ : Q → Σ → Q × ( Write Σ ) × Move } → (q : Q ) ( L : List Σ ) ( L : List Σ ) → ( Q × List Σ × List Σ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
34 move {Q} {Σ} {tnone} {tδ} q L [] = move {Q} {Σ} {tnone} {tδ} q L ( tnone ∷ [] )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
35 move {Q} {Σ} {tnone} {tδ} q [] R = move {Q} {Σ} {tnone} {tδ} q ( tnone ∷ [] ) R
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
36 move {Q} {Σ} {tnone} {tδ} q ( LH ∷ LT ) ( RH ∷ RT ) with tδ q LH
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
37 ... | nq , write x , left = ( nq , ( RH ∷ x ∷ LT ) , RT )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
38 ... | nq , write x , right = ( nq , LT , ( x ∷ RH ∷ RT ) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
39 ... | nq , write x , mnone = ( nq , ( x ∷ LT ) , ( RH ∷ RT ) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
40 ... | nq , wnone , left = ( nq , ( RH ∷ LH ∷ LT ) , RT )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
41 ... | nq , wnone , right = ( nq , LT , ( LH ∷ RH ∷ RT ) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
42 ... | nq , wnone , mnone = ( nq , ( LH ∷ LT ) , ( RH ∷ RT ) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
43 {-# TERMINATING #-}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
44 move-loop : {Q Σ : Set } → {tend : Q → Bool} → (q : Q ) ( L : List Σ ) ( L : List Σ ) → ( Q × List Σ × List Σ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
45 move-loop {Q} {Σ} {tend} q L R with tend q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
46 ... | true = ( q , L , R )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
47 ... | flase = move-loop {Q} {Σ} {tend} ( proj₁ next ) ( proj₁ ( proj₂ next ) ) ( proj₂ ( proj₂ next ) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
48 where
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
49 next = move {Q} {Σ} {{!!}} {{!!}} q L R
17
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 record Turing ( Q : Set ) ( Σ : Set )
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 : Set where
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 field
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
54 tδ : Q → Σ → Q × ( Write Σ ) × Move
17
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 tstart : Q
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 tend : Q → Bool
18
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
57 tnone : Σ
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
58 {-# TERMINATING #-}
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
59 move0 : (q : Q ) ( L : List Σ ) ( L : List Σ ) → ( Q × List Σ × List Σ )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
60 move0 q L R with tend q
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
61 ... | true = ( q , L , R )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
62 move0 q L [] | false = move0 q L ( tnone ∷ [] )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
63 move0 q [] R | false = move0 q ( tnone ∷ [] ) R
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
64 move0 q ( LH ∷ LT ) ( RH ∷ RT ) | false with tδ q LH
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
65 ... | nq , write x , left = move0 nq ( RH ∷ x ∷ LT ) RT
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
66 ... | nq , write x , right = move0 nq LT ( x ∷ RH ∷ RT )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
67 ... | nq , write x , mnone = move0 nq ( x ∷ LT ) ( RH ∷ RT )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
68 ... | nq , wnone , left = move0 nq ( RH ∷ LH ∷ LT ) RT
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
69 ... | nq , wnone , right = move0 nq LT ( LH ∷ RH ∷ RT )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
70 ... | nq , wnone , mnone = move0 nq ( LH ∷ LT ) ( RH ∷ RT )
18
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
71 taccept : List Σ → ( Q × List Σ × List Σ )
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
72 taccept L = move0 tstart L []
18
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
73
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
74 data CopyStates : Set where
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
75 s1 : CopyStates
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
76 s2 : CopyStates
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
77 s3 : CopyStates
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
78 s4 : CopyStates
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
79 s5 : CopyStates
19
e5d67f06aca8 turing machine done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
80 H : CopyStates
17
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
83 Copyδ : CopyStates → ℕ → CopyStates × ( Write ℕ ) × Move
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
84 Copyδ s1 0 = (H , wnone , mnone )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
85 Copyδ s1 1 = (s2 , write 0 , right )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
86 Copyδ s2 0 = (s3 , write 0 , right )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
87 Copyδ s2 1 = (s2 , write 1 , right )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
88 Copyδ s3 0 = (s4 , write 1 , left )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
89 Copyδ s3 1 = (s3 , write 1 , right )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
90 Copyδ s4 0 = (s5 , write 0 , left )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
91 Copyδ s4 1 = (s4 , write 1 , left )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
92 Copyδ s5 0 = (s1 , write 1 , right )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
93 Copyδ s5 1 = (s5 , write 1 , left )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
94 Copyδ H _ = (H , wnone , mnone )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
95 Copyδ _ (suc (suc _)) = (H , wnone , mnone )
17
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
97 copyMachine : Turing CopyStates ℕ
18
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
98 copyMachine = record {
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
99 tδ = Copyδ
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
100 ; tstart = s1
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
101 ; tend = tend
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
102 ; tnone = 0
18
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
103 } where
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
104 tend : CopyStates → Bool
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
105 tend H = true
6ec8e933ab43 turing wrote but not yet worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
106 tend _ = false
17
08b589172493 add pushdown and turing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
108 test1 : CopyStates × ( List ℕ ) × ( List ℕ )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
109 test1 = Turing.taccept copyMachine ( 1 ∷ 1 ∷ 0 ∷ 0 ∷ 0 ∷ [] )
19
e5d67f06aca8 turing machine done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
110
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
111 test2 : ℕ → CopyStates × ( List ℕ ) × ( List ℕ )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
112 test2 n = loop n (Turing.tstart copyMachine) ( 1 ∷ 1 ∷ 0 ∷ 0 ∷ 0 ∷ [] ) []
19
e5d67f06aca8 turing machine done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
113 where
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
114 loop : ℕ → CopyStates → ( List ℕ ) → ( List ℕ ) → CopyStates × ( List ℕ ) × ( List ℕ )
19
e5d67f06aca8 turing machine done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
115 loop zero q L R = ( q , L , R )
e5d67f06aca8 turing machine done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
116 loop (suc n) q L R = loop n ( proj₁ t1 ) ( proj₁ ( proj₂ t1 ) ) ( proj₂ ( proj₂ t1 ) )
e5d67f06aca8 turing machine done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
117 where
39
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
118 t1 = move {CopyStates} {ℕ} {0} {Copyδ} q L R
20
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
119
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
120
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
121 ---
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
122 -- utm char
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
123 -- head head position
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
124 -- send state description end
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
125 -- del state delimitor
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
126 -- sstart state description start
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
127 -- 0
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
128 -- 1
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
129 -- utm state description
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
130 -- state-num ℕ ( 0 accept, 1 reject )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
131 -- print 0 write 0, 1 write 1, 2 none
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
132 -- move 0 left , 1 none 2 write
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
133 -- utm state
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
134 -- head-value : ℕ
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
135 -- current-state : ℕ
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
136 -- direction : ℕ
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
137 -- head-dir : ℕ
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
138 --
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
139 -- --------------- head sstart ( state description ) * send input --------------
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
140 --
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
141 -- loop search sstart ( depend on head position )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
142 -- if state description end reject
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
143 -- if state-num eq current state
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
144 -- if accept end
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
145 -- set current-state, direction and head-value by utm state description
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
146 -- goto exec
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
147 -- else goto loop
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
148 -- exec
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
149 -- if head-dir = left
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
150 -- search head towrards letf
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
151 -- else
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
152 -- search head towards write
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
153 -- put head-value
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
154 -- move head ( considering state description )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
155 -- back to sstart
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
156 -- goto loop
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
157
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
158
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
159
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
160 postulate UTM : Turing ℕ ℕ
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
161 postulate encode-for-utm : Turing ℕ ℕ → List ℕ
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
162 postulate enumerate-tm : Turing ℕ ℕ → ℕ
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
163 postulate utm-simulate : ( tm : Turing ℕ ℕ ) → ( In : List ℕ ) → Turing.taccept UTM ((encode-for-utm tm) ++ In) ≡ Turing.taccept tm In
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
164
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
165 record Halt : Set where
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
166 field
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
167 halt : List ℕ → Bool
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
168 TM : Turing ℕ ℕ
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
169
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
170 open Halt
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
171
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
172 record NotHalt ( H : Halt ) : Set where
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
173 field
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
174 nothalt : List ℕ → Bool
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
175 NegTM : Turing ℕ ℕ
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
176 neg : (n : List ℕ ) → nothalt n ≡ negate ( halt H n )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
177
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
178 open NotHalt
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
179
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
180 -- neg : ( tm : Turing ℕ ℕ ) → ( h : Halt ) → Bool
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
181 -- neg tm h = negate ( halt h ( encode-for-utm tm ) )
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
182
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
183 open import Data.Empty
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
184
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
185 lemma1 : (H : Halt ) → (NH : NotHalt H ) → nothalt NH (encode-for-utm ( NegTM NH )) ≡ true → ⊥
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
186 lemma1 h nh negneg=1 with halt h (encode-for-utm ( NegTM nh )) | nothalt nh (encode-for-utm ( NegTM nh )) | neg nh (encode-for-utm ( NegTM nh ))
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
187 ... | true | false | refl = {!!}
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
188 ... | false | true | refl = {!!}
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
189
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
190 lemma2 : (H : Halt ) → (NH : NotHalt H ) → nothalt NH (encode-for-utm ( NegTM NH )) ≡ false → ⊥
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
191 lemma2 h nh negneg=1 with halt h (encode-for-utm ( NegTM nh )) | nothalt nh (encode-for-utm ( NegTM nh )) | neg nh (encode-for-utm ( NegTM nh ))
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
192 ... | true | false | refl = {!!}
6032a2317ffa add halt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
193 ... | false | true | refl = {!!}