src/HOL/Tools/Nitpick/nitpick_hol.ML
author blanchet
Mon, 28 Feb 2011 17:53:10 +0100
changeset 41860 49d0fc8c418c
parent 41859 c3a5912d0922
child 41871 394eef237bd1
permissions -rw-r--r--
improved "is_special_eligible_arg" further, by approximating the cardinality of the argument (as is done quite successfully elsewhere)
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
33705
947184dc75c9 removed a few global names in Nitpick (styp, nat_less, pairf)
blanchet
parents: 33583
diff changeset
    10
  type styp = Nitpick_Util.styp
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    11
  type const_table = term list Symtab.table
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    12
  type special_fun = (styp * int list * term list) * styp
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    13
  type unrolled = styp * styp
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    14
  type wf_cache = (styp * (bool * bool)) list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    15
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    16
  type hol_context =
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    17
    {thy: theory,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    18
     ctxt: Proof.context,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    19
     max_bisim_depth: int,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    20
     boxes: (typ option * bool option) list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    21
     stds: (typ option * bool) list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    22
     wfs: (styp option * bool option) list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    23
     user_axioms: bool option,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    24
     debug: bool,
38209
3d1d928dce50 added "whack"
blanchet
parents: 38208
diff changeset
    25
     whacks: term list,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    26
     binary_ints: bool option,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    27
     destroy_constrs: bool,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    28
     specialize: bool,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    29
     star_linear_preds: bool,
41803
ef13e3b7cbaf more work on "fix_datatype_vals" optimization (renamed "preconstruct")
blanchet
parents: 41795
diff changeset
    30
     preconstrs: (term option * bool option) list,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    31
     tac_timeout: Time.time option,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    32
     evals: term list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    33
     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
    34
     def_tables: const_table * const_table,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    35
     nondef_table: const_table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    36
     user_nondefs: term list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    37
     simp_table: const_table Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    38
     psimp_table: const_table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    39
     choice_spec_table: const_table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    40
     intro_table: const_table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    41
     ground_thm_table: term list Inttab.table,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    42
     ersatz_table: (string * string) list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    43
     skolems: (string * string list) list Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    44
     special_funs: special_fun list Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    45
     unrolled_preds: unrolled list Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    46
     wf_cache: wf_cache Unsynchronized.ref,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
    47
     constr_cache: (typ * styp list) list Unsynchronized.ref}
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    48
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    49
  datatype fixpoint_kind = Lfp | Gfp | NoFp
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    50
  datatype boxability =
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    51
    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
    52
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    53
  val name_sep : string
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    54
  val numeral_prefix : string
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
    55
  val base_prefix : string
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
    56
  val step_prefix : string
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
    57
  val unrolled_prefix : string
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    58
  val ubfp_prefix : string
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    59
  val lbfp_prefix : string
35311
8f9a66fc9f80 improved Nitpick's support for quotient types
blanchet
parents: 35309
diff changeset
    60
  val quot_normal_prefix : string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    61
  val skolem_prefix : string
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    62
  val special_prefix : string
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    63
  val uncurry_prefix : string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    64
  val eval_prefix : string
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
    65
  val iter_var_prefix : string
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
    66
  val strip_first_name_sep : string -> string * string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    67
  val original_name : string -> string
37476
0681e46b4022 optimized code generated for datatype cases + more;
blanchet
parents: 37269
diff changeset
    68
  val abs_var : indexname * typ -> term -> term
34998
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
    69
  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
    70
  val s_disj : term * term -> term
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    71
  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
    72
  val conjuncts_of : term -> term list
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
    73
  val disjuncts_of : term -> term list
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
    74
  val unarize_unbox_etc_type : typ -> typ
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
    75
  val uniterize_unarize_unbox_etc_type : typ -> typ
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    76
  val string_for_type : Proof.context -> typ -> string
38188
7f12a03c513c better "Pretty" handling
blanchet
parents: 38180
diff changeset
    77
  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
    78
  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
    79
  val shortest_name : string -> string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    80
  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
    81
  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
    82
  val strict_type_match : theory -> typ * typ -> bool
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    83
  val type_match : theory -> typ * typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    84
  val const_match : theory -> styp * styp -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    85
  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
    86
  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
    87
  val is_TFree : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    88
  val is_fun_type : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    89
  val is_set_type : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    90
  val is_pair_type : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    91
  val is_lfp_iterator_type : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    92
  val is_gfp_iterator_type : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    93
  val is_fp_iterator_type : typ -> bool
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
    94
  val is_iterator_type : typ -> bool
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    95
  val is_boolean_type : typ -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    96
  val is_integer_type : typ -> bool
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
    97
  val is_bit_type : typ -> bool
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
    98
  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
    99
  val is_integer_like_type : typ -> bool
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   100
  val is_record_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
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   103
  val const_for_iterator_type : typ -> styp
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   104
  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
   105
  val nth_range_type : int -> typ -> typ
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   106
  val num_factors_in_type : typ -> int
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   107
  val num_binder_types : typ -> int
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   108
  val curried_binder_types : typ -> typ list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   109
  val mk_flat_tuple : typ -> term list -> term
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   110
  val dest_n_tuple : int -> term -> term list
33978
2380c1dac86e fix soundness bug in Nitpick's "destroy_constrs" optimization
blanchet
parents: 33968
diff changeset
   111
  val is_real_datatype : theory -> string -> 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
   112
  val is_standard_datatype : theory -> (typ option * bool) list -> typ -> bool
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
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   117
  val is_datatype : Proof.context -> (typ option * bool) list -> typ -> bool
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   118
  val is_record_constr : styp -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   119
  val is_record_get : theory -> styp -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   120
  val is_record_update : theory -> styp -> bool
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   121
  val is_abs_fun : Proof.context -> styp -> bool
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   122
  val is_rep_fun : Proof.context -> styp -> bool
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   123
  val is_quot_abs_fun : Proof.context -> styp -> bool
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   124
  val is_quot_rep_fun : Proof.context -> styp -> bool
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   125
  val mate_of_rep_fun : Proof.context -> styp -> styp
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   126
  val is_constr_like : Proof.context -> styp -> bool
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   127
  val is_constr : Proof.context -> (typ option * bool) list -> styp -> 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
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   133
  val discr_for_constr : styp -> styp
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
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   136
  val nth_sel_for_constr : styp -> int -> styp
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 :
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   138
    hol_context -> bool -> styp -> int -> styp
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
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   150
  val register_codatatype :
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   151
    typ -> string -> styp list -> morphism -> Context.generic -> Context.generic
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   152
  val register_codatatype_global :
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   153
    typ -> string -> styp list -> theory -> theory
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   154
  val unregister_codatatype :
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   155
    typ -> morphism -> Context.generic -> Context.generic
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   156
  val unregister_codatatype_global : typ -> theory -> theory
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   157
  val datatype_constrs : hol_context -> typ -> styp list
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   158
  val binarized_and_boxed_datatype_constrs :
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   159
    hol_context -> bool -> typ -> styp list
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   160
  val num_datatype_constrs : hol_context -> typ -> int
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   161
  val constr_name_for_sel_like : string -> string
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   162
  val binarized_and_boxed_constr_for_sel : hol_context -> bool -> styp -> styp
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
   163
  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
   164
  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
   165
  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
   166
    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
   167
  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
   168
  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
   169
  val is_small_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
   170
  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
   171
  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
   172
    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
   173
  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
   174
  val s_betapplys : typ list -> term * term list -> term
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   175
  val discriminate_value : hol_context -> styp -> 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
   176
  val select_nth_constr_arg :
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   177
    Proof.context -> (typ option * bool) list -> styp -> term -> int -> typ
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   178
    -> 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
   179
  val construct_value :
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   180
    Proof.context -> (typ option * bool) list -> styp -> 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
