
neuper@42301: (* Title:  Build_Inverse_Z_Transform
neuper@42279:    Author: Jan Rocnik
neuper@42279:    (c) copyright due to lincense terms.
neuper@42279: 12345678901234567890123456789012345678901234567890123456789012345678901234567890
neuper@42279:         10        20        30        40        50        60        70        80
neuper@42279: *)
neuper@42279: 
jan@42298: theory Build_Inverse_Z_Transform imports Isac
neuper@42289:   
neuper@42289: begin
neuper@42279: 
neuper@42289: text{* We stepwise build Inverse_Z_Transform.thy as an exercise.
jan@42299:   Because subsection "Stepwise Check the Program" requires 
jan@42299:   Inverse_Z_Transform.thy as a subtheory of Isac.thy, the setup has been changed 
jan@42299:   from "theory Inverse_Z_Transform imports Isac begin.." to the above.
neuper@42279: 
neuper@42279:   ATTENTION WITH NAMES OF IDENTIFIERS WHEN GOING INTO INTERNALS:
neuper@42279:   Here in this theory there are the internal names twice, for instance we have
neuper@42279:   (Thm.derivation_name @{thm rule1} = "Build_Inverse_Z_Transform.rule1") = true;
neuper@42279:   but actually in us will be "Inverse_Z_Transform.rule1"
neuper@42279: *}
neuper@42279: ML {*val thy = @{theory Isac};*}
neuper@42279: 
neuper@42279: 
neuper@42279: section {*trials towards Z transform *}
neuper@42279: text{*===============================*}
neuper@42279: subsection {*terms*}
neuper@42279: ML {*
neuper@42279: @{term "1 < || z ||"};
neuper@42279: @{term "z / (z - 1)"};
neuper@42279: @{term "-u -n - 1"};
neuper@42279: @{term "-u [-n - 1]"}; (*[ ] denotes lists !!!*)
neuper@42279: @{term "z /(z - 1) = -u [-n - 1]"};Isac
neuper@42279: @{term "1 < || z || ==> z / (z - 1) = -u [-n - 1]"};
neuper@42279: term2str @{term "1 < || z || ==> z / (z - 1) = -u [-n - 1]"};
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: (*alpha -->  "</alpha>" *)
neuper@42279: @{term "\<alpha> "};
neuper@42279: @{term "\<delta> "};
neuper@42279: @{term "\<phi> "};
neuper@42279: @{term "\<rho> "};
neuper@42279: term2str @{term "\<rho> "};
neuper@42279: *}
neuper@42279: 
neuper@42279: subsection {*rules*}
neuper@42279: (*axiomatization "z / (z - 1) = -u [-n - 1]" Illegal variable name: "z / (z - 1) = -u [-n - 1]" *)
neuper@42279: (*definition     "z / (z - 1) = -u [-n - 1]" Bad head of lhs: existing constant "op /"*)
neuper@42279: axiomatization where 
neuper@42279:   rule1: "1 = \<delta>[n]" and
neuper@42279:   rule2: "|| z || > 1 ==> z / (z - 1) = u [n]" and
neuper@42279:   rule3: "|| z || < 1 ==> z / (z - 1) = -u [-n - 1]" and 
neuper@42279:   rule4: "|| z || > || \<alpha> || ==> z / (z - \<alpha>) = \<alpha>^^^n * u [n]" and
neuper@42279:   rule5: "|| z || < || \<alpha> || ==> z / (z - \<alpha>) = -(\<alpha>^^^n) * u [-n - 1]" and
neuper@42279:   rule6: "|| z || > 1 ==> z/(z - 1)^^^2 = n * u [n]"
neuper@42279: ML {*
neuper@42279: @{thm rule1};
neuper@42279: @{thm rule2};
neuper@42279: @{thm rule3};
neuper@42279: @{thm rule4};
neuper@42279: *}
neuper@42279: 
neuper@42279: subsection {*apply rules*}
neuper@42279: ML {*
neuper@42279: val inverse_Z = append_rls "inverse_Z" e_rls
neuper@42279:   [ Thm  ("rule3",num_str @{thm rule3}),
neuper@42279:     Thm  ("rule4",num_str @{thm rule4}),
neuper@42279:     Thm  ("rule1",num_str @{thm rule1})   
neuper@42279:   ];
neuper@42279: 
neuper@42279: val t = str2term "z / (z - 1) + z / (z - \<alpha>) + 1";
neuper@42279: val SOME (t', asm) = rewrite_set_ thy true inverse_Z t;
neuper@42279: term2str t' = "z / (z - ?\<delta> [?n]) + z / (z - \<alpha>) + ?\<delta> [?n]"; (*attention rule1 !!!*)
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: val (thy, ro, er) = (@{theory Isac}, tless_true, eval_rls);
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: val SOME (t, asm1) = rewrite_ thy ro er true (num_str @{thm rule3}) t;
neuper@42279: term2str t = "- ?u [- ?n - 1] + z / (z - \<alpha>) + 1"; (*- real *)
neuper@42301: term2str t;*}
neuper@42279: ML {*
neuper@42279: val SOME (t, asm2) = rewrite_ thy ro er true (num_str @{thm rule4}) t;
neuper@42279: term2str t = "- ?u [- ?n - 1] + \<alpha> ^^^ ?n * ?u [?n] + 1"; (*- real *)
neuper@42279: term2str t;
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: val SOME (t, asm3) = rewrite_ thy ro er true (num_str @{thm rule1}) t;
neuper@42279: term2str t = "- ?u [- ?n - 1] + \<alpha> ^^^ ?n * ?u [?n] + ?\<delta> [?n]"; (*- real *)
neuper@42279: term2str t;
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: terms2str (asm1 @ asm2 @ asm3);
neuper@42279: *}
neuper@42279: 
jan@42296: section {*Prepare steps for CTP-based programming language*}
jan@42296: text{*TODO insert Calculation (Referenz?!)
jan@42296: 
jan@42296: The goal... realized in sections below, in Sect.\ref{spec-meth} and Sect.\ref{prog-steps} 
jan@42296: 
jan@42296: the reader is advised to jump between the subsequent subsections and the respective steps in Sect.\ref{prog-steps} 
jan@42296: 
jan@42296: *}
jan@42296: subsection {*prepare expression \label{prep-expr}*}
neuper@42279: ML {*
neuper@42279: val ctxt = ProofContext.init_global @{theory Isac};
neuper@42279: val ctxt = declare_constraints' [@{term "z::real"}] ctxt;
neuper@42279: 
neuper@42279: val SOME fun1 = parseNEW ctxt "X z = 3 / (z - 1/4 + -1/8 * z ^^^ -1)"; term2str fun1;
neuper@42279: val SOME fun1' = parseNEW ctxt "X z = 3 / (z - 1/4 + -1/8 * (1/z))"; term2str fun1';
neuper@42279: *}
neuper@42279: 
jan@42298: subsubsection {*multply with z*}
neuper@42279: axiomatization where
neuper@42279:   ruleZY: "(X z = a / b) = (X' z = a / (z * b))"
neuper@42279: 
neuper@42279: ML {*
neuper@42279: val (thy, ro, er) = (@{theory Isac}, tless_true, eval_rls);
neuper@42279: val SOME (fun2, asm1) = rewrite_ thy ro er true  @{thm ruleZY} fun1; term2str fun2;
neuper@42279: val SOME (fun2', asm1) = rewrite_ thy ro er true  @{thm ruleZY} fun1'; term2str fun2';
neuper@42279: 
neuper@42279: val SOME (fun3,_) = rewrite_set_ @{theory Isac} false norm_Rational fun2;
neuper@42279: term2str fun3; (*fails on x^^^(-1) TODO*)
neuper@42279: val SOME (fun3',_) = rewrite_set_ @{theory Isac} false norm_Rational fun2';
neuper@42279: term2str fun3'; (*OK*)
neuper@42289: *}
neuper@42279: 
jan@42298: subsubsection {*get argument of X': z is the variable the equation is solved for*}
jan@42298: text{*grep... Atools.thy, Tools.thy contain general utilities: eval_argument_in, eval_rhs, eval_lhs,...
jan@42298: 
jan@42298: grep -r "fun eva_" ... shows all functions witch can be used in a script.
jan@42298: lookup this files how to build and handle such functions.
jan@42298: 
jan@42298: the next section shows how to introduce such a function.
jan@42298: *}
jan@42298: 
neuper@42302: subsubsection {*Decompose given term into lhs = rhs*}
neuper@42302: ML {*
neuper@42302:   val (_, expr) = HOLogic.dest_eq fun3'; term2str expr;
neuper@42302:   val (_, denom) = HOLogic.dest_bin "Rings.inverse_class.divide" (type_of expr) expr;
neuper@42302:   term2str denom = "-1 + -2 * z + 8 * z ^^^ 2";
neuper@42302: *}
neuper@42302: text {*we have rhs in the Script language, but we need a function 
neuper@42302:   which gets the denominator of a fraction*}
jan@42298: 
jan@42298: text{*---------------------------begin partial fractions snip--------------------------*}
jan@42298: 
jan@42298: subsubsection {*get the denominator out of a fraction*}
jan@42298: text {*get denominator should become a constant for the isabelle parser: *}
jan@42298: 
jan@42298: consts
neuper@42302:   get_denominator :: "real => real"
jan@42298: 
neuper@42302: text {* With the above definition we run into problems with parsing the Script InverseZTransform:
neuper@42302:   This leads to "ambiguous parse trees" and we avoid this by shifting the definition
neuper@42335:   to Rational.thy and re-building Isac.
neuper@42302:   ATTENTION: from now on Build_Inverse_Z_Transform mimics a build from scratch;
neuper@42302:   it only works due to re-building Isac several times (indicated explicityl).
neuper@42302: *}
jan@42300: 
jan@42298: ML {*
neuper@42301: (*("get_denominator", ("Rational.get_denominator", eval_get_denominator ""))*)
jan@42298: fun eval_get_denominator (thmid:string) _ 
neuper@42301: 		      (t as Const ("Rational.get_denominator", _) $
jan@42298:               (Const ("Rings.inverse_class.divide", _) $ num $
jan@42298:                 denom)) thy = 
neuper@42302:         SOME (mk_thmid thmid "" 
jan@42298:             (Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy)) denom) "", 
jan@42298: 	          Trueprop $ (mk_equality (t, denom)))
jan@42300:   | eval_get_denominator _ _ _ _ = NONE; 
jan@42299: 
jan@42298: *}
neuper@42302: text {* tests of eval_get_denominator see test/Knowledge/rational.sml*}
neuper@42289: 
jan@42297: 
jan@42297: text{*---------------------------end partial fractions snip--------------------------*}
neuper@42279: 
jan@42337: subsubsection {*get the numerator out of a fraction*}
jan@42337: text {*get dnumerator should also become a constant for the isabelle parser: *}
jan@42337: 
jan@42337: consts
jan@42337:   get_numerator :: "real => real"
jan@42337: 
jan@42337: ML {*
jan@42337: fun eval_get_numerator (thmid:string) _ 
jan@42337: 		      (t as Const ("Rational.get_numerator", _) $
jan@42337:               (Const ("Rings.inverse_class.divide", _) numerator
jan@42337:                 $ num $ )) thy = 
jan@42337:         SOME (mk_thmid thmid "" 
jan@42337:             (Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy)) denom) "", 
jan@42337: 	          Trueprop $ (mk_equality (t, denom)))
jan@42337:   | eval_get_numerator _ _ _ _ = NONE; 
jan@42337: 
jan@42337: *}
jan@42337: 
neuper@42279: subsection {*solve equation*}
neuper@42279: text {*this type of equation if too general for the present program*}
neuper@42279: ML {*
neuper@42279: "----------- Minisubplb/100-init-rootp (*OK*)bl.sml ---------------------";
neuper@42279: val denominator = parseNEW ctxt "z^^^2 - 1/4*z - 1/8 = 0";
neuper@42279: val fmz = ["equality (z^^^2 - 1/4*z - 1/8 = (0::real))", "solveFor z","solutions L"];
neuper@42279: val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
neuper@42279: (*                           ^^^^^^^^^^^^^^^^^^^^^^ TODO: ISAC determines type of eq*)
neuper@42279: *}
neuper@42279: text {*Does the Equation Match the Specification ?*}
neuper@42279: ML {*
neuper@42279: match_pbl fmz (get_pbt ["univariate","equation"]);
neuper@42279: *}
neuper@42279: ML {*Context.theory_name thy = "Isac"(*==================================================*)*}
neuper@42279: 
neuper@42279: ML {*
neuper@42303: val denominator = parseNEW ctxt "-1 + -2 * z + 8 * z ^^^ 2 = 0";
neuper@42279: val fmz =                                            (*specification*)
neuper@42303:   ["equality (-1 + -2 * z + 8 * z ^^^ 2 = (0::real))", (*equality*)
neuper@42279:    "solveFor z",                                     (*bound variable*)
neuper@42279:    "solutions L"];                                   (*identifier for solution*)
jan@42300: 
neuper@42279: val (dI',pI',mI') =
neuper@42303:   ("Isac", ["abcFormula","degree_2","polynomial","univariate","equation"], ["no_met"]);
neuper@42279: *}
neuper@42279: text {*Does the Other Equation Match the Specification ?*}
neuper@42279: ML {*
neuper@42303: match_pbl fmz (get_pbt ["abcFormula","degree_2","polynomial","univariate","equation"]);
neuper@42279: *}
neuper@42279: text {*Solve Equation Stepwise*}
neuper@42279: ML {*
neuper@42303: *}
neuper@42303: ML {*
neuper@42279: val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;         
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt =..,Check_elementwise "Assumptions")*)
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt;         
neuper@42279: val (p,_,f,nxt,_,pt) = me nxt p [] pt; f2str f;
neuper@42303: (*[z = 1 / 2, z = -1 / 4]*)
neuper@42279: show_pt pt; 
neuper@42279: val SOME f = parseNEW ctxt "[z=1/2, z=-1/4]";
neuper@42279: *}
neuper@42279: 
neuper@42279: subsection {*partial fraction decomposition*}
neuper@42279: subsubsection {*solution of the equation*}
neuper@42279: ML {*
neuper@42279: val SOME solutions = parseNEW ctxt "[z=1/2, z=-1/4]";
neuper@42279: term2str solutions;
neuper@42279: atomty solutions;
neuper@42279: *}
neuper@42279: 
neuper@42279: subsubsection {*get solutions out of list*}
neuper@42279: text {*in isac's CTP-based programming language: let$ $s_1 = NTH 1$ solutions; $s_2 = NTH 2...$*}
neuper@42279: ML {*
neuper@42279: val Const ("List.list.Cons", _) $ s_1 $ (Const ("List.list.Cons", _) $
neuper@42279:       s_2 $ Const ("List.list.Nil", _)) = solutions;
neuper@42279: term2str s_1;
neuper@42279: term2str s_2;
neuper@42279: *}
neuper@42279: 
neuper@42279: ML {* (*Solutions as Denominator --> Denominator1 = z - Zeropoint1, Denominator2 = z-Zeropoint2,...*)
neuper@42279: val xx = HOLogic.dest_eq s_1;
neuper@42279: val s_1' = HOLogic.mk_binop "Groups.minus_class.minus" xx;
neuper@42279: val xx = HOLogic.dest_eq s_2;
neuper@42279: val s_2' = HOLogic.mk_binop "Groups.minus_class.minus" xx;
neuper@42279: term2str s_1';
neuper@42279: term2str s_2';
neuper@42279: *}
neuper@42335: text {* for the programming language a function 
neuper@42335:   collecting all the above manipulations is helpful*}
neuper@42335: ML {*
neuper@42335: fun mk_minus_1 T = Free("-1", T); (*TODO DELETE WITH numbers_to_string*)
neuper@42335: fun flip_sign t = (*TODO improve for use in factors_from_solution: -(-1) etc*)
neuper@42335:   let val minus_1 = t |> type_of |> mk_minus_1
neuper@42335:   in HOLogic.mk_binop "Groups.times_class.times" (minus_1, t) end;
neuper@42335: fun fac_from_sol s =
neuper@42335:   let val (lhs, rhs) = HOLogic.dest_eq s
neuper@42335:   in HOLogic.mk_binop "Groups.plus_class.plus" (lhs, flip_sign rhs) end;
neuper@42335: *}
neuper@42335: ML {*
neuper@42335: e_term
neuper@42335: *}
neuper@42335: ML {*
neuper@42335: fun mk_prod prod [] =
neuper@42335:       if prod = e_term then error "mk_prod called with []" else prod
neuper@42335:   | mk_prod prod (t :: []) =
neuper@42335:       if prod = e_term then t else HOLogic.mk_binop "Groups.times_class.times" (prod, t)
neuper@42335:   | mk_prod prod (t1 :: t2 :: ts) =
neuper@42335:         if prod = e_term 
neuper@42335:         then 
neuper@42335:            let val p = HOLogic.mk_binop "Groups.times_class.times" (t1, t2)
neuper@42335:            in mk_prod p ts end 
neuper@42335:         else 
neuper@42335:            let val p = HOLogic.mk_binop "Groups.times_class.times" (prod, t1)
neuper@42335:            in mk_prod p (t2 :: ts) end 
neuper@42335: *}
neuper@42335: ML {*
neuper@42335: *}
neuper@42335: ML {*
neuper@42335: (*probably keept these test in test/Tools/isac/...
neuper@42335: (*mk_prod e_term [];*)
neuper@42335: 
neuper@42335: val prod = mk_prod e_term [str2term "x + 123"]; 
neuper@42335: term2str prod = "x + 123";
neuper@42335: 
neuper@42335: val sol = str2term "[z = 1 / 2, z = -1 / 4]";
neuper@42335: val sols = HOLogic.dest_list sol;
neuper@42335: val facs = map fac_from_sol sols;
neuper@42335: val prod = mk_prod e_term facs; 
neuper@42335: term2str prod = "(z + -1 * (1 / 2)) * (z + -1 * (-1 / 4))";
neuper@42335: 
neuper@42335: val prod = mk_prod e_term [str2term "x + 1", str2term "x + 2", str2term "x + 3"]; 
neuper@42335: term2str prod = "(x + 1) * (x + 2) * (x + 3)";
neuper@42335: *)
neuper@42335: 
neuper@42335: fun factors_from_solution sol = 
neuper@42335:   let val ts = HOLogic.dest_list sol
neuper@42335:   in mk_prod e_term (map fac_from_sol ts) end;
neuper@42335: (*
neuper@42335: val sol = str2term "[z = 1 / 2, z = -1 / 4]";
neuper@42335: val fs = factors_from_solution sol;
neuper@42335: term2str fs = "(z + -1 * (1 / 2)) * (z + -1 * (-1 / 4))"
neuper@42335: *)
neuper@42335: *}
neuper@42335: text {* This function needs to be packed such that it can be evaluated by the Lucas-Interpreter:
neuper@42335:   # shift these functions into the related Equation.thy
neuper@42335:   #  -- compare steps done with get_denominator above
neuper@42335:   *}
neuper@42335: ML {*
neuper@42335: (*("factors_from_solution", ("Equation.factors_from_solution", eval_factors_from_solution ""))*)
neuper@42335: fun eval_factors_from_solution (thmid:string) _ t thy =
neuper@42335:     (let val prod = factors_from_solution t
neuper@42335:      in SOME (mk_thmid thmid "" 
neuper@42335:             (Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy)) prod) "", 
neuper@42335: 	          Trueprop $ (mk_equality (t, prod)))
neuper@42335:      end)
neuper@42335:      handle _ => NONE; 
neuper@42335: *}
neuper@42279: 
neuper@42279: subsubsection {*build expression*}
neuper@42279: text {*in isac's CTP-based programming language: let s_1 = Take numerator / (s_1 * s_2)*}
neuper@42279: ML {*
neuper@42279: (*The Main Denominator is the multiplikation of the partial fraction denominators*)
neuper@42279: val denominator' = HOLogic.mk_binop "Groups.times_class.times" (s_1', s_2') ;
neuper@42279: val SOME numerator = parseNEW ctxt "3::real";
neuper@42279: 
neuper@42279: val expr' = HOLogic.mk_binop "Rings.inverse_class.divide" (numerator, denominator');
neuper@42279: term2str expr';
neuper@42279: *}
neuper@42279: 
neuper@42279: subsubsection {*Ansatz - create partial fractions out of our expression*}
neuper@42302: ML {*Context.theory_name thy = "Isac"*}
neuper@42279: 
neuper@42279: axiomatization where
neuper@42279:   ansatz2: "n / (a*b) = A/a + B/(b::real)" and
jan@42337:   multiply_eq2: "(n / (a*b) = A/a + B/b) = (a*b*(n  / (a*b)) = a*b*(A/a + B/b))" and
jan@42337:   ansatz3: "n / (a * b * c) = (A/a) + (B/b) + (C/c)" and
jan@42337:   ansatz4: "n / (a * b * c * d) = (A/a) + (B/b) + (C/c) + (D/d)" 
neuper@42279: 
neuper@42279: ML {*
neuper@42279: (*we use our ansatz2 to rewrite our expression and get an equilation with our expression on the left and the partial fractions of it on the right side*)
neuper@42279: val SOME (t1,_) = rewrite_ @{theory Isac} e_rew_ord e_rls false @{thm ansatz2} expr';
neuper@42279: term2str t1; atomty t1;
neuper@42279: val eq1 = HOLogic.mk_eq (expr', t1);
neuper@42279: term2str eq1;
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: (*eliminate the demoninators by multiplying the left and the right side with the main denominator*)
neuper@42279: val SOME (eq2,_) = rewrite_ @{theory Isac} e_rew_ord e_rls false @{thm multiply_eq2} eq1;
neuper@42279: term2str eq2;
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: (*simplificatoin*)
neuper@42279: val SOME (eq3,_) = rewrite_set_ @{theory Isac} false norm_Rational eq2;
neuper@42279: term2str eq3; (*?A ?B not simplified*)
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: val SOME fract1 =
neuper@42279:   parseNEW ctxt "(z - 1 / 2) * (z - -1 / 4) * (A / (z - 1 / 2) + B / (z - -1 / 4))"; (*A B !*)
neuper@42279: val SOME (fract2,_) = rewrite_set_ @{theory Isac} false norm_Rational fract1;
neuper@42279: term2str fract2 = "(A + -2 * B + 4 * A * z + 4 * B * z) / 4";
neuper@42279: (*term2str fract2 = "A * (1 / 4 + z) + B * (-1 / 2 + z)" would be more traditional*)
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: val (numerator, denominator) = HOLogic.dest_eq eq3;
neuper@42279: val eq3' = HOLogic.mk_eq (numerator, fract1); (*A B !*)
neuper@42279: term2str eq3';
neuper@42279: (*MANDATORY: simplify (and remove denominator) otherwise 3 = 0*)
neuper@42279: val SOME (eq3'' ,_) = rewrite_set_ @{theory Isac} false norm_Rational eq3';
neuper@42279: term2str eq3'';
neuper@42279: *}
neuper@42279: ML {*Context.theory_name thy = "Isac"(*==================================================*)*}
neuper@42279: 
neuper@42279: subsubsection {*get first koeffizient*}
neuper@42279: 
neuper@42279: ML {*
neuper@42279: (*substitude z with the first zeropoint to get A*)
neuper@42279: val SOME (eq4_1,_) = rewrite_terms_ @{theory Isac} e_rew_ord e_rls [s_1] eq3'';
neuper@42279: term2str eq4_1;
neuper@42279: 
neuper@42279: val SOME (eq4_2,_) = rewrite_set_ @{theory Isac} false norm_Rational eq4_1;
neuper@42279: term2str eq4_2;
neuper@42279: 
neuper@42279: val fmz = ["equality (3 = 3 * A / (4::real))", "solveFor A","solutions L"];
neuper@42279: val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
neuper@42279: (*solve the simple linear equilation for A TODO: return eq, not list of eq*)
neuper@42279: val (p,_,fa,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fa,nxt,_,pt) = me nxt p [] pt; 
neuper@42279: f2str fa;
neuper@42279: *}
neuper@42279: 
neuper@42279: subsubsection {*get second koeffizient*}
neuper@42279: ML {*thy*}
neuper@42279: 
neuper@42279: ML {*
neuper@42279: (*substitude z with the second zeropoint to get B*)
neuper@42279: val SOME (eq4b_1,_) = rewrite_terms_ @{theory Isac} e_rew_ord e_rls [s_2] eq3'';
neuper@42279: term2str eq4b_1;
neuper@42279: 
neuper@42279: val SOME (eq4b_2,_) = rewrite_set_ @{theory Isac} false norm_Rational eq4b_1;
neuper@42279: term2str eq4b_2;
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: (*solve the simple linear equilation for B TODO: return eq, not list of eq*)
neuper@42279: val fmz = ["equality (3 = -3 * B / (4::real))", "solveFor B","solutions L"];
neuper@42279: val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
neuper@42279: val (p,_,fb,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279: val (p,_,fb,nxt,_,pt) = me nxt p [] pt; 
neuper@42279: f2str fb;
neuper@42279: *}
neuper@42279: 
neuper@42279: ML {* (*check koeffizients*)
neuper@42279: if f2str fa = "[A = 4]" then () else error "part.fract. eq4_1";
neuper@42279: if f2str fb = "[B = -4]" then () else error "part.fract. eq4_1";
neuper@42279: *}
neuper@42279: 
neuper@42279: subsubsection {*substitute expression with solutions*}
neuper@42279: ML {*
neuper@42279: *}
neuper@42279: ML {*thy*}
neuper@42279: 
jan@42296: section {*Implement the Specification and the Method \label{spec-meth}*}
neuper@42279: text{*==============================================*}
neuper@42279: subsection{*Define the Field Descriptions for the specification*}
neuper@42279: consts
neuper@42279:   filterExpression  :: "bool => una"
neuper@42279:   stepResponse      :: "bool => una"
neuper@42279: 
neuper@42279: subsection{*Define the Specification*}
neuper@42279: ML {*
neuper@42279: store_pbt
neuper@42279:  (prep_pbt thy "pbl_SP" [] e_pblID
neuper@42279:  (["SignalProcessing"], [], e_rls, NONE, []));
neuper@42279: store_pbt
neuper@42279:  (prep_pbt thy "pbl_SP_Ztrans" [] e_pblID
neuper@42279:  (["Z_Transform","SignalProcessing"], [], e_rls, NONE, []));
neuper@42279: *}
neuper@42279: ML {*thy*}
neuper@42279: ML {*
neuper@42279: store_pbt
neuper@42279:  (prep_pbt thy "pbl_SP_Ztrans_inv" [] e_pblID
neuper@42279:  (["inverse", "Z_Transform", "SignalProcessing"],
neuper@42279:   [("#Given" ,["filterExpression X_eq"]),
neuper@42279:    ("#Find"  ,["stepResponse n_eq"])
neuper@42279:   ],
neuper@42279:   append_rls "e_rls" e_rls [(*for preds in where_*)], NONE, 
neuper@42279:   [["SignalProcessing","Z_Transform","inverse"]]));
neuper@42279: 
neuper@42279: show_ptyps();
neuper@42279: get_pbt ["inverse","Z_Transform","SignalProcessing"];
neuper@42279: *}
neuper@42279: 
neuper@42279: subsection {*Define Name and Signature for the Method*}
neuper@42279: consts
neuper@42279:   InverseZTransform :: "[bool, bool] => bool"
neuper@42279:     ("((Script InverseZTransform (_ =))// (_))" 9)
neuper@42279: 
neuper@42279: subsection {*Setup Parent Nodes in Hierarchy of Method*}
neuper@42279: ML {*
neuper@42279: store_met
neuper@42279:  (prep_met thy "met_SP" [] e_metID
neuper@42279:  (["SignalProcessing"], [],
neuper@42279:    {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
neuper@42279:     crls = e_rls, nrls = e_rls}, "empty_script"));
neuper@42279: store_met
neuper@42279:  (prep_met thy "met_SP_Ztrans" [] e_metID
neuper@42279:  (["SignalProcessing", "Z_Transform"], [],
neuper@42279:    {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
neuper@42279:     crls = e_rls, nrls = e_rls}, "empty_script"));
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: store_met
neuper@42279:  (prep_met thy "met_SP_Ztrans_inv" [] e_metID
neuper@42279:  (["SignalProcessing", "Z_Transform", "inverse"], 
neuper@42279:   [("#Given" ,["filterExpression X_eq"]),
neuper@42279:    ("#Find"  ,["stepResponse n_eq"])
neuper@42279:   ],
neuper@42279:    {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
neuper@42279:     crls = e_rls, nrls = e_rls},
neuper@42279:   "empty_script"
neuper@42279:  ));
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: store_met
neuper@42279:  (prep_met thy "met_SP_Ztrans_inv" [] e_metID
neuper@42279:  (["SignalProcessing", "Z_Transform", "inverse"], 
neuper@42279:   [("#Given" ,["filterExpression X_eq"]),
neuper@42279:    ("#Find"  ,["stepResponse n_eq"])
neuper@42279:   ],
neuper@42279:    {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
neuper@42279:     crls = e_rls, nrls = e_rls},
neuper@42279:   "Script InverseZTransform (Xeq::bool) =" ^
neuper@42279:   " (let X = Take Xeq;" ^
neuper@42279:   "      X = Rewrite ruleZY False X" ^
neuper@42279:   "  in X)"
neuper@42279:  ));
jan@42299: *}
jan@42299: ML {*
neuper@42279: show_mets();
jan@42299: *}
jan@42299: ML {*
neuper@42279: get_met ["SignalProcessing","Z_Transform","inverse"];
neuper@42279: *}
neuper@42279: 
jan@42296: section {*Program in CTP-based language \label{prog-steps}*}
neuper@42279: text{*=================================*}
neuper@42279: subsection {*Stepwise extend Program*}
neuper@42279: ML {*
neuper@42279: val str = 
neuper@42279: "Script InverseZTransform (Xeq::bool) =" ^
neuper@42279: " Xeq";
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: val str = 
neuper@42279: "Script InverseZTransform (Xeq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
neuper@42279: " (let X = Take Xeq;" ^
neuper@42279: "      X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
neuper@42279: "      X' = (Rewrite_Set norm_Rational False) X'" ^ (*simplify*)
neuper@42279: "  in X)";
neuper@42279: (*NONE*)
neuper@42279: "Script InverseZTransform (Xeq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
neuper@42279: " (let X = Take Xeq;" ^
neuper@42279: "      X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
neuper@42279: "      X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
neuper@42279: "      X' = (SubProblem (Isac',[pqFormula,degree_2,polynomial,univariate,equation], [no_met])   " ^
neuper@42279:     "                 [BOOL e_e, REAL v_v])" ^
neuper@42279: "  in X)";
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: val str = 
neuper@42279: "Script InverseZTransform (Xeq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
neuper@42279: " (let X = Take Xeq;" ^
neuper@42279: "      X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
neuper@42279: "      X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
neuper@42279: "      funterm = rhs X'" ^ (*drop X'= for equation solving*)
neuper@42279: "  in X)";
neuper@42279: *}
neuper@42279: ML {*
neuper@42290: val str = 
neuper@42290: "Script InverseZTransform (X_eq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
neuper@42290: " (let X = Take X_eq;" ^
neuper@42290: "      X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
neuper@42290: "      X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
jan@42298: "      (X'_z::real) = lhs X';" ^
jan@42298: "      (z::real) = argument_in X'_z;" ^
jan@42298: "      (funterm::real) = rhs X';" ^ (*drop X' z = for equation solving*)
jan@42298: "      (denom::real) = get_denominator funterm;" ^ (*get_denominator*)
jan@42298: "      (equ::bool) = (denom = (0::real));" ^
neuper@42290: "      (L_L::bool list) =                                    " ^
neuper@42290: "            (SubProblem (Test',                            " ^
neuper@42290: "                         [linear,univariate,equation,test]," ^
neuper@42290: "                         [Test,solve_linear])              " ^
neuper@42290: "                        [BOOL equ, REAL z])              " ^
neuper@42290: "  in X)"
neuper@42290: ;
neuper@42290: 
neuper@42279: parse thy str;
neuper@42279: val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
neuper@42279: atomty sc;
neuper@42279: 
neuper@42279: *}
jan@42300: 
jan@42300: text {*
jan@42300: This ruleset contains all functions that are in the script; 
jan@42300: The evaluation of the functions is done by rewriting using this ruleset.
jan@42300: *}
jan@42300: 
neuper@42279: ML {*
neuper@42290: val srls = Rls {id="srls_InverseZTransform", 
neuper@42290: 		  preconds = [], rew_ord = ("termlessI",termlessI), 
neuper@42290: 		  erls = append_rls "erls_in_srls_InverseZTransform" e_rls
neuper@42290: 				    [(*for asm in NTH_CONS ...*) Calc ("Orderings.ord_class.less",eval_equ "#less_"),
neuper@42290: 				     (*2nd NTH_CONS pushes n+-1 into asms*) Calc("Groups.plus_class.plus", eval_binop "#add_")
neuper@42290: 				    ], 
neuper@42290:   srls = Erls, calc = [],
neuper@42290: 		  rules =
neuper@42290:     [Thm ("NTH_CONS",num_str @{thm NTH_CONS}),
neuper@42290: 			     Calc("Groups.plus_class.plus", eval_binop "#add_"),
neuper@42290: 			     Thm ("NTH_NIL",num_str @{thm NTH_NIL}),
neuper@42290: 			     Calc("Tools.lhs", eval_lhs"eval_lhs_"), (*<=== ONLY USED*)
neuper@42290: 			     Calc("Tools.rhs", eval_rhs"eval_rhs_"), (*<=== ONLY USED*)
jan@42300: 			     Calc("Atools.argument'_in", eval_argument_in "Atools.argument'_in"),
neuper@42301:      Calc("Rational.get_denominator",
neuper@42301:        eval_get_denominator "Rational.get_denominator")
neuper@42290: 			    ],
neuper@42290: 		  scr = EmptyScr};
neuper@42279: *}
neuper@42279: 
neuper@42279: 
neuper@42279: subsection {*Store Final Version of Program for Execution*}
neuper@42279: ML {*
neuper@42279: store_met
neuper@42279:  (prep_met thy "met_SP_Ztrans_inv" [] e_metID
neuper@42279:  (["SignalProcessing", "Z_Transform", "inverse"], 
neuper@42279:   [("#Given" ,["filterExpression X_eq"]),
neuper@42279:    ("#Find"  ,["stepResponse n_eq"])
neuper@42279:   ],
neuper@42290:    {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = srls, 
neuper@42290:     prls = e_rls,
neuper@42279:     crls = e_rls, nrls = e_rls},
neuper@42289: "Script InverseZTransform (X_eq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
neuper@42289: " (let X = Take X_eq;" ^
neuper@42279: "      X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
neuper@42279: "      X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
jan@42298: "      (X'_z::real) = lhs X';" ^ (**)
neuper@42303: "      (zzz::real) = argument_in X'_z;" ^ (**)
jan@42298: "      (funterm::real) = rhs X';" ^ (*drop X' z = for equation solving*)
jan@42298: "      (denom::real) = get_denominator funterm;" ^ (*get_denominator*)
jan@42337: "      (numer::real) = get_numerator funterm;" ^
jan@42298: "      (equ::bool) = (denom = (0::real));" ^
neuper@42303: 
neuper@42303: "      (L_L::bool list) = (SubProblem (PolyEq'," ^
neuper@42315: "          [abcFormula,degree_2,polynomial,univariate,equation],[no_met])" ^
neuper@42303: "        [BOOL equ, REAL zzz])              " ^
jan@42337: "  in X);" ^
jan@42337: 
jan@42337: "   facs = factors_from_solution L_L;" ^
jan@42337: "   (eq::real) = Take (funterm = (num / facs));" ^
jan@42337: "   (eq::real) = (Try (Rewrite_Set ansatz False)) eq " ^
jan@42337: 
neuper@42279:  ));
neuper@42279: *}
neuper@42279: 
neuper@42281: subsection {*Check the Program*}
neuper@42279: 
neuper@42281: subsubsection {*Check the formalization*}
neuper@42279: ML {*
neuper@42279: val fmz = ["filterExpression (X  = 3 / (z - 1/4 + -1/8 * (1/(z::real))))", 
neuper@42279:   "stepResponse (x[n::real]::bool)"];
neuper@42279: val (dI,pI,mI) = ("Isac", ["inverse", "Z_Transform", "SignalProcessing"], 
neuper@42279:   ["SignalProcessing","Z_Transform","inverse"]);
neuper@42281: 
neuper@42281: val ([(1, [1], "#Given", Const ("Inverse_Z_Transform.filterExpression", _),
neuper@42281:             [Const ("HOL.eq", _) $ _ $ _]),
neuper@42281:            (2, [1], "#Find", Const ("Inverse_Z_Transform.stepResponse", _),
neuper@42281:             [Free ("x", _) $ _])],
neuper@42281:           _) = prep_ori fmz thy ((#ppc o get_pbt) pI);
neuper@42281: *}
neuper@42290: ML {*
neuper@42290: val Script sc = (#scr o get_met) ["SignalProcessing","Z_Transform","inverse"];
neuper@42290: atomty sc;
neuper@42290: *}
neuper@42281: 
neuper@42281: subsubsection {*Stepwise check the program*}
neuper@42281: ML {*
neuper@42302: trace_rewrite := false;
neuper@42306: trace_script := false; print_depth 9;
neuper@42281: val fmz = ["filterExpression (X z = 3 / (z - 1/4 + -1/8 * (1/(z::real))))", 
neuper@42281:   "stepResponse (x[n::real]::bool)"];
neuper@42281: val (dI,pI,mI) = ("Isac", ["inverse", "Z_Transform", "SignalProcessing"], 
neuper@42281:   ["SignalProcessing","Z_Transform","inverse"]);
neuper@42310: val (p,_,f,nxt,_,pt)  = CalcTreeTEST [(fmz, (dI,pI,mI))];
neuper@42310: *}
neuper@42310: ML {*
neuper@42303: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Add_Given";
neuper@42303: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Add_Find";
neuper@42303: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Theory";
neuper@42303: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Problem";
neuper@42303: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Method";
jan@42296: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Apply_Method";
jan@42297: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Rewrite (ruleZY, Inverse_Z_Transform.ruleZY) --> X z = 3 / (z - 1 / 4 + -1 / 8 * (1 / z))"; (*TODO naming!*)
jan@42296: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Rewrite_Set norm_Rational --> X' z = 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))";
neuper@42315: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = SubProblem";
jan@42300: *}
neuper@42305: text {* Instead of nxt = Subproblem above we had Empty_Tac; the search for the reason 
neuper@42305:   considered the following points:
neuper@42303:   # what shows show_pt pt; ...
neuper@42303:     (([2], Res), ?X' z = 24 / (-1 + -2 * z + 8 * z ^^^ 2))] ..calculation ok,
neuper@42303:     but no "next" step found: should be "nxt = Subproblem" ?!?
neuper@42303:   # what shows trace_script := true; we read bottom up ...
neuper@42303:     @@@ next   leaf 'SubProbfrom
neuper@42303:      (PolyEq', [abcFormula, degree_2, polynomial, univariate, equation],
neuper@42303:       no_meth)
neuper@42303:      [BOOL equ, REAL z]' ---> STac 'SubProblem
neuper@42303:      (PolyEq', [abcFormula, degree_2, polynomial, univariate, equation],
neuper@42303:       no_meth)
neuper@42303:      [BOOL (-1 + -2 * z + 8 * z ^^^ 2 = 0), REAL z]'
neuper@42305:     ... and see the SubProblem with correct arguments from searching next step
neuper@42305:     (program text !!!--->!!! STac (script tactic) with arguments evaluated.)
neuper@42310:   # do we have the right Script ...difference in the argumentsdifference in the arguments
neuper@42303:     val Script s = (#scr o get_met) ["SignalProcessing","Z_Transform","inverse"];
neuper@42303:     writeln (term2str s);
neuper@42310:     ... shows the right script.difference in the arguments
neuper@42305:   # test --- why helpless here ? --- shows: replace no_meth by [no_meth] in Script
neuper@42301: *}
neuper@42315: 
neuper@42301: ML {*
neuper@42315: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Model_Problem";
neuper@42306: *}
neuper@42306: text {* Instead of nxt = Model_Problem above we had Empty_Tac; the search for the reason 
neuper@42310:   considered the following points:difference in the arguments
neuper@42306:   # comparison with subsection { *solve equation* }: there solving this equation works,
neuper@42315:     so there must be some difference in the arguments of the Subproblem:
neuper@42315:     RIGHT: we had [no_meth] instead of [no_met] ;-))
neuper@42305: *}
neuper@42305: ML {*
neuper@42315: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Add_Given equality (-1 + -2 * z + 8 * z ^^^ 2 = 0)";
neuper@42315: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Add_Given solveFor z";
neuper@42315: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Add_Find solutions z_i";
neuper@42315: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Specify_Theory Isac";
neuper@42301: *}
neuper@42315: text {* We had "nxt = Empty_Tac instead Specify_Theory; 
neuper@42315:   the search for the reason considered the following points:
neuper@42302:   # was there an error message ? NO --ok
neuper@42302:   # has "nxt = Add_Find" been inserted in pt: get_obj g_pbl pt (fst p); YES --ok
neuper@42302:   # what is the returned "formula": print_depth 999; f; print_depth 999; --
neuper@42302:     {Find = [Correct "solutions z_i"], With = [], 
neuper@42302:      Given = [Correct "equality (-1 + -2 * z + 8 * z ^^^ 2 = 0)", Correct "solveFor z"],
neuper@42302:      Where = [False "matches (z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0) |\n
neuper@42302:                      matches (?b * z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0) |\n
neuper@42302:                      matches (?a + z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0) |\n
neuper@42302:                      matches (?a + ?b * z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0)"],
neuper@42302:      Relate = []}
neuper@42302:      -- the only False is the reason: the Where (the precondition) is False for good reasons:
neuper@42302:      the precondition seems to check for linear equations, not for the one we want to solve!
neuper@42302:   Removed this error by correcting the Script
neuper@42302:   from SubProblem (PolyEq', [linear,univariate,equation,test], [Test,solve_linear]
neuper@42302:   to   SubProblem (PolyEq', [abcFormula,degree_2,polynomial,univariate,equation],
neuper@42303:                    [PolyEq,solve_d2_polyeq_abc_equation]
neuper@42302:   You find the appropriate type of equation at
neuper@42302:     http://www.ist.tugraz.at/projects/isac/www/kbase/pbl/index_pbl.html
neuper@42302:   and the respective method in Knowledge/PolyEq.thy at the respective store_pbt.
neuper@42302:   Or you leave the selection of the appropriate type to isac as done in the final Script ;-))
neuper@42302: *}
neuper@42302: ML {*
neuper@42315: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Specify_Problem [abcFormula,...";
neuper@42315: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Specify_Method [PolyEq,solve_d2_polyeq_abc_equation";
neuper@42315: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Apply_Method [PolyEq,solve_d2_polyeq_abc_equation";
neuper@42315: val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Rewrite_Set_Inst ([(bdv, z)], d2_polyeq_abcFormula_simplify";
neuper@42289: show_pt pt;
neuper@42279: *}
neuper@42279: ML {*
neuper@42335: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279: *}
neuper@42279: ML {*
neuper@42335: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42335: *}
neuper@42335: ML {*
neuper@42335: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42335: *}
neuper@42335: ML {*
neuper@42335: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42335: *}
neuper@42335: ML {*
neuper@42335: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42335: *}
neuper@42335: ML {*
neuper@42335: val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42335: show_pt pt;
neuper@42279: *}
neuper@42279: ML {*
neuper@42279: *}
neuper@42279: 
neuper@42279: section {*Write Tests for Crucial Details*}
neuper@42279: text{*===================================*}
neuper@42279: ML {*
neuper@42279: *}
neuper@42279: 
neuper@42279: section {*Integrate Program into Knowledge*}
neuper@42279: ML {*
neuper@42290: @{theory Isac}
neuper@42279: *}
neuper@42279: 
neuper@42279: end
neuper@42279: 




