| author | blanchet | 
| Mon, 06 Dec 2010 13:29:23 +0100 | |
| changeset 40996 | 63112be4a469 | 
| parent 40995 | 3cae30b60577 | 
| child 40997 | 67e11a73532a | 
| permissions | -rw-r--r-- | 
| 33982 | 1  | 
(* Title: HOL/Tools/Nitpick/nitpick_mono.ML  | 
| 33192 | 2  | 
Author: Jasmin Blanchette, TU Muenchen  | 
| 
34982
 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 
blanchet 
parents: 
34936 
diff
changeset
 | 
3  | 
Copyright 2009, 2010  | 
| 33192 | 4  | 
|
| 35384 | 5  | 
Monotonicity inference for higher-order logic.  | 
| 33192 | 6  | 
*)  | 
7  | 
||
8  | 
signature NITPICK_MONO =  | 
|
9  | 
sig  | 
|
| 
35070
 
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
 
blanchet 
parents: 
34998 
diff
changeset
 | 
10  | 
type hol_context = Nitpick_HOL.hol_context  | 
| 33192 | 11  | 
|
| 38179 | 12  | 
val trace : bool Unsynchronized.ref  | 
| 33192 | 13  | 
val formulas_monotonic :  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
14  | 
hol_context -> bool -> int -> typ -> term list * term list -> bool  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
15  | 
val finitize_funs :  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
16  | 
hol_context -> bool -> (typ option * bool option) list -> int -> typ  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
17  | 
-> term list * term list -> term list * term list  | 
| 33192 | 18  | 
end;  | 
19  | 
||
| 
33232
 
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
 
blanchet 
parents: 
33192 
diff
changeset
 | 
20  | 
structure Nitpick_Mono : NITPICK_MONO =  | 
| 33192 | 21  | 
struct  | 
22  | 
||
| 
33232
 
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
 
blanchet 
parents: 
33192 
diff
changeset
 | 
23  | 
open Nitpick_Util  | 
| 
 
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
 
blanchet 
parents: 
33192 
diff
changeset
 | 
24  | 
open Nitpick_HOL  | 
| 33192 | 25  | 
|
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
26  | 
structure PL = PropLogic  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
27  | 
|
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
28  | 
datatype sign = Plus | Minus  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
29  | 
|
| 33192 | 30  | 
type var = int  | 
31  | 
||
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
32  | 
datatype annotation = Gen | New | Fls | Tru  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
33  | 
datatype annotation_atom = A of annotation | V of var  | 
| 33192 | 34  | 
|
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
35  | 
type assign_literal = var * (sign * annotation)  | 
| 33192 | 36  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
37  | 
datatype mtyp =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
38  | 
MAlpha |  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
39  | 
MFun of mtyp * annotation_atom * mtyp |  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
40  | 
MPair of mtyp * mtyp |  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
41  | 
MType of string * mtyp list |  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
42  | 
MRec of string * typ list  | 
| 33192 | 43  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
44  | 
datatype mterm =  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
45  | 
MRaw of term * mtyp |  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
46  | 
MAbs of string * typ * mtyp * annotation_atom * mterm |  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
47  | 
MApp of mterm * mterm  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
48  | 
|
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
49  | 
type mdata =  | 
| 
35070
 
96136eb6218f
split "nitpick_hol.ML" into two files to make it more manageable;
 
blanchet 
parents: 
34998 
diff
changeset
 | 
50  | 
  {hol_ctxt: hol_context,
 | 
| 
35190
 
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
 
blanchet 
parents: 
35079 
diff
changeset
 | 
51  | 
binarize: bool,  | 
| 33192 | 52  | 
alpha_T: typ,  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
53  | 
no_harmless: bool,  | 
| 33192 | 54  | 
max_fresh: int Unsynchronized.ref,  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
55  | 
datatype_mcache: ((string * typ list) * mtyp) list Unsynchronized.ref,  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
56  | 
constr_mcache: (styp * mtyp) list Unsynchronized.ref}  | 
| 33192 | 57  | 
|
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
58  | 
exception UNSOLVABLE of unit  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
59  | 
exception MTYPE of string * mtyp list * typ list  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
60  | 
exception MTERM of string * mterm list  | 
| 33192 | 61  | 
|
| 38179 | 62  | 
val trace = Unsynchronized.ref false  | 
63  | 
fun trace_msg msg = if !trace then tracing (msg ()) else ()  | 
|
| 33192 | 64  | 
|
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
65  | 
fun string_for_sign Plus = "+"  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
66  | 
| string_for_sign Minus = "-"  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
67  | 
|
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
68  | 
fun negate_sign Plus = Minus  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
69  | 
| negate_sign Minus = Plus  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
70  | 
|
| 33192 | 71  | 
val string_for_var = signed_string_of_int  | 
72  | 
fun string_for_vars sep [] = "0\<^bsub>" ^ sep ^ "\<^esub>"  | 
|
73  | 
| string_for_vars sep xs = space_implode sep (map string_for_var xs)  | 
|
74  | 
fun subscript_string_for_vars sep xs =  | 
|
75  | 
if null xs then "" else "\<^bsub>" ^ string_for_vars sep xs ^ "\<^esub>"  | 
|
76  | 
||
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
77  | 
fun string_for_annotation Gen = "G"  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
78  | 
| string_for_annotation New = "N"  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
79  | 
| string_for_annotation Fls = "F"  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
80  | 
| string_for_annotation Tru = "T"  | 
| 33192 | 81  | 
|
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
82  | 
fun string_for_annotation_atom (A a) = string_for_annotation a  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
83  | 
| string_for_annotation_atom (V x) = string_for_var x  | 
| 33192 | 84  | 
|
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
85  | 
fun string_for_assign_literal (x, (sn, a)) =  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
86  | 
string_for_var x ^ (case sn of Plus => " = " | Minus => " \<noteq> ") ^  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
87  | 
string_for_annotation a  | 
| 33192 | 88  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
89  | 
val bool_M = MType (@{type_name bool}, [])
 | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
90  | 
val dummy_M = MType (nitpick_prefix ^ "dummy", [])  | 
| 33192 | 91  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
92  | 
fun is_MRec (MRec _) = true  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
93  | 
| is_MRec _ = false  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
94  | 
fun dest_MFun (MFun z) = z  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
95  | 
  | dest_MFun M = raise MTYPE ("Nitpick_Mono.dest_MFun", [M], [])
 | 
| 33192 | 96  | 
|
97  | 
val no_prec = 100  | 
|
98  | 
||
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
99  | 
fun precedence_of_mtype (MFun _) = 1  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
100  | 
| precedence_of_mtype (MPair _) = 2  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
101  | 
| precedence_of_mtype _ = no_prec  | 
| 33192 | 102  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
103  | 
val string_for_mtype =  | 
| 33192 | 104  | 
let  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
105  | 
fun aux outer_prec M =  | 
| 33192 | 106  | 
let  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
107  | 
val prec = precedence_of_mtype M  | 
| 33192 | 108  | 
val need_parens = (prec < outer_prec)  | 
109  | 
in  | 
|
110  | 
        (if need_parens then "(" else "") ^
 | 
|
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
111  | 
(if M = dummy_M then  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
112  | 
"_"  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
113  | 
else case M of  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
114  | 
MAlpha => "\<alpha>"  | 
| 40988 | 115  | 
| MFun (M1, aa, M2) =>  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
116  | 
aux (prec + 1) M1 ^ " \<Rightarrow>\<^bsup>" ^  | 
| 40988 | 117  | 
string_for_annotation_atom aa ^ "\<^esup> " ^ aux prec M2  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
118  | 
| MPair (M1, M2) => aux (prec + 1) M1 ^ " \<times> " ^ aux prec M2  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
119  | 
| MType (s, []) =>  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
120  | 
             if s = @{type_name prop} orelse s = @{type_name bool} then "o"
 | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
121  | 
else s  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
122  | 
           | MType (s, Ms) => "(" ^ commas (map (aux 0) Ms) ^ ") " ^ s
 | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
123  | 
| MRec (s, _) => "[" ^ s ^ "]") ^  | 
| 33192 | 124  | 
(if need_parens then ")" else "")  | 
125  | 
end  | 
|
126  | 
in aux 0 end  | 
|
127  | 
||
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
128  | 
fun flatten_mtype (MPair (M1, M2)) = maps flatten_mtype [M1, M2]  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
129  | 
| flatten_mtype (MType (_, Ms)) = maps flatten_mtype Ms  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
130  | 
| flatten_mtype M = [M]  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
131  | 
|
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
132  | 
fun precedence_of_mterm (MRaw _) = no_prec  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
133  | 
| precedence_of_mterm (MAbs _) = 1  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
134  | 
| precedence_of_mterm (MApp _) = 2  | 
| 33192 | 135  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
136  | 
fun string_for_mterm ctxt =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
137  | 
let  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
138  | 
fun mtype_annotation M = "\<^bsup>" ^ string_for_mtype M ^ "\<^esup>"  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
139  | 
fun aux outer_prec m =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
140  | 
let  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
141  | 
val prec = precedence_of_mterm m  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
142  | 
val need_parens = (prec < outer_prec)  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
143  | 
in  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
144  | 
        (if need_parens then "(" else "") ^
 | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
145  | 
(case m of  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
146  | 
MRaw (t, M) => Syntax.string_of_term ctxt t ^ mtype_annotation M  | 
| 40988 | 147  | 
| MAbs (s, _, M, aa, m) =>  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
148  | 
"\<lambda>" ^ s ^ mtype_annotation M ^ ".\<^bsup>" ^  | 
| 40988 | 149  | 
string_for_annotation_atom aa ^ "\<^esup> " ^ aux prec m  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
150  | 
| MApp (m1, m2) => aux prec m1 ^ " " ^ aux (prec + 1) m2) ^  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
151  | 
(if need_parens then ")" else "")  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
152  | 
end  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
153  | 
in aux 0 end  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
154  | 
|
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
155  | 
fun mtype_of_mterm (MRaw (_, M)) = M  | 
| 40988 | 156  | 
| mtype_of_mterm (MAbs (_, _, M, aa, m)) = MFun (M, aa, mtype_of_mterm m)  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
157  | 
| mtype_of_mterm (MApp (m1, _)) =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
158  | 
case mtype_of_mterm m1 of  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
159  | 
MFun (_, _, M12) => M12  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
160  | 
    | M1 => raise MTYPE ("Nitpick_Mono.mtype_of_mterm", [M1], [])
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
161  | 
|
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
162  | 
fun strip_mcomb (MApp (m1, m2)) = strip_mcomb m1 ||> (fn ms => append ms [m2])  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
163  | 
| strip_mcomb m = (m, [])  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
164  | 
|
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
165  | 
fun initial_mdata hol_ctxt binarize no_harmless alpha_T =  | 
| 
35190
 
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
 
blanchet 
parents: 
35079 
diff
changeset
 | 
166  | 
  ({hol_ctxt = hol_ctxt, binarize = binarize, alpha_T = alpha_T,
 | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
167  | 
no_harmless = no_harmless, max_fresh = Unsynchronized.ref 0,  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
168  | 
datatype_mcache = Unsynchronized.ref [],  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
169  | 
constr_mcache = Unsynchronized.ref []} : mdata)  | 
| 33192 | 170  | 
|
171  | 
fun could_exist_alpha_subtype alpha_T (T as Type (_, Ts)) =  | 
|
| 
34936
 
c4f04bee79f3
some work on Nitpick's support for quotient types;
 
blanchet 
parents: 
34123 
diff
changeset
 | 
172  | 
T = alpha_T orelse (not (is_fp_iterator_type T) andalso  | 
| 
 
c4f04bee79f3
some work on Nitpick's support for quotient types;
 
blanchet 
parents: 
34123 
diff
changeset
 | 
173  | 
exists (could_exist_alpha_subtype alpha_T) Ts)  | 
| 33192 | 174  | 
| could_exist_alpha_subtype alpha_T T = (T = alpha_T)  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
175  | 
fun could_exist_alpha_sub_mtype _ (alpha_T as TFree _) T =  | 
| 
34121
 
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
 
blanchet 
parents: 
33982 
diff
changeset
 | 
176  | 
could_exist_alpha_subtype alpha_T T  | 
| 
37256
 
