clarified command name: this is to register already defined rule sets in the Knowledge Store;
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 \<le> k + n) = (m \<le> n)" by auto
14 (*Groups.ordered_ab_semigroup_add_imp_le_class.add_le_cancel_left*)
16 thm "Fields.linordered_field_class.mult_imp_le_div_pos" (*0 < ?y \<Longrightarrow> ?z * ?y \<le> ?x \<Longrightarrow> ?z \<le> ?x / ?y*)
18 axiomatization where (*for evaluating the assumptions of conditional rules*)
19 (* should be in Rational.thy, but needed for asms in e.g. d2_pqformula1 in PolyEq, RootEq... *)
20 rat_leq1: "0 \<noteq> b \<Longrightarrow> 0 \<noteq> d \<Longrightarrow> (a / b \<le> c / d) = (a * d \<le> b * c)"(*Quickcheck found a counterexample*) and
21 rat_leq2: "0 \<noteq> d \<Longrightarrow> (a \<le> c / d) = (a * d \<le> c)"(*Quickcheck found a counterexample*) and
22 rat_leq3: "0 \<noteq> b \<Longrightarrow> (a / b \<le> c ) = (a \<le> b * c)"(*Quickcheck found a counterexample*)
25 subsection \<open>setup for ML-functions\<close>
26 text \<open>required by "eval_binop" below\<close>
27 setup \<open>KEStore_Elems.add_calcs
28 [ ("occurs_in", ("Prog_Expr.occurs_in", Prog_Expr.eval_occurs_in "#occurs_in_")),
29 ("some_occur_in", ("Prog_Expr.some_occur_in", Prog_Expr.eval_some_occur_in "#some_occur_in_")),
30 ("is_atom", ("Prog_Expr.is_atom", Prog_Expr.eval_is_atom "#is_atom_")),
31 ("is_even", ("Prog_Expr.is_even", Prog_Expr.eval_is_even "#is_even_")),
32 ("is_const", ("Prog_Expr.is_const", Prog_Expr.eval_const "#is_const_")),
33 ("le", ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_")),
34 ("leq", ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_")),
35 ("ident", ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_")),
36 ("equal", ("HOL.eq", Prog_Expr.eval_equal "#equal_")),
37 ("PLUS", ("Groups.plus_class.plus", (**)eval_binop "#add_")),
38 ("MINUS", ("Groups.minus_class.minus", (**)eval_binop "#sub_")),
39 ("TIMES", ("Groups.times_class.times", (**)eval_binop "#mult_")),
40 ("DIVIDE", ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e")),
41 ("POWER",("Transcendental.powr", (**)eval_binop "#power_")),
42 ("boollist2sum", ("Prog_Expr.boollist2sum", Prog_Expr.eval_boollist2sum ""))]\<close>
44 subsection \<open>rewrite-order for rule-sets\<close>
50 fun termlessI (_: subst) uv = LibraryC.termless uv;
51 fun term_ordI (_: subst) uv = Term_Ord.term_ord uv;
54 (*TODO.WN0509 reduce ids: tless_true = e_rew_ord' = Rewrite_Ord.e_rew_ord = Rewrite_Ord.dummy_ord*)
55 val tless_true = Rewrite_Ord.dummy_ord;
56 Rewrite_Ord.rew_ord' := overwritel (! Rewrite_Ord.rew_ord', (*<<<---- use Know_Store.xxx here, too*)
57 [("tless_true", tless_true),
58 ("e_rew_ord'", tless_true),
59 ("dummy_ord", Rewrite_Ord.dummy_ord)]);
62 subsection \<open>rule-sets\<close>
65 val Atools_erls = Rule_Set.append_rules "Atools_erls" Rule_Set.empty
66 [ Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
67 Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
68 (*"(~ True) = False"*)
69 Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false}),
70 (*"(~ False) = True"*)
71 Rule.Thm ("and_true", ThmC.numerals_to_Free @{thm and_true}),
72 (*"(?a & True) = ?a"*)
73 Rule.Thm ("and_false", ThmC.numerals_to_Free @{thm and_false}),
74 (*"(?a & False) = False"*)
75 Rule.Thm ("or_true", ThmC.numerals_to_Free @{thm or_true}),
76 (*"(?a | True) = True"*)
77 Rule.Thm ("or_false", ThmC.numerals_to_Free @{thm or_false}),
78 (*"(?a | False) = ?a"*)
80 Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
81 Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
82 Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3}),
83 Rule.Thm ("refl", ThmC.numerals_to_Free @{thm refl}),
84 Rule.Thm ("order_refl", ThmC.numerals_to_Free @{thm order_refl}),
85 Rule.Thm ("radd_left_cancel_le", ThmC.numerals_to_Free @{thm radd_left_cancel_le}),
87 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
88 Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
90 Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
91 Rule.Eval ("Prog_Expr.is_const", Prog_Expr.eval_const "#is_const_"),
92 Rule.Eval ("Prog_Expr.occurs_in", Prog_Expr.eval_occurs_in ""),
93 Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches "")];
97 val Atools_crls = Rule_Set.append_rules "Atools_crls" Rule_Set.empty
98 [ Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
99 Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
100 Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false}),
101 Rule.Thm ("and_true", ThmC.numerals_to_Free @{thm and_true}),
102 Rule.Thm ("and_false", ThmC.numerals_to_Free @{thm and_false}),
103 Rule.Thm ("or_true", ThmC.numerals_to_Free @{thm or_true}),
104 Rule.Thm ("or_false", ThmC.numerals_to_Free @{thm or_false}),
106 Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
107 Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
108 Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3}),
109 Rule.Thm ("refl", ThmC.numerals_to_Free @{thm refl}),
110 Rule.Thm ("order_refl", ThmC.numerals_to_Free @{thm order_refl}),
111 Rule.Thm ("radd_left_cancel_le", ThmC.numerals_to_Free @{thm radd_left_cancel_le}),
113 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
114 Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
116 Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
117 Rule.Eval ("Prog_Expr.is_const", Prog_Expr.eval_const "#is_const_"),
118 Rule.Eval ("Prog_Expr.occurs_in", Prog_Expr.eval_occurs_in ""),
119 Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches "")];
122 subsection \<open>ONCE AGAIN extend rule-set for evaluating pre-conditions and program-expressions\<close>
123 text \<open>requires "eval_binop" from above\<close>
125 val prog_expr = Rule_Set.append_rules "prog_expr" prog_expr
126 [ Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
127 Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
128 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
129 Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
130 Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
131 Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),(*atom <> atom -> False*)
133 Rule.Eval ("Prog_Expr.Vars",Prog_Expr.eval_var "#Vars_"),
135 Rule.Thm ("if_True",ThmC.numerals_to_Free @{thm if_True}),
136 Rule.Thm ("if_False",ThmC.numerals_to_Free @{thm if_False})];
138 val prog_expr = Auto_Prog.prep_rls @{theory} (Rule_Set.merge "list_erls"
139 (Rule_Def.Repeat {id = "replaced", preconds = [], rew_ord = ("termlessI", termlessI),
140 erls = Rule_Def.Repeat {id = "list_elrs", preconds = [], rew_ord = ("termlessI", termlessI),
141 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
142 rules = [Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
143 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_")
144 (* ~~~~~~ for nth_Cons_*)],
145 scr = Rule.Empty_Prog},
146 srls = Rule_Set.Empty, calc = [], errpatts = [],
147 rules = [], scr = Rule.Empty_Prog})
151 subsection \<open>setup for extended rule-set\<close>
153 rule_set_knowledge prog_expr = \<open>Auto_Prog.prep_rls @{theory} prog_expr\<close>