35335
f715cfde056a support local definitions in Nitpick
blanchet
parents: 35332
diff changeset
   184
  val all_axioms_of :
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   185
    Proof.context -> (term * term) list -> term list * term 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
   186
  val arity_of_built_in_const :
39359
6f49c7fbb1b1 remove "fast_descs" option from Nitpick;
blanchet
parents: 39345
diff changeset
   187
    theory -> (typ option * bool) list -> styp -> int option
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
   188
  val is_built_in_const :
39359
6f49c7fbb1b1 remove "fast_descs" option from Nitpick;
blanchet
parents: 39345
diff changeset
   189
    theory -> (typ option * bool) list -> styp -> bool
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   190
  val term_under_def : 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
   191
  val case_const_names :
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   192
    Proof.context -> (typ option * bool) list -> (string * int) list
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   193
  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
   194
  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
   195
    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
   196
    -> const_table * const_table
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   197
  val const_nondef_table : term list -> const_table
35335
f715cfde056a support local definitions in Nitpick
blanchet
parents: 35332
diff changeset
   198
  val const_simp_table : Proof.context -> (term * term) list -> const_table
f715cfde056a support local definitions in Nitpick
blanchet
parents: 35332
diff changeset
   199
  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
   200
  val const_choice_spec_table :
e4d1b5cbd429 added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents: 35743
diff changeset
   201
    Proof.context -> (term * term) list -> const_table
35335
f715cfde056a support local definitions in Nitpick
blanchet
parents: 35332
diff changeset
   202
  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
   203
    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
   204
    -> const_table
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   205
  val ground_theorem_table : theory -> term list Inttab.table
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   206
  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
   207
  val add_simps : const_table Unsynchronized.ref -> string -> term list -> unit
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   208
  val inverse_axioms_for_rep_fun : Proof.context -> styp -> term list
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   209
  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
   210
  val optimized_quot_type_axioms :
35311
8f9a66fc9f80 improved Nitpick's support for quotient types
blanchet
parents: 35309
diff changeset
   211
    Proof.context -> (typ option * bool) list -> string * typ list -> term list
41791
01d722707a36 always unfold constant defitions marked with "nitpick_def" -- to prevent unfolding, there's already "nitpick_simp"
blanchet
parents: 41472
diff changeset
   212
  val def_of_const : theory -> const_table * const_table -> styp -> term option
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   213
  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
   214
  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
   215
    theory -> const_table * const_table -> string * typ -> fixpoint_kind
38205
37a7272cb453 handle inductive predicates correctly after change in "def" semantics
blanchet
parents: 38204
diff changeset
   216
  val is_real_inductive_pred : hol_context -> styp -> bool
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   217
  val is_constr_pattern_lhs : Proof.context -> term -> bool
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   218
  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
   219
  val nondef_props_for_const :
e4d1b5cbd429 added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents: 35743
diff changeset
   220
    theory -> bool -> const_table -> styp -> term list
e4d1b5cbd429 added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents: 35743
diff changeset
   221
  val is_choice_spec_fun : hol_context -> styp -> bool
e4d1b5cbd429 added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents: 35743
diff changeset
   222
  val is_choice_spec_axiom : theory -> const_table -> term -> bool
38205
37a7272cb453 handle inductive predicates correctly after change in "def" semantics
blanchet
parents: 38204
diff changeset
   223
  val is_real_equational_fun : hol_context -> styp -> bool
38202
379fb08da97b prevent the expansion of too large definitions -- use equations for these instead
blanchet
parents: 38201
diff changeset
   224
  val is_equational_fun_but_no_plain_def : hol_context -> styp -> bool
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   225
  val codatatype_bisim_axioms : hol_context -> typ -> term list
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   226
  val is_well_founded_inductive_pred : hol_context -> styp -> bool
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   227
  val unrolled_inductive_pred_const : hol_context -> bool -> styp -> term
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   228
  val equational_fun_axioms : hol_context -> styp -> term list
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   229
  val is_equational_fun_surely_complete : hol_context -> styp -> 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
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   244
type special_fun = (styp * int list * term list) * styp
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   245
type unrolled = styp * styp
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   246
type wf_cache = (styp * (bool * bool)) list
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,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   253
   stds: (typ option * bool) list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   254
   wfs: (styp option * bool option) list,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   255
   user_axioms: bool option,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   256
   debug: bool,
38209
3d1d928dce50 added "whack"
blanchet
parents: 38208
diff changeset
   257
   whacks: term list,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   258
   binary_ints: bool option,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   259
   destroy_constrs: bool,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   260
   specialize: bool,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   261
   star_linear_preds: bool,
