src/Tools/isac/Knowledge/Base_Tools.thy
author wneuper <walther.neuper@jku.at>
Sun, 02 May 2021 13:13:44 +0200
changeset 60273 f15995595411
parent 60149 f01072d28542
child 60274 5b1cd0f93d8b
permissions -rw-r--r--
eliminate axiomatization, first trial

a prompt success of Isabelle detecting an error from 2003, see
https://static.miraheze.org/isacwiki/3/3b/Da-rlang.pdf
wneuper@59424
     1
theory Base_Tools
walther@60149
     2
  imports Interpret.Interpret
walther@60149
     3
(** )"../BridgeJEdit/BridgeJEdit"                    ( *activate after devel.of BridgeJEdit*)
walther@60149
     4
(**) "../BridgeLibisabelle/BridgeLibisabelle"           (*remove after devel.of BridgeJEdit*)
walther@60149
     5
                      (*  ^^^ for KEStore_Elems.add_thes *)
wneuper@59424
     6
begin
wneuper@59602
     7
subsection \<open>theorems for Base_Tools\<close>
walther@60273
     8
walther@60273
     9
lemma real_unari_minus:   "- a = (-1) * (a::real)" by auto
walther@60273
    10
(*Semiring_Normalization.comm_ring_1_class.ring_normalization_rules(1)*)
walther@60273
    11
walther@60273
    12
(* should be in Rational.thy, but needed for asms in e.g. d2_pqformula1 in PolyEq, RootEq... *)
walther@60273
    13
lemma radd_left_cancel_le: "((k::real) + m <= k + n) = (m <= n)" by auto
walther@60273
    14
(*Groups.ordered_ab_semigroup_add_imp_le_class.add_le_cancel_left*)
walther@60273
    15
wneuper@59602
    16
axiomatization where (*for evaluating the assumptions of conditional rules*)
walther@60273
    17
  (* should be in Rational.thy, but needed for asms in e.g. d2_pqformula1 in PolyEq, RootEq... *)
walther@60273
    18
  rat_leq1: "[| 0 \<noteq> b; 0 \<noteq> d |] ==> (a / b <= c / d) = (a * d <= b * c)"(*Quickcheck found a counterexample*) and
walther@60273
    19
  rat_leq2:	          "0 \<noteq> d    ==> (a     <= c / d) = (a * d <=     c)" (*Quickcheck found a counterexample*) and
walther@60273
    20
  rat_leq3:	   "0 \<noteq> b           ==> (a / b <= c    ) = (a     <= b * c)" (*Quickcheck found a counterexample*)
wneuper@59602
    21
wneuper@59602
    22
wneuper@59602
    23
subsection \<open>setup for ML-functions\<close>
wneuper@59602
    24
text \<open>required by "eval_binop" below\<close>
wneuper@59602
    25
