author | blanchet |
Tue, 08 Nov 2011 08:56:24 +0100 | |
changeset 45402 | 1fac64bbdb4f |
parent 45399 | fdc73782278f |
child 46083 | efeaa79f021b |
permissions | -rw-r--r-- |
33982 | 1 |
(* Title: HOL/Tools/Nitpick/nitpick_scope.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 |
Scope enumerator for Nitpick. |
|
6 |
*) |
|
7 |
||
8 |
signature NITPICK_SCOPE = |
|
9 |
sig |
|
33705
947184dc75c9
removed a few global names in Nitpick (styp, nat_less, pairf)
blanchet
parents:
33580
diff
changeset
|
10 |
type styp = Nitpick_Util.styp |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34982
diff
changeset
|
11 |
type hol_context = Nitpick_HOL.hol_context |
33192 | 12 |
|
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
13 |
type constr_spec = |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
14 |
{const: styp, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
15 |
delta: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
16 |
epsilon: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
17 |
exclusive: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
18 |
explicit_max: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
19 |
total: bool} |
33192 | 20 |
|
38126 | 21 |
type datatype_spec = |
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
22 |
{typ: typ, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
23 |
card: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
24 |
co: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
25 |
standard: bool, |
38126 | 26 |
self_rec: bool, |
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
27 |
complete: bool * bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
28 |
concrete: bool * bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
29 |
deep: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
30 |
constrs: constr_spec list} |
33192 | 31 |
|
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
32 |
type scope = |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
33 |
{hol_ctxt: hol_context, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
34 |
binarize: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
35 |
card_assigns: (typ * int) list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
36 |
bits: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
37 |
bisim_depth: int, |
38126 | 38 |
datatypes: datatype_spec list, |
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
39 |
ofs: int Typtab.table} |
33192 | 40 |
|
38127 | 41 |
val is_asymmetric_nondatatype : typ -> bool |
38126 | 42 |
val datatype_spec : datatype_spec list -> typ -> datatype_spec option |
43 |
val constr_spec : datatype_spec list -> styp -> constr_spec |
|
44 |
val is_complete_type : datatype_spec list -> bool -> typ -> bool |
|
45 |
val is_concrete_type : datatype_spec list -> bool -> typ -> bool |
|
46 |
val is_exact_type : datatype_spec list -> bool -> typ -> bool |
|
33192 | 47 |
val offset_of_type : int Typtab.table -> typ -> int |
48 |
val spec_of_type : scope -> typ -> int * int |
|
49 |
val pretties_for_scope : scope -> bool -> Pretty.T list |
|
50 |
val multiline_string_for_scope : scope -> string |
|
35814 | 51 |
val scopes_equivalent : scope * scope -> bool |
33192 | 52 |
val scope_less_eq : scope -> scope -> bool |
38126 | 53 |
val is_self_recursive_constr_type : typ -> bool |
33192 | 54 |
val all_scopes : |
36386
2132f15b366f
Fruhjahrsputz: remove three mostly useless Nitpick options
blanchet
parents:
36385
diff
changeset
|
55 |
hol_context -> bool -> (typ option * int list) list |
33192 | 56 |
-> (styp option * int list) list -> (styp option * int list) list |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
57 |
-> int list -> int list -> typ list -> typ list -> typ list -> typ list |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
58 |
-> int * scope list |
33192 | 59 |
end; |
60 |
||
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
61 |
structure Nitpick_Scope : NITPICK_SCOPE = |
33192 | 62 |
struct |
63 |
||
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
64 |
open Nitpick_Util |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
65 |
open Nitpick_HOL |
33192 | 66 |
|
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
67 |
type constr_spec = |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
68 |
{const: styp, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
69 |
delta: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
70 |
epsilon: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
71 |
exclusive: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
72 |
explicit_max: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
73 |
total: bool} |
33192 | 74 |
|
38126 | 75 |
type datatype_spec = |
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
76 |
{typ: typ, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
77 |
card: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
78 |
co: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
79 |
standard: bool, |
38126 | 80 |
self_rec: bool, |
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
81 |
complete: bool * bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
82 |
concrete: bool * bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
83 |
deep: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
84 |
constrs: constr_spec list} |
33192 | 85 |
|
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
86 |
type scope = |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
87 |
{hol_ctxt: hol_context, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
88 |
binarize: bool, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
89 |
card_assigns: (typ * int) list, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
90 |
bits: int, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
91 |
bisim_depth: int, |
38126 | 92 |
datatypes: datatype_spec list, |
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36386
diff
changeset
|
93 |
ofs: int Typtab.table} |
33192 | 94 |
|
95 |
datatype row_kind = Card of typ | Max of styp |
|
96 |
||
97 |
type row = row_kind * int list |
|
98 |
type block = row list |
|
99 |
||
38127 | 100 |
val is_asymmetric_nondatatype = |
101 |
is_iterator_type orf is_integer_type orf is_bit_type |
|
102 |
||
38126 | 103 |
fun datatype_spec (dtypes : datatype_spec list) T = |
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
104 |
List.find (curry (op =) T o #typ) dtypes |
33192 | 105 |
|
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
106 |
fun constr_spec [] x = raise TERM ("Nitpick_Scope.constr_spec", [Const x]) |
38126 | 107 |
| constr_spec ({constrs, ...} :: dtypes : datatype_spec list) (x as (s, T)) = |
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
108 |
case List.find (curry (op =) (s, body_type T) o (apsnd body_type o #const)) |
33192 | 109 |
constrs of |
110 |
SOME c => c |
|
111 |
| NONE => constr_spec dtypes x |
|
112 |
||
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35385
diff
changeset
|
113 |
fun is_complete_type dtypes facto (Type (@{type_name fun}, [T1, T2])) = |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
114 |
is_concrete_type dtypes facto T1 andalso is_complete_type dtypes facto T2 |
38190
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38188
diff
changeset
|
115 |
| is_complete_type dtypes facto (Type (@{type_name prod}, Ts)) = |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
116 |
forall (is_complete_type dtypes facto) Ts |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
117 |
| is_complete_type dtypes facto 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
|
118 |
not (is_integer_like_type T) andalso not (is_bit_type T) andalso |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
119 |
fun_from_pair (#complete (the (datatype_spec dtypes T))) facto |
33192 | 120 |
handle Option.Option => true |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35385
diff
changeset
|
121 |
and is_concrete_type dtypes facto (Type (@{type_name fun}, [T1, T2])) = |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
122 |
is_complete_type dtypes facto T1 andalso is_concrete_type dtypes facto T2 |
38190
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
blanchet
parents:
38188
diff
changeset
|
123 |
| is_concrete_type dtypes facto (Type (@{type_name prod}, Ts)) = |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
124 |
forall (is_concrete_type dtypes facto) Ts |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
125 |
| is_concrete_type dtypes facto T = |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
126 |
fun_from_pair (#concrete (the (datatype_spec dtypes T))) facto |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
127 |
handle Option.Option => true |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35385
diff
changeset
|
128 |
and is_exact_type dtypes facto = |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
129 |
is_complete_type dtypes facto andf is_concrete_type dtypes facto |
33192 | 130 |
|
131 |
fun offset_of_type ofs T = |
|
132 |
case Typtab.lookup ofs T of |
|
133 |
SOME j0 => j0 |
|
134 |
| NONE => Typtab.lookup ofs dummyT |> the_default 0 |
|
135 |
||
136 |
fun spec_of_type ({card_assigns, ofs, ...} : scope) T = |
|
137 |
(card_of_type card_assigns T |
|
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
138 |
handle TYPE ("Nitpick_HOL.card_of_type", _, _) => ~1, offset_of_type ofs T) |
33192 | 139 |
|
38188 | 140 |
fun quintuple_for_scope code_type code_term code_string |
39118
12f3788be67b
turned show_all_types into proper configuration option;
wenzelm
parents:
38240
diff
changeset
|
141 |
({hol_ctxt = {ctxt = ctxt0, stds, ...}, card_assigns, bits, bisim_depth, |
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
|
142 |
datatypes, ...} : scope) = |
33192 | 143 |
let |
39118
12f3788be67b
turned show_all_types into proper configuration option;
wenzelm
parents:
38240
diff
changeset
|
144 |
val ctxt = set_show_all_types ctxt0 |
35075
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35072
diff
changeset
|
145 |
val boring_Ts = [@{typ unsigned_bit}, @{typ signed_bit}, |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
146 |
@{typ bisim_iterator}] |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
147 |
val (iter_assigns, card_assigns) = |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
148 |
card_assigns |> filter_out (member (op =) boring_Ts o fst) |
33192 | 149 |
|> List.partition (is_fp_iterator_type o fst) |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
150 |
val (secondary_card_assigns, primary_card_assigns) = |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
36390
diff
changeset
|
151 |
card_assigns |
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
36390
diff
changeset
|
152 |
|> List.partition ((is_integer_type orf is_datatype ctxt stds) o fst) |
33192 | 153 |
val cards = |
38188 | 154 |
map (fn (T, k) => |
155 |
[code_type ctxt T, code_string (" = " ^ string_of_int k)]) |
|
33192 | 156 |
fun maxes () = |
157 |
maps (map_filter |
|
158 |
(fn {const, explicit_max, ...} => |
|
159 |
if explicit_max < 0 then |
|
160 |
NONE |
|
161 |
else |
|
38188 | 162 |
SOME [code_term ctxt (Const const), |
163 |
code_string (" = " ^ string_of_int explicit_max)]) |
|
33192 | 164 |
o #constrs) datatypes |
165 |
fun iters () = |
|
166 |
map (fn (T, k) => |
|
38188 | 167 |
[code_term ctxt (Const (const_for_iterator_type T)), |
168 |
code_string (" = " ^ string_of_int (k - 1))]) iter_assigns |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
169 |
fun miscs () = |
38188 | 170 |
(if bits = 0 then [] |
171 |
else [code_string ("bits = " ^ string_of_int bits)]) @ |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
172 |
(if bisim_depth < 0 andalso forall (not o #co) datatypes then [] |
38188 | 173 |
else [code_string ("bisim_depth = " ^ signed_string_of_int bisim_depth)]) |
33192 | 174 |
in |
39118
12f3788be67b
turned show_all_types into proper configuration option;
wenzelm
parents:
38240
diff
changeset
|
175 |
(cards primary_card_assigns, cards secondary_card_assigns, |
12f3788be67b
turned show_all_types into proper configuration option;
wenzelm
parents:
38240
diff
changeset
|
176 |
maxes (), iters (), miscs ()) |
33192 | 177 |
end |
178 |
||
179 |
fun pretties_for_scope scope verbose = |
|
180 |
let |
|
38188 | 181 |
fun standard_blocks s = map (Pretty.block o cons (Pretty.str (s ^ " "))) |
182 |
val (primary_cards, secondary_cards, maxes, iters, miscs) = |
|
183 |
quintuple_for_scope (pretty_maybe_quote oo pretty_for_type) |
|
184 |
(pretty_maybe_quote oo Syntax.pretty_term) |
|
185 |
Pretty.str scope |
|
33192 | 186 |
in |
38188 | 187 |
standard_blocks "card" primary_cards @ |
188 |
(if verbose then |
|
189 |
standard_blocks "card" secondary_cards @ |
|
190 |
standard_blocks "max" maxes @ |
|
191 |
standard_blocks "iter" iters @ |
|
192 |
miscs |
|
193 |
else |
|
194 |
[]) |
|
195 |
|> pretty_serial_commas "and" |
|
33192 | 196 |
end |
197 |
||
198 |
fun multiline_string_for_scope scope = |
|
199 |
let |
|
38188 | 200 |
val (primary_cards, secondary_cards, maxes, iters, miscs) = |
201 |
quintuple_for_scope Syntax.string_of_typ Syntax.string_of_term I scope |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
202 |
val cards = primary_cards @ secondary_cards |
33192 | 203 |
in |
38188 | 204 |
case (if null cards then [] else ["card: " ^ commas (map implode cards)]) @ |
205 |
(if null maxes then [] else ["max: " ^ commas (map implode maxes)]) @ |
|
206 |
(if null iters then [] else ["iter: " ^ commas (map implode iters)]) @ |
|
207 |
miscs of |
|
33192 | 208 |
[] => "empty" |
209 |
| lines => space_implode "\n" lines |
|
210 |
end |
|
211 |
||
35814 | 212 |
fun scopes_equivalent (s1 : scope, s2 : scope) = |
33192 | 213 |
#datatypes s1 = #datatypes s2 andalso #card_assigns s1 = #card_assigns s2 |
214 |
fun scope_less_eq (s1 : scope) (s2 : scope) = |
|
215 |
(s1, s2) |> pairself (map snd o #card_assigns) |> op ~~ |> forall (op <=) |
|
216 |
||
217 |
fun rank_of_row (_, ks) = length ks |
|
218 |
fun rank_of_block block = fold Integer.max (map rank_of_row block) 1 |
|
41991
ea02b9ee3085
prevent an exception if "card" is empty (e.g., "nitpick [card]")
blanchet
parents:
41052
diff
changeset
|
219 |
fun project_row _ (y, []) = (y, [1]) (* desperate measure *) |
ea02b9ee3085
prevent an exception if "card" is empty (e.g., "nitpick [card]")
blanchet
parents:
41052
diff
changeset
|
220 |
| project_row column (y, ks) = (y, [nth ks (Int.min (column, length ks - 1))]) |
33192 | 221 |
fun project_block (column, block) = map (project_row column) block |
222 |
||
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
223 |
fun lookup_ints_assign eq assigns key = |
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
224 |
case triple_lookup eq assigns key of |
33192 | 225 |
SOME ks => ks |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
226 |
| NONE => raise ARG ("Nitpick_Scope.lookup_ints_assign", "") |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
227 |
fun lookup_type_ints_assign thy assigns T = |
36384 | 228 |
map (Integer.max 1) (lookup_ints_assign (type_match thy) assigns T) |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
229 |
handle ARG ("Nitpick_Scope.lookup_ints_assign", _) => |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
230 |
raise TYPE ("Nitpick_Scope.lookup_type_ints_assign", [T], []) |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
231 |
fun lookup_const_ints_assign thy assigns x = |
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
232 |
lookup_ints_assign (const_match thy) assigns x |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
233 |
handle ARG ("Nitpick_Scope.lookup_ints_assign", _) => |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33192
diff
changeset
|
234 |
raise TERM ("Nitpick_Scope.lookup_const_ints_assign", [Const x]) |
33192 | 235 |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
236 |
fun row_for_constr thy maxes_assigns constr = |
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
237 |
SOME (Max constr, lookup_const_ints_assign thy maxes_assigns constr) |
33192 | 238 |
handle TERM ("lookup_const_ints_assign", _) => NONE |
239 |
||
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
240 |
val max_bits = 31 (* Kodkod limit *) |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
241 |
|
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
242 |
fun block_for_type (hol_ctxt as {thy, ...}) binarize cards_assigns maxes_assigns |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
243 |
iters_assigns bitss bisim_depths T = |
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
244 |
case T of |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
245 |
@{typ unsigned_bit} => |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
246 |
[(Card T, map (Integer.min max_bits o Integer.max 1) bitss)] |
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
247 |
| @{typ signed_bit} => |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
248 |
[(Card T, map (Integer.add 1 o Integer.min max_bits o Integer.max 1) bitss)] |
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
249 |
| @{typ "unsigned_bit word"} => |
34126 | 250 |
[(Card T, lookup_type_ints_assign thy cards_assigns nat_T)] |
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
251 |
| @{typ "signed_bit word"} => |
34126 | 252 |
[(Card T, lookup_type_ints_assign thy cards_assigns int_T)] |
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
253 |
| @{typ bisim_iterator} => |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
254 |
[(Card T, map (Integer.add 1 o Integer.max 0) bisim_depths)] |
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
255 |
| _ => |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
256 |
if is_fp_iterator_type T then |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
257 |
[(Card T, map (Integer.add 1 o Integer.max 0) |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
258 |
(lookup_const_ints_assign thy iters_assigns |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
259 |
(const_for_iterator_type T)))] |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
260 |
else |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
261 |
(Card T, lookup_type_ints_assign thy cards_assigns T) :: |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
262 |
(case binarized_and_boxed_datatype_constrs hol_ctxt binarize T of |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
263 |
[_] => [] |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
264 |
| constrs => map_filter (row_for_constr thy maxes_assigns) constrs) |
33192 | 265 |
|
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
266 |
fun blocks_for_types hol_ctxt binarize cards_assigns maxes_assigns iters_assigns |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
267 |
bitss bisim_depths mono_Ts nonmono_Ts = |
33192 | 268 |
let |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
269 |
val block_for = block_for_type hol_ctxt binarize cards_assigns maxes_assigns |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
270 |
iters_assigns bitss bisim_depths |
33192 | 271 |
val mono_block = maps block_for mono_Ts |
272 |
val nonmono_blocks = map block_for nonmono_Ts |
|
273 |
in mono_block :: nonmono_blocks end |
|
274 |
||
275 |
val sync_threshold = 5 |
|
38186
c28018f5a1d6
example tweaking -- also prevents Nitpick_Tests from using more than 1 thread
blanchet
parents:
38180
diff
changeset
|
276 |
val linearity = 5 |
33192 | 277 |
|
38186
c28018f5a1d6
example tweaking -- also prevents Nitpick_Tests from using more than 1 thread
blanchet
parents:
38180
diff
changeset
|
278 |
val all_combinations_ordered_smartly = |
33192 | 279 |
let |
38186
c28018f5a1d6
example tweaking -- also prevents Nitpick_Tests from using more than 1 thread
blanchet
parents:
38180
diff
changeset
|
280 |
fun cost [] = 0 |
c28018f5a1d6
example tweaking -- also prevents Nitpick_Tests from using more than 1 thread
blanchet
parents:
38180
diff
changeset
|
281 |
| cost [k] = k |
c28018f5a1d6
example tweaking -- also prevents Nitpick_Tests from using more than 1 thread
blanchet
parents:
38180
diff
changeset
|
282 |
| cost (k :: ks) = |
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
283 |
if k < sync_threshold andalso forall (curry (op =) k) ks then |
33192 | 284 |
k - sync_threshold |
285 |
else |
|
38187 | 286 |
k :: ks |> map (fn k => (k + linearity) * (k + linearity)) |
287 |
|> Integer.sum |
|
33192 | 288 |
in |
38187 | 289 |
all_combinations #> map (`cost) #> sort (int_ord o pairself fst) #> map snd |
33192 | 290 |
end |
291 |
||
292 |
fun is_self_recursive_constr_type T = |
|
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
293 |
exists (exists_subtype (curry (op =) (body_type T))) (binder_types T) |
33192 | 294 |
|
295 |
fun constr_max maxes x = the_default ~1 (AList.lookup (op =) maxes x) |
|
296 |
||
297 |
type scope_desc = (typ * int) list * (styp * int) list |
|
298 |
||
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
299 |
fun is_surely_inconsistent_card_assign hol_ctxt binarize |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
300 |
(card_assigns, max_assigns) (T, k) = |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
301 |
case binarized_and_boxed_datatype_constrs hol_ctxt binarize T of |
33192 | 302 |
[] => false |
303 |
| xs => |
|
304 |
let |
|
34126 | 305 |
val dom_cards = |
306 |
map (Integer.prod o map (bounded_card_of_type k ~1 card_assigns) |
|
33192 | 307 |
o binder_types o snd) xs |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
308 |
val maxes = map (constr_max max_assigns) xs |
34126 | 309 |
fun effective_max card ~1 = card |
33192 | 310 |
| effective_max card max = Int.min (card, max) |
34126 | 311 |
val max = map2 effective_max dom_cards maxes |> Integer.sum |
312 |
in max < k end |
|
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
313 |
fun is_surely_inconsistent_scope_description hol_ctxt binarize seen rest |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
314 |
max_assigns = |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
315 |
exists (is_surely_inconsistent_card_assign hol_ctxt binarize |
34126 | 316 |
(seen @ rest, max_assigns)) seen |
33192 | 317 |
|
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
318 |
fun repair_card_assigns hol_ctxt binarize (card_assigns, max_assigns) = |
33192 | 319 |
let |
320 |
fun aux seen [] = SOME seen |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
321 |
| aux _ ((_, 0) :: _) = NONE |
34126 | 322 |
| aux seen ((T, k) :: rest) = |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
323 |
(if is_surely_inconsistent_scope_description hol_ctxt binarize |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
324 |
((T, k) :: seen) rest max_assigns then |
33192 | 325 |
raise SAME () |
326 |
else |
|
34126 | 327 |
case aux ((T, k) :: seen) rest of |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
328 |
SOME assigns => SOME assigns |
33192 | 329 |
| NONE => raise SAME ()) |
34126 | 330 |
handle SAME () => aux seen ((T, k - 1) :: rest) |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
331 |
in aux [] (rev card_assigns) end |
33192 | 332 |
|
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
333 |
fun repair_iterator_assign ctxt assigns (T as Type (_, Ts), k) = |
33192 | 334 |
(T, if T = @{typ bisim_iterator} then |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
335 |
let |
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
336 |
val co_cards = map snd (filter (is_codatatype ctxt o fst) assigns) |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
337 |
in Int.min (k, Integer.sum co_cards) end |
33192 | 338 |
else if is_fp_iterator_type T then |
339 |
case Ts of |
|
340 |
[] => 1 |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
341 |
| _ => bounded_card_of_type k ~1 assigns (foldr1 HOLogic.mk_prodT Ts) |
33192 | 342 |
else |
343 |
k) |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
344 |
| repair_iterator_assign _ _ assign = assign |
33192 | 345 |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
346 |
fun add_row_to_scope_descriptor (kind, ks) (card_assigns, max_assigns) = |
33192 | 347 |
case kind of |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
348 |
Card T => ((T, the_single ks) :: card_assigns, max_assigns) |
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
349 |
| Max x => (card_assigns, (x, the_single ks) :: max_assigns) |
33192 | 350 |
fun scope_descriptor_from_block block = |
351 |
fold_rev add_row_to_scope_descriptor block ([], []) |
|
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
352 |
fun scope_descriptor_from_combination (hol_ctxt as {ctxt, ...}) binarize blocks |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
353 |
columns = |
33192 | 354 |
let |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
355 |
val (card_assigns, max_assigns) = |
33192 | 356 |
maps project_block (columns ~~ blocks) |> scope_descriptor_from_block |
357 |
in |
|
41991
ea02b9ee3085
prevent an exception if "card" is empty (e.g., "nitpick [card]")
blanchet
parents:
41052
diff
changeset
|
358 |
(card_assigns, max_assigns) |
ea02b9ee3085
prevent an exception if "card" is empty (e.g., "nitpick [card]")
blanchet
parents:
41052
diff
changeset
|
359 |
|> repair_card_assigns hol_ctxt binarize |
ea02b9ee3085
prevent an exception if "card" is empty (e.g., "nitpick [card]")
blanchet
parents:
41052
diff
changeset
|
360 |
|> Option.map |
ea02b9ee3085
prevent an exception if "card" is empty (e.g., "nitpick [card]")
blanchet
parents:
41052
diff
changeset
|
361 |
(fn card_assigns => |
ea02b9ee3085
prevent an exception if "card" is empty (e.g., "nitpick [card]")
blanchet
parents:
41052
diff
changeset
|
362 |
(map (repair_iterator_assign ctxt card_assigns) card_assigns, |
ea02b9ee3085
prevent an exception if "card" is empty (e.g., "nitpick [card]")
blanchet
parents:
41052
diff
changeset
|
363 |
max_assigns)) |
33192 | 364 |
end |
365 |
||
38124 | 366 |
fun offset_table_for_card_assigns dtypes assigns = |
33192 | 367 |
let |
368 |
fun aux next _ [] = Typtab.update_new (dummyT, next) |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
369 |
| aux next reusable ((T, k) :: assigns) = |
38127 | 370 |
if k = 1 orelse is_asymmetric_nondatatype T then |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
371 |
aux next reusable assigns |
33192 | 372 |
else if length (these (Option.map #constrs (datatype_spec dtypes T))) |
373 |
> 1 then |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
374 |
Typtab.update_new (T, next) #> aux (next + k) reusable assigns |
33192 | 375 |
else |
376 |
case AList.lookup (op =) reusable k of |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
377 |
SOME j0 => Typtab.update_new (T, j0) #> aux next reusable assigns |
33192 | 378 |
| NONE => Typtab.update_new (T, next) |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
379 |
#> aux (next + k) ((k, next) :: reusable) assigns |
38124 | 380 |
in Typtab.empty |> aux 0 [] assigns end |
33192 | 381 |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
382 |
fun domain_card max card_assigns = |
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
383 |
Integer.prod o map (bounded_card_of_type max max card_assigns) o binder_types |
33192 | 384 |
|
38162
824e940a3dd0
minor symmetry breaking for codatatypes like llist
blanchet
parents:
38127
diff
changeset
|
385 |
fun add_constr_spec (card_assigns, max_assigns) acyclic card sum_dom_cards |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
386 |
num_self_recs num_non_self_recs (self_rec, x as (_, T)) |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
387 |
constrs = |
33192 | 388 |
let |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
389 |
val max = constr_max max_assigns x |
33192 | 390 |
fun next_delta () = if null constrs then 0 else #epsilon (hd constrs) |
391 |
val {delta, epsilon, exclusive, total} = |
|
392 |
if max = 0 then |
|
393 |
let val delta = next_delta () in |
|
394 |
{delta = delta, epsilon = delta, exclusive = true, total = false} |
|
395 |
end |
|
38162
824e940a3dd0
minor symmetry breaking for codatatypes like llist
blanchet
parents:
38127
diff
changeset
|
396 |
else if num_self_recs > 0 then |
38193 | 397 |
(if num_non_self_recs = 1 then |
35072
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
398 |
if self_rec then |
38193 | 399 |
case List.last constrs of |
400 |
{delta = 0, epsilon = 1, exclusive = true, ...} => |
|
401 |
{delta = 1, epsilon = card, exclusive = (num_self_recs = 1), |
|
402 |
total = false} |
|
35072
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
403 |
| _ => raise SAME () |
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
404 |
else |
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
405 |
if domain_card 2 card_assigns T = 1 then |
38162
824e940a3dd0
minor symmetry breaking for codatatypes like llist
blanchet
parents:
38127
diff
changeset
|
406 |
{delta = 0, epsilon = 1, exclusive = acyclic, total = acyclic} |
35072
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
407 |
else |
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
408 |
raise SAME () |
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
409 |
else |
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
410 |
raise SAME ()) |
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
411 |
handle SAME () => |
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
412 |
{delta = 0, epsilon = card, exclusive = false, total = false} |
33192 | 413 |
else if card = sum_dom_cards (card + 1) then |
414 |
let val delta = next_delta () in |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
415 |
{delta = delta, epsilon = delta + domain_card card card_assigns T, |
33192 | 416 |
exclusive = true, total = true} |
417 |
end |
|
418 |
else |
|
419 |
{delta = 0, epsilon = card, |
|
420 |
exclusive = (num_self_recs + num_non_self_recs = 1), total = false} |
|
421 |
in |
|
422 |
{const = x, delta = delta, epsilon = epsilon, exclusive = exclusive, |
|
423 |
explicit_max = max, total = total} :: constrs |
|
424 |
end |
|
425 |
||
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
426 |
fun has_exact_card hol_ctxt facto finitizable_dataTs card_assigns T = |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
427 |
let val card = card_of_type card_assigns T in |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
428 |
card = bounded_exact_card_of_type hol_ctxt |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
429 |
(if facto then finitizable_dataTs else []) (card + 1) 0 |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
430 |
card_assigns T |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
431 |
end |
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
432 |
|
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
433 |
fun datatype_spec_from_scope_descriptor (hol_ctxt as {thy, ctxt, stds, ...}) |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
434 |
binarize deep_dataTs finitizable_dataTs (desc as (card_assigns, _)) |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
435 |
(T, card) = |
33192 | 436 |
let |
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
|
437 |
val deep = member (op =) deep_dataTs T |
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
438 |
val co = is_codatatype ctxt 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
|
439 |
val standard = is_standard_datatype thy stds T |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
440 |
val xs = binarized_and_boxed_datatype_constrs hol_ctxt binarize T |
33192 | 441 |
val self_recs = map (is_self_recursive_constr_type o snd) xs |
442 |
val (num_self_recs, num_non_self_recs) = |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
443 |
List.partition I self_recs |> pairself length |
38126 | 444 |
val self_rec = num_self_recs > 0 |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
445 |
fun is_complete facto = |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
446 |
has_exact_card hol_ctxt facto finitizable_dataTs card_assigns T |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
447 |
fun is_concrete facto = |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
448 |
is_word_type T orelse |
45399 | 449 |
(* FIXME: looks wrong other types than just functions might be |
45402 | 450 |
abstract. "is_complete" is also suspicious. *) |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
451 |
xs |> maps (binder_types o snd) |> maps binder_types |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
452 |
|> forall (has_exact_card hol_ctxt facto finitizable_dataTs |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
453 |
card_assigns) |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
454 |
val complete = pair_from_fun is_complete |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
455 |
val concrete = pair_from_fun is_concrete |
33192 | 456 |
fun sum_dom_cards max = |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
457 |
map (domain_card max card_assigns o snd) xs |> Integer.sum |
33192 | 458 |
val constrs = |
38162
824e940a3dd0
minor symmetry breaking for codatatypes like llist
blanchet
parents:
38127
diff
changeset
|
459 |
fold_rev (add_constr_spec desc (not co andalso standard) card |
824e940a3dd0
minor symmetry breaking for codatatypes like llist
blanchet
parents:
38127
diff
changeset
|
460 |
sum_dom_cards num_self_recs num_non_self_recs) |
35072
d79308423aea
optimize Nitpick's encoding for other datatypes than list that have a constant constructor like "Nil";
blanchet
parents:
35071
diff
changeset
|
461 |
(sort (bool_ord o swap o pairself fst) (self_recs ~~ xs)) [] |
33558
a2db56854b83
optimized Nitpick's encoding and rendering of datatypes whose constructors don't appear in the problem
blanchet
parents:
33232
diff
changeset
|
462 |
in |
38126 | 463 |
{typ = T, card = card, co = co, standard = standard, self_rec = self_rec, |
464 |
complete = complete, concrete = concrete, deep = deep, constrs = constrs} |
|
33558
a2db56854b83
optimized Nitpick's encoding and rendering of datatypes whose constructors don't appear in the problem
blanchet
parents:
33232
diff
changeset
|
465 |
end |
33192 | 466 |
|
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
36390
diff
changeset
|
467 |
fun scope_from_descriptor (hol_ctxt as {ctxt, stds, ...}) binarize deep_dataTs |
36386
2132f15b366f
Fruhjahrsputz: remove three mostly useless Nitpick options
blanchet
parents:
36385
diff
changeset
|
468 |
finitizable_dataTs (desc as (card_assigns, _)) = |
33192 | 469 |
let |
33558
a2db56854b83
optimized Nitpick's encoding and rendering of datatypes whose constructors don't appear in the problem
blanchet
parents:
33232
diff
changeset
|
470 |
val datatypes = |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
471 |
map (datatype_spec_from_scope_descriptor hol_ctxt binarize deep_dataTs |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
472 |
finitizable_dataTs desc) |
37256
0dca1ec52999
thread along context instead of theory for typedef lookup
blanchet
parents:
36390
diff
changeset
|
473 |
(filter (is_datatype ctxt stds o fst) card_assigns) |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
474 |
val bits = card_of_type card_assigns @{typ signed_bit} - 1 |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
475 |
handle TYPE ("Nitpick_HOL.card_of_type", _, _) => |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
476 |
card_of_type card_assigns @{typ unsigned_bit} |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
477 |
handle TYPE ("Nitpick_HOL.card_of_type", _, _) => 0 |
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
478 |
val bisim_depth = card_of_type card_assigns @{typ bisim_iterator} - 1 |
33192 | 479 |
in |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
480 |
{hol_ctxt = hol_ctxt, binarize = binarize, card_assigns = card_assigns, |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
481 |
datatypes = datatypes, bits = bits, bisim_depth = bisim_depth, |
38124 | 482 |
ofs = offset_table_for_card_assigns datatypes card_assigns} |
33192 | 483 |
end |
484 |
||
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35385
diff
changeset
|
485 |
fun repair_cards_assigns_wrt_boxing_etc _ _ [] = [] |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35385
diff
changeset
|
486 |
| repair_cards_assigns_wrt_boxing_etc thy Ts ((SOME T, ks) :: cards_assigns) = |
33192 | 487 |
(if is_fun_type T orelse is_pair_type T then |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35385
diff
changeset
|
488 |
Ts |> filter (curry (type_match thy o swap) T) |> map (rpair ks o SOME) |
33192 | 489 |
else |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35385
diff
changeset
|
490 |
[(SOME T, ks)]) @ |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35385
diff
changeset
|
491 |
repair_cards_assigns_wrt_boxing_etc thy Ts cards_assigns |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35385
diff
changeset
|
492 |
| repair_cards_assigns_wrt_boxing_etc thy Ts ((NONE, ks) :: cards_assigns) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35385
diff
changeset
|
493 |
(NONE, ks) :: repair_cards_assigns_wrt_boxing_etc thy Ts cards_assigns |
33192 | 494 |
|
38180
7a88032f9265
bump up the max cardinalities, to use up more of the time given to us by the user
blanchet
parents:
38162
diff
changeset
|
495 |
val max_scopes = 5000 |
7a88032f9265
bump up the max cardinalities, to use up more of the time given to us by the user
blanchet
parents:
38162
diff
changeset
|
496 |
val distinct_threshold = 1000 |
33192 | 497 |
|
36386
2132f15b366f
Fruhjahrsputz: remove three mostly useless Nitpick options
blanchet
parents:
36385
diff
changeset
|
498 |
fun all_scopes (hol_ctxt as {thy, ...}) binarize cards_assigns maxes_assigns |
2132f15b366f
Fruhjahrsputz: remove three mostly useless Nitpick options
blanchet
parents:
36385
diff
changeset
|
499 |
iters_assigns bitss bisim_depths mono_Ts nonmono_Ts deep_dataTs |
2132f15b366f
Fruhjahrsputz: remove three mostly useless Nitpick options
blanchet
parents:
36385
diff
changeset
|
500 |
finitizable_dataTs = |
33192 | 501 |
let |
38240
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
502 |
val cards_assigns = |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
503 |
repair_cards_assigns_wrt_boxing_etc thy mono_Ts cards_assigns |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
504 |
val blocks = |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
505 |
blocks_for_types hol_ctxt binarize cards_assigns maxes_assigns |
a44d108a8d39
local versions of Nitpick.register_xxx functions
blanchet
parents:
38193
diff
changeset
|
506 |
iters_assigns bitss bisim_depths mono_Ts nonmono_Ts |
33192 | 507 |
val ranks = map rank_of_block blocks |
33580
45c33e97cb86
added datatype constructor cache in Nitpick (to speed up the scope enumeration) and never test more than 4096 scopes
blanchet
parents:
33558
diff
changeset
|
508 |
val all = all_combinations_ordered_smartly (map (rpair 0) ranks) |
33957 | 509 |
val head = take max_scopes all |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
510 |
val descs = |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
511 |
map_filter (scope_descriptor_from_combination hol_ctxt binarize blocks) |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35179
diff
changeset
|
512 |
head |
33192 | 513 |
in |
33580
45c33e97cb86
added datatype constructor cache in Nitpick (to speed up the scope enumeration) and never test more than 4096 scopes
blanchet
parents:
33558
diff
changeset
|
514 |
(length all - length head, |
45c33e97cb86
added datatype constructor cache in Nitpick (to speed up the scope enumeration) and never test more than 4096 scopes
blanchet
parents:
33558
diff
changeset
|
515 |
descs |> length descs <= distinct_threshold ? distinct (op =) |
36386
2132f15b366f
Fruhjahrsputz: remove three mostly useless Nitpick options
blanchet
parents:
36385
diff
changeset
|
516 |
|> map (scope_from_descriptor hol_ctxt binarize deep_dataTs |
2132f15b366f
Fruhjahrsputz: remove three mostly useless Nitpick options
blanchet
parents:
36385
diff
changeset
|
517 |
finitizable_dataTs)) |
33192 | 518 |
end |
519 |
||
520 |
end; |