wneuper@59582: (* title: Knowledge/polyminus.sml neuper@37906: author: Walther Neuper neuper@37906: WN071207, neuper@37906: (c) due to copyright terms neuper@37906: *) neuper@38037: "--------------------------------------------------------"; neuper@38037: "--------------------------------------------------------"; neuper@38037: "table of contents --------------------------------------"; neuper@38037: "--------------------------------------------------------"; walther@60325: "----------- fun identifier --------------------------------------------------------------------"; walther@60324: "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------"; walther@60324: "----------- fun ist_monom ---------------------------------------------------------------------"; neuper@38037: "----------- fun eval_ist_monom -------------------------"; neuper@38037: "----------- watch order_add_mult ----------------------"; neuper@38037: "----------- build predicate for +- ordering ------------"; neuper@38037: "----------- build fasse_zusammen -----------------------"; neuper@38037: "----------- build verschoenere -------------------------"; neuper@38037: "----------- met simplification for_polynomials with_minu"; neuper@38080: "----------- me simplification.for_polynomials.with_minus"; neuper@38037: "----------- pbl polynom vereinfachen p.33 --------------"; neuper@38037: "----------- met probe fuer_polynom ---------------------"; neuper@38037: "----------- pbl polynom probe --------------------------"; neuper@38037: "----------- pbl klammer polynom vereinfachen p.34 ------"; neuper@38037: "----------- try fun applyTactics -----------------------"; neuper@38037: "----------- pbl binom polynom vereinfachen p.39 --------"; neuper@38037: "----------- pbl binom polynom vereinfachen: cube -------"; walther@59968: "----------- Refine.refine Vereinfache -------------------------"; walther@59973: "----------- *** Problem.prep_input: syntax error in '#Where' of [v"; neuper@38037: "--------------------------------------------------------"; neuper@38037: "--------------------------------------------------------"; neuper@38037: "--------------------------------------------------------"; neuper@38037: neuper@41929: val thy = @{theory "PolyMinus"}; Walther@60424: val ctxt = Proof_Context.init_global thy; neuper@37906: walther@60325: "----------- fun identifier --------------------------------------------------------------------"; walther@60325: "----------- fun identifier --------------------------------------------------------------------"; walther@60325: "----------- fun identifier --------------------------------------------------------------------"; walther@60325: if identifier (TermC.str2term "12 ::real") = "12" then () else error "identifier 1"; walther@60351: if identifier (TermC.str2term walther@60351: "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g ::real") = "|||||||||||||" walther@60351: then () else error "identifier 1a"; walther@60333: walther@60325: if identifier (TermC.str2term "a ::real") = "a" then () else error "identifier 2"; walther@60325: if identifier (TermC.str2term "3 * a ::real") = "a" then () else error "identifier 3"; walther@60333: walther@60325: if identifier (TermC.str2term "a \ 2 ::real") = "a" then () else error "identifier 4"; walther@60325: if identifier (TermC.str2term "3*a \ 2 ::real") = "a" then () else error "identifier 5"; walther@60325: if identifier (TermC.str2term "a * b ::real") = "b" then () else error "identifier 5b"; walther@60324: walther@60325: (*these are strange (see "specific monomials" in comment to fun.def.)..*) walther@60325: if identifier (TermC.str2term "a*b ::real") = "b" then () else error "identifier 6"; walther@60325: if identifier (TermC.str2term "(3*a*b) ::real") = "b" then () else error "identifier 7"; walther@60324: walther@60324: walther@60324: "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------"; walther@60324: "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------"; walther@60324: "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------"; walther@60325: "a" < "b"; walther@60325: "ba" < "ab"; walther@60325: "123" < "a"; (*unused due to ---vvv*) walther@60325: "12" < "3"; (*true !!!*) walther@60325: walther@60325: " a kleiner b ==> (b + a) = (a + b)"; walther@60325: TermC.str2term "aaa"; walther@60325: TermC.str2term "222 * aaa"; walther@60325: walther@60325: case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of walther@60325: SOME ("123 kleiner 32 = False", _) => () walther@60325: | _ => error "polyminus.sml: 12 kleiner 9 = False"; walther@60325: case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of walther@60325: SOME ("a kleiner b = True", _) => () walther@60325: | _ => error "polyminus.sml: a kleiner b = True"; walther@60325: case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of walther@60325: SOME ("10 * g kleiner f = False", _) => () walther@60325: | _ => error "polyminus.sml: 10 * g kleiner f = False"; walther@60325: case eval_kleiner 0 0 (TermC.str2term "(a \ 2) kleiner b") 0 of walther@60325: SOME ("a \ 2 kleiner b = True", _) => () walther@60325: | _ => error "polyminus.sml: a \ 2 kleiner b = True"; walther@60325: case eval_kleiner 0 0 (TermC.str2term "(3*a \ 2) kleiner b") 0 of walther@60325: SOME ("3 * a \ 2 kleiner b = True", _) => () walther@60325: | _ => error "polyminus.sml: 3 * a \ 2 kleiner b = True"; walther@60325: case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of walther@60325: SOME ("a * b kleiner c = True", _) => () walther@60325: | _ => error "polyminus.sml: a * b kleiner b = True"; walther@60325: case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of walther@60325: SOME ("3 * a * b kleiner c = True", _) => () walther@60325: | _ => error "polyminus.sml: 3 * a * b kleiner b = True"; walther@60325: walther@60325: walther@60324: val t = TermC.str2term "12 kleiner 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * (g::real)"; walther@60324: val SOME ("12 kleiner 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g = True", _) = walther@60324: eval_kleiner "aaa" "bbb" t "ccc"; walther@60351: "~~~~~ fun eval_kleiner , args:"; val (_, _, (p as (Const (\<^const_name>\kleiner\,_) $ a $ b)), _) = walther@60324: ("aaa", "bbb", t, "ccc"); walther@60324: (*if*) TermC.is_num b (*else*); walther@60324: walther@60324: (*if*) identifier a < identifier b (*else*); walther@60324: "~~~~~ fun identifier , args:"; val (t) = (a); walther@60324: (*+*)case a of walther@60336: Const (\<^const_name>\numeral\, _) $ (Const (\<^const_name>\num.Bit0\, _) $ walther@60336: (Const (\<^const_name>\num.Bit0\, _) $ (Const (\<^const_name>\num.Bit1\, _) $ Const (\<^const_name>\num.One\, _)))) => () walther@60325: | _ => error "eval_kleiner CHANGED"; (*isa*) walther@60325: walther@60325: walther@60325: "----------- fun ist_monom ---------------------------------------------------------------------"; walther@60325: "----------- fun ist_monom ---------------------------------------------------------------------"; walther@60325: "----------- fun ist_monom ---------------------------------------------------------------------"; walther@60325: val t = TermC.str2term "0 ::real"; walther@60325: if ist_monom t then () else error "ist_monom 1"; walther@60325: walther@60325: val t = TermC.str2term "a"; walther@60325: if ist_monom t then () else error "ist_monom 2"; walther@60325: walther@60325: val t = TermC.str2term "2 * a"; walther@60325: if ist_monom t then () else error "ist_monom 3"; walther@60325: walther@60325: val t = TermC.str2term "2 * a * b"; walther@60325: if ist_monom t then () else error "ist_monom 4"; walther@60325: walther@60325: val t = TermC.str2term "a * b"; walther@60325: if ist_monom t then () else error "ist_monom 5"; walther@60325: walther@60325: (*not covered before NEW numerals*) walther@60325: val t = TermC.str2term "2 * a \ 2 * b"; walther@60325: if ist_monom t then () else error "ist_monom 6"; walther@60325: walther@60325: (*not covered before NEW numerals*) walther@60325: val t = TermC.str2term "a \ 2 * b \ 3"; walther@60325: if ist_monom t then () else error "ist_monom 7"; walther@60325: walther@60325: val t = TermC.str2term "a \ 2 * 4 * b \ 3 * 5"; walther@60325: if ist_monom t then () else error "ist_monom 8"; walther@60324: walther@60324: neuper@37906: "----------- fun eval_ist_monom ----------------------------------"; neuper@37906: "----------- fun eval_ist_monom ----------------------------------"; neuper@37906: "----------- fun eval_ist_monom ----------------------------------"; walther@60230: case eval_ist_monom 0 0 (TermC.str2term "12 ist_monom") 0 of neuper@37926: SOME ("12 ist_monom = True", _) => () neuper@38031: | _ => error "polyminus.sml: 12 ist_monom = True"; neuper@37906: walther@60230: case eval_ist_monom 0 0 (TermC.str2term "a ist_monom") 0 of neuper@37926: SOME ("a ist_monom = True", _) => () neuper@38031: | _ => error "polyminus.sml: a ist_monom = True"; neuper@37906: walther@60230: case eval_ist_monom 0 0 (TermC.str2term "(3*a) ist_monom") 0 of neuper@37926: SOME ("3 * a ist_monom = True", _) => () neuper@38031: | _ => error "polyminus.sml: 3 * a ist_monom = True"; neuper@37906: walther@60242: case eval_ist_monom 0 0 (TermC.str2term "(a \ 2) ist_monom") 0 of walther@60242: SOME ("a \ 2 ist_monom = True", _) => () walther@60242: | _ => error "polyminus.sml: a \ 2 ist_monom = True"; neuper@37906: walther@60242: case eval_ist_monom 0 0 (TermC.str2term "(3*a \ 2) ist_monom") 0 of walther@60242: SOME ("3 * a \ 2 ist_monom = True", _) => () walther@60242: | _ => error "polyminus.sml: 3*a \ 2 ist_monom = True"; neuper@37906: walther@60230: case eval_ist_monom 0 0 (TermC.str2term "(a*b) ist_monom") 0 of neuper@37926: SOME ("a * b ist_monom = True", _) => () neuper@38031: | _ => error "polyminus.sml: a*b ist_monom = True"; neuper@37906: walther@60230: case eval_ist_monom 0 0 (TermC.str2term "(3*a*b) ist_monom") 0 of neuper@37926: SOME ("3 * a * b ist_monom = True", _) => () neuper@38031: | _ => error "polyminus.sml: 3*a*b ist_monom = True"; neuper@37906: neuper@37906: neuper@37906: "----------- watch order_add_mult -------------------------------"; neuper@37906: "----------- watch order_add_mult -------------------------------"; neuper@37906: "----------- watch order_add_mult -------------------------------"; neuper@37906: "----- with these simple variables it works..."; Walther@60500: val ctxt = @{context}; walther@60230: val t = TermC.str2term "((a + d) + c) + b"; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false order_add_mult t; UnparseC.term t; walther@59868: if UnparseC.term t = "a + (b + (c + d))" then () neuper@38031: else error "polyminus.sml 1 watch order_add_mult"; neuper@37906: neuper@37906: "----- the same stepwise..."; neuper@41929: val od = ord_make_polynomial true (@{theory "Poly"}); walther@60230: val t = TermC.str2term "((a + d) + c) + b"; neuper@37906: "((a + d) + c) + b"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t; neuper@37906: "b + ((a + d) + c)"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t; neuper@37906: "b + (c + (a + d))"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t; neuper@37906: "b + (a + (c + d))"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t; neuper@37906: "a + (b + (c + d))"; walther@59868: if UnparseC.term t = "a + (b + (c + d))" then () neuper@38031: else error "polyminus.sml 2 watch order_add_mult"; neuper@37906: neuper@37906: "----- if parentheses are right, left_commute is (almost) sufficient..."; walther@60230: val t = TermC.str2term "a + (d + (c + b))"; neuper@37906: "a + (d + (c + b))"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t; neuper@37906: "a + (c + (d + b))"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t;UnparseC.term t; neuper@37906: "a + (c + (b + d))"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t; neuper@37906: "a + (b + (c + d))"; neuper@37906: neuper@37906: "----- but we do not want the parentheses at right; thus: cond.rew."; neuper@37906: "WN0712707 complicated monomials do not yet work ..."; walther@60230: val t = TermC.str2term "((5*a + 4*d) + 3*c) + 2*b"; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false order_add_mult t; UnparseC.term t; walther@59868: if UnparseC.term t = "2 * b + (3 * c + (4 * d + 5 * a))" then () neuper@38031: else error "polyminus.sml: order_add_mult changed"; neuper@37906: neuper@37906: "----- here we see rew_sub going into subterm with ord.rew...."; neuper@41929: val od = ord_make_polynomial false (@{theory "Poly"}); walther@60230: val t = TermC.str2term "b + a + c + d"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t; Walther@60500: val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t; neuper@37906: (*@@@ rew_sub gosub: t = d + (b + a + c) neuper@37906: @@@ rew_sub begin: t = b + a + c*) neuper@37906: neuper@37906: neuper@37906: "----------- build predicate for +- ordering ---------------------"; neuper@37906: "----------- build predicate for +- ordering ---------------------"; neuper@37906: "----------- build predicate for +- ordering ---------------------"; neuper@37906: "a" < "b"; neuper@37906: "ba" < "ab"; neuper@37906: "123" < "a"; (*unused due to ---vvv*) neuper@37906: "12" < "3"; (*true !!!*) neuper@37906: neuper@37906: " a kleiner b ==> (b + a) = (a + b)"; walther@60230: TermC.str2term "aaa"; walther@60230: TermC.str2term "222 * aaa"; neuper@42390: walther@60230: case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of neuper@42390: SOME ("123 kleiner 32 = False", _) => () neuper@38031: | _ => error "polyminus.sml: 12 kleiner 9 = False"; neuper@42390: walther@60230: case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of neuper@37926: SOME ("a kleiner b = True", _) => () neuper@38031: | _ => error "polyminus.sml: a kleiner b = True"; neuper@37906: walther@60230: case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of neuper@37926: SOME ("10 * g kleiner f = False", _) => () neuper@38031: | _ => error "polyminus.sml: 10 * g kleiner f = False"; neuper@37906: walther@60242: case eval_kleiner 0 0 (TermC.str2term "(a \ 2) kleiner b") 0 of walther@60242: SOME ("a \ 2 kleiner b = True", _) => () walther@60242: | _ => error "polyminus.sml: a \ 2 kleiner b = True"; neuper@37906: walther@60242: case eval_kleiner 0 0 (TermC.str2term "(3*a \ 2) kleiner b") 0 of walther@60242: SOME ("3 * a \ 2 kleiner b = True", _) => () walther@60242: | _ => error "polyminus.sml: 3 * a \ 2 kleiner b = True"; neuper@37906: walther@60230: case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of neuper@37926: SOME ("a * b kleiner c = True", _) => () neuper@38031: | _ => error "polyminus.sml: a * b kleiner b = True"; neuper@37906: walther@60230: case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of neuper@37926: SOME ("3 * a * b kleiner c = True", _) => () neuper@38031: | _ => error "polyminus.sml: 3 * a * b kleiner b = True"; neuper@37906: neuper@42390: "======= compare tausche_plus with real_num_collect"; Walther@60509: val od = Rewrite_Ord.function_empty; neuper@37906: neuper@37906: val erls = erls_ordne_alphabetisch; walther@60230: val t = TermC.str2term "b + a"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od erls false @{thm tausche_plus} t; UnparseC.term t; walther@59868: if UnparseC.term t = "a + b" then () neuper@38031: else error "polyminus.sml: ordne_alphabetisch1 b + a"; neuper@37906: neuper@37906: val erls = Atools_erls; walther@60230: val t = TermC.str2term "2*a + 3*a"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od erls false @{thm real_num_collect} t; UnparseC.term t; neuper@37906: neuper@42390: "======= test rewrite_, rewrite_set_"; walther@59901: (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*) neuper@37906: val erls = erls_ordne_alphabetisch; walther@60230: val t = TermC.str2term "b + a"; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t; walther@59868: if UnparseC.term t = "a + b" then () neuper@38031: else error "polyminus.sml: ordne_alphabetisch a + b"; neuper@37906: walther@60230: val t = TermC.str2term "2*b + a"; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t; walther@59868: if UnparseC.term t = "a + 2 * b" then () neuper@38031: else error "polyminus.sml: ordne_alphabetisch a + 2 * b"; neuper@37906: walther@60230: val t = TermC.str2term "a + c + b"; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t; walther@59868: if UnparseC.term t = "a + b + c" then () neuper@38031: else error "polyminus.sml: ordne_alphabetisch a + b + c"; neuper@37906: neuper@42390: "======= rewrite goes into subterms"; walther@60325: val t = TermC.str2term "a + c + b + d ::real"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od erls false @{thm tausche_plus_plus} t; UnparseC.term t; walther@59868: if UnparseC.term t = "a + b + c + d" then () neuper@38031: else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d"; neuper@37906: walther@60230: val t = TermC.str2term "a + c + d + b"; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t; walther@59868: if UnparseC.term t = "a + b + c + d" then () neuper@38031: else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d"; neuper@37906: neuper@42390: "======= here we see rew_sub going into subterm with cond.rew...."; walther@60230: val t = TermC.str2term "b + a + c + d"; Walther@60500: val SOME (t,_) = rewrite_ ctxt od erls false @{thm tausche_plus} t; UnparseC.term t; walther@59868: if UnparseC.term t = "a + b + c + d" then () neuper@38031: else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d"; neuper@37906: neuper@42390: "======= compile rls for the most complicated terms"; walther@60230: val t = TermC.str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12"; neuper@37906: "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12"; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; walther@59868: if UnparseC.term t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g" neuper@38031: then () else error "polyminus.sml: ordne_alphabetisch finished"; walther@60352: neuper@37906: neuper@37906: neuper@37906: "----------- build fasse_zusammen --------------------------------"; neuper@37906: "----------- build fasse_zusammen --------------------------------"; neuper@37906: "----------- build fasse_zusammen --------------------------------"; walther@60230: val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false fasse_zusammen t; walther@60325: if UnparseC.term t = "3 + - 2 * e + 2 * f + 2 * g" then () neuper@38031: else error "polyminus.sml: fasse_zusammen finished"; neuper@37906: neuper@37906: "----------- build verschoenere ----------------------------------"; neuper@37906: "----------- build verschoenere ----------------------------------"; neuper@37906: "----------- build verschoenere ----------------------------------"; walther@60329: val t = TermC.str2term "3 + - 2 * e + 2 * f + 2 * g"; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false verschoenere t; walther@59868: if UnparseC.term t = "3 - 2 * e + 2 * f + 2 * g" then () walther@60329: else error "polyminus.sml: verschoenere 3 + - 2 * e ..."; neuper@37906: neuper@37906: neuper@37906: "----------- met simplification for_polynomials with_minus -------"; neuper@37906: "----------- met simplification for_polynomials with_minus -------"; neuper@37906: "----------- met simplification for_polynomials with_minus -------"; neuper@37906: val str = wneuper@59585: "Program SimplifyScript (t_t::real) = \ walther@59637: \ (((Try (Rewrite_Set ordne_alphabetisch False)) #> \ walther@59637: \ (Try (Rewrite_Set fasse_zusammen False)) #> \ neuper@38080: \ (Try (Rewrite_Set verschoenere False))) t_t)" Walther@60424: val sc = (inst_abs o (TermC.parseNEW' ctxt)) str; walther@60230: TermC.atomty sc; neuper@37906: neuper@38080: "----------- me simplification.for_polynomials.with_minus"; neuper@38080: "----------- me simplification.for_polynomials.with_minus"; neuper@38080: "----------- me simplification.for_polynomials.with_minus"; neuper@38080: val c = []; neuper@38080: val (p,_,f,nxt,_,pt) = neuper@38080: CalcTreeTEST neuper@38083: [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)", neuper@38080: "normalform N"], walther@59997: ("PolyMinus",["plus_minus", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_minus"]))]; neuper@38080: val (p,_,f,nxt,_,pt) = me nxt p c pt; neuper@38085: val (p,_,f,nxt,_,pt) = me nxt p c pt; neuper@38085: val (p,_,f,nxt,_,pt) = me nxt p c pt; neuper@38085: val (p,_,f,nxt,_,pt) = me nxt p c pt; neuper@38085: val (p,_,f,nxt,_,pt) = me nxt p c pt; neuper@38085: val (p,_,f,nxt,_,pt) = me nxt p c pt; neuper@37906: neuper@38085: val (p,_,f,nxt,_,pt) = me nxt p c pt; neuper@38085: val (p,_,f,nxt,_,pt) = me nxt p c pt; neuper@38085: val (p,_,f,nxt,_,pt) = me nxt p c pt; walther@60351: val (p,_,f,nxt,_,pt) = me nxt p c pt; walther@60351: val (p,_,f,nxt,_,pt) = me nxt p c pt; walther@60351: if f2str f = "3 - 2 * e + 2 * f + 2 * g" walther@59749: then case nxt of End_Proof' => () | _ => error "me simplification.for_polynomials.with_minus 1" walther@59749: else error "polyminus.sml: me simplification.for_polynomials.with_minus 2"; neuper@38085: neuper@37906: "----------- pbl polynom vereinfachen p.33 -----------------------"; neuper@37906: "----------- pbl polynom vereinfachen p.33 -----------------------"; neuper@37906: "----------- pbl polynom vereinfachen p.33 -----------------------"; neuper@37906: "----------- 140 c ---"; s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)", neuper@37906: "normalform N"], walther@59997: ("PolyMinus",["plus_minus", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_minus"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; neuper@37906: if p = ([], Res) andalso walther@59868: UnparseC.term (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g" neuper@38031: then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f..."; neuper@37906: neuper@42390: "======= 140 d ---"; s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)", neuper@37906: "normalform N"], walther@59997: ("PolyMinus",["plus_minus", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_minus"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; neuper@37906: if p = ([], Res) andalso walther@59868: UnparseC.term (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t" neuper@38031: then () else error "polyminus.sml: Vereinfache 140 d)"; neuper@37906: neuper@42390: "======= 139 c ---"; s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)", neuper@37906: "normalform N"], walther@59997: ("PolyMinus",["plus_minus", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_minus"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; neuper@37906: if p = ([], Res) andalso walther@59868: UnparseC.term (get_obj g_res pt (fst p)) = "- (3 * f)" neuper@38031: then () else error "polyminus.sml: Vereinfache 139 c)"; neuper@37906: neuper@42390: "======= 139 b ---"; s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)", neuper@37906: "normalform N"], walther@59997: ("PolyMinus",["plus_minus", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_minus"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; neuper@37906: if p = ([], Res) andalso walther@60325: UnparseC.term (get_obj g_res pt (fst p)) = "- 3 * u - v" neuper@38031: then () else error "polyminus.sml: Vereinfache 139 b)"; neuper@37906: neuper@42390: "======= 138 a ---"; s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)", neuper@37906: "normalform N"], walther@59997: ("PolyMinus",["plus_minus", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_minus"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; neuper@37906: if p = ([], Res) andalso walther@60325: UnparseC.term (get_obj g_res pt (fst p)) = "- 4 * u + 2 * v" neuper@38031: then () else error "polyminus.sml: Vereinfache 138 a)"; neuper@37906: neuper@37906: "----------- met probe fuer_polynom ------------------------------"; neuper@37906: "----------- met probe fuer_polynom ------------------------------"; neuper@37906: "----------- met probe fuer_polynom ------------------------------"; neuper@37906: val str = wneuper@59585: "Program ProbeScript (e_e::bool) (w_s::bool list) =\ neuper@37991: \ (let e_e = Take e_e; \ neuper@38085: \ e_e = Substitute w_s e_e \ walther@59637: \ in (Repeat((Try (Repeat (Calculate ''TIMES''))) #> \ walther@59637: \ (Try (Repeat (Calculate ''PLUS''))) #> \ wneuper@59488: \ (Try (Repeat (Calculate ''MINUS''))))) e_e)" Walther@60424: val sc = (inst_abs o (TermC.parseNEW' ctxt)) str; walther@60230: TermC.atomty sc; neuper@37906: neuper@37906: "----------- pbl polynom probe -----------------------------------"; neuper@37906: "----------- pbl polynom probe -----------------------------------"; neuper@37906: "----------- pbl polynom probe -----------------------------------"; s1210629013@55445: reset_states (); bonzai@41949: CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\ wneuper@59582: \3 - 2 * e + 2 * f + 2 * (g::int))", wneuper@59582: "mitWert [e = (1::int), f = (2::int), g = (3::int)]", neuper@37906: "Geprueft b"], walther@59997: ("PolyMinus",["polynom", "probe"], walther@59997: ["probe", "fuer_polynom"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; wneuper@59248: (* autoCalculate 1 CompleteCalcHead; walther@59747: autoCalculate 1 (Steps 1); walther@59747: autoCalculate 1 (Steps 1); walther@59868: val ((pt,p),_) = get_calc 1; UnparseC.term (get_obj g_res pt (fst p)); neuper@37906: @@@@@WN081114 gives "??.empty", all "Pruefe" are the same, neuper@37906: although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*) neuper@37906: val ((pt,p),_) = get_calc 1; walther@59868: if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "11 = 11" neuper@38031: then () else error "polyminus.sml: Probe 11 = 11"; walther@59983: Test_Tool.show_pt pt; t@42115: walther@60352: neuper@37906: "----------- pbl klammer polynom vereinfachen p.34 ---------------"; neuper@37906: "----------- pbl klammer polynom vereinfachen p.34 ---------------"; neuper@37906: "----------- pbl klammer polynom vereinfachen p.34 ---------------"; s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))", neuper@37906: "normalform N"], walther@59997: ("PolyMinus",["klammer", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_parentheses"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; neuper@37906: val ((pt,p),_) = get_calc 1; neuper@37906: if p = ([], Res) andalso walther@59868: UnparseC.term (get_obj g_res pt (fst p)) = "1 + 14 * u" neuper@38031: then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ..."; walther@59983: Test_Tool.show_pt pt; neuper@37906: neuper@42390: "======= probe p.34 -----"; s1210629013@55445: reset_states (); wneuper@59582: CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * (u::int))", wneuper@59582: "mitWert [u = (2::int)]", neuper@37906: "Geprueft b"], walther@59997: ("PolyMinus",["polynom", "probe"], walther@59997: ["probe", "fuer_polynom"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; neuper@37906: val ((pt,p),_) = get_calc 1; walther@59868: if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "29 = 29" neuper@38031: then () else error "polyminus.sml: Probe 29 = 29"; walther@59983: Test_Tool.show_pt pt; neuper@37906: walther@60352: neuper@37906: "----------- try fun applyTactics --------------------------------"; neuper@37906: "----------- try fun applyTactics --------------------------------"; neuper@37906: "----------- try fun applyTactics --------------------------------"; s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)", neuper@37906: "normalform N"], walther@59997: ("PolyMinus",["plus_minus", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_minus"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalcHead; walther@59747: autoCalculate 1 (Steps 1); walther@59747: autoCalculate 1 (Steps 1); walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@60242: "----- 1 \ "; neuper@37906: fetchApplicableTactics 1 0 p; walther@59823: val appltacs = specific_from_prog pt p; neuper@37906: applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*); walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@60242: "----- 2 \ "; walther@59901: (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*) neuper@37906: val erls = erls_ordne_alphabetisch; walther@60230: val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g"; neuper@37926: val SOME (t',_) = Walther@60509: rewrite_ ctxt Rewrite_Ord.function_empty erls false @{thm tausche_minus} t; walther@59868: UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g"; neuper@37906: walther@60230: val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g"; neuper@37926: val NONE = Walther@60509: rewrite_ ctxt Rewrite_Ord.function_empty erls false @{thm tausche_minus_plus} t; neuper@37906: walther@60230: val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g"; neuper@37926: val SOME (t',_) = Walther@60500: rewrite_set_ ctxt false ordne_alphabetisch t; walther@59868: UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f"; neuper@37906: neuper@37906: walther@59823: applyTactic 1 p (hd (specific_from_prog pt p)) (*tausche_minus*); walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@60242: "----- 3 \ "; walther@59823: applyTactic 1 p (hd (specific_from_prog pt p)) (**); walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@60242: "----- 4 \ "; walther@59823: applyTactic 1 p (hd (specific_from_prog pt p)) (**); walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@60242: "----- 5 \ "; walther@59823: applyTactic 1 p (hd (specific_from_prog pt p)) (**); walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@60242: "----- 6 \ "; neuper@37906: neuper@37906: (* failure walther@59823: applyTactic 1 p (hd (specific_from_prog pt p)) (**); walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@60242: "----- 7 \ "; neuper@37906: *) wneuper@59248: autoCalculate 1 CompleteCalc; walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; neuper@37906: (*independent from failure above: met_simp_poly_minus not confluent: neuper@37906: (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)), neuper@37906: (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))] neuper@37906: ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*) walther@60352: val ([], Res) = p; walther@60352: val "2 * g + (3 - 2 * e + 2 * f)" = get_obj g_res pt (fst p) |> UnparseC.term; walther@60352: (* ---------^^^--- not quite perfect*) t@42115: neuper@37906: neuper@42107: "#############################################################################"; s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term (- (8 * g) + 10 * g + h)", neuper@37906: "normalform N"], walther@59997: ("PolyMinus",["plus_minus", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_minus"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@59868: if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "2 * g + h" neuper@38031: then () else error "polyminus.sml: addiere_vor_minus"; neuper@37906: neuper@37906: neuper@42107: "#############################################################################"; s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term (- (8 * g) + 10 * g + f)", neuper@37906: "normalform N"], walther@59997: ("PolyMinus",["plus_minus", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_minus"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@59868: if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "f + 2 * g" neuper@38031: then () else error "polyminus.sml: tausche_vor_plus"; neuper@37906: neuper@37906: "----------- pbl binom polynom vereinfachen p.39 -----------------"; neuper@37906: "----------- pbl binom polynom vereinfachen p.39 -----------------"; neuper@37906: "----------- pbl binom polynom vereinfachen p.39 -----------------"; walther@60333: val thy = @{theory}; neuper@37906: val rls = klammern_ausmultiplizieren; walther@60333: val t = TermC.str2term "(3 * a + 2) * (4 * a - 1::real)"; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t; neuper@37906: "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)"; neuper@37906: val rls = discard_parentheses; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t; neuper@37906: "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)"; neuper@37906: val rls = ordne_monome; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t; neuper@37906: "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)"; neuper@37906: (* walther@60230: val t = TermC.str2term "3 * a * 4 * a"; neuper@37906: val rls = ordne_monome; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t; neuper@37906: *) neuper@37906: val rls = klammern_aufloesen; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t; neuper@37906: "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2"; neuper@37906: val rls = ordne_alphabetisch; neuper@37906: (*TODO: make is_monom more general, a*a=a^2, ...*) Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t; neuper@37906: "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a"; neuper@41977: (*STOPPED.WN080104 neuper@37906: val rls = fasse_zusammen; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t; neuper@37906: val rls = verschoenere; Walther@60500: val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t; neuper@37906: *) neuper@37906: neuper@37906: (*@@@@@@@*) s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term ((3*a + 2) * (4*a - 1))", neuper@37906: "normalform N"], walther@59997: ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_parentheses_mult"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@60325: walther@60325: if p = ([], Res) andalso walther@60325: UnparseC.term (get_obj g_res pt (fst p)) =(*"- 2 + 12 * a \ 2 + 5 * a" with OLD numerals*) walther@60325: "- 2 + 5 * a + 12 * a \ 2" neuper@38031: then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ..."; t@42111: neuper@37906: "----------- pbl binom polynom vereinfachen: cube ----------------"; neuper@37906: "----------- pbl binom polynom vereinfachen: cube ----------------"; neuper@37906: "----------- pbl binom polynom vereinfachen: cube ----------------"; s1210629013@55445: reset_states (); neuper@38083: CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"], walther@59997: ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"], walther@59997: ["simplification", "for_polynomials", "with_parentheses_mult"]))]; neuper@37906: moveActiveRoot 1; wneuper@59248: autoCalculate 1 CompleteCalc; walther@59983: val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt; walther@59868: if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "12 * a - 16 * q" neuper@42107: then () else error "pbl binom polynom vereinfachen: cube"; neuper@37906: walther@59968: "----------- Refine.refine Vereinfache ----------------------------------"; walther@59968: "----------- Refine.refine Vereinfache ----------------------------------"; walther@59968: "----------- Refine.refine Vereinfache ----------------------------------"; neuper@42390: val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"]; wneuper@59348: (*default_print_depth 11;*) wenzelm@60237: val matches = Refine.refine fmz ["vereinfachen"]; wneuper@59348: (*default_print_depth 3;*) neuper@37906: neuper@37906: "----- go into details, if it seems not to work -----"; neuper@37906: "--- does the predicate evaluate correctly ?"; walther@60230: val t = TermC.str2term neuper@42390: "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))"; Walther@60504: val ma = eval_matchsub "" "Prog_Expr.matchsub" t ctxt; neuper@37906: case ma of neuper@37926: SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \ neuper@37906: \a - 2 * q + 3 * (a - 2 * q)) = True", _) => () neuper@38031: | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A"; neuper@37906: neuper@37906: "--- does the respective prls rewrite ?"; walther@59852: val prls = Rule_Set.append_rules "prls_pbl_vereinf_poly" Rule_Set.empty walther@60278: [Eval ("Poly.is_polyexp", eval_is_polyexp ""), walther@59878: Eval ("Prog_Expr.matchsub", eval_matchsub ""), neuper@38085: Thm ("or_true",@{thm or_true}), neuper@37906: (*"(?a | True) = True"*) neuper@38085: Thm ("or_false",@{thm or_false}), neuper@37906: (*"(?a | False) = ?a"*) walther@60337: Thm ("not_true", @{thm not_true}), neuper@37906: (*"(~ True) = False"*) walther@60337: Thm ("not_false", @{thm not_false}) neuper@37906: (*"(~ False) = True"*)]; walther@59901: (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*) Walther@60500: val SOME (t', _) = rewrite_set_ ctxt false prls t; neuper@37906: neuper@37906: "--- does the respective prls rewrite the whole predicate ?"; walther@60230: val t = TermC.str2term neuper@37906: "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \ neuper@37906: \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \ neuper@37906: \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \ neuper@37906: \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )"; walther@59901: (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*) Walther@60500: val SOME (t', _) = rewrite_set_ ctxt false prls t; walther@59868: if UnparseC.term t' = "False" then () neuper@38031: else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ..."; neuper@37906: walther@59973: "----------- *** Problem.prep_input: syntax error in '#Where' of [v"; walther@59973: "----------- *** Problem.prep_input: syntax error in '#Where' of [v"; walther@59973: "----------- *** Problem.prep_input: syntax error in '#Where' of [v"; neuper@38037: (*see test/../termC.sml for details*) walther@60230: val t = TermC.parse_patt thy "t_t is_polyexp"; walther@60230: val t = TermC.parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^ neuper@38037: " matchsub (?a + (?b - ?c)) t_t | " ^ neuper@38037: " matchsub (?a - (?b + ?c)) t_t | " ^ neuper@38037: " matchsub (?a + (?b - ?c)) t_t )"); neuper@42390: (*show_types := true; walther@59868: if UnparseC.term t = "~ (matchsub ((?a::real) + ((?b::real) + (?c::real))) (t_t::real) |\n matchsub (?a + (?b - ?c)) t_t |\n matchsub (?a - (?b + ?c)) t_t | matchsub (?a + (?b - ?c)) t_t)" neuper@38038: then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1"; neuper@42390: show_types := false;*) walther@59868: if UnparseC.term t = wneuper@59371: "\ (matchsub (?a + (?b + ?c)) t_t \\n " ^ wneuper@59371: "matchsub (?a + (?b - ?c)) t_t \\n " ^ wneuper@59371: "matchsub (?a - (?b + ?c)) t_t \ " ^ wneuper@59371: "matchsub (?a + (?b - ?c)) t_t)" neuper@42390: then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1"; neuper@37906: