src/HOL/Tools/Nitpick/nitpick_hol.ML
author blanchet
Sat, 19 Dec 2015 20:02:51 +0100
changeset 61858 3f494c048142
parent 61770 a20048c78891
child 62342 1cf129590be8
permissions -rw-r--r--
removed dead code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33978
2380c1dac86e fix soundness bug in Nitpick's "destroy_constrs" optimization
blanchet
parents: 33968
diff changeset
     1
(*  Title:      HOL/Tools/Nitpick/nitpick_hol.ML
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
34982
7b8c366e34a2 added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents: 34936
diff changeset
     3
    Copyright   2008, 2009, 2010
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     4
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     5
Auxiliary HOL-related functions used by Nitpick.
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     6
*)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     7
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     8
signature NITPICK_HOL =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     9
sig
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    10
  type const_table = term list Symtab.table
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
    11
  type special_fun = ((string * typ) * int list * term list) * (string * typ)
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
    12
  type unrolled = (string * typ) * (string * typ)
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
    13
  type wf_cache = ((string * typ) * (bool * bool)) list
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    14
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    15
  type hol_context =
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    16
    {thy: theory,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    17
     ctxt: Proof.context,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    18
     max_bisim_depth: int,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    19
     boxes: (typ option * bool option) list,
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
    20
     wfs: ((string * typ) option * bool option) list,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    21
     user_axioms: bool option,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    22
     debug: bool,
38209
3d1d928dce50 added "whack"
blanchet
parents: 38208
diff changeset
    23
     whacks: term list,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    24
     binary_ints: bool option,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    25
     destroy_constrs: bool,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    26
     specialize: bool,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    27
     star_linear_preds: bool,
41871
394eef237bd1 lower threshold for implicitly using "nitpick_simp" for predicate definitions when "total_consts" is on
blanchet
parents: 41860
diff changeset
    28
     total_consts: bool option,
41876
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
    29
     needs: term list option,
54816
10d48c2a3e32 made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents: 54489
diff changeset
    30
     tac_timeout: Time.time,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    31
     evals: term list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    32
     case_names: (string * int) list,
41791
01d722707a36 always unfold constant defitions marked with "nitpick_def" -- to prevent unfolding, there's already "nitpick_simp"
blanchet
parents: 41472
diff changeset
    33
     def_tables: const_table * const_table,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    34
     nondef_table: const_table,
42415
10accf397ab6 use "Spec_Rules" for finding axioms -- more reliable and cleaner
blanchet
parents: 42414
diff changeset
    35
     nondefs: term list,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    36
     simp_table: const_table Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    37
     psimp_table: const_table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    38
     choice_spec_table: const_table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    39
     intro_table: const_table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    40
     ground_thm_table: term list Inttab.table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    41
     ersatz_table: (string * string) list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    42
     skolems: (string * string list) list Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    43
     special_funs: special_fun list Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    44
     unrolled_preds: unrolled list Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    45
     wf_cache: wf_cache Unsynchronized.ref,
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
    46
     constr_cache: (typ * (string * typ) list) list Unsynchronized.ref}
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    47
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    48
  datatype fixpoint_kind = Lfp | Gfp | NoFp
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    49
  datatype boxability =
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    50
    InConstr | InSel | InExpr | InPair | InFunLHS | InFunRHS1 | InFunRHS2
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    51
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    52
  val name_sep : string
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    53
  val numeral_prefix : string
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
    54
  val base_prefix : string
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
    55
  val step_prefix : string
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
    56
  val unrolled_prefix : string
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    57
  val ubfp_prefix : string
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    58
  val lbfp_prefix : string
35311
8f9a66fc9f80 improved Nitpick's support for quotient types
blanchet
parents: 35309
diff changeset
    59
  val quot_normal_prefix : string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    60
  val skolem_prefix : string
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    61
  val special_prefix : string
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    62
  val uncurry_prefix : string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    63
  val eval_prefix : string
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
    64
  val iter_var_prefix : string
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
    65
  val strip_first_name_sep : string -> string * string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    66
  val original_name : string -> string
37476
0681e46b4022 optimized code generated for datatype cases + more;
blanchet
parents: 37269
diff changeset
    67
  val abs_var : indexname * typ -> term -> term
34998
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
    68
  val s_conj : term * term -> term
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    69
  val s_disj : term * term -> term
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    70
  val strip_any_connective : term -> term list * term
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    71
  val conjuncts_of : term -> term list
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    72
  val disjuncts_of : term -> term list
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
    73
  val unarize_unbox_etc_type : typ -> typ
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
    74
  val uniterize_unarize_unbox_etc_type : typ -> typ
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    75
  val string_for_type : Proof.context -> typ -> string
38188
7f12a03c513c better "Pretty" handling
blanchet
parents: 38180
diff changeset
    76
  val pretty_for_type : Proof.context -> typ -> Pretty.T
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    77
  val prefix_name : string -> string -> string
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
    78
  val shortest_name : string -> string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    79
  val short_name : string -> string
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
    80
  val shorten_names_in_term : term -> term
35711
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
    81
  val strict_type_match : theory -> typ * typ -> bool
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    82
  val type_match : theory -> typ * typ -> bool
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
    83
  val const_match : theory -> (string * typ) * (string * typ) -> bool
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    84
  val term_match : theory -> term * term -> bool
35711
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
    85
  val frac_from_term_pair : typ -> term -> term -> term
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    86
  val is_TFree : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    87
  val is_fun_type : typ -> bool
46115
ecab67f5a5c2 improved "set" support by code inspection
blanchet
parents: 46113
diff changeset
    88
  val is_set_type : typ -> bool
ecab67f5a5c2 improved "set" support by code inspection
blanchet
parents: 46113
diff changeset
    89
  val is_fun_or_set_type : typ -> bool
46081
8f6465f7021b ported mono calculus to handle "set" type constructors
blanchet
parents: 45980
diff changeset
    90
  val is_set_like_type : typ -> bool
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    91
  val is_pair_type : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    92
  val is_lfp_iterator_type : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    93
  val is_gfp_iterator_type : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    94
  val is_fp_iterator_type : typ -> bool
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
    95
  val is_iterator_type : typ -> bool
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    96
  val is_boolean_type : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    97
  val is_integer_type : typ -> bool
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
    98
  val is_bit_type : typ -> bool
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
    99
  val is_word_type : typ -> bool
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   100
  val is_integer_like_type : typ -> bool
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   101
  val is_number_type : Proof.context -> typ -> bool
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   102
  val is_higher_order_type : typ -> bool
46081
8f6465f7021b ported mono calculus to handle "set" type constructors
blanchet
parents: 45980
diff changeset
   103
  val elem_type : typ -> typ
46083
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   104
  val pseudo_domain_type : typ -> typ
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   105
  val pseudo_range_type : typ -> typ
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   106
  val const_for_iterator_type : typ -> string * typ
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   107
  val strip_n_binders : int -> typ -> typ list * typ
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   108
  val nth_range_type : int -> typ -> typ
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   109
  val num_factors_in_type : typ -> int
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   110
  val curried_binder_types : typ -> typ list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   111
  val mk_flat_tuple : typ -> term list -> term
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   112
  val dest_n_tuple : int -> term -> term list
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   113
  val is_codatatype : Proof.context -> typ -> bool
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   114
  val is_quot_type : Proof.context -> typ -> bool
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   115
  val is_pure_typedef : Proof.context -> typ -> bool
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   116
  val is_univ_typedef : Proof.context -> typ -> bool
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
   117
  val is_data_type : Proof.context -> typ -> bool
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   118
  val is_record_get : theory -> string * typ -> bool
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   119
  val is_record_update : theory -> string * typ -> bool
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   120
  val is_abs_fun : Proof.context -> string * typ -> bool
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   121
  val is_rep_fun : Proof.context -> string * typ -> bool
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   122
  val is_quot_abs_fun : Proof.context -> string * typ -> bool
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   123
  val is_quot_rep_fun : Proof.context -> string * typ -> bool
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   124
  val mate_of_rep_fun : Proof.context -> string * typ -> string * typ
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   125
  val is_nonfree_constr : Proof.context -> string * typ -> bool
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   126
  val is_free_constr : Proof.context -> string * typ -> bool
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   127
  val is_constr : Proof.context -> string * typ -> bool
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   128
  val is_sel : string -> bool
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
   129
  val is_sel_like_and_no_discr : string -> bool
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   130
  val box_type : hol_context -> boxability -> typ -> typ
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   131
  val binarize_nat_and_int_in_type : typ -> typ
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   132
  val binarize_nat_and_int_in_term : term -> term
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   133
  val discr_for_constr : string * typ -> string * typ
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   134
  val num_sels_for_constr_type : typ -> int
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   135
  val nth_sel_name_for_constr_name : string -> int -> string
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   136
  val nth_sel_for_constr : string * typ -> int -> string * typ
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   137
  val binarized_and_boxed_nth_sel_for_constr :
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   138
    hol_context -> bool -> string * typ -> int -> string * typ
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   139
  val sel_no_from_name : string -> int
35078
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   140
  val close_form : term -> term
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   141
  val distinctness_formula : typ -> term list -> term
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   142
  val register_frac_type :
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   143
    string -> (string * string) list -> morphism -> Context.generic
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   144
    -> Context.generic
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   145
  val register_frac_type_global :
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   146
    string -> (string * string) list -> theory -> theory
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   147
  val unregister_frac_type :
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   148
    string -> morphism -> Context.generic -> Context.generic
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   149
  val unregister_frac_type_global : string -> theory -> theory
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   150
  val register_ersatz :
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   151
    (string * string) list -> morphism -> Context.generic -> Context.generic
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   152
  val register_ersatz_global : (string * string) list -> theory -> theory
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   153
  val register_codatatype :
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   154
    typ -> string -> (string * typ) list -> morphism -> Context.generic ->
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   155
    Context.generic
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   156
  val register_codatatype_global :
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   157
    typ -> string -> (string * typ) list -> theory -> theory
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   158
  val unregister_codatatype :
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   159
    typ -> morphism -> Context.generic -> Context.generic
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   160
  val unregister_codatatype_global : typ -> theory -> theory
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
   161
  val binarized_and_boxed_data_type_constrs :
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   162
    hol_context -> bool -> typ -> (string * typ) list
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   163
  val constr_name_for_sel_like : string -> string
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   164
  val binarized_and_boxed_constr_for_sel : hol_context -> bool ->
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   165
    string * typ -> string * typ
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   166
  val card_of_type : (typ * int) list -> typ -> int
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   167
  val bounded_card_of_type : int -> int -> (typ * int) list -> typ -> int
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   168
  val bounded_exact_card_of_type :
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   169
    hol_context -> typ list -> int -> int -> (typ * int) list -> typ -> int
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   170
  val typical_card_of_type : typ -> int
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   171
  val is_finite_type : hol_context -> typ -> bool
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   172
  val is_special_eligible_arg : bool -> typ list -> term -> bool
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   173
  val s_let :
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   174
    typ list -> string -> int -> typ -> typ -> (term -> term) -> term -> term
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   175
  val s_betapply : typ list -> term * term -> term
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   176
  val s_betapplys : typ list -> term * term list -> term
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   177
  val discriminate_value : hol_context -> string * typ -> term -> term
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   178
  val select_nth_constr_arg :
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   179
    Proof.context -> string * typ -> term -> int -> typ -> term
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   180
  val construct_value : Proof.context -> string * typ -> term list -> term
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   181
  val coerce_term : hol_context -> typ list -> typ -> typ -> term -> term
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   182
  val special_bounds : term list -> (indexname * typ) list
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   183
  val is_funky_typedef : Proof.context -> typ -> bool
