15 is'_ratpolyexp :: "real => bool" ("_ is'_ratpolyexp") |
15 is'_ratpolyexp :: "real => bool" ("_ is'_ratpolyexp") |
16 |
16 |
17 axioms (*.not contained in Isabelle2002, |
17 axioms (*.not contained in Isabelle2002, |
18 stated as axioms, TODO?: prove as theorems*) |
18 stated as axioms, TODO?: prove as theorems*) |
19 |
19 |
20 mult_cross "[| b ~= 0; d ~= 0 |] ==> (a / b = c / d) = (a * d = b * c)" |
20 mult_cross: "[| b ~= 0; d ~= 0 |] ==> (a / b = c / d) = (a * d = b * c)" |
21 mult_cross1 " b ~= 0 ==> (a / b = c ) = (a = b * c)" |
21 mult_cross1: " b ~= 0 ==> (a / b = c ) = (a = b * c)" |
22 mult_cross2 " d ~= 0 ==> (a = c / d) = (a * d = c)" |
22 mult_cross2: " d ~= 0 ==> (a = c / d) = (a * d = c)" |
23 |
23 |
24 add_minus "a + b - b = a"(*RL->Poly.thy*) |
24 add_minus: "a + b - b = a"(*RL->Poly.thy*) |
25 add_minus1 "a - b + b = a"(*RL->Poly.thy*) |
25 add_minus1: "a - b + b = a"(*RL->Poly.thy*) |
26 |
26 |
27 rat_mult "a / b * (c / d) = a * c / (b * d)"(*?Isa02*) |
27 rat_mult: "a / b * (c / d) = a * c / (b * d)"(*?Isa02*) |
28 rat_mult2 "a / b * c = a * c / b "(*?Isa02*) |
28 rat_mult2: "a / b * c = a * c / b "(*?Isa02*) |
29 |
29 |
30 rat_mult_poly_l "c is_polyexp ==> c * (a / b) = c * a / b" |
30 rat_mult_poly_l: "c is_polyexp ==> c * (a / b) = c * a / b" |
31 rat_mult_poly_r "c is_polyexp ==> (a / b) * c = a * c / b" |
31 rat_mult_poly_r: "c is_polyexp ==> (a / b) * c = a * c / b" |
32 |
32 |
33 (*real_times_divide1_eq .. Isa02*) |
33 (*real_times_divide1_eq .. Isa02*) |
34 real_times_divide_1_eq "-1 * (c / d) =-1 * c / d " |
34 real_times_divide_1_eq: "-1 * (c / d) =-1 * c / d " |
35 real_times_divide_num "a is_const ==> |
35 real_times_divide_num: "a is_const ==> |
36 a * (c / d) = a * c / d " |
36 a * (c / d) = a * c / d " |
37 |
37 |
38 real_mult_div_cancel2 "k ~= 0 ==> m * k / (n * k) = m / n" |
38 real_mult_div_cancel2: "k ~= 0 ==> m * k / (n * k) = m / n" |
39 (*real_mult_div_cancel1 "k ~= 0 ==> k * m / (k * n) = m / n"..Isa02*) |
39 (*real_mult_div_cancel1: "k ~= 0 ==> k * m / (k * n) = m / n"..Isa02*) |
40 |
40 |
41 real_divide_divide1 "y ~= 0 ==> (u / v) / (y / z) = (u / v) * (z / y)" |
41 real_divide_divide1: "y ~= 0 ==> (u / v) / (y / z) = (u / v) * (z / y)" |
42 real_divide_divide1_mg "y ~= 0 ==> (u / v) / (y / z) = (u * z) / (y * v)" |
42 real_divide_divide1_mg: "y ~= 0 ==> (u / v) / (y / z) = (u * z) / (y * v)" |
43 (*real_divide_divide2_eq "x / y / z = x / (y * z)"..Isa02*) |
43 (*real_divide_divide2_eq: "x / y / z = x / (y * z)"..Isa02*) |
44 |
44 |
45 rat_power "(a / b)^^^n = (a^^^n) / (b^^^n)" |
45 rat_power: "(a / b)^^^n = (a^^^n) / (b^^^n)" |
46 |
46 |
47 |
47 |
48 rat_add "[| a is_const; b is_const; c is_const; d is_const |] ==> |
48 rat_add: "[| a is_const; b is_const; c is_const; d is_const |] ==> |
49 a / c + b / d = (a * d + b * c) / (c * d)" |
49 a / c + b / d = (a * d + b * c) / (c * d)" |
50 rat_add_assoc "[| a is_const; b is_const; c is_const; d is_const |] ==> |
50 rat_add_assoc: "[| a is_const; b is_const; c is_const; d is_const |] ==> |
51 a / c +(b / d + e) = (a * d + b * c)/(d * c) + e" |
51 a / c +(b / d + e) = (a * d + b * c)/(d * c) + e" |
52 rat_add1 "[| a is_const; b is_const; c is_const |] ==> |
52 rat_add1: "[| a is_const; b is_const; c is_const |] ==> |
53 a / c + b / c = (a + b) / c" |
53 a / c + b / c = (a + b) / c" |
54 rat_add1_assoc "[| a is_const; b is_const; c is_const |] ==> |
54 rat_add1_assoc: "[| a is_const; b is_const; c is_const |] ==> |
55 a / c + (b / c + e) = (a + b) / c + e" |
55 a / c + (b / c + e) = (a + b) / c + e" |
56 rat_add2 "[| a is_const; b is_const; c is_const |] ==> |
56 rat_add2: "[| a is_const; b is_const; c is_const |] ==> |
57 a / c + b = (a + b * c) / c" |
57 a / c + b = (a + b * c) / c" |
58 rat_add2_assoc "[| a is_const; b is_const; c is_const |] ==> |
58 rat_add2_assoc: "[| a is_const; b is_const; c is_const |] ==> |
59 a / c + (b + e) = (a + b * c) / c + e" |
59 a / c + (b + e) = (a + b * c) / c + e" |
60 rat_add3 "[| a is_const; b is_const; c is_const |] ==> |
60 rat_add3: "[| a is_const; b is_const; c is_const |] ==> |
61 a + b / c = (a * c + b) / c" |
61 a + b / c = (a * c + b) / c" |
62 rat_add3_assoc "[| a is_const; b is_const; c is_const |] ==> |
62 rat_add3_assoc: "[| a is_const; b is_const; c is_const |] ==> |
63 a + (b / c + e) = (a * c + b) / c + e" |
63 a + (b / c + e) = (a * c + b) / c + e" |
64 |
64 |
65 text {*calculate in rationals: gcd, lcm, etc. |
65 text {*calculate in rationals: gcd, lcm, etc. |
66 (c) Stefan Karnel 2002 |
66 (c) Stefan Karnel 2002 |
67 Institute for Mathematics D and Institute for Software Technology, |
67 Institute for Mathematics D and Institute for Software Technology, |
449 !g |
452 !g |
450 ) |
453 ) |
451 end; |
454 end; |
452 |
455 |
453 (*. calculates the minimum of two real values x and y .*) |
456 (*. calculates the minimum of two real values x and y .*) |
454 fun uv_mod_r_min(x,y):BasisLibrary.Real.real = if x>y then y else x; |
457 fun uv_mod_r_min(x,y):Real.real = if x>y then y else x; |
455 |
458 |
456 (*. calculates the minimum of two integer values x and y .*) |
459 (*. calculates the minimum of two integer values x and y .*) |
457 fun uv_mod_min(x,y) = if x>y then y else x; |
460 fun uv_mod_min(x,y) = if x>y then y else x; |
458 |
461 |
459 (*. adds the squared values of a integer list .*) |
462 (*. adds the squared values of a integer list .*) |
460 fun uv_mod_add_qu [] = 0.0 |
463 fun uv_mod_add_qu [] = 0.0 |
461 | uv_mod_add_qu (x::p) = BasisLibrary.Real.fromInt(x)*BasisLibrary.Real.fromInt(x) + uv_mod_add_qu p; |
464 | uv_mod_add_qu (x::p) = Real.fromInt(x)*Real.fromInt(x) + uv_mod_add_qu p; |
462 |
465 |
463 (*. calculates the euklidean norm .*) |
466 (*. calculates the euklidean norm .*) |
464 fun uv_mod_norm ([]:uv_poly) = 0.0 |
467 fun uv_mod_norm ([]:uv_poly) = 0.0 |
465 | uv_mod_norm p = Math.sqrt(uv_mod_add_qu(p)); |
468 | uv_mod_norm p = Math.sqrt(uv_mod_add_qu(p)); |
466 |
469 |
578 |
581 |
579 d:=gcd_int (uv_mod_lc(!p1)) (uv_mod_lc(!p2)); |
582 d:=gcd_int (uv_mod_lc(!p1)) (uv_mod_lc(!p2)); |
580 g1:=uv_mod_lc(!p1)*uv_mod_lc(!p2); |
583 g1:=uv_mod_lc(!p1)*uv_mod_lc(!p2); |
581 p:=4; |
584 p:=4; |
582 |
585 |
583 m:=BasisLibrary.Real.ceil(2.0 * |
586 m:=Real.ceil(2.0 * Real.fromInt(!d) * |
584 BasisLibrary.Real.fromInt(!d) * |
587 Real.fromInt(power 2 (uv_mod_min(uv_mod_deg(!p2),uv_mod_deg(!p1)))) * |
585 BasisLibrary.Real.fromInt(power 2 (uv_mod_min(uv_mod_deg(!p2),uv_mod_deg(!p1)))) * |
588 Real.fromInt(!d) * |
586 BasisLibrary.Real.fromInt(!d) * |
589 uv_mod_r_min(uv_mod_norm(!p1) / Real.fromInt(abs(uv_mod_lc(!p1))), |
587 uv_mod_r_min(uv_mod_norm(!p1) / BasisLibrary.Real.fromInt(abs(uv_mod_lc(!p1))), |
590 uv_mod_norm(!p2) / Real.fromInt(abs(uv_mod_lc(!p2))))); |
588 uv_mod_norm(!p2) / BasisLibrary.Real.fromInt(abs(uv_mod_lc(!p2))))); |
|
589 |
591 |
590 while (!exit=0) do |
592 while (!exit=0) do |
591 ( |
593 ( |
592 p:=uv_mod_nextprime(!d,!p); |
594 p:=uv_mod_nextprime(!d,!p); |
593 cp:=(uv_mod_gcd_modp (uv_mod_list_modp(!p1) (!p)) (uv_mod_list_modp(!p2) (!p)) (!p)) ; |
595 cp:=(uv_mod_gcd_modp (uv_mod_list_modp(!p1) (!p)) (uv_mod_list_modp(!p2) (!p)) (!p)) ; |
867 else raise error("MV_MDIV_EXCEPTION Dividing by empty Polynom") |
869 else raise error("MV_MDIV_EXCEPTION Dividing by empty Polynom") |
868 ) |
870 ) |
869 end; |
871 end; |
870 |
872 |
871 (*. prints a polynom for (internal use only) .*) |
873 (*. prints a polynom for (internal use only) .*) |
872 fun mv_print_poly([]:mv_poly)=print("[]\n") |
874 fun mv_print_poly([]:mv_poly)=writeln("[]\n") |
873 | mv_print_poly((x,y)::[])= print("("^BasisLibrary.Int.toString(x)^","^ints2str(y)^")\n") |
875 | mv_print_poly((x,y)::[])= writeln("("^Int.toString(x)^","^ints2str(y)^")\n") |
874 | mv_print_poly((x,y)::p1) = (print("("^BasisLibrary.Int.toString(x)^","^ints2str(y)^"),");mv_print_poly(p1)); |
876 | mv_print_poly((x,y)::p1) = (writeln("("^Int.toString(x)^","^ints2str(y)^"),");mv_print_poly(p1)); |
875 |
877 |
876 |
878 |
877 (*. division of two multivariate polynomials .*) |
879 (*. division of two multivariate polynomials .*) |
878 fun mv_division([]:mv_poly,g:mv_poly,order)=([]:mv_poly,[]:mv_poly) |
880 fun mv_division([]:mv_poly,g:mv_poly,order)=([]:mv_poly,[]:mv_poly) |
879 | mv_division(f,[],order)= raise error ("RATIONALS_MV_DIVISION_EXCEPTION Division by zero") |
881 | mv_division(f,[],order)= raise error ("RATIONALS_MV_DIVISION_EXCEPTION Division by zero") |
2764 Rls {id = "calc_rat_erls", preconds = [], rew_ord = ("dummy_ord",dummy_ord), |
2766 Rls {id = "calc_rat_erls", preconds = [], rew_ord = ("dummy_ord",dummy_ord), |
2765 erls = e_rls, srls = Erls, calc = [], (*asm_thm = [], *) |
2767 erls = e_rls, srls = Erls, calc = [], (*asm_thm = [], *) |
2766 rules = |
2768 rules = |
2767 [Calc ("op =",eval_equal "#equal_"), |
2769 [Calc ("op =",eval_equal "#equal_"), |
2768 Calc ("Atools.is'_const",eval_const "#is_const_"), |
2770 Calc ("Atools.is'_const",eval_const "#is_const_"), |
2769 Thm ("not_true",num_str @{not_true), |
2771 Thm ("not_true",num_str @{thm not_true}), |
2770 Thm ("not_false",num_str @{not_false) |
2772 Thm ("not_false",num_str @{thm not_false}) |
2771 ], |
2773 ], |
2772 scr = EmptyScr}); |
2774 scr = EmptyScr}); |
2773 |
2775 |
2774 |
2776 |
2775 (*.simplifies expressions with numerals; |
2777 (*.simplifies expressions with numerals; |
2782 calc = [], |
2784 calc = [], |
2783 rules = |
2785 rules = |
2784 [Calc ("HOL.divide" ,eval_cancel "#divide_"), |
2786 [Calc ("HOL.divide" ,eval_cancel "#divide_"), |
2785 |
2787 |
2786 Thm ("minus_divide_left", |
2788 Thm ("minus_divide_left", |
2787 num_str (@{thm real_minus_divide_eq} RS @{thm sym})), |
2789 num_str (@{thm minus_divide_left} RS @{thm sym})), |
2788 (*SYM - ?x / ?y = - (?x / ?y) may come from subst*) |
2790 (*SYM - ?x / ?y = - (?x / ?y) may come from subst*) |
2789 |
2791 |
2790 Thm ("rat_add",num_str @{thm rat_add}), |
2792 Thm ("rat_add",num_str @{thm rat_add}), |
2791 (*"[| a is_const; b is_const; c is_const; d is_const |] ==> \ |
2793 (*"[| a is_const; b is_const; c is_const; d is_const |] ==> \ |
2792 \"a / c + b / d = (a * d) / (c * d) + (b * c ) / (d * c)"*) |
2794 \"a / c + b / d = (a * d) / (c * d) + (b * c ) / (d * c)"*) |
3291 val rs = (distinct_Thm o (map #1)) der; |
3300 val rs = (distinct_Thm o (map #1)) der; |
3292 val rs = filter_out (eq_Thms ["sym_real_add_zero_left", |
3301 val rs = filter_out (eq_Thms ["sym_real_add_zero_left", |
3293 "sym_real_mult_0", |
3302 "sym_real_mult_0", |
3294 "sym_real_mult_1"]) rs; |
3303 "sym_real_mult_1"]) rs; |
3295 in (t,t'',[rs(*here only _ONE_*)],der) end; |
3304 in (t,t'',[rs(*here only _ONE_*)],der) end; |
3296 |
|
3297 (* use"knowledge/Rational.ML"; |
|
3298 *) |
|
3299 |
3305 |
3300 (*.locate_rule = fn : rule list -> term -> rule |
3306 (*.locate_rule = fn : rule list -> term -> rule |
3301 -> (rule * (term * term list) option) list. |
3307 -> (rule * (term * term list) option) list. |
3302 checks a rule R for being a cancel-rule, and if it is, |
3308 checks a rule R for being a cancel-rule, and if it is, |
3303 then return the list of rules (+ the terms they are rewriting to) |
3309 then return the list of rules (+ the terms they are rewriting to) |
3617 val simplify_rational = |
3622 val simplify_rational = |
3618 merge_rls "simplify_rational" expand_binoms |
3623 merge_rls "simplify_rational" expand_binoms |
3619 (append_rls "divide" calculate_Rational |
3624 (append_rls "divide" calculate_Rational |
3620 [Thm ("divide_1",num_str @{thm divide_1}), |
3625 [Thm ("divide_1",num_str @{thm divide_1}), |
3621 (*"?x / 1 = ?x"*) |
3626 (*"?x / 1 = ?x"*) |
3622 Thm ("rat_mult",num_str @{thm rat_mult), |
3627 Thm ("rat_mult",num_str @{thm rat_mult}), |
3623 (*(1)"?a / ?b * (?c / ?d) = ?a * ?c / (?b * ?d)"*) |
3628 (*(1)"?a / ?b * (?c / ?d) = ?a * ?c / (?b * ?d)"*) |
3624 Thm ("times_divide_eq_right",num_str @{thm times_divide_eq_right}), |
3629 Thm ("times_divide_eq_right",num_str @{thm times_divide_eq_right}), |
3625 (*(2)"?a * (?c / ?d) = ?a * ?c / ?d" must be [2], |
3630 (*(2)"?a * (?c / ?d) = ?a * ?c / ?d" must be [2], |
3626 otherwise inv.to a / b / c = ...*) |
3631 otherwise inv.to a / b / c = ...*) |
3627 Thm ("times_divide_eq_left",num_str @{thm times_divide_eq_left}), |
3632 Thm ("times_divide_eq_left",num_str @{thm times_divide_eq_left}), |
3628 (*"?a / ?b * ?c = ?a * ?c / ?b"*) |
3633 (*"?a / ?b * ?c = ?a * ?c / ?b"*) |
3629 Thm ("add_minus",num_str @{thm add_minus}), |
3634 Thm ("add_minus",num_str @{thm add_minus}), |
3630 (*"?a + ?b - ?b = ?a"*) |
3635 (*"?a + ?b - ?b = ?a"*) |
3631 Thm ("add_minus1",num_str @{thm add_minus1}), |
3636 Thm ("add_minus1",num_str @{thm add_minus1}), |
3632 (*"?a - ?b + ?b = ?a"*) |
3637 (*"?a - ?b + ?b = ?a"*) |
3633 Thm ("real_divide_minus1",num_str @{thm real_divide_minus1}) |
3638 Thm ("divide_minus1",num_str @{thm divide_minus1}) |
3634 (*"?x / -1 = - ?x"*) |
3639 (*"?x / -1 = - ?x"*) |
3635 (* |
3640 (* |
3636 , |
3641 , |
3637 Thm ("",num_str @{thm }) |
3642 Thm ("",num_str @{thm }) |
3638 *) |
3643 *) |