src/HOL/Tools/Nitpick/nitpick_scope.ML
author wenzelm
Tue Sep 26 20:54:40 2017 +0200 (24 months ago)
changeset 66695 91500c024c7f
parent 59058 a78612c67ec0
child 69593 3dda49e08b9d
permissions -rw-r--r--
tuned;
     1 (*  Title:      HOL/Tools/Nitpick/nitpick_scope.ML
     2     Author:     Jasmin Blanchette, TU Muenchen
     3     Copyright   2008, 2009, 2010
     4 
     5 Scope enumerator for Nitpick.
     6 *)
     7 
     8 signature NITPICK_SCOPE =
     9 sig
    10   type hol_context = Nitpick_HOL.hol_context
    11 
    12   type constr_spec =
    13     {const: string * typ,
    14      delta: int,
    15      epsilon: int,
    16      exclusive: bool,
    17      explicit_max: int,
    18      total: bool}
    19 
    20   type data_type_spec =
    21     {typ: typ,
    22      card: int,
    23      co: bool,
    24      self_rec: bool,
    25      complete: bool * bool,
    26      concrete: bool * bool,
    27      deep: bool,
    28      constrs: constr_spec list}
    29 
    30   type scope =
    31     {hol_ctxt: hol_context,
    32      binarize: bool,
    33      card_assigns: (typ * int) list,
    34      bits: int,
    35      bisim_depth: int,
    36      data_types: data_type_spec list,
    37      ofs: int Typtab.table}
    38 
    39   val is_asymmetric_non_data_type : typ -> bool
    40   val data_type_spec : data_type_spec list -> typ -> data_type_spec option
    41   val constr_spec : data_type_spec list -> string * typ -> constr_spec
    42   val is_complete_type : data_type_spec list -> bool -> typ -> bool
    43   val is_concrete_type : data_type_spec list -> bool -> typ -> bool
    44   val is_exact_type : data_type_spec list -> bool -> typ -> bool
    45   val offset_of_type : int Typtab.table -> typ -> int
    46   val spec_of_type : scope -> typ -> int * int
    47   val pretties_for_scope : scope -> bool -> Pretty.T list
    48   val multiline_string_for_scope : scope -> string
    49   val scopes_equivalent : scope * scope -> bool
    50   val scope_less_eq : scope -> scope -> bool
    51   val is_self_recursive_constr_type : typ -> bool
    52   val all_scopes :
    53     hol_context -> bool -> (typ option * int list) list ->
    54     ((string * typ) option * int list) list ->
    55     ((string * typ) option * int list) list -> int list -> int list ->
    56     typ list -> typ list -> typ list -> typ list -> int * scope list
    57 end;
    58 
    59 structure Nitpick_Scope : NITPICK_SCOPE =
    60 struct
    61 
    62 open Nitpick_Util
    63 open Nitpick_HOL
    64 
    65 type constr_spec =
    66   {const: string * typ,
    67    delta: int,
    68    epsilon: int,
    69    exclusive: bool,
    70    explicit_max: int,
    71    total: bool}
    72 
    73 type data_type_spec =
    74   {typ: typ,
    75    card: int,
    76    co: bool,
    77    self_rec: bool,
    78    complete: bool * bool,
    79    concrete: bool * bool,
    80    deep: bool,
    81    constrs: constr_spec list}
    82 
    83 type scope =
    84   {hol_ctxt: hol_context,
    85    binarize: bool,
    86    card_assigns: (typ * int) list,
    87    bits: int,
    88    bisim_depth: int,
    89    data_types: data_type_spec list,
    90    ofs: int Typtab.table}
    91 
    92 datatype row_kind = Card of typ | Max of string * typ
    93 
    94 type row = row_kind * int list
    95 type block = row list
    96 
    97 val is_asymmetric_non_data_type =
    98   is_iterator_type orf is_integer_type orf is_bit_type
    99 
   100 fun data_type_spec (dtypes : data_type_spec list) T =
   101   List.find (curry (op =) T o #typ) dtypes
   102 
   103 fun constr_spec [] x = raise TERM ("Nitpick_Scope.constr_spec", [Const x])
   104   | constr_spec ({constrs, ...} :: dtypes : data_type_spec list) (x as (s, T)) =
   105     case List.find (curry (op =) (s, body_type T) o (apsnd body_type o #const))
   106                    constrs of
   107       SOME c => c
   108     | NONE => constr_spec dtypes x
   109 
   110 fun is_complete_type dtypes facto (Type (@{type_name fun}, [T1, T2])) =
   111     is_concrete_type dtypes facto T1 andalso is_complete_type dtypes facto T2
   112   | is_complete_type dtypes facto (Type (@{type_name prod}, Ts)) =
   113     forall (is_complete_type dtypes facto) Ts
   114   | is_complete_type dtypes facto (Type (@{type_name set}, [T'])) =
   115     is_concrete_type dtypes facto T'
   116   | is_complete_type dtypes facto T =
   117     not (is_integer_like_type T) andalso not (is_bit_type T) andalso
   118     fun_from_pair (#complete (the (data_type_spec dtypes T))) facto
   119     handle Option.Option => true
   120 and is_concrete_type dtypes facto (Type (@{type_name fun}, [T1, T2])) =
   121     is_complete_type dtypes facto T1 andalso is_concrete_type dtypes facto T2
   122   | is_concrete_type dtypes facto (Type (@{type_name prod}, Ts)) =
   123     forall (is_concrete_type dtypes facto) Ts
   124   | is_concrete_type dtypes facto (Type (@{type_name set}, [T'])) =
   125     is_complete_type dtypes facto T'
   126   | is_concrete_type dtypes facto T =
   127     fun_from_pair (#concrete (the (data_type_spec dtypes T))) facto
   128     handle Option.Option => true
   129 and is_exact_type dtypes facto =
   130   is_complete_type dtypes facto andf is_concrete_type dtypes facto
   131 
   132 fun offset_of_type ofs T =
   133   case Typtab.lookup ofs T of
   134     SOME j0 => j0
   135   | NONE => Typtab.lookup ofs dummyT |> the_default 0
   136 
   137 fun spec_of_type ({card_assigns, ofs, ...} : scope) T =
   138   (card_of_type card_assigns T
   139    handle TYPE ("Nitpick_HOL.card_of_type", _, _) => ~1, offset_of_type ofs T)
   140 
   141 fun quintuple_for_scope code_type code_term code_string
   142         ({hol_ctxt = {ctxt, ...}, card_assigns, bits, bisim_depth,
   143          data_types, ...} : scope) =
   144   let
   145     val boring_Ts = [@{typ unsigned_bit}, @{typ signed_bit},
   146                      @{typ bisim_iterator}]
   147     val (iter_assigns, card_assigns) =
   148       card_assigns |> filter_out (member (op =) boring_Ts o fst)
   149                    |> List.partition (is_fp_iterator_type o fst)
   150     val (secondary_card_assigns, primary_card_assigns) =
   151       card_assigns
   152       |> List.partition ((is_integer_type orf is_data_type ctxt) o fst)
   153     val cards =
   154       map (fn (T, k) =>
   155               [code_type ctxt T, code_string (" = " ^ string_of_int k)])
   156     fun maxes () =
   157       maps (map_filter
   158                 (fn {const, explicit_max, ...} =>
   159                     if explicit_max < 0 then
   160                       NONE
   161                     else
   162                       SOME [code_term ctxt (Const const),
   163                             code_string (" = " ^ string_of_int explicit_max)])
   164                  o #constrs) data_types
   165     fun iters () =
   166       map (fn (T, k) =>
   167               [code_term ctxt (Const (const_for_iterator_type T)),
   168                code_string (" = " ^ string_of_int (k - 1))]) iter_assigns
   169     fun miscs () =
   170       (if bits = 0 then []
   171        else [code_string ("bits = " ^ string_of_int bits)]) @
   172       (if bisim_depth < 0 andalso forall (not o #co) data_types then []
   173        else [code_string ("bisim_depth = " ^ signed_string_of_int bisim_depth)])
   174   in
   175     (cards primary_card_assigns, cards secondary_card_assigns,
   176      maxes (), iters (), miscs ())
   177   end
   178 
   179 fun pretties_for_scope scope verbose =
   180   let
   181     fun standard_blocks s = map (Pretty.block o cons (Pretty.str (s ^ " ")))
   182     val (primary_cards, secondary_cards, maxes, iters, miscs) =
   183       quintuple_for_scope
   184         (fn ctxt => pretty_maybe_quote (Thy_Header.get_keywords' ctxt) o pretty_for_type ctxt)
   185         (fn ctxt => pretty_maybe_quote (Thy_Header.get_keywords' ctxt) o Syntax.pretty_term ctxt)
   186         Pretty.str scope
   187   in
   188     standard_blocks "card" primary_cards @
   189     (if verbose then
   190        standard_blocks "card" secondary_cards @
   191        standard_blocks "max" maxes @
   192        standard_blocks "iter" iters @
   193        miscs
   194      else
   195        [])
   196     |> pretty_serial_commas "and"
   197   end
   198 
   199 fun multiline_string_for_scope scope =
   200   let
   201     val (primary_cards, secondary_cards, maxes, iters, miscs) =
   202       quintuple_for_scope Syntax.string_of_typ Syntax.string_of_term I scope
   203     val cards = primary_cards @ secondary_cards
   204   in
   205     case (if null cards then [] else ["card: " ^ commas (map implode cards)]) @
   206          (if null maxes then [] else ["max: " ^ commas (map implode maxes)]) @
   207          (if null iters then [] else ["iter: " ^ commas (map implode iters)]) @
   208          miscs of
   209       [] => "empty"
   210     | lines => cat_lines lines
   211   end
   212 
   213 fun scopes_equivalent (s1 : scope, s2 : scope) =
   214   #data_types s1 = #data_types s2 andalso #card_assigns s1 = #card_assigns s2
   215 
   216 fun scope_less_eq (s1 : scope) (s2 : scope) =
   217   (s1, s2) |> apply2 (map snd o #card_assigns) |> op ~~ |> forall (op <=)
   218 
   219 fun rank_of_row (_, ks) = length ks
   220 
   221 fun rank_of_block block = fold Integer.max (map rank_of_row block) 1
   222 
   223 fun project_row _ (y, []) = (y, [1]) (* desperate measure *)
   224   | project_row column (y, ks) = (y, [nth ks (Int.min (column, length ks - 1))])
   225 
   226 fun project_block (column, block) = map (project_row column) block
   227 
   228 fun lookup_ints_assign eq assigns key =
   229   case triple_lookup eq assigns key of
   230     SOME ks => ks
   231   | NONE => raise ARG ("Nitpick_Scope.lookup_ints_assign", "")
   232 
   233 fun lookup_type_ints_assign thy assigns T =
   234   map (Integer.max 1) (lookup_ints_assign (type_match thy) assigns T)
   235   handle ARG ("Nitpick_Scope.lookup_ints_assign", _) =>
   236          raise TYPE ("Nitpick_Scope.lookup_type_ints_assign", [T], [])
   237 
   238 fun lookup_const_ints_assign thy assigns x =
   239   lookup_ints_assign (const_match thy) assigns x
   240   handle ARG ("Nitpick_Scope.lookup_ints_assign", _) =>
   241          raise TERM ("Nitpick_Scope.lookup_const_ints_assign", [Const x])
   242 
   243 fun row_for_constr thy maxes_assigns constr =
   244   SOME (Max constr, lookup_const_ints_assign thy maxes_assigns constr)
   245   handle TERM ("lookup_const_ints_assign", _) => NONE
   246 
   247 val max_bits = 31 (* Kodkod limit *)
   248 
   249 fun block_for_type (hol_ctxt as {thy, ...}) binarize cards_assigns maxes_assigns
   250                    iters_assigns bitss bisim_depths T =
   251   case T of
   252     @{typ unsigned_bit} =>
   253     [(Card T, map (Integer.min max_bits o Integer.max 1) bitss)]
   254   | @{typ signed_bit} =>
   255     [(Card T, map (Integer.add 1 o Integer.min max_bits o Integer.max 1) bitss)]
   256   | @{typ "unsigned_bit word"} =>
   257     [(Card T, lookup_type_ints_assign thy cards_assigns nat_T)]
   258   | @{typ "signed_bit word"} =>
   259     [(Card T, lookup_type_ints_assign thy cards_assigns int_T)]
   260   | @{typ bisim_iterator} =>
   261     [(Card T, map (Integer.add 1 o Integer.max 0) bisim_depths)]
   262   | _ =>
   263     if is_fp_iterator_type T then
   264       [(Card T, map (Integer.add 1 o Integer.max 0)
   265                     (lookup_const_ints_assign thy iters_assigns
   266                                               (const_for_iterator_type T)))]
   267     else
   268       (Card T, lookup_type_ints_assign thy cards_assigns T) ::
   269       (case binarized_and_boxed_data_type_constrs hol_ctxt binarize T of
   270          [_] => []
   271        | constrs => map_filter (row_for_constr thy maxes_assigns) constrs)
   272 
   273 fun blocks_for_types hol_ctxt binarize cards_assigns maxes_assigns iters_assigns
   274                      bitss bisim_depths mono_Ts nonmono_Ts =
   275   let
   276     val block_for = block_for_type hol_ctxt binarize cards_assigns maxes_assigns
   277                                    iters_assigns bitss bisim_depths
   278     val mono_block = maps block_for mono_Ts
   279     val nonmono_blocks = map block_for nonmono_Ts
   280   in mono_block :: nonmono_blocks end
   281 
   282 val sync_threshold = 5
   283 val linearity = 5
   284 
   285 val all_combinations_ordered_smartly =
   286   let
   287     fun cost [] = 0
   288       | cost [k] = k
   289       | cost (k :: ks) =
   290         if k < sync_threshold andalso forall (curry (op =) k) ks then
   291           k - sync_threshold
   292         else
   293           k :: ks |> map (fn k => (k + linearity) * (k + linearity))
   294                   |> Integer.sum
   295   in
   296     all_combinations #> map (`cost) #> sort (int_ord o apply2 fst) #> map snd
   297   end
   298 
   299 fun is_self_recursive_constr_type T =
   300   exists (exists_subtype (curry (op =) (body_type T))) (binder_types T)
   301 
   302 fun constr_max maxes x = the_default ~1 (AList.lookup (op =) maxes x)
   303 
   304 type scope_desc = (typ * int) list * ((string * typ) * int) list
   305 
   306 fun is_surely_inconsistent_card_assign hol_ctxt binarize
   307                                        (card_assigns, max_assigns) (T, k) =
   308   case binarized_and_boxed_data_type_constrs hol_ctxt binarize T of
   309     [] => false
   310   | xs =>
   311     let
   312       val dom_cards =
   313         map (Integer.prod o map (bounded_card_of_type k ~1 card_assigns)
   314              o binder_types o snd) xs
   315       val maxes = map (constr_max max_assigns) xs
   316       fun effective_max card ~1 = card
   317         | effective_max card max = Int.min (card, max)
   318       val max = map2 effective_max dom_cards maxes |> Integer.sum
   319     in max < k end
   320 
   321 fun is_surely_inconsistent_scope_description hol_ctxt binarize seen rest
   322                                              max_assigns =
   323   exists (is_surely_inconsistent_card_assign hol_ctxt binarize
   324                                              (seen @ rest, max_assigns)) seen
   325 
   326 fun repair_card_assigns hol_ctxt binarize (card_assigns, max_assigns) =
   327   let
   328     fun aux seen [] = SOME seen
   329       | aux _ ((_, 0) :: _) = NONE
   330       | aux seen ((T, k) :: rest) =
   331         (if is_surely_inconsistent_scope_description hol_ctxt binarize
   332                 ((T, k) :: seen) rest max_assigns then
   333            raise SAME ()
   334          else
   335            case aux ((T, k) :: seen) rest of
   336              SOME assigns => SOME assigns
   337            | NONE => raise SAME ())
   338         handle SAME () => aux seen ((T, k - 1) :: rest)
   339   in aux [] (rev card_assigns) end
   340 
   341 fun repair_iterator_assign ctxt assigns (T as Type (_, Ts), k) =
   342     (T, if T = @{typ bisim_iterator} then
   343           let
   344             val co_cards = map snd (filter (is_codatatype ctxt o fst) assigns)
   345           in Int.min (k, Integer.sum co_cards) end
   346         else if is_fp_iterator_type T then
   347           case Ts of
   348             [] => 1
   349           | _ => bounded_card_of_type k ~1 assigns (foldr1 HOLogic.mk_prodT Ts)
   350         else
   351           k)
   352   | repair_iterator_assign _ _ assign = assign
   353 
   354 fun add_row_to_scope_descriptor (kind, ks) (card_assigns, max_assigns) =
   355   case kind of
   356     Card T => ((T, the_single ks) :: card_assigns, max_assigns)
   357   | Max x => (card_assigns, (x, the_single ks) :: max_assigns)
   358 
   359 fun scope_descriptor_from_block block =
   360   fold_rev add_row_to_scope_descriptor block ([], [])
   361 
   362 fun scope_descriptor_from_combination (hol_ctxt as {ctxt, ...}) binarize blocks
   363                                       columns =
   364   let
   365     val (card_assigns, max_assigns) =
   366       maps project_block (columns ~~ blocks) |> scope_descriptor_from_block
   367   in
   368     (card_assigns, max_assigns)
   369     |> repair_card_assigns hol_ctxt binarize
   370     |> Option.map
   371            (fn card_assigns =>
   372                (map (repair_iterator_assign ctxt card_assigns) card_assigns,
   373                 max_assigns))
   374   end
   375 
   376 fun offset_table_for_card_assigns dtypes assigns =
   377   let
   378     fun aux next _ [] = Typtab.update_new (dummyT, next)
   379       | aux next reusable ((T, k) :: assigns) =
   380         if k = 1 orelse is_asymmetric_non_data_type T then
   381           aux next reusable assigns
   382         else if length (these (Option.map #constrs (data_type_spec dtypes T)))
   383                 > 1 then
   384           Typtab.update_new (T, next) #> aux (next + k) reusable assigns
   385         else
   386           case AList.lookup (op =) reusable k of
   387             SOME j0 => Typtab.update_new (T, j0) #> aux next reusable assigns
   388           | NONE => Typtab.update_new (T, next)
   389                     #> aux (next + k) ((k, next) :: reusable) assigns
   390   in Typtab.empty |> aux 0 [] assigns end
   391 
   392 fun domain_card max card_assigns =
   393   Integer.prod o map (bounded_card_of_type max max card_assigns) o binder_types
   394 
   395 fun add_constr_spec (card_assigns, max_assigns) acyclic card sum_dom_cards
   396                     num_self_recs num_non_self_recs (self_rec, x as (_, T))
   397                     constrs =
   398   let
   399     val max = constr_max max_assigns x
   400     fun next_delta () = if null constrs then 0 else #epsilon (hd constrs)
   401     val {delta, epsilon, exclusive, total} =
   402       if max = 0 then
   403         let val delta = next_delta () in
   404           {delta = delta, epsilon = delta, exclusive = true, total = false}
   405         end
   406       else if num_self_recs > 0 then
   407         (if num_non_self_recs = 1 then
   408            if self_rec then
   409              case List.last constrs of
   410                {delta = 0, epsilon = 1, exclusive = true, ...} =>
   411                {delta = 1, epsilon = card, exclusive = (num_self_recs = 1),
   412                 total = false}
   413              | _ => raise SAME ()
   414            else
   415              if domain_card 2 card_assigns T = 1 then
   416                {delta = 0, epsilon = 1, exclusive = acyclic, total = acyclic}
   417              else
   418                raise SAME ()
   419          else
   420            raise SAME ())
   421         handle SAME () =>
   422                {delta = 0, epsilon = card, exclusive = false, total = false}
   423       else if card = sum_dom_cards (card + 1) then
   424         let val delta = next_delta () in
   425           {delta = delta, epsilon = delta + domain_card card card_assigns T,
   426            exclusive = true, total = true}
   427         end
   428       else
   429         {delta = 0, epsilon = card,
   430          exclusive = (num_self_recs + num_non_self_recs = 1), total = false}
   431   in
   432     {const = x, delta = delta, epsilon = epsilon, exclusive = exclusive,
   433      explicit_max = max, total = total} :: constrs
   434   end
   435 
   436 fun has_exact_card hol_ctxt facto finitizable_dataTs card_assigns T =
   437   let val card = card_of_type card_assigns T in
   438     card = bounded_exact_card_of_type hol_ctxt
   439                (if facto then finitizable_dataTs else []) (card + 1) 0
   440                card_assigns T
   441   end
   442 
   443 fun data_type_spec_from_scope_descriptor (hol_ctxt as {ctxt, ...})
   444         binarize deep_dataTs finitizable_dataTs (desc as (card_assigns, _))
   445         (T, card) =
   446   let
   447     val deep = member (op =) deep_dataTs T
   448     val co = is_codatatype ctxt T
   449     val xs = binarized_and_boxed_data_type_constrs hol_ctxt binarize T
   450     val self_recs = map (is_self_recursive_constr_type o snd) xs
   451     val (num_self_recs, num_non_self_recs) =
   452       List.partition I self_recs |> apply2 length
   453     val self_rec = num_self_recs > 0
   454     fun is_complete facto =
   455       has_exact_card hol_ctxt facto finitizable_dataTs card_assigns T
   456     fun is_concrete facto =
   457       is_word_type T orelse
   458       (* FIXME: looks wrong; other types than just functions might be
   459          abstract. "is_complete" is also suspicious. *)
   460       xs |> maps (binder_types o snd) |> maps binder_types
   461          |> forall (has_exact_card hol_ctxt facto finitizable_dataTs
   462                                    card_assigns)
   463     val complete = pair_from_fun is_complete
   464     val concrete = pair_from_fun is_concrete
   465     fun sum_dom_cards max =
   466       map (domain_card max card_assigns o snd) xs |> Integer.sum
   467     val constrs =
   468       fold_rev (add_constr_spec desc (not co) card sum_dom_cards num_self_recs
   469                                 num_non_self_recs)
   470                (sort (bool_ord o swap o apply2 fst) (self_recs ~~ xs)) []
   471   in
   472     {typ = T, card = card, co = co, self_rec = self_rec, complete = complete,
   473      concrete = concrete, deep = deep, constrs = constrs}
   474   end
   475 
   476 fun scope_from_descriptor (hol_ctxt as {ctxt, ...}) binarize deep_dataTs
   477                           finitizable_dataTs (desc as (card_assigns, _)) =
   478   let
   479     val data_types =
   480       map (data_type_spec_from_scope_descriptor hol_ctxt binarize deep_dataTs
   481                                                 finitizable_dataTs desc)
   482           (filter (is_data_type ctxt o fst) card_assigns)
   483     val bits = card_of_type card_assigns @{typ signed_bit} - 1
   484                handle TYPE ("Nitpick_HOL.card_of_type", _, _) =>
   485                       card_of_type card_assigns @{typ unsigned_bit}
   486                       handle TYPE ("Nitpick_HOL.card_of_type", _, _) => 0
   487     val bisim_depth = card_of_type card_assigns @{typ bisim_iterator} - 1
   488   in
   489     {hol_ctxt = hol_ctxt, binarize = binarize, card_assigns = card_assigns,
   490      data_types = data_types, bits = bits, bisim_depth = bisim_depth,
   491      ofs = offset_table_for_card_assigns data_types card_assigns}
   492   end
   493 
   494 fun repair_cards_assigns_wrt_boxing_etc _ _ [] = []
   495   | repair_cards_assigns_wrt_boxing_etc thy Ts ((SOME T, ks) :: cards_assigns) =
   496     (if is_fun_type T orelse is_pair_type T then
   497        Ts |> filter (curry (type_match thy o swap) T) |> map (rpair ks o SOME)
   498      else
   499        [(SOME T, ks)]) @
   500        repair_cards_assigns_wrt_boxing_etc thy Ts cards_assigns
   501   | repair_cards_assigns_wrt_boxing_etc thy Ts ((NONE, ks) :: cards_assigns) =
   502     (NONE, ks) :: repair_cards_assigns_wrt_boxing_etc thy Ts cards_assigns
   503 
   504 val max_scopes = 5000
   505 val distinct_threshold = 1000
   506 
   507 fun all_scopes (hol_ctxt as {thy, ...}) binarize cards_assigns maxes_assigns
   508                iters_assigns bitss bisim_depths mono_Ts nonmono_Ts deep_dataTs
   509                finitizable_dataTs =
   510   let
   511     val cards_assigns =
   512       repair_cards_assigns_wrt_boxing_etc thy mono_Ts cards_assigns
   513     val blocks =
   514       blocks_for_types hol_ctxt binarize cards_assigns maxes_assigns
   515                        iters_assigns bitss bisim_depths mono_Ts nonmono_Ts
   516     val ranks = map rank_of_block blocks
   517     val all = all_combinations_ordered_smartly (map (rpair 0) ranks)
   518     val head = take max_scopes all
   519     val descs =
   520       map_filter (scope_descriptor_from_combination hol_ctxt binarize blocks)
   521                  head
   522   in
   523     (length all - length head,
   524      descs |> length descs <= distinct_threshold ? distinct (op =)
   525            |> map (scope_from_descriptor hol_ctxt binarize deep_dataTs
   526                                          finitizable_dataTs))
   527   end
   528 
   529 end;