src/Tools/isac/Knowledge/RatEq.thy
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 06 Sep 2010 15:09:37 +0200
branchisac-update-Isa09-2
changeset 37981 b2877b9d455a
parent 37972 66fc615a1e89
child 37982 66f3570ba808
permissions -rw-r--r--
updated Knowledge/Equation.thy, plus changes ahead.

find . -type f -exec sed -i s/' e_\"'/' e_e\"'/g {} \;
find . -type f -exec sed -i s/' e_ '/' e_e '/g {} \;
find . -type f -exec sed -i s/' e_)'/' e_e)'/g {} \;
find . -type f -exec sed -i s/' e_,'/' e_e,'/g {} \;
find . -type f -exec sed -i s/' e_:'/' e_e:'/g {} \;
find . -type f -exec sed -i s/'(e_:'/'(e_e:'/g {} \;

find . -type f -exec sed -i s/' v_\"'/' v_v\"'/g {} \;
find . -type f -exec sed -i s/' v_ '/' v_v '/g {} \;
find . -type f -exec sed -i s/' v_)'/' v_v)'/g {} \;
find . -type f -exec sed -i s/' v_,'/' v_v,'/g {} \;
find . -type f -exec sed -i s/' v_:'/' v_v:'/g {} \;

find . -type f -exec sed -i s/' v_i\"'/' v_i\"'/g {} \;
     1 (*.(c) by Richard Lang, 2003 .*)
     2 (* theory collecting all knowledge for RationalEquations
     3    created by: rlang 
     4          date: 02.08.12
     5    changed by: rlang
     6    last change by: rlang
     7              date: 02.11.28
     8 *)
     9 
    10 theory RatEq imports Rational begin
    11 
    12 consts
    13 
    14   is'_ratequation'_in :: "[bool, real] => bool" ("_ is'_ratequation'_in _")
    15 
    16   (*----------------------scripts-----------------------*)
    17   Solve'_rat'_equation
    18              :: "[bool,real, 
    19 		   bool list] => bool list"
    20                ("((Script Solve'_rat'_equation (_ _ =))// 
    21                   (_))" 9)
    22 
    23 axioms 
    24    (* FIXME also in Poly.thy def. --> FIXED*)
    25    (*real_diff_minus            
    26    "a - b = a + (-1) * b"*)
    27    real_rat_mult_1
    28    "a*(b/c) = (a*b)/c"
    29    real_rat_mult_2
    30    "(a/b)*(c/d) = (a*c)/(b*d)"
    31    real_rat_mult_3
    32    "(a/b)*c = (a*c)/b"
    33    real_rat_pow
    34    "(a/b)^^^2 = a^^^2/b^^^2"
    35 
    36    rat_double_rat_1
    37    "[|Not(c=0); Not(d=0)|] ==> (a / (c/d) = (a*d) / c)"
    38    rat_double_rat_2
    39    "[|Not(b=0);Not(c=0); Not(d=0)|] ==> ((a/b) / (c/d) = (a*d) / (b*c))"
    40    rat_double_rat_3
    41    "[|Not(b=0);Not(c=0)|] ==> ((a/b) / c = a / (b*c))"
    42 
    43   (* equation to same denominator *)
    44   rat_mult_denominator_both
    45    "[|Not(b=0); Not(d=0)|] ==> ((a::real) / b = c / d) = (a*d = c*b)"
    46   rat_mult_denominator_left
    47    "[|Not(d=0)|] ==> ((a::real) = c / d) = (a*d = c)"
    48   rat_mult_denominator_right
    49    "[|Not(b=0)|] ==> ((a::real) / b = c) = (a = c*b)"
    50 
    51 ML {*
    52 val thy = @{theory};
    53 
    54 (*-------------------------functions-----------------------*)
    55 (* is_rateqation_in becomes true, if a bdv is in the denominator of a fraction*)
    56 fun is_rateqation_in t v = 
    57     let 
    58 	fun coeff_in c v = member op = (vars c) v;
    59    	fun finddivide (_ $ _ $ _ $ _) v = raise error("is_rateqation_in:")
    60 	    (* at the moment there is no term like this, but ....*)
    61 	  | finddivide (t as (Const ("HOL.divide",_) $ _ $ b)) v = coeff_in b v
    62 	  | finddivide (_ $ t1 $ t2) v = (finddivide t1 v) 
    63                                          orelse (finddivide t2 v)
    64 	  | finddivide (_ $ t1) v = (finddivide t1 v)
    65 	  | finddivide _ _ = false;
    66      in
    67 	finddivide t v
    68     end;
    69     
    70 fun eval_is_ratequation_in _ _ 
    71        (p as (Const ("RatEq.is'_ratequation'_in",_) $ t $ v)) _  =
    72     if is_rateqation_in t v then 
    73 	SOME ((term2str p) ^ " = True",
    74 	      Trueprop $ (mk_equality (p, HOLogic.true_const)))
    75     else SOME ((term2str p) ^ " = True",
    76 	       Trueprop $ (mk_equality (p, HOLogic.false_const)))
    77   | eval_is_ratequation_in _ _ _ _ = ((*writeln"### nichts matcht";*) NONE);
    78 
    79 (*-------------------------rulse-----------------------*)
    80 val RatEq_prls = (*15.10.02:just the following order due to subterm evaluation*)
    81   append_rls "RatEq_prls" e_rls 
    82 	     [Calc ("Atools.ident",eval_ident "#ident_"),
    83 	      Calc ("Tools.matches",eval_matches ""),
    84 	      Calc ("Tools.lhs"    ,eval_lhs ""),
    85 	      Calc ("Tools.rhs"    ,eval_rhs ""),
    86 	      Calc ("RatEq.is'_ratequation'_in",eval_is_ratequation_in ""),
    87 	      Calc ("op =",eval_equal "#equal_"),
    88 	      Thm ("not_true",num_str @{thm not_true}),
    89 	      Thm ("not_false",num_str @{thm not_false}),
    90 	      Thm ("and_true",num_str @{thm and_true}),
    91 	      Thm ("and_false",num_str @{thm and_false}),
    92 	      Thm ("or_true",num_str @{thm or_true}),
    93 	      Thm ("or_false",num_str @{thm or_false})
    94 	      ];
    95 
    96 
    97 (*rls = merge_rls erls Poly_erls *)
    98 val rateq_erls = 
    99     remove_rls "rateq_erls"                                   (*WN: ein Hack*)
   100 	(merge_rls "is_ratequation_in" calculate_Rational
   101 		   (append_rls "is_ratequation_in"
   102 			Poly_erls
   103 			[(*Calc ("HOL.divide", eval_cancel "#divide_e"),*)
   104 			 Calc ("RatEq.is'_ratequation'_in",
   105 			       eval_is_ratequation_in "")
   106 
   107 			 ]))
   108 	[Thm ("and_commute",num_str @{thm and_commute}), (*WN: ein Hack*)
   109 	 Thm ("or_commute",num_str @{thm or_commute})    (*WN: ein Hack*)
   110 	 ];
   111 ruleset' := overwritelthy @{theory} (!ruleset',
   112 			[("rateq_erls",rateq_erls)(*FIXXXME:del with rls.rls'*)
   113 			 ]);
   114 
   115 
   116 val RatEq_crls = 
   117     remove_rls "RatEq_crls"                                   (*WN: ein Hack*)
   118 	(merge_rls "is_ratequation_in" calculate_Rational
   119 		   (append_rls "is_ratequation_in"
   120 			Poly_erls
   121 			[(*Calc ("HOL.divide", eval_cancel "#divide_e"),*)
   122 			 Calc ("RatEq.is'_ratequation'_in",
   123 			       eval_is_ratequation_in "")
   124 			 ]))
   125 	[Thm ("and_commute",num_str @{thm and_commute}), (*WN: ein Hack*)
   126 	 Thm ("or_commute",num_str @{thm or_commute})    (*WN: ein Hack*)
   127 	 ];
   128 
   129 val RatEq_eliminate = prep_rls(
   130   Rls {id = "RatEq_eliminate", preconds = [],
   131        rew_ord = ("termlessI", termlessI), erls = rateq_erls, srls = Erls, 
   132        calc = [], 
   133        rules = [
   134 	    Thm("rat_mult_denominator_both",num_str @{thm rat_mult_denominator_both}), 
   135 	     (* a/b=c/d -> ad=cb *)
   136 	    Thm("rat_mult_denominator_left",num_str @{thm rat_mult_denominator_left}), 
   137 	     (* a  =c/d -> ad=c  *)
   138 	    Thm("rat_mult_denominator_right",num_str @{thm rat_mult_denominator_right})
   139 	     (* a/b=c   ->  a=cb *)
   140 	    ],
   141     scr = Script ((term_of o the o (parse thy)) "empty_script")
   142     }:rls);
   143 ruleset' := overwritelthy @{theory} (!ruleset',
   144 			[("RatEq_eliminate",RatEq_eliminate)
   145 			 ]);
   146 
   147 val RatEq_simplify = prep_rls(
   148   Rls {id = "RatEq_simplify", preconds = [], rew_ord = ("termlessI", termlessI),
   149       erls = rateq_erls, srls = Erls, calc = [], 
   150     rules = [
   151 	     Thm("real_rat_mult_1",num_str @{thm real_rat_mult_1}),
   152 	     (*a*(b/c) = (a*b)/c*)
   153 	     Thm("real_rat_mult_2",num_str @{thm real_rat_mult_2}),
   154 	     (*(a/b)*(c/d) = (a*c)/(b*d)*)
   155              Thm("real_rat_mult_3",num_str @{thm real_rat_mult_3}),
   156              (* (a/b)*c = (a*c)/b*)
   157 	     Thm("real_rat_pow",num_str @{thm real_rat_pow}),
   158 	     (*(a/b)^^^2 = a^^^2/b^^^2*)
   159 	     Thm("real_diff_minus",num_str @{thm real_diff_minus}),
   160 	     (* a - b = a + (-1) * b *)
   161              Thm("rat_double_rat_1",num_str @{thm rat_double_rat_1}),
   162              (* (a / (c/d) = (a*d) / c) *)
   163              Thm("rat_double_rat_2",num_str @{thm rat_double_rat_2}), 
   164              (* ((a/b) / (c/d) = (a*d) / (b*c)) *)
   165              Thm("rat_double_rat_3",num_str @{thm rat_double_rat_3}) 
   166              (* ((a/b) / c = a / (b*c) ) *)
   167 	     ],
   168     scr = Script ((term_of o the o (parse thy)) "empty_script")
   169     }:rls);
   170 ruleset' := overwritelthy @{theory} (!ruleset',
   171 			[("RatEq_simplify",RatEq_simplify)
   172 			 ]);
   173 
   174 (*-------------------------Problem-----------------------*)
   175 (*
   176 (get_pbt ["rational","univariate","equation"]);
   177 show_ptyps(); 
   178 *)
   179 store_pbt
   180  (prep_pbt thy "pbl_equ_univ_rat" [] e_pblID
   181  (["rational","univariate","equation"],
   182   [("#Given" ,["equality e_e","solveFor v_v"]),
   183    ("#Where" ,["(e_e::bool) is_ratequation_in (v_::real)"]),
   184    ("#Find"  ,["solutions v_i"]) 
   185   ],
   186 
   187   RatEq_prls, SOME "solve (e_e::bool, v_v)",
   188   [["RatEq","solve_rat_equation"]]));
   189 
   190 
   191 (*-------------------------methods-----------------------*)
   192 store_met
   193  (prep_met thy "met_rateq" [] e_metID
   194  (["RatEq"],
   195    [],
   196    {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
   197     crls=RatEq_crls, nrls=norm_Rational
   198     (*, asm_rls=[],asm_thm=[]*)}, "empty_script"));
   199 store_met
   200  (prep_met thy "met_rat_eq" [] e_metID
   201  (["RatEq","solve_rat_equation"],
   202    [("#Given" ,["equality e_e","solveFor v_v"]),
   203    ("#Where" ,["(e_e::bool) is_ratequation_in (v_::real)"]),
   204    ("#Find"  ,["solutions v_i"])
   205   ],
   206    {rew_ord'="termlessI",
   207     rls'=rateq_erls,
   208     srls=e_rls,
   209     prls=RatEq_prls,
   210     calc=[],
   211     crls=RatEq_crls, nrls=norm_Rational},
   212    "Script Solve_rat_equation  (e_e::bool) (v_::real) =                   " ^
   213     "(let e_e = ((Repeat(Try (Rewrite_Set RatEq_simplify      True))) @@  " ^
   214     "           (Repeat(Try (Rewrite_Set norm_Rational      False))) @@  " ^
   215     "           (Repeat(Try (Rewrite_Set common_nominator_p False))) @@  " ^
   216     "           (Repeat(Try (Rewrite_Set RatEq_eliminate     True)))) e_;" ^
   217     " (L_::bool list) =  (SubProblem (RatEq_,[univariate,equation],      " ^
   218     "                [no_met]) [bool_ e_e, real_ v_])                     " ^
   219     " in Check_elementwise L_ {(v_::real). Assumptions})"
   220    ));
   221 
   222 calclist':= overwritel (!calclist', 
   223    [("is_ratequation_in", ("RatEq.is_ratequation_in", 
   224 			   eval_is_ratequation_in ""))
   225     ]);
   226 *}
   227 
   228 end