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>
9 lemma real_unari_minus: "- a = (-1) * (a::real)" by auto
10 (*Semiring_Normalization.comm_ring_1_class.ring_normalization_rules(1)*)
12 (* should be in Rational.thy, but needed for asms in e.g. d2_pqformula1 in PolyEq, RootEq... *)
13 lemma radd_left_cancel_le: "((k::real) + m <= k + n) = (m <= n)" by auto
14 (*Groups.ordered_ab_semigroup_add_imp_le_class.add_le_cancel_left*)
16 axiomatization where (*for evaluating the assumptions of conditional rules*)
17 (* should be in Rational.thy, but needed for asms in e.g. d2_pqformula1 in PolyEq, RootEq... *)
18 rat_leq1: "[| 0 \<noteq> b; 0 \<noteq> d |] ==> (a / b <= c / d) = (a * d <= b * c)"(*Quickcheck found a counterexample*) and
19 rat_leq2: "0 \<noteq> d ==> (a <= c / d) = (a * d <= c)" (*Quickcheck found a counterexample*) and
20 rat_leq3: "0 \<noteq> b ==> (a / b <= c ) = (a <= b * c)" (*Quickcheck found a counterexample*)
23 subsection \<open>setup for ML-functions\<close>
24 text \<open>required by "eval_binop" below\<close>
25 setup \<open>KEStore_Elems.add_calcs
26 [ ("occurs_in", ("Prog_Expr.occurs'_in", Prog_Expr.eval_occurs_in "#occurs_in_")),
27 ("some_occur_in", ("Prog_Expr.some'_occur'_in", Prog_Expr.eval_some_occur_in "#some_occur_in_")),
28 ("is_atom", ("Prog_Expr.is'_atom", Prog_Expr.eval_is_atom "#is_atom_")),
29 ("is_even", ("Prog_Expr.is'_even", Prog_Expr.eval_is_even "#is_even_")),
30 ("is_const", ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_")),
31 ("le", ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_")),
32 ("leq", ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_")),
33 ("ident", ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_")),
34 ("equal", ("HOL.eq", Prog_Expr.eval_equal "#equal_")),
35 ("PLUS", ("Groups.plus_class.plus", (**)eval_binop "#add_")),
36 ("MINUS", ("Groups.minus_class.minus", (**)eval_binop "#sub_")),
37 ("TIMES", ("Groups.times_class.times", (**)eval_binop "#mult_")),
38 ("DIVIDE", ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e")),
39 ("POWER",("Prog_Expr.pow", (**)eval_binop "#power_")),
40 ("boollist2sum", ("Prog_Expr.boollist2sum", Prog_Expr.eval_boollist2sum ""))]\<close>
42 subsection \<open>rewrite-order for rule-sets\<close>
48 fun termlessI (_: subst) uv = LibraryC.termless uv;
49 fun term_ordI (_: subst) uv = Term_Ord.term_ord uv;
52 (*TODO.WN0509 reduce ids: tless_true = e_rew_ord' = Rewrite_Ord.e_rew_ord = Rewrite_Ord.dummy_ord*)
53 val tless_true = Rewrite_Ord.dummy_ord;
54 Rewrite_Ord.rew_ord' := overwritel (! Rewrite_Ord.rew_ord', (*<<<---- use Know_Store.xxx here, too*)
55 [("tless_true", tless_true),
56 ("e_rew_ord'", tless_true),
57 ("dummy_ord", Rewrite_Ord.dummy_ord)]);
60 subsection \<open>rule-sets\<close>
63 val Atools_erls = Rule_Set.append_rules "Atools_erls" Rule_Set.empty
64 [ Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
65 Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
66 (*"(~ True) = False"*)
67 Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false}),
68 (*"(~ False) = True"*)
69 Rule.Thm ("and_true", ThmC.numerals_to_Free @{thm and_true}),
70 (*"(?a & True) = ?a"*)
71 Rule.Thm ("and_false", ThmC.numerals_to_Free @{thm and_false}),
72 (*"(?a & False) = False"*)
73 Rule.Thm ("or_true", ThmC.numerals_to_Free @{thm or_true}),
74 (*"(?a | True) = True"*)
75 Rule.Thm ("or_false", ThmC.numerals_to_Free @{thm or_false}),
76 (*"(?a | False) = ?a"*)
78 Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
79 Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
80 Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3}),
81 Rule.Thm ("refl", ThmC.numerals_to_Free @{thm refl}),
82 Rule.Thm ("order_refl", ThmC.numerals_to_Free @{thm order_refl}),
83 Rule.Thm ("radd_left_cancel_le", ThmC.numerals_to_Free @{thm radd_left_cancel_le}),
85 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
86 Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
88 Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
89 Rule.Eval ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_"),
90 Rule.Eval ("Prog_Expr.occurs'_in", Prog_Expr.eval_occurs_in ""),
91 Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches "")];
95 val Atools_crls = Rule_Set.append_rules "Atools_crls" Rule_Set.empty
96 [ Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
97 Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
98 Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false}),
99 Rule.Thm ("and_true", ThmC.numerals_to_Free @{thm and_true}),
100 Rule.Thm ("and_false", ThmC.numerals_to_Free @{thm and_false}),
101 Rule.Thm ("or_true", ThmC.numerals_to_Free @{thm or_true}),
102 Rule.Thm ("or_false", ThmC.numerals_to_Free @{thm or_false}),
104 Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
105 Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
106 Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3}),
107 Rule.Thm ("refl", ThmC.numerals_to_Free @{thm refl}),
108 Rule.Thm ("order_refl", ThmC.numerals_to_Free @{thm order_refl}),
109 Rule.Thm ("radd_left_cancel_le", ThmC.numerals_to_Free @{thm radd_left_cancel_le}),
111 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
112 Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
114 Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
115 Rule.Eval ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_"),
116 Rule.Eval ("Prog_Expr.occurs'_in", Prog_Expr.eval_occurs_in ""),
117 Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches "")];
120 subsection \<open>ONCE AGAIN extend rule-set for evaluating pre-conditions and program-expressions\<close>
121 text \<open>requires "eval_binop" from above\<close>
123 val prog_expr = Rule_Set.append_rules "prog_expr" prog_expr
124 [ Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
125 Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
126 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
127 Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
128 Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
129 Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),(*atom <> atom -> False*)
131 Rule.Eval ("Prog_Expr.Vars",Prog_Expr.eval_var "#Vars_"),
133 Rule.Thm ("if_True",ThmC.numerals_to_Free @{thm if_True}),
134 Rule.Thm ("if_False",ThmC.numerals_to_Free @{thm if_False})];
136 val prog_expr = Auto_Prog.prep_rls @{theory} (Rule_Set.merge "list_erls"
137 (Rule_Def.Repeat {id = "replaced", preconds = [], rew_ord = ("termlessI", termlessI),
138 erls = Rule_Def.Repeat {id = "list_elrs", preconds = [], rew_ord = ("termlessI", termlessI),
139 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
140 rules = [Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
141 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_")
142 (* ~~~~~~ for nth_Cons_*)],
143 scr = Rule.Empty_Prog},
144 srls = Rule_Set.Empty, calc = [], errpatts = [],
145 rules = [], scr = Rule.Empty_Prog})
148 subsection \<open>setup for extended rule-set\<close>
149 setup \<open>KEStore_Elems.add_rlss
150 [("prog_expr", (Context.theory_name @{theory}, Auto_Prog.prep_rls @{theory} prog_expr))]\<close>