src/HOL/Tools/Nitpick/nitpick_mono.ML
changeset 36385 ff5f88702590
parent 35832 1dac16f00cd2
child 37256 0dca1ec52999
     1.1 --- a/src/HOL/Tools/Nitpick/nitpick_mono.ML	Sat Apr 24 16:17:30 2010 +0200
     1.2 +++ b/src/HOL/Tools/Nitpick/nitpick_mono.ML	Sat Apr 24 16:33:01 2010 +0200
     1.3 @@ -54,55 +54,42 @@
     1.4  exception MTYPE of string * mtyp list * typ list
     1.5  exception MTERM of string * mterm list
     1.6  
     1.7 -(* string -> unit *)
     1.8  fun print_g (_ : string) = ()
     1.9  (* val print_g = tracing *)
    1.10  
    1.11 -(* var -> string *)
    1.12  val string_for_var = signed_string_of_int
    1.13 -(* string -> var list -> string *)
    1.14  fun string_for_vars sep [] = "0\<^bsub>" ^ sep ^ "\<^esub>"
    1.15    | string_for_vars sep xs = space_implode sep (map string_for_var xs)
    1.16  fun subscript_string_for_vars sep xs =
    1.17    if null xs then "" else "\<^bsub>" ^ string_for_vars sep xs ^ "\<^esub>"
    1.18  
    1.19 -(* sign -> string *)
    1.20  fun string_for_sign Plus = "+"
    1.21    | string_for_sign Minus = "-"
    1.22  
    1.23 -(* sign -> sign -> sign *)
    1.24  fun xor sn1 sn2 = if sn1 = sn2 then Plus else Minus
    1.25 -(* sign -> sign *)
    1.26  val negate = xor Minus
    1.27  
    1.28 -(* sign_atom -> string *)
    1.29  fun string_for_sign_atom (S sn) = string_for_sign sn
    1.30    | string_for_sign_atom (V x) = string_for_var x
    1.31  
    1.32 -(* literal -> string *)
    1.33  fun string_for_literal (x, sn) = string_for_var x ^ " = " ^ string_for_sign sn
    1.34  
    1.35  val bool_M = MType (@{type_name bool}, [])
    1.36  val dummy_M = MType (nitpick_prefix ^ "dummy", [])
    1.37  
    1.38 -(* mtyp -> bool *)
    1.39  fun is_MRec (MRec _) = true
    1.40    | is_MRec _ = false
    1.41 -(* mtyp -> mtyp * sign_atom * mtyp *)
    1.42  fun dest_MFun (MFun z) = z
    1.43    | dest_MFun M = raise MTYPE ("Nitpick_Mono.dest_MFun", [M], [])
    1.44  
    1.45  val no_prec = 100
    1.46  
    1.47 -(* mtyp -> int *)
    1.48  fun precedence_of_mtype (MFun _) = 1
    1.49    | precedence_of_mtype (MPair _) = 2
    1.50    | precedence_of_mtype _ = no_prec
    1.51  
    1.52 -(* mtyp -> string *)
    1.53  val string_for_mtype =
    1.54    let
    1.55 -    (* int -> mtyp -> string *)
    1.56      fun aux outer_prec M =
    1.57        let
    1.58          val prec = precedence_of_mtype M
    1.59 @@ -126,22 +113,17 @@
    1.60        end
    1.61    in aux 0 end
    1.62  
    1.63 -(* mtyp -> mtyp list *)
    1.64  fun flatten_mtype (MPair (M1, M2)) = maps flatten_mtype [M1, M2]
    1.65    | flatten_mtype (MType (_, Ms)) = maps flatten_mtype Ms
    1.66    | flatten_mtype M = [M]
    1.67  
    1.68 -(* mterm -> bool *)
    1.69  fun precedence_of_mterm (MRaw _) = no_prec
    1.70    | precedence_of_mterm (MAbs _) = 1
    1.71    | precedence_of_mterm (MApp _) = 2
    1.72  
    1.73 -(* Proof.context -> mterm -> string *)
    1.74  fun string_for_mterm ctxt =
    1.75    let
    1.76 -    (* mtype -> string *)
    1.77      fun mtype_annotation M = "\<^bsup>" ^ string_for_mtype M ^ "\<^esup>"
    1.78 -    (* int -> mterm -> string *)
    1.79      fun aux outer_prec m =
    1.80        let
    1.81          val prec = precedence_of_mterm m
    1.82 @@ -158,7 +140,6 @@
    1.83        end
    1.84    in aux 0 end
    1.85  
    1.86 -(* mterm -> mtyp *)
    1.87  fun mtype_of_mterm (MRaw (_, M)) = M
    1.88    | mtype_of_mterm (MAbs (_, _, M, a, m)) = MFun (M, a, mtype_of_mterm m)
    1.89    | mtype_of_mterm (MApp (m1, _)) =
    1.90 @@ -166,29 +147,24 @@
    1.91        MFun (_, _, M12) => M12
    1.92      | M1 => raise MTYPE ("Nitpick_Mono.mtype_of_mterm", [M1], [])
    1.93  
    1.94 -(* mterm -> mterm * mterm list *)
    1.95  fun strip_mcomb (MApp (m1, m2)) = strip_mcomb m1 ||> (fn ms => append ms [m2])
    1.96    | strip_mcomb m = (m, [])
    1.97  
    1.98 -(* hol_context -> bool -> bool -> typ -> mdata *)
    1.99  fun initial_mdata hol_ctxt binarize no_harmless alpha_T =
   1.100    ({hol_ctxt = hol_ctxt, binarize = binarize, alpha_T = alpha_T,
   1.101      no_harmless = no_harmless, max_fresh = Unsynchronized.ref 0,
   1.102      datatype_mcache = Unsynchronized.ref [],
   1.103      constr_mcache = Unsynchronized.ref []} : mdata)
   1.104  
   1.105 -(* typ -> typ -> bool *)
   1.106  fun could_exist_alpha_subtype alpha_T (T as Type (_, Ts)) =
   1.107      T = alpha_T orelse (not (is_fp_iterator_type T) andalso
   1.108                          exists (could_exist_alpha_subtype alpha_T) Ts)
   1.109    | could_exist_alpha_subtype alpha_T T = (T = alpha_T)
   1.110 -(* theory -> typ -> typ -> bool *)
   1.111  fun could_exist_alpha_sub_mtype _ (alpha_T as TFree _) T =
   1.112      could_exist_alpha_subtype alpha_T T
   1.113    | could_exist_alpha_sub_mtype thy alpha_T T =
   1.114      (T = alpha_T orelse is_datatype thy [(NONE, true)] T)
   1.115  
   1.116 -(* mtyp -> bool *)
   1.117  fun exists_alpha_sub_mtype MAlpha = true
   1.118    | exists_alpha_sub_mtype (MFun (M1, _, M2)) =
   1.119      exists exists_alpha_sub_mtype [M1, M2]
   1.120 @@ -197,7 +173,6 @@
   1.121    | exists_alpha_sub_mtype (MType (_, Ms)) = exists exists_alpha_sub_mtype Ms
   1.122    | exists_alpha_sub_mtype (MRec _) = true
   1.123  
   1.124 -(* mtyp -> bool *)
   1.125  fun exists_alpha_sub_mtype_fresh MAlpha = true
   1.126    | exists_alpha_sub_mtype_fresh (MFun (_, V _, _)) = true
   1.127    | exists_alpha_sub_mtype_fresh (MFun (_, _, M2)) =
   1.128 @@ -208,11 +183,9 @@
   1.129      exists exists_alpha_sub_mtype_fresh Ms
   1.130    | exists_alpha_sub_mtype_fresh (MRec _) = true
   1.131  
   1.132 -(* string * typ list -> mtyp list -> mtyp *)
   1.133  fun constr_mtype_for_binders z Ms =
   1.134    fold_rev (fn M => curry3 MFun M (S Minus)) Ms (MRec z)
   1.135  
   1.136 -(* ((string * typ list) * mtyp) list -> mtyp list -> mtyp -> mtyp *)
   1.137  fun repair_mtype _ _ MAlpha = MAlpha
   1.138    | repair_mtype cache seen (MFun (M1, a, M2)) =
   1.139      MFun (repair_mtype cache seen M1, a, repair_mtype cache seen M2)
   1.140 @@ -226,30 +199,24 @@
   1.141      | M => if member (op =) seen M then MType (s, [])
   1.142             else repair_mtype cache (M :: seen) M
   1.143  
   1.144 -(* ((string * typ list) * mtyp) list Unsynchronized.ref -> unit *)
   1.145  fun repair_datatype_mcache cache =
   1.146    let
   1.147 -    (* (string * typ list) * mtyp -> unit *)
   1.148      fun repair_one (z, M) =
   1.149        Unsynchronized.change cache
   1.150            (AList.update (op =) (z, repair_mtype (!cache) [] M))
   1.151    in List.app repair_one (rev (!cache)) end
   1.152  
   1.153 -(* (typ * mtyp) list -> (styp * mtyp) list Unsynchronized.ref -> unit *)
   1.154  fun repair_constr_mcache dtype_cache constr_mcache =
   1.155    let
   1.156 -    (* styp * mtyp -> unit *)
   1.157      fun repair_one (x, M) =
   1.158        Unsynchronized.change constr_mcache
   1.159            (AList.update (op =) (x, repair_mtype dtype_cache [] M))
   1.160    in List.app repair_one (!constr_mcache) end
   1.161  
   1.162 -(* typ -> bool *)
   1.163  fun is_fin_fun_supported_type @{typ prop} = true
   1.164    | is_fin_fun_supported_type @{typ bool} = true
   1.165    | is_fin_fun_supported_type (Type (@{type_name option}, _)) = true
   1.166    | is_fin_fun_supported_type _ = false
   1.167 -(* typ -> typ -> term -> term option *)
   1.168  fun fin_fun_body _ _ (t as @{term False}) = SOME t
   1.169    | fin_fun_body _ _ (t as Const (@{const_name None}, _)) = SOME t
   1.170    | fin_fun_body dom_T ran_T
   1.171 @@ -265,7 +232,6 @@
   1.172                  $ (Const (@{const_name unknown}, ran_T)) $ (t0 $ t1 $ t2 $ t3)))
   1.173    | fin_fun_body _ _ _ = NONE
   1.174  
   1.175 -(* mdata -> bool -> typ -> typ -> mtyp * sign_atom * mtyp *)
   1.176  fun fresh_mfun_for_fun_type (mdata as {max_fresh, ...} : mdata) all_minus
   1.177                              T1 T2 =
   1.178    let
   1.179 @@ -277,12 +243,10 @@
   1.180              else
   1.181                S Minus
   1.182    in (M1, a, M2) end
   1.183 -(* mdata -> bool -> typ -> mtyp *)
   1.184  and fresh_mtype_for_type (mdata as {hol_ctxt as {thy, ...}, binarize, alpha_T,
   1.185                                      datatype_mcache, constr_mcache, ...})
   1.186                           all_minus =
   1.187    let
   1.188 -    (* typ -> mtyp *)
   1.189      fun do_type T =
   1.190        if T = alpha_T then
   1.191          MAlpha
   1.192 @@ -329,21 +293,17 @@
   1.193        | _ => MType (Refute.string_of_typ T, [])
   1.194    in do_type end
   1.195  
   1.196 -(* mtyp -> mtyp list *)
   1.197  fun prodM_factors (MPair (M1, M2)) = maps prodM_factors [M1, M2]
   1.198    | prodM_factors M = [M]
   1.199 -(* mtyp -> mtyp list * mtyp *)
   1.200  fun curried_strip_mtype (MFun (M1, _, M2)) =
   1.201      curried_strip_mtype M2 |>> append (prodM_factors M1)
   1.202    | curried_strip_mtype M = ([], M)
   1.203 -(* string -> mtyp -> mtyp *)
   1.204  fun sel_mtype_from_constr_mtype s M =
   1.205    let val (arg_Ms, dataM) = curried_strip_mtype M in
   1.206      MFun (dataM, S Minus,
   1.207            case sel_no_from_name s of ~1 => bool_M | n => nth arg_Ms n)
   1.208    end
   1.209  
   1.210 -(* mdata -> styp -> mtyp *)
   1.211  fun mtype_for_constr (mdata as {hol_ctxt = {thy, ...}, alpha_T, constr_mcache,
   1.212                                  ...}) (x as (_, T)) =
   1.213    if could_exist_alpha_sub_mtype thy alpha_T T then
   1.214 @@ -362,14 +322,11 @@
   1.215    x |> binarized_and_boxed_constr_for_sel hol_ctxt binarize
   1.216      |> mtype_for_constr mdata |> sel_mtype_from_constr_mtype s
   1.217  
   1.218 -(* literal list -> sign_atom -> sign_atom *)
   1.219  fun resolve_sign_atom lits (V x) =
   1.220      x |> AList.lookup (op =) lits |> Option.map S |> the_default (V x)
   1.221    | resolve_sign_atom _ a = a
   1.222 -(* literal list -> mtyp -> mtyp *)
   1.223  fun resolve_mtype lits =
   1.224    let
   1.225 -    (* mtyp -> mtyp *)
   1.226      fun aux MAlpha = MAlpha
   1.227        | aux (MFun (M1, a, M2)) = MFun (aux M1, resolve_sign_atom lits a, aux M2)
   1.228        | aux (MPair Mp) = MPair (pairself aux Mp)
   1.229 @@ -384,24 +341,19 @@
   1.230  
   1.231  type constraint_set = literal list * comp list * sign_expr list
   1.232  
   1.233 -(* comp_op -> string *)
   1.234  fun string_for_comp_op Eq = "="
   1.235    | string_for_comp_op Leq = "\<le>"
   1.236  
   1.237 -(* sign_expr -> string *)
   1.238  fun string_for_sign_expr [] = "\<bot>"
   1.239    | string_for_sign_expr lits =
   1.240      space_implode " \<or> " (map string_for_literal lits)
   1.241  
   1.242 -(* literal -> literal list option -> literal list option *)
   1.243  fun do_literal _ NONE = NONE
   1.244    | do_literal (x, sn) (SOME lits) =
   1.245      case AList.lookup (op =) lits x of
   1.246        SOME sn' => if sn = sn' then SOME lits else NONE
   1.247      | NONE => SOME ((x, sn) :: lits)
   1.248  
   1.249 -(* comp_op -> var list -> sign_atom -> sign_atom -> literal list * comp list
   1.250 -   -> (literal list * comp list) option *)
   1.251  fun do_sign_atom_comp Eq [] a1 a2 (accum as (lits, comps)) =
   1.252      (case (a1, a2) of
   1.253         (S sn1, S sn2) => if sn1 = sn2 then SOME accum else NONE
   1.254 @@ -419,8 +371,6 @@
   1.255    | do_sign_atom_comp cmp xs a1 a2 (lits, comps) =
   1.256      SOME (lits, insert (op =) (a1, a2, cmp, xs) comps)
   1.257  
   1.258 -(* comp -> var list -> mtyp -> mtyp -> (literal list * comp list) option
   1.259 -   -> (literal list * comp list) option *)
   1.260  fun do_mtype_comp _ _ _ _ NONE = NONE
   1.261    | do_mtype_comp _ _ MAlpha MAlpha accum = accum
   1.262    | do_mtype_comp Eq xs (MFun (M11, a1, M12)) (MFun (M21, a2, M22))
   1.263 @@ -450,7 +400,6 @@
   1.264      raise MTYPE ("Nitpick_Mono.do_mtype_comp (" ^ string_for_comp_op cmp ^ ")",
   1.265                   [M1, M2], [])
   1.266  
   1.267 -(* comp_op -> mtyp -> mtyp -> constraint_set -> constraint_set *)
   1.268  fun add_mtype_comp cmp M1 M2 ((lits, comps, sexps) : constraint_set) =
   1.269      (print_g ("*** Add " ^ string_for_mtype M1 ^ " " ^ string_for_comp_op cmp ^
   1.270                " " ^ string_for_mtype M2);
   1.271 @@ -458,12 +407,9 @@
   1.272         NONE => (print_g "**** Unsolvable"; raise UNSOLVABLE ())
   1.273       | SOME (lits, comps) => (lits, comps, sexps))
   1.274  
   1.275 -(* mtyp -> mtyp -> constraint_set -> constraint_set *)
   1.276  val add_mtypes_equal = add_mtype_comp Eq
   1.277  val add_is_sub_mtype = add_mtype_comp Leq
   1.278  
   1.279 -(* sign -> sign_expr -> mtyp -> (literal list * sign_expr list) option
   1.280 -   -> (literal list * sign_expr list) option *)
   1.281  fun do_notin_mtype_fv _ _ _ NONE = NONE
   1.282    | do_notin_mtype_fv Minus _ MAlpha accum = accum
   1.283    | do_notin_mtype_fv Plus [] MAlpha _ = NONE
   1.284 @@ -499,7 +445,6 @@
   1.285    | do_notin_mtype_fv _ _ M _ =
   1.286      raise MTYPE ("Nitpick_Mono.do_notin_mtype_fv", [M], [])
   1.287  
   1.288 -(* sign -> mtyp -> constraint_set -> constraint_set *)
   1.289  fun add_notin_mtype_fv sn M ((lits, comps, sexps) : constraint_set) =
   1.290      (print_g ("*** Add " ^ string_for_mtype M ^ " is " ^
   1.291                (case sn of Minus => "concrete" | Plus => "complete") ^ ".");
   1.292 @@ -507,31 +452,23 @@
   1.293         NONE => (print_g "**** Unsolvable"; raise UNSOLVABLE ())
   1.294       | SOME (lits, sexps) => (lits, comps, sexps))
   1.295  
   1.296 -(* mtyp -> constraint_set -> constraint_set *)
   1.297  val add_mtype_is_concrete = add_notin_mtype_fv Minus
   1.298  val add_mtype_is_complete = add_notin_mtype_fv Plus
   1.299  
   1.300  val bool_from_minus = true
   1.301  
   1.302 -(* sign -> bool *)
   1.303  fun bool_from_sign Plus = not bool_from_minus
   1.304    | bool_from_sign Minus = bool_from_minus
   1.305 -(* bool -> sign *)
   1.306  fun sign_from_bool b = if b = bool_from_minus then Minus else Plus
   1.307  
   1.308 -(* literal -> PropLogic.prop_formula *)
   1.309  fun prop_for_literal (x, sn) =
   1.310    (not (bool_from_sign sn) ? PropLogic.Not) (PropLogic.BoolVar x)
   1.311 -(* sign_atom -> PropLogic.prop_formula *)
   1.312  fun prop_for_sign_atom_eq (S sn', sn) =
   1.313      if sn = sn' then PropLogic.True else PropLogic.False
   1.314    | prop_for_sign_atom_eq (V x, sn) = prop_for_literal (x, sn)
   1.315 -(* sign_expr -> PropLogic.prop_formula *)
   1.316  fun prop_for_sign_expr xs = PropLogic.exists (map prop_for_literal xs)
   1.317 -(* var list -> sign -> PropLogic.prop_formula *)
   1.318  fun prop_for_exists_eq xs sn =
   1.319    PropLogic.exists (map (fn x => prop_for_literal (x, sn)) xs)
   1.320 -(* comp -> PropLogic.prop_formula *)
   1.321  fun prop_for_comp (a1, a2, Eq, []) =
   1.322      PropLogic.SAnd (prop_for_comp (a1, a2, Leq, []),
   1.323                      prop_for_comp (a2, a1, Leq, []))
   1.324 @@ -541,7 +478,6 @@
   1.325    | prop_for_comp (a1, a2, cmp, xs) =
   1.326      PropLogic.SOr (prop_for_exists_eq xs Minus, prop_for_comp (a1, a2, cmp, []))
   1.327  
   1.328 -(* var -> (int -> bool option) -> literal list -> literal list *)
   1.329  fun literals_from_assignments max_var assigns lits =
   1.330    fold (fn x => fn accum =>
   1.331             if AList.defined (op =) lits x then
   1.332 @@ -550,18 +486,15 @@
   1.333               SOME b => (x, sign_from_bool b) :: accum
   1.334             | NONE => accum) (max_var downto 1) lits
   1.335  
   1.336 -(* comp -> string *)
   1.337  fun string_for_comp (a1, a2, cmp, xs) =
   1.338    string_for_sign_atom a1 ^ " " ^ string_for_comp_op cmp ^
   1.339    subscript_string_for_vars " \<and> " xs ^ " " ^ string_for_sign_atom a2
   1.340  
   1.341 -(* literal list -> comp list -> sign_expr list -> unit *)
   1.342  fun print_problem lits comps sexps =
   1.343    print_g ("*** Problem:\n" ^ cat_lines (map string_for_literal lits @
   1.344                                           map string_for_comp comps @
   1.345                                           map string_for_sign_expr sexps))
   1.346  
   1.347 -(* literal list -> unit *)
   1.348  fun print_solution lits =
   1.349    let val (pos, neg) = List.partition (curry (op =) Plus o snd) lits in
   1.350      print_g ("*** Solution:\n" ^
   1.351 @@ -569,10 +502,8 @@
   1.352               "-: " ^ commas (map (string_for_var o fst) neg))
   1.353    end
   1.354  
   1.355 -(* var -> constraint_set -> literal list option *)
   1.356  fun solve max_var (lits, comps, sexps) =
   1.357      let
   1.358 -      (* (int -> bool option) -> literal list option *)
   1.359        fun do_assigns assigns =
   1.360          SOME (literals_from_assignments max_var assigns lits
   1.361                |> tap print_solution)
   1.362 @@ -607,27 +538,21 @@
   1.363  
   1.364  val initial_gamma = {bound_Ts = [], bound_Ms = [], frees = [], consts = []}
   1.365  
   1.366 -(* typ -> mtyp -> mtype_context -> mtype_context *)
   1.367  fun push_bound T M {bound_Ts, bound_Ms, frees, consts} =
   1.368    {bound_Ts = T :: bound_Ts, bound_Ms = M :: bound_Ms, frees = frees,
   1.369     consts = consts}
   1.370 -(* mtype_context -> mtype_context *)
   1.371  fun pop_bound {bound_Ts, bound_Ms, frees, consts} =
   1.372    {bound_Ts = tl bound_Ts, bound_Ms = tl bound_Ms, frees = frees,
   1.373     consts = consts}
   1.374    handle List.Empty => initial_gamma (* FIXME: needed? *)
   1.375  
   1.376 -(* mdata -> term -> accumulator -> mterm * accumulator *)
   1.377  fun consider_term (mdata as {hol_ctxt as {thy, ctxt, stds, fast_descrs,
   1.378                                            def_table, ...},
   1.379                               alpha_T, max_fresh, ...}) =
   1.380    let
   1.381 -    (* typ -> mtyp *)
   1.382      val mtype_for = fresh_mtype_for_type mdata false
   1.383 -    (* mtyp -> mtyp *)
   1.384      fun plus_set_mtype_for_dom M =
   1.385        MFun (M, S (if exists_alpha_sub_mtype M then Plus else Minus), bool_M)
   1.386 -    (* typ -> accumulator -> mterm * accumulator *)
   1.387      fun do_all T (gamma, cset) =
   1.388        let
   1.389          val abs_M = mtype_for (domain_type (domain_type T))
   1.390 @@ -656,7 +581,6 @@
   1.391        let
   1.392          val set_T = domain_type T
   1.393          val set_M = mtype_for set_T
   1.394 -        (* typ -> mtyp *)
   1.395          fun custom_mtype_for (T as Type (@{type_name fun}, [T1, T2])) =
   1.396              if T = set_T then set_M
   1.397              else MFun (custom_mtype_for T1, S Minus, custom_mtype_for T2)
   1.398 @@ -664,20 +588,16 @@
   1.399        in
   1.400          (custom_mtype_for T, (gamma, cset |> add_mtype_is_concrete set_M))
   1.401        end
   1.402 -    (* typ -> accumulator -> mtyp * accumulator *)
   1.403      fun do_pair_constr T accum =
   1.404        case mtype_for (nth_range_type 2 T) of
   1.405          M as MPair (a_M, b_M) =>
   1.406          (MFun (a_M, S Minus, MFun (b_M, S Minus, M)), accum)
   1.407        | M => raise MTYPE ("Nitpick_Mono.consider_term.do_pair_constr", [M], [])
   1.408 -    (* int -> typ -> accumulator -> mtyp * accumulator *)
   1.409      fun do_nth_pair_sel n T =
   1.410        case mtype_for (domain_type T) of
   1.411          M as MPair (a_M, b_M) =>
   1.412          pair (MFun (M, S Minus, if n = 0 then a_M else b_M))
   1.413        | M => raise MTYPE ("Nitpick_Mono.consider_term.do_nth_pair_sel", [M], [])
   1.414 -    (* term -> string -> typ -> term -> term -> term -> accumulator
   1.415 -       -> mterm * accumulator *)
   1.416      fun do_bounded_quantifier t0 abs_s abs_T connective_t bound_t body_t accum =
   1.417        let
   1.418          val abs_M = mtype_for abs_T
   1.419 @@ -697,7 +617,6 @@
   1.420                                   MApp (bound_m, MRaw (Bound 0, M1))),
   1.421                             body_m))), accum)
   1.422        end
   1.423 -    (* term -> accumulator -> mterm * accumulator *)
   1.424      and do_term t (accum as (gamma as {bound_Ts, bound_Ms, frees, consts},
   1.425                               cset)) =
   1.426          (case t of
   1.427 @@ -747,7 +666,6 @@
   1.428                | @{const_name converse} =>
   1.429                  let
   1.430                    val x = Unsynchronized.inc max_fresh
   1.431 -                  (* typ -> mtyp *)
   1.432                    fun mtype_for_set T =
   1.433                      MFun (mtype_for (domain_type T), V x, bool_M)
   1.434                    val ab_set_M = domain_type T |> mtype_for_set
   1.435 @@ -757,7 +675,6 @@
   1.436                | @{const_name rel_comp} =>
   1.437                  let
   1.438                    val x = Unsynchronized.inc max_fresh
   1.439 -                  (* typ -> mtyp *)
   1.440                    fun mtype_for_set T =
   1.441                      MFun (mtype_for (domain_type T), V x, bool_M)
   1.442                    val bc_set_M = domain_type T |> mtype_for_set
   1.443 @@ -783,7 +700,6 @@
   1.444                | @{const_name Sigma} =>
   1.445                  let
   1.446                    val x = Unsynchronized.inc max_fresh
   1.447 -                  (* typ -> mtyp *)
   1.448                    fun mtype_for_set T =
   1.449                      MFun (mtype_for (domain_type T), V x, bool_M)
   1.450                    val a_set_T = domain_type T
   1.451 @@ -891,14 +807,12 @@
   1.452                                        string_for_mterm ctxt m))
   1.453    in do_term end
   1.454  
   1.455 -(* int -> mtyp -> accumulator -> accumulator *)
   1.456  fun force_minus_funs 0 _ = I
   1.457    | force_minus_funs n (M as MFun (M1, _, M2)) =
   1.458      add_mtypes_equal M (MFun (M1, S Minus, M2))
   1.459      #> force_minus_funs (n - 1) M2
   1.460    | force_minus_funs _ M =
   1.461      raise MTYPE ("Nitpick_Mono.force_minus_funs", [M], [])
   1.462 -(* mdata -> bool -> styp -> term -> term -> mterm * accumulator *)
   1.463  fun consider_general_equals mdata def (x as (_, T)) t1 t2 accum =
   1.464    let
   1.465      val (m1, accum) = consider_term mdata t1 accum
   1.466 @@ -918,17 +832,12 @@
   1.467            accum)
   1.468    end
   1.469  
   1.470 -(* mdata -> sign -> term -> accumulator -> mterm * accumulator *)
   1.471  fun consider_general_formula (mdata as {hol_ctxt = {ctxt, ...}, ...}) =
   1.472    let
   1.473 -    (* typ -> mtyp *)
   1.474      val mtype_for = fresh_mtype_for_type mdata false
   1.475 -    (* term -> accumulator -> mterm * accumulator *)
   1.476      val do_term = consider_term mdata
   1.477 -    (* sign -> term -> accumulator -> mterm * accumulator *)
   1.478      fun do_formula sn t accum =
   1.479          let
   1.480 -          (* styp -> string -> typ -> term -> mterm * accumulator *)
   1.481            fun do_quantifier (quant_x as (quant_s, _)) abs_s abs_T body_t =
   1.482              let
   1.483                val abs_M = mtype_for abs_T
   1.484 @@ -944,7 +853,6 @@
   1.485                       MAbs (abs_s, abs_T, abs_M, S Minus, body_m)),
   1.486                 accum |>> pop_bound)
   1.487              end
   1.488 -          (* styp -> term -> term -> mterm * accumulator *)
   1.489            fun do_equals x t1 t2 =
   1.490              case sn of
   1.491                Plus => do_term t accum
   1.492 @@ -1005,7 +913,6 @@
   1.493    [@{const_name ord_class.less}, @{const_name ord_class.less_eq}]
   1.494  val bounteous_consts = [@{const_name bisim}]
   1.495  
   1.496 -(* mdata -> term -> bool *)
   1.497  fun is_harmless_axiom ({no_harmless = true, ...} : mdata) _ = false
   1.498    | is_harmless_axiom {hol_ctxt = {thy, stds, fast_descrs, ...}, ...} t =
   1.499      Term.add_consts t []
   1.500 @@ -1013,12 +920,10 @@
   1.501      |> (forall (member (op =) harmless_consts o original_name o fst) orf
   1.502          exists (member (op =) bounteous_consts o fst))
   1.503  
   1.504 -(* mdata -> term -> accumulator -> mterm * accumulator *)
   1.505  fun consider_nondefinitional_axiom mdata t =
   1.506    if is_harmless_axiom mdata t then pair (MRaw (t, dummy_M))
   1.507    else consider_general_formula mdata Plus t
   1.508  
   1.509 -(* mdata -> term -> accumulator -> mterm * accumulator *)
   1.510  fun consider_definitional_axiom (mdata as {hol_ctxt = {thy, ...}, ...}) t =
   1.511    if not (is_constr_pattern_formula thy t) then
   1.512      consider_nondefinitional_axiom mdata t
   1.513 @@ -1026,11 +931,8 @@
   1.514      pair (MRaw (t, dummy_M))
   1.515    else
   1.516      let
   1.517 -      (* typ -> mtyp *)
   1.518        val mtype_for = fresh_mtype_for_type mdata false
   1.519 -      (* term -> accumulator -> mterm * accumulator *)
   1.520        val do_term = consider_term mdata
   1.521 -      (* term -> string -> typ -> term -> accumulator -> mterm * accumulator *)
   1.522        fun do_all quant_t abs_s abs_T body_t accum =
   1.523          let
   1.524            val abs_M = mtype_for abs_T
   1.525 @@ -1043,7 +945,6 @@
   1.526                   MAbs (abs_s, abs_T, abs_M, S Minus, body_m)),
   1.527             accum |>> pop_bound)
   1.528          end
   1.529 -      (* term -> term -> term -> accumulator -> mterm * accumulator *)
   1.530        and do_conjunction t0 t1 t2 accum =
   1.531          let
   1.532            val (m1, accum) = do_formula t1 accum
   1.533 @@ -1058,7 +959,6 @@
   1.534          in
   1.535            (MApp (MApp (MRaw (t0, mtype_for (fastype_of t0)), m1), m2), accum)
   1.536          end
   1.537 -      (* term -> accumulator -> accumulator *)
   1.538        and do_formula t accum =
   1.539            case t of
   1.540              (t0 as Const (@{const_name all}, _)) $ Abs (s1, T1, t1) =>
   1.541 @@ -1083,22 +983,17 @@
   1.542                               \do_formula", [t])
   1.543      in do_formula t end
   1.544  
   1.545 -(* Proof.context -> literal list -> term -> mtyp -> string *)
   1.546  fun string_for_mtype_of_term ctxt lits t M =
   1.547    Syntax.string_of_term ctxt t ^ " : " ^ string_for_mtype (resolve_mtype lits M)
   1.548  
   1.549 -(* theory -> literal list -> mtype_context -> unit *)
   1.550  fun print_mtype_context ctxt lits ({frees, consts, ...} : mtype_context) =
   1.551    map (fn (x, M) => string_for_mtype_of_term ctxt lits (Free x) M) frees @
   1.552    map (fn (x, M) => string_for_mtype_of_term ctxt lits (Const x) M) consts
   1.553    |> cat_lines |> print_g
   1.554  
   1.555 -(* ('a -> 'b -> 'c * 'd) -> 'a -> 'c list * 'b -> 'c list * 'd *)
   1.556  fun amass f t (ms, accum) =
   1.557    let val (m, accum) = f t accum in (m :: ms, accum) end
   1.558  
   1.559 -(* string -> bool -> hol_context -> bool -> typ -> term list * term list
   1.560 -   -> (literal list * (mterm list * mterm list) * (styp * mtyp) list) option *)
   1.561  fun infer which no_harmless (hol_ctxt as {ctxt, ...}) binarize alpha_T
   1.562            (nondef_ts, def_ts) =
   1.563    let
   1.564 @@ -1127,15 +1022,11 @@
   1.565         | MTERM (loc, ms) =>
   1.566           raise BAD (loc, commas (map (string_for_mterm ctxt) ms))
   1.567  
   1.568 -(* hol_context -> bool -> typ -> term list * term list -> bool *)
   1.569  val formulas_monotonic = is_some oooo infer "Monotonicity" false
   1.570  
   1.571 -(* typ -> typ -> styp *)
   1.572  fun fin_fun_constr T1 T2 =
   1.573    (@{const_name FinFun}, (T1 --> T2) --> Type (@{type_name fin_fun}, [T1, T2]))
   1.574  
   1.575 -(* hol_context -> bool -> (typ option * bool option) list -> typ
   1.576 -   -> term list * term list -> term list * term list *)
   1.577  fun finitize_funs (hol_ctxt as {thy, stds, fast_descrs, constr_cache, ...})
   1.578                    binarize finitizes alpha_T tsp =
   1.579    case infer "Finiteness" true hol_ctxt binarize alpha_T tsp of
   1.580 @@ -1144,12 +1035,10 @@
   1.581        tsp
   1.582      else
   1.583        let
   1.584 -        (* typ -> sign_atom -> bool *)
   1.585          fun should_finitize T a =
   1.586            case triple_lookup (type_match thy) finitizes T of
   1.587              SOME (SOME false) => false
   1.588            | _ => resolve_sign_atom lits a = S Plus
   1.589 -        (* typ -> mtyp -> typ *)
   1.590          fun type_from_mtype T M =
   1.591            case (M, T) of
   1.592              (MAlpha, _) => T
   1.593 @@ -1161,12 +1050,10 @@
   1.594            | (MType _, _) => T
   1.595            | _ => raise MTYPE ("Nitpick_Mono.finitize_funs.type_from_mtype",
   1.596                                [M], [T])
   1.597 -        (* styp -> styp *)
   1.598          fun finitize_constr (x as (s, T)) =
   1.599            (s, case AList.lookup (op =) constr_mtypes x of
   1.600                  SOME M => type_from_mtype T M
   1.601                | NONE => T)
   1.602 -        (* typ list -> mterm -> term *)
   1.603          fun term_from_mterm Ts m =
   1.604            case m of
   1.605              MRaw (t, M) =>