2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department of the University of Bologna, Italy.
8 \ / This file is distributed under the terms of the
9 \ / GNU General Public License Version 2
10 V_____________________________________________________________*)
12 include "turing/turing.ma".
16 record TM (sig:FinSet): Type[1] ≝
18 tapes_no: nat; (* additional working tapes *)
19 trans : states × (Vector (option sig) (S tapes_no)) →
20 states × (Vector (sig × move) (S tapes_no)) × (option sig) ;
26 inductive oracle_states :Type[0] ≝
27 | query : oracle_states
31 record config (sig:FinSet) (M:TM sig): Type[0] ≝
32 { state : states sig M;
34 tapes : Vector (tape sig) (S (tapes_no sig M));
38 definition option_hd ≝ λA.λl:list A.
44 definition tape_move ≝ λsig.λt: tape sig.λm:sig × move.
46 [ R ⇒ mk_tape sig ((\fst m)::(left ? t)) (tail ? (right ? t))
47 | L ⇒ mk_tape sig (tail ? (left ? t)) ((\fst m)::(right ? t))
48 | N ⇒ mk_tape sig (left ? t) ((\fst m)::(tail ? (right ? t)))
51 definition current_chars ≝ λsig.λM:TM sig.λc:config sig M.
52 vec_map ?? (λt.option_hd ? (right ? t)) (S (tapes_no sig M)) (tapes ?? c).
54 definition opt_cons ≝ λA.λa:option A.λl:list A.
60 definition step ≝ λsig.λM:TM sig.λc:config sig M.
61 let 〈news,mvs,outchar〉 ≝ trans sig M 〈state ?? c,current_chars ?? c〉 in
64 (pmap_vec ??? (tape_move sig) ? (tapes ?? c) mvs)
65 (opt_cons ? outchar (out ?? c)).
67 definition empty_tapes ≝ λsig.λn.
68 mk_Vector ? n (make_list (tape sig) (mk_tape sig [] []) n) ?.
69 elim n // normalize //
72 definition init ≝ λsig.λM:TM sig.λi:(list sig).
75 (vec_cons ? (mk_tape sig [] i) ? (empty_tapes sig (tapes_no sig M)))
78 definition stop ≝ λsig.λM:TM sig.λc:config sig M.
79 halt sig M (state sig M c).
81 let rec loop (A:Type[0]) n (f:A→A) p a on n ≝
84 | S m ⇒ if p a then (Some ? a) else loop A m f p (f a)
87 (* Compute ? M f states that f is computed by M *)
88 definition Compute ≝ λsig.λM:TM sig.λf:(list sig) → (list sig).
90 loop ? i (step sig M) (stop sig M) (init sig M l) = Some ? c ∧
93 (* for decision problems, we accept a string if on termination
94 output is not empty *)
96 definition ComputeB ≝ λsig.λM:TM sig.λf:(list sig) → bool.
98 loop ? i (step sig M) (stop sig M) (init sig M l) = Some ? c ∧
99 (isnilb ? (out ?? c) = false).