jan@42344
|
1 |
(* Partial_Fractions
|
jan@42344
|
2 |
author: Jan Rocnik, isac team
|
jan@42344
|
3 |
Copyright (c) isac team 2011
|
jan@42344
|
4 |
Use is subject to license terms.
|
jan@42344
|
5 |
|
jan@42344
|
6 |
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
|
jan@42344
|
7 |
10 20 30 40 50 60 70 80 90 100
|
jan@42344
|
8 |
*)
|
jan@42344
|
9 |
|
neuper@42289
|
10 |
theory Partial_Fractions imports Rational begin
|
neuper@42289
|
11 |
|
jan@42344
|
12 |
consts
|
jan@42344
|
13 |
|
jan@42345
|
14 |
factors_from_solution :: "bool list => real"
|
jan@42344
|
15 |
|
neuper@42289
|
16 |
subsection {*get the denominator out of a fraction*}
|
jan@42344
|
17 |
text {*this functions have been stored in Rationals.thy and can be put into rule sets*}
|
jan@42344
|
18 |
|
jan@42345
|
19 |
ML {*
|
jan@42345
|
20 |
(*("get_denominator", ("Rational.get'_denominator", eval_get_denominator ""))*)
|
jan@42345
|
21 |
fun eval_get_denominator (thmid:string) _
|
jan@42345
|
22 |
(t as (Const("Rings.inverse_class.divide", _) $ num $ denom)) thy =
|
jan@42345
|
23 |
SOME (mk_thmid thmid ""
|
jan@42345
|
24 |
(Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy)) denom) "",
|
jan@42345
|
25 |
Trueprop $ (mk_equality (t, denom)))
|
jan@42345
|
26 |
| eval_get_denominator _ _ _ _ = NONE;
|
jan@42345
|
27 |
*}
|
jan@42345
|
28 |
|
jan@42345
|
29 |
|
jan@42344
|
30 |
subsubsection {*get solutions out of list*}
|
jan@42344
|
31 |
|
jan@42344
|
32 |
|
neuper@42289
|
33 |
ML {*
|
jan@42344
|
34 |
fun mk_minus_1 T = Free("-1", T); (*TODO DELETE WITH numbers_to_string*)
|
jan@42344
|
35 |
fun flip_sign t = (*TODO improve for use in factors_from_solution: -(-1) etc*)
|
jan@42344
|
36 |
let val minus_1 = t |> type_of |> mk_minus_1
|
jan@42344
|
37 |
in HOLogic.mk_binop "Groups.times_class.times" (minus_1, t) end;
|
jan@42344
|
38 |
fun fac_from_sol s =
|
jan@42344
|
39 |
let val (lhs, rhs) = HOLogic.dest_eq s
|
jan@42344
|
40 |
in HOLogic.mk_binop "Groups.plus_class.plus" (lhs, flip_sign rhs) end;
|
neuper@42289
|
41 |
*}
|
jan@42344
|
42 |
|
jan@42344
|
43 |
ML {*
|
jan@42344
|
44 |
e_term
|
jan@42344
|
45 |
*}
|
jan@42344
|
46 |
|
jan@42344
|
47 |
ML {*
|
jan@42344
|
48 |
fun mk_prod prod [] =
|
jan@42344
|
49 |
if prod = e_term then error "mk_prod called with []" else prod
|
jan@42344
|
50 |
| mk_prod prod (t :: []) =
|
jan@42344
|
51 |
if prod = e_term then t else HOLogic.mk_binop "Groups.times_class.times" (prod, t)
|
jan@42344
|
52 |
| mk_prod prod (t1 :: t2 :: ts) =
|
jan@42344
|
53 |
if prod = e_term
|
jan@42344
|
54 |
then
|
jan@42344
|
55 |
let val p = HOLogic.mk_binop "Groups.times_class.times" (t1, t2)
|
jan@42344
|
56 |
in mk_prod p ts end
|
jan@42344
|
57 |
else
|
jan@42344
|
58 |
let val p = HOLogic.mk_binop "Groups.times_class.times" (prod, t1)
|
jan@42344
|
59 |
in mk_prod p (t2 :: ts) end
|
jan@42344
|
60 |
*}
|
jan@42344
|
61 |
|
jan@42344
|
62 |
ML {*
|
jan@42344
|
63 |
|
jan@42344
|
64 |
|
jan@42344
|
65 |
fun factors_from_solution sol =
|
jan@42344
|
66 |
let val ts = HOLogic.dest_list sol
|
jan@42344
|
67 |
in mk_prod e_term (map fac_from_sol ts) end;
|
jan@42344
|
68 |
|
jan@42344
|
69 |
*}
|
jan@42344
|
70 |
|
jan@42344
|
71 |
ML {*
|
jan@42352
|
72 |
(*("factors_from_solution", ("Equation.factors_from_solution", eval_factors_from_solution ""))*)
|
jan@42352
|
73 |
fun eval_factors_from_solution (thmid:string) _
|
jan@42352
|
74 |
(t as Const ("Partial_Fractions.factors_from_solution", _) $ sol) thy =
|
jan@42352
|
75 |
((let val prod = factors_from_solution sol
|
jan@42352
|
76 |
in SOME (mk_thmid thmid ""
|
jan@42352
|
77 |
(Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy)) prod) "",
|
jan@42352
|
78 |
Trueprop $ (mk_equality (t, prod)))
|
jan@42352
|
79 |
end)
|
jan@42352
|
80 |
handle _ => NONE)
|
jan@42352
|
81 |
| eval_factors_from_solution _ _ _ _ = NONE;
|
jan@42344
|
82 |
*}
|
jan@42344
|
83 |
|
jan@42344
|
84 |
|
jan@42344
|
85 |
|
jan@42344
|
86 |
|
jan@42295
|
87 |
text {*rule set for partial fractions*}
|
neuper@42289
|
88 |
ML {*
|
neuper@42289
|
89 |
val partial_fraction =
|
neuper@42289
|
90 |
Rls {id="partial_fraction", preconds = [], rew_ord = ("termlessI",termlessI),
|
neuper@42289
|
91 |
erls = Erls, srls = Erls, calc = [],
|
neuper@42289
|
92 |
rules = [
|
jan@42345
|
93 |
Calc ("Rings.inverse_class.divide", eval_get_denominator "#")
|
neuper@42289
|
94 |
],
|
neuper@42289
|
95 |
scr = EmptyScr};
|
neuper@42289
|
96 |
*}
|
jan@42295
|
97 |
text {*store the rule set for math engine*}
|
neuper@42289
|
98 |
ML {*
|
neuper@42289
|
99 |
overwritelthy @{theory} (!ruleset',
|
neuper@42289
|
100 |
[("partial_fraction", prep_rls partial_fraction)
|
neuper@42289
|
101 |
]);
|
neuper@42289
|
102 |
*}
|
neuper@42289
|
103 |
|
jan@42295
|
104 |
|
neuper@42289
|
105 |
end |