src/HOL/Tools/Nitpick/nitpick_scope.ML
changeset 33232 f93390060bbe
parent 33192 08a39a957ed7
child 33558 a2db56854b83
equal deleted inserted replaced
33231:1711610c5b7d 33232:f93390060bbe
     5 Scope enumerator for Nitpick.
     5 Scope enumerator for Nitpick.
     6 *)
     6 *)
     7 
     7 
     8 signature NITPICK_SCOPE =
     8 signature NITPICK_SCOPE =
     9 sig
     9 sig
    10   type extended_context = NitpickHOL.extended_context
    10   type extended_context = Nitpick_HOL.extended_context
    11 
    11 
    12   type constr_spec = {
    12   type constr_spec = {
    13     const: styp,
    13     const: styp,
    14     delta: int,
    14     delta: int,
    15     epsilon: int,
    15     epsilon: int,
    45     extended_context -> int -> (typ option * int list) list
    45     extended_context -> int -> (typ option * int list) list
    46     -> (styp option * int list) list -> (styp option * int list) list
    46     -> (styp option * int list) list -> (styp option * int list) list
    47     -> int list -> typ list -> typ list -> scope list
    47     -> int list -> typ list -> typ list -> scope list
    48 end;
    48 end;
    49 
    49 
    50 structure NitpickScope : NITPICK_SCOPE =
    50 structure Nitpick_Scope : NITPICK_SCOPE =
    51 struct
    51 struct
    52 
    52 
    53 open NitpickUtil
    53 open Nitpick_Util
    54 open NitpickHOL
    54 open Nitpick_HOL
    55 
    55 
    56 type constr_spec = {
    56 type constr_spec = {
    57   const: styp,
    57   const: styp,
    58   delta: int,
    58   delta: int,
    59   epsilon: int,
    59   epsilon: int,
    83 (* dtype_spec list -> typ -> dtype_spec option *)
    83 (* dtype_spec list -> typ -> dtype_spec option *)
    84 fun datatype_spec (dtypes : dtype_spec list) T =
    84 fun datatype_spec (dtypes : dtype_spec list) T =
    85   List.find (equal T o #typ) dtypes
    85   List.find (equal T o #typ) dtypes
    86 
    86 
    87 (* dtype_spec list -> styp -> constr_spec *)
    87 (* dtype_spec list -> styp -> constr_spec *)
    88 fun constr_spec [] x = raise TERM ("NitpickScope.constr_spec", [Const x])
    88 fun constr_spec [] x = raise TERM ("Nitpick_Scope.constr_spec", [Const x])
    89   | constr_spec ({constrs, ...} :: dtypes : dtype_spec list) (x as (s, T)) =
    89   | constr_spec ({constrs, ...} :: dtypes : dtype_spec list) (x as (s, T)) =
    90     case List.find (equal (s, body_type T) o (apsnd body_type o #const))
    90     case List.find (equal (s, body_type T) o (apsnd body_type o #const))
    91                    constrs of
    91                    constrs of
    92       SOME c => c
    92       SOME c => c
    93     | NONE => constr_spec dtypes x
    93     | NONE => constr_spec dtypes x
   113   | NONE => Typtab.lookup ofs dummyT |> the_default 0
   113   | NONE => Typtab.lookup ofs dummyT |> the_default 0
   114 
   114 
   115 (* scope -> typ -> int * int *)
   115 (* scope -> typ -> int * int *)
   116 fun spec_of_type ({card_assigns, ofs, ...} : scope) T =
   116 fun spec_of_type ({card_assigns, ofs, ...} : scope) T =
   117   (card_of_type card_assigns T
   117   (card_of_type card_assigns T
   118    handle TYPE ("NitpickHOL.card_of_type", _, _) => ~1, offset_of_type ofs T)
   118    handle TYPE ("Nitpick_HOL.card_of_type", _, _) => ~1, offset_of_type ofs T)
   119 
   119 
   120 (* (string -> string) -> scope
   120 (* (string -> string) -> scope
   121    -> string list * string list * string list * string list * string list *)
   121    -> string list * string list * string list * string list * string list *)
   122 fun quintuple_for_scope quote ({ext_ctxt as {thy, ctxt, ...}, card_assigns,
   122 fun quintuple_for_scope quote ({ext_ctxt as {thy, ctxt, ...}, card_assigns,
   123                                 bisim_depth, datatypes, ...} : scope) =
   123                                 bisim_depth, datatypes, ...} : scope) =
   203 
   203 
   204 (* (''a * ''a -> bool) -> (''a option * int list) list -> ''a -> int list *)
   204 (* (''a * ''a -> bool) -> (''a option * int list) list -> ''a -> int list *)
   205 fun lookup_ints_assign eq asgns key =
   205 fun lookup_ints_assign eq asgns key =
   206   case triple_lookup eq asgns key of
   206   case triple_lookup eq asgns key of
   207     SOME ks => ks
   207     SOME ks => ks
   208   | NONE => raise ARG ("NitpickScope.lookup_ints_assign", "")
   208   | NONE => raise ARG ("Nitpick_Scope.lookup_ints_assign", "")
   209 (* theory -> (typ option * int list) list -> typ -> int list *)
   209 (* theory -> (typ option * int list) list -> typ -> int list *)
   210 fun lookup_type_ints_assign thy asgns T =
   210 fun lookup_type_ints_assign thy asgns T =
   211   map (curry Int.max 1) (lookup_ints_assign (type_match thy) asgns T)
   211   map (curry Int.max 1) (lookup_ints_assign (type_match thy) asgns T)
   212   handle ARG ("NitpickScope.lookup_ints_assign", _) =>
   212   handle ARG ("Nitpick_Scope.lookup_ints_assign", _) =>
   213          raise TYPE ("NitpickScope.lookup_type_ints_assign", [T], [])
   213          raise TYPE ("Nitpick_Scope.lookup_type_ints_assign", [T], [])
   214 (* theory -> (styp option * int list) list -> styp -> int list *)
   214 (* theory -> (styp option * int list) list -> styp -> int list *)
   215 fun lookup_const_ints_assign thy asgns x =
   215 fun lookup_const_ints_assign thy asgns x =
   216   lookup_ints_assign (const_match thy) asgns x
   216   lookup_ints_assign (const_match thy) asgns x
   217   handle ARG ("NitpickScope.lookup_ints_assign", _) =>
   217   handle ARG ("Nitpick_Scope.lookup_ints_assign", _) =>
   218          raise TERM ("NitpickScope.lookup_const_ints_assign", [Const x])
   218          raise TERM ("Nitpick_Scope.lookup_const_ints_assign", [Const x])
   219 
   219 
   220 (* theory -> (styp option * int list) list -> styp -> row option *)
   220 (* theory -> (styp option * int list) list -> styp -> row option *)
   221 fun row_for_constr thy maxes_asgns constr =
   221 fun row_for_constr thy maxes_asgns constr =
   222   SOME (Max constr, lookup_const_ints_assign thy maxes_asgns constr)
   222   SOME (Max constr, lookup_const_ints_assign thy maxes_asgns constr)
   223   handle TERM ("lookup_const_ints_assign", _) => NONE
   223   handle TERM ("lookup_const_ints_assign", _) => NONE
   313            |> Integer.sum
   313            |> Integer.sum
   314     in
   314     in
   315       max < k
   315       max < k
   316       orelse (forall (not_equal 0) precise_cards andalso doms_card () < k)
   316       orelse (forall (not_equal 0) precise_cards andalso doms_card () < k)
   317     end
   317     end
   318     handle TYPE ("NitpickHOL.card_of_type", _, _) => false
   318     handle TYPE ("Nitpick_HOL.card_of_type", _, _) => false
   319 
   319 
   320 (* theory -> scope_desc -> bool *)
   320 (* theory -> scope_desc -> bool *)
   321 fun is_surely_inconsistent_scope_description thy (desc as (card_asgns, _)) =
   321 fun is_surely_inconsistent_scope_description thy (desc as (card_asgns, _)) =
   322   exists (is_surely_inconsistent_card_assign thy desc) card_asgns
   322   exists (is_surely_inconsistent_card_assign thy desc) card_asgns
   323 
   323