2 imports Interpret.Interpret
3 (** )"../BridgeJEdit/BridgeJEdit" ( *activate after devel.of BridgeJEdit*)
4 (**) "../BridgeLibisabelle/BridgeLibisabelle" (*remove after devel.of BridgeJEdit*)
5 (* ^^^ for KEStore_Elems.add_thes *)
7 subsection \<open>theorems for Base_Tools\<close>
8 axiomatization where (*for evaluating the assumptions of conditional rules*)
10 (*last_thmI: "lastI (x#xs) = (if xs =!= [] then x else lastI xs)" and*)
11 real_unari_minus: "- a = (-1) * a" and
12 radd_left_cancel_le:"((k::real) + m <= k + n) = (m <= n)" and
13 (* should be in Rational.thy, but:
14 needed for asms in e.g. d2_pqformula1 in PolyEq.ML, RootEq.ML...*)
15 rat_leq1: "[| b ~= 0; d ~= 0 |] ==>
16 ((a / b) <= (c / d)) = ((a*d) <= (b*c))"(*Isa?*) and
18 ( a <= (c / d)) = ((a*d) <= c )"(*Isa?*) and
20 ((a / b) <= c ) = ( a <= (b*c))"(*Isa?*)
22 subsection \<open>setup for ML-functions\<close>
23 text \<open>required by "eval_binop" below\<close>
24 setup \<open>KEStore_Elems.add_calcs
25 [ ("occurs_in", ("Prog_Expr.occurs'_in", Prog_Expr.eval_occurs_in "#occurs_in_")),
26 ("some_occur_in", ("Prog_Expr.some'_occur'_in", Prog_Expr.eval_some_occur_in "#some_occur_in_")),
27 ("is_atom", ("Prog_Expr.is'_atom", Prog_Expr.eval_is_atom "#is_atom_")),
28 ("is_even", ("Prog_Expr.is'_even", Prog_Expr.eval_is_even "#is_even_")),
29 ("is_const", ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_")),
30 ("le", ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_")),
31 ("leq", ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_")),
32 ("ident", ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_")),
33 ("equal", ("HOL.eq", Prog_Expr.eval_equal "#equal_")),
34 ("PLUS", ("Groups.plus_class.plus", (**)eval_binop "#add_")),
35 ("MINUS", ("Groups.minus_class.minus", (**)eval_binop "#sub_")),
36 ("TIMES", ("Groups.times_class.times", (**)eval_binop "#mult_")),
37 ("DIVIDE", ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e")),
38 ("POWER",("Prog_Expr.pow", (**)eval_binop "#power_")),
39 ("boollist2sum", ("Prog_Expr.boollist2sum", Prog_Expr.eval_boollist2sum ""))]\<close>
41 subsection \<open>rewrite-order for rule-sets\<close>
47 fun termlessI (_: subst) uv = LibraryC.termless uv;
48 fun term_ordI (_: subst) uv = Term_Ord.term_ord uv;
51 (*TODO.WN0509 reduce ids: tless_true = e_rew_ord' = Rewrite_Ord.e_rew_ord = Rewrite_Ord.dummy_ord*)
52 val tless_true = Rewrite_Ord.dummy_ord;
53 Rewrite_Ord.rew_ord' := overwritel (! Rewrite_Ord.rew_ord', (*<<<---- use Know_Store.xxx here, too*)
54 [("tless_true", tless_true),
55 ("e_rew_ord'", tless_true),
56 ("dummy_ord", Rewrite_Ord.dummy_ord)]);
59 subsection \<open>rule-sets\<close>
62 val Atools_erls = Rule_Set.append_rules "Atools_erls" Rule_Set.empty
63 [ Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
64 Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
65 (*"(~ True) = False"*)
66 Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false}),
67 (*"(~ False) = True"*)
68 Rule.Thm ("and_true", ThmC.numerals_to_Free @{thm and_true}),
69 (*"(?a & True) = ?a"*)
70 Rule.Thm ("and_false", ThmC.numerals_to_Free @{thm and_false}),
71 (*"(?a & False) = False"*)
72 Rule.Thm ("or_true", ThmC.numerals_to_Free @{thm or_true}),
73 (*"(?a | True) = True"*)
74 Rule.Thm ("or_false", ThmC.numerals_to_Free @{thm or_false}),
75 (*"(?a | False) = ?a"*)
77 Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
78 Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
79 Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3}),
80 Rule.Thm ("refl", ThmC.numerals_to_Free @{thm refl}),
81 Rule.Thm ("order_refl", ThmC.numerals_to_Free @{thm order_refl}),
82 Rule.Thm ("radd_left_cancel_le", ThmC.numerals_to_Free @{thm radd_left_cancel_le}),
84 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
85 Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
87 Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
88 Rule.Eval ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_"),
89 Rule.Eval ("Prog_Expr.occurs'_in", Prog_Expr.eval_occurs_in ""),
90 Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches "")];
94 val Atools_crls = Rule_Set.append_rules "Atools_crls" Rule_Set.empty
95 [ Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
96 Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
97 Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false}),
98 Rule.Thm ("and_true", ThmC.numerals_to_Free @{thm and_true}),
99 Rule.Thm ("and_false", ThmC.numerals_to_Free @{thm and_false}),
100 Rule.Thm ("or_true", ThmC.numerals_to_Free @{thm or_true}),
101 Rule.Thm ("or_false", ThmC.numerals_to_Free @{thm or_false}),
103 Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
104 Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
105 Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3}),
106 Rule.Thm ("refl", ThmC.numerals_to_Free @{thm refl}),
107 Rule.Thm ("order_refl", ThmC.numerals_to_Free @{thm order_refl}),
108 Rule.Thm ("radd_left_cancel_le", ThmC.numerals_to_Free @{thm radd_left_cancel_le}),
110 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
111 Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
113 Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
114 Rule.Eval ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_"),
115 Rule.Eval ("Prog_Expr.occurs'_in", Prog_Expr.eval_occurs_in ""),
116 Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches "")];
119 subsection \<open>ONCE AGAIN extend rule-set for evaluating pre-conditions and program-expressions\<close>
120 text \<open>requires "eval_binop" from above\<close>
122 val prog_expr = Rule_Set.append_rules "prog_expr" prog_expr
123 [ Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
124 Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
125 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
126 Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
127 Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
128 Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),(*atom <> atom -> False*)
130 Rule.Eval ("Prog_Expr.Vars",Prog_Expr.eval_var "#Vars_"),
132 Rule.Thm ("if_True",ThmC.numerals_to_Free @{thm if_True}),
133 Rule.Thm ("if_False",ThmC.numerals_to_Free @{thm if_False})];
135 val prog_expr = Auto_Prog.prep_rls @{theory} (Rule_Set.merge "list_erls"
136 (Rule_Def.Repeat {id = "replaced", preconds = [], rew_ord = ("termlessI", termlessI),
137 erls = Rule_Def.Repeat {id = "list_elrs", preconds = [], rew_ord = ("termlessI", termlessI),
138 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
139 rules = [Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
140 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_")
141 (* ~~~~~~ for nth_Cons_*)],
142 scr = Rule.Empty_Prog},
143 srls = Rule_Set.Empty, calc = [], errpatts = [],
144 rules = [], scr = Rule.Empty_Prog})
147 subsection \<open>setup for extended rule-set\<close>
148 setup \<open>KEStore_Elems.add_rlss
149 [("prog_expr", (Context.theory_name @{theory}, Auto_Prog.prep_rls @{theory} prog_expr))]\<close>