1.1 --- a/test/Tools/isac/Interpret/inform.sml Tue May 22 13:40:06 2012 +0200
1.2 +++ b/test/Tools/isac/Interpret/inform.sml Thu May 24 17:13:58 2012 +0200
1.3 @@ -36,7 +36,7 @@
1.4 "--------- build fun check_error_patterns ------------------------";
1.5 "--------- embed fun check_error_patterns ------------------------";
1.6 "--------- embed fun find_fillpatterns ---------------------------";
1.7 -"--------- embed fun get_fillform --------------------------------";
1.8 +"--------- embed fun get_fillformula -----------------------------";
1.9 "-----------------------------------------------------------------";
1.10 "-----------------------------------------------------------------";
1.11 "-----------------------------------------------------------------";
1.12 @@ -975,7 +975,7 @@
1.13 (*or
1.14 <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
1.15
1.16 -"~~~~~ fun FindFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
1.17 +"~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
1.18 val ((pt, _), _) = get_calc cI
1.19 val pos = get_pos cI 1;
1.20 "~~~~~ fun find_fillpatterns, args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
1.21 @@ -990,7 +990,7 @@
1.22 |> flat;
1.23
1.24 case map (get_fillpats subst f_curr errpatID) errpatthms |> flat of
1.25 - ("fill-d_d-arg", tm) :: _ => if term2str tm =
1.26 + ("fill-d_d-arg", tm, thm, subs_opt) :: _ => if term2str tm =
1.27 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
1.28 then () else error "find_fillpatterns changed 1a"
1.29 | _ => error "find_fillpatterns changed 1b"
1.30 @@ -1001,26 +1001,28 @@
1.31 val (part, thyID) = thy_containing_thm thmDeriv
1.32 val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
1.33 val Hthm {fillpats, ...} = get_the theID
1.34 - val some = map (get_fillform subst form errpatID) fillpats;
1.35 + val some = map (get_fillform subst (thm, form) errpatID) fillpats;
1.36
1.37 case some |> filter is_some |> map the of
1.38 - ("fill-d_d-arg", tm) :: _ => if term2str tm =
1.39 + ("fill-d_d-arg", tm, thm, subsopt) :: _ => if term2str tm =
1.40 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
1.41 then () else error "find_fillpatterns changed 2a"
1.42 | _ => error "find_fillpatterns changed 2b"
1.43
1.44 -"~~~~~ fun get_fillform, args:"; val (subst, form, errpatID, ((fillpatID, pat, erpaID): fillpat)) =
1.45 - (subst, form, errpatID, hd (*simulate beginning of "map"*) fillpats);
1.46 - val (form', _, _, rewritten) =
1.47 +"~~~~~ fun get_fillform, args:";
1.48 + val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
1.49 + (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
1.50 +val (form', _, _, rewritten) =
1.51 rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) form;
1.52
1.53 if term2str form' = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
1.54 else error "find_fillpatterns changed 3";
1.55
1.56 -"~~~~~ to FindFillpatterns return val:"; val (fillpats) =
1.57 - (map (get_fillpats subst f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
1.58 +"~~~~~ to findFillpatterns return val:"; val (fillpats) =
1.59 + (map (get_fillpats (subs_opt, subst) f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
1.60
1.61 -val msg = "fill patterns " ^ ((map (apsnd term2str) fillpats) |> map pair2str_ |> strs2str_);
1.62 +val msg = "fill patterns " ^
1.63 + ((map ((apsnd term2str) o quad2pair) fillpats) |> map pair2str_ |> strs2str_);
1.64 if msg =
1.65 "fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1.66 " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" ^
1.67 @@ -1034,9 +1036,9 @@
1.68 then () else error "find_fillpatterns changed 4";
1.69
1.70
1.71 -"--------- embed fun get_fillform --------------------------------";
1.72 -"--------- embed fun get_fillform --------------------------------";
1.73 -"--------- embed fun get_fillform --------------------------------";
1.74 +"--------- embed fun get_fillformula -----------------------------";
1.75 +"--------- embed fun get_fillformula -----------------------------";
1.76 +"--------- embed fun get_fillformula -----------------------------";
1.77 states := [];
1.78 CalcTree
1.79 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
1.80 @@ -1051,7 +1053,7 @@
1.81 would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
1.82 results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
1.83 instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
1.84 -FindFillpatterns 1 "chain-rule-diff-both";
1.85 +findFillpatterns 1 "chain-rule-diff-both";
1.86 (*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
1.87 d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
1.88
1.89 @@ -1064,11 +1066,79 @@
1.90 ((pt, pos), (errpatID, fillpatID));
1.91 val fillforms = find_fillpatterns (pt, pos) errpatID
1.92 val fillforms =
1.93 - filter ((curry op = fillpatID) o (#1: (fillpatID * term -> fillpatID))) fillforms;
1.94 + filter ((curry op = fillpatID) o (#1: (fillpatID * term * thm * (subs option) -> fillpatID))) fillforms;
1.95
1.96 -val [(fillpatID, fillform)] = fillforms;
1.97 -case (fillpatID, fillform) of
1.98 - ("fill-both-args", tm) => if term2str tm =
1.99 +val [(fillpatID, fillform, thm, subs_opt)] = fillforms;
1.100 +case (fillpatID, fillform, thm, subs_opt) of
1.101 + ("fill-both-args", tm, thm, subs_opt) => if term2str tm =
1.102 + "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3"
1.103 + then () else error "get_fillformula changed 1a"
1.104 +| _ => error "get_fillformula changed 1b";
1.105 +
1.106 + val f_curr = get_curr_formula (pt, pos); (*already done in find_fillpatterns, too*)
1.107 +term2str f_curr = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))";
1.108 +
1.109 +"~~~~~ fun generate_inconsistent, args:";
1.110 + val (_, (Rewrite' (_,_,_,_, thm', f, (f', asm))), (is, ctxt), (p,_), pt) =
1.111 + (0,
1.112 + (Rewrite' ("","",e_rls,true, (fillpatID, ""(*errpatthm known in find_fillpatterns*)),
1.113 + f_curr, (fillform, []))),
1.114 + (get_loc pt pos), (lev_on p, Und), pt);
1.115 +if p = [2] then () else error "generate_inconsistent changed 1";
1.116 +
1.117 +val (pt,c) = cappend_atomic pt p (is, insert_assumptions asm ctxt) f
1.118 + (Rewrite thm') (f', asm) Inconsistent
1.119 +val pt = update_branch pt p TransitiveB;
1.120 +
1.121 +"~~~~~ to get_fillformula return val:"; val (pos', _, _, pt) =
1.122 + ((p,Res), c, Form' (FormKF (~1,EdUndef,(length p), Nundef, term2str f')), pt);
1.123 +if pos' = ([2], Res) then () else error "generate_inconsistent changed 2";
1.124 +
1.125 +upd_calc cI ((pt, pos'), []); upd_ipos cI 1 pos';
1.126 +autocalculateOK2xml cI pos pos' pos';
1.127 +
1.128 +"~~~~~ final check:";
1.129 +val ((pt,pos),_) = get_calc 1;
1.130 +val p = get_pos 1 1;
1.131 +val (Form f, tac, asms) = pt_extract (pt, p);
1.132 +if p = ([2], Res) andalso term2str f =
1.133 + "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3"
1.134 +then () else error "";
1.135 +
1.136 +show_pt pt; (*ATTENTION: omits the last step, if pt is incomplete, ([2], Res) EXISTS !*)
1.137 +"--------- embed fun get_fillformula -----------------------------";
1.138 +states := [];
1.139 +CalcTree
1.140 +[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
1.141 + ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
1.142 +Iterator 1;
1.143 +moveActiveRoot 1;
1.144 +autoCalculate 1 CompleteCalcHead;
1.145 +autoCalculate 1 (Step 1);
1.146 +autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
1.147 +appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)";
1.148 +(* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
1.149 + would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
1.150 + results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
1.151 + instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
1.152 +findFillpatterns 1 "chain-rule-diff-both";
1.153 +(*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
1.154 + d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
1.155 +
1.156 +"~~~~~ fun requestFillformula, args:"; val (cI, (errpatID, fillpatID)) =
1.157 + (1, ("chain-rule-diff-both", "fill-both-args"));
1.158 +val ((pt, _), _) = get_calc cI
1.159 +val pos = get_pos cI 1; (* = ([1], Res)*)
1.160 +
1.161 +"~~~~~ fun get_fillformula, args:"; val ((pt, pos as (p, _)), (errpatID, fillpatID)) =
1.162 + ((pt, pos), (errpatID, fillpatID));
1.163 +val fillforms = find_fillpatterns (pt, pos) errpatID
1.164 +val fillforms =
1.165 + filter ((curry op = fillpatID) o (#1: (fillpatID * term * thm * (subs option) -> fillpatID))) fillforms;
1.166 +
1.167 +val [(fillpatID, fillform, thm, subs_opt)] = fillforms;
1.168 +case (fillpatID, fillform, thm, subs_opt) of
1.169 + ("fill-both-args", tm, thm, subs_opt) => if term2str tm =
1.170 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3"
1.171 then () else error "get_fillformula changed 1a"
1.172 | _ => error "get_fillformula changed 1b";