clarified theory context: avoid global "val thy = ..." hanging around (left-over from Isabelle2005), which is apt to various pitfalls;
1 (* rationals, fractions of multivariate polynomials over the real field
3 Copyright (c) isac team 2002, 2013
4 Use is subject to license terms.
6 depends on Poly (and not on Atools), because
7 fractions with _normalised_ polynomials are canceled, added, etc.
11 imports Poly GCD_Poly_ML
14 section \<open>Constants for evaluation by "Rule.Eval"\<close>
17 is_expanded :: "real => bool" ("_ is'_expanded") (*RL->Poly.thy*)
18 is_ratpolyexp :: "real => bool" ("_ is'_ratpolyexp")
19 get_denominator :: "real => real"
20 get_numerator :: "real => real"
23 (*.the expression contains + - * ^ / only ?.*)
24 fun is_ratpolyexp (Free _) = true
25 | is_ratpolyexp (Const ("Groups.plus_class.plus",_) $ Free _ $ Free _) = true
26 | is_ratpolyexp (Const ("Groups.minus_class.minus",_) $ Free _ $ Free _) = true
27 | is_ratpolyexp (Const ("Groups.times_class.times",_) $ Free _ $ Free _) = true
28 | is_ratpolyexp (Const ("Transcendental.powr",_) $ Free _ $ Free _) = true
29 | is_ratpolyexp (Const ("Rings.divide_class.divide",_) $ Free _ $ Free _) = true
30 | is_ratpolyexp (Const ("Groups.plus_class.plus",_) $ t1 $ t2) =
31 ((is_ratpolyexp t1) andalso (is_ratpolyexp t2))
32 | is_ratpolyexp (Const ("Groups.minus_class.minus",_) $ t1 $ t2) =
33 ((is_ratpolyexp t1) andalso (is_ratpolyexp t2))
34 | is_ratpolyexp (Const ("Groups.times_class.times",_) $ t1 $ t2) =
35 ((is_ratpolyexp t1) andalso (is_ratpolyexp t2))
36 | is_ratpolyexp (Const ("Transcendental.powr",_) $ t1 $ t2) =
37 ((is_ratpolyexp t1) andalso (is_ratpolyexp t2))
38 | is_ratpolyexp (Const ("Rings.divide_class.divide",_) $ t1 $ t2) =
39 ((is_ratpolyexp t1) andalso (is_ratpolyexp t2))
40 | is_ratpolyexp _ = false;
42 (*("is_ratpolyexp", ("Rational.is_ratpolyexp", eval_is_ratpolyexp ""))*)
43 fun eval_is_ratpolyexp (thmid:string) _
44 (t as (Const("Rational.is_ratpolyexp", _) $ arg)) thy =
46 then SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "",
47 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
48 else SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "",
49 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
50 | eval_is_ratpolyexp _ _ _ _ = NONE;
52 (*("get_denominator", ("Rational.get_denominator", eval_get_denominator ""))*)
53 fun eval_get_denominator (thmid:string) _
54 (t as Const ("Rational.get_denominator", _) $
55 (Const ("Rings.divide_class.divide", _) $ _(*num*) $
57 SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy denom) "",
58 HOLogic.Trueprop $ (TermC.mk_equality (t, denom)))
59 | eval_get_denominator _ _ _ _ = NONE;
61 (*("get_numerator", ("Rational.get_numerator", eval_get_numerator ""))*)
62 fun eval_get_numerator (thmid:string) _
63 (t as Const ("Rational.get_numerator", _) $
64 (Const ("Rings.divide_class.divide", _) $num
66 SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy num) "",
67 HOLogic.Trueprop $ (TermC.mk_equality (t, num)))
68 | eval_get_numerator _ _ _ _ = NONE;
71 section \<open>Theorems for rewriting\<close>
73 axiomatization (* naming due to Isabelle2002, but not contained in Isabelle2002;
74 many thms are due to RL and can be removed with updating the equation solver;
75 TODO: replace by equivalent thms in recent Isabelle201x *)
77 mult_cross: "[| b ~= 0; d ~= 0 |] ==> (a / b = c / d) = (a * d = b * c)" and
78 mult_cross1: " b ~= 0 ==> (a / b = c ) = (a = b * c)" and
79 mult_cross2: " d ~= 0 ==> (a = c / d) = (a * d = c)" and
81 add_minus: "a + b - b = a"(*RL->Poly.thy*) and
82 add_minus1: "a - b + b = a"(*RL->Poly.thy*) and
84 rat_mult: "a / b * (c / d) = a * c / (b * d)"(*?Isa02*) and
85 rat_mult2: "a / b * c = a * c / b "(*?Isa02*) and
87 rat_mult_poly_l: "c is_polyexp ==> c * (a / b) = c * a / b" and
88 rat_mult_poly_r: "c is_polyexp ==> (a / b) * c = a * c / b" and
90 (*real_times_divide1_eq .. Isa02*)
91 real_times_divide_1_eq: "-1 * (c / d) = -1 * c / d " and
92 real_times_divide_num: "a is_const ==> a * (c / d) = a * c / d " and
94 real_mult_div_cancel2: "k ~= 0 ==> m * k / (n * k) = m / n" and
95 (*real_mult_div_cancel1: "k ~= 0 ==> k * m / (k * n) = m / n"..Isa02*)
97 real_divide_divide1: "y ~= 0 ==> (u / v) / (y / z) = (u / v) * (z / y)" and
98 real_divide_divide1_mg: "y ~= 0 ==> (u / v) / (y / z) = (u * z) / (y * v)" and
99 (*real_divide_divide2_eq: "x / y / z = x / (y * z)"..Isa02*)
101 rat_power: "(a / b) \<up> n = (a \<up> n) / (b \<up> n)" and
103 rat_add: "[| a is_const; b is_const; c is_const; d is_const |] ==>
104 a / c + b / d = (a * d + b * c) / (c * d)" and
105 rat_add_assoc: "[| a is_const; b is_const; c is_const; d is_const |] ==>
106 a / c +(b / d + e) = (a * d + b * c)/(d * c) + e" and
107 rat_add1: "[| a is_const; b is_const; c is_const |] ==>
108 a / c + b / c = (a + b) / c" and
109 rat_add1_assoc: "[| a is_const; b is_const; c is_const |] ==>
110 a / c + (b / c + e) = (a + b) / c + e" and
111 rat_add2: "[| a is_const; b is_const; c is_const |] ==>
112 a / c + b = (a + b * c) / c" and
113 rat_add2_assoc: "[| a is_const; b is_const; c is_const |] ==>
114 a / c + (b + e) = (a + b * c) / c + e" and
115 rat_add3: "[| a is_const; b is_const; c is_const |] ==>
116 a + b / c = (a * c + b) / c" and
117 rat_add3_assoc: "[| a is_const; b is_const; c is_const |] ==>
118 a + (b / c + e) = (a * c + b) / c + e"
120 section \<open>Cancellation and addition of fractions\<close>
121 subsection \<open>Conversion term <--> poly\<close>
122 subsubsection \<open>Convert a term to the internal representation of a multivariate polynomial\<close>
124 fun monom_of_term vs (c, es) (t as Const _) =
125 (c, list_update es (find_index (curry op = t) vs) 1)
126 | monom_of_term vs (c, es) (t as Free (id, _)) =
128 then (id |> TermC.int_opt_of_string |> the |> curry op * c, es) (*several numerals in one monom*)
129 else (c, list_update es (find_index (curry op = t) vs) 1)
130 | monom_of_term vs (c, es) (Const ("Transcendental.powr", _) $ (t as Free _) $ Free (e, _)) =
131 (c, list_update es (find_index (curry op = t) vs) (the (TermC.int_opt_of_string e)))
132 | monom_of_term vs (c, es) (Const ("Groups.times_class.times", _) $ m1 $ m2) =
133 let val (c', es') = monom_of_term vs (c, es) m1
134 in monom_of_term vs (c', es') m2 end
135 | monom_of_term _ _ t = raise ERROR ("poly malformed 1 with " ^ UnparseC.term t)
137 fun monoms_of_term vs (t as Const _) =
138 [monom_of_term vs (1, replicate (length vs) 0) t]
139 | monoms_of_term vs (t as Free _) =
140 [monom_of_term vs (1, replicate (length vs) 0) t]
141 | monoms_of_term vs (t as Const ("Transcendental.powr", _) $ _ $ _) =
142 [monom_of_term vs (1, replicate (length vs) 0) t]
143 | monoms_of_term vs (t as Const ("Groups.times_class.times", _) $ _ $ _) =
144 [monom_of_term vs (1, replicate (length vs) 0) t]
145 | monoms_of_term vs (Const ("Groups.plus_class.plus", _) $ ms1 $ ms2) =
146 (monoms_of_term vs ms1) @ (monoms_of_term vs ms2)
147 | monoms_of_term _ t = raise ERROR ("poly malformed 2 with " ^ UnparseC.term t)
149 (* convert a term to the internal representation of a multivariate polynomial;
150 the conversion is quite liberal, see test --- fun poly_of_term ---:
151 * the order of variables and the parentheses within a monomial are arbitrary
152 * the coefficient may be somewhere
153 * he order and the parentheses within monomials are arbitrary
154 But the term must be completely expand + over * (laws of distributivity are not applicable).
156 The function requires the free variables as strings already given,
157 because the gcd involves 2 polynomials (with the same length for their list of exponents).
159 fun poly_of_term vs (t as Const ("Groups.plus_class.plus", _) $ _ $ _) =
160 (SOME (t |> monoms_of_term vs |> order)
161 handle ERROR _ => NONE)
162 | poly_of_term vs t =
163 (SOME [monom_of_term vs (1, replicate (length vs) 0) t]
164 handle ERROR _ => NONE)
168 val vs = TermC.vars_of t
170 case poly_of_term vs t of SOME _ => true | NONE => false
172 val is_expanded = is_poly (* TODO: check names *)
173 val is_polynomial = is_poly (* TODO: check names *)
176 subsubsection \<open>Convert internal representation of a multivariate polynomial to a term\<close>
178 fun term_of_es _ _ _ [] = [] (*assumes same length for vs and es*)
179 | term_of_es baseT expT (_ :: vs) (0 :: es) = [] @ term_of_es baseT expT vs es
180 | term_of_es baseT expT (v :: vs) (1 :: es) = v :: term_of_es baseT expT vs es
181 | term_of_es baseT expT (v :: vs) (e :: es) =
182 Const ("Transcendental.powr", [baseT, expT] ---> baseT) $ v $ (Free (TermC.isastr_of_int e, expT))
183 :: term_of_es baseT expT vs es
184 | term_of_es _ _ _ _ = raise ERROR "term_of_es: length vs <> length es"
186 fun term_of_monom baseT expT vs ((c, es): monom) =
187 let val es' = term_of_es baseT expT vs es
191 if es' = [] (*if es = [0,0,0,...]*)
192 then Free (TermC.isastr_of_int c, baseT)
193 else foldl (HOLogic.mk_binop "Groups.times_class.times") (hd es', tl es')
194 else foldl (HOLogic.mk_binop "Groups.times_class.times") (Free (TermC.isastr_of_int c, baseT), es')
197 fun term_of_poly baseT expT vs p =
198 let val monos = map (term_of_monom baseT expT vs) p
199 in foldl (HOLogic.mk_binop "Groups.plus_class.plus") (hd monos, tl monos) end
202 subsection \<open>Apply gcd_poly for cancelling and adding fractions as terms\<close>
204 fun mk_noteq_0 baseT t =
205 Const ("HOL.Not", HOLogic.boolT --> HOLogic.boolT) $
206 (Const ("HOL.eq", [baseT, baseT] ---> HOLogic.boolT) $ t $ Free ("0", HOLogic.realT))
208 fun mk_asms baseT ts =
209 let val as' = filter_out TermC.is_num ts (* asm like "2 ~= 0" is needless *)
210 in map (mk_noteq_0 baseT) as' end
213 subsubsection \<open>Factor out gcd for cancellation\<close>
215 fun check_fraction t =
217 Const ("Rings.divide_class.divide", _) $ numerator $ denominator
218 => SOME (numerator, denominator)
221 (* prepare a term for cancellation by factoring out the gcd
222 assumes: is a fraction with outmost "/"*)
223 fun factout_p_ (thy: theory) t =
224 let val opt = check_fraction t
228 | SOME (numerator, denominator) =>
230 val vs = TermC.vars_of t
231 val baseT = type_of numerator
232 val expT = HOLogic.realT
234 case (poly_of_term vs numerator, poly_of_term vs denominator) of
237 val ((a', b'), c) = gcd_poly a b
238 val es = replicate (length vs) 0
240 if c = [(1, es)] orelse c = [(~1, es)]
244 val b't = term_of_poly baseT expT vs b'
245 val ct = term_of_poly baseT expT vs c
247 HOLogic.mk_binop "Rings.divide_class.divide"
248 (HOLogic.mk_binop "Groups.times_class.times"
249 (term_of_poly baseT expT vs a', ct),
250 HOLogic.mk_binop "Groups.times_class.times" (b't, ct))
251 in SOME (t', mk_asms baseT [b't, ct]) end
253 | _ => NONE : (term * term list) option
258 subsubsection \<open>Cancel a fraction\<close>
260 (* cancel a term by the gcd ("" denote terms with internal algebraic structure)
261 cancel_p_ :: theory \<Rightarrow> term \<Rightarrow> (term \<times> term list) option
262 cancel_p_ thy "a / b" = SOME ("a' / b'", ["b' \<noteq> 0"])
263 assumes: a is_polynomial \<and> b is_polynomial \<and> b \<noteq> 0
265 SOME ("a' / b'", ["b' \<noteq> 0"]). gcd_poly a b \<noteq> 1 \<and> gcd_poly a b \<noteq> -1 \<and>
266 a' * gcd_poly a b = a \<and> b' * gcd_poly a b = b
268 fun cancel_p_ (_: theory) t =
269 let val opt = check_fraction t
273 | SOME (numerator, denominator) =>
275 val vs = TermC.vars_of t
276 val baseT = type_of numerator
277 val expT = HOLogic.realT
279 case (poly_of_term vs numerator, poly_of_term vs denominator) of
282 val ((a', b'), c) = gcd_poly a b
283 val es = replicate (length vs) 0
285 if c = [(1, es)] orelse c = [(~1, es)]
289 val bt' = term_of_poly baseT expT vs b'
290 val ct = term_of_poly baseT expT vs c
292 HOLogic.mk_binop "Rings.divide_class.divide"
293 (term_of_poly baseT expT vs a', bt')
294 val asm = mk_asms baseT [bt']
295 in SOME (t', asm) end
297 | _ => NONE : (term * term list) option
302 subsubsection \<open>Factor out to a common denominator for addition\<close>
304 (* addition of fractions allows (at most) one non-fraction (a monomial) *)
306 (Const ("Groups.plus_class.plus", _) $
307 (Const ("Rings.divide_class.divide", _) $ n1 $ d1) $
308 (Const ("Rings.divide_class.divide", _) $ n2 $ d2))
309 = SOME ((n1, d1), (n2, d2))
311 (Const ("Groups.plus_class.plus", _) $
313 (Const ("Rings.divide_class.divide", _) $ n2 $ d2))
314 = SOME ((nofrac, Free ("1", HOLogic.realT)), (n2, d2))
316 (Const ("Groups.plus_class.plus", _) $
317 (Const ("Rings.divide_class.divide", _) $ n1 $ d1) $
319 = SOME ((n1, d1), (nofrac, Free ("1", HOLogic.realT)))
320 | check_frac_sum _ = NONE
322 (* prepare a term for addition by providing the least common denominator as a product
323 assumes: is a term with outmost "+" and at least one outmost "/" in respective summands*)
324 fun common_nominator_p_ (_: theory) t =
325 let val opt = check_frac_sum t
329 | SOME ((n1, d1), (n2, d2)) =>
331 val vs = TermC.vars_of t
333 case (poly_of_term vs d1, poly_of_term vs d2) of
336 val ((a', b'), c) = gcd_poly a b
337 val (baseT, expT) = (type_of n1, HOLogic.realT)
338 val [d1', d2', c'] = map (term_of_poly baseT expT vs) [a', b', c]
339 (*----- minimum of parentheses & nice result, but breaks tests: -------------
340 val denom = HOLogic.mk_binop "Groups.times_class.times"
341 (HOLogic.mk_binop "Groups.times_class.times" (d1', d2'), c') -------------*)
343 if c = [(1, replicate (length vs) 0)]
344 then HOLogic.mk_binop "Groups.times_class.times" (d1', d2')
346 HOLogic.mk_binop "Groups.times_class.times" (c',
347 HOLogic.mk_binop "Groups.times_class.times" (d1', d2')) (*--------------*)
349 HOLogic.mk_binop "Groups.plus_class.plus"
350 (HOLogic.mk_binop "Rings.divide_class.divide"
351 (HOLogic.mk_binop "Groups.times_class.times" (n1, d2'), denom),
352 HOLogic.mk_binop "Rings.divide_class.divide"
353 (HOLogic.mk_binop "Groups.times_class.times" (n2, d1'), denom))
354 val asm = mk_asms baseT [d1', d2', c']
355 in SOME (t', asm) end
356 | _ => NONE : (term * term list) option
361 subsubsection \<open>Addition of at least one fraction within a sum\<close>
364 assumes: is a term with outmost "+" and at least one outmost "/" in respective summands
365 NOTE: the case "(_ + _) + _" need not be considered due to iterated addition.*)
366 fun add_fraction_p_ (_: theory) t =
367 case check_frac_sum t of
369 | SOME ((n1, d1), (n2, d2)) =>
371 val vs = TermC.vars_of t
373 case (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) of
374 (SOME _, SOME a, SOME _, SOME b) =>
376 val ((a', b'), c) = gcd_poly a b
377 val (baseT, expT) = (type_of n1, HOLogic.realT)
378 val nomin = term_of_poly baseT expT vs
379 (((the (poly_of_term vs n1)) %%*%% b') %%+%% ((the (poly_of_term vs n2)) %%*%% a'))
380 val denom = term_of_poly baseT expT vs ((c %%*%% a') %%*%% b')
381 val t' = HOLogic.mk_binop "Rings.divide_class.divide" (nomin, denom)
382 in SOME (t', mk_asms baseT [denom]) end
383 | _ => NONE : (term * term list) option
387 section \<open>Embed cancellation and addition into rewriting\<close>
389 subsection \<open>Rulesets and predicate for embedding\<close>
391 (* evaluates conditions in calculate_Rational *)
394 (Rule_Def.Repeat {id = "calc_rat_erls", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
395 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
397 [Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
398 Rule.Eval ("Prog_Expr.is_const", Prog_Expr.eval_const "#is_const_"),
399 Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
400 Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false})],
401 scr = Rule.Empty_Prog});
403 (* simplifies expressions with numerals;
404 does NOT rearrange the term by AC-rewriting; thus terms with variables
405 need to have constants to be commuted together respectively *)
406 val calculate_Rational =
407 prep_rls' (Rule_Set.merge "calculate_Rational"
408 (Rule_Def.Repeat {id = "divide", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
409 erls = calc_rat_erls, srls = Rule_Set.Empty,
410 calc = [], errpatts = [],
412 [Rule.Eval ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e"),
414 Rule.Thm ("minus_divide_left", ThmC.numerals_to_Free (@{thm minus_divide_left} RS @{thm sym})),
415 (*SYM - ?x / ?y = - (?x / ?y) may come from subst*)
416 Rule.Thm ("rat_add", ThmC.numerals_to_Free @{thm rat_add}),
417 (*"[| a is_const; b is_const; c is_const; d is_const |] ==> \
418 \a / c + b / d = (a * d) / (c * d) + (b * c ) / (d * c)"*)
419 Rule.Thm ("rat_add1", ThmC.numerals_to_Free @{thm rat_add1}),
420 (*"[| a is_const; b is_const; c is_const |] ==> a / c + b / c = (a + b) / c"*)
421 Rule.Thm ("rat_add2", ThmC.numerals_to_Free @{thm rat_add2}),
422 (*"[| ?a is_const; ?b is_const; ?c is_const |] ==> ?a / ?c + ?b = (?a + ?b * ?c) / ?c"*)
423 Rule.Thm ("rat_add3", ThmC.numerals_to_Free @{thm rat_add3}),
424 (*"[| a is_const; b is_const; c is_const |] ==> a + b / c = (a * c) / c + b / c"\
425 .... is_const to be omitted here FIXME*)
427 Rule.Thm ("rat_mult", ThmC.numerals_to_Free @{thm rat_mult}),
428 (*a / b * (c / d) = a * c / (b * d)*)
429 Rule.Thm ("times_divide_eq_right", ThmC.numerals_to_Free @{thm times_divide_eq_right}),
430 (*?x * (?y / ?z) = ?x * ?y / ?z*)
431 Rule.Thm ("times_divide_eq_left", ThmC.numerals_to_Free @{thm times_divide_eq_left}),
432 (*?y / ?z * ?x = ?y * ?x / ?z*)
434 Rule.Thm ("real_divide_divide1", ThmC.numerals_to_Free @{thm real_divide_divide1}),
435 (*"?y ~= 0 ==> ?u / ?v / (?y / ?z) = ?u / ?v * (?z / ?y)"*)
436 Rule.Thm ("divide_divide_eq_left", ThmC.numerals_to_Free @{thm divide_divide_eq_left}),
437 (*"?x / ?y / ?z = ?x / (?y * ?z)"*)
439 Rule.Thm ("rat_power", ThmC.numerals_to_Free @{thm rat_power}),
440 (*"(?a / ?b) \<up> ?n = ?a \<up> ?n / ?b \<up> ?n"*)
442 Rule.Thm ("mult_cross", ThmC.numerals_to_Free @{thm mult_cross}),
443 (*"[| b ~= 0; d ~= 0 |] ==> (a / b = c / d) = (a * d = b * c)*)
444 Rule.Thm ("mult_cross1", ThmC.numerals_to_Free @{thm mult_cross1}),
445 (*" b ~= 0 ==> (a / b = c ) = (a = b * c)*)
446 Rule.Thm ("mult_cross2", ThmC.numerals_to_Free @{thm mult_cross2})
447 (*" d ~= 0 ==> (a = c / d) = (a * d = c)*)],
448 scr = Rule.Empty_Prog})
451 (*("is_expanded", ("Rational.is_expanded", eval_is_expanded ""))*)
452 fun eval_is_expanded (thmid:string) _
453 (t as (Const("Rational.is_expanded", _) $ arg)) thy =
455 then SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "",
456 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
457 else SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "",
458 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
459 | eval_is_expanded _ _ _ _ = NONE;
461 setup \<open>KEStore_Elems.add_calcs
462 [("is_expanded", ("Rational.is_expanded", eval_is_expanded ""))]\<close>
465 Rule_Set.merge "rational_erls" calculate_Rational
466 (Rule_Set.append_rules "is_expanded" Atools_erls
467 [Rule.Eval ("Rational.is_expanded", eval_is_expanded "")]);
470 subsection \<open>Embed cancellation into rewriting\<close>
472 (**)local (* cancel_p *)
474 val {rules = rules, rew_ord = (_, ro), ...} = Rule_Set.rep (assoc_rls' @{theory} "rev_rew_p");
476 fun init_state thy eval_rls ro t =
478 val SOME (t', _) = factout_p_ thy t;
479 val SOME (t'', asm) = cancel_p_ thy t;
480 val der = Derive.steps_reverse thy eval_rls rules ro NONE t';
482 [(Rule.Thm ("real_mult_div_cancel2", ThmC.numerals_to_Free @{thm real_mult_div_cancel2}), (t'', asm))]
483 val rs = (Rule.distinct' o (map #1)) der
484 val rs = filter_out (ThmC.member'
485 ["sym_real_add_zero_left", "sym_real_mult_0", "sym_real_mult_1"]) rs
486 in (t, t'', [rs(*one in order to ease locate_rule*)], der) end;
488 fun locate_rule thy eval_rls ro [rs] t r =
489 if member op = ((map (Rule.thm_id)) rs) (Rule.thm_id r)
491 let val ropt = Rewrite.rewrite_ thy ro eval_rls true (Rule.thm r) t;
493 case ropt of SOME ta => [(r, ta)]
495 ("### locate_rule: rewrite " ^ Rule.thm_id r ^ " " ^ UnparseC.term t ^ " = NONE");*) [])
497 else ((*tracing ("### locate_rule: " ^ Rule.thm_id r ^ " not mem rrls");*) [])
498 | locate_rule _ _ _ _ _ _ = raise ERROR "locate_rule: doesnt match rev-sets in istate";
500 fun next_rule thy eval_rls ro [rs] t =
502 val der = Derive.do_one thy eval_rls rs ro NONE t;
503 in case der of (_, r, _) :: _ => SOME r | _ => NONE end
504 | next_rule _ _ _ _ _ = raise ERROR ("next_rule: doesnt match rev-sets in istate");
506 fun attach_form (_: Rule.rule list list) (_: term) (_: term) =
507 [(*TODO*)]: ( Rule.rule * (term * term list)) list;
512 Rule_Set.Rrls {id = "cancel_p", prepat = [],
513 rew_ord=("ord_make_polynomial", ord_make_polynomial false \<^theory>),
514 erls = rational_erls,
516 [("PLUS", ("Groups.plus_class.plus", (**)eval_binop "#add_")),
517 ("TIMES" , ("Groups.times_class.times", (**)eval_binop "#mult_")),
518 ("DIVIDE", ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e")),
519 ("POWER", ("Transcendental.powr", (**)eval_binop "#power_"))],
522 Rule.Rfuns {init_state = init_state \<^theory> Atools_erls ro,
523 normal_form = cancel_p_ \<^theory>,
524 locate_rule = locate_rule \<^theory> Atools_erls ro,
525 next_rule = next_rule \<^theory> Atools_erls ro,
526 attach_form = attach_form}}
527 (**)end(* local cancel_p *)
530 subsection \<open>Embed addition into rewriting\<close>
532 (**)local (* add_fractions_p *)
534 (*val {rules = rules, rew_ord = (_, ro), ...} = Rule_Set.rep (assoc_rls "make_polynomial");*)
535 val {rules, rew_ord=(_,ro),...} = Rule_Set.rep (assoc_rls' @{theory} "rev_rew_p");
537 fun init_state thy eval_rls ro t =
539 val SOME (t',_) = common_nominator_p_ thy t;
540 val SOME (t'', asm) = add_fraction_p_ thy t;
541 val der = Derive.steps_reverse thy eval_rls rules ro NONE t';
543 [(Rule.Thm ("real_mult_div_cancel2", ThmC.numerals_to_Free @{thm real_mult_div_cancel2}), (t'',asm))]
544 val rs = (Rule.distinct' o (map #1)) der;
545 val rs = filter_out (ThmC.member'
546 ["sym_real_add_zero_left", "sym_real_mult_0", "sym_real_mult_1"]) rs;
547 in (t, t'', [rs(*here only _ONE_*)], der) end;
549 fun locate_rule thy eval_rls ro [rs] t r =
550 if member op = ((map (Rule.thm_id)) rs) (Rule.thm_id r)
552 let val ropt = Rewrite.rewrite_ thy ro eval_rls true (Rule.thm r) t;
557 ((*tracing ("### locate_rule: rewrite " ^ Rule.thm_id r ^ " " ^ UnparseC.term t ^ " = NONE");*)
559 else ((*tracing ("### locate_rule: " ^ Rule.thm_id r ^ " not mem rrls");*) [])
560 | locate_rule _ _ _ _ _ _ = raise ERROR "locate_rule: doesnt match rev-sets in istate";
562 fun next_rule thy eval_rls ro [rs] t =
563 let val der = Derive.do_one thy eval_rls rs ro NONE t;
569 | next_rule _ _ _ _ _ = raise ERROR ("next_rule: doesnt match rev-sets in istate");
571 val pat0 = TermC.parse_patt \<^theory> "?r/?s+?u/?v :: real";
572 val pat1 = TermC.parse_patt \<^theory> "?r/?s+?u :: real";
573 val pat2 = TermC.parse_patt \<^theory> "?r +?u/?v :: real";
574 val prepat = [([@{term True}], pat0),
575 ([@{term True}], pat1),
576 ([@{term True}], pat2)];
579 val add_fractions_p =
580 Rule_Set.Rrls {id = "add_fractions_p", prepat=prepat,
581 rew_ord = ("ord_make_polynomial", ord_make_polynomial false \<^theory>),
582 erls = rational_erls,
583 calc = [("PLUS", ("Groups.plus_class.plus", (**)eval_binop "#add_")),
584 ("TIMES", ("Groups.times_class.times", (**)eval_binop "#mult_")),
585 ("DIVIDE", ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e")),
586 ("POWER", ("Transcendental.powr", (**)eval_binop "#power_"))],
588 scr = Rule.Rfuns {init_state = init_state \<^theory> Atools_erls ro,
589 normal_form = add_fraction_p_ \<^theory>,
590 locate_rule = locate_rule \<^theory> Atools_erls ro,
591 next_rule = next_rule \<^theory> Atools_erls ro,
592 attach_form = attach_form}}
593 (**)end(*local add_fractions_p *)
596 subsection \<open>Cancelling and adding all occurrences in a term /////////////////////////////\<close>
598 (*copying cancel_p_rls + add her caused error in interface.sml*)
601 section \<open>Rulesets for general simplification\<close>
603 (*erls for calculate_Rational; make local with FIXX@ME result:term *term list*)
604 val powers_erls = prep_rls'(
605 Rule_Def.Repeat {id = "powers_erls", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord),
606 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
607 rules = [Rule.Eval ("Prog_Expr.is_atom", Prog_Expr.eval_is_atom "#is_atom_"),
608 Rule.Eval ("Prog_Expr.is_even", Prog_Expr.eval_is_even "#is_even_"),
609 Rule.Eval ("Orderings.ord_class.less", Prog_Expr.eval_equ "#less_"),
610 Rule.Thm ("not_false", ThmC.numerals_to_Free @{thm not_false}),
611 Rule.Thm ("not_true", ThmC.numerals_to_Free @{thm not_true}),
612 Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_")
614 scr = Rule.Empty_Prog
616 (*.all powers over + distributed; atoms over * collected, other distributed
617 contains absolute minimum of thms for context in norm_Rational .*)
618 val powers = prep_rls'(
619 Rule_Def.Repeat {id = "powers", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord),
620 erls = powers_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
621 rules = [Rule.Thm ("realpow_multI", ThmC.numerals_to_Free @{thm realpow_multI}),
622 (*"(r * s) \<up> n = r \<up> n * s \<up> n"*)
623 Rule.Thm ("realpow_pow",ThmC.numerals_to_Free @{thm realpow_pow}),
624 (*"(a \<up> b) \<up> c = a \<up> (b * c)"*)
625 Rule.Thm ("realpow_oneI",ThmC.numerals_to_Free @{thm realpow_oneI}),
627 Rule.Thm ("realpow_minus_even",ThmC.numerals_to_Free @{thm realpow_minus_even}),
628 (*"n is_even ==> (- r) \<up> n = r \<up> n" ?-->discard_minus?*)
629 Rule.Thm ("realpow_minus_odd",ThmC.numerals_to_Free @{thm realpow_minus_odd}),
630 (*"Not (n is_even) ==> (- r) \<up> n = -1 * r \<up> n"*)
632 (*----- collect atoms over * -----*)
633 Rule.Thm ("realpow_two_atom",ThmC.numerals_to_Free @{thm realpow_two_atom}),
634 (*"r is_atom ==> r * r = r \<up> 2"*)
635 Rule.Thm ("realpow_plus_1",ThmC.numerals_to_Free @{thm realpow_plus_1}),
636 (*"r is_atom ==> r * r \<up> n = r \<up> (n + 1)"*)
637 Rule.Thm ("realpow_addI_atom",ThmC.numerals_to_Free @{thm realpow_addI_atom}),
638 (*"r is_atom ==> r \<up> n * r \<up> m = r \<up> (n + m)"*)
640 (*----- distribute none-atoms -----*)
641 Rule.Thm ("realpow_def_atom",ThmC.numerals_to_Free @{thm realpow_def_atom}),
642 (*"[| 1 < n; ~ (r is_atom) |]==>r \<up> n = r * r \<up> (n + -1)"*)
643 Rule.Thm ("realpow_eq_oneI",ThmC.numerals_to_Free @{thm realpow_eq_oneI}),
645 Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_")
647 scr = Rule.Empty_Prog
649 (*.contains absolute minimum of thms for context in norm_Rational.*)
650 val rat_mult_divide = prep_rls'(
651 Rule_Def.Repeat {id = "rat_mult_divide", preconds = [],
652 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
653 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
654 rules = [Rule.Thm ("rat_mult",ThmC.numerals_to_Free @{thm rat_mult}),
655 (*(1)"?a / ?b * (?c / ?d) = ?a * ?c / (?b * ?d)"*)
656 Rule.Thm ("times_divide_eq_right",ThmC.numerals_to_Free @{thm times_divide_eq_right}),
657 (*(2)"?a * (?c / ?d) = ?a * ?c / ?d" must be [2],
658 otherwise inv.to a / b / c = ...*)
659 Rule.Thm ("times_divide_eq_left",ThmC.numerals_to_Free @{thm times_divide_eq_left}),
660 (*"?a / ?b * ?c = ?a * ?c / ?b" order weights x \<up> n too much
661 and does not commute a / b * c \<up> 2 !*)
663 Rule.Thm ("divide_divide_eq_right",
664 ThmC.numerals_to_Free @{thm divide_divide_eq_right}),
665 (*"?x / (?y / ?z) = ?x * ?z / ?y"*)
666 Rule.Thm ("divide_divide_eq_left",
667 ThmC.numerals_to_Free @{thm divide_divide_eq_left}),
668 (*"?x / ?y / ?z = ?x / (?y * ?z)"*)
669 Rule.Eval ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e")
671 scr = Rule.Empty_Prog
674 (*.contains absolute minimum of thms for context in norm_Rational.*)
675 val reduce_0_1_2 = prep_rls'(
676 Rule_Def.Repeat{id = "reduce_0_1_2", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
677 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
678 rules = [(*Rule.Thm ("divide_1",ThmC.numerals_to_Free @{thm divide_1}),
679 "?x / 1 = ?x" unnecess.for normalform*)
680 Rule.Thm ("mult_1_left",ThmC.numerals_to_Free @{thm mult_1_left}),
682 (*Rule.Thm ("real_mult_minus1",ThmC.numerals_to_Free @{thm real_mult_minus1}),
684 (*Rule.Thm ("real_minus_mult_cancel",ThmC.numerals_to_Free @{thm real_minus_mult_cancel}),
685 "- ?x * - ?y = ?x * ?y"*)
687 Rule.Thm ("mult_zero_left",ThmC.numerals_to_Free @{thm mult_zero_left}),
689 Rule.Thm ("add_0_left",ThmC.numerals_to_Free @{thm add_0_left}),
691 (*Rule.Thm ("right_minus",ThmC.numerals_to_Free @{thm right_minus}),
694 Rule.Thm ("sym_real_mult_2",
695 ThmC.numerals_to_Free (@{thm real_mult_2} RS @{thm sym})),
696 (*"z1 + z1 = 2 * z1"*)
697 Rule.Thm ("real_mult_2_assoc",ThmC.numerals_to_Free @{thm real_mult_2_assoc}),
698 (*"z1 + (z1 + k) = 2 * z1 + k"*)
700 Rule.Thm ("division_ring_divide_zero",ThmC.numerals_to_Free @{thm division_ring_divide_zero})
702 ], scr = Rule.Empty_Prog});
704 (*erls for calculate_Rational;
705 make local with FIXX@ME result:term *term list WN0609???SKMG*)
706 val norm_rat_erls = prep_rls'(
707 Rule_Def.Repeat {id = "norm_rat_erls", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord),
708 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
709 rules = [Rule.Eval ("Prog_Expr.is_const", Prog_Expr.eval_const "#is_const_")
710 ], scr = Rule.Empty_Prog});
712 (* consists of rls containing the absolute minimum of thms *)
713 (*040209: this version has been used by RL for his equations,
714 which is now replaced by MGs version "norm_Rational" below *)
715 val norm_Rational_min = prep_rls'(
716 Rule_Def.Repeat {id = "norm_Rational_min", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord),
717 erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
718 rules = [(*sequence given by operator precedence*)
719 Rule.Rls_ discard_minus,
721 Rule.Rls_ rat_mult_divide,
723 Rule.Rls_ reduce_0_1_2,
724 Rule.Rls_ order_add_mult,
725 Rule.Rls_ collect_numerals,
726 Rule.Rls_ add_fractions_p,
729 scr = Rule.Empty_Prog});
731 val norm_Rational_parenthesized = prep_rls'(
732 Rule_Set.Sequence {id = "norm_Rational_parenthesized", preconds = []:term list,
733 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
734 erls = Atools_erls, srls = Rule_Set.Empty,
735 calc = [], errpatts = [],
736 rules = [Rule.Rls_ norm_Rational_min,
737 Rule.Rls_ discard_parentheses
739 scr = Rule.Empty_Prog});
741 (*WN030318???SK: simplifies all but cancel and common_nominator*)
742 val simplify_rational =
743 Rule_Set.merge "simplify_rational" expand_binoms
744 (Rule_Set.append_rules "divide" calculate_Rational
745 [Rule.Thm ("div_by_1",ThmC.numerals_to_Free @{thm div_by_1}),
747 Rule.Thm ("rat_mult",ThmC.numerals_to_Free @{thm rat_mult}),
748 (*(1)"?a / ?b * (?c / ?d) = ?a * ?c / (?b * ?d)"*)
749 Rule.Thm ("times_divide_eq_right",ThmC.numerals_to_Free @{thm times_divide_eq_right}),
750 (*(2)"?a * (?c / ?d) = ?a * ?c / ?d" must be [2],
751 otherwise inv.to a / b / c = ...*)
752 Rule.Thm ("times_divide_eq_left",ThmC.numerals_to_Free @{thm times_divide_eq_left}),
753 (*"?a / ?b * ?c = ?a * ?c / ?b"*)
754 Rule.Thm ("add_minus",ThmC.numerals_to_Free @{thm add_minus}),
755 (*"?a + ?b - ?b = ?a"*)
756 Rule.Thm ("add_minus1",ThmC.numerals_to_Free @{thm add_minus1}),
757 (*"?a - ?b + ?b = ?a"*)
758 Rule.Thm ("divide_minus1",ThmC.numerals_to_Free @{thm divide_minus1})
763 val add_fractions_p_rls = prep_rls'(
764 Rule_Def.Repeat {id = "add_fractions_p_rls", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
765 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
766 rules = [Rule.Rls_ add_fractions_p],
767 scr = Rule.Empty_Prog});
769 (* "Rule_Def.Repeat" causes repeated application of cancel_p to one and the same term *)
770 val cancel_p_rls = prep_rls'(
772 {id = "cancel_p_rls", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
773 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
774 rules = [Rule.Rls_ cancel_p],
775 scr = Rule.Empty_Prog});
777 (*. makes 'normal' fractions; 'is_polyexp' inhibits double fractions;
778 used in initial part norm_Rational_mg, see example DA-M02-main.p.60.*)
779 val rat_mult_poly = prep_rls'(
780 Rule_Def.Repeat {id = "rat_mult_poly", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
781 erls = Rule_Set.append_rules "Rule_Set.empty-is_polyexp" Rule_Set.empty [Rule.Eval ("Poly.is_polyexp", eval_is_polyexp "")],
782 srls = Rule_Set.Empty, calc = [], errpatts = [],
784 [Rule.Thm ("rat_mult_poly_l",ThmC.numerals_to_Free @{thm rat_mult_poly_l}),
785 (*"?c is_polyexp ==> ?c * (?a / ?b) = ?c * ?a / ?b"*)
786 Rule.Thm ("rat_mult_poly_r",ThmC.numerals_to_Free @{thm rat_mult_poly_r})
787 (*"?c is_polyexp ==> ?a / ?b * ?c = ?a * ?c / ?b"*) ],
788 scr = Rule.Empty_Prog});
790 (*. makes 'normal' fractions; 'is_polyexp' inhibits double fractions;
791 used in looping part norm_Rational_rls, see example DA-M02-main.p.60
792 .. WHERE THE LATTER DOES ALWAYS WORK, BECAUSE erls = Rule_Set.empty,
793 I.E. THE RESPECTIVE ASSUMPTION IS STORED AND Rule.Thm APPLIED; WN051028
795 val rat_mult_div_pow = prep_rls'(
796 Rule_Def.Repeat {id = "rat_mult_div_pow", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord),
797 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
798 rules = [Rule.Thm ("rat_mult", ThmC.numerals_to_Free @{thm rat_mult}),
799 (*"?a / ?b * (?c / ?d) = ?a * ?c / (?b * ?d)"*)
800 Rule.Thm ("rat_mult_poly_l", ThmC.numerals_to_Free @{thm rat_mult_poly_l}),
801 (*"?c is_polyexp ==> ?c * (?a / ?b) = ?c * ?a / ?b"*)
802 Rule.Thm ("rat_mult_poly_r", ThmC.numerals_to_Free @{thm rat_mult_poly_r}),
803 (*"?c is_polyexp ==> ?a / ?b * ?c = ?a * ?c / ?b"*)
805 Rule.Thm ("real_divide_divide1_mg", ThmC.numerals_to_Free @{thm real_divide_divide1_mg}),
806 (*"y ~= 0 ==> (u / v) / (y / z) = (u * z) / (y * v)"*)
807 Rule.Thm ("divide_divide_eq_right", ThmC.numerals_to_Free @{thm divide_divide_eq_right}),
808 (*"?x / (?y / ?z) = ?x * ?z / ?y"*)
809 Rule.Thm ("divide_divide_eq_left", ThmC.numerals_to_Free @{thm divide_divide_eq_left}),
810 (*"?x / ?y / ?z = ?x / (?y * ?z)"*)
811 Rule.Eval ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e"),
813 Rule.Thm ("rat_power", ThmC.numerals_to_Free @{thm rat_power})
814 (*"(?a / ?b) \<up> ?n = ?a \<up> ?n / ?b \<up> ?n"*)
816 scr = Rule.Empty_Prog});
818 val rat_reduce_1 = prep_rls'(
819 Rule_Def.Repeat {id = "rat_reduce_1", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
820 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
822 [Rule.Thm ("div_by_1", ThmC.numerals_to_Free @{thm div_by_1}),
824 Rule.Thm ("mult_1_left", ThmC.numerals_to_Free @{thm mult_1_left})
827 scr = Rule.Empty_Prog});
829 (* looping part of norm_Rational *)
830 val norm_Rational_rls = prep_rls' (
831 Rule_Def.Repeat {id = "norm_Rational_rls", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord),
832 erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
833 rules = [Rule.Rls_ add_fractions_p_rls,
834 Rule.Rls_ rat_mult_div_pow,
835 Rule.Rls_ make_rat_poly_with_parentheses,
836 Rule.Rls_ cancel_p_rls,
837 Rule.Rls_ rat_reduce_1
839 scr = Rule.Empty_Prog});
841 val norm_Rational = prep_rls' (
843 {id = "norm_Rational", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
844 erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
845 rules = [Rule.Rls_ discard_minus,
846 Rule.Rls_ rat_mult_poly, (* removes double fractions like a/b/c *)
847 Rule.Rls_ make_rat_poly_with_parentheses,
848 Rule.Rls_ cancel_p_rls,
849 Rule.Rls_ norm_Rational_rls, (* the main rls, looping (#) *)
850 Rule.Rls_ discard_parentheses1 (* mult only *)
852 scr = Rule.Empty_Prog});
856 calculate_Rational = calculate_Rational and
857 calc_rat_erls = calc_rat_erls and
858 rational_erls = rational_erls and
859 cancel_p = cancel_p and
860 add_fractions_p = add_fractions_p and
862 add_fractions_p_rls = add_fractions_p_rls and
863 powers_erls = powers_erls and
865 rat_mult_divide = rat_mult_divide and
866 reduce_0_1_2 = reduce_0_1_2 and
868 rat_reduce_1 = rat_reduce_1 and
869 norm_rat_erls = norm_rat_erls and
870 norm_Rational = norm_Rational and
871 norm_Rational_rls = norm_Rational_rls and
872 norm_Rational_min = norm_Rational_min and
873 norm_Rational_parenthesized = norm_Rational_parenthesized and
875 rat_mult_poly = rat_mult_poly and
876 rat_mult_div_pow = rat_mult_div_pow and
877 cancel_p_rls = cancel_p_rls
879 section \<open>A problem for simplification of rationals\<close>
880 setup \<open>KEStore_Elems.add_pbts
881 [(Problem.prep_input @{theory} "pbl_simp_rat" [] Problem.id_empty
882 (["rational", "simplification"],
883 [("#Given" ,["Term t_t"]),
884 ("#Where" ,["t_t is_ratpolyexp"]),
885 ("#Find" ,["normalform n_n"])],
886 Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)],
887 SOME "Simplify t_t", [["simplification", "of_rationals"]]))]\<close>
889 section \<open>A methods for simplification of rationals\<close>
890 (*WN061025 this methods script is copied from (auto-generated) script
891 of norm_Rational in order to ease repair on inform*)
893 partial_function (tailrec) simplify :: "real \<Rightarrow> real"
896 (Try (Rewrite_Set ''discard_minus'') #>
897 Try (Rewrite_Set ''rat_mult_poly'') #>
898 Try (Rewrite_Set ''make_rat_poly_with_parentheses'') #>
899 Try (Rewrite_Set ''cancel_p_rls'') #>
901 Try (Rewrite_Set ''add_fractions_p_rls'') #>
902 Try (Rewrite_Set ''rat_mult_div_pow'') #>
903 Try (Rewrite_Set ''make_rat_poly_with_parentheses'') #>
904 Try (Rewrite_Set ''cancel_p_rls'') #>
905 Try (Rewrite_Set ''rat_reduce_1''))) #>
906 Try (Rewrite_Set ''discard_parentheses1''))
908 setup \<open>KEStore_Elems.add_mets
909 [MethodC.prep_input @{theory} "met_simp_rat" [] MethodC.id_empty
910 (["simplification", "of_rationals"],
911 [("#Given" ,["Term t_t"]),
912 ("#Where" ,["t_t is_ratpolyexp"]),
913 ("#Find" ,["normalform n_n"])],
914 {rew_ord'="tless_true", rls' = Rule_Set.empty, calc = [], srls = Rule_Set.empty,
915 prls = Rule_Set.append_rules "simplification_of_rationals_prls" Rule_Set.empty
916 [(*for preds in where_*) Rule.Eval ("Rational.is_ratpolyexp", eval_is_ratpolyexp "")],
917 crls = Rule_Set.empty, errpats = [], nrls = norm_Rational_rls},
918 @{thm simplify.simps})]