7 left (tape in) = cs@'#'::ls →
8 right (tape in) = d::rs →
10 left (tape out) = ls ∧
11 right (tape out) = d::'#'::rev cs@rs ∧
18 left (tape in) = c::ls →
19 right (tape in) = d::rs →
21 left (tape out) = ls ∧
22 right (tape out) = d::c::rs
29 right (tape in) = c::rs →
31 (c ≠ '#' → state out = qtrue)
36 right (tape in) = c::rs →
38 (c = '#' → state out = qfalse) ∧
41 A = do A0 while A1 inv PA0 var |right (tape in)|;
43 posso assumere le precondizioni di A
44 H1 : left (tape in) = c::cs@'#'::ls
45 H2 : right (tape in) = d::rs
47 in particolare H2 → precondizioni di A1
49 eseguiamo dunque if A1 then (A0; A) else skip
53 by induction on left (tape in)
59 devo allora provare che PA1°PA0°PA(in,out) → PA(in,out)
60 ∃s1,s2: PA1t(in,s1) ∧ PA0(s1,s2) ∧ PA(s2,out)
62 usando anche Hcase, ottengo che tape in = tape s1
63 soddisfo allora le precondizioni di PA0(s1,s2) ottenendo che
64 left (tape s2) = cs@'#'::ls
65 right (tape s2) = d::c::rs
67 soddisfo allora le precondizioni di PA e per ipotesi induttiva
70 left (tape s) = d::cs@'#'::ls
81 (∃ls,cs,d,rs. left inc = ... ∧ right inc = ... ∧ state inc = q0) →
82 ∃i,outc. loop i step inc = Some ? outc
83 ∧(∀ls,cs,d,rs.left inc = ... → right inc = ... →
85 ∧ right outc = d::"#"::rev cs::rs
86 ∧ state outc = qfinal)
89 (ψ1(in1,out1) → ϕ2(out1)) → (ψ2(out1,out2) → ψ3(in1,out2)) →
94 -----------------------------------------------------
95 {} (tmp ≝ x; x ≝ y; y ≝ tmp) {x = old(x), y = old(y)}
103 left inc = cs@"#"::ls →
106 ∃i,outc. loop i step inc = Some outc
108 (∀ls,cs,d,rs.left inc = ... → right inc = ... →
110 ∧ right outc = d::"#"::rev cs::rs
111 ∧ state outc = qfinal
117 ||M|| This file is part of HELM, an Hypertextual, Electronic
118 ||A|| Library of Mathematics, developed at the Computer Science
119 ||T|| Department of the University of Bologna, Italy.
123 \ / This file is distributed under the terms of the
124 \ / GNU General Public License Version 2
125 V_____________________________________________________________*)
127 include "basics/vectors.ma".
129 record tape (sig:FinSet): Type[0] ≝
134 inductive move : Type[0] ≝
139 (* We do not distinuish an input tape *)
141 record TM (sig:FinSet): Type[1] ≝
143 tapes_no: nat; (* additional working tapes *)
144 trans : states × (Vector (option sig) (S tapes_no)) →
145 states × (Vector (sig × move) (S tapes_no)) × (option sig) ;
151 record config (sig:FinSet) (M:TM sig): Type[0] ≝
152 { state : states sig M;
153 tapes : Vector (tape sig) (S (tapes_no sig M));
157 definition option_hd ≝ λA.λl:list A.
163 definition tape_move ≝ λsig.λt: tape sig.λm:sig × move.
165 [ R ⇒ mk_tape sig ((\fst m)::(left ? t)) (tail ? (right ? t))
166 | L ⇒ mk_tape sig (tail ? (left ? t)) ((\fst m)::(right ? t))
167 | N ⇒ mk_tape sig (left ? t) ((\fst m)::(tail ? (right ? t)))
170 definition current_chars ≝ λsig.λM:TM sig.λc:config sig M.
171 vec_map ?? (λt.option_hd ? (right ? t)) (S (tapes_no sig M)) (tapes ?? c).
173 definition opt_cons ≝ λA.λa:option A.λl:list A.
179 definition step ≝ λsig.λM:TM sig.λc:config sig M.
180 let 〈news,mvs,outchar〉 ≝ trans sig M 〈state ?? c,current_chars ?? c〉 in
183 (pmap_vec ??? (tape_move sig) ? (tapes ?? c) mvs)
184 (opt_cons ? outchar (out ?? c)).
186 definition empty_tapes ≝ λsig.λn.
187 mk_Vector ? n (make_list (tape sig) (mk_tape sig [] []) n) ?.
188 elim n // normalize //
191 definition init ≝ λsig.λM:TM sig.λi:(list sig).
194 (vec_cons ? (mk_tape sig [] i) ? (empty_tapes sig (tapes_no sig M)))
197 definition stop ≝ λsig.λM:TM sig.λc:config sig M.
198 halt sig M (state sig M c).
200 let rec loop (A:Type[0]) n (f:A→A) p a on n ≝
203 | S m ⇒ if p a then (Some ? a) else loop A m f p (f a)
206 (* Compute ? M f states that f is computed by M *)
207 definition Compute ≝ λsig.λM:TM sig.λf:(list sig) → (list sig).
209 loop ? i (step sig M) (stop sig M) (init sig M l) = Some ? c ∧
212 (* for decision problems, we accept a string if on termination
213 output is not empty *)
215 definition ComputeB ≝ λsig.λM:TM sig.λf:(list sig) → bool.
217 loop ? i (step sig M) (stop sig M) (init sig M l) = Some ? c ∧
218 (isnilb ? (out ?? c) = false).
220 (* alternative approach.
221 We define the notion of computation. The notion must be constructive,
222 since we want to define functions over it, like lenght and size
224 Perche' serve Type[2] se sposto a e b a destra? *)
226 inductive cmove (A:Type[0]) (f:A→A) (p:A →bool) (a,b:A): Type[0] ≝
227 mk_move: p a = false → b = f a → cmove A f p a b.
229 inductive cstar (A:Type[0]) (M:A→A→Type[0]) : A →A → Type[0] ≝
230 | empty : ∀a. cstar A M a a
231 | more : ∀a,b,c. M a b → cstar A M b c → cstar A M a c.
233 definition computation ≝ λsig.λM:TM sig.
234 cstar ? (cmove ? (step sig M) (stop sig M)).
236 definition Compute_expl ≝ λsig.λM:TM sig.λf:(list sig) → (list sig).
237 ∀l.∃c.computation sig M (init sig M l) c →
238 (stop sig M c = true) ∧ out ?? c = f l.
240 definition ComputeB_expl ≝ λsig.λM:TM sig.λf:(list sig) → bool.
241 ∀l.∃c.computation sig M (init sig M l) c →
242 (stop sig M c = true) ∧ (isnilb ? (out ?? c) = false).