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