author | blanchet |
Sat, 24 Apr 2010 16:17:30 +0200 | |
changeset 36384 | 76d5fd5a45fb |
parent 35845 | e5980f0ad025 |
child 36385 | ff5f88702590 |
permissions | -rw-r--r-- |
33982 | 1 |
(* Title: HOL/Tools/Nitpick/nitpick_model.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:
34974
diff
changeset
|
3 |
Copyright 2009, 2010 |
33192 | 4 |
|
5 |
Model reconstruction for Nitpick. |
|
6 |
*) |
|
7 |
||
8 |
signature NITPICK_MODEL = |
|
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 |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
11 |
type scope = Nitpick_Scope.scope |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
12 |
type rep = Nitpick_Rep.rep |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
13 |
type nut = Nitpick_Nut.nut |
33192 | 14 |
|
15 |
type params = { |
|
16 |
show_skolems: bool, |
|
17 |
show_datatypes: bool, |
|
18 |
show_consts: bool} |
|
36384 | 19 |
|
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
20 |
type term_postprocessor = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
21 |
Proof.context -> string -> (typ -> term list) -> typ -> term -> term |
33192 | 22 |
|
23 |
structure NameTable : TABLE |
|
24 |
||
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
25 |
val irrelevant : string |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
26 |
val unknown : string |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
27 |
val unrep : string |
35711
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
28 |
val register_term_postprocessor : |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
29 |
typ -> term_postprocessor -> theory -> theory |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
30 |
val unregister_term_postprocessor : typ -> theory -> theory |
33192 | 31 |
val tuple_list_for_name : |
32 |
nut NameTable.table -> Kodkod.raw_bound list -> nut -> int list list |
|
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
33 |
val dest_plain_fun : term -> bool * (term list * term list) |
33192 | 34 |
val reconstruct_hol_model : |
35 |
params -> scope -> (term option * int list) list -> styp list -> nut list |
|
36 |
-> nut list -> nut list -> nut NameTable.table -> Kodkod.raw_bound list |
|
37 |
-> Pretty.T * bool |
|
38 |
val prove_hol_model : |
|
39 |
scope -> Time.time option -> nut list -> nut list -> nut NameTable.table |
|
40 |
-> Kodkod.raw_bound list -> term -> bool option |
|
41 |
end; |
|
42 |
||
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
43 |
structure Nitpick_Model : NITPICK_MODEL = |
33192 | 44 |
struct |
45 |
||
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
46 |
open Nitpick_Util |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
47 |
open Nitpick_HOL |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
48 |
open Nitpick_Scope |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
49 |
open Nitpick_Peephole |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
50 |
open Nitpick_Rep |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
51 |
open Nitpick_Nut |
33192 | 52 |
|
34126 | 53 |
structure KK = Kodkod |
54 |
||
33192 | 55 |
type params = { |
56 |
show_skolems: bool, |
|
57 |
show_datatypes: bool, |
|
58 |
show_consts: bool} |
|
59 |
||
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
60 |
type term_postprocessor = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
61 |
Proof.context -> string -> (typ -> term list) -> typ -> term -> term |
35711
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
62 |
|
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
63 |
structure Data = Theory_Data( |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
64 |
type T = (typ * term_postprocessor) list |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
65 |
val empty = [] |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
66 |
val extend = I |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
67 |
fun merge (ps1, ps2) = AList.merge (op =) (K true) (ps1, ps2)) |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
68 |
|
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
69 |
val irrelevant = "_" |
33192 | 70 |
val unknown = "?" |
71 |
val unrep = "\<dots>" |
|
72 |
val maybe_mixfix = "_\<^sup>?" |
|
73 |
val base_mixfix = "_\<^bsub>base\<^esub>" |
|
74 |
val step_mixfix = "_\<^bsub>step\<^esub>" |
|
75 |
val abs_mixfix = "\<guillemotleft>_\<guillemotright>" |
|
35718 | 76 |
val arg_var_prefix = "x" |
35179
4b198af5beb5
redo Nitpick's nonstandard values as cyclic values (instead of additional constructors)
blanchet
parents:
35177
diff
changeset
|
77 |
val cyclic_co_val_name = "\<omega>" |
35188
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
78 |
val cyclic_const_prefix = "\<xi>" |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
79 |
val cyclic_type_name = nitpick_prefix ^ cyclic_const_prefix |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
80 |
val opt_flag = nitpick_prefix ^ "opt" |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
81 |
val non_opt_flag = nitpick_prefix ^ "non_opt" |
33192 | 82 |
|
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
83 |
type atom_pool = ((string * int) * int list) list |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
84 |
|
35718 | 85 |
(* Proof.context -> ((string * string) * (string * string)) * Proof.context *) |
86 |
fun add_wacky_syntax ctxt = |
|
87 |
let |
|
88 |
(* term -> string *) |
|
89 |
val name_of = fst o dest_Const |
|
90 |
val thy = ProofContext.theory_of ctxt |> Context.reject_draft |
|
91 |
val (maybe_t, thy) = |
|
92 |
Sign.declare_const ((@{binding nitpick_maybe}, @{typ "'a => 'a"}), |
|
93 |
Mixfix (maybe_mixfix, [1000], 1000)) thy |
|
94 |
val (abs_t, thy) = |
|
95 |
Sign.declare_const ((@{binding nitpick_abs}, @{typ "'a => 'b"}), |
|
96 |
Mixfix (abs_mixfix, [40], 40)) thy |
|
97 |
val (base_t, thy) = |
|
98 |
Sign.declare_const ((@{binding nitpick_base}, @{typ "'a => 'a"}), |
|
99 |
Mixfix (base_mixfix, [1000], 1000)) thy |
|
100 |
val (step_t, thy) = |
|
101 |
Sign.declare_const ((@{binding nitpick_step}, @{typ "'a => 'a"}), |
|
102 |
Mixfix (step_mixfix, [1000], 1000)) thy |
|
103 |
in |
|
104 |
(pairself (pairself name_of) ((maybe_t, abs_t), (base_t, step_t)), |
|
105 |
ProofContext.transfer_syntax thy ctxt) |
|
106 |
end |
|
107 |
||
108 |
(** Term reconstruction **) |
|
109 |
||
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
110 |
(* atom_pool Unsynchronized.ref -> string -> int -> int -> string *) |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
111 |
fun nth_atom_suffix pool s j k = |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
112 |
(case AList.lookup (op =) (!pool) (s, k) of |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
113 |
SOME js => |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
114 |
(case find_index (curry (op =) j) js of |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
115 |
~1 => (Unsynchronized.change pool (cons ((s, k), j :: js)); |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
116 |
length js + 1) |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
117 |
| n => length js - n) |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
118 |
| NONE => (Unsynchronized.change pool (cons ((s, k), [j])); 1)) |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
119 |
|> nat_subscript |
33884
a0c43f185fef
generate clearer atom names in Nitpick for types that end with a digit;
blanchet
parents:
33705
diff
changeset
|
120 |
|> (s <> "" andalso Symbol.is_ascii_digit (List.last (explode s))) |
a0c43f185fef
generate clearer atom names in Nitpick for types that end with a digit;
blanchet
parents:
33705
diff
changeset
|
121 |
? prefix "\<^isub>," |
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
122 |
(* atom_pool Unsynchronized.ref -> string -> typ -> int -> int -> string *) |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
123 |
fun nth_atom_name pool prefix (Type (s, _)) j k = |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
124 |
let val s' = shortest_name s in |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
125 |
prefix ^ (if String.isPrefix "\\" s' then s' else substring (s', 0, 1)) ^ |
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
126 |
nth_atom_suffix pool s j k |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
127 |
end |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
128 |
| nth_atom_name pool prefix (TFree (s, _)) j k = |
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
129 |
prefix ^ perhaps (try (unprefix "'")) s ^ nth_atom_suffix pool s j k |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
130 |
| nth_atom_name _ _ T _ _ = |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
131 |
raise TYPE ("Nitpick_Model.nth_atom_name", [T], []) |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
132 |
(* atom_pool Unsynchronized.ref -> bool -> typ -> int -> int -> term *) |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
133 |
fun nth_atom pool for_auto T j k = |
33192 | 134 |
if for_auto then |
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
135 |
Free (nth_atom_name pool (hd (space_explode "." nitpick_prefix)) T j k, T) |
33192 | 136 |
else |
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
137 |
Const (nth_atom_name pool "" T j k, T) |
33192 | 138 |
|
34126 | 139 |
(* term -> real *) |
35177 | 140 |
fun extract_real_number (Const (@{const_name divide}, _) $ t1 $ t2) = |
34126 | 141 |
real (snd (HOLogic.dest_number t1)) / real (snd (HOLogic.dest_number t2)) |
142 |
| extract_real_number t = real (snd (HOLogic.dest_number t)) |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
143 |
(* term * term -> order *) |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
144 |
fun nice_term_ord (Abs (_, _, t1), Abs (_, _, t2)) = nice_term_ord (t1, t2) |
34126 | 145 |
| nice_term_ord tp = Real.compare (pairself extract_real_number tp) |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
146 |
handle TERM ("dest_number", _) => |
34126 | 147 |
case tp of |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
148 |
(t11 $ t12, t21 $ t22) => |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
149 |
(case nice_term_ord (t11, t21) of |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
150 |
EQUAL => nice_term_ord (t12, t22) |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
151 |
| ord => ord) |
35408 | 152 |
| _ => Term_Ord.fast_term_ord tp |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
153 |
|
35711
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
154 |
(* typ -> term_postprocessor -> theory -> theory *) |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
155 |
fun register_term_postprocessor T p = Data.map (cons (T, p)) |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
156 |
(* typ -> theory -> theory *) |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
157 |
fun unregister_term_postprocessor T = Data.map (AList.delete (op =) T) |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
158 |
|
34126 | 159 |
(* nut NameTable.table -> KK.raw_bound list -> nut -> int list list *) |
33192 | 160 |
fun tuple_list_for_name rel_table bounds name = |
161 |
the (AList.lookup (op =) bounds (the_rel rel_table name)) handle NUT _ => [[]] |
|
162 |
||
163 |
(* term -> term *) |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
164 |
fun unarize_unbox_etc_term (Const (@{const_name FinFun}, _) $ t1) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
165 |
unarize_unbox_etc_term t1 |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
166 |
| unarize_unbox_etc_term (Const (@{const_name FunBox}, _) $ t1) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
167 |
unarize_unbox_etc_term t1 |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
168 |
| unarize_unbox_etc_term |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
169 |
(Const (@{const_name PairBox}, |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
170 |
Type (@{type_name fun}, [T1, Type (@{type_name fun}, [T2, _])])) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
171 |
$ t1 $ t2) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
172 |
let val Ts = map uniterize_unarize_unbox_etc_type [T1, T2] in |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
173 |
Const (@{const_name Pair}, Ts ---> Type (@{type_name "*"}, Ts)) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
174 |
$ unarize_unbox_etc_term t1 $ unarize_unbox_etc_term t2 |
33192 | 175 |
end |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
176 |
| unarize_unbox_etc_term (Const (s, T)) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
177 |
Const (s, uniterize_unarize_unbox_etc_type T) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
178 |
| unarize_unbox_etc_term (t1 $ t2) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
179 |
unarize_unbox_etc_term t1 $ unarize_unbox_etc_term t2 |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
180 |
| unarize_unbox_etc_term (Free (s, T)) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
181 |
Free (s, uniterize_unarize_unbox_etc_type T) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
182 |
| unarize_unbox_etc_term (Var (x, T)) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
183 |
Var (x, uniterize_unarize_unbox_etc_type T) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
184 |
| unarize_unbox_etc_term (Bound j) = Bound j |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
185 |
| unarize_unbox_etc_term (Abs (s, T, t')) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
186 |
Abs (s, uniterize_unarize_unbox_etc_type T, unarize_unbox_etc_term t') |
33192 | 187 |
|
188 |
(* typ -> typ -> (typ * typ) * (typ * typ) *) |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
189 |
fun factor_out_types (T1 as Type (@{type_name "*"}, [T11, T12])) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
190 |
(T2 as Type (@{type_name "*"}, [T21, T22])) = |
33192 | 191 |
let val (n1, n2) = pairself num_factors_in_type (T11, T21) in |
192 |
if n1 = n2 then |
|
193 |
let |
|
194 |
val ((T11', opt_T12'), (T21', opt_T22')) = factor_out_types T12 T22 |
|
195 |
in |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
196 |
((Type (@{type_name "*"}, [T11, T11']), opt_T12'), |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
197 |
(Type (@{type_name "*"}, [T21, T21']), opt_T22')) |
33192 | 198 |
end |
199 |
else if n1 < n2 then |
|
200 |
case factor_out_types T1 T21 of |
|
201 |
(p1, (T21', NONE)) => (p1, (T21', SOME T22)) |
|
202 |
| (p1, (T21', SOME T22')) => |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
203 |
(p1, (T21', SOME (Type (@{type_name "*"}, [T22', T22])))) |
33192 | 204 |
else |
205 |
swap (factor_out_types T2 T1) |
|
206 |
end |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
207 |
| factor_out_types (Type (@{type_name "*"}, [T11, T12])) T2 = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
208 |
((T11, SOME T12), (T2, NONE)) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
209 |
| factor_out_types T1 (Type (@{type_name "*"}, [T21, T22])) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
210 |
((T1, NONE), (T21, SOME T22)) |
33192 | 211 |
| factor_out_types T1 T2 = ((T1, NONE), (T2, NONE)) |
212 |
||
213 |
(* bool -> typ -> typ -> (term * term) list -> term *) |
|
214 |
fun make_plain_fun maybe_opt T1 T2 = |
|
215 |
let |
|
216 |
(* typ -> typ -> (term * term) list -> term *) |
|
217 |
fun aux T1 T2 [] = |
|
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
218 |
Const (if maybe_opt then opt_flag else non_opt_flag, T1 --> T2) |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
219 |
| aux T1 T2 ((t1, t2) :: tps) = |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
220 |
Const (@{const_name fun_upd}, (T1 --> T2) --> T1 --> T2 --> T1 --> T2) |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
221 |
$ aux T1 T2 tps $ t1 $ t2 |
33192 | 222 |
in aux T1 T2 o rev end |
223 |
(* term -> bool *) |
|
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
224 |
fun is_plain_fun (Const (s, _)) = (s = opt_flag orelse s = non_opt_flag) |
33192 | 225 |
| is_plain_fun (Const (@{const_name fun_upd}, _) $ t0 $ _ $ _) = |
226 |
is_plain_fun t0 |
|
227 |
| is_plain_fun _ = false |
|
228 |
(* term -> bool * (term list * term list) *) |
|
229 |
val dest_plain_fun = |
|
230 |
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:
34974
diff
changeset
|
231 |
(* term -> bool * (term list * term list) *) |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
232 |
fun aux (Abs (_, _, Const (s, _))) = (s <> irrelevant, ([], [])) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
233 |
| aux (Const (s, _)) = (s <> non_opt_flag, ([], [])) |
33192 | 234 |
| aux (Const (@{const_name fun_upd}, _) $ t0 $ t1 $ t2) = |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
235 |
let val (maybe_opt, (ts1, ts2)) = aux t0 in |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
236 |
(maybe_opt, (t1 :: ts1, t2 :: ts2)) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
237 |
end |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
238 |
| aux t = raise TERM ("Nitpick_Model.dest_plain_fun", [t]) |
33192 | 239 |
in apsnd (pairself rev) o aux end |
240 |
||
33565
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
241 |
(* typ -> typ -> typ -> term -> term * term *) |
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
242 |
fun break_in_two T T1 T2 t = |
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
243 |
let |
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
244 |
val ps = HOLogic.flat_tupleT_paths T |
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
245 |
val cut = length (HOLogic.strip_tupleT T1) |
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
246 |
val (ps1, ps2) = pairself HOLogic.flat_tupleT_paths (T1, T2) |
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
247 |
val (ts1, ts2) = t |> HOLogic.strip_ptuple ps |> chop cut |
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
248 |
in (HOLogic.mk_ptuple ps1 T1 ts1, HOLogic.mk_ptuple ps2 T2 ts2) end |
33192 | 249 |
(* typ -> term -> term -> term *) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
250 |
fun pair_up (Type (@{type_name "*"}, [T1', T2'])) |
33192 | 251 |
(t1 as Const (@{const_name Pair}, |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
252 |
Type (@{type_name fun}, |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
253 |
[_, Type (@{type_name fun}, [_, T1])])) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
254 |
$ t11 $ t12) t2 = |
33192 | 255 |
if T1 = T1' then HOLogic.mk_prod (t1, t2) |
256 |
else HOLogic.mk_prod (t11, pair_up T2' t12 t2) |
|
257 |
| pair_up _ t1 t2 = HOLogic.mk_prod (t1, t2) |
|
258 |
(* typ -> term -> term list * term list -> (term * term) list*) |
|
259 |
fun multi_pair_up T1 t1 (ts2, ts3) = map2 (pair o pair_up T1 t1) ts2 ts3 |
|
260 |
||
261 |
(* typ -> typ -> typ -> term -> term *) |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
262 |
fun typecast_fun (Type (@{type_name fun}, [T1', T2'])) T1 T2 t = |
33192 | 263 |
let |
33565
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
264 |
(* typ -> typ -> typ -> typ -> term -> term *) |
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
265 |
fun do_curry T1 T1a T1b T2 t = |
33192 | 266 |
let |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
267 |
val (maybe_opt, tsp) = dest_plain_fun t |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
268 |
val tps = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
269 |
tsp |>> map (break_in_two T1 T1a T1b) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
270 |
|> uncurry (map2 (fn (t1a, t1b) => fn t2 => (t1a, (t1b, t2)))) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
271 |
|> AList.coalesce (op =) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
272 |
|> map (apsnd (make_plain_fun maybe_opt T1b T2)) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
273 |
in make_plain_fun maybe_opt T1a (T1b --> T2) tps end |
33192 | 274 |
(* typ -> typ -> term -> term *) |
275 |
and do_uncurry T1 T2 t = |
|
276 |
let |
|
277 |
val (maybe_opt, tsp) = dest_plain_fun t |
|
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
278 |
val tps = |
33192 | 279 |
tsp |> op ~~ |
280 |
|> maps (fn (t1, t2) => |
|
281 |
multi_pair_up T1 t1 (snd (dest_plain_fun t2))) |
|
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
282 |
in make_plain_fun maybe_opt T1 T2 tps end |
33192 | 283 |
(* typ -> typ -> typ -> typ -> term -> term *) |
284 |
and do_arrow T1' T2' _ _ (Const (s, _)) = Const (s, T1' --> T2') |
|
285 |
| do_arrow T1' T2' T1 T2 |
|
286 |
(Const (@{const_name fun_upd}, _) $ t0 $ t1 $ t2) = |
|
287 |
Const (@{const_name fun_upd}, |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
288 |
(T1' --> T2') --> T1' --> T2' --> T1' --> T2') |
33192 | 289 |
$ do_arrow T1' T2' T1 T2 t0 $ do_term T1' T1 t1 $ do_term T2' T2 t2 |
290 |
| do_arrow _ _ _ _ t = |
|
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
291 |
raise TERM ("Nitpick_Model.typecast_fun.do_arrow", [t]) |
33192 | 292 |
and do_fun T1' T2' T1 T2 t = |
293 |
case factor_out_types T1' T1 of |
|
294 |
((_, NONE), (_, NONE)) => t |> do_arrow T1' T2' T1 T2 |
|
295 |
| ((_, NONE), (T1a, SOME T1b)) => |
|
33565
5fad8e36dfb1
fixed error in Nitpick's display of uncurried constants, which resulted in an exception
blanchet
parents:
33558
diff
changeset
|
296 |
t |> do_curry T1 T1a T1b T2 |> do_arrow T1' T2' T1a (T1b --> T2) |
33192 | 297 |
| ((T1a', SOME T1b'), (_, NONE)) => |
298 |
t |> do_arrow T1a' (T1b' --> T2') T1 T2 |> do_uncurry T1' T2' |
|
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
299 |
| _ => raise TYPE ("Nitpick_Model.typecast_fun.do_fun", [T1, T1'], []) |
33192 | 300 |
(* typ -> typ -> term -> term *) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
301 |
and do_term (Type (@{type_name fun}, [T1', T2'])) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
302 |
(Type (@{type_name fun}, [T1, T2])) t = |
33192 | 303 |
do_fun T1' T2' T1 T2 t |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
304 |
| do_term (T' as Type (@{type_name "*"}, Ts' as [T1', T2'])) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
305 |
(Type (@{type_name "*"}, [T1, T2])) |
33192 | 306 |
(Const (@{const_name Pair}, _) $ t1 $ t2) = |
307 |
Const (@{const_name Pair}, Ts' ---> T') |
|
308 |
$ do_term T1' T1 t1 $ do_term T2' T2 t2 |
|
309 |
| do_term T' T t = |
|
310 |
if T = T' then t |
|
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
311 |
else raise TYPE ("Nitpick_Model.typecast_fun.do_term", [T, T'], []) |
33192 | 312 |
in if T1' = T1 andalso T2' = T2 then t else do_fun T1' T2' T1 T2 t end |
34998 | 313 |
| typecast_fun T' _ _ _ = |
314 |
raise TYPE ("Nitpick_Model.typecast_fun", [T'], []) |
|
33192 | 315 |
|
316 |
(* term -> string *) |
|
317 |
fun truth_const_sort_key @{const True} = "0" |
|
318 |
| truth_const_sort_key @{const False} = "2" |
|
319 |
| truth_const_sort_key _ = "1" |
|
320 |
||
321 |
(* typ -> term list -> term *) |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
322 |
fun mk_tuple (Type (@{type_name "*"}, [T1, T2])) ts = |
33192 | 323 |
HOLogic.mk_prod (mk_tuple T1 ts, |
324 |
mk_tuple T2 (List.drop (ts, length (HOLogic.flatten_tupleT T1)))) |
|
325 |
| mk_tuple _ (t :: _) = t |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
326 |
| mk_tuple T [] = raise TYPE ("Nitpick_Model.mk_tuple", [T], []) |
33192 | 327 |
|
35711
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
328 |
(* theory -> typ * typ -> bool *) |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
329 |
fun varified_type_match thy (candid_T, pat_T) = |
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
|
330 |
strict_type_match thy (candid_T, Logic.varifyT_global pat_T) |
35711
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
331 |
|
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
332 |
(* atom_pool -> (string * string) * (string * string) -> scope -> nut list |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
333 |
-> nut list -> nut list -> nut NameTable.table -> KK.raw_bound list -> typ |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
334 |
-> term list *) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
335 |
fun all_values_of_type pool wacky_names (scope as {card_assigns, ...} : scope) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
336 |
sel_names rel_table bounds card T = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
337 |
let |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
338 |
val card = if card = 0 then card_of_type card_assigns T else card |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
339 |
(* nat -> term *) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
340 |
fun nth_value_of_type n = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
341 |
let |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
342 |
(* bool -> term *) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
343 |
fun term unfold = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
344 |
reconstruct_term unfold pool wacky_names scope sel_names rel_table |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
345 |
bounds T T (Atom (card, 0)) [[n]] |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
346 |
in |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
347 |
case term false of |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
348 |
t as Const (s, _) => |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
349 |
if String.isPrefix cyclic_const_prefix s then |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
350 |
HOLogic.mk_eq (t, term true) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
351 |
else |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
352 |
t |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
353 |
| t => t |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
354 |
end |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
355 |
in index_seq 0 card |> map nth_value_of_type |> sort nice_term_ord end |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
356 |
(* bool -> atom_pool -> (string * string) * (string * string) -> scope |
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
357 |
-> nut list -> nut list -> nut list -> nut NameTable.table |
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
358 |
-> KK.raw_bound list -> typ -> typ -> rep -> int list list -> term *) |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
359 |
and reconstruct_term unfold pool (wacky_names as ((maybe_name, abs_name), _)) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
360 |
(scope as {hol_ctxt as {ctxt, thy, stds, ...}, binarize, card_assigns, |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
361 |
bits, datatypes, ofs, ...}) sel_names rel_table bounds = |
33192 | 362 |
let |
363 |
val for_auto = (maybe_name = "") |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
364 |
(* int list list -> int *) |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
365 |
fun value_of_bits jss = |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
366 |
let |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
367 |
val j0 = offset_of_type ofs @{typ unsigned_bit} |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
368 |
val js = map (Integer.add (~ j0) o the_single) jss |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
369 |
in |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
370 |
fold (fn j => Integer.add (reasonable_power 2 j |> j = bits ? op ~)) |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
371 |
js 0 |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
372 |
end |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
373 |
(* typ -> term list *) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
374 |
val all_values = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
375 |
all_values_of_type pool wacky_names scope sel_names rel_table bounds 0 |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
376 |
(* typ -> term -> term *) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
377 |
fun postprocess_term (Type (@{type_name fun}, _)) = I |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
378 |
| postprocess_term T = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
379 |
if null (Data.get thy) then |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
380 |
I |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
381 |
else case AList.lookup (varified_type_match thy) (Data.get thy) T of |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
382 |
SOME postproc => postproc ctxt maybe_name all_values T |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
383 |
| NONE => I |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
384 |
(* typ list -> term -> term *) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
385 |
fun postprocess_subterms Ts (t1 $ t2) = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
386 |
let val t = postprocess_subterms Ts t1 $ postprocess_subterms Ts t2 in |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
387 |
postprocess_term (fastype_of1 (Ts, t)) t |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
388 |
end |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
389 |
| postprocess_subterms Ts (Abs (s, T, t')) = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
390 |
Abs (s, T, postprocess_subterms (T :: Ts) t') |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
391 |
| postprocess_subterms Ts t = postprocess_term (fastype_of1 (Ts, t)) t |
33192 | 392 |
(* bool -> typ -> typ -> (term * term) list -> term *) |
35388
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
393 |
fun make_set maybe_opt T1 T2 tps = |
33192 | 394 |
let |
35402 | 395 |
val empty_const = Const (@{const_abbrev Set.empty}, T1 --> T2) |
33192 | 396 |
val insert_const = Const (@{const_name insert}, |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
397 |
T1 --> (T1 --> T2) --> T1 --> T2) |
33192 | 398 |
(* (term * term) list -> term *) |
399 |
fun aux [] = |
|
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
400 |
if maybe_opt andalso not (is_complete_type datatypes false T1) then |
33192 | 401 |
insert_const $ Const (unrep, T1) $ empty_const |
402 |
else |
|
403 |
empty_const |
|
404 |
| aux ((t1, t2) :: zs) = |
|
35388
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
405 |
aux zs |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
406 |
|> t2 <> @{const False} |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
407 |
? curry (op $) |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
408 |
(insert_const |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
409 |
$ (t1 |> t2 <> @{const True} |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
410 |
? curry (op $) |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
411 |
(Const (maybe_name, T1 --> T1)))) |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
412 |
in |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
413 |
if forall (fn (_, t) => t <> @{const True} andalso t <> @{const False}) |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
414 |
tps then |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
415 |
Const (unknown, T1 --> T2) |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
416 |
else |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
417 |
aux tps |
42d39948cace
use SAT4J for "Tests_Nits.thy" for safety (this should solve the Isatest failures) + minor changes
blanchet
parents:
35385
diff
changeset
|
418 |
end |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
419 |
(* bool -> typ -> typ -> typ -> (term * term) list -> term *) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
420 |
fun make_map maybe_opt T1 T2 T2' = |
33192 | 421 |
let |
422 |
val update_const = Const (@{const_name fun_upd}, |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
423 |
(T1 --> T2) --> T1 --> T2 --> T1 --> T2) |
33192 | 424 |
(* (term * term) list -> term *) |
35402 | 425 |
fun aux' [] = Const (@{const_abbrev Map.empty}, T1 --> T2) |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
426 |
| aux' ((t1, t2) :: tps) = |
33192 | 427 |
(case t2 of |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
428 |
Const (@{const_name None}, _) => aux' tps |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
429 |
| _ => update_const $ aux' tps $ t1 $ t2) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
430 |
fun aux tps = |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
431 |
if maybe_opt andalso not (is_complete_type datatypes false T1) then |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
432 |
update_const $ aux' tps $ Const (unrep, T1) |
33192 | 433 |
$ (Const (@{const_name Some}, T2' --> T2) $ Const (unknown, T2')) |
434 |
else |
|
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
435 |
aux' tps |
33192 | 436 |
in aux end |
437 |
(* typ list -> term -> term *) |
|
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
438 |
fun polish_funs Ts t = |
33192 | 439 |
(case fastype_of1 (Ts, t) of |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
440 |
Type (@{type_name fun}, [T1, T2]) => |
33192 | 441 |
if is_plain_fun t then |
442 |
case T2 of |
|
443 |
@{typ bool} => |
|
444 |
let |
|
445 |
val (maybe_opt, ts_pair) = |
|
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
446 |
dest_plain_fun t ||> pairself (map (polish_funs Ts)) |
33192 | 447 |
in |
448 |
make_set maybe_opt T1 T2 |
|
449 |
(sort_wrt (truth_const_sort_key o snd) (op ~~ ts_pair)) |
|
450 |
end |
|
451 |
| Type (@{type_name option}, [T2']) => |
|
452 |
let |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
453 |
val (maybe_opt, ts_pair) = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
454 |
dest_plain_fun t ||> pairself (map (polish_funs Ts)) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
455 |
in make_map maybe_opt T1 T2 T2' (rev (op ~~ ts_pair)) end |
33192 | 456 |
| _ => raise SAME () |
457 |
else |
|
458 |
raise SAME () |
|
459 |
| _ => raise SAME ()) |
|
460 |
handle SAME () => |
|
461 |
case t 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:
34974
diff
changeset
|
462 |
(t1 as Const (@{const_name fun_upd}, _) $ t11 $ _) |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
463 |
$ (t2 as Const (s, _)) => |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
464 |
if s = unknown then polish_funs Ts t11 |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
465 |
else polish_funs Ts t1 $ polish_funs Ts t2 |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
466 |
| t1 $ t2 => polish_funs Ts t1 $ polish_funs Ts t2 |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
467 |
| Abs (s, T, t') => Abs (s, T, polish_funs (T :: Ts) t') |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
468 |
| Const (s, Type (@{type_name fun}, [T1, T2])) => |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
469 |
if s = opt_flag orelse s = non_opt_flag then |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
470 |
Abs ("x", T1, |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
471 |
Const (if is_complete_type datatypes false T1 then |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
472 |
irrelevant |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
473 |
else |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
474 |
unknown, T2)) |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
475 |
else |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
476 |
t |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
477 |
| t => t |
33192 | 478 |
(* bool -> typ -> typ -> typ -> term list -> term list -> term *) |
479 |
fun make_fun maybe_opt T1 T2 T' ts1 ts2 = |
|
34126 | 480 |
ts1 ~~ ts2 |> sort (nice_term_ord o pairself fst) |
34998 | 481 |
|> make_plain_fun maybe_opt T1 T2 |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
482 |
|> unarize_unbox_etc_term |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
483 |
|> typecast_fun (uniterize_unarize_unbox_etc_type T') |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
484 |
(uniterize_unarize_unbox_etc_type T1) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
485 |
(uniterize_unarize_unbox_etc_type T2) |
33192 | 486 |
(* (typ * int) list -> typ -> typ -> int -> term *) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
487 |
fun term_for_atom seen (T as Type (@{type_name fun}, [T1, T2])) T' j _ = |
33192 | 488 |
let |
489 |
val k1 = card_of_type card_assigns T1 |
|
490 |
val k2 = card_of_type card_assigns T2 |
|
491 |
in |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
492 |
term_for_rep true seen T T' (Vect (k1, Atom (k2, 0))) |
33192 | 493 |
[nth_combination (replicate k1 (k2, 0)) j] |
494 |
handle General.Subscript => |
|
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
495 |
raise ARG ("Nitpick_Model.reconstruct_term.term_for_atom", |
33192 | 496 |
signed_string_of_int j ^ " for " ^ |
497 |
string_for_rep (Vect (k1, Atom (k2, 0)))) |
|
498 |
end |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
499 |
| term_for_atom seen (Type (@{type_name "*"}, [T1, T2])) _ j k = |
35075
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
500 |
let |
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
501 |
val k1 = card_of_type card_assigns T1 |
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
502 |
val k2 = k div k1 |
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
503 |
in |
33192 | 504 |
list_comb (HOLogic.pair_const T1 T2, |
35075
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
505 |
map3 (fn T => term_for_atom seen T T) [T1, T2] |
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
506 |
[j div k2, j mod k2] [k1, k2]) (* ### k2 or k1? FIXME *) |
33192 | 507 |
end |
35075
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
508 |
| term_for_atom seen @{typ prop} _ j k = |
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
509 |
HOLogic.mk_Trueprop (term_for_atom seen bool_T bool_T j k) |
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
510 |
| term_for_atom _ @{typ bool} _ j _ = |
33192 | 511 |
if j = 0 then @{const False} else @{const True} |
35075
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
512 |
| term_for_atom _ @{typ unit} _ _ _ = @{const Unity} |
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
513 |
| term_for_atom seen T _ j k = |
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
|
514 |
if T = nat_T andalso is_standard_datatype thy stds nat_T then |
33192 | 515 |
HOLogic.mk_number nat_T j |
516 |
else if T = int_T then |
|
35075
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
517 |
HOLogic.mk_number int_T (int_for_atom (k, 0) j) |
33192 | 518 |
else if is_fp_iterator_type T then |
35075
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
519 |
HOLogic.mk_number nat_T (k - j - 1) |
33192 | 520 |
else if T = @{typ bisim_iterator} then |
521 |
HOLogic.mk_number nat_T j |
|
522 |
else case datatype_spec datatypes T of |
|
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
523 |
NONE => nth_atom pool for_auto T j k |
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
524 |
| SOME {deep = false, ...} => nth_atom pool for_auto T j k |
35179
4b198af5beb5
redo Nitpick's nonstandard values as cyclic values (instead of additional constructors)
blanchet
parents:
35177
diff
changeset
|
525 |
| SOME {co, standard, constrs, ...} => |
33192 | 526 |
let |
527 |
(* styp -> int list *) |
|
528 |
fun tuples_for_const (s, T) = |
|
529 |
tuple_list_for_name rel_table bounds (ConstName (s, T, Any)) |
|
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
530 |
(* unit -> term *) |
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
531 |
fun cyclic_atom () = |
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
532 |
nth_atom pool for_auto (Type (cyclic_type_name, [])) j k |
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
533 |
fun cyclic_var () = Var ((nth_atom_name pool "" T j k, 0), T) |
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
534 |
|
33192 | 535 |
val discr_jsss = map (tuples_for_const o discr_for_constr o #const) |
536 |
constrs |
|
537 |
val real_j = j + offset_of_type ofs T |
|
538 |
val constr_x as (constr_s, constr_T) = |
|
539 |
get_first (fn (jss, {const, ...}) => |
|
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
540 |
if member (op =) jss [real_j] then SOME const |
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
541 |
else NONE) |
33192 | 542 |
(discr_jsss ~~ constrs) |> the |
543 |
val arg_Ts = curried_binder_types constr_T |
|
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35188
diff
changeset
|
544 |
val sel_xs = |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35188
diff
changeset
|
545 |
map (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:
35188
diff
changeset
|
546 |
constr_x) |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35188
diff
changeset
|
547 |
(index_seq 0 (length arg_Ts)) |
33192 | 548 |
val sel_Rs = |
549 |
map (fn x => get_first |
|
550 |
(fn ConstName (s', T', R) => |
|
551 |
if (s', T') = x then SOME R else NONE |
|
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
552 |
| u => raise NUT ("Nitpick_Model.reconstruct_\ |
33192 | 553 |
\term.term_for_atom", [u])) |
554 |
sel_names |> the) sel_xs |
|
555 |
val arg_Rs = map (snd o dest_Func) sel_Rs |
|
556 |
val sel_jsss = map tuples_for_const sel_xs |
|
557 |
val arg_jsss = |
|
558 |
map (map_filter (fn js => if hd js = real_j then SOME (tl js) |
|
559 |
else NONE)) sel_jsss |
|
560 |
val uncur_arg_Ts = binder_types constr_T |
|
35179
4b198af5beb5
redo Nitpick's nonstandard values as cyclic values (instead of additional constructors)
blanchet
parents:
35177
diff
changeset
|
561 |
val maybe_cyclic = co orelse not standard |
33192 | 562 |
in |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
563 |
if maybe_cyclic andalso not (null seen) andalso |
35188
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
564 |
member (op =) (seen |> unfold ? (fst o split_last)) (T, j) then |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
565 |
cyclic_var () |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
566 |
else if constr_s = @{const_name Word} then |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
567 |
HOLogic.mk_number |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
568 |
(if T = @{typ "unsigned_bit word"} then nat_T else int_T) |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
569 |
(value_of_bits (the_single arg_jsss)) |
33192 | 570 |
else |
571 |
let |
|
35179
4b198af5beb5
redo Nitpick's nonstandard values as cyclic values (instead of additional constructors)
blanchet
parents:
35177
diff
changeset
|
572 |
val seen = seen |> maybe_cyclic ? cons (T, j) |
33192 | 573 |
val ts = |
574 |
if length arg_Ts = 0 then |
|
575 |
[] |
|
576 |
else |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
577 |
map3 (fn Ts => |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
578 |
term_for_rep (constr_s <> @{const_name FinFun}) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
579 |
seen Ts Ts) arg_Ts arg_Rs arg_jsss |
33192 | 580 |
|> mk_tuple (HOLogic.mk_tupleT uncur_arg_Ts) |
581 |
|> dest_n_tuple (length uncur_arg_Ts) |
|
582 |
val t = |
|
583 |
if constr_s = @{const_name Abs_Frac} then |
|
35711
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
584 |
case ts of |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
585 |
[Const (@{const_name Pair}, _) $ t1 $ t2] => |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
586 |
frac_from_term_pair (body_type T) t1 t2 |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
587 |
| _ => raise TERM ("Nitpick_Model.reconstruct_term.\ |
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
blanchet
parents:
35665
diff
changeset
|
588 |
\term_for_atom (Abs_Frac)", ts) |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
589 |
else if not for_auto andalso |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
590 |
(is_abs_fun thy constr_x orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
591 |
constr_s = @{const_name Quot}) then |
33192 | 592 |
Const (abs_name, constr_T) $ the_single ts |
593 |
else |
|
594 |
list_comb (Const constr_x, ts) |
|
595 |
in |
|
35179
4b198af5beb5
redo Nitpick's nonstandard values as cyclic values (instead of additional constructors)
blanchet
parents:
35177
diff
changeset
|
596 |
if maybe_cyclic then |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
597 |
let val var = cyclic_var () in |
35188
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
598 |
if unfold andalso not standard andalso |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
599 |
length seen = 1 andalso |
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
600 |
exists_subterm (fn Const (s, _) => |
35188
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
601 |
String.isPrefix cyclic_const_prefix s |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
602 |
| t' => t' = var) t then |
35188
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
603 |
subst_atomic [(var, cyclic_atom ())] t |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
604 |
else if exists_subterm (curry (op =) var) t then |
35179
4b198af5beb5
redo Nitpick's nonstandard values as cyclic values (instead of additional constructors)
blanchet
parents:
35177
diff
changeset
|
605 |
if co then |
4b198af5beb5
redo Nitpick's nonstandard values as cyclic values (instead of additional constructors)
blanchet
parents:
35177
diff
changeset
|
606 |
Const (@{const_name The}, (T --> bool_T) --> T) |
4b198af5beb5
redo Nitpick's nonstandard values as cyclic values (instead of additional constructors)
blanchet
parents:
35177
diff
changeset
|
607 |
$ Abs (cyclic_co_val_name, T, |
4b198af5beb5
redo Nitpick's nonstandard values as cyclic values (instead of additional constructors)
blanchet
parents:
35177
diff
changeset
|
608 |
Const (@{const_name "op ="}, T --> T --> bool_T) |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
609 |
$ Bound 0 $ abstract_over (var, t)) |
35179
4b198af5beb5
redo Nitpick's nonstandard values as cyclic values (instead of additional constructors)
blanchet
parents:
35177
diff
changeset
|
610 |
else |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
611 |
cyclic_atom () |
33192 | 612 |
else |
613 |
t |
|
614 |
end |
|
615 |
else |
|
616 |
t |
|
617 |
end |
|
618 |
end |
|
619 |
(* (typ * int) list -> int -> rep -> typ -> typ -> typ -> int list |
|
620 |
-> term *) |
|
621 |
and term_for_vect seen k R T1 T2 T' js = |
|
35075
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
622 |
make_fun true T1 T2 T' |
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
623 |
(map (fn j => term_for_atom seen T1 T1 j k) (index_seq 0 k)) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
624 |
(map (term_for_rep true seen T2 T2 R o single) |
33192 | 625 |
(batch_list (arity_of_rep R) js)) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
626 |
(* bool -> (typ * int) list -> typ -> typ -> rep -> int list list -> term *) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
627 |
and term_for_rep _ seen T T' Unit [[]] = term_for_atom seen T T' 0 1 |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
628 |
| term_for_rep _ seen T T' (R as Atom (k, j0)) [[j]] = |
35075
888802be2019
handle Nitpick's nonstandard model enumeration in a cleaner way;
blanchet
parents:
35070
diff
changeset
|
629 |
if j >= j0 andalso j < j0 + k then term_for_atom seen T T' (j - j0) k |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
630 |
else raise REP ("Nitpick_Model.reconstruct_term.term_for_rep", [R]) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
631 |
| term_for_rep _ seen (Type (@{type_name "*"}, [T1, T2])) _ |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
632 |
(Struct [R1, R2]) [js] = |
33192 | 633 |
let |
634 |
val arity1 = arity_of_rep R1 |
|
635 |
val (js1, js2) = chop arity1 js |
|
636 |
in |
|
637 |
list_comb (HOLogic.pair_const T1 T2, |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
638 |
map3 (fn T => term_for_rep true seen T T) [T1, T2] [R1, R2] |
33192 | 639 |
[[js1], [js2]]) |
640 |
end |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
641 |
| term_for_rep _ seen (Type (@{type_name fun}, [T1, T2])) T' |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
642 |
(Vect (k, R')) [js] = |
33192 | 643 |
term_for_vect seen k R' T1 T2 T' js |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
644 |
| term_for_rep _ seen (Type (@{type_name fun}, [T1, T2])) T' |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
645 |
(Func (R1, Formula Neut)) jss = |
33192 | 646 |
let |
647 |
val jss1 = all_combinations_for_rep R1 |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
648 |
val ts1 = map (term_for_rep true seen T1 T1 R1 o single) jss1 |
33192 | 649 |
val ts2 = |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
650 |
map (fn js => term_for_rep true seen T2 T2 (Atom (2, 0)) |
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
651 |
[[int_from_bool (member (op =) jss js)]]) |
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
652 |
jss1 |
33192 | 653 |
in make_fun false T1 T2 T' ts1 ts2 end |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
654 |
| term_for_rep maybe_opt seen (Type (@{type_name fun}, [T1, T2])) T' |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
655 |
(Func (R1, R2)) jss = |
33192 | 656 |
let |
657 |
val arity1 = arity_of_rep R1 |
|
658 |
val jss1 = all_combinations_for_rep R1 |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
659 |
val ts1 = map (term_for_rep false seen T1 T1 R1 o single) jss1 |
33192 | 660 |
val grouped_jss2 = AList.group (op =) (map (chop arity1) jss) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
661 |
val ts2 = map (term_for_rep false seen T2 T2 R2 o the_default [] |
33192 | 662 |
o AList.lookup (op =) grouped_jss2) jss1 |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
663 |
in make_fun maybe_opt T1 T2 T' ts1 ts2 end |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
664 |
| term_for_rep _ seen T T' (Opt R) jss = |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
665 |
if null jss then Const (unknown, T) |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
666 |
else term_for_rep true seen T T' R jss |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
667 |
| term_for_rep _ _ T _ R jss = |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
668 |
raise ARG ("Nitpick_Model.reconstruct_term.term_for_rep", |
33192 | 669 |
Refute.string_of_typ T ^ " " ^ string_for_rep R ^ " " ^ |
670 |
string_of_int (length jss)) |
|
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
671 |
in |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
672 |
postprocess_subterms [] o polish_funs [] o unarize_unbox_etc_term |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
673 |
oooo term_for_rep true [] |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
674 |
end |
33192 | 675 |
|
35718 | 676 |
(** Constant postprocessing **) |
677 |
||
678 |
(* int -> typ -> typ list *) |
|
679 |
fun dest_n_tuple_type 1 T = [T] |
|
680 |
| dest_n_tuple_type n (Type (_, [T1, T2])) = |
|
681 |
T1 :: dest_n_tuple_type (n - 1) T2 |
|
682 |
| dest_n_tuple_type _ T = |
|
683 |
raise TYPE ("Nitpick_Model.dest_n_tuple_type", [T], []) |
|
684 |
||
685 |
(* theory -> const_table -> styp -> int list *) |
|
686 |
fun const_format thy def_table (x as (s, T)) = |
|
687 |
if String.isPrefix unrolled_prefix s then |
|
688 |
const_format thy def_table (original_name s, range_type T) |
|
689 |
else if String.isPrefix skolem_prefix s then |
|
690 |
let |
|
691 |
val k = unprefix skolem_prefix s |
|
692 |
|> strip_first_name_sep |> fst |> space_explode "@" |
|
693 |
|> hd |> Int.fromString |> the |
|
694 |
in [k, num_binder_types T - k] end |
|
695 |
else if original_name s <> s then |
|
696 |
[num_binder_types T] |
|
697 |
else case def_of_const thy def_table x of |
|
698 |
SOME t' => if fixpoint_kind_of_rhs t' <> NoFp then |
|
699 |
let val k = length (strip_abs_vars t') in |
|
700 |
[k, num_binder_types T - k] |
|
701 |
end |
|
702 |
else |
|
703 |
[num_binder_types T] |
|
704 |
| NONE => [num_binder_types T] |
|
705 |
(* int list -> int list -> int list *) |
|
706 |
fun intersect_formats _ [] = [] |
|
707 |
| intersect_formats [] _ = [] |
|
708 |
| intersect_formats ks1 ks2 = |
|
709 |
let val ((ks1', k1), (ks2', k2)) = pairself split_last (ks1, ks2) in |
|
710 |
intersect_formats (ks1' @ (if k1 > k2 then [k1 - k2] else [])) |
|
711 |
(ks2' @ (if k2 > k1 then [k2 - k1] else [])) @ |
|
712 |
[Int.min (k1, k2)] |
|
713 |
end |
|
714 |
||
715 |
(* theory -> const_table -> (term option * int list) list -> term -> int list *) |
|
716 |
fun lookup_format thy def_table formats t = |
|
717 |
case AList.lookup (fn (SOME x, SOME y) => |
|
718 |
(term_match thy) (x, y) | _ => false) |
|
719 |
formats (SOME t) of |
|
720 |
SOME format => format |
|
721 |
| NONE => let val format = the (AList.lookup (op =) formats NONE) in |
|
722 |
case t of |
|
723 |
Const x => intersect_formats format |
|
724 |
(const_format thy def_table x) |
|
725 |
| _ => format |
|
726 |
end |
|
727 |
||
728 |
(* int list -> int list -> typ -> typ *) |
|
729 |
fun format_type default_format format T = |
|
730 |
let |
|
731 |
val T = uniterize_unarize_unbox_etc_type T |
|
732 |
val format = format |> filter (curry (op <) 0) |
|
733 |
in |
|
734 |
if forall (curry (op =) 1) format then |
|
735 |
T |
|
736 |
else |
|
737 |
let |
|
738 |
val (binder_Ts, body_T) = strip_type T |
|
739 |
val batched = |
|
740 |
binder_Ts |
|
741 |
|> map (format_type default_format default_format) |
|
742 |
|> rev |> chunk_list_unevenly (rev format) |
|
743 |
|> map (HOLogic.mk_tupleT o rev) |
|
744 |
in List.foldl (op -->) body_T batched end |
|
745 |
end |
|
746 |
(* theory -> const_table -> (term option * int list) list -> term -> typ *) |
|
747 |
fun format_term_type thy def_table formats t = |
|
748 |
format_type (the (AList.lookup (op =) formats NONE)) |
|
749 |
(lookup_format thy def_table formats t) (fastype_of t) |
|
750 |
||
751 |
(* int list -> int -> int list -> int list *) |
|
752 |
fun repair_special_format js m format = |
|
753 |
m - 1 downto 0 |> chunk_list_unevenly (rev format) |
|
754 |
|> map (rev o filter_out (member (op =) js)) |
|
755 |
|> filter_out null |> map length |> rev |
|
756 |
||
757 |
(* hol_context -> string * string -> (term option * int list) list |
|
758 |
-> styp -> term * typ *) |
|
759 |
fun user_friendly_const ({thy, evals, def_table, skolems, special_funs, ...} |
|
760 |
: hol_context) (base_name, step_name) formats = |
|
761 |
let |
|
762 |
val default_format = the (AList.lookup (op =) formats NONE) |
|
763 |
(* styp -> term * typ *) |
|
764 |
fun do_const (x as (s, T)) = |
|
765 |
(if String.isPrefix special_prefix s then |
|
766 |
let |
|
767 |
(* term -> term *) |
|
768 |
val do_term = map_aterms (fn Const x => fst (do_const x) | t' => t') |
|
769 |
val (x' as (_, T'), js, ts) = |
|
770 |
AList.find (op =) (!special_funs) (s, unarize_unbox_etc_type T) |
|
771 |
|> the_single |
|
772 |
val max_j = List.last js |
|
773 |
val Ts = List.take (binder_types T', max_j + 1) |
|
774 |
val missing_js = filter_out (member (op =) js) (0 upto max_j) |
|
775 |
val missing_Ts = filter_indices missing_js Ts |
|
776 |
(* int -> indexname *) |
|
777 |
fun nth_missing_var n = |
|
778 |
((arg_var_prefix ^ nat_subscript (n + 1), 0), nth missing_Ts n) |
|
779 |
val missing_vars = map nth_missing_var (0 upto length missing_js - 1) |
|
780 |
val vars = special_bounds ts @ missing_vars |
|
781 |
val ts' = |
|
782 |
map (fn j => |
|
783 |
case AList.lookup (op =) (js ~~ ts) j of |
|
784 |
SOME t => do_term t |
|
785 |
| NONE => |
|
786 |
Var (nth missing_vars |
|
787 |
(find_index (curry (op =) j) missing_js))) |
|
788 |
(0 upto max_j) |
|
789 |
val t = do_const x' |> fst |
|
790 |
val format = |
|
791 |
case AList.lookup (fn (SOME t1, SOME t2) => term_match thy (t1, t2) |
|
792 |
| _ => false) formats (SOME t) of |
|
793 |
SOME format => |
|
794 |
repair_special_format js (num_binder_types T') format |
|
795 |
| NONE => |
|
796 |
const_format thy def_table x' |
|
797 |
|> repair_special_format js (num_binder_types T') |
|
798 |
|> intersect_formats default_format |
|
799 |
in |
|
800 |
(list_comb (t, ts') |> fold_rev abs_var vars, |
|
801 |
format_type default_format format T) |
|
802 |
end |
|
803 |
else if String.isPrefix uncurry_prefix s then |
|
804 |
let |
|
805 |
val (ss, s') = unprefix uncurry_prefix s |
|
806 |
|> strip_first_name_sep |>> space_explode "@" |
|
807 |
in |
|
808 |
if String.isPrefix step_prefix s' then |
|
809 |
do_const (s', T) |
|
810 |
else |
|
811 |
let |
|
812 |
val k = the (Int.fromString (hd ss)) |
|
813 |
val j = the (Int.fromString (List.last ss)) |
|
814 |
val (before_Ts, (tuple_T, rest_T)) = |
|
815 |
strip_n_binders j T ||> (strip_n_binders 1 #>> hd) |
|
816 |
val T' = before_Ts ---> dest_n_tuple_type k tuple_T ---> rest_T |
|
817 |
in do_const (s', T') end |
|
818 |
end |
|
819 |
else if String.isPrefix unrolled_prefix s then |
|
820 |
let val t = Const (original_name s, range_type T) in |
|
821 |
(lambda (Free (iter_var_prefix, nat_T)) t, |
|
822 |
format_type default_format |
|
823 |
(lookup_format thy def_table formats t) T) |
|
824 |
end |
|
825 |
else if String.isPrefix base_prefix s then |
|
826 |
(Const (base_name, T --> T) $ Const (unprefix base_prefix s, T), |
|
827 |
format_type default_format default_format T) |
|
828 |
else if String.isPrefix step_prefix s then |
|
829 |
(Const (step_name, T --> T) $ Const (unprefix step_prefix s, T), |
|
830 |
format_type default_format default_format T) |
|
831 |
else if String.isPrefix quot_normal_prefix s then |
|
832 |
let val t = Const (nitpick_prefix ^ "normalize quotient type", T) in |
|
833 |
(t, format_term_type thy def_table formats t) |
|
834 |
end |
|
835 |
else if String.isPrefix skolem_prefix s then |
|
836 |
let |
|
837 |
val ss = the (AList.lookup (op =) (!skolems) s) |
|
838 |
val (Ts, Ts') = chop (length ss) (binder_types T) |
|
839 |
val frees = map Free (ss ~~ Ts) |
|
840 |
val s' = original_name s |
|
841 |
in |
|
842 |
(fold lambda frees (Const (s', Ts' ---> T)), |
|
843 |
format_type default_format |
|
844 |
(lookup_format thy def_table formats (Const x)) T) |
|
845 |
end |
|
846 |
else if String.isPrefix eval_prefix s then |
|
847 |
let |
|
848 |
val t = nth evals (the (Int.fromString (unprefix eval_prefix s))) |
|
849 |
in (t, format_term_type thy def_table formats t) end |
|
850 |
else if s = @{const_name undefined_fast_The} then |
|
851 |
(Const (nitpick_prefix ^ "The fallback", T), |
|
852 |
format_type default_format |
|
853 |
(lookup_format thy def_table formats |
|
854 |
(Const (@{const_name The}, (T --> bool_T) --> T))) T) |
|
855 |
else if s = @{const_name undefined_fast_Eps} then |
|
856 |
(Const (nitpick_prefix ^ "Eps fallback", T), |
|
857 |
format_type default_format |
|
858 |
(lookup_format thy def_table formats |
|
859 |
(Const (@{const_name Eps}, (T --> bool_T) --> T))) T) |
|
860 |
else |
|
861 |
let val t = Const (original_name s, T) in |
|
862 |
(t, format_term_type thy def_table formats t) |
|
863 |
end) |
|
864 |
|>> map_types uniterize_unarize_unbox_etc_type |
|
865 |
|>> shorten_names_in_term |>> Term.map_abs_vars shortest_name |
|
866 |
in do_const end |
|
867 |
||
868 |
(* styp -> string *) |
|
869 |
fun assign_operator_for_const (s, T) = |
|
870 |
if String.isPrefix ubfp_prefix s then |
|
871 |
if is_fun_type T then "\<subseteq>" else "\<le>" |
|
872 |
else if String.isPrefix lbfp_prefix s then |
|
873 |
if is_fun_type T then "\<supseteq>" else "\<ge>" |
|
874 |
else if original_name s <> s then |
|
875 |
assign_operator_for_const (strip_first_name_sep s |> snd, T) |
|
876 |
else |
|
877 |
"=" |
|
878 |
||
879 |
(** Model reconstruction **) |
|
880 |
||
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
881 |
(* atom_pool -> scope -> nut list -> nut NameTable.table -> KK.raw_bound list |
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
882 |
-> nut -> term *) |
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
883 |
fun term_for_name pool scope sel_names rel_table bounds name = |
33192 | 884 |
let val T = type_of name in |
885 |
tuple_list_for_name rel_table bounds name |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
886 |
|> reconstruct_term false pool (("", ""), ("", "")) scope sel_names |
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
887 |
rel_table bounds T T (rep_of name) |
33192 | 888 |
end |
889 |
||
890 |
(* term -> term *) |
|
891 |
fun unfold_outer_the_binders (t as Const (@{const_name The}, _) |
|
892 |
$ Abs (s, T, Const (@{const_name "op ="}, _) |
|
893 |
$ Bound 0 $ t')) = |
|
894 |
betapply (Abs (s, T, t'), t) |> unfold_outer_the_binders |
|
895 |
| unfold_outer_the_binders t = t |
|
896 |
(* typ list -> int -> term * term -> bool *) |
|
897 |
fun bisimilar_values _ 0 _ = true |
|
898 |
| bisimilar_values coTs max_depth (t1, t2) = |
|
899 |
let val T = fastype_of t1 in |
|
900 |
if exists_subtype (member (op =) coTs) T then |
|
901 |
let |
|
902 |
val ((head1, args1), (head2, args2)) = |
|
903 |
pairself (strip_comb o unfold_outer_the_binders) (t1, t2) |
|
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
904 |
val max_depth = max_depth - (if member (op =) coTs T then 1 else 0) |
33192 | 905 |
in |
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
906 |
head1 = head2 andalso |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
907 |
forall (bisimilar_values coTs max_depth) (args1 ~~ args2) |
33192 | 908 |
end |
909 |
else |
|
910 |
t1 = t2 |
|
911 |
end |
|
912 |
||
913 |
(* params -> scope -> (term option * int list) list -> styp list -> nut list |
|
34126 | 914 |
-> nut list -> nut list -> nut NameTable.table -> KK.raw_bound list |
33192 | 915 |
-> Pretty.T * bool *) |
916 |
fun reconstruct_hol_model {show_skolems, show_datatypes, show_consts} |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
917 |
({hol_ctxt = {thy, ctxt, max_bisim_depth, boxes, stds, wfs, user_axioms, |
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
918 |
debug, binary_ints, destroy_constrs, specialize, |
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
919 |
skolemize, star_linear_preds, uncurry, fast_descrs, |
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
920 |
tac_timeout, evals, case_names, def_table, nondef_table, |
35807
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35718
diff
changeset
|
921 |
user_nondefs, simp_table, psimp_table, choice_spec_table, |
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35718
diff
changeset
|
922 |
intro_table, ground_thm_table, ersatz_table, skolems, |
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35718
diff
changeset
|
923 |
special_funs, unrolled_preds, wf_cache, constr_cache}, |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35188
diff
changeset
|
924 |
binarize, card_assigns, bits, bisim_depth, datatypes, ofs} : scope) |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
925 |
formats all_frees free_names sel_names nonsel_names rel_table bounds = |
33192 | 926 |
let |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
927 |
val pool = Unsynchronized.ref [] |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
928 |
val (wacky_names as (_, base_step_names), ctxt) = |
33192 | 929 |
add_wacky_syntax ctxt |
35070
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
blanchet
parents:
34998
diff
changeset
|
930 |
val hol_ctxt = |
33192 | 931 |
{thy = thy, ctxt = ctxt, max_bisim_depth = max_bisim_depth, boxes = boxes, |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
932 |
stds = stds, wfs = wfs, user_axioms = user_axioms, debug = debug, |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
933 |
binary_ints = binary_ints, destroy_constrs = destroy_constrs, |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
934 |
specialize = specialize, skolemize = skolemize, |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
935 |
star_linear_preds = star_linear_preds, uncurry = uncurry, |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
936 |
fast_descrs = fast_descrs, tac_timeout = tac_timeout, evals = evals, |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34123
diff
changeset
|
937 |
case_names = case_names, def_table = def_table, |
33192 | 938 |
nondef_table = nondef_table, user_nondefs = user_nondefs, |
939 |
simp_table = simp_table, psimp_table = psimp_table, |
|
35807
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35718
diff
changeset
|
940 |
choice_spec_table = choice_spec_table, intro_table = intro_table, |
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35718
diff
changeset
|
941 |
ground_thm_table = ground_thm_table, ersatz_table = ersatz_table, |
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35718
diff
changeset
|
942 |
skolems = skolems, special_funs = special_funs, |
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35718
diff
changeset
|
943 |
unrolled_preds = unrolled_preds, wf_cache = wf_cache, |
e4d1b5cbd429
added support for "specification" and "ax_specification" constructs to Nitpick
blanchet
parents:
35718
diff
changeset
|
944 |
constr_cache = constr_cache} |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35188
diff
changeset
|
945 |
val scope = {hol_ctxt = hol_ctxt, binarize = binarize, |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35188
diff
changeset
|
946 |
card_assigns = card_assigns, bits = bits, |
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35188
diff
changeset
|
947 |
bisim_depth = bisim_depth, datatypes = datatypes, ofs = ofs} |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
948 |
(* bool -> typ -> typ -> rep -> int list list -> term *) |
35188
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
949 |
fun term_for_rep unfold = |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
950 |
reconstruct_term unfold pool wacky_names scope sel_names rel_table bounds |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
951 |
(* nat -> typ -> nat -> term *) |
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
952 |
fun nth_value_of_type card T n = |
35188
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
953 |
let |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
954 |
(* bool -> term *) |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
955 |
fun aux unfold = term_for_rep unfold T T (Atom (card, 0)) [[n]] |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
956 |
in |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
957 |
case aux false of |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
958 |
t as Const (s, _) => |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
959 |
if String.isPrefix cyclic_const_prefix s then |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
960 |
HOLogic.mk_eq (t, aux true) |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
961 |
else |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
962 |
t |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
963 |
| t => t |
8c70a34931b1
improve Nitpick's "Datatypes" rendering for elements containing cycles
blanchet
parents:
35180
diff
changeset
|
964 |
end |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
965 |
(* nat -> typ -> term list *) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
966 |
val all_values = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
967 |
all_values_of_type pool wacky_names scope sel_names rel_table bounds |
33192 | 968 |
(* dtype_spec list -> dtype_spec -> bool *) |
969 |
fun is_codatatype_wellformed (cos : dtype_spec list) |
|
970 |
({typ, card, ...} : dtype_spec) = |
|
971 |
let |
|
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
972 |
val ts = all_values card typ |
33192 | 973 |
val max_depth = Integer.sum (map #card cos) |
974 |
in |
|
975 |
forall (not o bisimilar_values (map #typ cos) max_depth) |
|
976 |
(all_distinct_unordered_pairs_of ts) |
|
977 |
end |
|
978 |
(* string -> Pretty.T *) |
|
979 |
fun pretty_for_assign name = |
|
980 |
let |
|
981 |
val (oper, (t1, T'), T) = |
|
982 |
case name of |
|
983 |
FreeName (s, T, _) => |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
984 |
let val t = Free (s, uniterize_unarize_unbox_etc_type T) in |
33192 | 985 |
("=", (t, format_term_type thy def_table formats t), T) |
986 |
end |
|
987 |
| ConstName (s, T, _) => |
|
988 |
(assign_operator_for_const (s, T), |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
989 |
user_friendly_const hol_ctxt base_step_names formats (s, T), T) |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
990 |
| _ => raise NUT ("Nitpick_Model.reconstruct_hol_model.\ |
33192 | 991 |
\pretty_for_assign", [name]) |
992 |
val t2 = if rep_of name = Any then |
|
993 |
Const (@{const_name undefined}, T') |
|
994 |
else |
|
995 |
tuple_list_for_name rel_table bounds name |
|
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
996 |
|> term_for_rep false T T' (rep_of name) |
33192 | 997 |
in |
998 |
Pretty.block (Pretty.breaks |
|
33571 | 999 |
[setmp_show_all_types (Syntax.pretty_term ctxt) t1, |
33192 | 1000 |
Pretty.str oper, Syntax.pretty_term ctxt t2]) |
1001 |
end |
|
1002 |
(* dtype_spec -> Pretty.T *) |
|
34123
c4988215a691
distinguish better between "complete" (vs. incomplete) types and "concrete" (vs. abstract) types in Nitpick;
blanchet
parents:
34121
diff
changeset
|
1003 |
fun pretty_for_datatype ({typ, card, complete, ...} : dtype_spec) = |
33192 | 1004 |
Pretty.block (Pretty.breaks |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1005 |
(Syntax.pretty_typ ctxt (uniterize_unarize_unbox_etc_type typ) :: |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1006 |
(case typ of |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1007 |
Type (@{type_name fin_fun}, _) => [Pretty.str "[finite]"] |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1008 |
| Type (@{type_name fun_box}, _) => [Pretty.str "[boxed]"] |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1009 |
| Type (@{type_name pair_box}, _) => [Pretty.str "[boxed]"] |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1010 |
| _ => []) @ |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1011 |
[Pretty.str "=", |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1012 |
Pretty.enum "," "{" "}" |
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35711
diff
changeset
|
1013 |
(map (Syntax.pretty_term ctxt) (all_values card typ) @ |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1014 |
(if fun_from_pair complete false then [] |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1015 |
else [Pretty.str unrep]))])) |
33192 | 1016 |
(* typ -> dtype_spec list *) |
1017 |
fun integer_datatype T = |
|
1018 |
[{typ = T, card = card_of_type card_assigns T, co = false, |
|
35385
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
1019 |
standard = true, complete = (false, false), concrete = (true, true), |
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents:
35280
diff
changeset
|
1020 |
deep = true, constrs = []}] |
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
1021 |
handle TYPE ("Nitpick_HOL.card_of_type", _, _) => [] |
33192 | 1022 |
val (codatatypes, datatypes) = |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34974
diff
changeset
|
1023 |
datatypes |> filter #deep |> List.partition #co |
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
|
1024 |
||> append (integer_datatype int_T |
2bcdae5f4fdb
added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents:
35190
diff
changeset
|
1025 |
|> is_standard_datatype thy stds nat_T |
2bcdae5f4fdb
added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents:
35190
diff
changeset
|
1026 |
? append (integer_datatype nat_T)) |
33192 | 1027 |
val block_of_datatypes = |
1028 |
if show_datatypes andalso not (null datatypes) then |
|
1029 |
[Pretty.big_list ("Datatype" ^ plural_s_for_list datatypes ^ ":") |
|
1030 |
(map pretty_for_datatype datatypes)] |
|
1031 |
else |
|
1032 |
[] |
|
1033 |
val block_of_codatatypes = |
|
1034 |
if show_datatypes andalso not (null codatatypes) then |
|
1035 |
[Pretty.big_list ("Codatatype" ^ plural_s_for_list codatatypes ^ ":") |
|
1036 |
(map pretty_for_datatype codatatypes)] |
|
1037 |
else |
|
1038 |
[] |
|
1039 |
(* bool -> string -> nut list -> Pretty.T list *) |
|
1040 |
fun block_of_names show title names = |
|
1041 |
if show andalso not (null names) then |
|
1042 |
Pretty.str (title ^ plural_s_for_list names ^ ":") |
|
1043 |
:: map (Pretty.indent indent_size o pretty_for_assign) |
|
1044 |
(sort_wrt (original_name o nickname_of) names) |
|
1045 |
else |
|
1046 |
[] |
|
1047 |
val (skolem_names, nonskolem_nonsel_names) = |
|
1048 |
List.partition is_skolem_name nonsel_names |
|
1049 |
val (eval_names, noneval_nonskolem_nonsel_names) = |
|
1050 |
List.partition (String.isPrefix eval_prefix o nickname_of) |
|
1051 |
nonskolem_nonsel_names |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1052 |
||> filter_out (member (op =) [@{const_name bisim}, |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1053 |
@{const_name bisim_iterator_max}] |
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
1054 |
o nickname_of) |
33192 | 1055 |
val free_names = |
1056 |
map (fn x as (s, T) => |
|
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
1057 |
case filter (curry (op =) x |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
1058 |
o pairf nickname_of |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35625
diff
changeset
|
1059 |
(uniterize_unarize_unbox_etc_type o type_of)) |
35190
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
blanchet
parents:
35188
diff
changeset
|
1060 |
free_names of |
33192 | 1061 |
[name] => name |
1062 |
| [] => FreeName (s, T, Any) |
|
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33202
diff
changeset
|
1063 |
| _ => raise TERM ("Nitpick_Model.reconstruct_hol_model", |
33192 | 1064 |
[Const x])) all_frees |
1065 |
val chunks = block_of_names true "Free variable" free_names @ |
|
1066 |
block_of_names show_skolems "Skolem constant" skolem_names @ |
|
1067 |
block_of_names true "Evaluated term" eval_names @ |
|
1068 |
block_of_datatypes @ block_of_codatatypes @ |
|
1069 |
block_of_names show_consts "Constant" |
|
1070 |
noneval_nonskolem_nonsel_names |
|
1071 |
in |
|
1072 |
(Pretty.chunks (if null chunks then [Pretty.str "Empty assignment"] |
|
1073 |
else chunks), |
|
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
1074 |
bisim_depth >= 0 orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34126
diff
changeset
|
1075 |
forall (is_codatatype_wellformed codatatypes) codatatypes) |
33192 | 1076 |
end |
1077 |
||
1078 |
(* scope -> Time.time option -> nut list -> nut list -> nut NameTable.table |
|
34126 | 1079 |
-> KK.raw_bound list -> term -> bool option *) |
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
35220
diff
changeset
|
1080 |
fun prove_hol_model (scope as {hol_ctxt = {thy, ctxt, debug, ...}, |
34998 | 1081 |
card_assigns, ...}) |
33192 | 1082 |
auto_timeout free_names sel_names rel_table bounds prop = |
1083 |
let |
|
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
1084 |
val pool = Unsynchronized.ref [] |
33192 | 1085 |
(* typ * int -> term *) |
1086 |
fun free_type_assm (T, k) = |
|
1087 |
let |
|
1088 |
(* int -> term *) |
|
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
35075
diff
changeset
|
1089 |
fun atom j = nth_atom pool true T j k |
33192 | 1090 |
fun equation_for_atom j = HOLogic.eq_const T $ Bound 0 $ atom j |
1091 |
val eqs = map equation_for_atom (index_seq 0 k) |
|
1092 |
val compreh_assm = |
|
1093 |
Const (@{const_name All}, (T --> bool_T) --> bool_T) |
|
1094 |
$ Abs ("x", T, foldl1 HOLogic.mk_disj eqs) |
|
1095 |
val distinct_assm = distinctness_formula T (map atom (index_seq 0 k)) |
|
34998 | 1096 |
in s_conj (compreh_assm, distinct_assm) end |
33192 | 1097 |
(* nut -> term *) |
1098 |
fun free_name_assm name = |
|
1099 |
HOLogic.mk_eq (Free (nickname_of name, type_of name), |
|
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35179
diff
changeset
|
1100 |
term_for_name pool scope sel_names rel_table bounds name) |
33192 | 1101 |
val freeT_assms = map free_type_assm (filter (is_TFree o fst) card_assigns) |
1102 |
val model_assms = map free_name_assm free_names |
|
34998 | 1103 |
val assm = foldr1 s_conj (freeT_assms @ model_assms) |
33192 | 1104 |
(* bool -> bool *) |
1105 |
fun try_out negate = |
|
1106 |
let |
|
1107 |
val concl = (negate ? curry (op $) @{const Not}) |
|
35625 | 1108 |
(Object_Logic.atomize_term thy prop) |
34998 | 1109 |
val prop = HOLogic.mk_Trueprop (HOLogic.mk_imp (assm, concl)) |
33192 | 1110 |
|> map_types (map_type_tfree |
34998 | 1111 |
(fn (s, []) => TFree (s, HOLogic.typeS) |
1112 |
| x => TFree x)) |
|
1113 |
val _ = if debug then |
|
1114 |
priority ((if negate then "Genuineness" else "Spuriousness") ^ |
|
1115 |
" goal: " ^ Syntax.string_of_term ctxt prop ^ ".") |
|
1116 |
else |
|
1117 |
() |
|
1118 |
val goal = prop |> cterm_of thy |> Goal.init |
|
33192 | 1119 |
in |
1120 |
(goal |> SINGLE (DETERM_TIMEOUT auto_timeout |
|
1121 |
(auto_tac (clasimpset_of ctxt))) |
|
1122 |
|> the |> Goal.finish ctxt; true) |
|
1123 |
handle THM _ => false |
|
1124 |
| TimeLimit.TimeOut => false |
|
1125 |
end |
|
1126 |
in |
|
33705
947184dc75c9
removed a few global names in Nitpick (styp, nat_less, pairf)
blanchet
parents:
33580
diff
changeset
|
1127 |
if try_out false then SOME true |
947184dc75c9
removed a few global names in Nitpick (styp, nat_less, pairf)
blanchet
parents:
33580
diff
changeset
|
1128 |
else if try_out true then SOME false |
33192 | 1129 |
else NONE |
1130 |
end |
|
1131 |
||
1132 |
end; |