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