walther@59902
|
1 |
(* Title: "ProgLang/evaluate.sml"
|
walther@60278
|
2 |
test calculation of values for function constants
|
neuper@38022
|
3 |
Author: Walther Neuper 2000
|
neuper@38022
|
4 |
(c) copyright due to lincense terms.
|
neuper@37906
|
5 |
*)
|
neuper@37906
|
6 |
|
neuper@38022
|
7 |
"--------------------------------------------------------";
|
neuper@38022
|
8 |
"table of contents --------------------------------------";
|
neuper@38022
|
9 |
"--------------------------------------------------------";
|
neuper@55366
|
10 |
"-calculate.thy: provides 'setup' -----------------------";
|
neuper@41924
|
11 |
"----------- fun norm -----------------------------------";
|
wneuper@59255
|
12 |
"----------- check return value of adhoc_thm ----";
|
wneuper@59411
|
13 |
"----------- fun calculate_ --------------------------------------------------------------------";
|
wneuper@59411
|
14 |
"----------- calculate from Prog --------------------------------- -----------------------------";
|
neuper@55366
|
15 |
"----------- calculate from script --requires 'setup'----";
|
neuper@38032
|
16 |
"----------- calculate check test-root-equ --------------";
|
walther@60317
|
17 |
"----------- check calculate bottom up -----------------";
|
walther@59603
|
18 |
"----------- Prog_Expr.pow Power.power_class.power ---------";
|
walther@60317
|
19 |
"----------- fun cancel_int --------------------------------------------------------------------";
|
walther@60317
|
20 |
"----------- RE-BUILD fun calcul ---------------------------------------------------------------";
|
neuper@38032
|
21 |
"----------- get_pair with 3 args -----------------------";
|
neuper@38032
|
22 |
"----------- calculate (2 * x is_const) -----------------";
|
wneuper@59387
|
23 |
"----------- fun get_pair: examples ------------------------------------------------------------";
|
wneuper@59387
|
24 |
"----------- fun adhoc_thm: examples -----------------------------------------------------------";
|
wneuper@59403
|
25 |
"----------- fun power -------------------------------------------------------------------------";
|
wneuper@59403
|
26 |
"----------- fun divisors ----------------------------------------------------------------------";
|
wneuper@59403
|
27 |
"----------- fun doubles, fun squfact ----------------------------------------------------------";
|
neuper@38022
|
28 |
"--------------------------------------------------------";
|
neuper@38022
|
29 |
"--------------------------------------------------------";
|
neuper@38022
|
30 |
"--------------------------------------------------------";
|
neuper@37906
|
31 |
|
wneuper@59255
|
32 |
"----------- check return value of adhoc_thm ----";
|
wneuper@59255
|
33 |
"----------- check return value of adhoc_thm ----";
|
wneuper@59255
|
34 |
"----------- check return value of adhoc_thm ----";
|
neuper@41924
|
35 |
val thy = @{theory "Poly"};
|
s1210629013@52153
|
36 |
val cal = snd (assoc_calc' thy "is_polyexp");
|
neuper@38022
|
37 |
val t = @{term "(x / x) is_polyexp"};
|
wneuper@59255
|
38 |
val SOME (thmID, thm) = adhoc_thm thy cal t;
|
wneuper@59188
|
39 |
(HOLogic.dest_Trueprop (Thm.prop_of thm); writeln "all thms wrapped by Trueprop")
|
neuper@38022
|
40 |
handle TERM _ =>
|
walther@59902
|
41 |
error "evaluate.sml: adhoc_thm must return Trueprop";
|
neuper@38022
|
42 |
|
wneuper@59411
|
43 |
"----------- fun calculate_ --------------------------------------------------------------------";
|
wneuper@59411
|
44 |
"----------- fun calculate_ --------------------------------------------------------------------";
|
wneuper@59411
|
45 |
"----------- fun calculate_ --------------------------------------------------------------------";
|
wneuper@59411
|
46 |
(* fun rewrite__set_ \<longrightarrow> fun rew_once works the same way *)
|
walther@60242
|
47 |
val t = TermC.str2term "((1+2)*4/3) \<up> 2";
|
wneuper@59411
|
48 |
val thy = @{theory};
|
walther@59919
|
49 |
val times = ("Groups.times_class.times", eval_binop "#mult_") : string * Eval_Def.eval_fn;
|
walther@60317
|
50 |
val plus = ("Groups.plus_class.plus", eval_binop "#add_") : string * Eval_Def.eval_fn;
|
walther@60317
|
51 |
val divide = ("Rings.divide_class.divide", eval_cancel "#divide_e") : string * Eval_Def.eval_fn;
|
walther@60317
|
52 |
val pow = ("Transcendental.powr", eval_binop "#power_") : string * Eval_Def.eval_fn;
|
wneuper@59411
|
53 |
|
walther@60317
|
54 |
"~~~~~ fun calculate_ , args:"; val (thy, isa_fn, t) = (thy, plus, t);
|
wneuper@59411
|
55 |
val SOME ("#: 1 + 2 = 3", adh_thm) = adhoc_thm @{theory} isa_fn t;
|
walther@59852
|
56 |
val SOME (t', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
|
walther@60242
|
57 |
if UnparseC.term t' = "(3 * 4 / 3) \<up> 2" then () else error "calculate_ 1 + 2 = 3 changed";
|
wneuper@59411
|
58 |
|
wneuper@59411
|
59 |
"~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, times, t');
|
wneuper@59411
|
60 |
val SOME ("#: 3 * 4 = 12", adh_thm) = adhoc_thm @{theory} isa_fn t';
|
walther@59852
|
61 |
val SOME (t'', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
|
walther@60242
|
62 |
if UnparseC.term t'' = "(12 / 3) \<up> 2" then () else error "calculate_ 3 * 4 = 12 changed";
|
wneuper@59411
|
63 |
|
wneuper@59411
|
64 |
"~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, divide, t'');
|
wneuper@59411
|
65 |
val SOME ("#divide_e12_3", adh_thm) = adhoc_thm @{theory} isa_fn t;
|
walther@59852
|
66 |
val SOME (t''', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
|
walther@60242
|
67 |
if UnparseC.term t''' = "4 \<up> 2" then () else error "calculate_ 12 / 3 = 4 changed";
|
wneuper@59411
|
68 |
|
wneuper@59411
|
69 |
"~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, pow, t''');
|
walther@60242
|
70 |
val SOME ("#: 4 \<up> 2 = 16", adh_thm) = adhoc_thm @{theory} isa_fn t;
|
walther@59852
|
71 |
val SOME (t'''', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
|
walther@59868
|
72 |
if UnparseC.term t'''' = "16" then () else error "calculate_ 12 / 3 = 4 changed";
|
wneuper@59411
|
73 |
|
wneuper@59411
|
74 |
"----------- calculate from Prog --------------------------------- -----------------------------";
|
wneuper@59411
|
75 |
"----------- calculate from Prog --------------------------------- -----------------------------";
|
wneuper@59411
|
76 |
"----------- calculate from Prog --------------------------------- -----------------------------";
|
neuper@41924
|
77 |
val thy = @{theory "Test"};
|
walther@60242
|
78 |
val fmz = ["realTestGiven (((1+2)*4/3) \<up> 2)", "realTestFind s"];
|
neuper@37906
|
79 |
val (dI',pI',mI') =
|
walther@60317
|
80 |
("Test", ["calculate", "test"], ["Test", "test_calculate"]);
|
neuper@38035
|
81 |
|
neuper@37906
|
82 |
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
|
neuper@37906
|
83 |
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
|
walther@60242
|
84 |
(*nxt =("Add_Given",Add_Given "realTestGiven (((#1 + #2) * #4 // #3) \<up> #2)")*)
|
neuper@37906
|
85 |
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
|
neuper@37906
|
86 |
(*nxt = ("Add_Find",Add_Find "realTestFind s") : string * tac*)
|
neuper@37906
|
87 |
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
|
neuper@38035
|
88 |
(*nxt = ("Specify_Theory",Specify_Theory "Test") : string * tac*)
|
neuper@37906
|
89 |
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
|
walther@59997
|
90 |
(*nxt = ("Specify_Problem",Specify_Problem ["calculate", "test"])*)
|
neuper@37906
|
91 |
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
|
walther@59997
|
92 |
(*nxt = ("Specify_Method",Specify_Method ("Test", "test_calculate"))*)
|
neuper@37906
|
93 |
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
|
walther@59997
|
94 |
(*nxt = ("Apply_Method",Apply_Method ("Test", "test_calculate"))*)
|
neuper@37906
|
95 |
|
walther@59713
|
96 |
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "PLUS")*)
|
walther@59713
|
97 |
(*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "TIMES")*)
|
walther@59713
|
98 |
(*[2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "DIVIDE")*)
|
walther@59713
|
99 |
(*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "POWER")*)
|
walther@59997
|
100 |
(*[4], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Check_Postcond",Check_Postcond ["calculate", "test"])*)
|
walther@59713
|
101 |
(*[], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("End_Proof'",End_Proof')*)
|
walther@59959
|
102 |
case f of Test_Out.FormKF "16" => () | _ =>
|
walther@59902
|
103 |
error "evaluate.sml: script test_calculate changed behaviour";
|
neuper@37906
|
104 |
|
neuper@37906
|
105 |
|
neuper@38032
|
106 |
"----------- calculate check test-root-equ --------------";
|
neuper@38032
|
107 |
"----------- calculate check test-root-equ --------------";
|
neuper@38032
|
108 |
"----------- calculate check test-root-equ --------------";
|
neuper@37906
|
109 |
(*(1): 2nd Test_simplify didn't work:
|
neuper@37906
|
110 |
val ct =
|
walther@60329
|
111 |
"sqrt (x \<up> 2 + -3 * x) = (-3 + 2 * x + - 1 * (9 + 4 * x)) / (- 1 * 2)"
|
neuper@37906
|
112 |
> val rls = ("Test_simplify");
|
neuper@37906
|
113 |
> val (ct,_) = the (rewrite_set thy' ("tval_rls") false rls ct);
|
walther@60242
|
114 |
val ct = "sqrt (x \<up> 2 + -3 * x) =
|
walther@60329
|
115 |
(-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))";
|
neuper@37906
|
116 |
ie. cancel does not work properly
|
neuper@37906
|
117 |
*)
|
wneuper@59382
|
118 |
val thy = @{theory "Test"};
|
walther@59686
|
119 |
val op_ = the (LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE"));
|
walther@60337
|
120 |
val ct = @{term
|
walther@60329
|
121 |
"sqrt (x \<up> 2 + -3 * x) = (-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))"};
|
wneuper@59382
|
122 |
case calculate_ thy op_ ct of
|
wneuper@59382
|
123 |
SOME _ => ()
|
wneuper@59382
|
124 |
| NONE => error "calculate_ test-root-equ changed";
|
neuper@37906
|
125 |
(*
|
walther@60242
|
126 |
sqrt (x \<up> 2 + -3 * x) =\
|
walther@60329
|
127 |
\(-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))
|
neuper@37906
|
128 |
............... does not work *)
|
neuper@37906
|
129 |
|
neuper@37906
|
130 |
(*--------------(2): does divide work in Test_simplify ?: ------*)
|
akargl@42188
|
131 |
val thy = @{theory Test};
|
walther@60340
|
132 |
val t = (Thm.term_of o the o (TermC.parse thy)) "6 / 2";
|
neuper@37906
|
133 |
val rls = Test_simplify;
|
neuper@37906
|
134 |
val (t,_) = the (rewrite_set_ thy false rls t);
|
walther@59997
|
135 |
(*val t = Free ("3", "Real.real") : term*)
|
neuper@37906
|
136 |
|
neuper@37906
|
137 |
(*--------------(3): is_const works ?: -------------------------------------*)
|
walther@60340
|
138 |
val t = (Thm.term_of o the o (TermC.parse @{theory Test})) "2 is_const";
|
walther@60230
|
139 |
TermC.atomty t;
|
akargl@42188
|
140 |
rewrite_set_ @{theory Test} false tval_rls t;
|
wenzelm@60309
|
141 |
(*val it = SOME (Const (\<^const_name>\<open>True\<close>, "bool"),[]) ... works*)
|
neuper@37906
|
142 |
|
walther@60230
|
143 |
val t = TermC.str2term "2 * x is_const";
|
wneuper@59592
|
144 |
val SOME (str,t') = eval_const "" "" t (@{theory "Isac_Knowledge"});
|
walther@59868
|
145 |
UnparseC.term t';
|
neuper@37906
|
146 |
|
neuper@37906
|
147 |
|
neuper@38032
|
148 |
"----------- check calculate bottom up ------------------";
|
neuper@38032
|
149 |
"----------- check calculate bottom up ------------------";
|
neuper@38032
|
150 |
"----------- check calculate bottom up ------------------";
|
neuper@37906
|
151 |
(*-------------- eval_cancel works: *)
|
walther@60330
|
152 |
Rewrite.trace_on := false; (*true false*)
|
akargl@42188
|
153 |
val thy = @{theory Test};
|
wneuper@59384
|
154 |
val rls = Test_simplify;
|
walther@60340
|
155 |
val t = (Thm.term_of o the o (TermC.parse thy)) "(-4) / 2";
|
akargl@42188
|
156 |
|
wenzelm@60309
|
157 |
val SOME (_, t) = eval_cancel "xxx" \<^const_name>\<open>divide\<close> t thy;
|
akargl@42188
|
158 |
|
neuper@37906
|
159 |
(*--------------(5): reproduce (1) with simpler term: ------------*)
|
walther@60340
|
160 |
val t = (Thm.term_of o the o (TermC.parse thy)) "(3+5)/2";
|
wneuper@59384
|
161 |
case rewrite_set_ thy false rls t of
|
walther@60317
|
162 |
SOME (t', []) =>
|
walther@60317
|
163 |
if UnparseC.term t' = "4" then ()
|
walther@60317
|
164 |
else error "rewrite_set_ (3+5)/2 changed 1"
|
walther@60317
|
165 |
| _ => error "rewrite_set_ (3+5)/2 changed 2";
|
neuper@37906
|
166 |
|
walther@60340
|
167 |
val t = (Thm.term_of o the o (TermC.parse thy)) "(3+1+2*x)/2";
|
wneuper@59384
|
168 |
case rewrite_set_ thy false rls t of
|
walther@60356
|
169 |
SOME (t', _) =>
|
walther@60324
|
170 |
if UnparseC.term t' = "2 + x" then () else error "rewrite_set_ (3+1+2*x)/2 changed 1"
|
walther@60317
|
171 |
| _ => error "rewrite_set_ (3+1+2*x)/2 changed 2";
|
neuper@37906
|
172 |
|
walther@60330
|
173 |
Rewrite.trace_on := false; (*true false*)
|
akargl@42218
|
174 |
|
walther@59901
|
175 |
(*--- Rewrite.trace_on before correction of ... --------------------
|
walther@60329
|
176 |
val ct = "(-3 + 2 * x + - 1) / 2";
|
neuper@37906
|
177 |
val (ct,_) = the (rewrite_set thy' false rls ct);
|
neuper@37906
|
178 |
:
|
neuper@37906
|
179 |
### trying thm 'root_ge0_2'
|
walther@60329
|
180 |
### rewrite_set_: x + (- 1 + -3) / 2
|
neuper@37906
|
181 |
### trying thm 'radd_real_const_eq'
|
neuper@37906
|
182 |
### trying thm 'radd_real_const'
|
neuper@37906
|
183 |
### rewrite_set_: x + (-4) / 2
|
neuper@37906
|
184 |
### trying thm 'rcollect_right'
|
neuper@37906
|
185 |
:
|
neuper@37906
|
186 |
"x + (-4) / 2"
|
neuper@37906
|
187 |
-------------------------------------while before Isabelle20002:
|
walther@60329
|
188 |
val ct = "(#-3 + #2 * x + #- 1) // #2";
|
neuper@37906
|
189 |
val (ct,_) = the (rewrite_set thy' false rls ct);
|
neuper@37906
|
190 |
:
|
neuper@37906
|
191 |
### trying thm 'root_ge0_2'
|
walther@60329
|
192 |
### rewrite_set_: x + (#- 1 + #-3) // #2
|
neuper@37906
|
193 |
### trying thm 'radd_real_const_eq'
|
neuper@37906
|
194 |
### trying thm 'radd_real_const'
|
neuper@37906
|
195 |
### rewrite_set_: x + #-4 // #2
|
walther@60329
|
196 |
### rewrite_set_: x + #- 2
|
neuper@37906
|
197 |
### trying thm 'rcollect_right'
|
neuper@37906
|
198 |
:
|
walther@60329
|
199 |
"#- 2 + x"
|
neuper@37906
|
200 |
-----------------------------------------------------------------*)
|
neuper@37906
|
201 |
|
neuper@37906
|
202 |
|
neuper@37906
|
203 |
(*===================*)
|
walther@59901
|
204 |
Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
|
walther@60340
|
205 |
val t = (Thm.term_of o the o (TermC.parse thy)) "x + (- 1 + -3) / 2";
|
wneuper@59384
|
206 |
val SOME (res, []) = rewrite_set_ thy false rls t;
|
walther@60329
|
207 |
if UnparseC.term res = "- 2 + x" then () else error "rewrite_set_ x + (- 1 + -3) / 2 changed";
|
neuper@37906
|
208 |
"x + (-4) / 2";
|
neuper@37906
|
209 |
(*
|
neuper@37906
|
210 |
### trying calc. 'cancel'
|
neuper@37906
|
211 |
@@@ get_pair: binop, t = x + (-4) / 2
|
neuper@37906
|
212 |
@@@ get_pair: t else
|
neuper@38032
|
213 |
@@@ get_pair: t else -> NONE
|
neuper@37906
|
214 |
@@@ get_pair: binop, t = (-4) / 2
|
neuper@37906
|
215 |
@@@ get_pair: then 1
|
neuper@38032
|
216 |
@@@ get_pair: t -> NONE
|
neuper@38032
|
217 |
@@@ get_pair: t1 -> NONE
|
wneuper@59255
|
218 |
@@@ adhoc_thm': NONE
|
neuper@37906
|
219 |
### trying calc. 'pow'
|
neuper@37906
|
220 |
*)
|
neuper@37906
|
221 |
|
walther@59901
|
222 |
Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
|
neuper@37906
|
223 |
|
walther@59902
|
224 |
" ================= evaluate.sml: calculate_ 2002 =================== ";
|
walther@59902
|
225 |
" ================= evaluate.sml: calculate_ 2002 =================== ";
|
walther@59902
|
226 |
" ================= evaluate.sml: calculate_ 2002 =================== ";
|
neuper@37906
|
227 |
|
akargl@42188
|
228 |
val thy = @{theory Test};
|
walther@60340
|
229 |
val t = (Thm.term_of o the o (TermC.parse thy)) "12 / 3";
|
walther@59686
|
230 |
val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
|
neuper@38032
|
231 |
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
|
neuper@37906
|
232 |
"12 / 3 = 4";
|
akargl@42188
|
233 |
val thy = @{theory Test};
|
walther@60340
|
234 |
val t = (Thm.term_of o the o (TermC.parse thy)) "4 \<up> 2";
|
walther@59686
|
235 |
val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
|
neuper@38032
|
236 |
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
|
neuper@37906
|
237 |
"4 ^ 2 = 16";
|
neuper@37906
|
238 |
|
walther@60340
|
239 |
val t = (Thm.term_of o the o (TermC.parse thy)) "((1 + 2) * 4 / 3) \<up> 2";
|
walther@59686
|
240 |
val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t;
|
neuper@37906
|
241 |
"1 + 2 = 3";
|
neuper@38032
|
242 |
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
|
walther@59868
|
243 |
UnparseC.term t;
|
walther@60242
|
244 |
"(3 * 4 / 3) \<up> 2";
|
walther@59686
|
245 |
val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES")))t;
|
neuper@37906
|
246 |
"3 * 4 = 12";
|
neuper@38032
|
247 |
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
|
walther@59868
|
248 |
UnparseC.term t;
|
walther@60242
|
249 |
"(12 / 3) \<up> 2";
|
walther@59686
|
250 |
val SOME (thmID,thm) =adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
|
neuper@37906
|
251 |
"12 / 3 = 4";
|
neuper@38032
|
252 |
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
|
walther@59868
|
253 |
UnparseC.term t;
|
walther@60242
|
254 |
"4 \<up> 2";
|
walther@59686
|
255 |
val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")))t;
|
walther@60242
|
256 |
"4 \<up> 2 = 16";
|
neuper@38032
|
257 |
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
|
walther@59868
|
258 |
UnparseC.term t;
|
neuper@37906
|
259 |
"16";
|
walther@59902
|
260 |
if it <> "16" then error "evaluate.sml: new behaviour in calculate_"
|
neuper@37906
|
261 |
else ();
|
neuper@37906
|
262 |
|
neuper@37906
|
263 |
(*13.9.02 *** calc: operator = pow not defined*)
|
walther@60340
|
264 |
val t = (Thm.term_of o the o (TermC.parse thy)) "3 \<up> 2";
|
neuper@38032
|
265 |
val SOME (thmID,thm) =
|
walther@59686
|
266 |
adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
|
neuper@37906
|
267 |
(*** calc: operator = pow not defined*)
|
neuper@37906
|
268 |
|
walther@59686
|
269 |
val (op_, eval_fn) = the (LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"));
|
neuper@37906
|
270 |
(*
|
wenzelm@60309
|
271 |
val op_ = \<^const_name>\<open>powr\<close> : string
|
neuper@37906
|
272 |
val eval_fn = fn : string -> term -> theory -> (string * term) option*)
|
neuper@37906
|
273 |
|
neuper@38032
|
274 |
val SOME (thmid,t') = get_pair thy op_ eval_fn t;
|
neuper@37906
|
275 |
(*** calc: operator = pow not defined*)
|
neuper@37906
|
276 |
|
neuper@38032
|
277 |
val SOME (id,t') = eval_fn op_ t thy;
|
neuper@37906
|
278 |
(*** calc: operator = pow not defined*)
|
neuper@37906
|
279 |
|
walther@60317
|
280 |
case (op_, t) of
|
walther@60317
|
281 |
("Transcendental.powr",
|
walther@60336
|
282 |
Const (\<^const_name>\<open>powr\<close>, _) $ (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit1\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _))) $
|
walther@60336
|
283 |
(Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)))) => ()
|
walther@60317
|
284 |
| _ => error "3 \<up> 2 CHANGED";
|
walther@60317
|
285 |
val SOME (id, t') = eval_binop thmid op_ t thy;
|
neuper@37906
|
286 |
(*** calc: operator = pow not defined*)
|
neuper@37906
|
287 |
|
walther@60317
|
288 |
if UnparseC.term t' = "3 \<up> 2 = 9" then () else error "eval_binop 3 \<up> 2 = 9 CHANGED";
|
walther@60317
|
289 |
|
walther@60317
|
290 |
|
walther@60317
|
291 |
"----------- fun cancel_int --------------------------------------------------------------------";
|
walther@60317
|
292 |
"----------- fun cancel_int --------------------------------------------------------------------";
|
walther@60317
|
293 |
"----------- fun cancel_int --------------------------------------------------------------------";
|
walther@60317
|
294 |
if cancel_int (~4, 2) = (~1, (2, 1)) then () else error "cancel_int (~4, 2) CHANGED";
|
walther@60317
|
295 |
if cancel_int (4, ~8) = (~1, (1, 2)) then () else error "cancel_int (4, ~8) CHANGED";
|
walther@60317
|
296 |
if cancel_int (6, 4) = (1, (3, 2)) then () else error "cancel_int (6, 4)CHANGED";
|
walther@60317
|
297 |
|
walther@60317
|
298 |
|
walther@60317
|
299 |
"----------- RE-BUILD fun calcul ---------------------------------------------------------------";
|
walther@60317
|
300 |
"----------- RE-BUILD fun calcul ---------------------------------------------------------------";
|
walther@60317
|
301 |
"----------- RE-BUILD fun calcul ---------------------------------------------------------------";
|
walther@60317
|
302 |
val (t1, t2) = (@{term 3}, @{term "2::real"});
|
walther@60317
|
303 |
|
walther@60317
|
304 |
"~~~~~ fun calcul , args:"; val (op_, (t1, t2)) = ("Groups.plus_class.plus", (t1, t2));
|
walther@60336
|
305 |
val (Const (\<^const_name>\<open>numeral\<close>, _) $ n1) = t1;
|
walther@60336
|
306 |
val (Const (\<^const_name>\<open>numeral\<close>, _) $ n2) = t2;
|
walther@60317
|
307 |
val (T, _) = HOLogic.dest_number t1
|
walther@60317
|
308 |
val (i1, i2) = (HOLogic.dest_numeral n1, HOLogic.dest_numeral n2)
|
walther@60317
|
309 |
val result =
|
walther@60317
|
310 |
case op_ of
|
walther@60317
|
311 |
"Groups.plus_class.plus" => i1 + i2
|
walther@60317
|
312 |
| "Groups.minus_class.minus" => i1 - i2
|
walther@60317
|
313 |
| "Groups.times_class.times" => i1 * i2
|
walther@60317
|
314 |
| "Transcendental.powr" => power i1 i2
|
walther@60317
|
315 |
| str => raise ERROR ("calcul not impl.for op_ " ^ str)
|
walther@60317
|
316 |
(*in*)
|
walther@60317
|
317 |
val xxx = HOLogic.mk_number T result;
|
walther@60317
|
318 |
(*end*)
|
walther@60317
|
319 |
case HOLogic.dest_number xxx of
|
walther@60317
|
320 |
(_, 5) => ()
|
walther@60317
|
321 |
| _ => error "calcul + 2 3 CHANGED";
|
walther@60317
|
322 |
|
walther@60317
|
323 |
case HOLogic.dest_number (calcul "Groups.minus_class.minus" (t1, t2)) of
|
walther@60317
|
324 |
(_, 1) => xxx
|
walther@60317
|
325 |
| _ => error "calcul - 2 3 CHANGED";
|
walther@60317
|
326 |
|
walther@60317
|
327 |
case HOLogic.dest_number (calcul "Groups.times_class.times" (t1, t2)) of
|
walther@60317
|
328 |
(_, 6) => xxx
|
walther@60317
|
329 |
| _ => error "calcul - 2 3 CHANGED";
|
walther@60317
|
330 |
|
walther@60317
|
331 |
(* (calcul "Rings.divide_class.divide" (t1, t2)
|
walther@60317
|
332 |
ERROR: calcul not impl.for op_ Rings.divide_class.divide*)
|
walther@60317
|
333 |
|
walther@60317
|
334 |
case HOLogic.dest_number (calcul "Transcendental.powr" (t1, t2)) of
|
walther@60317
|
335 |
(_, 9) => xxx
|
walther@60317
|
336 |
| _ => error "calcul - 2 3 CHANGED";
|
walther@60317
|
337 |
|
akargl@42188
|
338 |
|
neuper@37906
|
339 |
"----------- get_pair with 3 args --------------------------------";
|
neuper@37906
|
340 |
"----------- get_pair with 3 args --------------------------------";
|
neuper@37906
|
341 |
"----------- get_pair with 3 args --------------------------------";
|
neuper@37906
|
342 |
val (thy, op_, ef, arg) =
|
walther@60278
|
343 |
(thy, "EqSystem.occur_exactly_in",
|
wneuper@59462
|
344 |
assoc_calc' (@{theory "EqSystem"}) "occur_exactly_in" |> snd |> snd,
|
walther@60230
|
345 |
TermC.str2term
|
walther@60329
|
346 |
"[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2"
|
neuper@37906
|
347 |
);
|
neuper@38032
|
348 |
val SOME (str, simpl) = get_pair thy op_ ef arg;
|
neuper@37906
|
349 |
if str =
|
walther@60317
|
350 |
"[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2 = True"
|
walther@59902
|
351 |
then () else error "evaluate.sml get_pair with 3 args:occur_exactly_in";
|
neuper@37906
|
352 |
|
neuper@37906
|
353 |
|
neuper@38032
|
354 |
"----------- calculate (2 * x is_const) -----------------";
|
neuper@38032
|
355 |
"----------- calculate (2 * x is_const) -----------------";
|
neuper@38032
|
356 |
"----------- calculate (2 * x is_const) -----------------";
|
walther@60230
|
357 |
val t = TermC.str2term "2 * x is_const";
|
akargl@42188
|
358 |
val SOME (str, t') = eval_const "" "" t @{theory Test};
|
walther@60317
|
359 |
if UnparseC.term t' = "(2 * x is_const) = False" then ()
|
walther@60317
|
360 |
else error "eval_const 2 * x is_const CHANGED";
|
neuper@37906
|
361 |
|
akargl@42188
|
362 |
val SOME (t',_) = rewrite_set_ @{theory Test} false tval_rls t;
|
walther@60317
|
363 |
if UnparseC.term t' = "False" then ()
|
walther@60317
|
364 |
else error "rewrite_set_ 2 * x is_const CHANGED";
|
wneuper@59387
|
365 |
|
wneuper@59387
|
366 |
"----------- fun get_pair: examples ------------------------------------------------------------";
|
wneuper@59387
|
367 |
"----------- fun get_pair: examples ------------------------------------------------------------";
|
wneuper@59387
|
368 |
"----------- fun get_pair: examples ------------------------------------------------------------";
|
wneuper@59388
|
369 |
val thy = @{theory};
|
walther@59686
|
370 |
val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
|
walther@60317
|
371 |
if isa_str = "Groups.plus_class.plus" then () else error "eval_fn PLUS changed";
|
wneuper@59388
|
372 |
|
walther@60317
|
373 |
val t = @{term "3 + 4 :: real"};
|
wneuper@59388
|
374 |
val SOME (str, term) = get_pair thy isa_str eval_fn t;
|
walther@60317
|
375 |
(*+*)if str = "#: 3 + 4 = 7" andalso UnparseC.term term = "3 + 4 = 7"
|
walther@60317
|
376 |
(*+*)then () else error "get_pair 3 + 4 changed";
|
wneuper@59388
|
377 |
|
walther@60317
|
378 |
val t = @{term "(a + 3) + 4 :: real"};
|
wneuper@59388
|
379 |
val SOME (str, term) = get_pair thy isa_str eval_fn t;
|
walther@59868
|
380 |
if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
|
wneuper@59388
|
381 |
then () else error "get_pair (a + 3) + 4 changed";
|
wneuper@59388
|
382 |
|
walther@60317
|
383 |
val t = @{term "(a + 3) + 4 :: real"};
|
wneuper@59388
|
384 |
val SOME (str, term) = get_pair thy isa_str eval_fn t;
|
walther@59868
|
385 |
if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
|
wneuper@59388
|
386 |
then () else error "get_pair (a + 3) + 4 changed";
|
wneuper@59388
|
387 |
|
walther@60317
|
388 |
val t = @{term "x = 5 * (3 + (4 + a) :: real)"};
|
wneuper@59388
|
389 |
val SOME (str, term) = get_pair thy isa_str eval_fn t;
|
walther@59868
|
390 |
if str = "#: 3 + (4 + a) = 7 + a" andalso UnparseC.term term = "3 + (4 + a) = 7 + a"
|
wneuper@59388
|
391 |
then ((* !!! gets subterm !!!*)) else error "get_pair x = 5 * (3 + (4 + a)) (subterm) changed";
|
wneuper@59388
|
392 |
|
walther@59686
|
393 |
val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
|
wneuper@59388
|
394 |
|
walther@60329
|
395 |
val t = @{term "-4 / - 2 :: real"};
|
wneuper@59388
|
396 |
val SOME (str, term) = get_pair thy isa_str eval_fn t;
|
walther@60317
|
397 |
if str = "#divide_e~4_~2" andalso UnparseC.term term = "- 4 / - 2 = 2"
|
walther@60329
|
398 |
then () else error "get_pair -4 / - 2 changed";
|
wneuper@59388
|
399 |
|
walther@59686
|
400 |
val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "POWER");
|
wneuper@59388
|
401 |
|
walther@60317
|
402 |
val t = @{term "2 \<up> 3 :: real"};
|
wneuper@59388
|
403 |
val SOME (str, term) = get_pair thy isa_str eval_fn t;
|
walther@60242
|
404 |
if str = "#: 2 \<up> 3 = 8" andalso UnparseC.term term = "2 \<up> 3 = 8"
|
walther@60242
|
405 |
then () else error "get_pair 2 \<up> 3 changed";
|
wneuper@59388
|
406 |
|
wneuper@59387
|
407 |
"----------- fun adhoc_thm: examples -----------------------------------------------------------";
|
wneuper@59387
|
408 |
"----------- fun adhoc_thm: examples -----------------------------------------------------------";
|
wneuper@59387
|
409 |
"----------- fun adhoc_thm: examples -----------------------------------------------------------";
|
wneuper@59388
|
410 |
(*--------------------------------------------------------------------vvvvvvvvvv*)
|
walther@59686
|
411 |
val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "is_const");
|
walther@60317
|
412 |
val t = @{term "9 is_const"};
|
wneuper@59388
|
413 |
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
|
walther@59876
|
414 |
if str = "#is_const_9_" andalso ThmC_Def.string_of_thm thm = "(9 is_const) = True"
|
wneuper@59388
|
415 |
then () else error "adhoc_thm 9 is_const changed";
|
wneuper@59387
|
416 |
|
wenzelm@60309
|
417 |
case assoc_calc thy \<^const_name>\<open>less\<close> of
|
wneuper@59388
|
418 |
"le" => () | _ => error "Orderings.ord_class.less <-> le changed";
|
walther@59686
|
419 |
val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "le");
|
walther@60317
|
420 |
if isa_str = "Orderings.ord_class.less" then () else error "adhoc_thm (4 < 4) = False CHANGED";
|
wneuper@59387
|
421 |
|
walther@60317
|
422 |
val t = @{term "4 < (4 :: real)"};
|
wneuper@59388
|
423 |
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
|
walther@59876
|
424 |
if str = "#less_4_4" andalso ThmC_Def.string_of_thm thm = "(4 < 4) = False"
|
wneuper@59388
|
425 |
then () else error "adhoc_thm 4 < 4 changed";
|
wneuper@59387
|
426 |
|
wneuper@59388
|
427 |
val SOME t = parseNEW @{context} "a < 4";
|
wneuper@59388
|
428 |
case adhoc_thm thy (isa_str, eval_fn) t of
|
wneuper@59388
|
429 |
NONE => () | _ => error "adhoc_thm a < 4 does NOT result in NONE";
|
wneuper@59387
|
430 |
|
walther@59686
|
431 |
val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
|
walther@60317
|
432 |
val SOME t = parseNEW @{context} "1 + (2::real)";
|
wneuper@59388
|
433 |
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
|
walther@59876
|
434 |
if str = "#: 1 + 2 = 3" andalso ThmC_Def.string_of_thm thm = "1 + 2 = 3"
|
wneuper@59388
|
435 |
then () else error "adhoc_thm 1 + 2 changed";
|
wneuper@59387
|
436 |
|
walther@59686
|
437 |
val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
|
walther@60317
|
438 |
val t = @{term "6 / -8 :: real"};
|
wneuper@59388
|
439 |
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
|
walther@60317
|
440 |
if str = "#divide_e6_~8" andalso ThmC_Def.string_of_thm thm = "6 / - 8 = - 3 / 4"
|
walther@60317
|
441 |
then () else error "adhoc_thm 6 / -8 = - 3 / 4 changed";
|
wneuper@59387
|
442 |
|
walther@59603
|
443 |
case assoc_calc thy "Prog_Expr.ident" of
|
walther@59603
|
444 |
"ident" => () | _ => error "Prog_Expr.ident <-> ident changed";
|
walther@59686
|
445 |
val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "ident");
|
wneuper@59387
|
446 |
|
walther@60317
|
447 |
val t = @{term "3 =!= (3 :: real)"};
|
wneuper@59388
|
448 |
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
|
walther@59876
|
449 |
if str = "#ident_(3)_(3)" andalso ThmC_Def.string_of_thm thm = "(3 =!= 3) = True"
|
wneuper@59388
|
450 |
then () else error "adhoc_thm (3 =!= 3) changed";
|
wneuper@59387
|
451 |
|
walther@60317
|
452 |
val t = @{term "\<not> ((4 :: real) + (4 * x + x \<up> 2) =!= 0)"};
|
wneuper@59388
|
453 |
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
|
walther@60317
|
454 |
if str = "#ident_(4 + (4 * x + x \<up> 2))_(0)" andalso ThmC_Def.string_of_thm thm = "(4 + (4 * x + x \<up> 2) =!= 0) = False"
|
wneuper@59388
|
455 |
then () else error "adhoc_thm (\<not> (4 + (4 * x + x ^ 2) =!= 0)) changed";
|
wneuper@59403
|
456 |
|
walther@60329
|
457 |
"----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
|
walther@60329
|
458 |
"----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
|
walther@60329
|
459 |
"----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
|
walther@60329
|
460 |
val t = TermC.str2term "sqrt 4";
|
walther@60329
|
461 |
|
walther@60330
|
462 |
(* TOODOO.1: exception TYPE raised by Skip_Proof.make_thm * )
|
walther@60329
|
463 |
exception TYPE raised (line 169 of "consts.ML"): Illegal type
|
walther@60329
|
464 |
for constant "HOL.eq" :: real \<Rightarrow> (num \<Rightarrow> real) \<Rightarrow> bool (**)
|
walther@60329
|
465 |
Eval.adhoc_thm (ThyC.get_theory "Isac_Knowledge") ("NthRoot.sqrt", eval_sqrt "#sqrt_") t
|
walther@60329
|
466 |
( **)
|
walther@60329
|
467 |
"~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), ct) =
|
walther@60329
|
468 |
((ThyC.get_theory "Isac_Knowledge"),
|
walther@60329
|
469 |
("NthRoot.sqrt", eval_sqrt "#sqrt_": string -> term -> theory -> (string * term) option), t);
|
walther@60356
|
470 |
|
walther@60329
|
471 |
val SOME (thmid, t) =
|
walther@60329
|
472 |
(*case*) get_pair thy op_ eval_fn ct (*of*);
|
walther@60356
|
473 |
(*+*)val "sqrt 4 = 2" = UnparseC.term t;
|
walther@60356
|
474 |
|
walther@60329
|
475 |
(** )
|
walther@60356
|
476 |
Skip_Proof.make_thm thy t;
|
walther@60356
|
477 |
|
walther@60329
|
478 |
exception TYPE raised (line 169 of "consts.ML"): Illegal type
|
walther@60329
|
479 |
for constant "HOL.eq" :: real \<Rightarrow> (num \<Rightarrow> real) \<Rightarrow> bool (**)
|
walther@60329
|
480 |
( **)
|
walther@60329
|
481 |
|
wneuper@59403
|
482 |
"----------- fun power -------------------------------------------------------------------------";
|
wneuper@59403
|
483 |
"----------- fun power -------------------------------------------------------------------------";
|
wneuper@59403
|
484 |
"----------- fun power -------------------------------------------------------------------------";
|
wneuper@59403
|
485 |
if power 2 3 = 8 then () else error "power 2 3 = 8";
|
wneuper@59403
|
486 |
if power ~2 3 = ~8 then () else error "power ~2 3 = ~8";
|
wneuper@59403
|
487 |
if power ~3 2 = 9 then () else error "power ~3 2 = 9";
|
walther@60270
|
488 |
case \<^try>\<open> power 3 ~2 \<close> of
|
walther@60270
|
489 |
SOME _ => raise error "power 3 ~2: should raise an exn 1"
|
walther@60271
|
490 |
| NONE => ();
|
wneuper@59403
|
491 |
|
wneuper@59403
|
492 |
"----------- fun divisors ----------------------------------------------------------------------";
|
wneuper@59403
|
493 |
"----------- fun divisors ----------------------------------------------------------------------";
|
wneuper@59403
|
494 |
"----------- fun divisors ----------------------------------------------------------------------";
|
wneuper@59403
|
495 |
if divisors 30 = [5, 3, 2] then () else error "divisors 30 = [5, 3, 2]";
|
wneuper@59403
|
496 |
if divisors 32 = [2, 2, 2, 2, 2] then () else error "divisors 32 = [2, 2, 2, 2, 2]";
|
wneuper@59403
|
497 |
if divisors 60 = [5, 3, 2, 2] then () else error "divisors 60 = [5, 3, 2, 2]";
|
wneuper@59403
|
498 |
if divisors 11 = [11] then () else error "divisors 11 = [11]";
|
wneuper@59403
|
499 |
|
wneuper@59403
|
500 |
"----------- fun doubles, fun squfact ----------------------------------------------------------";
|
wneuper@59403
|
501 |
"----------- fun doubles, fun squfact ----------------------------------------------------------";
|
wneuper@59403
|
502 |
"----------- fun doubles, fun squfact ----------------------------------------------------------";
|
wneuper@59403
|
503 |
if doubles [2,3,4] = [] then () else error "doubles [2,3,4] changed";
|
wneuper@59403
|
504 |
if doubles [2,3,3,5,5,7] = [5, 3] then () else error "doubles [2,3,3,5,5,7] changed";
|
wneuper@59403
|
505 |
|
wneuper@59403
|
506 |
if squfact 30 = 1 then () else error "squfact 30 changed";
|
wneuper@59403
|
507 |
if squfact 32 = 4 then () else error "squfact 32 changed";
|
wneuper@59403
|
508 |
if squfact 60 = 2 then () else error "squfact 60 changed";
|
wneuper@59403
|
509 |
if squfact 11 = 1 then () else error "squfact 11 changed";
|