setup \<open>KEStore_Elems.add_calcs
walther@59603
    26
  [ ("occurs_in", ("Prog_Expr.occurs'_in", Prog_Expr.eval_occurs_in "#occurs_in_")),
walther@59603
    27
    ("some_occur_in", ("Prog_Expr.some'_occur'_in", Prog_Expr.eval_some_occur_in "#some_occur_in_")),
walther@59603
    28
    ("is_atom", ("Prog_Expr.is'_atom", Prog_Expr.eval_is_atom "#is_atom_")),
walther@59603
    29
    ("is_even", ("Prog_Expr.is'_even", Prog_Expr.eval_is_even "#is_even_")),
walther@59603
    30
    ("is_const", ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_")),
walther@59603
    31
    ("le", ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_")),
walther@59603
    32
    ("leq", ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_")),
walther@59603
    33
    ("ident", ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_")),
walther@59603
    34
    ("equal", ("HOL.eq", Prog_Expr.eval_equal "#equal_")),
walther@59603
    35
    ("PLUS", ("Groups.plus_class.plus", (**)eval_binop "#add_")),
walther@59603
    36
    ("MINUS", ("Groups.minus_class.minus", (**)eval_binop "#sub_")),
walther@59603
    37
    ("TIMES", ("Groups.times_class.times", (**)eval_binop "#mult_")),
walther@59603
    38
    ("DIVIDE", ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e")),
walther@59603
    39
    ("POWER",("Prog_Expr.pow", (**)eval_binop "#power_")),
walther@59603
    40
    ("boollist2sum", ("Prog_Expr.boollist2sum", Prog_Expr.eval_boollist2sum ""))]\<close>
wneuper@59602
    41
wneuper@59602
    42
subsection \<open>rewrite-order for rule-sets\<close>
wneuper@59602
    43
ML \<open>
wneuper@59602
    44
\<close> ML \<open>
wneuper@59602
    45
local
wneuper@59602
    46
  open Term;
wneuper@59602
    47
in
walther@59910
    48
  fun termlessI (_: subst) uv = LibraryC.termless uv;
walther@59910
    49
  fun term_ordI (_: subst) uv = Term_Ord.term_ord uv;
wneuper@59602
    50
end;
wneuper@59602
    51
\<close> ML \<open>
walther@59857
    52
(*TODO.WN0509 reduce ids: tless_true = e_rew_ord' = Rewrite_Ord.e_rew_ord = Rewrite_Ord.dummy_ord*)
walther@59857
    53
val tless_true = Rewrite_Ord.dummy_ord;
walther@59887
    54
Rewrite_Ord.rew_ord' := overwritel (! Rewrite_Ord.rew_ord', (*<<<---- use Know_Store.xxx here, too*)
wneuper@59602
    55
			[("tless_true", tless_true),
wneuper@59602
    56
			 ("e_rew_ord'", tless_true),
walther@59857
    57
			 ("dummy_ord", Rewrite_Ord.dummy_ord)]);
wneuper@59602
    58
\<close>
wneuper@59602
    59
wneuper@59602
    60
subsection \<open>rule-sets\<close>
wneuper@59602
    61
ML \<open>
wneuper@59602
    62
\<close> ML \<open>
walther@59852
    63
val Atools_erls = Rule_Set.append_rules "Atools_erls" Rule_Set.empty
walther@59878
    64
  [ Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
walther@59871
    65
    Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
wneuper@59602
    66
		(*"(~ True) = False"*)
walther@59871
    67
		Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false}),
wneuper@59602
    68
		(*"(~ False) = True"*)
walther@59871
    69
		Rule.Thm ("and_true", ThmC.numerals_to_Free @{thm and_true}),
wneuper@59602
    70
		(*"(?a & True) = ?a"*)
walther@59871
    71
		Rule.Thm ("and_false", ThmC.numerals_to_Free @{thm and_false}),
wneuper@59602
    72
		(*"(?a & False) = False"*)
walther@59871
    73
		Rule.Thm ("or_true", ThmC.numerals_to_Free @{thm or_true}),
wneuper@59602
    74
		(*"(?a | True) = True"*)
walther@59871
    75
		Rule.Thm ("or_false", ThmC.numerals_to_Free @{thm or_false}),
wneuper@59602
    76
		(*"(?a | False) = ?a"*)
wneuper@59602
    77
               
walther@59871
    78
		Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
walther@59871
    79
		Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
walther@59871
    80
		Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3}),
walther@59871
    81
      Rule.Thm ("refl", ThmC.numerals_to_Free @{thm refl}),
walther@59871
    82
		Rule.Thm ("order_refl", ThmC.numerals_to_Free @{thm order_refl}),
walther@59871
    83
		Rule.Thm ("radd_left_cancel_le", ThmC.numerals_to_Free @{thm radd_left_cancel_le}),
wneuper@59602
    84
		
walther@59878
    85
		Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
walther@59878
    86
		Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
wneuper@59602
    87
		
walther@59878
    88
		Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),    
walther@59878
    89
		Rule.Eval ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_"),
walther@59878
    90
		Rule.Eval ("Prog_Expr.occurs'_in", Prog_Expr.eval_occurs_in ""),    
walther@59878
    91
		Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches "")];
wneuper@59602
    92
\<close>
wneuper@59602
    93