41803
ef13e3b7cbaf more work on "fix_datatype_vals" optimization (renamed "preconstruct")
blanchet
parents: 41795
diff changeset
   262
   preconstrs: (term option * bool option) list,
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   263
   tac_timeout: Time.time option,
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,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   268
   user_nondefs: term list,
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,
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   279
   constr_cache: (typ * styp 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
41472
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 41052
diff changeset
   285
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
   286
(
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   287
  type T = {frac_types: (string * (string * string) list) list,
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   288
            codatatypes: (string * (string * styp list)) list}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   289
  val empty = {frac_types = [], codatatypes = []}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   290
  val extend = I
33522
737589bb9bb8 adapted Theory_Data;
wenzelm
parents: 33351
diff changeset
   291
  fun merge ({frac_types = fs1, codatatypes = cs1},
36391
8f81c060cf12 cosmetics
blanchet
parents: 36390
diff changeset
   292
             {frac_types = fs2, codatatypes = cs2}) : T =
33699
f33b036ef318 permissive AList.merge -- most likely setup for theory data (beware of spurious AList.DUP);
wenzelm
parents: 33583
diff changeset
   293
    {frac_types = AList.merge (op =) (K true) (fs1, fs2),
41472
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 41052
diff changeset
   294
     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
   295
)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   296
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   297
val name_sep = "$"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   298
val numeral_prefix = nitpick_prefix ^ "num" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   299
val sel_prefix = nitpick_prefix ^ "sel"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   300
val discr_prefix = nitpick_prefix ^ "is" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   301
val set_prefix = nitpick_prefix ^ "set" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   302
val lfp_iterator_prefix = nitpick_prefix ^ "lfpit" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   303
val gfp_iterator_prefix = nitpick_prefix ^ "gfpit" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   304
val unrolled_prefix = nitpick_prefix ^ "unroll" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   305
val base_prefix = nitpick_prefix ^ "base" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   306
val step_prefix = nitpick_prefix ^ "step" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   307
val ubfp_prefix = nitpick_prefix ^ "ubfp" ^ name_sep
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   308
val lbfp_prefix = nitpick_prefix ^ "lbfp" ^ name_sep
35311
8f9a66fc9f80 improved Nitpick's support for quotient types
blanchet
parents: 35309
diff changeset
   309
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
   310
val skolem_prefix = nitpick_prefix ^ "sk"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   311
val special_prefix = nitpick_prefix ^ "sp"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   312
val uncurry_prefix = nitpick_prefix ^ "unc"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   313
val eval_prefix = nitpick_prefix ^ "eval"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   314
val iter_var_prefix = "i"
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   315
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   316
(** Constant/type information and term/type manipulation **)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   317
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   318
fun sel_prefix_for j = sel_prefix ^ string_of_int j ^ name_sep
35311
8f9a66fc9f80 improved Nitpick's support for quotient types
blanchet
parents: 35309
diff changeset
   319
fun quot_normal_name_for_type ctxt T =
8f9a66fc9f80 improved Nitpick's support for quotient types
blanchet
parents: 35309
diff changeset
   320
  quot_normal_prefix ^ unyxml (Syntax.string_of_typ ctxt T)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   321
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   322
val strip_first_name_sep =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   323
  Substring.full #> Substring.position name_sep ##> Substring.triml 1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   324
  #> pairself Substring.string
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   325
fun original_name s =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   326
  if String.isPrefix nitpick_prefix s then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   327
    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
   328
  else
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   329
    s
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   330
34998
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   331
fun s_conj (t1, @{const True}) = t1
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   332
  | s_conj (@{const True}, t2) = t2
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   333
  | s_conj (t1, t2) =
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   334
    if t1 = @{const False} orelse t2 = @{const False} then @{const False}
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   335
    else HOLogic.mk_conj (t1, t2)
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   336
fun s_disj (t1, @{const False}) = t1
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   337
  | s_disj (@{const False}, t2) = t2
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   338
  | s_disj (t1, t2) =
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   339
    if t1 = @{const True} orelse t2 = @{const True} then @{const True}
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   340
    else HOLogic.mk_disj (t1, t2)
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   341
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   342
fun strip_connective conn_t (t as (t0 $ t1 $ t2)) =
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   343
    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
   344
  | strip_connective _ t = [t]
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   345
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
   346
    if t0 = @{const HOL.conj} orelse t0 = @{const HOL.disj} then
34998
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   347
      (strip_connective t0 t, t0)
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   348
    else
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   349
      ([t], @{const Not})
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   350
  | 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
   351
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
   352
val disjuncts_of = strip_connective @{const HOL.disj}
34998
5e492a862b34 four changes to Nitpick:
blanchet
parents: 34982
diff changeset
   353
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   354
(* 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
   355
   "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
   356
   well. *)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   357
val built_in_consts =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   358
  [(@{const_name all}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   359
   (@{const_name "=="}, 2),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   360
   (@{const_name "==>"}, 2),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   361
   (@{const_name Pure.conjunction}, 2),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   362
   (@{const_name Trueprop}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   363
   (@{const_name Not}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   364
   (@{const_name False}, 0),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   365
   (@{const_name True}, 0),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   366
   (@{const_name All}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   367
   (@{const_name Ex}, 1),
38864
4abe644fcea5 formerly unnamed infix equality now named HOL.eq
haftmann
parents: 38795
diff changeset
   368
   (@{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
   369
   (@{const_name HOL.conj}, 2),
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   370
   (@{const_name HOL.disj}, 2),
38786
e46e7a9cb622 formerly unnamed infix impliciation now named HOL.implies
haftmann
parents: 38652
diff changeset
   371
   (@{const_name HOL.implies}, 2),
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   372
   (@{const_name If}, 3),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   373
   (@{const_name Let}, 2),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   374
   (@{const_name Pair}, 2),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   375
   (@{const_name fst}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   376
   (@{const_name snd}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   377
   (@{const_name Id}, 0),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   378
   (@{const_name converse}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   379
   (@{const_name trancl}, 1),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   380
   (@{const_name rel_comp}, 2),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   381
   (@{const_name finite}, 1),
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   382
   (@{const_name unknown}, 0),
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   383
   (@{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
   384
   (@{const_name safe_The}, 1),
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   385
   (@{const_name Frac}, 0),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   386
   (@{const_name norm_frac}, 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
   387
val built_in_nat_consts =
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   388
  [(@{const_name Suc}, 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
   389
   (@{const_name nat}, 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
   390
   (@{const_name nat_gcd}, 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
   391
   (@{const_name nat_lcm}, 0)]
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   392
val built_in_typed_consts =
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
   393
  [((@{const_name zero_class.zero}, 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
   394
   ((@{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
   395
   ((@{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
   396
   ((@{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
   397
   ((@{const_name times_class.times}, 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
   398
   ((@{const_name div_class.div}, 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
   399
   ((@{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
   400
   ((@{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
   401
   ((@{const_name ord_class.less_eq}, 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
   402
val built_in_typed_nat_consts =
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   403
  [((@{const_name zero_class.zero}, nat_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
   404
   ((@{const_name one_class.one}, nat_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
   405
   ((@{const_name plus_class.plus}, nat_T --> nat_T --> nat_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
   406
   ((@{const_name minus_class.minus}, nat_T --> nat_T --> nat_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
   407
   ((@{const_name times_class.times}, nat_T --> nat_T --> nat_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
   408
   ((@{const_name div_class.div}, nat_T --> nat_T --> nat_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
   409
   ((@{const_name ord_class.less}, nat_T --> nat_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
   410
   ((@{const_name ord_class.less_eq}, nat_T --> nat_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
   411
   ((@{const_name of_nat}, nat_T --> int_T), 0)]
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   412
val built_in_set_consts =
37476
0681e46b4022 optimized code generated for datatype cases + more;
blanchet
parents: 37269
diff changeset
   413
  [(@{const_name ord_class.less_eq}, 2)]
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   414
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   415
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
   416
  | 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
   417
  | 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
   418
  | unarize_type T = 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
   419
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
   420
    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
   421
  | 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
   422
    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
   423
  | 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
   424
  | 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
   425
  | unarize_unbox_etc_type (Type (s, Ts as _ :: _)) =
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   426
    Type (s, map unarize_unbox_etc_type Ts)
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   427
  | unarize_unbox_etc_type T = T
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   428
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
   429
  | uniterize_type @{typ bisim_iterator} = nat_T
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   430
  | uniterize_type T = T
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   431
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
   432
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   433
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
   434
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
   435
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   436
val prefix_name = Long_Name.qualify o Long_Name.base_name
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   437
fun shortest_name s = List.last (space_explode "." s) handle List.Empty => ""
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   438
val prefix_abs_vars = Term.map_abs_vars o prefix_name
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   439
fun short_name s =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   440
  case space_explode name_sep s of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   441
    [_] => 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
   442
  | ss => map shortest_name ss |> space_implode "_"
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   443
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
   444
    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
   445
  | shorten_names_in_type T = T
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   446
val shorten_names_in_term =
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   447
  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
   448
  #> map_types shorten_names_in_type
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   449
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   450
fun strict_type_match thy (T1, T2) =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   451
  (Sign.typ_match thy (T2, T1) Vartab.empty; true)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   452
  handle Type.TYPE_MATCH => false
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   453
fun type_match thy = strict_type_match thy o pairself unarize_unbox_etc_type
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   454
fun const_match thy ((s1, T1), (s2, T2)) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   455
  s1 = s2 andalso type_match thy (T1, T2)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   456
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
   457
  | 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
   458
    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
   459
  | term_match _ (t1, t2) = t1 aconv t2
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   460
35711
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   461
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
   462
  case snd (HOLogic.dest_number t1) of
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   463
    0 => HOLogic.mk_number T 0
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   464
  | 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
   465
            1 => HOLogic.mk_number T n1
548d3f16404b added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents: 35671
diff changeset
   466
          | 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
   467
                  $ 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
   468
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   469
fun is_TFree (TFree _) = true
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   470
  | is_TFree _ = false
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   471
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
   472
  | is_fun_type _ = false
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   473
fun is_set_type (Type (@{type_name fun}, [_, @{typ bool}])) = true
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   474
  | is_set_type _ = false
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   475
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
   476
  | is_pair_type _ = false
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   477
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
   478
  | is_lfp_iterator_type _ = false
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   479
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
   480
  | is_gfp_iterator_type _ = false
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   481
val is_fp_iterator_type = is_lfp_iterator_type orf is_gfp_iterator_type
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   482
fun is_iterator_type T =
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   483
  (T = @{typ bisim_iterator} orelse is_fp_iterator_type T)
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   484
fun is_boolean_type T = (T = prop_T orelse T = bool_T)
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
   485
fun is_integer_type T = (T = nat_T orelse T = int_T)
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
   486
fun is_bit_type T = (T = @{typ unsigned_bit} orelse T = @{typ signed_bit})
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
   487
fun is_word_type (Type (@{type_name word}, _)) = true
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34123
diff changeset
   488
  | is_word_type _ = false
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   489
val is_integer_like_type = is_iterator_type orf is_integer_type orf is_word_type
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   490
val is_record_type = not o null o Record.dest_recTs
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   491
fun is_frac_type ctxt (Type (s, [])) =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   492
    s |> AList.lookup (op =) (#frac_types (Data.get (Context.Proof ctxt)))
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   493
      |> these |> null |> not
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   494
  | is_frac_type _ _ = false
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   495
fun is_number_type ctxt = is_integer_like_type orf is_frac_type ctxt
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
   496
fun is_higher_order_type (Type (@{type_name fun}, _)) = 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
   497
  | 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
   498
  | is_higher_order_type _ = false
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   499
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   500
fun iterator_type_for_const gfp (s, T) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   501
  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
   502
        binder_types T)
35718
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   503
fun const_for_iterator_type (Type (s, Ts)) =
eee1a5e0d334 moved some Nitpick code around
blanchet
parents: 35711
diff changeset
   504
    (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
   505
  | const_for_iterator_type T =
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33202
diff changeset
   506
    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
   507
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   508
fun strip_n_binders 0 T = ([], T)
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   509
  | 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
   510
    strip_n_binders (n - 1) T2 |>> cons T1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   511
  | 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
   512
    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
   513
  | strip_n_binders _ T = raise TYPE ("Nitpick_HOL.strip_n_binders", [T], [])
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   514
val nth_range_type = snd oo strip_n_binders
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   515
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   516
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
   517
    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
   518
  | num_factors_in_type _ = 1
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   519
fun num_binder_types (Type (@{type_name fun}, [_, T2])) =
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   520
    1 + num_binder_types T2
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   521
  | num_binder_types _ = 0
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   522
val curried_binder_types = maps HOLogic.flatten_tupleT o binder_types
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   523
fun maybe_curried_binder_types T =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   524
  (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
   525
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   526
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
   527
  | 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
   528
    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
   529
  | mk_flat_tuple T ts = raise TYPE ("Nitpick_HOL.mk_flat_tuple", [T], ts)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   530
fun dest_n_tuple 1 t = [t]
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   531
  | 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
   532
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
   533
type typedef_info =
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   534
  {rep_type: typ, abs_type: typ, Rep_name: string, Abs_name: string,
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   535
   set_def: thm option, prop_of_Rep: thm, set_name: string,
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   536
   Abs_inverse: thm option, Rep_inverse: thm option}
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   537
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   538
fun typedef_info ctxt s =
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   539
  if is_frac_type ctxt (Type (s, [])) then
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   540
    SOME {abs_type = Type (s, []), rep_type = @{typ "int * int"},
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   541
          Abs_name = @{const_name Abs_Frac}, Rep_name = @{const_name Rep_Frac},
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   542
          set_def = NONE, prop_of_Rep = @{prop "Rep_Frac x \<in> Frac"}
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   543
                          |> Logic.varify_global,
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   544
          set_name = @{const_name Frac}, Abs_inverse = NONE, Rep_inverse = NONE}
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   545
  else case Typedef.get_info ctxt s of
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   546
    (* 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
   547
       we take (according to Florian Haftmann). *)
39315
27f7b7748425 always handle type variables in typedefs as global
blanchet
parents: 38864
diff changeset
   548
    (* 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
   549
       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
   550
       Remove these calls once "Typedef" is fully localized. *)
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   551
    ({abs_type, rep_type, Abs_name, Rep_name, ...},
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   552
     {set_def, Rep, Abs_inverse, Rep_inverse, ...}) :: _ =>
39315
27f7b7748425 always handle type variables in typedefs as global
blanchet
parents: 38864
diff changeset
   553
    SOME {abs_type = Logic.varifyT_global abs_type,
27f7b7748425 always handle type variables in typedefs as global
blanchet
parents: 38864
diff changeset
   554
          rep_type = Logic.varifyT_global rep_type, Abs_name = Abs_name,
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   555
          Rep_name = Rep_name, set_def = set_def, prop_of_Rep = prop_of Rep,
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   556
          set_name = set_prefix ^ s, Abs_inverse = SOME Abs_inverse,
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   557
          Rep_inverse = SOME Rep_inverse}
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   558
  | _ => 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
   559
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   560
val is_typedef = is_some oo typedef_info
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   561
val is_real_datatype = is_some oo Datatype.get_info
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   562
fun is_standard_datatype thy = the oo triple_lookup (type_match thy)
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
   563
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   564
(* FIXME: Use antiquotation for "code_numeral" below or detect "rep_datatype",
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   565
   e.g., by adding a field to "Datatype_Aux.info". *)
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
   566
fun is_basic_datatype thy stds s =
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   567
  member (op =) [@{type_name prod}, @{type_name bool}, @{type_name int},
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   568
                 "Code_Numeral.code_numeral"] s orelse
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
   569
  (s = @{type_name nat} andalso is_standard_datatype thy stds nat_T)
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   570
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   571
(* TODO: use "Term_Subst.instantiateT" instead? *)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   572
fun instantiate_type thy T1 T1' T2 =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   573
  Same.commit (Envir.subst_type_same
35311
8f9a66fc9f80 improved Nitpick's support for quotient types
blanchet
parents: 35309
diff changeset
   574
                   (Sign.typ_match thy (T1, T1') Vartab.empty)) T2
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   575
  handle Type.TYPE_MATCH =>
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33202
diff changeset
   576
         raise TYPE ("Nitpick_HOL.instantiate_type", [T1, T1'], [])
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   577
fun varify_and_instantiate_type ctxt T1 T1' T2 =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   578
  let val thy = ProofContext.theory_of ctxt in
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   579
    instantiate_type thy (varify_type ctxt T1) T1' (varify_type ctxt T2)
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   580
  end
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   581
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   582
fun repair_constr_type ctxt body_T' T =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   583
  varify_and_instantiate_type ctxt (body_type T) body_T' T
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   584
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   585
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
   586
  let
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   587
    val {frac_types, codatatypes} = Data.get generic
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   588
    val frac_types = AList.update (op =) (frac_s, ersaetze) frac_types
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   589
  in Data.put {frac_types = frac_types, codatatypes = codatatypes} generic end
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   590
(* TODO: Consider morphism. *)
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   591
fun register_frac_type frac_s ersaetze (_ : morphism) =
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   592
  register_frac_type_generic frac_s ersaetze
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   593
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
   594
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   595
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
   596
(* TODO: Consider morphism. *)
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   597
fun unregister_frac_type frac_s (_ : morphism) =
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   598
  unregister_frac_type_generic frac_s
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   599
val unregister_frac_type_global =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   600
  Context.theory_map o unregister_frac_type_generic
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   601
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   602
fun register_codatatype_generic co_T case_name constr_xs generic =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   603
  let
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   604
    val ctxt = Context.proof_of generic
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   605
    val thy = Context.theory_of generic
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   606
    val {frac_types, codatatypes} = Data.get generic
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   607
    val constr_xs = map (apsnd (repair_constr_type ctxt co_T)) constr_xs
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   608
    val (co_s, co_Ts) = dest_Type co_T
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   609
    val _ =
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   610
      if forall is_TFree co_Ts andalso not (has_duplicates (op =) co_Ts) andalso
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   611
         co_s <> @{type_name fun} andalso
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
   612
         not (is_basic_datatype thy [(NONE, true)] co_s) then
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   613
        ()
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   614
      else
38242
f26d590dce0f adapt occurrences of renamed Nitpick functions
blanchet
parents: 38240
diff changeset
   615
        raise TYPE ("Nitpick_HOL.register_codatatype_generic", [co_T], [])
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   616
    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
   617
                                   codatatypes
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   618
  in Data.put {frac_types = frac_types, codatatypes = codatatypes} generic end
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   619
(* TODO: Consider morphism. *)
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   620
fun register_codatatype co_T case_name constr_xs (_ : morphism) =
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   621
  register_codatatype_generic co_T case_name constr_xs
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   622
val register_codatatype_global =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   623
  Context.theory_map ooo register_codatatype_generic
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   624
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   625
fun unregister_codatatype_generic co_T = register_codatatype_generic co_T "" []
38284
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   626
(* TODO: Consider morphism. *)
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   627
fun unregister_codatatype co_T (_ : morphism) =
9f98107ad8b4 use "declaration" instead of "setup" to register Nitpick extensions
blanchet
parents: 38282
diff changeset
   628
  unregister_codatatype_generic co_T
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   629
val unregister_codatatype_global =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   630
  Context.theory_map o unregister_codatatype_generic
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   631
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   632
fun is_codatatype ctxt (Type (s, _)) =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   633
    s |> AList.lookup (op =) (#codatatypes (Data.get (Context.Proof ctxt)))
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   634
      |> Option.map snd |> these |> null |> not
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   635
  | is_codatatype _ _ = false
38215
1c7d7eaebdf2 quotient types registered as codatatypes are no longer quotient types
blanchet
parents: 38212
diff changeset
   636
fun is_real_quot_type thy (Type (s, _)) =
1c7d7eaebdf2 quotient types registered as codatatypes are no longer quotient types
blanchet
parents: 38212
diff changeset
   637
    is_some (Quotient_Info.quotdata_lookup_raw thy s)
1c7d7eaebdf2 quotient types registered as codatatypes are no longer quotient types
blanchet
parents: 38212
diff changeset
   638
  | is_real_quot_type _ _ = false
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   639
fun is_quot_type ctxt T =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   640
  let val thy = ProofContext.theory_of ctxt in
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   641
    is_real_quot_type thy T andalso not (is_codatatype ctxt T)
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   642
  end
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   643
fun is_pure_typedef ctxt (T as Type (s, _)) =
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   644
    let val thy = ProofContext.theory_of ctxt in
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   645
      is_typedef ctxt s andalso
38215
1c7d7eaebdf2 quotient types registered as codatatypes are no longer quotient types
blanchet
parents: 38212
diff changeset
   646
      not (is_real_datatype thy s orelse is_real_quot_type thy T orelse
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   647
           is_codatatype ctxt T orelse is_record_type T orelse
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   648
           is_integer_like_type T)
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   649
    end
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   650
  | is_pure_typedef _ _ = false
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   651
fun is_univ_typedef ctxt (Type (s, _)) =
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   652
    (case typedef_info ctxt s of
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   653
       SOME {set_def, prop_of_Rep, ...} =>
35332
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   654
       let
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   655
         val t_opt =
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   656
           case set_def of
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   657
             SOME thm => try (snd o Logic.dest_equals o prop_of) thm
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   658
           | NONE => try (snd o HOLogic.dest_mem o HOLogic.dest_Trueprop)
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   659
                         prop_of_Rep
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   660
       in
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   661
         case t_opt of
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   662
           SOME (Const (@{const_name top}, _)) => true
35386
45a4e19d3ebd more work on the new monotonicity stuff in Nitpick
blanchet
parents: 35385
diff changeset
   663
           (* "Multiset.multiset" *)
35332
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   664
         | SOME (Const (@{const_name Collect}, _)
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   665
                 $ Abs (_, _, Const (@{const_name finite}, _) $ _)) => true
35386
45a4e19d3ebd more work on the new monotonicity stuff in Nitpick
blanchet
parents: 35385
diff changeset
   666
           (* "FinFun.finfun" *)
45a4e19d3ebd more work on the new monotonicity stuff in Nitpick
blanchet
parents: 35385
diff changeset
   667
         | SOME (Const (@{const_name Collect}, _) $ Abs (_, _,
45a4e19d3ebd more work on the new monotonicity stuff in Nitpick
blanchet
parents: 35385
diff changeset
   668
                     Const (@{const_name Ex}, _) $ Abs (_, _,
45a4e19d3ebd more work on the new monotonicity stuff in Nitpick
blanchet
parents: 35385
diff changeset
   669
                         Const (@{const_name finite}, _) $ _))) => true
35332
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   670
         | _ => false
22442ab3e7a3 optimized multisets in Nitpick by fishing "finite"
blanchet
parents: 35311
diff changeset
   671
       end
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   672
     | NONE => false)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   673
  | is_univ_typedef _ _ = false
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   674
fun is_datatype ctxt stds (T as Type (s, _)) =
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   675
    let val thy = ProofContext.theory_of ctxt in
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   676
      (is_typedef ctxt s orelse is_codatatype ctxt T orelse
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   677
       T = @{typ ind} orelse is_real_quot_type thy T) andalso
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   678
      not (is_basic_datatype thy stds s)
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   679
    end
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
   680
  | is_datatype _ _ _ = false
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   681
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   682
fun all_record_fields thy T =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   683
  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
   684
    recs @ more :: all_record_fields thy (snd more)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   685
  end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   686
  handle TYPE _ => []
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   687
fun is_record_constr (s, T) =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   688
  String.isSuffix Record.extN s andalso
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   689
  let val dataT = body_type T in
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   690
    is_record_type dataT andalso
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   691
    s = unsuffix Record.ext_typeN (fst (dest_Type dataT)) ^ Record.extN
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   692
  end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   693
val num_record_fields = Integer.add 1 o length o fst oo Record.get_extT_fields
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   694
fun no_of_record_field thy s T1 =
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   695
  find_index (curry (op =) s o fst)
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   696
             (Record.get_extT_fields thy T1 ||> single |> op @)
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   697
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
   698
    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
   699
  | is_record_get _ _ = false
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   700
fun is_record_update thy (s, T) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   701
  String.isSuffix Record.updateN s andalso
34121
5e831d805118 get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents: 33978
diff changeset
   702
  exists (curry (op =) (unsuffix Record.updateN s) o fst)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   703
         (all_record_fields thy (body_type T))
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   704
  handle TYPE _ => false
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   705
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
   706
    (case typedef_info ctxt s' of
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   707
       SOME {Abs_name, ...} => s = Abs_name
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   708
     | NONE => false)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   709
  | is_abs_fun _ _ = false
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   710
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
   711
    (case typedef_info ctxt s' of
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   712
       SOME {Rep_name, ...} => s = Rep_name
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   713
     | NONE => false)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   714
  | is_rep_fun _ _ = false
38215
1c7d7eaebdf2 quotient types registered as codatatypes are no longer quotient types
blanchet
parents: 38212
diff changeset
   715
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
   716
                                         [_, abs_T as Type (s', _)]))) =
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   717
    try (Quotient_Term.absrep_const_chk Quotient_Term.AbsF ctxt) s'
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   718
    = SOME (Const x) andalso not (is_codatatype ctxt abs_T)
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   719
  | is_quot_abs_fun _ _ = false
38215
1c7d7eaebdf2 quotient types registered as codatatypes are no longer quotient types
blanchet
parents: 38212
diff changeset
   720
fun is_quot_rep_fun ctxt (x as (_, Type (@{type_name fun},
1c7d7eaebdf2 quotient types registered as codatatypes are no longer quotient types
blanchet
parents: 38212
diff changeset
   721
                                         [abs_T as Type (s', _), _]))) =
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   722
    try (Quotient_Term.absrep_const_chk Quotient_Term.RepF ctxt) s'
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   723
    = SOME (Const x) andalso not (is_codatatype ctxt abs_T)
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   724
  | is_quot_rep_fun _ _ = false
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   725
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   726
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
   727
                                         [T1 as Type (s', _), T2]))) =
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   728
    (case typedef_info ctxt s' of
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   729
       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
   730
     | 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
   731
  | mate_of_rep_fun _ x = raise TERM ("Nitpick_HOL.mate_of_rep_fun", [Const x])
35284
9edc2bd6d2bd enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents: 35283
diff changeset
   732
fun rep_type_for_quot_type thy (T as Type (s, _)) =
39345
062c10ff848c remove unreferenced identifiers
blanchet
parents: 39315
diff changeset
   733
    let val {qtyp, rtyp, ...} = Quotient_Info.quotdata_lookup thy s in
062c10ff848c remove unreferenced identifiers
blanchet
parents: 39315
diff changeset
   734
      instantiate_type thy qtyp T rtyp
062c10ff848c remove unreferenced identifiers
blanchet
parents: 39315
diff changeset
   735
    end
062c10ff848c remove unreferenced identifiers
blanchet
parents: 39315
diff changeset
   736
  | rep_type_for_quot_type _ T =
062c10ff848c remove unreferenced identifiers
blanchet
parents: 39315
diff changeset
   737
    raise TYPE ("Nitpick_HOL.rep_type_for_quot_type", [T], [])
35284
9edc2bd6d2bd enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents: 35283
diff changeset
   738
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
   739
    let
38243
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   740
      val {qtyp, equiv_rel, equiv_thm, ...} =
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   741
        Quotient_Info.quotdata_lookup thy s
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   742
      val partial =
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   743
        case prop_of equiv_thm of
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   744
          @{const Trueprop} $ (Const (@{const_name equivp}, _) $ _) => false
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   745
        | @{const Trueprop} $ (Const (@{const_name part_equivp}, _) $ _) => true
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   746
        | _ => raise NOT_SUPPORTED "Ill-formed quotient type equivalence \
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   747
                                   \relation theorem"
35284
9edc2bd6d2bd enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents: 35283
diff changeset
   748
      val Ts' = qtyp |> dest_Type |> snd
38243
f41865450450 added support for partial quotient types;
blanchet
parents: 38242
diff changeset
   749
    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
   750
  | equiv_relation_for_quot_type _ T =
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   751
    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
   752
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   753
fun is_coconstr ctxt (s, T) =
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   754
  case body_type T of
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   755
    co_T as Type (co_s, _) =>
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   756
    let val {codatatypes, ...} = Data.get (Context.Proof ctxt) in
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   757
      exists (fn (s', T') => s = s' andalso repair_constr_type ctxt co_T T' = T)
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   758
             (AList.lookup (op =) codatatypes co_s |> Option.map snd |> these)
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   759
    end
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   760
  | _ => false
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   761
fun is_constr_like 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
   762
  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
   763
                 @{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
   764
                 @{const_name Suc_Rep}] s orelse
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   765
  let
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   766
    val thy = ProofContext.theory_of ctxt
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   767
    val (x as (_, T)) = (s, unarize_unbox_etc_type T)
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   768
  in
37260
dde817e6dfb1 added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents: 37258
diff changeset
   769
    is_real_constr thy x orelse is_record_constr x orelse
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   770
    (is_abs_fun ctxt x andalso is_pure_typedef ctxt (range_type T)) orelse
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   771
    is_coconstr ctxt x
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   772
  end
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   773
fun is_stale_constr ctxt (x as (_, T)) =
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   774
  is_codatatype ctxt (body_type T) andalso is_constr_like ctxt x andalso
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   775
  not (is_coconstr ctxt x)
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   776
fun is_constr ctxt stds (x as (_, T)) =
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   777
  let val thy = ProofContext.theory_of ctxt in
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   778
    is_constr_like ctxt x andalso
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   779
    not (is_basic_datatype thy stds
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
   780
                         (fst (dest_Type (unarize_type (body_type T))))) andalso
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   781
    not (is_stale_constr ctxt x)
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   782
  end
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   783
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
   784
val is_sel_like_and_no_discr =
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   785
  String.isPrefix sel_prefix orf
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   786
  (member (op =) [@{const_name fst}, @{const_name snd}])
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   787
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   788
fun in_fun_lhs_for InConstr = InSel
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   789
  | in_fun_lhs_for _ = InFunLHS
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   790
fun in_fun_rhs_for InConstr = InConstr
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   791
  | in_fun_rhs_for InSel = InSel
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   792
  | in_fun_rhs_for InFunRHS1 = InFunRHS2
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   793
  | in_fun_rhs_for _ = InFunRHS1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   794
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   795
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
   796
  case T of
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   797
    Type (@{type_name fun}, _) =>
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   798
    (boxy = InPair orelse boxy = InFunLHS) andalso
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   799
    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
   800
  | Type (@{type_name prod}, Ts) =>
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   801
    boxy = InPair orelse boxy = InFunRHS1 orelse boxy = InFunRHS2 orelse
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   802
    ((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
   803
     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
   804
            (map (box_type hol_ctxt InPair) Ts))
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   805
  | _ => false
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   806
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
   807
  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
   808
    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
   809
  | _ => 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
   810
and box_type hol_ctxt boxy T =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   811
  case T of
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   812
    Type (z as (@{type_name fun}, [T1, T2])) =>
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   813
    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
   814
       should_box_type hol_ctxt boxy z then
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   815
      Type (@{type_name fun_box},
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   816
            [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
   817
    else
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
   818
      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
   819
      --> 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
   820
  | 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
   821
    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
   822
       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
   823
      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
   824
    else
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
   825
      Type (@{type_name prod},
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
   826
            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
   827
                          (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
   828
                           else InPair)) Ts)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   829
  | _ => T
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   830
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   831
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
   832
  | 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
   833
  | 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
   834
    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
   835
  | 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
   836
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
   837
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   838
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
   839
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   840
fun num_sels_for_constr_type T = length (maybe_curried_binder_types T)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   841
fun nth_sel_name_for_constr_name s n =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   842
  if s = @{const_name Pair} then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   843
    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
   844
  else
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   845
    sel_prefix_for n ^ s
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   846
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
   847
  | nth_sel_for_constr (s, T) n =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   848
    (nth_sel_name_for_constr_name s n,
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   849
     body_type T --> nth (maybe_curried_binder_types T) n)
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   850
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
   851
  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
   852
  oo nth_sel_for_constr
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   853
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   854
fun sel_no_from_name s =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   855
  if String.isPrefix discr_prefix s then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   856
    ~1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   857
  else if String.isPrefix sel_prefix s then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   858
    s |> unprefix sel_prefix |> Int.fromString |> the
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   859
  else if s = @{const_name snd} then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   860
    1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   861
  else
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   862
    0
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   863
35078
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   864
val close_form =
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   865
  let
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   866
    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
   867
      fold (fn (z as ((s, _), T)) => fn t' =>
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   868
               Term.all T $ Abs (s, T, abstract_over (Var z, t')))
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   869
           (take (length zs' - length zs) zs')
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   870
    fun aux zs (@{const "==>"} $ t1 $ t2) =
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   871
        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
   872
          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
   873
        end
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   874
      | 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
   875
  in aux [] end
6fd1052fe463 optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents: 35075
diff changeset
   876
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   877
fun distinctness_formula T =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   878
  all_distinct_unordered_pairs_of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   879
  #> 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
   880
  #> List.foldr (s_conj o swap) @{const True}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   881
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
   882
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
   883
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
   884
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   885
fun uncached_datatype_constrs ({thy, ctxt, stds, ...} : hol_context)
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
   886
                              (T as Type (s, Ts)) =
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   887
    (case AList.lookup (op =) (#codatatypes (Data.get (Context.Proof ctxt)))
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   888
                       s of
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   889
       SOME (_, xs' as (_ :: _)) => map (apsnd (repair_constr_type ctxt T)) xs'
33581
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   890
     | _ =>
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   891
       if is_datatype ctxt stds T then
33581
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   892
         case Datatype.get_info thy s of
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   893
           SOME {index, descr, ...} =>
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   894
           let
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   895
             val (_, dtyps, constrs) = AList.lookup (op =) descr index |> the
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   896
           in
37260
dde817e6dfb1 added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents: 37258
diff changeset
   897
             map (apsnd (fn Us =>
dde817e6dfb1 added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents: 37258
diff changeset
   898
                            map (typ_of_dtyp descr (dtyps ~~ Ts)) Us ---> T))
dde817e6dfb1 added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents: 37258
diff changeset
   899
                 constrs
33581
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   900
           end
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   901
         | NONE =>
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   902
           if is_record_type T then
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   903
             let
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   904
               val s' = unsuffix Record.ext_typeN s ^ Record.extN
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   905
               val T' = (Record.get_extT_fields thy T
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   906
                        |> apsnd single |> uncurry append |> map snd) ---> T
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   907
             in [(s', T')] end
38215
1c7d7eaebdf2 quotient types registered as codatatypes are no longer quotient types
blanchet
parents: 38212
diff changeset
   908
           else if is_real_quot_type thy T then
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
   909
             [(@{const_name Quot}, rep_type_for_quot_type thy T --> T)]
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
   910
           else case typedef_info ctxt s of
33581
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   911
             SOME {abs_type, rep_type, Abs_name, ...} =>
35311
8f9a66fc9f80 improved Nitpick's support for quotient types
blanchet
parents: 35309
diff changeset
   912
             [(Abs_name,
38240
a44d108a8d39 local versions of Nitpick.register_xxx functions
blanchet
parents: 38215
diff changeset
   913
               varify_and_instantiate_type ctxt abs_type T rep_type --> T)]
33581
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   914
           | NONE =>
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   915
             if T = @{typ ind} then
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   916
               [dest_Const @{const Zero_Rep}, dest_Const @{const Suc_Rep}]
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   917
             else
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   918
               []
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   919
       else
e1e77265fb1d added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents: 33580
diff changeset
   920
         [])
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
   921
  | uncached_datatype_constrs _ _ = []
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
   922
fun datatype_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
   923
  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
   924
    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
   925
  | 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
   926
    let val xs = uncached_datatype_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
   927
      (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
   928
    end
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   929
fun binarized_and_boxed_datatype_constrs hol_ctxt binarize =
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   930
  map (apsnd ((binarize ? 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
   931
              o box_type hol_ctxt InConstr)) o datatype_constrs hol_ctxt
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   932
val num_datatype_constrs = length oo datatype_constrs
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   933
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   934
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
   935
  | 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
   936
  | constr_name_for_sel_like s' = original_name s'
35190
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   937
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
   938
  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
   939
    AList.lookup (op =)
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   940
        (binarized_and_boxed_datatype_constrs hol_ctxt binarize (domain_type T'))
ce653cc27a94 make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents: 35181
diff changeset
   941
        s
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   942
    |> the |> pair s
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   943
  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
   944
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
   945
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
   946
    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
   947
  | 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
   948
    card_of_type assigns T1 * card_of_type 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
   949
  | 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
   950
  | 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
   951
  | 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
   952
  | 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
   953
    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
   954
      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
   955
    | 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
   956
              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
   957
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
   958
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
   959
                         (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
   960
    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
   961
      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
   962
      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
   963
    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
   964
      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
   965
      else Int.min (max, reasonable_power k2 k1)
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
   966
    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
   967
  | 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
   968
                         (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
   969
    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
   970
      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
   971
      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
   972
    in if k1 = max orelse k2 = max then max else Int.min (max, k1 * k2) 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
   973
  | 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
   974
    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
   975
                    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
   976
                  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
   977
                    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
   978
                    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
   979
                           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
   980
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
   981
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
   982
                               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
   983
  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
   984
    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
   985
      (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
   986
         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
   987
       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
   988
         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
   989
       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
   990
         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
   991
         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
   992
           val k1 = aux avoid 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
   993
           val k2 = aux avoid 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
   994
         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
   995
           if k1 = 0 orelse k2 = 0 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
   996
           else 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
   997
           else Int.min (max, reasonable_power k2 k1)
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
   998
         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
   999
       | 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
  1000
         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
  1001
           val k1 = aux avoid 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
  1002
           val k2 = aux avoid 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
  1003
         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
  1004
           if k1 = 0 orelse k2 = 0 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
  1005
           else 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
  1006
           else Int.min (max, k1 * k2)
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
  1007
         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
  1008
       | 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
  1009
       | @{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
  1010
       | @{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
  1011
       | 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
  1012
         (case datatype_constrs hol_ctxt 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
  1013
            [] => 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
  1014
                  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
  1015
          | 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
  1016
            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
  1017
              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
  1018
                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
  1019
                    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
  1020
            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
  1021
              if exists (curry (op =) 0) constr_cards 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
  1022
              else Integer.sum 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
  1023
            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
  1024
       | _ => 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
  1025
      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
  1026
             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
  1027
  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
  1028
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
val typical_atomic_card = 4
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
val typical_card_of_type = bounded_card_of_type 65536 typical_atomic_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
  1031
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
val small_type_max_card = 5
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
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
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
  1035
  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
  1036
fun is_small_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
  1037
  let val n = bounded_exact_card_of_type hol_ctxt [] 1 2 [] 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
  1038
    n > 0 andalso n <= small_type_max_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
  1039
  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
  1040
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
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
  1042
  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
  1043
    [] => 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
  1044
  | 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
  1045
    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
  1046
      val bad_Ts_cost = fold (Integer.max o typical_card_of_type) bad_Ts 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
  1047
      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
  1048
    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
  1049
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
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
  1051
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
  1052
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
  1053
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
  1054
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
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
  1056
  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
  1057
     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
  1058
    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
  1059
  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
  1060
    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
  1061
      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
  1062
      $ 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
  1063
    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
  1064
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
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
  1066
  | 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
  1067
    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
  1068
  | 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
  1069
  | 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
  1070
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
fun s_betapply _ (Const (@{const_name If}, _) $ @{const True} $ t1', _) = 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
  1072
  | 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
  1073
  | 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
  1074
                          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
  1075
                   $ 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
  1076
    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
  1077
      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
  1078
      $ 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
  1079
    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
  1080
  | 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
  1081
    (s_let Ts s1 (loose_bvar1_count (t1', 0)) T1 (fastype_of1 (T1 :: Ts, 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
  1082
              (curry betapply 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
  1083
     handle TERM _ => betapply (t1, t2)) (* FIXME: fix all uses *)
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
  1084
  | s_betapply _ (t1, t2) = 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
  1085
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
  1086
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
  1087
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
  1088
  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
  1089
    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
  1090
      | 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
  1091
      | 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
  1092
        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
  1093
      | 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
  1094
        ((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
  1095
           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
  1096
         | 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
  1097
        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
  1098
      | 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
  1099
  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
  1100
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
  1101
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
  1102
  let val dataT = body_type T in
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1103
    if s = @{const_name Suc} then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1104
      Abs (Name.uu, dataT,
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1105
           @{const Not} $ HOLogic.mk_eq (zero_const dataT, Bound 0))
35070
96136eb6218f split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents: 34998
diff changeset
  1106
    else if num_datatype_constrs hol_ctxt dataT >= 2 then
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1107
      Const (discr_for_constr x)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1108
    else
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1109
      Abs (Name.uu, dataT, @{const True})
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1110
  end
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1111
fun discriminate_value (hol_ctxt as {ctxt, ...}) x t =
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
  1112
  case head_of t of
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
  1113
    Const x' =>
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1114
    if x = x' then @{const True}
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1115
    else if is_constr_like ctxt x' then @{const False}
37476
0681e46b4022 optimized code generated for datatype cases + more;
blanchet
parents: 37269
diff changeset
  1116
    else s_betapply [] (discr_term_for_constr hol_ctxt x, t)
0681e46b4022 optimized code generated for datatype cases + more;
blanchet
parents: 37269
diff changeset
  1117
  | _ => s_betapply [] (discr_term_for_constr hol_ctxt x, t)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1118
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
  1119
fun nth_arg_sel_term_for_constr thy stds (x as (s, T)) n =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1120
  let val (arg_Ts, dataT) = strip_type T in
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
  1121
    if dataT = nat_T andalso is_standard_datatype thy stds nat_T then
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 35190
diff changeset
  1122
      @{term "%n::nat. n - 1"}
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1123
    else if is_pair_type dataT then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1124
      Const (nth_sel_for_constr x n)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1125
    else
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1126
      let
38190
b02e204b613a get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents: 38188
diff changeset
  1127
        fun aux m (Type (@{type_name prod}, [T1, T2])) =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1128
            let
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1129
              val (m, t1) = aux m T1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1130
              val (m, t2) = aux m T2
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1131
            in (m, HOLogic.mk_prod (t1, t2)) end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1132
          | aux m T =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1133
            (m + 1, Const (nth_sel_name_for_constr_name s m, dataT --> T)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1134
                    $ Bound 0)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1135
        val m = fold (Integer.add o num_factors_in_type)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1136
                     (List.take (arg_Ts, n)) 0
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1137
      in Abs ("x", dataT, aux m (nth arg_Ts n) |> snd) end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1138
  end
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1139
fun select_nth_constr_arg ctxt stds x t n res_T =
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1140
  let val thy = ProofContext.theory_of ctxt in
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1141
    (case strip_comb t of
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1142
       (Const x', args) =>
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1143
       if x = x' then nth args n
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1144
       else if is_constr_like ctxt x' then Const (@{const_name unknown}, res_T)
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1145
       else raise SAME ()
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1146
     | _ => raise SAME())
37476
0681e46b4022 optimized code generated for datatype cases + more;
blanchet
parents: 37269
diff changeset
  1147
    handle SAME () =>
0681e46b4022 optimized code generated for datatype cases + more;
blanchet
parents: 37269
diff changeset
  1148
           s_betapply [] (nth_arg_sel_term_for_constr thy stds x n, t)
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1149
  end
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1150
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
  1151
fun construct_value _ _ x [] = Const x
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1152
  | construct_value ctxt stds (x as (s, _)) args =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1153
    let val args = map Envir.eta_contract args in
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1154
      case hd args of
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
  1155
        Const (s', _) $ t =>
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
  1156
        if is_sel_like_and_no_discr s' andalso
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
  1157
           constr_name_for_sel_like s' = s andalso
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
  1158
           forall (fn (n, t') =>
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1159
                      select_nth_constr_arg ctxt stds x t n dummyT = t')
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34126
diff changeset
  1160
                  (index_seq 0 (length args) ~~ args) then
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1161
          t
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1162
        else
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1163
          list_comb (Const x, args)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1164
      | _ => list_comb (Const x, args)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1165
    end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
  1166
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1167
fun constr_expand (hol_ctxt as {ctxt, stds, ...}) T t =
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1168
  (case head_of t of
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1169
     Const x => if is_constr_like ctxt x then t else raise SAME ()
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1170
   | _ => raise SAME ())
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1171
  handle SAME () =>
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1172
         let
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1173
           val x' as (_, T') =
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1174
             if is_pair_type T then
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1175
               let val (T1, T2) = HOLogic.dest_prodT T in
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1176
                 (@{const_name Pair}, T1 --> T2 --> T)
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1177
               end
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1178
             else
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1179
               datatype_constrs hol_ctxt T |> hd
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1180
           val arg_Ts = binder_types T'
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1181
         in
37256
0dca1ec52999 thread along context instead of theory for typedef lookup
blanchet
parents: 37253
diff changeset
  1182
           list_comb (Const x', map2 (select_nth_constr_arg ctxt stds x' t)
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1183
                                     (index_seq 0 (length arg_Ts)) arg_Ts)
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1184
         end
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1185
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1186
fun coerce_bound_no f j t =
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1187
  case t of
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1188
    t1 $ t2 => coerce_bound_no f j t1 $ coerce_bound_no f j t2
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1189
  | Abs (s, T, t') => Abs (s, T, coerce_bound_no f (j + 1) t')
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1190
  | Bound j' => if j' = j then f t else t
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1191
  | _ => t
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1192
fun coerce_bound_0_in_term hol_ctxt new_T old_T =
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1193
  old_T <> new_T ? coerce_bound_no (coerce_term hol_ctxt [new_T] old_T new_T) 0
39345
062c10ff848c remove unreferenced identifiers
blanchet
parents: 39315
diff changeset
  1194
and coerce_term (hol_ctxt as {ctxt, stds, ...}) Ts new_T old_T t =
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35625
diff changeset
  1195
  if old_T = new_T then
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive