wneuper@59424: theory Base_Tools walther@60149: imports Interpret.Interpret walther@60149: (** )"../BridgeJEdit/BridgeJEdit" ( *activate after devel.of BridgeJEdit*) walther@60149: (**) "../BridgeLibisabelle/BridgeLibisabelle" (*remove after devel.of BridgeJEdit*) walther@60149: (* ^^^ for KEStore_Elems.add_thes *) wneuper@59424: begin wneuper@59602: subsection \theorems for Base_Tools\ walther@60273: walther@60384: lemma real_unari_minus: "Not (a is_num) ==> - a = (-1) * (a::real)" by auto walther@60318: (*lemma real_unari_minus: "- a = (-1) * (a::real)" by auto LOOPS WITH NUMERALS*) walther@60273: (*Semiring_Normalization.comm_ring_1_class.ring_normalization_rules(1)*) walther@60273: walther@60273: (* should be in Rational.thy, but needed for asms in e.g. d2_pqformula1 in PolyEq, RootEq... *) walther@60274: lemma radd_left_cancel_le: "((k::real) + m \ k + n) = (m \ n)" by auto walther@60273: (*Groups.ordered_ab_semigroup_add_imp_le_class.add_le_cancel_left*) walther@60273: walther@60274: thm "Fields.linordered_field_class.mult_imp_le_div_pos" (*0 < ?y \ ?z * ?y \ ?x \ ?z \ ?x / ?y*) walther@60274: wneuper@59602: axiomatization where (*for evaluating the assumptions of conditional rules*) walther@60273: (* should be in Rational.thy, but needed for asms in e.g. d2_pqformula1 in PolyEq, RootEq... *) walther@60274: rat_leq1: "0 \ b \ 0 \ d \ (a / b \ c / d) = (a * d \ b * c)"(*Quickcheck found a counterexample*) and walther@60274: rat_leq2: "0 \ d \ (a \ c / d) = (a * d \ c)"(*Quickcheck found a counterexample*) and walther@60274: rat_leq3: "0 \ b \ (a / b \ c ) = (a \ b * c)"(*Quickcheck found a counterexample*) wneuper@59602: wneuper@59602: wneuper@59602: subsection \setup for ML-functions\ wneuper@59602: text \required by "eval_binop" below\ wenzelm@60313: calculation occurs_in = \Prog_Expr.eval_occurs_in "#occurs_in_"\ wenzelm@60313: calculation some_occur_in = \Prog_Expr.eval_some_occur_in "#some_occur_in_"\ wenzelm@60313: calculation is_atom = \Prog_Expr.eval_is_atom "#is_atom_"\ wenzelm@60313: calculation is_even = \Prog_Expr.eval_is_even "#is_even_"\ wenzelm@60313: calculation le (less) = \Prog_Expr.eval_equ "#less_"\ wenzelm@60313: calculation leq (less_eq) = \Prog_Expr.eval_equ "#less_equal_"\ wenzelm@60313: calculation ident = \Prog_Expr.eval_ident "#ident_"\ wenzelm@60313: calculation equal (HOL.eq) = \Prog_Expr.eval_equal "#equal_"\ wenzelm@60313: calculation PLUS (plus) = \(**)eval_binop "#add_"\ wenzelm@60313: calculation MINUS (minus) = \(**)eval_binop "#sub_"\ wenzelm@60313: calculation TIMES (times) = \(**)eval_binop "#mult_"\ wenzelm@60313: calculation DIVIDE (divide) = \Prog_Expr.eval_cancel "#divide_e"\ wenzelm@60405: calculation POWER (realpow) = \(**)eval_binop "#power_"\ wenzelm@60313: calculation boollist2sum = \Prog_Expr.eval_boollist2sum ""\ wneuper@59602: wneuper@59602: subsection \rewrite-order for rule-sets\ wneuper@59602: ML \ wneuper@59602: \ ML \ wneuper@59602: local wneuper@59602: open Term; wneuper@59602: in walther@59910: fun termlessI (_: subst) uv = LibraryC.termless uv; walther@59910: fun term_ordI (_: subst) uv = Term_Ord.term_ord uv; wneuper@59602: end; wneuper@59602: \ ML \ Walther@60509: (*TODO.WN0509 reduce ids: tless_true = e_rew_ord' = Rewrite_Ord.function_empty = Rewrite_Ord.function_empty*) Walther@60509: val tless_true = Rewrite_Ord.function_empty; Walther@60506: \ ML \ Walther@60506: \ Walther@60506: setup \KEStore_Elems.add_rew_ord [ Walther@60506: ("tless_true", tless_true), Walther@60509: ("Rewrite_Ord.id_empty", tless_true), Walther@60506: ("e_rew_ord'", tless_true), Walther@60509: ("dummy_ord", Rewrite_Ord.function_empty)]\ wneuper@59602: wneuper@59602: subsection \rule-sets\ wneuper@59602: ML \ wneuper@59602: \ ML \ walther@60358: val Atools_erls = Rule_Set.append_rules "Atools_erls" Rule_Set.empty [ walther@60358: \<^rule_eval>\HOL.eq\ (Prog_Expr.eval_equal "#equal_"), walther@60358: \<^rule_thm>\not_true\, (*"(~ True) = False"*) walther@60358: \<^rule_thm>\not_false\, (*"(~ False) = True"*) walther@60358: \<^rule_thm>\and_true\, (*"(?a & True) = ?a"*) walther@60358: \<^rule_thm>\and_false\, (*"(?a & False) = False"*) walther@60358: \<^rule_thm>\or_true\, (*"(?a | True) = True"*) walther@60358: \<^rule_thm>\or_false\, (*"(?a | False) = ?a"*) walther@60358: walther@60358: \<^rule_thm>\rat_leq1\, walther@60358: \<^rule_thm>\rat_leq2\, walther@60358: \<^rule_thm>\rat_leq3\, walther@60358: \<^rule_thm>\refl\, walther@60358: \<^rule_thm>\order_refl\, walther@60358: \<^rule_thm>\radd_left_cancel_le\, walther@60358: walther@60358: \<^rule_eval>\less\ (Prog_Expr.eval_equ "#less_"), walther@60358: \<^rule_eval>\less_eq\ (Prog_Expr.eval_equ "#less_equal_"), walther@60358: walther@60358: \<^rule_eval>\Prog_Expr.ident\ (Prog_Expr.eval_ident "#ident_"), walther@60385: \<^rule_eval>\Prog_Expr.is_num\ (Prog_Expr.eval_is_num "#is_num_"), walther@60358: \<^rule_eval>\Prog_Expr.occurs_in\ (Prog_Expr.eval_occurs_in ""), walther@60358: \<^rule_eval>\Prog_Expr.matches\ (Prog_Expr.eval_matches "")]; wneuper@59602: \ wneuper@59602: wneuper@59602: ML \ walther@60358: val Atools_crls = Rule_Set.append_rules "Atools_crls" Rule_Set.empty [ walther@60358: \<^rule_eval>\HOL.eq\ (Prog_Expr.eval_equal "#equal_"), walther@60358: \<^rule_thm>\not_true\, walther@60358: \<^rule_thm>\not_false\, walther@60358: \<^rule_thm>\and_true\, walther@60358: \<^rule_thm>\and_false\, walther@60358: \<^rule_thm>\or_true\, walther@60358: \<^rule_thm>\or_false\, walther@60358: walther@60358: \<^rule_thm>\rat_leq1\, walther@60358: \<^rule_thm>\rat_leq2\, walther@60358: \<^rule_thm>\rat_leq3\, walther@60358: \<^rule_thm>\refl\, walther@60358: \<^rule_thm>\order_refl\, walther@60358: \<^rule_thm>\radd_left_cancel_le\, walther@60358: walther@60358: \<^rule_eval>\less\ (Prog_Expr.eval_equ "#less_"), walther@60358: \<^rule_eval>\less_eq\ (Prog_Expr.eval_equ "#less_equal_"), walther@60358: walther@60358: \<^rule_eval>\Prog_Expr.ident\ (Prog_Expr.eval_ident "#ident_"), walther@60385: \<^rule_eval>\Prog_Expr.is_num\ (Prog_Expr.eval_is_num "#is_num_"), walther@60358: \<^rule_eval>\Prog_Expr.occurs_in\ (Prog_Expr.eval_occurs_in ""), walther@60358: \<^rule_eval>\Prog_Expr.matches\ (Prog_Expr.eval_matches "")]; wneuper@59602: \ wneuper@59602: wneuper@59602: subsection \ONCE AGAIN extend rule-set for evaluating pre-conditions and program-expressions\ wneuper@59602: text \requires "eval_binop" from above\ wneuper@59602: ML \ walther@60358: val prog_expr = Rule_Set.append_rules "prog_expr" prog_expr [ walther@60358: \<^rule_eval>\times\ (**)(eval_binop "#mult_"), walther@60358: \<^rule_eval>\plus\ (**)(eval_binop "#add_"), walther@60358: \<^rule_eval>\less\ (Prog_Expr.eval_equ "#less_"), walther@60358: \<^rule_eval>\less_eq\ (Prog_Expr.eval_equ "#less_equal_"), walther@60358: \<^rule_eval>\Prog_Expr.ident\ (Prog_Expr.eval_ident "#ident_"), walther@60358: \<^rule_eval>\HOL.eq\ (Prog_Expr.eval_equal "#equal_"),(*atom <> atom -> False*) walther@60358: walther@60358: \<^rule_eval>\Prog_Expr.Vars\ (Prog_Expr.eval_var "#Vars_"), walther@60358: walther@60358: \<^rule_thm>\if_True\, walther@60358: \<^rule_thm>\if_False\]; wneuper@59602: walther@59852: val prog_expr = Auto_Prog.prep_rls @{theory} (Rule_Set.merge "list_erls" walther@59851: (Rule_Def.Repeat {id = "replaced", preconds = [], rew_ord = ("termlessI", termlessI), walther@59851: erls = Rule_Def.Repeat {id = "list_elrs", preconds = [], rew_ord = ("termlessI", termlessI), walther@59852: erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [], walther@60358: rules = [ walther@60358: \<^rule_eval>\plus\ (**)(eval_binop "#add_"), walther@60358: \<^rule_eval>\less\ (Prog_Expr.eval_equ "#less_") (*..for nth_Cons_*)], walther@59878: scr = Rule.Empty_Prog}, walther@59851: srls = Rule_Set.Empty, calc = [], errpatts = [], walther@59878: rules = [], scr = Rule.Empty_Prog}) walther@59801: prog_expr); wneuper@59602: \ wenzelm@60286: wneuper@59602: subsection \setup for extended rule-set\ wenzelm@60286: wenzelm@60289: rule_set_knowledge prog_expr = \Auto_Prog.prep_rls @{theory} prog_expr\ wneuper@59602: walther@60278: ML \ walther@60278: \ ML \ walther@60278: \ ML \ walther@60278: \ walther@60077: end