wneuper@59601
|
1 |
(* Title: tactics, tacticals etc. for scripts
|
wneuper@59601
|
2 |
Author: Walther Neuper 000224
|
wneuper@59601
|
3 |
(c) due to copyright terms
|
wneuper@59601
|
4 |
*)
|
wneuper@59601
|
5 |
|
walther@59603
|
6 |
theory Prog_Tac
|
walther@59603
|
7 |
imports "~~/src/Tools/isac/CalcElements/CalcElements"
|
walther@59603
|
8 |
begin
|
wneuper@59601
|
9 |
|
walther@59619
|
10 |
text \<open>Abstract:
|
walther@59619
|
11 |
Specific constants for tactics in programs, which each create a step in a calculation
|
walther@59619
|
12 |
as a side effect.
|
walther@59619
|
13 |
These program-tactics are related to Tactic.input for use in calculations and
|
walther@59619
|
14 |
Tactic.T for internal use by lucas-interpretation.
|
walther@59619
|
15 |
\<close>
|
walther@59619
|
16 |
|
wneuper@59601
|
17 |
subsection \<open>arguments of tactic SubProblem\<close>
|
wneuper@59601
|
18 |
|
wneuper@59601
|
19 |
typedecl
|
wneuper@59601
|
20 |
arg
|
wneuper@59601
|
21 |
|
wneuper@59601
|
22 |
consts
|
wneuper@59601
|
23 |
REAL :: "real => arg"
|
wneuper@59601
|
24 |
REAL_LIST :: "(real list) => arg"
|
wneuper@59601
|
25 |
REAL_SET :: "(real set) => arg"
|
wneuper@59601
|
26 |
BOOL :: "bool => arg"
|
wneuper@59601
|
27 |
BOOL_LIST :: "(bool list) => arg"
|
wneuper@59601
|
28 |
REAL_REAL :: "(real => real) => arg"
|
wneuper@59601
|
29 |
STRING :: "(char list) => arg"
|
wneuper@59601
|
30 |
STRING_LIST :: "(char list list) => arg"
|
wneuper@59601
|
31 |
|
wneuper@59601
|
32 |
subsection \<open>tactics in programs\<close>
|
wneuper@59601
|
33 |
text \<open>
|
wneuper@59601
|
34 |
Note: the items below MUST ALL be recorded in xxx TODO
|
wneuper@59601
|
35 |
\<close>
|
wneuper@59601
|
36 |
consts
|
walther@59634
|
37 |
Calculate :: "[char list, 'a] => 'a"
|
walther@59635
|
38 |
Rewrite :: "[char list, 'a] => 'a"
|
walther@59636
|
39 |
Rewrite'_Inst:: "[(char list * 'b) list, char list, 'a] => 'a"
|
walther@59637
|
40 |
("(Rewrite'_Inst (_ _))" 11) (*without last argument ^^ for #>*)
|
walther@59635
|
41 |
Rewrite'_Set :: "[char list, 'a] => 'a" ("(Rewrite'_Set (_))" 11)
|
wneuper@59601
|
42 |
Rewrite'_Set'_Inst
|
walther@59636
|
43 |
:: "[((char list) * 'b) list, char list, 'a] => 'a"
|
walther@59637
|
44 |
("(Rewrite'_Set'_Inst (_ _))" 11) (*without last argument ^^ for #>*)
|
walther@59634
|
45 |
Or'_to'_List :: "bool => 'a list" ("Or'_to'_List (_)" 11)
|
walther@59634
|
46 |
SubProblem :: "[char list * char list list * char list list, arg list] => 'a"
|
walther@59634
|
47 |
Substitute :: "[bool list, 'a] => 'a"
|
walther@59634
|
48 |
Take :: "'a => 'a"
|
walther@59634
|
49 |
|
walther@59635
|
50 |
(* legacy.. *)
|
walther@59635
|
51 |
Calculate1 :: "[char list, 'a] => 'a" (* unknown to lucas-interpreter *)
|
wneuper@59601
|
52 |
Check'_elementwise :: (* TODO: is idle, retained for test purposes in Minisubpbl *)
|
wneuper@59601
|
53 |
"['a list, 'b set] => 'a list" ("Check'_elementwise (_ _)" 11)
|
wneuper@59601
|
54 |
Assumptions :: bool (* TODO: remove with making ^^^ idle *)
|
walther@59634
|
55 |
|
wneuper@59601
|
56 |
|
wneuper@59601
|
57 |
subsection \<open>TODO\<close>
|
wneuper@59601
|
58 |
ML \<open>
|
wneuper@59601
|
59 |
signature PROGAM_TACTIC =
|
wneuper@59601
|
60 |
sig
|
walther@59659
|
61 |
val dest_spec : term -> Celem.spec
|
walther@59659
|
62 |
val get_stac : 'a -> term -> term option (*rename get_first*)
|
walther@59659
|
63 |
val subst_stacexpr: (term * term) list -> term option -> term -> term -> term option * Celem.stacexpr
|
wneuper@59601
|
64 |
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
|
wneuper@59601
|
65 |
(*NONE*)
|
walther@59702
|
66 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
|
wneuper@59601
|
67 |
(*NONE*)
|
walther@59702
|
68 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
wneuper@59601
|
69 |
end
|
wneuper@59601
|
70 |
\<close> ML \<open>
|
wneuper@59601
|
71 |
(**)
|
wneuper@59601
|
72 |
structure Prog_Tac(**): PROGAM_TACTIC(**) =
|
wneuper@59601
|
73 |
struct
|
wneuper@59601
|
74 |
(**)
|
wneuper@59601
|
75 |
|
walther@59618
|
76 |
fun dest_spec (Const ("Product_Type.Pair", _) $ d $ (Const ("Product_Type.Pair", _) $ p $ m)) =
|
walther@59618
|
77 |
(d |> HOLogic.dest_string,
|
walther@59618
|
78 |
p |> HOLogic.dest_list |> map HOLogic.dest_string,
|
walther@59618
|
79 |
m |> HOLogic.dest_list |> map HOLogic.dest_string) : Celem.spec
|
walther@59618
|
80 |
| dest_spec t = raise TERM ("dest_spec: called with ", [t])
|
walther@59618
|
81 |
|
walther@59635
|
82 |
(* get argument of first Prog_Tac in a progam for init_form *)
|
wneuper@59601
|
83 |
fun get_stac thy (_ $ body) =
|
wneuper@59601
|
84 |
let
|
walther@59637
|
85 |
(* entries occur twice, for form curried by #> or non-curried *)
|
walther@59688
|
86 |
fun get_t y (Const ("Tactical.Chain",_) $ e1 $ e2) a =
|
wneuper@59601
|
87 |
(case get_t y e1 a of NONE => get_t y e2 a | la => la)
|
walther@59688
|
88 |
| get_t y (Const ("Tactical.Chain",_) $ e1 $ e2 $ a) _ =
|
wneuper@59601
|
89 |
(case get_t y e1 a of NONE => get_t y e2 a | la => la)
|
walther@59603
|
90 |
| get_t y (Const ("Tactical.Try",_) $ e) a = get_t y e a
|
walther@59603
|
91 |
| get_t y (Const ("Tactical.Try",_) $ e $ a) _ = get_t y e a
|
walther@59603
|
92 |
| get_t y (Const ("Tactical.Repeat",_) $ e) a = get_t y e a
|
walther@59603
|
93 |
| get_t y (Const ("Tactical.Repeat",_) $ e $ a) _ = get_t y e a
|
walther@59603
|
94 |
| get_t y (Const ("Tactical.Or",_) $e1 $ e2) a =
|
wneuper@59601
|
95 |
(case get_t y e1 a of NONE => get_t y e2 a | la => la)
|
walther@59603
|
96 |
| get_t y (Const ("Tactical.Or",_) $e1 $ e2 $ a) _ =
|
wneuper@59601
|
97 |
(case get_t y e1 a of NONE => get_t y e2 a | la => la)
|
walther@59603
|
98 |
| get_t y (Const ("Tactical.While",_) $ _ $ e) a = get_t y e a
|
walther@59603
|
99 |
| get_t y (Const ("Tactical.While",_) $ _ $ e $ a) _ = get_t y e a
|
walther@59603
|
100 |
| get_t y (Const ("Tactical.Letpar",_) $ e1 $ Abs (_, _, e2)) a =
|
wneuper@59601
|
101 |
(case get_t y e1 a of NONE => get_t y e2 a | la => la)
|
wneuper@59601
|
102 |
| get_t y (Const ("HOL.Let",_) $ e1 $ Abs (_, _, _)) a =
|
walther@59635
|
103 |
get_t y e1 a (* don't go deeper without evaluation *)
|
wneuper@59601
|
104 |
| get_t _ (Const ("If", _) $ _ $ _ $ _) _ = NONE
|
wneuper@59601
|
105 |
|
walther@59635
|
106 |
| get_t _ (Const ("Prog_Tac.Rewrite",_) $ _ $ a) _ = SOME a
|
walther@59635
|
107 |
| get_t _ (Const ("Prog_Tac.Rewrite",_) $ _ ) a = SOME a
|
walther@59635
|
108 |
| get_t _ (Const ("Prog_Tac.Rewrite'_Inst",_) $ _ $ _ $ a) _ = SOME a
|
walther@59635
|
109 |
| get_t _ (Const ("Prog_Tac.Rewrite'_Inst",_) $ _ $ _ ) a = SOME a
|
walther@59635
|
110 |
| get_t _ (Const ("Prog_Tac.Rewrite'_Set",_) $ _ $ a) _ = SOME a
|
walther@59635
|
111 |
| get_t _ (Const ("Prog_Tac.Rewrite'_Set",_) $ _ ) a = SOME a
|
walther@59635
|
112 |
| get_t _ (Const ("Prog_Tac.Rewrite'_Set'_Inst",_) $ _ $ _ $a)_ =SOME a
|
walther@59635
|
113 |
| get_t _ (Const ("Prog_Tac.Rewrite'_Set'_Inst",_) $ _ $ _ ) a =SOME a
|
wneuper@59601
|
114 |
| get_t _ (Const ("Prog_Tac.Calculate",_) $ _ $ a) _ = SOME a
|
wneuper@59601
|
115 |
| get_t _ (Const ("Prog_Tac.Calculate",_) $ _ ) a = SOME a
|
wneuper@59601
|
116 |
| get_t _ (Const ("Prog_Tac.Substitute",_) $ _ $ a) _ = SOME a
|
wneuper@59601
|
117 |
| get_t _ (Const ("Prog_Tac.Substitute",_) $ _ ) a = SOME a
|
wneuper@59601
|
118 |
|
wneuper@59601
|
119 |
| get_t _ (Const ("Prog_Tac.SubProblem",_) $ _ $ _) _ = NONE
|
wneuper@59601
|
120 |
|
wneuper@59601
|
121 |
| get_t _ _ _ = ((*tracing ("### get_t yac: list-expr "^(term2str x));*) NONE)
|
wneuper@59601
|
122 |
in get_t thy body Rule.e_term end
|
wneuper@59601
|
123 |
| get_stac _ t = error ("get_stac: no fun-def. for " ^ Rule.term2str t);
|
wneuper@59601
|
124 |
|
walther@59635
|
125 |
(* substitute the Istate.T's environment to a leaf of the program
|
wneuper@59601
|
126 |
and attach the curried argument of a tactic, if any.
|
walther@59637
|
127 |
CAUTION: (1) currying with #> requires 2 patterns for each tactic
|
wneuper@59601
|
128 |
(2) the non-curried version must return NONE for a
|
wneuper@59601
|
129 |
(3) non-matching patterns become an Celem.Expr by fall-through.
|
wneuper@59601
|
130 |
WN060906 quick and dirty fix: due to (2) a is returned, too *)
|
walther@59635
|
131 |
fun subst_stacexpr E _ _ (t as (*1*)(Const ("Prog_Tac.Rewrite",_) $ _ $ _)) =
|
wneuper@59601
|
132 |
(NONE, Celem.STac (subst_atomic E t))
|
walther@59635
|
133 |
| subst_stacexpr E a v (t as (*2*)(Const ("Prog_Tac.Rewrite",_) $ _)) =
|
wneuper@59601
|
134 |
(a, (*in these cases we hope, that a = SOME _*)
|
wneuper@59601
|
135 |
Celem.STac (case a of SOME a' => (subst_atomic E (t $ a'))
|
wneuper@59601
|
136 |
| NONE => ((subst_atomic E t) $ v)))
|
walther@59635
|
137 |
| subst_stacexpr E _ _ (t as (*1*)(Const ("Prog_Tac.Rewrite'_Inst", _) $ _ $ _ $ _)) =
|
wneuper@59601
|
138 |
(NONE, Celem.STac (subst_atomic E t))
|
walther@59635
|
139 |
| subst_stacexpr E a v (t as (*2*)(Const ("Prog_Tac.Rewrite'_Inst", _) $ _ $ _)) =
|
wneuper@59601
|
140 |
(a, Celem.STac (case a of SOME a' => subst_atomic E (t $ a')
|
wneuper@59601
|
141 |
| NONE => ((subst_atomic E t) $ v)))
|
walther@59635
|
142 |
| subst_stacexpr E _ _ (t as (*1*)(Const ("Prog_Tac.Rewrite'_Set", _) $ _ $ _)) =
|
wneuper@59601
|
143 |
(NONE, Celem.STac (subst_atomic E t))
|
walther@59635
|
144 |
| subst_stacexpr E a v (t as (*2*)(Const ("Prog_Tac.Rewrite'_Set", _) $ _)) =
|
wneuper@59601
|
145 |
(a, Celem.STac (case a of SOME a' => subst_atomic E (t $ a')
|
wneuper@59601
|
146 |
| NONE => ((subst_atomic E t) $ v)))
|
wneuper@59601
|
147 |
| subst_stacexpr E _ _
|
walther@59635
|
148 |
(t as (*1*)(Const ("Prog_Tac.Rewrite'_Set'_Inst", _) $ _ $ _ $ _)) =
|
wneuper@59601
|
149 |
(NONE, Celem.STac (subst_atomic E t))
|
wneuper@59601
|
150 |
| subst_stacexpr E a v
|
walther@59635
|
151 |
(t as (*2*)(Const ("Prog_Tac.Rewrite'_Set'_Inst", _) $ _ $ _)) =
|
wneuper@59601
|
152 |
(a, Celem.STac (case a of SOME a' => subst_atomic E (t $ a')
|
wneuper@59601
|
153 |
| NONE => ((subst_atomic E t) $ v)))
|
wneuper@59601
|
154 |
| subst_stacexpr E _ _ (t as (Const ("Prog_Tac.Calculate", _) $ _ $ _)) =
|
wneuper@59601
|
155 |
(NONE, Celem.STac (subst_atomic E t))
|
wneuper@59601
|
156 |
| subst_stacexpr E a v (t as (Const ("Prog_Tac.Calculate", _) $ _)) =
|
wneuper@59601
|
157 |
(a, Celem.STac (case a of SOME a' => subst_atomic E (t $ a')
|
wneuper@59601
|
158 |
| NONE => ((subst_atomic E t) $ v)))
|
wneuper@59601
|
159 |
| subst_stacexpr E _ _
|
wneuper@59601
|
160 |
(t as (Const ("Prog_Tac.Check'_elementwise",_) $ _ $ _)) =
|
wneuper@59601
|
161 |
(NONE, Celem.STac (subst_atomic E t))
|
wneuper@59601
|
162 |
| subst_stacexpr E a v (t as (Const ("Prog_Tac.Check'_elementwise", _) $ _)) =
|
wneuper@59601
|
163 |
(a, Celem.STac (case a of SOME a' => subst_atomic E (t $ a')
|
wneuper@59601
|
164 |
| NONE => ((subst_atomic E t) $ v)))
|
wneuper@59601
|
165 |
| subst_stacexpr E _ _ (t as (Const ("Prog_Tac.Or'_to'_List", _) $ _)) =
|
wneuper@59601
|
166 |
(NONE, Celem.STac (subst_atomic E t))
|
wneuper@59601
|
167 |
| subst_stacexpr E a v (t as (Const ("Prog_Tac.Or'_to'_List", _))) = (*t $ v*)
|
wneuper@59601
|
168 |
(a, Celem.STac (case a of SOME a' => subst_atomic E (t $ a')
|
wneuper@59601
|
169 |
| NONE => ((subst_atomic E t) $ v)))
|
wneuper@59601
|
170 |
| subst_stacexpr E _ _ (t as (Const ("Prog_Tac.SubProblem", _) $ _ $ _)) =
|
wneuper@59601
|
171 |
(NONE, Celem.STac (subst_atomic E t))
|
wneuper@59601
|
172 |
| subst_stacexpr E _ _ (t as (Const ("Prog_Tac.Take",_) $ _)) =
|
wneuper@59601
|
173 |
(NONE, Celem.STac (subst_atomic E t))
|
wneuper@59601
|
174 |
| subst_stacexpr E _ _ (t as (Const ("Prog_Tac.Substitute", _) $ _ $ _)) =
|
wneuper@59601
|
175 |
(NONE, Celem.STac (subst_atomic E t))
|
wneuper@59601
|
176 |
| subst_stacexpr E a v (t as (Const ("Prog_Tac.Substitute", _) $ _)) =
|
wneuper@59601
|
177 |
(a, Celem.STac (case a of SOME a' => subst_atomic E (t $ a')
|
wneuper@59601
|
178 |
| NONE => ((subst_atomic E t) $ v)))
|
wneuper@59601
|
179 |
(*now all tactics are matched out and this leaf must be without a tactic*)
|
wneuper@59601
|
180 |
| subst_stacexpr E a v t =
|
walther@59697
|
181 |
(a, Celem.Expr (subst_atomic (case a of SOME a => Env.update E (a,v) | NONE => E) t));
|
wneuper@59601
|
182 |
|
wneuper@59601
|
183 |
(**)end(**)
|
wneuper@59601
|
184 |
\<close> ML \<open>
|
wneuper@59601
|
185 |
\<close>
|
wneuper@59601
|
186 |
subsection \<open>TODO\<close>
|
wneuper@59601
|
187 |
ML \<open>
|
wneuper@59601
|
188 |
\<close> ML \<open>
|
wneuper@59601
|
189 |
\<close> ML \<open>
|
wneuper@59601
|
190 |
\<close>
|
wneuper@59601
|
191 |
end
|