src/Pure/simplifier.ML
author wenzelm
Wed Jul 13 16:07:27 2005 +0200 (2005-07-13)
changeset 16806 916387f7afd2
parent 16709 a4679ac06502
child 16989 1877b00fb4d2
permissions -rw-r--r--
removed obsolete delta stuff;
     1 (*  Title:      Pure/simplifier.ML
     2     ID:         $Id$
     3     Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
     4 
     5 Generic simplifier, suitable for most logics (see also
     6 meta_simplifier.ML for the actual meta-level rewriting engine).
     7 *)
     8 
     9 signature BASIC_SIMPLIFIER =
    10 sig
    11   include BASIC_META_SIMPLIFIER
    12   type context_solver
    13   val mk_context_solver: string -> (Proof.context -> thm list -> int -> tactic)
    14     -> context_solver
    15   type context_simproc
    16   val mk_context_simproc: string -> cterm list ->
    17     (Proof.context -> simpset -> term -> thm option) -> context_simproc
    18   val print_simpset: theory -> unit
    19   val simpset_ref_of_sg: theory -> simpset ref    (*obsolete*)
    20   val simpset_ref_of: theory -> simpset ref
    21   val simpset_of_sg: theory -> simpset            (*obsolete*)
    22   val simpset_of: theory -> simpset
    23   val SIMPSET: (simpset -> tactic) -> tactic
    24   val SIMPSET': (simpset -> 'a -> tactic) -> 'a -> tactic
    25   val simpset: unit -> simpset
    26   val simpset_ref: unit -> simpset ref
    27   val Addsimps: thm list -> unit
    28   val Delsimps: thm list -> unit
    29   val Addsimprocs: simproc list -> unit
    30   val Delsimprocs: simproc list -> unit
    31   val Addcongs: thm list -> unit
    32   val Delcongs: thm list -> unit
    33   val local_simpset_of: Proof.context -> simpset
    34   val safe_asm_full_simp_tac: simpset -> int -> tactic
    35   val               simp_tac: simpset -> int -> tactic
    36   val           asm_simp_tac: simpset -> int -> tactic
    37   val          full_simp_tac: simpset -> int -> tactic
    38   val        asm_lr_simp_tac: simpset -> int -> tactic
    39   val      asm_full_simp_tac: simpset -> int -> tactic
    40   val               Simp_tac:            int -> tactic
    41   val           Asm_simp_tac:            int -> tactic
    42   val          Full_simp_tac:            int -> tactic
    43   val        Asm_lr_simp_tac:            int -> tactic
    44   val      Asm_full_simp_tac:            int -> tactic
    45   val          simplify: simpset -> thm -> thm
    46   val      asm_simplify: simpset -> thm -> thm
    47   val     full_simplify: simpset -> thm -> thm
    48   val   asm_lr_simplify: simpset -> thm -> thm
    49   val asm_full_simplify: simpset -> thm -> thm
    50 end;
    51 
    52 signature SIMPLIFIER =
    53 sig
    54   include BASIC_SIMPLIFIER
    55   val simproc_i: theory -> string -> term list
    56     -> (theory -> simpset -> term -> thm option) -> simproc
    57   val simproc: theory -> string -> string list
    58     -> (theory -> simpset -> term -> thm option) -> simproc
    59   val context_simproc_i: theory -> string -> term list
    60     -> (Proof.context -> simpset -> term -> thm option) -> context_simproc
    61   val context_simproc: theory -> string -> string list
    62     -> (Proof.context -> simpset -> term -> thm option) -> context_simproc
    63   val          rewrite: simpset -> cterm -> thm
    64   val      asm_rewrite: simpset -> cterm -> thm
    65   val     full_rewrite: simpset -> cterm -> thm
    66   val   asm_lr_rewrite: simpset -> cterm -> thm
    67   val asm_full_rewrite: simpset -> cterm -> thm
    68   val add_context_simprocs: context_simproc list -> theory -> theory
    69   val del_context_simprocs: context_simproc list -> theory -> theory
    70   val set_context_subgoaler: (Proof.context -> simpset -> int -> tactic) -> theory -> theory
    71   val reset_context_subgoaler: theory -> theory
    72   val add_context_looper: string * (Proof.context -> int -> Tactical.tactic) ->
    73     theory -> theory
    74   val del_context_looper: string -> theory -> theory
    75   val add_context_unsafe_solver: context_solver -> theory -> theory
    76   val add_context_safe_solver: context_solver -> theory -> theory
    77   val print_local_simpset: Proof.context -> unit
    78   val get_local_simpset: Proof.context -> simpset
    79   val put_local_simpset: simpset -> Proof.context -> Proof.context
    80   val change_global_ss: (simpset * thm list -> simpset) -> theory attribute
    81   val change_local_ss: (simpset * thm list -> simpset) -> Proof.context attribute
    82   val simp_add_global: theory attribute
    83   val simp_del_global: theory attribute
    84   val simp_add_local: Proof.context attribute
    85   val simp_del_local: Proof.context attribute
    86   val cong_add_global: theory attribute
    87   val cong_del_global: theory attribute
    88   val cong_add_local: Proof.context attribute
    89   val cong_del_local: Proof.context attribute
    90   val change_simpset_of: (simpset * 'a -> simpset) -> 'a -> theory -> theory
    91   val simp_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list
    92   val method_setup: (Args.T list -> (Method.modifier * Args.T list)) list
    93     -> (theory -> theory) list
    94   val easy_setup: thm -> thm list -> (theory -> theory) list
    95 end;
    96 
    97 structure Simplifier: SIMPLIFIER =
    98 struct
    99 
   100 open MetaSimplifier;
   101 
   102 
   103 (** context dependent simpset components **)
   104 
   105 (* datatype context_solver *)
   106 
   107 datatype context_solver =
   108   ContextSolver of (string * (Proof.context -> thm list -> int -> tactic)) * stamp;
   109 
   110 fun mk_context_solver name f = ContextSolver ((name, f), stamp ());
   111 fun eq_context_solver (ContextSolver (_, id1), ContextSolver (_, id2)) = (id1 = id2);
   112 val merge_context_solvers = gen_merge_lists eq_context_solver;
   113 
   114 
   115 (* datatype context_simproc *)
   116 
   117 datatype context_simproc = ContextSimproc of
   118   (string * cterm list * (Proof.context -> simpset -> term -> thm option)) * stamp;
   119 
   120 fun mk_context_simproc name lhss f = ContextSimproc ((name, lhss, f), stamp ());
   121 fun eq_context_simproc (ContextSimproc (_, id1), ContextSimproc (_, id2)) = (id1 = id2);
   122 val merge_context_simprocs = gen_merge_lists eq_context_simproc;
   123 
   124 fun context_simproc_i thy name =
   125   mk_context_simproc name o map (Thm.cterm_of thy o Logic.varify);
   126 
   127 fun context_simproc thy name =
   128   context_simproc_i thy name o map (Sign.read_term thy);
   129 
   130 
   131 (* datatype context_ss *)
   132 
   133 datatype context_ss = ContextSS of
   134  {simprocs: context_simproc list,
   135   subgoal_tac: (Proof.context -> simpset -> int -> tactic) option,
   136   loop_tacs: (string * (Proof.context -> int -> tactic)) list,
   137   unsafe_solvers: context_solver list,
   138   solvers: context_solver list};
   139 
   140 fun context_ss ctxt ss ctxt_ss =
   141   let
   142     val ContextSS {simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers} = ctxt_ss;
   143     fun prep_simproc (ContextSimproc ((name, lhss, f), _)) =
   144       mk_simproc name lhss (K (f ctxt));
   145     fun add_loop (name, f) simpset = simpset addloop (name, f ctxt);
   146     fun add_solver add (ContextSolver ((name, f), _)) simpset =
   147       add (simpset, mk_solver name (f ctxt));
   148   in
   149     ((case subgoal_tac of NONE => ss | SOME tac => ss setsubgoaler tac ctxt)
   150       addsimprocs map prep_simproc simprocs)
   151     |> fold_rev add_loop loop_tacs
   152     |> fold_rev (add_solver (op addSolver)) unsafe_solvers
   153     |> fold_rev (add_solver (op addSSolver)) solvers
   154   end;
   155 
   156 fun make_context_ss (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) =
   157   ContextSS {simprocs = simprocs, subgoal_tac = subgoal_tac, loop_tacs = loop_tacs,
   158     unsafe_solvers = unsafe_solvers, solvers = solvers};
   159 
   160 val empty_context_ss = make_context_ss ([], NONE, [], [], []);
   161 
   162 fun merge_context_ss (ctxt_ss1, ctxt_ss2) =
   163   let
   164     val ContextSS {simprocs = simprocs1, subgoal_tac = subgoal_tac1, loop_tacs = loop_tacs1,
   165       unsafe_solvers = unsafe_solvers1, solvers = solvers1} = ctxt_ss1;
   166     val ContextSS {simprocs = simprocs2, subgoal_tac = subgoal_tac2, loop_tacs = loop_tacs2,
   167       unsafe_solvers = unsafe_solvers2, solvers = solvers2} = ctxt_ss2;
   168 
   169     val simprocs' = merge_context_simprocs simprocs1 simprocs2;
   170     val subgoal_tac' = (case subgoal_tac1 of NONE => subgoal_tac2 | some => some);
   171     val loop_tacs' = merge_alists loop_tacs1 loop_tacs2;
   172     val unsafe_solvers' = merge_context_solvers unsafe_solvers1 unsafe_solvers2;
   173     val solvers' = merge_context_solvers solvers1 solvers2;
   174   in make_context_ss (simprocs', subgoal_tac', loop_tacs', unsafe_solvers', solvers') end;
   175 
   176 
   177 
   178 (** global and local simpset data **)
   179 
   180 (* theory data kind 'Pure/simpset' *)
   181 
   182 structure GlobalSimpset = TheoryDataFun
   183 (struct
   184   val name = "Pure/simpset";
   185   type T = simpset ref * context_ss;
   186 
   187   val empty = (ref empty_ss, empty_context_ss);
   188   fun copy (ref ss, ctxt_ss) = (ref ss, ctxt_ss): T;            (*create new reference!*)
   189   val extend = copy;
   190   fun merge _ ((ref ss1, ctxt_ss1), (ref ss2, ctxt_ss2)) =
   191     (ref (merge_ss (ss1, ss2)), merge_context_ss (ctxt_ss1, ctxt_ss2));
   192   fun print _ (ref ss, _) = print_ss ss;
   193 end);
   194 
   195 val _ = Context.add_setup [GlobalSimpset.init];
   196 val print_simpset = GlobalSimpset.print;
   197 
   198 val simpset_ref_of = #1 o GlobalSimpset.get;
   199 val simpset_ref_of_sg = simpset_ref_of;
   200 val get_context_ss = #2 o GlobalSimpset.get o ProofContext.theory_of;
   201 
   202 fun map_context_ss f = GlobalSimpset.map (apsnd
   203   (fn ContextSS {simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers} =>
   204     make_context_ss (f (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers))));
   205 
   206 
   207 (* access global simpset *)
   208 
   209 val simpset_of = ! o simpset_ref_of;
   210 val simpset_of_sg = simpset_of;
   211 
   212 fun SIMPSET tacf state = tacf (simpset_of (Thm.theory_of_thm state)) state;
   213 fun SIMPSET' tacf i state = tacf (simpset_of (Thm.theory_of_thm state)) i state;
   214 
   215 val simpset = simpset_of o Context.the_context;
   216 val simpset_ref = simpset_ref_of o Context.the_context;
   217 
   218 
   219 (* change global simpset *)
   220 
   221 fun change_simpset_of f x thy =
   222   let val r = simpset_ref_of thy
   223   in r := f (! r, x); thy end;
   224 
   225 fun change_simpset f x = (change_simpset_of f x (Context.the_context ()); ());
   226 
   227 val Addsimps = change_simpset (op addsimps);
   228 val Delsimps = change_simpset (op delsimps);
   229 val Addsimprocs = change_simpset (op addsimprocs);
   230 val Delsimprocs = change_simpset (op delsimprocs);
   231 val Addcongs = change_simpset (op addcongs);
   232 val Delcongs = change_simpset (op delcongs);
   233 
   234 
   235 (* change context dependent components *)
   236 
   237 fun add_context_simprocs procs =
   238   map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) =>
   239     (merge_context_simprocs procs simprocs, subgoal_tac, loop_tacs,
   240       unsafe_solvers, solvers));
   241 
   242 fun del_context_simprocs procs =
   243   map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) =>
   244     (gen_rems eq_context_simproc (simprocs, procs), subgoal_tac, loop_tacs,
   245       unsafe_solvers, solvers));
   246 
   247 fun set_context_subgoaler tac =
   248   map_context_ss (fn (simprocs, _, loop_tacs, unsafe_solvers, solvers) =>
   249     (simprocs, SOME tac, loop_tacs, unsafe_solvers, solvers));
   250 
   251 val reset_context_subgoaler =
   252   map_context_ss (fn (simprocs, _, loop_tacs, unsafe_solvers, solvers) =>
   253     (simprocs, NONE, loop_tacs, unsafe_solvers, solvers));
   254 
   255 fun add_context_looper (name, tac) =
   256   map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) =>
   257     (simprocs, subgoal_tac, merge_alists [(name, tac)] loop_tacs,
   258       unsafe_solvers, solvers));
   259 
   260 fun del_context_looper name =
   261   map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) =>
   262     (simprocs, subgoal_tac, filter_out (equal name o #1) loop_tacs,
   263       unsafe_solvers, solvers));
   264 
   265 fun add_context_unsafe_solver solver =
   266   map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) =>
   267     (simprocs, subgoal_tac, loop_tacs,
   268       merge_context_solvers [solver] unsafe_solvers, solvers));
   269 
   270 fun add_context_safe_solver solver =
   271   map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) =>
   272     (simprocs, subgoal_tac, loop_tacs, unsafe_solvers,
   273       merge_context_solvers [solver] solvers));
   274 
   275 
   276 (* proof data kind 'Pure/simpset' *)
   277 
   278 structure LocalSimpset = ProofDataFun
   279 (struct
   280   val name = "Pure/simpset";
   281   type T = simpset;
   282   val init = simpset_of;
   283   fun print ctxt ss = print_ss (context_ss ctxt ss (get_context_ss ctxt));
   284 end);
   285 
   286 val _ = Context.add_setup [LocalSimpset.init];
   287 val print_local_simpset = LocalSimpset.print;
   288 
   289 val get_local_simpset = LocalSimpset.get;
   290 val put_local_simpset = LocalSimpset.put;
   291 fun map_local_simpset f ctxt = put_local_simpset (f (get_local_simpset ctxt)) ctxt;
   292 
   293 fun local_simpset_of ctxt =
   294   context_ss ctxt (get_local_simpset ctxt) (get_context_ss ctxt);
   295 
   296 
   297 (* attributes *)
   298 
   299 fun change_global_ss f (thy, th) =
   300   let val r = simpset_ref_of thy
   301   in r := f (! r, [th]); (thy, th) end;
   302 
   303 fun change_local_ss f (ctxt, th) =
   304   let val ss = f (get_local_simpset ctxt, [th])
   305   in (put_local_simpset ss ctxt, th) end;
   306 
   307 val simp_add_global = change_global_ss (op addsimps);
   308 val simp_del_global = change_global_ss (op delsimps);
   309 val simp_add_local = change_local_ss (op addsimps);
   310 val simp_del_local = change_local_ss (op delsimps);
   311 
   312 val cong_add_global = change_global_ss (op addcongs);
   313 val cong_del_global = change_global_ss (op delcongs);
   314 val cong_add_local = change_local_ss (op addcongs);
   315 val cong_del_local = change_local_ss (op delcongs);
   316 
   317 
   318 (* tactics *)
   319 
   320 val simp_tac = generic_simp_tac false (false, false, false);
   321 val asm_simp_tac = generic_simp_tac false (false, true, false);
   322 val full_simp_tac = generic_simp_tac false (true, false, false);
   323 val asm_lr_simp_tac = generic_simp_tac false (true, true, false);
   324 val asm_full_simp_tac = generic_simp_tac false (true, true, true);
   325 val safe_asm_full_simp_tac = generic_simp_tac true (true, true, true);
   326 
   327 (*the abstraction over the proof state delays the dereferencing*)
   328 fun          Simp_tac i st =          simp_tac (simpset ()) i st;
   329 fun      Asm_simp_tac i st =      asm_simp_tac (simpset ()) i st;
   330 fun     Full_simp_tac i st =     full_simp_tac (simpset ()) i st;
   331 fun   Asm_lr_simp_tac i st =   asm_lr_simp_tac (simpset ()) i st;
   332 fun Asm_full_simp_tac i st = asm_full_simp_tac (simpset ()) i st;
   333 
   334 
   335 (* conversions *)
   336 
   337 val          simplify = simp_thm (false, false, false);
   338 val      asm_simplify = simp_thm (false, true, false);
   339 val     full_simplify = simp_thm (true, false, false);
   340 val   asm_lr_simplify = simp_thm (true, true, false);
   341 val asm_full_simplify = simp_thm (true, true, true);
   342 
   343 val          rewrite = simp_cterm (false, false, false);
   344 val      asm_rewrite = simp_cterm (false, true, false);
   345 val     full_rewrite = simp_cterm (true, false, false);
   346 val   asm_lr_rewrite = simp_cterm (true, true, false);
   347 val asm_full_rewrite = simp_cterm (true, true, true);
   348 
   349 
   350 
   351 (** concrete syntax of attributes **)
   352 
   353 (* add / del *)
   354 
   355 val simpN = "simp";
   356 val congN = "cong";
   357 val addN = "add";
   358 val delN = "del";
   359 val onlyN = "only";
   360 val no_asmN = "no_asm";
   361 val no_asm_useN = "no_asm_use";
   362 val no_asm_simpN = "no_asm_simp";
   363 val asm_lrN = "asm_lr";
   364 
   365 val simp_attr =
   366  (Attrib.add_del_args simp_add_global simp_del_global,
   367   Attrib.add_del_args simp_add_local simp_del_local);
   368 
   369 val cong_attr =
   370  (Attrib.add_del_args cong_add_global cong_del_global,
   371   Attrib.add_del_args cong_add_local cong_del_local);
   372 
   373 
   374 (* conversions *)
   375 
   376 local
   377 
   378 fun conv_mode x =
   379   ((Args.parens (Args.$$$ no_asmN) >> K simplify ||
   380     Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify ||
   381     Args.parens (Args.$$$ no_asm_useN) >> K full_simplify ||
   382     Scan.succeed asm_full_simplify) |> Scan.lift) x;
   383 
   384 fun simplified_att get args =
   385   Attrib.syntax (conv_mode -- args >> (fn (f, ths) =>
   386     Drule.rule_attribute (fn x => f ((if null ths then I else clear_ss) (get x) addsimps ths))));
   387 
   388 in
   389 
   390 val simplified_attr =
   391  (simplified_att simpset_of Attrib.global_thmss,
   392   simplified_att local_simpset_of Attrib.local_thmss);
   393 
   394 end;
   395 
   396 
   397 (* setup attributes *)
   398 
   399 val _ = Context.add_setup
   400  [Attrib.add_attributes
   401    [(simpN, simp_attr, "declaration of simplification rule"),
   402     (congN, cong_attr, "declaration of Simplifier congruence rule"),
   403     ("simplified", simplified_attr, "simplified rule")]];
   404 
   405 
   406 
   407 (** proof methods **)
   408 
   409 (* simplification *)
   410 
   411 val simp_options =
   412  (Args.parens (Args.$$$ no_asmN) >> K simp_tac ||
   413   Args.parens (Args.$$$ no_asm_simpN) >> K asm_simp_tac ||
   414   Args.parens (Args.$$$ no_asm_useN) >> K full_simp_tac ||
   415   Args.parens (Args.$$$ asm_lrN) >> K asm_lr_simp_tac ||
   416   Scan.succeed asm_full_simp_tac);
   417 
   418 fun simp_flags x = (Scan.repeat
   419   (Args.parens (Args.$$$ "depth_limit" -- Args.colon |-- Args.nat)
   420     >> setmp MetaSimplifier.simp_depth_limit)
   421   >> (curry (Library.foldl op o) I o rev)) x;
   422 
   423 val cong_modifiers =
   424  [Args.$$$ congN -- Args.colon >> K ((I, cong_add_local):Method.modifier),
   425   Args.$$$ congN -- Args.add -- Args.colon >> K (I, cong_add_local),
   426   Args.$$$ congN -- Args.del -- Args.colon >> K (I, cong_del_local)];
   427 
   428 val simp_modifiers =
   429  [Args.$$$ simpN -- Args.colon >> K (I, simp_add_local),
   430   Args.$$$ simpN -- Args.add -- Args.colon >> K (I, simp_add_local),
   431   Args.$$$ simpN -- Args.del -- Args.colon >> K (I, simp_del_local),
   432   Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon >> K (map_local_simpset clear_ss, simp_add_local)]
   433    @ cong_modifiers;
   434 
   435 val simp_modifiers' =
   436  [Args.add -- Args.colon >> K (I, simp_add_local),
   437   Args.del -- Args.colon >> K (I, simp_del_local),
   438   Args.$$$ onlyN -- Args.colon >> K (map_local_simpset clear_ss, simp_add_local)]
   439    @ cong_modifiers;
   440 
   441 fun simp_args more_mods =
   442   Method.sectioned_args (Args.bang_facts -- Scan.lift simp_options -- Scan.lift simp_flags)
   443     (more_mods @ simp_modifiers');
   444 
   445 fun simp_method ((prems, tac), FLAGS) ctxt = Method.METHOD (fn facts =>
   446   ALLGOALS (Method.insert_tac (prems @ facts)) THEN
   447     (FLAGS o CHANGED_PROP o ALLGOALS o tac) (local_simpset_of ctxt));
   448 
   449 fun simp_method' ((prems, tac), FLAGS) ctxt = Method.METHOD (fn facts =>
   450   HEADGOAL (Method.insert_tac (prems @ facts) THEN'
   451       ((FLAGS o CHANGED_PROP) oo tac) (local_simpset_of ctxt)));
   452 
   453 
   454 (* setup methods *)
   455 
   456 fun setup_methods more_mods = Method.add_methods
   457  [(simpN, simp_args more_mods simp_method', "simplification"),
   458   ("simp_all", simp_args more_mods simp_method, "simplification (all goals)")];
   459 
   460 fun method_setup mods = [setup_methods mods];
   461 
   462 
   463 (** easy_setup **)
   464 
   465 fun easy_setup reflect trivs =
   466   let
   467     val trivialities = Drule.reflexive_thm :: trivs;
   468 
   469     fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac];
   470     val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac;
   471 
   472     (*no premature instantiation of variables during simplification*)
   473     fun safe_solver_tac prems = FIRST' [match_tac (trivialities @ prems), eq_assume_tac];
   474     val safe_solver = mk_solver "easy safe" safe_solver_tac;
   475 
   476     fun mk_eq thm =
   477       if Logic.is_equals (Thm.concl_of thm) then [thm]
   478       else [thm RS reflect] handle THM _ => [];
   479 
   480     fun mksimps thm = mk_eq (Drule.forall_elim_vars (#maxidx (Thm.rep_thm thm) + 1) thm);
   481 
   482     fun init_ss thy =
   483       (simpset_ref_of thy :=
   484         empty_ss setsubgoaler asm_simp_tac
   485         setSSolver safe_solver
   486         setSolver unsafe_solver
   487         setmksimps mksimps; thy);
   488   in method_setup [] @ [init_ss] end;
   489 
   490 end;
   491 
   492 structure BasicSimplifier: BASIC_SIMPLIFIER = Simplifier;
   493 open BasicSimplifier;