42415
10accf397ab6 use "Spec_Rules" for finding axioms -- more reliable and cleaner
blanchet
parents: 42414
diff changeset
   184
  val all_defs_of : theory -> (term * term) list -> term list
10accf397ab6 use "Spec_Rules" for finding axioms -- more reliable and cleaner
blanchet
parents: 42414
diff changeset
   185
  val all_nondefs_of : Proof.context -> (term * term) list -> term list
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   186
  val arity_of_built_in_const : string * typ -> int option
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   187
  val is_built_in_const : string * typ -> bool
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   188
  val term_under_def : term -> term
55888
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   189
  val case_const_names : Proof.context -> (string * int) list
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   190
  val unfold_defs_in_term : hol_context -> term -> term
41791
01d722707a36 always unfold constant defitions marked with "nitpick_def" -- to prevent unfolding, there's already "nitpick_simp"
blanchet
parents: 41472
diff changeset
   191
  val const_def_tables :
01d722707a36 always unfold constant defitions marked with "nitpick_def" -- to prevent unfolding, there's already "nitpick_simp"
blanchet
parents: 41472
diff changeset
   192
    Proof.context -> (term * term) list -> term list
01d722707a36 always unfold constant defitions marked with "nitpick_def" -- to prevent unfolding, there's already "nitpick_simp"
blanchet
parents: 41472
diff changeset
   193
    -> const_table * const_table
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   194
  val const_nondef_table : term list -> const_table
35335
f715cfde056a support local definitions in Nitpick
blanchet
parents: 35332
diff changeset
   195
  val const_simp_table : Proof.context -> (term * term) list -> const_table
f715cfde056a support local definitions in Nitpick
blanchet
parents: 35332
diff changeset
   196
  val const_psimp_table : Proof.context -> (term * term) list -> const_table
35807
e4d1b5cbd429 added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents: 35743
diff changeset
   197
  val const_choice_spec_table :
e4d1b5cbd429 added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents: 35743
diff changeset
   198
    Proof.context -> (term * term) list -> const_table
35335
f715cfde056a support local definitions in Nitpick
blanchet
parents: 35332
diff changeset
   199
  val inductive_intro_table :
41791
01d722707a36 always unfold constant defitions marked with "nitpick_def" -- to prevent unfolding, there's already "nitpick_simp"
blanchet
parents: 41472
diff changeset
   200
    Proof.context -> (term * term) list -> const_table * const_table
01d722707a36 always unfold constant defitions marked with "nitpick_def" -- to prevent unfolding, there's already "nitpick_simp"
blanchet
parents: 41472
diff changeset
   201
    -> const_table
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   202
  val ground_theorem_table : theory -> term list Inttab.table
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   203
  val ersatz_table : Proof.context -> (string * string) list
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   204
  val add_simps : const_table Unsynchronized.ref -> string -> term list -> unit
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   205
  val inverse_axioms_for_rep_fun : Proof.context -> string * typ -> term list
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   206
  val optimized_typedef_axioms : Proof.context -> string * typ list -> term list
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   207
  val optimized_quot_type_axioms :
55888
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   208
    Proof.context -> string * typ list -> term list
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   209
  val def_of_const : theory -> const_table * const_table -> string * typ ->
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   210
    term option
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   211
  val fixpoint_kind_of_rhs : term -> fixpoint_kind
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   212
  val fixpoint_kind_of_const :
41791
01d722707a36 always unfold constant defitions marked with "nitpick_def" -- to prevent unfolding, there's already "nitpick_simp"
blanchet
parents: 41472
diff changeset
   213
    theory -> const_table * const_table -> string * typ -> fixpoint_kind
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   214
  val is_raw_inductive_pred : hol_context -> string * typ -> bool
41994
c567c860caf6 always destroy constructor patterns, since this seems to be always useful
blanchet
parents: 41898
diff changeset
   215
  val is_constr_pattern : Proof.context -> term -> bool
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   216
  val is_constr_pattern_lhs : Proof.context -> term -> bool
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   217
  val is_constr_pattern_formula : Proof.context -> term -> bool
35807
e4d1b5cbd429 added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents: 35743
diff changeset
   218
  val nondef_props_for_const :
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   219
    theory -> bool -> const_table -> string * typ -> term list
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   220
  val is_choice_spec_fun : hol_context -> string * typ -> bool
59970
e9f73d87d904 proper context for Object_Logic operations;
wenzelm
parents: 59621
diff changeset
   221
  val is_choice_spec_axiom : Proof.context -> const_table -> term -> bool
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   222
  val is_raw_equational_fun : hol_context -> string * typ -> bool
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   223
  val is_equational_fun : hol_context -> string * typ -> bool
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   224
  val codatatype_bisim_axioms : hol_context -> typ -> term list
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   225
  val is_well_founded_inductive_pred : hol_context -> string * typ -> bool
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   226
  val unrolled_inductive_pred_const : hol_context -> bool -> string * typ ->
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   227
    term
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   228
  val equational_fun_axioms : hol_context -> string * typ -> term list
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   229
  val is_equational_fun_surely_complete : hol_context -> string * typ -> bool
38212
a7e92239922f improved "merge_type_vars" option: map supersorts to subsorts, to avoid distinguishing, say, "{}", and "HOL.type"
blanchet
parents: 38209
diff changeset
   230
  val merged_type_var_table_for_terms :
a7e92239922f improved "merge_type_vars" option: map supersorts to subsorts, to avoid distinguishing, say, "{}", and "HOL.type"
blanchet
parents: 38209
diff changeset
   231
    theory -> term list -> (sort * string) list
a7e92239922f improved "merge_type_vars" option: map supersorts to subsorts, to avoid distinguishing, say, "{}", and "HOL.type"
blanchet
parents: 38209
diff changeset
   232
  val merge_type_vars_in_term :
a7e92239922f improved "merge_type_vars" option: map supersorts to subsorts, to avoid distinguishing, say, "{}", and "HOL.type"
blanchet
parents: 38209
diff changeset
   233
    theory -> bool -> (sort * string) list -> term -> term
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   234
  val ground_types_in_type : hol_context -> bool -> typ -> typ list
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   235
  val ground_types_in_terms : hol_context -> bool -> term list -> typ list
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   236
end;
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   237
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33202
diff changeset
   238
structure Nitpick_HOL : NITPICK_HOL =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   239
struct
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   240
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33202
diff changeset
   241
open Nitpick_Util
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   242
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   243
type const_table = term list Symtab.table
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   244
type special_fun = ((string * typ) * int list * term list) * (string * typ)
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   245
type unrolled = (string * typ) * (string * typ)
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   246
type wf_cache = ((string * typ) * (bool * bool)) list
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   247
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   248
type hol_context =
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   249
  {thy: theory,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   250
   ctxt: Proof.context,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   251
   max_bisim_depth: int,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   252
   boxes: (typ option * bool option) list,
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   253
   wfs: ((string * typ) option * bool option) list,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   254
   user_axioms: bool option,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   255
   debug: bool,
38209
3d1d928dce50 added "whack"
blanchet
parents: 38208
diff changeset
   256
   whacks: term list,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   257
   binary_ints: bool option,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   258
   destroy_constrs: bool,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   259
   specialize: bool,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   260
   star_linear_preds: bool,
41871
394eef237bd1 lower threshold for implicitly using "nitpick_simp" for predicate definitions when "total_consts" is on
blanchet
parents: 41860
diff changeset
   261
   total_consts: bool option,
41876
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
   262
   needs: term list option,
54816
10d48c2a3e32 made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents: 54489
diff changeset
   263
   tac_timeout: Time.time,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   264
   evals: term list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   265
   case_names: (string * int) list,
41791
01d722707a36 always unfold constant defitions marked with "nitpick_def" -- to prevent unfolding, there's already "nitpick_simp"
blanchet
parents: 41472
diff changeset
   266
   def_tables: const_table * const_table,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   267
   nondef_table: const_table,
42415
10accf397ab6 use "Spec_Rules" for finding axioms -- more reliable and cleaner
blanchet
parents: 42414
diff changeset
   268
   nondefs: term list,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   269
   simp_table: const_table Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   270
   psimp_table: const_table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   271
   choice_spec_table: const_table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   272
   intro_table: const_table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   273
   ground_thm_table: term list Inttab.table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   274
   ersatz_table: (string * string) list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   275
   skolems: (string * string list) list Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   276
   special_funs: special_fun list Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   277
   unrolled_preds: unrolled list Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   278
   wf_cache: wf_cache Unsynchronized.ref,
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   279
   constr_cache: (typ * (string * typ) list) list Unsynchronized.ref}
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   280
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   281
datatype fixpoint_kind = Lfp | Gfp | NoFp
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   282
datatype boxability =
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   283
  InConstr | InSel | InExpr | InPair | InFunLHS | InFunRHS1 | InFunRHS2
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   284
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   285
(* FIXME: Get rid of 'codatatypes' and related functionality *)
41472
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 41052
diff changeset
   286
structure Data = Generic_Data
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 41052
diff changeset
   287
(
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   288
  type T = {frac_types: (string * (string * string) list) list,
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   289
            ersatz_table: (string * string) list,
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   290
            codatatypes: (string * (string * (string * typ) list)) list}
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   291
  val empty = {frac_types = [], ersatz_table = [], codatatypes = []}
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   292
  val extend = I
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   293
  fun merge ({frac_types = fs1, ersatz_table = et1, codatatypes = cs1},
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   294
             {frac_types = fs2, ersatz_table = et2, codatatypes = cs2}) : T =
33699
f33b036ef318 permissive AList.merge -- most likely setup for theory data (beware of spurious AList.DUP);
wenzelm
parents: 33583
diff changeset
   295
    {frac_types = AList.merge (op =) (K true) (fs1, fs2),
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   296
     ersatz_table = AList.merge (op =) (K true) (et1, et2),
41472
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 41052
diff changeset
   297
     codatatypes = AList.merge (op =) (K true) (cs1, cs2)}
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 41052
diff changeset
   298
)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   299
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   300
val name_sep = "$"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   301
val numeral_prefix = nitpick_prefix ^ "num" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   302
val sel_prefix = nitpick_prefix ^ "sel"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   303
val discr_prefix = nitpick_prefix ^ "is" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   304
val lfp_iterator_prefix = nitpick_prefix ^ "lfpit" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   305
val gfp_iterator_prefix = nitpick_prefix ^ "gfpit" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   306
val unrolled_prefix = nitpick_prefix ^ "unroll" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   307
val base_prefix = nitpick_prefix ^ "base" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   308
val step_prefix = nitpick_prefix ^ "step" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   309
val ubfp_prefix = nitpick_prefix ^ "ubfp" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   310
val lbfp_prefix = nitpick_prefix ^ "lbfp" ^ name_sep
35311
8f9a66fc9f80 improved Nitpick's support for quotient types
blanchet
parents: 35309
diff changeset
   311
val quot_normal_prefix = nitpick_prefix ^ "qn" ^ name_sep
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   312
val skolem_prefix = nitpick_prefix ^ "sk"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   313
val special_prefix = nitpick_prefix ^ "sp"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   314
val uncurry_prefix = nitpick_prefix ^ "unc"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   315
val eval_prefix = nitpick_prefix ^ "eval"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   316
val iter_var_prefix = "i"
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   317
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   318
(** Constant/type information and term/type manipulation **)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   319
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   320
fun sel_prefix_for j = sel_prefix ^ string_of_int j ^ name_sep
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   321
35311
8f9a66fc9f80 improved Nitpick's support for quotient types
blanchet
parents: 35309
diff changeset
   322
fun quot_normal_name_for_type ctxt T =
59433
9da5b2c61049 tuned signature;
wenzelm
parents: 59058
diff changeset
   323
  quot_normal_prefix ^ YXML.content_of (Syntax.string_of_typ ctxt T)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   324
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   325
val strip_first_name_sep =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   326
  Substring.full #> Substring.position name_sep ##> Substring.triml 1
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 59038
diff changeset
   327
  #> apply2 Substring.string
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   328
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   329
fun original_name s =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   330
  if String.isPrefix nitpick_prefix s then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   331
    case strip_first_name_sep s of (s1, "") => s1 | (_, s2) => original_name s2
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   332
  else
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   333
    s
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   334
34998
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   335
fun s_conj (t1, @{const True}) = t1
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   336
  | s_conj (@{const True}, t2) = t2
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   337
  | s_conj (t1, t2) =
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   338
    if t1 = @{const False} orelse t2 = @{const False} then @{const False}
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   339
    else HOLogic.mk_conj (t1, t2)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   340
34998
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   341
fun s_disj (t1, @{const False}) = t1
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   342
  | s_disj (@{const False}, t2) = t2
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   343
  | s_disj (t1, t2) =
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   344
    if t1 = @{const True} orelse t2 = @{const True} then @{const True}
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   345
    else HOLogic.mk_disj (t1, t2)
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   346
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   347
fun strip_connective conn_t (t as (t0 $ t1 $ t2)) =
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   348
    if t0 = conn_t then strip_connective t0 t2 @ strip_connective t0 t1 else [t]
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   349
  | strip_connective _ t = [t]
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   350
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   351
fun strip_any_connective (t as (t0 $ _ $ _)) =
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   352
    if t0 = @{const HOL.conj} orelse t0 = @{const HOL.disj} then
34998
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   353
      (strip_connective t0 t, t0)
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   354
    else
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   355
      ([t], @{const Not})
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   356
  | strip_any_connective t = ([t], @{const Not})
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   357
val conjuncts_of = strip_connective @{const HOL.conj}
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   358
val disjuncts_of = strip_connective @{const HOL.disj}
34998
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   359
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   360
(* When you add constants to these lists, make sure to handle them in
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33202
diff changeset
   361
   "Nitpick_Nut.nut_from_term", and perhaps in "Nitpick_Mono.consider_term" as
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   362
   well. *)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   363
