author | blanchet |
Tue, 01 Jun 2010 10:31:18 +0200 | |
changeset 37256 | 0dca1ec52999 |
parent 37253 | e01c1fe245cd |
child 37258 | 40bebf3d6cc0 |
permissions | -rw-r--r-- |
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 | 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 | 4 |
|
5 |
Auxiliary HOL-related functions used by Nitpick. |
|
6 |
*) |
|
7 |
||
8 |
signature NITPICK_HOL = |
|
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 | 11 |
type const_table = term list Symtab.table |
12 |
type special_fun = (styp * int list * term list) * styp |
|
13 |
type unrolled = styp * styp |
|
14 |
type wf_cache = (styp * (bool * bool)) list |
|
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, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
25 |
binary_ints: bool option, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
26 |
destroy_constrs: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
27 |
specialize: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
28 |
star_linear_preds: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
29 |
fast_descrs: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
30 |
tac_timeout: Time.time option, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
31 |
evals: term list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
32 |
case_names: (string * int) list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
33 |
def_table: const_table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
34 |
nondef_table: const_table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
35 |
user_nondefs: term list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
36 |
simp_table: const_table Unsynchronized.ref, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
37 |
psimp_table: const_table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
38 |
choice_spec_table: const_table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
39 |
intro_table: const_table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
40 |
ground_thm_table: term list Inttab.table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
41 |
ersatz_table: (string * string) list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
42 |
skolems: (string * string list) list Unsynchronized.ref, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
43 |
special_funs: special_fun list Unsynchronized.ref, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
44 |
unrolled_preds: unrolled list Unsynchronized.ref, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
45 |
wf_cache: wf_cache Unsynchronized.ref, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
46 |
constr_cache: (typ * styp list) list Unsynchronized.ref} |
33192 | 47 |
|
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
48 |
datatype fixpoint_kind = Lfp | Gfp | NoFp |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
49 |
datatype boxability = |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
50 |
InConstr | InSel | InExpr | InPair | InFunLHS | InFunRHS1 | InFunRHS2 |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
51 |
|
33192 | 52 |
val name_sep : string |
53 |
val numeral_prefix : string |
|
35718 | 54 |
val base_prefix : string |
55 |
val step_prefix : string |
|
56 |
val unrolled_prefix : string |
|
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
57 |
val ubfp_prefix : string |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
58 |
val lbfp_prefix : string |
35311 | 59 |
val quot_normal_prefix : string |
33192 | 60 |
val skolem_prefix : string |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
61 |
val special_prefix : string |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
62 |
val uncurry_prefix : string |
33192 | 63 |
val eval_prefix : string |
35718 | 64 |
val iter_var_prefix : string |
65 |
val strip_first_name_sep : string -> string * string |
|
33192 | 66 |
val original_name : string -> string |
34998 | 67 |
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
|
68 |
val s_disj : term * term -> term |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
69 |
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
|
70 |
val conjuncts_of : term -> term list |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
71 |
val disjuncts_of : term -> term list |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
72 |
val unarize_unbox_etc_type : typ -> typ |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
73 |
val uniterize_unarize_unbox_etc_type : typ -> typ |
33192 | 74 |
val string_for_type : Proof.context -> typ -> string |
75 |
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
|
76 |
val shortest_name : string -> string |
33192 | 77 |
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
|
78 |
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
|
79 |
val strict_type_match : theory -> typ * typ -> bool |
33192 | 80 |
val type_match : theory -> typ * typ -> bool |
81 |
val const_match : theory -> styp * styp -> bool |
|
82 |
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
|
83 |
val frac_from_term_pair : typ -> term -> term -> term |
33192 | 84 |
val is_TFree : typ -> bool |
85 |
val is_higher_order_type : typ -> bool |
|
86 |
val is_fun_type : typ -> bool |
|
87 |
val is_set_type : typ -> bool |
|
88 |
val is_pair_type : typ -> bool |
|
89 |
val is_lfp_iterator_type : typ -> bool |
|
90 |
val is_gfp_iterator_type : typ -> bool |
|
91 |
val is_fp_iterator_type : typ -> bool |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
92 |
val is_iterator_type : typ -> bool |
33192 | 93 |
val is_boolean_type : typ -> bool |
94 |
val is_integer_type : typ -> bool |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
95 |
val is_bit_type : typ -> bool |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
96 |
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
|
97 |
val is_integer_like_type : typ -> bool |
33192 | 98 |
val is_record_type : typ -> bool |
99 |
val is_number_type : theory -> typ -> bool |
|
100 |
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
|
101 |
val strip_n_binders : int -> typ -> typ list * typ |
33192 | 102 |
val nth_range_type : int -> typ -> typ |
103 |
val num_factors_in_type : typ -> int |
|
104 |
val num_binder_types : typ -> int |
|
105 |
val curried_binder_types : typ -> typ list |
|
106 |
val mk_flat_tuple : typ -> term list -> term |
|
107 |
val dest_n_tuple : int -> term -> term list |
|
33978
2380c1dac86e
fix soundness bug in Nitpick's "destroy_constrs" optimization
blanchet
parents:
33968
diff
changeset
|
108 |
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
|
109 |
val is_standard_datatype : theory -> (typ option * bool) list -> typ -> bool |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
110 |
val is_quot_type : theory -> typ -> bool |
33192 | 111 |
val is_codatatype : theory -> typ -> bool |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
112 |
val is_pure_typedef : Proof.context -> typ -> bool |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
113 |
val is_univ_typedef : Proof.context -> typ -> bool |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
114 |
val is_datatype : Proof.context -> (typ option * bool) list -> typ -> bool |
33192 | 115 |
val is_record_constr : styp -> bool |
116 |
val is_record_get : theory -> styp -> bool |
|
117 |
val is_record_update : theory -> styp -> bool |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
118 |
val is_abs_fun : Proof.context -> styp -> bool |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
119 |
val is_rep_fun : Proof.context -> styp -> bool |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
120 |
val is_quot_abs_fun : Proof.context -> styp -> bool |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
121 |
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
|
122 |
val mate_of_rep_fun : Proof.context -> styp -> styp |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
123 |
val is_constr_like : Proof.context -> styp -> bool |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
124 |
val is_constr : Proof.context -> (typ option * bool) list -> styp -> bool |
33192 | 125 |
val is_sel : string -> bool |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
val binarize_nat_and_int_in_term : term -> term |
33192 | 130 |
val discr_for_constr : styp -> styp |
131 |
val num_sels_for_constr_type : typ -> int |
|
132 |
val nth_sel_name_for_constr_name : string -> int -> string |
|
133 |
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
|
134 |
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
|
135 |
hol_context -> bool -> styp -> int -> styp |
33192 | 136 |
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
|
137 |
val close_form : term -> term |
33192 | 138 |
val eta_expand : typ list -> term -> int -> term |
139 |
val extensionalize : term -> term |
|
140 |
val distinctness_formula : typ -> term list -> term |
|
141 |
val register_frac_type : string -> (string * string) list -> theory -> theory |
|
142 |
val unregister_frac_type : string -> theory -> theory |
|
143 |
val register_codatatype : typ -> string -> styp list -> theory -> theory |
|
144 |
val unregister_codatatype : typ -> theory -> theory |
|
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
val num_datatype_constrs : hol_context -> typ -> int |
33192 | 149 |
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
|
150 |
val binarized_and_boxed_constr_for_sel : hol_context -> bool -> styp -> styp |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
151 |
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
|
152 |
val select_nth_constr_arg : |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
153 |
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
|
154 |
-> 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
|
155 |
val construct_value : |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
156 |
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
|
157 |
val coerce_term : hol_context -> typ list -> typ -> typ -> term -> term |
33192 | 158 |
val card_of_type : (typ * int) list -> typ -> int |
159 |
val bounded_card_of_type : int -> int -> (typ * int) list -> typ -> int |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
160 |
val bounded_exact_card_of_type : |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35384
diff
changeset
|
161 |
hol_context -> typ list -> int -> int -> (typ * int) list -> typ -> int |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
162 |
val is_finite_type : hol_context -> typ -> bool |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
163 |
val is_small_finite_type : hol_context -> typ -> bool |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
164 |
val special_bounds : term list -> (indexname * typ) list |
35386
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
blanchet
parents:
35385
diff
changeset
|
165 |
val abs_var : indexname * typ -> term -> term |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
166 |
val is_funky_typedef : theory -> typ -> bool |
35335 | 167 |
val all_axioms_of : |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
168 |
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
|
169 |
val arity_of_built_in_const : |
2bcdae5f4fdb
added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents:
35190
diff
changeset
|
170 |
theory -> (typ option * bool) list -> bool -> styp -> int 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
|
171 |
val is_built_in_const : |
2bcdae5f4fdb
added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents:
35190
diff
changeset
|
172 |
theory -> (typ option * bool) list -> bool -> styp -> bool |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
173 |
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
|
174 |
val case_const_names : |
2bcdae5f4fdb
added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents:
35190
diff
changeset
|
175 |
theory -> (typ option * bool) list -> (string * int) list |
35718 | 176 |
val unfold_defs_in_term : hol_context -> term -> term |
35335 | 177 |
val const_def_table : |
178 |
Proof.context -> (term * term) list -> term list -> const_table |
|
33192 | 179 |
val const_nondef_table : term list -> const_table |
35335 | 180 |
val const_simp_table : Proof.context -> (term * term) list -> const_table |
181 |
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
|
182 |
val const_choice_spec_table : |
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35743
diff
changeset
|
183 |
Proof.context -> (term * term) list -> const_table |
35335 | 184 |
val inductive_intro_table : |
185 |
Proof.context -> (term * term) list -> const_table -> const_table |
|
33192 | 186 |
val ground_theorem_table : theory -> term list Inttab.table |
187 |
val ersatz_table : theory -> (string * string) list |
|
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
val optimized_quot_type_axioms : |
35311 | 192 |
Proof.context -> (typ option * bool) list -> string * typ list -> term list |
33192 | 193 |
val def_of_const : theory -> const_table -> styp -> term option |
35718 | 194 |
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
|
195 |
val fixpoint_kind_of_const : |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
196 |
theory -> const_table -> string * typ -> fixpoint_kind |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
197 |
val is_inductive_pred : hol_context -> styp -> bool |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
198 |
val is_equational_fun : hol_context -> styp -> bool |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
199 |
val is_constr_pattern_lhs : Proof.context -> term -> bool |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
200 |
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
|
201 |
val nondef_props_for_const : |
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35743
diff
changeset
|
202 |
theory -> bool -> const_table -> styp -> term list |
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35743
diff
changeset
|
203 |
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
|
204 |
val is_choice_spec_axiom : theory -> const_table -> term -> bool |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
val is_equational_fun_surely_complete : hol_context -> styp -> bool |
33556
cba22e2999d5
renamed Nitpick option "coalesce_type_vars" to "merge_type_vars" (shorter) and cleaned up old hacks that are no longer necessary
blanchet
parents:
33232
diff
changeset
|
210 |
val merge_type_vars_in_terms : term list -> term list |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35181
diff
changeset
|
211 |
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
|
212 |
val ground_types_in_terms : hol_context -> bool -> term list -> typ list |
33192 | 213 |
end; |
214 |
||
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
215 |
structure Nitpick_HOL : NITPICK_HOL = |
33192 | 216 |
struct |
217 |
||
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
218 |
open Nitpick_Util |
33192 | 219 |
|
220 |
type const_table = term list Symtab.table |
|
221 |
type special_fun = (styp * int list * term list) * styp |
|
222 |
type unrolled = styp * styp |
|
223 |
type wf_cache = (styp * (bool * bool)) list |
|
224 |
||
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
225 |
type hol_context = |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
226 |
{thy: theory, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
227 |
ctxt: Proof.context, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
228 |
max_bisim_depth: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
229 |
boxes: (typ option * bool option) list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
230 |
stds: (typ option * bool) list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
231 |
wfs: (styp option * bool option) list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
232 |
user_axioms: bool option, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
233 |
debug: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
234 |
binary_ints: bool option, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
235 |
destroy_constrs: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
236 |
specialize: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
237 |
star_linear_preds: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
238 |
fast_descrs: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
239 |
tac_timeout: Time.time option, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
240 |
evals: term list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
241 |
case_names: (string * int) list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
242 |
def_table: const_table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
243 |
nondef_table: const_table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
244 |
user_nondefs: term list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
245 |
simp_table: const_table Unsynchronized.ref, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
246 |
psimp_table: const_table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
247 |
choice_spec_table: const_table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
248 |
intro_table: const_table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
249 |
ground_thm_table: term list Inttab.table, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
250 |
ersatz_table: (string * string) list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
251 |
skolems: (string * string list) list Unsynchronized.ref, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
252 |
special_funs: special_fun list Unsynchronized.ref, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
253 |
unrolled_preds: unrolled list Unsynchronized.ref, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
254 |
wf_cache: wf_cache Unsynchronized.ref, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
255 |
constr_cache: (typ * styp list) list Unsynchronized.ref} |
33192 | 256 |
|
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
257 |
datatype fixpoint_kind = Lfp | Gfp | NoFp |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
258 |
datatype boxability = |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
259 |
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
|
260 |
|
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
261 |
structure Data = Theory_Data( |
33192 | 262 |
type T = {frac_types: (string * (string * string) list) list, |
263 |
codatatypes: (string * (string * styp list)) list} |
|
264 |
val empty = {frac_types = [], codatatypes = []} |
|
265 |
val extend = I |
|
33522 | 266 |
fun merge ({frac_types = fs1, codatatypes = cs1}, |
36391 | 267 |
{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
|
268 |
{frac_types = AList.merge (op =) (K true) (fs1, fs2), |
f33b036ef318
permissive AList.merge -- most likely setup for theory data (beware of spurious AList.DUP);
wenzelm
parents:
33583
diff
changeset
|
269 |
codatatypes = AList.merge (op =) (K true) (cs1, cs2)}) |
33192 | 270 |
|
271 |
val name_sep = "$" |
|
272 |
val numeral_prefix = nitpick_prefix ^ "num" ^ name_sep |
|
273 |
val sel_prefix = nitpick_prefix ^ "sel" |
|
274 |
val discr_prefix = nitpick_prefix ^ "is" ^ name_sep |
|
275 |
val set_prefix = nitpick_prefix ^ "set" ^ name_sep |
|
276 |
val lfp_iterator_prefix = nitpick_prefix ^ "lfpit" ^ name_sep |
|
277 |
val gfp_iterator_prefix = nitpick_prefix ^ "gfpit" ^ name_sep |
|
278 |
val unrolled_prefix = nitpick_prefix ^ "unroll" ^ name_sep |
|
279 |
val base_prefix = nitpick_prefix ^ "base" ^ name_sep |
|
280 |
val step_prefix = nitpick_prefix ^ "step" ^ name_sep |
|
281 |
val ubfp_prefix = nitpick_prefix ^ "ubfp" ^ name_sep |
|
282 |
val lbfp_prefix = nitpick_prefix ^ "lbfp" ^ name_sep |
|
35311 | 283 |
val quot_normal_prefix = nitpick_prefix ^ "qn" ^ name_sep |
33192 | 284 |
val skolem_prefix = nitpick_prefix ^ "sk" |
285 |
val special_prefix = nitpick_prefix ^ "sp" |
|
286 |
val uncurry_prefix = nitpick_prefix ^ "unc" |
|
287 |
val eval_prefix = nitpick_prefix ^ "eval" |
|
288 |
val iter_var_prefix = "i" |
|
35718 | 289 |
|
290 |
(** Constant/type information and term/type manipulation **) |
|
33192 | 291 |
|
292 |
fun sel_prefix_for j = sel_prefix ^ string_of_int j ^ name_sep |
|
35311 | 293 |
fun quot_normal_name_for_type ctxt T = |
294 |
quot_normal_prefix ^ unyxml (Syntax.string_of_typ ctxt T) |
|
33192 | 295 |
|
296 |
val strip_first_name_sep = |
|
297 |
Substring.full #> Substring.position name_sep ##> Substring.triml 1 |
|
298 |
#> pairself Substring.string |
|
299 |
fun original_name s = |
|
300 |
if String.isPrefix nitpick_prefix s then |
|
301 |
case strip_first_name_sep s of (s1, "") => s1 | (_, s2) => original_name s2 |
|
302 |
else |
|
303 |
s |
|
35718 | 304 |
|
305 |
fun s_betapply (Const (@{const_name If}, _) $ @{const True} $ t, _) = t |
|
306 |
| s_betapply (Const (@{const_name If}, _) $ @{const False} $ _, t) = t |
|
307 |
| s_betapply p = betapply p |
|
308 |
val s_betapplys = Library.foldl s_betapply |
|
33192 | 309 |
|
34998 | 310 |
fun s_conj (t1, @{const True}) = t1 |
311 |
| s_conj (@{const True}, t2) = t2 |
|
312 |
| s_conj (t1, t2) = |
|
313 |
if t1 = @{const False} orelse t2 = @{const False} then @{const False} |
|
314 |
else HOLogic.mk_conj (t1, t2) |
|
315 |
fun s_disj (t1, @{const False}) = t1 |
|
316 |
| s_disj (@{const False}, t2) = t2 |
|
317 |
| s_disj (t1, t2) = |
|
318 |
if t1 = @{const True} orelse t2 = @{const True} then @{const True} |
|
319 |
else HOLogic.mk_disj (t1, t2) |
|
320 |
||
321 |
fun strip_connective conn_t (t as (t0 $ t1 $ t2)) = |
|
322 |
if t0 = conn_t then strip_connective t0 t2 @ strip_connective t0 t1 else [t] |
|
323 |
| strip_connective _ t = [t] |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
324 |
fun strip_any_connective (t as (t0 $ _ $ _)) = |
34998 | 325 |
if t0 = @{const "op &"} orelse t0 = @{const "op |"} then |
326 |
(strip_connective t0 t, t0) |
|
327 |
else |
|
328 |
([t], @{const Not}) |
|
329 |
| strip_any_connective t = ([t], @{const Not}) |
|
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
330 |
val conjuncts_of = strip_connective @{const "op &"} |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
331 |
val disjuncts_of = strip_connective @{const "op |"} |
34998 | 332 |
|
33192 | 333 |
(* 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
|
334 |
"Nitpick_Nut.nut_from_term", and perhaps in "Nitpick_Mono.consider_term" as |
33192 | 335 |
well. *) |
336 |
val built_in_consts = |
|
337 |
[(@{const_name all}, 1), |
|
338 |
(@{const_name "=="}, 2), |
|
339 |
(@{const_name "==>"}, 2), |
|
340 |
(@{const_name Pure.conjunction}, 2), |
|
341 |
(@{const_name Trueprop}, 1), |
|
342 |
(@{const_name Not}, 1), |
|
343 |
(@{const_name False}, 0), |
|
344 |
(@{const_name True}, 0), |
|
345 |
(@{const_name All}, 1), |
|
346 |
(@{const_name Ex}, 1), |
|
347 |
(@{const_name "op ="}, 2), |
|
348 |
(@{const_name "op &"}, 2), |
|
349 |
(@{const_name "op |"}, 2), |
|
350 |
(@{const_name "op -->"}, 2), |
|
351 |
(@{const_name If}, 3), |
|
352 |
(@{const_name Let}, 2), |
|
353 |
(@{const_name Unity}, 0), |
|
354 |
(@{const_name Pair}, 2), |
|
355 |
(@{const_name fst}, 1), |
|
356 |
(@{const_name snd}, 1), |
|
357 |
(@{const_name Id}, 0), |
|
358 |
(@{const_name insert}, 2), |
|
359 |
(@{const_name converse}, 1), |
|
360 |
(@{const_name trancl}, 1), |
|
361 |
(@{const_name rel_comp}, 2), |
|
362 |
(@{const_name image}, 2), |
|
363 |
(@{const_name finite}, 1), |
|
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
364 |
(@{const_name unknown}, 0), |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
365 |
(@{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
|
366 |
(@{const_name safe_The}, 1), |
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
blanchet
parents:
35665
diff
changeset
|
367 |
(@{const_name safe_Eps}, 1), |
33192 | 368 |
(@{const_name Frac}, 0), |
369 |
(@{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
|
370 |
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
|
371 |
[(@{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
|
372 |
(@{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
|
373 |
(@{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
|
374 |
(@{const_name nat_lcm}, 0)] |
33192 | 375 |
val built_in_descr_consts = |
376 |
[(@{const_name The}, 1), |
|
377 |
(@{const_name Eps}, 1)] |
|
378 |
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
|
379 |
[((@{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
|
380 |
((@{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
|
381 |
((@{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
|
382 |
((@{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
|
383 |
((@{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
|
384 |
((@{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
|
385 |
((@{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
|
386 |
((@{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
|
387 |
((@{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
|
388 |
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
|
389 |
[((@{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
|
390 |
((@{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
|
391 |
((@{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
|
392 |
((@{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
|
393 |
((@{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
|
394 |
((@{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
|
395 |
((@{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
|
396 |
((@{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
|
397 |
((@{const_name of_nat}, nat_T --> int_T), 0)] |
33192 | 398 |
val built_in_set_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
|
399 |
[(@{const_name semilattice_inf_class.inf}, 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
|
400 |
(@{const_name semilattice_sup_class.sup}, 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 minus_class.minus}, 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 |
(@{const_name ord_class.less_eq}, 2)] |
33192 | 403 |
|
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35181
diff
changeset
|
404 |
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
|
405 |
| 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
|
406 |
| 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
|
407 |
| unarize_type T = T |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
408 |
fun unarize_unbox_etc_type (Type (@{type_name fin_fun}, Ts)) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
409 |
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
|
410 |
| unarize_unbox_etc_type (Type (@{type_name fun_box}, Ts)) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
411 |
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
|
412 |
| unarize_unbox_etc_type (Type (@{type_name pair_box}, Ts)) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
413 |
Type (@{type_name "*"}, map unarize_unbox_etc_type Ts) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
414 |
| 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
|
415 |
| 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
|
416 |
| unarize_unbox_etc_type (Type (s, Ts as _ :: _)) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
417 |
Type (s, map unarize_unbox_etc_type Ts) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
418 |
| unarize_unbox_etc_type T = T |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
419 |
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
|
420 |
| uniterize_type @{typ bisim_iterator} = nat_T |
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
421 |
| uniterize_type T = T |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
422 |
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
|
423 |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
424 |
fun string_for_type ctxt = Syntax.string_of_typ ctxt o unarize_unbox_etc_type |
33192 | 425 |
|
426 |
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
|
427 |
fun shortest_name s = List.last (space_explode "." s) handle List.Empty => "" |
33192 | 428 |
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
|
429 |
fun short_name s = |
33192 | 430 |
case space_explode name_sep s of |
431 |
[_] => 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
|
432 |
| 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
|
433 |
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
|
434 |
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
|
435 |
| 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
|
436 |
val shorten_names_in_term = |
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33978
diff
changeset
|
437 |
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
|
438 |
#> map_types shorten_names_in_type |
33192 | 439 |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
440 |
fun strict_type_match thy (T1, T2) = |
33192 | 441 |
(Sign.typ_match thy (T2, T1) Vartab.empty; true) |
442 |
handle Type.TYPE_MATCH => false |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
443 |
fun type_match thy = strict_type_match thy o pairself unarize_unbox_etc_type |
33192 | 444 |
fun const_match thy ((s1, T1), (s2, T2)) = |
445 |
s1 = s2 andalso type_match thy (T1, T2) |
|
446 |
fun term_match thy (Const x1, Const x2) = const_match thy (x1, x2) |
|
447 |
| 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
|
448 |
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
|
449 |
| term_match _ (t1, t2) = t1 aconv t2 |
33192 | 450 |
|
35711
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35671
diff
changeset
|
451 |
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
|
452 |
case snd (HOLogic.dest_number t1) of |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35671
diff
changeset
|
453 |
0 => HOLogic.mk_number T 0 |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35671
diff
changeset
|
454 |
| 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
|
455 |
1 => HOLogic.mk_number T n1 |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35671
diff
changeset
|
456 |
| 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
|
457 |
$ 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
|
458 |
|
33192 | 459 |
fun is_TFree (TFree _) = true |
460 |
| is_TFree _ = false |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
461 |
fun is_higher_order_type (Type (@{type_name fun}, _)) = true |
33192 | 462 |
| is_higher_order_type (Type (_, Ts)) = exists is_higher_order_type Ts |
463 |
| is_higher_order_type _ = false |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
464 |
fun is_fun_type (Type (@{type_name fun}, _)) = true |
33192 | 465 |
| is_fun_type _ = false |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
466 |
fun is_set_type (Type (@{type_name fun}, [_, @{typ bool}])) = true |
33192 | 467 |
| is_set_type _ = false |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
468 |
fun is_pair_type (Type (@{type_name "*"}, _)) = true |
33192 | 469 |
| is_pair_type _ = false |
470 |
fun is_lfp_iterator_type (Type (s, _)) = String.isPrefix lfp_iterator_prefix s |
|
471 |
| is_lfp_iterator_type _ = false |
|
472 |
fun is_gfp_iterator_type (Type (s, _)) = String.isPrefix gfp_iterator_prefix s |
|
473 |
| is_gfp_iterator_type _ = false |
|
474 |
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
|
475 |
fun is_iterator_type T = |
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
476 |
(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
|
477 |
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
|
478 |
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
|
479 |
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
|
480 |
fun is_word_type (Type (@{type_name word}, _)) = true |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
481 |
| is_word_type _ = false |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
482 |
val is_integer_like_type = is_iterator_type orf is_integer_type orf is_word_type |
33192 | 483 |
val is_record_type = not o null o Record.dest_recTs |
484 |
fun is_frac_type thy (Type (s, [])) = |
|
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
485 |
not (null (these (AList.lookup (op =) (#frac_types (Data.get thy)) s))) |
33192 | 486 |
| is_frac_type _ _ = false |
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
|
487 |
fun is_number_type thy = is_integer_like_type orf is_frac_type thy |
33192 | 488 |
|
489 |
fun iterator_type_for_const gfp (s, T) = |
|
490 |
Type ((if gfp then gfp_iterator_prefix else lfp_iterator_prefix) ^ s, |
|
491 |
binder_types T) |
|
35718 | 492 |
fun const_for_iterator_type (Type (s, Ts)) = |
493 |
(strip_first_name_sep s |> snd, Ts ---> bool_T) |
|
33192 | 494 |
| const_for_iterator_type T = |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
495 |
raise TYPE ("Nitpick_HOL.const_for_iterator_type", [T], []) |
33192 | 496 |
|
497 |
fun strip_n_binders 0 T = ([], T) |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
498 |
| strip_n_binders n (Type (@{type_name fun}, [T1, T2])) = |
33192 | 499 |
strip_n_binders (n - 1) T2 |>> cons T1 |
500 |
| 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
|
501 |
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
|
502 |
| strip_n_binders _ T = raise TYPE ("Nitpick_HOL.strip_n_binders", [T], []) |
33192 | 503 |
val nth_range_type = snd oo strip_n_binders |
504 |
||
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
505 |
fun num_factors_in_type (Type (@{type_name "*"}, [T1, T2])) = |
33192 | 506 |
fold (Integer.add o num_factors_in_type) [T1, T2] 0 |
507 |
| num_factors_in_type _ = 1 |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
508 |
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
|
509 |
1 + num_binder_types T2 |
33192 | 510 |
| num_binder_types _ = 0 |
511 |
val curried_binder_types = maps HOLogic.flatten_tupleT o binder_types |
|
512 |
fun maybe_curried_binder_types T = |
|
513 |
(if is_pair_type (body_type T) then binder_types else curried_binder_types) T |
|
514 |
||
515 |
fun mk_flat_tuple _ [t] = t |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
516 |
| mk_flat_tuple (Type (@{type_name "*"}, [T1, T2])) (t :: ts) = |
33192 | 517 |
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
|
518 |
| mk_flat_tuple T ts = raise TYPE ("Nitpick_HOL.mk_flat_tuple", [T], ts) |
33192 | 519 |
fun dest_n_tuple 1 t = [t] |
520 |
| dest_n_tuple n t = HOLogic.dest_prod t ||> dest_n_tuple (n - 1) |> op :: |
|
521 |
||
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
|
522 |
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
|
523 |
{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
|
524 |
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
|
525 |
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
|
526 |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
527 |
fun typedef_info ctxt s = |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
528 |
let val thy = ProofContext.theory_of ctxt in |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
529 |
if is_frac_type thy (Type (s, [])) then |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
530 |
SOME {abs_type = Type (s, []), rep_type = @{typ "int * int"}, |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
531 |
Abs_name = @{const_name Abs_Frac}, Rep_name = @{const_name Rep_Frac}, |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
532 |
set_def = NONE, prop_of_Rep = @{prop "Rep_Frac x \<in> Frac"} |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
533 |
|> Logic.varify_global, |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
534 |
set_name = @{const_name Frac}, Abs_inverse = NONE, Rep_inverse = NONE} |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
535 |
else case Typedef.get_info ctxt s of |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
536 |
(* ### multiple *) |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
537 |
[({abs_type, rep_type, Abs_name, Rep_name, ...}, |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
538 |
{set_def, Rep, Abs_inverse, Rep_inverse, ...})] => |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
539 |
SOME {abs_type = abs_type, rep_type = rep_type, Abs_name = Abs_name, |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
540 |
Rep_name = Rep_name, set_def = set_def, prop_of_Rep = prop_of Rep, |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
541 |
set_name = set_prefix ^ s, Abs_inverse = SOME Abs_inverse, |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
542 |
Rep_inverse = SOME Rep_inverse} |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
543 |
| _ => NONE |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
544 |
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
|
545 |
|
2bcdae5f4fdb
added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents:
35190
diff
changeset
|
546 |
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
|
547 |
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
|
548 |
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
|
549 |
|
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33978
diff
changeset
|
550 |
(* 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
|
551 |
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
|
552 |
fun is_basic_datatype thy stds s = |
2bcdae5f4fdb
added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents:
35190
diff
changeset
|
553 |
member (op =) [@{type_name "*"}, @{type_name bool}, @{type_name unit}, |
2bcdae5f4fdb
added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents:
35190
diff
changeset
|
554 |
@{type_name int}, "Code_Numeral.code_numeral"] s orelse |
2bcdae5f4fdb
added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents:
35190
diff
changeset
|
555 |
(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
|
556 |
|
33192 | 557 |
fun instantiate_type thy T1 T1' T2 = |
558 |
Same.commit (Envir.subst_type_same |
|
35311 | 559 |
(Sign.typ_match thy (T1, T1') Vartab.empty)) T2 |
33192 | 560 |
handle Type.TYPE_MATCH => |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
561 |
raise TYPE ("Nitpick_HOL.instantiate_type", [T1, T1'], []) |
35311 | 562 |
fun varify_and_instantiate_type thy T1 T1' T2 = |
35845
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
35807
diff
changeset
|
563 |
instantiate_type thy (Logic.varifyT_global T1) T1' (Logic.varifyT_global T2) |
33192 | 564 |
|
565 |
fun repair_constr_type thy body_T' T = |
|
35311 | 566 |
varify_and_instantiate_type thy (body_type T) body_T' T |
33192 | 567 |
|
568 |
fun register_frac_type frac_s ersaetze thy = |
|
569 |
let |
|
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
570 |
val {frac_types, codatatypes} = Data.get thy |
33192 | 571 |
val frac_types = AList.update (op =) (frac_s, ersaetze) frac_types |
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
572 |
in Data.put {frac_types = frac_types, codatatypes = codatatypes} thy end |
33192 | 573 |
fun unregister_frac_type frac_s = register_frac_type frac_s [] |
574 |
||
575 |
fun register_codatatype co_T case_name constr_xs thy = |
|
576 |
let |
|
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
577 |
val {frac_types, codatatypes} = Data.get thy |
33192 | 578 |
val constr_xs = map (apsnd (repair_constr_type thy co_T)) constr_xs |
579 |
val (co_s, co_Ts) = dest_Type co_T |
|
580 |
val _ = |
|
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
581 |
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
|
582 |
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
|
583 |
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
|
584 |
() |
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33978
diff
changeset
|
585 |
else |
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33978
diff
changeset
|
586 |
raise TYPE ("Nitpick_HOL.register_codatatype", [co_T], []) |
33192 | 587 |
val codatatypes = AList.update (op =) (co_s, (case_name, constr_xs)) |
588 |
codatatypes |
|
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
589 |
in Data.put {frac_types = frac_types, codatatypes = codatatypes} thy end |
33192 | 590 |
fun unregister_codatatype co_T = register_codatatype co_T "" [] |
591 |
||
35284
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
592 |
fun is_quot_type thy (Type (s, _)) = |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
593 |
is_some (Quotient_Info.quotdata_lookup_raw thy s) |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
594 |
| is_quot_type _ _ = false |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
595 |
fun is_codatatype thy (Type (s, _)) = |
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
596 |
not (null (AList.lookup (op =) (#codatatypes (Data.get thy)) s |
33192 | 597 |
|> Option.map snd |> these)) |
598 |
| is_codatatype _ _ = false |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
599 |
fun is_pure_typedef ctxt (T as Type (s, _)) = |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
600 |
let val thy = ProofContext.theory_of ctxt in |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
601 |
is_typedef ctxt s andalso |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
602 |
not (is_real_datatype thy s orelse is_quot_type thy T orelse |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
603 |
is_codatatype thy T orelse is_record_type T orelse |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
604 |
is_integer_like_type T) |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
605 |
end |
33192 | 606 |
| is_pure_typedef _ _ = false |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
607 |
fun is_univ_typedef ctxt (Type (s, _)) = |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
608 |
(case typedef_info ctxt s of |
33192 | 609 |
SOME {set_def, prop_of_Rep, ...} => |
35332
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
610 |
let |
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
611 |
val t_opt = |
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
612 |
case set_def of |
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
613 |
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
|
614 |
| NONE => try (snd o HOLogic.dest_mem o HOLogic.dest_Trueprop) |
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
615 |
prop_of_Rep |
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
616 |
in |
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
617 |
case t_opt of |
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
618 |
SOME (Const (@{const_name top}, _)) => true |
35386
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
blanchet
parents:
35385
diff
changeset
|
619 |
(* "Multiset.multiset" *) |
35332
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
620 |
| SOME (Const (@{const_name Collect}, _) |
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
621 |
$ Abs (_, _, Const (@{const_name finite}, _) $ _)) => true |
35386
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
blanchet
parents:
35385
diff
changeset
|
622 |
(* "FinFun.finfun" *) |
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
blanchet
parents:
35385
diff
changeset
|
623 |
| SOME (Const (@{const_name Collect}, _) $ Abs (_, _, |
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
blanchet
parents:
35385
diff
changeset
|
624 |
Const (@{const_name Ex}, _) $ Abs (_, _, |
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
blanchet
parents:
35385
diff
changeset
|
625 |
Const (@{const_name finite}, _) $ _))) => true |
35332
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
626 |
| _ => false |
22442ab3e7a3
optimized multisets in Nitpick by fishing "finite"
blanchet
parents:
35311
diff
changeset
|
627 |
end |
33192 | 628 |
| NONE => false) |
629 |
| is_univ_typedef _ _ = false |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
630 |
fun is_datatype ctxt stds (T as Type (s, _)) = |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
631 |
let val thy = ProofContext.theory_of ctxt in |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
632 |
(is_typedef ctxt s orelse is_codatatype thy T orelse T = @{typ ind} orelse |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
633 |
is_quot_type thy T) andalso not (is_basic_datatype thy stds s) |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
634 |
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
|
635 |
| is_datatype _ _ _ = false |
33192 | 636 |
|
637 |
fun all_record_fields thy T = |
|
638 |
let val (recs, more) = Record.get_extT_fields thy T in |
|
639 |
recs @ more :: all_record_fields thy (snd more) |
|
640 |
end |
|
641 |
handle TYPE _ => [] |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
642 |
fun is_record_constr (s, T) = |
33192 | 643 |
String.isSuffix Record.extN s andalso |
644 |
let val dataT = body_type T in |
|
645 |
is_record_type dataT andalso |
|
646 |
s = unsuffix Record.ext_typeN (fst (dest_Type dataT)) ^ Record.extN |
|
647 |
end |
|
648 |
val num_record_fields = Integer.add 1 o length o fst oo Record.get_extT_fields |
|
649 |
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
|
650 |
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
|
651 |
(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
|
652 |
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
|
653 |
exists (curry (op =) s o fst) (all_record_fields thy T1) |
33192 | 654 |
| is_record_get _ _ = false |
655 |
fun is_record_update thy (s, T) = |
|
656 |
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
|
657 |
exists (curry (op =) (unsuffix Record.updateN s) o fst) |
33192 | 658 |
(all_record_fields thy (body_type T)) |
659 |
handle TYPE _ => false |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
660 |
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
|
661 |
(case typedef_info ctxt s' of |
33192 | 662 |
SOME {Abs_name, ...} => s = Abs_name |
663 |
| NONE => false) |
|
664 |
| is_abs_fun _ _ = false |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
665 |
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
|
666 |
(case typedef_info ctxt s' of |
33192 | 667 |
SOME {Rep_name, ...} => s = Rep_name |
668 |
| NONE => false) |
|
669 |
| is_rep_fun _ _ = false |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
670 |
fun is_quot_abs_fun ctxt |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
671 |
(x as (_, Type (@{type_name fun}, [_, Type (s', _)]))) = |
35284
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
672 |
(try (Quotient_Term.absrep_const_chk Quotient_Term.AbsF ctxt) s' |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
673 |
= SOME (Const x)) |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
674 |
| is_quot_abs_fun _ _ = false |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
675 |
fun is_quot_rep_fun ctxt |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
676 |
(x as (_, Type (@{type_name fun}, [Type (s', _), _]))) = |
35284
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
677 |
(try (Quotient_Term.absrep_const_chk Quotient_Term.RepF ctxt) s' |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
678 |
= SOME (Const x)) |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
679 |
| is_quot_rep_fun _ _ = false |
33192 | 680 |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
681 |
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
|
682 |
[T1 as Type (s', _), T2]))) = |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
683 |
(case typedef_info ctxt s' of |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
684 |
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
|
685 |
| 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
|
686 |
| 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
|
687 |
fun rep_type_for_quot_type thy (T as Type (s, _)) = |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
688 |
let val {qtyp, rtyp, ...} = Quotient_Info.quotdata_lookup thy s in |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
689 |
instantiate_type thy qtyp T rtyp |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
690 |
end |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
691 |
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
|
692 |
let |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
693 |
val {qtyp, equiv_rel, ...} = Quotient_Info.quotdata_lookup thy s |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
694 |
val Ts' = qtyp |> dest_Type |> snd |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35283
diff
changeset
|
695 |
in subst_atomic_types (Ts' ~~ Ts) equiv_rel end |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
696 |
| equiv_relation_for_quot_type _ T = |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
697 |
raise TYPE ("Nitpick_HOL.equiv_relation_for_quot_type", [T], []) |
33192 | 698 |
|
699 |
fun is_coconstr thy (s, T) = |
|
700 |
let |
|
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
701 |
val {codatatypes, ...} = Data.get thy |
33192 | 702 |
val co_T = body_type T |
703 |
val co_s = dest_Type co_T |> fst |
|
704 |
in |
|
705 |
exists (fn (s', T') => s = s' andalso repair_constr_type thy co_T T' = T) |
|
706 |
(AList.lookup (op =) codatatypes co_s |> Option.map snd |> these) |
|
707 |
end |
|
708 |
handle TYPE ("dest_Type", _, _) => false |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
709 |
fun is_constr_like ctxt (s, T) = |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
710 |
member (op =) [@{const_name FinFun}, @{const_name FunBox}, |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
711 |
@{const_name PairBox}, @{const_name Quot}, |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
712 |
@{const_name Zero_Rep}, @{const_name Suc_Rep}] s orelse |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
713 |
let |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
714 |
val thy = ProofContext.theory_of ctxt |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
715 |
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
|
716 |
in |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
717 |
Refute.is_IDT_constructor thy x orelse is_record_constr x orelse |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
718 |
(is_abs_fun ctxt x andalso is_pure_typedef ctxt (range_type T)) orelse |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
719 |
is_coconstr thy x |
33192 | 720 |
end |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
721 |
fun is_stale_constr ctxt (x as (_, T)) = |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
722 |
let val thy = ProofContext.theory_of ctxt in |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
723 |
is_codatatype thy (body_type T) andalso is_constr_like ctxt x andalso |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
724 |
not (is_coconstr thy x) |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
725 |
end |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
726 |
fun is_constr ctxt stds (x as (_, T)) = |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
727 |
let val thy = ProofContext.theory_of ctxt in |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
728 |
is_constr_like ctxt x andalso |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
729 |
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
|
730 |
(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
|
731 |
not (is_stale_constr ctxt x) |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
732 |
end |
33192 | 733 |
val is_sel = String.isPrefix discr_prefix orf String.isPrefix sel_prefix |
734 |
val is_sel_like_and_no_discr = |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
735 |
String.isPrefix sel_prefix orf |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
736 |
(member (op =) [@{const_name fst}, @{const_name snd}]) |
33192 | 737 |
|
738 |
fun in_fun_lhs_for InConstr = InSel |
|
739 |
| in_fun_lhs_for _ = InFunLHS |
|
740 |
fun in_fun_rhs_for InConstr = InConstr |
|
741 |
| in_fun_rhs_for InSel = InSel |
|
742 |
| in_fun_rhs_for InFunRHS1 = InFunRHS2 |
|
743 |
| in_fun_rhs_for _ = InFunRHS1 |
|
744 |
||
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
745 |
fun is_boxing_worth_it (hol_ctxt : hol_context) boxy T = |
33192 | 746 |
case T of |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
747 |
Type (@{type_name fun}, _) => |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
748 |
(boxy = InPair orelse boxy = InFunLHS) andalso |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
749 |
not (is_boolean_type (body_type T)) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
750 |
| Type (@{type_name "*"}, Ts) => |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
751 |
boxy = InPair orelse boxy = InFunRHS1 orelse boxy = InFunRHS2 orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
752 |
((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
|
753 |
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
|
754 |
(map (box_type hol_ctxt InPair) Ts)) |
33192 | 755 |
| _ => false |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
756 |
and should_box_type (hol_ctxt as {thy, boxes, ...}) boxy z = |
33192 | 757 |
case triple_lookup (type_match thy) boxes (Type z) of |
758 |
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
|
759 |
| _ => 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
|
760 |
and box_type hol_ctxt boxy T = |
33192 | 761 |
case T of |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
762 |
Type (z as (@{type_name fun}, [T1, T2])) => |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
763 |
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
|
764 |
should_box_type hol_ctxt boxy z then |
33192 | 765 |
Type (@{type_name fun_box}, |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
766 |
[box_type hol_ctxt InFunLHS T1, box_type hol_ctxt InFunRHS1 T2]) |
33192 | 767 |
else |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
768 |
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
|
769 |
--> box_type hol_ctxt (in_fun_rhs_for boxy) T2 |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
770 |
| Type (z as (@{type_name "*"}, 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
|
771 |
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
|
772 |
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
|
773 |
Type (@{type_name pair_box}, map (box_type hol_ctxt InSel) Ts) |
33192 | 774 |
else |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
775 |
Type (@{type_name "*"}, |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
776 |
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
|
777 |
(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
|
778 |
else InPair)) Ts) |
33192 | 779 |
| _ => T |
780 |
||
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35181
diff
changeset
|
781 |
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
|
782 |
| 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
|
783 |
| 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
|
784 |
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
|
785 |
| 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
|
786 |
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
|
787 |
|
33192 | 788 |
fun discr_for_constr (s, T) = (discr_prefix ^ s, body_type T --> bool_T) |
789 |
||
790 |
fun num_sels_for_constr_type T = length (maybe_curried_binder_types T) |
|
791 |
fun nth_sel_name_for_constr_name s n = |
|
792 |
if s = @{const_name Pair} then |
|
793 |
if n = 0 then @{const_name fst} else @{const_name snd} |
|
794 |
else |
|
795 |
sel_prefix_for n ^ s |
|
796 |
fun nth_sel_for_constr x ~1 = discr_for_constr x |
|
797 |
| nth_sel_for_constr (s, T) n = |
|
798 |
(nth_sel_name_for_constr_name s n, |
|
799 |
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
|
800 |
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
|
801 |
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
|
802 |
oo nth_sel_for_constr |
33192 | 803 |
|
804 |
fun sel_no_from_name s = |
|
805 |
if String.isPrefix discr_prefix s then |
|
806 |
~1 |
|
807 |
else if String.isPrefix sel_prefix s then |
|
808 |
s |> unprefix sel_prefix |> Int.fromString |> the |
|
809 |
else if s = @{const_name snd} then |
|
810 |
1 |
|
811 |
else |
|
812 |
0 |
|
813 |
||
35078
6fd1052fe463
optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents:
35075
diff
changeset
|
814 |
val close_form = |
6fd1052fe463
optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents:
35075
diff
changeset
|
815 |
let |
6fd1052fe463
optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents:
35075
diff
changeset
|
816 |
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
|
817 |
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
|
818 |
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
|
819 |
(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
|
820 |
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
|
821 |
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
|
822 |
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
|
823 |
end |
6fd1052fe463
optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents:
35075
diff
changeset
|
824 |
| 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
|
825 |
in aux [] end |
6fd1052fe463
optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents:
35075
diff
changeset
|
826 |
|
33192 | 827 |
fun eta_expand _ t 0 = t |
828 |
| eta_expand Ts (Abs (s, T, t')) n = |
|
829 |
Abs (s, T, eta_expand (T :: Ts) t' (n - 1)) |
|
830 |
| eta_expand Ts t n = |
|
831 |
fold_rev (curry3 Abs ("x\<^isub>\<eta>" ^ nat_subscript n)) |
|
832 |
(List.take (binder_types (fastype_of1 (Ts, t)), n)) |
|
833 |
(list_comb (incr_boundvars n t, map Bound (n - 1 downto 0))) |
|
834 |
||
835 |
fun extensionalize t = |
|
836 |
case t of |
|
837 |
(t0 as @{const Trueprop}) $ t1 => t0 $ extensionalize t1 |
|
838 |
| Const (@{const_name "op ="}, _) $ t1 $ Abs (s, T, t2) => |
|
839 |
let val v = Var ((s, maxidx_of_term t + 1), T) in |
|
840 |
extensionalize (HOLogic.mk_eq (t1 $ v, subst_bound (v, t2))) |
|
841 |
end |
|
842 |
| _ => t |
|
843 |
||
844 |
fun distinctness_formula T = |
|
845 |
all_distinct_unordered_pairs_of |
|
846 |
#> map (fn (t1, t2) => @{const Not} $ (HOLogic.eq_const T $ t1 $ t2)) |
|
847 |
#> List.foldr (s_conj o swap) @{const True} |
|
848 |
||
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
|
849 |
fun zero_const T = Const (@{const_name zero_class.zero}, T) |
33192 | 850 |
fun suc_const T = Const (@{const_name Suc}, T --> T) |
851 |
||
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
852 |
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
|
853 |
(T as Type (s, Ts)) = |
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
854 |
(case AList.lookup (op =) (#codatatypes (Data.get thy)) s of |
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
|
855 |
SOME (_, xs' as (_ :: _)) => map (apsnd (repair_constr_type thy T)) xs' |
33581
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
856 |
| _ => |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
857 |
if is_datatype ctxt stds T then |
33581
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
858 |
case Datatype.get_info thy s of |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
859 |
SOME {index, descr, ...} => |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
860 |
let |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
861 |
val (_, dtyps, constrs) = AList.lookup (op =) descr index |> the |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
862 |
in |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
863 |
map (fn (s', Us) => |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
864 |
(s', map (Refute.typ_of_dtyp descr (dtyps ~~ Ts)) Us |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
865 |
---> T)) constrs |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
866 |
end |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
867 |
| NONE => |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
868 |
if is_record_type T then |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
869 |
let |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
870 |
val s' = unsuffix Record.ext_typeN s ^ Record.extN |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
871 |
val T' = (Record.get_extT_fields thy T |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
872 |
|> apsnd single |> uncurry append |> map snd) ---> T |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
873 |
in [(s', T')] end |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
874 |
else if is_quot_type thy T then |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
875 |
[(@{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
|
876 |
else case typedef_info ctxt s of |
33581
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
877 |
SOME {abs_type, rep_type, Abs_name, ...} => |
35311 | 878 |
[(Abs_name, |
879 |
varify_and_instantiate_type thy abs_type T rep_type --> T)] |
|
33581
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
880 |
| NONE => |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
881 |
if T = @{typ ind} then |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
882 |
[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
|
883 |
else |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
884 |
[] |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
885 |
else |
e1e77265fb1d
added possibility to register datatypes as codatatypes in Nitpick;
blanchet
parents:
33580
diff
changeset
|
886 |
[]) |
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
|
887 |
| 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
|
888 |
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
|
889 |
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
|
890 |
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
|
891 |
| 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
|
892 |
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
|
893 |
(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
|
894 |
end |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35181
diff
changeset
|
895 |
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
|
896 |
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
|
897 |
o box_type hol_ctxt InConstr)) o datatype_constrs hol_ctxt |
33192 | 898 |
val num_datatype_constrs = length oo datatype_constrs |
899 |
||
900 |
fun constr_name_for_sel_like @{const_name fst} = @{const_name Pair} |
|
901 |
| constr_name_for_sel_like @{const_name snd} = @{const_name Pair} |
|
902 |
| 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
|
903 |
fun binarized_and_boxed_constr_for_sel hol_ctxt binarize (s', T') = |
33192 | 904 |
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
|
905 |
AList.lookup (op =) |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35181
diff
changeset
|
906 |
(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
|
907 |
s |
33192 | 908 |
|> the |> pair s |
909 |
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
|
910 |
|
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
911 |
fun discr_term_for_constr hol_ctxt (x as (s, T)) = |
33192 | 912 |
let val dataT = body_type T in |
913 |
if s = @{const_name Suc} then |
|
914 |
Abs (Name.uu, dataT, |
|
915 |
@{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
|
916 |
else if num_datatype_constrs hol_ctxt dataT >= 2 then |
33192 | 917 |
Const (discr_for_constr x) |
918 |
else |
|
919 |
Abs (Name.uu, dataT, @{const True}) |
|
920 |
end |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
921 |
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
|
922 |
case head_of t of |
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
923 |
Const x' => |
33192 | 924 |
if x = x' then @{const True} |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
925 |
else if is_constr_like ctxt x' then @{const False} |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
926 |
else betapply (discr_term_for_constr hol_ctxt x, t) |
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
927 |
| _ => betapply (discr_term_for_constr hol_ctxt x, t) |
33192 | 928 |
|
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
|
929 |
fun nth_arg_sel_term_for_constr thy stds (x as (s, T)) n = |
33192 | 930 |
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
|
931 |
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
|
932 |
@{term "%n::nat. n - 1"} |
33192 | 933 |
else if is_pair_type dataT then |
934 |
Const (nth_sel_for_constr x n) |
|
935 |
else |
|
936 |
let |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
937 |
fun aux m (Type (@{type_name "*"}, [T1, T2])) = |
33192 | 938 |
let |
939 |
val (m, t1) = aux m T1 |
|
940 |
val (m, t2) = aux m T2 |
|
941 |
in (m, HOLogic.mk_prod (t1, t2)) end |
|
942 |
| aux m T = |
|
943 |
(m + 1, Const (nth_sel_name_for_constr_name s m, dataT --> T) |
|
944 |
$ Bound 0) |
|
945 |
val m = fold (Integer.add o num_factors_in_type) |
|
946 |
(List.take (arg_Ts, n)) 0 |
|
947 |
in Abs ("x", dataT, aux m (nth arg_Ts n) |> snd) end |
|
948 |
end |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
949 |
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
|
950 |
let val thy = ProofContext.theory_of ctxt in |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
951 |
(case strip_comb t of |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
952 |
(Const x', args) => |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
953 |
if x = x' then nth args n |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
954 |
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
|
955 |
else raise SAME () |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
956 |
| _ => raise SAME()) |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
957 |
handle SAME () => betapply (nth_arg_sel_term_for_constr thy stds x n, t) |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
958 |
end |
33192 | 959 |
|
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
|
960 |
fun construct_value _ _ x [] = Const x |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
961 |
| construct_value ctxt stds (x as (s, _)) args = |
33192 | 962 |
let val args = map Envir.eta_contract args in |
963 |
case hd args of |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
964 |
Const (s', _) $ t => |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
965 |
if is_sel_like_and_no_discr s' andalso |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
966 |
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
|
967 |
forall (fn (n, t') => |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
968 |
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
|
969 |
(index_seq 0 (length args) ~~ args) then |
33192 | 970 |
t |
971 |
else |
|
972 |
list_comb (Const x, args) |
|
973 |
| _ => list_comb (Const x, args) |
|
974 |
end |
|
975 |
||
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
976 |
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
|
977 |
(case head_of t of |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
978 |
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
|
979 |
| _ => raise SAME ()) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
980 |
handle SAME () => |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
981 |
let |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
982 |
val x' as (_, T') = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
983 |
if is_pair_type T then |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
984 |
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
|
985 |
(@{const_name Pair}, T1 --> T2 --> T) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
986 |
end |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
987 |
else |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
988 |
datatype_constrs hol_ctxt T |> hd |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
989 |
val arg_Ts = binder_types T' |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
990 |
in |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
991 |
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
|
992 |
(index_seq 0 (length arg_Ts)) arg_Ts) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
993 |
end |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
994 |
|
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
995 |
fun coerce_bound_no f j t = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
996 |
case t of |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
997 |
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
|
998 |
| 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
|
999 |
| 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
|
1000 |
| _ => t |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1001 |
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
|
1002 |
old_T <> new_T ? coerce_bound_no (coerce_term hol_ctxt [new_T] old_T new_T) 0 |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1003 |
and coerce_term (hol_ctxt as {ctxt, stds, fast_descrs, ...}) Ts new_T old_T t = |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1004 |
if old_T = new_T then |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1005 |
t |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1006 |
else |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1007 |
case (new_T, old_T) of |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1008 |
(Type (new_s, new_Ts as [new_T1, new_T2]), |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1009 |
Type (@{type_name fun}, [old_T1, old_T2])) => |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1010 |
(case eta_expand Ts t 1 of |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1011 |
Abs (s, _, t') => |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1012 |
Abs (s, new_T1, |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1013 |
t' |> coerce_bound_0_in_term hol_ctxt new_T1 old_T1 |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1014 |
|> coerce_term hol_ctxt (new_T1 :: Ts) new_T2 old_T2) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1015 |
|> Envir.eta_contract |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1016 |
|> new_s <> @{type_name fun} |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1017 |
? construct_value ctxt stds |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1018 |
(if new_s = @{type_name fin_fun} then @{const_name FinFun} |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1019 |
else @{const_name FunBox}, |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1020 |
Type (@{type_name fun}, new_Ts) --> new_T) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1021 |
o single |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1022 |
| t' => raise TERM ("Nitpick_HOL.coerce_term", [t'])) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1023 |
| (Type (new_s, new_Ts as [new_T1, new_T2]), |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1024 |
Type (old_s, old_Ts as [old_T1, old_T2])) => |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1025 |
if old_s = @{type_name fin_fun} orelse old_s = @{type_name fun_box} orelse |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1026 |
old_s = @{type_name pair_box} orelse old_s = @{type_name "*"} then |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1027 |
case constr_expand hol_ctxt old_T t of |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1028 |
Const (old_s, _) $ t1 => |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1029 |
if new_s = @{type_name fun} then |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1030 |
coerce_term hol_ctxt Ts new_T (Type (@{type_name fun}, old_Ts)) t1 |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1031 |
else |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1032 |
construct_value ctxt stds |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1033 |
(old_s, Type (@{type_name fun}, new_Ts) --> new_T) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1034 |
[coerce_term hol_ctxt Ts (Type (@{type_name fun}, new_Ts)) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1035 |
(Type (@{type_name fun}, old_Ts)) t1] |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1036 |
| Const _ $ t1 $ t2 => |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1037 |
construct_value ctxt stds |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1038 |
(if new_s = @{type_name "*"} then @{const_name Pair} |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1039 |
else @{const_name PairBox}, new_Ts ---> new_T) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1040 |
(map3 (coerce_term hol_ctxt Ts) [new_T1, new_T2] [old_T1, old_T2] |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1041 |
[t1, t2]) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1042 |
| t' => raise TERM ("Nitpick_HOL.coerce_term", [t']) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1043 |
else |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1044 |
raise TYPE ("Nitpick_HOL.coerce_term", [new_T, old_T], [t]) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1045 |
| _ => raise TYPE ("Nitpick_HOL.coerce_term", [new_T, old_T], [t]) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1046 |
|
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1047 |
fun card_of_type assigns (Type (@{type_name fun}, [T1, T2])) = |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1048 |
reasonable_power (card_of_type assigns T2) (card_of_type assigns T1) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1049 |
| card_of_type assigns (Type (@{type_name "*"}, [T1, T2])) = |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1050 |
card_of_type assigns T1 * card_of_type assigns T2 |
33192 | 1051 |
| card_of_type _ (Type (@{type_name itself}, _)) = 1 |
1052 |
| card_of_type _ @{typ prop} = 2 |
|
1053 |
| card_of_type _ @{typ bool} = 2 |
|
1054 |
| card_of_type _ @{typ unit} = 1 |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1055 |
| card_of_type assigns T = |
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1056 |
case AList.lookup (op =) assigns T of |
33192 | 1057 |
SOME k => k |
1058 |
| NONE => if T = @{typ bisim_iterator} then 0 |
|
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
1059 |
else raise TYPE ("Nitpick_HOL.card_of_type", [T], []) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1060 |
fun bounded_card_of_type max default_card assigns |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1061 |
(Type (@{type_name fun}, [T1, T2])) = |
33192 | 1062 |
let |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1063 |
val k1 = bounded_card_of_type max default_card assigns T1 |
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1064 |
val k2 = bounded_card_of_type max default_card assigns T2 |
33192 | 1065 |
in |
1066 |
if k1 = max orelse k2 = max then max |
|
1067 |
else Int.min (max, reasonable_power k2 k1) |
|
1068 |
end |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1069 |
| bounded_card_of_type max default_card assigns |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1070 |
(Type (@{type_name "*"}, [T1, T2])) = |
33192 | 1071 |
let |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1072 |
val k1 = bounded_card_of_type max default_card assigns T1 |
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1073 |
val k2 = bounded_card_of_type max default_card assigns T2 |
33192 | 1074 |
in if k1 = max orelse k2 = max then max else Int.min (max, k1 * k2) end |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1075 |
| bounded_card_of_type max default_card assigns T = |
33192 | 1076 |
Int.min (max, if default_card = ~1 then |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1077 |
card_of_type assigns T |
33192 | 1078 |
else |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1079 |
card_of_type assigns T |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
1080 |
handle TYPE ("Nitpick_HOL.card_of_type", _, _) => |
33192 | 1081 |
default_card) |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35384
diff
changeset
|
1082 |
fun bounded_exact_card_of_type hol_ctxt finitizable_dataTs max default_card |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35384
diff
changeset
|
1083 |
assigns T = |
33192 | 1084 |
let |
1085 |
fun aux avoid T = |
|
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33978
diff
changeset
|
1086 |
(if member (op =) avoid T then |
33192 | 1087 |
0 |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35384
diff
changeset
|
1088 |
else if member (op =) finitizable_dataTs T then |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35384
diff
changeset
|
1089 |
raise SAME () |
33192 | 1090 |
else case T of |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1091 |
Type (@{type_name fun}, [T1, T2]) => |
33192 | 1092 |
let |
1093 |
val k1 = aux avoid T1 |
|
1094 |
val k2 = aux avoid T2 |
|
1095 |
in |
|
1096 |
if k1 = 0 orelse k2 = 0 then 0 |
|
1097 |
else if k1 >= max orelse k2 >= max then max |
|
1098 |
else Int.min (max, reasonable_power k2 k1) |
|
1099 |
end |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1100 |
| Type (@{type_name "*"}, [T1, T2]) => |
33192 | 1101 |
let |
1102 |
val k1 = aux avoid T1 |
|
1103 |
val k2 = aux avoid T2 |
|
1104 |
in |
|
1105 |
if k1 = 0 orelse k2 = 0 then 0 |
|
1106 |
else if k1 >= max orelse k2 >= max then max |
|
1107 |
else Int.min (max, k1 * k2) |
|
1108 |
end |
|
1109 |
| Type (@{type_name itself}, _) => 1 |
|
1110 |
| @{typ prop} => 2 |
|
1111 |
| @{typ bool} => 2 |
|
1112 |
| @{typ unit} => 1 |
|
1113 |
| Type _ => |
|
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
1114 |
(case datatype_constrs hol_ctxt T of |
34126 | 1115 |
[] => if is_integer_type T orelse is_bit_type T then 0 |
1116 |
else raise SAME () |
|
33192 | 1117 |
| constrs => |
1118 |
let |
|
1119 |
val constr_cards = |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
1120 |
map (Integer.prod o map (aux (T :: avoid)) o binder_types o snd) |
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
1121 |
constrs |
33192 | 1122 |
in |
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33978
diff
changeset
|
1123 |
if exists (curry (op =) 0) constr_cards then 0 |
33192 | 1124 |
else Integer.sum constr_cards |
1125 |
end) |
|
1126 |
| _ => raise SAME ()) |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1127 |
handle SAME () => |
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1128 |
AList.lookup (op =) assigns T |> the_default default_card |
33192 | 1129 |
in Int.min (max, aux [] T) end |
1130 |
||
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1131 |
val small_type_max_card = 5 |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1132 |
|
35384 | 1133 |
fun is_finite_type hol_ctxt T = |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1134 |
bounded_exact_card_of_type hol_ctxt [] 1 2 [] T > 0 |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1135 |
fun is_small_finite_type hol_ctxt T = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1136 |
let val n = bounded_exact_card_of_type hol_ctxt [] 1 2 [] T in |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1137 |
n > 0 andalso n <= small_type_max_card |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1138 |
end |
33192 | 1139 |
|
1140 |
fun is_ground_term (t1 $ t2) = is_ground_term t1 andalso is_ground_term t2 |
|
1141 |
| is_ground_term (Const _) = true |
|
1142 |
| is_ground_term _ = false |
|
1143 |
||
36062 | 1144 |
fun hashw_term (t1 $ t2) = hashw (hashw_term t1, hashw_term t2) |
1145 |
| hashw_term (Const (s, _)) = hashw_string (s, 0w0) |
|
33192 | 1146 |
| hashw_term _ = 0w0 |
1147 |
val hash_term = Word.toInt o hashw_term |
|
1148 |
||
1149 |
fun special_bounds ts = |
|
35408 | 1150 |
fold Term.add_vars ts [] |> sort (Term_Ord.fast_indexname_ord o pairself fst) |
33192 | 1151 |
|
1152 |
fun abs_var ((s, j), T) body = Abs (s, T, abstract_over (Var ((s, j), T), body)) |
|
1153 |
||
33571 | 1154 |
fun is_funky_typedef_name thy s = |
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33978
diff
changeset
|
1155 |
member (op =) [@{type_name unit}, @{type_name "*"}, @{type_name "+"}, |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
1156 |
@{type_name int}] s orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
1157 |
is_frac_type thy (Type (s, [])) |
33571 | 1158 |
fun is_funky_typedef thy (Type (s, _)) = is_funky_typedef_name thy s |
1159 |
| is_funky_typedef _ _ = false |
|
33192 | 1160 |
fun is_arity_type_axiom (Const (@{const_name HOL.type_class}, _) |
1161 |
$ Const (@{const_name TYPE}, _)) = true |
|
1162 |
| is_arity_type_axiom _ = false |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1163 |
fun is_typedef_axiom ctxt boring (@{const "==>"} $ _ $ t2) = |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1164 |
is_typedef_axiom ctxt boring t2 |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1165 |
| is_typedef_axiom ctxt boring |
33192 | 1166 |
(@{const Trueprop} $ (Const (@{const_name Typedef.type_definition}, _) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1167 |
$ Const (_, Type (@{type_name fun}, [Type (s, _), _])) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1168 |
$ Const _ $ _)) = |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1169 |
let val thy = ProofContext.theory_of ctxt in |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1170 |
boring <> is_funky_typedef_name thy s andalso is_typedef ctxt s |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1171 |
end |
33192 | 1172 |
| is_typedef_axiom _ _ _ = false |
36126 | 1173 |
val is_class_axiom = |
1174 |
Logic.strip_horn #> swap #> op :: #> forall (can Logic.dest_of_class) |
|
33192 | 1175 |
|
1176 |
(* Distinguishes between (1) constant definition axioms, (2) type arity and |
|
1177 |
typedef axioms, and (3) other axioms, and returns the pair ((1), (3)). |
|
1178 |
Typedef axioms are uninteresting to Nitpick, because it can retrieve them |
|
1179 |
using "typedef_info". *) |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1180 |
fun partition_axioms_by_definitionality ctxt axioms def_names = |
33192 | 1181 |
let |
1182 |
val axioms = sort (fast_string_ord o pairself fst) axioms |
|
1183 |
val defs = OrdList.inter (fast_string_ord o apsnd fst) def_names axioms |
|
1184 |
val nondefs = |
|
1185 |
OrdList.subtract (fast_string_ord o apsnd fst) def_names axioms |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1186 |
|> filter_out ((is_arity_type_axiom orf is_typedef_axiom ctxt true) o snd) |
33192 | 1187 |
in pairself (map snd) (defs, nondefs) end |
1188 |
||
33197
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
blanchet
parents:
33192
diff
changeset
|
1189 |
(* Ideally we would check against "Complex_Main", not "Refute", but any theory |
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
blanchet
parents:
33192
diff
changeset
|
1190 |
will do as long as it contains all the "axioms" and "axiomatization" |
33192 | 1191 |
commands. *) |
1192 |
fun is_built_in_theory thy = Theory.subthy (thy, @{theory Refute}) |
|
1193 |
||
35283
7ae51d5ea05d
filter out trivial definitions in Nitpick (e.g. "Topology.topo" from AFP)
blanchet
parents:
35280
diff
changeset
|
1194 |
val is_trivial_definition = |
7ae51d5ea05d
filter out trivial definitions in Nitpick (e.g. "Topology.topo" from AFP)
blanchet
parents:
35280
diff
changeset
|
1195 |
the_default false o try (op aconv o Logic.dest_equals) |
33192 | 1196 |
val is_plain_definition = |
1197 |
let |
|
1198 |
fun do_lhs t1 = |
|
1199 |
case strip_comb t1 of |
|
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
1200 |
(Const _, args) => |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
1201 |
forall is_Var args andalso not (has_duplicates (op =) args) |
33192 | 1202 |
| _ => false |
1203 |
fun do_eq (Const (@{const_name "=="}, _) $ t1 $ _) = do_lhs t1 |
|
1204 |
| do_eq (@{const Trueprop} $ (Const (@{const_name "op ="}, _) $ t1 $ _)) = |
|
1205 |
do_lhs t1 |
|
1206 |
| do_eq _ = false |
|
1207 |
in do_eq end |
|
1208 |
||
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1209 |
fun all_axioms_of ctxt subst = |
33192 | 1210 |
let |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1211 |
val thy = ProofContext.theory_of ctxt |
35335 | 1212 |
val axioms_of_thys = |
35893 | 1213 |
maps Thm.axioms_of |
1214 |
#> map (apsnd (subst_atomic subst o prop_of)) |
|
1215 |
#> filter_out (is_class_axiom o snd) |
|
33192 | 1216 |
val specs = Defs.all_specifications_of (Theory.defs_of thy) |
33701
9dd1079cec3a
primitive defs: clarified def (axiom name) vs. description;
wenzelm
parents:
33699
diff
changeset
|
1217 |
val def_names = specs |> maps snd |> map_filter #def |
33197
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
blanchet
parents:
33192
diff
changeset
|
1218 |
|> OrdList.make fast_string_ord |
33192 | 1219 |
val thys = thy :: Theory.ancestors_of thy |
1220 |
val (built_in_thys, user_thys) = List.partition is_built_in_theory thys |
|
1221 |
val built_in_axioms = axioms_of_thys built_in_thys |
|
1222 |
val user_axioms = axioms_of_thys user_thys |
|
1223 |
val (built_in_defs, built_in_nondefs) = |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1224 |
partition_axioms_by_definitionality ctxt built_in_axioms def_names |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
37253
diff
changeset
|
1225 |
||> filter (is_typedef_axiom ctxt false) |
33192 | 1226 |
val (u |