src/Tools/isac/Knowledge/Test.thy
author wneuper <walther.neuper@jku.at>
Thu, 29 Apr 2021 14:13:11 +0200
changeset 60269 74965ce81297
parent 60262 aa0f0bf98d40
child 60275 98ee674d18d3
permissions -rw-r--r--
eliminate warnings from src/*, finished
wneuper@59430
     1
(* Knowledge for tests, specifically simplified or bound to a fixed state
wneuper@59430
     2
   for the purpose of simplifying tests.
neuper@37954
     3
   Author: Walther Neuper 2003
neuper@37954
     4
   (c) due to copyright terms
wneuper@59432
     5
wneuper@59432
     6
Notes on cleanup:
wneuper@59432
     7
(0) revert import Test -- DiophantEq, this raises issues related to (1..4)
wneuper@59432
     8
(1) transfer methods to respective theories, if only test, then hierarchy at ["...", "Test"]:
wneuper@59432
     9
    differentiate, root equatioh, polynomial equation, diophantine equation
wneuper@59432
    10
(2) transfer problems accordingly
wneuper@59432
    11
(3) rearrange rls according to (1..2)
wneuper@59432
    12
(4) rearrange axiomatizations according to (3)
neuper@37954
    13
*) 
neuper@37906
    14
wneuper@59424
    15
theory Test imports Base_Tools Poly Rational Root Diff begin
neuper@37906
    16
 
wneuper@59551
    17
section \<open>consts for problems\<close>
wneuper@59430
    18
consts
neuper@42008
    19
  "is'_root'_free"   :: "'a => bool"      ("is'_root'_free _" 10)
neuper@42008
    20
  "contains'_root"   :: "'a => bool"      ("contains'_root _" 10)
neuper@42008
    21
neuper@42008
    22
  "precond'_rootmet" :: "'a => bool"      ("precond'_rootmet _" 10)
neuper@42008
    23
  "precond'_rootpbl" :: "'a => bool"      ("precond'_rootpbl _" 10)
neuper@42008
    24
  "precond'_submet"  :: "'a => bool"      ("precond'_submet _" 10)
neuper@42008
    25
  "precond'_subpbl"  :: "'a => bool"      ("precond'_subpbl _" 10)
neuper@37906
    26
neuper@37906
    27
wneuper@59472
    28
section \<open>functions\<close>
wneuper@59472
    29
ML \<open>
wneuper@59430
    30
fun bin_o (Const (op_, (Type ("fun", [Type (s2, []), Type ("fun", [Type (s4, _),Type (s5, _)])]))))
wneuper@59430
    31
      = if s2 = s4 andalso s4 = s5 then [op_] else []
wneuper@59430
    32
    | bin_o _ = [];
neuper@37906
    33
wneuper@59430
    34
fun bin_op (t1 $ t2) = union op = (bin_op t1) (bin_op t2)
wneuper@59430
    35
  | bin_op t         =  bin_o t;
wneuper@59430
    36
fun is_bin_op t = (bin_op t <> []);
neuper@37906
    37
wneuper@59430
    38
fun bin_op_arg1 ((Const (_,
wneuper@59430
    39
    (Type ("fun", [Type (_, []), Type ("fun", [Type _, Type _])])))) $ arg1 $ _) = arg1
walther@59868
    40
  | bin_op_arg1 t = raise ERROR ("bin_op_arg1: t = " ^ UnparseC.term t);
wneuper@59430
    41
fun bin_op_arg2 ((Const (_,
wneuper@59430
    42
    (Type ("fun", [Type (_, []),Type ("fun", [Type _, Type _])]))))$ _ $ arg2) = arg2
walther@59868
    43
  | bin_op_arg2 t = raise ERROR ("bin_op_arg1: t = " ^ UnparseC.term t);
neuper@37906
    44
wneuper@59430
    45
exception NO_EQUATION_TERM;
wneuper@59430
    46
fun is_equation ((Const ("HOL.eq",
wneuper@59430
    47
    (Type ("fun", [Type (_, []), Type ("fun", [Type (_, []),Type ("bool",[])])])))) $ _ $ _) = true
wneuper@59430
    48
  | is_equation _ = false;
wneuper@59430
    49
fun equ_lhs ((Const ("HOL.eq",
wneuper@59430
    50
    (Type ("fun", [Type (_, []), Type ("fun", [Type (_, []),Type ("bool",[])])])))) $ l $ _) = l
wneuper@59430
    51
  | equ_lhs _ = raise NO_EQUATION_TERM;
wneuper@59430
    52
fun equ_rhs ((Const ("HOL.eq", (Type ("fun",
wneuper@59430
    53
		 [Type (_, []), Type ("fun", [Type (_, []), Type ("bool",[])])])))) $ _ $ r) = r
wneuper@59430
    54
  | equ_rhs _ = raise NO_EQUATION_TERM;
neuper@37906
    55
wneuper@59430
    56
fun atom (Const (_, Type (_,[]))) = true
wneuper@59430
    57
  | atom (Free (_, Type (_,[]))) = true
wneuper@59430
    58
  | atom (Var (_, Type (_,[]))) = true
wneuper@59430
    59
  | atom((Const ("Bin.integ_of_bin",_)) $ _) = true
wneuper@59430
    60
  | atom _ = false;
wneuper@59430
    61
wneuper@59430
    62
fun varids (Const (s, Type (_,[]))) = [strip_thy s]
wneuper@59430
    63
  | varids (Free (s, Type (_,[]))) = if TermC.is_num' s then [] else [strip_thy s]  
wneuper@59430
    64
  | varids (Var((s, _),Type (_,[]))) = [strip_thy s]
wneuper@59430
    65
(*| varids (_      (s,"?DUMMY"   )) =   ..ML-error *)
wneuper@59430
    66
  | varids((Const ("Bin.integ_of_bin",_)) $ _)= [](*8.01: superfluous?*)
wneuper@59430
    67
  | varids (Abs (a, _, t)) = union op = [a] (varids t)
wneuper@59430
    68
  | varids (t1 $ t2) = union op = (varids t1) (varids t2)
wneuper@59430
    69
  | varids _ = [];
wneuper@59430
    70
wneuper@59430
    71
fun bin_ops_only ((Const op_) $ t1 $ t2) =
wneuper@59430
    72
    if is_bin_op (Const op_) then bin_ops_only t1 andalso bin_ops_only t2 else false
wneuper@59430
    73
  | bin_ops_only t = if atom t then true else bin_ops_only t;
wneuper@59430
    74
wneuper@59430
    75
fun polynomial opl t _(* bdVar TODO *) =
wneuper@59430
    76
    subset op = (bin_op t, opl) andalso (bin_ops_only t);
wneuper@59430
    77
wneuper@59430
    78
fun poly_equ opl bdVar t = is_equation t (* bdVar TODO *) 
wneuper@59430
    79
    andalso polynomial opl (equ_lhs t) bdVar 
wneuper@59430
    80
    andalso polynomial opl (equ_rhs t) bdVar
wneuper@59430
    81
    andalso (subset op = (varids bdVar, varids (equ_lhs t)) orelse
wneuper@59430
    82
             subset op = (varids bdVar, varids (equ_lhs t)));
wneuper@59430
    83
wneuper@59430
    84
fun max (a,b) = if a < b then b else a;
wneuper@59430
    85
wneuper@59430
    86
fun degree addl mul bdVar t =
wneuper@59430
    87
let
wneuper@59430
    88
fun deg _ _ v (Const  (s, Type (_, []))) = if v=strip_thy s then 1 else 0
wneuper@59430
    89
  | deg _ _ v (Free   (s, Type (_, []))) = if v=strip_thy s then 1 else 0
wneuper@59430
    90
  | deg _ _ v (Var((s, _), Type (_, []))) = if v=strip_thy s then 1 else 0
wneuper@59430
    91
(*| deg _ _ v (_     (s,"?DUMMY"   ))          =   ..ML-error *) 
wneuper@59430
    92
  | deg _ _ _ ((Const ("Bin.integ_of_bin", _)) $ _ ) = 0 
wneuper@59430
    93
  | deg addl mul v (h $ t1 $ t2) =
wneuper@59430
    94
    if subset op = (bin_op h, addl)
wneuper@59430
    95
    then max (deg addl mul v t1  , deg addl mul v t2)
wneuper@59430
    96
    else (*mul!*)(deg addl mul v t1) + (deg addl mul v t2)
walther@59868
    97
  | deg _ _ _ t = raise ERROR ("deg: t = " ^ UnparseC.term t)
wneuper@59430
    98
in
wneuper@59430
    99
  if polynomial (addl @ [mul]) t bdVar
wneuper@59430
   100
  then SOME (deg addl mul (id_of bdVar) t)
wneuper@59430
   101
  else (NONE:int option)
wneuper@59430
   102
end;
wneuper@59430
   103
fun degree_ addl mul bdVar t = (* do not export *)
wneuper@59430
   104
let
wneuper@59430
   105
  fun opt (SOME i)= i
wneuper@59430
   106
	  | opt  NONE = 0
wneuper@59430
   107
in opt (degree addl mul bdVar t) end;
wneuper@59430
   108
wneuper@59430
   109
fun linear addl mul t bdVar = (degree_ addl mul bdVar t) < 2;
wneuper@59430
   110
wneuper@59430
   111
fun linear_equ addl mul bdVar t =
wneuper@59430
   112
  if is_equation t 
wneuper@59430
   113
  then
wneuper@59430
   114
    let
wneuper@59430
   115
      val degl = degree_ addl mul bdVar (equ_lhs t);
wneuper@59430
   116
	    val degr = degree_ addl mul bdVar (equ_rhs t)
wneuper@59430
   117
	  in if (degl>0 orelse degr>0)andalso max(degl,degr) < 2 then true else false end
wneuper@59430
   118
  else false;
wneuper@59430
   119
(* strip_thy op_  before *)
wneuper@59430
   120
fun is_div_op (dv, (Const (op_,
wneuper@59430
   121
    (Type ("fun", [Type (_, []), Type ("fun", [Type _, Type _])])))) ) = (dv = strip_thy op_)
wneuper@59430
   122
  | is_div_op _ = false;
wneuper@59430
   123
wneuper@59430
   124
fun is_denom bdVar div_op t =
walther@60269
   125
  let
walther@60269
   126
    fun is bool [v] _ (Const  (s,Type(_,[])))= bool andalso(if v = strip_thy s then true else false)
walther@60269
   127
  	  | is bool [v] _ (Free   (s,Type(_,[])))= bool andalso(if v = strip_thy s then true else false) 
walther@60269
   128
  	  | is bool [v] _ (Var((s,_),Type(_,[])))= bool andalso(if v = strip_thy s then true else false)
walther@60269
   129
  	  | is _ [_] _ ((Const ("Bin.integ_of_bin",_)) $ _) = false 
walther@60269
   130
  	  | is bool [v] dv (h$n$d) = 
walther@60269
   131
	      if is_div_op (dv, h) 
walther@60269
   132
	      then (is false [v] dv n) orelse(is true [v] dv d)
walther@60269
   133
	      else (is bool [v] dv n) orelse(is bool [v] dv d)
walther@60269
   134
  	  | is _ _ _ _ = raise ERROR "is_denom: uncovered case in fun.def."    
walther@60269
   135
  in is false (varids bdVar) (strip_thy div_op) t end;
wneuper@59430
   136
wneuper@59430
   137
wneuper@59430
   138
fun rational t div_op bdVar = 
wneuper@59430
   139
    is_denom bdVar div_op t andalso bin_ops_only t;
wneuper@59430
   140
wneuper@59472
   141
\<close>
wneuper@59430
   142
wneuper@59472
   143
section \<open>axiomatizations\<close>
neuper@52148
   144
axiomatization where (*TODO: prove as theorems*)
neuper@37906
   145
neuper@52148
   146
  radd_mult_distrib2:      "(k::real) * (m + n) = k * m + k * n" and
neuper@52148
   147
  rdistr_right_assoc:      "(k::real) + l * n + m * n = k + (l + m) * n" and
neuper@52148
   148
  rdistr_right_assoc_p:    "l * n + (m * n + (k::real)) = (l + m) * n + k" and
neuper@52148
   149
  rdistr_div_right:        "((k::real) + l) / n = k / n + l / n" and
neuper@37983
   150
  rcollect_right:
neuper@52148
   151
          "[| l is_const; m is_const |] ==> (l::real)*n + m*n = (l + m) * n" and
neuper@37983
   152
  rcollect_one_left:
neuper@52148
   153
          "m is_const ==> (n::real) + m * n = (1 + m) * n" and
neuper@37983
   154
  rcollect_one_left_assoc:
neuper@52148
   155
          "m is_const ==> (k::real) + n + m * n = k + (1 + m) * n" and
neuper@37983
   156
  rcollect_one_left_assoc_p:
neuper@52148
   157
          "m is_const ==> n + (m * n + (k::real)) = (1 + m) * n + k" and
neuper@37906
   158
neuper@52148
   159
  rtwo_of_the_same:        "a + a = 2 * a" and
neuper@52148
   160
  rtwo_of_the_same_assoc:  "(x + a) + a = x + 2 * a" and
neuper@52148
   161
  rtwo_of_the_same_assoc_p:"a + (a + x) = 2 * a + x" and
neuper@37906
   162
neuper@52148
   163
  rcancel_den:             "not(a=0) ==> a * (b / a) = b" and
neuper@52148
   164
  rcancel_const:           "[| a is_const; b is_const |] ==> a*(x/b) = a/b*x" and
neuper@52148
   165
  rshift_nominator:        "(a::real) * b / c = a / c * b" and
neuper@37906
   166
walther@60242
   167
  exp_pow:                 "(a \<up> b) \<up> c = a \<up> (b * c)" and
walther@60242
   168
  rsqare:                  "(a::real) * a = a \<up> 2" and
walther@60242
   169
  power_1:                 "(a::real) \<up> 1 = a" and
walther@60242
   170
  rbinom_power_2:          "((a::real) + b) \<up>  2 = a \<up>  2 + 2*a*b + b \<up>  2" and
neuper@37906
   171
neuper@52148
   172
  rmult_1:                 "1 * k = (k::real)" and
neuper@52148
   173
  rmult_1_right:           "k * 1 = (k::real)" and
neuper@52148
   174
  rmult_0:                 "0 * k = (0::real)" and
neuper@52148
   175
  rmult_0_right:           "k * 0 = (0::real)" and
neuper@52148
   176
  radd_0:                  "0 + k = (k::real)" and
neuper@52148
   177
  radd_0_right:            "k + 0 = (k::real)" and
neuper@37906
   178
neuper@37983
   179
  radd_real_const_eq:
neuper@52148
   180
          "[| a is_const; c is_const; d is_const |] ==> a/d + c/d = (a+c)/(d::real)" and
neuper@37983
   181
  radd_real_const:
neuper@37906
   182
          "[| a is_const; b is_const; c is_const; d is_const |] ==> a/b + c/d = (a*d + b*c)/(b*(d::real))"  
neuper@52148
   183
   and
neuper@37906
   184
(*for AC-operators*)
neuper@52148
   185
  radd_commute:            "(m::real) + (n::real) = n + m" and
neuper@52148
   186
  radd_left_commute:       "(x::real) + (y + z) = y + (x + z)" and
neuper@52148
   187
  radd_assoc:              "(m::real) + n + k = m + (n + k)" and
neuper@52148
   188
  rmult_commute:           "(m::real) * n = n * m" and
neuper@52148
   189
  rmult_left_commute:      "(x::real) * (y * z) = y * (x * z)" and
neuper@52148
   190
  rmult_assoc:             "(m::real) * n * k = m * (n * k)" and
neuper@37906
   191
neuper@37906
   192
(*for equations: 'bdv' is a meta-constant*)
neuper@52148
   193
  risolate_bdv_add:       "((k::real) + bdv = m) = (bdv = m + (-1)*k)" and
neuper@52148
   194
  risolate_bdv_mult_add:  "((k::real) + n*bdv = m) = (n*bdv = m + (-1)*k)" and
neuper@52148
   195
  risolate_bdv_mult:      "((n::real) * bdv = m) = (bdv = m / n)" and
neuper@37906
   196
neuper@37983
   197
  rnorm_equation_add:
neuper@52148
   198
      "~(b =!= 0) ==> (a = b) = (a + (-1)*b = 0)" and
neuper@37906
   199
neuper@37906
   200
(*17.9.02 aus SqRoot.thy------------------------------vvv---*) 
walther@60262
   201
  root_ge0:            "0 <= a ==> 0 <= sqrt a = True" and
neuper@37906
   202
  (*should be dropped with better simplification in eval_rls ...*)
neuper@37983
   203
  root_add_ge0:
neuper@52148
   204
	"[| 0 <= a; 0 <= b |] ==> (0 <= sqrt a + sqrt b) = True" and
neuper@37983
   205
  root_ge0_1:
neuper@52148
   206
	"[| 0<=a; 0<=b; 0<=c |] ==> (0 <= a * sqrt b + sqrt c) = True" and
neuper@37983
   207
  root_ge0_2:
neuper@52148
   208
	"[| 0<=a; 0<=b; 0<=c |] ==> (0 <= sqrt a + b * sqrt c) = True" and
neuper@37906
   209
neuper@37906
   210
walther@60242
   211
  rroot_square_inv:         "(sqrt a) \<up>  2 = a" and
neuper@52148
   212
  rroot_times_root:         "sqrt a * sqrt b = sqrt(a*b)" and
neuper@52148
   213
  rroot_times_root_assoc:   "(a * sqrt b) * sqrt c = a * sqrt(b*c)" and
neuper@52148
   214
  rroot_times_root_assoc_p: "sqrt b * (sqrt c * a)= sqrt(b*c) * a" and
neuper@37906
   215
neuper@37906
   216
neuper@37906
   217
(*for root-equations*)
neuper@37983
   218
  square_equation_left:
walther@60242
   219
          "[| 0 <= a; 0 <= b |] ==> (((sqrt a)=b)=(a=(b \<up>  2)))" and
neuper@37983
   220
  square_equation_right:
walther@60242
   221
          "[| 0 <= a; 0 <= b |] ==> ((a=(sqrt b))=((a \<up>  2)=b))" and
neuper@37906
   222
  (*causes frequently non-termination:*)
neuper@37983
   223
  square_equation:  
walther@60242
   224
          "[| 0 <= a; 0 <= b |] ==> ((a=b)=((a \<up>  2)=b \<up>  2))" and
neuper@37906
   225
  
neuper@52148
   226
  risolate_root_add:        "(a+  sqrt c = d) = (  sqrt c = d + (-1)*a)" and
neuper@52148
   227
  risolate_root_mult:       "(a+b*sqrt c = d) = (b*sqrt c = d + (-1)*a)" and
neuper@52148
   228
  risolate_root_div:        "(a * sqrt c = d) = (  sqrt c = d / a)" and
neuper@37906
   229
neuper@37906
   230
(*for polynomial equations of degree 2; linear case in RatArith*)
walther@60242
   231
  mult_square:		"(a*bdv \<up> 2 = b) = (bdv \<up> 2 = b / a)" and
walther@60242
   232
  constant_square:       "(a + bdv \<up> 2 = b) = (bdv \<up> 2 = b + -1*a)" and
walther@60242
   233
  constant_mult_square:  "(a + b*bdv \<up> 2 = c) = (b*bdv \<up> 2 = c + -1*a)" and
neuper@37906
   234
neuper@37983
   235
  square_equality: 
walther@60242
   236
	     "0 <= a ==> (x \<up> 2 = a) = ((x=sqrt a) | (x=-1*sqrt a))" and
neuper@37983
   237
  square_equality_0:
walther@60242
   238
	     "(x \<up> 2 = 0) = (x = 0)" and
neuper@37906
   239
neuper@37906
   240
(*isolate root on the LEFT hand side of the equation
neuper@37906
   241
  otherwise shuffling from left to right would not terminate*)  
neuper@37906
   242
walther@60269
   243
(*Ambiguous input\<^here> produces 2 parse trees -----------------------------\\*)
walther@60269
   244
  rroot_to_lhs: "is_root_free a ==> (a = sqrt b) = (a + (-1)*sqrt b = 0)" and
walther@60269
   245
  rroot_to_lhs_mult: "is_root_free a ==> (a = c*sqrt b) = (a + (-1)*c*sqrt b = 0)" and
walther@60269
   246
  rroot_to_lhs_add_mult: "is_root_free a ==> (a = d+c*sqrt b) = (a + (-1)*c*sqrt b = d)"
walther@60269
   247
(*Ambiguous input\<^here> produces 2 parse trees -----------------------------//*)
neuper@37906
   248
wneuper@59472
   249
section \<open>eval functions\<close>
wneuper@59472
   250
ML \<open>
neuper@37972
   251
val thy = @{theory};
neuper@37972
   252
neuper@37954
   253
(** evaluation of numerals and predicates **)
neuper@37954
   254
neuper@37954
   255
(*does a term contain a root ?*)
neuper@37954
   256
fun eval_contains_root (thmid:string) _ 
walther@60269
   257
		       (t as (Const("Test.contains'_root", _) $ arg)) thy = 
neuper@38053
   258
  if member op = (ids_of arg) "sqrt"
walther@59870
   259
  then SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg)"",
wneuper@59390
   260
	       HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
walther@59870
   261
  else SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg)"",
wneuper@59390
   262
	       HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
neuper@38053
   263
| eval_contains_root _ _ _ _ = NONE; 
neuper@42008
   264
neuper@42008
   265
(*dummy precondition for root-met of x+1=2*)
neuper@42008
   266
fun eval_precond_rootmet (thmid:string) _ (t as (Const ("Test.precond'_rootmet", _) $ arg)) thy = 
walther@59870
   267
    SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg)"",
wneuper@59390
   268
      HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
neuper@52070
   269
  | eval_precond_rootmet _ _ _ _ = NONE; 
neuper@42008
   270
neuper@42008
   271
(*dummy precondition for root-pbl of x+1=2*)
neuper@42008
   272
fun eval_precond_rootpbl (thmid:string) _ (t as (Const ("Test.precond'_rootpbl", _) $ arg)) thy = 
walther@59870
   273
    SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "",
wneuper@59390
   274
	    HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
s1210629013@52159
   275
	| eval_precond_rootpbl _ _ _ _ = NONE;
wneuper@59472
   276
\<close>
wneuper@59472
   277
setup \<open>KEStore_Elems.add_calcs
wneuper@59403
   278
  [("contains_root", ("Test.contains'_root", eval_contains_root"#contains_root_")),
s1210629013@52145
   279
    ("Test.precond'_rootmet", ("Test.precond'_rootmet", eval_precond_rootmet"#Test.precond_rootmet_")),
s1210629013@52145
   280
    ("Test.precond'_rootpbl", ("Test.precond'_rootpbl",
wneuper@59430
   281
        eval_precond_rootpbl"#Test.precond_rootpbl_"))]
wneuper@59472
   282
\<close>
wneuper@59472
   283
ML \<open>
wneuper@59430
   284
(*8.4.03  aus Poly.ML--------------------------------vvv---
wneuper@59430
   285
  make_polynomial  ---> make_poly
wneuper@59430
   286
  ^-- for user          ^-- for systest _ONLY_*)  
wneuper@59430
   287
wneuper@59430
   288
local (*. for make_polytest .*)
wneuper@59430
   289
wneuper@59430
   290
open Term;  (* for type order = EQUAL | LESS | GREATER *)
wneuper@59430
   291
wneuper@59430
   292
fun pr_ord EQUAL = "EQUAL"
wneuper@59430
   293
  | pr_ord LESS  = "LESS"
wneuper@59430
   294
  | pr_ord GREATER = "GREATER";
wneuper@59430
   295
wneuper@59430
   296
fun dest_hd' (Const (a, T)) =                          (* ~ term.ML *)
walther@60269
   297
    (case a of
walther@60269
   298
      "Prog_Expr.pow" => ((("|||||||||||||", 0), T), 0)           (*WN greatest *)
walther@60269
   299
  | _ => (((a, 0), T), 0))
wneuper@59430
   300
  | dest_hd' (Free (a, T)) = (((a, 0), T), 1)
wneuper@59430
   301
  | dest_hd' (Var v) = (v, 2)
wneuper@59430
   302
  | dest_hd' (Bound i) = ((("", i), dummyT), 3)
walther@60269
   303
  | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4)
walther@60269
   304
  | dest_hd' _ = raise ERROR "dest_hd': uncovered case in fun.def.";
walther@60269
   305
walther@60269
   306
\<^isac_test>\<open>
walther@60269
   307
fun get_order_pow (t $ (Free(order,_))) =
walther@59875
   308
    	(case TermC.int_opt_of_string order of
wneuper@59430
   309
	             SOME d => d
wneuper@59430
   310
		   | NONE   => 0)
wneuper@59430
   311
  | get_order_pow _ = 0;
walther@60269
   312
\<close>
wneuper@59430
   313
wneuper@59430
   314
fun size_of_term' (Const(str,_) $ t) =
walther@59603
   315
  if "Prog_Expr.pow"=str then 1000 + size_of_term' t else 1 + size_of_term' t(*WN*)
wneuper@59430
   316
  | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
wneuper@59430
   317
  | size_of_term' (f$t) = size_of_term' f  +  size_of_term' t
wneuper@59430
   318
  | size_of_term' _ = 1;
wneuper@59430
   319
fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) =       (* ~ term.ML *)
wneuper@59430
   320
    (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) 
wneuper@59430
   321
                                   | ord => ord)
walther@60269
   322
  | term_ord' pr _ (t, u) =
wneuper@59430
   323
    (if pr then 
wneuper@59430
   324
	 let val (f, ts) = strip_comb t and (g, us) = strip_comb u;
walther@59868
   325
	     val _ = tracing ("t= f@ts= \"" ^ UnparseC.term f ^ "\" @ \"[" ^
walther@59868
   326
	                      commas(map UnparseC.term ts) ^ "]\"")
walther@59868
   327
	     val _ = tracing ("u= g@us= \"" ^ UnparseC.term g ^"\" @ \"[" ^
walther@59868
   328
	                      commas(map UnparseC.term us) ^"]\"")
wneuper@59430
   329
	     val _ = tracing ("size_of_term(t,u)= (" ^
wneuper@59430
   330
	                      string_of_int (size_of_term' t) ^ ", " ^
wneuper@59430
   331
	                      string_of_int (size_of_term' u) ^ ")")
wneuper@59430
   332
	     val _ = tracing ("hd_ord(f,g)      = " ^ (pr_ord o hd_ord) (f,g))
wneuper@59430
   333
	     val _ = tracing ("terms_ord(ts,us) = " ^
wneuper@59430
   334
			      (pr_ord o terms_ord str false) (ts,us));
wneuper@59430
   335
	     val _ = tracing "-------"
wneuper@59430
   336
	 in () end
wneuper@59430
   337
       else ();
wneuper@59430
   338
	 case int_ord (size_of_term' t, size_of_term' u) of
wneuper@59430
   339
	   EQUAL =>
wneuper@59430
   340
	     let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
wneuper@59430
   341
	       (case hd_ord (f, g) of EQUAL => (terms_ord str pr) (ts, us) 
wneuper@59430
   342
	     | ord => ord)
wneuper@59430
   343
	     end
wneuper@59430
   344
	 | ord => ord)
wneuper@59430
   345
and hd_ord (f, g) =                                        (* ~ term.ML *)
wneuper@59430
   346
  prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
walther@60269
   347
and terms_ord _ pr (ts, us) = 
walther@59881
   348
    list_ord (term_ord' pr (ThyC.get_theory "Isac_Knowledge"))(ts, us);
wneuper@59430
   349
in
wneuper@59430
   350
walther@59910
   351
fun ord_make_polytest (pr:bool) thy (_: subst) tu = 
wneuper@59430
   352
    (term_ord' pr thy(***) tu = LESS );
wneuper@59430
   353
wneuper@59430
   354
end;(*local*)
wneuper@59472
   355
\<close> 
wneuper@59430
   356
wneuper@59472
   357
section \<open>term order\<close>
wneuper@59472
   358
ML \<open>
walther@59910
   359
fun term_order (_: subst) tu = (term_ordI [] tu = LESS);
wneuper@59472
   360
\<close>
s1210629013@52145
   361
wneuper@59472
   362
section \<open>rulesets\<close>
wneuper@59472
   363
ML \<open>
neuper@37954
   364
val testerls = 
walther@59851
   365
  Rule_Def.Repeat {id = "testerls", preconds = [], rew_ord = ("termlessI",termlessI), 
walther@59852
   366
      erls = Rule_Set.empty, srls = Rule_Set.Empty, 
neuper@42451
   367
      calc = [], errpatts = [], 
walther@59871
   368
      rules = [Rule.Thm ("refl",ThmC.numerals_to_Free @{thm refl}),
walther@59871
   369
	       Rule.Thm ("order_refl",ThmC.numerals_to_Free @{thm order_refl}),
walther@59871
   370
	       Rule.Thm ("radd_left_cancel_le",ThmC.numerals_to_Free @{thm radd_left_cancel_le}),
walther@59871
   371
	       Rule.Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
walther@59871
   372
	       Rule.Thm ("not_false",ThmC.numerals_to_Free @{thm not_false}),
walther@59871
   373
	       Rule.Thm ("and_true",ThmC.numerals_to_Free @{thm and_true}),
walther@59871
   374
	       Rule.Thm ("and_false",ThmC.numerals_to_Free @{thm and_false}),
walther@59871
   375
	       Rule.Thm ("or_true",ThmC.numerals_to_Free @{thm or_true}),
walther@59871
   376
	       Rule.Thm ("or_false",ThmC.numerals_to_Free @{thm or_false}),
walther@59871
   377
	       Rule.Thm ("and_commute",ThmC.numerals_to_Free @{thm and_commute}),
walther@59871
   378
	       Rule.Thm ("or_commute",ThmC.numerals_to_Free @{thm or_commute}),
neuper@37954
   379
walther@59878
   380
	       Rule.Eval ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_"),
walther@59878
   381
	       Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches ""),
neuper@37954
   382
    
walther@59878
   383
	       Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
walther@59878
   384
	       Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
walther@59878
   385
	       Rule.Eval ("Prog_Expr.pow" , (**)eval_binop "#power_"),
neuper@37954
   386
		    
walther@59878
   387
	       Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
walther@59878
   388
	       Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
neuper@37954
   389
	     	    
walther@59878
   390
	       Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_")],
walther@59878
   391
      scr = Rule.Empty_Prog
wneuper@59406
   392
      };      
wneuper@59472
   393
\<close>
wneuper@59472
   394
ML \<open>
neuper@37954
   395
(*.for evaluation of conditions in rewrite rules.*)
neuper@37954
   396
(*FIXXXXXXME 10.8.02: handle like _simplify*)
neuper@37954
   397
val tval_rls =  
walther@59851
   398
  Rule_Def.Repeat{id = "tval_rls", preconds = [], 
wneuper@59397
   399
      rew_ord = ("sqrt_right",sqrt_right false @{theory "Pure"}), 
walther@59852
   400
      erls=testerls,srls = Rule_Set.empty, 
neuper@42451
   401
      calc=[], errpatts = [],
walther@59871
   402
      rules = [Rule.Thm ("refl",ThmC.numerals_to_Free @{thm refl}),
walther@59871
   403
	       Rule.Thm ("order_refl",ThmC.numerals_to_Free @{thm order_refl}),
walther@59871
   404
	       Rule.Thm ("radd_left_cancel_le",ThmC.numerals_to_Free @{thm radd_left_cancel_le}),
walther@59871
   405
	       Rule.Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
walther@59871
   406
	       Rule.Thm ("not_false",ThmC.numerals_to_Free @{thm not_false}),
walther@59871
   407
	       Rule.Thm ("and_true",ThmC.numerals_to_Free @{thm and_true}),
walther@59871
   408
	       Rule.Thm ("and_false",ThmC.numerals_to_Free @{thm and_false}),
walther@59871
   409
	       Rule.Thm ("or_true",ThmC.numerals_to_Free @{thm or_true}),
walther@59871
   410
	       Rule.Thm ("or_false",ThmC.numerals_to_Free @{thm or_false}),
walther@59871
   411
	       Rule.Thm ("and_commute",ThmC.numerals_to_Free @{thm and_commute}),
walther@59871
   412
	       Rule.Thm ("or_commute",ThmC.numerals_to_Free @{thm or_commute}),
neuper@37954
   413
walther@59871
   414
	       Rule.Thm ("real_diff_minus",ThmC.numerals_to_Free @{thm real_diff_minus}),
neuper@37954
   415
walther@59871
   416
	       Rule.Thm ("root_ge0",ThmC.numerals_to_Free @{thm root_ge0}),
walther@59871
   417
	       Rule.Thm ("root_add_ge0",ThmC.numerals_to_Free @{thm root_add_ge0}),
walther@59871
   418
	       Rule.Thm ("root_ge0_1",ThmC.numerals_to_Free @{thm root_ge0_1}),
walther@59871
   419
	       Rule.Thm ("root_ge0_2",ThmC.numerals_to_Free @{thm root_ge0_2}),
neuper@37954
   420
walther@59878
   421
	       Rule.Eval ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_"),
walther@59878
   422
	       Rule.Eval ("Test.contains'_root", eval_contains_root "#eval_contains_root"),
walther@59878
   423
	       Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches ""),
walther@59878
   424
	       Rule.Eval ("Test.contains'_root",
neuper@37954
   425
		     eval_contains_root"#contains_root_"),
neuper@37954
   426
    
walther@59878
   427
	       Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
walther@59878
   428
	       Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
walther@59878
   429
	       Rule.Eval ("NthRoot.sqrt", eval_sqrt "#sqrt_"),
walther@59878
   430
	       Rule.Eval ("Prog_Expr.pow", (**)eval_binop "#power_"),
neuper@37954
   431
		    
walther@59878
   432
	       Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
walther@59878
   433
	       Rule.Eval ("Orderings.ord_class.less_eq", Prog_Expr.eval_equ "#less_equal_"),
neuper@37954
   434
	     	    
walther@59878
   435
	       Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_")],
walther@59878
   436
      scr = Rule.Empty_Prog
wneuper@59406
   437
      };      
wneuper@59472
   438
\<close>
wneuper@59472
   439
setup \<open>KEStore_Elems.add_rlss [("testerls", (Context.theory_name @{theory}, prep_rls' testerls))]\<close>
neuper@52155
   440
wneuper@59472
   441
ML \<open>
neuper@37954
   442
(*make () dissappear*)   
neuper@37954
   443
val rearrange_assoc =
walther@59851
   444
  Rule_Def.Repeat{id = "rearrange_assoc", preconds = [], 
walther@59857
   445
      rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), 
walther@59852
   446
      erls = Rule_Set.empty, srls = Rule_Set.empty, calc = [], errpatts = [],
neuper@37954
   447
      rules = 
walther@59877
   448
      [Rule.Thm ("sym_add.assoc",ThmC.numerals_to_Free (@{thm add.assoc} RS @{thm sym})),
walther@59871
   449
       Rule.Thm ("sym_rmult_assoc",ThmC.numerals_to_Free (@{thm rmult_assoc} RS @{thm sym}))],
walther@59878
   450
      scr = Rule.Empty_Prog
wneuper@59406
   451
      };      
neuper@37954
   452
neuper@37954
   453
val ac_plus_times =
walther@59851
   454
  Rule_Def.Repeat{id = "ac_plus_times", preconds = [], rew_ord = ("term_order",term_order),
walther@59852
   455
      erls = Rule_Set.empty, srls = Rule_Set.empty, calc = [], errpatts = [],
neuper@37954
   456
      rules = 
walther@59871
   457
      [Rule.Thm ("radd_commute",ThmC.numerals_to_Free @{thm radd_commute}),
walther@59871
   458
       Rule.Thm ("radd_left_commute",ThmC.numerals_to_Free @{thm radd_left_commute}),
walther@59877
   459
       Rule.Thm ("add.assoc",ThmC.numerals_to_Free @{thm add.assoc}),
walther@59871
   460
       Rule.Thm ("rmult_commute",ThmC.numerals_to_Free @{thm rmult_commute}),
walther@59871
   461
       Rule.Thm ("rmult_left_commute",ThmC.numerals_to_Free @{thm rmult_left_commute}),
walther@59871
   462
       Rule.Thm ("rmult_assoc",ThmC.numerals_to_Free @{thm rmult_assoc})],
walther@59878
   463
      scr = Rule.Empty_Prog
wneuper@59406
   464
      };      
neuper@37954
   465
walther@59871
   466
(*todo: replace by Rewrite("rnorm_equation_add",ThmC.numerals_to_Free @{thm rnorm_equation_add)*)
neuper@37954
   467
val norm_equation =
walther@59857
   468
  Rule_Def.Repeat{id = "norm_equation", preconds = [], rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
walther@59852
   469
      erls = tval_rls, srls = Rule_Set.empty, calc = [], errpatts = [],
walther@59871
   470
      rules = [Rule.Thm ("rnorm_equation_add",ThmC.numerals_to_Free @{thm rnorm_equation_add})
neuper@37954
   471
	       ],
walther@59878
   472
      scr = Rule.Empty_Prog
wneuper@59406
   473
      };      
wneuper@59472
   474
\<close>
wneuper@59472
   475
ML \<open>
neuper@37954
   476
(* expects * distributed over + *)
neuper@37954
   477
val Test_simplify =
walther@59851
   478
  Rule_Def.Repeat{id = "Test_simplify", preconds = [], 
wneuper@59397
   479
      rew_ord = ("sqrt_right",sqrt_right false @{theory "Pure"}),
walther@59852
   480
      erls = tval_rls, srls = Rule_Set.empty, 
s1210629013@55444
   481
      calc=[(*since 040209 filled by prep_rls'*)], errpatts = [],
neuper@37954
   482
      rules = [
walther@59871
   483
	       Rule.Thm ("real_diff_minus",ThmC.numerals_to_Free @{thm real_diff_minus}),
walther@59871
   484
	       Rule.Thm ("radd_mult_distrib2",ThmC.numerals_to_Free @{thm radd_mult_distrib2}),
walther@59871
   485
	       Rule.Thm ("rdistr_right_assoc",ThmC.numerals_to_Free @{thm rdistr_right_assoc}),
walther@59871
   486
	       Rule.Thm ("rdistr_right_assoc_p",ThmC.numerals_to_Free @{thm rdistr_right_assoc_p}),
walther@59871
   487
	       Rule.Thm ("rdistr_div_right",ThmC.numerals_to_Free @{thm rdistr_div_right}),
walther@59871
   488
	       Rule.Thm ("rbinom_power_2",ThmC.numerals_to_Free @{thm rbinom_power_2}),	       
neuper@37954
   489
walther@59871
   490
               Rule.Thm ("radd_commute",ThmC.numerals_to_Free @{thm radd_commute}), 
walther@59871
   491
	       Rule.Thm ("radd_left_commute",ThmC.numerals_to_Free @{thm radd_left_commute}),
walther@59877
   492
	       Rule.Thm ("add.assoc",ThmC.numerals_to_Free @{thm add.assoc}),
walther@59871
   493
	       Rule.Thm ("rmult_commute",ThmC.numerals_to_Free @{thm rmult_commute}),
walther@59871
   494
	       Rule.Thm ("rmult_left_commute",ThmC.numerals_to_Free @{thm rmult_left_commute}),
walther@59871
   495
	       Rule.Thm ("rmult_assoc",ThmC.numerals_to_Free @{thm rmult_assoc}),
neuper@37954
   496
walther@59871
   497
	       Rule.Thm ("radd_real_const_eq",ThmC.numerals_to_Free @{thm radd_real_const_eq}),
walther@59871
   498
	       Rule.Thm ("radd_real_const",ThmC.numerals_to_Free @{thm radd_real_const}),
neuper@37954
   499
	       (* these 2 rules are invers to distr_div_right wrt. termination.
neuper@37954
   500
		  thus they MUST be done IMMEDIATELY before calc *)
walther@59878
   501
	       Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"), 
walther@59878
   502
	       Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
walther@59878
   503
	       Rule.Eval ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e"),
walther@59878
   504
	       Rule.Eval ("Prog_Expr.pow", (**)eval_binop "#power_"),
neuper@37954
   505
walther@59871
   506
	       Rule.Thm ("rcollect_right",ThmC.numerals_to_Free @{thm rcollect_right}),
walther@59871
   507
	       Rule.Thm ("rcollect_one_left",ThmC.numerals_to_Free @{thm rcollect_one_left}),
walther@59871
   508
	       Rule.Thm ("rcollect_one_left_assoc",ThmC.numerals_to_Free @{thm rcollect_one_left_assoc}),
walther@59871
   509
	       Rule.Thm ("rcollect_one_left_assoc_p",ThmC.numerals_to_Free @{thm rcollect_one_left_assoc_p}),
neuper@37954
   510
walther@59871
   511
	       Rule.Thm ("rshift_nominator",ThmC.numerals_to_Free @{thm rshift_nominator}),
walther@59871
   512
	       Rule.Thm ("rcancel_den",ThmC.numerals_to_Free @{thm rcancel_den}),
walther@59871
   513
	       Rule.Thm ("rroot_square_inv",ThmC.numerals_to_Free @{thm rroot_square_inv}),
walther@59871
   514
	       Rule.Thm ("rroot_times_root",ThmC.numerals_to_Free @{thm rroot_times_root}),
walther@59871
   515
	       Rule.Thm ("rroot_times_root_assoc_p",ThmC.numerals_to_Free @{thm rroot_times_root_assoc_p}),
walther@59871
   516
	       Rule.Thm ("rsqare",ThmC.numerals_to_Free @{thm rsqare}),
walther@59871
   517
	       Rule.Thm ("power_1",ThmC.numerals_to_Free @{thm power_1}),
walther@59871
   518
	       Rule.Thm ("rtwo_of_the_same",ThmC.numerals_to_Free @{thm rtwo_of_the_same}),
walther@59871
   519
	       Rule.Thm ("rtwo_of_the_same_assoc_p",ThmC.numerals_to_Free @{thm rtwo_of_the_same_assoc_p}),
neuper@37954
   520
walther@59871
   521
	       Rule.Thm ("rmult_1",ThmC.numerals_to_Free @{thm rmult_1}),
walther@59871
   522
	       Rule.Thm ("rmult_1_right",ThmC.numerals_to_Free @{thm rmult_1_right}),
walther@59871
   523
	       Rule.Thm ("rmult_0",ThmC.numerals_to_Free @{thm rmult_0}),
walther@59871
   524
	       Rule.Thm ("rmult_0_right",ThmC.numerals_to_Free @{thm rmult_0_right}),
walther@59871
   525
	       Rule.Thm ("radd_0",ThmC.numerals_to_Free @{thm radd_0}),
walther@59871
   526
	       Rule.Thm ("radd_0_right",ThmC.numerals_to_Free @{thm radd_0_right})
neuper@37954
   527
	       ],
walther@59878
   528
      scr = Rule.Empty_Prog
s1210629013@55444
   529
		    (*since 040209 filled by prep_rls': STest_simplify*)
wneuper@59406
   530
      };      
wneuper@59472
   531
\<close>
wneuper@59472
   532
ML \<open>
neuper@37954
   533
(*isolate the root in a root-equation*)
neuper@37954
   534
val isolate_root =
walther@59857
   535
  Rule_Def.Repeat{id = "isolate_root", preconds = [], rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), 
walther@59852
   536
      erls=tval_rls,srls = Rule_Set.empty, calc=[], errpatts = [],
walther@59871
   537
      rules = [Rule.Thm ("rroot_to_lhs",ThmC.numerals_to_Free @{thm rroot_to_lhs}),
walther@59871
   538
	       Rule.Thm ("rroot_to_lhs_mult",ThmC.numerals_to_Free @{thm rroot_to_lhs_mult}),
walther@59871
   539
	       Rule.Thm ("rroot_to_lhs_add_mult",ThmC.numerals_to_Free @{thm rroot_to_lhs_add_mult}),
walther@59871
   540
	       Rule.Thm ("risolate_root_add",ThmC.numerals_to_Free @{thm risolate_root_add}),
walther@59871
   541
	       Rule.Thm ("risolate_root_mult",ThmC.numerals_to_Free @{thm risolate_root_mult}),
walther@59871
   542
	       Rule.Thm ("risolate_root_div",ThmC.numerals_to_Free @{thm risolate_root_div})       ],
wneuper@59416
   543
      scr = Rule.Prog ((Thm.term_of o the o (TermC.parse thy)) 
neuper@37954
   544
      "empty_script")
wneuper@59406
   545
      };
neuper@37954
   546
neuper@37954
   547
(*isolate the bound variable in an equation; 'bdv' is a meta-constant*)
neuper@37954
   548
val isolate_bdv =
walther@59857
   549
    Rule_Def.Repeat{id = "isolate_bdv", preconds = [], rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
walther@59852
   550
	erls=tval_rls,srls = Rule_Set.empty, calc= [], errpatts = [],
neuper@37954
   551
	rules = 
walther@59871
   552
	[Rule.Thm ("risolate_bdv_add",ThmC.numerals_to_Free @{thm risolate_bdv_add}),
walther@59871
   553
	 Rule.Thm ("risolate_bdv_mult_add",ThmC.numerals_to_Free @{thm risolate_bdv_mult_add}),
walther@59871
   554
	 Rule.Thm ("risolate_bdv_mult",ThmC.numerals_to_Free @{thm risolate_bdv_mult}),
walther@59871
   555
	 Rule.Thm ("mult_square",ThmC.numerals_to_Free @{thm mult_square}),
walther@59871
   556
	 Rule.Thm ("constant_square",ThmC.numerals_to_Free @{thm constant_square}),
walther@59871
   557
	 Rule.Thm ("constant_mult_square",ThmC.numerals_to_Free @{thm constant_mult_square})
neuper@37954
   558
	 ],
wneuper@59416
   559
	scr = Rule.Prog ((Thm.term_of o the o (TermC.parse thy)) 
neuper@37954
   560
			  "empty_script")
wneuper@59406
   561
	};      
wneuper@59472
   562
\<close>
walther@59618
   563
ML \<open>val prep_rls' = Auto_Prog.prep_rls @{theory};\<close>
wneuper@59472
   564
setup \<open>KEStore_Elems.add_rlss 
s1210629013@55444
   565
  [("Test_simplify", (Context.theory_name @{theory}, prep_rls' Test_simplify)), 
s1210629013@55444
   566
  ("tval_rls", (Context.theory_name @{theory}, prep_rls' tval_rls)), 
s1210629013@55444
   567
  ("isolate_root", (Context.theory_name @{theory}, prep_rls' isolate_root)), 
s1210629013@55444
   568
  ("isolate_bdv", (Context.theory_name @{theory}, prep_rls' isolate_bdv)), 
s1210629013@55444
   569
  ("matches", (Context.theory_name @{theory}, prep_rls'
walther@59878
   570
    (Rule_Set.append_rules "matches" testerls [Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches "#matches_")])))]
wneuper@59472
   571
\<close>
neuper@37954
   572
wneuper@59472
   573
subsection \<open>problems\<close>
neuper@37954
   574
(** problem types **)
wneuper@59472
   575
setup \<open>KEStore_Elems.add_pbts
walther@59973
   576
  [(Problem.prep_input thy "pbl_test" [] Problem.id_empty (["test"], [], Rule_Set.empty, NONE, [])),
walther@59973
   577
    (Problem.prep_input thy "pbl_test_equ" [] Problem.id_empty
walther@59997
   578
      (["equation", "test"],
walther@59997
   579
        [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55339
   580
           ("#Where" ,["matches (?a = ?b) e_e"]),
s1210629013@55339
   581
           ("#Find"  ,["solutions v_v'i'"])],
s1210629013@55339
   582
        assoc_rls' @{theory} "matches", SOME "solve (e_e::bool, v_v)", [])),
walther@59973
   583
    (Problem.prep_input thy "pbl_test_uni" [] Problem.id_empty
walther@59997
   584
      (["univariate", "equation", "test"],
walther@59997
   585
        [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55339
   586
           ("#Where" ,["matches (?a = ?b) e_e"]),
s1210629013@55339
   587
           ("#Find"  ,["solutions v_v'i'"])],
s1210629013@55339
   588
        assoc_rls' @{theory} "matches", SOME "solve (e_e::bool, v_v)", [])),
walther@59973
   589
    (Problem.prep_input thy "pbl_test_uni_lin" [] Problem.id_empty
walther@59997
   590
      (["LINEAR", "univariate", "equation", "test"],
walther@59997
   591
        [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55339
   592
           ("#Where" ,["(matches (   v_v = 0) e_e) | (matches (   ?b*v_v = 0) e_e) |" ^
s1210629013@55339
   593
             "(matches (?a+v_v = 0) e_e) | (matches (?a+?b*v_v = 0) e_e)  "]),
s1210629013@55339
   594
           ("#Find"  ,["solutions v_v'i'"])],
s1210629013@55339
   595
        assoc_rls' @{theory} "matches", 
walther@59997
   596
        SOME "solve (e_e::bool, v_v)", [["Test", "solve_linear"]]))]
wneuper@59472
   597
\<close>
wneuper@59472
   598
ML \<open>
walther@59857
   599
Rewrite_Ord.rew_ord' := overwritel (! Rewrite_Ord.rew_ord',
neuper@37954
   600
[("termlessI", termlessI),
neuper@37954
   601
 ("ord_make_polytest", ord_make_polytest false thy)
neuper@37954
   602
 ]);
neuper@37954
   603
neuper@37954
   604
val make_polytest =
walther@59851
   605
  Rule_Def.Repeat{id = "make_polytest", preconds = []:term list, 
neuper@52105
   606
      rew_ord = ("ord_make_polytest", ord_make_polytest false @{theory "Poly"}),
walther@59851
   607
      erls = testerls, srls = Rule_Set.Empty,
walther@59603
   608
      calc = [("PLUS"  , ("Groups.plus_class.plus", (**)eval_binop "#add_")), 
walther@59603
   609
	      ("TIMES" , ("Groups.times_class.times", (**)eval_binop "#mult_")),
walther@59603
   610
	      ("POWER", ("Prog_Expr.pow", (**)eval_binop "#power_"))
neuper@42451
   611
	      ], errpatts = [],
walther@59871
   612
      rules = [Rule.Thm ("real_diff_minus",ThmC.numerals_to_Free @{thm real_diff_minus}),
neuper@37954
   613
	       (*"a - b = a + (-1) * b"*)
walther@59871
   614
	       Rule.Thm ("distrib_right" ,ThmC.numerals_to_Free @{thm distrib_right}),
neuper@37954
   615
	       (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
walther@59871
   616
	       Rule.Thm ("distrib_left",ThmC.numerals_to_Free @{thm distrib_left}),
neuper@37954
   617
	       (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
walther@59871
   618
	       Rule.Thm ("left_diff_distrib" ,ThmC.numerals_to_Free @{thm left_diff_distrib}),
neuper@37954
   619
	       (*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
walther@59871
   620
	       Rule.Thm ("right_diff_distrib",ThmC.numerals_to_Free @{thm right_diff_distrib}),
neuper@37954
   621
	       (*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
walther@59871
   622
	       Rule.Thm ("mult_1_left",ThmC.numerals_to_Free @{thm mult_1_left}),                 
neuper@37954
   623
	       (*"1 * z = z"*)
walther@59871
   624
	       Rule.Thm ("mult_zero_left",ThmC.numerals_to_Free @{thm mult_zero_left}),        
neuper@37954
   625
	       (*"0 * z = 0"*)
walther@59871
   626
	       Rule.Thm ("add_0_left",ThmC.numerals_to_Free @{thm add_0_left}),
neuper@37954
   627
	       (*"0 + z = z"*)
neuper@37954
   628
neuper@37954
   629
	       (*AC-rewriting*)
walther@59877
   630
	       Rule.Thm ("mult.commute",ThmC.numerals_to_Free @{thm mult.commute}),
neuper@37954
   631
	       (* z * w = w * z *)
walther@59871
   632
	       Rule.Thm ("real_mult_left_commute",ThmC.numerals_to_Free @{thm real_mult_left_commute}),
neuper@37954
   633
	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
walther@59877
   634
	       Rule.Thm ("mult.assoc",ThmC.numerals_to_Free @{thm mult.assoc}),		
neuper@37954
   635
	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
walther@59877
   636
	       Rule.Thm ("add.commute",ThmC.numerals_to_Free @{thm add.commute}),	
neuper@37954
   637
	       (*z + w = w + z*)
walther@59877
   638
	       Rule.Thm ("add.left_commute",ThmC.numerals_to_Free @{thm add.left_commute}),
neuper@37954
   639
	       (*x + (y + z) = y + (x + z)*)
walther@59877
   640
	       Rule.Thm ("add.assoc",ThmC.numerals_to_Free @{thm add.assoc}),	               
neuper@37954
   641
	       (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
neuper@37954
   642
wneuper@59416
   643
	       Rule.Thm ("sym_realpow_twoI",
walther@59871
   644
                     ThmC.numerals_to_Free (@{thm realpow_twoI} RS @{thm sym})),	
walther@60242
   645
	       (*"r1 * r1 = r1 \<up> 2"*)
walther@59871
   646
	       Rule.Thm ("realpow_plus_1",ThmC.numerals_to_Free @{thm realpow_plus_1}),		
walther@60242
   647
	       (*"r * r \<up> n = r \<up> (n + 1)"*)
wneuper@59416
   648
	       Rule.Thm ("sym_real_mult_2",
walther@59871
   649
                     ThmC.numerals_to_Free (@{thm real_mult_2} RS @{thm sym})),	
neuper@37954
   650
	       (*"z1 + z1 = 2 * z1"*)
walther@59871
   651
	       Rule.Thm ("real_mult_2_assoc",ThmC.numerals_to_Free @{thm real_mult_2_assoc}),	
neuper@37954
   652
	       (*"z1 + (z1 + k) = 2 * z1 + k"*)
neuper@37954
   653
walther@59871
   654
	       Rule.Thm ("real_num_collect",ThmC.numerals_to_Free @{thm real_num_collect}), 
neuper@37954
   655
	       (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
walther@59871
   656
	       Rule.Thm ("real_num_collect_assoc",ThmC.numerals_to_Free @{thm real_num_collect_assoc}),
neuper@37954
   657
	       (*"[| l is_const; m is_const |] ==>  
neuper@37954
   658
				l * n + (m * n + k) =  (l + m) * n + k"*)
walther@59871
   659
	       Rule.Thm ("real_one_collect",ThmC.numerals_to_Free @{thm real_one_collect}),	
neuper@37954
   660
	       (*"m is_const ==> n + m * n = (1 + m) * n"*)
walther@59871
   661
	       Rule.Thm ("real_one_collect_assoc",ThmC.numerals_to_Free @{thm real_one_collect_assoc}), 
neuper@37954
   662
	       (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
neuper@37954
   663
walther@59878
   664
	       Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"), 
walther@59878
   665
	       Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
walther@59878
   666
	       Rule.Eval ("Prog_Expr.pow", (**)eval_binop "#power_")
neuper@37954
   667
	       ],
walther@59878
   668
      scr = Rule.Empty_Prog(*Rule.Prog ((Thm.term_of o the o (parse thy)) 
neuper@37954
   669
      scr_make_polytest)*)
wneuper@59406
   670
      }; 
neuper@37954
   671
neuper@37954
   672
val expand_binomtest =
walther@59851
   673
  Rule_Def.Repeat{id = "expand_binomtest", preconds = [], 
neuper@37954
   674
      rew_ord = ("termlessI",termlessI),
walther@59851
   675
      erls = testerls, srls = Rule_Set.Empty,
walther@59603
   676
      calc = [("PLUS"  , ("Groups.plus_class.plus", (**)eval_binop "#add_")), 
walther@59603
   677
	      ("TIMES" , ("Groups.times_class.times", (**)eval_binop "#mult_")),
walther@59603
   678
	      ("POWER", ("Prog_Expr.pow", (**)eval_binop "#power_"))
neuper@42451
   679
	      ], errpatts = [],
neuper@38001
   680
      rules = 
walther@59871
   681
      [Rule.Thm ("real_plus_binom_pow2"  ,ThmC.numerals_to_Free @{thm real_plus_binom_pow2}),     
walther@60242
   682
	       (*"(a + b) \<up> 2 = a \<up> 2 + 2 * a * b + b \<up> 2"*)
walther@59871
   683
       Rule.Thm ("real_plus_binom_times" ,ThmC.numerals_to_Free @{thm real_plus_binom_times}),    
neuper@37954
   684
	      (*"(a + b)*(a + b) = ...*)
walther@59871
   685
       Rule.Thm ("real_minus_binom_pow2" ,ThmC.numerals_to_Free @{thm real_minus_binom_pow2}),   
walther@60242
   686
       (*"(a - b) \<up> 2 = a \<up> 2 - 2 * a * b + b \<up> 2"*)
walther@59871
   687
       Rule.Thm ("real_minus_binom_times",ThmC.numerals_to_Free @{thm real_minus_binom_times}),   
neuper@38001
   688
       (*"(a - b)*(a - b) = ...*)
walther@59871
   689
       Rule.Thm ("real_plus_minus_binom1",ThmC.numerals_to_Free @{thm real_plus_minus_binom1}),   
walther@60242
   690
        (*"(a + b) * (a - b) = a \<up> 2 - b \<up> 2"*)
walther@59871
   691
       Rule.Thm ("real_plus_minus_binom2",ThmC.numerals_to_Free @{thm real_plus_minus_binom2}),   
walther@60242
   692
        (*"(a - b) * (a + b) = a \<up> 2 - b \<up> 2"*)
neuper@38001
   693
       (*RL 020915*)
walther@59871
   694
       Rule.Thm ("real_pp_binom_times",ThmC.numerals_to_Free @{thm real_pp_binom_times}), 
neuper@38001
   695
        (*(a + b)*(c + d) = a*c + a*d + b*c + b*d*)
walther@59871
   696
       Rule.Thm ("real_pm_binom_times",ThmC.numerals_to_Free @{thm real_pm_binom_times}), 
neuper@38001
   697
        (*(a + b)*(c - d) = a*c - a*d + b*c - b*d*)
walther@59871
   698
       Rule.Thm ("real_mp_binom_times",ThmC.numerals_to_Free @{thm real_mp_binom_times}), 
neuper@38001
   699
        (*(a - b)*(c p d) = a*c + a*d - b*c - b*d*)
walther@59871
   700
       Rule.Thm ("real_mm_binom_times",ThmC.numerals_to_Free @{thm real_mm_binom_times}), 
neuper@38001
   701
        (*(a - b)*(c p d) = a*c - a*d - b*c + b*d*)
walther@59871
   702
       Rule.Thm ("realpow_multI",ThmC.numerals_to_Free @{thm realpow_multI}),                
walther@60242
   703
        (*(a*b) \<up> n = a \<up> n * b \<up> n*)
walther@59871
   704
       Rule.Thm ("real_plus_binom_pow3",ThmC.numerals_to_Free @{thm real_plus_binom_pow3}),
walther@60242
   705
        (* (a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3 *)
walther@59871
   706
       Rule.Thm ("real_minus_binom_pow3",ThmC.numerals_to_Free @{thm real_minus_binom_pow3}),
walther@60242
   707
        (* (a - b) \<up> 3 = a \<up> 3 - 3*a \<up> 2*b + 3*a*b \<up> 2 - b \<up> 3 *)
neuper@37954
   708
neuper@37954
   709
walther@59871
   710
     (*  Rule.Thm ("distrib_right" ,ThmC.numerals_to_Free @{thm distrib_right}),	
neuper@38001
   711
	 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
walther@59871
   712
	Rule.Thm ("distrib_left",ThmC.numerals_to_Free @{thm distrib_left}),	
neuper@38001
   713
	(*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
walther@59871
   714
	Rule.Thm ("left_diff_distrib" ,ThmC.numerals_to_Free @{thm left_diff_distrib}),	
neuper@38001
   715
	(*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
walther@59871
   716
	Rule.Thm ("right_diff_distrib",ThmC.numerals_to_Free @{thm right_diff_distrib}),	
neuper@38001
   717
	(*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
neuper@38001
   718
	*)
neuper@38001
   719
	
walther@59871
   720
	Rule.Thm ("mult_1_left",ThmC.numerals_to_Free @{thm mult_1_left}),              
neuper@38001
   721
         (*"1 * z = z"*)
walther@59871
   722
	Rule.Thm ("mult_zero_left",ThmC.numerals_to_Free @{thm mult_zero_left}),              
neuper@38001
   723
         (*"0 * z = 0"*)
walther@59871
   724
	Rule.Thm ("add_0_left",ThmC.numerals_to_Free @{thm add_0_left}),
neuper@38001
   725
         (*"0 + z = z"*)
neuper@37954
   726
walther@59878
   727
	Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"), 
walther@59878
   728
	Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
walther@59878
   729
	Rule.Eval ("Prog_Expr.pow", (**)eval_binop "#power_"),
neuper@38001
   730
        (*	       
walther@59877
   731
	 Rule.Thm ("mult.commute",ThmC.numerals_to_Free @{thm mult.commute}),		
neuper@38001
   732
        (*AC-rewriting*)
walther@59871
   733
	Rule.Thm ("real_mult_left_commute",ThmC.numerals_to_Free @{thm real_mult_left_commute}),
walther@59877
   734
	Rule.Thm ("mult.assoc",ThmC.numerals_to_Free @{thm mult.assoc}),
walther@59877
   735
	Rule.Thm ("add.commute",ThmC.numerals_to_Free @{thm add.commute}),	
walther@59877
   736
	Rule.Thm ("add.left_commute",ThmC.numerals_to_Free @{thm add.left_commute}),
walther@59877
   737
	Rule.Thm ("add.assoc",ThmC.numerals_to_Free @{thm add.assoc}),
neuper@38001
   738
	*)
neuper@38001
   739
	
wneuper@59416
   740
	Rule.Thm ("sym_realpow_twoI",
walther@59871
   741
              ThmC.numerals_to_Free (@{thm realpow_twoI} RS @{thm sym})),
walther@60242
   742
	(*"r1 * r1 = r1 \<up> 2"*)
walther@59871
   743
	Rule.Thm ("realpow_plus_1",ThmC.numerals_to_Free @{thm realpow_plus_1}),			
walther@60242
   744
	(*"r * r \<up> n = r \<up> (n + 1)"*)
wneuper@59416
   745
	(*Rule.Thm ("sym_real_mult_2",
walther@59871
   746
                ThmC.numerals_to_Free (@{thm real_mult_2} RS @{thm sym})),
neuper@38001
   747
	(*"z1 + z1 = 2 * z1"*)*)
walther@59871
   748
	Rule.Thm ("real_mult_2_assoc",ThmC.numerals_to_Free @{thm real_mult_2_assoc}),		
neuper@38001
   749
	(*"z1 + (z1 + k) = 2 * z1 + k"*)
neuper@37954
   750
walther@59871
   751
	Rule.Thm ("real_num_collect",ThmC.numerals_to_Free @{thm real_num_collect}), 
neuper@38001
   752
	(*"[| l is_const; m is_const |] ==> l * n + m * n = (l + m) * n"*)
walther@59871
   753
	Rule.Thm ("real_num_collect_assoc",ThmC.numerals_to_Free @{thm real_num_collect_assoc}),	
neuper@38001
   754
	(*"[| l is_const; m is_const |] ==>  l * n + (m * n + k) =  (l + m) * n + k"*)
walther@59871
   755
	Rule.Thm ("real_one_collect",ThmC.numerals_to_Free @{thm real_one_collect}),		
neuper@38001
   756
	(*"m is_const ==> n + m * n = (1 + m) * n"*)
walther@59871
   757
	Rule.Thm ("real_one_collect_assoc",ThmC.numerals_to_Free @{thm real_one_collect_assoc}), 
neuper@38001
   758
	(*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
neuper@37954
   759
walther@59878
   760
	Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"), 
walther@59878
   761
	Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
walther@59878
   762
	Rule.Eval ("Prog_Expr.pow", (**)eval_binop "#power_")
neuper@38001
   763
	],
walther@59878
   764
      scr = Rule.Empty_Prog
wneuper@59585
   765
(*Program ((Thm.term_of o the o (parse thy)) scr_expand_binomtest)*)
wneuper@59406
   766
      };      
wneuper@59472
   767
\<close>
wneuper@59472
   768
setup \<open>KEStore_Elems.add_rlss 
s1210629013@55444
   769
  [("make_polytest", (Context.theory_name @{theory}, prep_rls' make_polytest)), 
wneuper@59472
   770
  ("expand_binomtest", (Context.theory_name @{theory}, prep_rls' expand_binomtest))]\<close>
wneuper@59472
   771
setup \<open>KEStore_Elems.add_rlss 
wneuper@59430
   772
  [("norm_equation", (Context.theory_name @{theory}, prep_rls' norm_equation)), 
wneuper@59430
   773
  ("ac_plus_times", (Context.theory_name @{theory}, prep_rls' ac_plus_times)), 
wneuper@59472
   774
  ("rearrange_assoc", (Context.theory_name @{theory}, prep_rls' rearrange_assoc))]\<close>
wneuper@59430
   775
wneuper@59472
   776
section \<open>problems\<close>
wneuper@59472
   777
setup \<open>KEStore_Elems.add_pbts
walther@59973
   778
  [(Problem.prep_input thy "pbl_test_uni_plain2" [] Problem.id_empty
walther@59997
   779
    (["plain_square", "univariate", "equation", "test"],
walther@59997
   780
      [("#Given" ,["equality e_e", "solveFor v_v"]),
walther@60242
   781
        ("#Where" ,["(matches (?a + ?b*v_v  \<up> 2 = 0) e_e) |" ^
walther@60242
   782
	        "(matches (     ?b*v_v  \<up> 2 = 0) e_e) |" ^
walther@60242
   783
	        "(matches (?a +    v_v  \<up> 2 = 0) e_e) |" ^
walther@60242
   784
	        "(matches (        v_v  \<up> 2 = 0) e_e)"]),
wneuper@59430
   785
        ("#Find"  ,["solutions v_v'i'"])],
wneuper@59430
   786
      assoc_rls' @{theory} "matches", 
walther@59997
   787
      SOME "solve (e_e::bool, v_v)", [["Test", "solve_plain_square"]])),
walther@59973
   788
    (Problem.prep_input thy "pbl_test_uni_poly" [] Problem.id_empty
walther@59997
   789
      (["polynomial", "univariate", "equation", "test"],
walther@60242
   790
        [("#Given" ,["equality (v_v  \<up> 2 + p_p * v_v + q__q = 0)", "solveFor v_v"]),
wneuper@59430
   791
          ("#Where" ,["HOL.False"]),
wneuper@59430
   792
          ("#Find"  ,["solutions v_v'i'"])],
walther@59852
   793
        Rule_Set.empty, SOME "solve (e_e::bool, v_v)", [])),
walther@59973
   794
    (Problem.prep_input thy "pbl_test_uni_poly_deg2" [] Problem.id_empty
walther@59997
   795
      (["degree_two", "polynomial", "univariate", "equation", "test"],
walther@60242
   796
        [("#Given" ,["equality (v_v  \<up> 2 + p_p * v_v + q__q = 0)", "solveFor v_v"]),
wneuper@59430
   797
          ("#Find"  ,["solutions v_v'i'"])],
walther@60242
   798
        Rule_Set.empty, SOME "solve (v_v  \<up> 2 + p_p * v_v + q__q = 0, v_v)", [])),
walther@59973
   799
    (Problem.prep_input thy "pbl_test_uni_poly_deg2_pq" [] Problem.id_empty
walther@59997
   800
      (["pq_formula", "degree_two", "polynomial", "univariate", "equation", "test"],
walther@60242
   801
        [("#Given" ,["equality (v_v  \<up> 2 + p_p * v_v + q__q = 0)", "solveFor v_v"]),
wneuper@59430
   802
          ("#Find"  ,["solutions v_v'i'"])],
walther@60242
   803
        Rule_Set.empty, SOME "solve (v_v  \<up> 2 + p_p * v_v + q__q = 0, v_v)", [])),
walther@59973
   804
    (Problem.prep_input thy "pbl_test_uni_poly_deg2_abc" [] Problem.id_empty
walther@59997
   805
      (["abc_formula", "degree_two", "polynomial", "univariate", "equation", "test"],
walther@60242
   806
        [("#Given" ,["equality (a_a * x  \<up> 2 + b_b * x + c_c = 0)", "solveFor v_v"]),
wneuper@59430
   807
          ("#Find"  ,["solutions v_v'i'"])],
walther@60242
   808
        Rule_Set.empty, SOME "solve (a_a * x  \<up> 2 + b_b * x + c_c = 0, v_v)", [])),
walther@59973
   809
    (Problem.prep_input thy "pbl_test_uni_root" [] Problem.id_empty
walther@59997
   810
      (["squareroot", "univariate", "equation", "test"],
walther@59997
   811
        [("#Given" ,["equality e_e", "solveFor v_v"]),
wneuper@59430
   812
          ("#Where" ,["precond_rootpbl v_v"]),
wneuper@59430
   813
          ("#Find"  ,["solutions v_v'i'"])],
walther@59878
   814
        Rule_Set.append_rules "contains_root" Rule_Set.empty [Rule.Eval ("Test.contains'_root",
wneuper@59430
   815
            eval_contains_root "#contains_root_")], 
walther@59997
   816
        SOME "solve (e_e::bool, v_v)", [["Test", "square_equation"]])),
walther@59973
   817
    (Problem.prep_input thy "pbl_test_uni_norm" [] Problem.id_empty
walther@59997
   818
      (["normalise", "univariate", "equation", "test"],
walther@59997
   819
        [("#Given" ,["equality e_e", "solveFor v_v"]),
wneuper@59430
   820
          ("#Where" ,[]),
wneuper@59430
   821
          ("#Find"  ,["solutions v_v'i'"])],
walther@59997
   822
        Rule_Set.empty, SOME "solve (e_e::bool, v_v)", [["Test", "norm_univar_equation"]])),
walther@59973
   823
    (Problem.prep_input thy "pbl_test_uni_roottest" [] Problem.id_empty
walther@59997
   824
      (["sqroot-test", "univariate", "equation", "test"],
walther@59997
   825
        [("#Given" ,["equality e_e", "solveFor v_v"]),
wneuper@59430
   826
          ("#Where" ,["precond_rootpbl v_v"]),
wneuper@59430
   827
          ("#Find"  ,["solutions v_v'i'"])],
walther@59852
   828
        Rule_Set.empty, SOME "solve (e_e::bool, v_v)", [])),
walther@59973
   829
    (Problem.prep_input thy "pbl_test_intsimp" [] Problem.id_empty
walther@59997
   830
      (["inttype", "test"],
wneuper@59430
   831
        [("#Given" ,["intTestGiven t_t"]),
wneuper@59430
   832
          ("#Where" ,[]),
wneuper@59430
   833
          ("#Find"  ,["intTestFind s_s"])],
walther@59997
   834
      Rule_Set.empty, NONE, [["Test", "intsimp"]]))]\<close>
wneuper@59430
   835
wneuper@59472
   836
section \<open>methods\<close>
wneuper@59472
   837
subsection \<open>differentiate\<close>
wneuper@59472
   838
setup \<open>KEStore_Elems.add_mets
walther@60154
   839
    [MethodC.prep_input @{theory "Diff"} "met_test" [] MethodC.id_empty
wneuper@59430
   840
      (["Test"], [],
walther@59852
   841
        {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = Rule_Set.empty, prls=Rule_Set.empty,
walther@59852
   842
          crls=Atools_erls, errpats = [], nrls = Rule_Set.empty}, @{thm refl})]
wneuper@59473
   843
\<close>
wneuper@59545
   844
wneuper@59504
   845
partial_function (tailrec) solve_linear :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504
   846
  where
walther@59635
   847
"solve_linear e_e v_v = (
walther@59635
   848
  let e_e =
walther@59635
   849
    Repeat (
walther@59637
   850
      (Rewrite_Set_Inst [(''bdv'', v_v)] ''isolate_bdv'') #>
walther@59635
   851
      (Rewrite_Set ''Test_simplify'')) e_e
walther@59635
   852
  in
walther@59635
   853
    [e_e])"
wneuper@59473
   854
setup \<open>KEStore_Elems.add_mets
walther@60154
   855
    [MethodC.prep_input thy "met_test_solvelin" [] MethodC.id_empty
walther@59997
   856
      (["Test", "solve_linear"],
walther@59997
   857
        [("#Given" ,["equality e_e", "solveFor v_v"]),
wneuper@59430
   858
          ("#Where" ,["matches (?a = ?b) e_e"]),
wneuper@59430
   859
          ("#Find"  ,["solutions v_v'i'"])],
walther@59852
   860
        {rew_ord' = "e_rew_ord", rls' = tval_rls, srls = Rule_Set.empty,
wneuper@59430
   861
          prls = assoc_rls' @{theory} "matches", calc = [], crls = tval_rls, errpats = [],
wneuper@59430
   862
          nrls = Test_simplify},
wneuper@59551
   863
        @{thm solve_linear.simps})]
wneuper@59472
   864
\<close>
wneuper@59472
   865
subsection \<open>root equation\<close>
wneuper@59545
   866
wneuper@59504
   867
partial_function (tailrec) solve_root_equ :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504
   868
  where
walther@59635
   869
"solve_root_equ e_e v_v = (
walther@59635
   870
  let
walther@59635
   871
    e_e = (
walther@59635
   872
      (While (contains_root e_e) Do (
walther@59637
   873
        (Rewrite ''square_equation_left'' ) #>
walther@59637
   874
        (Try (Rewrite_Set ''Test_simplify'' )) #>
walther@59637
   875
        (Try (Rewrite_Set ''rearrange_assoc'' )) #>
walther@59637
   876
        (Try (Rewrite_Set ''isolate_root'' )) #>
walther@59637
   877
        (Try (Rewrite_Set ''Test_simplify'' )))) #>
walther@59637
   878
      (Try (Rewrite_Set ''norm_equation'' )) #>
walther@59637
   879
      (Try (Rewrite_Set ''Test_simplify'' )) #>
walther@59637
   880
      (Rewrite_Set_Inst [(''bdv'', v_v)] ''isolate_bdv'' ) #>
walther@59635
   881
      (Try (Rewrite_Set ''Test_simplify'' ))
walther@59635
   882
      ) e_e                                                                
walther@59635
   883
  in
walther@59635
   884
    [e_e])"
wneuper@59472
   885
setup \<open>KEStore_Elems.add_mets
walther@60154
   886
    [MethodC.prep_input thy  "met_test_sqrt" [] MethodC.id_empty
wneuper@59430
   887
      (*root-equation, version for tests before 8.01.01*)
walther@59997
   888
      (["Test", "sqrt-equ-test"],
walther@59997
   889
        [("#Given" ,["equality e_e", "solveFor v_v"]),
wneuper@59430
   890
          ("#Where" ,["contains_root (e_e::bool)"]),
wneuper@59430
   891
          ("#Find"  ,["solutions v_v'i'"])],
wneuper@59430
   892
        {rew_ord'="e_rew_ord",rls'=tval_rls,
walther@59852
   893
          srls = Rule_Set.append_rules "srls_contains_root" Rule_Set.empty
walther@59878
   894
              [Rule.Eval ("Test.contains'_root", eval_contains_root "")],
walther@59852
   895
          prls = Rule_Set.append_rules "prls_contains_root" Rule_Set.empty 
walther@59878
   896
              [Rule.Eval ("Test.contains'_root", eval_contains_root "")],
walther@59852
   897
          calc=[], crls=tval_rls, errpats = [], nrls = Rule_Set.empty (*,asm_rls=[],
walther@59997
   898
          asm_thm=[("square_equation_left", ""), ("square_equation_right", "")]*)},
wneuper@59551
   899
        @{thm solve_root_equ.simps})]
wneuper@59472
   900
\<close>
wneuper@59477
   901
walther@59635
   902
partial_function (tailrec) minisubpbl :: "bool \<Rightarrow> real \<Rightarrow> bool list"
walther@59635
   903
  where
walther@59635
   904
"minisubpbl e_e v_v = (
walther@59635
   905
  let
walther@59635
   906
    e_e = (
walther@59637
   907
      (Try (Rewrite_Set ''norm_equation'' )) #>
walther@59635
   908
      (Try (Rewrite_Set ''Test_simplify'' ))) e_e;
walther@59635
   909
    L_L = SubProblem (''Test'', [''LINEAR'', ''univariate'', ''equation'', ''test''],
walther@59635
   910
      [''Test'', ''solve_linear'']) [BOOL e_e, REAL v_v]
walther@59635
   911
  in
walther@59635
   912
    Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59472
   913
setup \<open>KEStore_Elems.add_mets
walther@60154
   914
    [MethodC.prep_input thy "met_test_squ_sub" [] MethodC.id_empty
wneuper@59430
   915
      (*tests subproblem fixed linear*)
walther@59997
   916
      (["Test", "squ-equ-test-subpbl1"],
walther@59997
   917
        [("#Given" ,["equality e_e", "solveFor v_v"]),
wneuper@59430
   918
          ("#Where" ,["precond_rootmet v_v"]),
wneuper@59430
   919
          ("#Find"  ,["solutions v_v'i'"])],
walther@59852
   920
        {rew_ord' = "e_rew_ord", rls' = tval_rls, srls = Rule_Set.empty,
walther@59852
   921
          prls = Rule_Set.append_rules "prls_met_test_squ_sub" Rule_Set.empty
walther@59878
   922
              [Rule.Eval ("Test.precond'_rootmet", eval_precond_rootmet "")],
wneuper@59430
   923
          calc=[], crls=tval_rls, errpats = [], nrls = Test_simplify},
wneuper@59551
   924
        @{thm minisubpbl.simps})]
wneuper@59472
   925
\<close>
wneuper@59545
   926
wneuper@59504
   927
partial_function (tailrec) solve_root_equ2 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
walther@59635
   928
  where
walther@59635
   929
"solve_root_equ2 e_e v_v = (
walther@59635
   930
  let
walther@59635
   931
    e_e = (
walther@59635
   932
      (While (contains_root e_e) Do (
walther@59637
   933
        (Rewrite ''square_equation_left'' ) #>
walther@59637
   934
        (Try (Rewrite_Set ''Test_simplify'' )) #>
walther@59637
   935
        (Try (Rewrite_Set ''rearrange_assoc'' )) #>
walther@59637
   936
        (Try (Rewrite_Set ''isolate_root'' )) #>
walther@59637
   937
        (Try (Rewrite_Set ''Test_simplify'' )))) #>
walther@59637
   938
      (Try (Rewrite_Set ''norm_equation'' )) #>
walther@59635
   939
      (Try (Rewrite_Set ''Test_simplify'' ))
walther@59635
   940
      ) e_e;
walther@59635
   941
    L_L = SubProblem (''Test'', [''LINEAR'', ''univariate'', ''equation'', ''test''],
wneuper@59504
   942
             [''Test'', ''solve_linear'']) [BOOL e_e, REAL v_v]
walther@59635
   943
  in
walther@59635
   944
    Check_elementwise L_L {(v_v::real). Assumptions})                                       "
wneuper@59472
   945
setup \<open>KEStore_Elems.add_mets
walther@60154
   946
    [MethodC.prep_input thy  "met_test_eq1" [] MethodC.id_empty
wneuper@59430
   947
      (*root-equation1:*)
walther@59997
   948
      (["Test", "square_equation1"],
walther@59997
   949
        [("#Given" ,["equality e_e", "solveFor v_v"]),
wneuper@59430
   950
          ("#Find"  ,["solutions v_v'i'"])],
wneuper@59430
   951
        {rew_ord'="e_rew_ord",rls'=tval_rls,
walther@59852
   952
          srls = Rule_Set.append_rules "srls_contains_root" Rule_Set.empty 
walther@59878
   953
            [Rule.Eval ("Test.contains'_root", eval_contains_root"")], prls=Rule_Set.empty, calc=[], crls=tval_rls,
walther@59997
   954
              errpats = [], nrls = Rule_Set.empty(*,asm_rls=[], asm_thm=[("square_equation_left", ""),
walther@59997
   955
              ("square_equation_right", "")]*)},
wneuper@59551
   956
        @{thm solve_root_equ2.simps})]
wneuper@59472
   957
\<close>
wneuper@59545
   958
wneuper@59504
   959
partial_function (tailrec) solve_root_equ3 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504
   960
  where
walther@59635
   961
"solve_root_equ3 e_e v_v = (
walther@59635
   962
  let
walther@59635
   963
    e_e = (
walther@59635
   964
      (While (contains_root e_e) Do ((
walther@59635
   965
        (Rewrite ''square_equation_left'' ) Or
walther@59637
   966
        (Rewrite ''square_equation_right'' )) #>
walther@59637
   967
        (Try (Rewrite_Set ''Test_simplify'' )) #>
walther@59637
   968
        (Try (Rewrite_Set ''rearrange_assoc'' )) #>
walther@59637
   969
        (Try (Rewrite_Set ''isolate_root'' )) #>
walther@59637
   970
        (Try (Rewrite_Set ''Test_simplify'' )))) #>
walther@59637
   971
      (Try (Rewrite_Set ''norm_equation'' )) #>
walther@59635
   972
      (Try (Rewrite_Set ''Test_simplify'' ))
walther@59635
   973
      ) e_e;
walther@59635
   974
    L_L = SubProblem (''Test'', [''plain_square'', ''univariate'', ''equation'', ''test''],
walther@59635
   975
      [''Test'', ''solve_plain_square'']) [BOOL e_e, REAL v_v]
walther@59635
   976
  in
walther@59635
   977
    Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59472
   978
setup \<open>KEStore_Elems.add_mets
walther@60154
   979
    [MethodC.prep_input thy "met_test_squ2" [] MethodC.id_empty
wneuper@59430
   980
      (*root-equation2*)
walther@59997
   981
        (["Test", "square_equation2"],
walther@59997
   982
          [("#Given" ,["equality e_e", "solveFor v_v"]),
wneuper@59430
   983
          ("#Find"  ,["solutions v_v'i'"])],
wneuper@59430
   984
        {rew_ord'="e_rew_ord",rls'=tval_rls,
walther@59852
   985
          srls = Rule_Set.append_rules "srls_contains_root" Rule_Set.empty 
walther@59878
   986
              [Rule.Eval ("Test.contains'_root", eval_contains_root"")],
walther@59852
   987
          prls=Rule_Set.empty,calc=[], crls=tval_rls, errpats = [], nrls = Rule_Set.empty(*,asm_rls=[],
walther@59997
   988
          asm_thm=[("square_equation_left", ""), ("square_equation_right", "")]*)},
wneuper@59551
   989
        @{thm solve_root_equ3.simps})]
wneuper@59472
   990
\<close>
wneuper@59545
   991
wneuper@59504
   992
partial_function (tailrec) solve_root_equ4 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504
   993
  where
walther@59635
   994
"solve_root_equ4 e_e v_v = (
walther@59635
   995
  let
walther@59635
   996
    e_e = (
walther@59635
   997
      (While (contains_root e_e) Do ((
walther@59635
   998
        (Rewrite ''square_equation_left'' ) Or
walther@59637
   999
        (Rewrite ''square_equation_right'' )) #>
walther@59637
  1000
        (Try (Rewrite_Set ''Test_simplify'' )) #>
walther@59637
  1001
        (Try (Rewrite_Set ''rearrange_assoc'' )) #>
walther@59637
  1002
        (Try (Rewrite_Set ''isolate_root'' )) #>
walther@59637
  1003
        (Try (Rewrite_Set ''Test_simplify'' )))) #>
walther@59637
  1004
      (Try (Rewrite_Set ''norm_equation'' )) #>
walther@59635
  1005
      (Try (Rewrite_Set ''Test_simplify'' ))
walther@59635
  1006
      ) e_e;
walther@59635
  1007
    L_L = SubProblem (''Test'', [''univariate'', ''equation'', ''test''],
walther@59635
  1008
      [''no_met'']) [BOOL e_e, REAL v_v]
walther@59635
  1009
  in
walther@59635
  1010
    Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59472
  1011
setup \<open>KEStore_Elems.add_mets
walther@60154
  1012
    [MethodC.prep_input thy "met_test_squeq" [] MethodC.id_empty
wneuper@59430
  1013
      (*root-equation*)
walther@59997
  1014
      (["Test", "square_equation"],
walther@59997
  1015
        [("#Given" ,["equality e_e", "solveFor v_v"]),
wneuper@59430
  1016
          ("#Find"  ,["solutions v_v'i'"])],
wneuper@59430
  1017
        {rew_ord'="e_rew_ord",rls'=tval_rls,
walther@59852
  1018
          srls = Rule_Set.append_rules "srls_contains_root" Rule_Set.empty 
walther@59878
  1019
              [Rule.Eval ("Test.contains'_root", eval_contains_root"")],
walther@59852
  1020
          prls=Rule_Set.empty,calc=[], crls=tval_rls, errpats = [], nrls = Rule_Set.empty (*,asm_rls=[],
walther@59997
  1021
          asm_thm=[("square_equation_left", ""), ("square_equation_right", "")]*)},
wneuper@59551
  1022
        @{thm solve_root_equ4.simps})]
wneuper@59472
  1023
\<close>
wneuper@59545
  1024
wneuper@59504
  1025
partial_function (tailrec) solve_plain_square :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504
  1026
  where
walther@59635
  1027
"solve_plain_square e_e v_v = (
walther@59635
  1028
  let
walther@59635
  1029
    e_e = (
walther@59637
  1030
      (Try (Rewrite_Set ''isolate_bdv'' )) #>
walther@59637
  1031
      (Try (Rewrite_Set ''Test_simplify'' )) #>
walther@59635
  1032
      ((Rewrite ''square_equality_0'' ) Or
walther@59637
  1033
       (Rewrite ''square_equality'' )) #>
walther@59635
  1034
      (Try (Rewrite_Set ''tval_rls'' ))) e_e
walther@59635
  1035
  in
walther@59635
  1036
    Or_to_List e_e)"
wneuper@59472
  1037
setup \<open>KEStore_Elems.add_mets
walther@60154
  1038
    [MethodC.prep_input thy "met_test_eq_plain" [] MethodC.id_empty
wneuper@59430
  1039
      (*solve_plain_square*)
walther@59997
  1040
      (["Test", "solve_plain_square"],
walther@59997
  1041
        [("#Given",["equality e_e", "solveFor v_v"]),
walther@60242
  1042
          ("#Where" ,["(matches (?a + ?b*v_v  \<up> 2 = 0) e_e) |" ^
walther@60242
  1043
              "(matches (     ?b*v_v  \<up> 2 = 0) e_e) |" ^
walther@60242
  1044
              "(matches (?a +    v_v  \<up> 2 = 0) e_e) |" ^
walther@60242
  1045
              "(matches (        v_v  \<up> 2 = 0) e_e)"]), 
wneuper@59430
  1046
          ("#Find"  ,["solutions v_v'i'"])],
walther@59852
  1047
        {rew_ord'="e_rew_ord",rls'=tval_rls,calc=[],srls=Rule_Set.empty,
walther@59852
  1048
          prls = assoc_rls' @{theory} "matches", crls=tval_rls, errpats = [], nrls = Rule_Set.empty(*,
wneuper@59430
  1049
          asm_rls=[],asm_thm=[]*)},
wneuper@59551
  1050
        @{thm solve_plain_square.simps})]
wneuper@59472
  1051
\<close>
wneuper@59472
  1052
subsection \<open>polynomial equation\<close>
wneuper@59545
  1053
wneuper@59504
  1054
partial_function (tailrec) norm_univariate_equ :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504
  1055
  where
walther@59635
  1056
"norm_univariate_equ e_e v_v = (
walther@59635
  1057
  let
walther@59635
  1058
    e_e = (
walther@59637
  1059
      (Try (Rewrite ''rnorm_equation_add'' )) #>
walther@59635
  1060
      (Try (Rewrite_Set ''Test_simplify'' )) ) e_e
walther@59635
  1061
  in
walther@59635
  1062
    SubProblem (''Test'', [''univariate'', ''equation'', ''test''],
wneuper@59504
  1063
        [''no_met'']) [BOOL e_e, REAL v_v])"
wneuper@59472
  1064
setup \<open>KEStore_Elems.add_mets
walther@60154
  1065
    [MethodC.prep_input thy "met_test_norm_univ" [] MethodC.id_empty
walther@59997
  1066
      (["Test", "norm_univar_equation"],
walther@59997
  1067
        [("#Given",["equality e_e", "solveFor v_v"]),
wneuper@59430
  1068
          ("#Where" ,[]), 
wneuper@59430
  1069
          ("#Find"  ,["solutions v_v'i'"])],
walther@59852
  1070
        {rew_ord'="e_rew_ord",rls'=tval_rls,srls = Rule_Set.empty,prls=Rule_Set.empty, calc=[], crls=tval_rls,
walther@59852
  1071
          errpats = [], nrls = Rule_Set.empty},
wneuper@59551
  1072
        @{thm norm_univariate_equ.simps})]
wneuper@59472
  1073
\<close>
wneuper@59472
  1074
subsection \<open>diophantine equation\<close>
wneuper@59545
  1075
wneuper@59504
  1076
partial_function (tailrec) test_simplify :: "int \<Rightarrow> int"
wneuper@59504
  1077
  where
walther@59635
  1078
"test_simplify t_t = (
walther@59635
  1079
  Repeat (
walther@59637
  1080
    (Try (Calculate ''PLUS'')) #>         
walther@59635
  1081
    (Try (Calculate ''TIMES''))) t_t)"
wneuper@59472
  1082
setup \<open>KEStore_Elems.add_mets
walther@60154
  1083
    [MethodC.prep_input thy "met_test_intsimp" [] MethodC.id_empty
walther@59997
  1084
      (["Test", "intsimp"],
wneuper@59430
  1085
        [("#Given" ,["intTestGiven t_t"]),
wneuper@59430
  1086
          ("#Where" ,[]),
wneuper@59430
  1087
          ("#Find"  ,["intTestFind s_s"])],
walther@59852
  1088
        {rew_ord' = "e_rew_ord", rls' = tval_rls, srls = Rule_Set.empty,  prls = Rule_Set.empty, calc = [],
wneuper@59430
  1089
          crls = tval_rls, errpats = [], nrls = Test_simplify},
wneuper@59551
  1090
        @{thm test_simplify.simps})]
wneuper@59472
  1091
\<close>
wneuper@59430
  1092
neuper@37906
  1093
end