src/Tools/isac/Knowledge/Rational.thy
author wneuper <walther.neuper@jku.at>
Sat, 03 Jul 2021 16:21:07 +0200
changeset 60318 e6e7a9b9ced7
parent 60317 638d02a9a96a
child 60319 2edbed71fde6
permissions -rw-r--r--
//test/../rewrite.sml,poly.sml WORK
neuper@52105
     1
(* rationals, fractions of multivariate polynomials over the real field
neuper@37906
     2
   author: isac team
neuper@52105
     3
   Copyright (c) isac team 2002, 2013
neuper@37906
     4
   Use is subject to license terms.
neuper@37906
     5
neuper@37906
     6
   depends on Poly (and not on Atools), because 
wneuper@59370
     7
   fractions with _normalised_ polynomials are canceled, added, etc.
neuper@37906
     8
*)
neuper@37906
     9
neuper@48884
    10
theory Rational 
wneuper@59553
    11
imports Poly GCD_Poly_ML
neuper@48884
    12
begin
neuper@37906
    13
walther@59878
    14
section \<open>Constants for evaluation by "Rule.Eval"\<close>
neuper@37906
    15
consts
neuper@37906
    16
walther@60278
    17
  is_expanded    :: "real => bool" ("_ is'_expanded")     (*RL->Poly.thy*)
walther@60278
    18
  is_ratpolyexp  :: "real => bool" ("_ is'_ratpolyexp") 
jan@42300
    19
  get_denominator :: "real => real"
walther@60017
    20
  get_numerator   :: "real => real"           
neuper@37906
    21
wneuper@59472
    22
ML \<open>
neuper@52105
    23
(*.the expression contains + - * ^ / only ?.*)
neuper@52105
    24
fun is_ratpolyexp (Free _) = true
neuper@52105
    25
  | is_ratpolyexp (Const ("Groups.plus_class.plus",_) $ Free _ $ Free _) = true
neuper@52105
    26
  | is_ratpolyexp (Const ("Groups.minus_class.minus",_) $ Free _ $ Free _) = true
neuper@52105
    27
  | is_ratpolyexp (Const ("Groups.times_class.times",_) $ Free _ $ Free _) = true
walther@60275
    28
  | is_ratpolyexp (Const ("Transcendental.powr",_) $ Free _ $ Free _) = true
wneuper@59360
    29
  | is_ratpolyexp (Const ("Rings.divide_class.divide",_) $ Free _ $ Free _) = true
neuper@52105
    30
  | is_ratpolyexp (Const ("Groups.plus_class.plus",_) $ t1 $ t2) = 
neuper@52105
    31
               ((is_ratpolyexp t1) andalso (is_ratpolyexp t2))
neuper@52105
    32
  | is_ratpolyexp (Const ("Groups.minus_class.minus",_) $ t1 $ t2) = 
neuper@52105
    33
               ((is_ratpolyexp t1) andalso (is_ratpolyexp t2))
neuper@52105
    34
  | is_ratpolyexp (Const ("Groups.times_class.times",_) $ t1 $ t2) = 
neuper@52105
    35
               ((is_ratpolyexp t1) andalso (is_ratpolyexp t2))
walther@60275
    36
  | is_ratpolyexp (Const ("Transcendental.powr",_) $ t1 $ t2) = 
neuper@52105
    37
               ((is_ratpolyexp t1) andalso (is_ratpolyexp t2))
wneuper@59360
    38
  | is_ratpolyexp (Const ("Rings.divide_class.divide",_) $ t1 $ t2) = 
neuper@52105
    39
               ((is_ratpolyexp t1) andalso (is_ratpolyexp t2))
neuper@52105
    40
  | is_ratpolyexp _ = false;
neuper@37950
    41
walther@60278
    42
(*("is_ratpolyexp", ("Rational.is_ratpolyexp", eval_is_ratpolyexp ""))*)
neuper@52105
    43
fun eval_is_ratpolyexp (thmid:string) _ 
walther@60278
    44
		       (t as (Const("Rational.is_ratpolyexp", _) $ arg)) thy =
neuper@52105
    45
    if is_ratpolyexp arg
walther@59870
    46
    then SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "", 
wneuper@59390
    47
	         HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
walther@59870
    48
    else SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "", 
wneuper@59390
    49
	         HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
neuper@52105
    50
  | eval_is_ratpolyexp _ _ _ _ = NONE; 
neuper@52105
    51
neuper@52105
    52
(*("get_denominator", ("Rational.get_denominator", eval_get_denominator ""))*)
neuper@52105
    53
fun eval_get_denominator (thmid:string) _ 
neuper@52105
    54
		      (t as Const ("Rational.get_denominator", _) $
walther@59603
    55
              (Const ("Rings.divide_class.divide", _) $ _(*num*) $
neuper@52105
    56
                denom)) thy = 
walther@59870
    57
      SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy denom) "", 
wneuper@59390
    58
	            HOLogic.Trueprop $ (TermC.mk_equality (t, denom)))
neuper@52105
    59
  | eval_get_denominator _ _ _ _ = NONE; 
neuper@52105
    60
neuper@52105
    61
(*("get_numerator", ("Rational.get_numerator", eval_get_numerator ""))*)
neuper@52105
    62
fun eval_get_numerator (thmid:string) _ 
neuper@52105
    63
      (t as Const ("Rational.get_numerator", _) $
wneuper@59360
    64
          (Const ("Rings.divide_class.divide", _) $num
neuper@52105
    65
            $denom )) thy = 
walther@59870
    66
    SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy num) "", 
wneuper@59390
    67
	    HOLogic.Trueprop $ (TermC.mk_equality (t, num)))
neuper@52105
    68
  | eval_get_numerator _ _ _ _ = NONE; 
wneuper@59472
    69
\<close>
neuper@52105
    70
wneuper@59472
    71
section \<open>Theorems for rewriting\<close>
neuper@52105
    72
neuper@52105
    73
axiomatization (* naming due to Isabelle2002, but not contained in Isabelle2002; 
neuper@52105
    74
                  many thms are due to RL and can be removed with updating the equation solver;
neuper@52105
    75
                  TODO: replace by equivalent thms in recent Isabelle201x *) 
neuper@52105
    76
where
neuper@52105
    77
  mult_cross:      "[| b ~= 0; d ~= 0 |] ==> (a / b = c / d) = (a * d = b * c)" and
neuper@52105
    78
  mult_cross1:     "   b ~= 0            ==> (a / b = c    ) = (a     = b * c)" and
neuper@52105
    79
  mult_cross2:     "           d ~= 0    ==> (a     = c / d) = (a * d =     c)" and
neuper@37950
    80
                  
neuper@52105
    81
  add_minus:       "a + b - b = a"(*RL->Poly.thy*) and
neuper@52105
    82
  add_minus1:      "a - b + b = a"(*RL->Poly.thy*) and
neuper@37950
    83
                  
neuper@52105
    84
  rat_mult:        "a / b * (c / d) = a * c / (b * d)"(*?Isa02*)  and
neuper@52105
    85
  rat_mult2:       "a / b *  c      = a * c /  b     "(*?Isa02*) and
t@42211
    86
neuper@52105
    87
  rat_mult_poly_l: "c is_polyexp ==> c * (a / b) = c * a /  b" and
neuper@52105
    88
  rat_mult_poly_r: "c is_polyexp ==> (a / b) * c = a * c /  b" and
neuper@37906
    89
neuper@37906
    90
(*real_times_divide1_eq .. Isa02*) 
neuper@52105
    91
  real_times_divide_1_eq:  "-1 * (c / d) = -1 * c / d " and
neuper@52105
    92
  real_times_divide_num:   "a is_const ==> a * (c / d) = a * c / d " and
t@42211
    93
neuper@52105
    94
  real_mult_div_cancel2:   "k ~= 0 ==> m * k / (n * k) = m / n" and
neuper@37978
    95
(*real_mult_div_cancel1:   "k ~= 0 ==> k * m / (k * n) = m / n"..Isa02*)
neuper@37906
    96
			  
neuper@52105
    97
  real_divide_divide1:     "y ~= 0 ==> (u / v) / (y / z) = (u / v) * (z / y)" and
neuper@52105
    98
  real_divide_divide1_mg:  "y ~= 0 ==> (u / v) / (y / z) = (u * z) / (y * v)" and
neuper@37978
    99
(*real_divide_divide2_eq:  "x / y / z = x / (y * z)"..Isa02*)
neuper@37906
   100
			  
walther@60242
   101
  rat_power:               "(a / b) \<up> n = (a \<up> n) / (b \<up> n)" and
neuper@37978
   102
neuper@37978
   103
  rat_add:         "[| a is_const; b is_const; c is_const; d is_const |] ==> 
neuper@52105
   104
	           a / c + b / d = (a * d + b * c) / (c * d)" and
neuper@37978
   105
  rat_add_assoc:   "[| a is_const; b is_const; c is_const; d is_const |] ==> 
neuper@52105
   106
	           a / c +(b / d + e) = (a * d + b * c)/(d * c) + e" and
neuper@37978
   107
  rat_add1:        "[| a is_const; b is_const; c is_const |] ==> 
neuper@52105
   108
	           a / c + b / c = (a + b) / c" and
neuper@37978
   109
  rat_add1_assoc:   "[| a is_const; b is_const; c is_const |] ==> 
neuper@52105
   110
	           a / c + (b / c + e) = (a + b) / c + e" and
neuper@37978
   111
  rat_add2:        "[| a is_const; b is_const; c is_const |] ==> 
neuper@52105
   112
	           a / c + b = (a + b * c) / c" and
neuper@37978
   113
  rat_add2_assoc:  "[| a is_const; b is_const; c is_const |] ==> 
neuper@52105
   114
	           a / c + (b + e) = (a + b * c) / c + e" and
neuper@37978
   115
  rat_add3:        "[| a is_const; b is_const; c is_const |] ==> 
neuper@52105
   116
	           a + b / c = (a * c + b) / c" and
neuper@37978
   117
  rat_add3_assoc:   "[| a is_const; b is_const; c is_const |] ==> 
neuper@37950
   118
	           a + (b / c + e) = (a * c + b) / c + e"
neuper@37950
   119
wneuper@59472
   120
section \<open>Cancellation and addition of fractions\<close>
wneuper@59472
   121
subsection \<open>Conversion term <--> poly\<close>
wneuper@59472
   122
subsubsection \<open>Convert a term to the internal representation of a multivariate polynomial\<close>
wneuper@59472
   123
ML \<open>
wneuper@59532
   124
fun monom_of_term vs (c, es) (t as Const _) =
wneuper@59532
   125
    (c, list_update es (find_index (curry op = t) vs) 1)
walther@60318
   126
  | monom_of_term vs (c, es) (t as (Const ("Num.numeral_class.numeral", _) $ _)) =
walther@60318
   127
    (t |> HOLogic.dest_number |> snd |> string_of_int
walther@60317
   128
      |> TermC.int_opt_of_string |> the |> curry op * c, es) (*several numerals in one monom*)
walther@60318
   129
  | monom_of_term  vs (c, es) (t as Free _) =
walther@60318
   130
    (c, list_update es (find_index (curry op = t) vs) 1)
walther@60318
   131
  | monom_of_term  vs (c, es) (Const ("Transcendental.powr", _) $ (t as Free _) $
walther@60318
   132
      (Const ("Num.numeral_class.numeral", _) $ num)) =
walther@60317
   133
    (c, list_update es (find_index (curry op = t) vs) (num |> HOLogic.dest_numeral))
neuper@52087
   134
  | monom_of_term vs (c, es) (Const ("Groups.times_class.times", _) $ m1 $ m2) =
neuper@52087
   135
    let val (c', es') = monom_of_term vs (c, es) m1
neuper@52087
   136
    in monom_of_term vs (c', es') m2 end
walther@59868
   137
  | monom_of_term _ _ t = raise ERROR ("poly malformed 1 with " ^ UnparseC.term t)
neuper@52087
   138
walther@60318
   139
(*-------v------*)
wneuper@59531
   140
fun monoms_of_term vs (t as Const _) =
wneuper@59531
   141
    [monom_of_term  vs (1, replicate (length vs) 0) t]
wneuper@59531
   142
  | monoms_of_term vs (t as Free _) =
neuper@52087
   143
    [monom_of_term  vs (1, replicate (length vs) 0) t]
walther@60275
   144
  | monoms_of_term vs (t as Const ("Transcendental.powr", _) $ _ $  _) =
neuper@52087
   145
    [monom_of_term  vs (1, replicate (length vs) 0) t]
neuper@52087
   146
  | monoms_of_term vs (t as Const ("Groups.times_class.times", _) $ _ $  _) =
neuper@52087
   147
    [monom_of_term  vs (1, replicate (length vs) 0) t]
neuper@52087
   148
  | monoms_of_term vs (Const ("Groups.plus_class.plus", _) $ ms1 $ ms2) =
neuper@52087
   149
    (monoms_of_term vs ms1) @ (monoms_of_term vs ms2)
walther@59868
   150
  | monoms_of_term _ t = raise ERROR ("poly malformed 2 with " ^ UnparseC.term t)
neuper@52087
   151
neuper@52087
   152
(* convert a term to the internal representation of a multivariate polynomial;
neuper@52087
   153
  the conversion is quite liberal, see test --- fun poly_of_term ---:
neuper@52087
   154
* the order of variables and the parentheses within a monomial are arbitrary
neuper@52087
   155
* the coefficient may be somewhere
neuper@52087
   156
* he order and the parentheses within monomials are arbitrary
neuper@52087
   157
But the term must be completely expand + over * (laws of distributivity are not applicable).
neuper@52087
   158
neuper@52087
   159
The function requires the free variables as strings already given, 
neuper@52087
   160
because the gcd involves 2 polynomials (with the same length for their list of exponents).
neuper@52087
   161
*)
neuper@52087
   162
fun poly_of_term vs (t as Const ("Groups.plus_class.plus", _) $ _ $ _) =
neuper@52101
   163
    (SOME (t |> monoms_of_term vs |> order)
neuper@52087
   164
      handle ERROR _ => NONE)
neuper@52087
   165
  | poly_of_term vs t =
neuper@52101
   166
    (SOME [monom_of_term vs (1, replicate (length vs) 0) t]
neuper@52087
   167
      handle ERROR _ => NONE)
neuper@52087
   168
neuper@52087
   169
fun is_poly t =
wneuper@59532
   170
  let
wneuper@59532
   171
    val vs = TermC.vars_of t
neuper@52087
   172
  in 
neuper@52087
   173
    case poly_of_term vs t of SOME _ => true | NONE => false
neuper@52087
   174
  end
neuper@52105
   175
val is_expanded = is_poly   (* TODO: check names *)
neuper@52105
   176
val is_polynomial = is_poly (* TODO: check names *)
wneuper@59472
   177
\<close>
neuper@52087
   178
wneuper@59472
   179
subsubsection \<open>Convert internal representation of a multivariate polynomial to a term\<close>
wneuper@59472
   180
ML \<open>
neuper@52087
   181
fun term_of_es _ _ _ [] = [] (*assumes same length for vs and es*)
wneuper@59532
   182
  | term_of_es baseT expT (_ :: vs) (0 :: es) = [] @ term_of_es baseT expT vs es
wneuper@59532
   183
  | term_of_es baseT expT (v :: vs) (1 :: es) = v :: term_of_es baseT expT vs es
neuper@52087
   184
  | term_of_es baseT expT (v :: vs) (e :: es) =
walther@60317
   185
    Const ("Transcendental.powr", [baseT, expT] ---> baseT) $ v $ (HOLogic.mk_number expT e)
wneuper@59532
   186
    :: term_of_es baseT expT vs es
wneuper@59532
   187
  | term_of_es _ _ _ _ = raise ERROR "term_of_es: length vs <> length es"
neuper@52087
   188
neuper@52087
   189
fun term_of_monom baseT expT vs ((c, es): monom) =
neuper@52087
   190
    let val es' = term_of_es baseT expT vs es
neuper@52087
   191
    in 
neuper@52087
   192
      if c = 1 
neuper@52087
   193
      then 
neuper@52087
   194
        if es' = [] (*if es = [0,0,0,...]*)
walther@60317
   195
        then HOLogic.mk_number baseT c
neuper@52087
   196
        else foldl (HOLogic.mk_binop "Groups.times_class.times") (hd es', tl es')
walther@60317
   197
      else foldl (HOLogic.mk_binop "Groups.times_class.times")
