src/sml/IsacKnowledge/Integrate.ML
author wneuper
Sun, 28 Aug 2005 16:09:45 +0200
branchstart_Take
changeset 347 d55ea685a8af
parent 346 08ec9d7553ac
child 375 49f28e3acadb
permissions -rw-r--r--
Scripts/scrtools#is_dsc improved
     1 (* tools for integration over the reals
     2    author: Walther Neuper
     3    050814, 08:51
     4    (c) due to copyright terms
     5 
     6 use"~/proto2/isac/src/sml/IsacKnowledge/Integrate.ML";
     7 *)
     8 
     9 (** interface isabelle -- isac **)
    10 
    11 theory' := overwritel (!theory', [("Integrate.thy",Integrate.thy)]);
    12 
    13 theorem' := overwritel (!theorem',
    14 [("integral_const",num_str integral_const),
    15  ("integral_var",num_str integral_var),
    16  ("integral_add",num_str integral_add),
    17  ("integral_mult",num_str integral_mult),
    18  ("call_for_new_c",num_str call_for_new_c),
    19  ("integral_pow",num_str integral_pow)
    20 ]);
    21 
    22 (** eval functions **)
    23 
    24 val c = Free ("c", HOLogic.realT);
    25 (*.create a new unique variable 'c..' in a term.*)
    26 fun new_c term = 
    27     let fun selc var = 
    28 	    case (explode o id_of) var of
    29 		"c"::[] => true
    30 	      |	"c"::"_"::is => (case (int_of_str o implode) is of
    31 				     Some _ => true
    32 				   | None => false)
    33               | _ => false;
    34 	fun get_coeff c = case (explode o id_of) c of
    35 	      		      "c"::"_"::is => (the o int_of_str o implode) is
    36 			    | _ => 0;
    37         val cs = filter selc (vars term);
    38     in 
    39 	case cs of
    40 	    [] => c
    41 	  | [c] => Free ("c_2", HOLogic.realT)
    42 	  | cs => 
    43 	    let val max_coeff = maxl (map get_coeff cs)
    44 	    in Free ("c_"^string_of_int (max_coeff + 1), HOLogic.realT) end
    45     end;
    46 
    47 (*("new_c", ("Integrate.new'_c", eval_new_c "new_c_"))*)
    48 fun eval_new_c _ _ (p as (Const ("Integrate.new'_c",_) $ t)) _ =
    49      Some ((term2str p) ^ " = " ^ term2str (new_c p),
    50 	  Trueprop $ (mk_equality (p, new_c p)))
    51   | eval_new_c _ _ _ _ = None;
    52 
    53 (*("is_f_x", ("Integrate.is'_f'_x", eval_is_f_x "is_f_x_"))*)
    54 fun eval_is_f_x _ _(p as (Const ("Integrate.is'_f'_x", _)
    55 					   $ arg)) _ =
    56     if is_f_x arg
    57     then Some ((term2str p) ^ " = True",
    58 	       Trueprop $ (mk_equality (p, HOLogic.true_const)))
    59     else Some ((term2str p) ^ " = False",
    60 	       Trueprop $ (mk_equality (p, HOLogic.false_const)))
    61   | eval_is_f_x _ _ _ _ = None;
    62 
    63 calclist':= overwritel (!calclist', 
    64    [("new_c", ("Integrate.new'_c", eval_new_c "new_c_")),
    65     ("is_f_x", ("Integrate.is'_f'_x", eval_is_f_x "is_f_idextifier_"))
    66     ]);
    67 
    68 (** rulesets **)
    69 
    70 val integration_rules = 
    71     prep_rls (Rls {id="integration_rules", preconds = [], 
    72 		   rew_ord = ("termlessI",termlessI), 
    73 		   erls = Rls {id="conditions_in_integration_rules", 
    74 			       preconds = [], 
    75 			       rew_ord = ("termlessI",termlessI), 
    76 			       erls = Erls, 
    77 			       srls = Erls, calc = [],
    78 			       rules = [(*for rewriting conditions in Thm's*)
    79 					Calc ("Atools.occurs'_in", 
    80 					      eval_occurs_in "#occurs_in_"),
    81 					Thm ("not_true",num_str not_true),
    82 					Thm ("not_false",not_false)
    83 					],
    84 			       scr = EmptyScr}, 
    85 		   srls = Erls, calc = [],
    86 		   rules = [
    87 			    Thm ("integral_const",num_str integral_const),
    88 			    Thm ("integral_var",num_str integral_var),
    89 			    Thm ("integral_add",num_str integral_add),
    90 			    Thm ("integral_mult",num_str integral_mult),
    91 			    Thm ("integral_pow",num_str integral_pow),
    92 			    Calc ("op +", eval_binop "#add_")(*for n+1*)
    93 			    ],
    94 		   scr = EmptyScr});
    95 val add_new_c = 
    96     prep_rls (Seq {id="add_new_c", preconds = [], 
    97 		   rew_ord = ("termlessI",termlessI), 
    98 		   erls = Rls {id="conditions_in_add_new_c", 
    99 			       preconds = [], 
   100 			       rew_ord = ("termlessI",termlessI), 
   101 			       erls = Erls, 
   102 			       srls = Erls, calc = [],
   103 			       rules = [Calc ("Tools.matches", eval_matches""),
   104 					Calc ("Integrate.is'_f'_x", 
   105 					 eval_is_f_x "is_f_x_"),
   106 					Thm ("not_true",num_str not_true),
   107 					Thm ("not_false",num_str not_false)
   108 					],
   109 			       scr = EmptyScr}, 
   110 		   srls = Erls, calc = [],
   111 		   rules = [ Thm ("call_for_new_c", num_str call_for_new_c),
   112 			     Calc("Integrate.new'_c", eval_new_c "new_c_")
   113 			    ],
   114 		   scr = EmptyScr});
   115 val integration = 
   116     prep_rls (Seq {id="integration", preconds = [], 
   117 		   rew_ord = ("termlessI",termlessI), 
   118 		   erls = Rls {id="conditions_in_integration", 
   119 			       preconds = [], 
   120 			       rew_ord = ("termlessI",termlessI), 
   121 			       erls = Erls, 
   122 			       srls = Erls, calc = [],
   123 			       rules = [],
   124 			       scr = EmptyScr}, 
   125 		   srls = Erls, calc = [],
   126 		   rules = [ Rls_ integration_rules,
   127 			     Rls_ add_new_c,
   128 			     Rls_ norm_Poly
   129 			    ],
   130 		   scr = EmptyScr});
   131 ruleset' := overwritel (!ruleset', [("integration_rules", integration_rules),
   132 				    ("add_new_c", add_new_c),
   133 				    ("integration", integration)]);
   134 
   135 (** problems **)
   136 
   137 store_pbt
   138  (prep_pbt Integrate.thy
   139  (["integrate","function"],
   140   [("#Given" ,["functionTerm f_", "integrateBy v_"]),
   141    ("#Find"  ,["antiDerivative F_"])
   142   ],
   143   append_rls "e_rls" e_rls [(*for preds in where_*)], 
   144   Some "Integrate (f_, v_)", 
   145   [["Diff","integration"]]));
   146  
   147 store_pbt
   148  (prep_pbt Integrate.thy
   149  (["named","integrate","function"],
   150   [("#Given" ,["functionTerm f_", "integrateBy v_"]),
   151    ("#Find"  ,["antiDerivativeName F_"])
   152   ],
   153   append_rls "e_rls" e_rls [(*for preds in where_*)], 
   154   Some "Integrate (f_, v_)", 
   155   [["Diff","integration","named"]]));
   156  
   157 (** methods **)
   158 
   159 store_met
   160     (prep_met Integrate.thy
   161 	      (["Diff","integration"],
   162 	       [("#Given" ,["functionTerm f_", "integrateBy v_"]),
   163 		("#Find"  ,["antiDerivative F_"])
   164 		],
   165 	       {rew_ord'="tless_true", rls'=Atools_erls, calc = [], 
   166 		srls = e_rls, 
   167 		prls=e_rls,
   168 	     crls = Atools_erls, nrls = e_rls},
   169 "Script IntegrationScript (f_::real) (v_::real) =                \
   170 \  (let t_ = Take (Integral f_ D v_)                             \
   171 \   in (Rewrite_Set_Inst [(bdv,v_)] integration False) (t_::real))"
   172 ));
   173     
   174 store_met
   175     (prep_met Integrate.thy
   176 	      (["Diff","integration","named"],
   177 	       [("#Given" ,["functionTerm f_", "integrateBy v_"]),
   178 		("#Find"  ,["antiDerivativeName F_"])
   179 		],
   180 	       {rew_ord'="tless_true", rls'=Atools_erls, calc = [], 
   181 		srls = e_rls, 
   182 		prls=e_rls,
   183 		crls = Atools_erls, nrls = e_rls},
   184 "Script NamedIntegrationScript (f_::real) (v_::real) (F_::real=>real) = \
   185 \  (let t_ = Take (F_ v_ = Integral f_ D v_)                         \
   186 \   in (Rewrite_Set_Inst [(bdv,v_)] integration False) t_)"
   187  ));
   188