eliminate global flag Rewrite.trace_on
authorwneuper <Walther.Neuper@jku.at>
Sat, 30 Jul 2022 16:47:45 +0200
changeset 6050059a3af532717
parent 60499 d2407e9cb491
child 60501 3be00036a653
eliminate global flag Rewrite.trace_on
TODO.md
src/Tools/isac/BaseDefinitions/substitution.sml
src/Tools/isac/BaseDefinitions/theoryC.sml
src/Tools/isac/BaseDefinitions/unparseC.sml
src/Tools/isac/BridgeLibisabelle/datatypes.sml
src/Tools/isac/Interpret/derive.sml
src/Tools/isac/Interpret/error-pattern.sml
src/Tools/isac/Interpret/istate.sml
src/Tools/isac/Interpret/li-tool.sml
src/Tools/isac/Interpret/lucas-interpreter.sml
src/Tools/isac/Interpret/solve-step.sml
src/Tools/isac/Knowledge/Rational.thy
src/Tools/isac/MathEngBasic/rewrite.sml
src/Tools/isac/MathEngBasic/tactic.sml
src/Tools/isac/MathEngine/detail-step.sml
src/Tools/isac/MathEngine/fetch-tactics.sml
src/Tools/isac/Specify/pre-conditions.sml
test/Tools/isac/ADDTESTS/course/phst11/T2_Rewriting.thy
test/Tools/isac/BaseDefinitions/rewrite-order.sml
test/Tools/isac/BaseDefinitions/substitution.sml
test/Tools/isac/Interpret/error-pattern.sml
test/Tools/isac/Knowledge/algein.sml
test/Tools/isac/Knowledge/biegelinie-1.sml
test/Tools/isac/Knowledge/diff-app.sml
test/Tools/isac/Knowledge/diff.sml
test/Tools/isac/Knowledge/diophanteq.sml
test/Tools/isac/Knowledge/eqsystem-1.sml
test/Tools/isac/Knowledge/eqsystem-2.sml
test/Tools/isac/Knowledge/inssort.sml
test/Tools/isac/Knowledge/integrate.sml
test/Tools/isac/Knowledge/poly-1.sml
test/Tools/isac/Knowledge/polyeq-1.sml
test/Tools/isac/Knowledge/polyeq-2.sml
test/Tools/isac/Knowledge/polyminus.sml
test/Tools/isac/Knowledge/rateq.sml
test/Tools/isac/Knowledge/rational-1.sml
test/Tools/isac/Knowledge/rational-2.sml
test/Tools/isac/Knowledge/root.sml
test/Tools/isac/Knowledge/rootrat.sml
test/Tools/isac/Knowledge/rootrateq.sml
test/Tools/isac/Knowledge/simplify.sml
test/Tools/isac/MathEngBasic/rewrite.sml
test/Tools/isac/MathEngine/mathengine-stateless.sml
test/Tools/isac/Minisubpbl/200-start-method-NEXT_STEP.sml
test/Tools/isac/Minisubpbl/300-init-subpbl.sml
test/Tools/isac/ProgLang/auto_prog.sml
test/Tools/isac/ProgLang/evaluate.sml
test/Tools/isac/ProgLang/listC.sml
test/Tools/isac/ProgLang/prog_expr.sml
test/Tools/isac/Test_Isac.thy
     1.1 --- a/TODO.md	Thu Jul 28 11:43:27 2022 +0200
     1.2 +++ b/TODO.md	Sat Jul 30 16:47:45 2022 +0200
     1.3 @@ -85,6 +85,16 @@
     1.4    val rewrite_trace = Attrib.setup_config_bool \<^binding>\<open>rewrite_trace\<close> (K false);
     1.5  \<close>
     1.6  
     1.7 +* WN: rewriting with ctxt not complete (cause errors hard to indentify later)
     1.8 +    - Prconditions.eval
     1.9 +    - Solve_Step.check ..Rewrite_Inst, Substitute, ..
    1.10 +    - Error_Pattern.check_for', fill_form
    1.11 +    - Derive.steps
    1.12 +    - Fetch_Tacs.specific_from_prog ?
    1.13 +    - ? LIST IS NOT COMPLETE
    1.14 +
    1.15 +* WN: ? Rational.Cancel_p; extend use of \<^theory> to \<^theory_context>
    1.16 +
    1.17  * WN: redesign transition from Specification to Solution: how relate 
    1.18      - Formalise.model with variants (e.g. VSCode_Example)
    1.19        reconsider separation of variants F_I, F_II, see MAWEN paper
     2.1 --- a/src/Tools/isac/BaseDefinitions/substitution.sml	Thu Jul 28 11:43:27 2022 +0200
     2.2 +++ b/src/Tools/isac/BaseDefinitions/substitution.sml	Sat Jul 30 16:47:45 2022 +0200
     2.3 @@ -25,7 +25,7 @@
     2.4    val T_to_string_eqs: T -> as_string_eqs
     2.5    val T_to_input: T -> input
     2.6    val T_from_string_eqs: theory -> as_string_eqs -> T
     2.7 -  val T_from_input: theory -> input -> T
     2.8 +  val T_from_input: Proof.context -> input -> T
     2.9  
    2.10    val input_to_terms: input -> term list
    2.11    val eqs_to_input: as_eqs -> as_string_eqs
    2.12 @@ -70,8 +70,8 @@
    2.13  
    2.14  fun T_from_string_eqs thy s = map (TermC.dest_equals o (TermC.parse_patt thy)) s;
    2.15  (*TODO: input requires parse _: _ -> _ option*)
    2.16 -fun T_from_input thy input = (input
    2.17 -  |> map (TermC.parse_patt thy(*FIXME use context, get type of snd (e.g. x,y,z), copy to fst*))
    2.18 +fun T_from_input ctxt input = (input
    2.19 +  |> map (TermC.parse_patt (Proof_Context.theory_of ctxt))
    2.20    |> map TermC.isapair2pair
    2.21    |> map (apfst HOLogic.dest_string)
    2.22    |> map (apfst (fn str => (TermC.mk_Free (str, HOLogic.realT)))))
     3.1 --- a/src/Tools/isac/BaseDefinitions/theoryC.sml	Thu Jul 28 11:43:27 2022 +0200
     3.2 +++ b/src/Tools/isac/BaseDefinitions/theoryC.sml	Sat Jul 30 16:47:45 2022 +0200
     3.3 @@ -52,7 +52,8 @@
     3.4  
     3.5  fun id_to_ctxt thy' = Proof_Context.init_global (get_theory thy');
     3.6  
     3.7 -fun Isac _ = Proof_Context.theory_of (id_to_ctxt "Isac_Knowledge");
     3.8 +fun Isac _ = 
     3.9 + (get_theory "Isac_Knowledge");
    3.10  
    3.11  fun parent_of thy1 thy2 = if Context.subthy (thy1, thy2) then thy2 else thy1;
    3.12  
     4.1 --- a/src/Tools/isac/BaseDefinitions/unparseC.sml	Thu Jul 28 11:43:27 2022 +0200
     4.2 +++ b/src/Tools/isac/BaseDefinitions/unparseC.sml	Sat Jul 30 16:47:45 2022 +0200
     4.3 @@ -12,6 +12,7 @@
     4.4  
     4.5    val term: term -> term_as_string
     4.6    val term_in_ctxt: Proof.context -> term -> term_as_string
     4.7 +  val terms_in_ctxt: Proof.context -> term list -> term_as_string
     4.8    val term_in_thy: theory -> term -> term_as_string
     4.9  
    4.10    val term_opt: term option -> term_as_string
    4.11 @@ -43,6 +44,9 @@
    4.12    in
    4.13      Print_Mode.setmp [] (Syntax.string_of_term ctxt') t
    4.14    end;
    4.15 +fun terms_in_ctxt ctxt ts = ts |> map (term_in_ctxt ctxt) |> strs2str';
    4.16 +
    4.17 +
    4.18  \<^isac_test>\<open>
    4.19  fun term_by_thyID thyID t =
    4.20    let
     5.1 --- a/src/Tools/isac/BridgeLibisabelle/datatypes.sml	Thu Jul 28 11:43:27 2022 +0200
     5.2 +++ b/src/Tools/isac/BridgeLibisabelle/datatypes.sml	Sat Jul 30 16:47:45 2022 +0200
     5.3 @@ -173,9 +173,11 @@
     5.4      XML.Elem (("VARIABLE", []), [xml_of_term id]),
     5.5      XML.Elem (("VALUE", []), [xml_of_term value])])
     5.6  fun xml_of_subs (subs : Subst.input) =
     5.7 -  XML.Elem (("SUBSTITUTION", []), map xml_of_sub (Subst.T_from_input (ThyC.get_theory "Isac_Knowledge") subs))
     5.8 +  XML.Elem (("SUBSTITUTION", []), 
     5.9 +    map xml_of_sub (Subst.T_from_input (ThyC.id_to_ctxt "Isac_Knowledge") subs))
    5.10  fun xml_of_sube sube =
    5.11 -  XML.Elem (("SUBSTITUTION", []), map xml_of_sub (Subst.T_from_string_eqs (ThyC.get_theory "Isac_Knowledge") sube))
    5.12 +  XML.Elem (("SUBSTITUTION", []), 
    5.13 +    map xml_of_sub (Subst.T_from_string_eqs (ThyC.get_theory "Isac_Knowledge") sube))
    5.14  
    5.15  fun thm''2xml j (thm : thm) =
    5.16      indt j ^ "<THEOREM>\n" ^
     6.1 --- a/src/Tools/isac/Interpret/derive.sml	Thu Jul 28 11:43:27 2022 +0200
     6.2 +++ b/src/Tools/isac/Interpret/derive.sml	Sat Jul 30 16:47:45 2022 +0200
     6.3 @@ -14,9 +14,9 @@
     6.4    type step
     6.5    type derivation
     6.6  
     6.7 -  val do_one : theory -> Rule_Set.T -> Rule.rule list -> Rule_Def.rew_ord_ ->
     6.8 +  val do_one : Proof.context -> Rule_Set.T -> Rule.rule list -> Rule_Def.rew_ord_ ->
     6.9      term option -> term -> derivation
    6.10 -  val steps_reverse : theory -> Rule_Set.T -> Rule.rule list -> Rule_Def.rew_ord_ ->
    6.11 +  val steps_reverse : Proof.context -> Rule_Set.T -> Rule.rule list -> Rule_Def.rew_ord_ ->
    6.12      term option -> term -> rule_result list
    6.13    val steps : Rule_Def.rew_ord -> Rule_Set.T -> Rule.rule list -> term -> term ->
    6.14      bool * derivation
    6.15 @@ -50,17 +50,17 @@
    6.16  fun msg_1 rts =
    6.17    (tracing ("do_one exceeds " ^ int2str (! Rewrite.lim_deriv) ^ "with derivation =\n");
    6.18     tracing (deriv2str rts));
    6.19 -fun msg_2 thmid =
    6.20 -  if not (! Rewrite.trace_on) then () else tracing ("### trying thm \"" ^ thmid ^ "\"");
    6.21 -fun msg_3 t' =
    6.22 -  if ! Rewrite.trace_on then tracing ("=== rewrites to: " ^ UnparseC.term t') else ();
    6.23 -fun msg_4 op_ =
    6.24 -  if not (! Rewrite.trace_on) then () else tracing ("### trying calc. \"" ^ op_^"\"");
    6.25 -fun msg_5 t' =
    6.26 -  if not (! Rewrite.trace_on) then () else tracing("=== calc. to: " ^ UnparseC.term t')
    6.27 +fun msg_2 ctxt thmid =
    6.28 +  if not (Config.get ctxt rewrite_trace) then () else tracing ("### trying thm \"" ^ thmid ^ "\"");
    6.29 +fun msg_3 ctxt t' =
    6.30 +  if Config.get ctxt rewrite_trace then tracing ("=== rewrites to: " ^ UnparseC.term t') else ();
    6.31 +fun msg_4 ctxt op_ =
    6.32 +  if not (Config.get ctxt rewrite_trace) then () else tracing ("### trying calc. \"" ^ op_^"\"");
    6.33 +fun msg_5 ctxt t' =
    6.34 +  if not (Config.get ctxt rewrite_trace) then () else tracing("=== calc. to: " ^ UnparseC.term t')
    6.35  
    6.36  
    6.37 -fun do_one thy erls rs ro goal tt = 
    6.38 +fun do_one ctxt erls rs ro goal tt = 
    6.39    let 
    6.40      datatype switch = Appl | Noap (* TODO: unify with version in Rewrite *)
    6.41      fun rew_once _ rts t Noap [] = 
    6.42 @@ -77,26 +77,26 @@
    6.43        else
    6.44          (case r of
    6.45            Rule.Thm (thmid, tm) => 
    6.46 -            (msg_2 thmid;
    6.47 -            case Rewrite.rewrite_ thy ro erls true tm t of
    6.48 +            (msg_2 ctxt thmid;
    6.49 +            case Rewrite.rewrite_ ctxt ro erls true tm t of
    6.50                NONE => rew_once lim rts t apno rs'
    6.51              | SOME (t', a') =>
    6.52 -              (msg_3 t'; rew_once (lim - 1) (rts @ [(t, r, (t', a'))]) t' Appl rrs'))
    6.53 +              (msg_3 ctxt t'; rew_once (lim - 1) (rts @ [(t, r, (t', a'))]) t' Appl rrs'))
    6.54          | Rule.Eval (c as (op_, _)) => 
    6.55 -            (msg_4 op_;
    6.56 -            case Eval.adhoc_thm thy c t of
    6.57 +            (msg_4 ctxt op_;
    6.58 +            case Eval.adhoc_thm (Proof_Context.theory_of ctxt) c t of
    6.59                NONE => rew_once lim rts t apno rs'
    6.60              | SOME (thmid, tm) => 
    6.61                (let
    6.62 -                val (t', a') = case Rewrite.rewrite_ thy ro erls true tm t of
    6.63 +                val (t', a') = case Rewrite.rewrite_ ctxt ro erls true tm t of
    6.64                    SOME ta => ta
    6.65                  | NONE => raise ERROR "adhoc_thm: NONE"
    6.66 -                val _ = msg_5 t'
    6.67 +                val _ = msg_5 ctxt t'
    6.68                  val r' = Rule.Thm (thmid, tm)
    6.69                in rew_once (lim - 1) (rts @ [(t, r', (t', a'))]) t' Appl rrs' end) 
    6.70                  handle Rewrite.NO_REWRITE => raise ERROR "derive_norm, Eval: no rewrite")
    6.71          | Rule.Rls_ rls =>
    6.72 -          (case Rewrite.rewrite_set_ thy true rls t of
    6.73 +          (case Rewrite.rewrite_set_ ctxt true rls t of
    6.74              NONE => rew_once lim rts t apno rs'
    6.75            | SOME (t', a') => rew_once (lim - 1) (rts @ [(t, r, (t', a'))]) t' Appl rrs')
    6.76          | rule => raise ERROR ("rew_once: uncovered case " ^ Rule.to_string rule))
    6.77 @@ -121,8 +121,8 @@
    6.78      fun derivat ([]:(term * Rule.rule * (term * term list)) list) = TermC.empty
    6.79        | derivat dt = (#1 o #3 o last_elem) dt
    6.80      fun equal (_, _, (t1, _)) (_, _, (t2, _)) = t1 = t2
    6.81 -    val  fod = do_one (ThyC.Isac()) erls rules (snd rew_ord) NONE  fo
    6.82 -    val ifod = do_one (ThyC.Isac()) erls rules (snd rew_ord) NONE ifo
    6.83 +    val  fod = do_one (Proof_Context.init_global (ThyC.Isac())) erls rules (snd rew_ord) NONE  fo
    6.84 +    val ifod = do_one (Proof_Context.init_global (ThyC.Isac())) erls rules (snd rew_ord) NONE ifo
    6.85    in 
    6.86      case (fod, ifod) of
    6.87        ([], []) => if fo = ifo then (true, []) else (false, [])
     7.1 --- a/src/Tools/isac/Interpret/error-pattern.sml	Thu Jul 28 11:43:27 2022 +0200
     7.2 +++ b/src/Tools/isac/Interpret/error-pattern.sml	Sat Jul 30 16:47:45 2022 +0200
     7.3 @@ -55,16 +55,18 @@
     7.4    check if (agreed result, input formula) matches the error pattern "pat" modulo simplifier rls
     7.5  *)
     7.6  fun check_for' (res, inf) subst (id, pat) rls =
     7.7 -  let 
     7.8 -    val (res', _, _, rewritten) = Rewrite.rew_sub (ThyC.Isac()) 1 subst Rewrite_Ord.e_rew_ord
     7.9 -      Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
    7.10 +  let
    7.11 +    val ctxt = Proof_Context.init_global ((ThyC.Isac()))
    7.12 +    val (res', _, _, rewritten) =
    7.13 +      Rewrite.rew_sub ctxt 1 subst Rewrite_Ord.e_rew_ord
    7.14 +        Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
    7.15    in
    7.16      if rewritten then 
    7.17        let
    7.18 -        val norm_res = case Rewrite.rewrite_set_inst_ (ThyC.Isac()) false subst rls  res' of
    7.19 +        val norm_res = case Rewrite.rewrite_set_inst_ ctxt false subst rls  res' of
    7.20              NONE => res'
    7.21            | SOME (norm_res, _) => norm_res
    7.22 -        val norm_inf = case Rewrite.rewrite_set_inst_ (ThyC.Isac()) false subst rls inf of
    7.23 +        val norm_inf = case Rewrite.rewrite_set_inst_ ctxt false subst rls inf of
    7.24              NONE => inf
    7.25            | SOME (norm_inf, _) => norm_inf
    7.26        in
    7.27 @@ -96,8 +98,9 @@
    7.28    returns thm required by "fun in_fillform *)
    7.29  fun fill_form (subs_opt, subst) (thm, form) id (fillpatID, pat, erpaID) =
    7.30    let
    7.31 +    val ctxt = Proof_Context.init_global ((ThyC.Isac()))
    7.32      val (form', _, _, rewritten) =
    7.33 -      Rewrite.rew_sub (ThyC.Isac()) 1 subst Rewrite_Ord.e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) form;
    7.34 +      Rewrite.rew_sub ctxt 1 subst Rewrite_Ord.e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) form;
    7.35    in (*the fillpat of the thm must be dedicated to id*)
    7.36      if id = erpaID andalso rewritten then
    7.37        SOME (fillpatID, HOLogic.mk_eq (form, form'), thm, subs_opt) 
     8.1 --- a/src/Tools/isac/Interpret/istate.sml	Thu Jul 28 11:43:27 2022 +0200
     8.2 +++ b/src/Tools/isac/Interpret/istate.sml	Sat Jul 30 16:47:45 2022 +0200
     8.3 @@ -175,12 +175,12 @@
     8.4      end
     8.5    | init_detail (Tactic.Rewrite_Set_Inst (subs, rls)) t =
     8.6      let
     8.7 -      val thy = ThyC.get_theory "Isac_Knowledge"
     8.8 +      val ctxt = Proof_Context.init_global (ThyC.get_theory "Isac_Knowledge")
     8.9        val rls' = assoc_rls rls
    8.10 -      val v = case Subst.T_from_input thy subs of
    8.11 +      val v = case Subst.T_from_input ctxt subs of
    8.12          (_, v) :: _ => v (*...we suppose the substitution of only ONE bound variable*)
    8.13        | _ => raise ERROR "init_detail: uncovered case"
    8.14 -      val prog = Auto_Prog.gen thy t rls'
    8.15 +      val prog = Auto_Prog.gen (Proof_Context.theory_of ctxt) t rls'
    8.16        val args = Program.formal_args prog
    8.17      in
    8.18        Istate_Def.Pstate (Istate_Def.e_pstate |> Istate_Def.set_env_true (args ~~ [t, v]))
     9.1 --- a/src/Tools/isac/Interpret/li-tool.sml	Thu Jul 28 11:43:27 2022 +0200
     9.2 +++ b/src/Tools/isac/Interpret/li-tool.sml	Sat Jul 30 16:47:45 2022 +0200
     9.3 @@ -191,7 +191,7 @@
     9.4    		      else Associated (Tactic.Substitute' (ro, erls, subte, t, t'), t', ctxt)
     9.5    		    end
     9.6    		  else
     9.7 -  		    (case Rewrite.rewrite_terms_ (ThyC.Isac ()) ro erls subte t of
     9.8 +  		    (case Rewrite.rewrite_terms_ (Proof_Context.init_global (ThyC.Isac ())) ro erls subte t of
     9.9    		      SOME (t', _) =>  Associated (Tactic.Substitute' (ro, erls, subte, t, t'), t', ctxt)
    9.10    		    | NONE => raise ERROR "associate: Substitute' not applicable to val of Expr")
    9.11    | associate pt ctxt (Tactic.Subproblem' ((domID, pblID, _), _, _, _, _, _),
    9.12 @@ -328,14 +328,14 @@
    9.13      case Prog_Tac.eval_leaf E a v t of
    9.14  	    (Program.Tac stac, a') =>
    9.15  	      let
    9.16 -	        val stac' = Rewrite.eval_prog_expr (Proof_Context.theory_of ctxt) srls 
    9.17 +	        val stac' = Rewrite.eval_prog_expr ctxt srls 
    9.18                (subst_atomic (Env.update_opt E (a, v)) stac)
    9.19  	      in
    9.20            (trace_msg_1 call t stac; (Program.Tac stac', a'))
    9.21  	      end
    9.22      | (Program.Expr lexpr, a') =>
    9.23  	      let
    9.24 -	        val lexpr' = Rewrite.eval_prog_expr (Proof_Context.theory_of ctxt) srls
    9.25 +	        val lexpr' = Rewrite.eval_prog_expr ctxt srls
    9.26                (subst_atomic (Env.update_opt E (a, v)) lexpr)
    9.27  	      in
    9.28            (trace_msg_2 call t lexpr'; (Program.Expr lexpr', a'))
    10.1 --- a/src/Tools/isac/Interpret/lucas-interpreter.sml	Thu Jul 28 11:43:27 2022 +0200
    10.2 +++ b/src/Tools/isac/Interpret/lucas-interpreter.sml	Sat Jul 30 16:47:45 2022 +0200
    10.3 @@ -153,11 +153,11 @@
    10.4      | (*Accept_Tac*) goback => goback)
    10.5  
    10.6    | scan_dn (cc as (_, ctxt)) (ist as {eval, act_arg, ...}) (Const (\<^const_name>\<open>Tactical.While\<close>(*1*), _) $ c $ e $ a) =
    10.7 -    if Rewrite.eval_true_ (Proof_Context.theory_of ctxt) eval (subst_atomic (ist |> get_act_env |> Env.update' a) c)
    10.8 +    if Rewrite.eval_true_ ctxt eval (subst_atomic (ist |> get_act_env |> Env.update' a) c)
    10.9      then scan_dn cc (ist |> path_down_form ([L, R], a)) e
   10.10      else Term_Val act_arg
   10.11    | scan_dn (cc as (_, ctxt)) (ist as {eval, act_arg, ...}) (Const (\<^const_name>\<open>Tactical.While\<close>(*2*), _) $ c $ e) =
   10.12 -    if Rewrite.eval_true_ (Proof_Context.theory_of ctxt) eval (subst_atomic (Env.update_opt' (get_subst ist)) c)
   10.13 +    if Rewrite.eval_true_ ctxt eval (subst_atomic (Env.update_opt' (get_subst ist)) c)
   10.14      then scan_dn cc (ist |> path_down [R]) e
   10.15      else Term_Val act_arg
   10.16  
   10.17 @@ -171,7 +171,7 @@
   10.18      | _ => scan_dn cc (ist |> path_down [R]) e2)
   10.19  
   10.20    |  scan_dn (cc as (_, ctxt)) (ist as {eval, ...}) (Const (\<^const_name>\<open>Tactical.If\<close>(*1*), _) $ c $ e1 $ e2) =
   10.21 -    if Rewrite.eval_true_ (Proof_Context.theory_of ctxt) eval (subst_atomic (Env.update_opt' (get_subst ist)) c)
   10.22 +    if Rewrite.eval_true_ ctxt eval (subst_atomic (Env.update_opt' (get_subst ist)) c)
   10.23      then scan_dn cc (ist |> path_down [L, R]) e1
   10.24      else scan_dn cc (ist |> path_down [R]) e2
   10.25  
   10.26 @@ -231,7 +231,7 @@
   10.27  
   10.28    | scan_up (pcc as (_, cc as (_, ctxt)))  (ist as {eval, ...})
   10.29        (Const (\<^const_name>\<open>Tactical.While\<close>(*1*), _) $ c $ e $ _) = 
   10.30 -    if Rewrite.eval_true_ (Proof_Context.theory_of ctxt) eval (subst_atomic (Env.update_opt' (get_subst ist)) c) 
   10.31 +    if Rewrite.eval_true_ ctxt eval (subst_atomic (Env.update_opt' (get_subst ist)) c) 
   10.32      then
   10.33        case scan_dn cc (ist |> path_down [L, R]) e of
   10.34    	     Accept_Tac ict => Accept_Tac ict
   10.35 @@ -241,7 +241,7 @@
   10.36        go_scan_up pcc (ist (*|> set_found*))
   10.37    | scan_up  (pcc as (_, cc as (_, ctxt))) (ist as {eval, ...})
   10.38        (Const (\<^const_name>\<open>Tactical.While\<close>(*2*), _) $ c $ e) = 
   10.39 -    if Rewrite.eval_true_ (Proof_Context.theory_of ctxt) eval (subst_atomic (Env.update_opt' (get_subst ist)) c) 
   10.40 +    if Rewrite.eval_true_ ctxt eval (subst_atomic (Env.update_opt' (get_subst ist)) c) 
   10.41      then
   10.42        case scan_dn cc (ist |> path_down [R]) e of
   10.43    	    Accept_Tac ict => Accept_Tac ict
   10.44 @@ -360,12 +360,12 @@
   10.45  
   10.46    | scan_dn1 (cct as (_, ctxt, _)) (ist as {eval, act_arg, ...})
   10.47        (Const (\<^const_name>\<open>Tactical.While\<close>(*1*), _) $ c $ e $ a) =
   10.48 -    if Rewrite.eval_true_ (Proof_Context.theory_of ctxt) eval (subst_atomic (ist |> get_act_env |> Env.update' a) c)
   10.49 +    if Rewrite.eval_true_ ctxt eval (subst_atomic (ist |> get_act_env |> Env.update' a) c)
   10.50      then scan_dn1 cct (ist |> path_down_form ([L, R], a)) e
   10.51      else Term_Val1 act_arg
   10.52    | scan_dn1 (cct as (_, ctxt, _)) (ist as {eval, act_arg, ...})
   10.53        (Const (\<^const_name>\<open>Tactical.While\<close>(*2*),_) $ c $ e) =
   10.54 -    if Rewrite.eval_true_ (Proof_Context.theory_of ctxt) eval (subst_atomic (Env.update_opt' (get_subst ist)) c) 
   10.55 +    if Rewrite.eval_true_ ctxt eval (subst_atomic (Env.update_opt' (get_subst ist)) c) 
   10.56      then scan_dn1 cct (ist |> path_down [R]) e
   10.57      else Term_Val1 act_arg
   10.58  
   10.59 @@ -387,7 +387,7 @@
   10.60       | goback => goback)
   10.61  
   10.62    | scan_dn1 (cct as (_, ctxt, _)) (ist as {eval, ...}) (Const (\<^const_name>\<open>Tactical.If\<close>, _) $ c $ e1 $ e2) =
   10.63 -    if Rewrite.eval_true_ (Proof_Context.theory_of ctxt) eval (subst_atomic (Env.update_opt' (get_subst ist)) c)
   10.64 +    if Rewrite.eval_true_ ctxt eval (subst_atomic (Env.update_opt' (get_subst ist)) c)
   10.65      then scan_dn1 cct (ist |> path_down [L, R]) e1
   10.66      else scan_dn1 cct (ist |> path_down [R]) e2
   10.67  
   10.68 @@ -396,7 +396,7 @@
   10.69      else
   10.70        case LItool.check_leaf "locate" ctxt eval (get_subst ist) t of
   10.71    	    (Program.Expr _, form_arg) => 
   10.72 -  	      Term_Val1 (Rewrite.eval_prog_expr (Proof_Context.theory_of ctxt) eval
   10.73 +  	      Term_Val1 (Rewrite.eval_prog_expr ctxt eval
   10.74    		      (subst_atomic (Env.update_opt'' (get_act_env ist, form_arg)) t))
   10.75        | (Program.Tac prog_tac, form_arg) =>
   10.76            check_tac1 cct ist (prog_tac, form_arg)
   10.77 @@ -446,7 +446,7 @@
   10.78  
   10.79    | scan_up1 (pcct as (prog, cct as (cstate, ctxt, _))) (ist as {eval, ...})
   10.80        (t as Const (\<^const_name>\<open>Tactical.While\<close>(*1*),_) $ c $ e $ a) =
   10.81 -    if Rewrite.eval_true_ (Proof_Context.theory_of ctxt) eval (subst_atomic (Env.update' a (get_act_env ist)) c)
   10.82 +    if Rewrite.eval_true_ ctxt eval (subst_atomic (Env.update' a (get_act_env ist)) c)
   10.83      then
   10.84        case scan_dn1 cct (ist |> path_down_form ([L, R], a) |> set_or ORundef) e of 
   10.85          Term_Val1 v => go_scan_up1 pcct (ist |> set_act v |> set_form a)
   10.86 @@ -456,7 +456,7 @@
   10.87      else go_scan_up1 pcct (ist |> set_form a)
   10.88    | scan_up1 (pcct as (prog, cct as (cstate, ctxt, _))) (ist as {eval, ...})
   10.89        (t as Const (\<^const_name>\<open>Tactical.While\<close>(*2*), _) $ c $ e) =
   10.90 -    if Rewrite.eval_true_ (Proof_Context.theory_of ctxt) eval (subst_atomic (Env.update_opt' (get_subst ist)) c)
   10.91 +    if Rewrite.eval_true_ ctxt eval (subst_atomic (Env.update_opt' (get_subst ist)) c)
   10.92      then
   10.93        case scan_dn1 cct (ist |> path_down [R] |> set_or ORundef) e of 
   10.94          Term_Val1 v => go_scan_up1 pcct (ist |> set_act v)
    11.1 --- a/src/Tools/isac/Interpret/solve-step.sml	Thu Jul 28 11:43:27 2022 +0200
    11.2 +++ b/src/Tools/isac/Interpret/solve-step.sml	Sat Jul 30 16:47:45 2022 +0200
    11.3 @@ -110,7 +110,7 @@
    11.4        in
    11.5          if msg = "OK"
    11.6          then
    11.7 -    	    case Rewrite.calculate_ (ThyC.get_theory thy') isa_fn f of
    11.8 +    	    case Rewrite.calculate_ (ThyC.id_to_ctxt thy') isa_fn f of
    11.9      	      SOME (f', (id, thm))
   11.10      	        => Applicable.Yes (Tactic.Calculate' (thy', op_, f, (f', (id, thm))))
   11.11      	    | NONE => Applicable.No ("'calculate " ^ op_ ^ "' not applicable") 
   11.12 @@ -136,7 +136,7 @@
   11.13    | check (Tactic.Rewrite thm) (cs as (pt, (p, _))) = 
   11.14        let
   11.15          val (msg, thy', ro, rls', _) = get_ruleset thm p pt;
   11.16 -        val thy = ThyC.get_theory thy';
   11.17 +        val thy = ThyC.id_to_ctxt thy';
   11.18          val f = Calc.current_formula cs;
   11.19        in
   11.20          if msg = "OK" 
   11.21 @@ -151,11 +151,12 @@
   11.22          val pp = Ctree.par_pblobj pt p;
   11.23          val thy' = Ctree.get_obj Ctree.g_domID pt pp;
   11.24          val thy = ThyC.get_theory thy';
   11.25 +        val ctxt = Proof_Context.init_global thy;
   11.26          val {rew_ord' = ro', erls = erls, ...} = MethodC.from_store (Ctree.get_obj Ctree.g_metID pt pp);
   11.27          val f = Calc.current_formula cs;
   11.28 -        val subst = Subst.T_from_input thy subs; (*TODO: input requires parse _: _ -> _ option*)
   11.29 +        val subst = Subst.T_from_input ctxt subs; (*TODO: input requires parse _: _ -> _ option*)
   11.30        in 
   11.31 -        case Rewrite.rewrite_inst_ thy (Rewrite_Ord.assoc_rew_ord ro') erls false subst (snd thm) f of
   11.32 +        case Rewrite.rewrite_inst_ ctxt (Rewrite_Ord.assoc_rew_ord ro') erls false subst (snd thm) f of
   11.33            SOME (f', asm) =>
   11.34              Applicable.Yes (Tactic.Rewrite_Inst' (thy', ro', erls, false, subst, thm, f, (f', asm)))
   11.35          | NONE => Applicable.No (fst thm ^ " not applicable")
   11.36 @@ -166,7 +167,7 @@
   11.37          val thy' = Ctree.get_obj Ctree.g_domID pt pp;
   11.38          val f = Calc.current_formula cs;
   11.39        in
   11.40 -        case Rewrite.rewrite_set_ (ThyC.get_theory thy') false (assoc_rls rls) f of
   11.41 +        case Rewrite.rewrite_set_ (ThyC.id_to_ctxt thy') false (assoc_rls rls) f of
   11.42            SOME (f', asm)
   11.43              => Applicable.Yes (Tactic.Rewrite_Set' (thy', false, assoc_rls rls, f, (f', asm)))
   11.44            | NONE => Applicable.No (rls ^ " not applicable")
   11.45 @@ -176,10 +177,11 @@
   11.46          val pp = Ctree.par_pblobj pt p;
   11.47          val thy' = Ctree.get_obj Ctree.g_domID pt pp;
   11.48          val thy = ThyC.get_theory thy';
   11.49 +        val ctxt = Proof_Context.init_global thy;
   11.50          val f = Calc.current_formula cs;
   11.51 -    	  val subst = Subst.T_from_input thy subs; (*TODO: input requires parse _: _ -> _ option*)
   11.52 +    	  val subst = Subst.T_from_input ctxt subs; (*TODO: input requires parse _: _ -> _ option*)
   11.53        in 
   11.54 -        case Rewrite.rewrite_set_inst_ thy false subst (assoc_rls rls) f of
   11.55 +        case Rewrite.rewrite_set_inst_ ctxt false subst (assoc_rls rls) f of
   11.56            SOME (f', asm)
   11.57              => Applicable.Yes (Tactic.Rewrite_Set_Inst' (thy', false, subst, assoc_rls rls, f, (f', asm)))
   11.58          | NONE => Applicable.No (rls ^ " not applicable")
   11.59 @@ -191,6 +193,7 @@
   11.60        let
   11.61          val pp = Ctree.par_pblobj pt p
   11.62          val thy = ThyC.get_theory (Ctree.get_obj Ctree.g_domID pt pp)
   11.63 +        val ctxt = Proof_Context.init_global thy;
   11.64          val f = Calc.current_formula cs;
   11.65  		    val {rew_ord', erls, ...} = MethodC.from_store (Ctree.get_obj Ctree.g_metID pt pp)
   11.66  		    val subte = Subst.input_to_terms sube (*TODO: input requires parse _: _ -> _ option*)
   11.67 @@ -205,7 +208,7 @@
   11.68  		        else Applicable.Yes (Tactic.Substitute' (ro, erls, subte, f, f'))
   11.69  		      end
   11.70  		    else (*2*)
   11.71 -		      case Rewrite.rewrite_terms_ thy ro erls subte f of
   11.72 +		      case Rewrite.rewrite_terms_ ctxt ro erls subte f of
   11.73  		        SOME (f', _) =>  Applicable.Yes (Tactic.Substitute' (ro, erls, subte, f, f'))
   11.74  		      | NONE => Applicable.No (Subst.string_eqs_to_string sube ^ " not applicable")
   11.75  		  end
    12.1 --- a/src/Tools/isac/Knowledge/Rational.thy	Thu Jul 28 11:43:27 2022 +0200
    12.2 +++ b/src/Tools/isac/Knowledge/Rational.thy	Sat Jul 30 16:47:45 2022 +0200
    12.3 @@ -480,7 +480,7 @@
    12.4    let
    12.5      val SOME (t', _) = factout_p_ thy t;
    12.6      val SOME (t'', asm) = cancel_p_ thy t;
    12.7 -    val der = Derive.steps_reverse thy eval_rls rules ro NONE t';
    12.8 +    val der = Derive.steps_reverse (Proof_Context.init_global thy) eval_rls rules ro NONE t';
    12.9      val der = der @ 
   12.10        [(\<^rule_thm>\<open>real_mult_div_cancel2\<close>, (t'', asm))]
   12.11      val rs = (Rule.distinct' o (map #1)) der
   12.12 @@ -491,7 +491,7 @@
   12.13  fun locate_rule thy eval_rls ro [rs] t r =
   12.14      if member op = ((map (Rule.thm_id)) rs) (Rule.thm_id r)
   12.15      then 
   12.16 -      let val ropt = Rewrite.rewrite_ thy ro eval_rls true (Rule.thm r) t;
   12.17 +      let val ropt = Rewrite.rewrite_ (Proof_Context.init_global thy) ro eval_rls true (Rule.thm r) t;
   12.18        in
   12.19          case ropt of SOME ta => [(r, ta)]
   12.20  	      | NONE => ((*tracing 
   12.21 @@ -502,7 +502,7 @@
   12.22  
   12.23  fun next_rule thy eval_rls ro [rs] t =
   12.24      let
   12.25 -      val der = Derive.do_one thy eval_rls rs ro NONE t;
   12.26 +      val der = Derive.do_one (Proof_Context.init_global thy) eval_rls rs ro NONE t;
   12.27      in case der of (_, r, _) :: _ => SOME r | _ => NONE end
   12.28    | next_rule _ _ _ _ _ = raise ERROR ("next_rule: doesnt match rev-sets in istate");
   12.29  
   12.30 @@ -541,7 +541,7 @@
   12.31    let 
   12.32      val SOME (t', _) = common_nominator_p_ thy t;
   12.33      val SOME (t'', asm) = add_fraction_p_ thy t;
   12.34 -    val der = Derive.steps_reverse thy eval_rls rules ro NONE t';
   12.35 +    val der = Derive.steps_reverse (Proof_Context.init_global thy) eval_rls rules ro NONE t';
   12.36      val der = der @ 
   12.37        [(\<^rule_thm>\<open>real_mult_div_cancel2\<close>, (t'',asm))]
   12.38      val rs = (Rule.distinct' o (map #1)) der;
   12.39 @@ -552,7 +552,7 @@
   12.40  fun locate_rule thy eval_rls ro [rs] t r =
   12.41      if member op = ((map (Rule.thm_id)) rs) (Rule.thm_id r)
   12.42      then 
   12.43 -      let val ropt = Rewrite.rewrite_ thy ro eval_rls true (Rule.thm r) t;
   12.44 +      let val ropt = Rewrite.rewrite_ (Proof_Context.init_global thy) ro eval_rls true (Rule.thm r) t;
   12.45        in 
   12.46          case ropt of
   12.47            SOME ta => [(r, ta)]
   12.48 @@ -563,7 +563,7 @@
   12.49    | locate_rule _ _ _ _ _ _ = raise ERROR "locate_rule: doesnt match rev-sets in istate";
   12.50  
   12.51  fun next_rule thy eval_rls ro [rs] t =
   12.52 -    let val der = Derive.do_one thy eval_rls rs ro NONE t;
   12.53 +    let val der = Derive.do_one (Proof_Context.init_global thy) eval_rls rs ro NONE t;
   12.54      in 
   12.55        case der of
   12.56  	      (_,r,_)::_ => SOME r
    13.1 --- a/src/Tools/isac/MathEngBasic/rewrite.sml	Thu Jul 28 11:43:27 2022 +0200
    13.2 +++ b/src/Tools/isac/MathEngBasic/rewrite.sml	Sat Jul 30 16:47:45 2022 +0200
    13.3 @@ -5,43 +5,44 @@
    13.4  signature REWRITE =
    13.5  sig
    13.6    exception NO_REWRITE
    13.7 -  val calculate_: theory -> string * Eval_Def.eval_fn -> term -> (term * (string * thm)) option
    13.8 -  val eval__true: theory -> int -> term list -> Subst.T -> Rule_Set.T -> term list * bool
    13.9 -  val eval_prog_expr: theory -> Rule_Set.T -> term -> term
   13.10 -  val eval_true_: theory -> Rule_Set.T -> term -> bool
   13.11 -  val eval_true: theory -> term list -> Rule_Set.T -> bool
   13.12 -  val rew_sub: theory -> int -> Subst.T -> Rule_Def.rew_ord_
   13.13 +  val calculate_: Proof.context -> string * Eval_Def.eval_fn -> term -> (term * (string * thm)) option
   13.14 +  val eval__true: Proof.context -> int -> term list -> Subst.T -> Rule_Set.T -> term list * bool
   13.15 +  val eval_prog_expr: Proof.context -> Rule_Set.T -> term -> term
   13.16 +  val eval_true_: Proof.context -> Rule_Set.T -> term -> bool
   13.17 +  val eval_true: Proof.context -> term list -> Rule_Set.T -> bool
   13.18 +  val rew_sub: Proof.context -> int -> Subst.T -> Rule_Def.rew_ord_
   13.19      -> Rule_Set.T -> bool -> TermC.path -> term -> term -> term * term list * TermC.path * bool
   13.20 -  val rewrite_: theory -> Rule_Def.rew_ord_ -> Rule_Set.T -> bool -> thm ->
   13.21 +  val rewrite_: Proof.context -> Rule_Def.rew_ord_ -> Rule_Set.T -> bool -> thm ->
   13.22      term -> (term * term list) option
   13.23 -  val rewrite_inst_: theory -> Rule_Def.rew_ord_ -> Rule_Set.T -> bool
   13.24 +  val rewrite_inst_: Proof.context -> Rule_Def.rew_ord_ -> Rule_Set.T -> bool
   13.25      -> Subst.T -> thm -> term -> (term * term list) option
   13.26 -  val rewrite_set_: theory -> bool -> Rule_Set.T -> term -> (term * term list) option
   13.27 -  val rewrite_set_inst_: theory -> bool -> Subst.T -> Rule_Set.T -> term -> (term * term list) option
   13.28 -  val rewrite_terms_: theory -> Rule_Def.rew_ord_ -> Rule_Set.T -> term list
   13.29 +  val rewrite_set_: Proof.context -> bool -> Rule_Set.T -> term -> (term * term list) option
   13.30 +  val rewrite_set_inst_: Proof.context -> bool -> Subst.T -> Rule_Set.T -> term -> (term * term list) option
   13.31 +  val rewrite_terms_: Proof.context -> Rule_Def.rew_ord_ -> Rule_Set.T -> term list
   13.32      -> term -> (term * term list) option
   13.33  
   13.34 -  val trace_on: bool Unsynchronized.ref
   13.35    val depth: int Unsynchronized.ref
   13.36    val lim_deriv: int Unsynchronized.ref
   13.37  
   13.38  \<^isac_test>\<open>
   13.39 -  val rewrite__: theory -> int -> Subst.T -> Rule_Def.rew_ord_ ->
   13.40 +  val rewrite__: Proof.context -> int -> Subst.T -> Rule_Def.rew_ord_ ->
   13.41      Rule_Set.T -> bool -> thm -> term -> (term * term list) option
   13.42 -  val rewrite__set_: theory -> int -> bool -> Subst.T -> Rule_Set.T -> term -> (term * term list) option
   13.43 -  val app_rev: theory -> int -> Rule_Set.T -> term -> term * term list * bool
   13.44 -  val app_sub: theory -> int -> Rule_Set.T -> term -> term * term list * bool
   13.45 -  val trace1: int -> string -> unit
   13.46 -  val trace_eq1 : int -> string -> Rule_Def.rule_set -> theory -> term -> unit;
   13.47 -  val trace_eq2 : int -> string -> theory -> term -> term -> unit;
   13.48 -  val trace_in1 : int -> string -> string -> unit;
   13.49 -  val trace_in2 : int -> string -> theory -> term -> unit;
   13.50 -  val trace_in3 : int -> string -> theory -> (term * 'a) option -> unit;
   13.51 -  val trace_in4 : int -> string -> theory -> term list -> term list -> unit;
   13.52 -  val trace_in5 : int -> string -> theory -> term list -> unit;
   13.53 +  val rewrite__set_: Proof.context -> int -> bool -> Subst.T -> Rule_Set.T -> term -> (term * term list) option
   13.54 +  val app_rev: Proof.context -> int -> Rule_Set.T -> term -> term * term list * bool
   13.55 +  val app_sub: Proof.context -> int -> Rule_Set.T -> term -> term * term list * bool
   13.56 +  val trace1: Proof.context -> int -> string -> unit
   13.57 +  val trace_eq1 : Proof.context -> int -> string -> Rule_Def.rule_set -> term -> unit;
   13.58 +  val trace_eq2 : Proof.context -> int -> string -> term -> term -> unit;
   13.59 +  val trace_in1 : Proof.context -> int -> string -> string -> unit;
   13.60 +  val trace_in2 : Proof.context -> int -> string -> term -> unit;
   13.61 +  val trace_in3 : Proof.context -> int -> string -> (term * 'a) option -> unit;
   13.62 +  val trace_in4 : Proof.context -> int -> string -> term list -> term list -> unit;
   13.63 +  val trace_in5 : Proof.context -> int -> string -> term list -> unit;
   13.64  \<close>
   13.65  end
   13.66  
   13.67 +(* must be global for re-use in other structs *)
   13.68 +val rewrite_trace = Attrib.setup_config_bool \<^binding>\<open>rewrite_trace\<close> (K false);
   13.69  (**)
   13.70  structure Rewrite(**): REWRITE(**) =
   13.71  struct
   13.72 @@ -49,65 +50,65 @@
   13.73  
   13.74  exception NO_REWRITE;
   13.75  
   13.76 -val trace_on = Unsynchronized.ref false;
   13.77  (* depth of recursion in traces of the rewriter, if trace_on:=true *)
   13.78  val depth = Unsynchronized.ref 99999;
   13.79  (* no of rewrites exceeding this int -> NO rewrite *)
   13.80  val lim_deriv = Unsynchronized.ref 100;
   13.81  
   13.82 -fun trace i str = 
   13.83 -  if ! trace_on andalso i < ! depth then tracing (idt "#" i ^ str) else ()
   13.84 -fun trace_eq1 i str rrls thy t =
   13.85 -  trace i (" " ^ str ^ ": " ^ Rule_Set.id rrls ^ " on: " ^ UnparseC.term_in_thy thy t)
   13.86 -fun trace_eq2 i str thy t t' =
   13.87 -  trace i (" " ^ str ^ ": \"" ^
   13.88 -    UnparseC.term_in_thy thy t ^ "\" > \"" ^ UnparseC.term_in_thy thy t' ^ "\"");
   13.89 -fun trace1 i str =
   13.90 -  if ! trace_on andalso i < ! depth then tracing (idt "#" (i + 1) ^ str) else ()
   13.91 -fun trace_in1 i str thmid =
   13.92 -  trace1 i (" " ^ str ^ ": \"" ^ thmid ^ "\"")
   13.93 -fun trace_in2 i str thy t =
   13.94 -  trace1 i (" " ^ str ^ ": \"" ^ UnparseC.term_in_thy thy t ^ "\"");
   13.95 -fun trace_in3 i str thy pairopt =
   13.96 -  trace1 i (" " ^ str ^ ": " ^ UnparseC.term_in_thy thy ((fst o the) pairopt));
   13.97 -fun trace_in4 i str thy ts ts' =
   13.98 -  if ! trace_on andalso i < ! depth andalso ts <> []
   13.99 -  then tracing (idt "#" (i + 1) ^ " " ^ str ^ ": " ^ UnparseC.terms_in_thy thy ts ^
  13.100 -  	"   stored: " ^ UnparseC.terms_in_thy thy ts')
  13.101 +fun trace ctxt i str = 
  13.102 +  if Config.get ctxt rewrite_trace andalso i < ! depth then tracing (idt "#" i ^ str) else ()
  13.103 +fun trace_eq1 ctxt i str rrls t =
  13.104 +  trace ctxt i (" " ^ str ^ ": " ^ Rule_Set.id rrls ^ " on: " ^ UnparseC.term_in_ctxt ctxt t)
  13.105 +fun trace_eq2 ctxt i str t t' =
  13.106 +  trace ctxt i (" " ^ str ^ ": \"" ^
  13.107 +    UnparseC.term_in_ctxt ctxt t ^ "\" > \"" ^ UnparseC.term_in_ctxt ctxt t' ^ "\"");
  13.108 +fun trace1 ctxt i str =
  13.109 +  if Config.get ctxt rewrite_trace andalso i < ! depth then tracing (idt "#" (i + 1) ^ str) else ()
  13.110 +fun trace_in1 ctxt i str thmid =
  13.111 +  trace1 ctxt i (" " ^ str ^ ": \"" ^ thmid ^ "\"")
  13.112 +fun trace_in2 ctxt i str t =
  13.113 +  trace1 ctxt i (" " ^ str ^ ": \"" ^ UnparseC.term_in_ctxt ctxt t ^ "\"");
  13.114 +fun trace_in3 ctxt i str pairopt =
  13.115 +  trace1 ctxt i (" " ^ str ^ ": " ^ UnparseC.term_in_ctxt ctxt ((fst o the) pairopt));
  13.116 +fun trace_in4 ctxt i str ts ts' =
  13.117 +  if Config.get ctxt rewrite_trace andalso i < ! depth andalso ts <> []
  13.118 +  then tracing (idt "#" (i + 1) ^ " " ^ str ^ ": " ^ UnparseC.terms_in_ctxt ctxt ts ^
  13.119 +  	"   stored: " ^ UnparseC.terms_in_ctxt ctxt ts')
  13.120    else ();
  13.121 -fun trace_in5 i str thy p' =
  13.122 -  if ! trace_on andalso i < ! depth 
  13.123 -  then tracing (idt "#" (i + 1) ^ " " ^ str ^ ": " ^ UnparseC.terms_in_thy thy p')
  13.124 +fun trace_in5 ctxt i str p' =
  13.125 +  if Config.get ctxt rewrite_trace andalso i < ! depth 
  13.126 +  then tracing (idt "#" (i + 1) ^ " " ^ str ^ ": " ^ UnparseC.terms_in_ctxt ctxt p')
  13.127    else();
  13.128 -fun msg call thy op_ thmC t = 
  13.129 +fun msg call ctxt op_ thmC t = 
  13.130    call ^ ": \n" ^
  13.131    "Eval.get_pair for " ^ quote op_ ^ " \<longrightarrow> SOME (_, " ^ quote (ThmC.string_of_thm thmC) ^ ")\n" ^
  13.132 -  "but rewrite__ on " ^ quote (UnparseC.term_in_thy thy t) ^ " \<longrightarrow> NONE";
  13.133 +  "but rewrite__ on " ^ quote (UnparseC.term_in_ctxt ctxt t) ^ " \<longrightarrow> NONE";
  13.134  
  13.135 -fun rewrite__ thy i bdv tless rls put_asm thm ct =
  13.136 +fun rewrite__ ctxt i bdv tless rls put_asm thm ct =
  13.137    let
  13.138 -    val (t', asms, _(*lrd*), rew) = rew_sub thy i bdv tless rls put_asm ([(*root of the term*)]: TermC.path)
  13.139 +    val (t', asms, _(*lrd*), rew) = rew_sub ctxt i bdv tless rls put_asm ([(*root of the term*)]: TermC.path)
  13.140  		  (TermC.inst_bdv bdv (Eval.norm (Thm.prop_of thm))) ct
  13.141    in if rew then SOME (t', distinct op = asms) else NONE end
  13.142    (* one rewrite (possibly conditional, ordered) EXOR exn EXOR go into subterms *)
  13.143 -and rew_sub thy i bdv tless rls put_asm lrd r t = 
  13.144 +and rew_sub ctxt i bdv tless rls put_asm lrd r t = 
  13.145    (let
  13.146      val (lhs, rhs) = (HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r
  13.147 -    val r' = (Envir.subst_term (Pattern.match thy (lhs, t) (Vartab.empty, Vartab.empty)) r)
  13.148 +    val r' = (Envir.subst_term (Pattern.match (Proof_Context.theory_of ctxt) 
  13.149 +      (lhs, t) (Vartab.empty, Vartab.empty)) r)
  13.150        handle Pattern.MATCH => raise NO_REWRITE
  13.151      val p' = map HOLogic.dest_Trueprop ((fst o Logic.strip_prems) (Logic.count_prems r', [], r'))
  13.152      val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r'
  13.153 -    val _ = trace_in2 i "eval asms" thy r';
  13.154 +    val _ = trace_in2 ctxt i "eval asms" r';
  13.155      val (t'', p'') =                                                      (*conditional rewriting*)
  13.156 -      let val (simpl_p', nofalse) = eval__true thy (i + 1) p' bdv rls 	     
  13.157 +      let val (simpl_p', nofalse) = eval__true ctxt (i + 1) p' bdv rls 	     
  13.158  	    in
  13.159  	      if nofalse
  13.160 -        then (trace_in4 i "asms accepted" thy p' simpl_p'; (t', simpl_p'))(*uncond.rew.from above*)
  13.161 -        else (trace_in5 i "asms false" thy p'; raise NO_REWRITE)   (* don't go into subtm.of cond*)
  13.162 +        then (trace_in4 ctxt i "asms accepted" p' simpl_p'; (t', simpl_p'))(*uncond.rew.from above*)
  13.163 +        else (trace_in5 ctxt i "asms false" p'; raise NO_REWRITE)   (* don't go into subtm.of cond*)
  13.164  	    end                                    
  13.165    in
  13.166      if TermC.perm lhs rhs andalso not (tless bdv (t', t))                     (*ordered rewriting*)
  13.167 -    then (trace_eq2 i "not >" thy t t'; raise NO_REWRITE)
  13.168 +    then (trace_eq2 ctxt i "not >" t t'; raise NO_REWRITE)
  13.169      else (t'', p'', [], true)
  13.170    end
  13.171    ) handle NO_REWRITE =>
  13.172 @@ -117,17 +118,17 @@
  13.173      | Var(n, T) => (Var(n, T), [], lrd, false)
  13.174      | Bound i => (Bound i, [], lrd, false)
  13.175      | Abs(s, T, body) => 
  13.176 -      let val (t', asms, _ (*lrd*), rew) =  rew_sub thy i bdv tless rls put_asm (lrd @ [TermC.D]) r body
  13.177 +      let val (t', asms, _ (*lrd*), rew) =  rew_sub ctxt i bdv tless rls put_asm (lrd @ [TermC.D]) r body
  13.178         in (Abs(s, T, t'), asms, [], rew) end
  13.179      | t1 $ t2 => 
  13.180 -       let val (t2', asm2, lrd, rew2) = rew_sub thy i bdv tless rls put_asm (lrd @ [TermC.R]) r t2
  13.181 +       let val (t2', asm2, lrd, rew2) = rew_sub ctxt i bdv tless rls put_asm (lrd @ [TermC.R]) r t2
  13.182         in
  13.183          if rew2 then (t1 $ t2', asm2, lrd, true)
  13.184          else
  13.185 -          let val (t1', asm1, lrd, rew1) = rew_sub thy i bdv tless rls put_asm (lrd @ [TermC.L]) r t1
  13.186 +          let val (t1', asm1, lrd, rew1) = rew_sub ctxt i bdv tless rls put_asm (lrd @ [TermC.L]) r t1
  13.187            in if rew1 then (t1' $ t2, asm1, lrd, true) else (t1 $ t2,[], lrd, false) end
  13.188      end)
  13.189 -and eval__true thy i asms bdv rls =            (* rewrite asumptions until one evaluates to false*)
  13.190 +and eval__true ctxt i asms bdv rls =            (* rewrite asumptions until one evaluates to false*)
  13.191    if asms = [@{term True}] orelse asms = [] then ([], true)
  13.192    else (* this allows to check Rrls with prepat = ([@{term True}], pat) *)
  13.193      if asms = [@{term False}] then ([], false)
  13.194 @@ -135,7 +136,7 @@
  13.195        let                            
  13.196          fun chk indets [] = (indets, true) (*return asms<>True until false*)
  13.197            | chk indets (a :: asms) =
  13.198 -            (case rewrite__set_ thy (i + 1) false bdv rls a of
  13.199 +            (case rewrite__set_ ctxt (i + 1) false bdv rls a of
  13.200                NONE => (chk (indets @ [a]) asms)
  13.201              | SOME (t, a') =>
  13.202                if t = @{term True} then (chk (indets @ a') asms) 
  13.203 @@ -143,16 +144,16 @@
  13.204              (*asm false .. thm not applied ^^^; continue until False vvv*)
  13.205              else chk (indets @ [t] @ a') asms);
  13.206        in chk [] asms end
  13.207 -and rewrite__set_ thy (*1*)_ _ _ Rule_Set.Empty t =                         (* rewrite with a rule set*)
  13.208 -    raise ERROR ("rewrite__set_ called with 'Erls' for '" ^ UnparseC.term_in_thy thy t ^ "'")
  13.209 -  | rewrite__set_ (*2*)thy i _ _ (rrls as Rule_Set.Rrls _) t =    (* rewrite with a 'reverse rule set'*)
  13.210 +and rewrite__set_ ctxt (*1*)_ _ _ Rule_Set.Empty t =                         (* rewrite with a rule set*)
  13.211 +    raise ERROR ("rewrite__set_ called with 'Erls' for '" ^ UnparseC.term_in_ctxt ctxt t ^ "'")
  13.212 +  | rewrite__set_ (*2*)ctxt i _ _ (rrls as Rule_Set.Rrls _) t =    (* rewrite with a 'reverse rule set'*)
  13.213      let
  13.214 -      val _= trace_eq1 i "rls" rrls thy t;
  13.215 -	    val (t', asm, rew) = app_rev thy (i + 1) rrls t                   
  13.216 +      val _= trace_eq1 ctxt i "rls" rrls t;
  13.217 +	    val (t', asm, rew) = app_rev ctxt (i + 1) rrls t                   
  13.218      in if rew then SOME (t', distinct op = asm) else NONE end
  13.219 -  | rewrite__set_ (*3*)thy i put_asm bdv rls ct =           (* Rls, Seq containing Thms or Eval, Cal1 *)
  13.220 +  | rewrite__set_ (*3*)ctxt i put_asm bdv rls ct =           (* Rls, Seq containing Thms or Eval, Cal1 *)
  13.221      let
  13.222 -      (* attention with cp to test/..: unbound thy, i, bdv, rls; TODO1803? pull out to rewrite__*)
  13.223 +      (* attention with cp to test/..: unbound ctxt, i, bdv, rls; TODO1803? pull out to rewrite__*)
  13.224        datatype switch = Appl | Noap;
  13.225        fun rew_once (*1*)_ asm ct Noap [] = (ct, asm) (* ?TODO unify with Prog_Expr.rew_once? *)
  13.226          | rew_once (*2*)ruls asm ct Appl [] = 
  13.227 @@ -162,90 +163,90 @@
  13.228          | rew_once (*3*)ruls asm ct apno (rul :: thms) =
  13.229            case rul of
  13.230              Rule.Thm (thmid, thm) =>
  13.231 -              (trace_in1 i "try thm" thmid;
  13.232 -              case rewrite__ thy (i + 1) bdv ((snd o #rew_ord o Rule_Set.rep) rls)
  13.233 +              (trace_in1 ctxt i "try thm" thmid;
  13.234 +              case rewrite__ ctxt (i + 1) bdv ((snd o #rew_ord o Rule_Set.rep) rls)
  13.235                    ((#erls o Rule_Set.rep) rls) put_asm thm ct of
  13.236                  NONE => rew_once ruls asm ct apno thms
  13.237                | SOME (ct', asm') => 
  13.238 -                (trace_in2 i "rewrites to" thy ct';
  13.239 +                (trace_in2 ctxt i "rewrites to" ct';
  13.240                  rew_once ruls (union (op =) asm asm') ct' Appl (rul :: thms)))
  13.241                  (* once again try the same rule, e.g. associativity against "()"*)
  13.242 -          | Rule.Eval (cc as (op_, _)) => 
  13.243 -            let val _ = trace_in1 i "try calc" op_;
  13.244 -            in case Eval.adhoc_thm thy cc ct of
  13.245 +          | Rule.Eval (cc as (op_, _)) =>
  13.246 +            let val _ = trace_in1 ctxt i "try calc" op_;
  13.247 +            in case Eval.adhoc_thm (Proof_Context.theory_of ctxt) cc ct of
  13.248                  NONE => rew_once ruls asm ct apno thms
  13.249                | SOME (_, thm') => 
  13.250                  let 
  13.251 -                  val pairopt = rewrite__ thy (i + 1) bdv ((snd o #rew_ord o Rule_Set.rep) rls)
  13.252 +                  val pairopt = rewrite__ ctxt (i + 1) bdv ((snd o #rew_ord o Rule_Set.rep) rls)
  13.253                      ((#erls o Rule_Set.rep) rls) put_asm thm' ct;
  13.254 -                  val _ = if pairopt <> NONE then () else raise ERROR (msg "rew_once" thy op_ thm' ct)
  13.255 -                  val _ = trace_in3 i "calc. to" thy pairopt;
  13.256 +                  val _ = if pairopt <> NONE then () else raise ERROR (msg "rew_once" ctxt op_ thm' ct)
  13.257 +                  val _ = trace_in3 ctxt i "calc. to" pairopt;
  13.258                  in rew_once ruls asm ((fst o the) pairopt) Appl (rul :: thms) end
  13.259              end
  13.260            | Rule.Cal1 (cc as (op_, _)) => 
  13.261 -            let val _ = trace_in1 i "try cal1" op_;
  13.262 -            in case Eval.adhoc_thm1_ thy cc ct of
  13.263 +            let val _ = trace_in1 ctxt i "try cal1" op_;
  13.264 +            in case Eval.adhoc_thm1_ (Proof_Context.theory_of ctxt) cc ct of
  13.265                  NONE => (ct, asm)
  13.266                | SOME (_, thm') =>
  13.267                  let 
  13.268 -                  val pairopt = rewrite__ thy (i + 1) bdv ((snd o #rew_ord o Rule_Set.rep) rls)
  13.269 +                  val pairopt = rewrite__ ctxt (i + 1) bdv ((snd o #rew_ord o Rule_Set.rep) rls)
  13.270                      ((#erls o Rule_Set.rep) rls) put_asm thm' ct;
  13.271                    val _ = if pairopt <> NONE then () else raise ERROR ("rewrite_set_, rewrite_ \"" ^
  13.272 -                     ThmC.string_of_thm thm' ^ "\" " ^ UnparseC.term_in_thy thy ct ^ " = NONE")
  13.273 -                  val _ = trace_in3 i "cal1. to" thy pairopt;
  13.274 +                     ThmC.string_of_thm thm' ^ "\" " ^ UnparseC.term_in_ctxt ctxt ct ^ " = NONE")
  13.275 +                  val _ = trace_in3 ctxt i "cal1. to" pairopt;
  13.276                  in the pairopt end
  13.277              end
  13.278            | Rule.Rls_ rls' => 
  13.279 -            (case rewrite__set_ thy (i + 1) put_asm bdv rls' ct of
  13.280 +            (case rewrite__set_ ctxt (i + 1) put_asm bdv rls' ct of
  13.281                SOME (t', asm') => rew_once ruls (union (op =) asm asm') t' Appl thms
  13.282              | NONE => rew_once ruls asm ct apno thms)
  13.283            | r => raise ERROR ("rew_once not appl. to \"" ^ Rule.to_string r ^ "\"");
  13.284        val ruls = (#rules o Rule_Set.rep) rls;
  13.285 -      val _ = trace_eq1 i "rls" rls thy ct
  13.286 +      val _ = trace_eq1 ctxt i "rls" rls ct
  13.287        val (ct', asm') = rew_once ruls [] ct Noap ruls;
  13.288  	  in if ct = ct' then NONE else SOME (ct', distinct op =  asm') end
  13.289 -(*-------------------------------------------------------------*)
  13.290 -and app_rev thy i rrls t =             (* apply an Rrls; if not applicable proceed with subterms*)
  13.291 +(*--vvv and app_sub are type correct-----------------------------------------------------------*)
  13.292 +and app_rev ctxt i rrls t =             (* apply an Rrls; if not applicable proceed with subterms*)
  13.293    let (* check a (precond, pattern) of a rev-set; stops with 1st true *)
  13.294      fun chk_prepat _ _ [] _ = true
  13.295 -      | chk_prepat thy erls prepat t =
  13.296 +      | chk_prepat ctxt erls prepat t =
  13.297          let
  13.298            fun chk (pres, pat) =
  13.299              (let 
  13.300                val subst: Type.tyenv * Envir.tenv =
  13.301 -                Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
  13.302 +                Pattern.match (Proof_Context.theory_of ctxt) (pat, t) (Vartab.empty, Vartab.empty)
  13.303               in
  13.304 -              snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
  13.305 +              snd (eval__true ctxt (i + 1) (map (Envir.subst_term subst) pres) [] erls)
  13.306               end) handle Pattern.MATCH => false
  13.307             fun scan_ _ [] = false
  13.308               | scan_ f (pp :: pps) =
  13.309                 if f pp then true else scan_ f pps;
  13.310          in scan_ chk prepat end;
  13.311      (* apply the normal_form of a rev-set *)
  13.312 -    fun app_rev' thy (Rule_Set.Rrls {erls, prepat, scr = Rule.Rfuns {normal_form, ...}, ...}) t =
  13.313 -      if chk_prepat thy erls prepat t then normal_form t else NONE
  13.314 +    fun app_rev' ctxt (Rule_Set.Rrls {erls, prepat, scr = Rule.Rfuns {normal_form, ...}, ...}) t =
  13.315 +      if chk_prepat ctxt erls prepat t then normal_form t else NONE
  13.316        | app_rev' _ r _ = raise ERROR ("app_rev' not appl. to \"" ^ Rule_Set.id r ^ "\"");
  13.317 -    val opt = app_rev' thy rrls t
  13.318 +    val opt = app_rev' ctxt rrls t
  13.319    in
  13.320      case opt of
  13.321        SOME (t', asm) => (t', asm, true)
  13.322 -    | NONE => app_sub thy i rrls t
  13.323 +    | NONE => app_sub ctxt i rrls t
  13.324    end
  13.325 -and app_sub thy i rrls t =                                          (* apply an Rrls to subterms*)
  13.326 +and app_sub ctxt i rrls t =                                          (* apply an Rrls to subterms*)
  13.327    case t of
  13.328      Const (s, T) => (Const(s, T), [], false)
  13.329    | Free (s, T) => (Free(s, T), [], false)
  13.330    | Var (n, T) => (Var(n, T), [], false)
  13.331    | Bound i => (Bound i, [], false)
  13.332    | Abs (s, T, body) => 
  13.333 -	  let val (t', asm, rew) = app_rev thy i rrls body
  13.334 +	  let val (t', asm, rew) = app_rev ctxt i rrls body
  13.335  	  in (Abs(s, T, t'), asm, rew) end
  13.336    | t1 $ t2 => 
  13.337 -    let val (t2', asm2, rew2) = app_rev thy i rrls t2
  13.338 +    let val (t2', asm2, rew2) = app_rev ctxt i rrls t2
  13.339      in
  13.340        if rew2 then (t1 $ t2', asm2, true)
  13.341        else
  13.342 -        let val (t1', asm1, rew1) = app_rev thy i rrls t1
  13.343 +        let val (t1', asm1, rew1) = app_rev ctxt i rrls t1
  13.344          in if rew1 then (t1' $ t2, asm1, true)
  13.345             else (t1 $ t2, [], false)
  13.346          end
  13.347 @@ -282,13 +283,13 @@
  13.348      end;
  13.349  
  13.350  (* search ct for adjacent numerals and calculate them by operator isa_fn *)
  13.351 -fun calculate_ thy (isa_fn as (id, eval_fn)) t =
  13.352 -  case Eval.adhoc_thm thy isa_fn t of
  13.353 +fun calculate_ ctxt (isa_fn as (id, eval_fn)) t =
  13.354 +  case Eval.adhoc_thm (Proof_Context.theory_of ctxt) isa_fn t of
  13.355  	  NONE => NONE
  13.356  	| SOME (thmID, thm) =>
  13.357 -	  (let val rew = case rewrite_ thy Rewrite_Ord.dummy_ord Rule_Set.empty false thm t of
  13.358 +	  (let val rew = case rewrite_ ctxt Rewrite_Ord.dummy_ord Rule_Set.empty false thm t of
  13.359          SOME (rew, _) => rew
  13.360 -      | NONE => raise ERROR (msg "calculate_" thy id thm t)
  13.361 +      | NONE => raise ERROR (msg "calculate_" ctxt id thm t)
  13.362      in SOME (rew, (thmID, thm)) end)
  13.363  	    handle NO_REWRITE => raise ERROR ("calculate_: " ^ thmID ^ " does not rewrite");
  13.364  
    14.1 --- a/src/Tools/isac/MathEngBasic/tactic.sml	Thu Jul 28 11:43:27 2022 +0200
    14.2 +++ b/src/Tools/isac/MathEngBasic/tactic.sml	Sat Jul 30 16:47:45 2022 +0200
    14.3 @@ -81,8 +81,8 @@
    14.4    val is_rewtac : input -> bool
    14.5    val is_rewset : input -> bool
    14.6    val rls_of : input -> Rule_Set.id
    14.7 -  val rule2tac : theory -> Env.T ->  Rule.rule -> input
    14.8 -  val applicable : theory -> string -> Rule_Set.T -> term -> input ->input list
    14.9 +  val rule2tac : Proof.context -> Env.T ->  Rule.rule -> input
   14.10 +  val applicable : Proof.context -> string -> Rule_Set.T -> term -> input ->input list
   14.11    val for_specify: input -> bool
   14.12  
   14.13    val input_from_T : T -> input
   14.14 @@ -228,7 +228,7 @@
   14.15    | rls_of (Rewrite_Set rls) = rls
   14.16    | rls_of input = raise ERROR ("rls_of: called with input \"" ^ tac2IDstr input ^ "\"");
   14.17  
   14.18 -fun rule2tac thy _ (Rule.Eval (opID, _)) = Calculate (assoc_calc thy opID)
   14.19 +fun rule2tac ctxt _ (Rule.Eval (opID, _)) = Calculate (assoc_calc (Proof_Context.theory_of ctxt) opID)
   14.20    | rule2tac _ [] (Rule.Thm thm'') = Rewrite thm''
   14.21    | rule2tac _ subst (Rule.Thm thm'') = 
   14.22      Rewrite_Inst (Subst.T_to_input subst, thm'')
   14.23 @@ -240,21 +240,21 @@
   14.24  
   14.25  (* try if a rewrite-rule is applicable to a given formula; 
   14.26     in case of rule-sets (recursivley) collect all _atomic_ rewrites *) 
   14.27 -fun try_rew thy ((_, ro) : Rewrite_Ord.rew_ord) erls (subst : subst) f (thm' as Rule.Thm (_, thm)) =
   14.28 +fun try_rew ctxt ((_, ro) : Rewrite_Ord.rew_ord) erls (subst : subst) f (thm' as Rule.Thm (_, thm)) =
   14.29      if Auto_Prog.contains_bdv thm
   14.30 -    then case Rewrite.rewrite_inst_ thy ro erls false subst thm f of
   14.31 -	    SOME _ => [rule2tac thy subst thm']
   14.32 +    then case Rewrite.rewrite_inst_ ctxt ro erls false subst thm f of
   14.33 +	    SOME _ => [rule2tac ctxt subst thm']
   14.34  	  | NONE => []
   14.35 -    else (case Rewrite.rewrite_ thy ro erls false thm f of
   14.36 -	    SOME _ => [rule2tac thy [] thm']
   14.37 +    else (case Rewrite.rewrite_ ctxt ro erls false thm f of
   14.38 +	    SOME _ => [rule2tac ctxt [] thm']
   14.39  	  | NONE => [])
   14.40 -  | try_rew thy _ _ _ f (cal as Rule.Eval c) = 
   14.41 -    (case Eval.adhoc_thm thy c f of
   14.42 -	    SOME _ => [rule2tac thy [] cal]
   14.43 +  | try_rew ctxt _ _ _ f (cal as Rule.Eval c) = 
   14.44 +    (case Eval.adhoc_thm (Proof_Context.theory_of ctxt) c f of
   14.45 +	    SOME _ => [rule2tac ctxt [] cal]
   14.46      | NONE => [])
   14.47 -  | try_rew thy _ _ _ f (cal as Rule.Cal1 c) = 
   14.48 -    (case Eval.adhoc_thm thy c f of
   14.49 -	      SOME _ => [rule2tac thy [] cal]
   14.50 +  | try_rew ctxt _ _ _ f (cal as Rule.Cal1 c) = 
   14.51 +    (case Eval.adhoc_thm (Proof_Context.theory_of ctxt) c f of
   14.52 +	      SOME _ => [rule2tac ctxt [] cal]
   14.53        | NONE => [])
   14.54    | try_rew thy _ _ subst f (Rule.Rls_ rls) = filter_appl_rews thy subst f rls
   14.55    | try_rew _ _ _ _ _ _ = raise ERROR "try_rew: uncovered case"
   14.56 @@ -267,12 +267,13 @@
   14.57  
   14.58  (* decide if a tactic is applicable to a given formula; 
   14.59     in case of Rewrite_Set* go down to _atomic_ rewrite-tactics *)
   14.60 -fun applicable thy _ _ f (Calculate scrID) =
   14.61 -    try_rew thy Rewrite_Ord.e_rew_ordX Rule_Set.empty [] f (Rule.Eval (assoc_calc' thy scrID |> snd))
   14.62 -  | applicable thy ro erls f (Rewrite thm'') =
   14.63 -    try_rew thy (ro, Rewrite_Ord.assoc_rew_ord ro) erls [] f (Rule.Thm thm'')
   14.64 -  | applicable thy ro erls f (Rewrite_Inst (subs, thm'')) =
   14.65 -    try_rew thy (ro, Rewrite_Ord.assoc_rew_ord ro) erls (Subst.T_from_input thy subs) f (Rule.Thm thm'')
   14.66 +fun applicable ctxt _ _ f (Calculate scrID) =
   14.67 +    try_rew ctxt Rewrite_Ord.e_rew_ordX Rule_Set.empty [] f 
   14.68 +      (Rule.Eval (assoc_calc' (Proof_Context.theory_of ctxt) scrID |> snd))
   14.69 +  | applicable ctxt ro erls f (Rewrite thm'') =
   14.70 +    try_rew ctxt (ro, Rewrite_Ord.assoc_rew_ord ro) erls [] f (Rule.Thm thm'')
   14.71 +  | applicable ctxt ro erls f (Rewrite_Inst (subs, thm'')) =
   14.72 +    try_rew ctxt (ro, Rewrite_Ord.assoc_rew_ord ro) erls (Subst.T_from_input ctxt subs) f (Rule.Thm thm'')
   14.73  
   14.74    | applicable thy _ _ f (Rewrite_Set rls') =
   14.75      filter_appl_rews thy [] f (assoc_rls rls')
    15.1 --- a/src/Tools/isac/MathEngine/detail-step.sml	Thu Jul 28 11:43:27 2022 +0200
    15.2 +++ b/src/Tools/isac/MathEngine/detail-step.sml	Sat Jul 30 16:47:45 2022 +0200
    15.3 @@ -37,7 +37,7 @@
    15.4  	    Rule_Set.Rrls {scr = Rule.Rfuns {init_state, ...}, ...} => 
    15.5  	    let
    15.6          val (_, _, _, rul_terms) = init_state t
    15.7 -	      val newnds = rul_terms_2nds (Proof_Context.theory_of ctxt) [] t rul_terms
    15.8 +	      val newnds = rul_terms_2nds ctxt [] t rul_terms
    15.9  	      val pt''' = ins_chn newnds pt p 
   15.10  	    in ("detailrls", pt''', (p @ [length newnds], Res)) end
   15.11  	  | _ =>
    16.1 --- a/src/Tools/isac/MathEngine/fetch-tactics.sml	Thu Jul 28 11:43:27 2022 +0200
    16.2 +++ b/src/Tools/isac/MathEngine/fetch-tactics.sml	Sat Jul 30 16:47:45 2022 +0200
    16.3 @@ -70,7 +70,8 @@
    16.4            | _ => raise ERROR "specific_from_prog 2")
    16.5            (*WN071231 ? replace atomic_appl_tacs with applicable_in (ineff!) ?*)
    16.6        in
    16.7 -        ((distinct Tactic.eq_tac) o flat o (map (Tactic.applicable thy ro erls f))) alltacs
    16.8 +        ((distinct Tactic.eq_tac) o flat o 
    16.9 +          (map (Tactic.applicable (Proof_Context.init_global thy) ro erls f))) alltacs
   16.10        end;
   16.11  
   16.12  (**)end(**)
   16.13 \ No newline at end of file
    17.1 --- a/src/Tools/isac/Specify/pre-conditions.sml	Thu Jul 28 11:43:27 2022 +0200
    17.2 +++ b/src/Tools/isac/Specify/pre-conditions.sml	Sat Jul 30 16:47:45 2022 +0200
    17.3 @@ -26,10 +26,9 @@
    17.4  fun to_str (b, t) = pair2str (bool2str b, UnparseC.term t);
    17.5  fun to_string pres = strs2str' (map (linefeed o to_str) pres);
    17.6  
    17.7 -                  (*NOT ALL Free's have been substituted*)
    17.8 -fun eval _ (false, pre) = (false, pre)
    17.9 +fun eval _ (false, pre) = (false, pre) (*NOT ALL Free's have been substituted*)
   17.10    | eval prls (true, pre) =
   17.11 -    if Rewrite.eval_true (ThyC.get_theory "Isac_Knowledge") [pre] prls
   17.12 +    if Rewrite.eval_true (Proof_Context.init_global (ThyC.Isac "")) [pre] prls
   17.13      then (true , pre)
   17.14      else (false , pre);
   17.15  
    18.1 --- a/test/Tools/isac/ADDTESTS/course/phst11/T2_Rewriting.thy	Thu Jul 28 11:43:27 2022 +0200
    18.2 +++ b/test/Tools/isac/ADDTESTS/course/phst11/T2_Rewriting.thy	Sat Jul 30 16:47:45 2022 +0200
    18.3 @@ -81,10 +81,10 @@
    18.4    diff_const; let us try:\<close>
    18.5  ML \<open>
    18.6  val t1 = TermC.parseNEW' ctxt "d_d x (a*BC*x*z)";
    18.7 -Rewrite.rewrite_inst_ thy ro er true inst diff_const t1;
    18.8 +Rewrite.rewrite_inst_ ctxt ro er true inst diff_const t1;
    18.9  
   18.10  val t2 = TermC.parseNEW' ctxt "d_d x (a*BC*y*z)";
   18.11 -Rewrite.rewrite_inst_ thy ro er true inst diff_const t2;
   18.12 +Rewrite.rewrite_inst_ ctxt ro er true inst diff_const t2;
   18.13  \<close>
   18.14  text \<open>For term t1 the assumption 'not (x occurs_in "a*BC*x*z")' is false, 
   18.15    since x occurs in t1 actually; thus the rule following implication '==>' is 
   18.16 @@ -104,10 +104,10 @@
   18.17  text \<open>Now we want to bring 4*a close to 2*a in order to get 6*a:
   18.18  \<close>
   18.19  ML \<open>
   18.20 -val SOME (t, _) = Rewrite.rewrite_ thy ro er true @{thm add.assoc} t0; UnparseC.term t;
   18.21 -val SOME (t, _) = Rewrite.rewrite_ thy ro er true @{thm add.left_commute} t; UnparseC.term t;
   18.22 -val SOME (t, _) = Rewrite.rewrite_ thy ro er true @{thm add.commute} t; UnparseC.term t;
   18.23 -val SOME (t, _) = Rewrite.rewrite_ thy ro er true @{thm real_num_collect} t; UnparseC.term t;
   18.24 +val SOME (t, _) = Rewrite.rewrite_ ctxt ro er true @{thm add.assoc} t0; UnparseC.term t;
   18.25 +val SOME (t, _) = Rewrite.rewrite_ ctxt ro er true @{thm add.left_commute} t; UnparseC.term t;
   18.26 +val SOME (t, _) = Rewrite.rewrite_ ctxt ro er true @{thm add.commute} t; UnparseC.term t;
   18.27 +val SOME (t, _) = Rewrite.rewrite_ ctxt ro er true @{thm real_num_collect} t; UnparseC.term t;
   18.28  \<close>
   18.29  text \<open>That is fine, we just need to add 2+4 !!!!! See the next section below.
   18.30  
   18.31 @@ -117,10 +117,10 @@
   18.32    as one rule is applicable (that is the way such rulesets work).
   18.33    Try to step through the ML-sections without skipping one of them ...
   18.34  \<close>
   18.35 -ML \<open>val SOME (t, _) = Rewrite.rewrite_ thy ro er true @{thm add.commute} t; UnparseC.term t\<close>
   18.36 -ML \<open>val SOME (t, _) = Rewrite.rewrite_ thy ro er true @{thm add.commute} t; UnparseC.term t\<close>
   18.37 -ML \<open>val SOME (t, _) = Rewrite.rewrite_ thy ro er true @{thm add.commute} t; UnparseC.term t\<close>
   18.38 -ML \<open>val SOME (t, _) = Rewrite.rewrite_ thy ro er true @{thm add.commute} t; UnparseC.term t\<close>
   18.39 +ML \<open>val SOME (t, _) = Rewrite.rewrite_ ctxt ro er true @{thm add.commute} t; UnparseC.term t\<close>
   18.40 +ML \<open>val SOME (t, _) = Rewrite.rewrite_ ctxt ro er true @{thm add.commute} t; UnparseC.term t\<close>
   18.41 +ML \<open>val SOME (t, _) = Rewrite.rewrite_ ctxt ro er true @{thm add.commute} t; UnparseC.term t\<close>
   18.42 +ML \<open>val SOME (t, _) = Rewrite.rewrite_ ctxt ro er true @{thm add.commute} t; UnparseC.term t\<close>
   18.43  text \<open>... you can go forever, the ruleset is 'not terminating'.
   18.44    The theory of rewriting makes this kind of rulesets terminate by the use of
   18.45    'rewrite orders': 
   18.46 @@ -148,19 +148,19 @@
   18.47  ML \<open>
   18.48  (*show_brackets := false; TODO*)
   18.49  val t1 = TermC.parseNEW' ctxt "(a - b) * (a\<up>2 + a*b + b\<up>2)";
   18.50 -val SOME (t, _) = Rewrite.rewrite_set_ thy true make_polynomial t1; UnparseC.term t;
   18.51 +val SOME (t, _) = Rewrite.rewrite_set_ ctxt true make_polynomial t1; UnparseC.term t;
   18.52  \<close>
   18.53  ML \<open>
   18.54  val t2 = TermC.parseNEW' ctxt 
   18.55    "(2 / (x + 3) + 2 / (x - 3)) / (8 * x / (x \<up> 2 - 9))";
   18.56 -val SOME (t, _) = Rewrite.rewrite_set_ thy true norm_Rational t2; UnparseC.term t;
   18.57 +val SOME (t, _) = Rewrite.rewrite_set_ ctxt true norm_Rational t2; UnparseC.term t;
   18.58  \<close>
   18.59  text \<open>The simplifiers are quite busy when finding the above results. you can
   18.60    watch them at work by setting the switch 'Rewrite.trace_on:\<close>
   18.61  ML \<open>
   18.62  Rewrite.trace_on := false; (*true false*)
   18.63  tracing "+++begin++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
   18.64 -val SOME (t, _) = Rewrite.rewrite_set_ thy true norm_Rational t2; UnparseC.term t;
   18.65 +val SOME (t, _) = Rewrite.rewrite_set_ ctxt true norm_Rational t2; UnparseC.term t;
   18.66  tracing "+++end++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
   18.67  Rewrite.trace_on := false; (*true false*)
   18.68  \<close>
   18.69 @@ -189,7 +189,7 @@
   18.70  ML \<open>
   18.71  val t2 = TermC.parseNEW' ctxt 
   18.72    "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12::real";
   18.73 -val SOME (t, _) = Rewrite.rewrite_set_ thy true rls_p_33 t2; UnparseC.term t;
   18.74 +val SOME (t, _) = Rewrite.rewrite_set_ ctxt true rls_p_33 t2; UnparseC.term t;
   18.75  \<close>
   18.76  text \<open>Try your own examples !\<close>
   18.77  
   18.78 @@ -229,7 +229,7 @@
   18.79  ML \<open>
   18.80  val t = TermC.parseNEW' ctxt 
   18.81    "(2*a - 5*b) * (2*a + 5*b)";
   18.82 -Rewrite.rewrite_set_ thy true rls_p_33 t; UnparseC.term t;
   18.83 +Rewrite.rewrite_set_ ctxt true rls_p_33 t; UnparseC.term t;
   18.84  \<close>
   18.85  
   18.86  end
    19.1 --- a/test/Tools/isac/BaseDefinitions/rewrite-order.sml	Thu Jul 28 11:43:27 2022 +0200
    19.2 +++ b/test/Tools/isac/BaseDefinitions/rewrite-order.sml	Sat Jul 30 16:47:45 2022 +0200
    19.3 @@ -19,10 +19,11 @@
    19.4  "-------- identify difference in term-order between isa=NEW, isa2+OLD --------------------------";
    19.5  val form = TermC.str2term "x + -2 ::real"
    19.6  val Repeat {rew_ord = ("sqrt_right", rew_ord_), erls, ...} = Test_simplify;
    19.7 -Rewrite.trace_on := false; (*true false*)
    19.8 +val ctxt = Proof_Context.init_global @{theory Test};
    19.9 +(*Rewrite.trace_on := false; (*true false*)*)
   19.10  (** )val NONE =                                         ( *isa*)
   19.11  (**)val SOME (form', _) =                             (*isa2*)
   19.12 -      rewrite_ @{theory Test} rew_ord_ erls true @{thm radd_commute} form;
   19.13 +      rewrite_ ctxt rew_ord_ erls true @{thm radd_commute} form;
   19.14  (*
   19.15  -------------------- code in rew_sub -------------------------------------------------------
   19.16  (
   19.17 @@ -42,7 +43,7 @@
   19.18    (thy, 1, []: Subst.T, rew_ord, erls, bool, thm, term);
   19.19  
   19.20      val (t', asms, _(*lrd*), rew) =
   19.21 -           rew_sub thy i bdv tless rls put_asm ([(*root of the term*)]: TermC.path)
   19.22 +           rew_sub ctxt i bdv tless rls put_asm ([(*root of the term*)]: TermC.path)
   19.23  		         (TermC.inst_bdv bdv (Eval.norm (Thm.prop_of thm))) ct;
   19.24  "~~~~~ fun rew_sub , args:"; val (thy, i, bdv, tless, rls, put_asm, lrd, r, t) =
   19.25  (thy, i, bdv, tless, rls, put_asm, ([(*root of the term*)]: TermC.path),
   19.26 @@ -52,13 +53,13 @@
   19.27        handle Pattern.MATCH => raise NO_REWRITE
   19.28      val p' = map HOLogic.dest_Trueprop ((fst o Logic.strip_prems) (Logic.count_prems r', [], r'))
   19.29      val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r'
   19.30 -    val _ = trace_in2 i "eval asms" thy r';
   19.31 +    val _ = trace_in2 ctxt i "eval asms" r';
   19.32      val (t'', p'') =                                                      (*conditional rewriting*)
   19.33 -      let val (simpl_p', nofalse) = Rewrite.eval__true thy (i + 1) p' bdv rls 	     
   19.34 +      let val (simpl_p', nofalse) = Rewrite.eval__true ctxt (i + 1) p' bdv rls 	     
   19.35  	    in
   19.36  	      if nofalse
   19.37 -        then (trace_in4 i "asms accepted" thy p' simpl_p'; (t',simpl_p'))(* uncond.rew.from above*)
   19.38 -        else (trace_in5 i "asms false" thy p'; raise NO_REWRITE)   (* don't go into subtm.of cond*)
   19.39 +        then (trace_in4 ctxt i "asms accepted" p' simpl_p'; (t',simpl_p'))(* uncond.rew.from above*)
   19.40 +        else (trace_in5 ctxt i "asms false" p'; raise NO_REWRITE)   (* don't go into subtm.of cond*)
   19.41  	    end;
   19.42      (*if*) TermC.perm lhs rhs andalso not (tless bdv (t', t));                     (*ordered rewriting*)
   19.43                                        not (tless bdv (t', t)); (*isa = true , isa2 = false*)
    20.1 --- a/test/Tools/isac/BaseDefinitions/substitution.sml	Thu Jul 28 11:43:27 2022 +0200
    20.2 +++ b/test/Tools/isac/BaseDefinitions/substitution.sml	Sat Jul 30 16:47:45 2022 +0200
    20.3 @@ -21,6 +21,7 @@
    20.4  "-------- fun program_to_input -----------------------------------------------";
    20.5  "-------- fun program_to_input -----------------------------------------------";
    20.6  "-------- fun program_to_input -----------------------------------------------";
    20.7 +val ctxt = Proof_Context.init_global @{theory}
    20.8  val subst_prog = @{term "[(''bdv_1'', x::real), (''bdv_2'', y::real), (''bdv_3'', z::real)]"};
    20.9  if Subst.program_to_input subst_prog = ["(''bdv_1'', x)", "(''bdv_2'', y)", "(''bdv_3'', z)"] then ()
   20.10  else error "program_to_input changed";
   20.11 @@ -28,7 +29,7 @@
   20.12  "-------- fun T_from_input -----------------------------------------------------";
   20.13  "-------- fun T_from_input -----------------------------------------------------";
   20.14  "-------- fun T_from_input -----------------------------------------------------";
   20.15 -case Subst.T_from_input @{theory} ["(''bdv_1'', x)", "(''bdv_2'', y)", "(''bdv_3'', z)"] of 
   20.16 +case Subst.T_from_input ctxt ["(''bdv_1'', x)", "(''bdv_2'', y)", "(''bdv_3'', z)"] of 
   20.17    [(Free ("bdv_1", _), Free ("x", _)),
   20.18     (Free ("bdv_2", _), Free ("y", _)),
   20.19     (Free ("bdv_3", _), Free ("z", _))] => ()
    21.1 --- a/test/Tools/isac/Interpret/error-pattern.sml	Thu Jul 28 11:43:27 2022 +0200
    21.2 +++ b/test/Tools/isac/Interpret/error-pattern.sml	Sat Jul 30 16:47:45 2022 +0200
    21.3 @@ -116,13 +116,13 @@
    21.4     *)
    21.5  "----------------------------------------------------------";
    21.6  
    21.7 - val fod = Derive.do_one (@{theory "Isac_Knowledge"}) Atools_erls 
    21.8 + val fod = Derive.do_one (Proof_Context.init_global @{theory "Isac_Knowledge"}) Atools_erls 
    21.9  		       ((#rules o Rule_Set.rep) Test_simplify)
   21.10  		       (sqrt_right false (@{theory "Pure"})) NONE 
   21.11  		       (TermC.str2term "x + 1 + - 1 * 2 = 0");
   21.12   (writeln o Derive.trtas2str) fod;
   21.13  
   21.14 - val ifod = Derive.do_one (@{theory "Isac_Knowledge"}) Atools_erls 
   21.15 + val ifod = Derive.do_one (Proof_Context.init_global @{theory "Isac_Knowledge"}) Atools_erls 
   21.16  		       ((#rules o Rule_Set.rep) Test_simplify)
   21.17  		       (sqrt_right false (@{theory "Pure"})) NONE 
   21.18  		       (TermC.str2term "- 2 * 1 + (1 + x) = 0");
   21.19 @@ -909,14 +909,14 @@
   21.20  val (res, inf) = (TermC.str2term "(2 + 3)/(3 + 4)", TermC.str2term "1 / 2");
   21.21  
   21.22  val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern TermC.matches in res*)
   21.23 -  rew_sub thy 1 [] e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
   21.24 +  rew_sub ctxt 1 [] e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
   21.25  if rewritten then NONE else SOME "e_errpatID";
   21.26  
   21.27 -val norm_res = case rewrite_set_ (Isac()) false rls res' of
   21.28 +val norm_res = case rewrite_set_ ctxt false rls res' of
   21.29    NONE => res'
   21.30  | SOME (norm_res, _) => norm_res
   21.31  
   21.32 -val norm_inf = case rewrite_set_ (Isac()) false rls inf of
   21.33 +val norm_inf = case rewrite_set_ ctxt false rls inf of
   21.34    NONE => inf
   21.35  | SOME (norm_inf, _) => norm_inf;
   21.36  
   21.37 @@ -945,9 +945,10 @@
   21.38  "--------- build fun check_for' ?bdv -------------------------";
   21.39  "--------- build fun check_for' ?bdv -------------------------";
   21.40  "--------- build fun check_for' ?bdv -------------------------";
   21.41 +val ctxt = Proof_Context.init_global @{theory}
   21.42  val subst = [(TermC.str2term "bdv", TermC.str2term "x")]: subst;
   21.43  val t = TermC.str2term "d_d x (x \<up> 2 + sin (x \<up> 4))";
   21.44 -val SOME (t, _) = rewrite_set_inst_ thy false subst norm_diff t;
   21.45 +val SOME (t, _) = rewrite_set_inst_ ctxt false subst norm_diff t;
   21.46  if UnparseC.term t = "2 * x + cos (x \<up> 4) * 4 * x \<up> 3" then ()
   21.47  else error "build fun check_for' ?bdv changed 1"; 
   21.48  
   21.49 @@ -956,17 +957,17 @@
   21.50  val (res, inf) = (TermC.str2term "2 * x + d_d x (sin (x \<up> 4))", TermC.str2term "2 * x + cos (4 * x \<up> 3)");
   21.51  
   21.52  val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern TermC.matches in res*)
   21.53 -  rew_sub thy 1 subst e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
   21.54 +  rew_sub ctxt 1 subst e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
   21.55  if UnparseC.term res' = "2 * x + cos (d_d x (x \<up> 4))" andalso rewritten then ()
   21.56  else error "build fun check_for' ?bdv changed 2";
   21.57  
   21.58 -val norm_res = case rewrite_set_inst_ (Isac()) false subst rls  res' of
   21.59 +val norm_res = case rewrite_set_inst_ ctxt false subst rls  res' of
   21.60    NONE => res'
   21.61  | SOME (norm_res, _) => norm_res;
   21.62  if UnparseC.term norm_res = "2 * x + cos (4 * x \<up> 3)" then ()
   21.63  else error "build fun check_for' ?bdv changed 3";
   21.64  
   21.65 -val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
   21.66 +val norm_inf = case rewrite_set_inst_ ctxt false subst rls inf of
   21.67    NONE => inf
   21.68  | SOME (norm_inf, _) => norm_inf;
   21.69  if UnparseC.term norm_inf = "2 * x + cos (4 * x \<up> 3)" then ()
   21.70 @@ -1118,7 +1119,7 @@
   21.71    val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
   21.72    (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
   21.73  val (form', _, _, rewritten) =
   21.74 -      rew_sub (Isac()) 1 subst e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) form;
   21.75 +      rew_sub ctxt 1 subst e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) form;
   21.76  
   21.77  if UnparseC.term form' = "d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x ?_dummy_1" then ()
   21.78  else error "find_fill_patterns changed 3";
    22.1 --- a/test/Tools/isac/Knowledge/algein.sml	Thu Jul 28 11:43:27 2022 +0200
    22.2 +++ b/test/Tools/isac/Knowledge/algein.sml	Sat Jul 30 16:47:45 2022 +0200
    22.3 @@ -98,11 +98,12 @@
    22.4  "----------- Widerspruch 3 = 777 ---------------------------------";
    22.5  "----------- Widerspruch 3 = 777 ---------------------------------";
    22.6  val thy = @{theory "Isac_Knowledge"}; 
    22.7 +val ctxt = Proof_Context.init_global thy;
    22.8  val rew_ord = dummy_ord;
    22.9  val erls = Rule_Set.Empty;
   22.10  val thm = ThmC.thm_from_thy thy "sym_mult_zero_right";
   22.11  val t = TermC.str2term "0 = (0::real)";
   22.12 -val SOME (t',_) = rewrite_ thy rew_ord erls false thm t;
   22.13 +val SOME (t',_) = rewrite_ ctxt rew_ord erls false thm t;
   22.14  UnparseC.term t' = "0 = ?a1 * 0"; (* = true*)
   22.15  
   22.16  val sube = ["?a1 = (3::real)"];
    23.1 --- a/test/Tools/isac/Knowledge/biegelinie-1.sml	Thu Jul 28 11:43:27 2022 +0200
    23.2 +++ b/test/Tools/isac/Knowledge/biegelinie-1.sml	Sat Jul 30 16:47:45 2022 +0200
    23.3 @@ -31,7 +31,7 @@
    23.4  val ctxt = ThyC.id_to_ctxt "Biegelinie";
    23.5  fun str2term str = TermC.parseNEW' ctxt str;
    23.6  fun term2s t = UnparseC.term_by_thyID "Biegelinie" t;
    23.7 -fun rewrit thm str = fst (the (rewrite_ thy tless_true Rule_Set.empty true thm str));
    23.8 +fun rewrit thm str = fst (the (rewrite_ ctxt tless_true Rule_Set.empty true thm str));
    23.9  
   23.10  "----------- the rules -------------------------------------------";
   23.11  "----------- the rules -------------------------------------------";
   23.12 @@ -73,15 +73,14 @@
   23.13  		scr = Empty_Prog};
   23.14  val rm_ = TermC.str2term"[M_b 0 = 0, M_b L = 0]";
   23.15  val M__ = TermC.str2term"M_b x = - 1 * x \<up> 2 / 2 + x * c + c_2";
   23.16 -val SOME (e1__,_) = rewrite_set_ thy false srls 
   23.17 +val SOME (e1__,_) = rewrite_set_ ctxt false srls 
   23.18    (TermC.str2term "(NTH::[real,bool list]=>bool) 1 " $ rm_);
   23.19  if UnparseC.term e1__ = "M_b 0 = 0" then () else error "biegelinie.sml simplify NTH 1 rm_";
   23.20  
   23.21 -val SOME (x1__,_) = rewrite_set_ thy false srls (TermC.str2term "argument_in (lhs (M_b 0 = 0))");
   23.22 +val SOME (x1__,_) = rewrite_set_ ctxt false srls (TermC.str2term "argument_in (lhs (M_b 0 = 0))");
   23.23  if UnparseC.term x1__ = "0" then ()
   23.24  else error "biegelinie.sml simplify argument_in (lhs (M_b 0 = 0)";
   23.25  
   23.26 -Rewrite.trace_on := false; (*true false*)
   23.27  
   23.28  "----------- SubProblem (_,[setzeRandbedingungen,Biegelinien] ----";
   23.29  "----------- SubProblem (_,[setzeRandbedingungen,Biegelinien] ----";
    24.1 --- a/test/Tools/isac/Knowledge/diff-app.sml	Thu Jul 28 11:43:27 2022 +0200
    24.2 +++ b/test/Tools/isac/Knowledge/diff-app.sml	Sat Jul 30 16:47:45 2022 +0200
    24.3 @@ -6,7 +6,6 @@
    24.4     use"diffapp.sml";
    24.5  *)
    24.6  
    24.7 -Rewrite.trace_on := false; (*true false*)
    24.8  "Contents----------------------------------------------";
    24.9  "              Specify_Problem (match_itms_oris)       ";
   24.10  "              test specify, fmz <> []                  ";
   24.11 @@ -562,7 +561,7 @@
   24.12  UnparseC.term s;
   24.13  val t = TermC.str2term 
   24.14       "(hd o filterVar b) [A = a * b, (a / 2) \<up> 2 + (b / 2) \<up> 2 = r \<up> 2]";
   24.15 -val SOME (t',_) = rewrite_set_ thy false prog_expr t;
   24.16 +val SOME (t',_) = rewrite_set_ ctxt false prog_expr t;
   24.17  val s' = UnparseC.term t';
   24.18  (*=== inhibit exn 110726=============================================================
   24.19  if s' = "A = a * b" then () else error "new behaviour with prog_expr 2.1";
   24.20 @@ -668,9 +667,7 @@
   24.21  UnparseC.term s;
   24.22  val t = TermC.str2term 
   24.23  "(hd o filterVar A) [A = a * b, a / 2 = r * sin alpha, b / 2 = r * cos alpha]";
   24.24 -Rewrite.trace_on := false; (*true false*)
   24.25 -val SOME (t',_) = rewrite_set_ thy false prog_expr t;
   24.26 -Rewrite.trace_on:=false; (*true false*)
   24.27 +val SOME (t',_) = rewrite_set_ ctxt false prog_expr t;
   24.28  val s' = UnparseC.term t';
   24.29  (*=== inhibit exn 110726=============================================================
   24.30  if s' = "A = a * b" then() else error "new behaviour with prog_expr 3.1.";
   24.31 @@ -734,7 +731,7 @@
   24.32  UnparseC.term s;
   24.33  val t = TermC.str2term 
   24.34  	   "(hd o filterVar a) [a / 2 = r * sin alpha, b / 2 = r * cos alpha]";
   24.35 -val SOME (t',_) = rewrite_set_ thy false prog_expr t;
   24.36 +val SOME (t',_) = rewrite_set_ ctxt false prog_expr t;
   24.37  val s' = UnparseC.term t';
   24.38  (*=== inhibit exn 110726=============================================================
   24.39  if s' = "a / 2 = r * sin alpha" then () 
   24.40 @@ -749,7 +746,7 @@
   24.41  UnparseC.term s;
   24.42  val t = TermC.str2term 
   24.43  	  "(hd o filterVar b) [a / 2 = r * sin alpha, b / 2 = r * cos alpha]";
   24.44 -val SOME (t',_) = rewrite_set_ thy false prog_expr t;
   24.45 +val SOME (t',_) = rewrite_set_ ctxt false prog_expr t;
   24.46  val s' = UnparseC.term t';
   24.47  (*=== inhibit exn 110726=============================================================
   24.48  if s' = "b / 2 = r * cos alpha" then () 
   24.49 @@ -784,7 +781,7 @@
   24.50  UnparseC.term s;
   24.51  "Substitute\n [(a = (rhs o hd) [a = 2 * r * sin alpha]),\
   24.52  \              (b = (rhs o hd) [b = 2 * r * cos alpha])] (A = a * b)";
   24.53 -val SOME (s',_) = rewrite_set_ thy false prog_expr s;
   24.54 +val SOME (s',_) = rewrite_set_ ctxt false prog_expr s;
   24.55  val s'' = UnparseC.term s';
   24.56  (*=== inhibit exn 110726=============================================================
   24.57  if s'' = 
    25.1 --- a/test/Tools/isac/Knowledge/diff.sml	Thu Jul 28 11:43:27 2022 +0200
    25.2 +++ b/test/Tools/isac/Knowledge/diff.sml	Sat Jul 30 16:47:45 2022 +0200
    25.3 @@ -47,63 +47,66 @@
    25.4  "----------- for correction of diff_const ---------------";
    25.5  "----------- for correction of diff_const ---------------";
    25.6  "----------- for correction of diff_const ---------------";
    25.7 +val ctxt = Proof_Context.init_global @{theory};
    25.8  (*re-evaluate this file, otherwise > *** ME_Isa: 'erls' not known*)
    25.9  val t = TermC.parseNEW' ctxt "Not (x =!= a)";
   25.10 -case rewrite_set_ thy false erls_diff t of
   25.11 +case rewrite_set_ ctxt false erls_diff t of
   25.12    SOME (Const (\<^const_name>\<open>True\<close>, _), []) => ()
   25.13  | _ => error "rewrite_set_  Not (x =!= a)  changed";
   25.14  
   25.15  val t = TermC.parseNEW' ctxt "2 is_num";
   25.16 -case rewrite_set_ thy false erls_diff t of
   25.17 +case rewrite_set_ ctxt false erls_diff t of
   25.18    SOME (Const (\<^const_name>\<open>True\<close>, _), []) => ()
   25.19  | _ => error "rewrite_set_   2 is_num   changed";
   25.20  
   25.21  val thm = @{thm diff_const};
   25.22  val ct = TermC.parseNEW' ctxt "d_d x x";
   25.23  val subst = [(@{term "bdv::real"}, @{term "x::real"})];
   25.24 -val NONE = (rewrite_inst_ thy tless_true erls_diff false subst thm ct);
   25.25 +val NONE = (rewrite_inst_ ctxt tless_true erls_diff false subst thm ct);
   25.26  
   25.27  "----------- for correction of diff_quot ----------------";
   25.28  "----------- for correction of diff_quot ----------------";
   25.29  "----------- for correction of diff_quot ----------------";
   25.30  val thy = @{theory "Diff"};
   25.31 +val ctxt = Proof_Context.init_global thy;
   25.32  val ct = TermC.parseNEW' ctxt "Not (x = 0)";
   25.33 -rewrite_set_ thy false erls_diff ct;
   25.34 +rewrite_set_ ctxt false erls_diff ct;
   25.35  
   25.36  val ct = TermC.parseNEW' ctxt "d_d x ((x+1) / (x - 1))";
   25.37  val thm = @{thm diff_quot};
   25.38  val SOME (ctt,_) =
   25.39 -    (rewrite_inst_ thy tless_true erls_diff true subst thm ct);
   25.40 +    (rewrite_inst_ ctxt tless_true erls_diff true subst thm ct);
   25.41  
   25.42  "----------- differentiate by rewrite -------------------";
   25.43  "----------- differentiate by rewrite -------------------";
   25.44  "----------- differentiate by rewrite -------------------";
   25.45  val thy = @{theory "Diff"};
   25.46 +val ctxt = Proof_Context.init_global thy;
   25.47  val ct = TermC.parseNEW' ctxt "d_d x (x \<up> 2 + 3 * x + 4)";
   25.48  "--- 1 ---";
   25.49  val thm = @{thm "diff_sum"};
   25.50 -val (ct, _) = the (rewrite_inst_ thy tless_true erls_diff true subst thm ct);
   25.51 +val (ct, _) = the (rewrite_inst_ ctxt tless_true erls_diff true subst thm ct);
   25.52  "--- 2 ---";
   25.53 -val (ct, _) = the (rewrite_inst_ thy tless_true erls_diff true subst thm ct);
   25.54 +val (ct, _) = the (rewrite_inst_ ctxt tless_true erls_diff true subst thm ct);
   25.55  "--- 3 ---";
   25.56  val thm = @{thm "diff_prod_const"};
   25.57 -val (ct, _) = the (rewrite_inst_ thy tless_true erls_diff true subst thm ct);
   25.58 +val (ct, _) = the (rewrite_inst_ ctxt tless_true erls_diff true subst thm ct);
   25.59  "--- 4 ---";
   25.60  val thm = @{thm "diff_pow"};
   25.61 -val (ct, _) = the (rewrite_inst_ thy tless_true erls_diff true subst thm ct);
   25.62 +val (ct, _) = the (rewrite_inst_ ctxt tless_true erls_diff true subst thm ct);
   25.63  "--- 5 ---";
   25.64  val thm = @{thm "diff_const"};
   25.65 -val (ct, _) = the (rewrite_inst_ thy tless_true erls_diff true subst thm ct);
   25.66 +val (ct, _) = the (rewrite_inst_ ctxt tless_true erls_diff true subst thm ct);
   25.67  "--- 6 ---";
   25.68  val thm = @{thm "diff_var"};
   25.69 -val (ct, _) = the (rewrite_inst_ thy tless_true erls_diff true subst thm ct);
   25.70 +val (ct, _) = the (rewrite_inst_ ctxt tless_true erls_diff true subst thm ct);
   25.71  if UnparseC.term ct = "2 * x \<up> (2 - 1) + 3 * 1 + 0" then ()
   25.72  else error "diff.sml diff.behav. in rewrite 1";
   25.73  "--- 7 ---";
   25.74  "--- 7 ---";
   25.75  val rls = Test_simplify;
   25.76  val ct = TermC.parseNEW' ctxt "2 * x \<up> (2 - 1) + 3 * 1 + 0";
   25.77 -val (ct, _) = the (rewrite_set_ thy true rls ct);
   25.78 +val (ct, _) = the (rewrite_set_ ctxt true rls ct);
   25.79  if UnparseC.term ct = "3 + 2 * x" then () else error "rewrite_set_ Test_simplify 2 changed";
   25.80  
   25.81  "----------- differentiate: me (*+ tacs input*) ---------";
   25.82 @@ -214,6 +217,7 @@
   25.83  "----------- primed id ----------------------------------";
   25.84  "----------- primed id ----------------------------------";
   25.85  "----------- primed id ----------------------------------";
   25.86 +val ctxt = Proof_Context.init_global @{theory Isac_Knowledge};
   25.87  val f_ = TermC.str2term "f_f::bool";
   25.88  val f  = TermC.str2term "A = s * (a - s)";
   25.89  val v_ = TermC.str2term "v_v";
   25.90 @@ -225,7 +229,7 @@
   25.91  UnparseC.term screxp1;
   25.92  TermC.atomty screxp1;
   25.93  
   25.94 -val SOME (f'_,_) = rewrite_set_ (@{theory "Isac_Knowledge"}) false srls_diff screxp1; 
   25.95 +val SOME (f'_,_) = rewrite_set_ ctxt false srls_diff screxp1; 
   25.96  if UnparseC.term f'_= "Take (A' = d_d s (s * (a - s)))" then ()
   25.97  else error "diff.sml: diff.behav. in 'primed'";
   25.98  TermC.atomty f'_;
   25.99 @@ -268,29 +272,29 @@
  25.100  val rls = diff_conv;
  25.101  
  25.102  val t = TermC.str2term "2/x \<up> 2"; 
  25.103 -val SOME (t,_) = rewrite_set_inst_ thy false subs rls t; UnparseC.term t;
  25.104 +val SOME (t,_) = rewrite_set_inst_ ctxt false subs rls t; UnparseC.term t;
  25.105  if UnparseC.term t = "2 * x \<up> - 2" then () else error "diff.sml 1/x";
  25.106  
  25.107  val t = TermC.str2term "sqrt (x \<up> 3)";
  25.108 -val SOME (t,_) = rewrite_set_inst_ thy false subs rls t; UnparseC.term t;
  25.109 +val SOME (t,_) = rewrite_set_inst_ ctxt false subs rls t; UnparseC.term t;
  25.110  if UnparseC.term t = "x \<up> (3 / 2)" then () else error "diff.sml x \<up> 1/2";
  25.111  
  25.112  val t = TermC.str2term "2 / sqrt x \<up> 3";
  25.113 -val SOME (t,_) = rewrite_set_inst_ thy false subs rls t; UnparseC.term t;
  25.114 +val SOME (t,_) = rewrite_set_inst_ ctxt false subs rls t; UnparseC.term t;
  25.115  if UnparseC.term t = "2 * x \<up> (- 3 / 2)" then () else error "diff.sml x \<up> - 1/2";
  25.116  
  25.117  val rls = diff_sym_conv;
  25.118  
  25.119  val t = TermC.str2term "2 * x \<up> - 2";
  25.120 -val SOME (t, _) = rewrite_set_inst_ thy false subs rls t; UnparseC.term t;
  25.121 +val SOME (t, _) = rewrite_set_inst_ ctxt false subs rls t; UnparseC.term t;
  25.122  if UnparseC.term t = "2 / x \<up> 2" then () else error "diff.sml sym 1/x";
  25.123  
  25.124  val t = TermC.str2term "x \<up> (3 / 2)";
  25.125 -val SOME (t,_) = rewrite_set_inst_ thy false subs rls t; UnparseC.term t;
  25.126 +val SOME (t,_) = rewrite_set_inst_ ctxt false subs rls t; UnparseC.term t;
  25.127  if UnparseC.term t = "sqrt (x \<up> 3)" then ((*..wrong rewrite*)) else error"diff.sml sym x \<up> 1/x";
  25.128  
  25.129  val t = TermC.str2term "2 * x \<up> (-3 / 2)";
  25.130 -val SOME (t,_) = rewrite_set_inst_ thy false subs rls t; UnparseC.term t;
  25.131 +val SOME (t,_) = rewrite_set_inst_ ctxt false subs rls t; UnparseC.term t;
  25.132  if UnparseC.term t ="2 / sqrt (x \<up> 3)"then()else error"diff.sml sym x \<up> - 1/x";
  25.133  
  25.134  
    26.1 --- a/test/Tools/isac/Knowledge/diophanteq.sml	Thu Jul 28 11:43:27 2022 +0200
    26.2 +++ b/test/Tools/isac/Knowledge/diophanteq.sml	Sat Jul 30 16:47:45 2022 +0200
    26.3 @@ -33,14 +33,14 @@
    26.4        SOME t' => t'
    26.5      | NONE => error "diophanteq.sml: syntax error in rewriting for usecase1";
    26.6  
    26.7 -val SOME (t,_) = rewrite_inst_ thy e_rew_ord Rule_Set.empty true subst 
    26.8 +val SOME (t,_) = rewrite_inst_ ctxt e_rew_ord Rule_Set.empty true subst 
    26.9    @{thm "int_isolate_add"} t; UnparseC.term t;
   26.10  
   26.11  val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES"))) t; 
   26.12 -val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t; UnparseC.term t;
   26.13 +val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; UnparseC.term t;
   26.14  
   26.15  val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t; 
   26.16 -val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t; UnparseC.term t;
   26.17 +val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; UnparseC.term t;
   26.18  
   26.19  "----------- mathengine with usecase1 -------------------";
   26.20  "----------- mathengine with usecase1 -------------------";
   26.21 @@ -72,10 +72,10 @@
   26.22      | NONE => error "diophanteq.sml: syntax error in rewriting for usecase2";
   26.23  
   26.24  val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES"))) t; 
   26.25 -val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t; UnparseC.term t;
   26.26 +val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; UnparseC.term t;
   26.27  
   26.28  val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t; 
   26.29 -val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t; UnparseC.term t;
   26.30 +val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; UnparseC.term t;
   26.31  
   26.32  
   26.33  "----------- mathengine with usecase2 -------------------";
    27.1 --- a/test/Tools/isac/Knowledge/eqsystem-1.sml	Thu Jul 28 11:43:27 2022 +0200
    27.2 +++ b/test/Tools/isac/Knowledge/eqsystem-1.sml	Sat Jul 30 16:47:45 2022 +0200
    27.3 @@ -3,7 +3,6 @@
    27.4     (c) due to copyright terms
    27.5  *)
    27.6  
    27.7 -Rewrite.trace_on := false; (*true false*)
    27.8  "-----------------------------------------------------------------";
    27.9  "table of contents -----------------------------------------------";
   27.10  "-----------------------------------------------------------------";
   27.11 @@ -90,7 +89,7 @@
   27.12  			  Eval (\<^const_name>\<open>plus\<close>, eval_binop "#add_"),
   27.13  			  Eval (\<^const_name>\<open>HOL.eq\<close>,eval_equal "#equal_")
   27.14  			  ];
   27.15 -val SOME (t',_) = rewrite_set_ thy false testrls t;
   27.16 +val SOME (t',_) = rewrite_set_ ctxt false testrls t;
   27.17  if UnparseC.term t' = "True" then () 
   27.18  else error "eqsystem.sml: length_ [x+y=1,y=2] = 2";
   27.19  
   27.20 @@ -108,7 +107,7 @@
   27.21          assume flawed test setup hidden by "handle _ => ..."
   27.22          ERROR rewrite__set_ called with 'Erls' for '1 < 1'
   27.23  val SOME (t,_) = 
   27.24 -    rewrite_set_ thy true 
   27.25 +    rewrite_set_ ctxt true 
   27.26  		 (Rule_Set.append_rules "prls_" Rule_Set.empty 
   27.27  			     [Thm ("NTH_CONS",ThmC.numerals_to_Free @{thm NTH_CONS}),
   27.28  			      Thm ("NTH_NIL",ThmC.numerals_to_Free @{thm NTH_NIL}),
   27.29 @@ -159,20 +158,20 @@
   27.30  	        \0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2]";
   27.31  val bdvs = [(TermC.str2term"bdv_1",TermC.str2term"c"),
   27.32  	    (TermC.str2term"bdv_2",TermC.str2term"c_2")];
   27.33 -val SOME(t,_)= rewrite_set_inst_ thy true bdvs simplify_System_parenthesized t;
   27.34 +val SOME(t,_)= rewrite_set_inst_ ctxt true bdvs simplify_System_parenthesized t;
   27.35  if UnparseC.term t = "[0 = - 1 * q_0 * L \<up> 2 / 2 + (L * c + c_2), 0 = c_2]"
   27.36  then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.1";
   27.37  
   27.38 -val SOME (t,_) = rewrite_set_inst_ thy true bdvs isolate_bdvs t;
   27.39 +val SOME (t,_) = rewrite_set_inst_ ctxt true bdvs isolate_bdvs t;
   27.40  if UnparseC.term t = "[L * c + c_2 = 0 + - 1 * (- 1 * q_0 * L \<up> 2 / 2), c_2 = 0]"
   27.41  then () else error "eqsystem.sml rewrite in 2x2 isolate_bdvs";
   27.42  
   27.43 -val SOME(t,_)= rewrite_set_inst_ thy true bdvs simplify_System t;
   27.44 +val SOME(t,_)= rewrite_set_inst_ ctxt true bdvs simplify_System t;
   27.45  if UnparseC.term t = "[L * c + c_2 = q_0 * L \<up> 2 / 2, c_2 = 0]"
   27.46  then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.2";
   27.47  
   27.48  "--- 3--- see EqSystem.thy (*..if replaced by 'and' ...*)";
   27.49 -val SOME (t,_) = rewrite_set_ thy true order_system t;
   27.50 +val SOME (t,_) = rewrite_set_ ctxt true order_system t;
   27.51  if UnparseC.term t = "[c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]"
   27.52  then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.3";
   27.53  
   27.54 @@ -180,36 +179,37 @@
   27.55  "----------- rewrite example from 2nd [EqSystem,normalise,2x2] ---";
   27.56  "----------- rewrite example from 2nd [EqSystem,normalise,2x2] ---";
   27.57  val thy = @{theory "Isac_Knowledge"} (*because of Undeclared constant "Biegelinie.EI*);
   27.58 +val ctxt = Proof_Context.init_global thy;
   27.59  val t = 
   27.60      TermC.str2term"[0 = c_2 + c * 0 + 1 / EI * (L * q_0 / 12 * 0 \<up> 3 +         \
   27.61  	    \                                     - 1 * q_0 / 24 * 0 \<up> 4),\
   27.62  	    \ 0 = c_2 + c * L + 1 / EI * (L * q_0 / 12 * L \<up> 3 +         \
   27.63  	    \                                     - 1 * q_0 / 24 * L \<up> 4)]";
   27.64 -val SOME (t, _) = rewrite_set_ thy true norm_Rational t;
   27.65 +val SOME (t, _) = rewrite_set_ ctxt true norm_Rational t;
   27.66  if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
   27.67                        "[c_2 = 0, 0 = q_0 * L \<up> 4 / (24 * EI) + (L * c + c_2)]"*)
   27.68                        "[0 = c_2, 0 = (24 * c_2 + 24 * L * c + L \<up> 4 * q_0) / 24]"
   27.69  then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.0b";
   27.70  
   27.71 -val SOME(t, _)= rewrite_set_inst_ thy true bdvs simplify_System_parenthesized t;
   27.72 +val SOME(t, _)= rewrite_set_inst_ ctxt true bdvs simplify_System_parenthesized t;
   27.73  if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
   27.74                         "[c_2 = 0, 0 = q_0 * L \<up> 4 / (24 * EI) + (L * c + c_2)]"*)
   27.75                         "[0 = c_2, 0 = q_0 * L \<up> 4 / 24 + (L * c + c_2)]"
   27.76  then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.1b";
   27.77  
   27.78 -val SOME (t,_) = rewrite_set_inst_ thy true bdvs isolate_bdvs t;
   27.79 +val SOME (t,_) = rewrite_set_inst_ ctxt true bdvs isolate_bdvs t;
   27.80  if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
   27.81                         "[c_2 = 0, L * c + c_2 = 0 + - 1 * (q_0 * L \<up> 4 / (24 * EI))]"*)
   27.82                         "[c_2 = 0, L * c + c_2 = 0 + - 1 * (q_0 * L \<up> 4 / 24)]"
   27.83  then () else error "eqsystem.sml rewrite in 2x2 isolate_bdvs b";
   27.84  
   27.85 -val SOME(t,_)= rewrite_set_inst_ thy true bdvs simplify_System t;
   27.86 +val SOME(t,_)= rewrite_set_inst_ ctxt true bdvs simplify_System t;
   27.87  if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
   27.88                         "[c_2 = 0, L * c + c_2 = - 1 * q_0 * L \<up> 4 / (24 * EI)]"*)
   27.89                         "[c_2 = 0, L * c + c_2 = - 1 * q_0 * L \<up> 4 / 24]"
   27.90  then () else error "eqsystem.sml rewrite in 2x2 simplify_System.2b";
   27.91  
   27.92 -val xxx = rewrite_set_ thy true order_system t;
   27.93 +val xxx = rewrite_set_ ctxt true order_system t;
   27.94  if is_none xxx
   27.95  then () else error "eqsystem.sml rewrite in 2x2 simplify_System.3b";
   27.96  
   27.97 @@ -221,21 +221,21 @@
   27.98  val e2__ = TermC.str2term "L * c + c_2 = q_0 * L \<up> 2 / 2";
   27.99  val bdvs = [(TermC.str2term"bdv_1",TermC.str2term"c"),
  27.100  	    (TermC.str2term"bdv_2",TermC.str2term"c_2")];
  27.101 -val SOME (e2__,_) = rewrite_terms_ thy dummy_ord Rule_Set.Empty [e1__] e2__;
  27.102 +val SOME (e2__,_) = rewrite_terms_ ctxt dummy_ord Rule_Set.Empty [e1__] e2__;
  27.103  if UnparseC.term e2__ = "L * c + 77 = q_0 * L \<up> 2 / 2" then ()
  27.104  else error "eqsystem.sml top_down_substitution,2x2] subst";
  27.105  
  27.106  val SOME (e2__,_) = 
  27.107 -    rewrite_set_inst_ thy true bdvs simplify_System_parenthesized e2__;
  27.108 +    rewrite_set_inst_ ctxt true bdvs simplify_System_parenthesized e2__;
  27.109  if UnparseC.term e2__ = "77 + L * c = q_0 * L \<up> 2 / 2" then ()
  27.110  else error "eqsystem.sml top_down_substitution,2x2] simpl_par";
  27.111  
  27.112 -val SOME (e2__,_) = rewrite_set_inst_ thy true bdvs isolate_bdvs e2__;
  27.113 +val SOME (e2__,_) = rewrite_set_inst_ ctxt true bdvs isolate_bdvs e2__;
  27.114  if UnparseC.term e2__ = "c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L" then ()
  27.115  else error "eqsystem.sml top_down_substitution,2x2] isolate";
  27.116  
  27.117  val t = TermC.str2term "[c_2 = 77, c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L]";
  27.118 -val SOME (t,_) = rewrite_set_ thy true order_system t;
  27.119 +val SOME (t,_) = rewrite_set_ ctxt true order_system t;
  27.120  if UnparseC.term t = "[c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L, c_2 = 77]" then ()
  27.121  else error "eqsystem.sml top_down_substitution,2x2] order_system";
  27.122  
  27.123 @@ -260,24 +260,24 @@
  27.124  	    (TermC.str2term"bdv_3::real",TermC.str2term"c_3::real"),
  27.125  	    (TermC.str2term"bdv_4::real",TermC.str2term"c_4::real")];
  27.126  val SOME (t, _) = 
  27.127 -    rewrite_set_inst_ thy true bdvs simplify_System_parenthesized t;
  27.128 +    rewrite_set_inst_ ctxt true bdvs simplify_System_parenthesized t;
  27.129  if UnparseC.term t = "[0 = c_4, 0 = - 1 * q_0 * L \<up> 2 / 2 + (L * c_3 + c_4),\n c + (c_2 + (c_3 + c_4)) = 0, c_2 + (c_3 + c_4) = 0]"
  27.130  then () else error "eqsystem.sml rewrite in 4x4 simplify_System_paren";
  27.131  
  27.132 -val SOME (t, _) = rewrite_set_inst_ thy true bdvs isolate_bdvs t;
  27.133 +val SOME (t, _) = rewrite_set_inst_ ctxt true bdvs isolate_bdvs t;
  27.134  if UnparseC.term t = "[c_4 = 0, \
  27.135  	        \L * c_3 + c_4 = 0 + - 1 * (- 1 * q_0 * L \<up> 2 / 2),\n \
  27.136  		\c + (c_2 + (c_3 + c_4)) = 0, c_2 + (c_3 + c_4) = 0]"
  27.137  then () else error "eqsystem.sml rewrite in 4x4 isolate_bdvs";
  27.138  
  27.139 -val SOME(t, _)= rewrite_set_inst_ thy true bdvs simplify_System_parenthesized t;
  27.140 +val SOME(t, _)= rewrite_set_inst_ ctxt true bdvs simplify_System_parenthesized t;
  27.141  if UnparseC.term t = "[c_4 = 0,\
  27.142  		\ L * c_3 + c_4 = q_0 * L \<up> 2 / 2,\
  27.143  		\ c + (c_2 + (c_3 + c_4)) = 0,\n\
  27.144  		\ c_2 + (c_3 + c_4) = 0]"
  27.145  then () else error "eqsystem.sml rewrite in 4x4 simplify_System_p..2";
  27.146  
  27.147 -val SOME (t, _) = rewrite_set_ thy true order_system t;
  27.148 +val SOME (t, _) = rewrite_set_ ctxt true order_system t;
  27.149  if UnparseC.term t = "[c_4 = 0,\
  27.150  		\ L * c_3 + c_4 = q_0 * L \<up> 2 / 2,\
  27.151  		\ c_2 + (c_3 + c_4) = 0,\n\
  27.152 @@ -371,8 +371,8 @@
  27.153            [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]"]*)
  27.154  val t = TermC.str2term ("[c, c_2] from [c, c_2] occur_exactly_in NTH 2" ^   
  27.155  		  "[c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]");
  27.156 -Rewrite.trace_on := false; (*true false*)
  27.157 -val SOME (t', _) = rewrite_set_ thy false prls_triangular t;
  27.158 +
  27.159 +val SOME (t', _) = rewrite_set_ ctxt false prls_triangular t;
  27.160  (*found:...
  27.161  ##  try thm: NTH_CONS
  27.162  ###  eval asms: 1 < 2 + - 1
  27.163 @@ -433,9 +433,7 @@
  27.164  val fmz = ["equalities [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,\
  27.165  	               \0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2]", 
  27.166  	   "solveForVars [c, c_2]", "solution LL"];
  27.167 -Rewrite.trace_on := false; (*true false*)
  27.168  val matches = Refine.refine fmz ["2x2", "LINEAR", "system"];
  27.169 -Rewrite.trace_on := false; (*true false*)
  27.170  (*default_print_depth 11;*) TermC.matches; (*default_print_depth 3;*)
  27.171  (*brought: 'False "length_ es_ = 2"'*)
  27.172  
    28.1 --- a/test/Tools/isac/Knowledge/eqsystem-2.sml	Thu Jul 28 11:43:27 2022 +0200
    28.2 +++ b/test/Tools/isac/Knowledge/eqsystem-2.sml	Sat Jul 30 16:47:45 2022 +0200
    28.3 @@ -3,7 +3,6 @@
    28.4     (c) due to copyright terms
    28.5  *)
    28.6  
    28.7 -Rewrite.trace_on := false; (*true false*)
    28.8  "-----------------------------------------------------------------";
    28.9  "table of contents -----------------------------------------------";
   28.10  "-----------------------------------------------------------------";
   28.11 @@ -130,26 +129,26 @@
   28.12    "0 = c_4 + L * c_3 +(12 * L \<up> 2 * c_2 + 4 * L \<up> 3 * c + - 1 * L \<up> 4 * q_0) / (- 24 * EI), " ^
   28.13    "0 = c_2, " ^
   28.14    "0 = (2 * c_2 + 2 * L * c + - 1 * L \<up> 2 * q_0) / 2]");
   28.15 -val SOME (t, _) = rewrite_set_ thy false isolate_bdvs_4x4 t;
   28.16 +val SOME (t, _) = rewrite_set_ ctxt false isolate_bdvs_4x4 t;
   28.17  if UnparseC.term t =
   28.18  "[c_4 = 0,\n (12 * L \<up> 2 * c_2 + 4 * L \<up> 3 * c + - 1 * L \<up> 4 * q_0) /\n (- 24 * EI) =\n - 1 * (c_4 + L * c_3) + 0,\n c_2 = 0, (2 * c_2 + 2 * L * c + - 1 * L \<up> 2 * q_0) / 2 = 0]"
   28.19  then () else error "Bsp 7.27";
   28.20  
   28.21  "----- Bsp 7.27 go through the rewrites in met_eqsys_norm_4x4";
   28.22  val t = TermC.str2term "0 = (2 * c_2 + 2 * L * c + - 1 * L \<up> 2 * q_0) / 2";
   28.23 -val NONE = rewrite_set_ thy false norm_Rational t;
   28.24 +val NONE = rewrite_set_ ctxt false norm_Rational t;
   28.25  val SOME (t,_) = 
   28.26 -    rewrite_set_inst_ thy false subst simplify_System_parenthesized t;
   28.27 +    rewrite_set_inst_ ctxt false subst simplify_System_parenthesized t;
   28.28  if UnparseC.term t = "0 = - 1 * q_0 * L \<up> 2 / 2 + (L * c + c_2)"
   28.29  then () else error "Bsp 7.27 go through the rewrites in met_eqsys_norm_4x4";
   28.30  
   28.31  "--- isolate_bdvs_4x4";
   28.32  (*
   28.33 -val SOME (t,_) = rewrite_set_inst_ thy false subst isolate_bdvs_4x4 t;
   28.34 +val SOME (t,_) = rewrite_set_inst_ ctxt false subst isolate_bdvs_4x4 t;
   28.35  UnparseC.term t;
   28.36 -val SOME (t,_) = rewrite_set_inst_ thy false subst simplify_System t;
   28.37 +val SOME (t,_) = rewrite_set_inst_ ctxt false subst simplify_System t;
   28.38  UnparseC.term t;
   28.39 -val SOME (t,_) = rewrite_set_ thy false order_system t;
   28.40 +val SOME (t,_) = rewrite_set_ ctxt false order_system t;
   28.41  UnparseC.term t;
   28.42  *)
   28.43  
   28.44 @@ -208,29 +207,29 @@
   28.45    "0 = (2 * c_2 + 2 * L * c + - 1 * L \<up> 2 * q_0) / 2, " ^
   28.46    "0 = c_4, " ^
   28.47    "0 = c_3]");
   28.48 -val SOME (t,_) = rewrite_ thy e_rew_ord Rule_Set.empty false @{thm commute_0_equality} t;
   28.49 -val SOME (t,_) = rewrite_ thy e_rew_ord Rule_Set.empty false @{thm commute_0_equality} t;
   28.50 -val SOME (t,_) = rewrite_ thy e_rew_ord Rule_Set.empty false @{thm commute_0_equality} t;
   28.51 +val SOME (t,_) = rewrite_ ctxt e_rew_ord Rule_Set.empty false @{thm commute_0_equality} t;
   28.52 +val SOME (t,_) = rewrite_ ctxt e_rew_ord Rule_Set.empty false @{thm commute_0_equality} t;
   28.53 +val SOME (t,_) = rewrite_ ctxt e_rew_ord Rule_Set.empty false @{thm commute_0_equality} t;
   28.54  if UnparseC.term t = 
   28.55    "[L * q_0 = c, (2 * c_2 + 2 * L * c + - 1 * L \<up> 2 * q_0) / 2 = 0,\n c_4 = 0, c_3 = 0]"
   28.56  then () else error "7.70 go through the rewrites in met_eqsys_norm_4x4, 1";
   28.57  
   28.58 -val SOME (t,_) = rewrite_set_inst_ thy false subst simplify_System_parenthesized t;
   28.59 +val SOME (t,_) = rewrite_set_inst_ ctxt false subst simplify_System_parenthesized t;
   28.60  if UnparseC.term t = "[L * q_0 = c, - 1 * q_0 * L \<up> 2 / 2 + (L * c + c_2) = 0, c_4 = 0,\n c_3 = 0]"
   28.61  then () else error "7.70 go through the rewrites in met_eqsys_norm_4x4, 2";
   28.62  
   28.63 -val SOME (t,_) = rewrite_set_inst_ thy false subst isolate_bdvs_4x4 t;
   28.64 +val SOME (t,_) = rewrite_set_inst_ ctxt false subst isolate_bdvs_4x4 t;
   28.65  if UnparseC.term t =
   28.66     "[c = (- 1 * (L * q_0) + 0) / - 1,\n" ^ 
   28.67     " L * c + c_2 = - 1 * (- 1 * q_0 * L \<up> 2 / 2) + 0, c_4 = 0, c_3 = 0]"
   28.68  then () else error "7.70 go through the rewrites in met_eqsys_norm_4x4, 3";
   28.69  
   28.70 -val SOME (t,_) = rewrite_set_inst_ thy false subst simplify_System_parenthesized t;
   28.71 +val SOME (t,_) = rewrite_set_inst_ ctxt false subst simplify_System_parenthesized t;
   28.72  if UnparseC.term t =
   28.73    "[c = - 1 * L * q_0 / - 1, L * c + c_2 = q_0 * L \<up> 2 / 2, c_4 = 0,\n c_3 = 0]"
   28.74  then () else error "7.70 go through the rewrites in met_eqsys_norm_4x4, 4";
   28.75  
   28.76 -val SOME (t, _) = rewrite_set_ thy false order_system t;
   28.77 +val SOME (t, _) = rewrite_set_ ctxt false order_system t;
   28.78  if UnparseC.term t =
   28.79    "[c = - 1 * L * q_0 / - 1, L * c + c_2 = q_0 * L \<up> 2 / 2, c_3 = 0,\n c_4 = 0]"
   28.80  then () else error "eqsystem.sml: exp 7.70 normalise 4x4 by rewrite changed";
    29.1 --- a/test/Tools/isac/Knowledge/inssort.sml	Thu Jul 28 11:43:27 2022 +0200
    29.2 +++ b/test/Tools/isac/Knowledge/inssort.sml	Sat Jul 30 16:47:45 2022 +0200
    29.3 @@ -36,62 +36,62 @@
    29.4  val ctxt = Proof_Context.init_global @{theory};
    29.5  val SOME t = parseNEW ctxt "sort {|| 1, 3, 2 ||}";
    29.6  
    29.7 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm sort_deff} t;
    29.8 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm sort_deff} t;
    29.9  UnparseC.term t' = "xfoldr ins {|| 1, 3, 2 ||} {|| ||}";
   29.10  
   29.11 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm xfoldr_Cons} t';
   29.12 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm xfoldr_Cons} t';
   29.13  UnparseC.term t' = "(ins 1 o xfoldr ins {|| 3, 2 ||}) {|| ||}";
   29.14  
   29.15 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm xfoldr_Cons} t';
   29.16 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm xfoldr_Cons} t';
   29.17  UnparseC.term t' = "(ins 1 o (ins 3 o xfoldr ins {|| 2 ||})) {|| ||}";
   29.18  
   29.19 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm xfoldr_Cons} t';
   29.20 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm xfoldr_Cons} t';
   29.21  UnparseC.term t' = "(ins 1 o (ins 3 o (ins 2 o xfoldr ins {|| ||}))) {|| ||}";
   29.22  
   29.23 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm xfoldr_Nil} t';
   29.24 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm xfoldr_Nil} t';
   29.25  UnparseC.term t' = "(ins 1 o (ins 3 o (ins 2 o id))) {|| ||}";
   29.26  
   29.27 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm o_id} t';
   29.28 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm o_id} t';
   29.29  UnparseC.term t' = "(ins 1 o (ins 3 o ins 2)) {|| ||}";
   29.30  
   29.31 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm o_assoc} t';
   29.32 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm o_assoc} t';
   29.33  UnparseC.term t' = "(ins 1 o ins 3 o ins 2) {|| ||}";
   29.34  
   29.35 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm o_apply} t';
   29.36 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm o_apply} t';
   29.37  UnparseC.term t' = "(ins 1 o ins 3) (ins 2 {|| ||})";
   29.38  
   29.39 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm o_apply} t';
   29.40 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm o_apply} t';
   29.41  UnparseC.term t' = "ins 1 (ins 3 (ins 2 {|| ||}))";
   29.42  
   29.43 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm ins_Nil} t';
   29.44 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm ins_Nil} t';
   29.45  UnparseC.term t' = "ins 1 (ins 3 {|| 2 ||})";
   29.46  
   29.47 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm ins_Cons} t';
   29.48 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm ins_Cons} t';
   29.49  UnparseC.term t' = "ins 1 (if 3 < 2 then {|| 3, 2 ||} else 2 @# ins 3 {|| ||})";
   29.50  
   29.51 -val SOME (t', _) = calculate_ @{theory} (\<^const_name>\<open>less\<close>, eval_equ "#less_")  t';
   29.52 +val SOME (t', _) = calculate_ ctxt (\<^const_name>\<open>less\<close>, eval_equ "#less_")  t';
   29.53  UnparseC.term t' = "ins 1 (if False then {|| 3, 2 ||} else 2 @# ins 3 {|| ||})";
   29.54  
   29.55 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm if_False} t';
   29.56 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm if_False} t';
   29.57  UnparseC.term t' = "ins 1 (2 @# ins 3 {|| ||})";
   29.58  
   29.59 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm ins_Nil} t';
   29.60 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm ins_Nil} t';
   29.61  UnparseC.term t' = "ins 1 {|| 2, 3 ||}";
   29.62  
   29.63 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm ins_Cons} t';
   29.64 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm ins_Cons} t';
   29.65  UnparseC.term t' = "if 1 < 2 then {|| 1, 2, 3 ||} else 2 @# ins 1 {|| 3 ||}";
   29.66  
   29.67 -val SOME (t', _) = calculate_ @{theory} (\<^const_name>\<open>less\<close>, eval_equ "#less_")  t';
   29.68 +val SOME (t', _) = calculate_ ctxt (\<^const_name>\<open>less\<close>, eval_equ "#less_")  t';
   29.69  UnparseC.term t' = "if True then {|| 1, 2, 3 ||} else 2 @# ins 1 {|| 3 ||}";
   29.70  
   29.71 -val SOME (t', _) = rewrite_ @{theory} tless_true eval_rls false @{thm if_True} t';
   29.72 +val SOME (t', _) = rewrite_ ctxt tless_true eval_rls false @{thm if_True} t';
   29.73  if UnparseC.term t' = "{|| 1, 2, 3 ||}" then () else error "CHANGED RESULT FOR sort by rewrite stepwise";
   29.74  
   29.75  "----------- insertion sort with ruleset -------------------------------------";
   29.76  "----------- insertion sort with ruleset -------------------------------------";
   29.77  "----------- insertion sort with ruleset -------------------------------------";
   29.78  if UnparseC.term t = "InsSort.sort {|| 1, 3, 2 ||}" then () else error "CHANGED START FOR sort with ruleset";
   29.79 -val SOME (t', _) = rewrite_set_ @{theory} false ins_sort t;
   29.80 +val SOME (t', _) = rewrite_set_ ctxt false ins_sort t;
   29.81  if UnparseC.term t' = "{|| 1, 2, 3 ||}" then () else error "CHANGED RESULT FOR sort with ruleset";
   29.82  
   29.83  "----------- insertion sort with MathEngine ----------------------------------";
    30.1 --- a/test/Tools/isac/Knowledge/integrate.sml	Thu Jul 28 11:43:27 2022 +0200
    30.2 +++ b/test/Tools/isac/Knowledge/integrate.sml	Sat Jul 30 16:47:45 2022 +0200
    30.3 @@ -43,7 +43,7 @@
    30.4      scr = Empty_Prog};
    30.5  val subs = [(str2t "bdv::real", str2t "x::real")];
    30.6  fun rewrit thm str = 
    30.7 -    fst (the (rewrite_inst_ thy tless_true 
    30.8 +    fst (the (rewrite_inst_ ctxt tless_true 
    30.9  			   conditions_in_integration_rules 
   30.10  			   true subs thm str));
   30.11  
   30.12 @@ -104,12 +104,12 @@
   30.13  val cc = ("Integrate.add_new_c", eval_add_new_c "add_new_c_");
   30.14  val SOME (thmstr, thm) = adhoc_thm1_ thy cc term;
   30.15  
   30.16 -val SOME (t',_) = rewrite_set_ thy true add_new_c term;
   30.17 +val SOME (t',_) = rewrite_set_ ctxt true add_new_c term;
   30.18  if UnparseC.term t' = "x \<up> 2 * c + c_2 + c_3" then ()
   30.19  else error "intergrate.sml: diff. rewrite_set add_new_c 1";
   30.20  
   30.21  val term = TermC.str2term "ff x = x \<up> 2*c + c_2";
   30.22 -val SOME (t',_) = rewrite_set_ thy true add_new_c term;
   30.23 +val SOME (t',_) = rewrite_set_ ctxt true add_new_c term;
   30.24  if UnparseC.term t' = "ff x = x \<up> 2 * c + c_2 + c_3" then ()
   30.25  else error "intergrate.sml: diff. rewrite_set add_new_c 2";
   30.26  
   30.27 @@ -172,25 +172,26 @@
   30.28  "----------- simplify by ruleset reducing make_ratpoly_in";
   30.29  "----------- simplify by ruleset reducing make_ratpoly_in";
   30.30  val thy = @{theory "Isac_Knowledge"};
   30.31 +val ctxt = Proof_Context.init_global thy;
   30.32  val subst = [(TermC.str2term "bdv ::real", TermC.str2term "x ::real")]; (*DOESN'T HELP*)
   30.33  "===== test 1";
   30.34  val t = TermC.str2term "1/EI * (L * q_0 * x / 2 + - 1 * q_0 * x \<up> 2 / 2)";
   30.35  
   30.36  "----- stepwise from the rulesets in simplify_Integral and below-----";
   30.37  val rls = norm_Rational_noadd_fractions;
   30.38 -case rewrite_set_inst_ thy true subs rls t of
   30.39 +case rewrite_set_inst_ ctxt true subs rls t of
   30.40      SOME _ => error "integrate.sml simplify by ruleset norm_Rational_.#2"
   30.41    | NONE => ();
   30.42  
   30.43  "===== test 2";
   30.44  val rls = order_add_mult_in;
   30.45 -val SOME (t, []) = rewrite_set_inst_ thy true subst rls t;
   30.46 +val SOME (t, []) = rewrite_set_inst_ ctxt true subst rls t;
   30.47  if UnparseC.term t = "1 / EI * (L * (q_0 * x) / 2 + - 1 * (q_0 * x \<up> 2) / 2)" then()
   30.48  else error "integrate.sml simplify by ruleset order_add_mult_in #2";
   30.49  
   30.50  "===== test 3";
   30.51  val rls = discard_parentheses;
   30.52 -val SOME (t, []) = rewrite_set_ thy true rls t;
   30.53 +val SOME (t, []) = rewrite_set_ ctxt true rls t;
   30.54  if UnparseC.term t = "1 / EI * (L * q_0 * x / 2 + - 1 * q_0 * x \<up> 2 / 2)" then ()
   30.55  else error "integrate.sml simplify by ruleset discard_parenth.. #3";
   30.56  
   30.57 @@ -215,14 +216,14 @@
   30.58  @{thm separate_1_bdv_n}; (*::real ..because of  \<up> *)
   30.59  (*show_types := false; --- do we need type-constraint in thms? YES ?!?!?!*)
   30.60  
   30.61 -val SOME (t, []) = rewrite_set_inst_ thy true subs rls t;
   30.62 +val SOME (t, []) = rewrite_set_inst_ ctxt true subs rls t;
   30.63  if UnparseC.term t = "1 / EI * (L * q_0 / 2 * x + - 1 * q_0 / 2 * x \<up> 2)" then ()
   30.64  else error "integrate.sml simplify by ruleset separate_bdv.. #4";
   30.65  
   30.66  "===== test 5";
   30.67  val t = TermC.str2term "1/EI * (L * q_0 * x / 2 + - 1 * q_0 * x \<up> 2 / 2)";
   30.68  val rls = simplify_Integral;
   30.69 -val SOME (t,[]) = rewrite_set_inst_ thy true subs rls t;
   30.70 +val SOME (t,[]) = rewrite_set_inst_ ctxt true subs rls t;
   30.71  (* given was:   "1 / EI * (L * q_0 * x / 2 + - 1 * q_0 * x \<up> 2 / 2)" *)
   30.72  if UnparseC.term t = "1 / EI * (L * q_0 / 2 * x + - 1 * q_0 / 2 * x \<up> 2)" then ()
   30.73  else error "integrate.sml, simplify_Integral #99";
   30.74 @@ -237,12 +238,12 @@
   30.75    "Integral 1 / EI * (L * q_0 / 2 * (x \<up> 2 / 2) + - 1 * q_0 / 2 * (x \<up> 3 / 3)) D x";
   30.76  
   30.77  val rls = simplify_Integral;
   30.78 -val SOME (t,[]) = rewrite_set_inst_ thy true subs rls t;
   30.79 +val SOME (t,[]) = rewrite_set_inst_ ctxt true subs rls t;
   30.80  if UnparseC.term t = "Integral 1 / EI * (L * q_0 / 4 * x \<up> 2 + - 1 * q_0 / 6 * x \<up> 3) D x"
   30.81  then () else raise error "integrate.sml, simplify_Integral #198";
   30.82  
   30.83  val rls = integration_rules;
   30.84 -val SOME (t, []) = rewrite_set_ thy true rls t;
   30.85 +val SOME (t, []) = rewrite_set_ ctxt true rls t;
   30.86  if UnparseC.term t = "1 / EI * (L * q_0 / 4 * (x \<up> 3 / 3) + - 1 * q_0 / 6 * (x \<up> 4 / 4))"
   30.87  then () else error "integrate.sml, simplify_Integral #199";
   30.88  
   30.89 @@ -256,66 +257,65 @@
   30.90  (*~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
   30.91  
   30.92  val t = TermC.parseNEW' ctxt "Integral x D x";
   30.93 -val SOME (res, _) = rewrite_set_inst_ thy true subs rls t;
   30.94 +val SOME (res, _) = rewrite_set_inst_ ctxt true subs rls t;
   30.95  if UnparseC.term res = "x \<up> 2 / 2" then () else error "Integral x D x changed";
   30.96  
   30.97  val t = TermC.parseNEW' ctxt "Integral c * x \<up> 2 + c_2 D x";
   30.98 -val SOME (res, _) = rewrite_set_inst_ thy true subs rls t;
   30.99 +val SOME (res, _) = rewrite_set_inst_ ctxt true subs rls t;
  30.100  if UnparseC.term res = "c * (x \<up> 3 / 3) + c_2 * x" then () else error "Integral c * x \<up> 2 + c_2 D x";
  30.101  
  30.102  val rls = add_new_c;
  30.103  val t = TermC.parseNEW' ctxt "c * (x \<up> 3 / 3) + c_2 * x";
  30.104 -val SOME (res, _) = rewrite_set_inst_ thy true subs rls t;
  30.105 +val SOME (res, _) = rewrite_set_inst_ ctxt true subs rls t;
  30.106  if UnparseC.term res = "c * (x \<up> 3 / 3) + c_2 * x + c_3" then () 
  30.107  else error "integrate.sml: diff.behav. in add_new_c simpl.";
  30.108  
  30.109  val t = TermC.parseNEW' ctxt "F x = x \<up> 3 / 3 + x";
  30.110 -val SOME (res, _) = rewrite_set_inst_ thy true subs rls t;
  30.111 +val SOME (res, _) = rewrite_set_inst_ ctxt true subs rls t;
  30.112  if UnparseC.term res = "F x = x \<up> 3 / 3 + x + c"(*not "F x + c =..."*) then () 
  30.113  else error "integrate.sml: diff.behav. in add_new_c equation";
  30.114  
  30.115  val rls = simplify_Integral;
  30.116  (*~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
  30.117  val t = TermC.parseNEW' ctxt "ff x = c * x + - 1 * q_0 * (x \<up> 2 / 2) + c_2";
  30.118 -val SOME (res, _) = rewrite_set_inst_ thy true subs rls t;
  30.119 +val SOME (res, _) = rewrite_set_inst_ ctxt true subs rls t;
  30.120  if UnparseC.term res = "ff x = c_2 + c * x + - 1 * q_0 / 2 * x \<up> 2"
  30.121  then () else error "integrate.sml: diff.behav. in simplify_I #1";
  30.122  
  30.123  val rls = integration;
  30.124  (*~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
  30.125  val t = TermC.parseNEW' ctxt "Integral c * x \<up> 2 + c_2 D x";
  30.126 -val SOME (res, _) = rewrite_set_inst_ thy true subs rls t;
  30.127 +val SOME (res, _) = rewrite_set_inst_ ctxt true subs rls t;
  30.128  if UnparseC.term res = "c_3 + c_2 * x + c / 3 * x \<up> 3"
  30.129  then () else error "integrate.sml: diff.behav. in integration #1";
  30.130  
  30.131  val t = TermC.parseNEW' ctxt "Integral 3*x \<up> 2 + 2*x + 1 D x";
  30.132 -val SOME (res, _) = rewrite_set_inst_ thy true subs rls t;
  30.133 +val SOME (res, _) = rewrite_set_inst_ ctxt true subs rls t;
  30.134  if UnparseC.term res = "c + x + x \<up> 2 + x \<up> 3" then () 
  30.135  else error "integrate.sml: diff.behav. in integration #2";
  30.136  
  30.137  val t = TermC.parseNEW' ctxt
  30.138    "Integral 1 / EI * (L * q_0 / 2 * x + - 1 * q_0 / 2 * x \<up> 2) D x";
  30.139 -val SOME (res, _) = rewrite_set_inst_ thy true subs rls t;
  30.140 +val SOME (res, _) = rewrite_set_inst_ ctxt true subs rls t;
  30.141  "Integral 1 / EI * (L * q_0 / 2 * x + - 1 * q_0 / 2 * x \<up> 2) D x";
  30.142  if UnparseC.term res = "c + 1 / EI * (L * q_0 / 4 * x \<up> 2 + - 1 * q_0 / 6 * x \<up> 3)"
  30.143  then () else error "integrate.sml: diff.behav. in integration #3";
  30.144  
  30.145  val t = TermC.parseNEW' ctxt ("Integral " ^ UnparseC.term res ^ " D x");
  30.146 -val SOME (res, _) = rewrite_set_inst_ thy true subs rls t;
  30.147 +val SOME (res, _) = rewrite_set_inst_ ctxt true subs rls t;
  30.148  if UnparseC.term res = "c_2 + c * x +\n1 / EI * (L * q_0 / 12 * x \<up> 3 + - 1 * q_0 / 24 * x \<up> 4)"
  30.149  then () else error "integrate.sml: diff.behav. in integration #4";
  30.150  
  30.151  "----------- rewrite 3rd integration in 7.27 ------------";
  30.152  "----------- rewrite 3rd integration in 7.27 ------------";
  30.153  "----------- rewrite 3rd integration in 7.27 ------------";
  30.154 -val thy = @{theory "Isac_Knowledge"} (*because of Undeclared constant "Biegelinie.EI*);
  30.155  val t = TermC.str2term "Integral 1 / EI * ((L * q_0 * x + - 1 * q_0 * x \<up> 2) / 2) D x";
  30.156 -val SOME(t, _)= rewrite_set_inst_ thy true subs simplify_Integral t;
  30.157 +val SOME(t, _)= rewrite_set_inst_ ctxt true subs simplify_Integral t;
  30.158  if UnparseC.term t = 
  30.159    "Integral 1 / EI * (L * q_0 / 2 * x + - 1 * q_0 / 2 * x \<up> 2) D x"
  30.160  then () else error "integrate.sml 3rd integration in 7.27, simplify_Integral";
  30.161  
  30.162 -val SOME(t, _) = rewrite_set_inst_ thy true subs integration t;
  30.163 +val SOME(t, _) = rewrite_set_inst_ ctxt true subs integration t;
  30.164  if UnparseC.term t = 
  30.165    "c + 1 / EI * (L * q_0 / 4 * x \<up> 2 + - 1 * q_0 / 6 * x \<up> 3)"
  30.166  then () else error "integrate.sml 3rd integration in 7.27, integration";
    31.1 --- a/test/Tools/isac/Knowledge/poly-1.sml	Thu Jul 28 11:43:27 2022 +0200
    31.2 +++ b/test/Tools/isac/Knowledge/poly-1.sml	Sat Jul 30 16:47:45 2022 +0200
    31.3 @@ -263,9 +263,9 @@
    31.4  "-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
    31.5  "-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
    31.6  "-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
    31.7 +val ctxt = Proof_Context.init_global @{theory}
    31.8  val t = TermC.str2term "x \<up> 2 * y \<up> 2 + x * x \<up> 2 * y";
    31.9 -Rewrite.trace_on := false; (*true false*)
   31.10 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
   31.11 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   31.12     UnparseC.term t = "x \<up> 2 * y \<up> 2 + x \<up> 3 * y";
   31.13  if UnparseC.term t = "x \<up> 3 * y + x \<up> 2 * y \<up> 2" then ()
   31.14  else error "poly.sml: diff.behav. in make_polynomial 23";
   31.15 @@ -413,32 +413,32 @@
   31.16  "-------- check make_polynomial with simple terms ----------------------------------------------";
   31.17  "----- check 1 ---";
   31.18  val t = TermC.str2term "2*3*a";
   31.19 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
   31.20 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   31.21  if UnparseC.term t = "6 * a" then () else error "check make_polynomial 1";
   31.22  
   31.23  "----- check 2 ---";
   31.24  val t = TermC.str2term "2*a + 3*a";
   31.25 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
   31.26 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   31.27  if UnparseC.term t = "5 * a" then () else error "check make_polynomial 2";
   31.28  
   31.29  "----- check 3 ---";
   31.30  val t = TermC.str2term "2*a + 3*a + 3*a";
   31.31 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
   31.32 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   31.33  if UnparseC.term t = "8 * a" then () else error "check make_polynomial 3";
   31.34  
   31.35  "----- check 4 ---";
   31.36  val t = TermC.str2term "3*a - 2*a";
   31.37 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
   31.38 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   31.39  if UnparseC.term t = "a" then () else error "check make_polynomial 4";
   31.40  
   31.41  "----- check 5 ---";
   31.42  val t = TermC.str2term "4*(3*a - 2*a)";
   31.43 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
   31.44 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   31.45  if UnparseC.term t = "4 * a" then () else error "check make_polynomial 5";
   31.46  
   31.47  "----- check 6 ---";
   31.48  val t = TermC.str2term "4*(3*a \<up> 2 - 2*a \<up> 2)";
   31.49 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
   31.50 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   31.51  if UnparseC.term t = "4 * a \<up> 2" then () else error "check make_polynomial 6";
   31.52  
   31.53  "-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
   31.54 @@ -447,7 +447,7 @@
   31.55  val thy = @{theory "Isac_Knowledge"};
   31.56  "===== works for a simple example, see rewrite.sml -- fun app_rev ===";
   31.57  val t = TermC.str2term "x \<up> 2 * x";
   31.58 -val SOME (t', _) = rewrite_set_ thy true order_mult_ t;
   31.59 +val SOME (t', _) = rewrite_set_ ctxt true order_mult_ t;
   31.60  if UnparseC.term t' = "x * x \<up> 2" then ()
   31.61  else error "poly.sml Poly.is_multUnordered doesn't work";
   31.62  
   31.63 @@ -478,7 +478,7 @@
   31.64    | _ => error "poly.sml diff. eval_is_multUnordered";
   31.65  
   31.66  "----- rewrite_set_ STILL DIDN'T WORK";
   31.67 -val SOME (t, _) = rewrite_set_ thy true order_mult_ t;
   31.68 +val SOME (t, _) = rewrite_set_ ctxt true order_mult_ t;
   31.69  UnparseC.term t;
   31.70  
   31.71  
   31.72 @@ -637,7 +637,7 @@
   31.73  "-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
   31.74  "-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
   31.75  val t = TermC.str2term "b * a * a";
   31.76 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
   31.77 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   31.78  if UnparseC.term t = "a \<up> 2 * b" then ()
   31.79  else error "poly.sml: diff.behav. in make_polynomial 21";
   31.80  
   31.81 @@ -660,7 +660,7 @@
   31.82  "-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
   31.83  "-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
   31.84  val t = TermC.str2term "2*3*a";
   31.85 -val SOME (t', _) = rewrite_set_ thy false make_polynomial t;
   31.86 +val SOME (t', _) = rewrite_set_ ctxt false make_polynomial t;
   31.87  (*+*)if UnparseC.term t' = "6 * a" then () else error "rewrite_set_ 2*3*a CHANGED";
   31.88  (*
   31.89  ##  try calc: "Groups.times_class.times" 
   31.90 @@ -701,7 +701,7 @@
   31.91  val thy = @{theory AlgEin};
   31.92  val ctxt = Proof_Context.init_global thy;
   31.93  
   31.94 -val SOME (f',_) = rewrite_set_ thy false norm_Poly
   31.95 +val SOME (f',_) = rewrite_set_ ctxt false norm_Poly
   31.96  (TermC.str2term "L = k - 2 * q + (k - 2 * q) + (k - 2 * q) + (k - 2 * q) + senkrecht + oben");
   31.97  if UnparseC.term f' = "L = 2 * 2 * k + 2 * - 4 * q + senkrecht + oben"
   31.98  then ((*norm_Poly NOT COMPLETE -- TODO MG*))
   31.99 @@ -730,37 +730,37 @@
  31.100  "-------- complex examples from textbook Schalk I ----------------------------------------------";
  31.101  "-------- complex examples from textbook Schalk I ----------------------------------------------";
  31.102  val t = TermC.str2term "1 + 2 * x \<up> 4 + 2 * - 2 * x \<up> 4 + x \<up> 8";
  31.103 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
  31.104 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.105  if (UnparseC.term t) = "1 + - 2 * x \<up> 4 + x \<up> 8"
  31.106  then () else error "poly.sml: diff.behav. in make_polynomial 9b";
  31.107  
  31.108  "-----SPB Schalk I p.64 No.296a ---";
  31.109  val t = TermC.str2term "(x - a) \<up> 3";
  31.110 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
  31.111 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.112  if (UnparseC.term t) = "- 1 * a \<up> 3 + 3 * a \<up> 2 * x + - 3 * a * x \<up> 2 + x \<up> 3"
  31.113  then () else error "poly.sml: diff.behav. in make_polynomial 10";
  31.114  
  31.115  "-----SPB Schalk I p.64 No.296c ---";
  31.116  val t = TermC.str2term "(-3*x - 4*y) \<up> 3";
  31.117 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
  31.118 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.119  if (UnparseC.term t) = "- 27 * x \<up> 3 + - 108 * x \<up> 2 * y + - 144 * x * y \<up> 2 +\n- 64 * y \<up> 3"
  31.120  then () else error "poly.sml: diff.behav. in make_polynomial 11";
  31.121  
  31.122  "-----SPB Schalk I p.62 No.242c ---";
  31.123  val t = TermC.str2term "x \<up> (- 4)*(x \<up> (- 4)*y \<up> (- 2)) \<up> (- 1)*y \<up> (- 2)";
  31.124 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
  31.125 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.126  if (UnparseC.term t) = "1"
  31.127  then () else error "poly.sml: diff.behav. in make_polynomial 12";
  31.128  
  31.129  "-----SPB Schalk I p.60 No.209a ---";
  31.130  val t = TermC.str2term "a \<up> (7-x) * a \<up> x";
  31.131 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
  31.132 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.133  if UnparseC.term t = "a \<up> 7"
  31.134  then () else error "poly.sml: diff.behav. in make_polynomial 13";
  31.135  
  31.136  "-----SPB Schalk I p.60 No.209d ---";
  31.137  val t = TermC.str2term "d \<up> x * d \<up> (x+1) * d \<up> (2 - 2*x)";
  31.138 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
  31.139 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.140  if UnparseC.term t = "d \<up> 3"
  31.141  then () else error "poly.sml: diff.behav. in make_polynomial 14";
  31.142  
  31.143 @@ -770,28 +770,28 @@
  31.144  "-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
  31.145  "-----SPO ---";
  31.146  val t = TermC.str2term "a \<up> 2*a \<up> (- 2)";
  31.147 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
  31.148 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.149  if UnparseC.term t = "1" then ()
  31.150  else error "poly.sml: diff.behav. in make_polynomial 15";
  31.151  
  31.152  "-----SPO ---";
  31.153  val t = TermC.str2term "a \<up> 2*b*b \<up> (- 1)";
  31.154 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
  31.155 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.156  if UnparseC.term t = "a \<up> 2" then ()
  31.157  else error "poly.sml: diff.behav. in make_polynomial 18";
  31.158  "-----SPO ---";
  31.159  val t = TermC.str2term "a \<up> 2*a \<up> (- 2)";
  31.160 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
  31.161 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.162  if (UnparseC.term t) = "1" then ()
  31.163  else error "poly.sml: diff.behav. in make_polynomial 19";
  31.164  "-----SPO ---";
  31.165  val t = TermC.str2term "b + a - b";
  31.166 -val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
  31.167 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.168  if (UnparseC.term t) = "a" then ()
  31.169  else error "poly.sml: diff.behav. in make_polynomial 20";
  31.170  
  31.171  "-----SPO ---";
  31.172  val t = TermC.parseNEW' ctxt "a \<up> 2 * (-a) \<up> 2";
  31.173 -val SOME (t,_) = rewrite_set_ @{theory} false make_polynomial t; UnparseC.term t;
  31.174 +val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
  31.175  if (UnparseC.term t) = "a \<up> 4" then ()
  31.176  else error "poly.sml: diff.behav. in make_polynomial 24";
    32.1 --- a/test/Tools/isac/Knowledge/polyeq-1.sml	Thu Jul 28 11:43:27 2022 +0200
    32.2 +++ b/test/Tools/isac/Knowledge/polyeq-1.sml	Sat Jul 30 16:47:45 2022 +0200
    32.3 @@ -52,57 +52,56 @@
    32.4  "----------- tests on predicates in problems ---------------------";
    32.5  val thy = @{theory};
    32.6  val ctxt = Proof_Context.init_global thy;
    32.7 -Rewrite.trace_on:=false;  (*true false*)
    32.8  
    32.9   val t1 = TermC.parseNEW' ctxt "lhs (-8 - 2*x + x \<up> 2 = 0)";
   32.10 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t1;
   32.11 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_prls t1;
   32.12   if ((UnparseC.term t) = "- 8 - 2 * x + x \<up> 2") then ()
   32.13   else  error "polyeq.sml: diff.behav. in lhs";
   32.14  
   32.15   val t2 = TermC.parseNEW' ctxt "(-8 - 2*x + x \<up> 2) is_expanded_in x";
   32.16 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t2;
   32.17 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_prls t2;
   32.18   if (UnparseC.term t) = "True" then ()
   32.19   else  error "polyeq.sml: diff.behav. 1 in is_expended_in";
   32.20  
   32.21   val t0 = TermC.parseNEW' ctxt "(sqrt(x)) is_poly_in x";
   32.22 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t0;
   32.23 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_prls t0;
   32.24   if (UnparseC.term t) = "False" then ()
   32.25   else  error "polyeq.sml: diff.behav. 2 in is_poly_in";
   32.26  
   32.27   val t3 = TermC.parseNEW' ctxt "(-8 + (- 1)*2*x + x \<up> 2) is_poly_in x";
   32.28 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t3;
   32.29 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_prls t3;
   32.30   if (UnparseC.term t) = "True" then ()
   32.31   else  error "polyeq.sml: diff.behav. 3 in is_poly_in";
   32.32  
   32.33   val t4 = TermC.parseNEW' ctxt "(lhs (-8 + (- 1)*2*x + x \<up> 2 = 0)) is_expanded_in x";
   32.34 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t4;
   32.35 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_prls t4;
   32.36   if (UnparseC.term t) = "True" then ()
   32.37   else  error "polyeq.sml: diff.behav. 4 in is_expended_in";
   32.38  
   32.39   val t6 = TermC.parseNEW' ctxt "(lhs (-8 - 2*x + x \<up> 2 = 0)) is_expanded_in x";
   32.40 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t6;
   32.41 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_prls t6;
   32.42   if (UnparseC.term t) = "True" then ()
   32.43   else  error "polyeq.sml: diff.behav. 5 in is_expended_in";
   32.44   
   32.45   val t3 = TermC.parseNEW' ctxt"((-8 - 2*x + x \<up> 2) has_degree_in x) = 2";
   32.46 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t3;
   32.47 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_prls t3;
   32.48   if (UnparseC.term t) = "True" then ()
   32.49   else  error "polyeq.sml: diff.behav. in has_degree_in_in";
   32.50  
   32.51   val t3 = TermC.parseNEW' ctxt "((sqrt(x)) has_degree_in x) = 2";
   32.52 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t3;
   32.53 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_prls t3;
   32.54   if (UnparseC.term t) = "False" then ()
   32.55   else  error "polyeq.sml: diff.behav. 6 in has_degree_in_in";
   32.56  
   32.57   val t4 = TermC.parseNEW' ctxt 
   32.58  	      "((-8 - 2*x + x \<up> 2) has_degree_in x) = 1";
   32.59 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t4;
   32.60 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_prls t4;
   32.61   if (UnparseC.term t) = "False" then ()
   32.62   else  error "polyeq.sml: diff.behav. 7 in has_degree_in_in";
   32.63  
   32.64  val t5 = TermC.parseNEW' ctxt 
   32.65  	      "((-8 - 2*x + x \<up> 2) has_degree_in x) = 2";
   32.66 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t5;
   32.67 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_prls t5;
   32.68   if (UnparseC.term t) = "True" then ()
   32.69   else  error "polyeq.sml: diff.behav. 8 in has_degree_in_in";
   32.70  
   32.71 @@ -375,29 +374,29 @@
   32.72    val x  = TermC.parseNEW' ctxt "x ::real";
   32.73    val a  = TermC.parseNEW' ctxt "a ::real";
   32.74    val b  = TermC.parseNEW' ctxt "b ::real";
   32.75 -val SOME (t',_) = rewrite_set_inst_ thy false [(bdv,a)] make_polynomial_in x2;
   32.76 +val SOME (t',_) = rewrite_set_inst_ ctxt false [(bdv,a)] make_polynomial_in x2;
   32.77  if UnparseC.term t' = "b + x + a" then ()
   32.78  else error "termorder.sml diff.behav ord_make_polynomial_in #11";
   32.79  
   32.80 -val NONE = rewrite_set_inst_ thy false [(bdv,b)] make_polynomial_in x2;
   32.81 +val NONE = rewrite_set_inst_ ctxt false [(bdv,b)] make_polynomial_in x2;
   32.82  
   32.83 -val SOME (t',_) = rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in x2;
   32.84 +val SOME (t',_) = rewrite_set_inst_ ctxt false [(bdv,x)] make_polynomial_in x2;
   32.85  if UnparseC.term t' = "a + b + x" then ()
   32.86  else error "termorder.sml diff.behav ord_make_polynomial_in #13";
   32.87  
   32.88    val ppp' = "-6 + -5*x + x \<up> 3 + - 1*x \<up> 2 + - 1*x \<up> 3 + - 14*x \<up> 2";
   32.89    val ppp  = TermC.parseNEW' ctxt ppp';
   32.90 -val SOME (t', _) = rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in ppp;
   32.91 +val SOME (t', _) = rewrite_set_inst_ ctxt false [(bdv,x)] make_polynomial_in ppp;
   32.92  if UnparseC.term t' = "- 6 + - 5 * x + - 15 * x \<up> 2" then ()
   32.93  else error "termorder.sml diff.behav ord_make_polynomial_in #15";
   32.94  
   32.95    val ttt' = "(3*x + 5)/18 ::real";
   32.96    val ttt = TermC.parseNEW' ctxt ttt';
   32.97 -val SOME (uuu,_) = rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in ttt;
   32.98 +val SOME (uuu,_) = rewrite_set_inst_ ctxt false [(bdv,x)] make_polynomial_in ttt;
   32.99  if UnparseC.term uuu = "(5 + 3 * x) / 18" then ()
  32.100  else error "termorder.sml diff.behav ord_make_polynomial_in #16a";
  32.101  
  32.102 -val SOME (uuu,_) = rewrite_set_ thy false make_polynomial ttt;
  32.103 +val SOME (uuu,_) = rewrite_set_ ctxt false make_polynomial ttt;
  32.104  if UnparseC.term uuu = "(5 + 3 * x) / 18" then ()
  32.105  else error "termorder.sml diff.behav ord_make_polynomial_in #16b";
  32.106  
  32.107 @@ -1014,42 +1013,42 @@
  32.108  val t = (the o (parseNEW  ctxt)) "-8 - 2*x + x \<up> 2 = (0::real)";
  32.109  
  32.110  val rls = complete_square;
  32.111 -val SOME (t,asm) = rewrite_set_inst_ thy true inst rls t;
  32.112 +val SOME (t,asm) = rewrite_set_inst_ ctxt true inst rls t;
  32.113  if UnparseC.term t = "- 8 + (2 / 2 - x) \<up> 2 = (2 / 2) \<up> 2"
  32.114  then () else error "rls complete_square CHANGED";
  32.115  
  32.116  val thm = @{thm square_explicit1};
  32.117 -val SOME (t,asm) = rewrite_ thy dummy_ord Rule_Set.Empty true thm t;
  32.118 +val SOME (t,asm) = rewrite_ ctxt dummy_ord Rule_Set.Empty true thm t;
  32.119  if UnparseC.term t = "(2 / 2 - x) \<up> 2 = (2 / 2) \<up> 2 - - 8"
  32.120  then () else error "thm square_explicit1 CHANGED";
  32.121  
  32.122  val thm = @{thm root_plus_minus};
  32.123 -val SOME (t,asm) = rewrite_ thy dummy_ord PolyEq_erls true thm t;
  32.124 +val SOME (t,asm) = rewrite_ ctxt dummy_ord PolyEq_erls true thm t;
  32.125  if UnparseC.term t =
  32.126  "2 / 2 - x = sqrt ((2 / 2) \<up> 2 - - 8) \<or>\n2 / 2 - x = - 1 * sqrt ((2 / 2) \<up> 2 - - 8)"
  32.127  then () else error "thm root_plus_minus CHANGED";
  32.128  
  32.129  (*the thm bdv_explicit2* here required to be constrained to ::real*)
  32.130  val thm = @{thm bdv_explicit2};
  32.131 -val SOME (t,asm) = rewrite_inst_ thy dummy_ord Rule_Set.Empty true inst thm t;
  32.132 +val SOME (t,asm) = rewrite_inst_ ctxt dummy_ord Rule_Set.Empty true inst thm t;
  32.133  if UnparseC.term t =
  32.134  "2 / 2 - x = sqrt ((2 / 2) \<up> 2 - - 8) \<or>\n- 1 * x = - (2 / 2) + - 1 * sqrt ((2 / 2) \<up> 2 - - 8)"
  32.135  then () else error "thm bdv_explicit2 CHANGED";
  32.136  
  32.137  val thm = @{thm bdv_explicit3};
  32.138 -val SOME (t,asm) = rewrite_inst_ thy dummy_ord Rule_Set.Empty true inst thm t;
  32.139 +val SOME (t,asm) = rewrite_inst_ ctxt dummy_ord Rule_Set.Empty true inst thm t;
  32.140  if UnparseC.term t =
  32.141  "2 / 2 - x = sqrt ((2 / 2) \<up> 2 - - 8) \<or>\nx = - 1 * (- (2 / 2) + - 1 * sqrt ((2 / 2) \<up> 2 - - 8))"
  32.142  then () else error "thm bdv_explicit3 CHANGED";
  32.143  
  32.144  val thm = @{thm bdv_explicit2};
  32.145 -val SOME (t,asm) = rewrite_inst_ thy dummy_ord Rule_Set.Empty true inst thm t;
  32.146 +val SOME (t,asm) = rewrite_inst_ ctxt dummy_ord Rule_Set.Empty true inst thm t;
  32.147  if UnparseC.term t =
  32.148  "- 1 * x = - (2 / 2) + sqrt ((2 / 2) \<up> 2 - - 8) \<or>\nx = - 1 * (- (2 / 2) + - 1 * sqrt ((2 / 2) \<up> 2 - - 8))"
  32.149  then () else error "thm bdv_explicit2 CHANGED";
  32.150  
  32.151  val rls = calculate_RootRat;
  32.152 -val SOME (t,asm) = rewrite_set_ thy true rls t;
  32.153 +val SOME (t,asm) = rewrite_set_ ctxt true rls t;
  32.154  if UnparseC.term t =
  32.155    "- 1 * x = - 1 + sqrt (2 \<up> 2 / 2 \<up> 2 - - 8) \<or>\nx = - 1 * - 1 + - 1 * (- 1 * sqrt (2 \<up> 2 / 2 \<up> 2 - - 8))"
  32.156  (*"- 1 * x = - 1 + sqrt (2 \<up> 2 / 2 \<up> 2 - -8) |\nx = - 1 * - 1 + - 1 * (- 1 * sqrt (2 \<up> 2 / 2 \<up> 2 - -8))"..isabisac15*)
  32.157 @@ -1062,7 +1061,7 @@
  32.158  "-------------------- (3 - 10*x + 3*x \<up> 2 = 0), ----------------------";
  32.159  "---- test the erls ----";
  32.160   val t1 = TermC.parseNEW' ctxt "0 <= (10/3/2) \<up> 2 - 1";
  32.161 - val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_erls t1;
  32.162 + val SOME (t,_) = rewrite_set_ ctxt false PolyEq_erls t1;
  32.163   val t' = UnparseC.term t;
  32.164   (*if t'= \<^const_name>\<open>True\<close> then ()
  32.165   else error "polyeq.sml: diff.behav. in 'rewrite_set_.. PolyEq_erls";*)
    33.1 --- a/test/Tools/isac/Knowledge/polyeq-2.sml	Thu Jul 28 11:43:27 2022 +0200
    33.2 +++ b/test/Tools/isac/Knowledge/polyeq-2.sml	Sat Jul 30 16:47:45 2022 +0200
    33.3 @@ -215,11 +215,12 @@
    33.4  "----------- rls make_polynomial_in ------------------------------";
    33.5  "----------- rls make_polynomial_in ------------------------------";
    33.6  val thy = @{theory};
    33.7 +val ctxt = @{context};
    33.8  (*Punkte aus dem TestBericht, die ich in rlang.sml nicht zuordnen konnte:*)
    33.9  (*WN.19.3.03 ---v-*)
   33.10  (*3(b)*)val (bdv,v) = (TermC.str2term "''bdv''", TermC.str2term "R1");
   33.11  val t = TermC.str2term "- 1 * (R * R2) + R2 * R1 + - 1 * (R * R1) = 0";
   33.12 -val SOME (t',_) = rewrite_set_inst_ thy false [(bdv,v)] make_polynomial_in t;
   33.13 +val SOME (t',_) = rewrite_set_inst_ ctxt false [(bdv,v)] make_polynomial_in t;
   33.14  if UnparseC.term t' = "- 1 * R * R2 + R2 * R1 + - 1 * R * R1 = 0" then ()
   33.15  else error "make_polynomial_in (- 1 * (R * R2) + R2 * R1 + - 1 * (R * R1) = 0)";
   33.16  "- 1 * R * R2 + (R2 + - 1 * R) * R1 = 0";
   33.17 @@ -227,21 +228,21 @@
   33.18  
   33.19  (*3(c)*)val (bdv,v) = (TermC.str2term "bdv", TermC.str2term "p");
   33.20  val t = TermC.str2term "y \<up> 2 + - 2 * (x * p) = 0";
   33.21 -val SOME (t',_) = rewrite_set_inst_ thy false [(bdv,v)] make_polynomial_in t;
   33.22 +val SOME (t',_) = rewrite_set_inst_ ctxt false [(bdv,v)] make_polynomial_in t;
   33.23  if UnparseC.term t' = "y \<up> 2 + - 2 * x * p = 0" then ()
   33.24  else error "make_polynomial_in (y \<up> 2 + - 2 * (x * p) = 0)";
   33.25  
   33.26  (*3(d)*)val (bdv,v) = (TermC.str2term "''bdv''", TermC.str2term "x2");
   33.27  val t = TermC.str2term 
   33.28  "A + x1 * (y3 * (1 / 2)) + x3 * (y2 * (1 / 2)) + - 1 * (x1 * (y2 * (1 / 2))) + - 1 * (x3 * (y1 * (1 / 2 ))) + y1 * (1 / 2 * x2) + - 1 * (y3 * (1 / 2 * x2)) = 0";
   33.29 -val SOME (t',_) = rewrite_set_inst_ thy false [(bdv,v)] make_polynomial_in t;
   33.30 +val SOME (t',_) = rewrite_set_inst_ ctxt false [(bdv,v)] make_polynomial_in t;
   33.31  if UnparseC.term t' =
   33.32  "A + x1 * y3 * (1 / 2) + x3 * y2 * (1 / 2) + - 1 * x1 * y2 * (1 / 2) +\n- 1 * x3 * y1 * (1 / 2) +\ny1 * (1 / 2) * x2 +\n- 1 * y3 * (1 / 2) * x2 =\n0"
   33.33  then ()
   33.34  else error "make_polynomial_in (A + x1 * (y3 * (1 / 2)) + x3 * (y2 * (1 / 2)) + - 1...";
   33.35  "A + x1 * y3 * (1 / 2) + x3 * y2 * (1 / 2) + - x1 * y2 * (1 / 2) + - x3 * y1 * (1 / 2) + (y1 * (1 / 2) + - y3 * (1 / 2)) * x2 = 0";
   33.36  
   33.37 -val SOME (t',_) = rewrite_set_inst_ thy false [(bdv,v)] make_ratpoly_in t;
   33.38 +val SOME (t',_) = rewrite_set_inst_ ctxt false [(bdv,v)] make_ratpoly_in t;
   33.39  if UnparseC.term t' = 
   33.40  "A / 1 + x1 * y3 / 2 + x3 * y2 / 2 + - 1 * x1 * y2 / 2 + - 1 * x3 * y1 / 2 +\ny1 * x2 / 2 +\n- 1 * y3 * x2 / 2 =\n0"
   33.41  then ()
   33.42 @@ -251,13 +252,11 @@
   33.43  (*3(e)*)val (bdv,v) = (TermC.str2term "bdv", TermC.str2term "a");
   33.44  val t = TermC.str2term 
   33.45  "A \<up> 2 + c \<up> 2 * (c / d) \<up> 2 + (-4 * (c / d) \<up> 2) * a \<up> 2 = 0";
   33.46 -val NONE = rewrite_set_inst_ thy false [(bdv,v)] make_polynomial_in t;
   33.47 +val NONE = rewrite_set_inst_ ctxt false [(bdv,v)] make_polynomial_in t;
   33.48  (* the invisible parentheses are as expected *)
   33.49  
   33.50  val t = TermC.str2term "(x + 1) * (x + 2) - (3 * x - 2) \<up> 2 - ((2 * x - 1) \<up> 2 + (3 * x - 1) * (x + 1)) = 0";
   33.51 -Rewrite.trace_on:= false; (*true false*)
   33.52 -rewrite_set_ thy false expand_binoms t;
   33.53 -Rewrite.trace_on:=false; (*true false*)
   33.54 +rewrite_set_ ctxt false expand_binoms t;
   33.55  
   33.56  
   33.57  "----------- interSteps ([1],Res); on Schalk Is86Bsp5-------------";
   33.58 @@ -281,21 +280,21 @@
   33.59  "----------- rls d2_polyeq_bdv_only_simplify ---------------------";
   33.60  val t = TermC.str2term "-6 * x + 5 * x \<up> 2 = (0::real)";
   33.61  val subst = [(TermC.str2term "(bdv::real)", TermC.str2term "(x::real)")];
   33.62 -val SOME (t''''', _) = rewrite_set_inst_ thy true subst d2_polyeq_bdv_only_simplify t;
   33.63 +val SOME (t''''', _) = rewrite_set_inst_ ctxt true subst d2_polyeq_bdv_only_simplify t;
   33.64  (* steps in rls d2_polyeq_bdv_only_simplify:*)
   33.65  
   33.66  (*-6 * x + 5 * x ^ 2 = 0 : Rewrite_Inst (["(''bdv'',x)"],("d2_prescind1", "")) --> x * (-6 + 5 * x) = 0*)
   33.67  t |> UnparseC.term; t |> TermC.atomty;
   33.68  val thm = @{thm d2_prescind1};
   33.69  thm |> Thm.prop_of |> UnparseC.term; thm |> Thm.prop_of |> TermC.atomty;
   33.70 -val SOME (t', _) = rewrite_inst_ thy e_rew_ord Rule_Set.empty true subst thm t; UnparseC.term t';
   33.71 +val SOME (t', _) = rewrite_inst_ ctxt e_rew_ord Rule_Set.empty true subst thm t; UnparseC.term t';
   33.72  
   33.73  (*x * (-6 + 5 * x) = 0   : Rewrite_Inst (["(''bdv'',x)"],("d2_reduce_equation1", "")) 
   33.74                                                                          --> x = 0 | -6 + 5 * x = 0*)
   33.75  t' |> UnparseC.term; t' |> TermC.atomty;
   33.76  val thm = @{thm d2_reduce_equation1};
   33.77  thm |> Thm.prop_of |> UnparseC.term; thm |> Thm.prop_of |> TermC.atomty;
   33.78 -val SOME (t'', _) = rewrite_inst_ thy e_rew_ord Rule_Set.empty true subst thm t'; UnparseC.term t'';
   33.79 +val SOME (t'', _) = rewrite_inst_ ctxt e_rew_ord Rule_Set.empty true subst thm t'; UnparseC.term t'';
   33.80  (* NONE with d2_reduce_equation1:   "(bdv*(a +b*bdv)=0) = ((bdv=0)|(a+b*bdv=0))"
   33.81     instead   d2_reduce_equation1:   "(bdv*(a +b*bdv)=0) = ((bdv=0)|(a+b*bdv=(0::real)))"
   33.82  *)
    34.1 --- a/test/Tools/isac/Knowledge/polyminus.sml	Thu Jul 28 11:43:27 2022 +0200
    34.2 +++ b/test/Tools/isac/Knowledge/polyminus.sml	Sat Jul 30 16:47:45 2022 +0200
    34.3 @@ -169,25 +169,23 @@
    34.4  "----------- watch order_add_mult  -------------------------------";
    34.5  "----------- watch order_add_mult  -------------------------------";
    34.6  "----- with these simple variables it works...";
    34.7 -(*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
    34.8 -Rewrite.trace_on:=false; (*true false*)
    34.9 +val ctxt = @{context};
   34.10  val t = TermC.str2term "((a + d) + c) + b";
   34.11 -val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
   34.12 +val SOME (t,_) = rewrite_set_ ctxt false order_add_mult t; UnparseC.term t;
   34.13  if UnparseC.term t = "a + (b + (c + d))" then ()
   34.14  else error "polyminus.sml 1 watch order_add_mult";
   34.15 -Rewrite.trace_on:=false; (*true false*)
   34.16  
   34.17  "----- the same stepwise...";
   34.18  val od = ord_make_polynomial true (@{theory "Poly"});
   34.19  val t = TermC.str2term "((a + d) + c) + b";
   34.20  "((a + d) + c) + b"; 
   34.21 -val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
   34.22 +val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
   34.23  "b + ((a + d) + c)";
   34.24 -val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
   34.25 +val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
   34.26  "b + (c + (a + d))";
   34.27 -val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
   34.28 +val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
   34.29  "b + (a + (c + d))";
   34.30 -val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
   34.31 +val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
   34.32  "a + (b + (c + d))";
   34.33  if UnparseC.term t = "a + (b + (c + d))" then ()
   34.34  else error "polyminus.sml 2 watch order_add_mult";
   34.35 @@ -195,25 +193,25 @@
   34.36  "----- if parentheses are right, left_commute is (almost) sufficient...";
   34.37  val t = TermC.str2term "a + (d + (c + b))";
   34.38  "a + (d + (c + b))";
   34.39 -val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
   34.40 +val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
   34.41  "a + (c + (d + b))";
   34.42 -val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t;UnparseC.term t;
   34.43 +val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t;UnparseC.term t;
   34.44  "a + (c + (b + d))";
   34.45 -val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
   34.46 +val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
   34.47  "a + (b + (c + d))";
   34.48  
   34.49  "----- but we do not want the parentheses at right; thus: cond.rew.";
   34.50  "WN0712707 complicated monomials do not yet work ...";
   34.51  val t = TermC.str2term "((5*a + 4*d) + 3*c) + 2*b";
   34.52 -val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
   34.53 +val SOME (t,_) = rewrite_set_ ctxt false order_add_mult t; UnparseC.term t;
   34.54  if UnparseC.term t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
   34.55  else error "polyminus.sml: order_add_mult changed";
   34.56  
   34.57  "----- here we see rew_sub going into subterm with ord.rew....";
   34.58  val od = ord_make_polynomial false (@{theory "Poly"});
   34.59  val t = TermC.str2term "b + a + c + d";
   34.60 -val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
   34.61 -val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
   34.62 +val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
   34.63 +val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
   34.64  (*@@@ rew_sub gosub: t = d + (b + a + c)
   34.65    @@@ rew_sub begin: t = b + a + c*)
   34.66  
   34.67 @@ -263,53 +261,53 @@
   34.68  
   34.69  val erls = erls_ordne_alphabetisch;
   34.70  val t = TermC.str2term "b + a";
   34.71 -val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
   34.72 +val SOME (t,_) = rewrite_ ctxt od erls false @{thm tausche_plus} t; UnparseC.term t;
   34.73  if UnparseC.term t = "a + b" then ()
   34.74  else error "polyminus.sml: ordne_alphabetisch1 b + a";
   34.75  
   34.76  val erls = Atools_erls;
   34.77  val t = TermC.str2term "2*a + 3*a";
   34.78 -val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; UnparseC.term t;
   34.79 +val SOME (t,_) = rewrite_ ctxt od erls false @{thm real_num_collect} t; UnparseC.term t;
   34.80  
   34.81  "======= test rewrite_, rewrite_set_";
   34.82  (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
   34.83  val erls = erls_ordne_alphabetisch;
   34.84  val t = TermC.str2term "b + a";
   34.85 -val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
   34.86 +val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t;
   34.87  if UnparseC.term t = "a + b" then ()
   34.88  else error "polyminus.sml: ordne_alphabetisch a + b";
   34.89  
   34.90  val t = TermC.str2term "2*b + a";
   34.91 -val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
   34.92 +val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t;
   34.93  if UnparseC.term t = "a + 2 * b" then ()
   34.94  else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
   34.95  
   34.96  val t = TermC.str2term "a + c + b";
   34.97 -val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
   34.98 +val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t;
   34.99  if UnparseC.term t = "a + b + c" then ()
  34.100  else error "polyminus.sml: ordne_alphabetisch a + b + c";
  34.101  
  34.102  "======= rewrite goes into subterms";
  34.103  val t = TermC.str2term "a + c + b + d ::real";
  34.104 -val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; UnparseC.term t;
  34.105 +val SOME (t,_) = rewrite_ ctxt od erls false @{thm tausche_plus_plus} t; UnparseC.term t;
  34.106  if UnparseC.term t = "a + b + c + d" then ()
  34.107  else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
  34.108  
  34.109  val t = TermC.str2term "a + c + d + b";
  34.110 -val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
  34.111 +val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t;
  34.112  if UnparseC.term t = "a + b + c + d" then ()
  34.113  else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
  34.114  
  34.115  "======= here we see rew_sub going into subterm with cond.rew....";
  34.116  val t = TermC.str2term "b + a + c + d";
  34.117 -val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
  34.118 +val SOME (t,_) = rewrite_ ctxt od erls false @{thm tausche_plus} t; UnparseC.term t;
  34.119  if UnparseC.term t = "a + b + c + d" then ()
  34.120  else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
  34.121  
  34.122  "======= compile rls for the most complicated terms";
  34.123  val t = TermC.str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
  34.124  "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
  34.125 -val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; 
  34.126 +val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; 
  34.127  if UnparseC.term t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
  34.128  then () else error "polyminus.sml: ordne_alphabetisch finished";
  34.129  
  34.130 @@ -319,7 +317,7 @@
  34.131  "----------- build fasse_zusammen --------------------------------";
  34.132  "----------- build fasse_zusammen --------------------------------";
  34.133  val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
  34.134 -val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
  34.135 +val SOME (t,_) = rewrite_set_ ctxt false fasse_zusammen t;
  34.136  if UnparseC.term t = "3 + - 2 * e + 2 * f + 2 * g" then ()
  34.137  else error "polyminus.sml: fasse_zusammen finished";
  34.138  
  34.139 @@ -327,12 +325,10 @@
  34.140  "----------- build verschoenere ----------------------------------";
  34.141  "----------- build verschoenere ----------------------------------";
  34.142  val t = TermC.str2term "3 + - 2 * e + 2 * f + 2 * g";
  34.143 -val SOME (t,_) = rewrite_set_ thy false verschoenere t;
  34.144 +val SOME (t,_) = rewrite_set_ ctxt false verschoenere t;
  34.145  if UnparseC.term t = "3 - 2 * e + 2 * f + 2 * g" then ()
  34.146  else error "polyminus.sml: verschoenere 3 + - 2 * e ...";
  34.147  
  34.148 -(*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
  34.149 -Rewrite.trace_on:=false; (*true false*)
  34.150  
  34.151  "----------- met simplification for_polynomials with_minus -------";
  34.152  "----------- met simplification for_polynomials with_minus -------";
  34.153 @@ -530,18 +526,17 @@
  34.154  val erls = erls_ordne_alphabetisch;
  34.155  val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
  34.156  val SOME (t',_) = 
  34.157 -    rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus} t;
  34.158 +    rewrite_ ctxt e_rew_ord erls false @{thm tausche_minus} t;
  34.159  UnparseC.term t';     "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
  34.160  
  34.161  val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
  34.162  val NONE = 
  34.163 -    rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
  34.164 +    rewrite_ ctxt e_rew_ord erls false @{thm tausche_minus_plus} t;
  34.165  
  34.166  val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
  34.167  val SOME (t',_) = 
  34.168 -    rewrite_set_ (@{theory "Isac_Knowledge"}) false ordne_alphabetisch t;
  34.169 +    rewrite_set_ ctxt false ordne_alphabetisch t;
  34.170  UnparseC.term t';     "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
  34.171 -Rewrite.trace_on := false; (*true false*)
  34.172  
  34.173  
  34.174  applyTactic 1 p (hd (specific_from_prog pt p)) (*tausche_minus*);
  34.175 @@ -604,31 +599,31 @@
  34.176  val thy = @{theory};
  34.177  val rls = klammern_ausmultiplizieren;
  34.178  val t = TermC.str2term "(3 * a + 2) * (4 * a - 1::real)";
  34.179 -val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
  34.180 +val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
  34.181  "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
  34.182  val rls = discard_parentheses;
  34.183 -val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
  34.184 +val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
  34.185  "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
  34.186  val rls = ordne_monome;
  34.187 -val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
  34.188 +val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
  34.189  "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
  34.190  (*
  34.191  val t = TermC.str2term "3 * a * 4 * a";
  34.192  val rls = ordne_monome;
  34.193 -val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
  34.194 +val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
  34.195  *)
  34.196  val rls = klammern_aufloesen;
  34.197 -val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
  34.198 +val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
  34.199  "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
  34.200  val rls = ordne_alphabetisch;
  34.201  (*TODO: make is_monom more general, a*a=a^2, ...*)
  34.202 -val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
  34.203 +val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
  34.204  "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
  34.205  (*STOPPED.WN080104
  34.206  val rls = fasse_zusammen;
  34.207 -val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
  34.208 +val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
  34.209  val rls = verschoenere;
  34.210 -val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
  34.211 +val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
  34.212  *)
  34.213  
  34.214  (*@@@@@@@*)
  34.215 @@ -690,8 +685,7 @@
  34.216  	      Thm ("not_false", @{thm not_false})
  34.217  	      (*"(~ False) = True"*)];
  34.218  (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
  34.219 -val SOME (t', _) = rewrite_set_ thy false prls t;
  34.220 -Rewrite.trace_on := false; (*true false*)
  34.221 +val SOME (t', _) = rewrite_set_ ctxt false prls t;
  34.222  
  34.223  "--- does the respective prls rewrite the whole predicate ?";
  34.224  val t = TermC.str2term 
  34.225 @@ -700,8 +694,7 @@
  34.226  	    \     matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
  34.227  	    \     matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
  34.228  (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
  34.229 -val SOME (t', _) = rewrite_set_ thy false prls t;
  34.230 -Rewrite.trace_on := false; (*true false*)
  34.231 +val SOME (t', _) = rewrite_set_ ctxt false prls t;
  34.232  if UnparseC.term t' = "False" then ()
  34.233  else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
  34.234  
    35.1 --- a/test/Tools/isac/Knowledge/rateq.sml	Thu Jul 28 11:43:27 2022 +0200
    35.2 +++ b/test/Tools/isac/Knowledge/rateq.sml	Sat Jul 30 16:47:45 2022 +0200
    35.3 @@ -21,22 +21,22 @@
    35.4  "------------ pbl: rational, univariate, equation ----------------";
    35.5  "------------ pbl: rational, univariate, equation ----------------";
    35.6  val t = TermC.parseNEW' ctxt "(1/b+1/x=1) is_ratequation_in  x";
    35.7 -val SOME (t_, _) = rewrite_set_ thy  false RatEq_prls t;
    35.8 +val SOME (t_, _) = rewrite_set_ ctxt  false RatEq_prls t;
    35.9  val result = UnparseC.term t_;
   35.10  if result <>  "True"  then error "rateq.sml: new behaviour 1:" else ();
   35.11  
   35.12  val t = TermC.parseNEW' ctxt "(sqrt(x)=1) is_ratequation_in  x";
   35.13 -val SOME (t_, _) = rewrite_set_ thy  false RatEq_prls t;
   35.14 +val SOME (t_, _) = rewrite_set_ ctxt  false RatEq_prls t;
   35.15  val result = UnparseC.term t_;
   35.16  if result <>  "False"  then error "rateq.sml: new behaviour 2:" else ();
   35.17  
   35.18  val t = TermC.parseNEW' ctxt "(x=- 1) is_ratequation_in x";
   35.19 -val SOME (t_,_) = rewrite_set_ thy  false RatEq_prls t;
   35.20 +val SOME (t_,_) = rewrite_set_ ctxt  false RatEq_prls t;
   35.21  val result = UnparseC.term t_;
   35.22  if result <>  "False"  then error "rateq.sml: new behaviour 3:" else ();
   35.23  
   35.24  val t = TermC.parseNEW' ctxt "(3 + x \<up> 2 + 1/(x \<up> 2+3)=1) is_ratequation_in x";
   35.25 -val SOME (t_,_) = rewrite_set_ thy  false RatEq_prls t;
   35.26 +val SOME (t_,_) = rewrite_set_ ctxt  false RatEq_prls t;
   35.27  val result = UnparseC.term t_;
   35.28  if result <>  "True"  then error "rateq.sml: new behaviour 4:" else ();
   35.29  
    36.1 --- a/test/Tools/isac/Knowledge/rational-1.sml	Thu Jul 28 11:43:27 2022 +0200
    36.2 +++ b/test/Tools/isac/Knowledge/rational-1.sml	Sat Jul 30 16:47:45 2022 +0200
    36.3 @@ -134,6 +134,7 @@
    36.4  "-------- fun cancel_p special cases -----------------------------------------------------------";
    36.5  "-------- fun cancel_p special cases -----------------------------------------------------------";
    36.6  val thy = @{theory Isac_Knowledge};
    36.7 +val ctxt = Proof_Context.init_global thy
    36.8  
    36.9  (*------- standard case: *)
   36.10  val t = TermC.str2term "2 / 3 + 1 / 6 ::real";
   36.11 @@ -175,7 +176,7 @@
   36.12  (*------- 0 / m + 0 / n
   36.13               20 years old bug found here: *)
   36.14  val t = TermC.str2term "0 = c_2 + c * 0 + 1 / EI * (L * q_0 / 12 * 0 \<up> 3 + - 1 * q_0 / 24 * 0 \<up> 4)";
   36.15 -val SOME (t', _) = rewrite_set_ thy true norm_Rational t;
   36.16 +val SOME (t', _) = rewrite_set_ ctxt true norm_Rational t;
   36.17  (*
   36.18  :
   36.19  ##  rls: cancel_p_rls on: 0 = c_2 + 1 / EI * (0 / 12 + 0 / 24) 
   36.20 @@ -246,7 +247,7 @@
   36.21  val ctxt = Proof_Context.init_global @{theory}
   36.22  val SOME t = TermC.parseNEW ctxt "2 * AA / 2"; (* Const (\<^const_name>\<open>AA\<close>, "real") *)
   36.23  
   36.24 -val SOME (t', _) = rewrite_set_ thy true cancel_p t;
   36.25 +val SOME (t', _) = rewrite_set_ ctxt true cancel_p t;
   36.26  case t' of
   36.27    Const (\<^const_name>\<open>divide\<close>, _) $ Const (\<^const_name>\<open>AA\<close>, _) $
   36.28      Const (\<^const_name>\<open>one_class.one\<close>, _) => ()
   36.29 @@ -268,16 +269,16 @@
   36.30  "-------- complex examples: rls norm_Rational --------------------------------------------------";
   36.31  "-------- complex examples: rls norm_Rational --------------------------------------------------";
   36.32  val t = TermC.str2term "(3*x+5)/18 - x/2  - -(3*x - 2)/9 = 0";
   36.33 -val SOME (t', _) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
   36.34 +val SOME (t', _) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
   36.35  if UnparseC.term t' = "1 / 18 = 0" then () else error "rational.sml 1";
   36.36  
   36.37  val t = TermC.str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0";
   36.38 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
   36.39 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
   36.40  if UnparseC.term t' = "(237 + 65 * x) / 36 = 0" then () 
   36.41  else error "rational.sml 2";
   36.42  
   36.43  val t = TermC.str2term "(1/2 + (5*x)/2) \<up> 2 - ((13*x)/2 - 5/2) \<up> 2 - (6*x) \<up> 2 + 29";
   36.44 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
   36.45 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
   36.46  if UnparseC.term t' = "23 + 35 * x + - 72 * x \<up> 2" then ()
   36.47  else error "rational.sml 3";
   36.48  
   36.49 @@ -286,20 +287,20 @@
   36.50  "-------- complex examples cancellation from: Mathematik 1 Schalk ------------------------------";
   36.51  (*Schalk I, p.60 Nr. 215c *)
   36.52  val t = TermC.str2term "(a + b) \<up> 4 * (x - y)  /  ((x - y) \<up> 3 * (a + b) \<up> 2)";
   36.53 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   36.54 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   36.55  if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + - 2 * x * y + y \<up> 2)"
   36.56  then () else error "rational.sml: diff.behav. in norm_Rational_mg 7";
   36.57  
   36.58  (*SRC Schalk I, p.66 Nr. 381b *)
   36.59  val t = TermC.str2term 
   36.60  "(4*x \<up> 2 - 20*x + 25)/(2*x - 5) \<up> 3";
   36.61 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   36.62 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   36.63  if UnparseC.term t = "1 / (- 5 + 2 * x)"
   36.64  then () else error "rational.sml: diff.behav. in norm_Rational_mg 9";
   36.65  
   36.66  (*Schalk I, p.60 Nr. 215c *)
   36.67  val t = TermC.str2term "(a + b) \<up> 4 * (x - y)  /  ((x - y) \<up> 3 * (a + b) \<up> 2)";
   36.68 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   36.69 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   36.70  if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + - 2 * x * y + y \<up> 2)"
   36.71  then () else error "Schalk I, p.60 Nr. 215c: with Isabelle2002 cancellation incomplete, changed";
   36.72  
    37.1 --- a/test/Tools/isac/Knowledge/rational-2.sml	Thu Jul 28 11:43:27 2022 +0200
    37.2 +++ b/test/Tools/isac/Knowledge/rational-2.sml	Sat Jul 30 16:47:45 2022 +0200
    37.3 @@ -158,7 +158,7 @@
    37.4                val subst: Type.tyenv * Envir.tenv =
    37.5                  Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
    37.6               in
    37.7 -              snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
    37.8 +              snd (eval__true ctxt (i + 1) (map (Envir.subst_term subst) pres) [] erls)
    37.9               end) handle Pattern.MATCH => false
   37.10             fun scan_ f [] = false (*scan_ NEVER called by []*)
   37.11               | scan_ f (pp::pps) =
   37.12 @@ -180,7 +180,7 @@
   37.13                val subst: Type.tyenv * Envir.tenv =
   37.14                  Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
   37.15               in
   37.16 -              snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
   37.17 +              snd (eval__true ctxt (i + 1) (map (Envir.subst_term subst) pres) [] erls)
   37.18               end) handle Pattern.MATCH => false
   37.19             fun scan_ f [] = false (*scan_ NEVER called by []*)
   37.20               | scan_ f (pp::pps) =
   37.21 @@ -275,8 +275,7 @@
   37.22  "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
   37.23  "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
   37.24  val t = TermC.str2term "(x \<up> 2 - 4)*(3 - y) / ((y \<up> 2 - 9)*(2+x))";
   37.25 -Rewrite.trace_on := false (*true false*);
   37.26 -(* trace stops with ...: (and then jEdit hangs)..
   37.27 +(* trace_rewrite stops with ...: (and then jEdit hangs)..
   37.28  rewrite_set_ thy false norm_Rational t;
   37.29  :
   37.30  ###  rls: cancel_p on: (- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)) /
   37.31 @@ -329,7 +328,7 @@
   37.32                val subst: Type.tyenv * Envir.tenv =
   37.33                  Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
   37.34               in
   37.35 -              snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
   37.36 +              snd (eval__true ctxt (i + 1) (map (Envir.subst_term subst) pres) [] erls)
   37.37               end) handle Pattern.MATCH => false
   37.38             fun scan_ f [] = false (*scan_ NEVER called by []*)
   37.39               | scan_ f (pp::pps) =
   37.40 @@ -377,9 +376,7 @@
   37.41                                  (* required for applying thms in rewriting  \<up> ^*)
   37.42  (* we get details from here..*)
   37.43  
   37.44 -Rewrite.trace_on := false; (*true false*)
   37.45 -val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t;
   37.46 -Rewrite.trace_on := false; (*true false*)
   37.47 +val SOME (t', _) = Rewrite.rewrite_set_ ctxt true add_fractions_p t;
   37.48  (* Rewrite.trace_on:
   37.49  add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + - 1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
   37.50                       (* |||||||||||||||||||||||||||||||||||| *)
   37.51 @@ -420,9 +417,7 @@
   37.52                                      (*AA :: real*)
   37.53  (* we get details from here..*)
   37.54  
   37.55 -Rewrite.trace_on := false; (*true false*)
   37.56 -val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t;
   37.57 -Rewrite.trace_on := false; (*true false*)
   37.58 +val SOME (t', _) = Rewrite.rewrite_set_ ctxt true add_fractions_p t;
   37.59  (* Rewrite.trace_on:
   37.60  add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + - 1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
   37.61                       (* |||||||||||||||||||||||||||||||||||| *)
   37.62 @@ -462,26 +457,26 @@
   37.63  val thy  = @{theory "Rational"};
   37.64  "-------- WN";
   37.65  val t = TermC.str2term "(2 + -3 * x) / 9";
   37.66 -if NONE = rewrite_set_ thy false cancel_p t then ()
   37.67 +if NONE = rewrite_set_ ctxt false cancel_p t then ()
   37.68  else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled";
   37.69  
   37.70  "-------- example 186a";
   37.71  val t = TermC.str2term "(14 * x * y) / (x * y)";
   37.72    is_expanded (TermC.str2term "14 * x * y");
   37.73    is_expanded (TermC.str2term "x * y");
   37.74 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   37.75 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   37.76  if (UnparseC.term t', UnparseC.terms asm) = ("14 / 1", "[]")
   37.77  then () else error "rational.sml cancel Schalk 186a";
   37.78  
   37.79  "-------- example 186b";
   37.80  val t = TermC.str2term "(60 * a * b) / ( 15 * a  * b )";
   37.81 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   37.82 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   37.83  if (UnparseC.term t', UnparseC.terms asm) = ("4 / 1", "[]")
   37.84  then () else error "rational.sml cancel Schalk 186b";
   37.85  
   37.86  "-------- example 186c";
   37.87  val t = TermC.str2term "(144 * a \<up> 2 * b * c) / (12 * a * b * c)";
   37.88 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   37.89 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   37.90  if (UnparseC.term t', UnparseC.terms asm) = ("12 * a / 1", "[]")
   37.91  then () else error "rational.sml cancel Schalk 186c";
   37.92  
   37.93 @@ -489,7 +484,7 @@
   37.94    see --- fun rewrite_set_ downto fun gcd_poly ---
   37.95  "-------- example 187a";
   37.96  val t = TermC.str2term "(12 * x * y) / (8 * y \<up> 2 )";
   37.97 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   37.98 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   37.99  if (UnparseC.term t', UnparseC.terms asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]")
  37.100  then () else error "rational.sml cancel Schalk 187a";
  37.101  *)
  37.102 @@ -498,7 +493,7 @@
  37.103    see --- fun rewrite_set_ downto fun gcd_poly ---
  37.104  "-------- example 187b";
  37.105  val t = TermC.str2term "(8 * x \<up> 2 * y * z ) / (18 * x * y \<up> 2 * z )";
  37.106 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.107 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.108  if (UnparseC.term t', UnparseC.terms asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]")
  37.109  then () else error "rational.sml cancel Schalk 187b";
  37.110  *)
  37.111 @@ -507,7 +502,7 @@
  37.112    see --- fun rewrite_set_ downto fun gcd_poly ---
  37.113  "-------- example 187c";
  37.114  val t = TermC.str2term "(9 * x \<up> 5 * y \<up> 2 * z \<up> 4) / (15 * x \<up> 6 * y \<up> 3 * z )";
  37.115 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.116 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.117  if (UnparseC.term t', UnparseC.terms asm) = 
  37.118    ("3 * z \<up> 3 / (5 * (y * x))", "[\"3 * (z * (y \<up> 2 * x \<up> 5)) ~= 0\"]") 
  37.119  then () else error "rational.sml cancel Schalk 187c";
  37.120 @@ -516,43 +511,43 @@
  37.121  "-------- example 188a";
  37.122  val t = TermC.str2term "(-8 + 8 * x) / (-9 + 9 * x)";
  37.123    is_expanded (TermC.str2term "8 * x + -8");
  37.124 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.125 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.126  if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]")
  37.127  then () else error "rational.sml cancel Schalk 188a";
  37.128  
  37.129  val t = TermC.str2term "(8*((- 1) + x))/(9*((- 1) + x))";
  37.130 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
  37.131 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
  37.132  if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]")
  37.133  then () else error "rational.sml cancel Schalk make_polynomial 1";
  37.134  
  37.135  "-------- example 188b";
  37.136  val t = TermC.str2term "(- 15 + 5 * x) / (- 18 + 6 * x)";
  37.137 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.138 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.139  if (UnparseC.term t', UnparseC.terms asm) = ("5 / 6", "[]")
  37.140  then () else error "rational.sml cancel Schalk 188b";
  37.141  
  37.142  "-------- example 188c";
  37.143  val t = TermC.str2term "(a + - 1 * b) / (b + - 1 * a)";
  37.144 -val SOME (t', asm) = rewrite_set_ thy false  cancel_p t;
  37.145 +val SOME (t', asm) = rewrite_set_ ctxt false  cancel_p t;
  37.146  if (UnparseC.term t', UnparseC.terms asm) = ("- 1 / 1", "[]")
  37.147  then () else error "rational.sml cancel Schalk 188c";
  37.148  
  37.149  is_expanded (TermC.str2term "a + - 1 * b") = true;
  37.150  val t = TermC.str2term "((- 1)*(b + (- 1) * a))/(1*(b + (- 1) * a))";
  37.151 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
  37.152 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
  37.153  if (UnparseC.term t', UnparseC.terms asm) = ("(a + - 1 * b) / (- 1 * a + b)", "[]")
  37.154  then () else error "rational.sml cancel Schalk make_polynomial 2";
  37.155  
  37.156  "-------- example 190a";
  37.157  val t = TermC.str2term "( 27 * a \<up> 3 + 9 * a \<up> 2 + 3 * a + 1 ) / ( 27 * a \<up> 3 + 18 * a \<up> 2 + 3 * a )";
  37.158 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.159 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.160  if (UnparseC.term t', UnparseC.terms asm) = 
  37.161    ("(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)", "[\"3 * a + 9 * a \<up> 2 \<noteq> 0\"]")
  37.162  then () else error "rational.sml cancel Schalk 190a";
  37.163  
  37.164  "-------- example 190c";
  37.165  val t = TermC.str2term "((1 + 9 * a \<up> 2)*(1 + 3 * a))/((3 * a + 9 * a \<up> 2)*(1 + 3 * a))";
  37.166 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
  37.167 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
  37.168  if (UnparseC.term t', UnparseC.terms asm) = 
  37.169    ("(1 + 3 * a + 9 * a \<up> 2 + 27 * a \<up> 3) /\n(3 * a + 18 * a \<up> 2 + 27 * a \<up> 3)", "[]")
  37.170  then () else error "rational.sml make_polynomial Schalk 190c";
  37.171 @@ -561,13 +556,13 @@
  37.172  val t = TermC.str2term "( x \<up> 2 + - 1 * y \<up> 2 ) / ( x + y )";
  37.173    is_expanded (TermC.str2term "x \<up> 2 + - 1 * y \<up> 2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
  37.174    is_expanded (TermC.str2term "x + y") = true;
  37.175 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.176 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.177  if (UnparseC.term t', UnparseC.terms asm) = ("(x + - 1 * y) / 1", "[]")
  37.178  then () else error "rational.sml make_polynomial Schalk 191a";
  37.179  
  37.180  "-------- example 191b";
  37.181  val t = TermC.str2term "((x + (- 1) * y)*(x + y))/((1)*(x + y))";
  37.182 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
  37.183 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
  37.184  if (UnparseC.term t', UnparseC.terms asm) = ("(x \<up> 2 + - 1 * y \<up> 2) / (x + y)", "[]")
  37.185  then () else error "rational.sml make_polynomial Schalk 191b";
  37.186  
  37.187 @@ -578,57 +573,57 @@
  37.188    is_expanded (TermC.str2term "- 25 + 9*x \<up> 2") = true;
  37.189  
  37.190  val t = TermC.str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
  37.191 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
  37.192 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
  37.193  if (UnparseC.term t', UnparseC.terms asm) = ("(25 + - 30 * x + 9 * x \<up> 2) / (- 25 + 9 * x \<up> 2)", "[]")
  37.194  then () else error "rational.sml make_polynomial Schalk 191c";
  37.195  
  37.196  "-------- example 192b";
  37.197  val t = TermC.str2term "( 7 * x \<up> 3 + - 1 * x \<up> 2 * y ) / ( 7 * x * y \<up> 2 + - 1 *  y \<up> 3 )";
  37.198 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.199 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.200  if (UnparseC.term t', UnparseC.terms asm) = ("x \<up> 2 / y \<up> 2", "[\"y \<up> 2 \<noteq> 0\"]")
  37.201  then () else error "rational.sml cancel_p Schalk 192b";
  37.202  
  37.203  val t = TermC.str2term "((x \<up> 2)*(7 * x + (- 1) * y))/((y \<up> 2)*(7 * x + (- 1) * y))";
  37.204 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
  37.205 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
  37.206  if (UnparseC.term t', UnparseC.terms asm) = 
  37.207    ("(7 * x \<up> 3 + - 1 * x \<up> 2 * y) /\n(7 * x * y \<up> 2 + - 1 * y \<up> 3)", "[]")
  37.208  then () else error "rational.sml make_polynomial Schalk 192b";
  37.209  
  37.210  val t = TermC.str2term "((x \<up> 2)*(7 * x + (- 1) * y))/((y \<up> 2)*(7 * x + (- 1) * y))";
  37.211 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
  37.212 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
  37.213  if (UnparseC.term t', UnparseC.terms asm) = 
  37.214    ("(7 * x \<up> 3 + - 1 * x \<up> 2 * y) /\n(7 * x * y \<up> 2 + - 1 * y \<up> 3)", "[]")
  37.215  then () else error "rational.sml make_polynomial Schalk WN050929 not working";
  37.216  
  37.217  "-------- example 193a";
  37.218  val t = TermC.str2term "( x \<up> 2 + -6 * x + 9 ) / ( x \<up> 2 + -9 )";
  37.219 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.220 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.221  if (UnparseC.term t', UnparseC.terms asm) = ("(- 3 + x) / (3 + x)", "[\"3 + x \<noteq> 0\"]")
  37.222  then () else error "rational.sml cancel_p Schalk 193a";
  37.223  
  37.224  "-------- example 193b";
  37.225  val t = TermC.str2term "( x \<up> 2 + -8 * x + 16 ) / ( 2 * x \<up> 2 + -32 )";
  37.226 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.227 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.228  if (UnparseC.term t', UnparseC.terms asm) = ("(- 4 + x) / (8 + 2 * x)", "[\"8 + 2 * x \<noteq> 0\"]")
  37.229  then () else error "rational.sml cancel_p Schalk 193b";
  37.230  
  37.231  "-------- example 193c";
  37.232  val t = TermC.str2term "( 2 * x + -50 * x \<up> 3 ) / ( 25 * x \<up> 2 + - 10 * x + 1 )";
  37.233 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.234 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.235  if (UnparseC.term t', UnparseC.terms asm) = 
  37.236    ("(2 * x + 10 * x \<up> 2) / (1 + - 5 * x)", "[\"1 + - 5 * x \<noteq> 0\"]")
  37.237  then () else error "rational.sml cancel_p Schalk 193c";
  37.238  
  37.239  (*WN: improved with new numerals*)
  37.240  val t = TermC.str2term "(- 25 + 9*x \<up> 2)/(5 + 3*x)";
  37.241 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.242 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.243  if (UnparseC.term t', UnparseC.terms asm) = ("(- 5 + 3 * x) / 1", "[]")
  37.244  then () else error "rational.sml cancel WN 1";
  37.245  
  37.246  "-------- example heuberger";
  37.247  val t = TermC.str2term ("(x \<up> 4 + x * y + x \<up> 3 * y + y \<up> 2) / " ^
  37.248    "(x + 5 * x \<up> 2 + y + 5 * x * y + x \<up> 2 * y \<up> 3 + x * y \<up> 4)");
  37.249 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.250 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.251  if (UnparseC.term t', UnparseC.terms asm) = 
  37.252    ("(x \<up> 3 + y) / (1 + 5 * x + x * y \<up> 3)", "[\"1 + 5 * x + x * y \<up> 3 \<noteq> 0\"]")
  37.253  then () else error "rational.sml cancel_p heuberger";
  37.254 @@ -647,25 +642,25 @@
  37.255  if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction";
  37.256  
  37.257  "-------- gcd_poly integration level 2: picks out ONE appropriate subterm";
  37.258 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  37.259 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
  37.260  if UnparseC.term t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f" 
  37.261  then () else error "level 2, rewrite_set_ cancel_p: changed";
  37.262 -val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t;
  37.263 +val SOME (t', asm) = rewrite_set_ ctxt false add_fractions_p t;
  37.264  if UnparseC.term t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)"
  37.265  then () else error "level 2, rewrite_set_ add_fractions_p: changed";
  37.266  
  37.267  "-------- gcd_poly integration level 3: rewrites all appropriate subterms";
  37.268 -val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t;
  37.269 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p_rls t;
  37.270  if UnparseC.term t' = "123 = a / b + c / d + e / f"
  37.271  then () else error "level 3, rewrite_set_ cancel_p_rls: changed";
  37.272 -val SOME (t', asm) = rewrite_set_ thy false add_fractions_p_rls t; (*CREATE add_fractions_p_rls*)
  37.273 +val SOME (t', asm) = rewrite_set_ ctxt false add_fractions_p_rls t; (*CREATE add_fractions_p_rls*)
  37.274  if UnparseC.term t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)"
  37.275  then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed";
  37.276  
  37.277  "-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p";
  37.278  (* simpler variant *)
  37.279  val testrls = Rule_Set.append_rules "testrls" Rule_Set.empty [Rls_ cancel_p, Rls_ add_fractions_p]
  37.280 -val SOME (t', asm) = rewrite_set_ thy false testrls t;
  37.281 +val SOME (t', asm) = rewrite_set_ ctxt false testrls t;
  37.282  (*Rewrite.trace_on := false; (*true false*)
  37.283  #  rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
  37.284  ##  rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
  37.285 @@ -679,7 +674,7 @@
  37.286  
  37.287  (* complicated variant *)
  37.288  val testrls_rls = Rule_Set.append_rules "testrls_rls" Rule_Set.empty [Rls_ cancel_p_rls, Rls_ add_fractions_p_rls];
  37.289 -val SOME (t', asm) = rewrite_set_ thy false testrls_rls t;
  37.290 +val SOME (t', asm) = rewrite_set_ ctxt false testrls_rls t;
  37.291  (*#  rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
  37.292  ##  rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
  37.293  ###  rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
  37.294 @@ -698,7 +693,7 @@
  37.295  then () else error "level 4, rewrite_set_ *_p_rls: changed"
  37.296  
  37.297  "-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational";
  37.298 -val SOME (t', asm) = rewrite_set_ thy false norm_Rational t;
  37.299 +val SOME (t', asm) = rewrite_set_ ctxt false norm_Rational t;
  37.300  if UnparseC.term t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)"
  37.301  then () else error "level 5, rewrite_set_ norm_Rational: changed"
  37.302  
  37.303 @@ -851,49 +846,47 @@
  37.304  "-------- examples: rls norm_Rational ----------------------------------------";
  37.305  "-------- examples: rls norm_Rational ----------------------------------------";
  37.306  "-------- examples: rls norm_Rational ----------------------------------------";
  37.307 -Rewrite.trace_on := false; (*true false*)
  37.308 -
  37.309  val t = TermC.str2term "Not (6*x is_atom)";
  37.310 -val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t';
  37.311 +val SOME (t',_) = rewrite_set_ ctxt false powers_erls t; UnparseC.term t';
  37.312  "HOL.True";
  37.313  val t = TermC.str2term "1 < 2";
  37.314 -val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t';
  37.315 +val SOME (t',_) = rewrite_set_ ctxt false powers_erls t; UnparseC.term t';
  37.316  "HOL.True";
  37.317  
  37.318  val t = TermC.str2term "(6*x) \<up> 2";
  37.319 -val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false @{thm realpow_def_atom} t;
  37.320 +val SOME (t',_) = rewrite_ ctxt dummy_ord powers_erls false @{thm realpow_def_atom} t;
  37.321  if UnparseC.term t' = "6 * x * (6 * x) \<up> (2 + - 1)" then ()
  37.322  else error "rational.sml powers_erls (6*x) \<up> 2";
  37.323  
  37.324  val t = TermC.str2term "- 1 * (- 2 * (5 / 2 * (13 * x / 2)))";
  37.325 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
  37.326 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
  37.327  if UnparseC.term t' = "65 * x / 2" then () else error "rational.sml 4";
  37.328  
  37.329  val t = TermC.str2term "1 - ((13*x)/2 - 5/2) \<up> 2";
  37.330 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
  37.331 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
  37.332  if UnparseC.term t' = "(- 21 + 130 * x + - 169 * x \<up> 2) / 4" then () 
  37.333  else error "rational.sml 5";
  37.334  
  37.335  (*SRAM Schalk I, p.92 Nr. 609a*)
  37.336  val t = TermC.str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
  37.337 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
  37.338 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
  37.339  if UnparseC.term t' = "(- 255 + 112 * x) / 135" then () 
  37.340  else error "rational.sml 6";
  37.341  
  37.342  (*SRAM Schalk I, p.92 Nr. 610c*)
  37.343  val t = TermC.str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
  37.344 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
  37.345 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
  37.346  if UnparseC.term t' = "(3 + x) / - 2" then () else error "rational.sml 7";
  37.347  
  37.348  (*SRAM Schalk I, p.92 Nr. 476a*)
  37.349  val t = TermC.str2term "(x \<up> 2/(1 - x \<up> 2) + 1)/(x/(1 - x) + 1) * (1 + x)";
  37.350  (*. a/b : c/d translated to a/b * d/c .*)
  37.351 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
  37.352 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
  37.353  if UnparseC.term t' = "1" then () else error "rational.sml 8";
  37.354  
  37.355  (*Schalk I, p.92 Nr. 472a*)
  37.356  val t = TermC.str2term "((8*x \<up> 2 - 32*y \<up> 2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
  37.357 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
  37.358 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
  37.359  if UnparseC.term t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
  37.360  
  37.361  (*Schalk I, p.70 Nr. 480b: SEE rational.sml --- nonterminating rls norm_Rational ---*)
  37.362 @@ -901,11 +894,11 @@
  37.363  (*WN130910 add_fractions_p exception Div raised + history:
  37.364  ### WN.2.6.03 from rlang.sml 56a 
  37.365  val t = TermC.str2term "(a + b * x) / (a + - 1 * (b * x)) + (- 1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a \<up> 2 + - 1 * b \<up> 2)";
  37.366 -val NONE = rewrite_set_ thy false add_fractions_p t;
  37.367 +val NONE = rewrite_set_ ctxt false add_fractions_p t;
  37.368  
  37.369  THE ERROR ALREADY OCCURS IN THIS PART:
  37.370  val t = TermC.str2term "(a + b * x) / (a + - 1 * (b * x)) + (- 1 * a + b * x) / (a + b * x)";
  37.371 -val NONE = add_fraction_p_ thy t;
  37.372 +val NONE = add_fraction_p_ ctxt t;
  37.373  
  37.374  SEE Test_Some.thy: section {* add_fractions_p downto exception Div raised ===
  37.375  *)
  37.376 @@ -915,13 +908,13 @@
  37.377  "-------- rational numerals --------------------------------------------------";
  37.378  (*SRA Schalk I, p.40 Nr. 164b *)
  37.379  val t = TermC.str2term "(47/6 - 76/9 + 13/4)/(35/12)";
  37.380 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.381 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.382  if UnparseC.term t = "19 / 21" then ()
  37.383  else error "rational.sml: diff.behav. in norm_Rational_mg 1";
  37.384  
  37.385  (*SRA Schalk I, p.40 Nr. 166a *)
  37.386  val t = TermC.str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
  37.387 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.388 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.389  if UnparseC.term t = "45 / 2" then ()
  37.390  else error "rational.sml: diff.behav. in norm_Rational_mg 2";
  37.391  
  37.392 @@ -930,49 +923,49 @@
  37.393  "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
  37.394  (* e190c Stefan K.*)
  37.395  val t = TermC.str2term "((1 + 9*a \<up> 2) * (1 + 3*a)) / ((3*a + 9*a \<up> 2) * (1 + 3*a))";
  37.396 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.397 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.398  if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
  37.399  then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
  37.400  
  37.401  (* e192b Stefan K.*)
  37.402  val t = TermC.str2term "(x \<up> 2 * (7*x + (- 1)*y))  /  (y \<up> 2 * (7*x + (- 1)*y))";
  37.403 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.404 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.405  if UnparseC.term t = "x \<up> 2 / y \<up> 2"
  37.406  then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
  37.407  
  37.408  (*SRC Schalk I, p.66 Nr. 379c *)
  37.409  val t = TermC.str2term "(a - b)/(b - a)";
  37.410 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.411 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.412  if UnparseC.term t = "- 1"
  37.413  then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
  37.414  
  37.415  (*SRC Schalk I, p.66 Nr. 380b *)
  37.416  val t = TermC.str2term "15*(3*x + 3) * (4*x + 9)  /  (12*(2*x + 7) * (5*x + 5))";
  37.417 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.418 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.419  if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)"
  37.420  then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
  37.421  
  37.422  (* e190c Stefan K.*)
  37.423  val t = TermC.str2term "((1 + 9*a \<up> 2) * (1 + 3*a))  /  ((3*a + 9*a \<up> 2) * (1 + 3 * a))";
  37.424 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.425 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.426  if UnparseC.term t =  "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
  37.427  then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
  37.428  
  37.429  (* e192b Stefan K.*)
  37.430  val t = TermC.str2term "(x \<up> 2 * (7*x + (- 1)*y))  /  (y \<up> 2 * (7*x + (- 1)*y))";
  37.431 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.432 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.433  if UnparseC.term t = "x \<up> 2 / y \<up> 2"
  37.434  then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
  37.435  
  37.436  (*SRC Schalk I, p.66 Nr. 379c *)
  37.437  val t = TermC.str2term "(a - b) / (b - a)";
  37.438 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.439 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.440  if UnparseC.term t = "- 1"
  37.441  then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
  37.442  
  37.443  (*SRC Schalk I, p.66 Nr. 380b *)
  37.444  val t = TermC.str2term "15*(3*x + 3) * (4*x + 9)  /  (12*(2*x + 7) * (5*x + 5))";
  37.445 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.446 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.447  if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)"
  37.448  then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
  37.449  
  37.450 @@ -984,32 +977,32 @@
  37.451    " / (a \<up> 2 * x \<up> 3  +  -3*a \<up> 2 * x \<up> 2 * y  +  3*a \<up> 2 * x * y \<up> 2  +  - 1*a \<up> 2 * y \<up> 3 + " ^
  37.452        "2*a * b * x \<up> 3  +  -6*a * b * x \<up> 2 * y  +  6*a * b * x * y \<up> 2  +  - 2*a * b * y \<up> 3 + " ^
  37.453        "b \<up> 2 * x \<up> 3  +  -3*b \<up> 2 * x \<up> 2 * y  +  3*b \<up> 2 * x * y \<up> 2  +  - 1*b \<up> 2 * y \<up> 3)")
  37.454 -val SOME (t, _) = rewrite_set_ thy false cancel_p t;
  37.455 +val SOME (t, _) = rewrite_set_ ctxt false cancel_p t;
  37.456  if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + - 2 * x * y + y \<up> 2)"
  37.457  then () else error "with Isabelle2002: NONE -- now SOME changed";
  37.458  
  37.459  (*Schalk I, p.66 Nr. 381a *)
  37.460  (* ATTENTION: here the rls is very slow. In Isabelle2002 this required 2 min *)
  37.461  val t = TermC.str2term "18*(a + b) \<up> 3 * (a - b) \<up> 2 / (72*(a - b) \<up> 3 * (a + b) \<up> 2)";
  37.462 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.463 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.464  if UnparseC.term t = "(a + b) / (4 * a + - 4 * b)"
  37.465  then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
  37.466  
  37.467  (*SRC Schalk I, p.66 Nr. 381b *)
  37.468  val t = TermC.str2term "(4*x \<up> 2 - 20*x + 25) / (2*x - 5) \<up> 3";
  37.469 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.470 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.471  if UnparseC.term t = "1 / (- 5 + 2 * x)"
  37.472  then () else error "rational.sml: diff.behav. in norm_Rational_mg 9";
  37.473  
  37.474  (*SRC Schalk I, p.66 Nr. 381c *)
  37.475  val t = TermC.str2term "(27*a \<up> 3 + 9*a \<up> 2+3*a+1) / (27*a \<up> 3 + 18*a \<up> 2+3*a)";
  37.476 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.477 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.478  if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
  37.479  then () else error "rational.sml: diff.behav. in norm_Rational_mg 10";
  37.480  
  37.481  (*SRC Schalk I, p.66 Nr. 383a *)
  37.482  val t = TermC.str2term "(5*a \<up> 2 - 5*a*b) / (a - b) \<up> 2";
  37.483 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.484 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.485  if UnparseC.term t = "- 5 * a / (- 1 * a + b)"
  37.486  then () else error "rational.sml: diff.behav. in norm_Rational_mg 11";
  37.487  
  37.488 @@ -1019,7 +1012,7 @@
  37.489    cancel_p_ thy (TermC.str2term ("(- 1 + - 1 * b + a \<up> 2 + a \<up> 2 * b) /" ^
  37.490                             "(- 1 + - 1 * a + b \<up> 2 + a * b \<up> 2)"))
  37.491  
  37.492 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.493 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.494  if UnparseC.term t = "(1 + - 1 * a) / (1 + - 1 * b)" then ()
  37.495  else error "rational.sml MG tests 3e";
  37.496  *)
  37.497 @@ -1029,12 +1022,12 @@
  37.498  "-------- examples common denominator from: Mathematik 1 Schalk --------------";
  37.499  (*SRA Schalk I, p.67 Nr. 403a *)
  37.500  val t = TermC.str2term "4/x - 3/y - 1";
  37.501 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.502 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.503  if UnparseC.term t = "(- 3 * x + 4 * y + - 1 * x * y) / (x * y)"
  37.504  then () else error "rational.sml: diff.behav. in norm_Rational_mg 12";
  37.505  
  37.506  val t = TermC.str2term "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a \<up> 2+3*b*c)/(a*b*c)";
  37.507 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.508 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.509  if UnparseC.term t = "4 / c"
  37.510  then () else error "rational.sml: diff.behav. in norm_Rational_mg 13";
  37.511  
  37.512 @@ -1043,20 +1036,20 @@
  37.513  (* WN130911 non-termination due to non-termination of
  37.514    cancel_p_ thy (TermC.str2term "(5 + 3 * x) / (6 + 11 * x + 6 * x \<up> 2 + x \<up> 3)")
  37.515  
  37.516 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.517 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.518  if UnparseC.term t = "(5 + 3 * x) / (6 + 11 * x + 6 * x \<up> 2 + x \<up> 3)"
  37.519  then () else error "rational.sml: diff.behav. in norm_Rational_mg 14";
  37.520  *)
  37.521  
  37.522  (*SRA Schalk I, p.67 Nr. 413b *)
  37.523  val t = TermC.str2term "(1 + x)/(1 - x)  -  (1 - x)/(1 + x)  +  2*x/(1 - x \<up> 2)";
  37.524 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.525 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.526  if UnparseC.term t = "6 * x / (1 + - 1 * x \<up> 2)"
  37.527  then () else error "rational.sml: diff.behav. in norm_Rational_mg 15";
  37.528  
  37.529  (*SRA Schalk I, p.68 Nr. 414a *)
  37.530  val t = TermC.str2term "(x + 2)/(x - 1)  +  (x - 3)/(x - 2)  -  (x + 1)/((x - 1)*(x - 2))";
  37.531 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.532 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.533  if UnparseC.term t ="(- 2 + - 5 * x + 2 * x \<up> 2) / (2 + - 3 * x + x \<up> 2)"
  37.534  then () else error "rational.sml: diff.behav. in norm_Rational_mg 16";
  37.535  
  37.536 @@ -1066,7 +1059,7 @@
  37.537  (* WN130911 non-termination due to non-termination of
  37.538    cancel_p_ thy (TermC.str2term "(4 + -4 * b \<up> 2) / (a \<up> 4 + - 2 * (a \<up> 2 * b \<up> 2) + b \<up> 4)")
  37.539  
  37.540 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.541 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.542  if UnparseC.term t = "4 / (a \<up> 4 + - 2 * a \<up> 2 * b \<up> 2 + b \<up> 4)"
  37.543  then () else error "rational.sml: diff.behav. in norm_Rational_mg 18";
  37.544  *)
  37.545 @@ -1074,7 +1067,7 @@
  37.546  (*SRA Schalk I, p.68 Nr. 430b *)
  37.547  val t = TermC.str2term 
  37.548    "a \<up> 2/(a - 3*b) - 108*a*b \<up> 3/((a+3*b)*(a \<up> 2 - 9*b \<up> 2)) - 9*b \<up> 2*(a - 3*b)/(a+3*b) \<up> 2";
  37.549 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.550 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.551  if UnparseC.term t = "a + 3 * b"
  37.552  then () else error "rational.sml: diff.behav. in norm_Rational_mg 19";
  37.553  
  37.554 @@ -1083,13 +1076,13 @@
  37.555    ("(a \<up> 2 + a*b) / (a \<up> 2 - b \<up> 2)  -  (b \<up> 2 - a*b) / (b \<up> 2 - a \<up> 2)  +  " ^
  37.556    "a \<up> 2*(a - b) / (a \<up> 3 - a \<up> 2*b)  -  2*a*(a \<up> 2 - b \<up> 2) / (a \<up> 3 - a*b \<up> 2)  -  " ^
  37.557    "2*b \<up> 2 / (a \<up> 2 - b \<up> 2)");
  37.558 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.559 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.560  if UnparseC.term t = (*"0" ..isabisac15 | Isabelle2017..*)  "0 / (a \<up> 2 + - 1 * b \<up> 2)"
  37.561  then () else error "rational.sml: diff.behav. in norm_Rational_mg 20";
  37.562  
  37.563  (* some example *)
  37.564  val t = TermC.str2term "3*a / (a*b)  +  x/y";
  37.565 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.566 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.567  if UnparseC.term t = "(3 * y + b * x) / (b * y)"
  37.568  then () else error "rational.sml: diff.behav. in norm_Rational_mg 21";
  37.569  
  37.570 @@ -1099,20 +1092,20 @@
  37.571  "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
  37.572  (*------- SRM Schalk I, p.68 Nr. 436a *)
  37.573  val t = TermC.str2term "3*(x+y) / (15*(x - y))  *   25*(x - y) \<up> 2 / (18*(x + y) \<up> 2)";
  37.574 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.575 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.576  if UnparseC.term t = "(- 5 * x + 5 * y) / (- 18 * x + - 18 * y)"
  37.577  then () else error "rational.sml: diff.behav. in norm_Rational_mg 22";
  37.578  
  37.579  (*------- SRM.test Schalk I, p.68 Nr. 436b *)
  37.580  val t = TermC.str2term "5*a*(a - b) \<up> 2*(a + b) \<up> 3/(7*b*(a - b) \<up> 3) * 7*b/(a + b) \<up> 3";
  37.581 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.582 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.583  if UnparseC.term t = "5 * a / (a + - 1 * b)"
  37.584  then () else error "rational.sml: diff.behav. in norm_Rational_mg 23";
  37.585  
  37.586  (*------- Schalk I, p.68 Nr. 437a *)
  37.587  val t = TermC.str2term "(3*a - 4*b) / (4*c+3*e)  *  (3*a+4*b)/(9*a \<up> 2 - 16*b \<up> 2)";
  37.588  (* raises an exception for unclear reasons:
  37.589 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.590 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.591  :
  37.592  ###  rls: cancel_p on: (9 * a \<up> 2 + - 16 * b \<up> 2) / (4 * c + 3 * e) /
  37.593  (9 * a \<up> 2 + - 16 * b \<up> 2) 
  37.594 @@ -1130,7 +1123,7 @@
  37.595  
  37.596  "----- S.K. corrected non-termination 060904";
  37.597  val t = TermC.str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a \<up> 2 - 16*b \<up> 2))";
  37.598 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
  37.599 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
  37.600  if UnparseC.term t = 
  37.601    "(9 * a \<up> 2 + - 16 * b \<up> 2) /\n(36 * a \<up> 2 * c + 27 * a \<up> 2 * e + - 64 * b \<up> 2 * c +\n - 48 * b \<up> 2 * e)"
  37.602  then () else error "rational.sml: S.K.8..corrected 060904-6";
  37.603 @@ -1139,14 +1132,14 @@
  37.604  val t'' = TermC.str2term ("(9 * a \<up> 2 + - 16 * b \<up> 2) /" ^
  37.605    "(36 * a \<up> 2 * c + (27 * a \<up> 2 * e + (-64 * b \<up> 2 * c + -48 * b \<up> 2 * e)))");
  37.606  (* /--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------\
  37.607 -val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
  37.608 +val SOME (t',_) = rewrite_set_ ctxt false cancel_p t'';
  37.609  if UnparseC.term t' = "1 / (4 * c + 3 * e)"
  37.610  then () else error "rational.sml: diff.behav. in cancel_p S.K.8";
  37.611     \--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------/*)
  37.612  
  37.613  (*------- Schalk I, p.68 Nr. 437b*)
  37.614  val t = TermC.str2term "(a + b)/(x \<up> 2 - y \<up> 2) * ((x - y) \<up> 2/(a \<up> 2 - b \<up> 2))";
  37.615 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.616 +(*val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.617  :
  37.618  ####  rls: cancel_p on: (a * x \<up> 2 + - 2 * (a * (x * y)) + a * y \<up> 2 + b * x \<up> 2 +
  37.619   - 2 * (b * (x * y)) +
  37.620 @@ -1158,26 +1151,26 @@
  37.621  
  37.622  (*------- SRM Schalk I, p.68 Nr. 438a *)
  37.623  val t = TermC.str2term "x*y / (x*y - y \<up> 2)  *  (x \<up> 2 - x*y)";
  37.624 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.625 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.626  if UnparseC.term t = "x \<up> 2"
  37.627  then () else error "rational.sml: diff.behav. in norm_Rational_mg 24";
  37.628  
  37.629  (*------- SRM Schalk I, p.68 Nr. 439b *)
  37.630  val t = TermC.str2term "(4*x \<up> 2 + 4*x + 1)  *  ((x \<up> 2 - 2*x \<up> 3) / (4*x \<up> 2 + 2*x))";
  37.631 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.632 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.633  if UnparseC.term t = "(x + - 4 * x \<up> 3) / 2"
  37.634  then () else error "rational.sml: diff.behav. in norm_Rational_mg 25";
  37.635  
  37.636  (*------- SRM Schalk I, p.68 Nr. 440a *)
  37.637  val t = TermC.str2term "(x \<up> 2 - 2*x) / (x \<up> 2 - 3*x)  *  (x - 3) \<up> 2 / (x \<up> 2 - 4)";
  37.638 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.639 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.640  if UnparseC.term t = "(- 3 + x) / (2 + x)"
  37.641  then () else error "rational.sml: diff.behav. in norm_Rational_mg 26";
  37.642  
  37.643  "----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
  37.644  val t = TermC.str2term "(a \<up> 3 - 9*a) / (a \<up> 3*b - a*b \<up> 3)  *  (a \<up> 2*b + a*b \<up> 2) / (a+3)";
  37.645  (* WN130911 non-termination for unclear reasons:
  37.646 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.647 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.648  
  37.649  ... ENDS WITH THIS TRACE:
  37.650  :
  37.651 @@ -1201,7 +1194,7 @@
  37.652  (* WN130911 non-termination due to non-termination of
  37.653    cancel_p_ thy (TermC.str2term "(4 + -4 * b \<up> 2) / (a \<up> 4 + - 2 * (a \<up> 2 * b \<up> 2) + b \<up> 4)")
  37.654  
  37.655 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.656 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.657  if UnparseC.term t' = "(-3 * a + a \<up> 2) / (a + - 1 * b)" then ()
  37.658  else error "rational.sml: diff.behav. in norm_Rational 28";
  37.659  *)
  37.660 @@ -1211,32 +1204,32 @@
  37.661  "-------- examples common denominator and multiplication from: Schalk --------";
  37.662  (*------- SRAM Schalk I, p.69 Nr. 441b *)
  37.663  val t = TermC.str2term "(4*a/3 + 3*b \<up> 2/a \<up> 3 + b/(4*a))*(4*b/(3*a))";
  37.664 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.665 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.666  if UnparseC.term t = "(36 * b \<up> 3 + 3 * a \<up> 2 * b \<up> 2 + 16 * a \<up> 4 * b) /\n(9 * a \<up> 4)"
  37.667  then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
  37.668  
  37.669  (*------- SRAM Schalk I, p.69 Nr. 442b *)
  37.670  val t = TermC.str2term ("(15*a \<up> 2/x \<up> 3 - 5*b \<up> 4/x \<up> 2 + 25*c \<up> 2/x) * " ^
  37.671    "(x \<up> 3/(5*a*b \<up> 3*c \<up> 3)) + 1/c \<up> 3 * (b*x/a - 3*a/b \<up> 3)");
  37.672 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.673 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.674  if UnparseC.term t = "5 * x \<up> 2 / (a * b \<up> 3 * c)"
  37.675  then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
  37.676  
  37.677  (*------- SRAM Schalk I, p.69 Nr. 443b *)
  37.678  val t = TermC.str2term "(a/2 + b/3) * (b/3 - a/2)";
  37.679 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.680 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.681  if UnparseC.term t = "(- 9 * a \<up> 2 + 4 * b \<up> 2) / 36"
  37.682  then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
  37.683  
  37.684  (*------- SRAM Schalk I, p.69 Nr. 445b *)
  37.685  val t = TermC.str2term "(a \<up> 2/9 + 2*a/(3*b) + 4/b \<up> 2)*(a/3 - 2/b) + 8/b \<up> 3";
  37.686 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.687 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.688  if UnparseC.term t = "a \<up> 3 / 27"
  37.689  then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
  37.690  
  37.691  (*------- SRAM Schalk I, p.69 Nr. 446b *)
  37.692  val t = TermC.str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x \<up> 2 - 16*y \<up> 2)";
  37.693 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.694 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.695  if UnparseC.term t = (*"30 * x \<up> 2 + -9 * x * y + - 20 * y \<up> 2" ..isabisac15 | Isabelle2017..*)
  37.696                    "(- 30 * x \<up> 2 + 9 * x * y + 20 * y \<up> 2) / - 1"
  37.697  then () else error "rational.sml: diff.behav. in norm_Rational_mg 32";
  37.698 @@ -1244,14 +1237,14 @@
  37.699  (*------- SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
  37.700  val t = TermC.str2term 
  37.701  "(2*x \<up> 2/(3*y)+x/y \<up> 2)*(4*x \<up> 4/(9*y \<up> 2)+x \<up> 2/y \<up> 4)*(2*x \<up> 2/(3*y) - x/y \<up> 2)";
  37.702 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.703 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.704  if UnparseC.term t = "(- 81 * x \<up> 4 + 16 * x \<up> 8 * y \<up> 4) / (81 * y \<up> 8)"
  37.705  then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
  37.706  
  37.707  (*------- SRAM Schalk I, p.69 Nr. 450a *)
  37.708  val t = TermC.str2term 
  37.709  "(4*x/(3*y)+2*y/(3*x)) \<up> 2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
  37.710 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.711 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.712  if UnparseC.term t = "(52 * x \<up> 2 + 16 * y \<up> 2) / (9 * y \<up> 2)"
  37.713  then () else error "rational.sml: diff.behav. in norm_Rational_mg 34";
  37.714  
  37.715 @@ -1259,7 +1252,7 @@
  37.716  val t = TermC.str2term 
  37.717    ("(15*a \<up> 4/(a*x \<up> 3)  -  5*a*((b \<up> 4 - 5*c \<up> 2*x) / x \<up> 2))  *  " ^
  37.718    "(x \<up> 3/(5*a*b \<up> 3*c \<up> 3))   +   a/c \<up> 3 * (x*(b/a) - 3*b*(a/b \<up> 4))");
  37.719 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.720 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.721  if UnparseC.term t = "5 * x \<up> 2 / (b \<up> 3 * c)"
  37.722  then () else error "rational.sml: diff.behav. in norm_Rational_mg 53";
  37.723  
  37.724 @@ -1269,13 +1262,13 @@
  37.725  "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
  37.726  "----- SRD Schalk I, p.69 Nr. 454b";
  37.727  val t = TermC.str2term "((2 - x)/(2*a)) / (2*a/(x - 2))";
  37.728 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.729 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.730  if UnparseC.term t = "(- 4 + 4 * x + - 1 * x \<up> 2) / (4 * a \<up> 2)"
  37.731  then () else error "rational.sml: diff.behav. in norm_Rational_mg 35";
  37.732  
  37.733  "----- SRD Schalk I, p.69 Nr. 455a";
  37.734  val t = TermC.str2term "(a \<up> 2 + 1)/(a \<up> 2 - 1) / ((a+1)/(a - 1))";
  37.735 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.736 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.737  if UnparseC.term t = "(1 + a \<up> 2) / (1 + 2 * a + a \<up> 2)" then ()
  37.738  else error "rational.sml: diff.behav. in norm_Rational_mg 36";
  37.739  
  37.740 @@ -1285,7 +1278,7 @@
  37.741    cancel_p_ thy (TermC.str2term ("(- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)) /" ^
  37.742                             "(- 18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)"))
  37.743  
  37.744 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.745 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.746  if UnparseC.term t = "(2 + - 1 * x) / (3 + y)" then ()
  37.747  else error "rational.sml: diff.behav. in norm_Rational_mg 37";
  37.748  *)
  37.749 @@ -1296,32 +1289,32 @@
  37.750    cancel_p_ thy (TermC.str2term ("(- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)) /" ^
  37.751                             "(- 18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)"))
  37.752  
  37.753 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.754 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.755  if UnparseC.term t = "(2 + - 1 * x) / (3 + y)" then ()
  37.756  else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
  37.757  *)
  37.758  
  37.759  "----- ?: worked before 0707xx";
  37.760  val t = TermC.str2term "(3 + - 1 * y) / (-9 + y \<up> 2)";
  37.761 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.762 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.763  if UnparseC.term t = "- 1 / (3 + y)"
  37.764  then () else error "rational.sml: - 1 / (3 + y) norm_Rational";
  37.765  
  37.766  "----- SRD Schalk I, p.69 Nr. 456b";
  37.767  val t = TermC.str2term "(b \<up> 3 - b \<up> 2) / (b \<up> 2+b) / (b \<up> 2 - 1)";
  37.768 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.769 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.770  if UnparseC.term t = "b / (1 + 2 * b + b \<up> 2)"
  37.771  then () else error "rational.sml: diff.behav. in norm_Rational_mg 38";
  37.772  
  37.773  "----- SRD Schalk I, p.69 Nr. 457b";
  37.774  val t = TermC.str2term "(16*a \<up> 2 - 9*b \<up> 2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a \<up> 2 - 9*a \<up> 2*b \<up> 2))";
  37.775 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.776 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.777  if UnparseC.term t = "8 * a \<up> 2 + - 6 * a * b + - 12 * a \<up> 2 * b + 9 * a * b \<up> 2"
  37.778  then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
  37.779  
  37.780  "----- Schalk I, p.69 Nr. 458b works since 0707";
  37.781  val t = TermC.str2term "(2*a \<up> 2*x - a \<up> 2) / (a*x - b*x) / (b \<up> 2*(2*x - 1) / (x*(a - b)))";
  37.782 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.783 +(*val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.784  :
  37.785  ###  rls: cancel_p on: (- 1 * a \<up> 2 + 2 * (a \<up> 2 * x)) / (a * x + - 1 * (b * x)) /
  37.786  ((- 1 * b \<up> 2 + 2 * (b \<up> 2 * x)) / (a * x + - 1 * (b * x))) 
  37.787 @@ -1339,13 +1332,13 @@
  37.788  
  37.789  "----- SRD Schalk I, p.69 Nr. 459b";
  37.790  val t = TermC.str2term "(a \<up> 2 - b \<up> 2)/(a*b) / (4*(a+b) \<up> 2/a)";
  37.791 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.792 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.793  if UnparseC.term t = "(a + - 1 * b) / (4 * a * b + 4 * b \<up> 2)" then ()
  37.794  else error "rational.sml: diff.behav. in norm_Rational_mg 41";
  37.795  
  37.796  "----- Schalk I, p.69 Nr. 460b nonterm.SK";
  37.797  val t = TermC.str2term "(9*(x \<up> 2 - 8*x + 16) / (4*(y \<up> 2 - 2*y + 1))) / ((3*x - 12) / (16*y - 16))";
  37.798 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.799 +(*val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.800  exception Div raised
  37.801  
  37.802  BUT
  37.803 @@ -1360,32 +1353,32 @@
  37.804  
  37.805  "----- some variant of the above; was non-terminating before";
  37.806  val t = TermC.str2term "9*(x \<up> 2 - 8*x+16)*(16*y - 16)/(4*(y \<up> 2 - 2*y+1)*(3*x - 12))";
  37.807 -val SOME (t , _) = rewrite_set_ thy false norm_Rational t;
  37.808 +val SOME (t , _) = rewrite_set_ ctxt false norm_Rational t;
  37.809  if UnparseC.term t = "(48 + - 12 * x) / (1 + - 1 * y)"
  37.810  then () else error "some variant of the above; was non-terminating before";
  37.811  
  37.812  "----- SRD Schalk I, p.70 Nr. 472a";
  37.813  val t = TermC.str2term ("((8*x \<up> 2 - 32*y \<up> 2) / (2*x + 4*y))  /  ((4*x - 8*y) / (x + y))");
  37.814 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.815 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.816  if UnparseC.term t = "x + y"
  37.817  then () else error "rational.sml: diff.behav. in norm_Rational_mg 43";
  37.818  
  37.819  "----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
  37.820  val t = TermC.str2term ("(a - (a*b + b \<up> 2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
  37.821  		 "((a - a \<up> 2/(a+b))/(a+(a*b)/(a - b)))");
  37.822 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.823 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.824  if UnparseC.term t = "(2 * a \<up> 3 + 2 * a \<up> 2 * b) / (a \<up> 2 * b + b \<up> 3)"
  37.825  then () else error "rational.sml: diff.behav. in norm_Rational_mg 51";
  37.826  
  37.827  (*SRD Schalk I, p.69 Nr. 461a *)
  37.828  val t = TermC.str2term "(2/(x+3) + 2/(x - 3)) / (8*x/(x \<up> 2 - 9))";
  37.829 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.830 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.831  if UnparseC.term t = "1 / 2"
  37.832  then () else error "rational.sml: diff.behav. in norm_Rational_mg 44";
  37.833  
  37.834  (*SRD Schalk I, p.69 Nr. 464b *)
  37.835  val t = TermC.str2term "(a - a/(a - 2)) / (a + a/(a - 2))";
  37.836 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.837 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.838  if UnparseC.term t = "(- 3 + a) / (- 1 + a)"
  37.839  then () else error "rational.sml: diff.behav. in norm_Rational_mg 45";
  37.840  
  37.841 @@ -1396,21 +1389,21 @@
  37.842      ("("(576 * x \<up> 2 + 1728 * (x * y) + 1296 * y \<up> 2 + - 2916 * z \<up> 2) /" ^
  37.843        "(576 * x \<up> 2 + 864 * (x * y) + 1296 * (x * z))"))
  37.844  
  37.845 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.846 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.847  if UnparseC.term t = "(4 * x + 6 * y + -9 * z) / (4 * x)"
  37.848  then () else error "rational.sml: diff.behav. in norm_Rational_mg 46";
  37.849  *)
  37.850  
  37.851  (*SRD Schalk I, p.69 Nr. 466b *)
  37.852  val t = TermC.str2term "((1 - 7*(x - 2)/(x \<up> 2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x \<up> 2 - 25))";
  37.853 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.854 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.855  if UnparseC.term t = "(25 + - 10 * x + x \<up> 2) / 18"
  37.856  then () else error "rational.sml: diff.behav. in norm_Rational_mg 47";
  37.857  
  37.858  (*SRD Schalk I, p.70 Nr. 469 *)
  37.859  val t = TermC.str2term ("3*b \<up> 2 / (4*a \<up> 2 - 8*a*b + 4*b \<up> 2) / " ^
  37.860    "(a / (a \<up> 2*b - b \<up> 3)  +  (a - b) / (4*a*b \<up> 2 + 4*b \<up> 3)  -  1 / (4*b \<up> 2))");
  37.861 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.862 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.863  if UnparseC.term t = "- 3 * b \<up> 3 / (- 2 * a + 2 * b)"
  37.864  then () else error "rational.sml: diff.behav. in norm_Rational_mg 48";
  37.865  
  37.866 @@ -1569,10 +1562,10 @@
  37.867  val tt = TermC.str2term "(1 * a + 1 * b) * (1 * a + - 1 * b)"(*numerator only*);
  37.868  
  37.869  "----- with rewrite_set_";
  37.870 -val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
  37.871 +val SOME (tt',asm) = rewrite_set_ ctxt false make_polynomial tt;
  37.872  if UnparseC.term tt'= "a \<up> 2 + - 1 * b \<up> 2" then () else error "rls chancel_p 1";
  37.873  val tt = TermC.str2term "((1 * a + - 1 * b) * (1 * a + - 1 * b))"(*denominator only*);
  37.874 -val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
  37.875 +val SOME (tt',asm) = rewrite_set_ ctxt false make_polynomial tt;
  37.876  if UnparseC.term tt' = "a \<up> 2 + - 2 * a * b + b \<up> 2" then () else error "rls chancel_p 2";
  37.877  
  37.878  "----- with Derive.do_one; WN1130912 not investigated further, will be discontinued";
  37.879 @@ -1582,7 +1575,7 @@
  37.880  
  37.881  "--- with simpler ruleset";
  37.882  val {rules, rew_ord= (_, ro), ...} = Rule_Set.rep (assoc_rls "rev_rew_p");
  37.883 -val der = Derive.do_one thy Atools_erls rules ro NONE tt;
  37.884 +val der = Derive.do_one ctxt Atools_erls rules ro NONE tt;
  37.885  if length der = 12 then () else error "WN1130912 rls chancel_p 4";
  37.886  (*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
  37.887  
  37.888 @@ -1591,12 +1584,12 @@
  37.889  (*default_print_depth 99;*) map (Rule.to_string o #2) der; (*default_print_depth 3;*)
  37.890  (*default_print_depth 99;*) map (UnparseC.term o #1 o #3) der; (*default_print_depth 3;*)
  37.891  
  37.892 -val der = Derive.do_one thy Atools_erls rules ro NONE 
  37.893 +val der = Derive.do_one ctxt Atools_erls rules ro NONE 
  37.894  	(TermC.str2term "(1 * a + 1 * b) * (1 * a + - 1 * b)");
  37.895  (*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
  37.896  
  37.897  val {rules, rew_ord=(_,ro),...} = Rule_Set.rep (assoc_rls "rev_rew_p");
  37.898 -val der = Derive.do_one thy Atools_erls rules ro NONE 
  37.899 +val der = Derive.do_one ctxt Atools_erls rules ro NONE 
  37.900  	(TermC.str2term "(1 * a + - 1 * b) * (1 * a + - 1 * b)");
  37.901  (*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
  37.902  (*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*)
  37.903 @@ -1651,17 +1644,17 @@
  37.904  
  37.905  (*1st factor separately simplified *)
  37.906  val t = TermC.str2term "((12*x*y / (9*x \<up> 2 - y \<up> 2))  /  (1 / (3*x - y) \<up> 2 - 1 / (3*x + y) \<up> 2))";
  37.907 -val SOME (t', _) = rewrite_set_ thy false norm_Rational t; 
  37.908 +val SOME (t', _) = rewrite_set_ ctxt false norm_Rational t; 
  37.909  if UnparseC.term t' = "(- 9 * x \<up> 2 + y \<up> 2) / - 1" then () else error "Nr. 480b lhs changed";
  37.910  (*2nd factor separately simplified *)
  37.911  val t = TermC.str2term "((1/(x - 5*y) \<up> 2  -  1/(x + 5*y) \<up> 2)  /  (20*x*y / (x \<up> 2 - 25*y \<up> 2)))";
  37.912 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
  37.913 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
  37.914  if UnparseC.term t' = "- 1 / (- 1 * x \<up> 2 + 25 * y \<up> 2)" then () else error "Nr. 480b rhs changed";
  37.915  
  37.916  "-------- Schalk I, p.70 Nr. 477a: terms are exploding ?!?";
  37.917  val t = TermC.str2term ("b*y/(b - 2*y)/((b \<up> 2 - y \<up> 2)/(b+2*y))  /" ^
  37.918  		 "(b \<up> 2*y + b*y \<up> 2) * (a+x) \<up> 2  /  ((b \<up> 2 - 4*y \<up> 2) * (a+2*x) \<up> 2)");
  37.919 -(*val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
  37.920 +(*val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t;
  37.921  :
  37.922  ###  rls: cancel_p on: (a \<up> 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \<up> 2 * y)) /
  37.923  (b + - 2 * y) /
  37.924 @@ -1691,7 +1684,7 @@
  37.925    ("((a \<up> 2 - b \<up> 2)/(2*a*b) + 2*a*b/(a \<up> 2 - b \<up> 2))  /  ((a \<up> 2 + b \<up> 2)/(2*a*b) + 1)    / " ^
  37.926     "((a \<up> 2 + b \<up> 2) \<up> 2  /  (a + b) \<up> 2)");
  37.927  (* Rewrite.trace_on := true; (*true false*)
  37.928 -rewrite_set_ thy false norm_Rational t;
  37.929 +rewrite_set_ ctxt false norm_Rational t;
  37.930  :
  37.931  ####  rls: cancel_p on: (2 * (a \<up> 7 * b) + 4 * (a \<up> 6 * b \<up> 2) + 6 * (a \<up> 5 * b \<up> 3) +
  37.932   8 * (a \<up> 4 * b \<up> 4) +
  37.933 @@ -1714,7 +1707,7 @@
  37.934  val t = TermC.str2term ("(1/x + 1/y + 1/z)  /  (1/x - 1/y - 1/z)  /  " ^
  37.935    "(2*x \<up> 2 / (x \<up> 2 - z \<up> 2) / (x / (x + z)  +  x / (x - z)))");
  37.936  (* Rewrite.trace_on := true; (*true false*)
  37.937 -rewrite_set_ thy false norm_Rational t;
  37.938 +rewrite_set_ ctxt false norm_Rational t;
  37.939  :
  37.940  ####  rls: cancel_p on: (2 * (x \<up> 6 * (y \<up> 2 * z)) + 2 * (x \<up> 6 * (y * z \<up> 2)) +
  37.941   2 * (x \<up> 5 * (y \<up> 2 * z \<up> 2)) +
  37.942 @@ -1733,11 +1726,11 @@
  37.943  (* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:
  37.944  
  37.945  val t = TermC.str2term "(a-b) \<up> 3 * (x+y) \<up> 4";
  37.946 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.947 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.948  UnparseC.term t;
  37.949  "a \<up> 3 * x \<up> 4 + 4 * a \<up> 3 * x \<up> 3 * y +6 * a \<up> 3 * x \<up> 2 * y \<up> 2 +4 * a \<up> 3 * x * y \<up> 3 +a \<up> 3 * y \<up> 4 +-3 * a \<up> 2 * b * x \<up> 4 +- 12 * a \<up> 2 * b * x \<up> 3 * y +- 18 * a \<up> 2 * b * x \<up> 2 * y \<up> 2 +- 12 * a \<up> 2 * b * x * y \<up> 3 +-3 * a \<up> 2 * b * y \<up> 4 +3 * a * b \<up> 2 * x \<up> 4 +12 * a * b \<up> 2 * x \<up> 3 * y +18 * a * b \<up> 2 * x \<up> 2 * y \<up> 2 +12 * a * b \<up> 2 * x * y \<up> 3 +3 * a * b \<up> 2 * y \<up> 4 +- 1 * b \<up> 3 * x \<up> 4 +-4 * b \<up> 3 * x \<up> 3 * y +-6 * b \<up> 3 * x \<up> 2 * y \<up> 2 +-4 * b \<up> 3 * x * y \<up> 3 +- 1 * b \<up> 3 * y \<up> 4";
  37.950  val t = TermC.str2term "((x+y) \<up> 2 * (a-b) \<up> 5)";
  37.951 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.952 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.953  UnparseC.term t;
  37.954  "a \<up> 5 * x \<up> 2 + 2 * a \<up> 5 * x * y + a \<up> 5 * y \<up> 2 +-5 * a \<up> 4 * b * x \<up> 2 +- 10 * a \<up> 4 * b * x * y +-5 * a \<up> 4 * b * y \<up> 2 +10 * a \<up> 3 * b \<up> 2 * x \<up> 2 +20 * a \<up> 3 * b \<up> 2 * x * y +10 * a \<up> 3 * b \<up> 2 * y \<up> 2 +- 10 * a \<up> 2 * b \<up> 3 * x \<up> 2 +- 20 * a \<up> 2 * b \<up> 3 * x * y +- 10 * a \<up> 2 * b \<up> 3 * y \<up> 2 +5 * a * b \<up> 4 * x \<up> 2 +10 * a * b \<up> 4 * x * y +5 * a * b \<up> 4 * y \<up> 2 +- 1 * b \<up> 5 * x \<up> 2 +- 2 * b \<up> 5 * x * y +- 1 * b \<up> 5 * y \<up> 2";
  37.955  
  37.956 @@ -1748,7 +1741,7 @@
  37.957  		 "(1/(3*x - y) \<up> 2 - 1/(3*x + y) \<up> 2)) *" ^
  37.958  		 "(1/(x - 5*y) \<up> 2 - 1/(x + 5*y) \<up> 2)/" ^
  37.959  		 "(20*x*y/(x \<up> 2 - 25*y \<up> 2))");
  37.960 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
  37.961 +(*val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
  37.962  :
  37.963  ####  rls: cancel_p on: (19440 * (x \<up> 8 * y \<up> 2) + -490320 * (x \<up> 6 * y \<up> 4) +
  37.964   108240 * (x \<up> 4 * y \<up> 6) +
    38.1 --- a/test/Tools/isac/Knowledge/root.sml	Thu Jul 28 11:43:27 2022 +0200
    38.2 +++ b/test/Tools/isac/Knowledge/root.sml	Sat Jul 30 16:47:45 2022 +0200
    38.3 @@ -16,13 +16,13 @@
    38.4  "----------- rls Root_erls ------------------------------";
    38.5  "----------- rls Root_erls ------------------------------";
    38.6  val t = TermC.str2term "sqrt 1";
    38.7 -val SOME (t',_) = rewrite_set_ thy false Root_erls t;
    38.8 +val SOME (t',_) = rewrite_set_ ctxt false Root_erls t;
    38.9  if UnparseC.term t' = "1" then () else error "root.sml: diff.behav. sqrt 1";
   38.10  
   38.11  val t = TermC.str2term "sqrt (- 1)";
   38.12 -val NONE = rewrite_set_ thy false Root_erls t;
   38.13 +val NONE = rewrite_set_ ctxt false Root_erls t;
   38.14  
   38.15  val t = TermC.str2term "sqrt 0";
   38.16 -val SOME (t',_) = rewrite_set_ thy false Root_erls t;
   38.17 +val SOME (t',_) = rewrite_set_ ctxt false Root_erls t;
   38.18  if UnparseC.term t' = "0" then () else error "root.sml: diff.behav. sqrt 1";
   38.19  
    39.1 --- a/test/Tools/isac/Knowledge/rootrat.sml	Thu Jul 28 11:43:27 2022 +0200
    39.2 +++ b/test/Tools/isac/Knowledge/rootrat.sml	Sat Jul 30 16:47:45 2022 +0200
    39.3 @@ -26,14 +26,14 @@
    39.4  ("- 1 * x = - (2 / 2) + sqrt ((2 / 2) \<up> 2 - -8) | \nx = - 1 * (- (2 / 2) + - 1 * sqrt ((2 / 2) \<up> 2 - -8))");
    39.5  
    39.6  val rls = calculate_Rational;
    39.7 -val SOME (t', asm) = rewrite_set_ thy true rls t;
    39.8 +val SOME (t', asm) = rewrite_set_ ctxt true rls t;
    39.9  if UnparseC.term t' =
   39.10    "- 1 * x = - 1 + sqrt (2 \<up> 2 / 2 \<up> 2 - - 8) \<or>\nx = - 1 * (- 1 + - 1 * sqrt (2 \<up> 2 / 2 \<up> 2 - - 8))"
   39.11  (*"- 1 * x = - 1 + sqrt (1 \<up> 2 - -8) | x = - 1 * (- 1 + - 1 * sqrt (1 \<up> 2 - -8))" (*1*)*)
   39.12  then () else error "rls calculate_Rational CHANGED";
   39.13  
   39.14  val rls = calculate_RootRat;
   39.15 -val SOME (t, asm) = rewrite_set_ thy true rls t;
   39.16 +val SOME (t, asm) = rewrite_set_ ctxt true rls t;
   39.17  if UnparseC.term t =
   39.18  "- 1 * x = - 1 + sqrt (2 \<up> 2 / 2 \<up> 2 - - 8) \<or>\nx = - 1 * - 1 + - 1 * (- 1 * sqrt (2 \<up> 2 / 2 \<up> 2 - - 8))"
   39.19  then () else error "rls calculate_RootRat CHANGED";
    40.1 --- a/test/Tools/isac/Knowledge/rootrateq.sml	Thu Jul 28 11:43:27 2022 +0200
    40.2 +++ b/test/Tools/isac/Knowledge/rootrateq.sml	Sat Jul 30 16:47:45 2022 +0200
    40.3 @@ -29,37 +29,37 @@
    40.4  "------------ tests on predicates  -------------------------------";
    40.5  "------------ tests on predicates  -------------------------------";
    40.6  val t1 = TermC.parseNEW' ctxt "(-8 - sqrt(x) + x \<up> 2) is_rootRatAddTerm_in x";
    40.7 -val SOME (t,_) = rewrite_set_ @{theory "RootRatEq"} false RootRatEq_prls t1;
    40.8 +val SOME (t,_) = rewrite_set_ ctxt  false RootRatEq_prls t1;
    40.9  if (UnparseC.term t) = "False" then ()
   40.10   else  error "rootrateq.sml: diff.behav. 1 in is_rootRatAddTerm_in";
   40.11  
   40.12  val t1 = TermC.parseNEW' ctxt "(1/x) is_rootRatAddTerm_in x";
   40.13 -val SOME (t,_) = rewrite_set_ @{theory "RootRatEq"} false RootRatEq_prls t1;
   40.14 +val SOME (t,_) = rewrite_set_ ctxt false RootRatEq_prls t1;
   40.15  if (UnparseC.term t) = "False" then ()
   40.16   else  error "rootrateq.sml: diff.behav. 2 in is_rootRatAddTerm_in";
   40.17  
   40.18  val t1 = TermC.parseNEW' ctxt "(1/sqrt(x)) is_rootRatAddTerm_in x";
   40.19 -val SOME (t,_) = rewrite_set_ @{theory "RootRatEq"} false RootRatEq_prls t1;
   40.20 +val SOME (t,_) = rewrite_set_ ctxt false RootRatEq_prls t1;
   40.21  if (UnparseC.term t) = "False" then ()
   40.22   else  error "rootrateq.sml: diff.behav. 3 in is_rootRatAddTerm_in";
   40.23  
   40.24  val t1 = TermC.parseNEW' ctxt "(1/(sqrt(x)+1)) is_rootRatAddTerm_in x";
   40.25 -val SOME (t,_) = rewrite_set_ @{theory "RootRatEq"} false RootRatEq_prls t1;
   40.26 +val SOME (t,_) = rewrite_set_ ctxt false RootRatEq_prls t1;
   40.27  if (UnparseC.term t) = "True" then ()
   40.28   else  error "rootrateq.sml: diff.behav. 4 in is_rootRatAddTerm_in";
   40.29  
   40.30  val t1 = TermC.parseNEW' ctxt "(3 + 1/(1+sqrt(x))) is_rootRatAddTerm_in x";
   40.31 -val SOME (t,_) = rewrite_set_ @{theory "RootRatEq"} false RootRatEq_prls t1;
   40.32 +val SOME (t,_) = rewrite_set_ ctxt false RootRatEq_prls t1;
   40.33  if (UnparseC.term t) = "True" then ()
   40.34   else  error "rootrateq.sml: diff.behav. 5 in is_rootRatAddTerm_in";
   40.35  
   40.36  val t1 = TermC.parseNEW' ctxt "(1/(1+sqrt(y)) + 3 + 1/(1+sqrt(x))) is_rootRatAddTerm_in x";
   40.37 -val SOME (t,_) = rewrite_set_ @{theory "RootRatEq"} false RootRatEq_prls t1;
   40.38 +val SOME (t,_) = rewrite_set_ ctxt false RootRatEq_prls t1;
   40.39  if (UnparseC.term t) = "True" then ()
   40.40   else  error "rootrateq.sml: diff.behav. 6 in is_rootRatAddTerm_in";
   40.41  
   40.42  val t1 = TermC.parseNEW' ctxt "(1/(1+sqrt(x)) + 3 + 1/(1+sqrt(y))) is_rootRatAddTerm_in x";
   40.43 -val SOME (t,_) = rewrite_set_ @{theory "RootRatEq"} false RootRatEq_prls t1;
   40.44 +val SOME (t,_) = rewrite_set_ ctxt false RootRatEq_prls t1;
   40.45  if (UnparseC.term t) = "True" then ()
   40.46   else  error "rootrateq.sml: diff.behav. 7 in is_rootRatAddTerm_in";
   40.47  
    41.1 --- a/test/Tools/isac/Knowledge/simplify.sml	Thu Jul 28 11:43:27 2022 +0200
    41.2 +++ b/test/Tools/isac/Knowledge/simplify.sml	Sat Jul 30 16:47:45 2022 +0200
    41.3 @@ -106,7 +106,6 @@
    41.4      val cmI = if mI = MethodC.id_empty then mI' else mI;
    41.5      val {ppc = mpc, prls, pre, ...} = MethodC.from_store cmI;    (*..MethodC ?*)
    41.6  
    41.7 -(*+*)Rewrite.trace_on := false; (*false true*)
    41.8  (** ) val (preok as false, _) = Pre_Conds.check prls pre pbl 0;                       ( *isa*)
    41.9  (**) val (preok as true, _) = Pre_Conds.check prls pre pbl 0;                        (*isa2*)
   41.10   (*####  eval asms: "14 * x * y / (x * y) is_ratpolyexp = False"                       (*isa*)
    42.1 --- a/test/Tools/isac/MathEngBasic/rewrite.sml	Thu Jul 28 11:43:27 2022 +0200
    42.2 +++ b/test/Tools/isac/MathEngBasic/rewrite.sml	Sat Jul 30 16:47:45 2022 +0200
    42.3 @@ -88,7 +88,7 @@
    42.4  val thm =  @{thm add.commute};
    42.5  val tm = @{term "x + y*z::real"};
    42.6  
    42.7 -val SOME (r,_) = (rewrite_ thy dummy_ord Rule_Set.empty false thm tm);
    42.8 +val SOME (r,_) = (rewrite_ ctxt dummy_ord Rule_Set.empty false thm tm);
    42.9  (*is displayed on _TOP_ of <response> buffer...*)
   42.10  Pretty.writeln (Proof_Context.pretty_term_abbrev @{context} r);
   42.11  if r = @{term "y*z + x::real"}
   42.12 @@ -97,19 +97,19 @@
   42.13  "----- rewriting a subterm";
   42.14  val tm = @{term "w*(x + y*z)::real"};
   42.15  
   42.16 -val SOME (r, _) = (rewrite_ thy dummy_ord Rule_Set.empty false thm tm);
   42.17 +val SOME (r, _) = (rewrite_ ctxt dummy_ord Rule_Set.empty false thm tm);
   42.18  
   42.19  "----- ordered rewriting";
   42.20  fun tord (_:subst) pp = LibraryC.termless pp;
   42.21  if tord [] (@{term "x + y*z::real"}, @{term "y*z + x::real"}) then ()
   42.22  else error "rewrite.sml diff.behav. in ord.rewr.";
   42.23  
   42.24 -val NONE = (rewrite_ thy tord Rule_Set.empty false thm tm);
   42.25 +val NONE = (rewrite_ ctxt tord Rule_Set.empty false thm tm);
   42.26  (*is displayed on _TOP_ of <response> buffer...*)
   42.27  Pretty.writeln (Proof_Context.pretty_term_abbrev @{context} r);
   42.28  
   42.29  val tm = @{term "x*y + z::real"};
   42.30 -val SOME (r,_) = (rewrite_ thy tord Rule_Set.empty false thm tm);
   42.31 +val SOME (r, _) = (rewrite_ ctxt tord Rule_Set.empty false thm tm);
   42.32  
   42.33  
   42.34  "----------- conditional rewriting without Isac's thys -----------------------------------------";
   42.35 @@ -150,7 +150,7 @@
   42.36  val thm =  @{thm nonzero_divide_mult_cancel_right};
   42.37  val tm = @{term "x / (2 * x)::real"};
   42.38  
   42.39 -val SOME (rew, asm) = (rewrite_ thy dummy_ord Rule_Set.empty false thm tm);
   42.40 +val SOME (rew, asm) = (rewrite_ ctxt dummy_ord Rule_Set.empty false thm tm);
   42.41  
   42.42  if rew = @{term "1 / 2::real"} then () (* the rewrite is _NO_ Trueprop *)
   42.43  else error "rewrite.sml diff.result in cond.rew.";
   42.44 @@ -168,7 +168,7 @@
   42.45  val tm = @{term "x / (2 * x)::real"};
   42.46  val erls = eval_rls;
   42.47  
   42.48 -(**)val SOME (rew, asm) = (rewrite_ thy dummy_ord Rule_Set.empty false thm tm);
   42.49 +(**)val SOME (rew, asm) = rewrite_ ctxt dummy_ord Rule_Set.empty false thm tm;
   42.50  (** )exception TERM raised (line 196 of "~~/src/HOL/Tools/hologic.ML"):
   42.51    dest_Trueprop
   42.52    ?b \<noteq> 0 \<Longrightarrow> ?b / (?a * ?b) = 1 / ?a( **)
   42.53 @@ -177,7 +177,7 @@
   42.54  "~~~~~ fun rewrite__ , args:"; val (thy, i, bdv, tless, rls, put_asm, thm, ct) =
   42.55    (thy, 1, []: Subst.T, rew_ord, erls, bool, thm, term);
   42.56  
   42.57 -(**) val (t', asms, _(*lrd*), rew) = rew_sub thy i bdv tless rls put_asm ([(*root of the term*)]: TermC.path)
   42.58 +(**) val (t', asms, _(*lrd*), rew) = rew_sub ctxt i bdv tless rls put_asm ([(*root of the term*)]: TermC.path)
   42.59  		  (TermC.inst_bdv bdv (Eval.norm (Thm.prop_of thm))) ct;
   42.60  (** )exception TERM raised (line 196 of "~~/src/HOL/Tools/hologic.ML"):
   42.61    dest_Trueprop
   42.62 @@ -195,10 +195,10 @@
   42.63  (*+*)UnparseC.term r' = "x \<noteq> 0 \<Longrightarrow> x / (2 * x) = 1 / 2";
   42.64  (*+*)r';
   42.65      val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r'
   42.66 -    val _ = trace_in2 i "eval asms" thy r';
   42.67 -        val (simpl_p', nofalse) = eval__true thy (i + 1) p' bdv rls;
   42.68 +    val _ = trace_in2 ctxt i "eval asms" r';
   42.69 +        val (simpl_p', nofalse) = eval__true ctxt (i + 1) p' bdv rls;
   42.70  	      (*if*) nofalse (*then*);
   42.71 -      val (t'', p'') = (trace_in4 i "asms accepted" thy p' simpl_p'; (t',simpl_p'));
   42.72 +      val (t'', p'') = (trace_in4 ctxt i "asms accepted" p' simpl_p'; (t',simpl_p'));
   42.73  (*##  asms accepted: [x \<noteq> 0]   stored: [x \<noteq> 0] *)
   42.74  
   42.75  (*+*)if (UnparseC.term t'', map UnparseC.term p'') = ("1 / 2", ["x \<noteq> 0"]) then ()
   42.76 @@ -210,7 +210,7 @@
   42.77  "----------- step through 'and rew_sub': ----------------";
   42.78  (*and make asms without Trueprop, beginning with the result:*)
   42.79  val tm = @{term "x / (2 * x)::real"};
   42.80 -val (t', asm, _, _) = rew_sub thy 0 [] dummy_ord Rule_Set.empty true [] (Thm.prop_of thm) tm;
   42.81 +val (t', asm, _, _) = rew_sub ctxt 0 [] dummy_ord Rule_Set.empty true [] (Thm.prop_of thm) tm;
   42.82  (*show_types := false;*)
   42.83  "----- evaluate arguments";
   42.84  val (thy, i, bdv, tless, rls, put_asm, lrd, r, t) = 
   42.85 @@ -250,25 +250,25 @@
   42.86  "----- step 1: args for rew_";
   42.87  val ((t', asm'), (rules as r::rs), t) = ((TermC.empty, []), equs, t);
   42.88  "----- step 2: rew_sub";
   42.89 -rew_sub thy 1 [] ord erls false [] (HOLogic.Trueprop $ r) t;
   42.90 +rew_sub ctxt 1 [] ord erls false [] (HOLogic.Trueprop $ r) t;
   42.91  "----- step 3: step through rew_sub -- inefficient: goes into subterms";
   42.92  
   42.93  
   42.94 -val SOME (t', _) = rewrite_terms_ thy dummy_ord Rule_Set.Empty equs t;
   42.95 +val SOME (t', _) = rewrite_terms_ ctxt dummy_ord Rule_Set.Empty equs t;
   42.96  writeln "---------- rewrite_terms_  1---------------------------";
   42.97  if UnparseC.term t' = "M_b 0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2" then ()
   42.98  else error "rewrite.sml rewrite_terms_ [x = 0]";
   42.99  
  42.100  val equs = [TermC.str2term "M_b 0 = 0"];
  42.101  val t = TermC.str2term "M_b 0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2";
  42.102 -val SOME (t', _) = rewrite_terms_ thy dummy_ord Rule_Set.Empty equs t;
  42.103 +val SOME (t', _) = rewrite_terms_ ctxt dummy_ord Rule_Set.Empty equs t;
  42.104  writeln "---------- rewrite_terms_  2---------------------------";
  42.105  if UnparseC.term t' = "0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2" then ()
  42.106  else error "rewrite.sml rewrite_terms_ [M_b 0 = 0]";
  42.107  
  42.108  val equs = [TermC.str2term "x = 0", TermC.str2term"M_b 0 = 0"];
  42.109  val t = TermC.str2term "M_b x = - 1 * q_0 * x \<up> 2 / 2 + x * c + c_2";
  42.110 -val SOME (t', _) = rewrite_terms_ thy dummy_ord Rule_Set.Empty equs t;
  42.111 +val SOME (t', _) = rewrite_terms_ ctxt dummy_ord Rule_Set.Empty equs t;
  42.112  writeln "---------- rewrite_terms_  3---------------------------";
  42.113  if UnparseC.term t' = "0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2" then ()
  42.114  else error "rewrite.sml rewrite_terms_ [x = 0, M_b 0 = 0]";
  42.115 @@ -329,7 +329,7 @@
  42.116  if UnparseC.terms asms = "[\"a + b is_expanded\", \"c is_expanded\"]"
  42.117  then () else error "rewrite.sml: prepat cancel subst";
  42.118  
  42.119 -if ([], true) = eval__true thy 0 asms [] erls
  42.120 +if ([], true) = eval__true ctxt 0 asms [] erls
  42.121  then () else error "rewrite.sml: prepat cancel eval__true";
  42.122  
  42.123  "===== Rational.thy: add_fractions_p ===";
  42.124 @@ -343,7 +343,7 @@
  42.125  (* erls got from Rrls {erls, prepat, scr = Rfuns {normal_form, ...}, ...} *)
  42.126  
  42.127  val subst = Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty);
  42.128 -if ([], true) = eval__true thy 0 (map (Envir.subst_term subst) pres) [] erls
  42.129 +if ([], true) = eval__true ctxt 0 (map (Envir.subst_term subst) pres) [] erls
  42.130  then () else error "rewrite.sml: prepat add_fractions_p";
  42.131  
  42.132  "===== Poly.thy: order_mult_ ===";
  42.133 @@ -362,7 +362,7 @@
  42.134  if UnparseC.terms asms = "[\"x \<up> 2 * x is_multUnordered\"]"
  42.135  then () else error "rewrite.sml: prepat order_mult_ subst";
  42.136  
  42.137 -if ([], true) = eval__true thy 0 asms [] erls
  42.138 +if ([], true) = eval__true ctxt 0 asms [] erls
  42.139  then () else error "rewrite.sml: prepat order_mult_ eval__true";
  42.140  
  42.141  
  42.142 @@ -396,16 +396,16 @@
  42.143                            Const (\<^const_name>\<open>True\<close>, _))) => ()
  42.144    | _ => error "rewrite.sml diff. eval_is_multUnordered 2b";
  42.145  
  42.146 -tracing "----- begin rewrite x \<up> 2 * x ---"; Rewrite.trace_on := false; (*true false*)
  42.147 -val SOME (t', _) = rewrite_set_ thy true order_mult_ t;
  42.148 -tracing "----- end rewrite x \<up> 2 * x ---"; Rewrite.trace_on := false; (*true false*)
  42.149 +tracing "----- begin rewrite x \<up> 2 * x ---";
  42.150 +val SOME (t', _) = rewrite_set_ ctxt true order_mult_ t;
  42.151 +tracing "----- end rewrite x \<up> 2 * x ---";
  42.152  if UnparseC.term t' = "x * x \<up> 2" then ()
  42.153  else error "rewrite.sml Poly.is_multUnordered doesn't work";
  42.154  
  42.155  (* for achieving the previous result, the following code was taken apart *)
  42.156  "----- rewrite__set_ ---";
  42.157  val (thy, i, _, _, (rrls as Rrls _), t) = (thy, 0, true, [], order_mult_, tm);
  42.158 -	val (t', asm, rew) = app_rev thy (i+1) rrls t;
  42.159 +	val (t', asm, rew) = app_rev ctxt (i+1) rrls t;
  42.160  "----- app_rev ---";
  42.161  val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
  42.162  	fun chk_prepat thy erls [] t = true
  42.163 @@ -414,7 +414,7 @@
  42.164  		    (let val subst: Type.tyenv * Envir.tenv = 
  42.165  			     Pattern.match thy (pat, t)
  42.166  					    (Vartab.empty, Vartab.empty)
  42.167 -		     in snd (eval__true thy (i+1) 
  42.168 +		     in snd (eval__true ctxt (i+1) 
  42.169  					(map (Envir.subst_term subst) pres)
  42.170  					[] erls)
  42.171  		     end)
  42.172 @@ -440,7 +440,7 @@
  42.173  		    (let val subst: Type.tyenv * Envir.tenv = 
  42.174  			     Pattern.match thy (pat, t)
  42.175  					    (Vartab.empty, Vartab.empty)
  42.176 -		     in snd (eval__true thy (i+1) 
  42.177 +		     in snd (eval__true ctxt (i+1) 
  42.178  					(map (Envir.subst_term subst) pres)
  42.179  					[] erls)
  42.180  		     end)
  42.181 @@ -467,7 +467,7 @@
  42.182  val (thy, i, asms, bdv, rls) = 
  42.183      (thy, (i+1), [TermC.str2term "(x \<up> 2 * x) is_multUnordered"], 
  42.184       [] : Subst.T, erls);
  42.185 -case eval__true thy i asms bdv rls of 
  42.186 +case eval__true ctxt i asms bdv rls of 
  42.187      ([], true) => ()
  42.188    | _ => error "rewrite.sml: diff. is_multUnordered, eval__true";
  42.189  
  42.190 @@ -481,7 +481,7 @@
  42.191  
  42.192  val (thy, ro, er, inst) = 
  42.193      (@{theory "Isac_Knowledge"}, tless_true, eval_rls, [(@{term "bdv::real"}, @{term "x::real"})]);
  42.194 -val SOME (t, _) = rewrite_ thy ro er true thm t; (*real TermC.matches 'a ?via ring? etc*)
  42.195 +val SOME (t, _) = rewrite_ ctxt ro er true thm t; (*real TermC.matches 'a ?via ring? etc*)
  42.196  
  42.197  "----------- fun rewrite_set_ .. RatEq_eliminate step into to fun chk --------------------------";
  42.198  "----------- fun rewrite_set_ .. RatEq_eliminate step into to fun chk --------------------------";
  42.199 @@ -492,9 +492,9 @@
  42.200  val rls = assoc_rls "RatEq_eliminate"
  42.201  
  42.202  val SOME (t''''', asm''''') =
  42.203 -           rewrite_set_ thy true rls t;
  42.204 +           rewrite_set_ ctxt true rls t;
  42.205  "~~~~~ fun rewrite_set_ , args:"; val (thy, bool, rls, term) = (thy, true, rls, t);
  42.206 -           rewrite__set_ thy 1 bool [] rls term;
  42.207 +           rewrite__set_ ctxt 1 bool [] rls term;
  42.208  "~~~~~ and rewrite__set_ , args:"; val (thy, i, put_asm, bdv, rls, ct)
  42.209    = (thy, 1, bool, []:Subst.T, rls, term);
  42.210  
  42.211 @@ -682,7 +682,7 @@
  42.212  val rls = norm_equation;
  42.213  val term = TermC.str2term "x + 1 = 2";
  42.214  
  42.215 -(**)val SOME (t, asm) = rewrite_set_ thy false rls term;
  42.216 +(**)val SOME (t, asm) = rewrite_set_ ctxt false rls term;
  42.217  (** )#####  try thm: "root_ge0" 
  42.218  exception TERM raised (line 271 of "~~/src/HOL/Tools/hologic.ML"):
  42.219    dest_eq
    43.1 --- a/test/Tools/isac/MathEngine/mathengine-stateless.sml	Thu Jul 28 11:43:27 2022 +0200
    43.2 +++ b/test/Tools/isac/MathEngine/mathengine-stateless.sml	Sat Jul 30 16:47:45 2022 +0200
    43.3 @@ -264,6 +264,7 @@
    43.4  "----------- improved fun getTactic for interSteps and numeral calculations --";
    43.5  "----------- improved fun getTactic for interSteps and numeral calculations --";
    43.6  "----------- improved fun getTactic for interSteps and numeral calculations --";
    43.7 +val ctxt = Proof_Context.init_global @{theory Test};
    43.8  reset_states (); val cI = 1;
    43.9  CalcTree [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
   43.10    ("Test",["sqroot-test", "univariate", "equation", "test"],["Test", "squ-equ-test-subpbl1"]))];
   43.11 @@ -322,6 +323,6 @@
   43.12      fun derivat ([]:(term * rule * (term * term list)) list) = TermC.empty
   43.13        | derivat dt = (#1 o #3 o last_elem) dt
   43.14      fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1=t2
   43.15 -    (*val  fod = *)Derive.do_one (Isac"") erls rules (snd rew_ord) NONE  fo;
   43.16 -    (*val ifod = *)Derive.do_one (Isac"") erls rules (snd rew_ord) NONE ifo;
   43.17 +    (*val  fod = *)Derive.do_one ctxt erls rules (snd rew_ord) NONE  fo;
   43.18 +    (*val ifod = *)Derive.do_one ctxt erls rules (snd rew_ord) NONE ifo;
   43.19  
    44.1 --- a/test/Tools/isac/Minisubpbl/200-start-method-NEXT_STEP.sml	Thu Jul 28 11:43:27 2022 +0200
    44.2 +++ b/test/Tools/isac/Minisubpbl/200-start-method-NEXT_STEP.sml	Sat Jul 30 16:47:45 2022 +0200
    44.3 @@ -6,6 +6,7 @@
    44.4  "----------- Minisubplb/200-start-method-NEXT_STEP.sml ---------------------------------------";
    44.5  "----------- Minisubplb/200-start-method-NEXT_STEP.sml ---------------------------------------";
    44.6  "----------- Minisubplb/200-start-method-NEXT_STEP.sml ---------------------------------------";
    44.7 +val ctxt = Proof_Context.init_global @{theory}
    44.8  val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
    44.9  val (dI',pI',mI') =
   44.10    ("Test", ["sqroot-test", "univariate", "equation", "test"],
   44.11 @@ -73,8 +74,7 @@
   44.12  (*+* )UnparseC.term res = "1 + (x + - 2) = 0"; ( *isa*)
   44.13  (*+*)if UnparseC.term res = "- 1 + x = 0" (*isa2*) then () else error "Test_simplify CHANGED";
   44.14  
   44.15 -Rewrite.trace_on := false; (*true false*)
   44.16 -val SOME (form', _) = rewrite_set_ @{theory Test} true Test_simplify form;
   44.17 +val SOME (form', _) = rewrite_set_ ctxt true Test_simplify form;
   44.18  
   44.19  (*+* )UnparseC.term form' = "1 + (x + - 2) = 0"; ( *isa*)
   44.20  (*+*)if UnparseC.term form' = "- 1 + x = 0" (*isa2*) then () else error "Test_simplify CHANGED";
    45.1 --- a/test/Tools/isac/Minisubpbl/300-init-subpbl.sml	Thu Jul 28 11:43:27 2022 +0200
    45.2 +++ b/test/Tools/isac/Minisubpbl/300-init-subpbl.sml	Sat Jul 30 16:47:45 2022 +0200
    45.3 @@ -111,7 +111,7 @@
    45.4  "~~~~~ from fun eval_leaf \<longrightarrow> fun check_leaf return val:"; val ((Program.Tac stac, a'))
    45.5    = ((Program.Tac (subst_atomic E t), NONE : term option));
    45.6          val stac' =
    45.7 -            Rewrite.eval_prog_expr (Proof_Context.theory_of ctxt) srls 
    45.8 +            Rewrite.eval_prog_expr ctxt srls 
    45.9                (subst_atomic (Env.update_opt E (a,v)) stac);
   45.10  
   45.11      (Program.Tac stac', a'); (*return from check_leaf*) 
    46.1 --- a/test/Tools/isac/ProgLang/auto_prog.sml	Thu Jul 28 11:43:27 2022 +0200
    46.2 +++ b/test/Tools/isac/ProgLang/auto_prog.sml	Sat Jul 30 16:47:45 2022 +0200
    46.3 @@ -27,6 +27,7 @@
    46.4  "-------- check auto-gen.script for Rewrite_Set_Inst -------------------------------------------";
    46.5  val rls = assoc_rls "integration";
    46.6  val thy' = @{theory "Integrate"}
    46.7 +val ctxt = Proof_Context.init_global thy'
    46.8  val t = @{term "ttt :: real"};
    46.9  
   46.10   Auto_Prog.gen thy' t rls;
   46.11 @@ -53,7 +54,7 @@
   46.12      Istate.init_detail (Rewrite_Set_Inst (["(''bdv'', x)"], "integration_rules")) (TermC.str2term "someTermWithBdv");
   46.13  "~~~~~ fun init_detail , args:"; val ((Tactic.Rewrite_Set_Inst (subs, rls)), t)
   46.14    = ((Rewrite_Set_Inst (["(''bdv'', x)"], "integration_rules")), TermC.str2term "someTermWithBdv");
   46.15 -      val v = case Subst.T_from_input (ThyC.get_theory "Isac_Knowledge") subs of
   46.16 +      val v = case Subst.T_from_input ctxt subs of
   46.17          (_, v) :: _ => v;
   46.18      (*case*) assoc_rls rls (*of*);
   46.19  
    47.1 --- a/test/Tools/isac/ProgLang/evaluate.sml	Thu Jul 28 11:43:27 2022 +0200
    47.2 +++ b/test/Tools/isac/ProgLang/evaluate.sml	Sat Jul 30 16:47:45 2022 +0200
    47.3 @@ -48,6 +48,7 @@
    47.4  (* fun rewrite__set_ \<longrightarrow> fun rew_once works the same way *)
    47.5  val t = TermC.str2term "((1+2)*4/3) \<up> 2";
    47.6  val thy = @{theory};
    47.7 +val ctxt = Proof_Context.init_global @{theory}
    47.8  val times =  ("Groups.times_class.times", eval_binop "#mult_") : string * Eval_Def.eval_fn;
    47.9  val plus =   ("Groups.plus_class.plus", eval_binop "#add_") : string * Eval_Def.eval_fn;
   47.10  val divide = ("Rings.divide_class.divide", eval_cancel "#divide_e") : string * Eval_Def.eval_fn;
   47.11 @@ -55,22 +56,22 @@
   47.12  
   47.13  "~~~~~ fun calculate_ , args:"; val (thy, isa_fn, t) = (thy, plus, t);
   47.14  val SOME ("#: 1 + 2 = 3", adh_thm) = adhoc_thm @{theory} isa_fn t;
   47.15 -val SOME (t', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
   47.16 +val SOME (t', []) = rewrite__ ctxt 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
   47.17  if UnparseC.term t' = "(3 * 4 / 3) \<up> 2" then () else error "calculate_  1 + 2 = 3  changed";
   47.18  
   47.19  "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, times, t');
   47.20  val SOME ("#: 3 * 4 = 12", adh_thm) = adhoc_thm @{theory} isa_fn t';
   47.21 -val SOME (t'', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
   47.22 +val SOME (t'', []) = rewrite__ ctxt 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
   47.23  if UnparseC.term t'' = "(12 / 3) \<up> 2" then () else error "calculate_  3 * 4 = 12  changed";
   47.24  
   47.25  "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, divide, t'');
   47.26  val SOME ("#divide_e12_3", adh_thm) = adhoc_thm @{theory} isa_fn t;
   47.27 -val SOME (t''', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
   47.28 +val SOME (t''', []) = rewrite__ ctxt 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
   47.29  if UnparseC.term t''' = "4 \<up> 2" then () else error "calculate_  12 / 3 = 4  changed";
   47.30  
   47.31  "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, pow, t''');
   47.32  val SOME ("#: 4 \<up> 2 = 16", adh_thm) = adhoc_thm @{theory} isa_fn t;
   47.33 -val SOME (t'''', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
   47.34 +val SOME (t'''', []) = rewrite__ ctxt 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
   47.35  if UnparseC.term t'''' = "16" then () else error "calculate_  12 / 3 = 4  changed";
   47.36  
   47.37  "----------- calculate from Prog --------------------------------- -----------------------------";
   47.38 @@ -121,7 +122,7 @@
   47.39   val op_ = the (LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE"));
   47.40   val ct = @{term
   47.41     "sqrt (x \<up> 2 + -3 * x) = (-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))"};
   47.42 -case calculate_ thy op_ ct of
   47.43 +case calculate_ ctxt op_ ct of
   47.44    SOME _ => ()
   47.45  | NONE => error "calculate_ test-root-equ changed";
   47.46  (*
   47.47 @@ -134,13 +135,13 @@
   47.48   val ctxt = (ThyC.id_to_ctxt "Test")
   47.49   val t = TermC.parseNEW' ctxt "6 / 2";
   47.50   val rls = Test_simplify;
   47.51 - val (t,_) = the (rewrite_set_ thy false rls t);
   47.52 + val (t,_) = the (rewrite_set_ ctxt false rls t);
   47.53  (*val t = Free ("3", "Real.real") : term*)
   47.54  
   47.55  (*--------------(3): is_num works ?: -------------------------------------*)
   47.56   val t = TermC.parseNEW' ctxt "2 is_num";
   47.57   TermC.atomty t;
   47.58 - rewrite_set_ @{theory Test} false tval_rls t;
   47.59 + rewrite_set_ ctxt false tval_rls t;
   47.60  (*val it = SOME (Const (\<^const_name>\<open>True\<close>, "bool"),[]) ... works*)
   47.61  
   47.62   val t = TermC.str2term "2 * x is_num";
   47.63 @@ -151,7 +152,6 @@
   47.64  "----------- check calculate bottom up ------------------";
   47.65  "----------- check calculate bottom up ------------------";
   47.66  (*-------------- eval_cancel works: *)
   47.67 - Rewrite.trace_on := false; (*true false*)
   47.68   val thy = @{theory Test};
   47.69   val rls = Test_simplify;
   47.70   val t = TermC.parseNEW' ctxt "(-4) / 2";
   47.71 @@ -160,21 +160,19 @@
   47.72  
   47.73  (*--------------(5): reproduce (1) with simpler term: ------------*)
   47.74   val t = TermC.parseNEW' ctxt "(3+5)/(2::real)";
   47.75 -case rewrite_set_ thy false rls t of
   47.76 +case rewrite_set_ ctxt false rls t of
   47.77    SOME (t', []) =>
   47.78      if UnparseC.term t' = "4" then ()
   47.79      else error "rewrite_set_ (3+5)/2 changed 1"
   47.80  | _ => error "rewrite_set_ (3+5)/2 changed 2";
   47.81  
   47.82   val t = TermC.parseNEW' ctxt "(3+1+2*x)/(2::real)";
   47.83 -case rewrite_set_ thy false rls t of
   47.84 +case rewrite_set_ ctxt false rls t of
   47.85    SOME (t', _) =>
   47.86      if UnparseC.term t' = "2 + x" then () else error "rewrite_set_ (3+1+2*x)/2 changed 1"
   47.87  | _ => error "rewrite_set_ (3+1+2*x)/2 changed 2";
   47.88  
   47.89 - Rewrite.trace_on := false; (*true false*)
   47.90 -
   47.91 -(*--- Rewrite.trace_on before correction of ... --------------------
   47.92 +(*--- trace_rewrite before correction of ... --------------------
   47.93   val ct = "(-3 + 2 * x + - 1) / 2";
   47.94   val (ct,_) = the (rewrite_set thy'  false rls ct);
   47.95  :
   47.96 @@ -203,9 +201,8 @@
   47.97  
   47.98  
   47.99  (*===================*)
  47.100 - Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
  47.101   val t = TermC.parseNEW' ctxt "x + (- 1 + -3) / (2::real)";
  47.102 -val SOME (res, []) = rewrite_set_ thy false rls t;
  47.103 +val SOME (res, []) = rewrite_set_ ctxt false rls t;
  47.104  if UnparseC.term res = "- 2 + x" then () else error "rewrite_set_  x + (- 1 + -3) / 2  changed";
  47.105  "x + (-4) / 2";						
  47.106  (*
  47.107 @@ -221,8 +218,6 @@
  47.108  ### trying calc. 'pow'
  47.109  *)
  47.110  
  47.111 - Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
  47.112 -
  47.113  " ================= evaluate.sml: calculate_ 2002 =================== ";
  47.114  " ================= evaluate.sml: calculate_ 2002 =================== ";
  47.115  " ================= evaluate.sml: calculate_ 2002 =================== ";
  47.116 @@ -230,33 +225,33 @@
  47.117  val thy = @{theory Test};
  47.118   val t = TermC.parseNEW' ctxt "12 / 3";
  47.119  val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
  47.120 -val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
  47.121 +val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
  47.122  "12 / 3 = 4";
  47.123  val thy = @{theory Test};
  47.124   val t = TermC.parseNEW' ctxt "4 \<up> 2";
  47.125  val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
  47.126 -val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
  47.127 +val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
  47.128  "4 ^ 2 = 16";
  47.129  
  47.130   val t = TermC.parseNEW' ctxt "((1 + 2) * 4 / 3) \<up> 2";
  47.131   val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t;
  47.132  "1 + 2 = 3";
  47.133 - val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
  47.134 + val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
  47.135   UnparseC.term t;
  47.136  "(3 * 4 / 3) \<up> 2";
  47.137   val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES")))t;
  47.138  "3 * 4 = 12";
  47.139 - val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
  47.140 + val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
  47.141   UnparseC.term t;
  47.142  "(12 / 3) \<up> 2";
  47.143   val SOME (thmID,thm) =adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
  47.144  "12 / 3 = 4";
  47.145 - val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
  47.146 + val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
  47.147   UnparseC.term t;
  47.148  "4 \<up> 2";
  47.149   val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")))t;
  47.150  "4 \<up> 2 = 16";
  47.151 - val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
  47.152 + val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
  47.153   UnparseC.term t;
  47.154  "16";
  47.155   if it <> "16" then error "evaluate.sml: new behaviour in calculate_"
  47.156 @@ -342,7 +337,7 @@
  47.157  if UnparseC.term t' = "(2 * x is_num) = False" then ()
  47.158  else error "is_num 2 * x is_num CHANGED";
  47.159  
  47.160 -val SOME (t',_) = rewrite_set_ @{theory Test} false tval_rls t;
  47.161 +val SOME (t',_) = rewrite_set_ ctxt false tval_rls t;
  47.162  if UnparseC.term t' = "False" then ()
  47.163  else error "rewrite_set_ 2 * x is_num CHANGED";
  47.164  
    48.1 --- a/test/Tools/isac/ProgLang/listC.sml	Thu Jul 28 11:43:27 2022 +0200
    48.2 +++ b/test/Tools/isac/ProgLang/listC.sml	Sat Jul 30 16:47:45 2022 +0200
    48.3 @@ -44,13 +44,14 @@
    48.4  "--------------------- NTH ---------------------------------------------------";
    48.5  "--------------------- NTH ---------------------------------------------------";
    48.6  "--------------------- NTH ---------------------------------------------------";
    48.7 +val ctxt = Proof_Context.init_global @{theory}
    48.8  val prog_expr = assoc_rls "prog_expr"
    48.9  
   48.10  val t = TermC.str2term "NTH 1 [a,b,c,d,e]";
   48.11  TermC.atomty t;
   48.12  val thm = Thm.prop_of @{thm NTH_NIL};
   48.13  TermC.atomty thm;
   48.14 -val SOME (t', _) = rewrite_ thy dummy_ord prog_expr false @{thm NTH_NIL} t;
   48.15 +val SOME (t', _) = rewrite_ ctxt dummy_ord prog_expr false @{thm NTH_NIL} t;
   48.16  if UnparseC.term t' = "a" then () 
   48.17  else error "NTH 1 [a,b,c,d,e] = a ..changed";
   48.18  
   48.19 @@ -65,16 +66,15 @@
   48.20  | _ => error "ListC.NTH changed";
   48.21  val thm = Thm.prop_of @{thm NTH_CONS};
   48.22  TermC.atomty thm;
   48.23 -val SOME (t', _) = rewrite_ thy dummy_ord prog_expr false  @{thm NTH_CONS} t;
   48.24 +val SOME (t', _) = rewrite_ ctxt dummy_ord prog_expr false  @{thm NTH_CONS} t;
   48.25  if UnparseC.term t' = "NTH (3 + - 1) [b, c, d, e]" then () 
   48.26  else error "NTH 3 [a,b,c,d,e] = NTH (3 + - 1) [b, c, d, e] ..changed";
   48.27  
   48.28  (* now the argument "(3 + - 1)" etc needs to be evaluated in the assumption of NTH_CONS *)
   48.29  val t = TermC.str2term "NTH 3 [a,b,c,d,e]";
   48.30  TermC.atomty t;
   48.31 -Rewrite.trace_on := false; (*true false*)
   48.32 -val SOME (t', _) = rewrite_set_ thy false prog_expr t;
   48.33 -Rewrite.trace_on := false; (*true false*)
   48.34 +
   48.35 +val SOME (t', _) = rewrite_set_ ctxt false prog_expr t;
   48.36  if UnparseC.term t' = "c" then () 
   48.37  else error "NTH 3 [a,b,c,d,e] = c ..changed";
   48.38  
   48.39 @@ -85,25 +85,25 @@
   48.40  
   48.41  val thy = @{theory ListC};
   48.42  val t = TermC.str2term "Length [1, 1, 1]";
   48.43 -val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
   48.44 +val SOME (t, asm) = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_CONS} t;
   48.45  UnparseC.term t = "1 + Length [1, 1]";
   48.46 -val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
   48.47 +val SOME (t, asm) = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_CONS} t;
   48.48  UnparseC.term t = "1 + (1 + Length [1])";
   48.49 -val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
   48.50 +val SOME (t, asm) = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_CONS} t;
   48.51  UnparseC.term t = "1 + (1 + (1 + Length []))";
   48.52 -val NONE          = rewrite_ thy tless_true tval_rls false @{thm LENGTH_CONS} t;
   48.53 -val SOME (t, asm) = rewrite_ thy tless_true tval_rls false @{thm LENGTH_NIL} t;
   48.54 -val NONE          = rewrite_ thy tless_true tval_rls false @{thm LENGTH_NIL} t;
   48.55 +val NONE          = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_CONS} t;
   48.56 +val SOME (t, asm) = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_NIL} t;
   48.57 +val NONE          = rewrite_ ctxt tless_true tval_rls false @{thm LENGTH_NIL} t;
   48.58  if UnparseC.term t = "1 + (1 + (1 + 0))" then () 
   48.59  else error "Length [1, 1, 1] = 1 + (1 + (1 + 0))  ..changed";
   48.60  
   48.61  val t = TermC.str2term "Length [1, 1, 1]";
   48.62 -val SOME (t, asm) = rewrite_set_ thy false prog_expr t;
   48.63 +val SOME (t, asm) = rewrite_set_ ctxt false prog_expr t;
   48.64  if UnparseC.term t = "3" then ()
   48.65  else error "Length [1, 1, 1] = 3  ..prog_expr changed";
   48.66  
   48.67  val t = TermC.str2term "Length [1, 1, 1]";
   48.68 -val t = eval_prog_expr thy prog_expr t;
   48.69 +val t = eval_prog_expr ctxt prog_expr t;
   48.70  case t of 
   48.71    Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit1\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)) => () 
   48.72  | _ => error "Length [1, 1, 1] = 3  ..eval_prog_expr changed";
    49.1 --- a/test/Tools/isac/ProgLang/prog_expr.sml	Thu Jul 28 11:43:27 2022 +0200
    49.2 +++ b/test/Tools/isac/ProgLang/prog_expr.sml	Sat Jul 30 16:47:45 2022 +0200
    49.3 @@ -89,8 +89,9 @@
    49.4  "-------- fun eval_is_num ----------------------------------------------------------------------";
    49.5  "-------- fun eval_is_num ----------------------------------------------------------------------";
    49.6  "-------- fun eval_is_num ----------------------------------------------------------------------";
    49.7 +val ctxt = Proof_Context.init_global @{theory Test}
    49.8  val t = TermC.parseNEW' ctxt "2 is_num";
    49.9 -case rewrite_set_ @{theory Test} false tval_rls t of
   49.10 +case rewrite_set_ ctxt false tval_rls t of
   49.11    SOME (Const (\<^const_name>\<open>True\<close>, _), []) => ()
   49.12  | _ => error "2 is_num CHANGED";
   49.13  
   49.14 @@ -409,13 +410,11 @@
   49.15  if UnparseC.term pred = "boollist2sum\n [b1 = k - 2 * q, b2 = k - 2 * q, b3 = k - 2 * q, b4 = k - 2 * q] =\nb1 + b2 + b3 + b4" then () 
   49.16  else error "atools.sml diff.behav. in eval_boollist2sum";
   49.17  
   49.18 -Rewrite.trace_on := false; (*true false*)
   49.19  val srls_ = Rule_Set.append_rules "srls_..Berechnung-erstSymbolisch" Rule_Set.empty 
   49.20  		      [Eval ("Prog_Expr.boollist2sum", eval_boollist2sum "")];
   49.21  val t = @{term "boollist2sum [b1 = k - 2*(q::real), b2 = k - 2*q, b3 = k - 2*q, b4 = k - 2*q]"};
   49.22 -case rewrite_set_ @{theory} false srls_ t of SOME _ => ()
   49.23 +case rewrite_set_ ctxt false srls_ t of SOME _ => ()
   49.24  | _ => error "atools.sml diff.rewrite boollist2sum";
   49.25 -Rewrite.trace_on := false; (*true false*)
   49.26  
   49.27  
   49.28  "-------- REBUILD fun eval_binop FOR Isabelle's NUMERALS ---------------------------------------";
    50.1 --- a/test/Tools/isac/Test_Isac.thy	Thu Jul 28 11:43:27 2022 +0200
    50.2 +++ b/test/Tools/isac/Test_Isac.thy	Sat Jul 30 16:47:45 2022 +0200
    50.3 @@ -144,7 +144,6 @@
    50.4  \<close> ML \<open> (*//---------------- adhoc inserted ------------------------------------------------\\*)
    50.5  \<close> ML \<open>
    50.6  \<close> ML \<open> (*\\---------------- adhoc inserted ------------------------------------------------//*)
    50.7 -Rewrite.trace_on := false;
    50.8  \<close>
    50.9  ML \<open>
   50.10  \<close> ML \<open>