src/Tools/isac/ProgLang/Atools.thy
author Walther Neuper <wneuper@ist.tugraz.at>
Sat, 01 Jun 2019 11:09:19 +0200
changeset 59549 e0e3d41ef86c
parent 59547 a6dcec53aec0
child 59585 0bb418c3855a
permissions -rw-r--r--
[-Test_Isac] funpack: repair errors in test, spot remaining errors

Note: check, whether error is due to "switch from Script to partial_function" 4035ec339062
or due to "failed trial to generalise handling of meths which extend the model of a probl" 98298342fb6d
neuper@37944
     1
(* Title:  tools for arithmetic
neuper@37944
     2
   Author: Walther Neuper 010308
neuper@37944
     3
   (c) due to copyright terms
neuper@37906
     4
*)
neuper@37906
     5
wneuper@59424
     6
theory Atools imports Descript Script
neuper@37967
     7
begin
neuper@37906
     8
wneuper@59549
     9
subsection \<open>preparation to build up a program from rules\<close>
wneuper@59549
    10
wneuper@59547
    11
partial_function (tailrec) auto_generated :: "'z \<Rightarrow> 'z"
wneuper@59547
    12
  where "auto_generated t_t = t_t"
wneuper@59547
    13
partial_function (tailrec) auto_generated_inst :: "'z \<Rightarrow> real \<Rightarrow> 'z"
wneuper@59547
    14
  where "auto_generated_inst t_t v =  t_t"
wneuper@59549
    15
wneuper@59549
    16
subsection \<open>use preparation\<close>
wneuper@59424
    17
ML_file "~~/src/Tools/isac/ProgLang/scrtools.sml"
wneuper@59424
    18
wneuper@59549
    19
subsection \<open>consts & axiomatization\<close>
wneuper@59549
    20
neuper@37906
    21
consts
neuper@37906
    22
neuper@37946
    23
  Arbfix           :: "real"
neuper@37949
    24
  Undef            :: "real"
neuper@37949
    25
  dummy            :: "real"
neuper@37949
    26
neuper@37949
    27
  some'_occur'_in  :: "[real list, 'a] => bool" ("some'_of _ occur'_in _")
neuper@37949
    28
  occurs'_in       :: "[real     , 'a] => bool" ("_ occurs'_in _")
neuper@37949
    29
neuper@37949
    30
  pow              :: "[real, real] => real"    (infixr "^^^" 80)
wneuper@59549
    31
  (* ~~~ power doesn't allow Free("2",real) ^ Free("2",nat)
neuper@37949
    32
                           ~~~~     ~~~~    ~~~~     ~~~*)
neuper@37949
    33
(*WN0603 at FE-interface encoded strings to '^', 
neuper@37949
    34
	see 'fun encode', fun 'decode'*)
neuper@37949
    35
neuper@37949
    36
  abs              :: "real => real"            ("(|| _ ||)")
neuper@37949
    37
(* ~~~ FIXXXME Isabelle2002 has abs already !!!*)
neuper@37949
    38
  absset           :: "real set => real"        ("(||| _ |||)")
neuper@37949
    39
  (*is numeral constant ?*)
neuper@37949
    40
  is'_const        :: "real => bool"            ("_ is'_const" 10)
neuper@37949
    41
  (*is_const rename to is_num FIXXXME.WN.16.5.03 *)
neuper@37949
    42
  is'_atom         :: "real => bool"            ("_ is'_atom" 10)
neuper@37949
    43
  is'_even         :: "real => bool"            ("_ is'_even" 10)
neuper@37949
    44
		
neuper@37949
    45
  (* identity on term level*)
neuper@37949
    46
  ident            :: "['a, 'a] => bool"        ("(_ =!=/ _)" [51, 51] 50)
neuper@37949
    47
neuper@37949
    48
  argument'_in     :: "real => real"            ("argument'_in _" 10)
neuper@37949
    49
  sameFunId        :: "[real, bool] => bool"    (**"same'_funid _ _" 10
neuper@37949
    50
	WN0609 changed the id, because ".. _ _" inhibits currying**)
neuper@37949
    51
  filter'_sameFunId:: "[real, bool list] => bool list" 
neuper@37949
    52
					        ("filter'_sameFunId _ _" 10)
neuper@37949
    53
  boollist2sum     :: "bool list => real"
wneuper@59429
    54
  lastI            :: "'a list \<Rightarrow> 'a"
neuper@37949
    55
neuper@52148
    56
axiomatization where (*for evaluating the assumptions of conditional rules*)
neuper@37949
    57
neuper@52148
    58
  last_thmI:	      "lastI (x#xs) = (if xs =!= [] then x else lastI xs)" and
neuper@52148
    59
  real_unari_minus:   "- a = (-1) * a" and
neuper@37949
    60
neuper@52148
    61
  rle_refl:           "(n::real) <= n" and
neuper@52148
    62
  radd_left_cancel_le:"((k::real) + m <= k + n) = (m <= n)" and
neuper@52148
    63
  not_true:           "(~ True) = False" and
neuper@37965
    64
  not_false:          "(~ False) = True"
neuper@52148
    65
neuper@52148
    66
axiomatization where (*..if replaced by "and" we get error:
t@42203
    67
Type unification failed: No type arity bool :: zero ...*)
neuper@52148
    68
  and_true:           "(a & True) = a" and
neuper@52148
    69
  and_false:          "(a & False) = False" and
neuper@52148
    70
  or_true:            "(a | True) = True" and
neuper@52148
    71
  or_false:           "(a | False) = a" and
neuper@52148
    72
  and_commute:        "(a & b) = (b & a)" and
t@42203
    73
  or_commute:         "(a | b) = (b | a)" 
neuper@37949
    74
neuper@37949
    75
  (*.should be in Rational.thy, but: 
neuper@37949
    76
   needed for asms in e.g. d2_pqformula1 in PolyEq.ML, RootEq.ML.*)
neuper@52148
    77
axiomatization where (*..if replaced by "and" we get error:
t@42203
    78
Type unification failed: No type arity bool :: zero ...*)
neuper@37965
    79
  rat_leq1:	      "[| b ~= 0; d ~= 0 |] ==>
neuper@52148
    80
		       ((a / b) <= (c / d)) = ((a*d) <= (b*c))"(*Isa?*) and
neuper@37965
    81
  rat_leq2:	      "d ~= 0 ==>
neuper@52148
    82
		       ( a      <= (c / d)) = ((a*d) <=    c )"(*Isa?*) and
neuper@37965
    83
  rat_leq3:	      "b ~= 0 ==>
neuper@37949
    84
		       ((a / b) <=  c     ) = ( a    <= (b*c))"(*Isa?*)
neuper@37949
    85
neuper@37965
    86
wneuper@59549
    87
subsection \<open>Coding standards\<close>
wneuper@59472
    88
text \<open>copy from doc/math-eng.tex WN.28.3.03
wneuper@59472
    89
WN071228 extended\<close>
neuper@37949
    90
wneuper@59549
    91
subsubsection \<open>Identifiers\<close>
wneuper@59472
    92
text \<open>Naming is particularily crucial, because Isabelles name space is global, and isac does not yet use the novel locale features introduces by Isar. For instance, {\tt probe} sounds reasonable as (1) a description in the model of a problem-pattern, (2) as an element of the problem hierarchies key, (3) as a socalled CAS-command, (4) as the name of a related script etc. However, all the cases (1)..(4) require different typing for one and the same identifier {\tt probe} which is impossible, and actually leads to strange errors (for instance (1) is used as string, except in a script addressing a Subproblem).
neuper@37949
    93
neuper@37949
    94
This are the preliminary rules for naming identifiers>
neuper@37949
    95
\begin{description}
neuper@37949
    96
\item [elements of a key] into the hierarchy of problems or methods must not contain capital letters and may contain underscrores, e.g. {\tt probe, for_polynomials}.
neuper@37949
    97
\item [descriptions in problem-patterns] must contain at least 1 capital letter and must not contain underscores, e.g. {\tt Probe, forPolynomials}.
neuper@37949
    98
\item [CAS-commands] follow the same rules as descriptions in problem-patterns above, thus beware of conflicts~!
neuper@37949
    99
\item [script identifiers] always end with {\tt Script}, e.g. {\tt ProbeScript}.
neuper@37949
   100
\item [???] ???
neuper@37949
   101
\item [???] ???
neuper@37949
   102
\end{description}
wneuper@59472
   103
%WN071228 extended\<close>
neuper@37949
   104
wneuper@59549
   105
subsubsection \<open>Rule sets\<close>
wneuper@59472
   106
text \<open>The actual version of the coding standards for rulesets is in {\tt /IsacKnowledge/Atools.ML where it can be viewed using the knowledge browsers.
neuper@37949
   107
neuper@37949
   108
There are rulesets visible to the student, and there are rulesets visible (in general) only for math authors. There are also rulesets which {\em must} exist for {\em each} theory; these contain the identifier of the respective theory (including all capital letters) as indicated by {\it Thy} below.
neuper@37949
   109
\begin{description}
neuper@37949
   110
neuper@37949
   111
\item [norm\_{\it Thy}] exists for each theory, and {\em efficiently} calculates a normalform for all terms which can be expressed by the definitions of the respective theory (and the respective parents).
neuper@37949
   112
neuper@37949
   113
\item [simplify\_{\it Thy}] exists for each theory, and calculates a normalform for all terms which can be expressed by the definitions of the respective theory (and the respective parents) such, that the rewrites can be presented to the student.
neuper@37949
   114
neuper@37949
   115
\item [calculate\_{\it Thy}] exists for each theory, and evaluates terms with numerical constants only (i.e. all terms which can be expressed by the definitions of the respective theory and the respective parent theories). In particular, this ruleset includes evaluating in/equalities with numerical constants only.
neuper@37949
   116
WN.3.7.03: may be dropped due to more generality: numericals and non-numericals are logically equivalent, where the latter often add to the assumptions (e.g. in Check_elementwise).
neuper@37949
   117
\end{description}
neuper@37949
   118
neuper@52155
   119
The above rulesets are all visible to the user, and also may be input; 
neuper@52155
   120
thus they must be contained in {\tt Theory_Data} (KEStore_Elems.add_rlss,
neuper@52155
   121
KEStore_Elems.get_rlss). All these rulesets must undergo a preparation
s1210629013@55444
   122
using the function {\tt prep_rls'}, which generates a script for stepwise rewriting etc.
neuper@37949
   123
The following rulesets are used for internal purposes and usually invisible to the (naive) user:
neuper@37949
   124
\begin{description}
neuper@37949
   125
neuper@37949
   126
\item [*\_erls] TODO
neuper@37949
   127
\item [*\_prls] 
neuper@37949
   128
\item [*\_srls] 
neuper@37949
   129
neuper@37949
   130
\end{description}
wneuper@59416
   131
{\tt Rule.append_rls, Rule.merge_rls, remove_rls} TODO
wneuper@59472
   132
\<close>
neuper@37946
   133
wneuper@59549
   134
subsection \<open>evaluation of numerals and special predicates on the meta-level\<close>
wneuper@59472
   135
ML \<open>
neuper@37972
   136
val thy = @{theory};
neuper@37949
   137
wneuper@59527
   138
fun occurs_in v t = member op = (((map strip_thy) o TermC.ids2str) t) (Term.term_name v);
neuper@37949
   139
neuper@37949
   140
(*("occurs_in", ("Atools.occurs'_in", eval_occurs_in ""))*)
neuper@37949
   141
fun eval_occurs_in _ "Atools.occurs'_in"
neuper@37949
   142
	     (p as (Const ("Atools.occurs'_in",_) $ v $ t)) _ =
wneuper@59416
   143
    ((*tracing("@@@ eval_occurs_in: v= "^(Rule.term2str v));
wneuper@59416
   144
     tracing("@@@ eval_occurs_in: t= "^(Rule.term2str t));*)
neuper@37949
   145
     if occurs_in v t
wneuper@59416
   146
    then SOME ((Rule.term2str p) ^ " = True",
wneuper@59390
   147
	  HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
wneuper@59416
   148
    else SOME ((Rule.term2str p) ^ " = False",
wneuper@59390
   149
	  HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False}))))
neuper@37949
   150
  | eval_occurs_in _ _ _ _ = NONE;
neuper@37949
   151
neuper@37949
   152
(*some of the (bound) variables (eg. in an eqsys) "vs" occur in term "t"*)   
neuper@37949
   153
fun some_occur_in vs t = 
neuper@37949
   154
    let fun occurs_in' a b = occurs_in b a
