src/HOL/Tools/Nitpick/nitpick.ML
author blanchet
Mon Feb 21 16:33:21 2011 +0100 (2011-02-21 ago)
changeset 41802 7592a165fa0b
parent 41801 ed77524f3429
child 41803 ef13e3b7cbaf
permissions -rw-r--r--
more work on "fix_datatype_vals"
     1 (*  Title:      HOL/Tools/Nitpick/nitpick.ML
     2     Author:     Jasmin Blanchette, TU Muenchen
     3     Copyright   2008, 2009, 2010
     4 
     5 Finite model generation for HOL formulas using Kodkod.
     6 *)
     7 
     8 signature NITPICK =
     9 sig
    10   type styp = Nitpick_Util.styp
    11   type term_postprocessor = Nitpick_Model.term_postprocessor
    12   type params =
    13     {cards_assigns: (typ option * int list) list,
    14      maxes_assigns: (styp option * int list) list,
    15      iters_assigns: (styp option * int list) list,
    16      bitss: int list,
    17      bisim_depths: int list,
    18      boxes: (typ option * bool option) list,
    19      finitizes: (typ option * bool option) list,
    20      monos: (typ option * bool option) list,
    21      stds: (typ option * bool) list,
    22      wfs: (styp option * bool option) list,
    23      sat_solver: string,
    24      blocking: bool,
    25      falsify: bool,
    26      debug: bool,
    27      verbose: bool,
    28      overlord: bool,
    29      user_axioms: bool option,
    30      assms: bool,
    31      whacks: term list,
    32      merge_type_vars: bool,
    33      binary_ints: bool option,
    34      destroy_constrs: bool,
    35      specialize: bool,
    36      star_linear_preds: bool,
    37      peephole_optim: bool,
    38      fix_datatype_vals: bool,
    39      datatype_sym_break: int,
    40      kodkod_sym_break: int,
    41      timeout: Time.time option,
    42      tac_timeout: Time.time option,
    43      max_threads: int,
    44      show_datatypes: bool,
    45      show_consts: bool,
    46      evals: term list,
    47      formats: (term option * int list) list,
    48      atomss: (typ option * string list) list,
    49      max_potential: int,
    50      max_genuine: int,
    51      check_potential: bool,
    52      check_genuine: bool,
    53      batch_size: int,
    54      expect: string}
    55 
    56   val register_frac_type : string -> (string * string) list -> theory -> theory
    57   val unregister_frac_type : string -> theory -> theory
    58   val register_codatatype : typ -> string -> styp list -> theory -> theory
    59   val unregister_codatatype : typ -> theory -> theory
    60   val register_term_postprocessor :
    61     typ -> term_postprocessor -> theory -> theory
    62   val unregister_term_postprocessor : typ -> theory -> theory
    63   val pick_nits_in_term :
    64     Proof.state -> params -> bool -> int -> int -> int -> (term * term) list
    65     -> term list -> term -> string * Proof.state
    66   val pick_nits_in_subgoal :
    67     Proof.state -> params -> bool -> int -> int -> string * Proof.state
    68 end;
    69 
    70 structure Nitpick : NITPICK =
    71 struct
    72 
    73 open Nitpick_Util
    74 open Nitpick_HOL
    75 open Nitpick_Preproc
    76 open Nitpick_Mono
    77 open Nitpick_Scope
    78 open Nitpick_Peephole
    79 open Nitpick_Rep
    80 open Nitpick_Nut
    81 open Nitpick_Kodkod
    82 open Nitpick_Model
    83 
    84 structure KK = Kodkod
    85 
    86 type params =
    87   {cards_assigns: (typ option * int list) list,
    88    maxes_assigns: (styp option * int list) list,
    89    iters_assigns: (styp option * int list) list,
    90    bitss: int list,
    91    bisim_depths: int list,
    92    boxes: (typ option * bool option) list,
    93    finitizes: (typ option * bool option) list,
    94    monos: (typ option * bool option) list,
    95    stds: (typ option * bool) list,
    96    wfs: (styp option * bool option) list,
    97    sat_solver: string,
    98    blocking: bool,
    99    falsify: bool,
   100    debug: bool,
   101    verbose: bool,
   102    overlord: bool,
   103    user_axioms: bool option,
   104    assms: bool,
   105    whacks: term list,
   106    merge_type_vars: bool,
   107    binary_ints: bool option,
   108    destroy_constrs: bool,
   109    specialize: bool,
   110    star_linear_preds: bool,
   111    peephole_optim: bool,
   112    fix_datatype_vals: bool,
   113    datatype_sym_break: int,
   114    kodkod_sym_break: int,
   115    timeout: Time.time option,
   116    tac_timeout: Time.time option,
   117    max_threads: int,
   118    show_datatypes: bool,
   119    show_consts: bool,
   120    evals: term list,
   121    formats: (term option * int list) list,
   122    atomss: (typ option * string list) list,
   123    max_potential: int,
   124    max_genuine: int,
   125    check_potential: bool,
   126    check_genuine: bool,
   127    batch_size: int,
   128    expect: string}
   129 
   130 (* TODO: eliminate these historical aliases *)
   131 val register_frac_type = Nitpick_HOL.register_frac_type_global
   132 val unregister_frac_type = Nitpick_HOL.unregister_frac_type_global
   133 val register_codatatype = Nitpick_HOL.register_codatatype_global
   134 val unregister_codatatype = Nitpick_HOL.unregister_codatatype_global
   135 val register_term_postprocessor =
   136   Nitpick_Model.register_term_postprocessor_global
   137 val unregister_term_postprocessor =
   138   Nitpick_Model.unregister_term_postprocessor_global
   139 
   140 type problem_extension =
   141   {free_names: nut list,
   142    sel_names: nut list,
   143    nonsel_names: nut list,
   144    rel_table: nut NameTable.table,
   145    unsound: bool,
   146    scope: scope}
   147 
   148 type rich_problem = KK.problem * problem_extension
   149 
   150 fun pretties_for_formulas _ _ [] = []
   151   | pretties_for_formulas ctxt s ts =
   152     [Pretty.str (s ^ plural_s_for_list ts ^ ":"),
   153      Pretty.indent indent_size (Pretty.chunks
   154          (map2 (fn j => fn t =>
   155                    Pretty.block [t |> shorten_names_in_term
   156                                    |> Syntax.pretty_term ctxt,
   157                                  Pretty.str (if j = 1 then "." else ";")])
   158                (length ts downto 1) ts))]
   159 
   160 fun install_java_message () =
   161   "Nitpick requires a Java 1.5 virtual machine called \"java\"."
   162 fun install_kodkodi_message () =
   163   "Nitpick requires the external Java program Kodkodi. To install it, download \
   164   \the package from Isabelle's web page and add the \"kodkodi-x.y.z\" \
   165   \directory's full path to \"" ^
   166   Path.implode (Path.expand (Path.appends
   167       (Path.variable "ISABELLE_HOME_USER" ::
   168        map Path.basic ["etc", "components"]))) ^ "\" on a line of its own."
   169 
   170 val max_unsound_delay_ms = 200
   171 val max_unsound_delay_percent = 2
   172 
   173 fun unsound_delay_for_timeout NONE = max_unsound_delay_ms
   174   | unsound_delay_for_timeout (SOME timeout) =
   175     Int.max (0, Int.min (max_unsound_delay_ms,
   176                          Time.toMilliseconds timeout
   177                          * max_unsound_delay_percent div 100))
   178 
   179 fun passed_deadline NONE = false
   180   | passed_deadline (SOME time) = Time.compare (Time.now (), time) <> LESS
   181 
   182 fun none_true assigns = forall (not_equal (SOME true) o snd) assigns
   183 
   184 fun has_lonely_bool_var (@{const Pure.conjunction}
   185                          $ (@{const Trueprop} $ Free _) $ _) = true
   186   | has_lonely_bool_var _ = false
   187 
   188 val syntactic_sorts =
   189   @{sort "{default,zero,one,plus,minus,uminus,times,inverse,abs,sgn,ord,equal}"} @
   190   @{sort number}
   191 fun has_tfree_syntactic_sort (TFree (_, S as _ :: _)) =
   192     subset (op =) (S, syntactic_sorts)
   193   | has_tfree_syntactic_sort _ = false
   194 val has_syntactic_sorts = exists_type (exists_subtype has_tfree_syntactic_sort)
   195 
   196 fun plazy f = Pretty.blk (0, pstrs (f ()))
   197 
   198 fun pick_them_nits_in_term deadline state (params : params) auto i n step
   199                            subst assm_ts orig_t =
   200   let
   201     val timer = Timer.startRealTimer ()
   202     val thy = Proof.theory_of state
   203     val ctxt = Proof.context_of state
   204 (* FIXME: reintroduce code before new release:
   205 
   206     val nitpick_thy = Thy_Info.get_theory "Nitpick"
   207     val _ = Theory.subthy (nitpick_thy, thy) orelse
   208             error "You must import the theory \"Nitpick\" to use Nitpick"
   209 *)
   210     val {cards_assigns, maxes_assigns, iters_assigns, bitss, bisim_depths,
   211          boxes, finitizes, monos, stds, wfs, sat_solver, falsify, debug,
   212          verbose, overlord, user_axioms, assms, whacks, merge_type_vars,
   213          binary_ints, destroy_constrs, specialize, star_linear_preds,
   214          peephole_optim, fix_datatype_vals, datatype_sym_break,
   215          kodkod_sym_break, tac_timeout, max_threads, show_datatypes,
   216          show_consts, evals, formats, atomss, max_potential, max_genuine,
   217          check_potential, check_genuine, batch_size, ...} = params
   218     val state_ref = Unsynchronized.ref state
   219     val pprint =
   220       if auto then
   221         Unsynchronized.change state_ref o Proof.goal_message o K
   222         o Pretty.chunks o cons (Pretty.str "") o single
   223         o Pretty.mark Markup.hilite
   224       else
   225         (fn s => (Output.urgent_message s; if debug then tracing s else ()))
   226         o Pretty.string_of
   227     fun pprint_m f = () |> not auto ? pprint o f
   228     fun pprint_v f = () |> verbose ? pprint o f
   229     fun pprint_d f = () |> debug ? pprint o f
   230     val print = pprint o curry Pretty.blk 0 o pstrs
   231 (*
   232     val print_g = pprint o Pretty.str
   233 *)
   234     val print_m = pprint_m o K o plazy
   235     val print_v = pprint_v o K o plazy
   236 
   237     fun check_deadline () =
   238       if passed_deadline deadline then raise TimeLimit.TimeOut else ()
   239 
   240     val assm_ts = if assms orelse auto then assm_ts else []
   241     val _ =
   242       if step = 0 then
   243         print_m (fn () => "Nitpicking formula...")
   244       else
   245         pprint_m (fn () => Pretty.chunks (
   246             pretties_for_formulas ctxt ("Nitpicking " ^
   247                 (if i <> 1 orelse n <> 1 then
   248                    "subgoal " ^ string_of_int i ^ " of " ^ string_of_int n
   249                  else
   250                    "goal")) [Logic.list_implies (assm_ts, orig_t)]))
   251     val _ = print_v (enclose "Timestamp: " "." o Date.fmt "%H:%M:%S"
   252                      o Date.fromTimeLocal o Time.now)
   253     val neg_t = if falsify then Logic.mk_implies (orig_t, @{prop False})
   254                 else orig_t
   255     val tfree_table =
   256       if merge_type_vars then
   257         merged_type_var_table_for_terms thy (neg_t :: assm_ts @ evals)
   258       else
   259         []
   260     val neg_t = merge_type_vars_in_term thy merge_type_vars tfree_table neg_t
   261     val assm_ts = map (merge_type_vars_in_term thy merge_type_vars tfree_table)
   262                       assm_ts
   263     val evals = map (merge_type_vars_in_term thy merge_type_vars tfree_table)
   264                     evals
   265     val original_max_potential = max_potential
   266     val original_max_genuine = max_genuine
   267     val max_bisim_depth = fold Integer.max bisim_depths ~1
   268     val case_names = case_const_names ctxt stds
   269     val (defs, built_in_nondefs, user_nondefs) = all_axioms_of ctxt subst
   270     val def_tables = const_def_tables ctxt subst defs
   271     val nondef_table = const_nondef_table (built_in_nondefs @ user_nondefs)
   272     val simp_table = Unsynchronized.ref (const_simp_table ctxt subst)
   273     val psimp_table = const_psimp_table ctxt subst
   274     val choice_spec_table = const_choice_spec_table ctxt subst
   275     val user_nondefs =
   276       user_nondefs |> filter_out (is_choice_spec_axiom thy choice_spec_table)
   277     val intro_table = inductive_intro_table ctxt subst def_tables
   278     val ground_thm_table = ground_theorem_table thy
   279     val ersatz_table = ersatz_table ctxt
   280     val hol_ctxt as {wf_cache, ...} =
   281       {thy = thy, ctxt = ctxt, max_bisim_depth = max_bisim_depth, boxes = boxes,
   282        stds = stds, wfs = wfs, user_axioms = user_axioms, debug = debug,
   283        whacks = whacks, binary_ints = binary_ints,
   284        destroy_constrs = destroy_constrs, specialize = specialize,
   285        star_linear_preds = star_linear_preds, tac_timeout = tac_timeout,
   286        evals = evals, case_names = case_names, def_tables = def_tables,
   287        nondef_table = nondef_table, user_nondefs = user_nondefs,
   288        simp_table = simp_table, psimp_table = psimp_table,
   289        choice_spec_table = choice_spec_table, intro_table = intro_table,
   290        ground_thm_table = ground_thm_table, ersatz_table = ersatz_table,
   291        skolems = Unsynchronized.ref [], special_funs = Unsynchronized.ref [],
   292        unrolled_preds = Unsynchronized.ref [], wf_cache = Unsynchronized.ref [],
   293        constr_cache = Unsynchronized.ref []}
   294     val pseudo_frees = []
   295     val real_frees = fold Term.add_frees (neg_t :: assm_ts) []
   296     val _ = null (fold Term.add_tvars (neg_t :: assm_ts) []) orelse
   297             raise NOT_SUPPORTED "schematic type variables"
   298     val (nondef_ts, def_ts, got_all_mono_user_axioms, no_poly_user_axioms,
   299          binarize) = preprocess_formulas hol_ctxt assm_ts neg_t
   300     val got_all_user_axioms =
   301       got_all_mono_user_axioms andalso no_poly_user_axioms
   302 
   303     fun print_wf (x, (gfp, wf)) =
   304       pprint (Pretty.blk (0,
   305           pstrs ("The " ^ (if gfp then "co" else "") ^ "inductive predicate \"")
   306           @ Syntax.pretty_term ctxt (Const x) ::
   307           pstrs (if wf then
   308                    "\" was proved well-founded. Nitpick can compute it \
   309                    \efficiently."
   310                  else
   311                    "\" could not be proved well-founded. Nitpick might need to \
   312                    \unroll it.")))
   313     val _ = if verbose then List.app print_wf (!wf_cache) else ()
   314     val das_wort_formula = if falsify then "Negated conjecture" else "Formula"
   315     val _ =
   316       pprint_d (fn () => Pretty.chunks
   317           (pretties_for_formulas ctxt das_wort_formula [hd nondef_ts] @
   318            pretties_for_formulas ctxt "Relevant definitional axiom" def_ts @
   319            pretties_for_formulas ctxt "Relevant nondefinitional axiom"
   320                                  (tl nondef_ts)))
   321     val _ = List.app (ignore o Term.type_of) (nondef_ts @ def_ts)
   322             handle TYPE (_, Ts, ts) =>
   323                    raise TYPE ("Nitpick.pick_them_nits_in_term", Ts, ts)
   324 
   325     val nondef_us = nondef_ts |> map (nut_from_term hol_ctxt Eq)
   326     val def_us = def_ts |> map (nut_from_term hol_ctxt DefEq)
   327     val needed_us =
   328       if fix_datatype_vals then
   329         [@{term "[A, B, C, A]"}, @{term "[C, B, A]"}]
   330         |> map (nut_from_term hol_ctxt Eq)
   331         (* infer_needed_constructs ### *)
   332       else
   333         []
   334     val (free_names, const_names) =
   335       fold add_free_and_const_names (nondef_us @ def_us) ([], [])
   336     val (sel_names, nonsel_names) =
   337       List.partition (is_sel o nickname_of) const_names
   338     val sound_finitizes =
   339       none_true (filter_out (fn (SOME (Type (@{type_name fun}, _)), _) => true
   340                           | _ => false) finitizes)
   341     val standard = forall snd stds
   342 (*
   343     val _ = List.app (print_g o string_for_nut ctxt) (nondef_us @ def_us)
   344 *)
   345 
   346     val unique_scope = forall (curry (op =) 1 o length o snd) cards_assigns
   347     fun monotonicity_message Ts extra =
   348       let val pretties = map (pretty_maybe_quote o pretty_for_type ctxt) Ts in
   349         Pretty.blk (0,
   350           pstrs ("The type" ^ plural_s_for_list pretties ^ " ") @
   351           pretty_serial_commas "and" pretties @
   352           pstrs (" " ^
   353           (if none_true monos then
   354              "passed the monotonicity test"
   355            else
   356              (if length pretties = 1 then "is" else "are") ^ " considered monotonic") ^
   357           ". " ^ extra))
   358       end
   359     fun is_type_fundamentally_monotonic T =
   360       (is_datatype ctxt stds T andalso not (is_quot_type ctxt T) andalso
   361        (not (is_pure_typedef ctxt T) orelse is_univ_typedef ctxt T)) orelse
   362       is_number_type ctxt T orelse is_bit_type T
   363     fun is_type_actually_monotonic T =
   364       formulas_monotonic hol_ctxt binarize T (nondef_ts, def_ts)
   365     fun is_type_kind_of_monotonic T =
   366       case triple_lookup (type_match thy) monos T of
   367         SOME (SOME false) => false
   368       | _ => is_type_actually_monotonic T
   369     fun is_type_monotonic T =
   370       unique_scope orelse
   371       case triple_lookup (type_match thy) monos T of
   372         SOME (SOME b) => b
   373       | _ => is_type_fundamentally_monotonic T orelse
   374              is_type_actually_monotonic T
   375     fun is_deep_datatype_finitizable T =
   376       triple_lookup (type_match thy) finitizes T = SOME (SOME true)
   377     fun is_shallow_datatype_finitizable (T as Type (@{type_name fun_box}, _)) =
   378         is_type_kind_of_monotonic T
   379       | is_shallow_datatype_finitizable T =
   380         case triple_lookup (type_match thy) finitizes T of
   381           SOME (SOME b) => b
   382         | _ => is_type_kind_of_monotonic T
   383     fun is_datatype_deep T =
   384       not standard orelse T = nat_T orelse is_word_type T orelse
   385       exists (curry (op =) T o domain_type o type_of) sel_names
   386     val all_Ts = ground_types_in_terms hol_ctxt binarize (nondef_ts @ def_ts)
   387                  |> sort Term_Ord.typ_ord
   388     val _ =
   389       if verbose andalso binary_ints = SOME true andalso
   390          exists (member (op =) [nat_T, int_T]) all_Ts then
   391         print_v (K "The option \"binary_ints\" will be ignored because of the \
   392                    \presence of rationals, reals, \"Suc\", \"gcd\", or \"lcm\" \
   393                    \in the problem or because of the \"non_std\" option.")
   394       else
   395         ()
   396     val _ =
   397       if not auto andalso
   398          exists (fn Type (@{type_name Datatype.node}, _) => true | _ => false)
   399                 all_Ts then
   400         print_m (K ("Warning: The problem involves directly or indirectly the \
   401                     \internal type " ^ quote @{type_name Datatype.node} ^
   402                     ". This type is very Nitpick-unfriendly, and its presence \
   403                     \usually indicates either a failure of abstraction or a \
   404                     \quirk in Nitpick."))
   405       else
   406         ()
   407     val (mono_Ts, nonmono_Ts) = List.partition is_type_monotonic all_Ts
   408     val _ =
   409       if verbose andalso not unique_scope then
   410         case filter_out is_type_fundamentally_monotonic mono_Ts of
   411           [] => ()
   412         | interesting_mono_Ts =>
   413           pprint_v (K (monotonicity_message interesting_mono_Ts
   414                           "Nitpick might be able to skip some scopes."))
   415       else
   416         ()
   417     val (deep_dataTs, shallow_dataTs) =
   418       all_Ts |> filter (is_datatype ctxt stds)
   419              |> List.partition is_datatype_deep
   420     val finitizable_dataTs =
   421       (deep_dataTs |> filter_out (is_finite_type hol_ctxt)
   422                    |> filter is_deep_datatype_finitizable) @
   423       (shallow_dataTs |> filter_out (is_finite_type hol_ctxt)
   424                       |> filter is_shallow_datatype_finitizable)
   425     val _ =
   426       if verbose andalso not (null finitizable_dataTs) then
   427         pprint_v (K (monotonicity_message finitizable_dataTs
   428                          "Nitpick can use a more precise finite encoding."))
   429       else
   430         ()
   431     (* This detection code is an ugly hack. Fortunately, it is used only to
   432        provide a hint to the user. *)
   433     fun is_struct_induct_step (name, (Rule_Cases.Case {fixes, assumes, ...}, _)) =
   434       not (null fixes) andalso
   435       exists (String.isSuffix ".hyps" o fst) assumes andalso
   436       exists (exists (curry (op =) name o shortest_name o fst)
   437               o datatype_constrs hol_ctxt) deep_dataTs
   438     val likely_in_struct_induct_step =
   439       exists is_struct_induct_step (ProofContext.cases_of ctxt)
   440     val _ = if standard andalso likely_in_struct_induct_step then
   441               pprint_m (fn () => Pretty.blk (0,
   442                   pstrs "Hint: To check that the induction hypothesis is \
   443                         \general enough, try this command: " @
   444                   [Pretty.mark Markup.sendback (Pretty.blk (0,
   445                        pstrs ("nitpick [non_std, show_all]")))] @ pstrs "."))
   446             else
   447               ()
   448 (*
   449     val _ = print_g "Monotonic types:"
   450     val _ = List.app (print_g o string_for_type ctxt) mono_Ts
   451     val _ = print_g "Nonmonotonic types:"
   452     val _ = List.app (print_g o string_for_type ctxt) nonmono_Ts
   453 *)
   454 
   455     val incremental = Int.max (max_potential, max_genuine) >= 2
   456     val actual_sat_solver =
   457       if sat_solver <> "smart" then
   458         if incremental andalso
   459            not (member (op =) (Kodkod_SAT.configured_sat_solvers true)
   460                        sat_solver) then
   461           (print_m (K ("An incremental SAT solver is required: \"SAT4J\" will \
   462                        \be used instead of " ^ quote sat_solver ^ "."));
   463            "SAT4J")
   464         else
   465           sat_solver
   466       else
   467         Kodkod_SAT.smart_sat_solver_name incremental
   468     val _ =
   469       if sat_solver = "smart" then
   470         print_v (fn () =>
   471             "Using SAT solver " ^ quote actual_sat_solver ^ ". The following" ^
   472             (if incremental then " incremental " else " ") ^
   473             "solvers are configured: " ^
   474             commas_quote (Kodkod_SAT.configured_sat_solvers incremental) ^ ".")
   475       else
   476         ()
   477 
   478     val too_big_scopes = Unsynchronized.ref []
   479 
   480     fun problem_for_scope unsound
   481             (scope as {card_assigns, bits, bisim_depth, datatypes, ofs, ...}) =
   482       let
   483         val _ = not (exists (fn other => scope_less_eq other scope)
   484                             (!too_big_scopes)) orelse
   485                 raise TOO_LARGE ("Nitpick.pick_them_nits_in_term.\
   486                                  \problem_for_scope", "too large scope")
   487 (*
   488         val _ = print_g "Offsets:"
   489         val _ = List.app (fn (T, j0) =>
   490                              print_g (string_for_type ctxt T ^ " = " ^
   491                                     string_of_int j0))
   492                          (Typtab.dest ofs)
   493 *)
   494         val all_exact = forall (is_exact_type datatypes true) all_Ts
   495         val main_j0 = offset_of_type ofs bool_T
   496         val (nat_card, nat_j0) = spec_of_type scope nat_T
   497         val (int_card, int_j0) = spec_of_type scope int_T
   498         val _ = (nat_j0 = main_j0 andalso int_j0 = main_j0) orelse
   499                 raise BAD ("Nitpick.pick_them_nits_in_term.problem_for_scope",
   500                            "bad offsets")
   501         val kk = kodkod_constrs peephole_optim nat_card int_card main_j0
   502         val (free_names, rep_table) =
   503           choose_reps_for_free_vars scope pseudo_frees free_names
   504                                     NameTable.empty
   505         val (sel_names, rep_table) = choose_reps_for_all_sels scope rep_table
   506         val (nonsel_names, rep_table) =
   507           choose_reps_for_consts scope all_exact nonsel_names rep_table
   508         val (guiltiest_party, min_highest_arity) =
   509           NameTable.fold (fn (name, R) => fn (s, n) =>
   510                              let val n' = arity_of_rep R in
   511                                if n' > n then (nickname_of name, n') else (s, n)
   512                              end) rep_table ("", 1)
   513         val min_univ_card =
   514           NameTable.fold (Integer.max o min_univ_card_of_rep o snd) rep_table
   515                          (univ_card nat_card int_card main_j0 [] KK.True)
   516         val _ = check_arity guiltiest_party min_univ_card min_highest_arity
   517 
   518         val def_us =
   519           def_us |> map (choose_reps_in_nut scope unsound rep_table true)
   520         val nondef_us =
   521           nondef_us |> map (choose_reps_in_nut scope unsound rep_table false)
   522         val needed_us =
   523           needed_us |> map (choose_reps_in_nut scope unsound rep_table false)
   524 (*
   525         val _ = List.app (print_g o string_for_nut ctxt)
   526                          (free_names @ sel_names @ nonsel_names @
   527                           nondef_us @ def_us)
   528 *)
   529         val (free_rels, pool, rel_table) =
   530           rename_free_vars free_names initial_pool NameTable.empty
   531         val (sel_rels, pool, rel_table) =
   532           rename_free_vars sel_names pool rel_table
   533         val (other_rels, pool, rel_table) =
   534           rename_free_vars nonsel_names pool rel_table
   535         val nondef_us = nondef_us |> map (rename_vars_in_nut pool rel_table)
   536         val def_us = def_us |> map (rename_vars_in_nut pool rel_table)
   537         val needed_us = needed_us |> map (rename_vars_in_nut pool rel_table)
   538         val nondef_fs = map (kodkod_formula_from_nut ofs kk) nondef_us
   539         val def_fs = map (kodkod_formula_from_nut ofs kk) def_us
   540         val formula = fold (fold s_and) [def_fs, nondef_fs] KK.True
   541         val comment = (if unsound then "unsound" else "sound") ^ "\n" ^
   542                       Print_Mode.setmp [] multiline_string_for_scope scope
   543         val kodkod_sat_solver =
   544           Kodkod_SAT.sat_solver_spec actual_sat_solver |> snd
   545         val bit_width = if bits = 0 then 16 else bits + 1
   546         val delay =
   547           if unsound then
   548             Option.map (fn time => Time.- (time, Time.now ())) deadline
   549             |> unsound_delay_for_timeout
   550           else
   551             0
   552         val settings = [("solver", commas_quote kodkod_sat_solver),
   553                         ("bit_width", string_of_int bit_width),
   554                         ("symmetry_breaking", string_of_int kodkod_sym_break),
   555                         ("sharing", "3"),
   556                         ("flatten", "false"),
   557                         ("delay", signed_string_of_int delay)]
   558         val plain_rels = free_rels @ other_rels
   559         val plain_bounds = map (bound_for_plain_rel ctxt debug) plain_rels
   560         val plain_axioms = map (declarative_axiom_for_plain_rel kk) plain_rels
   561         val sel_bounds = map (bound_for_sel_rel ctxt debug datatypes) sel_rels
   562         val dtype_axioms =
   563           declarative_axioms_for_datatypes hol_ctxt binarize needed_us
   564               datatype_sym_break bits ofs kk rel_table datatypes
   565         val declarative_axioms = plain_axioms @ dtype_axioms
   566         val univ_card = Int.max (univ_card nat_card int_card main_j0
   567                                      (plain_bounds @ sel_bounds) formula,
   568                                  main_j0 |> bits > 0 ? Integer.add (bits + 1))
   569         val (built_in_bounds, built_in_axioms) =
   570           bounds_and_axioms_for_built_in_rels_in_formulas debug univ_card
   571               nat_card int_card main_j0 (formula :: declarative_axioms)
   572         val bounds = built_in_bounds @ plain_bounds @ sel_bounds
   573                      |> not debug ? merge_bounds
   574         val axioms = built_in_axioms @ declarative_axioms
   575         val highest_arity =
   576           fold Integer.max (map (fst o fst) (maps fst bounds)) 0
   577         val formula = fold_rev s_and axioms formula
   578         val _ = if bits = 0 then () else check_bits bits formula
   579         val _ = if formula = KK.False then ()
   580                 else check_arity "" univ_card highest_arity
   581       in
   582         SOME ({comment = comment, settings = settings, univ_card = univ_card,
   583                tuple_assigns = [], bounds = bounds,
   584                int_bounds = if bits = 0 then sequential_int_bounds univ_card
   585                             else pow_of_two_int_bounds bits main_j0,
   586                expr_assigns = [], formula = formula},
   587               {free_names = free_names, sel_names = sel_names,
   588                nonsel_names = nonsel_names, rel_table = rel_table,
   589                unsound = unsound, scope = scope})
   590       end
   591       handle TOO_LARGE (loc, msg) =>
   592              if loc = "Nitpick_Kodkod.check_arity" andalso
   593                 not (Typtab.is_empty ofs) then
   594                problem_for_scope unsound
   595                    {hol_ctxt = hol_ctxt, binarize = binarize,
   596                     card_assigns = card_assigns, bits = bits,
   597                     bisim_depth = bisim_depth, datatypes = datatypes,
   598                     ofs = Typtab.empty}
   599              else if loc = "Nitpick.pick_them_nits_in_term.\
   600                            \problem_for_scope" then
   601                NONE
   602              else
   603                (Unsynchronized.change too_big_scopes (cons scope);
   604                 print_v (fn () => ("Limit reached: " ^ msg ^
   605                                    ". Skipping " ^ (if unsound then "potential"
   606                                                     else "genuine") ^
   607                                    " component of scope."));
   608                 NONE)
   609            | TOO_SMALL (_, msg) =>
   610              (print_v (fn () => ("Limit reached: " ^ msg ^
   611                                  ". Skipping " ^ (if unsound then "potential"
   612                                                   else "genuine") ^
   613                                  " component of scope."));
   614               NONE)
   615 
   616     val das_wort_model =
   617       (if falsify then "counterexample" else "model")
   618       |> not standard ? prefix "nonstandard "
   619 
   620     val scopes = Unsynchronized.ref []
   621     val generated_scopes = Unsynchronized.ref []
   622     val generated_problems = Unsynchronized.ref ([] : rich_problem list)
   623     val checked_problems = Unsynchronized.ref (SOME [])
   624     val met_potential = Unsynchronized.ref 0
   625 
   626     fun update_checked_problems problems =
   627       List.app (Unsynchronized.change checked_problems o Option.map o cons
   628                 o nth problems)
   629     fun show_kodkod_warning "" = ()
   630       | show_kodkod_warning s = print_m (fn () => "Kodkod warning: " ^ s ^ ".")
   631 
   632     fun print_and_check_model genuine bounds
   633             ({free_names, sel_names, nonsel_names, rel_table, scope, ...}
   634              : problem_extension) =
   635       let
   636         val (reconstructed_model, codatatypes_ok) =
   637           reconstruct_hol_model {show_datatypes = show_datatypes,
   638                                  show_consts = show_consts}
   639               scope formats atomss real_frees pseudo_frees free_names sel_names
   640               nonsel_names rel_table bounds
   641         val genuine_means_genuine =
   642           got_all_user_axioms andalso none_true wfs andalso
   643           sound_finitizes andalso codatatypes_ok
   644         fun assms_prop () = Logic.mk_conjunction_list (neg_t :: assm_ts)
   645       in
   646         (pprint (Pretty.chunks
   647              [Pretty.blk (0,
   648                   (pstrs ((if auto then "Auto " else "") ^ "Nitpick found a" ^
   649                           (if not genuine then " potential "
   650                            else if genuine_means_genuine then " "
   651                            else " quasi genuine ") ^ das_wort_model) @
   652                    (case pretties_for_scope scope verbose of
   653                       [] => []
   654                     | pretties => pstrs " for " @ pretties) @
   655                    [Pretty.str ":\n"])),
   656               Pretty.indent indent_size reconstructed_model]);
   657          if genuine then
   658            (if check_genuine andalso standard then
   659               case prove_hol_model scope tac_timeout free_names sel_names
   660                                    rel_table bounds (assms_prop ()) of
   661                 SOME true =>
   662                 print ("Confirmation by \"auto\": The above " ^
   663                        das_wort_model ^ " is really genuine.")
   664               | SOME false =>
   665                 if genuine_means_genuine then
   666                   error ("A supposedly genuine " ^ das_wort_model ^ " was \
   667                          \shown to be spurious by \"auto\".\nThis should never \
   668                          \happen.\nPlease send a bug report to blanchet\
   669                          \te@in.tum.de.")
   670                  else
   671                    print ("Refutation by \"auto\": The above " ^
   672                           das_wort_model ^ " is spurious.")
   673                | NONE => print "No confirmation by \"auto\"."
   674             else
   675               ();
   676             if not standard andalso likely_in_struct_induct_step then
   677               print "The existence of a nonstandard model suggests that the \
   678                     \induction hypothesis is not general enough or may even be \
   679                     \wrong. See the Nitpick manual's \"Inductive Properties\" \
   680                     \section for details (\"isabelle doc nitpick\")."
   681             else
   682               ();
   683             if has_lonely_bool_var orig_t then
   684               print "Hint: Maybe you forgot a colon after the lemma's name?"
   685             else if has_syntactic_sorts orig_t then
   686               print "Hint: Maybe you forgot a type constraint?"
   687             else
   688               ();
   689             if not genuine_means_genuine then
   690               if no_poly_user_axioms then
   691                 let
   692                   val options =
   693                     [] |> not got_all_mono_user_axioms
   694                           ? cons ("user_axioms", "\"true\"")
   695                        |> not (none_true wfs)
   696                           ? cons ("wf", "\"smart\" or \"false\"")
   697                        |> not sound_finitizes
   698                           ? cons ("finitize", "\"smart\" or \"false\"")
   699                        |> not codatatypes_ok
   700                           ? cons ("bisim_depth", "a nonnegative value")
   701                   val ss =
   702                     map (fn (name, value) => quote name ^ " set to " ^ value)
   703                         options
   704                 in
   705                   print ("Try again with " ^
   706                          implode (serial_commas "and" ss) ^
   707                          " to confirm that the " ^ das_wort_model ^
   708                          " is genuine.")
   709                 end
   710               else
   711                 print ("Nitpick is unable to guarantee the authenticity of \
   712                        \the " ^ das_wort_model ^ " in the presence of \
   713                        \polymorphic axioms.")
   714             else
   715               ();
   716             NONE)
   717          else
   718            if not genuine then
   719              (Unsynchronized.inc met_potential;
   720               if check_potential then
   721                 let
   722                   val status = prove_hol_model scope tac_timeout free_names
   723                                                sel_names rel_table bounds
   724                                                (assms_prop ())
   725                 in
   726                   (case status of
   727                      SOME true => print ("Confirmation by \"auto\": The \
   728                                          \above " ^ das_wort_model ^
   729                                          " is genuine.")
   730                    | SOME false => print ("Refutation by \"auto\": The above " ^
   731                                           das_wort_model ^ " is spurious.")
   732                    | NONE => print "No confirmation by \"auto\".");
   733                   status
   734                 end
   735               else
   736                 NONE)
   737            else
   738              NONE)
   739         |> pair genuine_means_genuine
   740       end
   741     fun solve_any_problem (found_really_genuine, max_potential, max_genuine,
   742                            donno) first_time problems =
   743       let
   744         val max_potential = Int.max (0, max_potential)
   745         val max_genuine = Int.max (0, max_genuine)
   746         fun print_and_check genuine (j, bounds) =
   747           print_and_check_model genuine bounds (snd (nth problems j))
   748         val max_solutions = max_potential + max_genuine
   749                             |> not incremental ? Integer.min 1
   750       in
   751         if max_solutions <= 0 then
   752           (found_really_genuine, 0, 0, donno)
   753         else
   754           case KK.solve_any_problem debug overlord deadline max_threads
   755                                     max_solutions (map fst problems) of
   756             KK.JavaNotInstalled =>
   757             (print_m install_java_message;
   758              (found_really_genuine, max_potential, max_genuine, donno + 1))
   759           | KK.JavaTooOld =>
   760             (print_m install_java_message;
   761              (found_really_genuine, max_potential, max_genuine, donno + 1))
   762           | KK.KodkodiNotInstalled =>
   763             (print_m install_kodkodi_message;
   764              (found_really_genuine, max_potential, max_genuine, donno + 1))
   765           | KK.Normal ([], unsat_js, s) =>
   766             (update_checked_problems problems unsat_js; show_kodkod_warning s;
   767              (found_really_genuine, max_potential, max_genuine, donno))
   768           | KK.Normal (sat_ps, unsat_js, s) =>
   769             let
   770               val (lib_ps, con_ps) =
   771                 List.partition (#unsound o snd o nth problems o fst) sat_ps
   772             in
   773               update_checked_problems problems (unsat_js @ map fst lib_ps);
   774               show_kodkod_warning s;
   775               if null con_ps then
   776                 let
   777                   val genuine_codes =
   778                     lib_ps |> take max_potential
   779                            |> map (print_and_check false)
   780                            |> filter (curry (op =) (SOME true) o snd)
   781                   val found_really_genuine =
   782                     found_really_genuine orelse exists fst genuine_codes
   783                   val num_genuine = length genuine_codes
   784                   val max_genuine = max_genuine - num_genuine
   785                   val max_potential = max_potential
   786                                       - (length lib_ps - num_genuine)
   787                 in
   788                   if max_genuine <= 0 then
   789                     (found_really_genuine, 0, 0, donno)
   790                   else
   791                     let
   792                       (* "co_js" is the list of sound problems whose unsound
   793                          pendants couldn't be satisfied and hence that most
   794                          probably can't be satisfied themselves. *)
   795                       val co_js =
   796                         map (fn j => j - 1) unsat_js
   797                         |> filter (fn j =>
   798                                       j >= 0 andalso
   799                                       scopes_equivalent
   800                                           (#scope (snd (nth problems j)),
   801                                            #scope (snd (nth problems (j + 1)))))
   802                       val bye_js = sort_distinct int_ord (map fst sat_ps @
   803                                                           unsat_js @ co_js)
   804                       val problems =
   805                         problems |> filter_out_indices bye_js
   806                                  |> max_potential <= 0
   807                                     ? filter_out (#unsound o snd)
   808                     in
   809                       solve_any_problem (found_really_genuine, max_potential,
   810                                          max_genuine, donno) false problems
   811                     end
   812                 end
   813               else
   814                 let
   815                   val genuine_codes =
   816                     con_ps |> take max_genuine
   817                            |> map (print_and_check true)
   818                   val max_genuine = max_genuine - length genuine_codes
   819                   val found_really_genuine =
   820                     found_really_genuine orelse exists fst genuine_codes
   821                 in
   822                   if max_genuine <= 0 orelse not first_time then
   823                     (found_really_genuine, 0, max_genuine, donno)
   824                   else
   825                     let
   826                       val bye_js = sort_distinct int_ord
   827                                                  (map fst sat_ps @ unsat_js)
   828                       val problems =
   829                         problems |> filter_out_indices bye_js
   830                                  |> filter_out (#unsound o snd)
   831                     in
   832                       solve_any_problem (found_really_genuine, 0, max_genuine,
   833                                          donno) false problems
   834                     end
   835                 end
   836             end
   837           | KK.TimedOut unsat_js =>
   838             (update_checked_problems problems unsat_js; raise TimeLimit.TimeOut)
   839           | KK.Error (s, unsat_js) =>
   840             (update_checked_problems problems unsat_js;
   841              print_v (K ("Kodkod error: " ^ s ^ "."));
   842              (found_really_genuine, max_potential, max_genuine, donno + 1))
   843       end
   844 
   845     fun run_batch j n scopes (found_really_genuine, max_potential, max_genuine,
   846                               donno) =
   847       let
   848         val _ =
   849           if null scopes then
   850             print_m (K "The scope specification is inconsistent.")
   851           else if verbose then
   852             pprint (Pretty.chunks
   853                 [Pretty.blk (0,
   854                      pstrs ((if n > 1 then
   855                                "Batch " ^ string_of_int (j + 1) ^ " of " ^
   856                                signed_string_of_int n ^ ": "
   857                              else
   858                                "") ^
   859                             "Trying " ^ string_of_int (length scopes) ^
   860                             " scope" ^ plural_s_for_list scopes ^ ":")),
   861                  Pretty.indent indent_size
   862                      (Pretty.chunks (map2
   863                           (fn j => fn scope =>
   864                               Pretty.block (
   865                                   (case pretties_for_scope scope true of
   866                                      [] => [Pretty.str "Empty"]
   867                                    | pretties => pretties) @
   868                                   [Pretty.str (if j = 1 then "." else ";")]))
   869                           (length scopes downto 1) scopes))])
   870           else
   871             ()
   872         fun add_problem_for_scope (scope, unsound) (problems, donno) =
   873           (check_deadline ();
   874            case problem_for_scope unsound scope of
   875              SOME problem =>
   876              (problems
   877               |> (null problems orelse
   878                   not (KK.problems_equivalent (fst problem, fst (hd problems))))
   879                   ? cons problem, donno)
   880            | NONE => (problems, donno + 1))
   881         val (problems, donno) =
   882           fold add_problem_for_scope
   883                (map_product pair scopes
   884                     ((if max_genuine > 0 then [false] else []) @
   885                      (if max_potential > 0 then [true] else [])))
   886                ([], donno)
   887         val _ = Unsynchronized.change generated_problems (append problems)
   888         val _ = Unsynchronized.change generated_scopes (append scopes)
   889         val _ =
   890           if j + 1 = n then
   891             let
   892               val (unsound_problems, sound_problems) =
   893                 List.partition (#unsound o snd) (!generated_problems)
   894             in
   895               if not (null sound_problems) andalso
   896                  forall (KK.is_problem_trivially_false o fst)
   897                         sound_problems then
   898                 print_m (fn () =>
   899                     "Warning: The conjecture either trivially holds for the \
   900                     \given scopes or lies outside Nitpick's supported \
   901                     \fragment." ^
   902                     (if exists (not o KK.is_problem_trivially_false o fst)
   903                                unsound_problems then
   904                        " Only potential " ^ das_wort_model ^ "s may be found."
   905                      else
   906                        ""))
   907               else
   908                 ()
   909             end
   910           else
   911             ()
   912       in
   913         solve_any_problem (found_really_genuine, max_potential, max_genuine,
   914                            donno) true (rev problems)
   915       end
   916 
   917     fun scope_count (problems : rich_problem list) scope =
   918       length (filter (curry scopes_equivalent scope o #scope o snd) problems)
   919     fun excipit did_so_and_so =
   920       let
   921         val do_filter =
   922           if !met_potential = max_potential then filter_out (#unsound o snd)
   923           else I
   924         val total = length (!scopes)
   925         val unsat =
   926           fold (fn scope =>
   927                    case scope_count (do_filter (!generated_problems)) scope of
   928                      0 => I
   929                    | n =>
   930                      scope_count (do_filter (these (!checked_problems)))
   931                                  scope = n
   932                      ? Integer.add 1) (!generated_scopes) 0
   933       in
   934         "Nitpick " ^ did_so_and_so ^
   935         (if is_some (!checked_problems) andalso total > 0 then
   936            " " ^ string_of_int unsat ^ " of " ^ string_of_int total ^ " scope"
   937            ^ plural_s total
   938          else
   939            "") ^ "."
   940       end
   941 
   942     val (skipped, the_scopes) =
   943       all_scopes hol_ctxt binarize cards_assigns maxes_assigns iters_assigns
   944                  bitss bisim_depths mono_Ts nonmono_Ts deep_dataTs
   945                  finitizable_dataTs
   946     val _ = if skipped > 0 then
   947               print_m (fn () => "Too many scopes. Skipping " ^
   948                                 string_of_int skipped ^ " scope" ^
   949                                 plural_s skipped ^
   950                                 ". (Consider using \"mono\" or \
   951                                 \\"merge_type_vars\" to prevent this.)")
   952             else
   953               ()
   954     val _ = scopes := the_scopes
   955 
   956     fun run_batches _ _ []
   957                     (found_really_genuine, max_potential, max_genuine, donno) =
   958         if donno > 0 andalso max_genuine > 0 then
   959           (print_m (fn () => excipit "checked"); "unknown")
   960         else if max_genuine = original_max_genuine then
   961           if max_potential = original_max_potential then
   962             (print_m (fn () =>
   963                  "Nitpick found no " ^ das_wort_model ^ "." ^
   964                  (if not standard andalso likely_in_struct_induct_step then
   965                     " This suggests that the induction hypothesis might be \
   966                     \general enough to prove this subgoal."
   967                   else
   968                     "")); if skipped > 0 then "unknown" else "none")
   969           else
   970             (print_m (fn () =>
   971                  excipit ("could not find a" ^
   972                           (if max_genuine = 1 then
   973                              " better " ^ das_wort_model ^ "."
   974                            else
   975                              "ny better " ^ das_wort_model ^ "s.") ^
   976                           " It checked"));
   977              "potential")
   978         else if found_really_genuine then
   979           "genuine"
   980         else
   981           "quasi_genuine"
   982       | run_batches j n (batch :: batches) z =
   983         let val (z as (_, _, max_genuine, _)) = run_batch j n batch z in
   984           run_batches (j + 1) n (if max_genuine > 0 then batches else []) z
   985         end
   986 
   987     val batches = batch_list batch_size (!scopes)
   988     val outcome_code =
   989       run_batches 0 (length batches) batches
   990                   (false, max_potential, max_genuine, 0)
   991       handle TimeLimit.TimeOut =>
   992              (print_m (fn () => excipit "ran out of time after checking");
   993               if !met_potential > 0 then "potential" else "unknown")
   994     val _ = print_v (fn () =>
   995                 "Total time: " ^ string_from_time (Timer.checkRealTimer timer) ^
   996                 ".")
   997   in (outcome_code, !state_ref) end
   998 
   999 (* Give the inner timeout a chance. *)
  1000 val timeout_bonus = seconds 1.0
  1001 
  1002 fun pick_nits_in_term state (params as {debug, timeout, expect, ...}) auto i n
  1003                       step subst assm_ts orig_t =
  1004   let val print_m = if auto then K () else Output.urgent_message in
  1005     if getenv "KODKODI" = "" then
  1006       (* The "expect" argument is deliberately ignored if Kodkodi is missing so
  1007          that the "Nitpick_Examples" can be processed on any machine. *)
  1008       (print_m (Pretty.string_of (plazy install_kodkodi_message));
  1009        ("no_kodkodi", state))
  1010     else
  1011       let
  1012         val unknown_outcome = ("unknown", state)
  1013         val deadline = Option.map (curry Time.+ (Time.now ())) timeout
  1014         val outcome as (outcome_code, _) =
  1015           time_limit (if debug orelse is_none timeout then NONE
  1016                       else SOME (Time.+ (the timeout, timeout_bonus)))
  1017               (pick_them_nits_in_term deadline state params auto i n step subst
  1018                                       assm_ts) orig_t
  1019           handle TOO_LARGE (_, details) =>
  1020                  (print_m ("Limit reached: " ^ details ^ "."); unknown_outcome)
  1021                | TOO_SMALL (_, details) =>
  1022                  (print_m ("Limit reached: " ^ details ^ "."); unknown_outcome)
  1023                | Kodkod.SYNTAX (_, details) =>
  1024                  (print_m ("Malformed Kodkodi output: " ^ details ^ ".");
  1025                   unknown_outcome)
  1026                | TimeLimit.TimeOut =>
  1027                  (print_m "Nitpick ran out of time."; unknown_outcome)
  1028       in
  1029         if expect = "" orelse outcome_code = expect then outcome
  1030         else error ("Unexpected outcome: " ^ quote outcome_code ^ ".")
  1031       end
  1032   end
  1033 
  1034 fun is_fixed_equation fixes
  1035                       (Const (@{const_name "=="}, _) $ Free (s, _) $ Const _) =
  1036     member (op =) fixes s
  1037   | is_fixed_equation _ _ = false
  1038 fun extract_fixed_frees ctxt (assms, t) =
  1039   let
  1040     val fixes = Variable.fixes_of ctxt |> map snd
  1041     val (subst, other_assms) =
  1042       List.partition (is_fixed_equation fixes) assms
  1043       |>> map Logic.dest_equals
  1044   in (subst, other_assms, subst_atomic subst t) end
  1045 
  1046 fun pick_nits_in_subgoal state params auto i step =
  1047   let
  1048     val ctxt = Proof.context_of state
  1049     val t = state |> Proof.raw_goal |> #goal |> prop_of
  1050   in
  1051     case Logic.count_prems t of
  1052       0 => (Output.urgent_message "No subgoal!"; ("none", state))
  1053     | n =>
  1054       let
  1055         val t = Logic.goal_params t i |> fst
  1056         val assms = map term_of (Assumption.all_assms_of ctxt)
  1057         val (subst, assms, t) = extract_fixed_frees ctxt (assms, t)
  1058       in pick_nits_in_term state params auto i n step subst assms t end
  1059   end
  1060 
  1061 end;