wneuper@59602
    94
ML \<open>
walther@59852
    95
val Atools_crls = Rule_Set.append_rules "Atools_crls" Rule_Set.empty
walther@59878
    96
  [ Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
walther@59871
    97
    Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
walther@59871
    98
		Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false}),
walther@59871
    99
		Rule.Thm ("and_true", ThmC.numerals_to_Free @{thm and_true}),
walther@59871
   100
		Rule.Thm ("and_false", ThmC.numerals_to_Free @{thm and_false}),
walther@59871
   101
		Rule.Thm ("or_true", ThmC.numerals_to_Free @{thm or_true}),
walther@59871
   102
		Rule.Thm ("or_false", ThmC.numerals_to_Free @{thm or_false}),
wneuper@59602
   103
               
walther@59871
   104
		Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
walther@59871
   105
		Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
walther@59871
   106
		Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3}),
walther@59871
   107
		Rule.Thm ("refl", ThmC.numerals_to_Free @{thm refl}),
walther@59871
   108
		Rule.Thm ("order_refl", ThmC.numerals_to_Free @{thm order_refl}),
walther@59871
   109
		Rule.Thm ("radd_left_cancel_le", ThmC.numerals_to_Free @{thm radd_left_cancel_le}),
wneuper@59602
   110
		
walther@59878
   111
		Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
walther@59878
   112
		Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
wneuper@59602
   113
		
walther@59878
   114
		Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),    
walther@59878
   115
		Rule.Eval ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_"),
walther@59878
   116
		Rule.Eval ("Prog_Expr.occurs'_in", Prog_Expr.eval_occurs_in ""),    
walther@59878
   117
		Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches "")];
wneuper@59602
   118
\<close>
wneuper@59602
   119
wneuper@59602
   120
subsection \<open>ONCE AGAIN extend rule-set for evaluating pre-conditions and program-expressions\<close>
wneuper@59602
   121
text \<open>requires "eval_binop" from above\<close>
wneuper@59602
   122
ML \<open>
walther@59852
   123
val prog_expr = Rule_Set.append_rules "prog_expr" prog_expr
walther@59878
   124
	[ Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
walther@59878
   125
		Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"), 
walther@59878
   126
		Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
walther@59878
   127
		Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
walther@59878
   128
		Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
walther@59878
   129
		Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),(*atom <> atom -> False*)
wneuper@59602
   130
       
walther@59878
   131
		Rule.Eval ("Prog_Expr.Vars",Prog_Expr.eval_var "#Vars_"),
wneuper@59602
   132
		
walther@59871
   133
		Rule.Thm ("if_True",ThmC.numerals_to_Free @{thm if_True}),
walther@59871
   134
		Rule.Thm ("if_False",ThmC.numerals_to_Free @{thm if_False})];
wneuper@59602
   135
walther@59852
   136
val prog_expr = Auto_Prog.prep_rls @{theory} (Rule_Set.merge "list_erls"
walther@59851
   137
	(Rule_Def.Repeat {id = "replaced", preconds = [], rew_ord = ("termlessI", termlessI),
walther@59851
   138
    erls = Rule_Def.Repeat {id = "list_elrs", preconds = [], rew_ord = ("termlessI", termlessI), 
walther@59852
   139
    erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
walther@59878
   140
    rules = [Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
walther@59878
   141
      Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_")
wneuper@59602
   142
      (*    ~~~~~~ for nth_Cons_*)],
walther@59878
   143
    scr = Rule.Empty_Prog},
walther@59851
   144
    srls = Rule_Set.Empty, calc = [], errpatts = [],
walther@59878
   145
    rules = [], scr = Rule.Empty_Prog})
walther@59801
   146
  prog_expr);
wneuper@59602
   147
\<close>
wneuper@59602
   148
subsection \<open>setup for extended rule-set\<close>
wneuper@59602
   149
setup \<open>KEStore_Elems.add_rlss
walther@59801
   150
  [("prog_expr", (Context.theory_name @{theory}, Auto_Prog.prep_rls @{theory} prog_expr))]\<close>
wneuper@59602
   151
walther@60077
   152
end