src/Tools/isac/Knowledge/Base_Tools.thy
author wneuper <walther.neuper@jku.at>
Mon, 03 May 2021 08:49:50 +0200
changeset 60275 98ee674d18d3
parent 60274 5b1cd0f93d8b
child 60278 343efa173023
permissions -rw-r--r--
replace Isac's power with Isabelle's Transcendental.powr
     1 theory Base_Tools
     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 *)
     6 begin
     7 subsection \<open>theorems for Base_Tools\<close>
     8 
     9 lemma real_unari_minus:   "- a = (-1) * (a::real)" by auto
    10 (*Semiring_Normalization.comm_ring_1_class.ring_normalization_rules(1)*)
    11 
    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*)
    15 
    16 thm "Fields.linordered_field_class.mult_imp_le_div_pos" (*0 < ?y \<Longrightarrow> ?z * ?y \<le> ?x \<Longrightarrow> ?z \<le> ?x / ?y*)
    17 
    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*)
    23 
    24 
    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>
    43 
    44 subsection \<open>rewrite-order for rule-sets\<close>
    45 ML \<open>
    46 \<close> ML \<open>
    47 local
    48   open Term;
    49 in
    50   fun termlessI (_: subst) uv = LibraryC.termless uv;
    51   fun term_ordI (_: subst) uv = Term_Ord.term_ord uv;
    52 end;
    53 \<close> ML \<open>
    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)]);
    60 \<close>
    61 
    62 subsection \<open>rule-sets\<close>
    63 ML \<open>
    64 \<close> ML \<open>
    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"*)
    79                
    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}),
    86 		
    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_"),
    89 		
    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 "")];
    94 \<close>
    95 
    96 ML \<open>
    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}),
   105                
   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}),
   112 		
   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_"),
   115 		
   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 "")];
   120 \<close>
   121 
   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>
   124 ML \<open>
   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*)
   132        
   133 		Rule.Eval ("Prog_Expr.Vars",Prog_Expr.eval_var "#Vars_"),
   134 		
   135 		Rule.Thm ("if_True",ThmC.numerals_to_Free @{thm if_True}),
   136 		Rule.Thm ("if_False",ThmC.numerals_to_Free @{thm if_False})];
   137 
   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})
   148   prog_expr);
   149 \<close>
   150 subsection \<open>setup for extended rule-set\<close>
   151 setup \<open>KEStore_Elems.add_rlss
   152   [("prog_expr", (Context.theory_name @{theory}, Auto_Prog.prep_rls @{theory} prog_expr))]\<close>
   153 
   154 end