src/sml/IsacKnowledge/RatEq.ML
author agriesma
Thu, 17 Apr 2003 18:01:03 +0200
branchgriesmayer
changeset 322 ecd8eb2fb15d
child 703 751332b50cdc
permissions -rw-r--r--
neues cvs-verzeichnis
     1 (* (c) by Richard Lang
     2    collecting all knowledge for RationalEquations
     3    created by: rlang 
     4          date: 02.09
     5    changed by: rlang
     6    last change by: rlang
     7              date: 02.11.29
     8 *)
     9 
    10 (* use"knowledge/RatEq.ML";
    11    use"RatEq.ML";
    12    remove_thy"RatEq";
    13    use_thy"Isac";
    14 
    15    use"ROOT.ML";
    16    cd"knowledge";
    17    *)
    18 "******* RatEq.ML begin *******";
    19 
    20 theory' := overwritel (!theory', [("RatEq.thy",RatEq.thy)]);
    21 
    22 (*-------------------------functions-----------------------*)
    23 (* is_rateqation_in becomes true, if a bdv is in the denominator of a fraction*)
    24 fun is_rateqation_in t v = 
    25     let 
    26 	fun coeff_in c v = v mem (vars c);
    27    	fun finddivide (_ $ _ $ _ $ _) v = raise error("is_rateqation_in:")
    28 	    (* at the moment there is no term like this, but ....*)
    29 	  | finddivide (t as (Const ("HOL.divide",_) $ _ $ b)) v = coeff_in b v
    30 	  | finddivide (_ $ t1 $ t2) v = (finddivide t1 v) orelse (finddivide t2 v)
    31 	  | finddivide (_ $ t1) v = (finddivide t1 v)
    32 	  | finddivide _ _ = false;
    33      in
    34 	finddivide t v
    35     end;
    36     
    37 fun eval_is_ratequation_in _ _ (p as (Const ("RatEq.is'_ratequation'_in",_) $ t $ v)) _  =
    38     if is_rateqation_in t v then 
    39 	Some ((term2str p) ^ " = True",
    40 	      Trueprop $ (mk_equality (p, HOLogic.true_const)))
    41     else Some ((term2str p) ^ " = True",
    42 	       Trueprop $ (mk_equality (p, HOLogic.false_const)))
    43   | eval_is_ratequation_in _ _ _ _ = ((*writeln"### nichts matcht";*) None);
    44 
    45 (*-------------------------rulse-----------------------*)
    46 val rateq_prls = (*15.10.02:just the following order due to subterm evaluation*)
    47   append_rls "rateq_prls" e_rls 
    48 	     [Calc ("Atools.ident",eval_ident "#ident_"),
    49 	      Calc ("Tools.matches",eval_matches ""),
    50 	      Calc ("Tools.lhs"    ,eval_lhs ""),
    51               Calc ("Tools.rhs"    ,eval_rhs ""),
    52 	      Calc ("RatEq.is'_ratequation'_in",eval_is_ratequation_in ""),
    53 	      Calc ("op =",eval_equal "#equal_"),
    54 	      Thm ("not_true",num_str not_true),
    55 	      Thm ("not_false",num_str not_false),
    56 	      Thm ("and_true",num_str and_true),
    57 	      Thm ("and_false",num_str and_false),
    58 	      Thm ("or_true",num_str or_true),
    59 	      Thm ("or_false",num_str or_false),
    60 	      Thm ("and_commute",num_str and_commute),
    61 	      Thm ("or_commute",num_str or_commute)
    62 	      ];
    63 
    64 (*rls = merge_rls erls poly_erls *)
    65     remove_rls "no_commute"                                   (*ein Hack*)
    66     remove_rls "rateq_erls"                                   (*WN: ein Hack*)
    67 	(merge_rls "is_ratequation_in" calculate_Rational
    68 		   (append_rls "is_ratequation_in"
    69 			poly_erls
    70 			[(*Calc ("HOL.divide", eval_cancel "#divide_"),*)
    71 			 Calc ("RatEq.is'_ratequation'_in",
    72 			       eval_is_ratequation_in "")
    73 	[Thm ("and_commute",num_str and_commute), (*ein Hack*)
    74 	 Thm ("or_commute",num_str or_commute)    (*ein Hack*)
    75 	 Thm ("or_commute",num_str or_commute)    (*WN: ein Hack*)
    76 	 ];
    77 ruleset' := overwritel (!ruleset',
    78 			[("rateq_erls",rateq_erls)(*FIXXXME:del with rls.rls'*)
    79 			 ]);
    80 
    81 val rat_eliminate = 
    82       erls = rateq_erls, srls = Erls, calc = [], asm_thm = [],
    83                   ("rat_mult_denominator_right","")],
    84     rules = [
    85 	     Thm("rat_mult_denominator_both",num_str rat_mult_denominator_both), 
    86 	     (* a/b=c/d -> ad=cb *)
    87 	     Thm("rat_mult_denominator_left",num_str rat_mult_denominator_left), 
    88 	     (* a  =c/d -> ad=c  *)
    89 	     Thm("rat_mult_denominator_right",num_str rat_mult_denominator_right)
    90 	     (* a/b=c   ->  a=cb *)
    91 	     ],
    92     scr = Script ((term_of o the o (parse thy)) "empty_script")
    93     }:rls;
    94 ruleset' := overwritel (!ruleset',
    95 			[("rat_eliminate",rat_eliminate)
    96 			 ]);
    97 
    98 
    99 
   100 val rat_simplify = 
   101       erls = rateq_erls, srls = Erls, calc = [], asm_thm = [],
   102                   ("rat_double_rat_3","")],
   103     rules = [
   104 	     Thm("real_rat_mult_1",num_str real_rat_mult_1),
   105 	     (*a*(b/c) = (a*b)/c*)
   106 	     Thm("real_rat_mult_2",num_str real_rat_mult_2),
   107 	     (*(a/b)*(c/d) = (a*c)/(b*d)*)
   108              Thm("real_rat_mult_3",num_str real_rat_mult_3),
   109              (* (a/b)*c = (a*c)/b*)
   110 	     Thm("real_rat_pow",num_str real_rat_pow),
   111 	     (*(a/b)^^^2 = a^^^2/b^^^2*)
   112 	     Thm("real_diff_minus",num_str real_diff_minus),
   113 	     (* a - b = a + (-1) * b *)
   114              Thm("rat_double_rat_1",num_str rat_double_rat_1),
   115              (* (a / (c/d) = (a*d) / c) *)
   116              Thm("rat_double_rat_2",num_str rat_double_rat_2), 
   117              (* ((a/b) / (c/d) = (a*d) / (b*c)) *)
   118              Thm("rat_double_rat_3",num_str rat_double_rat_3) 
   119              (* ((a/b) / c = a / (b*c) ) *)
   120 	     ],
   121     scr = Script ((term_of o the o (parse thy)) "empty_script")
   122     }:rls;
   123 ruleset' := overwritel (!ruleset',
   124 			[("rat_simplify",rat_simplify)
   125 			 ]);
   126 
   127 (*-------------------------Problem-----------------------*)
   128 (*
   129 (get_pbt ["rational","univariate","equation"]);
   130 show_ptyps(); 
   131 *)
   132 store_pbt
   133  (prep_pbt RatEq.thy
   134  (["rational","univariate","equation"],
   135   [("#Given" ,["equality e_","solveFor v_"]),
   136    ("#Where" ,["(e_::bool) is_ratequation_in (v_::real)"]),
   137    ("#Find"  ,["solutions v_i_"]) 
   138   ],
   139   [("RatEq.thy","solve_rat_equation")]));
   140   [["RatEq","solve_rat_equation"]]));
   141 
   142 methods:= overwritel (!methods,
   143 [ 
   144  prep_met 
   145  (("RatEq.thy","solve_rat_equation"),
   146  (["RatEq","solve_rat_equation"],
   147    [("#Given" ,["equality e_","solveFor v_"]),
   148    ("#Where" ,["(e_::bool) is_ratequation_in (v_::real)"]),
   149    ("#Find"  ,["solutions v_i_"])
   150   ],
   151    {rew_ord'="termlessI",
   152     rls'=rateq_erls,
   153     srls=e_rls,
   154     prls=rateq_prls,
   155     asm_rls=["rat_simplify","rat_eliminate"],
   156     asm_rls=[],
   157     asm_thm=[("rat_double_rat_1",""),("rat_double_rat_2",""),("rat_double_rat_3",""),
   158              ("rat_mult_denominator_both",""),("rat_mult_denominator_left",""),
   159              ("rat_mult_denominator_right","")]},
   160    "Script Solve_rat_equation  (e_::bool) (v_::real) =                   \
   161     \(let e_ = ((Repeat(Try (Rewrite_Set rat_simplify       True))) @@   \
   162     \           (Repeat(Try (Rewrite_Set make_polynomial    False))) @@  \
   163     \           (Repeat(Try (Rewrite_Set common_nominator_p False))) @@  \
   164     \           (Repeat(Try (Rewrite_Set rat_eliminate       True)))) e_;\
   165     \                (RatEq_,no_met)) [bool_ e_, real_ v_])              \
   166     \                [no_met]) [bool_ e_, real_ v_])              \
   167    )
   168 ]);
   169    ));
   170 "******* RatEq.ML end *******";