neuper@37949
   155
    in foldl or_ (false, map (occurs_in' t) vs) end;
neuper@37949
   156
neuper@37949
   157
(*("some_occur_in", ("Atools.some'_occur'_in", 
neuper@37949
   158
			eval_some_occur_in "#eval_some_occur_in_"))*)
neuper@37949
   159
fun eval_some_occur_in _ "Atools.some'_occur'_in"
neuper@37949
   160
			  (p as (Const ("Atools.some'_occur'_in",_) 
neuper@37949
   161
				       $ vs $ t)) _ =
wneuper@59389
   162
    if some_occur_in (TermC.isalist2list vs) t
wneuper@59416
   163
    then SOME ((Rule.term2str p) ^ " = True",
wneuper@59390
   164
	       HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
wneuper@59416
   165
    else SOME ((Rule.term2str p) ^ " = False",
wneuper@59390
   166
	       HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
neuper@37949
   167
  | eval_some_occur_in _ _ _ _ = NONE;
neuper@37949
   168
neuper@37949
   169
neuper@37949
   170
neuper@37949
   171
neuper@37949
   172
(*evaluate 'is_atom'*)
neuper@37949
   173
(*("is_atom",("Atools.is'_atom",eval_is_atom "#is_atom_"))*)
neuper@37949
   174
fun eval_is_atom (thmid:string) "Atools.is'_atom"
neuper@37949
   175
		 (t as (Const(op0,_) $ arg)) thy = 
neuper@37949
   176
    (case arg of 
wneuper@59392
   177
	 Free (n,_) => SOME (TermC.mk_thmid thmid n "", 
wneuper@59390
   178
			      HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
wneuper@59392
   179
       | _ => SOME (TermC.mk_thmid thmid "" "", 
wneuper@59390
   180
		    HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False}))))
neuper@37949
   181
  | eval_is_atom _ _ _ _ = NONE;
neuper@37949
   182
neuper@37949
   183
(*evaluate 'is_even'*)
neuper@37949
   184
fun even i = (i div 2) * 2 = i;
neuper@37949
   185
(*("is_even",("Atools.is'_even",eval_is_even "#is_even_"))*)
neuper@37949
   186
fun eval_is_even (thmid:string) "Atools.is'_even"
neuper@37949
   187
		 (t as (Const(op0,_) $ arg)) thy = 
neuper@37949
   188
    (case arg of 
neuper@37949
   189
	Free (n,_) =>
wneuper@59390
   190
	 (case TermC.int_of_str_opt n of
neuper@37949
   191
	      SOME i =>
wneuper@59392
   192
	      if even i then SOME (TermC.mk_thmid thmid n "", 
wneuper@59390
   193
				   HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
wneuper@59392
   194
	      else SOME (TermC.mk_thmid thmid "" "", 
wneuper@59390
   195
			 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
neuper@37949
   196
	    | _ => NONE)
neuper@37949
   197
       | _ => NONE)
neuper@37949
   198
  | eval_is_even _ _ _ _ = NONE; 
neuper@37949
   199
neuper@37949
   200
(*evaluate 'is_const'*)
neuper@37949
   201
(*("is_const",("Atools.is'_const",eval_const "#is_const_"))*)
neuper@37949
   202
fun eval_const (thmid:string) _(*"Atools.is'_const" WN050820 diff.beh. rooteq*)
neuper@37949
   203
	       (t as (Const(op0,t0) $ arg)) (thy:theory) = 
neuper@37949
   204
    (*eval_const FIXXXXXME.WN.16.5.03 still forgets ComplexI*)
neuper@37949
   205
    (case arg of 
neuper@37949
   206
       Const (n1,_) =>
wneuper@59392
   207
	 SOME (TermC.mk_thmid thmid n1 "", 
wneuper@59390
   208
	       HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
neuper@37949
   209
     | Free (n1,_) =>
wneuper@59390
   210
	 if TermC.is_num' n1
wneuper@59392
   211
	   then SOME (TermC.mk_thmid thmid n1 "", 
wneuper@59390
   212
		      HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
wneuper@59392
   213
	 else SOME (TermC.mk_thmid thmid n1 "", 
wneuper@59390
   214
		    HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
neuper@37949
   215
     | Const ("Float.Float",_) =>
wneuper@59416
   216
       SOME (TermC.mk_thmid thmid (Rule.term2str arg) "", 
wneuper@59390
   217
	     HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
neuper@37949
   218
     | _ => (*NONE*)
wneuper@59416
   219
       SOME (TermC.mk_thmid thmid (Rule.term2str arg) "", 
wneuper@59390
   220
		    HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False}))))
neuper@37949
   221
  | eval_const _ _ _ _ = NONE; 
neuper@37949
   222
neuper@37949
   223
(*. evaluate binary, associative, commutative operators: *,+,^ .*)
neuper@38014
   224
(*("PLUS"    ,("Groups.plus_class.plus"        ,eval_binop "#add_")),
neuper@38034
   225
  ("TIMES"   ,("Groups.times_class.times"        ,eval_binop "#mult_")),
neuper@37949
   226
  ("POWER"  ,("Atools.pow"  ,eval_binop "#power_"))*)
neuper@37949
   227
neuper@37949
   228
(* val (thmid,op_,t as(Const (op0,t0) $ Free (n1,t1) $ Free(n2,t2)),thy) =
neuper@37949
   229
       ("xxxxxx",op_,t,thy);
neuper@37949
   230
   *)
neuper@55487
   231
fun mk_thmid_f thmid ((v11, v12), (p11, p12)) ((v21, v22), (p21, p22)) = (* dropped *)
neuper@55487
   232
  thmid ^ "Float ((" ^ 
neuper@55487
   233
  (string_of_int v11)^","^(string_of_int v12)^"), ("^
neuper@55487
   234
  (string_of_int p11)^","^(string_of_int p12)^")) __ (("^
neuper@55487
   235
  (string_of_int v21)^","^(string_of_int v22)^"), ("^
neuper@55487
   236
  (string_of_int p21)^","^(string_of_int p22)^"))";
neuper@37949
   237
neuper@37949
   238
(*.convert int and float to internal floatingpoint prepresentation.*)
neuper@37949
   239
fun numeral (Free (str, T)) = 
wneuper@59390
   240
    (case TermC.int_of_str_opt str of
neuper@37949
   241
	 SOME i => SOME ((i, 0), (0, 0))
neuper@37949
   242
       | NONE => NONE)
neuper@37949
   243
  | numeral (Const ("Float.Float", _) $
neuper@41972
   244
		   (Const ("Product_Type.Pair", _) $
neuper@41972
   245
			  (Const ("Product_Type.Pair", T) $ Free (v1, _) $ Free (v2,_)) $
neuper@41972
   246
			  (Const ("Product_Type.Pair", _) $ Free (p1, _) $ Free (p2,_))))=
wneuper@59390
   247
    (case (TermC.int_of_str_opt v1, TermC.int_of_str_opt v2, TermC.int_of_str_opt p1, TermC.int_of_str_opt p2) of
neuper@37949
   248
	(SOME v1', SOME v2', SOME p1', SOME p2') =>
neuper@37949
   249
	SOME ((v1', v2'), (p1', p2'))
neuper@37949
   250
      | _ => NONE)
neuper@37949
   251
  | numeral _ = NONE;
neuper@37949
   252
neuper@55487
   253
(* evaluate binary associative operations *)
neuper@55487
   254
fun eval_binop (thmid : string) (op_: string) 
neuper@55487
   255
      (t as (Const (op0, t0) $ (Const (op0', _) $ v $ t1) $ t2)) _ =  (* binary . (v.n1).n2 *)
neuper@37949
   256
    if op0 = op0' then
neuper@55487
   257
      case (numeral t1, numeral t2) of
neuper@55487
   258
        (SOME n1, SOME n2) =>
neuper@55487
   259
          let 
wneuper@59389
   260
            val (T1, _, _) = TermC.dest_binop_typ t0
neuper@55487
   261
            val res = 
neuper@55490
   262
              calcul (if op0 = "Groups.minus_class.minus" then "Groups.plus_class.plus" else op0)n1 n2
wneuper@59360
   263
              (*WN071229 "Rings.divide_class.divide" never tried*)
neuper@55487
   264
            val rhs = var_op_float v op_ t0 T1 res
wneuper@59390
   265
            val prop = HOLogic.Trueprop $ (TermC.mk_equality (t, rhs))
wneuper@59416
   266
          in SOME ("#: " ^ Rule.term2str prop, prop) end
neuper@55487
   267
      | _ => NONE
neuper@37949
   268
    else NONE
neuper@55487
   269
  | eval_binop (thmid : string) (op_ : string) 
neuper@55487
   270
      (t as (Const (op0, t0) $ t1 $ (Const (op0', _) $ t2 $ v))) _ =  (* binary . n1.(n2.v) *)
neuper@55487
   271
    if op0 = op0' then
neuper@55487
   272
      case (numeral t1, numeral t2) of
neuper@55487
   273
        (SOME n1, SOME n2) =>
neuper@55487
   274
          if op0 = "Groups.minus_class.minus" then NONE 
neuper@55487
   275
          else let 
wneuper@59389
   276
            val (T1, _, _) = TermC.dest_binop_typ t0
neuper@55490
   277
            val res = calcul op0 n1 n2
neuper@55487
   278
            val rhs = float_op_var v op_ t0 T1 res
wneuper@59390
   279
            val prop = HOLogic.Trueprop $ (TermC.mk_equality (t, rhs))
wneuper@59416
   280
          in SOME ("#: " ^ Rule.term2str prop, prop) end
neuper@55487
   281
      | _ => NONE
neuper@55487
   282
    else NONE
neuper@55487
   283
  | eval_binop (thmid : string) _ (t as (Const (op0, t0) $ t1 $ t2)) _ =   (* binary . n1.n2 *)
neuper@37949
   284
    (case (numeral t1, numeral t2) of
neuper@55487
   285
      (SOME n1, SOME n2) =>
neuper@55487
   286
        let 
wneuper@59389
   287
          val (_, _, Trange) = TermC.dest_binop_typ t0;
neuper@55490
   288
          val res = calcul op0 n1 n2;
neuper@55487
   289
          val rhs = term_of_float Trange res;
wneuper@59390
   290
          val prop = HOLogic.Trueprop $ (TermC.mk_equality (t, rhs));
wneuper@59416
   291
        in SOME ("#: " ^ Rule.term2str prop, prop) end
neuper@55487
   292
    | _ => NONE)
neuper@37949
   293
  | eval_binop _ _ _ _ = NONE; 
neuper@37949
   294
(*
neuper@38014
   295
> val SOME (thmid, t) = eval_binop "#add_" "Groups.plus_class.plus" (str2term "-1 + 2") thy;
wneuper@59416
   296
> Rule.term2str t;
neuper@37949
   297
val it = "-1 + 2 = 1"
neuper@37949
   298
> val t = str2term "-1 * (-1 * a)";
neuper@38034
   299
> val SOME (thmid, t) = eval_binop "#mult_" "Groups.times_class.times" t thy;
wneuper@59416
   300
> Rule.term2str t;
neuper@37949
   301
val it = "-1 * (-1 * a) = 1 * a"*)
neuper@37949
   302
neuper@37949
   303
neuper@37949
   304
neuper@37949
   305
(*.evaluate < and <= for numerals.*)
neuper@38045
   306
(*("le"      ,("Orderings.ord_class.less"        ,eval_equ "#less_")),
neuper@38045
   307
  ("leq"     ,("Orderings.ord_class.less_eq"       ,eval_equ "#less_equal_"))*)
neuper@37949
   308
fun eval_equ (thmid:string) (op_:string) (t as 
neuper@37949
   309
	       (Const (op0,t0) $ Free (n1,t1) $ Free(n2,t2))) thy = 
wneuper@59390
   310
    (case (TermC.int_of_str_opt n1, TermC.int_of_str_opt n2) of
neuper@37949
   311
	 (SOME n1', SOME n2') =>
wneuper@59401
   312
  if Calc.calc_equ (strip_thy op0) (n1', n2')
wneuper@59392
   313
    then SOME (TermC.mk_thmid thmid n1 n2, 
wneuper@59390
   314
	  HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
wneuper@59392
   315
  else SOME (TermC.mk_thmid thmid n1 n2,  
wneuper@59390
   316
	  HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
neuper@37949
   317
       | _ => NONE)
neuper@37949
   318
    
neuper@37949
   319
  | eval_equ _ _ _ _ = NONE;
neuper@37949
   320
neuper@37949
   321
neuper@37949
   322
(*evaluate identity
neuper@37949
   323
> reflI;
neuper@37949
   324
val it = "(?t = ?t) = True"
neuper@37949
   325
> val t = str2term "x = 0";
wneuper@59416
   326
> val NONE = rewrite_ thy Rule.dummy_ord Rule.e_rls false reflI t;
neuper@37949
   327
neuper@37949
   328
> val t = str2term "1 = 0";
wneuper@59416
   329
> val NONE = rewrite_ thy Rule.dummy_ord Rule.e_rls false reflI t;
wneuper@59416
   330
----------- thus needs Rule.Calc !
neuper@37949
   331
> val t = str2term "0 = 0";
wneuper@59416
   332
> val SOME (t',_) = rewrite_ thy Rule.dummy_ord Rule.e_rls false reflI t;
wneuper@59416
   333
> Rule.term2str t';
neuper@41928
   334
val it = "HOL.True"
neuper@37949
   335
neuper@37949
   336
val t = str2term "Not (x = 0)";
wneuper@59416
   337
atomt t; Rule.term2str t;
neuper@37949
   338
*** -------------
neuper@37949
   339
*** Const ( Not)
neuper@37949
   340
*** . Const ( op =)
neuper@37949
   341
*** . . Free ( x, )
neuper@37949
   342
*** . . Free ( 0, )
neuper@37949
   343
val it = "x ~= 0" : string*)
neuper@37949
   344
neuper@37949
   345
(*.evaluate identity on the term-level, =!= ,i.e. without evaluation of 
neuper@37949
   346
  the arguments: thus special handling by 'fun eval_binop'*)
neuper@37949
   347
(*("ident"   ,("Atools.ident",eval_ident "#ident_")):calc*)
neuper@37949
   348
fun eval_ident (thmid:string) "Atools.ident" (t as 
neuper@37949
   349
	       (Const (op0,t0) $ t1 $ t2 )) thy = 
neuper@37949
   350
  if t1 = t2
wneuper@59392
   351
  then SOME (TermC.mk_thmid thmid 
wneuper@59416
   352
	              ("(" ^ (Rule.term_to_string''' thy t1) ^ ")")
wneuper@59416
   353
	              ("(" ^ (Rule.term_to_string''' thy t2) ^ ")"), 
wneuper@59390
   354
	     HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
wneuper@59392
   355
  else SOME (TermC.mk_thmid thmid  
wneuper@59416
   356
	              ("(" ^ (Rule.term_to_string''' thy t1) ^ ")")
wneuper@59416
   357
	              ("(" ^ (Rule.term_to_string''' thy t2) ^ ")"),  
wneuper@59390
   358
	     HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
neuper@37949
   359
  | eval_ident _ _ _ _ = NONE;
neuper@37949
   360
(* TODO
neuper@37949
   361
> val t = str2term "x =!= 0";
neuper@37949
   362
> val SOME (str, t') = eval_ident "ident_" "b" t thy;
wneuper@59416
   363
> Rule.term2str t';
neuper@37949
   364
val str = "ident_(x)_(0)" : string
neuper@37949
   365
val it = "(x =!= 0) = False" : string                                
neuper@37949
   366
> val t = str2term "1 =!= 0";
neuper@37949
   367
> val SOME (str, t') = eval_ident "ident_" "b" t thy;
wneuper@59416
   368
> Rule.term2str t';
neuper@37949
   369
val str = "ident_(1)_(0)" : string 
neuper@37949
   370
val it = "(1 =!= 0) = False" : string                                       
neuper@37949
   371
> val t = str2term "0 =!= 0";
neuper@37949
   372
> val SOME (str, t') = eval_ident "ident_" "b" t thy;
wneuper@59416
   373
> Rule.term2str t';
neuper@37949
   374
val str = "ident_(0)_(0)" : string
neuper@37949
   375
val it = "(0 =!= 0) = True" : string
neuper@37949
   376
*)
neuper@37949
   377
neuper@37949
   378
(*.evaluate identity of terms, which stay ready for evaluation in turn;
neuper@37949
   379
  thus returns False only for atoms.*)
neuper@41922
   380
(*("equal"   ,("HOL.eq",eval_equal "#equal_")):calc*)
neuper@52070
   381
fun eval_equal (thmid : string) "HOL.eq" (t as (Const (op0,t0) $ t1 $ t2 )) thy = 
neuper@52070
   382
  if t1 = t2
wneuper@59392
   383
  then SOME (TermC.mk_thmid thmid 
wneuper@59416
   384
                ("(" ^ Rule.term_to_string''' thy t1 ^ ")")
wneuper@59416
   385
                ("(" ^ Rule.term_to_string''' thy t2 ^ ")"), 
wneuper@59390
   386
       HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
wneuper@59389
   387
  else (case (TermC.is_atom t1, TermC.is_atom t2) of
neuper@52070
   388
      (true, true) => 
wneuper@59392
   389
      SOME (TermC.mk_thmid thmid  
wneuper@59416
   390
         ("(" ^ Rule.term_to_string''' thy t1 ^ ")")
wneuper@59416
   391
         ("(" ^ Rule.term_to_string''' thy t2 ^ ")"),
wneuper@59390
   392
      HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
neuper@52070
   393
    | _ => NONE)                             (* NOT is_atom t1,t2 --> rew_sub *)
neuper@38053
   394
  | eval_equal _ _ _ _ = NONE;                                  (* error-exit *)
neuper@37949
   395
(*
neuper@37949
   396
val t = str2term "x ~= 0";
neuper@37949
   397
val NONE = eval_equal "equal_" "b" t thy;
neuper@37949
   398
neuper@37949
   399
neuper@37949
   400
> val t = str2term "(x + 1) = (x + 1)";
neuper@37949
   401
> val SOME (str, t') = eval_equal "equal_" "b" t thy;
wneuper@59416
   402
> Rule.term2str t';
neuper@37949
   403
val str = "equal_(x + 1)_(x + 1)" : string
neuper@37949
   404
val it = "(x + 1 = x + 1) = True" : string
neuper@37949
   405
> val t = str2term "x = 0";
neuper@37949
   406
> val NONE = eval_equal "equal_" "b" t thy;
neuper@37949
   407
neuper@37949
   408
> val t = str2term "1 = 0";
neuper@37949
   409
> val SOME (str, t') = eval_equal "equal_" "b" t thy;
wneuper@59416
   410
> Rule.term2str t';
neuper@37949
   411
val str = "equal_(1)_(0)" : string 
neuper@37949
   412
val it = "(1 = 0) = False" : string
neuper@37949
   413
> val t = str2term "0 = 0";
neuper@37949
   414
> val SOME (str, t') = eval_equal "equal_" "b" t thy;
wneuper@59416
   415
> Rule.term2str t';
neuper@37949
   416
val str = "equal_(0)_(0)" : string
neuper@37949
   417
val it = "(0 = 0) = True" : string
neuper@37949
   418
*)
neuper@37949
   419
neuper@37949
   420
wneuper@59472
   421
\<close>
neuper@42451
   422
wneuper@59549
   423
subsection \<open>evaluation on the meta-level\<close>
wneuper@59472
   424
ML \<open>
neuper@37949
   425
(*. evaluate HOL.divide .*)
wneuper@59360
   426
(*("DIVIDE" ,("Rings.divide_class.divide"  ,eval_cancel "#divide_e"))*)
wneuper@59360
   427
fun eval_cancel (thmid:string) "Rings.divide_class.divide" (t as 
neuper@37949
   428
	       (Const (op0,t0) $ Free (n1,t1) $ Free(n2,t2))) thy = 
wneuper@59390
   429
    (case (TermC.int_of_str_opt n1, TermC.int_of_str_opt n2) of
neuper@37949
   430
	 (SOME n1', SOME n2') =>
neuper@37949
   431
  let 
wneuper@59401
   432
    val sg = Calc.sign_mult n1' n2';
wneuper@59389
   433
    val (T1,T2,Trange) = TermC.dest_binop_typ t0;
wneuper@59401
   434
    val gcd' = Calc.gcd (abs n1') (abs n2');
neuper@37949
   435
  in if gcd' = abs n2' 
wneuper@59389
   436
     then let val rhs = TermC.term_of_num Trange (sg * (abs n1') div gcd')
wneuper@59390
   437
	      val prop = HOLogic.Trueprop $ (TermC.mk_equality (t, rhs))
wneuper@59392
   438
	  in SOME (TermC.mk_thmid thmid n1 n2, prop) end     
neuper@37949
   439
     else if 0 < n2' andalso gcd' = 1 then NONE
wneuper@59390
   440
     else let val rhs = TermC.mk_num_op_num T1 T2 (op0,t0) (sg * (abs n1') div gcd')
neuper@37949
   441
				   ((abs n2') div gcd')
wneuper@59390
   442
	      val prop = HOLogic.Trueprop $ (TermC.mk_equality (t, rhs))
wneuper@59392
   443
	  in SOME (TermC.mk_thmid thmid n1 n2, prop) end
neuper@37949
   444
  end
neuper@38015
   445
       | _ => ((*tracing"@@@ eval_cancel NONE";*)NONE))
neuper@37949
   446
neuper@37949
   447
  | eval_cancel _ _ _ _ = NONE;
neuper@37949
   448
neuper@37949
   449
(*. get the argument from a function-definition.*)
neuper@37949
   450
(*("argument_in" ,("Atools.argument'_in",
neuper@37949
   451
		   eval_argument_in "Atools.argument'_in"))*)
neuper@37949
   452
fun eval_argument_in _ "Atools.argument'_in" 
neuper@37949
   453
		     (t as (Const ("Atools.argument'_in", _) $ (f $ arg))) _ =
neuper@37949
   454
    if is_Free arg (*could be something to be simplified before*)
wneuper@59416
   455
    then SOME (Rule.term2str t ^ " = " ^ Rule.term2str arg,
wneuper@59390
   456
	       HOLogic.Trueprop $ (TermC.mk_equality (t, arg)))
neuper@37949
   457
    else NONE
neuper@37949
   458
  | eval_argument_in _ _ _ _ = NONE;
neuper@37949
   459
neuper@37949
   460
(*.check if the function-identifier of the first argument matches 
neuper@37949
   461
   the function-identifier of the lhs of the second argument.*)
neuper@37949
   462
(*("sameFunId" ,("Atools.sameFunId",
neuper@37949
   463
		   eval_same_funid "Atools.sameFunId"))*)
neuper@37949
   464
fun eval_sameFunId _ "Atools.sameFunId" 
neuper@37949
   465
		     (p as Const ("Atools.sameFunId",_) $ 
neuper@37949
   466
			(f1 $ _) $ 
neuper@41922
   467
			(Const ("HOL.eq", _) $ (f2 $ _) $ _)) _ =
neuper@37949
   468
    if f1 = f2 
wneuper@59416
   469
    then SOME ((Rule.term2str p) ^ " = True",
wneuper@59390
   470
	       HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
wneuper@59416
   471
    else SOME ((Rule.term2str p) ^ " = False",
wneuper@59390
   472
	       HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
neuper@37949
   473
| eval_sameFunId _ _ _ _ = NONE;
neuper@37949
   474
neuper@37949
   475
neuper@37949
   476
(*.from a list of fun-definitions "f x = ..." as 2nd argument
neuper@37949
   477
   filter the elements with the same fun-identfier in "f y"
neuper@37949
   478
   as the fst argument;
neuper@37949
   479
   this is, because Isabelles filter takes more than 1 sec.*)
neuper@41922
   480
fun same_funid f1 (Const ("HOL.eq", _) $ (f2 $ _) $ _) = f1 = f2
neuper@38031
   481
  | same_funid f1 t = error ("same_funid called with t = ("
wneuper@59416
   482
				   ^Rule.term2str f1^") ("^Rule.term2str t^")");
neuper@37949
   483
(*("filter_sameFunId" ,("Atools.filter'_sameFunId",
neuper@37949
   484
		   eval_filter_sameFunId "Atools.filter'_sameFunId"))*)
neuper@37949
   485
fun eval_filter_sameFunId _ "Atools.filter'_sameFunId" 
neuper@37949
   486
		     (p as Const ("Atools.filter'_sameFunId",_) $ 
neuper@37949
   487
			(fid $ _) $ fs) _ =
wneuper@59389
   488
    let val fs' = ((TermC.list2isalist HOLogic.boolT) o 
wneuper@59389
   489
		   (filter (same_funid fid))) (TermC.isalist2list fs)
wneuper@59416
   490
    in SOME (Rule.term2str (TermC.mk_equality (p, fs')),
wneuper@59390
   491
	       HOLogic.Trueprop $ (TermC.mk_equality (p, fs'))) end
neuper@37949
   492
| eval_filter_sameFunId _ _ _ _ = NONE;
neuper@37949
   493
neuper@37949
   494
neuper@37949
   495
(*make a list of terms to a sum*)
neuper@37949
   496
fun list2sum [] = error ("list2sum called with []")
neuper@37949
   497
  | list2sum [s] = s
neuper@37949
   498
  | list2sum (s::ss) = 
neuper@37949
   499
    let fun sum su [s'] = 
neuper@38014
   500
	    Const ("Groups.plus_class.plus", [HOLogic.realT,HOLogic.realT]--->HOLogic.realT)
neuper@37949
   501
		  $ su $ s'
neuper@37949
   502
	  | sum su (s'::ss') = 
neuper@38014
   503
	    sum (Const ("Groups.plus_class.plus", [HOLogic.realT,HOLogic.realT]--->HOLogic.realT)
neuper@37949
   504
		  $ su $ s') ss'
neuper@37949
   505
    in sum s ss end;
neuper@37949
   506
neuper@37949
   507
(*make a list of equalities to the sum of the lhs*)
neuper@37949
   508
(*("boollist2sum"    ,("Atools.boollist2sum"    ,eval_boollist2sum "")):calc*)
neuper@37949
   509
fun eval_boollist2sum _ "Atools.boollist2sum" 
neuper@37949
   510
		      (p as Const ("Atools.boollist2sum", _) $ 
neuper@37949
   511
			 (l as Const ("List.list.Cons", _) $ _ $ _)) _ =
wneuper@59389
   512
    let val isal = TermC.isalist2list l
wneuper@59491
   513
	val lhss = map Tools.lhs isal
neuper@37949
   514
	val sum = list2sum lhss
wneuper@59416
   515
    in SOME ((Rule.term2str p) ^ " = " ^ (Rule.term2str sum),
wneuper@59390
   516
	  HOLogic.Trueprop $ (TermC.mk_equality (p, sum)))
neuper@37949
   517
    end
neuper@37949
   518
| eval_boollist2sum _ _ _ _ = NONE;
wneuper@59549
   519
\<close>
neuper@37949
   520
wneuper@59549
   521
subsection \<open>rule sets, for evaluating list-expressions in scripts, etc\<close>
wneuper@59549
   522
ML \<open>
neuper@37949
   523
local
neuper@37949
   524
neuper@37949
   525
open Term;
neuper@37949
   526
neuper@37949
   527
in
wneuper@59457
   528
fun termlessI (_: Rule.subst) uv = LibraryC.termless uv;
wneuper@59416
   529
fun term_ordI (_: Rule.subst) uv = Term_Ord.term_ord uv;
neuper@37949
   530
end;
neuper@37949
   531
wneuper@59416
   532
val list_rls = Rule.append_rls "list_rls" list_rls
wneuper@59416
   533
	 [Rule.Calc ("Groups.times_class.times",eval_binop "#mult_"),
wneuper@59416
   534
		Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
wneuper@59416
   535
		Rule.Calc ("Orderings.ord_class.less",eval_equ "#less_"),
wneuper@59416
   536
		Rule.Calc ("Orderings.ord_class.less_eq",eval_equ "#less_equal_"),
wneuper@59416
   537
		Rule.Calc ("Atools.ident",eval_ident "#ident_"),
wneuper@59416
   538
		Rule.Calc ("HOL.eq",eval_equal "#equal_"),(*atom <> atom -> False*)
neuper@37949
   539
       
wneuper@59491
   540
		Rule.Calc ("Tools.Vars",Tools.eval_var "#Vars_"),
neuper@37949
   541
		
wneuper@59416
   542
		Rule.Thm ("if_True",TermC.num_str @{thm if_True}),
wneuper@59416
   543
		Rule.Thm ("if_False",TermC.num_str @{thm if_False})
neuper@37949
   544
		];
wneuper@59472
   545
\<close>
wneuper@59472
   546
ML \<open>
neuper@37949
   547
wneuper@59416
   548
(*TODO.WN0509 reduce ids: tless_true = e_rew_ord' = Rule.e_rew_ord = Rule.dummy_ord*)
wneuper@59416
   549
val tless_true = Rule.dummy_ord;
wneuper@59416
   550
Rule.rew_ord' := overwritel (! Rule.rew_ord',
neuper@37949
   551
			[("tless_true", tless_true),
neuper@37949
   552
			 ("e_rew_ord'", tless_true),
wneuper@59416
   553
			 ("dummy_ord", Rule.dummy_ord)]);
neuper@37949
   554
wneuper@59424
   555
val calculate_Base_Tools = 
wneuper@59416
   556
    Rule.append_rls "calculate_Atools" Rule.e_rls
wneuper@59416
   557
               [Rule.Calc ("Orderings.ord_class.less",eval_equ "#less_"),
wneuper@59416
   558
		Rule.Calc ("Orderings.ord_class.less_eq",eval_equ "#less_equal_"),
wneuper@59416
   559
		Rule.Calc ("HOL.eq",eval_equal "#equal_"),
neuper@37949
   560
wneuper@59416
   561
		Rule.Thm  ("real_unari_minus",TermC.num_str @{thm real_unari_minus}),
wneuper@59416
   562
		Rule.Calc ("Groups.plus_class.plus",eval_binop "#add_"),
wneuper@59416
   563
		Rule.Calc ("Groups.minus_class.minus",eval_binop "#sub_"),
wneuper@59416
   564
		Rule.Calc ("Groups.times_class.times",eval_binop "#mult_")
neuper@37949
   565
		];
neuper@37949
   566
wneuper@59472
   567
\<close>
neuper@42451
   568
neuper@48763
   569
find_theorems (9) "?n <= ?n"
neuper@48763
   570
wneuper@59472
   571
ML \<open>
neuper@37949
   572
val Atools_erls = 
wneuper@59416
   573
    Rule.append_rls "Atools_erls" Rule.e_rls
wneuper@59416
   574
               [Rule.Calc ("HOL.eq",eval_equal "#equal_"),
wneuper@59416
   575
                Rule.Thm ("not_true",TermC.num_str @{thm not_true}),
neuper@37949
   576
		(*"(~ True) = False"*)
wneuper@59416
   577
		Rule.Thm ("not_false",TermC.num_str @{thm not_false}),
neuper@37949
   578
		(*"(~ False) = True"*)
wneuper@59416
   579
		Rule.Thm ("and_true",TermC.num_str @{thm and_true}),
neuper@37949
   580
		(*"(?a & True) = ?a"*)
wneuper@59416
   581
		Rule.Thm ("and_false",TermC.num_str @{thm and_false}),
neuper@37949
   582
		(*"(?a & False) = False"*)
wneuper@59416
   583
		Rule.Thm ("or_true",TermC.num_str @{thm or_true}),
neuper@37949
   584
		(*"(?a | True) = True"*)
wneuper@59416
   585
		Rule.Thm ("or_false",TermC.num_str @{thm or_false}),
neuper@37949
   586
		(*"(?a | False) = ?a"*)
neuper@37949
   587
               
wneuper@59416
   588
		Rule.Thm ("rat_leq1",TermC.num_str @{thm rat_leq1}),
wneuper@59416
   589
		Rule.Thm ("rat_leq2",TermC.num_str @{thm rat_leq2}),
wneuper@59416
   590
		Rule.Thm ("rat_leq3",TermC.num_str @{thm rat_leq3}),
wneuper@59416
   591
                Rule.Thm ("refl",TermC.num_str @{thm refl}),
wneuper@59416
   592
		Rule.Thm ("order_refl",TermC.num_str @{thm order_refl}),
wneuper@59416
   593
		Rule.Thm ("radd_left_cancel_le",TermC.num_str @{thm radd_left_cancel_le}),
neuper@37949
   594
		
wneuper@59416
   595
		Rule.Calc ("Orderings.ord_class.less",eval_equ "#less_"),
wneuper@59416
   596
		Rule.Calc ("Orderings.ord_class.less_eq",eval_equ "#less_equal_"),
neuper@37949
   597
		
wneuper@59416
   598
		Rule.Calc ("Atools.ident",eval_ident "#ident_"),    
wneuper@59416
   599
		Rule.Calc ("Atools.is'_const",eval_const "#is_const_"),
wneuper@59416
   600
		Rule.Calc ("Atools.occurs'_in",eval_occurs_in ""),    
wneuper@59491
   601
		Rule.Calc ("Tools.matches", Tools.eval_matches "")
neuper@37949
   602
		];
neuper@37949
   603
wneuper@59472
   604
\<close>
neuper@42451
   605
wneuper@59472
   606
ML \<open>
neuper@37949
   607
val Atools_crls = 
wneuper@59416
   608
    Rule.append_rls "Atools_crls" Rule.e_rls
wneuper@59416
   609
               [Rule.Calc ("HOL.eq",eval_equal "#equal_"),
wneuper@59416
   610
                Rule.Thm ("not_true",TermC.num_str @{thm not_true}),
wneuper@59416
   611
		Rule.Thm ("not_false",TermC.num_str @{thm not_false}),
wneuper@59416
   612
		Rule.Thm ("and_true",TermC.num_str @{thm and_true}),
wneuper@59416
   613
		Rule.Thm ("and_false",TermC.num_str @{thm and_false}),
wneuper@59416
   614
		Rule.Thm ("or_true",TermC.num_str @{thm or_true}),
wneuper@59416
   615
		Rule.Thm ("or_false",TermC.num_str @{thm or_false}),
neuper@37949
   616
               
wneuper@59416
   617
		Rule.Thm ("rat_leq1",TermC.num_str @{thm rat_leq1}),
wneuper@59416
   618
		Rule.Thm ("rat_leq2",TermC.num_str @{thm rat_leq2}),
wneuper@59416
   619
		Rule.Thm ("rat_leq3",TermC.num_str @{thm rat_leq3}),
wneuper@59416
   620
                Rule.Thm ("refl",TermC.num_str @{thm refl}),
wneuper@59416
   621
		Rule.Thm ("order_refl",TermC.num_str @{thm order_refl}),
wneuper@59416
   622
		Rule.Thm ("radd_left_cancel_le",TermC.num_str @{thm radd_left_cancel_le}),
neuper@37949
   623
		
wneuper@59416
   624
		Rule.Calc ("Orderings.ord_class.less",eval_equ "#less_"),
wneuper@59416
   625
		Rule.Calc ("Orderings.ord_class.less_eq",eval_equ "#less_equal_"),
neuper@37949
   626
		
wneuper@59416
   627
		Rule.Calc ("Atools.ident",eval_ident "#ident_"),    
wneuper@59416
   628
		Rule.Calc ("Atools.is'_const",eval_const "#is_const_"),
wneuper@59416
   629
		Rule.Calc ("Atools.occurs'_in",eval_occurs_in ""),    
wneuper@59491
   630
		Rule.Calc ("Tools.matches", Tools.eval_matches "")
neuper@37949
   631
		];
neuper@37949
   632
neuper@37949
   633
(*val atools_erls = ... waere zu testen ...
wneuper@59416
   634
    Rule.merge_rls calculate_Atools
wneuper@59416
   635
	      (Rule.append_rls Atools_erls (*i.A. zu viele rules*)
wneuper@59416
   636
			  [Rule.Calc ("Atools.ident",eval_ident "#ident_"),    
wneuper@59416
   637
			   Rule.Calc ("Atools.is'_const",eval_const "#is_const_"),
wneuper@59416
   638
			   Rule.Calc ("Atools.occurs'_in",
neuper@37949
   639
				 eval_occurs_in "#occurs_in"),    
wneuper@59416
   640
			   Rule.Calc ("Tools.matches",eval_matches "#matches")
neuper@37949
   641
			   ] (*i.A. zu viele rules*)
neuper@37949
   642
			  );*)
s1210629013@55444
   643
(* val atools_erls = prep_rls'(     (*outcommented*)
wneuper@59416
   644
  Rule.Rls {id="atools_erls",preconds = [], rew_ord = ("termlessI",termlessI), 
wneuper@59416
   645
      erls = Rule.e_rls, srls = Rule.Erls, calc = [], errpatts = [],
wneuper@59416
   646
      rules = [Rule.Thm ("refl",num_str @{thm refl}),
wneuper@59416
   647
		Rule.Thm ("order_refl",num_str @{thm order_refl}),
wneuper@59416
   648
		Rule.Thm ("radd_left_cancel_le",num_str @{thm radd_left_cancel_le}),
wneuper@59416
   649
		Rule.Thm ("not_true",num_str @{thm not_true}),
wneuper@59416
   650
		Rule.Thm ("not_false",num_str @{thm not_false}),
wneuper@59416
   651
		Rule.Thm ("and_true",num_str @{thm and_true}),
wneuper@59416
   652
		Rule.Thm ("and_false",num_str @{thm and_false}),
wneuper@59416
   653
		Rule.Thm ("or_true",num_str @{thm or_true}),
wneuper@59416
   654
		Rule.Thm ("or_false",num_str @{thm or_false}),
wneuper@59416
   655
		Rule.Thm ("and_commute",num_str @{thm and_commute}),
wneuper@59416
   656
		Rule.Thm ("or_commute",num_str @{thm or_commute}),
neuper@37949
   657
		
wneuper@59416
   658
		Rule.Calc ("Orderings.ord_class.less",eval_equ "#less_"),
wneuper@59416
   659
		Rule.Calc ("Orderings.ord_class.less_eq",eval_equ "#less_equal_"),
neuper@37949
   660
		
wneuper@59416
   661
		Rule.Calc ("Atools.ident",eval_ident "#ident_"),    
wneuper@59416
   662
		Rule.Calc ("Atools.is'_const",eval_const "#is_const_"),
wneuper@59416
   663
		Rule.Calc ("Atools.occurs'_in",eval_occurs_in ""),    
wneuper@59416
   664
		Rule.Calc ("Tools.matches",eval_matches "")
neuper@37949
   665
	       ],
wneuper@59416
   666
      scr = Rule.Prog ((Thm.term_of o the o (parse @{theory})) "empty_script")
wneuper@59406
   667
      });
neuper@37949
   668
*)
neuper@37949
   669
"******* Atools.ML end *******";
wneuper@59472
   670
\<close>
wneuper@59549
   671
subsection \<open>write to KEStore: calcs, rule-sets\<close>
wneuper@59472
   672
setup \<open>KEStore_Elems.add_calcs
s1210629013@52145
   673
  [("occurs_in",("Atools.occurs'_in", eval_occurs_in "#occurs_in_")),
s1210629013@52145
   674
    ("some_occur_in",
s1210629013@52145
   675
      ("Atools.some'_occur'_in", eval_some_occur_in "#some_occur_in_")),
s1210629013@52145
   676
    ("is_atom"  ,("Atools.is'_atom", eval_is_atom "#is_atom_")),
s1210629013@52145
   677
    ("is_even"  ,("Atools.is'_even", eval_is_even "#is_even_")),
s1210629013@52145
   678
    ("is_const" ,("Atools.is'_const", eval_const "#is_const_")),
s1210629013@52145
   679
    ("le"       ,("Orderings.ord_class.less", eval_equ "#less_")),
s1210629013@52145
   680
    ("leq"      ,("Orderings.ord_class.less_eq", eval_equ "#less_equal_")),
s1210629013@52145
   681
    ("ident"    ,("Atools.ident", eval_ident "#ident_")),
s1210629013@52145
   682
    ("equal"    ,("HOL.eq", eval_equal "#equal_")),
s1210629013@52145
   683
    ("PLUS"     ,("Groups.plus_class.plus", eval_binop "#add_")),
s1210629013@52145
   684
    ("MINUS"    ,("Groups.minus_class.minus", eval_binop "#sub_")),
s1210629013@52145
   685
    ("TIMES"    ,("Groups.times_class.times", eval_binop "#mult_")),
wneuper@59360
   686
    ("DIVIDE"  ,("Rings.divide_class.divide", eval_cancel "#divide_e")),
s1210629013@52145
   687
    ("POWER"   ,("Atools.pow", eval_binop "#power_")),
wneuper@59472
   688
    ("boollist2sum",("Atools.boollist2sum", eval_boollist2sum ""))]\<close>
wneuper@59472
   689
ML \<open>
wneuper@59416
   690
val list_rls = LTool.prep_rls @{theory} (Rule.merge_rls "list_erls"
wneuper@59416
   691
	(Rule.Rls {id = "replaced", preconds = [], rew_ord = ("termlessI", termlessI),
wneuper@59416
   692
    erls = Rule.Rls {id = "list_elrs", preconds = [], rew_ord = ("termlessI", termlessI), 
wneuper@59416
   693
      erls = Rule.e_rls, srls = Rule.Erls, calc = [], errpatts = [],
wneuper@59416
   694
      rules = [Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_"),
wneuper@59416
   695
        Rule.Calc ("Orderings.ord_class.less", eval_equ "#less_")
neuper@52139
   696
        (*    ~~~~~~ for nth_Cons_*)],
wneuper@59416
   697
      scr = Rule.EmptyScr},
wneuper@59416
   698
    srls = Rule.Erls, calc = [], errpatts = [],
wneuper@59416
   699
    rules = [], scr = Rule.EmptyScr})
neuper@52139
   700
  list_rls);
wneuper@59472
   701
\<close>
wneuper@59472
   702
setup \<open>KEStore_Elems.add_rlss
wneuper@59472
   703
  [("list_rls", (Context.theory_name @{theory}, LTool.prep_rls @{theory} list_rls))]\<close>
neuper@48764
   704
wneuper@59457
   705
ML \<open>
wneuper@59457
   706
\<close> ML \<open>
wneuper@59457
   707
\<close> 
neuper@37906
   708
end