0dca1ec52999
thread along context instead of theory for typedef lookup
 
blanchet 
parents: 
36385 
diff
changeset
 | 
177  | 
| could_exist_alpha_sub_mtype ctxt alpha_T T =  | 
| 
 
0dca1ec52999
thread along context instead of theory for typedef lookup
 
blanchet 
parents: 
36385 
diff
changeset
 | 
178  | 
(T = alpha_T orelse is_datatype ctxt [(NONE, true)] T)  | 
| 33192 | 179  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
180  | 
fun exists_alpha_sub_mtype MAlpha = true  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
181  | 
| exists_alpha_sub_mtype (MFun (M1, _, M2)) =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
182  | 
exists exists_alpha_sub_mtype [M1, M2]  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
183  | 
| exists_alpha_sub_mtype (MPair (M1, M2)) =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
184  | 
exists exists_alpha_sub_mtype [M1, M2]  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
185  | 
| exists_alpha_sub_mtype (MType (_, Ms)) = exists exists_alpha_sub_mtype Ms  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
186  | 
| exists_alpha_sub_mtype (MRec _) = true  | 
| 33192 | 187  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
188  | 
fun exists_alpha_sub_mtype_fresh MAlpha = true  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
189  | 
| exists_alpha_sub_mtype_fresh (MFun (_, V _, _)) = true  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
190  | 
| exists_alpha_sub_mtype_fresh (MFun (_, _, M2)) =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
191  | 
exists_alpha_sub_mtype_fresh M2  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
192  | 
| exists_alpha_sub_mtype_fresh (MPair (M1, M2)) =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
193  | 
exists exists_alpha_sub_mtype_fresh [M1, M2]  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
194  | 
| exists_alpha_sub_mtype_fresh (MType (_, Ms)) =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
195  | 
exists exists_alpha_sub_mtype_fresh Ms  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
196  | 
| exists_alpha_sub_mtype_fresh (MRec _) = true  | 
| 33192 | 197  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
198  | 
fun constr_mtype_for_binders z Ms =  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
199  | 
fold_rev (fn M => curry3 MFun M (A Gen)) Ms (MRec z)  | 
| 33192 | 200  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
201  | 
fun repair_mtype _ _ MAlpha = MAlpha  | 
| 40988 | 202  | 
| repair_mtype cache seen (MFun (M1, aa, M2)) =  | 
203  | 
MFun (repair_mtype cache seen M1, aa, repair_mtype cache seen M2)  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
204  | 
| repair_mtype cache seen (MPair Mp) =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
205  | 
MPair (pairself (repair_mtype cache seen) Mp)  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
206  | 
| repair_mtype cache seen (MType (s, Ms)) =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
207  | 
MType (s, maps (flatten_mtype o repair_mtype cache seen) Ms)  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
208  | 
| repair_mtype cache seen (MRec (z as (s, _))) =  | 
| 33192 | 209  | 
case AList.lookup (op =) cache z |> the of  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
210  | 
MRec _ => MType (s, [])  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
211  | 
| M => if member (op =) seen M then MType (s, [])  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
212  | 
else repair_mtype cache (M :: seen) M  | 
| 33192 | 213  | 
|
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
214  | 
fun repair_datatype_mcache cache =  | 
| 33192 | 215  | 
let  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
216  | 
fun repair_one (z, M) =  | 
| 33192 | 217  | 
Unsynchronized.change cache  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
218  | 
(AList.update (op =) (z, repair_mtype (!cache) [] M))  | 
| 33192 | 219  | 
in List.app repair_one (rev (!cache)) end  | 
220  | 
||
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
221  | 
fun repair_constr_mcache dtype_cache constr_mcache =  | 
| 33192 | 222  | 
let  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
223  | 
fun repair_one (x, M) =  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
224  | 
Unsynchronized.change constr_mcache  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
225  | 
(AList.update (op =) (x, repair_mtype dtype_cache [] M))  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
226  | 
in List.app repair_one (!constr_mcache) end  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
227  | 
|
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
228  | 
fun is_fin_fun_supported_type @{typ prop} = true
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
229  | 
  | is_fin_fun_supported_type @{typ bool} = true
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
230  | 
  | is_fin_fun_supported_type (Type (@{type_name option}, _)) = true
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
231  | 
| is_fin_fun_supported_type _ = false  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
232  | 
fun fin_fun_body _ _ (t as @{term False}) = SOME t
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
233  | 
  | fin_fun_body _ _ (t as Const (@{const_name None}, _)) = SOME t
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
234  | 
| fin_fun_body dom_T ran_T  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
235  | 
                 ((t0 as Const (@{const_name If}, _))
 | 
| 
38864
 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 
haftmann 
parents: 
38795 
diff
changeset
 | 
236  | 
                  $ (t1 as Const (@{const_name HOL.eq}, _) $ Bound 0 $ t1')
 | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
237  | 
$ t2 $ t3) =  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
238  | 
(if loose_bvar1 (t1', 0) then  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
239  | 
NONE  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
240  | 
else case fin_fun_body dom_T ran_T t3 of  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
241  | 
NONE => NONE  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
242  | 
| SOME t3 =>  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
243  | 
       SOME (t0 $ (Const (@{const_name is_unknown}, dom_T --> bool_T) $ t1')
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
244  | 
                $ (Const (@{const_name unknown}, ran_T)) $ (t0 $ t1 $ t2 $ t3)))
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
245  | 
| fin_fun_body _ _ _ = NONE  | 
| 33192 | 246  | 
|
| 35672 | 247  | 
fun fresh_mfun_for_fun_type (mdata as {max_fresh, ...} : mdata) all_minus
 | 
248  | 
T1 T2 =  | 
|
| 33192 | 249  | 
let  | 
| 35672 | 250  | 
val M1 = fresh_mtype_for_type mdata all_minus T1  | 
251  | 
val M2 = fresh_mtype_for_type mdata all_minus T2  | 
|
| 40988 | 252  | 
val aa = if not all_minus andalso exists_alpha_sub_mtype_fresh M1 andalso  | 
253  | 
is_fin_fun_supported_type (body_type T2) then  | 
|
254  | 
V (Unsynchronized.inc max_fresh)  | 
|
255  | 
else  | 
|
256  | 
A Gen  | 
|
257  | 
in (M1, aa, M2) end  | 
|
| 
37256
 
0dca1ec52999
thread along context instead of theory for typedef lookup
 
blanchet 
parents: 
36385 
diff
changeset
 | 
258  | 
and fresh_mtype_for_type (mdata as {hol_ctxt as {ctxt, ...}, binarize, alpha_T,
 | 
| 35672 | 259  | 
datatype_mcache, constr_mcache, ...})  | 
260  | 
all_minus =  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
261  | 
let  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
262  | 
fun do_type T =  | 
| 33192 | 263  | 
if T = alpha_T then  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
264  | 
MAlpha  | 
| 33192 | 265  | 
else case T of  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
266  | 
        Type (@{type_name fun}, [T1, T2]) =>
 | 
| 39342 | 267  | 
MFun (fresh_mfun_for_fun_type mdata all_minus T1 T2)  | 
| 
38190
 
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
 
blanchet 
parents: 
38179 
diff
changeset
 | 
268  | 
      | Type (@{type_name prod}, [T1, T2]) => MPair (pairself do_type (T1, T2))
 | 
| 33192 | 269  | 
| Type (z as (s, _)) =>  | 
| 
37256
 
0dca1ec52999
thread along context instead of theory for typedef lookup
 
blanchet 
parents: 
36385 
diff
changeset
 | 
270  | 
if could_exist_alpha_sub_mtype ctxt alpha_T T then  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
271  | 
case AList.lookup (op =) (!datatype_mcache) z of  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
272  | 
SOME M => M  | 
| 33192 | 273  | 
| NONE =>  | 
274  | 
let  | 
|
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
275  | 
val _ = Unsynchronized.change datatype_mcache (cons (z, MRec z))  | 
| 
35219
 
15a5f213ef5b
fix bug in Nitpick's monotonicity code w.r.t. binary integers
 
blanchet 
parents: 
35190 
diff
changeset
 | 
276  | 
val xs = binarized_and_boxed_datatype_constrs hol_ctxt binarize T  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
277  | 
val (all_Ms, constr_Ms) =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
278  | 
fold_rev (fn (_, T') => fn (all_Ms, constr_Ms) =>  | 
| 33192 | 279  | 
let  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
280  | 
val binder_Ms = map do_type (binder_types T')  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
281  | 
val new_Ms = filter exists_alpha_sub_mtype_fresh  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
282  | 
binder_Ms  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
283  | 
val constr_M = constr_mtype_for_binders z  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
284  | 
binder_Ms  | 
| 33192 | 285  | 
in  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
286  | 
(union (op =) new_Ms all_Ms,  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
287  | 
constr_M :: constr_Ms)  | 
| 33192 | 288  | 
end)  | 
289  | 
xs ([], [])  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
290  | 
val M = MType (s, all_Ms)  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
291  | 
val _ = Unsynchronized.change datatype_mcache  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
292  | 
(AList.update (op =) (z, M))  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
293  | 
val _ = Unsynchronized.change constr_mcache  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
294  | 
(append (xs ~~ constr_Ms))  | 
| 33192 | 295  | 
in  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
296  | 
if forall (not o is_MRec o snd) (!datatype_mcache) then  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
297  | 
(repair_datatype_mcache datatype_mcache;  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
298  | 
repair_constr_mcache (!datatype_mcache) constr_mcache;  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
299  | 
AList.lookup (op =) (!datatype_mcache) z |> the)  | 
| 33192 | 300  | 
else  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
301  | 
M  | 
| 33192 | 302  | 
end  | 
303  | 
else  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
304  | 
MType (s, [])  | 
| 
37260
 
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
 
blanchet 
parents: 
37256 
diff
changeset
 | 
305  | 
| _ => MType (simple_string_of_typ T, [])  | 
| 33192 | 306  | 
in do_type end  | 
307  | 
||
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
308  | 
fun prodM_factors (MPair (M1, M2)) = maps prodM_factors [M1, M2]  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
309  | 
| prodM_factors M = [M]  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
310  | 
fun curried_strip_mtype (MFun (M1, _, M2)) =  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
311  | 
curried_strip_mtype M2 |>> append (prodM_factors M1)  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
312  | 
| curried_strip_mtype M = ([], M)  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
313  | 
fun sel_mtype_from_constr_mtype s M =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
314  | 
let val (arg_Ms, dataM) = curried_strip_mtype M in  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
315  | 
MFun (dataM, A Gen,  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
316  | 
case sel_no_from_name s of ~1 => bool_M | n => nth arg_Ms n)  | 
| 33192 | 317  | 
end  | 
318  | 
||
| 
37256
 
0dca1ec52999
thread along context instead of theory for typedef lookup
 
blanchet 
parents: 
36385 
diff
changeset
 | 
319  | 
fun mtype_for_constr (mdata as {hol_ctxt = {ctxt, ...}, alpha_T, constr_mcache,
 | 
| 33192 | 320  | 
...}) (x as (_, T)) =  | 
| 
37256
 
0dca1ec52999
thread along context instead of theory for typedef lookup
 
blanchet 
parents: 
36385 
diff
changeset
 | 
321  | 
if could_exist_alpha_sub_mtype ctxt alpha_T T then  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
322  | 
case AList.lookup (op =) (!constr_mcache) x of  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
323  | 
SOME M => M  | 
| 35384 | 324  | 
| NONE => if T = alpha_T then  | 
| 35672 | 325  | 
let val M = fresh_mtype_for_type mdata false T in  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
326  | 
(Unsynchronized.change constr_mcache (cons (x, M)); M)  | 
| 35384 | 327  | 
end  | 
328  | 
else  | 
|
| 35672 | 329  | 
(fresh_mtype_for_type mdata false (body_type T);  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
330  | 
AList.lookup (op =) (!constr_mcache) x |> the)  | 
| 33192 | 331  | 
else  | 
| 35672 | 332  | 
fresh_mtype_for_type mdata false T  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
333  | 
fun mtype_for_sel (mdata as {hol_ctxt, binarize, ...}) (x as (s, _)) =
 | 
| 
35190
 
ce653cc27a94
make sure that Nitpick uses binary notation consistently if "binary_ints" is enabled
 
blanchet 
parents: 
35079 
diff
changeset
 | 
334  | 
x |> binarized_and_boxed_constr_for_sel hol_ctxt binarize  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
335  | 
|> mtype_for_constr mdata |> sel_mtype_from_constr_mtype s  | 
| 33192 | 336  | 
|
| 40989 | 337  | 
fun resolve_annotation_atom asgs (V x) =  | 
338  | 
x |> AList.lookup (op =) asgs |> Option.map A |> the_default (V x)  | 
|
| 40988 | 339  | 
| resolve_annotation_atom _ aa = aa  | 
| 40989 | 340  | 
fun resolve_mtype asgs =  | 
| 33192 | 341  | 
let  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
342  | 
fun aux MAlpha = MAlpha  | 
| 40988 | 343  | 
| aux (MFun (M1, aa, M2)) =  | 
| 40989 | 344  | 
MFun (aux M1, resolve_annotation_atom asgs aa, aux M2)  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
345  | 
| aux (MPair Mp) = MPair (pairself aux Mp)  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
346  | 
| aux (MType (s, Ms)) = MType (s, map aux Ms)  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
347  | 
| aux (MRec z) = MRec z  | 
| 33192 | 348  | 
in aux end  | 
349  | 
||
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
350  | 
datatype comp_op = Eq | Neq | Leq  | 
| 33192 | 351  | 
|
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
352  | 
type comp = annotation_atom * annotation_atom * comp_op * var list  | 
| 
40995
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
353  | 
type assign_clause = assign_literal list  | 
| 33192 | 354  | 
|
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
355  | 
type constraint_set = comp list * assign_clause list  | 
| 33192 | 356  | 
|
357  | 
fun string_for_comp_op Eq = "="  | 
|
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
358  | 
| string_for_comp_op Neq = "\<noteq>"  | 
| 33192 | 359  | 
| string_for_comp_op Leq = "\<le>"  | 
360  | 
||
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
361  | 
fun string_for_comp (aa1, aa2, cmp, xs) =  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
362  | 
string_for_annotation_atom aa1 ^ " " ^ string_for_comp_op cmp ^  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
363  | 
subscript_string_for_vars " \<and> " xs ^ " " ^ string_for_annotation_atom aa2  | 
| 33192 | 364  | 
|
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
365  | 
fun string_for_assign_clause [] = "\<bot>"  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
366  | 
| string_for_assign_clause asgs =  | 
| 
40995
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
367  | 
space_implode " \<or> " (map string_for_assign_literal asgs)  | 
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
368  | 
|
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
369  | 
fun add_assign_literal (x, (sn, a)) clauses =  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
370  | 
if exists (fn [(x', (sn', a'))] =>  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
371  | 
x = x' andalso ((sn = sn' andalso a <> a') orelse  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
372  | 
(sn <> sn' andalso a = a'))  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
373  | 
| _ => false) clauses then  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
374  | 
NONE  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
375  | 
else  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
376  | 
SOME ([(x, a)] :: clauses)  | 
| 33192 | 377  | 
|
| 
40991
 
902ad76994d5
proper handling of assignment disjunctions vs. conjunctions
 
blanchet 
parents: 
40990 
diff
changeset
 | 
378  | 
fun add_assign_disjunct _ NONE = NONE  | 
| 
 
902ad76994d5
proper handling of assignment disjunctions vs. conjunctions
 
blanchet 
parents: 
40990 
diff
changeset
 | 
379  | 
| add_assign_disjunct asg (SOME asgs) = SOME (insert (op =) asg asgs)  | 
| 
 
902ad76994d5
proper handling of assignment disjunctions vs. conjunctions
 
blanchet 
parents: 
40990 
diff
changeset
 | 
380  | 
|
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
381  | 
fun annotation_comp Eq a1 a2 = (a1 = a2)  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
382  | 
| annotation_comp Neq a1 a2 = (a1 <> a2)  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
383  | 
| annotation_comp Leq a1 a2 = (a1 = a2 orelse a2 = Gen)  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
384  | 
|
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
385  | 
fun comp_op_sign Eq = Plus  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
386  | 
| comp_op_sign Neq = Minus  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
387  | 
| comp_op_sign Leq =  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
388  | 
    raise BAD ("Nitpick_Mono.comp_op_sign", "unexpected \"Leq\"")
 | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
389  | 
|
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
390  | 
fun do_annotation_atom_comp Leq [] aa1 aa2 (cset as (comps, clauses)) =  | 
| 40988 | 391  | 
(case (aa1, aa2) of  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
392  | 
(A a1, A a2) => if annotation_comp Leq a1 a2 then SOME cset else NONE  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
393  | 
| _ => SOME (insert (op =) (aa1, aa2, Leq, []) comps, clauses))  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
394  | 
| do_annotation_atom_comp cmp [] aa1 aa2 (cset as (comps, clauses)) =  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
395  | 
(case (aa1, aa2) of  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
396  | 
(A a1, A a2) => if annotation_comp cmp a1 a2 then SOME cset else NONE  | 
| 40988 | 397  | 
| (V x1, A a2) =>  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
398  | 
clauses |> add_assign_literal (x1, (comp_op_sign cmp, a2))  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
399  | 
|> Option.map (pair comps)  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
400  | 
| (A _, V _) => do_annotation_atom_comp cmp [] aa2 aa1 cset  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
401  | 
| (V _, V _) => SOME (insert (op =) (aa1, aa2, cmp, []) comps, clauses))  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
402  | 
| do_annotation_atom_comp cmp xs aa1 aa2 (comps, clauses) =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
403  | 
SOME (insert (op =) (aa1, aa2, cmp, xs) comps, clauses)  | 
| 33192 | 404  | 
|
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
405  | 
fun add_annotation_atom_comp cmp xs aa1 aa2  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
406  | 
((comps, clauses) : constraint_set) =  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
407  | 
(trace_msg (fn () => "*** Add " ^ string_for_annotation_atom aa1 ^ " " ^  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
408  | 
string_for_comp_op cmp ^ " " ^  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
409  | 
string_for_annotation_atom aa2);  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
410  | 
case do_annotation_atom_comp cmp xs aa1 aa2 (comps, clauses) of  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
411  | 
NONE => (trace_msg (K "**** Unsolvable"); raise UNSOLVABLE ())  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
412  | 
| SOME cset => cset)  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
413  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
414  | 
fun do_mtype_comp _ _ _ _ NONE = NONE  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
415  | 
| do_mtype_comp _ _ MAlpha MAlpha cset = cset  | 
| 40988 | 416  | 
| do_mtype_comp Eq xs (MFun (M11, aa1, M12)) (MFun (M21, aa2, M22))  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
417  | 
(SOME cset) =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
418  | 
cset |> do_annotation_atom_comp Eq xs aa1 aa2  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
419  | 
|> do_mtype_comp Eq xs M11 M21 |> do_mtype_comp Eq xs M12 M22  | 
| 40988 | 420  | 
| do_mtype_comp Leq xs (MFun (M11, aa1, M12)) (MFun (M21, aa2, M22))  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
421  | 
(SOME cset) =  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
422  | 
(if exists_alpha_sub_mtype M11 then  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
423  | 
cset |> do_annotation_atom_comp Leq xs aa1 aa2  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
424  | 
|> do_mtype_comp Leq xs M21 M11  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
425  | 
|> (case aa2 of  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
426  | 
A Gen => I  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
427  | 
| A _ => do_mtype_comp Leq xs M11 M21  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
428  | 
| V x => do_mtype_comp Leq (x :: xs) M11 M21)  | 
| 33192 | 429  | 
else  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
430  | 
SOME cset)  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
431  | 
|> do_mtype_comp Leq xs M12 M22  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
432  | 
| do_mtype_comp cmp xs (M1 as MPair (M11, M12)) (M2 as MPair (M21, M22))  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
433  | 
cset =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
434  | 
(cset |> fold (uncurry (do_mtype_comp cmp xs)) [(M11, M21), (M12, M22)]  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
435  | 
handle Library.UnequalLengths =>  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
436  | 
            raise MTYPE ("Nitpick_Mono.do_mtype_comp", [M1, M2], []))
 | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
437  | 
| do_mtype_comp _ _ (MType _) (MType _) cset =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
438  | 
cset (* no need to compare them thanks to the cache *)  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
439  | 
| do_mtype_comp cmp _ M1 M2 _ =  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
440  | 
    raise MTYPE ("Nitpick_Mono.do_mtype_comp (" ^ string_for_comp_op cmp ^ ")",
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
441  | 
[M1, M2], [])  | 
| 33192 | 442  | 
|
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
443  | 
fun add_mtype_comp cmp M1 M2 cset =  | 
| 
40991
 
902ad76994d5
proper handling of assignment disjunctions vs. conjunctions
 
blanchet 
parents: 
40990 
diff
changeset
 | 
444  | 
(trace_msg (fn () => "*** Add " ^ string_for_mtype M1 ^ " " ^  | 
| 
 
902ad76994d5
proper handling of assignment disjunctions vs. conjunctions
 
blanchet 
parents: 
40990 
diff
changeset
 | 
445  | 
string_for_comp_op cmp ^ " " ^ string_for_mtype M2);  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
446  | 
case SOME cset |> do_mtype_comp cmp [] M1 M2 of  | 
| 
40991
 
902ad76994d5
proper handling of assignment disjunctions vs. conjunctions
 
blanchet 
parents: 
40990 
diff
changeset
 | 
447  | 
NONE => (trace_msg (K "**** Unsolvable"); raise UNSOLVABLE ())  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
448  | 
| SOME cset => cset)  | 
| 33192 | 449  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
450  | 
val add_mtypes_equal = add_mtype_comp Eq  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
451  | 
val add_is_sub_mtype = add_mtype_comp Leq  | 
| 33192 | 452  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
453  | 
fun do_notin_mtype_fv _ _ _ NONE = NONE  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
454  | 
| do_notin_mtype_fv Minus _ MAlpha cset = cset  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
455  | 
| do_notin_mtype_fv Plus [] MAlpha _ = NONE  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
456  | 
| do_notin_mtype_fv Plus [asg] MAlpha (SOME clauses) =  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
457  | 
clauses |> add_assign_literal asg  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
458  | 
| do_notin_mtype_fv Plus clause MAlpha (SOME clauses) =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
459  | 
SOME (insert (op =) clause clauses)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
460  | 
| do_notin_mtype_fv sn clause (MFun (M1, A a, M2)) cset =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
461  | 
cset |> (if a <> Gen andalso sn = Plus then do_notin_mtype_fv Plus clause M1  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
462  | 
else I)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
463  | 
|> (if a = Gen orelse sn = Plus then do_notin_mtype_fv Minus clause M1  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
464  | 
else I)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
465  | 
|> do_notin_mtype_fv sn clause M2  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
466  | 
| do_notin_mtype_fv Plus clause (MFun (M1, V x, M2)) cset =  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
467  | 
cset |> (case add_assign_disjunct (x, (Plus, Gen)) (SOME clause) of  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
468  | 
NONE => I  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
469  | 
| SOME clause' => do_notin_mtype_fv Plus clause' M1)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
470  | 
|> do_notin_mtype_fv Minus clause M1  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
471  | 
|> do_notin_mtype_fv Plus clause M2  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
472  | 
| do_notin_mtype_fv Minus clause (MFun (M1, V x, M2)) cset =  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
473  | 
cset |> (case fold (fn a => add_assign_disjunct (x, (Plus, a))) [Fls, Tru]  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
474  | 
(SOME clause) of  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
475  | 
NONE => I  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
476  | 
| SOME clause' => do_notin_mtype_fv Plus clause' M1)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
477  | 
|> do_notin_mtype_fv Minus clause M2  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
478  | 
| do_notin_mtype_fv sn clause (MPair (M1, M2)) cset =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
479  | 
cset |> fold (do_notin_mtype_fv sn clause) [M1, M2]  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
480  | 
| do_notin_mtype_fv sn clause (MType (_, Ms)) cset =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
481  | 
cset |> fold (do_notin_mtype_fv sn clause) Ms  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
482  | 
| do_notin_mtype_fv _ _ M _ =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
483  | 
   raise MTYPE ("Nitpick_Mono.do_notin_mtype_fv", [M], [])
 | 
| 33192 | 484  | 
|
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
485  | 
fun add_notin_mtype_fv sn M ((comps, clauses) : constraint_set) =  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
486  | 
(trace_msg (fn () => "*** Add " ^ string_for_mtype M ^ " is " ^  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
487  | 
(case sn of Minus => "concrete" | Plus => "complete"));  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
488  | 
case SOME clauses |> do_notin_mtype_fv sn [] M of  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
489  | 
NONE => (trace_msg (K "**** Unsolvable"); raise UNSOLVABLE ())  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
490  | 
| SOME clauses => (comps, clauses))  | 
| 33192 | 491  | 
|
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
492  | 
val add_mtype_is_concrete = add_notin_mtype_fv Minus  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
493  | 
val add_mtype_is_complete = add_notin_mtype_fv Plus  | 
| 33192 | 494  | 
|
| 
40986
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
495  | 
val bool_table =  | 
| 
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
496  | 
[(Gen, (false, false)),  | 
| 
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
497  | 
(New, (false, true)),  | 
| 
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
498  | 
(Fls, (true, false)),  | 
| 
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
499  | 
(Tru, (true, true))]  | 
| 
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
500  | 
|
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
501  | 
fun fst_var n = 2 * n  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
502  | 
fun snd_var n = 2 * n + 1  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
503  | 
|
| 
40986
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
504  | 
val bools_from_annotation = AList.lookup (op =) bool_table #> the  | 
| 
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
505  | 
val annotation_from_bools = AList.find (op =) bool_table #> the_single  | 
| 33192 | 506  | 
|
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
507  | 
fun prop_for_bool b = if b then PL.True else PL.False  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
508  | 
fun prop_for_bool_var_equality (v1, v2) =  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
509  | 
PL.And (PL.Or (PL.BoolVar v1, PL.Not (PL.BoolVar v2)),  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
510  | 
PL.Or (PL.Not (PL.BoolVar v1), PL.BoolVar v2))  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
511  | 
fun prop_for_assign (x, a) =  | 
| 
40986
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
512  | 
let val (b1, b2) = bools_from_annotation a in  | 
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
513  | 
PL.And (PL.BoolVar (fst_var x) |> not b1 ? PL.Not,  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
514  | 
PL.BoolVar (snd_var x) |> not b2 ? PL.Not)  | 
| 
40986
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
515  | 
end  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
516  | 
fun prop_for_assign_literal (x, (Plus, a)) = prop_for_assign (x, a)  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
517  | 
| prop_for_assign_literal (x, (Minus, a)) = PL.Not (prop_for_assign (x, a))  | 
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
518  | 
fun prop_for_atom_assign (A a', a) = prop_for_bool (a = a')  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
519  | 
| prop_for_atom_assign (V x, a) = prop_for_assign_literal (x, (Plus, a))  | 
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
520  | 
fun prop_for_atom_equality (aa1, A a2) = prop_for_atom_assign (aa1, a2)  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
521  | 
| prop_for_atom_equality (A a1, aa2) = prop_for_atom_assign (aa2, a1)  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
522  | 
| prop_for_atom_equality (V x1, V x2) =  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
523  | 
PL.And (prop_for_bool_var_equality (pairself fst_var (x1, x2)),  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
524  | 
prop_for_bool_var_equality (pairself snd_var (x1, x2)))  | 
| 
40995
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
525  | 
val prop_for_assign_clause = PL.exists o map prop_for_assign_literal  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
526  | 
fun prop_for_exists_var_assign_literal xs a =  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
527  | 
PL.exists (map (fn x => prop_for_assign_literal (x, (Plus, a))) xs)  | 
| 40988 | 528  | 
fun prop_for_comp (aa1, aa2, Eq, []) =  | 
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
529  | 
PL.SAnd (prop_for_comp (aa1, aa2, Leq, []),  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
530  | 
prop_for_comp (aa2, aa1, Leq, []))  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
531  | 
| prop_for_comp (aa1, aa2, Neq, []) =  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
532  | 
PL.Not (prop_for_comp (aa1, aa2, Eq, []))  | 
| 40988 | 533  | 
| prop_for_comp (aa1, aa2, Leq, []) =  | 
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
534  | 
PL.SOr (prop_for_atom_equality (aa1, aa2), prop_for_atom_assign (aa2, Gen))  | 
| 40988 | 535  | 
| prop_for_comp (aa1, aa2, cmp, xs) =  | 
| 
40995
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
536  | 
PL.SOr (prop_for_exists_var_assign_literal xs Gen,  | 
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
537  | 
prop_for_comp (aa1, aa2, cmp, []))  | 
| 33192 | 538  | 
|
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
539  | 
(* The "calculus" parameter may be 1, 2, or 3, corresponding approximately to  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
540  | 
the M1, M2, and M3 calculi from Blanchette & Krauss 2011. *)  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
541  | 
fun variable_domain calculus =  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
542  | 
[Gen] @ (if calculus > 1 then [Fls] else [])  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
543  | 
@ (if calculus > 2 then [New, Tru] else [])  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
544  | 
|
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
545  | 
fun prop_for_variable_domain calculus x =  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
546  | 
PL.exists (map (fn a => prop_for_assign_literal (x, (Plus, a)))  | 
| 
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
547  | 
(variable_domain calculus))  | 
| 
40986
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
548  | 
|
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
549  | 
fun extract_assigns max_var assigns asgs =  | 
| 33192 | 550  | 
fold (fn x => fn accum =>  | 
| 40989 | 551  | 
if AList.defined (op =) asgs x then  | 
| 33192 | 552  | 
accum  | 
| 
40986
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
553  | 
else case (fst_var x, snd_var x) |> pairself assigns of  | 
| 
 
cfd91aa80701
use boolean pair to encode annotation, which may now take four values
 
blanchet 
parents: 
40985 
diff
changeset
 | 
554  | 
(NONE, NONE) => accum  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
555  | 
| bp => (x, annotation_from_bools (pairself (the_default false) bp))  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
556  | 
:: accum)  | 
| 40989 | 557  | 
(max_var downto 1) asgs  | 
| 33192 | 558  | 
|
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
559  | 
fun print_problem calculus comps clauses =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
560  | 
trace_msg (fn () =>  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
561  | 
"*** Problem (calculus M" ^ string_of_int calculus ^ "):\n" ^  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
562  | 
cat_lines (map string_for_comp comps @  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
563  | 
map string_for_assign_clause clauses))  | 
| 33192 | 564  | 
|
| 40989 | 565  | 
fun print_solution asgs =  | 
566  | 
trace_msg (fn () => "*** Solution:\n" ^  | 
|
567  | 
(asgs  | 
|
568  | 
|> map swap  | 
|
569  | 
|> AList.group (op =)  | 
|
570  | 
|> map (fn (a, xs) => string_for_annotation a ^ ": " ^  | 
|
571  | 
string_for_vars ", " xs)  | 
|
572  | 
|> space_implode "\n"))  | 
|
| 33192 | 573  | 
|
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
574  | 
fun solve calculus max_var (comps, clauses) =  | 
| 40146 | 575  | 
let  | 
| 
40996
 
63112be4a469
added "Neq" operator to monotonicity inference module
 
blanchet 
parents: 
40995 
diff
changeset
 | 
576  | 
val asgs = map_filter (fn [(x, (_, a))] => SOME (x, a) | _ => NONE) clauses  | 
| 40146 | 577  | 
fun do_assigns assigns =  | 
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
578  | 
SOME (extract_assigns max_var assigns asgs |> tap print_solution)  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
579  | 
val _ = print_problem calculus comps clauses  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
580  | 
val prop =  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
581  | 
map prop_for_comp comps @  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
582  | 
map prop_for_assign_clause clauses @  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
583  | 
(if calculus < 3 then  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
584  | 
map (prop_for_variable_domain calculus) (1 upto max_var)  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
585  | 
else  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
586  | 
[])  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
587  | 
|> PL.all  | 
| 40146 | 588  | 
in  | 
| 
40990
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
589  | 
if PL.eval (K false) prop then  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
590  | 
do_assigns (K (SOME false))  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
591  | 
else if PL.eval (K true) prop then  | 
| 
 
a36d4d869439
adapt monotonicity code to four annotation types
 
blanchet 
parents: 
40989 
diff
changeset
 | 
592  | 
do_assigns (K (SOME true))  | 
| 40146 | 593  | 
else  | 
594  | 
let  | 
|
595  | 
(* use the first ML solver (to avoid startup overhead) *)  | 
|
596  | 
val solvers = !SatSolver.solvers  | 
|
597  | 
|> filter (member (op =) ["dptsat", "dpll"] o fst)  | 
|
598  | 
in  | 
|
599  | 
case snd (hd solvers) prop of  | 
|
600  | 
SatSolver.SATISFIABLE assigns => do_assigns assigns  | 
|
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
601  | 
| _ => (trace_msg (K "*** Unsolvable"); NONE)  | 
| 40146 | 602  | 
end  | 
603  | 
end  | 
|
| 33192 | 604  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
605  | 
type mtype_schema = mtyp * constraint_set  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
606  | 
type mtype_context =  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
607  | 
  {bound_Ts: typ list,
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
608  | 
bound_Ms: mtyp list,  | 
| 
40987
 
7d52af07bff1
added frame component to Gamma in monotonicity calculus
 
blanchet 
parents: 
40986 
diff
changeset
 | 
609  | 
bound_frame: (int * annotation_atom) list,  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
610  | 
frees: (styp * mtyp) list,  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
611  | 
consts: (styp * mtyp) list}  | 
| 33192 | 612  | 
|
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
613  | 
val string_for_frame =  | 
| 
40995
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
614  | 
map (fn (j, aa) => "#" ^ string_of_int j ^ " |-> " ^  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
615  | 
string_for_annotation_atom aa)  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
616  | 
#> commas #> enclose "[" "]"  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
617  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
618  | 
type accumulator = mtype_context * constraint_set  | 
| 33192 | 619  | 
|
| 
40987
 
7d52af07bff1
added frame component to Gamma in monotonicity calculus
 
blanchet 
parents: 
40986 
diff
changeset
 | 
620  | 
val initial_gamma =  | 
| 
 
7d52af07bff1
added frame component to Gamma in monotonicity calculus
 
blanchet 
parents: 
40986 
diff
changeset
 | 
621  | 
  {bound_Ts = [], bound_Ms = [], bound_frame = [], frees = [], consts = []}
 | 
| 33192 | 622  | 
|
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
623  | 
fun push_bound aa T M {bound_Ts, bound_Ms, bound_frame, frees, consts} =
 | 
| 
40987
 
7d52af07bff1
added frame component to Gamma in monotonicity calculus
 
blanchet 
parents: 
40986 
diff
changeset
 | 
624  | 
  {bound_Ts = T :: bound_Ts, bound_Ms = M :: bound_Ms,
 | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
625  | 
bound_frame = (length bound_Ts, aa) :: bound_frame, frees = frees,  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
626  | 
consts = consts}  | 
| 
40987
 
7d52af07bff1
added frame component to Gamma in monotonicity calculus
 
blanchet 
parents: 
40986 
diff
changeset
 | 
627  | 
fun pop_bound {bound_Ts, bound_Ms, bound_frame, frees, consts} =
 | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
628  | 
  {bound_Ts = tl bound_Ts, bound_Ms = tl bound_Ms,
 | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
629  | 
bound_frame = bound_frame  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
630  | 
|> filter_out (fn (j, _) => j = length bound_Ts - 1),  | 
| 
40987
 
7d52af07bff1
added frame component to Gamma in monotonicity calculus
 
blanchet 
parents: 
40986 
diff
changeset
 | 
631  | 
frees = frees, consts = consts}  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
632  | 
handle List.Empty => initial_gamma (* FIXME: needed? *)  | 
| 33192 | 633  | 
|
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
634  | 
fun set_frame bound_frame ({bound_Ts, bound_Ms, frees, consts, ...}
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
635  | 
: mtype_context) =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
636  | 
  {bound_Ts = bound_Ts, bound_Ms = bound_Ms, bound_frame = bound_frame,
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
637  | 
frees = frees, consts = consts}  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
638  | 
|
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
639  | 
(* FIXME: make sure tracing messages are complete *)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
640  | 
|
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
641  | 
fun add_comp_frame a cmp frame =  | 
| 
40995
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
642  | 
(trace_msg (fn () => "*** Add " ^ string_for_annotation a ^ " " ^  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
643  | 
string_for_comp_op cmp ^ " " ^  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
644  | 
string_for_frame frame);  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
645  | 
fold (add_annotation_atom_comp cmp [] (A a) o snd) frame)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
646  | 
|
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
647  | 
fun add_bound_frame j frame =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
648  | 
let  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
649  | 
val (new_frame, gen_frame) = List.partition (curry (op =) j o fst) frame  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
650  | 
in  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
651  | 
add_comp_frame New Leq new_frame  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
652  | 
#> add_comp_frame Gen Eq gen_frame  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
653  | 
end  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
654  | 
|
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
655  | 
fun fresh_imp_frame ({max_fresh, ...} : mdata) sn =
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
656  | 
let  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
657  | 
fun do_var (j, A Fls) = (j, A (case sn of Plus => Fls | Minus => Tru))  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
658  | 
| do_var (j, A Gen) = (j, A Gen)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
659  | 
| do_var (j, _) = (j, V (Unsynchronized.inc max_fresh))  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
660  | 
in map do_var end  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
661  | 
|
| 
40995
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
662  | 
fun do_not_var j aa0 aa1 _ = I  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
663  | 
(*  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
664  | 
x1 ~= T | x0 = F  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
665  | 
x1 ~= F | x0 = T  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
666  | 
x1 ~= G | x0 = G  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
667  | 
x1 ~= N | x0 = G  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
668  | 
*)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
669  | 
|
| 
40995
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
670  | 
fun do_conj_var j aa0 aa1 aa2 = I  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
671  | 
(*  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
672  | 
(x1 ≠T | x2 ≠T | x0 = T) &  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
673  | 
(x1 ≠F | x0 = F) &  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
674  | 
(x2 ≠F | x0 = F) &  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
675  | 
(x1 ≠G | x2 = F | x0 = G) &  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
676  | 
(x1 ≠N | x2 = F | x0 = G) &  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
677  | 
(x1 = F | x2 ≠G | x0 = G) &  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
678  | 
(x1 = F | x2 ≠N | x0 = G)"  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
679  | 
*)  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
680  | 
|
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
681  | 
fun do_disj_var j aa0 aa1 aa2 = I  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
682  | 
fun do_imp_var j aa0 aa1 aa2 = I  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
683  | 
|
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
684  | 
fun add_connective_frames do_var res_frame frame1 frame2 =  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
685  | 
fold I (map3 (fn (j, aa0) => fn (_, aa1) => fn (_, aa2) =>  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
686  | 
do_var j aa0 aa1 aa2) res_frame frame1 frame2)  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
687  | 
|
| 39359 | 688  | 
fun consider_term (mdata as {hol_ctxt = {thy, ctxt, stds, ...}, alpha_T,
 | 
689  | 
max_fresh, ...}) =  | 
|
| 33192 | 690  | 
let  | 
| 
37476
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
691  | 
fun is_enough_eta_expanded t =  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
692  | 
case strip_comb t of  | 
| 39359 | 693  | 
(Const x, ts) => the_default 0 (arity_of_built_in_const thy stds x)  | 
| 
37476
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
694  | 
<= length ts  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
695  | 
| _ => true  | 
| 35672 | 696  | 
val mtype_for = fresh_mtype_for_type mdata false  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
697  | 
fun plus_set_mtype_for_dom M =  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
698  | 
MFun (M, A (if exists_alpha_sub_mtype M then Fls else Gen), bool_M)  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
699  | 
fun do_all T (gamma, cset) =  | 
| 33192 | 700  | 
let  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
701  | 
val abs_M = mtype_for (domain_type (domain_type T))  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
702  | 
val body_M = mtype_for (body_type T)  | 
| 33192 | 703  | 
in  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
704  | 
(MFun (MFun (abs_M, A Gen, body_M), A Gen, body_M),  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
705  | 
(gamma, cset |> add_mtype_is_complete abs_M))  | 
| 33192 | 706  | 
end  | 
707  | 
fun do_equals T (gamma, cset) =  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
708  | 
let val M = mtype_for (domain_type T) in  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
709  | 
(MFun (M, A Gen, MFun (M, V (Unsynchronized.inc max_fresh),  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
710  | 
mtype_for (nth_range_type 2 T))),  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
711  | 
(gamma, cset |> add_mtype_is_concrete M))  | 
| 33192 | 712  | 
end  | 
713  | 
fun do_robust_set_operation T (gamma, cset) =  | 
|
714  | 
let  | 
|
715  | 
val set_T = domain_type T  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
716  | 
val M1 = mtype_for set_T  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
717  | 
val M2 = mtype_for set_T  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
718  | 
val M3 = mtype_for set_T  | 
| 33192 | 719  | 
in  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
720  | 
(MFun (M1, A Gen, MFun (M2, A Gen, M3)),  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
721  | 
(gamma, cset |> add_is_sub_mtype M1 M3 |> add_is_sub_mtype M2 M3))  | 
| 33192 | 722  | 
end  | 
723  | 
fun do_fragile_set_operation T (gamma, cset) =  | 
|
724  | 
let  | 
|
725  | 
val set_T = domain_type T  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
726  | 
val set_M = mtype_for set_T  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
727  | 
        fun custom_mtype_for (T as Type (@{type_name fun}, [T1, T2])) =
 | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
728  | 
if T = set_T then set_M  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
729  | 
else MFun (custom_mtype_for T1, A Gen, custom_mtype_for T2)  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
730  | 
| custom_mtype_for T = mtype_for T  | 
| 33192 | 731  | 
in  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
732  | 
(custom_mtype_for T, (gamma, cset |> add_mtype_is_concrete set_M))  | 
| 33192 | 733  | 
end  | 
734  | 
fun do_pair_constr T accum =  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
735  | 
case mtype_for (nth_range_type 2 T) of  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
736  | 
M as MPair (a_M, b_M) =>  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
737  | 
(MFun (a_M, A Gen, MFun (b_M, A Gen, M)), accum)  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
738  | 
      | M => raise MTYPE ("Nitpick_Mono.consider_term.do_pair_constr", [M], [])
 | 
| 33192 | 739  | 
fun do_nth_pair_sel n T =  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
740  | 
case mtype_for (domain_type T) of  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
741  | 
M as MPair (a_M, b_M) =>  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
742  | 
pair (MFun (M, A Gen, if n = 0 then a_M else b_M))  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
743  | 
      | M => raise MTYPE ("Nitpick_Mono.consider_term.do_nth_pair_sel", [M], [])
 | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
744  | 
fun do_bounded_quantifier t0 abs_s abs_T connective_t bound_t body_t accum =  | 
| 33192 | 745  | 
let  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
746  | 
val abs_M = mtype_for abs_T  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
747  | 
val aa = V (Unsynchronized.inc max_fresh)  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
748  | 
val (bound_m, accum) =  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
749  | 
accum |>> push_bound aa abs_T abs_M |> do_term bound_t  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
750  | 
val expected_bound_M = plus_set_mtype_for_dom abs_M  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
751  | 
val (body_m, accum) =  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
752  | 
accum ||> add_mtypes_equal expected_bound_M (mtype_of_mterm bound_m)  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
753  | 
|> do_term body_t ||> apfst pop_bound  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
754  | 
val bound_M = mtype_of_mterm bound_m  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
755  | 
val (M1, aa', _) = dest_MFun bound_M  | 
| 33192 | 756  | 
in  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
757  | 
(MApp (MRaw (t0, MFun (bound_M, aa, bool_M)),  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
758  | 
MAbs (abs_s, abs_T, M1, aa',  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
759  | 
MApp (MApp (MRaw (connective_t,  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
760  | 
mtype_for (fastype_of connective_t)),  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
761  | 
MApp (bound_m, MRaw (Bound 0, M1))),  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
762  | 
body_m))), accum)  | 
| 33192 | 763  | 
end  | 
| 
40995
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
764  | 
    and do_connect do_var t0 t1 t2 (accum as ({bound_frame, ...}, _)) =
 | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
765  | 
let  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
766  | 
val frame1 = fresh_imp_frame mdata Minus bound_frame  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
767  | 
val frame2 = fresh_imp_frame mdata Plus bound_frame  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
768  | 
val (m1, accum) = accum |>> set_frame frame1 |> do_term t1  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
769  | 
val (m2, accum) = accum |>> set_frame frame2 |> do_term t2  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
770  | 
in  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
771  | 
(MApp (MApp (MRaw (t0, mtype_for (fastype_of t0)), m1), m2),  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
772  | 
accum |>> set_frame bound_frame  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
773  | 
||> add_connective_frames do_var bound_frame frame1 frame2)  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
774  | 
end  | 
| 
40987
 
7d52af07bff1
added frame component to Gamma in monotonicity calculus
 
blanchet 
parents: 
40986 
diff
changeset
 | 
775  | 
    and do_term t (accum as ({bound_Ts, bound_Ms, bound_frame, frees, consts},
 | 
| 
 
7d52af07bff1
added frame component to Gamma in monotonicity calculus
 
blanchet 
parents: 
40986 
diff
changeset
 | 
776  | 
cset)) =  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
777  | 
(trace_msg (fn () => " \<Gamma> \<turnstile> " ^  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
778  | 
Syntax.string_of_term ctxt t ^ " : _?");  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
779  | 
case t of  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
780  | 
         @{const False} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
781  | 
(MRaw (t, bool_M), accum ||> add_comp_frame Fls Leq bound_frame)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
782  | 
       | @{const True} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
783  | 
(MRaw (t, bool_M), accum ||> add_comp_frame Tru Leq bound_frame)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
784  | 
| Const (x as (s, T)) =>  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
785  | 
(case AList.lookup (op =) consts x of  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
786  | 
SOME M => (M, accum)  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
787  | 
| NONE =>  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
788  | 
if not (could_exist_alpha_subtype alpha_T T) then  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
789  | 
(mtype_for T, accum)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
790  | 
else case s of  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
791  | 
              @{const_name all} => do_all T accum
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
792  | 
            | @{const_name "=="} => do_equals T accum
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
793  | 
            | @{const_name All} => do_all T accum
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
794  | 
            | @{const_name Ex} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
795  | 
let val set_T = domain_type T in  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
796  | 
do_term (Abs (Name.uu, set_T,  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
797  | 
                              @{const Not} $ (HOLogic.mk_eq
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
798  | 
(Abs (Name.uu, domain_type set_T,  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
799  | 
                                        @{const False}),
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
800  | 
Bound 0)))) accum  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
801  | 
|>> mtype_of_mterm  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
802  | 
end  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
803  | 
            | @{const_name HOL.eq} => do_equals T accum
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
804  | 
            | @{const_name The} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
805  | 
(trace_msg (K "*** The"); raise UNSOLVABLE ())  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
806  | 
            | @{const_name Eps} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
807  | 
(trace_msg (K "*** Eps"); raise UNSOLVABLE ())  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
808  | 
            | @{const_name If} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
809  | 
do_robust_set_operation (range_type T) accum  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
810  | 
|>> curry3 MFun bool_M (A Gen)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
811  | 
            | @{const_name Pair} => do_pair_constr T accum
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
812  | 
            | @{const_name fst} => do_nth_pair_sel 0 T accum
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
813  | 
            | @{const_name snd} => do_nth_pair_sel 1 T accum
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
814  | 
            | @{const_name Id} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
815  | 
(MFun (mtype_for (domain_type T), A Gen, bool_M), accum)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
816  | 
            | @{const_name converse} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
817  | 
let  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
818  | 
val x = Unsynchronized.inc max_fresh  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
819  | 
fun mtype_for_set T =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
820  | 
MFun (mtype_for (domain_type T), V x, bool_M)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
821  | 
val ab_set_M = domain_type T |> mtype_for_set  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
822  | 
val ba_set_M = range_type T |> mtype_for_set  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
823  | 
in (MFun (ab_set_M, A Gen, ba_set_M), accum) end  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
824  | 
            | @{const_name trancl} => do_fragile_set_operation T accum
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
825  | 
            | @{const_name rel_comp} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
826  | 
let  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
827  | 
val x = Unsynchronized.inc max_fresh  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
828  | 
fun mtype_for_set T =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
829  | 
MFun (mtype_for (domain_type T), V x, bool_M)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
830  | 
val bc_set_M = domain_type T |> mtype_for_set  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
831  | 
val ab_set_M = domain_type (range_type T) |> mtype_for_set  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
832  | 
val ac_set_M = nth_range_type 2 T |> mtype_for_set  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
833  | 
in  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
834  | 
(MFun (bc_set_M, A Gen, MFun (ab_set_M, A Gen, ac_set_M)),  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
835  | 
accum)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
836  | 
end  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
837  | 
            | @{const_name image} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
838  | 
let  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
839  | 
val a_M = mtype_for (domain_type (domain_type T))  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
840  | 
val b_M = mtype_for (range_type (domain_type T))  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
841  | 
in  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
842  | 
(MFun (MFun (a_M, A Gen, b_M), A Gen,  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
843  | 
MFun (plus_set_mtype_for_dom a_M, A Gen,  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
844  | 
plus_set_mtype_for_dom b_M)), accum)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
845  | 
end  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
846  | 
            | @{const_name finite} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
847  | 
let val M1 = mtype_for (domain_type (domain_type T)) in  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
848  | 
(MFun (plus_set_mtype_for_dom M1, A Gen, bool_M), accum)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
849  | 
end  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
850  | 
            | @{const_name Sigma} =>
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
851  | 
let  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
852  | 
val x = Unsynchronized.inc max_fresh  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
853  | 
fun mtype_for_set T =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
854  | 
MFun (mtype_for (domain_type T), V x, bool_M)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
855  | 
val a_set_T = domain_type T  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
856  | 
val a_M = mtype_for (domain_type a_set_T)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
857  | 
val b_set_M =  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
858  | 
mtype_for_set (range_type (domain_type (range_type T)))  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
859  | 
val a_set_M = mtype_for_set a_set_T  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
860  | 
val a_to_b_set_M = MFun (a_M, A Gen, b_set_M)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
861  | 
val ab_set_M = mtype_for_set (nth_range_type 2 T)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
862  | 
in  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
863  | 
(MFun (a_set_M, A Gen, MFun (a_to_b_set_M, A Gen, ab_set_M)),  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
864  | 
accum)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
865  | 
end  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
866  | 
| _ =>  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
867  | 
              if s = @{const_name safe_The} then
 | 
| 33192 | 868  | 
let  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
869  | 
val a_set_M = mtype_for (domain_type T)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
870  | 
val a_M = dest_MFun a_set_M |> #1  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
871  | 
in (MFun (a_set_M, A Gen, a_M), accum) end  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
872  | 
              else if s = @{const_name ord_class.less_eq} andalso
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
873  | 
is_set_type (domain_type T) then  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
874  | 
do_fragile_set_operation T accum  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
875  | 
else if is_sel s then  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
876  | 
(mtype_for_sel mdata x, accum)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
877  | 
else if is_constr ctxt stds x then  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
878  | 
(mtype_for_constr mdata x, accum)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
879  | 
else if is_built_in_const thy stds x then  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
880  | 
(fresh_mtype_for_type mdata true T, accum)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
881  | 
else  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
882  | 
let val M = mtype_for T in  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
883  | 
                  (M, ({bound_Ts = bound_Ts, bound_Ms = bound_Ms,
 | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
884  | 
bound_frame = bound_frame, frees = frees,  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
885  | 
consts = (x, M) :: consts}, cset))  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
886  | 
end)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
887  | 
|>> curry MRaw t  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
888  | 
||> apsnd (add_comp_frame Gen Eq bound_frame)  | 
| 33192 | 889  | 
| Free (x as (_, T)) =>  | 
890  | 
(case AList.lookup (op =) frees x of  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
891  | 
SOME M => (M, accum)  | 
| 33192 | 892  | 
| NONE =>  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
893  | 
let val M = mtype_for T in  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
894  | 
                (M, ({bound_Ts = bound_Ts, bound_Ms = bound_Ms,
 | 
| 
40987
 
7d52af07bff1
added frame component to Gamma in monotonicity calculus
 
blanchet 
parents: 
40986 
diff
changeset
 | 
895  | 
bound_frame = bound_frame, frees = (x, M) :: frees,  | 
| 
 
7d52af07bff1
added frame component to Gamma in monotonicity calculus
 
blanchet 
parents: 
40986 
diff
changeset
 | 
896  | 
consts = consts}, cset))  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
897  | 
end)  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
898  | 
|>> curry MRaw t ||> apsnd (add_comp_frame Gen Eq bound_frame)  | 
| 38179 | 899  | 
| Var _ => (trace_msg (K "*** Var"); raise UNSOLVABLE ())  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
900  | 
| Bound j =>  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
901  | 
(MRaw (t, nth bound_Ms j),  | 
| 
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
902  | 
accum ||> add_bound_frame (length bound_Ts - j - 1) bound_frame)  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
903  | 
| Abs (s, T, t') =>  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
904  | 
(case fin_fun_body T (fastype_of1 (T :: bound_Ts, t')) t' of  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
905  | 
SOME t' =>  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
906  | 
let  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
907  | 
val M = mtype_for T  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
908  | 
val (m', accum) = do_term t' (accum |>> push_bound (A Fls) T M)  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
909  | 
in (MAbs (s, T, M, A Fls, m'), accum |>> pop_bound) end  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
910  | 
| NONE =>  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
911  | 
((case t' of  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
912  | 
t1' $ Bound 0 =>  | 
| 
37476
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
913  | 
if not (loose_bvar1 (t1', 0)) andalso  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
914  | 
is_enough_eta_expanded t1' then  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
915  | 
do_term (incr_boundvars ~1 t1') accum  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
916  | 
else  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
917  | 
raise SAME ()  | 
| 
38864
 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 
haftmann 
parents: 
38795 
diff
changeset
 | 
918  | 
                | (t11 as Const (@{const_name HOL.eq}, _)) $ Bound 0 $ t13 =>
 | 
| 
37476
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
919  | 
if not (loose_bvar1 (t13, 0)) then  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
920  | 
do_term (incr_boundvars ~1 (t11 $ t13)) accum  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
921  | 
else  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
922  | 
raise SAME ()  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
923  | 
| _ => raise SAME ())  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
924  | 
handle SAME () =>  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
925  | 
let  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
926  | 
val M = mtype_for T  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
927  | 
val aa = V (Unsynchronized.inc max_fresh)  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
928  | 
val (m', accum) =  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
929  | 
do_term t' (accum |>> push_bound aa T M)  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
930  | 
in (MAbs (s, T, M, aa, m'), accum |>> pop_bound) end))  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
931  | 
         | (t0 as Const (@{const_name All}, _))
 | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
932  | 
           $ Abs (s', T', (t10 as @{const HOL.implies})
 | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
933  | 
$ (t11 $ Bound 0) $ t12) =>  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
934  | 
do_bounded_quantifier t0 s' T' t10 t11 t12 accum  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
935  | 
         | (t0 as Const (@{const_name Ex}, _))
 | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
936  | 
           $ Abs (s', T', (t10 as @{const HOL.conj})
 | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
937  | 
$ (t11 $ Bound 0) $ t12) =>  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
938  | 
do_bounded_quantifier t0 s' T' t10 t11 t12 accum  | 
| 
40995
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
939  | 
         | (t0 as @{const Not}) $ t1 =>
 | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
940  | 
let  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
941  | 
val frame1 = fresh_imp_frame mdata Minus bound_frame  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
942  | 
val (m1, accum) = accum |>> set_frame frame1 |> do_term t1  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
943  | 
in  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
944  | 
(MApp (MRaw (t0, mtype_for (fastype_of t0)), m1),  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
945  | 
accum |>> set_frame bound_frame  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
946  | 
||> add_connective_frames do_not_var bound_frame frame1  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
947  | 
frame1)  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
948  | 
end  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
949  | 
         | (t0 as @{const conj}) $ t1 $ t2 =>
 | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
950  | 
do_connect do_conj_var t0 t1 t2 accum  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
951  | 
         | (t0 as @{const disj}) $ t1 $ t2 =>
 | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
952  | 
do_connect do_disj_var t0 t1 t2 accum  | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
953  | 
         | (t0 as @{const implies}) $ t1 $ t2 =>
 | 
| 
 
3cae30b60577
started implementing connectives in new monotonicity calculus
 
blanchet 
parents: 
40994 
diff
changeset
 | 
954  | 
do_connect do_imp_var t0 t1 t2 accum  | 
| 33192 | 955  | 
         | Const (@{const_name Let}, _) $ t1 $ t2 =>
 | 
956  | 
do_term (betapply (t2, t1)) accum  | 
|
957  | 
| t1 $ t2 =>  | 
|
958  | 
let  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
959  | 
val (m1, accum) = do_term t1 accum  | 
| 
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
960  | 
val (m2, accum) = do_term t2 accum  | 
| 33192 | 961  | 
in  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
962  | 
let  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
963  | 
val M11 = mtype_of_mterm m1 |> dest_MFun |> #1  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
964  | 
val M2 = mtype_of_mterm m2  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
965  | 
in (MApp (m1, m2), accum ||> add_is_sub_mtype M2 M11) end  | 
| 33192 | 966  | 
end)  | 
| 38179 | 967  | 
|> tap (fn (m, _) => trace_msg (fn () => " \<Gamma> \<turnstile> " ^  | 
968  | 
string_for_mterm ctxt m))  | 
|
| 33192 | 969  | 
in do_term end  | 
970  | 
||
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
971  | 
fun force_minus_funs 0 _ = I  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
972  | 
| force_minus_funs n (M as MFun (M1, _, M2)) =  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
973  | 
add_mtypes_equal M (MFun (M1, A Gen, M2)) #> force_minus_funs (n - 1) M2  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
974  | 
| force_minus_funs _ M =  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
975  | 
    raise MTYPE ("Nitpick_Mono.force_minus_funs", [M], [])
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
976  | 
fun consider_general_equals mdata def (x as (_, T)) t1 t2 accum =  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
977  | 
let  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
978  | 
val (m1, accum) = consider_term mdata t1 accum  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
979  | 
val (m2, accum) = consider_term mdata t2 accum  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
980  | 
val M1 = mtype_of_mterm m1  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
981  | 
val M2 = mtype_of_mterm m2  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
982  | 
val accum = accum ||> add_mtypes_equal M1 M2  | 
| 35672 | 983  | 
val body_M = fresh_mtype_for_type mdata false (nth_range_type 2 T)  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
984  | 
val m = MApp (MApp (MRaw (Const x,  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
985  | 
MFun (M1, A Gen, MFun (M2, A Gen, body_M))), m1), m2)  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
986  | 
in  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
987  | 
(m, if def then  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
988  | 
let val (head_m, arg_ms) = strip_mcomb m1 in  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
989  | 
accum ||> force_minus_funs (length arg_ms) (mtype_of_mterm head_m)  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
990  | 
end  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
991  | 
else  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
992  | 
accum)  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
993  | 
end  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
994  | 
|
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
995  | 
fun consider_general_formula (mdata as {hol_ctxt = {ctxt, ...}, ...}) =
 | 
| 33192 | 996  | 
let  | 
| 35672 | 997  | 
val mtype_for = fresh_mtype_for_type mdata false  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
998  | 
val do_term = consider_term mdata  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
999  | 
fun do_formula sn t accum =  | 
| 33192 | 1000  | 
let  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1001  | 
fun do_quantifier (quant_x as (quant_s, _)) abs_s abs_T body_t =  | 
| 33192 | 1002  | 
let  | 
| 
35385
 
29f81babefd7
improved precision of infinite "shallow" datatypes in Nitpick;
 
blanchet 
parents: 
35384 
diff
changeset
 | 
1003  | 
val abs_M = mtype_for abs_T  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
1004  | 
val a = Gen (* FIXME: strengthen *)  | 
| 
34982
 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 
blanchet 
parents: 
34936 
diff
changeset
 | 
1005  | 
              val side_cond = ((sn = Minus) = (quant_s = @{const_name Ex}))
 | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1006  | 
val (body_m, accum) =  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1007  | 
accum ||> side_cond ? add_mtype_is_complete abs_M  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
1008  | 
|>> push_bound (A a) abs_T abs_M |> do_formula sn body_t  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1009  | 
val body_M = mtype_of_mterm body_m  | 
| 33192 | 1010  | 
in  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1011  | 
(MApp (MRaw (Const quant_x,  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
1012  | 
MFun (MFun (abs_M, A Gen, body_M), A Gen, body_M)),  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
1013  | 
MAbs (abs_s, abs_T, abs_M, A Gen, body_m)),  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1014  | 
accum |>> pop_bound)  | 
| 33192 | 1015  | 
end  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1016  | 
fun do_equals x t1 t2 =  | 
| 33192 | 1017  | 
case sn of  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1018  | 
Plus => do_term t accum  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1019  | 
| Minus => consider_general_equals mdata false x t1 t2 accum  | 
| 33192 | 1020  | 
in  | 
| 38179 | 1021  | 
(trace_msg (fn () => " \<Gamma> \<turnstile> " ^  | 
1022  | 
Syntax.string_of_term ctxt t ^ " : o\<^sup>" ^  | 
|
1023  | 
string_for_sign sn ^ "?");  | 
|
| 
37704
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1024  | 
case t of  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1025  | 
             Const (x as (@{const_name all}, _)) $ Abs (s1, T1, t1) =>
 | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1026  | 
do_quantifier x s1 T1 t1  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1027  | 
           | Const (x as (@{const_name "=="}, _)) $ t1 $ t2 => do_equals x t1 t2
 | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1028  | 
           | @{const Trueprop} $ t1 =>
 | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1029  | 
let val (m1, accum) = do_formula sn t1 accum in  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1030  | 
               (MApp (MRaw (@{const Trueprop}, mtype_for (bool_T --> prop_T)),
 | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1031  | 
m1), accum)  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1032  | 
end  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1033  | 
           | @{const Not} $ t1 =>
 | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
1034  | 
let val (m1, accum) = do_formula (negate_sign sn) t1 accum in  | 
| 
37704
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1035  | 
               (MApp (MRaw (@{const Not}, mtype_for (bool_T --> bool_T)), m1),
 | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1036  | 
accum)  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1037  | 
end  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1038  | 
           | Const (x as (@{const_name All}, _)) $ Abs (s1, T1, t1) =>
 | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1039  | 
do_quantifier x s1 T1 t1  | 
| 39345 | 1040  | 
           | Const (x0 as (@{const_name Ex}, T0))
 | 
| 
37704
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1041  | 
$ (t1 as Abs (s1, T1, t1')) =>  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1042  | 
(case sn of  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1043  | 
Plus => do_quantifier x0 s1 T1 t1'  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1044  | 
| Minus =>  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1045  | 
(* FIXME: Move elsewhere *)  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1046  | 
                do_term (@{const Not}
 | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1047  | 
$ (HOLogic.eq_const (domain_type T0) $ t1  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1048  | 
                            $ Abs (Name.uu, T1, @{const False}))) accum)
 | 
| 
38864
 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 
haftmann 
parents: 
38795 
diff
changeset
 | 
1049  | 
           | Const (x as (@{const_name HOL.eq}, _)) $ t1 $ t2 =>
 | 
| 
37704
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1050  | 
do_equals x t1 t2  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1051  | 
           | Const (@{const_name Let}, _) $ t1 $ t2 =>
 | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1052  | 
do_formula sn (betapply (t2, t1)) accum  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1053  | 
| (t0 as Const (s0, _)) $ t1 $ t2 =>  | 
| 
38199
 
8a9cace789d6
deal correctly with Pure.conjunction in mono check
 
blanchet 
parents: 
38190 
diff
changeset
 | 
1054  | 
             if s0 = @{const_name "==>"} orelse
 | 
| 
 
8a9cace789d6
deal correctly with Pure.conjunction in mono check
 
blanchet 
parents: 
38190 
diff
changeset
 | 
1055  | 
                s0 = @{const_name Pure.conjunction} orelse
 | 
| 
38795
 
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
 
haftmann 
parents: 
38786 
diff
changeset
 | 
1056  | 
                s0 = @{const_name HOL.conj} orelse
 | 
| 
 
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
 
haftmann 
parents: 
38786 
diff
changeset
 | 
1057  | 
                s0 = @{const_name HOL.disj} orelse
 | 
| 
38786
 
e46e7a9cb622
formerly unnamed infix impliciation now named HOL.implies
 
haftmann 
parents: 
38199 
diff
changeset
 | 
1058  | 
                s0 = @{const_name HOL.implies} then
 | 
| 
37704
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1059  | 
let  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1060  | 
                 val impl = (s0 = @{const_name "==>"} orelse
 | 
| 
38786
 
e46e7a9cb622
formerly unnamed infix impliciation now named HOL.implies
 
haftmann 
parents: 
38199 
diff
changeset
 | 
1061  | 
                             s0 = @{const_name HOL.implies})
 | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
1062  | 
val (m1, accum) =  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
1063  | 
do_formula (sn |> impl ? negate_sign) t1 accum  | 
| 
37704
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1064  | 
val (m2, accum) = do_formula sn t2 accum  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1065  | 
in  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1066  | 
(MApp (MApp (MRaw (t0, mtype_for (fastype_of t0)), m1), m2),  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1067  | 
accum)  | 
| 
39316
 
b6c4385ab400
change defaults of Auto Nitpick so that it consumes less resources (time and Kodkod threads)
 
blanchet 
parents: 
38864 
diff
changeset
 | 
1068  | 
end  | 
| 
37704
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1069  | 
else  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1070  | 
do_term t accum  | 
| 
 
c6161bee8486
adapt Nitpick to "prod_case" and "*" -> "sum" renaming;
 
blanchet 
parents: 
37678 
diff
changeset
 | 
1071  | 
| _ => do_term t accum)  | 
| 33192 | 1072  | 
end  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1073  | 
|> tap (fn (m, _) =>  | 
| 38179 | 1074  | 
trace_msg (fn () => "\<Gamma> \<turnstile> " ^  | 
1075  | 
string_for_mterm ctxt m ^ " : o\<^sup>" ^  | 
|
1076  | 
string_for_sign sn))  | 
|
| 33192 | 1077  | 
in do_formula end  | 
1078  | 
||
1079  | 
(* The harmless axiom optimization below is somewhat too aggressive in the face  | 
|
1080  | 
of (rather peculiar) user-defined axioms. *)  | 
|
1081  | 
val harmless_consts =  | 
|
1082  | 
  [@{const_name ord_class.less}, @{const_name ord_class.less_eq}]
 | 
|
1083  | 
val bounteous_consts = [@{const_name bisim}]
 | 
|
1084  | 
||
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1085  | 
fun is_harmless_axiom ({no_harmless = true, ...} : mdata) _ = false
 | 
| 39359 | 1086  | 
  | is_harmless_axiom {hol_ctxt = {thy, stds, ...}, ...} t =
 | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1087  | 
Term.add_consts t []  | 
| 39359 | 1088  | 
|> filter_out (is_built_in_const thy stds)  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1089  | 
|> (forall (member (op =) harmless_consts o original_name o fst) orf  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1090  | 
exists (member (op =) bounteous_consts o fst))  | 
| 33192 | 1091  | 
|
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1092  | 
fun consider_nondefinitional_axiom mdata t =  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1093  | 
if is_harmless_axiom mdata t then pair (MRaw (t, dummy_M))  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1094  | 
else consider_general_formula mdata Plus t  | 
| 33192 | 1095  | 
|
| 
37256
 
0dca1ec52999
thread along context instead of theory for typedef lookup
 
blanchet 
parents: 
36385 
diff
changeset
 | 
1096  | 
fun consider_definitional_axiom (mdata as {hol_ctxt = {ctxt, ...}, ...}) t =
 | 
| 
 
0dca1ec52999
thread along context instead of theory for typedef lookup
 
blanchet 
parents: 
36385 
diff
changeset
 | 
1097  | 
if not (is_constr_pattern_formula ctxt t) then  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1098  | 
consider_nondefinitional_axiom mdata t  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1099  | 
else if is_harmless_axiom mdata t then  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1100  | 
pair (MRaw (t, dummy_M))  | 
| 33192 | 1101  | 
else  | 
1102  | 
let  | 
|
| 35672 | 1103  | 
val mtype_for = fresh_mtype_for_type mdata false  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1104  | 
val do_term = consider_term mdata  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1105  | 
fun do_all quant_t abs_s abs_T body_t accum =  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1106  | 
let  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1107  | 
val abs_M = mtype_for abs_T  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1108  | 
val (body_m, accum) =  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
1109  | 
accum |>> push_bound (A Gen) abs_T abs_M |> do_formula body_t  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1110  | 
val body_M = mtype_of_mterm body_m  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1111  | 
in  | 
| 
40985
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
1112  | 
(MApp (MRaw (quant_t, MFun (MFun (abs_M, A Gen, body_M), A Gen,  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
1113  | 
body_M)),  | 
| 
 
8b870370c26f
started generalizing monotonicity code to accommodate new calculus
 
blanchet 
parents: 
40722 
diff
changeset
 | 
1114  | 
MAbs (abs_s, abs_T, abs_M, A Gen, body_m)),  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1115  | 
accum |>> pop_bound)  | 
| 33192 | 1116  | 
end  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1117  | 
and do_conjunction t0 t1 t2 accum =  | 
| 33192 | 1118  | 
let  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1119  | 
val (m1, accum) = do_formula t1 accum  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1120  | 
val (m2, accum) = do_formula t2 accum  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1121  | 
in  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1122  | 
(MApp (MApp (MRaw (t0, mtype_for (fastype_of t0)), m1), m2), accum)  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1123  | 
end  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1124  | 
and do_implies t0 t1 t2 accum =  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1125  | 
let  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1126  | 
val (m1, accum) = do_term t1 accum  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1127  | 
val (m2, accum) = do_formula t2 accum  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1128  | 
in  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1129  | 
(MApp (MApp (MRaw (t0, mtype_for (fastype_of t0)), m1), m2), accum)  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1130  | 
end  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1131  | 
and do_formula t accum =  | 
| 33192 | 1132  | 
case t of  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1133  | 
            (t0 as Const (@{const_name all}, _)) $ Abs (s1, T1, t1) =>
 | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1134  | 
do_all t0 s1 T1 t1 accum  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1135  | 
          | @{const Trueprop} $ t1 =>
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1136  | 
let val (m1, accum) = do_formula t1 accum in  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1137  | 
              (MApp (MRaw (@{const Trueprop}, mtype_for (bool_T --> prop_T)),
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1138  | 
m1), accum)  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1139  | 
end  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1140  | 
          | Const (x as (@{const_name "=="}, _)) $ t1 $ t2 =>
 | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1141  | 
consider_general_equals mdata true x t1 t2 accum  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1142  | 
          | (t0 as @{const "==>"}) $ t1 $ t2 => do_implies t0 t1 t2 accum
 | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1143  | 
          | (t0 as @{const Pure.conjunction}) $ t1 $ t2 =>
 | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1144  | 
do_conjunction t0 t1 t2 accum  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1145  | 
          | (t0 as Const (@{const_name All}, _)) $ Abs (s0, T1, t1) =>
 | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1146  | 
do_all t0 s0 T1 t1 accum  | 
| 
38864
 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 
haftmann 
parents: 
38795 
diff
changeset
 | 
1147  | 
          | Const (x as (@{const_name HOL.eq}, _)) $ t1 $ t2 =>
 | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1148  | 
consider_general_equals mdata true x t1 t2 accum  | 
| 
38795
 
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
 
haftmann 
parents: 
38786 
diff
changeset
 | 
1149  | 
          | (t0 as @{const HOL.conj}) $ t1 $ t2 => do_conjunction t0 t1 t2 accum
 | 
| 
38786
 
e46e7a9cb622
formerly unnamed infix impliciation now named HOL.implies
 
haftmann 
parents: 
38199 
diff
changeset
 | 
1150  | 
          | (t0 as @{const HOL.implies}) $ t1 $ t2 => do_implies t0 t1 t2 accum
 | 
| 
33232
 
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
 
blanchet 
parents: 
33192 
diff
changeset
 | 
1151  | 
          | _ => raise TERM ("Nitpick_Mono.consider_definitional_axiom.\
 | 
| 33192 | 1152  | 
\do_formula", [t])  | 
1153  | 
in do_formula t end  | 
|
1154  | 
||
| 40989 | 1155  | 
fun string_for_mtype_of_term ctxt asgs t M =  | 
1156  | 
Syntax.string_of_term ctxt t ^ " : " ^ string_for_mtype (resolve_mtype asgs M)  | 
|
| 33192 | 1157  | 
|
| 40989 | 1158  | 
fun print_mtype_context ctxt asgs ({frees, consts, ...} : mtype_context) =
 | 
| 38179 | 1159  | 
trace_msg (fn () =>  | 
| 40989 | 1160  | 
map (fn (x, M) => string_for_mtype_of_term ctxt asgs (Free x) M) frees @  | 
1161  | 
map (fn (x, M) => string_for_mtype_of_term ctxt asgs (Const x) M) consts  | 
|
| 
37476
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
1162  | 
|> cat_lines)  | 
| 33192 | 1163  | 
|
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1164  | 
fun amass f t (ms, accum) =  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1165  | 
let val (m, accum) = f t accum in (m :: ms, accum) end  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1166  | 
|
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
1167  | 
fun infer which no_harmless (hol_ctxt as {ctxt, ...}) binarize calculus alpha_T
 | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1168  | 
(nondef_ts, def_ts) =  | 
| 33192 | 1169  | 
let  | 
| 38179 | 1170  | 
val _ = trace_msg (fn () => "****** " ^ which ^ " analysis: " ^  | 
1171  | 
string_for_mtype MAlpha ^ " is " ^  | 
|
1172  | 
Syntax.string_of_typ ctxt alpha_T)  | 
|
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1173  | 
    val mdata as {max_fresh, constr_mcache, ...} =
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1174  | 
initial_mdata hol_ctxt binarize no_harmless alpha_T  | 
| 
40994
 
3bdb8df0daf0
more work on frames in the new monotonicity calculus
 
blanchet 
parents: 
40993 
diff
changeset
 | 
1175  | 
val accum = (initial_gamma, ([], []))  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1176  | 
val (nondef_ms, accum) =  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1177  | 
([], accum) |> amass (consider_general_formula mdata Plus) (hd nondef_ts)  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1178  | 
|> fold (amass (consider_nondefinitional_axiom mdata))  | 
| 
35386
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1179  | 
(tl nondef_ts)  | 
| 
 
45a4e19d3ebd
more work on the new monotonicity stuff in Nitpick
 
blanchet 
parents: 
35385 
diff
changeset
 | 
1180  | 
val (def_ms, (gamma, cset)) =  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1181  | 
([], accum) |> fold (amass (consider_definitional_axiom mdata)) def_ts  | 
| 33192 | 1182  | 
in  | 
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
1183  | 
case solve calculus (!max_fresh) cset of  | 
| 40989 | 1184  | 
SOME asgs => (print_mtype_context ctxt asgs gamma;  | 
1185  | 
SOME (asgs, (nondef_ms, def_ms), !constr_mcache))  | 
|
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1186  | 
| _ => NONE  | 
| 33192 | 1187  | 
end  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1188  | 
handle UNSOLVABLE () => NONE  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1189  | 
| MTYPE (loc, Ms, Ts) =>  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1190  | 
raise BAD (loc, commas (map string_for_mtype Ms @  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1191  | 
map (Syntax.string_of_typ ctxt) Ts))  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1192  | 
| MTERM (loc, ms) =>  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1193  | 
raise BAD (loc, commas (map (string_for_mterm ctxt) ms))  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1194  | 
|
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
1195  | 
fun formulas_monotonic hol_ctxt =  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
1196  | 
is_some oooo infer "Monotonicity" false hol_ctxt  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1197  | 
|
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1198  | 
fun fin_fun_constr T1 T2 =  | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1199  | 
  (@{const_name FinFun}, (T1 --> T2) --> Type (@{type_name fin_fun}, [T1, T2]))
 | 
| 
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1200  | 
|
| 
40993
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
1201  | 
fun finitize_funs (hol_ctxt as {thy, ctxt, stds, constr_cache, ...}) binarize
 | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
1202  | 
finitizes calculus alpha_T tsp =  | 
| 
 
52ee2a187cdb
support 3 monotonicity calculi in one and fix soundness bug
 
blanchet 
parents: 
40991 
diff
changeset
 | 
1203  | 
case infer "Finiteness" true hol_ctxt binarize calculus alpha_T tsp of  | 
| 40989 | 1204  | 
SOME (asgs, msp, constr_mtypes) =>  | 
1205  | 
if forall (curry (op =) Gen o snd) asgs then  | 
|
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1206  | 
tsp  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1207  | 
else  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1208  | 
let  | 
| 40988 | 1209  | 
fun should_finitize T aa =  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1210  | 
case triple_lookup (type_match thy) finitizes T of  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1211  | 
SOME (SOME false) => false  | 
| 40989 | 1212  | 
| _ => resolve_annotation_atom asgs aa = A Fls  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1213  | 
fun type_from_mtype T M =  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1214  | 
case (M, T) of  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1215  | 
(MAlpha, _) => T  | 
| 40988 | 1216  | 
          | (MFun (M1, aa, M2), Type (@{type_name fun}, Ts)) =>
 | 
1217  | 
            Type (if should_finitize T aa then @{type_name fin_fun}
 | 
|
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1218  | 
                  else @{type_name fun}, map2 type_from_mtype Ts [M1, M2])
 | 
| 
38190
 
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
 
blanchet 
parents: 
38179 
diff
changeset
 | 
1219  | 
          | (MPair (M1, M2), Type (@{type_name prod}, Ts)) =>
 | 
| 
 
b02e204b613a
get rid of all "optimizations" regarding "unit" and other cardinality-1 types
 
blanchet 
parents: 
38179 
diff
changeset
 | 
1220  | 
            Type (@{type_name prod}, map2 type_from_mtype Ts [M1, M2])
 | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1221  | 
| (MType _, _) => T  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1222  | 
          | _ => raise MTYPE ("Nitpick_Mono.finitize_funs.type_from_mtype",
 | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1223  | 
[M], [T])  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1224  | 
fun finitize_constr (x as (s, T)) =  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1225  | 
(s, case AList.lookup (op =) constr_mtypes x of  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1226  | 
SOME M => type_from_mtype T M  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1227  | 
| NONE => T)  | 
| 
37267
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1228  | 
fun term_from_mterm new_Ts old_Ts m =  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1229  | 
case m of  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1230  | 
MRaw (t, M) =>  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1231  | 
let  | 
| 
37267
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1232  | 
val T = fastype_of1 (old_Ts, t)  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1233  | 
val T' = type_from_mtype T M  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1234  | 
in  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1235  | 
case t of  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1236  | 
Const (x as (s, _)) =>  | 
| 
37476
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
1237  | 
                if s = @{const_name finite} then
 | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1238  | 
case domain_type T' of  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1239  | 
                    set_T' as Type (@{type_name fin_fun}, _) =>
 | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1240  | 
                    Abs (Name.uu, set_T', @{const True})
 | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1241  | 
| _ => Const (s, T')  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1242  | 
                else if s = @{const_name "=="} orelse
 | 
| 
38864
 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 
haftmann 
parents: 
38795 
diff
changeset
 | 
1243  | 
                        s = @{const_name HOL.eq} then
 | 
| 
37476
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
1244  | 
let  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
1245  | 
val T =  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
1246  | 
case T' of  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
1247  | 
Type (_, [T1, Type (_, [T2, T3])]) =>  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
1248  | 
T1 --> T2 --> T3  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
1249  | 
                      | _ => raise TYPE ("Nitpick_Mono.finitize_funs.\
 | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
1250  | 
\term_from_mterm", [T, T'], [])  | 
| 
 
0681e46b4022
optimized code generated for datatype cases + more;
 
blanchet 
parents: 
37267 
diff
changeset
 | 
1251  | 
in coerce_term hol_ctxt new_Ts T' T (Const (s, T)) end  | 
| 39359 | 1252  | 
else if is_built_in_const thy stds x then  | 
| 
37267
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1253  | 
coerce_term hol_ctxt new_Ts T' T t  | 
| 
37256
 
0dca1ec52999
thread along context instead of theory for typedef lookup
 
blanchet 
parents: 
36385 
diff
changeset
 | 
1254  | 
else if is_constr ctxt stds x then  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1255  | 
Const (finitize_constr x)  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1256  | 
else if is_sel s then  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1257  | 
let  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1258  | 
val n = sel_no_from_name s  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1259  | 
val x' =  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1260  | 
x |> binarized_and_boxed_constr_for_sel hol_ctxt binarize  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1261  | 
|> finitize_constr  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1262  | 
val x'' =  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1263  | 
binarized_and_boxed_nth_sel_for_constr hol_ctxt binarize  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1264  | 
x' n  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1265  | 
in Const x'' end  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1266  | 
else  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1267  | 
Const (s, T')  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1268  | 
| Free (s, T) => Free (s, type_from_mtype T M)  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1269  | 
| Bound _ => t  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1270  | 
              | _ => raise MTERM ("Nitpick_Mono.finitize_funs.term_from_mterm",
 | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1271  | 
[m])  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1272  | 
end  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1273  | 
| MApp (m1, m2) =>  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1274  | 
let  | 
| 
37267
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1275  | 
val (t1, t2) = pairself (term_from_mterm new_Ts old_Ts) (m1, m2)  | 
| 
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1276  | 
val (T1, T2) = pairself (curry fastype_of1 new_Ts) (t1, t2)  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1277  | 
val (t1', T2') =  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1278  | 
case T1 of  | 
| 
39316
 
b6c4385ab400
change defaults of Auto Nitpick so that it consumes less resources (time and Kodkod threads)
 
blanchet 
parents: 
38864 
diff
changeset
 | 
1279  | 
Type (s, [T11, T12]) =>  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1280  | 
                  (if s = @{type_name fin_fun} then
 | 
| 
37256
 
0dca1ec52999
thread along context instead of theory for typedef lookup
 
blanchet 
parents: 
36385 
diff
changeset
 | 
1281  | 
select_nth_constr_arg ctxt stds (fin_fun_constr T11 T12) t1  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1282  | 
0 (T11 --> T12)  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1283  | 
else  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1284  | 
t1, T11)  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1285  | 
                | _ => raise TYPE ("Nitpick_Mono.finitize_funs.term_from_mterm",
 | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1286  | 
[T1], [])  | 
| 
37267
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1287  | 
in betapply (t1', coerce_term hol_ctxt new_Ts T2' T2 t2) end  | 
| 40988 | 1288  | 
| MAbs (s, old_T, M, aa, m') =>  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1289  | 
let  | 
| 
37267
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1290  | 
val new_T = type_from_mtype old_T M  | 
| 
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1291  | 
val t' = term_from_mterm (new_T :: new_Ts) (old_T :: old_Ts) m'  | 
| 
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1292  | 
val T' = fastype_of1 (new_T :: new_Ts, t')  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1293  | 
in  | 
| 
37267
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1294  | 
Abs (s, new_T, t')  | 
| 40988 | 1295  | 
|> should_finitize (new_T --> T') aa  | 
| 
37267
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1296  | 
? construct_value ctxt stds (fin_fun_constr new_T T') o single  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1297  | 
end  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1298  | 
in  | 
| 
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1299  | 
Unsynchronized.change constr_cache (map (apsnd (map finitize_constr)));  | 
| 
37267
 
5c47d633c84d
fix code that used to raise an exception if bound variables were given a finite function type, because the old vs. new bound variable types were confused
 
blanchet 
parents: 
37260 
diff
changeset
 | 
1300  | 
pairself (map (term_from_mterm [] [])) msp  | 
| 
35812
 
394fe2b064cd
solve error in "Nitpick_Mono" + short path when no finite functions are inferred
 
blanchet 
parents: 
35672 
diff
changeset
 | 
1301  | 
end  | 
| 
35665
 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 
blanchet 
parents: 
35386 
diff
changeset
 | 
1302  | 
| NONE => tsp  | 
| 33192 | 1303  | 
|
1304  | 
end;  |