src/Tools/isac/Knowledge/Integrate.thy
changeset 60586 007ef64dbb08
parent 60515 03e19793d81e
child 60587 8af797c555a8
equal deleted inserted replaced
60585:b7071d1dd263 60586:007ef64dbb08
   111 
   111 
   112 (*.rulesets for integration.*)
   112 (*.rulesets for integration.*)
   113 val integration_rules = 
   113 val integration_rules = 
   114   Rule_Def.Repeat {id="integration_rules", preconds = [], 
   114   Rule_Def.Repeat {id="integration_rules", preconds = [], 
   115     rew_ord = ("termlessI",termlessI), 
   115     rew_ord = ("termlessI",termlessI), 
   116     erls = Rule_Def.Repeat {id="conditions_in_integration_rules", 
   116     asm_rls = Rule_Def.Repeat {id="conditions_in_integration_rules", 
   117    	  preconds = [], 
   117    	  preconds = [], 
   118    	  rew_ord = ("termlessI",termlessI), 
   118    	  rew_ord = ("termlessI",termlessI), 
   119    	  erls = Rule_Set.Empty, 
   119    	  asm_rls = Rule_Set.Empty, 
   120    	  srls = Rule_Set.Empty, calc = [], errpatts = [],
   120    	  prog_rls = Rule_Set.Empty, calc = [], errpatts = [],
   121    	  rules = [(*for rewriting conditions in Thm's*)
   121    	  rules = [(*for rewriting conditions in Thm's*)
   122    		   \<^rule_eval>\<open>Prog_Expr.occurs_in\<close> (Prog_Expr.eval_occurs_in "#occurs_in_"),
   122    		   \<^rule_eval>\<open>Prog_Expr.occurs_in\<close> (Prog_Expr.eval_occurs_in "#occurs_in_"),
   123    		   \<^rule_thm>\<open>not_true\<close>,
   123    		   \<^rule_thm>\<open>not_true\<close>,
   124    		   \<^rule_thm>\<open>not_false\<close>],
   124    		   \<^rule_thm>\<open>not_false\<close>],
   125    	  scr = Rule.Empty_Prog}, 
   125    	  program = Rule.Empty_Prog}, 
   126     srls = Rule_Set.Empty, calc = [], errpatts = [],
   126     prog_rls = Rule_Set.Empty, calc = [], errpatts = [],
   127     rules = [
   127     rules = [
   128    	  \<^rule_thm>\<open>integral_const\<close>,
   128    	  \<^rule_thm>\<open>integral_const\<close>,
   129    	  \<^rule_thm>\<open>integral_var\<close>,
   129    	  \<^rule_thm>\<open>integral_var\<close>,
   130    	  \<^rule_thm>\<open>integral_add\<close>,
   130    	  \<^rule_thm>\<open>integral_add\<close>,
   131    	  \<^rule_thm>\<open>integral_mult\<close>,
   131    	  \<^rule_thm>\<open>integral_mult\<close>,
   132    	  \<^rule_thm>\<open>integral_pow\<close>,
   132    	  \<^rule_thm>\<open>integral_pow\<close>,
   133    	  \<^rule_eval>\<open>plus\<close> (**)(Calc_Binop.numeric "#add_")(*for n+1*)],
   133    	  \<^rule_eval>\<open>plus\<close> (**)(Calc_Binop.numeric "#add_")(*for n+1*)],
   134     scr = Rule.Empty_Prog};
   134     program = Rule.Empty_Prog};
   135 \<close>
   135 \<close>
   136 ML \<open>
   136 ML \<open>
   137 val add_new_c = 
   137 val add_new_c = 
   138   Rule_Set.Sequence {id="add_new_c", preconds = [], 
   138   Rule_Set.Sequence {id="add_new_c", preconds = [], 
   139     rew_ord = ("termlessI",termlessI), 
   139     rew_ord = ("termlessI",termlessI), 
   140     erls = Rule_Def.Repeat {id="conditions_in_add_new_c", 
   140     asm_rls = Rule_Def.Repeat {id="conditions_in_add_new_c", 
   141       preconds = [], rew_ord = ("termlessI",termlessI), erls = Rule_Set.Empty, 
   141       preconds = [], rew_ord = ("termlessI",termlessI), asm_rls = Rule_Set.Empty, 
   142       srls = Rule_Set.Empty, calc = [], errpatts = [],
   142       prog_rls = Rule_Set.Empty, calc = [], errpatts = [],
   143       rules = [
   143       rules = [
   144         \<^rule_eval>\<open>Prog_Expr.matches\<close> (Prog_Expr.eval_matches""),
   144         \<^rule_eval>\<open>Prog_Expr.matches\<close> (Prog_Expr.eval_matches""),
   145    	    \<^rule_eval>\<open>Integrate.is_f_x\<close> (eval_is_f_x "is_f_x_"),
   145    	    \<^rule_eval>\<open>Integrate.is_f_x\<close> (eval_is_f_x "is_f_x_"),
   146    	    \<^rule_thm>\<open>not_true\<close>,
   146    	    \<^rule_thm>\<open>not_true\<close>,
   147    	    \<^rule_thm>\<open>not_false\<close>],
   147    	    \<^rule_thm>\<open>not_false\<close>],
   148       scr = Rule.Empty_Prog}, 
   148       program = Rule.Empty_Prog}, 
   149     srls = Rule_Set.Empty, calc = [], errpatts = [],
   149     prog_rls = Rule_Set.Empty, calc = [], errpatts = [],
   150     rules = [ (*\<^rule_thm>\<open>call_for_new_c\<close>,*)
   150     rules = [ (*\<^rule_thm>\<open>call_for_new_c\<close>,*)
   151       Rule.Cal1 ("Integrate.add_new_c", eval_add_new_c "new_c_")],
   151       Rule.Cal1 ("Integrate.add_new_c", eval_add_new_c "new_c_")],
   152     scr = Rule.Empty_Prog};
   152     program = Rule.Empty_Prog};
   153 \<close>
   153 \<close>
   154 ML \<open>
   154 ML \<open>
   155 
   155 
   156 (*.rulesets for simplifying Integrals.*)
   156 (*.rulesets for simplifying Integrals.*)
   157 
   157 
   158 (*.for simplify_Integral adapted from 'norm_Rational_rls'.*)
   158 (*.for simplify_Integral adapted from 'norm_Rational_rls'.*)
   159 val norm_Rational_rls_noadd_fractions = 
   159 val norm_Rational_rls_noadd_fractions = 
   160   Rule_Def.Repeat {id = "norm_Rational_rls_noadd_fractions", preconds = [], 
   160   Rule_Def.Repeat {id = "norm_Rational_rls_noadd_fractions", preconds = [], 
   161     rew_ord = ("dummy_ord",Rewrite_Ord.function_empty), 
   161     rew_ord = ("dummy_ord",Rewrite_Ord.function_empty), 
   162     erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
   162     asm_rls = norm_rat_erls, prog_rls = Rule_Set.Empty, calc = [], errpatts = [],
   163     rules = [(*Rule.Rls_ add_fractions_p_rls,!!!*)
   163     rules = [(*Rule.Rls_ add_fractions_p_rls,!!!*)
   164   	  Rule.Rls_ (*rat_mult_div_pow original corrected WN051028*)
   164   	  Rule.Rls_ (*rat_mult_div_pow original corrected WN051028*)
   165   		(Rule_Def.Repeat {id = "rat_mult_div_pow", preconds = [], 
   165   		(Rule_Def.Repeat {id = "rat_mult_div_pow", preconds = [], 
   166   		   rew_ord = ("dummy_ord",Rewrite_Ord.function_empty), 
   166   		   rew_ord = ("dummy_ord",Rewrite_Ord.function_empty), 
   167   		   erls = Rule_Set.append_rules "Rule_Set.empty-is_polyexp" Rule_Set.empty
   167   		   asm_rls = Rule_Set.append_rules "Rule_Set.empty-is_polyexp" Rule_Set.empty
   168   				 [\<^rule_eval>\<open>is_polyexp\<close> (eval_is_polyexp "")],
   168   				 [\<^rule_eval>\<open>is_polyexp\<close> (eval_is_polyexp "")],
   169   			 srls = Rule_Set.Empty, calc = [], errpatts = [],
   169   			 prog_rls = Rule_Set.Empty, calc = [], errpatts = [],
   170   		   rules = [
   170   		   rules = [
   171            \<^rule_thm>\<open>rat_mult\<close>, (*"?a / ?b * (?c / ?d) = ?a * ?c / (?b * ?d)"*)
   171            \<^rule_thm>\<open>rat_mult\<close>, (*"?a / ?b * (?c / ?d) = ?a * ?c / (?b * ?d)"*)
   172   	       \<^rule_thm>\<open>rat_mult_poly_l\<close>, (*"?c is_polyexp ==> ?c * (?a / ?b) = ?c * ?a / ?b"*)
   172   	       \<^rule_thm>\<open>rat_mult_poly_l\<close>, (*"?c is_polyexp ==> ?c * (?a / ?b) = ?c * ?a / ?b"*)
   173   	       \<^rule_thm>\<open>rat_mult_poly_r\<close>, (*"?c is_polyexp ==> ?a / ?b * ?c = ?a * ?c / ?b"*)
   173   	       \<^rule_thm>\<open>rat_mult_poly_r\<close>, (*"?c is_polyexp ==> ?a / ?b * ?c = ?a * ?c / ?b"*)
   174   
   174   
   176   	       \<^rule_thm>\<open>divide_divide_eq_right\<close>, (*"?x / (?y / ?z) = ?x * ?z / ?y"*)
   176   	       \<^rule_thm>\<open>divide_divide_eq_right\<close>, (*"?x / (?y / ?z) = ?x * ?z / ?y"*)
   177   	       \<^rule_thm>\<open>divide_divide_eq_left\<close>, (*"?x / ?y / ?z = ?x / (?y * ?z)"*)
   177   	       \<^rule_thm>\<open>divide_divide_eq_left\<close>, (*"?x / ?y / ?z = ?x / (?y * ?z)"*)
   178   	       \<^rule_eval>\<open>divide\<close> (Prog_Expr.eval_cancel "#divide_e"),
   178   	       \<^rule_eval>\<open>divide\<close> (Prog_Expr.eval_cancel "#divide_e"),
   179   	      
   179   	      
   180   	       \<^rule_thm>\<open>rat_power\<close>], (*"(?a / ?b)  \<up>  ?n = ?a  \<up>  ?n / ?b  \<up>  ?n"*)
   180   	       \<^rule_thm>\<open>rat_power\<close>], (*"(?a / ?b)  \<up>  ?n = ?a  \<up>  ?n / ?b  \<up>  ?n"*)
   181         scr = Rule.Empty_Prog}),
   181         program = Rule.Empty_Prog}),
   182   		Rule.Rls_ make_rat_poly_with_parentheses,
   182   		Rule.Rls_ make_rat_poly_with_parentheses,
   183   		Rule.Rls_ cancel_p_rls,(*FIXME:cancel_p does NOT order sometimes*)
   183   		Rule.Rls_ cancel_p_rls,(*FIXME:cancel_p does NOT order sometimes*)
   184   		Rule.Rls_ rat_reduce_1],
   184   		Rule.Rls_ rat_reduce_1],
   185     scr = Rule.Empty_Prog};
   185     program = Rule.Empty_Prog};
   186 
   186 
   187 (*.for simplify_Integral adapted from 'norm_Rational'.*)
   187 (*.for simplify_Integral adapted from 'norm_Rational'.*)
   188 val norm_Rational_noadd_fractions = 
   188 val norm_Rational_noadd_fractions = 
   189   Rule_Set.Sequence {id = "norm_Rational_noadd_fractions", preconds = [], 
   189   Rule_Set.Sequence {id = "norm_Rational_noadd_fractions", preconds = [], 
   190     rew_ord = ("dummy_ord",Rewrite_Ord.function_empty), 
   190     rew_ord = ("dummy_ord",Rewrite_Ord.function_empty), 
   191     erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
   191     asm_rls = norm_rat_erls, prog_rls = Rule_Set.Empty, calc = [], errpatts = [],
   192     rules = [Rule.Rls_ discard_minus,
   192     rules = [Rule.Rls_ discard_minus,
   193   		Rule.Rls_ rat_mult_poly,(* removes double fractions like a/b/c    *)
   193   		Rule.Rls_ rat_mult_poly,(* removes double fractions like a/b/c    *)
   194   		Rule.Rls_ make_rat_poly_with_parentheses, (*WN0510 also in(#)below*)
   194   		Rule.Rls_ make_rat_poly_with_parentheses, (*WN0510 also in(#)below*)
   195   		Rule.Rls_ cancel_p_rls, (*FIXME.MG:cancel_p does NOT order sometim*)
   195   		Rule.Rls_ cancel_p_rls, (*FIXME.MG:cancel_p does NOT order sometim*)
   196   		Rule.Rls_ norm_Rational_rls_noadd_fractions,(* the main rls (#)   *)
   196   		Rule.Rls_ norm_Rational_rls_noadd_fractions,(* the main rls (#)   *)
   197   		Rule.Rls_ discard_parentheses1], (* mult only                       *)
   197   		Rule.Rls_ discard_parentheses1], (* mult only                       *)
   198     scr = Rule.Empty_Prog};
   198     program = Rule.Empty_Prog};
   199 
   199 
   200 (*.simplify terms before and after Integration such that  
   200 (*.simplify terms before and after Integration such that  
   201    ..a.x^2/2 + b.x^3/3.. is made to ..a/2.x^2 + b/3.x^3.. (and NO
   201    ..a.x^2/2 + b.x^3/3.. is made to ..a/2.x^2 + b/3.x^3.. (and NO
   202    common denominator as done by norm_Rational or make_ratpoly_in.
   202    common denominator as done by norm_Rational or make_ratpoly_in.
   203    This is a copy from 'make_ratpoly_in' with respective reduction of rules and
   203    This is a copy from 'make_ratpoly_in' with respective reduction of rules and
   213 		rule_thm>\<open>add_divide_distrib\<close> (*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"*)*)
   213 		rule_thm>\<open>add_divide_distrib\<close> (*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"*)*)
   214 		];
   214 		];
   215 val simplify_Integral = 
   215 val simplify_Integral = 
   216   Rule_Set.Sequence {id = "simplify_Integral", preconds = []:term list, 
   216   Rule_Set.Sequence {id = "simplify_Integral", preconds = []:term list, 
   217     rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
   217     rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
   218     erls = Atools_erls, srls = Rule_Set.Empty,
   218     asm_rls = Atools_erls, prog_rls = Rule_Set.Empty,
   219     calc = [],  errpatts = [],
   219     calc = [],  errpatts = [],
   220     rules = [
   220     rules = [
   221       \<^rule_thm>\<open>distrib_right\<close>, (*"(?z1.0 + ?z2.0) * ?w = ?z1.0 * ?w + ?z2.0 * ?w"*)
   221       \<^rule_thm>\<open>distrib_right\<close>, (*"(?z1.0 + ?z2.0) * ?w = ?z1.0 * ?w + ?z2.0 * ?w"*)
   222 	    \<^rule_thm>\<open>add_divide_distrib\<close>, (*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"*)
   222 	    \<^rule_thm>\<open>add_divide_distrib\<close>, (*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"*)
   223 	     (*^^^^^ *1* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
   223 	     (*^^^^^ *1* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
   225 	    Rule.Rls_ order_add_mult_in,
   225 	    Rule.Rls_ order_add_mult_in,
   226 	    Rule.Rls_ discard_parentheses,
   226 	    Rule.Rls_ discard_parentheses,
   227 	    (*Rule.Rls_ collect_bdv, from make_polynomial_in*)
   227 	    (*Rule.Rls_ collect_bdv, from make_polynomial_in*)
   228 	    Rule.Rls_ separate_bdv2,
   228 	    Rule.Rls_ separate_bdv2,
   229 	    \<^rule_eval>\<open>divide\<close> (Prog_Expr.eval_cancel "#divide_e")],
   229 	    \<^rule_eval>\<open>divide\<close> (Prog_Expr.eval_cancel "#divide_e")],
   230     scr = Rule.Empty_Prog};      
   230     program = Rule.Empty_Prog};      
   231 
   231 
   232 val integration =
   232 val integration =
   233   Rule_Set.Sequence {
   233   Rule_Set.Sequence {
   234      id="integration", preconds = [], rew_ord = ("termlessI",termlessI), 
   234      id="integration", preconds = [], rew_ord = ("termlessI",termlessI), 
   235   	 erls = Rule_Def.Repeat {
   235   	 asm_rls = Rule_Def.Repeat {
   236        id="conditions_in_integration",  preconds = [], rew_ord = ("termlessI",termlessI), 
   236        id="conditions_in_integration",  preconds = [], rew_ord = ("termlessI",termlessI), 
   237   		 erls = Rule_Set.Empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
   237   		 asm_rls = Rule_Set.Empty, prog_rls = Rule_Set.Empty, calc = [], errpatts = [],
   238   		 rules = [], scr = Rule.Empty_Prog}, 
   238   		 rules = [], program = Rule.Empty_Prog}, 
   239   	 srls = Rule_Set.Empty, calc = [], errpatts = [],
   239   	 prog_rls = Rule_Set.Empty, calc = [], errpatts = [],
   240   	 rules = [
   240   	 rules = [
   241       Rule.Rls_ integration_rules,
   241       Rule.Rls_ integration_rules,
   242   		 Rule.Rls_ add_new_c,
   242   		 Rule.Rls_ add_new_c,
   243   		 Rule.Rls_ simplify_Integral],
   243   		 Rule.Rls_ simplify_Integral],
   244   	 scr = Rule.Empty_Prog};
   244   	 program = Rule.Empty_Prog};
   245 
   245 
   246 val prep_rls' = Auto_Prog.prep_rls @{theory};
   246 val prep_rls' = Auto_Prog.prep_rls @{theory};
   247 \<close>
   247 \<close>
   248 rule_set_knowledge
   248 rule_set_knowledge
   249   integration_rules = \<open>prep_rls' integration_rules\<close> and
   249   integration_rules = \<open>prep_rls' integration_rules\<close> and
   280     t_t = Take (Integral f_f D v_v)
   280     t_t = Take (Integral f_f D v_v)
   281   in
   281   in
   282     (Rewrite_Set_Inst [(''bdv'', v_v)] ''integration'') t_t)"
   282     (Rewrite_Set_Inst [(''bdv'', v_v)] ''integration'') t_t)"
   283 
   283 
   284 method met_diffint : "diff/integration" =
   284 method met_diffint : "diff/integration" =
   285   \<open>{rew_ord'="tless_true", rls'=Atools_erls, calc = [], srls = Rule_Set.empty, prls=Rule_Set.empty,
   285   \<open>{rew_ord="tless_true", rls'=Atools_erls, calc = [], prog_rls = Rule_Set.empty, where_rls=Rule_Set.empty,
   286 	  crls = Atools_erls, errpats = [], nrls = Rule_Set.empty}\<close>
   286 	  crls = Atools_erls, errpats = [], rew_rls = Rule_Set.empty}\<close>
   287   Program: integrate.simps
   287   Program: integrate.simps
   288   Given: "functionTerm f_f" "integrateBy v_v"
   288   Given: "functionTerm f_f" "integrateBy v_v"
   289   Find: "antiDerivative F_F"
   289   Find: "antiDerivative F_F"
   290 
   290 
   291 partial_function (tailrec) intergrate_named :: "real \<Rightarrow> real \<Rightarrow> (real \<Rightarrow> real) \<Rightarrow> bool"
   291 partial_function (tailrec) intergrate_named :: "real \<Rightarrow> real \<Rightarrow> (real \<Rightarrow> real) \<Rightarrow> bool"
   297     (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''simplify_Integral'')) #>
   297     (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''simplify_Integral'')) #>
   298     (Rewrite_Set_Inst [(''bdv'', v_v)] ''integration'')
   298     (Rewrite_Set_Inst [(''bdv'', v_v)] ''integration'')
   299     ) t_t)"
   299     ) t_t)"
   300 
   300 
   301 method met_diffint_named : "diff/integration/named" =
   301 method met_diffint_named : "diff/integration/named" =
   302   \<open>{rew_ord'="tless_true", rls'=Atools_erls, calc = [], srls = Rule_Set.empty, prls=Rule_Set.empty,
   302   \<open>{rew_ord="tless_true", rls'=Atools_erls, calc = [], prog_rls = Rule_Set.empty, where_rls=Rule_Set.empty,
   303     crls = Atools_erls, errpats = [], nrls = Rule_Set.empty}\<close>
   303     crls = Atools_erls, errpats = [], rew_rls = Rule_Set.empty}\<close>
   304   Program: intergrate_named.simps
   304   Program: intergrate_named.simps
   305   Given: "functionTerm f_f" "integrateBy v_v"
   305   Given: "functionTerm f_f" "integrateBy v_v"
   306   Find: "antiDerivativeName F_F"
   306   Find: "antiDerivativeName F_F"
   307 
   307 
   308 ML \<open>
   308 ML \<open>