56 |
56 |
57 |
57 |
58 "-------- fun eval_is_even ---------------------------------------------------------------------"; |
58 "-------- fun eval_is_even ---------------------------------------------------------------------"; |
59 "-------- fun eval_is_even ---------------------------------------------------------------------"; |
59 "-------- fun eval_is_even ---------------------------------------------------------------------"; |
60 "-------- fun eval_is_even ---------------------------------------------------------------------"; |
60 "-------- fun eval_is_even ---------------------------------------------------------------------"; |
61 val t = TermC.parse_test @{context} "2 is_even"; |
61 val t = ParseC.parse_test @{context} "2 is_even"; |
62 eval_is_even "aaa" "Prog_Expr.is_even" t "ccc"; |
62 eval_is_even "aaa" "Prog_Expr.is_even" t "ccc"; |
63 "~~~~~ fun eval_is_even , args:"; val ((thmid:string), "Prog_Expr.is_even", (t as (Const _ $ arg)), _) = |
63 "~~~~~ fun eval_is_even , args:"; val ((thmid:string), "Prog_Expr.is_even", (t as (Const _ $ arg)), _) = |
64 ("aaa", "Prog_Expr.is_even", t, "ccc"); |
64 ("aaa", "Prog_Expr.is_even", t, "ccc"); |
65 (*if*) TermC.is_num arg (*then*); |
65 (*if*) TermC.is_num arg (*then*); |
66 val i = arg |> HOLogic.dest_number |> snd; |
66 val i = arg |> HOLogic.dest_number |> snd; |
69 SOME (TermC.mk_thmid thmid (string_of_int n) "", |
69 SOME (TermC.mk_thmid thmid (string_of_int n) "", |
70 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True}))); |
70 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True}))); |
71 if UnparseC.term t' = "(2 is_even) = True" then () else error "(2 is_even) = True CHANGED"; |
71 if UnparseC.term t' = "(2 is_even) = True" then () else error "(2 is_even) = True CHANGED"; |
72 |
72 |
73 |
73 |
74 val t = TermC.parse_test @{context} "3 is_even"; |
74 val t = ParseC.parse_test @{context} "3 is_even"; |
75 case eval_is_even "aaa" "Prog_Expr.is_even" t "ccc" of |
75 case eval_is_even "aaa" "Prog_Expr.is_even" t "ccc" of |
76 SOME (str, t') => |
76 SOME (str, t') => |
77 if str = "aaa_" andalso UnparseC.term t' = "(3 is_even) = False" then () |
77 if str = "aaa_" andalso UnparseC.term t' = "(3 is_even) = False" then () |
78 else error "eval_is_even (3 is_even) CHANGED 1" |
78 else error "eval_is_even (3 is_even) CHANGED 1" |
79 | NONE => error "eval_is_even (3 is_even) CHANGED 2"; |
79 | NONE => error "eval_is_even (3 is_even) CHANGED 2"; |
80 |
80 |
81 val t = TermC.parse_test @{context} "a ::real"; |
81 val t = ParseC.parse_test @{context} "a ::real"; |
82 val NONE = |
82 val NONE = |
83 eval_is_even "aaa" "Prog_Expr.is_even" t "ccc"; |
83 eval_is_even "aaa" "Prog_Expr.is_even" t "ccc"; |
84 case eval_is_even "aaa" "Prog_Expr.is_even" t "ccc" of |
84 case eval_is_even "aaa" "Prog_Expr.is_even" t "ccc" of |
85 SOME _ => error "eval_is_even (a is_even) CHANGED" |
85 SOME _ => error "eval_is_even (a is_even) CHANGED" |
86 | NONE => (); |
86 | NONE => (); |
93 val t = TermC.parseNEW' ctxt "2 is_num"; |
93 val t = TermC.parseNEW' ctxt "2 is_num"; |
94 case rewrite_set_ ctxt false tval_rls t of |
94 case rewrite_set_ ctxt false tval_rls t of |
95 SOME (Const (\<^const_name>\<open>True\<close>, _), []) => () |
95 SOME (Const (\<^const_name>\<open>True\<close>, _), []) => () |
96 | _ => error "2 is_num CHANGED"; |
96 | _ => error "2 is_num CHANGED"; |
97 |
97 |
98 val t = TermC.parse_test @{context} "2 * x is_num"; |
98 val t = ParseC.parse_test @{context} "2 * x is_num"; |
99 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t (@{theory "Isac_Knowledge"}); |
99 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t (@{theory "Isac_Knowledge"}); |
100 if UnparseC.term t' = "(2 * x is_num) = False" then () |
100 if UnparseC.term t' = "(2 * x is_num) = False" then () |
101 else error "(2 * x is_num) = False CHANGED"; |
101 else error "(2 * x is_num) = False CHANGED"; |
102 |
102 |
103 val t = TermC.parse_test @{context} "- 2 is_num"; |
103 val t = ParseC.parse_test @{context} "- 2 is_num"; |
104 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t (@{theory "Isac_Knowledge"}); |
104 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t (@{theory "Isac_Knowledge"}); |
105 if UnparseC.term t' = "(- 2 is_num) = True" then () |
105 if UnparseC.term t' = "(- 2 is_num) = True" then () |
106 else error "(- 2 is_num) = False CHANGED"; |
106 else error "(- 2 is_num) = False CHANGED"; |
107 |
107 |
108 val t = TermC.parse_test @{context} "- 1 is_num"; |
108 val t = ParseC.parse_test @{context} "- 1 is_num"; |
109 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t (@{theory "Isac_Knowledge"}); |
109 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t (@{theory "Isac_Knowledge"}); |
110 if UnparseC.term t' = "(- 1 is_num) = True" then () |
110 if UnparseC.term t' = "(- 1 is_num) = True" then () |
111 else error "(- 1 is_num) = False CHANGED"; |
111 else error "(- 1 is_num) = False CHANGED"; |
112 |
112 |
113 val t = TermC.parse_test @{context} "0 is_num"; |
113 val t = ParseC.parse_test @{context} "0 is_num"; |
114 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t (@{theory "Isac_Knowledge"}); |
114 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t (@{theory "Isac_Knowledge"}); |
115 if UnparseC.term t' = "(0 is_num) = True" then () |
115 if UnparseC.term t' = "(0 is_num) = True" then () |
116 else error "(0 is_num) = False CHANGED"; |
116 else error "(0 is_num) = False CHANGED"; |
117 |
117 |
118 val t = TermC.parse_test @{context} "AA is_num"; |
118 val t = ParseC.parse_test @{context} "AA is_num"; |
119 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t (@{theory "Isac_Knowledge"}); |
119 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t (@{theory "Isac_Knowledge"}); |
120 if UnparseC.term t' = "(AA is_num) = False" then () |
120 if UnparseC.term t' = "(AA is_num) = False" then () |
121 else error "(0 is_num) = False CHANGED"; |
121 else error "(0 is_num) = False CHANGED"; |
122 |
122 |
123 |
123 |
202 "-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------"; |
202 "-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------"; |
203 "-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------"; |
203 "-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------"; |
204 val thy = @{theory} |
204 val thy = @{theory} |
205 val ctxt = (ThyC.id_to_ctxt "Isac_Knowledge") |
205 val ctxt = (ThyC.id_to_ctxt "Isac_Knowledge") |
206 |
206 |
207 val t = TermC.parse_test @{context} "x = 0"; |
207 val t = ParseC.parse_test @{context} "x = 0"; |
208 val NONE(*= indetermined*) = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t ctxt; |
208 val NONE(*= indetermined*) = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t ctxt; |
209 |
209 |
210 val t = TermC.parse_test @{context} "(x + 1) = (x + 1)"; |
210 val t = ParseC.parse_test @{context} "(x + 1) = (x + 1)"; |
211 val (Const _(*op0,t0*) $ t1 $ t2 ) = t |
211 val (Const _(*op0,t0*) $ t1 $ t2 ) = t |
212 val SOME ("equal_(x + 1)_(x + 1)", t') = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t ctxt; |
212 val SOME ("equal_(x + 1)_(x + 1)", t') = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t ctxt; |
213 if UnparseC.term t' = "(x + 1 = x + 1) = True" then () else error "(x + 1) = (x + 1) CHANGED"; |
213 if UnparseC.term t' = "(x + 1 = x + 1) = True" then () else error "(x + 1) = (x + 1) CHANGED"; |
214 |
214 |
215 val t as Const _ $ v $ c = TermC.parse_test @{context} "1 = 0"; |
215 val t as Const _ $ v $ c = ParseC.parse_test @{context} "1 = 0"; |
216 val false = variable_constant_pair (v, c); |
216 val false = variable_constant_pair (v, c); |
217 val SOME ("equal_(1)_(0)", t') = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t ctxt; |
217 val SOME ("equal_(1)_(0)", t') = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t ctxt; |
218 if UnparseC.term t' = "(1 = 0) = False" then () else error "1 = 0 CHANGED"; |
218 if UnparseC.term t' = "(1 = 0) = False" then () else error "1 = 0 CHANGED"; |
219 |
219 |
220 val t = TermC.parse_test @{context} "0 = 0"; |
220 val t = ParseC.parse_test @{context} "0 = 0"; |
221 val SOME ("equal_(0)_(0)", t') = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t ctxt; |
221 val SOME ("equal_(0)_(0)", t') = eval_equal "equal_" \<^const_name>\<open>HOL.eq\<close> t ctxt; |
222 if UnparseC.term t' = "(0 = 0) = True" then () else error "0 = 0 CHANGED"; |
222 if UnparseC.term t' = "(0 = 0) = True" then () else error "0 = 0 CHANGED"; |
223 |
223 |
224 |
224 |
225 "-------- occurs_in ----------------------------------------------------------------------------"; |
225 "-------- occurs_in ----------------------------------------------------------------------------"; |
226 "-------- occurs_in ----------------------------------------------------------------------------"; |
226 "-------- occurs_in ----------------------------------------------------------------------------"; |
227 "-------- occurs_in ----------------------------------------------------------------------------"; |
227 "-------- occurs_in ----------------------------------------------------------------------------"; |
228 val t = @{term "x::real"}; |
228 val t = @{term "x::real"}; |
229 if occurs_in t t then "OK" else error "occurs_in x x -> f ..changed"; |
229 if occurs_in t t then "OK" else error "occurs_in x x -> f ..changed"; |
230 |
230 |
231 val t = TermC.parse_test @{context} "x occurs_in x"; |
231 val t = ParseC.parse_test @{context} "x occurs_in x"; |
232 val SOME (str, t') = eval_occurs_in 0 "Prog_Expr.occurs_in" t 0; |
232 val SOME (str, t') = eval_occurs_in 0 "Prog_Expr.occurs_in" t 0; |
233 if UnparseC.term t' = "x occurs_in x = True" then () |
233 if UnparseC.term t' = "x occurs_in x = True" then () |
234 else error "x occurs_in x = True ..changed"; |
234 else error "x occurs_in x = True ..changed"; |
235 |
235 |
236 "------- some_occur_in"; |
236 "------- some_occur_in"; |
335 |
335 |
336 |
336 |
337 "---------fun eval_argument_of -----------------------------------------------------------------"; |
337 "---------fun eval_argument_of -----------------------------------------------------------------"; |
338 "---------fun eval_argument_of -----------------------------------------------------------------"; |
338 "---------fun eval_argument_of -----------------------------------------------------------------"; |
339 "---------fun eval_argument_of -----------------------------------------------------------------"; |
339 "---------fun eval_argument_of -----------------------------------------------------------------"; |
340 val t = TermC.parse_test @{context} "argument_in (M_b x)"; |
340 val t = ParseC.parse_test @{context} "argument_in (M_b x)"; |
341 val SOME (str, t') = eval_argument_in "0" "Prog_Expr.argument_in" t 0; |
341 val SOME (str, t') = eval_argument_in "0" "Prog_Expr.argument_in" t 0; |
342 if UnparseC.term t' = "(argument_in M_b x) = x" then () |
342 if UnparseC.term t' = "(argument_in M_b x) = x" then () |
343 else error "atools.sml:(argument_in M_b x) = x ???"; |
343 else error "atools.sml:(argument_in M_b x) = x ???"; |
344 |
344 |
345 |
345 |
448 |
448 |
449 |
449 |
450 "-------- fun matchsub -------------------------------------------------------------------------"; |
450 "-------- fun matchsub -------------------------------------------------------------------------"; |
451 "-------- fun matchsub -------------------------------------------------------------------------"; |
451 "-------- fun matchsub -------------------------------------------------------------------------"; |
452 "-------- fun matchsub -------------------------------------------------------------------------"; |
452 "-------- fun matchsub -------------------------------------------------------------------------"; |
453 if matchsub thy (TermC.parse_test @{context} "(a + (b + c))") (TermC.parse_patt_test @{theory} "?x + (?y + ?z)") |
453 if matchsub thy (ParseC.parse_test @{context} "(a + (b + c))") (ParseC.parse_patt_test @{theory} "?x + (?y + ?z)") |
454 then () else error "tools.sml matchsub a + (b + c)"; |
454 then () else error "tools.sml matchsub a + (b + c)"; |
455 |
455 |
456 if matchsub thy (TermC.parse_test @{context} "(a + (b + c)) + d") (TermC.parse_patt_test @{theory} "?x + (?y + ?z)") |
456 if matchsub thy (ParseC.parse_test @{context} "(a + (b + c)) + d") (ParseC.parse_patt_test @{theory} "?x + (?y + ?z)") |
457 then () else error "tools.sml matchsub (a + (b + c)) + d"; |
457 then () else error "tools.sml matchsub (a + (b + c)) + d"; |
458 |
458 |
459 |
459 |
460 "-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------"; |
460 "-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------"; |
461 "-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------"; |
461 "-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------"; |
463 "see: --------- search for Or_to_List ---"; |
463 "see: --------- search for Or_to_List ---"; |
464 case or2list @{term True} of Const (\<^const_name>\<open>UniversalList\<close>, _) => () |
464 case or2list @{term True} of Const (\<^const_name>\<open>UniversalList\<close>, _) => () |
465 | _ => error "TermC.UniversalList changed 1"; |
465 | _ => error "TermC.UniversalList changed 1"; |
466 case or2list @{term False} of Const (\<^const_name>\<open>Nil\<close>, _) => () |
466 case or2list @{term False} of Const (\<^const_name>\<open>Nil\<close>, _) => () |
467 | _ => error "TermC.UniversalList changed 2"; |
467 | _ => error "TermC.UniversalList changed 2"; |
468 val t = (TermC.parse_test @{context} "x=3"); |
468 val t = (ParseC.parse_test @{context} "x=3"); |
469 if UnparseC.term (or2list t) = "[x = 3]" then () |
469 if UnparseC.term (or2list t) = "[x = 3]" then () |
470 else error "or2list changed"; |
470 else error "or2list changed"; |
471 val t = (TermC.parse_test @{context} "x=3 | x=-3 | x=0"); |
471 val t = (ParseC.parse_test @{context} "x=3 | x=-3 | x=0"); |
472 if UnparseC.term (or2list t) = "[x = 3, x = - 3, x = 0]" then () |
472 if UnparseC.term (or2list t) = "[x = 3, x = - 3, x = 0]" then () |
473 else error "HOL.eq ? HOL.disj ? changed"; |
473 else error "HOL.eq ? HOL.disj ? changed"; |