val built_in_consts =
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56243
diff changeset
   364
  [(@{const_name Pure.all}, 1),
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56243
diff changeset
   365
   (@{const_name Pure.eq}, 2),
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56243
diff changeset
   366
   (@{const_name Pure.imp}, 2),
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   367
   (@{const_name Pure.conjunction}, 2),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   368
   (@{const_name Trueprop}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   369
   (@{const_name Not}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   370
   (@{const_name False}, 0),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   371
   (@{const_name True}, 0),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   372
   (@{const_name All}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   373
   (@{const_name Ex}, 1),
38864
4abe644fcea5 formerly unnamed infix equality now named HOL.eq
haftmann
parents: 38795
diff changeset
   374
   (@{const_name HOL.eq}, 1),
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   375
   (@{const_name HOL.conj}, 2),
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   376
   (@{const_name HOL.disj}, 2),
38786
e46e7a9cb622 formerly unnamed infix impliciation now named HOL.implies
haftmann
parents: 38652
diff changeset
   377
   (@{const_name HOL.implies}, 2),
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   378
   (@{const_name If}, 3),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   379
   (@{const_name Let}, 2),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   380
   (@{const_name Pair}, 2),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   381
   (@{const_name fst}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   382
   (@{const_name snd}, 1),
46083
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   383
   (@{const_name Set.member}, 2),
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   384
   (@{const_name Collect}, 1),
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   385
   (@{const_name Id}, 0),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   386
   (@{const_name converse}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   387
   (@{const_name trancl}, 1),
47433
07f4bf913230 renamed "rel_comp" to "relcomp" (to be consistent with, e.g., "relpow")
griff
parents: 47109
diff changeset
   388
   (@{const_name relcomp}, 2),
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   389
   (@{const_name finite}, 1),
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   390
   (@{const_name unknown}, 0),
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   391
   (@{const_name is_unknown}, 1),
35671
ed2c3830d881 improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
blanchet
parents: 35665
diff changeset
   392
   (@{const_name safe_The}, 1),
61324
d4ec7594f558 avoid unsound simplification of (C (s x)) when s is a selector but not C's
blanchet
parents: 61125
diff changeset
   393
   (@{const_name Frac}, 0),
d4ec7594f558 avoid unsound simplification of (C (s x)) when s is a selector but not C's
blanchet
parents: 61125
diff changeset
   394
   (@{const_name norm_frac}, 0),
55888
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   395
   (@{const_name Suc}, 0),
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   396
   (@{const_name nat}, 0),
61324
d4ec7594f558 avoid unsound simplification of (C (s x)) when s is a selector but not C's
blanchet
parents: 61125
diff changeset
   397
   (@{const_name nat_gcd}, 0),
d4ec7594f558 avoid unsound simplification of (C (s x)) when s is a selector but not C's
blanchet
parents: 61125
diff changeset
   398
   (@{const_name nat_lcm}, 0)]
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   399
val built_in_typed_consts =
55888
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   400
  [((@{const_name zero_class.zero}, nat_T), 0),
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   401
   ((@{const_name one_class.one}, nat_T), 0),
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   402
   ((@{const_name plus_class.plus}, nat_T --> nat_T --> nat_T), 0),
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   403
   ((@{const_name minus_class.minus}, nat_T --> nat_T --> nat_T), 0),
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   404
   ((@{const_name times_class.times}, nat_T --> nat_T --> nat_T), 0),
60352
d46de31a50c4 separate class for division operator, with particular syntax added in more specific classes
haftmann
parents: 59970
diff changeset
   405
   ((@{const_name Rings.divide}, nat_T --> nat_T --> nat_T), 0),
55888
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   406
   ((@{const_name ord_class.less}, nat_T --> nat_T --> bool_T), 2),
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   407
   ((@{const_name ord_class.less_eq}, nat_T --> nat_T --> bool_T), 2),
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   408
   ((@{const_name of_nat}, nat_T --> int_T), 0),
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   409
   ((@{const_name zero_class.zero}, int_T), 0),
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   410
   ((@{const_name one_class.one}, int_T), 0),
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   411
   ((@{const_name plus_class.plus}, int_T --> int_T --> int_T), 0),
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   412
   ((@{const_name minus_class.minus}, int_T --> int_T --> int_T), 0),
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   413
   ((@{const_name times_class.times}, int_T --> int_T --> int_T), 0),
60352
d46de31a50c4 separate class for division operator, with particular syntax added in more specific classes
haftmann
parents: 59970
diff changeset
   414
   ((@{const_name Rings.divide}, int_T --> int_T --> int_T), 0),
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   415
   ((@{const_name uminus_class.uminus}, int_T --> int_T), 0),
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   416
   ((@{const_name ord_class.less}, int_T --> int_T --> bool_T), 2),
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   417
   ((@{const_name ord_class.less_eq}, int_T --> int_T --> bool_T), 2)]
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   418
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   419
fun unarize_type @{typ "unsigned_bit word"} = nat_T
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   420
  | unarize_type @{typ "signed_bit word"} = int_T
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   421
  | unarize_type (Type (s, Ts as _ :: _)) = Type (s, map unarize_type Ts)
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   422
  | unarize_type T = T
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   423
41052
3db267a01c1d remove the "fin_fun" optimization in Nitpick -- it was always a hack and didn't help much
blanchet
parents: 41049
diff changeset
   424
fun unarize_unbox_etc_type (Type (@{type_name fun_box}, Ts)) =
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   425
    unarize_unbox_etc_type (Type (@{type_name fun}, Ts))
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   426
  | unarize_unbox_etc_type (Type (@{type_name pair_box}, Ts)) =
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   427
    Type (@{type_name prod}, map unarize_unbox_etc_type Ts)
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   428
  | unarize_unbox_etc_type @{typ "unsigned_bit word"} = nat_T
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   429
  | unarize_unbox_etc_type @{typ "signed_bit word"} = int_T
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   430
  | unarize_unbox_etc_type (Type (s, Ts as _ :: _)) =
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   431
    Type (s, map unarize_unbox_etc_type Ts)
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   432
  | unarize_unbox_etc_type T = T
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   433
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   434
fun uniterize_type (Type (s, Ts as _ :: _)) = Type (s, map uniterize_type Ts)
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   435
  | uniterize_type @{typ bisim_iterator} = nat_T
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   436
  | uniterize_type T = T
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   437
val uniterize_unarize_unbox_etc_type = uniterize_type o unarize_unbox_etc_type
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   438
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   439
fun string_for_type ctxt = Syntax.string_of_typ ctxt o unarize_unbox_etc_type
38188
7f12a03c513c better "Pretty" handling
blanchet
parents: 38180
diff changeset
   440
fun pretty_for_type ctxt = Syntax.pretty_typ ctxt o unarize_unbox_etc_type
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   441
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   442
val prefix_name = Long_Name.qualify o Long_Name.base_name
56220
4c43a2881b25 more explicit Long_Name operations (NB: analyzing qualifiers is inherently fragile);
wenzelm
parents: 56161
diff changeset
   443
val shortest_name = Long_Name.base_name
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   444
val prefix_abs_vars = Term.map_abs_vars o prefix_name
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   445
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   446
fun short_name s =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   447
  case space_explode name_sep s of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   448
    [_] => s |> String.isPrefix nitpick_prefix s ? unprefix nitpick_prefix
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   449
  | ss => map shortest_name ss |> space_implode "_"
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   450
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   451
fun shorten_names_in_type (Type (s, Ts)) =
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   452
    Type (short_name s, map shorten_names_in_type Ts)
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   453
  | shorten_names_in_type T = T
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   454
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   455
val shorten_names_in_term =
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   456
  map_aterms (fn Const (s, T) => Const (short_name s, T) | t => t)
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   457
  #> map_types shorten_names_in_type
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   458
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   459
fun strict_type_match thy (T1, T2) =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   460
  (Sign.typ_match thy (T2, T1) Vartab.empty; true)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   461
  handle Type.TYPE_MATCH => false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   462
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 59038
diff changeset
   463
fun type_match thy = strict_type_match thy o apply2 unarize_unbox_etc_type
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   464
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   465
fun const_match thy ((s1, T1), (s2, T2)) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   466
  s1 = s2 andalso type_match thy (T1, T2)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   467
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   468
fun term_match thy (Const x1, Const x2) = const_match thy (x1, x2)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   469
  | term_match thy (Free (s1, T1), Free (s2, T2)) =
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   470
    const_match thy ((shortest_name s1, T1), (shortest_name s2, T2))
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   471
  | term_match _ (t1, t2) = t1 aconv t2
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   472
35711
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   473
fun frac_from_term_pair T t1 t2 =
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   474
  case snd (HOLogic.dest_number t1) of
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   475
    0 => HOLogic.mk_number T 0
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   476
  | n1 => case snd (HOLogic.dest_number t2) of
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   477
            1 => HOLogic.mk_number T n1
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   478
          | n2 => Const (@{const_name divide}, T --> T --> T)
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   479
                  $ HOLogic.mk_number T n1 $ HOLogic.mk_number T n2
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   480
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   481
fun is_TFree (TFree _) = true
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   482
  | is_TFree _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   483
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   484
fun is_fun_type (Type (@{type_name fun}, _)) = true
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   485
  | is_fun_type _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   486
46115
ecab67f5a5c2 improved "set" support by code inspection
blanchet
parents: 46113
diff changeset
   487
fun is_set_type (Type (@{type_name set}, _)) = true
ecab67f5a5c2 improved "set" support by code inspection
blanchet
parents: 46113
diff changeset
   488
  | is_set_type _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   489
46115
ecab67f5a5c2 improved "set" support by code inspection
blanchet
parents: 46113
diff changeset
   490
val is_fun_or_set_type = is_fun_type orf is_set_type
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   491
46115
ecab67f5a5c2 improved "set" support by code inspection
blanchet
parents: 46113
diff changeset
   492
fun is_set_like_type (Type (@{type_name fun}, [_, T'])) =
ecab67f5a5c2 improved "set" support by code inspection
blanchet
parents: 46113
diff changeset
   493
    (body_type T' = bool_T)
46081
8f6465f7021b ported mono calculus to handle "set" type constructors
blanchet
parents: 45980
diff changeset
   494
  | is_set_like_type (Type (@{type_name set}, _)) = true
8f6465f7021b ported mono calculus to handle "set" type constructors
blanchet
parents: 45980
diff changeset
   495
  | is_set_like_type _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   496
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   497
fun is_pair_type (Type (@{type_name prod}, _)) = true
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   498
  | is_pair_type _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   499
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   500
fun is_lfp_iterator_type (Type (s, _)) = String.isPrefix lfp_iterator_prefix s
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   501
  | is_lfp_iterator_type _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   502
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   503
fun is_gfp_iterator_type (Type (s, _)) = String.isPrefix gfp_iterator_prefix s
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   504
  | is_gfp_iterator_type _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   505
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   506
val is_fp_iterator_type = is_lfp_iterator_type orf is_gfp_iterator_type
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   507
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   508
fun is_iterator_type T =
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   509
  (T = @{typ bisim_iterator} orelse is_fp_iterator_type T)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   510
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   511
fun is_boolean_type T = (T = prop_T orelse T = bool_T)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   512
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   513
fun is_integer_type T = (T = nat_T orelse T = int_T)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   514
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
   515
fun is_bit_type T = (T = @{typ unsigned_bit} orelse T = @{typ signed_bit})
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   516
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
   517
fun is_word_type (Type (@{type_name word}, _)) = true
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
   518
  | is_word_type _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   519
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   520
val is_integer_like_type = is_iterator_type orf is_integer_type orf is_word_type
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   521
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   522
fun is_frac_type ctxt (Type (s, [])) =
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   523
    s |> AList.defined (op =) (#frac_types (Data.get (Context.Proof ctxt)))
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   524
  | is_frac_type _ _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   525
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   526
fun is_number_type ctxt = is_integer_like_type orf is_frac_type ctxt
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   527
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   528
fun is_higher_order_type (Type (@{type_name fun}, _)) = true
46115
ecab67f5a5c2 improved "set" support by code inspection
blanchet
parents: 46113
diff changeset
   529
  | is_higher_order_type (Type (@{type_name set}, _)) = true
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   530
  | is_higher_order_type (Type (_, Ts)) = exists is_higher_order_type Ts
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
   531
  | is_higher_order_type _ = false
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   532
46083
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   533
fun elem_type (Type (@{type_name set}, [T'])) = T'
46081
8f6465f7021b ported mono calculus to handle "set" type constructors
blanchet
parents: 45980
diff changeset
   534
  | elem_type T = raise TYPE ("Nitpick_HOL.elem_type", [T], [])
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   535
46083
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   536
fun pseudo_domain_type (Type (@{type_name fun}, [T1, _])) = T1
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   537
  | pseudo_domain_type T = elem_type T
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   538
46083
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   539
fun pseudo_range_type (Type (@{type_name fun}, [_, T2])) = T2
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   540
  | pseudo_range_type (Type (@{type_name set}, _)) = bool_T
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   541
  | pseudo_range_type T = raise TYPE ("Nitpick_HOL.pseudo_range_type", [T], [])
46081
8f6465f7021b ported mono calculus to handle "set" type constructors
blanchet
parents: 45980
diff changeset
   542
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   543
fun iterator_type_for_const gfp (s, T) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   544
  Type ((if gfp then gfp_iterator_prefix else lfp_iterator_prefix) ^ s,
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   545
        binder_types T)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   546
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   547
fun const_for_iterator_type (Type (s, Ts)) =
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   548
    (strip_first_name_sep s |> snd, Ts ---> bool_T)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   549
  | const_for_iterator_type T =
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33202
diff changeset
   550
    raise TYPE ("Nitpick_HOL.const_for_iterator_type", [T], [])
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   551
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   552
fun strip_n_binders 0 T = ([], T)
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   553
  | strip_n_binders n (Type (@{type_name fun}, [T1, T2])) =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   554
    strip_n_binders (n - 1) T2 |>> cons T1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   555
  | strip_n_binders n (Type (@{type_name fun_box}, Ts)) =
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   556
    strip_n_binders n (Type (@{type_name fun}, Ts))
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33202
diff changeset
   557
  | strip_n_binders _ T = raise TYPE ("Nitpick_HOL.strip_n_binders", [T], [])
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   558
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   559
val nth_range_type = snd oo strip_n_binders
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   560
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   561
fun num_factors_in_type (Type (@{type_name prod}, [T1, T2])) =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   562
    fold (Integer.add o num_factors_in_type) [T1, T2] 0
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   563
  | num_factors_in_type _ = 1
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   564
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   565
val curried_binder_types = maps HOLogic.flatten_tupleT o binder_types
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   566
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   567
fun maybe_curried_binder_types T =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   568
  (if is_pair_type (body_type T) then binder_types else curried_binder_types) T
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   569
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   570
fun mk_flat_tuple _ [t] = t
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   571
  | mk_flat_tuple (Type (@{type_name prod}, [T1, T2])) (t :: ts) =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   572
    HOLogic.pair_const T1 T2 $ t $ (mk_flat_tuple T2 ts)
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33202
diff changeset
   573
  | mk_flat_tuple T ts = raise TYPE ("Nitpick_HOL.mk_flat_tuple", [T], ts)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   574
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   575
fun dest_n_tuple 1 t = [t]
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   576
  | dest_n_tuple n t = HOLogic.dest_prod t ||> dest_n_tuple (n - 1) |> op ::
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   577
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   578
fun typedef_info ctxt s =
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   579
  if is_frac_type ctxt (Type (s, [])) then
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   580
    SOME {abs_type = Type (s, []), rep_type = @{typ "int * int"},
61324
d4ec7594f558 avoid unsound simplification of (C (s x)) when s is a selector but not C's
blanchet
parents: 61125
diff changeset
   581
          Abs_name = @{const_name Abs_Frac},
d4ec7594f558 avoid unsound simplification of (C (s x)) when s is a selector but not C's
blanchet
parents: 61125
diff changeset
   582
          Rep_name = @{const_name Rep_Frac},
d4ec7594f558 avoid unsound simplification of (C (s x)) when s is a selector but not C's
blanchet
parents: 61125
diff changeset
   583
          prop_of_Rep = @{prop "Rep_Frac x \<in> Collect Frac"}
47909
5f1afeebafbc fixed "real" after they were redefined as a 'quotient_type'
blanchet
parents: 47782
diff changeset
   584
                        |> Logic.varify_global,
52205
e62408ee2343 don't create needless constant
blanchet
parents: 51706
diff changeset
   585
          Abs_inverse = NONE, Rep_inverse = NONE}
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   586
  else case Typedef.get_info ctxt s of
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   587
    (* When several entries are returned, it shouldn't matter much which one
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   588
       we take (according to Florian Haftmann). *)
39315
27f7b7748425 always handle type variables in typedefs as global
blanchet
parents: 38864
diff changeset
   589
    (* The "Logic.varifyT_global" calls are a temporary hack because these
27f7b7748425 always handle type variables in typedefs as global
blanchet
parents: 38864
diff changeset
   590
       types's type variables sometimes clash with locally fixed type variables.
27f7b7748425 always handle type variables in typedefs as global
blanchet
parents: 38864
diff changeset
   591
       Remove these calls once "Typedef" is fully localized. *)
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   592
    ({abs_type, rep_type, Abs_name, Rep_name, ...},
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 48812
diff changeset
   593
     {Rep, Abs_inverse, Rep_inverse, ...}) :: _ =>
39315
27f7b7748425 always handle type variables in typedefs as global
blanchet
parents: 38864
diff changeset
   594
    SOME {abs_type = Logic.varifyT_global abs_type,
27f7b7748425 always handle type variables in typedefs as global
blanchet
parents: 38864
diff changeset
   595
          rep_type = Logic.varifyT_global rep_type, Abs_name = Abs_name,
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59433
diff changeset
   596
          Rep_name = Rep_name, prop_of_Rep = Thm.prop_of Rep,
52205
e62408ee2343 don't create needless constant
blanchet
parents: 51706
diff changeset
   597
          Abs_inverse = SOME Abs_inverse, Rep_inverse = SOME Rep_inverse}
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   598
  | _ => NONE
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   599
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   600
val is_raw_typedef = is_some oo typedef_info
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   601
val is_raw_free_datatype = is_some oo Ctr_Sugar.ctr_sugar_of
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   602
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
   603
val is_interpreted_type =
46083
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
   604
  member (op =) [@{type_name prod}, @{type_name set}, @{type_name bool},
55888
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   605
                 @{type_name nat}, @{type_name int}, @{type_name natural},
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   606
                 @{type_name integer}]
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   607
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   608
fun repair_constr_type (Type (_, Ts)) T =
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   609
  snd (dest_Const (Ctr_Sugar.mk_ctr Ts (Const (Name.uu, T))))
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   610
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   611
fun register_frac_type_generic frac_s ersaetze generic =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   612
  let
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   613
    val {frac_types, ersatz_table, codatatypes} = Data.get generic
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   614
    val frac_types = AList.update (op =) (frac_s, ersaetze) frac_types
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   615
  in Data.put {frac_types = frac_types, ersatz_table = ersatz_table,
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   616
               codatatypes = codatatypes} generic end
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   617
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   618
(* TODO: Consider morphism. *)
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   619
fun register_frac_type frac_s ersaetze (_ : morphism) =
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   620
  register_frac_type_generic frac_s ersaetze
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   621
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   622
val register_frac_type_global = Context.theory_map oo register_frac_type_generic
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   623
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   624
fun unregister_frac_type_generic frac_s = register_frac_type_generic frac_s []
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   625
(* TODO: Consider morphism. *)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   626
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   627
fun unregister_frac_type frac_s (_ : morphism) =
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   628
  unregister_frac_type_generic frac_s
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   629
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   630
val unregister_frac_type_global =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   631
  Context.theory_map o unregister_frac_type_generic
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   632
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   633
fun register_ersatz_generic ersatz generic =
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   634
  let
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   635
    val {frac_types, ersatz_table, codatatypes} = Data.get generic
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   636
    val ersatz_table = AList.merge (op =) (K true) (ersatz_table, ersatz)
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   637
  in Data.put {frac_types = frac_types, ersatz_table = ersatz_table,
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   638
               codatatypes = codatatypes} generic end
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   639
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   640
(* TODO: Consider morphism. *)
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   641
fun register_ersatz ersatz (_ : morphism) =
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   642
  register_ersatz_generic ersatz
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   643
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   644
val register_ersatz_global = Context.theory_map o register_ersatz_generic
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   645
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   646
fun register_codatatype_generic coT case_name constr_xs generic =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   647
  let
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   648
    val {frac_types, ersatz_table, codatatypes} = Data.get generic
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   649
    val constr_xs = map (apsnd (repair_constr_type coT)) constr_xs
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   650
    val (co_s, coTs) = dest_Type coT
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   651
    val _ =
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   652
      if forall is_TFree coTs andalso not (has_duplicates (op =) coTs) andalso
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
   653
         co_s <> @{type_name fun} andalso not (is_interpreted_type co_s) then
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   654
        ()
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   655
      else
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   656
        raise TYPE ("Nitpick_HOL.register_codatatype_generic", [coT], [])
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   657
    val codatatypes = AList.update (op =) (co_s, (case_name, constr_xs))
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   658
                                   codatatypes
44012
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   659
  in Data.put {frac_types = frac_types, ersatz_table = ersatz_table,
8c1dfd6c2262 added dynamic ersatz_table to Nitpick's data slot
krauss
parents: 43827
diff changeset
   660
               codatatypes = codatatypes} generic end
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   661
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   662
(* TODO: Consider morphism. *)
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   663
fun register_codatatype coT case_name constr_xs (_ : morphism) =
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   664
  register_codatatype_generic coT case_name constr_xs
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   665
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   666
val register_codatatype_global =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   667
  Context.theory_map ooo register_codatatype_generic
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   668
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   669
fun unregister_codatatype_generic coT = register_codatatype_generic coT "" []
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   670
(* TODO: Consider morphism. *)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   671
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   672
fun unregister_codatatype coT (_ : morphism) =
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   673
  unregister_codatatype_generic coT
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   674
val unregister_codatatype_global =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   675
  Context.theory_map o unregister_codatatype_generic
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   676
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   677
fun is_raw_codatatype ctxt s =
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   678
  Option.map #fp (BNF_FP_Def_Sugar.fp_sugar_of ctxt s)
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   679
  = SOME BNF_Util.Greatest_FP
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   680
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   681
fun is_registered_codatatype ctxt s =
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   682
  not (null (these (Option.map snd (AList.lookup (op =)
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   683
    (#codatatypes (Data.get (Context.Proof ctxt))) s))))
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   684
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   685
fun is_codatatype ctxt (Type (s, _)) =
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   686
    is_raw_codatatype ctxt s orelse is_registered_codatatype ctxt s
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   687
  | is_codatatype _ _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   688
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   689
fun is_registered_type ctxt (T as Type (s, _)) =
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   690
    is_frac_type ctxt T orelse is_registered_codatatype ctxt s
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   691
  | is_registered_type _ _ = false
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   692
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   693
fun is_raw_quot_type ctxt (Type (s, _)) =
45280
9fd6fce8a230 localized quotient data;
wenzelm
parents: 45279
diff changeset
   694
    is_some (Quotient_Info.lookup_quotients ctxt s)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   695
  | is_raw_quot_type _ _ = false
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   696
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   697
fun is_quot_type ctxt T =
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   698
  is_raw_quot_type ctxt T andalso not (is_registered_type ctxt T) andalso
48812
9509fc5485b2 fixed handling of "int" in the wake of its port to the quotient package
blanchet
parents: 48811
diff changeset
   699
  T <> @{typ int}
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   700
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   701
fun is_pure_typedef ctxt (T as Type (s, _)) =
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   702
    is_frac_type ctxt T orelse
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   703
    (is_raw_typedef ctxt s andalso
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   704
     not (is_raw_free_datatype ctxt s orelse is_raw_quot_type ctxt T orelse
57228
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
   705
       is_codatatype ctxt T orelse is_integer_like_type T))
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   706
  | is_pure_typedef _ _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   707
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   708
fun is_univ_typedef ctxt (Type (s, _)) =
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   709
    (case typedef_info ctxt s of
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 48812
diff changeset
   710
       SOME {prop_of_Rep, ...} =>
35332
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   711
       let
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   712
         val t_opt =
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 48812
diff changeset
   713
           try (snd o HOLogic.dest_mem o HOLogic.dest_Trueprop) prop_of_Rep
35332
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   714
       in
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   715
         case t_opt of
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   716
           SOME (Const (@{const_name top}, _)) => true
35386
45a4e19d3ebd more work on the new monotonicity stuff in Nitpick
blanchet
parents: 35385
diff changeset
   717
           (* "Multiset.multiset" *)
35332
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   718
         | SOME (Const (@{const_name Collect}, _)
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   719
                 $ Abs (_, _, Const (@{const_name finite}, _) $ _)) => true
35386
45a4e19d3ebd more work on the new monotonicity stuff in Nitpick
blanchet
parents: 35385
diff changeset
   720
           (* "FinFun.finfun" *)
45a4e19d3ebd more work on the new monotonicity stuff in Nitpick
blanchet
parents: 35385
diff changeset
   721
         | SOME (Const (@{const_name Collect}, _) $ Abs (_, _,
45a4e19d3ebd more work on the new monotonicity stuff in Nitpick
blanchet
parents: 35385
diff changeset
   722
                     Const (@{const_name Ex}, _) $ Abs (_, _,
45a4e19d3ebd more work on the new monotonicity stuff in Nitpick
blanchet
parents: 35385
diff changeset
   723
                         Const (@{const_name finite}, _) $ _))) => true
35332
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   724
         | _ => false
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   725
       end
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   726
     | NONE => false)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   727
  | is_univ_typedef _ _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   728
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
   729
fun is_data_type ctxt (T as Type (s, _)) =
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   730
    (is_raw_typedef ctxt s orelse is_registered_type ctxt T orelse
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   731
     T = @{typ ind} orelse is_raw_quot_type ctxt T) andalso
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
   732
    not (is_interpreted_type s)
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
   733
  | is_data_type _ _ = false
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   734
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   735
fun all_record_fields thy T =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   736
  let val (recs, more) = Record.get_extT_fields thy T in
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   737
    recs @ more :: all_record_fields thy (snd more)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   738
  end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   739
  handle TYPE _ => []
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   740
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   741
val num_record_fields = Integer.add 1 o length o fst oo Record.get_extT_fields
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   742
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   743
fun no_of_record_field thy s T1 =
57228
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
   744
  find_index (curry (op =) s o fst) (Record.get_extT_fields thy T1 ||> single |> op @)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   745
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   746
fun is_record_get thy (s, Type (@{type_name fun}, [T1, _])) =
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   747
    exists (curry (op =) s o fst) (all_record_fields thy T1)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   748
  | is_record_get _ _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   749
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   750
fun is_record_update thy (s, T) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   751
  String.isSuffix Record.updateN s andalso
57228
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
   752
  exists (curry (op =) (unsuffix Record.updateN s) o fst) (all_record_fields thy (body_type T))
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   753
  handle TYPE _ => false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   754
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   755
fun is_abs_fun ctxt (s, Type (@{type_name fun}, [_, Type (s', _)])) =
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   756
    (case typedef_info ctxt s' of
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   757
       SOME {Abs_name, ...} => s = Abs_name
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   758
     | NONE => false)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   759
  | is_abs_fun _ _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   760
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   761
fun is_rep_fun ctxt (s, Type (@{type_name fun}, [Type (s', _), _])) =
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   762
    (case typedef_info ctxt s' of
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   763
       SOME {Rep_name, ...} => s = Rep_name
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   764
     | NONE => false)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   765
  | is_rep_fun _ _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   766
38215
1c7d7eaebdf2 quotient types registered as codatatypes are no longer quotient types
blanchet
parents: 38212
diff changeset
   767
fun is_quot_abs_fun ctxt (x as (_, Type (@{type_name fun},
1c7d7eaebdf2 quotient types registered as codatatypes are no longer quotient types
blanchet
parents: 38212
diff changeset
   768
                                         [_, abs_T as Type (s', _)]))) =
45797
977cf00fb8d3 make ctxt the first parameter
kuncar
parents: 45280
diff changeset
   769
    try (Quotient_Term.absrep_const_chk ctxt Quotient_Term.AbsF) s'
47909
5f1afeebafbc fixed "real" after they were redefined as a 'quotient_type'
blanchet
parents: 47782
diff changeset
   770
    = SOME (Const x) andalso not (is_registered_type ctxt abs_T)
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   771
  | is_quot_abs_fun _ _ = false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   772
46819
9b38f8527510 addressed a quotient-type-related issue that arose with the port to "set"
blanchet
parents: 46746
diff changeset
   773
fun is_quot_rep_fun ctxt (s, Type (@{type_name fun},
9b38f8527510 addressed a quotient-type-related issue that arose with the port to "set"
blanchet
parents: 46746
diff changeset
   774
                                   [abs_T as Type (abs_s, _), _])) =
46746
a10dcc985e8d improved handling of polymorphic quotient types, by avoiding comparing types that will generally differ in the polymorphic case
blanchet
parents: 46745
diff changeset
   775
    (case try (Quotient_Term.absrep_const_chk ctxt Quotient_Term.RepF) abs_s of
47909
5f1afeebafbc fixed "real" after they were redefined as a 'quotient_type'
blanchet
parents: 47782
diff changeset
   776
       SOME (Const (s', _)) =>
5f1afeebafbc fixed "real" after they were redefined as a 'quotient_type'
blanchet
parents: 47782
diff changeset
   777
       s = s' andalso not (is_registered_type ctxt abs_T)
48811
d1688612668d removed dead code
blanchet
parents: 47990
diff changeset
   778
     | _ => false)
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   779
  | is_quot_rep_fun _ _ = false
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   780
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   781
fun mate_of_rep_fun ctxt (x as (_, Type (@{type_name fun},
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   782
                                         [T1 as Type (s', _), T2]))) =
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   783
    (case typedef_info ctxt s' of
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   784
       SOME {Abs_name, ...} => (Abs_name, Type (@{type_name fun}, [T2, T1]))
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33202
diff changeset
   785
     | NONE => raise TERM ("Nitpick_HOL.mate_of_rep_fun", [Const x]))
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33202
diff changeset
   786
  | mate_of_rep_fun _ x = raise TERM ("Nitpick_HOL.mate_of_rep_fun", [Const x])
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   787
45280
9fd6fce8a230 localized quotient data;
wenzelm
parents: 45279
diff changeset
   788
fun rep_type_for_quot_type ctxt (T as Type (s, _)) =
9fd6fce8a230 localized quotient data;
wenzelm
parents: 45279
diff changeset
   789
    let
9fd6fce8a230 localized quotient data;
wenzelm
parents: 45279
diff changeset
   790
      val thy = Proof_Context.theory_of ctxt
9fd6fce8a230 localized quotient data;
wenzelm
parents: 45279
diff changeset
   791
      val {qtyp, rtyp, ...} = the (Quotient_Info.lookup_quotients ctxt s)
9fd6fce8a230 localized quotient data;
wenzelm
parents: 45279
diff changeset
   792
    in
39345
062c10ff848c remove unreferenced identifiers
blanchet
parents: 39315
diff changeset
   793
      instantiate_type thy qtyp T rtyp
062c10ff848c remove unreferenced identifiers
blanchet
parents: 39315
diff changeset
   794
    end
062c10ff848c remove unreferenced identifiers
blanchet
parents: 39315
diff changeset
   795
  | rep_type_for_quot_type _ T =
062c10ff848c remove unreferenced identifiers
blanchet
parents: 39315
diff changeset
   796
    raise TYPE ("Nitpick_HOL.rep_type_for_quot_type", [T], [])
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   797
35284
9edc2bd6d2bd enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents: 35283
diff changeset
   798
fun equiv_relation_for_quot_type thy (Type (s, Ts)) =
9edc2bd6d2bd enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents: 35283
diff changeset
   799
    let
46745
a6f83f21dc2c fixed handling of "Rep_" function of quotient types -- side-effect of "set" constructor reintroduction
blanchet
parents: 46320
diff changeset
   800
      val {qtyp, equiv_rel, equiv_thm, ...} =
a6f83f21dc2c fixed handling of "Rep_" function of quotient types -- side-effect of "set" constructor reintroduction
blanchet
parents: 46320
diff changeset
   801
        the (Quotient_Info.lookup_quotients thy s)
38243
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   802
      val partial =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59433
diff changeset
   803
        case Thm.prop_of equiv_thm of
38243
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   804
          @{const Trueprop} $ (Const (@{const_name equivp}, _) $ _) => false
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   805
        | @{const Trueprop} $ (Const (@{const_name part_equivp}, _) $ _) => true
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   806
        | _ => raise NOT_SUPPORTED "Ill-formed quotient type equivalence \
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   807
                                   \relation theorem"
35284
9edc2bd6d2bd enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents: 35283
diff changeset
   808
      val Ts' = qtyp |> dest_Type |> snd
38243
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   809
    in (subst_atomic_types (Ts' ~~ Ts) equiv_rel, partial) end
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   810
  | equiv_relation_for_quot_type _ T =
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   811
    raise TYPE ("Nitpick_HOL.equiv_relation_for_quot_type", [T], [])
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   812
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   813
fun is_raw_free_datatype_constr ctxt (s, T) =
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   814
  case body_type T of
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   815
    dtT as Type (dt_s, _) =>
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   816
    let
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   817
      val ctrs =
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   818
        case Ctr_Sugar.ctr_sugar_of ctxt dt_s of
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   819
          SOME {ctrs, ...} => map dest_Const ctrs
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   820
        | _ => []
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   821
    in
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   822
      exists (fn (s', T') => s = s' andalso repair_constr_type dtT T' = T) ctrs
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   823
    end
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   824
  | _  => false
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   825
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   826
fun is_registered_coconstr ctxt (s, T) =
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   827
  case body_type T of
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   828
    coT as Type (co_s, _) =>
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   829
    let
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   830
      val ctrs =
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   831
        co_s
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   832
        |> AList.lookup (op =) (#codatatypes (Data.get (Context.Proof ctxt)))
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   833
        |> Option.map snd |> these
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   834
    in
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   835
      exists (fn (s', T') => s = s' andalso repair_constr_type coT T' = T) ctrs
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   836
    end
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 55017
diff changeset
   837
  | _ => false
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   838
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   839
fun is_nonfree_constr ctxt (s, T) =
41052
3db267a01c1d remove the "fin_fun" optimization in Nitpick -- it was always a hack and didn't help much
blanchet
parents: 41049
diff changeset
   840
  member (op =) [@{const_name FunBox}, @{const_name PairBox},
3db267a01c1d remove the "fin_fun" optimization in Nitpick -- it was always a hack and didn't help much
blanchet
parents: 41049
diff changeset
   841
                 @{const_name Quot}, @{const_name Zero_Rep},
3db267a01c1d remove the "fin_fun" optimization in Nitpick -- it was always a hack and didn't help much
blanchet
parents: 41049
diff changeset
   842
                 @{const_name Suc_Rep}] s orelse
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   843
  let val (x as (_, T)) = (s, unarize_unbox_etc_type T) in
57228
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
   844
    is_raw_free_datatype_constr ctxt x orelse
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   845
    (is_abs_fun ctxt x andalso is_pure_typedef ctxt (range_type T)) orelse
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   846
    is_registered_coconstr ctxt x
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   847
  end
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   848
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   849
fun is_free_constr ctxt (s, T) =
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   850
  is_nonfree_constr ctxt (s, T) andalso
51706
0a4b4735d8bd not all Nitpick 'constructors' are injective -- careful
blanchet
parents: 51143
diff changeset
   851
  let val (x as (_, T)) = (s, unarize_unbox_etc_type T) in
0a4b4735d8bd not all Nitpick 'constructors' are injective -- careful
blanchet
parents: 51143
diff changeset
   852
    not (is_abs_fun ctxt x) orelse is_univ_typedef ctxt (range_type T)
0a4b4735d8bd not all Nitpick 'constructors' are injective -- careful
blanchet
parents: 51143
diff changeset
   853
  end
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   854
47909
5f1afeebafbc fixed "real" after they were redefined as a 'quotient_type'
blanchet
parents: 47782
diff changeset
   855
fun is_stale_constr ctxt (x as (s, T)) =
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   856
  is_registered_type ctxt (body_type T) andalso is_nonfree_constr ctxt x andalso
61324
d4ec7594f558 avoid unsound simplification of (C (s x)) when s is a selector but not C's
blanchet
parents: 61125
diff changeset
   857
  not (s = @{const_name Abs_Frac} orelse is_registered_coconstr ctxt x)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   858
55888
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   859
fun is_constr ctxt (x as (_, T)) =
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   860
  is_nonfree_constr ctxt x andalso
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
   861
  not (is_interpreted_type (fst (dest_Type (unarize_type (body_type T))))) andalso
55888
cac1add157e8 removed nonstandard models from Nitpick
blanchet
parents: 55874
diff changeset
   862
  not (is_stale_constr ctxt x)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   863
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   864
val is_sel = String.isPrefix discr_prefix orf String.isPrefix sel_prefix
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   865
val is_sel_like_and_no_discr =
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   866
  String.isPrefix sel_prefix orf
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   867
  (member (op =) [@{const_name fst}, @{const_name snd}])
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   868
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   869
fun in_fun_lhs_for InConstr = InSel
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   870
  | in_fun_lhs_for _ = InFunLHS
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   871
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   872
fun in_fun_rhs_for InConstr = InConstr
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   873
  | in_fun_rhs_for InSel = InSel
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   874
  | in_fun_rhs_for InFunRHS1 = InFunRHS2
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   875
  | in_fun_rhs_for _ = InFunRHS1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   876
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   877
fun is_boxing_worth_it (hol_ctxt : hol_context) boxy T =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   878
  case T of
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   879
    Type (@{type_name fun}, _) =>
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   880
    (boxy = InPair orelse boxy = InFunLHS) andalso
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   881
    not (is_boolean_type (body_type T))
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   882
  | Type (@{type_name prod}, Ts) =>
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   883
    boxy = InPair orelse boxy = InFunRHS1 orelse boxy = InFunRHS2 orelse
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   884
    ((boxy = InExpr orelse boxy = InFunLHS) andalso
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   885
     exists (is_boxing_worth_it hol_ctxt InPair)
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   886
            (map (box_type hol_ctxt InPair) Ts))
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   887
  | _ => false
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   888
and should_box_type (hol_ctxt as {thy, boxes, ...}) boxy z =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   889
  case triple_lookup (type_match thy) boxes (Type z) of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   890
    SOME (SOME box_me) => box_me
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   891
  | _ => is_boxing_worth_it hol_ctxt boxy (Type z)
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   892
and box_type hol_ctxt boxy T =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   893
  case T of
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   894
    Type (z as (@{type_name fun}, [T1, T2])) =>
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   895
    if boxy <> InConstr andalso boxy <> InSel andalso
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   896
       should_box_type hol_ctxt boxy z then
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   897
      Type (@{type_name fun_box},
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   898
            [box_type hol_ctxt InFunLHS T1, box_type hol_ctxt InFunRHS1 T2])
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   899
    else
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   900
      box_type hol_ctxt (in_fun_lhs_for boxy) T1
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   901
      --> box_type hol_ctxt (in_fun_rhs_for boxy) T2
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   902
  | Type (z as (@{type_name prod}, Ts)) =>
34982
7b8c366e34a2 added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents: 34936
diff changeset
   903
    if boxy <> InConstr andalso boxy <> InSel
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   904
       andalso should_box_type hol_ctxt boxy z then
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   905
      Type (@{type_name pair_box}, map (box_type hol_ctxt InSel) Ts)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   906
    else
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   907
      Type (@{type_name prod},
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   908
            map (box_type hol_ctxt
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   909
                          (if boxy = InConstr orelse boxy = InSel then boxy
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   910
                           else InPair)) Ts)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   911
  | _ => T
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   912
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   913
fun binarize_nat_and_int_in_type @{typ nat} = @{typ "unsigned_bit word"}
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   914
  | binarize_nat_and_int_in_type @{typ int} = @{typ "signed_bit word"}
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   915
  | binarize_nat_and_int_in_type (Type (s, Ts)) =
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   916
    Type (s, map binarize_nat_and_int_in_type Ts)
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   917
  | binarize_nat_and_int_in_type T = T
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   918
val binarize_nat_and_int_in_term = map_types binarize_nat_and_int_in_type
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   919
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   920
fun discr_for_constr (s, T) = (discr_prefix ^ s, body_type T --> bool_T)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   921
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   922
fun num_sels_for_constr_type T = length (maybe_curried_binder_types T)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   923
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   924
fun nth_sel_name_for_constr_name s n =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   925
  if s = @{const_name Pair} then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   926
    if n = 0 then @{const_name fst} else @{const_name snd}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   927
  else
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   928
    sel_prefix_for n ^ s
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   929
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   930
fun nth_sel_for_constr x ~1 = discr_for_constr x
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   931
  | nth_sel_for_constr (s, T) n =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   932
    (nth_sel_name_for_constr_name s n,
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   933
     body_type T --> nth (maybe_curried_binder_types T) n)
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   934
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   935
fun binarized_and_boxed_nth_sel_for_constr hol_ctxt binarize =
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   936
  apsnd ((binarize ? binarize_nat_and_int_in_type) o box_type hol_ctxt InSel)
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   937
  oo nth_sel_for_constr
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   938
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   939
fun sel_no_from_name s =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   940
  if String.isPrefix discr_prefix s then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   941
    ~1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   942
  else if String.isPrefix sel_prefix s then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   943
    s |> unprefix sel_prefix |> Int.fromString |> the
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   944
  else if s = @{const_name snd} then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   945
    1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   946
  else
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   947
    0
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   948
35078
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   949
val close_form =
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   950
  let
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   951
    fun close_up zs zs' =
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   952
      fold (fn (z as ((s, _), T)) => fn t' =>
46217
7b19666f0e3d renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents: 46115
diff changeset
   953
               Logic.all_const T $ Abs (s, T, abstract_over (Var z, t')))
35078
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   954
           (take (length zs' - length zs) zs')
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56243
diff changeset
   955
    fun aux zs (@{const Pure.imp} $ t1 $ t2) =
35078
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   956
        let val zs' = Term.add_vars t1 zs in
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   957
          close_up zs zs' (Logic.mk_implies (t1, aux zs' t2))
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   958
        end
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   959
      | aux zs t = close_up zs (Term.add_vars t zs) t
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   960
  in aux [] end
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   961
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   962
fun distinctness_formula T =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   963
  all_distinct_unordered_pairs_of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   964
  #> map (fn (t1, t2) => @{const Not} $ (HOLogic.eq_const T $ t1 $ t2))
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   965
  #> List.foldr (s_conj o swap) @{const True}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   966
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   967
fun zero_const T = Const (@{const_name zero_class.zero}, T)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   968
fun suc_const T = Const (@{const_name Suc}, T --> T)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   969
57992
blanchet
parents: 57964
diff changeset
   970
fun uncached_data_type_constrs ({ctxt, ...} : hol_context) (T as Type (s, _)) =
55893
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   971
    if is_interpreted_type s then
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   972
      []
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   973
    else
57228
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
   974
      (case AList.lookup (op =) (#codatatypes (Data.get (Context.Proof ctxt))) s of
55893
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   975
         SOME (_, xs' as (_ :: _)) => map (apsnd (repair_constr_type T)) xs'
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   976
       | _ =>
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   977
         if is_frac_type ctxt T then
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   978
           case typedef_info ctxt s of
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   979
             SOME {abs_type, rep_type, Abs_name, ...} =>
57228
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
   980
             [(Abs_name, varify_and_instantiate_type ctxt abs_type T rep_type --> T)]
55893
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   981
           | NONE => [] (* impossible *)
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   982
         else
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   983
           case Ctr_Sugar.ctr_sugar_of ctxt s of
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   984
             SOME {ctrs, ...} =>
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   985
             map (apsnd (repair_constr_type T) o dest_Const) ctrs
55891
d1a9b07783ab support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
blanchet
parents: 55890
diff changeset
   986
           | NONE =>
57228
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
   987
             if is_raw_quot_type ctxt T then
55893
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   988
               [(@{const_name Quot}, rep_type_for_quot_type ctxt T --> T)]
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   989
             else case typedef_info ctxt s of
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   990
               SOME {abs_type, rep_type, Abs_name, ...} =>
57228
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
   991
               [(Abs_name, varify_and_instantiate_type ctxt abs_type T rep_type --> T)]
55893
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
   992
             | NONE =>
57228
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
   993
               if T = @{typ ind} then [dest_Const @{const Zero_Rep}, dest_Const @{const Suc_Rep}]
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
   994
               else [])
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
   995
  | uncached_data_type_constrs _ _ = []
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
   996
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
   997
fun data_type_constrs (hol_ctxt as {constr_cache, ...}) T =
33580
45c33e97cb86 added datatype constructor cache in Nitpick (to speed up the scope enumeration) and never test more than 4096 scopes
blanchet
parents: 33578
diff changeset
   998
  case AList.lookup (op =) (!constr_cache) T of
45c33e97cb86 added datatype constructor cache in Nitpick (to speed up the scope enumeration) and never test more than 4096 scopes
blanchet
parents: 33578
diff changeset
   999
    SOME xs => xs
45c33e97cb86 added datatype constructor cache in Nitpick (to speed up the scope enumeration) and never test more than 4096 scopes
blanchet
parents: 33578
diff changeset
  1000
  | NONE =>
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
  1001
    let val xs = uncached_data_type_constrs hol_ctxt T in
33580
45c33e97cb86 added datatype constructor cache in Nitpick (to speed up the scope enumeration) and never test more than 4096 scopes
blanchet
parents: 33578
diff changeset
  1002
      (Unsynchronized.change constr_cache (cons (T, xs)); xs)
45c33e97cb86 added datatype constructor cache in Nitpick (to speed up the scope enumeration) and never test more than 4096 scopes
blanchet
parents: 33578
diff changeset
  1003
    end
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
  1004
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
  1005
fun binarized_and_boxed_data_type_constrs hol_ctxt binarize =
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
  1006
  map (apsnd ((binarize ? binarize_nat_and_int_in_type)
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
  1007
              o box_type hol_ctxt InConstr)) o data_type_constrs hol_ctxt
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1008
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1009
fun constr_name_for_sel_like @{const_name fst} = @{const_name Pair}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1010
  | constr_name_for_sel_like @{const_name snd} = @{const_name Pair}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1011
  | constr_name_for_sel_like s' = original_name s'
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
  1012
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
  1013
fun binarized_and_boxed_constr_for_sel hol_ctxt binarize (s', T') =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1014
  let val s = constr_name_for_sel_like s' in
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
  1015
    AList.lookup (op =)
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
  1016
        (binarized_and_boxed_data_type_constrs hol_ctxt binarize (domain_type T'))
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
  1017
        s
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1018
    |> the |> pair s
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1019
  end
34982
7b8c366e34a2 added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents: 34936
diff changeset
  1020
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1021
fun card_of_type assigns (Type (@{type_name fun}, [T1, T2])) =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1022
    reasonable_power (card_of_type assigns T2) (card_of_type assigns T1)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1023
  | card_of_type assigns (Type (@{type_name prod}, [T1, T2])) =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1024
    card_of_type assigns T1 * card_of_type assigns T2
46083
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
  1025
  | card_of_type assigns (Type (@{type_name set}, [T'])) =
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
  1026
    reasonable_power 2 (card_of_type assigns T')
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1027
  | card_of_type _ (Type (@{type_name itself}, _)) = 1
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1028
  | card_of_type _ @{typ prop} = 2
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1029
  | card_of_type _ @{typ bool} = 2
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1030
  | card_of_type assigns T =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1031
    case AList.lookup (op =) assigns T of
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1032
      SOME k => k
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1033
    | NONE => if T = @{typ bisim_iterator} then 0
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1034
              else raise TYPE ("Nitpick_HOL.card_of_type", [T], [])
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1035
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1036
fun bounded_card_of_type max default_card assigns
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1037
                         (Type (@{type_name fun}, [T1, T2])) =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1038
    let
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1039
      val k1 = bounded_card_of_type max default_card assigns T1
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1040
      val k2 = bounded_card_of_type max default_card assigns T2
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1041
    in
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1042
      if k1 = max orelse k2 = max then max
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1043
      else Int.min (max, reasonable_power k2 k1)
47668
13da7b50e9a5 more meaningful default value
blanchet
parents: 47667
diff changeset
  1044
      handle TOO_LARGE _ => max
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1045
    end
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1046
  | bounded_card_of_type max default_card assigns
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1047
                         (Type (@{type_name prod}, [T1, T2])) =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1048
    let
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1049
      val k1 = bounded_card_of_type max default_card assigns T1
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1050
      val k2 = bounded_card_of_type max default_card assigns T2
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1051
    in if k1 = max orelse k2 = max then max else Int.min (max, k1 * k2) end
46083
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
  1052
  | bounded_card_of_type max default_card assigns
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
  1053
                         (Type (@{type_name set}, [T'])) =
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
  1054
    bounded_card_of_type max default_card assigns (T' --> bool_T)
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1055
  | bounded_card_of_type max default_card assigns T =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1056
    Int.min (max, if default_card = ~1 then
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1057
                    card_of_type assigns T
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1058
                  else
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1059
                    card_of_type assigns T
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1060
                    handle TYPE ("Nitpick_HOL.card_of_type", _, _) =>
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1061
                           default_card)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1062
46320
0b8b73b49848 renamed two files to make room for a new file
blanchet
parents: 46244
diff changeset
  1063
(* Similar to "ATP_Util.tiny_card_of_type". *)
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1064
fun bounded_exact_card_of_type hol_ctxt finitizable_dataTs max default_card
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1065
                               assigns T =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1066
  let
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1067
    fun aux avoid T =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1068
      (if member (op =) avoid T then
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1069
         0
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1070
       else if member (op =) finitizable_dataTs T then
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1071
         raise SAME ()
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1072
       else case T of
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1073
         Type (@{type_name fun}, [T1, T2]) =>
42679
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1074
         (case (aux avoid T1, aux avoid T2) of
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1075
            (_, 1) => 1
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1076
          | (0, _) => 0
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1077
          | (_, 0) => 0
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1078
          | (k1, k2) =>
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1079
            if k1 >= max orelse k2 >= max then max
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1080
            else Int.min (max, reasonable_power k2 k1))
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1081
       | Type (@{type_name prod}, [T1, T2]) =>
42679
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1082
         (case (aux avoid T1, aux avoid T2) of
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1083
            (0, _) => 0
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1084
          | (_, 0) => 0
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1085
          | (k1, k2) =>
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1086
            if k1 >= max orelse k2 >= max then max
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1087
            else Int.min (max, k1 * k2))
46083
efeaa79f021b port part of Nitpick to "set" type constructor
blanchet
parents: 46081
diff changeset
  1088
       | Type (@{type_name set}, [T']) => aux avoid (T' --> bool_T)
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1089
       | Type (@{type_name itself}, _) => 1
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1090
       | @{typ prop} => 2
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1091
       | @{typ bool} => 2
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1092
       | Type _ =>
55890
bd7927cca152 tuned ML names
blanchet
parents: 55889
diff changeset
  1093
         (case data_type_constrs hol_ctxt T of
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1094
            [] => if is_integer_type T orelse is_bit_type T then 0
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1095
                  else raise SAME ()
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1096
          | constrs =>
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1097
            let
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1098
              val constr_cards =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1099
                map (Integer.prod o map (aux (T :: avoid)) o binder_types o snd)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1100
                    constrs
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1101
            in
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1102
              if exists (curry (op =) 0) constr_cards then 0
42679
223f01b32f17 [mq]: nitpick_tuning
blanchet
parents: 42678
diff changeset
  1103
              else Int.min (max, Integer.sum constr_cards)
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1104
            end)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1105
       | _ => raise SAME ())
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1106
      handle SAME () =>
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1107
             AList.lookup (op =) assigns T |> the_default default_card
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1108
  in Int.min (max, aux [] T) end
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1109
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1110
val typical_atomic_card = 4
41898
55d981e1232a improved formula for specialization, to prevent needless specializations -- and removed dead code
blanchet
parents: 41876
diff changeset
  1111
val typical_card_of_type = bounded_card_of_type 16777217 typical_atomic_card []
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1112
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1113
fun is_finite_type hol_ctxt T =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1114
  bounded_exact_card_of_type hol_ctxt [] 1 2 [] T > 0
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1115
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1116
fun is_special_eligible_arg strict Ts t =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1117
  case map snd (Term.add_vars t []) @ map (nth Ts) (loose_bnos t) of
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1118
    [] => true
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1119
  | bad_Ts =>
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1120
    let
41898
55d981e1232a improved formula for specialization, to prevent needless specializations -- and removed dead code
blanchet
parents: 41876
diff changeset
  1121
      val bad_Ts_cost =
55d981e1232a improved formula for specialization, to prevent needless specializations -- and removed dead code
blanchet
parents: 41876
diff changeset
  1122
        if strict then fold (curry (op *) o typical_card_of_type) bad_Ts 1
55d981e1232a improved formula for specialization, to prevent needless specializations -- and removed dead code
blanchet
parents: 41876
diff changeset
  1123
        else fold (Integer.max o typical_card_of_type) bad_Ts 0
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1124
      val T_cost = typical_card_of_type (fastype_of1 (Ts, t))
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1125
    in (bad_Ts_cost, T_cost) |> (if strict then op < else op <=) end
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1126
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1127
fun abs_var ((s, j), T) body = Abs (s, T, abstract_over (Var ((s, j), T), body))
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1128
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1129
fun let_var s = (nitpick_prefix ^ s, 999)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1130
val let_inline_threshold = 20
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1131
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1132
fun s_let Ts s n abs_T body_T f t =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1133
  if (n - 1) * (size_of_term t - 1) <= let_inline_threshold orelse
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1134
     is_special_eligible_arg false Ts t then
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1135
    f t
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1136
  else
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1137
    let val z = (let_var s, abs_T) in
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1138
      Const (@{const_name Let}, abs_T --> (abs_T --> body_T) --> body_T)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1139
      $ t $ abs_var z (incr_boundvars 1 (f (Var z)))
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1140
    end
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1141
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1142
fun loose_bvar1_count (Bound i, k) = if i = k then 1 else 0
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1143
  | loose_bvar1_count (t1 $ t2, k) =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1144
    loose_bvar1_count (t1, k) + loose_bvar1_count (t2, k)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1145
  | loose_bvar1_count (Abs (_, _, t), k) = loose_bvar1_count (t, k + 1)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1146
  | loose_bvar1_count _ = 0
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1147
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56243
diff changeset
  1148
fun s_betapply _ (t1 as Const (@{const_name Pure.eq}, _) $ t1', t2) =
42414
9465651c0db7 optimize trivial equalities early in Nitpick -- it shouldn't be the job of the peephole optimizer
blanchet
parents: 42361
diff changeset
  1149
    if t1' aconv t2 then @{prop True} else t1 $ t2
9465651c0db7 optimize trivial equalities early in Nitpick -- it shouldn't be the job of the peephole optimizer
blanchet
parents: 42361
diff changeset
  1150
  | s_betapply _ (t1 as Const (@{const_name HOL.eq}, _) $ t1', t2) =
9465651c0db7 optimize trivial equalities early in Nitpick -- it shouldn't be the job of the peephole optimizer
blanchet
parents: 42361
diff changeset
  1151
    if t1' aconv t2 then @{term True} else t1 $ t2
9465651c0db7 optimize trivial equalities early in Nitpick -- it shouldn't be the job of the peephole optimizer
blanchet
parents: 42361
diff changeset
  1152
  | s_betapply _ (Const (@{const_name If}, _) $ @{const True} $ t1', _) = t1'
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1153
  | s_betapply _ (Const (@{const_name If}, _) $ @{const False} $ _, t2) = t2
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1154
  | s_betapply Ts (Const (@{const_name Let},
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1155
                          Type (_, [bound_T, Type (_, [_, body_T])]))
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1156
                   $ t12 $ Abs (s, T, t13'), t2) =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1157
    let val body_T' = range_type body_T in
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1158
      Const (@{const_name Let}, bound_T --> (bound_T --> body_T') --> body_T')
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1159
      $ t12 $ Abs (s, T, s_betapply (T :: Ts) (t13', incr_boundvars 1 t2))
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1160
    end
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1161
  | s_betapply Ts (t1 as Abs (s1, T1, t1'), t2) =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1162
    (s_let Ts s1 (loose_bvar1_count (t1', 0)) T1 (fastype_of1 (T1 :: Ts, t1'))
42958
034fc4d0c909 fixed de Bruijn index bug
blanchet
parents: 42793
diff changeset
  1163
           (curry betapply t1) t2
034fc4d0c909 fixed de Bruijn index bug
blanchet
parents: 42793
diff changeset
  1164
     (* FIXME: fix all "s_betapply []" calls *)
034fc4d0c909 fixed de Bruijn index bug
blanchet
parents: 42793
diff changeset
  1165
     handle TERM _ => betapply (t1, t2)
034fc4d0c909 fixed de Bruijn index bug
blanchet
parents: 42793
diff changeset
  1166
          | General.Subscript => betapply (t1, t2))
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1167
  | s_betapply _ (t1, t2) = t1 $ t2
55889
6bfbec3dff62 tuned code
blanchet
parents: 55888
diff changeset
  1168
41860
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1169
fun s_betapplys Ts = Library.foldl (s_betapply Ts)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1170
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1171
fun s_beta_norm Ts t =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1172
  let
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1173
    fun aux _ (Var _) = raise Same.SAME
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1174
      | aux Ts (Abs (s, T, t')) = Abs (s, T, aux (T :: Ts) t')
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1175
      | aux Ts ((t1 as Abs _) $ t2) =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1176
        Same.commit (aux Ts) (s_betapply Ts (t1, t2))
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1177
      | aux Ts (t1 $ t2) =
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1178
        ((case aux Ts t1 of
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1179
           t1 as Abs _ => Same.commit (aux Ts) (s_betapply Ts (t1, t2))
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1180
         | t1 => t1 $ Same.commit (aux Ts) t2)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1181
        handle Same.SAME => t1 $ aux Ts t2)
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1182
      | aux _ _ = raise Same.SAME
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1183
  in aux Ts t handle Same.SAME => t end
49d0fc8c418c improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
blanchet
parents: 41859
diff changeset
  1184
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
  1185
fun discr_term_for_constr hol_ctxt (x as (s, T)) =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1186
  let val dataT = body_type T in
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1187
    if s = @{const_name Suc} then
57228
d52012eabf0d removed subsumed record-related code, now that records are registered as 'ctr_sugar'
blanchet
parents: 57227
diff changeset
  1188
      Abs (Name.uu, dataT, @{const Not} $ HOLogic.mk_eq (zero_const dataT, Bound 0))
55893
aed17a173d16 fixed handling of 'case_prod' and other 'case' functions for interpreted types
blanchet
parents: 55891
diff changeset
  1189</