walther@60317
   198
        (HOLogic.mk_number baseT c, es') 
neuper@52087
   199
    end
neuper@52087
   200
neuper@52087
   201
fun term_of_poly baseT expT vs p =
wneuper@59190
   202
  let val monos = map (term_of_monom baseT expT vs) p
neuper@52087
   203
  in foldl (HOLogic.mk_binop "Groups.plus_class.plus") (hd monos, tl monos) end
wneuper@59472
   204
\<close>
neuper@52087
   205
wneuper@59472
   206
subsection \<open>Apply gcd_poly for cancelling and adding fractions as terms\<close>
wneuper@59472
   207
ML \<open>
neuper@52091
   208
fun mk_noteq_0 baseT t = 
neuper@52091
   209
  Const ("HOL.Not", HOLogic.boolT --> HOLogic.boolT) $ 
walther@60317
   210
    (Const ("HOL.eq", [baseT, baseT] ---> HOLogic.boolT) $ t $ HOLogic.mk_number HOLogic.realT 0)
neuper@52091
   211
neuper@52094
   212
fun mk_asms baseT ts =
wneuper@59389
   213
  let val as' = filter_out TermC.is_num ts (* asm like "2 ~= 0" is needless *)
neuper@52094
   214
  in map (mk_noteq_0 baseT) as' end
wneuper@59472
   215
\<close>
neuper@52094
   216
wneuper@59472
   217
subsubsection \<open>Factor out gcd for cancellation\<close>
wneuper@59472
   218
ML \<open>
neuper@52091
   219
fun check_fraction t =
walther@60269
   220
  case t of
walther@60269
   221
    Const ("Rings.divide_class.divide", _) $ numerator $ denominator
walther@60269
   222
      => SOME (numerator, denominator)
walther@60269
   223
  | _ => NONE
neuper@52091
   224
neuper@52091
   225
(* prepare a term for cancellation by factoring out the gcd
neuper@52091
   226
  assumes: is a fraction with outmost "/"*)
neuper@52091
   227
fun factout_p_ (thy: theory) t =
neuper@52091
   228
  let val opt = check_fraction t
neuper@52091
   229
  in
neuper@52091
   230
    case opt of 
neuper@52091
   231
      NONE => NONE
neuper@52091
   232
    | SOME (numerator, denominator) =>
wneuper@59532
   233
      let
wneuper@59532
   234
        val vs = TermC.vars_of t
neuper@52091
   235
        val baseT = type_of numerator
neuper@52091
   236
        val expT = HOLogic.realT
neuper@52091
   237
      in
neuper@52091
   238
        case (poly_of_term vs numerator, poly_of_term vs denominator) of
neuper@52091
   239
          (SOME a, SOME b) =>
neuper@52091
   240
            let
neuper@52091
   241
              val ((a', b'), c) = gcd_poly a b
neuper@52096
   242
              val es = replicate (length vs) 0 
neuper@52096
   243
            in
neuper@52096
   244
              if c = [(1, es)] orelse c = [(~1, es)]
neuper@52096
   245
              then NONE
neuper@52096
   246
              else 
neuper@52096
   247
                let
neuper@52096
   248
                  val b't = term_of_poly baseT expT vs b'
neuper@52096
   249
                  val ct = term_of_poly baseT expT vs c
neuper@52096
   250
                  val t' = 
wneuper@59360
   251
                    HOLogic.mk_binop "Rings.divide_class.divide" 
neuper@52096
   252
                      (HOLogic.mk_binop "Groups.times_class.times"
wneuper@59190
   253
                        (term_of_poly baseT expT vs a', ct),
neuper@52096
   254
                       HOLogic.mk_binop "Groups.times_class.times" (b't, ct))
neuper@52105
   255
                in SOME (t', mk_asms baseT [b't, ct]) end
neuper@52096
   256
            end
neuper@52091
   257
        | _ => NONE : (term * term list) option
neuper@52091
   258
      end
neuper@52091
   259
  end
wneuper@59472
   260
\<close>
neuper@52091
   261
wneuper@59472
   262
subsubsection \<open>Cancel a fraction\<close>
wneuper@59472
   263
ML \<open>
neuper@52096
   264
(* cancel a term by the gcd ("" denote terms with internal algebraic structure)
neuper@52096
   265
  cancel_p_ :: theory \<Rightarrow> term  \<Rightarrow> (term \<times> term list) option
neuper@52096
   266
  cancel_p_ thy "a / b" = SOME ("a' / b'", ["b' \<noteq> 0"])
neuper@52096
   267
  assumes: a is_polynomial  \<and>  b is_polynomial  \<and>  b \<noteq> 0
neuper@52096
   268
  yields
neuper@52096
   269
    SOME ("a' / b'", ["b' \<noteq> 0"]). gcd_poly a b \<noteq> 1  \<and>  gcd_poly a b \<noteq> -1  \<and>  
neuper@52096
   270
      a' * gcd_poly a b = a  \<and>  b' * gcd_poly a b = b
neuper@52096
   271
    \<or> NONE *)
neuper@52101
   272
fun cancel_p_ (_: theory) t =
neuper@52091
   273
  let val opt = check_fraction t
neuper@52091
   274
  in
neuper@52091
   275
    case opt of 
neuper@52091
   276
      NONE => NONE
neuper@52091
   277
    | SOME (numerator, denominator) =>
wneuper@59532
   278
      let
wneuper@59532
   279
        val vs = TermC.vars_of t
neuper@52091
   280
        val baseT = type_of numerator
neuper@52091
   281
        val expT = HOLogic.realT
neuper@52091
   282
      in
neuper@52091
   283
        case (poly_of_term vs numerator, poly_of_term vs denominator) of
neuper@52091
   284
          (SOME a, SOME b) =>
neuper@52091
   285
            let
neuper@52091
   286
              val ((a', b'), c) = gcd_poly a b
neuper@52096
   287
              val es = replicate (length vs) 0 
neuper@52096
   288
            in
neuper@52096
   289
              if c = [(1, es)] orelse c = [(~1, es)]
neuper@52096
   290
              then NONE
neuper@52096
   291
              else 
neuper@52096
   292
                let
neuper@52096
   293
                  val bt' = term_of_poly baseT expT vs b'
neuper@52096
   294
                  val ct = term_of_poly baseT expT vs c
neuper@52096
   295
                  val t' = 
wneuper@59360
   296
                    HOLogic.mk_binop "Rings.divide_class.divide" 
wneuper@59190
   297
                      (term_of_poly baseT expT vs a', bt')
neuper@52096
   298
                  val asm = mk_asms baseT [bt']
neuper@52096
   299
                in SOME (t', asm) end
neuper@52096
   300
            end
neuper@52091
   301
        | _ => NONE : (term * term list) option
neuper@52091
   302
      end
neuper@52091
   303
  end
wneuper@59472
   304
\<close>
neuper@52091
   305
wneuper@59472
   306
subsubsection \<open>Factor out to a common denominator for addition\<close>
wneuper@59472
   307
ML \<open>
neuper@52101
   308
(* addition of fractions allows (at most) one non-fraction (a monomial) *)
neuper@52101
   309
fun check_frac_sum 
neuper@52091
   310
    (Const ("Groups.plus_class.plus", _) $ 
wneuper@59360
   311
      (Const ("Rings.divide_class.divide", _) $ n1 $ d1) $
wneuper@59360
   312
      (Const ("Rings.divide_class.divide", _) $ n2 $ d2))
neuper@52091
   313
    = SOME ((n1, d1), (n2, d2))
neuper@52101
   314
  | check_frac_sum 
neuper@52091
   315
    (Const ("Groups.plus_class.plus", _) $ 
neuper@52091
   316
      nofrac $ 
wneuper@59360
   317
      (Const ("Rings.divide_class.divide", _) $ n2 $ d2))
walther@60317
   318
    = SOME ((nofrac, HOLogic.mk_number HOLogic.realT 1), (n2, d2))
neuper@52101
   319
  | check_frac_sum 
neuper@52091
   320
    (Const ("Groups.plus_class.plus", _) $ 
wneuper@59360
   321
      (Const ("Rings.divide_class.divide", _) $ n1 $ d1) $ 
neuper@52091
   322
      nofrac)
walther@60317
   323
    = SOME ((n1, d1), (nofrac, HOLogic.mk_number HOLogic.realT 1))
neuper@52101
   324
  | check_frac_sum _ = NONE  
neuper@52091
   325
neuper@52091
   326
(* prepare a term for addition by providing the least common denominator as a product
neuper@52091
   327
  assumes: is a term with outmost "+" and at least one outmost "/" in respective summands*)
neuper@52101
   328
fun common_nominator_p_ (_: theory) t =
neuper@52101
   329
  let val opt = check_frac_sum t
neuper@52091
   330
  in
neuper@52091
   331
    case opt of 
neuper@52091
   332
      NONE => NONE
neuper@52091
   333
    | SOME ((n1, d1), (n2, d2)) =>
wneuper@59532
   334
      let
wneuper@59532
   335
        val vs = TermC.vars_of t
neuper@52091
   336
      in
neuper@52091
   337
        case (poly_of_term vs d1, poly_of_term vs d2) of
neuper@52091
   338
          (SOME a, SOME b) =>
neuper@52091
   339
            let
neuper@52091
   340
              val ((a', b'), c) = gcd_poly a b
neuper@52101
   341
              val (baseT, expT) = (type_of n1, HOLogic.realT)
wneuper@59190
   342
              val [d1', d2', c'] = map (term_of_poly baseT expT vs) [a', b', c]
neuper@52091
   343
              (*----- minimum of parentheses & nice result, but breaks tests: -------------
neuper@52091
   344
              val denom = HOLogic.mk_binop "Groups.times_class.times" 
neuper@52101
   345
                (HOLogic.mk_binop "Groups.times_class.times" (d1', d2'), c') -------------*)
neuper@52101
   346
              val denom =
neuper@52101
   347
                if c = [(1, replicate (length vs) 0)]
neuper@52101
   348
                then HOLogic.mk_binop "Groups.times_class.times" (d1', d2')
neuper@52101
   349
                else
neuper@52101
   350
                  HOLogic.mk_binop "Groups.times_class.times" (c',
neuper@52101
   351
                  HOLogic.mk_binop "Groups.times_class.times" (d1', d2')) (*--------------*)
neuper@52091
   352
              val t' =
neuper@52091
   353
                HOLogic.mk_binop "Groups.plus_class.plus"
wneuper@59360
   354
                  (HOLogic.mk_binop "Rings.divide_class.divide"
neuper@52091
   355
                    (HOLogic.mk_binop "Groups.times_class.times" (n1, d2'), denom),
wneuper@59360
   356
                  HOLogic.mk_binop "Rings.divide_class.divide" 
neuper@52091
   357
                    (HOLogic.mk_binop "Groups.times_class.times" (n2, d1'), denom))
neuper@52094
   358
              val asm = mk_asms baseT [d1', d2', c']
neuper@52091
   359
            in SOME (t', asm) end
neuper@52091
   360
        | _ => NONE : (term * term list) option
neuper@52091
   361
      end
neuper@52091
   362
  end
wneuper@59472
   363
\<close>
neuper@52105
   364
wneuper@59472
   365
subsubsection \<open>Addition of at least one fraction within a sum\<close>
wneuper@59472
   366
ML \<open>
neuper@52091
   367
(* add fractions
neuper@52100
   368
  assumes: is a term with outmost "+" and at least one outmost "/" in respective summands
neuper@52100
   369
  NOTE: the case "(_ + _) + _" need not be considered due to iterated addition.*)
neuper@52105
   370
fun add_fraction_p_ (_: theory) t =
neuper@52101
   371
  case check_frac_sum t of 
neuper@52101
   372
    NONE => NONE
neuper@52101
   373
  | SOME ((n1, d1), (n2, d2)) =>
wneuper@59532
   374
    let
wneuper@59532
   375
      val vs = TermC.vars_of t
neuper@52101
   376
    in
neuper@52101
   377
      case (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) of
neuper@52101
   378
        (SOME _, SOME a, SOME _, SOME b) =>
neuper@52101
   379
          let
neuper@52101
   380
            val ((a', b'), c) = gcd_poly a b
neuper@52101
   381
            val (baseT, expT) = (type_of n1, HOLogic.realT)
neuper@52101
   382
            val nomin = term_of_poly baseT expT vs 
neuper@52101
   383
              (((the (poly_of_term vs n1)) %%*%% b') %%+%% ((the (poly_of_term vs n2)) %%*%% a')) 
neuper@52101
   384
            val denom = term_of_poly baseT expT vs ((c %%*%% a') %%*%% b')
wneuper@59360
   385
            val t' = HOLogic.mk_binop "Rings.divide_class.divide" (nomin, denom)
neuper@52101
   386
          in SOME (t', mk_asms baseT [denom]) end
neuper@52101
   387
      | _ => NONE : (term * term list) option
neuper@52101
   388
    end
wneuper@59472
   389
\<close>
neuper@52091
   390
wneuper@59472
   391
section \<open>Embed cancellation and addition into rewriting\<close>
wneuper@59472
   392
ML \<open>val thy = @{theory}\<close>
wneuper@59472
   393
subsection \<open>Rulesets and predicate for embedding\<close>
wneuper@59472
   394
ML \<open>
neuper@52105
   395
(* evaluates conditions in calculate_Rational *)
neuper@52105
   396
val calc_rat_erls =
s1210629013@55444
   397
  prep_rls'
walther@59857
   398
    (Rule_Def.Repeat {id = "calc_rat_erls", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), 
walther@59852
   399
      erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
neuper@52105
   400
      rules = 
walther@59878
   401
        [Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
walther@60278
   402
        Rule.Eval ("Prog_Expr.is_const", Prog_Expr.eval_const "#is_const_"),
walther@59871
   403
        Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
walther@59871
   404
        Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false})], 
walther@59878
   405
      scr = Rule.Empty_Prog});
neuper@37950
   406
neuper@52105
   407
(* simplifies expressions with numerals;
neuper@52105
   408
   does NOT rearrange the term by AC-rewriting; thus terms with variables 
neuper@52105
   409
   need to have constants to be commuted together respectively           *)
neuper@52105
   410
val calculate_Rational =
walther@59852
   411
  prep_rls' (Rule_Set.merge "calculate_Rational"
walther@59857
   412
    (Rule_Def.Repeat {id = "divide", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), 
walther@59851
   413
      erls = calc_rat_erls, srls = Rule_Set.Empty,
neuper@52105
   414
      calc = [], errpatts = [],
neuper@52105
   415
      rules = 
walther@59878
   416
        [Rule.Eval ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e"),
neuper@37950
   417
walther@59871
   418
        Rule.Thm ("minus_divide_left", ThmC.numerals_to_Free (@{thm minus_divide_left} RS @{thm sym})),
neuper@52105
   419
          (*SYM - ?x / ?y = - (?x / ?y)  may come from subst*)
walther@59871
   420
        Rule.Thm ("rat_add", ThmC.numerals_to_Free @{thm rat_add}),
neuper@52105
   421
          (*"[| a is_const; b is_const; c is_const; d is_const |] ==> \
neuper@52105
   422
          \a / c + b / d = (a * d) / (c * d) + (b * c ) / (d * c)"*)
walther@59871
   423
        Rule.Thm ("rat_add1", ThmC.numerals_to_Free @{thm rat_add1}),
neuper@52105
   424
          (*"[| a is_const; b is_const; c is_const |] ==> a / c + b / c = (a + b) / c"*)
walther@59871
   425
        Rule.Thm ("rat_add2", ThmC.numerals_to_Free @{thm rat_add2}),
neuper@52105
   426
          (*"[| ?a is_const; ?b is_const; ?c is_const |] ==> ?a / ?c + ?b = (?a + ?b * ?c) / ?c"*)
walther@59871
   427
        Rule.Thm ("rat_add3", ThmC.numerals_to_Free @{thm rat_add3}),
neuper@52105
   428
          (*"[| a is_const; b is_const; c is_const |] ==> a + b / c = (a * c) / c + b / c"\
neuper@52105
   429
          .... is_const to be omitted here FIXME*)
neuper@52105
   430
        
walther@59871
   431
        Rule.Thm ("rat_mult", ThmC.numerals_to_Free @{thm rat_mult}), 
neuper@52105
   432
          (*a / b * (c / d) = a * c / (b * d)*)
walther@59871
   433
        Rule.Thm ("times_divide_eq_right", ThmC.numerals_to_Free @{thm times_divide_eq_right}),
neuper@52105
   434
          (*?x * (?y / ?z) = ?x * ?y / ?z*)
walther@59871
   435
        Rule.Thm ("times_divide_eq_left", ThmC.numerals_to_Free @{thm times_divide_eq_left}),
neuper@52105
   436
          (*?y / ?z * ?x = ?y * ?x / ?z*)
neuper@52105
   437
        
walther@59871
   438
        Rule.Thm ("real_divide_divide1", ThmC.numerals_to_Free @{thm real_divide_divide1}),
neuper@52105
   439
          (*"?y ~= 0 ==> ?u / ?v / (?y / ?z) = ?u / ?v * (?z / ?y)"*)
walther@59871
   440
        Rule.Thm ("divide_divide_eq_left", ThmC.numerals_to_Free @{thm divide_divide_eq_left}),
neuper@52105
   441
          (*"?x / ?y / ?z = ?x / (?y * ?z)"*)
neuper@52105
   442
        
walther@59871
   443
        Rule.Thm ("rat_power", ThmC.numerals_to_Free @{thm rat_power}),
walther@60260
   444
          (*"(?a / ?b)  \<up>  ?n = ?a  \<up>  ?n / ?b  \<up>  ?n"*)
neuper@52105
   445
        
walther@59871
   446
        Rule.Thm ("mult_cross", ThmC.numerals_to_Free @{thm mult_cross}),
neuper@52105
   447
          (*"[| b ~= 0; d ~= 0 |] ==> (a / b = c / d) = (a * d = b * c)*)
walther@59871
   448
        Rule.Thm ("mult_cross1", ThmC.numerals_to_Free @{thm mult_cross1}),
neuper@52105
   449
          (*"   b ~= 0            ==> (a / b = c    ) = (a     = b * c)*)
walther@59871
   450
        Rule.Thm ("mult_cross2", ThmC.numerals_to_Free @{thm mult_cross2})
neuper@52105
   451
          (*"           d ~= 0    ==> (a     = c / d) = (a * d =     c)*)], 
walther@59878
   452
      scr = Rule.Empty_Prog})
neuper@52105
   453
    calculate_Poly);
neuper@37950
   454
walther@60278
   455
(*("is_expanded", ("Rational.is_expanded", eval_is_expanded ""))*)
neuper@37950
   456
fun eval_is_expanded (thmid:string) _ 
walther@60278
   457
		       (t as (Const("Rational.is_expanded", _) $ arg)) thy = 
neuper@37950
   458
    if is_expanded arg
walther@59870
   459
    then SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "", 
wneuper@59390
   460
	         HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
walther@59870
   461
    else SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "", 
wneuper@59390
   462
	         HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
s1210629013@52159
   463
  | eval_is_expanded _ _ _ _ = NONE;
wneuper@59472
   464
\<close>
wneuper@59472
   465
setup \<open>KEStore_Elems.add_calcs
walther@60278
   466
  [("is_expanded", ("Rational.is_expanded", eval_is_expanded ""))]\<close>
wneuper@59472
   467
ML \<open>
neuper@37950
   468
val rational_erls = 
walther@59852
   469
  Rule_Set.merge "rational_erls" calculate_Rational 
walther@59852
   470
    (Rule_Set.append_rules "is_expanded" Atools_erls 
walther@60278
   471
      [Rule.Eval ("Rational.is_expanded", eval_is_expanded "")]);
wneuper@59472
   472
\<close>
neuper@37950
   473
wneuper@59472
   474
subsection \<open>Embed cancellation into rewriting\<close>
wneuper@59472
   475
ML \<open>
walther@59603
   476
(**)local (* cancel_p *)
neuper@37950
   477
walther@59852
   478
val {rules = rules, rew_ord = (_, ro), ...} = Rule_Set.rep (assoc_rls' @{theory} "rev_rew_p");
neuper@37950
   479
neuper@52105
   480
fun init_state thy eval_rls ro t =
neuper@52105
   481
  let
neuper@52105
   482
    val SOME (t', _) = factout_p_ thy t;
neuper@52105
   483
    val SOME (t'', asm) = cancel_p_ thy t;
walther@59907
   484
    val der = Derive.steps_reverse thy eval_rls rules ro NONE t';
neuper@52105
   485
    val der = der @ 
walther@59871
   486
      [(Rule.Thm ("real_mult_div_cancel2", ThmC.numerals_to_Free @{thm real_mult_div_cancel2}), (t'', asm))]
walther@60017
   487
    val rs = (Rule.distinct' o (map #1)) der
walther@60017
   488
  	val rs = filter_out (ThmC.member'
neuper@52105
   489
  	  ["sym_real_add_zero_left", "sym_real_mult_0", "sym_real_mult_1"]) rs
neuper@52105
   490
  in (t, t'', [rs(*one in order to ease locate_rule*)], der) end;
neuper@37950
   491
neuper@52105
   492
fun locate_rule thy eval_rls ro [rs] t r =
walther@59876
   493
    if member op = ((map (Rule.thm_id)) rs) (Rule.thm_id r)
neuper@52105
   494
    then 
walther@59876
   495
      let val ropt = Rewrite.rewrite_ thy ro eval_rls true (Rule.thm r) t;
neuper@52105
   496
      in
neuper@52105
   497
        case ropt of SOME ta => [(r, ta)]
walther@59733
   498
	      | NONE => ((*tracing 
walther@59876
   499
	          ("### locate_rule:  rewrite " ^ Rule.thm_id r ^ " " ^ UnparseC.term t ^ " = NONE");*) []) 
neuper@52105
   500
			end
walther@59876
   501
    else ((*tracing ("### locate_rule:  " ^ Rule.thm_id r ^ " not mem rrls");*) [])
walther@59962
   502
  | locate_rule _ _ _ _ _ _ = raise ERROR "locate_rule: doesnt match rev-sets in istate";
neuper@37950
   503
neuper@52105
   504
fun next_rule thy eval_rls ro [rs] t =
neuper@52105
   505
    let
walther@59907
   506
      val der = Derive.do_one thy eval_rls rs ro NONE t;
neuper@52105
   507
    in case der of (_, r, _) :: _ => SOME r | _ => NONE end
walther@59962
   508
  | next_rule _ _ _ _ _ = raise ERROR ("next_rule: doesnt match rev-sets in istate");
neuper@37950
   509
wneuper@59416
   510
fun attach_form (_: Rule.rule list list) (_: term) (_: term) = 
wneuper@59416
   511
  [(*TODO*)]: ( Rule.rule * (term * term list)) list;
neuper@37950
   512
walther@59861
   513
(**)in(**)
neuper@37950
   514
neuper@52105
   515
val cancel_p = 
walther@59850
   516
  Rule_Set.Rrls {id = "cancel_p", prepat = [],
neuper@52105
   517
	rew_ord=("ord_make_polynomial", ord_make_polynomial false thy),
neuper@52105
   518
	erls = rational_erls, 
neuper@52105
   519
	calc = 
walther@59603
   520
	  [("PLUS", ("Groups.plus_class.plus", (**)eval_binop "#add_")),
walther@59603
   521
	  ("TIMES" , ("Groups.times_class.times", (**)eval_binop "#mult_")),
walther@59603
   522
	  ("DIVIDE", ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e")),
walther@60275
   523
	  ("POWER", ("Transcendental.powr", (**)eval_binop "#power_"))],
neuper@52105
   524
    errpatts = [],
neuper@52105
   525
	scr =
wneuper@59416
   526
	  Rule.Rfuns {init_state  = init_state thy Atools_erls ro,
neuper@52105
   527
		normal_form = cancel_p_ thy, 
neuper@52105
   528
		locate_rule = locate_rule thy Atools_erls ro,
neuper@52105
   529
		next_rule   = next_rule thy Atools_erls ro,
neuper@52105
   530
		attach_form = attach_form}}
walther@59861
   531
(**)end(* local cancel_p *)
wneuper@59472
   532
\<close>
neuper@37950
   533
wneuper@59472
   534
subsection \<open>Embed addition into rewriting\<close>
wneuper@59472
   535
ML \<open>
walther@59861
   536
(**)local (* add_fractions_p *)
neuper@37950
   537
walther@59852
   538
(*val {rules = rules, rew_ord = (_, ro), ...} = Rule_Set.rep (assoc_rls "make_polynomial");*)
walther@59852
   539
val {rules, rew_ord=(_,ro),...} = Rule_Set.rep (assoc_rls' @{theory} "rev_rew_p");
neuper@37950
   540
neuper@52105
   541
fun init_state thy eval_rls ro t =
neuper@52105
   542
  let 
neuper@52105
   543
    val SOME (t',_) = common_nominator_p_ thy t;
neuper@52105
   544
    val SOME (t'', asm) = add_fraction_p_ thy t;
walther@59907
   545
    val der = Derive.steps_reverse thy eval_rls rules ro NONE t';
neuper@52105
   546
    val der = der @ 
walther@59871
   547
      [(Rule.Thm ("real_mult_div_cancel2", ThmC.numerals_to_Free @{thm real_mult_div_cancel2}), (t'',asm))]
walther@60017
   548
    val rs = (Rule.distinct' o (map #1)) der;
walther@60017
   549
    val rs = filter_out (ThmC.member'
neuper@52105
   550
      ["sym_real_add_zero_left", "sym_real_mult_0", "sym_real_mult_1"]) rs;
neuper@52105
   551
  in (t, t'', [rs(*here only _ONE_*)], der) end;
neuper@37950
   552
neuper@52105
   553
fun locate_rule thy eval_rls ro [rs] t r =
walther@59876
   554
    if member op = ((map (Rule.thm_id)) rs) (Rule.thm_id r)
neuper@52105
   555
    then 
walther@59876
   556
      let val ropt = Rewrite.rewrite_ thy ro eval_rls true (Rule.thm r) t;
neuper@52105
   557
      in 
neuper@52105
   558
        case ropt of
neuper@52105
   559
          SOME ta => [(r, ta)]
neuper@52105
   560
	      | NONE => 
walther@59876
   561
	        ((*tracing ("### locate_rule:  rewrite " ^ Rule.thm_id r ^ " " ^ UnparseC.term t ^ " = NONE");*)
neuper@52105
   562
	        []) end
walther@59876
   563
    else ((*tracing ("### locate_rule:  " ^ Rule.thm_id r ^ " not mem rrls");*) [])
walther@59962
   564
  | locate_rule _ _ _ _ _ _ = raise ERROR "locate_rule: doesnt match rev-sets in istate";
neuper@37950
   565
neuper@37950
   566
fun next_rule thy eval_rls ro [rs] t =
walther@59907
   567
    let val der = Derive.do_one thy eval_rls rs ro NONE t;
neuper@52105
   568
    in 
neuper@52105
   569
      case der of
neuper@52105
   570
	      (_,r,_)::_ => SOME r
neuper@52105
   571
	    | _ => NONE
neuper@37950
   572
    end
walther@59962
   573
  | next_rule _ _ _ _ _ = raise ERROR ("next_rule: doesnt match rev-sets in istate");
neuper@37950
   574
wneuper@59389
   575
val pat0 = TermC.parse_patt thy "?r/?s+?u/?v :: real";
wneuper@59389
   576
val pat1 = TermC.parse_patt thy "?r/?s+?u    :: real";
wneuper@59389
   577
val pat2 = TermC.parse_patt thy "?r   +?u/?v :: real";
neuper@48760
   578
val prepat = [([@{term True}], pat0),
neuper@48760
   579
	      ([@{term True}], pat1),
neuper@48760
   580
	      ([@{term True}], pat2)];
walther@59861
   581
(**)in(**)
neuper@37950
   582
neuper@52105
   583
val add_fractions_p =
walther@59850
   584
  Rule_Set.Rrls {id = "add_fractions_p", prepat=prepat,
neuper@52105
   585
    rew_ord = ("ord_make_polynomial", ord_make_polynomial false thy),
neuper@52105
   586
    erls = rational_erls,
walther@59603
   587
    calc = [("PLUS", ("Groups.plus_class.plus", (**)eval_binop "#add_")),
walther@59603
   588
      ("TIMES", ("Groups.times_class.times", (**)eval_binop "#mult_")),
walther@59603
   589
      ("DIVIDE", ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e")),
walther@60275
   590
      ("POWER", ("Transcendental.powr", (**)eval_binop "#power_"))],
neuper@52105
   591
    errpatts = [],
wneuper@59416
   592
    scr = Rule.Rfuns {init_state  = init_state thy Atools_erls ro,
neuper@52105
   593
      normal_form = add_fraction_p_ thy,
neuper@52105
   594
      locate_rule = locate_rule thy Atools_erls ro,
neuper@52105
   595
      next_rule   = next_rule thy Atools_erls ro,
neuper@52105
   596
      attach_form = attach_form}}
walther@59861
   597
(**)end(*local add_fractions_p *)
wneuper@59472
   598
\<close>
neuper@37950
   599
wneuper@59472
   600
subsection \<open>Cancelling and adding all occurrences in a term /////////////////////////////\<close>
wneuper@59472
   601
ML \<open>
neuper@52105
   602
(*copying cancel_p_rls + add her caused error in interface.sml*)
wneuper@59472
   603
\<close>
neuper@42451
   604
wneuper@59472
   605
section \<open>Rulesets for general simplification\<close>
wneuper@59472
   606
ML \<open>
neuper@37950
   607
(*.all powers over + distributed; atoms over * collected, other distributed
neuper@37950
   608
   contains absolute minimum of thms for context in norm_Rational .*)
s1210629013@55444
   609
val powers = prep_rls'(
walther@59857
   610
  Rule_Def.Repeat {id = "powers", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord), 
walther@59851
   611
      erls = powers_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
walther@59871
   612
      rules = [Rule.Thm ("realpow_multI", ThmC.numerals_to_Free @{thm realpow_multI}),
walther@60260
   613
	       (*"(r * s)  \<up>  n = r  \<up>  n * s  \<up>  n"*)
walther@59871
   614
	       Rule.Thm ("realpow_pow",ThmC.numerals_to_Free @{thm realpow_pow}),
walther@60260
   615
	       (*"(a  \<up>  b)  \<up>  c = a  \<up>  (b * c)"*)
walther@59871
   616
	       Rule.Thm ("realpow_oneI",ThmC.numerals_to_Free @{thm realpow_oneI}),
walther@60260
   617
	       (*"r  \<up>  1 = r"*)
walther@59871
   618
	       Rule.Thm ("realpow_minus_even",ThmC.numerals_to_Free @{thm realpow_minus_even}),
walther@60260
   619
	       (*"n is_even ==> (- r)  \<up>  n = r  \<up>  n" ?-->discard_minus?*)
walther@59871
   620
	       Rule.Thm ("realpow_minus_odd",ThmC.numerals_to_Free @{thm realpow_minus_odd}),
walther@60260
   621
	       (*"Not (n is_even) ==> (- r)  \<up>  n = -1 * r  \<up>  n"*)
neuper@37950
   622
	       
neuper@37950
   623
	       (*----- collect atoms over * -----*)
walther@59871
   624
	       Rule.Thm ("realpow_two_atom",ThmC.numerals_to_Free @{thm realpow_two_atom}),	
walther@60260
   625
	       (*"r is_atom ==> r * r = r  \<up>  2"*)
walther@59871
   626
	       Rule.Thm ("realpow_plus_1",ThmC.numerals_to_Free @{thm realpow_plus_1}),		
walther@60260
   627
	       (*"r is_atom ==> r * r  \<up>  n = r  \<up>  (n + 1)"*)
walther@59871
   628
	       Rule.Thm ("realpow_addI_atom",ThmC.numerals_to_Free @{thm realpow_addI_atom}),
walther@60260
   629
	       (*"r is_atom ==> r  \<up>  n * r  \<up>  m = r  \<up>  (n + m)"*)
neuper@37950
   630
neuper@37950
   631
	       (*----- distribute none-atoms -----*)
walther@59871
   632
	       Rule.Thm ("realpow_def_atom",ThmC.numerals_to_Free @{thm realpow_def_atom}),
walther@60276
   633
	       (*"[| 1 < n; ~ (r is_atom) |]==>r  \<up>  n = r * r  \<up>  (n + -1)"*)
walther@59871
   634
	       Rule.Thm ("realpow_eq_oneI",ThmC.numerals_to_Free @{thm realpow_eq_oneI}),
walther@60260
   635
	       (*"1  \<up>  n = 1"*)
walther@59878
   636
	       Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_")
neuper@37950
   637
	       ],
walther@59878
   638
      scr = Rule.Empty_Prog
wneuper@59406
   639
      });
neuper@37950
   640
(*.contains absolute minimum of thms for context in norm_Rational.*)
s1210629013@55444
   641
val rat_mult_divide = prep_rls'(
walther@59851
   642
  Rule_Def.Repeat {id = "rat_mult_divide", preconds = [], 
walther@59857
   643
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), 
walther@59852
   644
      erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
walther@59871
   645
      rules = [Rule.Thm ("rat_mult",ThmC.numerals_to_Free @{thm rat_mult}),
neuper@37950
   646
	       (*(1)"?a / ?b * (?c / ?d) = ?a * ?c / (?b * ?d)"*)
walther@59871
   647
	       Rule.Thm ("times_divide_eq_right",ThmC.numerals_to_Free @{thm times_divide_eq_right}),
neuper@37950
   648
	       (*(2)"?a * (?c / ?d) = ?a * ?c / ?d" must be [2],
neuper@37950
   649
	       otherwise inv.to a / b / c = ...*)
walther@59871
   650
	       Rule.Thm ("times_divide_eq_left",ThmC.numerals_to_Free @{thm times_divide_eq_left}),
walther@60260
   651
	       (*"?a / ?b * ?c = ?a * ?c / ?b" order weights x \<up> n too much
walther@60260
   652
		     and does not commute a / b * c  \<up>  2 !*)
neuper@37950
   653
	       
wneuper@59416
   654
	       Rule.Thm ("divide_divide_eq_right", 
walther@59871
   655
                     ThmC.numerals_to_Free @{thm divide_divide_eq_right}),
neuper@37950
   656
	       (*"?x / (?y / ?z) = ?x * ?z / ?y"*)
wneuper@59416
   657
	       Rule.Thm ("divide_divide_eq_left",
walther@59871
   658
                     ThmC.numerals_to_Free @{thm divide_divide_eq_left}),
neuper@37950
   659
	       (*"?x / ?y / ?z = ?x / (?y * ?z)"*)
walther@59878
   660
	       Rule.Eval ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e")
neuper@37950
   661
	       ],
walther@59878
   662
      scr = Rule.Empty_Prog
wneuper@59406
   663
      });
neuper@37979
   664
neuper@37950
   665
(*.contains absolute minimum of thms for context in norm_Rational.*)
s1210629013@55444
   666
val reduce_0_1_2 = prep_rls'(
walther@59857
   667
  Rule_Def.Repeat{id = "reduce_0_1_2", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   668
      erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
walther@59871
   669
      rules = [(*Rule.Thm ("divide_1",ThmC.numerals_to_Free @{thm divide_1}),
neuper@37950
   670
		 "?x / 1 = ?x" unnecess.for normalform*)
walther@59871
   671
	       Rule.Thm ("mult_1_left",ThmC.numerals_to_Free @{thm mult_1_left}),                 
neuper@37950
   672
	       (*"1 * z = z"*)
walther@59871
   673
	       (*Rule.Thm ("real_mult_minus1",ThmC.numerals_to_Free @{thm real_mult_minus1}),
neuper@37950
   674
	       "-1 * z = - z"*)
walther@59871
   675
	       (*Rule.Thm ("real_minus_mult_cancel",ThmC.numerals_to_Free @{thm real_minus_mult_cancel}),
neuper@37950
   676
	       "- ?x * - ?y = ?x * ?y"*)
neuper@37950
   677
walther@59871
   678
	       Rule.Thm ("mult_zero_left",ThmC.numerals_to_Free @{thm mult_zero_left}),        
neuper@37950
   679
	       (*"0 * z = 0"*)
walther@59871
   680
	       Rule.Thm ("add_0_left",ThmC.numerals_to_Free @{thm add_0_left}),
neuper@37950
   681
	       (*"0 + z = z"*)
walther@59871
   682
	       (*Rule.Thm ("right_minus",ThmC.numerals_to_Free @{thm right_minus}),
neuper@37950
   683
	       "?z + - ?z = 0"*)
neuper@37950
   684
wneuper@59416
   685
	       Rule.Thm ("sym_real_mult_2",
walther@59871
   686
                     ThmC.numerals_to_Free (@{thm real_mult_2} RS @{thm sym})),	
neuper@37950
   687
	       (*"z1 + z1 = 2 * z1"*)
walther@59871
   688
	       Rule.Thm ("real_mult_2_assoc",ThmC.numerals_to_Free @{thm real_mult_2_assoc}),
neuper@37950
   689
	       (*"z1 + (z1 + k) = 2 * z1 + k"*)
neuper@37950
   690
walther@59871
   691
	       Rule.Thm ("division_ring_divide_zero",ThmC.numerals_to_Free @{thm division_ring_divide_zero})
neuper@37950
   692
	       (*"0 / ?x = 0"*)
walther@59878
   693
	       ], scr = Rule.Empty_Prog});
neuper@37950
   694
neuper@37950
   695
(*erls for calculate_Rational; 
neuper@37950
   696
  make local with FIXX@ME result:term *term list WN0609???SKMG*)
s1210629013@55444
   697
val norm_rat_erls = prep_rls'(
walther@59857
   698
  Rule_Def.Repeat {id = "norm_rat_erls", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord), 
walther@59852
   699
      erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
walther@60278
   700
      rules = [Rule.Eval ("Prog_Expr.is_const", Prog_Expr.eval_const "#is_const_")
walther@59878
   701
	       ], scr = Rule.Empty_Prog});
neuper@37979
   702
neuper@52105
   703
(* consists of rls containing the absolute minimum of thms *)
neuper@37950
   704
(*040209: this version has been used by RL for his equations,
neuper@52105
   705
which is now replaced by MGs version "norm_Rational" below *)
s1210629013@55444
   706
val norm_Rational_min = prep_rls'(
walther@59857
   707
  Rule_Def.Repeat {id = "norm_Rational_min", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord), 
walther@59851
   708
      erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
neuper@37950
   709
      rules = [(*sequence given by operator precedence*)
wneuper@59416
   710
	       Rule.Rls_ discard_minus,
wneuper@59416
   711
	       Rule.Rls_ powers,
wneuper@59416
   712
	       Rule.Rls_ rat_mult_divide,
wneuper@59416
   713
	       Rule.Rls_ expand,
wneuper@59416
   714
	       Rule.Rls_ reduce_0_1_2,
wneuper@59416
   715
	       Rule.Rls_ order_add_mult,
wneuper@59416
   716
	       Rule.Rls_ collect_numerals,
wneuper@59416
   717
	       Rule.Rls_ add_fractions_p,
wneuper@59416
   718
	       Rule.Rls_ cancel_p
neuper@37950
   719
	       ],
walther@59878
   720
      scr = Rule.Empty_Prog});
neuper@37979
   721
s1210629013@55444
   722
val norm_Rational_parenthesized = prep_rls'(
walther@59878
   723
  Rule_Set.Sequence {id = "norm_Rational_parenthesized", preconds = []:term list, 
walther@59857
   724
       rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59851
   725
      erls = Atools_erls, srls = Rule_Set.Empty,
neuper@42451
   726
      calc = [], errpatts = [],
wneuper@59416
   727
      rules = [Rule.Rls_  norm_Rational_min,
wneuper@59416
   728
	       Rule.Rls_ discard_parentheses
neuper@37950
   729
	       ],
walther@59878
   730
      scr = Rule.Empty_Prog});      
neuper@37950
   731
neuper@37950
   732
(*WN030318???SK: simplifies all but cancel and common_nominator*)
neuper@37950
   733
val simplify_rational = 
walther@59852
   734
    Rule_Set.merge "simplify_rational" expand_binoms
walther@59852
   735
    (Rule_Set.append_rules "divide" calculate_Rational
walther@59871
   736
		[Rule.Thm ("div_by_1",ThmC.numerals_to_Free @{thm div_by_1}),
neuper@37950
   737
		 (*"?x / 1 = ?x"*)
walther@59871
   738
		 Rule.Thm ("rat_mult",ThmC.numerals_to_Free @{thm rat_mult}),
neuper@37950
   739
		 (*(1)"?a / ?b * (?c / ?d) = ?a * ?c / (?b * ?d)"*)
walther@59871
   740
		 Rule.Thm ("times_divide_eq_right",ThmC.numerals_to_Free @{thm times_divide_eq_right}),
neuper@37950
   741
		 (*(2)"?a * (?c / ?d) = ?a * ?c / ?d" must be [2],
neuper@37950
   742
		 otherwise inv.to a / b / c = ...*)
walther@59871
   743
		 Rule.Thm ("times_divide_eq_left",ThmC.numerals_to_Free @{thm times_divide_eq_left}),
neuper@37950
   744
		 (*"?a / ?b * ?c = ?a * ?c / ?b"*)
walther@59871
   745
		 Rule.Thm ("add_minus",ThmC.numerals_to_Free @{thm add_minus}),
neuper@37950
   746
		 (*"?a + ?b - ?b = ?a"*)
walther@59871
   747
		 Rule.Thm ("add_minus1",ThmC.numerals_to_Free @{thm add_minus1}),
neuper@37950
   748
		 (*"?a - ?b + ?b = ?a"*)
walther@59871
   749
		 Rule.Thm ("divide_minus1",ThmC.numerals_to_Free @{thm divide_minus1})
neuper@37950
   750
		 (*"?x / -1 = - ?x"*)
neuper@37950
   751
		 ]);
wneuper@59472
   752
\<close>
wneuper@59472
   753
ML \<open>
s1210629013@55444
   754
val add_fractions_p_rls = prep_rls'(
walther@59857
   755
  Rule_Def.Repeat {id = "add_fractions_p_rls", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), 
walther@59852
   756
	  erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
wneuper@59416
   757
	  rules = [Rule.Rls_ add_fractions_p], 
walther@59878
   758
	  scr = Rule.Empty_Prog});
neuper@37950
   759
walther@59851
   760
(* "Rule_Def.Repeat" causes repeated application of cancel_p to one and the same term *)
s1210629013@55444
   761
val cancel_p_rls = prep_rls'(
walther@59851
   762
  Rule_Def.Repeat 
walther@59857
   763
    {id = "cancel_p_rls", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), 
walther@59852
   764
    erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
wneuper@59416
   765
    rules = [Rule.Rls_ cancel_p], 
walther@59878
   766
	  scr = Rule.Empty_Prog});
neuper@52105
   767
neuper@37950
   768
(*. makes 'normal' fractions; 'is_polyexp' inhibits double fractions;
neuper@37950
   769
    used in initial part norm_Rational_mg, see example DA-M02-main.p.60.*)
s1210629013@55444
   770
val rat_mult_poly = prep_rls'(
walther@59857
   771
  Rule_Def.Repeat {id = "rat_mult_poly", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), 
walther@60278
   772
	  erls = Rule_Set.append_rules "Rule_Set.empty-is_polyexp" Rule_Set.empty [Rule.Eval ("Poly.is_polyexp", eval_is_polyexp "")], 
walther@59851
   773
	  srls = Rule_Set.Empty, calc = [], errpatts = [],
neuper@52105
   774
	  rules = 
walther@59871
   775
	    [Rule.Thm ("rat_mult_poly_l",ThmC.numerals_to_Free @{thm rat_mult_poly_l}),
neuper@52105
   776
	    (*"?c is_polyexp ==> ?c * (?a / ?b) = ?c * ?a / ?b"*)
walther@59871
   777
	    Rule.Thm ("rat_mult_poly_r",ThmC.numerals_to_Free @{thm rat_mult_poly_r})
neuper@52105
   778
	    (*"?c is_polyexp ==> ?a / ?b * ?c = ?a * ?c / ?b"*) ], 
walther@59878
   779
	  scr = Rule.Empty_Prog});
neuper@37979
   780
neuper@37950
   781
(*. makes 'normal' fractions; 'is_polyexp' inhibits double fractions;
neuper@37950
   782
    used in looping part norm_Rational_rls, see example DA-M02-main.p.60 
walther@59852
   783
    .. WHERE THE LATTER DOES ALWAYS WORK, BECAUSE erls = Rule_Set.empty, 
wneuper@59416
   784
    I.E. THE RESPECTIVE ASSUMPTION IS STORED AND Rule.Thm APPLIED; WN051028 
neuper@37950
   785
    ... WN0609???MG.*)
s1210629013@55444
   786
val rat_mult_div_pow = prep_rls'(
walther@59857
   787
  Rule_Def.Repeat {id = "rat_mult_div_pow", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord), 
walther@59852
   788
    erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
walther@59871
   789
    rules = [Rule.Thm ("rat_mult", ThmC.numerals_to_Free @{thm rat_mult}),
neuper@52105
   790
      (*"?a / ?b * (?c / ?d) = ?a * ?c / (?b * ?d)"*)
walther@59871
   791
      Rule.Thm ("rat_mult_poly_l", ThmC.numerals_to_Free @{thm rat_mult_poly_l}),
neuper@52105
   792
      (*"?c is_polyexp ==> ?c * (?a / ?b) = ?c * ?a / ?b"*)
walther@59871
   793
      Rule.Thm ("rat_mult_poly_r", ThmC.numerals_to_Free @{thm rat_mult_poly_r}),
neuper@52105
   794
      (*"?c is_polyexp ==> ?a / ?b * ?c = ?a * ?c / ?b"*)
neuper@52105
   795
      
walther@59871
   796
      Rule.Thm ("real_divide_divide1_mg", ThmC.numerals_to_Free @{thm real_divide_divide1_mg}),
neuper@52105
   797
      (*"y ~= 0 ==> (u / v) / (y / z) = (u * z) / (y * v)"*)
walther@59871
   798
      Rule.Thm ("divide_divide_eq_right", ThmC.numerals_to_Free @{thm divide_divide_eq_right}),
neuper@52105
   799
      (*"?x / (?y / ?z) = ?x * ?z / ?y"*)
walther@59871
   800
      Rule.Thm ("divide_divide_eq_left", ThmC.numerals_to_Free @{thm divide_divide_eq_left}),
neuper@52105
   801
      (*"?x / ?y / ?z = ?x / (?y * ?z)"*)
walther@59878
   802
      Rule.Eval ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e"),
neuper@52105
   803
      
walther@59871
   804
      Rule.Thm ("rat_power", ThmC.numerals_to_Free @{thm rat_power})
walther@60260
   805
      (*"(?a / ?b)  \<up>  ?n = ?a  \<up>  ?n / ?b  \<up>  ?n"*)
neuper@52105
   806
      ],
walther@59878
   807
    scr = Rule.Empty_Prog});
neuper@37950
   808
s1210629013@55444
   809
val rat_reduce_1 = prep_rls'(
walther@59857
   810
  Rule_Def.Repeat {id = "rat_reduce_1", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), 
walther@59852
   811
    erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [], 
neuper@52105
   812
    rules = 
walther@59871
   813
      [Rule.Thm ("div_by_1", ThmC.numerals_to_Free @{thm div_by_1}),
neuper@52105
   814
      (*"?x / 1 = ?x"*)
walther@59871
   815
      Rule.Thm ("mult_1_left", ThmC.numerals_to_Free @{thm mult_1_left})           
neuper@52105
   816
      (*"1 * z = z"*)
neuper@52105
   817
      ],
walther@59878
   818
    scr = Rule.Empty_Prog});
neuper@52105
   819
neuper@52105
   820
(* looping part of norm_Rational *)
s1210629013@55444
   821
val norm_Rational_rls = prep_rls' (
walther@59857
   822
  Rule_Def.Repeat {id = "norm_Rational_rls", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord), 
walther@59851
   823
    erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
wneuper@59416
   824
    rules = [Rule.Rls_ add_fractions_p_rls,
wneuper@59416
   825
      Rule.Rls_ rat_mult_div_pow,
wneuper@59416
   826
      Rule.Rls_ make_rat_poly_with_parentheses,
wneuper@59416
   827
      Rule.Rls_ cancel_p_rls,
wneuper@59416
   828
      Rule.Rls_ rat_reduce_1
neuper@52105
   829
      ],
walther@59878
   830
    scr = Rule.Empty_Prog});
neuper@52105
   831
s1210629013@55444
   832
val norm_Rational = prep_rls' (
walther@59878
   833
  Rule_Set.Sequence 
walther@59857
   834
    {id = "norm_Rational", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), 
walther@59851
   835
    erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
wneuper@59416
   836
    rules = [Rule.Rls_ discard_minus,
wneuper@59416
   837
      Rule.Rls_ rat_mult_poly,             (* removes double fractions like a/b/c *)
wneuper@59416
   838
      Rule.Rls_ make_rat_poly_with_parentheses,
wneuper@59416
   839
      Rule.Rls_ cancel_p_rls,
wneuper@59416
   840
      Rule.Rls_ norm_Rational_rls,         (* the main rls, looping (#) *)
wneuper@59416
   841
      Rule.Rls_ discard_parentheses1       (* mult only *)
neuper@52100
   842
      ],
walther@59878
   843
    scr = Rule.Empty_Prog});
wneuper@59472
   844
\<close>
neuper@52125
   845
wneuper@59472
   846
setup \<open>KEStore_Elems.add_rlss 
neuper@52125
   847
  [("calculate_Rational", (Context.theory_name @{theory}, calculate_Rational)), 
neuper@52125
   848
  ("calc_rat_erls", (Context.theory_name @{theory}, calc_rat_erls)), 
neuper@52125
   849
  ("rational_erls", (Context.theory_name @{theory}, rational_erls)), 
neuper@52125
   850
  ("cancel_p", (Context.theory_name @{theory}, cancel_p)), 
neuper@52125
   851
  ("add_fractions_p", (Context.theory_name @{theory}, add_fractions_p)),
neuper@52125
   852
 
neuper@52125
   853
  ("add_fractions_p_rls", (Context.theory_name @{theory}, add_fractions_p_rls)), 
neuper@52125
   854
  ("powers_erls", (Context.theory_name @{theory}, powers_erls)), 
neuper@52125
   855
  ("powers", (Context.theory_name @{theory}, powers)), 
neuper@52125
   856
  ("rat_mult_divide", (Context.theory_name @{theory}, rat_mult_divide)), 
neuper@52125
   857
  ("reduce_0_1_2", (Context.theory_name @{theory}, reduce_0_1_2)),
neuper@52125
   858
 
neuper@52125
   859
  ("rat_reduce_1", (Context.theory_name @{theory}, rat_reduce_1)), 
neuper@52125
   860
  ("norm_rat_erls", (Context.theory_name @{theory}, norm_rat_erls)), 
neuper@52125
   861
  ("norm_Rational", (Context.theory_name @{theory}, norm_Rational)), 
neuper@52125
   862
  ("norm_Rational_rls", (Context.theory_name @{theory}, norm_Rational_rls)), 
neuper@55493
   863
  ("norm_Rational_min", (Context.theory_name @{theory}, norm_Rational_min)),
neuper@52125
   864
  ("norm_Rational_parenthesized", (Context.theory_name @{theory}, norm_Rational_parenthesized)),
neuper@52125
   865
 
neuper@52125
   866
  ("rat_mult_poly", (Context.theory_name @{theory}, rat_mult_poly)), 
neuper@52125
   867
  ("rat_mult_div_pow", (Context.theory_name @{theory}, rat_mult_div_pow)), 
wneuper@59472
   868
  ("cancel_p_rls", (Context.theory_name @{theory}, cancel_p_rls))]\<close>
neuper@37950
   869
wneuper@59472
   870
section \<open>A problem for simplification of rationals\<close>
wneuper@59472
   871
setup \<open>KEStore_Elems.add_pbts
walther@59973
   872
  [(Problem.prep_input thy "pbl_simp_rat" [] Problem.id_empty
walther@59997
   873
      (["rational", "simplification"],
s1210629013@55339
   874
        [("#Given" ,["Term t_t"]),
s1210629013@55339
   875
          ("#Where" ,["t_t is_ratpolyexp"]),
s1210629013@55339
   876
          ("#Find"  ,["normalform n_n"])],
walther@59852
   877
        Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)], 
walther@59997
   878
        SOME "Simplify t_t", [["simplification", "of_rationals"]]))]\<close>
neuper@37950
   879
wneuper@59472
   880
section \<open>A methods for simplification of rationals\<close>
s1210629013@55373
   881
(*WN061025 this methods script is copied from (auto-generated) script
s1210629013@55373
   882
  of norm_Rational in order to ease repair on inform*)
wneuper@59545
   883
wneuper@59504
   884
partial_function (tailrec) simplify :: "real \<Rightarrow> real"
wneuper@59504
   885
  where
walther@59716
   886
"simplify term = (
walther@59637
   887
  (Try (Rewrite_Set ''discard_minus'') #>
walther@59637
   888
   Try (Rewrite_Set ''rat_mult_poly'') #>
walther@59637
   889
   Try (Rewrite_Set ''make_rat_poly_with_parentheses'') #>
walther@59637
   890
   Try (Rewrite_Set ''cancel_p_rls'') #>
walther@59635
   891
   (Repeat (
walther@59637
   892
     Try (Rewrite_Set ''add_fractions_p_rls'') #>
walther@59637
   893
     Try (Rewrite_Set ''rat_mult_div_pow'') #>
walther@59637
   894
     Try (Rewrite_Set ''make_rat_poly_with_parentheses'') #>
walther@59637
   895
     Try (Rewrite_Set ''cancel_p_rls'') #>
walther@59637
   896
     Try (Rewrite_Set ''rat_reduce_1''))) #>
walther@59635
   897
   Try (Rewrite_Set ''discard_parentheses1''))
walther@59716
   898
   term)"
wneuper@59472
   899
setup \<open>KEStore_Elems.add_mets
walther@60154
   900
    [MethodC.prep_input thy "met_simp_rat" [] MethodC.id_empty
walther@59997
   901
      (["simplification", "of_rationals"],
s1210629013@55373
   902
        [("#Given" ,["Term t_t"]),
s1210629013@55373
   903
          ("#Where" ,["t_t is_ratpolyexp"]),
s1210629013@55373
   904
          ("#Find"  ,["normalform n_n"])],
walther@59852
   905
	      {rew_ord'="tless_true", rls' = Rule_Set.empty, calc = [], srls = Rule_Set.empty, 
walther@59852
   906
	        prls = Rule_Set.append_rules "simplification_of_rationals_prls" Rule_Set.empty 
walther@60278
   907
				    [(*for preds in where_*) Rule.Eval ("Rational.is_ratpolyexp", eval_is_ratpolyexp "")],
walther@59852
   908
				  crls = Rule_Set.empty, errpats = [], nrls = norm_Rational_rls},
wneuper@59551
   909
				  @{thm simplify.simps})]
walther@60278
   910
\<close> ML \<open>
walther@60278
   911
\<close> ML \<open>
wneuper@59472
   912
\<close>
neuper@52105
   913
end