author | webertj |
Thu, 04 Jan 2007 17:52:28 +0100 | |
changeset 21998 | aa2764dda077 |
parent 21992 | 337990f42ce0 |
child 22024 | adf64b316f07 |
permissions | -rw-r--r-- |
14350 | 1 |
(* Title: HOL/Tools/refute.ML |
2 |
ID: $Id$ |
|
3 |
Author: Tjark Weber |
|
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
4 |
Copyright 2003-2007 |
14350 | 5 |
|
14965 | 6 |
Finite model generation for HOL formulas, using a SAT solver. |
14350 | 7 |
*) |
8 |
||
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
9 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
10 |
(* Declares the 'REFUTE' signature as well as a structure 'Refute'. *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
11 |
(* Documentation is available in the Isabelle/Isar theory 'HOL/Refute.thy'. *) |
14350 | 12 |
(* ------------------------------------------------------------------------- *) |
13 |
||
14 |
signature REFUTE = |
|
15 |
sig |
|
16 |
||
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
17 |
exception REFUTE of string * string |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
18 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
19 |
(* ------------------------------------------------------------------------- *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
20 |
(* Model/interpretation related code (translation HOL -> propositional logic *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
21 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
22 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
23 |
type params |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
24 |
type interpretation |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
25 |
type model |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
26 |
type arguments |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
27 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
28 |
exception MAXVARS_EXCEEDED |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
29 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
30 |
val add_interpreter : string -> (theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option) -> theory -> theory |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
31 |
val add_printer : string -> (theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option) -> theory -> theory |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
32 |
|
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
33 |
val interpret : theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
34 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
35 |
val print : theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
36 |
val print_model : theory -> model -> (int -> bool) -> string |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
37 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
38 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
39 |
(* Interface *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
40 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
41 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
42 |
val set_default_param : (string * string) -> theory -> theory |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
43 |
val get_default_param : theory -> string -> string option |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
44 |
val get_default_params : theory -> (string * string) list |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
45 |
val actual_params : theory -> (string * string) list -> params |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
46 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
47 |
val find_model : theory -> params -> Term.term -> bool -> unit |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
48 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
49 |
val satisfy_term : theory -> (string * string) list -> Term.term -> unit (* tries to find a model for a formula *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
50 |
val refute_term : theory -> (string * string) list -> Term.term -> unit (* tries to find a model that refutes a formula *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
51 |
val refute_subgoal : theory -> (string * string) list -> Thm.thm -> int -> unit |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
52 |
|
18708 | 53 |
val setup : theory -> theory |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
54 |
end; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
55 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
56 |
structure Refute : REFUTE = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
57 |
struct |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
58 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
59 |
open PropLogic; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
60 |
|
14350 | 61 |
(* We use 'REFUTE' only for internal error conditions that should *) |
62 |
(* never occur in the first place (i.e. errors caused by bugs in our *) |
|
63 |
(* code). Otherwise (e.g. to indicate invalid input data) we use *) |
|
64 |
(* 'error'. *) |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
65 |
exception REFUTE of string * string; (* ("in function", "cause") *) |
14350 | 66 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
67 |
(* should be raised by an interpreter when more variables would be *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
68 |
(* required than allowed by 'maxvars' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
69 |
exception MAXVARS_EXCEEDED; |
14350 | 70 |
|
71 |
(* ------------------------------------------------------------------------- *) |
|
72 |
(* TREES *) |
|
73 |
(* ------------------------------------------------------------------------- *) |
|
74 |
||
75 |
(* ------------------------------------------------------------------------- *) |
|
76 |
(* tree: implements an arbitrarily (but finitely) branching tree as a list *) |
|
77 |
(* of (lists of ...) elements *) |
|
78 |
(* ------------------------------------------------------------------------- *) |
|
79 |
||
80 |
datatype 'a tree = |
|
81 |
Leaf of 'a |
|
82 |
| Node of ('a tree) list; |
|
83 |
||
84 |
(* ('a -> 'b) -> 'a tree -> 'b tree *) |
|
85 |
||
86 |
fun tree_map f tr = |
|
87 |
case tr of |
|
88 |
Leaf x => Leaf (f x) |
|
89 |
| Node xs => Node (map (tree_map f) xs); |
|
90 |
||
91 |
(* ('a * 'b -> 'a) -> 'a * ('b tree) -> 'a *) |
|
92 |
||
93 |
fun tree_foldl f = |
|
94 |
let |
|
95 |
fun itl (e, Leaf x) = f(e,x) |
|
15570 | 96 |
| itl (e, Node xs) = Library.foldl (tree_foldl f) (e,xs) |
14350 | 97 |
in |
98 |
itl |
|
99 |
end; |
|
100 |
||
101 |
(* 'a tree * 'b tree -> ('a * 'b) tree *) |
|
102 |
||
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
103 |
fun tree_pair (t1, t2) = |
14350 | 104 |
case t1 of |
105 |
Leaf x => |
|
106 |
(case t2 of |
|
107 |
Leaf y => Leaf (x,y) |
|
108 |
| Node _ => raise REFUTE ("tree_pair", "trees are of different height (second tree is higher)")) |
|
109 |
| Node xs => |
|
110 |
(case t2 of |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
111 |
(* '~~' will raise an exception if the number of branches in *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
112 |
(* both trees is different at the current node *) |
14350 | 113 |
Node ys => Node (map tree_pair (xs ~~ ys)) |
114 |
| Leaf _ => raise REFUTE ("tree_pair", "trees are of different height (first tree is higher)")); |
|
115 |
||
116 |
(* ------------------------------------------------------------------------- *) |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
117 |
(* params: parameters that control the translation into a propositional *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
118 |
(* formula/model generation *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
119 |
(* *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
120 |
(* The following parameters are supported (and required (!), except for *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
121 |
(* "sizes"): *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
122 |
(* *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
123 |
(* Name Type Description *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
124 |
(* *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
125 |
(* "sizes" (string * int) list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
126 |
(* Size of ground types (e.g. 'a=2), or depth of IDTs. *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
127 |
(* "minsize" int If >0, minimal size of each ground type/IDT depth. *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
128 |
(* "maxsize" int If >0, maximal size of each ground type/IDT depth. *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
129 |
(* "maxvars" int If >0, use at most 'maxvars' Boolean variables *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
130 |
(* when transforming the term into a propositional *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
131 |
(* formula. *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
132 |
(* "maxtime" int If >0, terminate after at most 'maxtime' seconds. *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
133 |
(* "satsolver" string SAT solver to be used. *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
134 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
135 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
136 |
type params = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
137 |
{ |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
138 |
sizes : (string * int) list, |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
139 |
minsize : int, |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
140 |
maxsize : int, |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
141 |
maxvars : int, |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
142 |
maxtime : int, |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
143 |
satsolver: string |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
144 |
}; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
145 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
146 |
(* ------------------------------------------------------------------------- *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
147 |
(* interpretation: a term's interpretation is given by a variable of type *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
148 |
(* 'interpretation' *) |
14350 | 149 |
(* ------------------------------------------------------------------------- *) |
150 |
||
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
151 |
type interpretation = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
152 |
prop_formula list tree; |
14350 | 153 |
|
154 |
(* ------------------------------------------------------------------------- *) |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
155 |
(* model: a model specifies the size of types and the interpretation of *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
156 |
(* terms *) |
14350 | 157 |
(* ------------------------------------------------------------------------- *) |
158 |
||
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
159 |
type model = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
160 |
(Term.typ * int) list * (Term.term * interpretation) list; |
14350 | 161 |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
162 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
163 |
(* arguments: additional arguments required during interpretation of terms *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
164 |
(* ------------------------------------------------------------------------- *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
165 |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
166 |
type arguments = |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
167 |
{ |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
168 |
maxvars : int, (* just passed unchanged from 'params' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
169 |
def_eq : bool, (* whether to use 'make_equality' or 'make_def_equality' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
170 |
(* the following may change during the translation *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
171 |
next_idx : int, |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
172 |
bounds : interpretation list, |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
173 |
wellformed: prop_formula |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
174 |
}; |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
175 |
|
14350 | 176 |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
177 |
structure RefuteDataArgs = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
178 |
struct |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
179 |
val name = "HOL/refute"; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
180 |
type T = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
181 |
{interpreters: (string * (theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option)) list, |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
182 |
printers: (string * (theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option)) list, |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
183 |
parameters: string Symtab.table}; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
184 |
val empty = {interpreters = [], printers = [], parameters = Symtab.empty}; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
185 |
val copy = I; |
16424 | 186 |
val extend = I; |
187 |
fun merge _ |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
188 |
({interpreters = in1, printers = pr1, parameters = pa1}, |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
189 |
{interpreters = in2, printers = pr2, parameters = pa2}) = |
21098
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
190 |
{interpreters = AList.merge (op =) (K true) (in1, in2), |
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
191 |
printers = AList.merge (op =) (K true) (pr1, pr2), |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
192 |
parameters = Symtab.merge (op=) (pa1, pa2)}; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
193 |
fun print sg {interpreters, printers, parameters} = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
194 |
Pretty.writeln (Pretty.chunks |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
195 |
[Pretty.strs ("default parameters:" :: List.concat (map (fn (name, value) => [name, "=", value]) (Symtab.dest parameters))), |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
196 |
Pretty.strs ("interpreters:" :: map fst interpreters), |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
197 |
Pretty.strs ("printers:" :: map fst printers)]); |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
198 |
end; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
199 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
200 |
structure RefuteData = TheoryDataFun(RefuteDataArgs); |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
201 |
|
14350 | 202 |
|
203 |
(* ------------------------------------------------------------------------- *) |
|
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
204 |
(* interpret: interprets the term 't' using a suitable interpreter; returns *) |
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
205 |
(* the interpretation and a (possibly extended) model that keeps *) |
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
206 |
(* track of the interpretation of subterms *) |
14350 | 207 |
(* ------------------------------------------------------------------------- *) |
208 |
||
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
209 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
210 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
211 |
fun interpret thy model args t = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
212 |
(case get_first (fn (_, f) => f thy model args t) (#interpreters (RefuteData.get thy)) of |
21992 | 213 |
NONE => raise REFUTE ("interpret", "no interpreter for term " ^ quote (Sign.string_of_term thy t)) |
15531 | 214 |
| SOME x => x); |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
215 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
216 |
(* ------------------------------------------------------------------------- *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
217 |
(* print: converts the constant denoted by the term 't' into a term using a *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
218 |
(* suitable printer *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
219 |
(* ------------------------------------------------------------------------- *) |
14350 | 220 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
221 |
(* theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
222 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
223 |
fun print thy model t intr assignment = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
224 |
(case get_first (fn (_, f) => f thy model t intr assignment) (#printers (RefuteData.get thy)) of |
21992 | 225 |
NONE => raise REFUTE ("print", "no printer for term " ^ quote (Sign.string_of_term thy t)) |
15531 | 226 |
| SOME x => x); |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
227 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
228 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
229 |
(* print_model: turns the model into a string, using a fixed interpretation *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
230 |
(* (given by an assignment for Boolean variables) and suitable *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
231 |
(* printers *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
232 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
233 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
234 |
(* theory -> model -> (int -> bool) -> string *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
235 |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
236 |
fun print_model thy model assignment = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
237 |
let |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
238 |
val (typs, terms) = model |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
239 |
val typs_msg = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
240 |
if null typs then |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
241 |
"empty universe (no type variables in term)\n" |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
242 |
else |
21992 | 243 |
"Size of types: " ^ commas (map (fn (T, i) => Sign.string_of_typ thy T ^ ": " ^ string_of_int i) typs) ^ "\n" |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
244 |
val show_consts_msg = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
245 |
if not (!show_consts) andalso Library.exists (is_Const o fst) terms then |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
246 |
"set \"show_consts\" to show the interpretation of constants\n" |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
247 |
else |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
248 |
"" |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
249 |
val terms_msg = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
250 |
if null terms then |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
251 |
"empty interpretation (no free variables in term)\n" |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
252 |
else |
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
253 |
space_implode "\n" (List.mapPartial (fn (t, intr) => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
254 |
(* print constants only if 'show_consts' is true *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
255 |
if (!show_consts) orelse not (is_Const t) then |
21992 | 256 |
SOME (Sign.string_of_term thy t ^ ": " ^ Sign.string_of_term thy (print thy model t intr assignment)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
257 |
else |
15531 | 258 |
NONE) terms) ^ "\n" |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
259 |
in |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
260 |
typs_msg ^ show_consts_msg ^ terms_msg |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
261 |
end; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
262 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
263 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
264 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
265 |
(* PARAMETER MANAGEMENT *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
266 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
267 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
268 |
(* string -> (theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option) -> theory -> theory *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
269 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
270 |
fun add_interpreter name f thy = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
271 |
let |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
272 |
val {interpreters, printers, parameters} = RefuteData.get thy |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
273 |
in |
17314 | 274 |
case AList.lookup (op =) interpreters name of |
15531 | 275 |
NONE => RefuteData.put {interpreters = (name, f) :: interpreters, printers = printers, parameters = parameters} thy |
276 |
| SOME _ => error ("Interpreter " ^ name ^ " already declared") |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
277 |
end; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
278 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
279 |
(* string -> (theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option) -> theory -> theory *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
280 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
281 |
fun add_printer name f thy = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
282 |
let |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
283 |
val {interpreters, printers, parameters} = RefuteData.get thy |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
284 |
in |
17314 | 285 |
case AList.lookup (op =) printers name of |
15531 | 286 |
NONE => RefuteData.put {interpreters = interpreters, printers = (name, f) :: printers, parameters = parameters} thy |
287 |
| SOME _ => error ("Printer " ^ name ^ " already declared") |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
288 |
end; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
289 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
290 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
291 |
(* set_default_param: stores the '(name, value)' pair in RefuteData's *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
292 |
(* parameter table *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
293 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
294 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
295 |
(* (string * string) -> theory -> theory *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
296 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
297 |
fun set_default_param (name, value) thy = |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
298 |
let |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
299 |
val {interpreters, printers, parameters} = RefuteData.get thy |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
300 |
in |
17412 | 301 |
case Symtab.lookup parameters name of |
15531 | 302 |
NONE => RefuteData.put |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
303 |
{interpreters = interpreters, printers = printers, parameters = Symtab.extend (parameters, [(name, value)])} thy |
15531 | 304 |
| SOME _ => RefuteData.put |
17412 | 305 |
{interpreters = interpreters, printers = printers, parameters = Symtab.update (name, value) parameters} thy |
14350 | 306 |
end; |
307 |
||
308 |
(* ------------------------------------------------------------------------- *) |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
309 |
(* get_default_param: retrieves the value associated with 'name' from *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
310 |
(* RefuteData's parameter table *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
311 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
312 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
313 |
(* theory -> string -> string option *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
314 |
|
17412 | 315 |
val get_default_param = Symtab.lookup o #parameters o RefuteData.get; |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
316 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
317 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
318 |
(* get_default_params: returns a list of all '(name, value)' pairs that are *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
319 |
(* stored in RefuteData's parameter table *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
320 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
321 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
322 |
(* theory -> (string * string) list *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
323 |
|
17261 | 324 |
val get_default_params = Symtab.dest o #parameters o RefuteData.get; |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
325 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
326 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
327 |
(* actual_params: takes a (possibly empty) list 'params' of parameters that *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
328 |
(* override the default parameters currently specified in 'thy', and *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
329 |
(* returns a record that can be passed to 'find_model'. *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
330 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
331 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
332 |
(* theory -> (string * string) list -> params *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
333 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
334 |
fun actual_params thy override = |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
335 |
let |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
336 |
(* (string * string) list * string -> int *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
337 |
fun read_int (parms, name) = |
17314 | 338 |
case AList.lookup (op =) parms name of |
15531 | 339 |
SOME s => (case Int.fromString s of |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
340 |
SOME i => i |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
341 |
| NONE => error ("parameter " ^ quote name ^ " (value is " ^ quote s ^ ") must be an integer value")) |
15531 | 342 |
| NONE => error ("parameter " ^ quote name ^ " must be assigned a value") |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
343 |
(* (string * string) list * string -> string *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
344 |
fun read_string (parms, name) = |
17314 | 345 |
case AList.lookup (op =) parms name of |
15531 | 346 |
SOME s => s |
347 |
| NONE => error ("parameter " ^ quote name ^ " must be assigned a value") |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
348 |
(* (string * string) list *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
349 |
val allparams = override @ (get_default_params thy) (* 'override' first, defaults last *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
350 |
(* int *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
351 |
val minsize = read_int (allparams, "minsize") |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
352 |
val maxsize = read_int (allparams, "maxsize") |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
353 |
val maxvars = read_int (allparams, "maxvars") |
20544 | 354 |
val maxtime = read_int (allparams, "maxtime") |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
355 |
(* string *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
356 |
val satsolver = read_string (allparams, "satsolver") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
357 |
(* all remaining parameters of the form "string=int" are collected in *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
358 |
(* 'sizes' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
359 |
(* TODO: it is currently not possible to specify a size for a type *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
360 |
(* whose name is one of the other parameters (e.g. 'maxvars') *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
361 |
(* (string * int) list *) |
15570 | 362 |
val sizes = List.mapPartial |
15531 | 363 |
(fn (name,value) => (case Int.fromString value of SOME i => SOME (name, i) | NONE => NONE)) |
15570 | 364 |
(List.filter (fn (name,_) => name<>"minsize" andalso name<>"maxsize" andalso name<>"maxvars" andalso name<>"maxtime" andalso name<>"satsolver") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
365 |
allparams) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
366 |
in |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
367 |
{sizes=sizes, minsize=minsize, maxsize=maxsize, maxvars=maxvars, maxtime=maxtime, satsolver=satsolver} |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
368 |
end; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
369 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
370 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
371 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
372 |
(* TRANSLATION HOL -> PROPOSITIONAL LOGIC, BOOLEAN ASSIGNMENT -> MODEL *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
373 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
374 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
375 |
(* ------------------------------------------------------------------------- *) |
15335
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
376 |
(* typ_of_dtyp: converts a data type ('DatatypeAux.dtyp') into a type *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
377 |
(* ('Term.typ'), given type parameters for the data type's type *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
378 |
(* arguments *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
379 |
(* ------------------------------------------------------------------------- *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
380 |
|
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
381 |
(* DatatypeAux.descr -> (DatatypeAux.dtyp * Term.typ) list -> DatatypeAux.dtyp -> Term.typ *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
382 |
|
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
383 |
fun typ_of_dtyp descr typ_assoc (DatatypeAux.DtTFree a) = |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
384 |
(* replace a 'DtTFree' variable by the associated type *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
385 |
(Option.valOf o AList.lookup (op =) typ_assoc) (DatatypeAux.DtTFree a) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
386 |
| typ_of_dtyp descr typ_assoc (DatatypeAux.DtType (s, ds)) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
387 |
Type (s, map (typ_of_dtyp descr typ_assoc) ds) |
15335
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
388 |
| typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec i) = |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
389 |
let |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
390 |
val (s, ds, _) = (Option.valOf o AList.lookup (op =) descr) i |
15335
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
391 |
in |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
392 |
Type (s, map (typ_of_dtyp descr typ_assoc) ds) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
393 |
end; |
15335
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
394 |
|
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
395 |
(* ------------------------------------------------------------------------- *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
396 |
(* close_form: universal closure over schematic variables in 't' *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
397 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
398 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
399 |
(* Term.term -> Term.term *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
400 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
401 |
fun close_form t = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
402 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
403 |
(* (Term.indexname * Term.typ) list *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
404 |
val vars = sort_wrt (fst o fst) (map dest_Var (term_vars t)) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
405 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
406 |
Library.foldl |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
407 |
(fn (t', ((x, i), T)) => (Term.all T) $ Abs (x, T, abstract_over (Var ((x, i), T), t'))) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
408 |
(t, vars) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
409 |
end; |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
410 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
411 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
412 |
(* monomorphic_term: applies a type substitution 'typeSubs' for all type *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
413 |
(* variables in a term 't' *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
414 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
415 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
416 |
(* Type.tyenv -> Term.term -> Term.term *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
417 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
418 |
fun monomorphic_term typeSubs t = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
419 |
map_types (map_type_tvar |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
420 |
(fn v => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
421 |
case Type.lookup (typeSubs, v) of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
422 |
NONE => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
423 |
(* schematic type variable not instantiated *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
424 |
raise REFUTE ("monomorphic_term", |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
425 |
"no substitution for type variable " ^ fst (fst v) ^ |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
426 |
" in term " ^ Display.raw_string_of_term t) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
427 |
| SOME typ => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
428 |
typ)) t; |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
429 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
430 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
431 |
(* specialize_type: given a constant 's' of type 'T', which is a subterm of *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
432 |
(* 't', where 't' has a (possibly) more general type, the *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
433 |
(* schematic type variables in 't' are instantiated to *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
434 |
(* match the type 'T' (may raise Type.TYPE_MATCH) *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
435 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
436 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
437 |
(* theory -> (string * Term.typ) -> Term.term -> Term.term *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
438 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
439 |
fun specialize_type thy (s, T) t = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
440 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
441 |
fun find_typeSubs (Const (s', T')) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
442 |
if s=s' then |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
443 |
SOME (Sign.typ_match thy (T', T) Vartab.empty) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
444 |
handle Type.TYPE_MATCH => NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
445 |
else |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
446 |
NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
447 |
| find_typeSubs (Free _) = NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
448 |
| find_typeSubs (Var _) = NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
449 |
| find_typeSubs (Bound _) = NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
450 |
| find_typeSubs (Abs (_, _, body)) = find_typeSubs body |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
451 |
| find_typeSubs (t1 $ t2) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
452 |
(case find_typeSubs t1 of SOME x => SOME x |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
453 |
| NONE => find_typeSubs t2) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
454 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
455 |
case find_typeSubs t of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
456 |
SOME typeSubs => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
457 |
monomorphic_term typeSubs t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
458 |
| NONE => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
459 |
(* no match found - perhaps due to sort constraints *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
460 |
raise Type.TYPE_MATCH |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
461 |
end; |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
462 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
463 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
464 |
(* is_const_of_class: returns 'true' iff 'Const (s, T)' is a constant that *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
465 |
(* denotes membership to an axiomatic type class *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
466 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
467 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
468 |
(* theory -> string * Term.typ -> bool *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
469 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
470 |
fun is_const_of_class thy (s, T) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
471 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
472 |
val class_const_names = map Logic.const_of_class (Sign.all_classes thy) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
473 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
474 |
(* I'm not quite sure if checking the name 's' is sufficient, *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
475 |
(* or if we should also check the type 'T'. *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
476 |
s mem_string class_const_names |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
477 |
end; |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
478 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
479 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
480 |
(* is_IDT_constructor: returns 'true' iff 'Const (s, T)' is the constructor *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
481 |
(* of an inductive datatype in 'thy' *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
482 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
483 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
484 |
(* theory -> string * Term.typ -> bool *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
485 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
486 |
fun is_IDT_constructor thy (s, T) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
487 |
(case body_type T of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
488 |
Type (s', _) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
489 |
(case DatatypePackage.get_datatype_constrs thy s' of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
490 |
SOME constrs => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
491 |
List.exists (fn (cname, cty) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
492 |
cname = s andalso Sign.typ_instance thy (T, cty)) constrs |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
493 |
| NONE => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
494 |
false) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
495 |
| _ => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
496 |
false); |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
497 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
498 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
499 |
(* is_IDT_recursor: returns 'true' iff 'Const (s, T)' is the recursion *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
500 |
(* operator of an inductive datatype in 'thy' *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
501 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
502 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
503 |
(* theory -> string * Term.typ -> bool *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
504 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
505 |
fun is_IDT_recursor thy (s, T) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
506 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
507 |
val rec_names = Symtab.fold (append o #rec_names o snd) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
508 |
(DatatypePackage.get_datatypes thy) [] |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
509 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
510 |
(* I'm not quite sure if checking the name 's' is sufficient, *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
511 |
(* or if we should also check the type 'T'. *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
512 |
s mem_string rec_names |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
513 |
end; |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
514 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
515 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
516 |
(* get_def: looks up the definition of a constant, as created by "constdefs" *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
517 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
518 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
519 |
(* theory -> string * Term.typ -> (string * Term.term) option *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
520 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
521 |
fun get_def thy (s, T) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
522 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
523 |
(* maps f ?t1 ... ?tn == rhs to %t1...tn. rhs *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
524 |
fun norm_rhs eqn = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
525 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
526 |
fun lambda (v as Var ((x, _), T)) t = Abs (x, T, abstract_over (v, t)) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
527 |
| lambda v t = raise TERM ("lambda", [v, t]) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
528 |
val (lhs, rhs) = Logic.dest_equals eqn |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
529 |
val (_, args) = Term.strip_comb lhs |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
530 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
531 |
fold lambda (rev args) rhs |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
532 |
end |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
533 |
(* (string * Term.term) list -> (string * Term.term) option *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
534 |
fun get_def_ax [] = NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
535 |
| get_def_ax ((axname, ax) :: axioms) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
536 |
(let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
537 |
val (lhs, _) = Logic.dest_equals ax (* equations only *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
538 |
val c = Term.head_of lhs |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
539 |
val (s', T') = Term.dest_Const c |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
540 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
541 |
if s=s' then |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
542 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
543 |
val typeSubs = Sign.typ_match thy (T', T) Vartab.empty |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
544 |
val ax' = monomorphic_term typeSubs ax |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
545 |
val rhs = norm_rhs ax' |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
546 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
547 |
SOME (axname, rhs) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
548 |
end |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
549 |
else |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
550 |
get_def_ax axioms |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
551 |
end handle ERROR _ => get_def_ax axioms |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
552 |
| TERM _ => get_def_ax axioms |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
553 |
| Type.TYPE_MATCH => get_def_ax axioms) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
554 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
555 |
get_def_ax (Theory.all_axioms_of thy) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
556 |
end; |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
557 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
558 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
559 |
(* get_typedef: looks up the definition of a type, as created by "typedef" *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
560 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
561 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
562 |
(* theory -> (string * Term.typ) -> (string * Term.term) option *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
563 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
564 |
fun get_typedef thy T = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
565 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
566 |
(* (string * Term.term) list -> (string * Term.term) option *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
567 |
fun get_typedef_ax [] = NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
568 |
| get_typedef_ax ((axname, ax) :: axioms) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
569 |
(let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
570 |
(* Term.term -> Term.typ option *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
571 |
fun type_of_type_definition (Const (s', T')) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
572 |
if s'="Typedef.type_definition" then |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
573 |
SOME T' |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
574 |
else |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
575 |
NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
576 |
| type_of_type_definition (Free _) = NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
577 |
| type_of_type_definition (Var _) = NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
578 |
| type_of_type_definition (Bound _) = NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
579 |
| type_of_type_definition (Abs (_, _, body)) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
580 |
type_of_type_definition body |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
581 |
| type_of_type_definition (t1 $ t2) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
582 |
(case type_of_type_definition t1 of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
583 |
SOME x => SOME x |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
584 |
| NONE => type_of_type_definition t2) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
585 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
586 |
case type_of_type_definition ax of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
587 |
SOME T' => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
588 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
589 |
val T'' = (domain_type o domain_type) T' |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
590 |
val typeSubs = Sign.typ_match thy (T'', T) Vartab.empty |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
591 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
592 |
SOME (axname, monomorphic_term typeSubs ax) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
593 |
end |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
594 |
| NONE => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
595 |
get_typedef_ax axioms |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
596 |
end handle ERROR _ => get_typedef_ax axioms |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
597 |
| MATCH => get_typedef_ax axioms |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
598 |
| Type.TYPE_MATCH => get_typedef_ax axioms) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
599 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
600 |
get_typedef_ax (Theory.all_axioms_of thy) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
601 |
end; |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
602 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
603 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
604 |
(* get_classdef: looks up the defining axiom for an axiomatic type class, as *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
605 |
(* created by the "axclass" command *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
606 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
607 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
608 |
(* theory -> string -> (string * Term.term) option *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
609 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
610 |
fun get_classdef thy class = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
611 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
612 |
val axname = class ^ "_class_def" |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
613 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
614 |
Option.map (pair axname) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
615 |
(AList.lookup (op =) (Theory.all_axioms_of thy) axname) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
616 |
end; |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
617 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
618 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
619 |
(* unfold_defs: unfolds all defined constants in a term 't', beta-eta *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
620 |
(* normalizes the result term; certain constants are not *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
621 |
(* unfolded (cf. 'collect_axioms' and the various interpreters *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
622 |
(* below): if the interpretation respects a definition anyway, *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
623 |
(* that definition does not need to be unfolded *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
624 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
625 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
626 |
(* theory -> Term.term -> Term.term *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
627 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
628 |
(* Note: we could intertwine unfolding of constants and beta-(eta-) *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
629 |
(* normalization; this would save some unfolding for terms where *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
630 |
(* constants are eliminated by beta-reduction (e.g. 'K c1 c2'). On *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
631 |
(* the other hand, this would cause additional work for terms where *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
632 |
(* constants are duplicated by beta-reduction (e.g. 'S c1 c2 c3'). *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
633 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
634 |
fun unfold_defs thy t = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
635 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
636 |
(* Term.term -> Term.term *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
637 |
fun unfold_loop t = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
638 |
case t of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
639 |
(* Pure *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
640 |
Const ("all", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
641 |
| Const ("==", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
642 |
| Const ("==>", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
643 |
| Const ("TYPE", _) => t (* axiomatic type classes *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
644 |
(* HOL *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
645 |
| Const ("Trueprop", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
646 |
| Const ("Not", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
647 |
| (* redundant, since 'True' is also an IDT constructor *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
648 |
Const ("True", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
649 |
| (* redundant, since 'False' is also an IDT constructor *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
650 |
Const ("False", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
651 |
| Const ("arbitrary", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
652 |
| Const ("The", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
653 |
| Const ("Hilbert_Choice.Eps", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
654 |
| Const ("All", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
655 |
| Const ("Ex", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
656 |
| Const ("op =", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
657 |
| Const ("op &", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
658 |
| Const ("op |", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
659 |
| Const ("op -->", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
660 |
(* sets *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
661 |
| Const ("Collect", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
662 |
| Const ("op :", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
663 |
(* other optimizations *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
664 |
| Const ("Finite_Set.card", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
665 |
| Const ("Finite_Set.Finites", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
666 |
| Const ("Orderings.less", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("bool", [])])])) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
667 |
| Const ("HOL.plus", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
668 |
| Const ("HOL.minus", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
669 |
| Const ("HOL.times", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
670 |
| Const ("List.op @", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
671 |
| Const ("Lfp.lfp", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
672 |
| Const ("Gfp.gfp", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
673 |
| Const ("fst", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
674 |
| Const ("snd", _) => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
675 |
(* simply-typed lambda calculus *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
676 |
| Const (s, T) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
677 |
(if is_IDT_constructor thy (s, T) orelse is_IDT_recursor thy (s, T) then |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
678 |
t (* do not unfold IDT constructors/recursors *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
679 |
(* unfold the constant if there is a defining equation *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
680 |
else case get_def thy (s, T) of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
681 |
SOME (axname, rhs) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
682 |
(* Note: if the term to be unfolded (i.e. 'Const (s, T)') *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
683 |
(* occurs on the right-hand side of the equation, i.e. in *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
684 |
(* 'rhs', we must not use this equation to unfold, because *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
685 |
(* that would loop. Here would be the right place to *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
686 |
(* check this. However, getting this really right seems *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
687 |
(* difficult because the user may state arbitrary axioms, *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
688 |
(* which could interact with overloading to create loops. *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
689 |
((*immediate_output (" unfolding: " ^ axname);*)unfold_loop rhs) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
690 |
| NONE => t) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
691 |
| Free _ => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
692 |
| Var _ => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
693 |
| Bound _ => t |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
694 |
| Abs (s, T, body) => Abs (s, T, unfold_loop body) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
695 |
| t1 $ t2 => (unfold_loop t1) $ (unfold_loop t2) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
696 |
val result = Envir.beta_eta_contract (unfold_loop t) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
697 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
698 |
result |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
699 |
end; |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
700 |
|
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
701 |
(* ------------------------------------------------------------------------- *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
702 |
(* collect_axioms: collects (monomorphic, universally quantified, unfolded *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
703 |
(* versions of) all HOL axioms that are relevant w.r.t 't' *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
704 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
705 |
|
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
706 |
(* Note: to make the collection of axioms more easily extensible, this *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
707 |
(* function could be based on user-supplied "axiom collectors", *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
708 |
(* similar to 'interpret'/interpreters or 'print'/printers *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
709 |
|
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
710 |
(* Note: currently we use "inverse" functions to the definitional *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
711 |
(* mechanisms provided by Isabelle/HOL, e.g. for "axclass", *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
712 |
(* "typedef", "constdefs". A more general approach could consider *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
713 |
(* *every* axiom of the theory and collect it if it has a constant/ *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
714 |
(* type/typeclass in common with the term 't'. *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
715 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
716 |
(* theory -> Term.term -> Term.term list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
717 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
718 |
(* Which axioms are "relevant" for a particular term/type goes hand in *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
719 |
(* hand with the interpretation of that term/type by its interpreter (see *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
720 |
(* way below): if the interpretation respects an axiom anyway, the axiom *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
721 |
(* does not need to be added as a constraint here. *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
722 |
|
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
723 |
(* To avoid collecting the same axiom multiple times, we use an *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
724 |
(* accumulator 'axs' which contains all axioms collected so far. *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
725 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
726 |
fun collect_axioms thy t = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
727 |
let |
14984 | 728 |
val _ = immediate_output "Adding axioms..." |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
729 |
(* (string * Term.term) list *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
730 |
val axioms = Theory.all_axioms_of thy |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
731 |
(* string * Term.term -> Term.term list -> Term.term list *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
732 |
fun collect_this_axiom (axname, ax) axs = |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
733 |
let |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
734 |
val ax' = unfold_defs thy ax |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
735 |
in |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
736 |
if member (op aconv) axs ax' then |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
737 |
axs |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
738 |
else ( |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
739 |
immediate_output (" " ^ axname); |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
740 |
collect_term_axioms (ax' :: axs, ax') |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
741 |
) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
742 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
743 |
(* Term.term list * Term.typ -> Term.term list *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
744 |
and collect_sort_axioms (axs, T) = |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
745 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
746 |
(* string list *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
747 |
val sort = (case T of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
748 |
TFree (_, sort) => sort |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
749 |
| TVar (_, sort) => sort |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
750 |
| _ => raise REFUTE ("collect_axioms", "type " ^ |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
751 |
Sign.string_of_typ thy T ^ " is not a variable")) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
752 |
(* obtain axioms for all superclasses *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
753 |
val superclasses = sort @ (maps (Sign.super_classes thy) sort) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
754 |
(* merely an optimization, because 'collect_this_axiom' disallows *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
755 |
(* duplicate axioms anyway: *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
756 |
val superclasses = distinct (op =) superclasses |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
757 |
val class_axioms = maps (fn class => map (fn ax => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
758 |
("<" ^ class ^ ">", Thm.prop_of ax)) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
759 |
(#axioms (AxClass.get_definition thy class) handle ERROR _ => [])) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
760 |
superclasses |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
761 |
(* replace the (at most one) schematic type variable in each axiom *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
762 |
(* by the actual type 'T' *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
763 |
val monomorphic_class_axioms = map (fn (axname, ax) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
764 |
(case Term.term_tvars ax of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
765 |
[] => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
766 |
(axname, ax) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
767 |
| [(idx, S)] => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
768 |
(axname, monomorphic_term (Vartab.make [(idx, (S, T))]) ax) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
769 |
| _ => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
770 |
raise REFUTE ("collect_axioms", "class axiom " ^ axname ^ " (" ^ |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
771 |
Sign.string_of_term thy ax ^ |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
772 |
") contains more than one type variable"))) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
773 |
class_axioms |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
774 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
775 |
fold collect_this_axiom monomorphic_class_axioms axs |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
776 |
end |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
777 |
(* Term.term list * Term.typ -> Term.term list *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
778 |
and collect_type_axioms (axs, T) = |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
779 |
case T of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
780 |
(* simple types *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
781 |
Type ("prop", []) => axs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
782 |
| Type ("fun", [T1, T2]) => collect_type_axioms (collect_type_axioms (axs, T1), T2) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
783 |
| Type ("set", [T1]) => collect_type_axioms (axs, T1) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
784 |
| Type ("itself", [T1]) => collect_type_axioms (axs, T1) (* axiomatic type classes *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
785 |
| Type (s, Ts) => |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
786 |
(case DatatypePackage.get_datatype thy s of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
787 |
SOME info => (* inductive datatype *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
788 |
(* only collect relevant type axioms for the argument types *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
789 |
Library.foldl collect_type_axioms (axs, Ts) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
790 |
| NONE => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
791 |
(case get_typedef thy T of |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
792 |
SOME (axname, ax) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
793 |
collect_this_axiom (axname, ax) axs |
15531 | 794 |
| NONE => |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
795 |
(* unspecified type, perhaps introduced with "typedecl" *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
796 |
(* at least collect relevant type axioms for the argument types *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
797 |
Library.foldl collect_type_axioms (axs, Ts))) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
798 |
| TFree _ => collect_sort_axioms (axs, T) (* axiomatic type classes *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
799 |
| TVar _ => collect_sort_axioms (axs, T) (* axiomatic type classes *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
800 |
(* Term.term list * Term.term -> Term.term list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
801 |
and collect_term_axioms (axs, t) = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
802 |
case t of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
803 |
(* Pure *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
804 |
Const ("all", _) => axs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
805 |
| Const ("==", _) => axs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
806 |
| Const ("==>", _) => axs |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
807 |
| Const ("TYPE", T) => collect_type_axioms (axs, T) (* axiomatic type classes *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
808 |
(* HOL *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
809 |
| Const ("Trueprop", _) => axs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
810 |
| Const ("Not", _) => axs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
811 |
| Const ("True", _) => axs (* redundant, since 'True' is also an IDT constructor *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
812 |
| Const ("False", _) => axs (* redundant, since 'False' is also an IDT constructor *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
813 |
| Const ("arbitrary", T) => collect_type_axioms (axs, T) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
814 |
| Const ("The", T) => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
815 |
let |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
816 |
val ax = specialize_type thy ("The", T) ((Option.valOf o AList.lookup (op =) axioms) "HOL.the_eq_trivial") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
817 |
in |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
818 |
collect_this_axiom ("HOL.the_eq_trivial", ax) axs |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
819 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
820 |
| Const ("Hilbert_Choice.Eps", T) => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
821 |
let |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
822 |
val ax = specialize_type thy ("Hilbert_Choice.Eps", T) ((Option.valOf o AList.lookup (op =) axioms) "Hilbert_Choice.someI") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
823 |
in |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
824 |
collect_this_axiom ("Hilbert_Choice.someI", ax) axs |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
825 |
end |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
826 |
| Const ("All", T) => collect_type_axioms (axs, T) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
827 |
| Const ("Ex", T) => collect_type_axioms (axs, T) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
828 |
| Const ("op =", T) => collect_type_axioms (axs, T) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
829 |
| Const ("op &", _) => axs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
830 |
| Const ("op |", _) => axs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
831 |
| Const ("op -->", _) => axs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
832 |
(* sets *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
833 |
| Const ("Collect", T) => collect_type_axioms (axs, T) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
834 |
| Const ("op :", T) => collect_type_axioms (axs, T) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
835 |
(* other optimizations *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
836 |
| Const ("Finite_Set.card", T) => collect_type_axioms (axs, T) |
15571 | 837 |
| Const ("Finite_Set.Finites", T) => collect_type_axioms (axs, T) |
19277 | 838 |
| Const ("Orderings.less", T as Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("bool", [])])])) => collect_type_axioms (axs, T) |
19233
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
haftmann
parents:
18932
diff
changeset
|
839 |
| Const ("HOL.plus", T as Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => collect_type_axioms (axs, T) |
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
haftmann
parents:
18932
diff
changeset
|
840 |
| Const ("HOL.minus", T as Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => collect_type_axioms (axs, T) |
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
haftmann
parents:
18932
diff
changeset
|
841 |
| Const ("HOL.times", T as Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => collect_type_axioms (axs, T) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
842 |
| Const ("List.op @", T) => collect_type_axioms (axs, T) |
16050 | 843 |
| Const ("Lfp.lfp", T) => collect_type_axioms (axs, T) |
844 |
| Const ("Gfp.gfp", T) => collect_type_axioms (axs, T) |
|
21267 | 845 |
| Const ("fst", T) => collect_type_axioms (axs, T) |
846 |
| Const ("snd", T) => collect_type_axioms (axs, T) |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
847 |
(* simply-typed lambda calculus *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
848 |
| Const (s, T) => |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
849 |
if is_const_of_class thy (s, T) then |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
850 |
(* axiomatic type classes: add "OFCLASS(?'a::c, c_class)" *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
851 |
(* and the class definition *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
852 |
let |
18932 | 853 |
val class = Logic.class_of_const s |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
854 |
val inclass = Logic.mk_inclass (TVar (("'a", 0), [class]), class) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
855 |
val ax_in = SOME (specialize_type thy (s, T) inclass) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
856 |
(* type match may fail due to sort constraints *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
857 |
handle Type.TYPE_MATCH => NONE |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
858 |
val ax_1 = Option.map (fn ax => (Sign.string_of_term thy ax, ax)) ax_in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
859 |
val ax_2 = Option.map (apsnd (specialize_type thy (s, T))) (get_classdef thy class) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
860 |
in |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
861 |
collect_type_axioms (fold collect_this_axiom |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
862 |
(map_filter I [ax_1, ax_2]) axs, T) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
863 |
end |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
864 |
else if is_IDT_constructor thy (s, T) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
865 |
orelse is_IDT_recursor thy (s, T) then |
15125 | 866 |
(* only collect relevant type axioms *) |
867 |
collect_type_axioms (axs, T) |
|
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
868 |
else |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
869 |
(* other constants should have been unfolded, with some *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
870 |
(* exceptions: e.g. Abs_xxx/Rep_xxx functions for *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
871 |
(* typedefs, or type-class related constants *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
872 |
(* only collect relevant type axioms *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
873 |
collect_type_axioms (axs, T) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
874 |
| Free (_, T) => collect_type_axioms (axs, T) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
875 |
| Var (_, T) => collect_type_axioms (axs, T) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
876 |
| Bound i => axs |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
877 |
| Abs (_, T, body) => collect_term_axioms (collect_type_axioms (axs, T), body) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
878 |
| t1 $ t2 => collect_term_axioms (collect_term_axioms (axs, t1), t2) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
879 |
(* Term.term list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
880 |
val result = map close_form (collect_term_axioms ([], t)) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
881 |
val _ = writeln " ...done." |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
882 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
883 |
result |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
884 |
end; |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
885 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
886 |
(* ------------------------------------------------------------------------- *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
887 |
(* ground_types: collects all ground types in a term (including argument *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
888 |
(* types of other types), suppressing duplicates. Does not *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
889 |
(* return function types, set types, non-recursive IDTs, or *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
890 |
(* 'propT'. For IDTs, also the argument types of constructors *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
891 |
(* are considered. *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
892 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
893 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
894 |
(* theory -> Term.term -> Term.typ list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
895 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
896 |
fun ground_types thy t = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
897 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
898 |
(* Term.typ * Term.typ list -> Term.typ list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
899 |
fun collect_types (T, acc) = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
900 |
if T mem acc then |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
901 |
acc (* prevent infinite recursion (for IDTs) *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
902 |
else |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
903 |
(case T of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
904 |
Type ("fun", [T1, T2]) => collect_types (T1, collect_types (T2, acc)) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
905 |
| Type ("prop", []) => acc |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
906 |
| Type ("set", [T1]) => collect_types (T1, acc) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
907 |
| Type (s, Ts) => |
19346 | 908 |
(case DatatypePackage.get_datatype thy s of |
15531 | 909 |
SOME info => (* inductive datatype *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
910 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
911 |
val index = #index info |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
912 |
val descr = #descr info |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
913 |
val (_, dtyps, constrs) = (Option.valOf o AList.lookup (op =) descr) index |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
914 |
val typ_assoc = dtyps ~~ Ts |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
915 |
(* sanity check: every element in 'dtyps' must be a 'DtTFree' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
916 |
val _ = (if Library.exists (fn d => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
917 |
case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
918 |
then |
21992 | 919 |
raise REFUTE ("ground_types", "datatype argument (for type " ^ Sign.string_of_typ thy (Type (s, Ts)) ^ ") is not a variable") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
920 |
else |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
921 |
()) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
922 |
(* if the current type is a recursive IDT (i.e. a depth is required), add it to 'acc' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
923 |
val acc' = (if Library.exists (fn (_, ds) => Library.exists DatatypeAux.is_rec_type ds) constrs then |
20854 | 924 |
insert (op =) T acc |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
925 |
else |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
926 |
acc) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
927 |
(* collect argument types *) |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15571
diff
changeset
|
928 |
val acc_args = foldr collect_types acc' Ts |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
929 |
(* collect constructor types *) |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15571
diff
changeset
|
930 |
val acc_constrs = foldr collect_types acc_args (List.concat (map (fn (_, ds) => map (typ_of_dtyp descr typ_assoc) ds) constrs)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
931 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
932 |
acc_constrs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
933 |
end |
15531 | 934 |
| NONE => (* not an inductive datatype, e.g. defined via "typedef" or "typedecl" *) |
20854 | 935 |
insert (op =) T (foldr collect_types acc Ts)) |
936 |
| TFree _ => insert (op =) T acc |
|
937 |
| TVar _ => insert (op =) T acc) |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
938 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
939 |
it_term_types collect_types (t, []) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
940 |
end; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
941 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
942 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
943 |
(* string_of_typ: (rather naive) conversion from types to strings, used to *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
944 |
(* look up the size of a type in 'sizes'. Parameterized *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
945 |
(* types with different parameters (e.g. "'a list" vs. "bool *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
946 |
(* list") are identified. *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
947 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
948 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
949 |
(* Term.typ -> string *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
950 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
951 |
fun string_of_typ (Type (s, _)) = s |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
952 |
| string_of_typ (TFree (s, _)) = s |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
953 |
| string_of_typ (TVar ((s,_), _)) = s; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
954 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
955 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
956 |
(* first_universe: returns the "first" (i.e. smallest) universe by assigning *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
957 |
(* 'minsize' to every type for which no size is specified in *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
958 |
(* 'sizes' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
959 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
960 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
961 |
(* Term.typ list -> (string * int) list -> int -> (Term.typ * int) list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
962 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
963 |
fun first_universe xs sizes minsize = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
964 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
965 |
fun size_of_typ T = |
17314 | 966 |
case AList.lookup (op =) sizes (string_of_typ T) of |
15531 | 967 |
SOME n => n |
968 |
| NONE => minsize |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
969 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
970 |
map (fn T => (T, size_of_typ T)) xs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
971 |
end; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
972 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
973 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
974 |
(* next_universe: enumerates all universes (i.e. assignments of sizes to *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
975 |
(* types), where the minimal size of a type is given by *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
976 |
(* 'minsize', the maximal size is given by 'maxsize', and a *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
977 |
(* type may have a fixed size given in 'sizes' *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
978 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
979 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
980 |
(* (Term.typ * int) list -> (string * int) list -> int -> int -> (Term.typ * int) list option *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
981 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
982 |
fun next_universe xs sizes minsize maxsize = |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
983 |
let |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
984 |
(* creates the "first" list of length 'len', where the sum of all list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
985 |
(* elements is 'sum', and the length of the list is 'len' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
986 |
(* int -> int -> int -> int list option *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
987 |
fun make_first _ 0 sum = |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
988 |
if sum=0 then |
15531 | 989 |
SOME [] |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
990 |
else |
15531 | 991 |
NONE |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
992 |
| make_first max len sum = |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
993 |
if sum<=max orelse max<0 then |
15570 | 994 |
Option.map (fn xs' => sum :: xs') (make_first max (len-1) 0) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
995 |
else |
15570 | 996 |
Option.map (fn xs' => max :: xs') (make_first max (len-1) (sum-max)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
997 |
(* enumerates all int lists with a fixed length, where 0<=x<='max' for *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
998 |
(* all list elements x (unless 'max'<0) *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
999 |
(* int -> int -> int -> int list -> int list option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1000 |
fun next max len sum [] = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1001 |
NONE |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1002 |
| next max len sum [x] = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1003 |
(* we've reached the last list element, so there's no shift possible *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1004 |
make_first max (len+1) (sum+x+1) (* increment 'sum' by 1 *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1005 |
| next max len sum (x1::x2::xs) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1006 |
if x1>0 andalso (x2<max orelse max<0) then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1007 |
(* we can shift *) |
15570 | 1008 |
SOME (valOf (make_first max (len+1) (sum+x1-1)) @ (x2+1) :: xs) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1009 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1010 |
(* continue search *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1011 |
next max (len+1) (sum+x1) (x2::xs) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1012 |
(* only consider those types for which the size is not fixed *) |
17314 | 1013 |
val mutables = List.filter (not o (AList.defined (op =) sizes) o string_of_typ o fst) xs |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1014 |
(* subtract 'minsize' from every size (will be added again at the end) *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1015 |
val diffs = map (fn (_, n) => n-minsize) mutables |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1016 |
in |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1017 |
case next (maxsize-minsize) 0 0 diffs of |
15531 | 1018 |
SOME diffs' => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1019 |
(* merge with those types for which the size is fixed *) |
15531 | 1020 |
SOME (snd (foldl_map (fn (ds, (T, _)) => |
17314 | 1021 |
case AList.lookup (op =) sizes (string_of_typ T) of |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1022 |
SOME n => (ds, (T, n)) (* return the fixed size *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1023 |
| NONE => (tl ds, (T, minsize + hd ds))) (* consume the head of 'ds', add 'minsize' *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1024 |
(diffs', xs))) |
15531 | 1025 |
| NONE => |
1026 |
NONE |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1027 |
end; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1028 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1029 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1030 |
(* toTrue: converts the interpretation of a Boolean value to a propositional *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1031 |
(* formula that is true iff the interpretation denotes "true" *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1032 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1033 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1034 |
(* interpretation -> prop_formula *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1035 |
|
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
1036 |
fun toTrue (Leaf [fm, _]) = fm |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
1037 |
| toTrue _ = raise REFUTE ("toTrue", "interpretation does not denote a Boolean value"); |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1038 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1039 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1040 |
(* toFalse: converts the interpretation of a Boolean value to a *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1041 |
(* propositional formula that is true iff the interpretation *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1042 |
(* denotes "false" *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1043 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1044 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1045 |
(* interpretation -> prop_formula *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1046 |
|
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
1047 |
fun toFalse (Leaf [_, fm]) = fm |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
1048 |
| toFalse _ = raise REFUTE ("toFalse", "interpretation does not denote a Boolean value"); |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1049 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1050 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1051 |
(* find_model: repeatedly calls 'interpret' with appropriate parameters, *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1052 |
(* applies a SAT solver, and (in case a model is found) displays *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1053 |
(* the model to the user by calling 'print_model' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1054 |
(* thy : the current theory *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1055 |
(* {...} : parameters that control the translation/model generation *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1056 |
(* t : term to be translated into a propositional formula *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1057 |
(* negate : if true, find a model that makes 't' false (rather than true) *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1058 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1059 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1060 |
(* theory -> params -> Term.term -> bool -> unit *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1061 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1062 |
fun find_model thy {sizes, minsize, maxsize, maxvars, maxtime, satsolver} t negate = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1063 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1064 |
(* unit -> unit *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1065 |
fun wrapper () = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1066 |
let |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1067 |
val u = unfold_defs thy t |
21992 | 1068 |
val _ = writeln ("Unfolded term: " ^ Sign.string_of_term thy u) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1069 |
val axioms = collect_axioms thy u |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1070 |
(* Term.typ list *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1071 |
val types = Library.foldl (fn (acc, t') => acc union (ground_types thy t')) ([], u :: axioms) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1072 |
val _ = writeln ("Ground types: " |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1073 |
^ (if null types then "none." |
21992 | 1074 |
else commas (map (Sign.string_of_typ thy) types))) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1075 |
(* we can only consider fragments of recursive IDTs, so we issue a *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1076 |
(* warning if the formula contains a recursive IDT *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1077 |
(* TODO: no warning needed for /positive/ occurrences of IDTs *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1078 |
val _ = if Library.exists (fn |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1079 |
Type (s, _) => |
19346 | 1080 |
(case DatatypePackage.get_datatype thy s of |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1081 |
SOME info => (* inductive datatype *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1082 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1083 |
val index = #index info |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1084 |
val descr = #descr info |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1085 |
val (_, _, constrs) = (Option.valOf o AList.lookup (op =) descr) index |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1086 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1087 |
(* recursive datatype? *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1088 |
Library.exists (fn (_, ds) => Library.exists DatatypeAux.is_rec_type ds) constrs |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1089 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1090 |
| NONE => false) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1091 |
| _ => false) types then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1092 |
warning "Term contains a recursive datatype; countermodel(s) may be spurious!" |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1093 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1094 |
() |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1095 |
(* (Term.typ * int) list -> unit *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1096 |
fun find_model_loop universe = |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
1097 |
let |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1098 |
val init_model = (universe, []) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1099 |
val init_args = {maxvars = maxvars, def_eq = false, next_idx = 1, bounds = [], wellformed = True} |
14984 | 1100 |
val _ = immediate_output ("Translating term (sizes: " ^ commas (map (fn (_, n) => string_of_int n) universe) ^ ") ...") |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1101 |
(* translate 'u' and all axioms *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1102 |
val ((model, args), intrs) = foldl_map (fn ((m, a), t') => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1103 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1104 |
val (i, m', a') = interpret thy m a t' |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1105 |
in |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1106 |
(* set 'def_eq' to 'true' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1107 |
((m', {maxvars = #maxvars a', def_eq = true, next_idx = #next_idx a', bounds = #bounds a', wellformed = #wellformed a'}), i) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1108 |
end) ((init_model, init_args), u :: axioms) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1109 |
(* make 'u' either true or false, and make all axioms true, and *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1110 |
(* add the well-formedness side condition *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1111 |
val fm_u = (if negate then toFalse else toTrue) (hd intrs) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1112 |
val fm_ax = PropLogic.all (map toTrue (tl intrs)) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1113 |
val fm = PropLogic.all [#wellformed args, fm_ax, fm_u] |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1114 |
in |
14984 | 1115 |
immediate_output " invoking SAT solver..."; |
14965 | 1116 |
(case SatSolver.invoke_solver satsolver fm of |
1117 |
SatSolver.SATISFIABLE assignment => |
|
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1118 |
(writeln " model found!"; |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1119 |
writeln ("*** Model found: ***\n" ^ print_model thy model (fn i => case assignment i of SOME b => b | NONE => true))) |
17493
cf8713d880b1
SAT solver interface modified to support proofs of unsatisfiability
webertj
parents:
17412
diff
changeset
|
1120 |
| SatSolver.UNSATISFIABLE _ => |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1121 |
(immediate_output " no model exists.\n"; |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1122 |
case next_universe universe sizes minsize maxsize of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1123 |
SOME universe' => find_model_loop universe' |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1124 |
| NONE => writeln "Search terminated, no larger universe within the given limits.") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1125 |
| SatSolver.UNKNOWN => |
14984 | 1126 |
(immediate_output " no model found.\n"; |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1127 |
case next_universe universe sizes minsize maxsize of |
15531 | 1128 |
SOME universe' => find_model_loop universe' |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1129 |
| NONE => writeln "Search terminated, no larger universe within the given limits.") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1130 |
) handle SatSolver.NOT_CONFIGURED => |
14965 | 1131 |
error ("SAT solver " ^ quote satsolver ^ " is not configured.") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1132 |
end handle MAXVARS_EXCEEDED => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1133 |
writeln ("\nSearch terminated, number of Boolean variables (" ^ string_of_int maxvars ^ " allowed) exceeded.") |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1134 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1135 |
find_model_loop (first_universe types sizes minsize) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1136 |
end |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1137 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1138 |
(* some parameter sanity checks *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1139 |
assert (minsize>=1) ("\"minsize\" is " ^ string_of_int minsize ^ ", must be at least 1"); |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1140 |
assert (maxsize>=1) ("\"maxsize\" is " ^ string_of_int maxsize ^ ", must be at least 1"); |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1141 |
assert (maxsize>=minsize) ("\"maxsize\" (=" ^ string_of_int maxsize ^ ") is less than \"minsize\" (=" ^ string_of_int minsize ^ ")."); |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1142 |
assert (maxvars>=0) ("\"maxvars\" is " ^ string_of_int maxvars ^ ", must be at least 0"); |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1143 |
assert (maxtime>=0) ("\"maxtime\" is " ^ string_of_int maxtime ^ ", must be at least 0"); |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1144 |
(* enter loop with or without time limit *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1145 |
writeln ("Trying to find a model that " ^ (if negate then "refutes" else "satisfies") ^ ": " |
21992 | 1146 |
^ Sign.string_of_term thy t); |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1147 |
if maxtime>0 then ( |
18760 | 1148 |
interrupt_timeout (Time.fromSeconds (Int.toLarge maxtime)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1149 |
wrapper () |
18760 | 1150 |
handle Interrupt => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1151 |
writeln ("\nSearch terminated, time limit (" |
14965 | 1152 |
^ string_of_int maxtime ^ (if maxtime=1 then " second" else " seconds") |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1153 |
^ ") exceeded.") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1154 |
) else |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1155 |
wrapper () |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1156 |
end; |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1157 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1158 |
|
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1159 |
(* ------------------------------------------------------------------------- *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1160 |
(* INTERFACE, PART 2: FINDING A MODEL *) |
14350 | 1161 |
(* ------------------------------------------------------------------------- *) |
1162 |
||
1163 |
(* ------------------------------------------------------------------------- *) |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1164 |
(* satisfy_term: calls 'find_model' to find a model that satisfies 't' *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1165 |
(* params : list of '(name, value)' pairs used to override default *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1166 |
(* parameters *) |
14350 | 1167 |
(* ------------------------------------------------------------------------- *) |
1168 |
||
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1169 |
(* theory -> (string * string) list -> Term.term -> unit *) |
14350 | 1170 |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1171 |
fun satisfy_term thy params t = |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1172 |
find_model thy (actual_params thy params) t false; |
14350 | 1173 |
|
1174 |
(* ------------------------------------------------------------------------- *) |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1175 |
(* refute_term: calls 'find_model' to find a model that refutes 't' *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1176 |
(* params : list of '(name, value)' pairs used to override default *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1177 |
(* parameters *) |
14350 | 1178 |
(* ------------------------------------------------------------------------- *) |
1179 |
||
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1180 |
(* theory -> (string * string) list -> Term.term -> unit *) |
14350 | 1181 |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1182 |
fun refute_term thy params t = |
14350 | 1183 |
let |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1184 |
(* disallow schematic type variables, since we cannot properly negate *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1185 |
(* terms containing them (their logical meaning is that there EXISTS a *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1186 |
(* type s.t. ...; to refute such a formula, we would have to show that *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1187 |
(* for ALL types, not ...) *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1188 |
val _ = assert (null (term_tvars t)) "Term to be refuted contains schematic type variables" |
21556 | 1189 |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1190 |
(* existential closure over schematic variables *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1191 |
(* (Term.indexname * Term.typ) list *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1192 |
val vars = sort_wrt (fst o fst) (map dest_Var (term_vars t)) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1193 |
(* Term.term *) |
15570 | 1194 |
val ex_closure = Library.foldl |
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1195 |
(fn (t', ((x, i), T)) => (HOLogic.exists_const T) $ Abs (x, T, abstract_over (Var ((x, i), T), t'))) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1196 |
(t, vars) |
21556 | 1197 |
(* Note: If 't' is of type 'propT' (rather than 'boolT'), applying *) |
1198 |
(* 'HOLogic.exists_const' is not type-correct. However, this is not *) |
|
1199 |
(* really a problem as long as 'find_model' still interprets the *) |
|
1200 |
(* resulting term correctly, without checking its type. *) |
|
1201 |
||
1202 |
(* replace outermost universally quantified variables by Free's: *) |
|
1203 |
(* refuting a term with Free's is generally faster than refuting a *) |
|
1204 |
(* term with (nested) quantifiers, because quantifiers are expanded, *) |
|
1205 |
(* while the SAT solver searches for an interpretation for Free's. *) |
|
1206 |
(* Also we get more information back that way, namely an *) |
|
1207 |
(* interpretation which includes values for the (formerly) *) |
|
1208 |
(* quantified variables. *) |
|
1209 |
(* maps !!x1...xn. !xk...xm. t to t *) |
|
1210 |
fun strip_all_body (Const ("all", _) $ Abs (_, _, t)) = strip_all_body t |
|
1211 |
| strip_all_body (Const ("Trueprop", _) $ t) = strip_all_body t |
|
1212 |
| strip_all_body (Const ("All", _) $ Abs (_, _, t)) = strip_all_body t |
|
1213 |
| strip_all_body t = t |
|
1214 |
(* maps !!x1...xn. !xk...xm. t to [x1, ..., xn, xk, ..., xm] *) |
|
1215 |
fun strip_all_vars (Const ("all", _) $ Abs (a, T, t)) = (a, T) :: strip_all_vars t |
|
1216 |
| strip_all_vars (Const ("Trueprop", _) $ t) = strip_all_vars t |
|
1217 |
| strip_all_vars (Const ("All", _) $ Abs (a, T, t)) = (a, T) :: strip_all_vars t |
|
1218 |
| strip_all_vars t = [] : (string * typ) list |
|
1219 |
val strip_t = strip_all_body ex_closure |
|
1220 |
val frees = Term.rename_wrt_term strip_t (strip_all_vars ex_closure) |
|
1221 |
val subst_t = Term.subst_bounds (map Free frees, strip_t) |
|
14350 | 1222 |
in |
21556 | 1223 |
find_model thy (actual_params thy params) subst_t true |
14350 | 1224 |
end; |
1225 |
||
1226 |
(* ------------------------------------------------------------------------- *) |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1227 |
(* refute_subgoal: calls 'refute_term' on a specific subgoal *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1228 |
(* params : list of '(name, value)' pairs used to override default *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1229 |
(* parameters *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1230 |
(* subgoal : 0-based index specifying the subgoal number *) |
14350 | 1231 |
(* ------------------------------------------------------------------------- *) |
1232 |
||
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1233 |
(* theory -> (string * string) list -> Thm.thm -> int -> unit *) |
14350 | 1234 |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1235 |
fun refute_subgoal thy params thm subgoal = |
15570 | 1236 |
refute_term thy params (List.nth (prems_of thm, subgoal)); |
14350 | 1237 |
|
1238 |
||
1239 |
(* ------------------------------------------------------------------------- *) |
|
15292 | 1240 |
(* INTERPRETERS: Auxiliary Functions *) |
14350 | 1241 |
(* ------------------------------------------------------------------------- *) |
1242 |
||
1243 |
(* ------------------------------------------------------------------------- *) |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1244 |
(* make_constants: returns all interpretations that have the same tree *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1245 |
(* structure as 'intr', but consist of unit vectors with *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1246 |
(* 'True'/'False' only (no Boolean variables) *) |
14350 | 1247 |
(* ------------------------------------------------------------------------- *) |
1248 |
||
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1249 |
(* interpretation -> interpretation list *) |
14350 | 1250 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1251 |
fun make_constants intr = |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1252 |
let |
14350 | 1253 |
(* returns a list with all unit vectors of length n *) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1254 |
(* int -> interpretation list *) |
14350 | 1255 |
fun unit_vectors n = |
1256 |
let |
|
1257 |
(* returns the k-th unit vector of length n *) |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1258 |
(* int * int -> interpretation *) |
14350 | 1259 |
fun unit_vector (k,n) = |
1260 |
Leaf ((replicate (k-1) False) @ (True :: (replicate (n-k) False))) |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1261 |
(* int -> interpretation list -> interpretation list *) |
14350 | 1262 |
fun unit_vectors_acc k vs = |
1263 |
if k>n then [] else (unit_vector (k,n))::(unit_vectors_acc (k+1) vs) |
|
1264 |
in |
|
1265 |
unit_vectors_acc 1 [] |
|
1266 |
end |
|
1267 |
(* concatenates 'x' with every list in 'xss', returning a new list of lists *) |
|
1268 |
(* 'a -> 'a list list -> 'a list list *) |
|
1269 |
fun cons_list x xss = |
|
1270 |
map (fn xs => x::xs) xss |
|
1271 |
(* returns a list of lists, each one consisting of n (possibly identical) elements from 'xs' *) |
|
1272 |
(* int -> 'a list -> 'a list list *) |
|
1273 |
fun pick_all 1 xs = |
|
1274 |
map (fn x => [x]) xs |
|
1275 |
| pick_all n xs = |
|
1276 |
let val rec_pick = pick_all (n-1) xs in |
|
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1277 |
Library.foldl (fn (acc, x) => (cons_list x rec_pick) @ acc) ([], xs) |
14350 | 1278 |
end |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1279 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1280 |
case intr of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1281 |
Leaf xs => unit_vectors (length xs) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1282 |
| Node xs => map (fn xs' => Node xs') (pick_all (length xs) (make_constants (hd xs))) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1283 |
end; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1284 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1285 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1286 |
(* size_of_type: returns the number of constants in a type (i.e. 'length *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1287 |
(* (make_constants intr)', but implemented more efficiently) *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1288 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1289 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1290 |
(* interpretation -> int *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1291 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1292 |
fun size_of_type intr = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1293 |
let |
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1294 |
(* power (a, b) computes a^b, for a>=0, b>=0 *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1295 |
(* int * int -> int *) |
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1296 |
fun power (a, 0) = 1 |
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1297 |
| power (a, 1) = a |
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1298 |
| power (a, b) = let val ab = power(a, b div 2) in ab * ab * power(a, b mod 2) end |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1299 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1300 |
case intr of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1301 |
Leaf xs => length xs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1302 |
| Node xs => power (size_of_type (hd xs), length xs) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1303 |
end; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1304 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1305 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1306 |
(* TT/FF: interpretations that denote "true" or "false", respectively *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1307 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1308 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1309 |
(* interpretation *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1310 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1311 |
val TT = Leaf [True, False]; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1312 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1313 |
val FF = Leaf [False, True]; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1314 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1315 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1316 |
(* make_equality: returns an interpretation that denotes (extensional) *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1317 |
(* equality of two interpretations *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1318 |
(* - two interpretations are 'equal' iff they are both defined and denote *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1319 |
(* the same value *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1320 |
(* - two interpretations are 'not_equal' iff they are both defined at least *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1321 |
(* partially, and a defined part denotes different values *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1322 |
(* - a completely undefined interpretation is neither 'equal' nor *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1323 |
(* 'not_equal' to another interpretation *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1324 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1325 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1326 |
(* We could in principle represent '=' on a type T by a particular *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1327 |
(* interpretation. However, the size of that interpretation is quadratic *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1328 |
(* in the size of T. Therefore comparing the interpretations 'i1' and *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1329 |
(* 'i2' directly is more efficient than constructing the interpretation *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1330 |
(* for equality on T first, and "applying" this interpretation to 'i1' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1331 |
(* and 'i2' in the usual way (cf. 'interpretation_apply') then. *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1332 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1333 |
(* interpretation * interpretation -> interpretation *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1334 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1335 |
fun make_equality (i1, i2) = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1336 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1337 |
(* interpretation * interpretation -> prop_formula *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1338 |
fun equal (i1, i2) = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1339 |
(case i1 of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1340 |
Leaf xs => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1341 |
(case i2 of |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1342 |
Leaf ys => PropLogic.dot_product (xs, ys) (* defined and equal *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1343 |
| Node _ => raise REFUTE ("make_equality", "second interpretation is higher")) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1344 |
| Node xs => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1345 |
(case i2 of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1346 |
Leaf _ => raise REFUTE ("make_equality", "first interpretation is higher") |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1347 |
| Node ys => PropLogic.all (map equal (xs ~~ ys)))) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1348 |
(* interpretation * interpretation -> prop_formula *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1349 |
fun not_equal (i1, i2) = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1350 |
(case i1 of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1351 |
Leaf xs => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1352 |
(case i2 of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1353 |
Leaf ys => PropLogic.all ((PropLogic.exists xs) :: (PropLogic.exists ys) :: |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1354 |
(map (fn (x,y) => SOr (SNot x, SNot y)) (xs ~~ ys))) (* defined and not equal *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1355 |
| Node _ => raise REFUTE ("make_equality", "second interpretation is higher")) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1356 |
| Node xs => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1357 |
(case i2 of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1358 |
Leaf _ => raise REFUTE ("make_equality", "first interpretation is higher") |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1359 |
| Node ys => PropLogic.exists (map not_equal (xs ~~ ys)))) |
14350 | 1360 |
in |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1361 |
(* a value may be undefined; therefore 'not_equal' is not just the *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1362 |
(* negation of 'equal' *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1363 |
Leaf [equal (i1, i2), not_equal (i1, i2)] |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1364 |
end; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1365 |
|
15292 | 1366 |
(* ------------------------------------------------------------------------- *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1367 |
(* make_def_equality: returns an interpretation that denotes (extensional) *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1368 |
(* equality of two interpretations *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1369 |
(* This function treats undefined/partially defined interpretations *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1370 |
(* different from 'make_equality': two undefined interpretations are *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1371 |
(* considered equal, while a defined interpretation is considered not equal *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1372 |
(* to an undefined interpretation. *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1373 |
(* ------------------------------------------------------------------------- *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1374 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1375 |
(* interpretation * interpretation -> interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1376 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1377 |
fun make_def_equality (i1, i2) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1378 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1379 |
(* interpretation * interpretation -> prop_formula *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1380 |
fun equal (i1, i2) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1381 |
(case i1 of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1382 |
Leaf xs => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1383 |
(case i2 of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1384 |
Leaf ys => SOr (PropLogic.dot_product (xs, ys), (* defined and equal, or both undefined *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1385 |
SAnd (PropLogic.all (map SNot xs), PropLogic.all (map SNot ys))) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1386 |
| Node _ => raise REFUTE ("make_def_equality", "second interpretation is higher")) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1387 |
| Node xs => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1388 |
(case i2 of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1389 |
Leaf _ => raise REFUTE ("make_def_equality", "first interpretation is higher") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1390 |
| Node ys => PropLogic.all (map equal (xs ~~ ys)))) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1391 |
(* interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1392 |
val eq = equal (i1, i2) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1393 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1394 |
Leaf [eq, SNot eq] |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1395 |
end; |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1396 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1397 |
(* ------------------------------------------------------------------------- *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1398 |
(* interpretation_apply: returns an interpretation that denotes the result *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1399 |
(* of applying the function denoted by 'i2' to the *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1400 |
(* argument denoted by 'i2' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1401 |
(* ------------------------------------------------------------------------- *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1402 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1403 |
(* interpretation * interpretation -> interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1404 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1405 |
fun interpretation_apply (i1, i2) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1406 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1407 |
(* interpretation * interpretation -> interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1408 |
fun interpretation_disjunction (tr1,tr2) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1409 |
tree_map (fn (xs,ys) => map (fn (x,y) => SOr(x,y)) (xs ~~ ys)) (tree_pair (tr1,tr2)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1410 |
(* prop_formula * interpretation -> interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1411 |
fun prop_formula_times_interpretation (fm,tr) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1412 |
tree_map (map (fn x => SAnd (fm,x))) tr |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1413 |
(* prop_formula list * interpretation list -> interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1414 |
fun prop_formula_list_dot_product_interpretation_list ([fm],[tr]) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1415 |
prop_formula_times_interpretation (fm,tr) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1416 |
| prop_formula_list_dot_product_interpretation_list (fm::fms,tr::trees) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1417 |
interpretation_disjunction (prop_formula_times_interpretation (fm,tr), prop_formula_list_dot_product_interpretation_list (fms,trees)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1418 |
| prop_formula_list_dot_product_interpretation_list (_,_) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1419 |
raise REFUTE ("interpretation_apply", "empty list (in dot product)") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1420 |
(* concatenates 'x' with every list in 'xss', returning a new list of lists *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1421 |
(* 'a -> 'a list list -> 'a list list *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1422 |
fun cons_list x xss = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1423 |
map (fn xs => x::xs) xss |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1424 |
(* returns a list of lists, each one consisting of one element from each element of 'xss' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1425 |
(* 'a list list -> 'a list list *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1426 |
fun pick_all [xs] = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1427 |
map (fn x => [x]) xs |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1428 |
| pick_all (xs::xss) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1429 |
let val rec_pick = pick_all xss in |
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1430 |
Library.foldl (fn (acc, x) => (cons_list x rec_pick) @ acc) ([], xs) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1431 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1432 |
| pick_all _ = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1433 |
raise REFUTE ("interpretation_apply", "empty list (in pick_all)") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1434 |
(* interpretation -> prop_formula list *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1435 |
fun interpretation_to_prop_formula_list (Leaf xs) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1436 |
xs |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1437 |
| interpretation_to_prop_formula_list (Node trees) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1438 |
map PropLogic.all (pick_all (map interpretation_to_prop_formula_list trees)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1439 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1440 |
case i1 of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1441 |
Leaf _ => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1442 |
raise REFUTE ("interpretation_apply", "first interpretation is a leaf") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1443 |
| Node xs => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1444 |
prop_formula_list_dot_product_interpretation_list (interpretation_to_prop_formula_list i2, xs) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1445 |
end; |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1446 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1447 |
(* ------------------------------------------------------------------------- *) |
15292 | 1448 |
(* eta_expand: eta-expands a term 't' by adding 'i' lambda abstractions *) |
1449 |
(* ------------------------------------------------------------------------- *) |
|
1450 |
||
1451 |
(* Term.term -> int -> Term.term *) |
|
1452 |
||
1453 |
fun eta_expand t i = |
|
1454 |
let |
|
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1455 |
val Ts = Term.binder_types (Term.fastype_of t) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1456 |
val t' = Term.incr_boundvars i t |
15292 | 1457 |
in |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1458 |
foldr (fn (T, term) => Abs ("<eta_expand>", T, term)) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1459 |
(Term.list_comb (t', map Bound (i-1 downto 0))) (List.take (Ts, i)) |
15292 | 1460 |
end; |
1461 |
||
15335
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1462 |
(* ------------------------------------------------------------------------- *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1463 |
(* sum: returns the sum of a list 'xs' of integers *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1464 |
(* ------------------------------------------------------------------------- *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1465 |
|
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1466 |
(* int list -> int *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1467 |
|
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1468 |
fun sum xs = foldl op+ 0 xs; |
15335
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1469 |
|
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1470 |
(* ------------------------------------------------------------------------- *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1471 |
(* product: returns the product of a list 'xs' of integers *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1472 |
(* ------------------------------------------------------------------------- *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1473 |
|
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1474 |
(* int list -> int *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1475 |
|
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1476 |
fun product xs = foldl op* 1 xs; |
15335
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1477 |
|
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1478 |
(* ------------------------------------------------------------------------- *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1479 |
(* size_of_dtyp: the size of (an initial fragment of) an inductive data type *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1480 |
(* is the sum (over its constructors) of the product (over *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1481 |
(* their arguments) of the size of the argument types *) |
15335
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1482 |
(* ------------------------------------------------------------------------- *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1483 |
|
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1484 |
(* theory -> (Term.typ * int) list -> DatatypeAux.descr -> (DatatypeAux.dtyp * Term.typ) list -> (string * DatatypeAux.dtyp list) list -> int *) |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1485 |
|
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1486 |
fun size_of_dtyp thy typ_sizes descr typ_assoc constructors = |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1487 |
sum (map (fn (_, dtyps) => |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1488 |
product (map (fn dtyp => |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1489 |
let |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1490 |
val T = typ_of_dtyp descr typ_assoc dtyp |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1491 |
val (i, _, _) = interpret thy (typ_sizes, []) {maxvars=0, def_eq = false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
15335
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1492 |
in |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1493 |
size_of_type i |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1494 |
end) dtyps)) constructors); |
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1495 |
|
15292 | 1496 |
|
1497 |
(* ------------------------------------------------------------------------- *) |
|
1498 |
(* INTERPRETERS: Actual Interpreters *) |
|
1499 |
(* ------------------------------------------------------------------------- *) |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1500 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1501 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1502 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1503 |
(* simply typed lambda calculus: Isabelle's basic term syntax, with type *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1504 |
(* variables, function types, and propT *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1505 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1506 |
fun stlc_interpreter thy model args t = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1507 |
let |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1508 |
val (typs, terms) = model |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1509 |
val {maxvars, def_eq, next_idx, bounds, wellformed} = args |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1510 |
(* Term.typ -> (interpretation * model * arguments) option *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1511 |
fun interpret_groundterm T = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1512 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1513 |
(* unit -> (interpretation * model * arguments) option *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1514 |
fun interpret_groundtype () = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1515 |
let |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1516 |
val size = (if T = Term.propT then 2 else (Option.valOf o AList.lookup (op =) typs) T) (* the model MUST specify a size for ground types *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1517 |
val next = next_idx+size |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1518 |
val _ = (if next-1>maxvars andalso maxvars>0 then raise MAXVARS_EXCEEDED else ()) (* check if 'maxvars' is large enough *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1519 |
(* prop_formula list *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1520 |
val fms = map BoolVar (next_idx upto (next_idx+size-1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1521 |
(* interpretation *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1522 |
val intr = Leaf fms |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1523 |
(* prop_formula list -> prop_formula *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1524 |
fun one_of_two_false [] = True |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1525 |
| one_of_two_false (x::xs) = SAnd (PropLogic.all (map (fn x' => SOr (SNot x, SNot x')) xs), one_of_two_false xs) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1526 |
(* prop_formula *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1527 |
val wf = one_of_two_false fms |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1528 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1529 |
(* extend the model, increase 'next_idx', add well-formedness condition *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1530 |
SOME (intr, (typs, (t, intr)::terms), {maxvars = maxvars, def_eq = def_eq, next_idx = next, bounds = bounds, wellformed = SAnd (wellformed, wf)}) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1531 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1532 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1533 |
case T of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1534 |
Type ("fun", [T1, T2]) => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1535 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1536 |
(* we create 'size_of_type (interpret (... T1))' different copies *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1537 |
(* of the interpretation for 'T2', which are then combined into a *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1538 |
(* single new interpretation *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1539 |
val (i1, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1540 |
(* make fresh copies, with different variable indices *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1541 |
(* 'idx': next variable index *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1542 |
(* 'n' : number of copies *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1543 |
(* int -> int -> (int * interpretation list * prop_formula *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1544 |
fun make_copies idx 0 = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1545 |
(idx, [], True) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1546 |
| make_copies idx n = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1547 |
let |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1548 |
val (copy, _, new_args) = interpret thy (typs, []) {maxvars = maxvars, def_eq = false, next_idx = idx, bounds = [], wellformed = True} (Free ("dummy", T2)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1549 |
val (idx', copies, wf') = make_copies (#next_idx new_args) (n-1) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1550 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1551 |
(idx', copy :: copies, SAnd (#wellformed new_args, wf')) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1552 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1553 |
val (next, copies, wf) = make_copies next_idx (size_of_type i1) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1554 |
(* combine copies into a single interpretation *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1555 |
val intr = Node copies |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1556 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1557 |
(* extend the model, increase 'next_idx', add well-formedness condition *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1558 |
SOME (intr, (typs, (t, intr)::terms), {maxvars = maxvars, def_eq = def_eq, next_idx = next, bounds = bounds, wellformed = SAnd (wellformed, wf)}) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1559 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1560 |
| Type _ => interpret_groundtype () |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1561 |
| TFree _ => interpret_groundtype () |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1562 |
| TVar _ => interpret_groundtype () |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1563 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1564 |
in |
17314 | 1565 |
case AList.lookup (op =) terms t of |
15531 | 1566 |
SOME intr => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1567 |
(* return an existing interpretation *) |
15531 | 1568 |
SOME (intr, model, args) |
1569 |
| NONE => |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1570 |
(case t of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1571 |
Const (_, T) => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1572 |
interpret_groundterm T |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1573 |
| Free (_, T) => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1574 |
interpret_groundterm T |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1575 |
| Var (_, T) => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1576 |
interpret_groundterm T |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1577 |
| Bound i => |
15570 | 1578 |
SOME (List.nth (#bounds args, i), model, args) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1579 |
| Abs (x, T, body) => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1580 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1581 |
(* create all constants of type 'T' *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1582 |
val (i, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1583 |
val constants = make_constants i |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1584 |
(* interpret the 'body' separately for each constant *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1585 |
val ((model', args'), bodies) = foldl_map |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1586 |
(fn ((m, a), c) => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1587 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1588 |
(* add 'c' to 'bounds' *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1589 |
val (i', m', a') = interpret thy m {maxvars = #maxvars a, def_eq = #def_eq a, next_idx = #next_idx a, bounds = (c :: #bounds a), wellformed = #wellformed a} body |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1590 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1591 |
(* keep the new model m' and 'next_idx' and 'wellformed', but use old 'bounds' *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1592 |
((m', {maxvars = maxvars, def_eq = def_eq, next_idx = #next_idx a', bounds = bounds, wellformed = #wellformed a'}), i') |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1593 |
end) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1594 |
((model, args), constants) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1595 |
in |
15531 | 1596 |
SOME (Node bodies, model', args') |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1597 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1598 |
| t1 $ t2 => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1599 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1600 |
(* interpret 't1' and 't2' separately *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1601 |
val (intr1, model1, args1) = interpret thy model args t1 |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1602 |
val (intr2, model2, args2) = interpret thy model1 args1 t2 |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1603 |
in |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1604 |
SOME (interpretation_apply (intr1, intr2), model2, args2) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1605 |
end) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1606 |
end; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1607 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1608 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1609 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1610 |
fun Pure_interpreter thy model args t = |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
1611 |
case t of |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1612 |
Const ("all", _) $ t1 => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1613 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1614 |
val (i, m, a) = interpret thy model args t1 |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1615 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1616 |
case i of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1617 |
Node xs => |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1618 |
(* 3-valued logic *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1619 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1620 |
val fmTrue = PropLogic.all (map toTrue xs) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1621 |
val fmFalse = PropLogic.exists (map toFalse xs) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1622 |
in |
15531 | 1623 |
SOME (Leaf [fmTrue, fmFalse], m, a) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1624 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1625 |
| _ => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1626 |
raise REFUTE ("Pure_interpreter", "\"all\" is not followed by a function") |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1627 |
end |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1628 |
| Const ("all", _) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1629 |
SOME (interpret thy model args (eta_expand t 1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1630 |
| Const ("==", _) $ t1 $ t2 => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1631 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1632 |
val (i1, m1, a1) = interpret thy model args t1 |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1633 |
val (i2, m2, a2) = interpret thy m1 a1 t2 |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1634 |
in |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1635 |
(* we use either 'make_def_equality' or 'make_equality' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1636 |
SOME ((if #def_eq args then make_def_equality else make_equality) (i1, i2), m2, a2) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1637 |
end |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1638 |
| Const ("==", _) $ t1 => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1639 |
SOME (interpret thy model args (eta_expand t 1)) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1640 |
| Const ("==", _) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1641 |
SOME (interpret thy model args (eta_expand t 2)) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1642 |
| Const ("==>", _) $ t1 $ t2 => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1643 |
(* 3-valued logic *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1644 |
let |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1645 |
val (i1, m1, a1) = interpret thy model args t1 |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1646 |
val (i2, m2, a2) = interpret thy m1 a1 t2 |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1647 |
val fmTrue = PropLogic.SOr (toFalse i1, toTrue i2) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1648 |
val fmFalse = PropLogic.SAnd (toTrue i1, toFalse i2) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1649 |
in |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1650 |
SOME (Leaf [fmTrue, fmFalse], m2, a2) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1651 |
end |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1652 |
| Const ("==>", _) $ t1 => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1653 |
SOME (interpret thy model args (eta_expand t 1)) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1654 |
| Const ("==>", _) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1655 |
SOME (interpret thy model args (eta_expand t 2)) |
15531 | 1656 |
| _ => NONE; |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1657 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1658 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1659 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1660 |
fun HOLogic_interpreter thy model args t = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1661 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1662 |
(* Providing interpretations directly is more efficient than unfolding the *) |
15283 | 1663 |
(* logical constants. In HOL however, logical constants can themselves be *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1664 |
(* arguments. They are then translated using eta-expansion. *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1665 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1666 |
case t of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1667 |
Const ("Trueprop", _) => |
15531 | 1668 |
SOME (Node [TT, FF], model, args) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1669 |
| Const ("Not", _) => |
15531 | 1670 |
SOME (Node [FF, TT], model, args) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1671 |
| Const ("True", _) => (* redundant, since 'True' is also an IDT constructor *) |
15531 | 1672 |
SOME (TT, model, args) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1673 |
| Const ("False", _) => (* redundant, since 'False' is also an IDT constructor *) |
15531 | 1674 |
SOME (FF, model, args) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1675 |
| Const ("All", _) $ t1 => (* similar to "all" (Pure) *) |
14350 | 1676 |
let |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1677 |
val (i, m, a) = interpret thy model args t1 |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1678 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1679 |
case i of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1680 |
Node xs => |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1681 |
(* 3-valued logic *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1682 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1683 |
val fmTrue = PropLogic.all (map toTrue xs) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1684 |
val fmFalse = PropLogic.exists (map toFalse xs) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1685 |
in |
15531 | 1686 |
SOME (Leaf [fmTrue, fmFalse], m, a) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1687 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1688 |
| _ => |
15292 | 1689 |
raise REFUTE ("HOLogic_interpreter", "\"All\" is followed by a non-function") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1690 |
end |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1691 |
| Const ("All", _) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1692 |
SOME (interpret thy model args (eta_expand t 1)) |
15333 | 1693 |
| Const ("Ex", _) $ t1 => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1694 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1695 |
val (i, m, a) = interpret thy model args t1 |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1696 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1697 |
case i of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1698 |
Node xs => |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1699 |
(* 3-valued logic *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1700 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1701 |
val fmTrue = PropLogic.exists (map toTrue xs) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1702 |
val fmFalse = PropLogic.all (map toFalse xs) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1703 |
in |
15531 | 1704 |
SOME (Leaf [fmTrue, fmFalse], m, a) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1705 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1706 |
| _ => |
15292 | 1707 |
raise REFUTE ("HOLogic_interpreter", "\"Ex\" is followed by a non-function") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1708 |
end |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1709 |
| Const ("Ex", _) => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1710 |
SOME (interpret thy model args (eta_expand t 1)) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1711 |
| Const ("op =", _) $ t1 $ t2 => (* similar to "==" (Pure) *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1712 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1713 |
val (i1, m1, a1) = interpret thy model args t1 |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1714 |
val (i2, m2, a2) = interpret thy m1 a1 t2 |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1715 |
in |
15531 | 1716 |
SOME (make_equality (i1, i2), m2, a2) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1717 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1718 |
| Const ("op =", _) $ t1 => |
15531 | 1719 |
SOME (interpret thy model args (eta_expand t 1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1720 |
| Const ("op =", _) => |
15531 | 1721 |
SOME (interpret thy model args (eta_expand t 2)) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1722 |
| Const ("op &", _) $ t1 $ t2 => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1723 |
(* 3-valued logic *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1724 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1725 |
val (i1, m1, a1) = interpret thy model args t1 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1726 |
val (i2, m2, a2) = interpret thy m1 a1 t2 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1727 |
val fmTrue = PropLogic.SAnd (toTrue i1, toTrue i2) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1728 |
val fmFalse = PropLogic.SOr (toFalse i1, toFalse i2) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1729 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1730 |
SOME (Leaf [fmTrue, fmFalse], m2, a2) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1731 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1732 |
| Const ("op &", _) $ t1 => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1733 |
SOME (interpret thy model args (eta_expand t 1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1734 |
| Const ("op &", _) => |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1735 |
SOME (interpret thy model args (eta_expand t 2)) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1736 |
(* this would make "undef" propagate, even for formulae like *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1737 |
(* "False & undef": *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1738 |
(* SOME (Node [Node [TT, FF], Node [FF, FF]], model, args) *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1739 |
| Const ("op |", _) $ t1 $ t2 => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1740 |
(* 3-valued logic *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1741 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1742 |
val (i1, m1, a1) = interpret thy model args t1 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1743 |
val (i2, m2, a2) = interpret thy m1 a1 t2 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1744 |
val fmTrue = PropLogic.SOr (toTrue i1, toTrue i2) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1745 |
val fmFalse = PropLogic.SAnd (toFalse i1, toFalse i2) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1746 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1747 |
SOME (Leaf [fmTrue, fmFalse], m2, a2) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1748 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1749 |
| Const ("op |", _) $ t1 => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1750 |
SOME (interpret thy model args (eta_expand t 1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1751 |
| Const ("op |", _) => |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1752 |
SOME (interpret thy model args (eta_expand t 2)) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1753 |
(* this would make "undef" propagate, even for formulae like *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1754 |
(* "True | undef": *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1755 |
(* SOME (Node [Node [TT, TT], Node [TT, FF]], model, args) *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1756 |
| Const ("op -->", _) $ t1 $ t2 => (* similar to "==>" (Pure) *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1757 |
(* 3-valued logic *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1758 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1759 |
val (i1, m1, a1) = interpret thy model args t1 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1760 |
val (i2, m2, a2) = interpret thy m1 a1 t2 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1761 |
val fmTrue = PropLogic.SOr (toFalse i1, toTrue i2) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1762 |
val fmFalse = PropLogic.SAnd (toTrue i1, toFalse i2) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1763 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1764 |
SOME (Leaf [fmTrue, fmFalse], m2, a2) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1765 |
end |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1766 |
| Const ("op -->", _) $ t1 => |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1767 |
SOME (interpret thy model args (eta_expand t 1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1768 |
| Const ("op -->", _) => |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1769 |
SOME (interpret thy model args (eta_expand t 2)) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1770 |
(* this would make "undef" propagate, even for formulae like *) |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1771 |
(* "False --> undef": *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1772 |
(* SOME (Node [Node [TT, FF], Node [TT, TT]], model, args) *) |
15531 | 1773 |
| _ => NONE; |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1774 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1775 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1776 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1777 |
fun set_interpreter thy model args t = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1778 |
(* "T set" is isomorphic to "T --> bool" *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1779 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1780 |
val (typs, terms) = model |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1781 |
in |
17314 | 1782 |
case AList.lookup (op =) terms t of |
15531 | 1783 |
SOME intr => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1784 |
(* return an existing interpretation *) |
15531 | 1785 |
SOME (intr, model, args) |
1786 |
| NONE => |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1787 |
(case t of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1788 |
Free (x, Type ("set", [T])) => |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
1789 |
let |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1790 |
val (intr, _, args') = interpret thy (typs, []) args (Free (x, T --> HOLogic.boolT)) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1791 |
in |
15531 | 1792 |
SOME (intr, (typs, (t, intr)::terms), args') |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
1793 |
end |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
1794 |
| Var ((x, i), Type ("set", [T])) => |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
1795 |
let |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1796 |
val (intr, _, args') = interpret thy (typs, []) args (Var ((x,i), T --> HOLogic.boolT)) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1797 |
in |
15531 | 1798 |
SOME (intr, (typs, (t, intr)::terms), args') |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
1799 |
end |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1800 |
| Const (s, Type ("set", [T])) => |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
1801 |
let |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1802 |
val (intr, _, args') = interpret thy (typs, []) args (Const (s, T --> HOLogic.boolT)) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1803 |
in |
15531 | 1804 |
SOME (intr, (typs, (t, intr)::terms), args') |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
1805 |
end |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1806 |
(* 'Collect' == identity *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1807 |
| Const ("Collect", _) $ t1 => |
15531 | 1808 |
SOME (interpret thy model args t1) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1809 |
| Const ("Collect", _) => |
15531 | 1810 |
SOME (interpret thy model args (eta_expand t 1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1811 |
(* 'op :' == application *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1812 |
| Const ("op :", _) $ t1 $ t2 => |
15531 | 1813 |
SOME (interpret thy model args (t2 $ t1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1814 |
| Const ("op :", _) $ t1 => |
15531 | 1815 |
SOME (interpret thy model args (eta_expand t 1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1816 |
| Const ("op :", _) => |
15531 | 1817 |
SOME (interpret thy model args (eta_expand t 2)) |
1818 |
| _ => NONE) |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1819 |
end; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1820 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1821 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1822 |
|
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1823 |
(* interprets variables and constants whose type is an IDT; constructors of *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1824 |
(* IDTs are properly interpreted by 'IDT_constructor_interpreter' however *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1825 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1826 |
fun IDT_interpreter thy model args t = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1827 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1828 |
val (typs, terms) = model |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1829 |
(* Term.typ -> (interpretation * model * arguments) option *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1830 |
fun interpret_term (Type (s, Ts)) = |
19346 | 1831 |
(case DatatypePackage.get_datatype thy s of |
15531 | 1832 |
SOME info => (* inductive datatype *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1833 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1834 |
(* int option -- only recursive IDTs have an associated depth *) |
17314 | 1835 |
val depth = AList.lookup (op =) typs (Type (s, Ts)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1836 |
in |
15531 | 1837 |
if depth = (SOME 0) then (* termination condition to avoid infinite recursion *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1838 |
(* return a leaf of size 0 *) |
15531 | 1839 |
SOME (Leaf [], model, args) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1840 |
else |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1841 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1842 |
val index = #index info |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1843 |
val descr = #descr info |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1844 |
val (_, dtyps, constrs) = (Option.valOf o AList.lookup (op =) descr) index |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1845 |
val typ_assoc = dtyps ~~ Ts |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1846 |
(* sanity check: every element in 'dtyps' must be a 'DtTFree' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1847 |
val _ = (if Library.exists (fn d => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1848 |
case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1849 |
then |
21992 | 1850 |
raise REFUTE ("IDT_interpreter", "datatype argument (for type " ^ Sign.string_of_typ thy (Type (s, Ts)) ^ ") is not a variable") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1851 |
else |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1852 |
()) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1853 |
(* if the model specifies a depth for the current type, decrement it to avoid infinite recursion *) |
17314 | 1854 |
val typs' = case depth of NONE => typs | SOME n => |
1855 |
AList.update (op =) (Type (s, Ts), n-1) typs |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1856 |
(* recursively compute the size of the datatype *) |
15335
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents:
15334
diff
changeset
|
1857 |
val size = size_of_dtyp thy typs' descr typ_assoc constrs |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1858 |
val next_idx = #next_idx args |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1859 |
val next = next_idx+size |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1860 |
val _ = (if next-1>(#maxvars args) andalso (#maxvars args)>0 then raise MAXVARS_EXCEEDED else ()) (* check if 'maxvars' is large enough *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1861 |
(* prop_formula list *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1862 |
val fms = map BoolVar (next_idx upto (next_idx+size-1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1863 |
(* interpretation *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1864 |
val intr = Leaf fms |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1865 |
(* prop_formula list -> prop_formula *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1866 |
fun one_of_two_false [] = True |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1867 |
| one_of_two_false (x::xs) = SAnd (PropLogic.all (map (fn x' => SOr (SNot x, SNot x')) xs), one_of_two_false xs) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1868 |
(* prop_formula *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1869 |
val wf = one_of_two_false fms |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1870 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1871 |
(* extend the model, increase 'next_idx', add well-formedness condition *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1872 |
SOME (intr, (typs, (t, intr)::terms), {maxvars = #maxvars args, def_eq = #def_eq args, next_idx = next, bounds = #bounds args, wellformed = SAnd (#wellformed args, wf)}) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1873 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1874 |
end |
15531 | 1875 |
| NONE => (* not an inductive datatype *) |
1876 |
NONE) |
|
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1877 |
| interpret_term _ = (* a (free or schematic) type variable *) |
15531 | 1878 |
NONE |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1879 |
in |
17314 | 1880 |
case AList.lookup (op =) terms t of |
15531 | 1881 |
SOME intr => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1882 |
(* return an existing interpretation *) |
15531 | 1883 |
SOME (intr, model, args) |
1884 |
| NONE => |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1885 |
(case t of |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1886 |
Free (_, T) => interpret_term T |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1887 |
| Var (_, T) => interpret_term T |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1888 |
| Const (_, T) => interpret_term T |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1889 |
| _ => NONE) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1890 |
end; |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1891 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1892 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1893 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1894 |
fun IDT_constructor_interpreter thy model args t = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1895 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1896 |
val (typs, terms) = model |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1897 |
in |
17314 | 1898 |
case AList.lookup (op =) terms t of |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1899 |
SOME intr => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1900 |
(* return an existing interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1901 |
SOME (intr, model, args) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1902 |
| NONE => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1903 |
(case t of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1904 |
Const (s, T) => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1905 |
(case body_type T of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1906 |
Type (s', Ts') => |
19346 | 1907 |
(case DatatypePackage.get_datatype thy s' of |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1908 |
SOME info => (* body type is an inductive datatype *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1909 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1910 |
val index = #index info |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1911 |
val descr = #descr info |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
1912 |
val (_, dtyps, constrs) = (Option.valOf o AList.lookup (op =) descr) index |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1913 |
val typ_assoc = dtyps ~~ Ts' |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1914 |
(* sanity check: every element in 'dtyps' must be a 'DtTFree' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1915 |
val _ = (if Library.exists (fn d => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1916 |
case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1917 |
then |
21992 | 1918 |
raise REFUTE ("IDT_constructor_interpreter", "datatype argument (for type " ^ Sign.string_of_typ thy (Type (s', Ts')) ^ ") is not a variable") |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1919 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1920 |
()) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1921 |
(* split the constructors into those occuring before/after 'Const (s, T)' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1922 |
val (constrs1, constrs2) = take_prefix (fn (cname, ctypes) => |
16935 | 1923 |
not (cname = s andalso Sign.typ_instance thy (T, |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1924 |
map (typ_of_dtyp descr typ_assoc) ctypes ---> Type (s', Ts')))) constrs |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1925 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1926 |
case constrs2 of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1927 |
[] => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1928 |
(* 'Const (s, T)' is not a constructor of this datatype *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1929 |
NONE |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1930 |
| (_, ctypes)::cs => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1931 |
let |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1932 |
(* compute the total size of the datatype (with the current depth) *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1933 |
val (i, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type (s', Ts'))) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1934 |
val total = size_of_type i |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1935 |
(* int option -- only recursive IDTs have an associated depth *) |
17314 | 1936 |
val depth = AList.lookup (op =) typs (Type (s', Ts')) |
1937 |
val typs' = (case depth of NONE => typs | SOME n => |
|
1938 |
AList.update (op =) (Type (s', Ts'), n-1) typs) |
|
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1939 |
(* returns an interpretation where everything is mapped to "undefined" *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1940 |
(* DatatypeAux.dtyp list -> interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1941 |
fun make_undef [] = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1942 |
Leaf (replicate total False) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1943 |
| make_undef (d::ds) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1944 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1945 |
(* compute the current size of the type 'd' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1946 |
val T = typ_of_dtyp descr typ_assoc d |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1947 |
val (i, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1948 |
val size = size_of_type i |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1949 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1950 |
Node (replicate size (make_undef ds)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1951 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1952 |
(* returns the interpretation for a constructor at depth 1 *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1953 |
(* int * DatatypeAux.dtyp list -> int * interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1954 |
fun make_constr (offset, []) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1955 |
if offset<total then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1956 |
(offset+1, Leaf ((replicate offset False) @ True :: (replicate (total-offset-1) False))) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1957 |
else |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1958 |
raise REFUTE ("IDT_constructor_interpreter", "offset >= total") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1959 |
| make_constr (offset, d::ds) = |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1960 |
let |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1961 |
(* compute the current and the old size of the type 'd' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1962 |
val T = typ_of_dtyp descr typ_assoc d |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1963 |
val (i, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1964 |
val size = size_of_type i |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1965 |
val (i', _, _) = interpret thy (typs', []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1966 |
val size' = size_of_type i' |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1967 |
(* sanity check *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1968 |
val _ = if size < size' then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1969 |
raise REFUTE ("IDT_constructor_interpreter", "current size is less than old size") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1970 |
else |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1971 |
() |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1972 |
(* int * interpretation list *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1973 |
val (new_offset, intrs) = foldl_map make_constr (offset, replicate size' ds) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1974 |
(* interpretation list *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1975 |
val undefs = replicate (size - size') (make_undef ds) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1976 |
in |
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1977 |
(* elements that exist at the previous depth are mapped to a defined *) |
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1978 |
(* value, while new elements are mapped to "undefined" by the *) |
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1979 |
(* recursive constructor *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1980 |
(new_offset, Node (intrs @ undefs)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1981 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1982 |
(* extends the interpretation for a constructor (both recursive *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1983 |
(* and non-recursive) obtained at depth n (n>=1) to depth n+1 *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1984 |
(* int * DatatypeAux.dtyp list * interpretation -> int * interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1985 |
fun extend_constr (offset, [], Leaf xs) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1986 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1987 |
(* returns the k-th unit vector of length n *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1988 |
(* int * int -> interpretation *) |
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
1989 |
fun unit_vector (k, n) = |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1990 |
Leaf ((replicate (k-1) False) @ (True :: (replicate (n-k) False))) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1991 |
(* int *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1992 |
val k = find_index_eq True xs |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
1993 |
in |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1994 |
if k=(~1) then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1995 |
(* if the element was mapped to "undefined" before, map it to *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1996 |
(* the value given by 'offset' now (and extend the length of *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1997 |
(* the leaf) *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1998 |
(offset+1, unit_vector (offset+1, total)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
1999 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2000 |
(* if the element was already mapped to a defined value, map it *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2001 |
(* to the same value again, just extend the length of the leaf, *) |
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
2002 |
(* do not increment the 'offset' *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2003 |
(offset, unit_vector (k+1, total)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2004 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2005 |
| extend_constr (_, [], Node _) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2006 |
raise REFUTE ("IDT_constructor_interpreter", "interpretation for constructor (with no arguments left) is a node") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2007 |
| extend_constr (offset, d::ds, Node xs) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2008 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2009 |
(* compute the size of the type 'd' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2010 |
val T = typ_of_dtyp descr typ_assoc d |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2011 |
val (i, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2012 |
val size = size_of_type i |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2013 |
(* sanity check *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2014 |
val _ = if size < length xs then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2015 |
raise REFUTE ("IDT_constructor_interpreter", "new size of type is less than old size") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2016 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2017 |
() |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2018 |
(* extend the existing interpretations *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2019 |
(* int * interpretation list *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2020 |
val (new_offset, intrs) = foldl_map (fn (off, i) => extend_constr (off, ds, i)) (offset, xs) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2021 |
(* new elements of the type 'd' are mapped to "undefined" *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2022 |
val undefs = replicate (size - length xs) (make_undef ds) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2023 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2024 |
(new_offset, Node (intrs @ undefs)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2025 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2026 |
| extend_constr (_, d::ds, Leaf _) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2027 |
raise REFUTE ("IDT_constructor_interpreter", "interpretation for constructor (with arguments left) is a leaf") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2028 |
(* returns 'true' iff the constructor has a recursive argument *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2029 |
(* DatatypeAux.dtyp list -> bool *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2030 |
fun is_rec_constr ds = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2031 |
Library.exists DatatypeAux.is_rec_type ds |
15611
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
2032 |
(* constructors before 'Const (s, T)' generate elements of the datatype *) |
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
webertj
parents:
15574
diff
changeset
|
2033 |
val offset = size_of_dtyp thy typs' descr typ_assoc constrs1 |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2034 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2035 |
case depth of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2036 |
NONE => (* equivalent to a depth of 1 *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2037 |
SOME (snd (make_constr (offset, ctypes)), model, args) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2038 |
| SOME 0 => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2039 |
raise REFUTE ("IDT_constructor_interpreter", "depth is 0") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2040 |
| SOME 1 => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2041 |
SOME (snd (make_constr (offset, ctypes)), model, args) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2042 |
| SOME n => (* n > 1 *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2043 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2044 |
(* interpret the constructor at depth-1 *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2045 |
val (iC, _, _) = interpret thy (typs', []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Const (s, T)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2046 |
(* elements generated by the constructor at depth-1 must be added to 'offset' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2047 |
(* interpretation -> int *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2048 |
fun number_of_defined_elements (Leaf xs) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2049 |
if find_index_eq True xs = (~1) then 0 else 1 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2050 |
| number_of_defined_elements (Node xs) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2051 |
sum (map number_of_defined_elements xs) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2052 |
(* int *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2053 |
val offset' = offset + number_of_defined_elements iC |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2054 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2055 |
SOME (snd (extend_constr (offset', ctypes, iC)), model, args) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2056 |
end |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2057 |
end |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2058 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2059 |
| NONE => (* body type is not an inductive datatype *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2060 |
NONE) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2061 |
| _ => (* body type is a (free or schematic) type variable *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2062 |
NONE) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2063 |
| _ => (* term is not a constant *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2064 |
NONE) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2065 |
end; |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2066 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2067 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2068 |
|
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2069 |
(* Difficult code ahead. Make sure you understand the 'IDT_constructor_interpreter' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2070 |
(* and the order in which it enumerates elements of an IDT before you try to *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2071 |
(* understand this function. *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2072 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2073 |
fun IDT_recursion_interpreter thy model args t = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2074 |
case strip_comb t of (* careful: here we descend arbitrarily deep into 't', *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2075 |
(* possibly before any other interpreter for atomic *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2076 |
(* terms has had a chance to look at 't' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2077 |
(Const (s, T), params) => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2078 |
(* iterate over all datatypes in 'thy' *) |
21056 | 2079 |
Symtab.fold (fn (_, info) => fn result => |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2080 |
case result of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2081 |
SOME _ => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2082 |
result (* just keep 'result' *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2083 |
| NONE => |
21056 | 2084 |
if member (op =) (#rec_names info) s then |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2085 |
(* we do have a recursion operator of the datatype given by 'info', *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2086 |
(* or of a mutually recursive datatype *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2087 |
let |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2088 |
val index = #index info |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2089 |
val descr = #descr info |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
2090 |
val (dtname, dtyps, _) = (Option.valOf o AList.lookup (op =) descr) index |
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
2091 |
(* number of all constructors, including those of ({({(a0, True)}, False), ({(a0, False)}, False)}, True)different *) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2092 |
(* (mutually recursive) datatypes within the same descriptor 'descr' *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2093 |
val mconstrs_count = sum (map (fn (_, (_, _, cs)) => length cs) descr) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2094 |
val params_count = length params |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2095 |
(* the type of a recursion operator: [T1, ..., Tn, IDT] ---> Tresult *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2096 |
val IDT = List.nth (binder_types T, mconstrs_count) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2097 |
in |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2098 |
if (fst o dest_Type) IDT <> dtname then |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2099 |
(* recursion operator of a mutually recursive datatype *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2100 |
NONE |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2101 |
else if mconstrs_count < params_count then |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2102 |
(* too many actual parameters; for now we'll use the *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2103 |
(* 'stlc_interpreter' to strip off one application *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2104 |
NONE |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2105 |
else if mconstrs_count > params_count then |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2106 |
(* too few actual parameters; we use eta expansion *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2107 |
(* Note that the resulting expansion of lambda abstractions *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2108 |
(* by the 'stlc_interpreter' may be rather slow (depending on *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2109 |
(* the argument types and the size of the IDT, of course). *) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2110 |
SOME (interpret thy model args (eta_expand t (mconstrs_count - params_count))) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2111 |
else (* mconstrs_count = params_count *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2112 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2113 |
(* interpret each parameter separately *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2114 |
val ((model', args'), p_intrs) = foldl_map (fn ((m, a), p) => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2115 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2116 |
val (i, m', a') = interpret thy m a p |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2117 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2118 |
((m', a'), i) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2119 |
end) ((model, args), params) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2120 |
val (typs, _) = model' |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2121 |
val typ_assoc = dtyps ~~ (snd o dest_Type) IDT |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2122 |
(* interpret each constructor in the descriptor (including *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2123 |
(* those of mutually recursive datatypes) *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2124 |
(* (int * interpretation list) list *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2125 |
val mc_intrs = map (fn (idx, (_, _, cs)) => |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2126 |
let |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2127 |
val c_return_typ = typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec idx) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2128 |
in |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2129 |
(idx, map (fn (cname, cargs) => |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2130 |
(#1 o interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True}) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2131 |
(Const (cname, map (typ_of_dtyp descr typ_assoc) cargs ---> c_return_typ))) cs) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2132 |
end) descr |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2133 |
(* the recursion operator is a function that maps every element of *) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2134 |
(* the inductive datatype (and of mutually recursive types) to an *) |
15783 | 2135 |
(* element of some result type; an array entry of NONE means that *) |
2136 |
(* the actual result has not been computed yet *) |
|
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2137 |
(* (int * interpretation option Array.array) list *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2138 |
val INTRS = map (fn (idx, _) => |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2139 |
let |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2140 |
val T = typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec idx) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2141 |
val (i, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2142 |
val size = size_of_type i |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2143 |
in |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2144 |
(idx, Array.array (size, NONE)) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2145 |
end) descr |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2146 |
(* takes an interpretation, and if some leaf of this interpretation *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2147 |
(* is the 'elem'-th element of the type, the indices of the arguments *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2148 |
(* leading to this leaf are returned *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2149 |
(* interpretation -> int -> int list option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2150 |
fun get_args (Leaf xs) elem = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2151 |
if find_index_eq True xs = elem then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2152 |
SOME [] |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2153 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2154 |
NONE |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2155 |
| get_args (Node xs) elem = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2156 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2157 |
(* interpretation * int -> int list option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2158 |
fun search ([], _) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2159 |
NONE |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2160 |
| search (x::xs, n) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2161 |
(case get_args x elem of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2162 |
SOME result => SOME (n::result) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2163 |
| NONE => search (xs, n+1)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2164 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2165 |
search (xs, 0) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2166 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2167 |
(* returns the index of the constructor and indices for its *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2168 |
(* arguments that generate the 'elem'-th element of the datatype *) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2169 |
(* given by 'idx' *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2170 |
(* int -> int -> int * int list *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2171 |
fun get_cargs idx elem = |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2172 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2173 |
(* int * interpretation list -> int * int list *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2174 |
fun get_cargs_rec (_, []) = |
21992 | 2175 |
raise REFUTE ("IDT_recursion_interpreter", "no matching constructor found for element " ^ string_of_int elem ^ " in datatype " ^ Sign.string_of_typ thy IDT ^ " (datatype index " ^ string_of_int idx ^ ")") |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2176 |
| get_cargs_rec (n, x::xs) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2177 |
(case get_args x elem of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2178 |
SOME args => (n, args) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2179 |
| NONE => get_cargs_rec (n+1, xs)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2180 |
in |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
2181 |
get_cargs_rec (0, (Option.valOf o AList.lookup (op =) mc_intrs) idx) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2182 |
end |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2183 |
(* returns the number of constructors in datatypes that occur in *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2184 |
(* the descriptor 'descr' before the datatype given by 'idx' *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2185 |
fun get_coffset idx = |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2186 |
let |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2187 |
fun get_coffset_acc _ [] = |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2188 |
raise REFUTE ("IDT_recursion_interpreter", "index " ^ string_of_int idx ^ " not found in descriptor") |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2189 |
| get_coffset_acc sum ((i, (_, _, cs))::descr') = |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2190 |
if i=idx then |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2191 |
sum |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2192 |
else |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2193 |
get_coffset_acc (sum + length cs) descr' |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2194 |
in |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2195 |
get_coffset_acc 0 descr |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2196 |
end |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2197 |
(* computes one entry in INTRS, and recursively all entries needed for it, *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2198 |
(* where 'idx' gives the datatype and 'elem' the element of it *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2199 |
(* int -> int -> interpretation *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2200 |
fun compute_array_entry idx elem = |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
2201 |
case Array.sub ((Option.valOf o AList.lookup (op =) INTRS) idx, elem) of |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2202 |
SOME result => |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2203 |
(* simply return the previously computed result *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2204 |
result |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2205 |
| NONE => |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2206 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2207 |
(* int * int list *) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2208 |
val (c, args) = get_cargs idx elem |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2209 |
(* interpretation * int list -> interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2210 |
fun select_subtree (tr, []) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2211 |
tr (* return the whole tree *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2212 |
| select_subtree (Leaf _, _) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2213 |
raise REFUTE ("IDT_recursion_interpreter", "interpretation for parameter is a leaf; cannot select a subtree") |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2214 |
| select_subtree (Node tr, x::xs) = |
15570 | 2215 |
select_subtree (List.nth (tr, x), xs) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2216 |
(* select the correct subtree of the parameter corresponding to constructor 'c' *) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2217 |
val p_intr = select_subtree (List.nth (p_intrs, get_coffset idx + c), args) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2218 |
(* find the indices of the constructor's recursive arguments *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
2219 |
val (_, _, constrs) = (Option.valOf o AList.lookup (op =) descr) idx |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2220 |
val constr_args = (snd o List.nth) (constrs, c) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2221 |
val rec_args = List.filter (DatatypeAux.is_rec_type o fst) (constr_args ~~ args) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2222 |
val rec_args' = map (fn (dtyp, elem) => (DatatypeAux.dest_DtRec dtyp, elem)) rec_args |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2223 |
(* apply 'p_intr' to recursively computed results *) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2224 |
val result = foldl (fn ((idx, elem), intr) => |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2225 |
interpretation_apply (intr, compute_array_entry idx elem)) p_intr rec_args' |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2226 |
(* update 'INTRS' *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
2227 |
val _ = Array.update ((Option.valOf o AList.lookup (op =) INTRS) idx, elem, SOME result) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2228 |
in |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2229 |
result |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2230 |
end |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2231 |
(* compute all entries in INTRS for the current datatype (given by 'index') *) |
21998 | 2232 |
val _ = Array.modifyi (fn (i, _) => SOME (compute_array_entry index i)) ((Option.valOf o AList.lookup (op =) INTRS) index) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2233 |
(* 'a Array.array -> 'a list *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2234 |
fun toList arr = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2235 |
Array.foldr op:: [] arr |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2236 |
in |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2237 |
(* return the part of 'INTRS' that corresponds to the current datatype *) |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
2238 |
SOME ((Node o map Option.valOf o toList o Option.valOf o AList.lookup (op =) INTRS) index, model', args') |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2239 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2240 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2241 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2242 |
NONE (* not a recursion operator of this datatype *) |
21056 | 2243 |
) (DatatypePackage.get_datatypes thy) NONE |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2244 |
| _ => (* head of term is not a constant *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2245 |
NONE; |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2246 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2247 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2248 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2249 |
(* only an optimization: 'card' could in principle be interpreted with *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2250 |
(* interpreters available already (using its definition), but the code *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2251 |
(* below is more efficient *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2252 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2253 |
fun Finite_Set_card_interpreter thy model args t = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2254 |
case t of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2255 |
Const ("Finite_Set.card", Type ("fun", [Type ("set", [T]), Type ("nat", [])])) => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2256 |
let |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2257 |
val (i_nat, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("nat", []))) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2258 |
val size_nat = size_of_type i_nat |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2259 |
val (i_set, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T]))) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2260 |
val constants = make_constants i_set |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2261 |
(* interpretation -> int *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2262 |
fun number_of_elements (Node xs) = |
15570 | 2263 |
Library.foldl (fn (n, x) => |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2264 |
if x=TT then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2265 |
n+1 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2266 |
else if x=FF then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2267 |
n |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2268 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2269 |
raise REFUTE ("Finite_Set_card_interpreter", "interpretation for set type does not yield a Boolean")) (0, xs) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2270 |
| number_of_elements (Leaf _) = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2271 |
raise REFUTE ("Finite_Set_card_interpreter", "interpretation for set type is a leaf") |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2272 |
(* takes an interpretation for a set and returns an interpretation for a 'nat' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2273 |
(* interpretation -> interpretation *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2274 |
fun card i = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2275 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2276 |
val n = number_of_elements i |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2277 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2278 |
if n<size_nat then |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2279 |
Leaf ((replicate n False) @ True :: (replicate (size_nat-n-1) False)) |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
2280 |
else |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2281 |
Leaf (replicate size_nat False) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2282 |
end |
14350 | 2283 |
in |
15531 | 2284 |
SOME (Node (map card constants), model, args) |
14350 | 2285 |
end |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2286 |
| _ => |
15531 | 2287 |
NONE; |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2288 |
|
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2289 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2290 |
|
15571 | 2291 |
(* only an optimization: 'Finites' could in principle be interpreted with *) |
2292 |
(* interpreters available already (using its definition), but the code *) |
|
2293 |
(* below is more efficient *) |
|
2294 |
||
2295 |
fun Finite_Set_Finites_interpreter thy model args t = |
|
2296 |
case t of |
|
2297 |
Const ("Finite_Set.Finites", Type ("set", [Type ("set", [T])])) => |
|
2298 |
let |
|
2299 |
val (i_set, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T]))) |
|
2300 |
val size_set = size_of_type i_set |
|
2301 |
in |
|
2302 |
(* we only consider finite models anyway, hence EVERY set is in "Finites" *) |
|
2303 |
SOME (Node (replicate size_set TT), model, args) |
|
2304 |
end |
|
2305 |
| _ => |
|
2306 |
NONE; |
|
2307 |
||
2308 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
|
2309 |
||
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2310 |
(* only an optimization: 'op <' could in principle be interpreted with *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2311 |
(* interpreters available already (using its definition), but the code *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2312 |
(* below is more efficient *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2313 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2314 |
fun Nat_less_interpreter thy model args t = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2315 |
case t of |
19277 | 2316 |
Const ("Orderings.less", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("bool", [])])])) => |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2317 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2318 |
val (i_nat, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("nat", []))) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2319 |
val size_nat = size_of_type i_nat |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2320 |
(* int -> interpretation *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2321 |
(* the 'n'-th nat is not less than the first 'n' nats, while it *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2322 |
(* is less than the remaining 'size_nat - n' nats *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2323 |
fun less n = Node ((replicate n FF) @ (replicate (size_nat - n) TT)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2324 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2325 |
SOME (Node (map less (1 upto size_nat)), model, args) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2326 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2327 |
| _ => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2328 |
NONE; |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2329 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2330 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2331 |
|
19233
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
haftmann
parents:
18932
diff
changeset
|
2332 |
(* only an optimization: 'HOL.plus' could in principle be interpreted with*) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2333 |
(* interpreters available already (using its definition), but the code *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2334 |
(* below is more efficient *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2335 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2336 |
fun Nat_plus_interpreter thy model args t = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2337 |
case t of |
19233
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
haftmann
parents:
18932
diff
changeset
|
2338 |
Const ("HOL.plus", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2339 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2340 |
val (i_nat, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("nat", []))) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2341 |
val size_nat = size_of_type i_nat |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2342 |
(* int -> int -> interpretation *) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2343 |
fun plus m n = |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2344 |
let |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2345 |
val element = (m+n)+1 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2346 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2347 |
if element > size_nat then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2348 |
Leaf (replicate size_nat False) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2349 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2350 |
Leaf ((replicate (element-1) False) @ True :: (replicate (size_nat - element) False)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2351 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2352 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2353 |
SOME (Node (map (fn m => Node (map (plus m) (0 upto size_nat-1))) (0 upto size_nat-1)), model, args) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2354 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2355 |
| _ => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2356 |
NONE; |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2357 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2358 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2359 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2360 |
(* only an optimization: 'op -' could in principle be interpreted with *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2361 |
(* interpreters available already (using its definition), but the code *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2362 |
(* below is more efficient *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2363 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2364 |
fun Nat_minus_interpreter thy model args t = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2365 |
case t of |
19233
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
haftmann
parents:
18932
diff
changeset
|
2366 |
Const ("HOL.minus", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2367 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2368 |
val (i_nat, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("nat", []))) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2369 |
val size_nat = size_of_type i_nat |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2370 |
(* int -> int -> interpretation *) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2371 |
fun minus m n = |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2372 |
let |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2373 |
val element = Int.max (m-n, 0) + 1 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2374 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2375 |
Leaf ((replicate (element-1) False) @ True :: (replicate (size_nat - element) False)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2376 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2377 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2378 |
SOME (Node (map (fn m => Node (map (minus m) (0 upto size_nat-1))) (0 upto size_nat-1)), model, args) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2379 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2380 |
| _ => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2381 |
NONE; |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2382 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2383 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2384 |
|
19233
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
haftmann
parents:
18932
diff
changeset
|
2385 |
(* only an optimization: 'HOL.times' could in principle be interpreted with *) |
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
haftmann
parents:
18932
diff
changeset
|
2386 |
(* interpreters available already (using its definition), but the code *) |
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
haftmann
parents:
18932
diff
changeset
|
2387 |
(* below is more efficient *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2388 |
|
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2389 |
fun Nat_mult_interpreter thy model args t = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2390 |
case t of |
19233
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
haftmann
parents:
18932
diff
changeset
|
2391 |
Const ("HOL.times", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2392 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2393 |
val (i_nat, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("nat", []))) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2394 |
val size_nat = size_of_type i_nat |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2395 |
(* nat -> nat -> interpretation *) |
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2396 |
fun mult m n = |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2397 |
let |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2398 |
val element = (m*n)+1 |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2399 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2400 |
if element > size_nat then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2401 |
Leaf (replicate size_nat False) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2402 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2403 |
Leaf ((replicate (element-1) False) @ True :: (replicate (size_nat - element) False)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2404 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2405 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2406 |
SOME (Node (map (fn m => Node (map (mult m) (0 upto size_nat-1))) (0 upto size_nat-1)), model, args) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2407 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2408 |
| _ => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2409 |
NONE; |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2410 |
|
15767
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2411 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2412 |
|
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2413 |
(* only an optimization: 'op @' could in principle be interpreted with *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2414 |
(* interpreters available already (using its definition), but the code *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2415 |
(* below is more efficient *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2416 |
|
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2417 |
fun List_append_interpreter thy model args t = |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2418 |
case t of |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2419 |
Const ("List.op @", Type ("fun", [Type ("List.list", [T]), Type ("fun", [Type ("List.list", [_]), Type ("List.list", [_])])])) => |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2420 |
let |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2421 |
val (i_elem, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2422 |
val size_elem = size_of_type i_elem |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2423 |
val (i_list, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("List.list", [T]))) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2424 |
val size_list = size_of_type i_list |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2425 |
(* power (a, b) computes a^b, for a>=0, b>=0 *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2426 |
(* int * int -> int *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2427 |
fun power (a, 0) = 1 |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2428 |
| power (a, 1) = a |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2429 |
| power (a, b) = let val ab = power(a, b div 2) in ab * ab * power(a, b mod 2) end |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2430 |
(* log (a, b) computes floor(log_a(b)), i.e. the largest integer x s.t. a^x <= b, for a>=2, b>=1 *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2431 |
(* int * int -> int *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2432 |
fun log (a, b) = |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2433 |
let |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2434 |
fun logloop (ax, x) = |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2435 |
if ax > b then x-1 else logloop (a * ax, x+1) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2436 |
in |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2437 |
logloop (1, 0) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2438 |
end |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2439 |
(* nat -> nat -> interpretation *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2440 |
fun append m n = |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2441 |
let |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2442 |
(* The following formula depends on the order in which lists are *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2443 |
(* enumerated by the 'IDT_constructor_interpreter'. It took me *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2444 |
(* a while to come up with this formula. *) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2445 |
val element = n + m * (if size_elem = 1 then 1 else power (size_elem, log (size_elem, n+1))) + 1 |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2446 |
in |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2447 |
if element > size_list then |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2448 |
Leaf (replicate size_list False) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2449 |
else |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2450 |
Leaf ((replicate (element-1) False) @ True :: (replicate (size_list - element) False)) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2451 |
end |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2452 |
in |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2453 |
SOME (Node (map (fn m => Node (map (append m) (0 upto size_list-1))) (0 upto size_list-1)), model, args) |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2454 |
end |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2455 |
| _ => |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2456 |
NONE; |
8ed9fcc004fe
support for recursion over mutually recursive IDTs
webertj
parents:
15611
diff
changeset
|
2457 |
|
16050 | 2458 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
2459 |
||
2460 |
(* only an optimization: 'lfp' could in principle be interpreted with *) |
|
2461 |
(* interpreters available already (using its definition), but the code *) |
|
2462 |
(* below is more efficient *) |
|
2463 |
||
2464 |
fun Lfp_lfp_interpreter thy model args t = |
|
2465 |
case t of |
|
2466 |
Const ("Lfp.lfp", Type ("fun", [Type ("fun", [Type ("set", [T]), Type ("set", [_])]), Type ("set", [_])])) => |
|
2467 |
let |
|
2468 |
val (i_elem, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
|
2469 |
val size_elem = size_of_type i_elem |
|
2470 |
(* the universe (i.e. the set that contains every element) *) |
|
2471 |
val i_univ = Node (replicate size_elem TT) |
|
2472 |
(* all sets with elements from type 'T' *) |
|
2473 |
val (i_set, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T]))) |
|
2474 |
val i_sets = make_constants i_set |
|
2475 |
(* all functions that map sets to sets *) |
|
2476 |
val (i_fun, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("fun", [Type ("set", [T]), Type ("set", [T])]))) |
|
2477 |
val i_funs = make_constants i_fun |
|
2478 |
(* "lfp(f) == Inter({u. f(u) <= u})" *) |
|
2479 |
(* interpretation * interpretation -> bool *) |
|
2480 |
fun is_subset (Node subs, Node sups) = |
|
2481 |
List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) (subs ~~ sups) |
|
2482 |
| is_subset (_, _) = |
|
2483 |
raise REFUTE ("Lfp_lfp_interpreter", "is_subset: interpretation for set is not a node") |
|
2484 |
(* interpretation * interpretation -> interpretation *) |
|
2485 |
fun intersection (Node xs, Node ys) = |
|
2486 |
Node (map (fn (x, y) => if (x = TT) andalso (y = TT) then TT else FF) (xs ~~ ys)) |
|
2487 |
| intersection (_, _) = |
|
2488 |
raise REFUTE ("Lfp_lfp_interpreter", "intersection: interpretation for set is not a node") |
|
2489 |
(* interpretation -> interpretaion *) |
|
2490 |
fun lfp (Node resultsets) = |
|
2491 |
foldl (fn ((set, resultset), acc) => |
|
2492 |
if is_subset (resultset, set) then |
|
2493 |
intersection (acc, set) |
|
2494 |
else |
|
2495 |
acc) i_univ (i_sets ~~ resultsets) |
|
2496 |
| lfp _ = |
|
2497 |
raise REFUTE ("Lfp_lfp_interpreter", "lfp: interpretation for function is not a node") |
|
2498 |
in |
|
2499 |
SOME (Node (map lfp i_funs), model, args) |
|
2500 |
end |
|
2501 |
| _ => |
|
2502 |
NONE; |
|
2503 |
||
2504 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
|
2505 |
||
2506 |
(* only an optimization: 'gfp' could in principle be interpreted with *) |
|
2507 |
(* interpreters available already (using its definition), but the code *) |
|
2508 |
(* below is more efficient *) |
|
2509 |
||
2510 |
fun Gfp_gfp_interpreter thy model args t = |
|
2511 |
case t of |
|
2512 |
Const ("Gfp.gfp", Type ("fun", [Type ("fun", [Type ("set", [T]), Type ("set", [_])]), Type ("set", [_])])) => |
|
16073 | 2513 |
let nonfix union (*because "union" is used below*) |
16050 | 2514 |
val (i_elem, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
2515 |
val size_elem = size_of_type i_elem |
|
2516 |
(* the universe (i.e. the set that contains every element) *) |
|
2517 |
val i_univ = Node (replicate size_elem TT) |
|
2518 |
(* all sets with elements from type 'T' *) |
|
2519 |
val (i_set, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T]))) |
|
2520 |
val i_sets = make_constants i_set |
|
2521 |
(* all functions that map sets to sets *) |
|
2522 |
val (i_fun, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("fun", [Type ("set", [T]), Type ("set", [T])]))) |
|
2523 |
val i_funs = make_constants i_fun |
|
2524 |
(* "gfp(f) == Union({u. u <= f(u)})" *) |
|
2525 |
(* interpretation * interpretation -> bool *) |
|
2526 |
fun is_subset (Node subs, Node sups) = |
|
2527 |
List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) (subs ~~ sups) |
|
2528 |
| is_subset (_, _) = |
|
2529 |
raise REFUTE ("Gfp_gfp_interpreter", "is_subset: interpretation for set is not a node") |
|
2530 |
(* interpretation * interpretation -> interpretation *) |
|
2531 |
fun union (Node xs, Node ys) = |
|
16073 | 2532 |
Node (map (fn (x,y) => if x=TT orelse y=TT then TT else FF) |
2533 |
(xs ~~ ys)) |
|
16050 | 2534 |
| union (_, _) = |
16200 | 2535 |
raise REFUTE ("Gfp_gfp_interpreter", "union: interpretation for set is not a node") |
16050 | 2536 |
(* interpretation -> interpretaion *) |
2537 |
fun gfp (Node resultsets) = |
|
2538 |
foldl (fn ((set, resultset), acc) => |
|
16073 | 2539 |
if is_subset (set, resultset) then union (acc, set) |
2540 |
else acc) |
|
2541 |
i_univ (i_sets ~~ resultsets) |
|
16050 | 2542 |
| gfp _ = |
2543 |
raise REFUTE ("Gfp_gfp_interpreter", "gfp: interpretation for function is not a node") |
|
2544 |
in |
|
2545 |
SOME (Node (map gfp i_funs), model, args) |
|
2546 |
end |
|
2547 |
| _ => |
|
2548 |
NONE; |
|
2549 |
||
21267 | 2550 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
2551 |
||
2552 |
(* only an optimization: 'fst' could in principle be interpreted with *) |
|
2553 |
(* interpreters available already (using its definition), but the code *) |
|
2554 |
(* below is more efficient *) |
|
2555 |
||
2556 |
fun Product_Type_fst_interpreter thy model args t = |
|
2557 |
case t of |
|
2558 |
Const ("fst", Type ("fun", [Type ("*", [T, U]), _])) => |
|
2559 |
let |
|
2560 |
val (iT, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
|
2561 |
val is_T = make_constants iT |
|
2562 |
val (iU, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", U)) |
|
2563 |
val size_U = size_of_type iU |
|
2564 |
in |
|
2565 |
SOME (Node (List.concat (map (replicate size_U) is_T)), model, args) |
|
2566 |
end |
|
2567 |
| _ => |
|
2568 |
NONE; |
|
2569 |
||
2570 |
(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) |
|
2571 |
||
2572 |
(* only an optimization: 'snd' could in principle be interpreted with *) |
|
2573 |
(* interpreters available already (using its definition), but the code *) |
|
2574 |
(* below is more efficient *) |
|
2575 |
||
2576 |
fun Product_Type_snd_interpreter thy model args t = |
|
2577 |
case t of |
|
2578 |
Const ("snd", Type ("fun", [Type ("*", [T, U]), _])) => |
|
2579 |
let |
|
2580 |
val (iT, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
|
2581 |
val size_T = size_of_type iT |
|
2582 |
val (iU, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", U)) |
|
2583 |
val is_U = make_constants iU |
|
2584 |
in |
|
2585 |
SOME (Node (List.concat (replicate size_T is_U)), model, args) |
|
2586 |
end |
|
2587 |
| _ => |
|
2588 |
NONE; |
|
2589 |
||
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2590 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2591 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2592 |
(* PRINTERS *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2593 |
(* ------------------------------------------------------------------------- *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2594 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2595 |
(* theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2596 |
|
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2597 |
fun stlc_printer thy model t intr assignment = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2598 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2599 |
(* Term.term -> Term.typ option *) |
15531 | 2600 |
fun typeof (Free (_, T)) = SOME T |
2601 |
| typeof (Var (_, T)) = SOME T |
|
2602 |
| typeof (Const (_, T)) = SOME T |
|
2603 |
| typeof _ = NONE |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2604 |
(* string -> string *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2605 |
fun strip_leading_quote s = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2606 |
(implode o (fn ss => case ss of [] => [] | x::xs => if x="'" then xs else ss) o explode) s |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2607 |
(* Term.typ -> string *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2608 |
fun string_of_typ (Type (s, _)) = s |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2609 |
| string_of_typ (TFree (x, _)) = strip_leading_quote x |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2610 |
| string_of_typ (TVar ((x,i), _)) = strip_leading_quote x ^ string_of_int i |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2611 |
(* interpretation -> int *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2612 |
fun index_from_interpretation (Leaf xs) = |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2613 |
find_index (PropLogic.eval assignment) xs |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2614 |
| index_from_interpretation _ = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2615 |
raise REFUTE ("stlc_printer", "interpretation for ground type is not a leaf") |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2616 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2617 |
case typeof t of |
15531 | 2618 |
SOME T => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2619 |
(case T of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2620 |
Type ("fun", [T1, T2]) => |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
2621 |
let |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2622 |
(* create all constants of type 'T1' *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2623 |
val (i, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T1)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2624 |
val constants = make_constants i |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2625 |
(* interpretation list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2626 |
val results = (case intr of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2627 |
Node xs => xs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2628 |
| _ => raise REFUTE ("stlc_printer", "interpretation for function type is a leaf")) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2629 |
(* Term.term list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2630 |
val pairs = map (fn (arg, result) => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2631 |
HOLogic.mk_prod |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2632 |
(print thy model (Free ("dummy", T1)) arg assignment, |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2633 |
print thy model (Free ("dummy", T2)) result assignment)) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2634 |
(constants ~~ results) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2635 |
(* Term.typ *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2636 |
val HOLogic_prodT = HOLogic.mk_prodT (T1, T2) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2637 |
val HOLogic_setT = HOLogic.mk_setT HOLogic_prodT |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2638 |
(* Term.term *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2639 |
val HOLogic_empty_set = Const ("{}", HOLogic_setT) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2640 |
val HOLogic_insert = Const ("insert", HOLogic_prodT --> HOLogic_setT --> HOLogic_setT) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2641 |
in |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15571
diff
changeset
|
2642 |
SOME (foldr (fn (pair, acc) => HOLogic_insert $ pair $ acc) HOLogic_empty_set pairs) |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
2643 |
end |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2644 |
| Type ("prop", []) => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2645 |
(case index_from_interpretation intr of |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2646 |
(~1) => SOME (HOLogic.mk_Trueprop (Const ("arbitrary", HOLogic.boolT))) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2647 |
| 0 => SOME (HOLogic.mk_Trueprop HOLogic.true_const) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2648 |
| 1 => SOME (HOLogic.mk_Trueprop HOLogic.false_const) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2649 |
| _ => raise REFUTE ("stlc_interpreter", "illegal interpretation for a propositional value")) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2650 |
| Type _ => if index_from_interpretation intr = (~1) then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2651 |
SOME (Const ("arbitrary", T)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2652 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2653 |
SOME (Const (string_of_typ T ^ string_of_int (index_from_interpretation intr), T)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2654 |
| TFree _ => if index_from_interpretation intr = (~1) then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2655 |
SOME (Const ("arbitrary", T)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2656 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2657 |
SOME (Const (string_of_typ T ^ string_of_int (index_from_interpretation intr), T)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2658 |
| TVar _ => if index_from_interpretation intr = (~1) then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2659 |
SOME (Const ("arbitrary", T)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2660 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2661 |
SOME (Const (string_of_typ T ^ string_of_int (index_from_interpretation intr), T))) |
15531 | 2662 |
| NONE => |
2663 |
NONE |
|
14350 | 2664 |
end; |
2665 |
||
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
2666 |
(* theory -> model -> Term.term -> interpretation -> (int -> bool) -> string option *) |
14350 | 2667 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2668 |
fun set_printer thy model t intr assignment = |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2669 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2670 |
(* Term.term -> Term.typ option *) |
15531 | 2671 |
fun typeof (Free (_, T)) = SOME T |
2672 |
| typeof (Var (_, T)) = SOME T |
|
2673 |
| typeof (Const (_, T)) = SOME T |
|
2674 |
| typeof _ = NONE |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2675 |
in |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2676 |
case typeof t of |
15531 | 2677 |
SOME (Type ("set", [T])) => |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
2678 |
let |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2679 |
(* create all constants of type 'T' *) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2680 |
val (i, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T)) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2681 |
val constants = make_constants i |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2682 |
(* interpretation list *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2683 |
val results = (case intr of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2684 |
Node xs => xs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2685 |
| _ => raise REFUTE ("set_printer", "interpretation for set type is a leaf")) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2686 |
(* Term.term list *) |
15570 | 2687 |
val elements = List.mapPartial (fn (arg, result) => |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2688 |
case result of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2689 |
Leaf [fmTrue, fmFalse] => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2690 |
if PropLogic.eval assignment fmTrue then |
15531 | 2691 |
SOME (print thy model (Free ("dummy", T)) arg assignment) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2692 |
else (*if PropLogic.eval assignment fmFalse then*) |
15531 | 2693 |
NONE |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2694 |
| _ => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2695 |
raise REFUTE ("set_printer", "illegal interpretation for a Boolean value")) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2696 |
(constants ~~ results) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2697 |
(* Term.typ *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2698 |
val HOLogic_setT = HOLogic.mk_setT T |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2699 |
(* Term.term *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2700 |
val HOLogic_empty_set = Const ("{}", HOLogic_setT) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2701 |
val HOLogic_insert = Const ("insert", T --> HOLogic_setT --> HOLogic_setT) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2702 |
in |
15570 | 2703 |
SOME (Library.foldl (fn (acc, elem) => HOLogic_insert $ elem $ acc) (HOLogic_empty_set, elements)) |
15334
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents:
15333
diff
changeset
|
2704 |
end |
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
2705 |
| _ => |
15531 | 2706 |
NONE |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2707 |
end; |
14350 | 2708 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2709 |
(* theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option *) |
14350 | 2710 |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2711 |
fun IDT_printer thy model t intr assignment = |
14350 | 2712 |
let |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2713 |
(* Term.term -> Term.typ option *) |
15531 | 2714 |
fun typeof (Free (_, T)) = SOME T |
2715 |
| typeof (Var (_, T)) = SOME T |
|
2716 |
| typeof (Const (_, T)) = SOME T |
|
2717 |
| typeof _ = NONE |
|
14350 | 2718 |
in |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2719 |
case typeof t of |
15531 | 2720 |
SOME (Type (s, Ts)) => |
19346 | 2721 |
(case DatatypePackage.get_datatype thy s of |
15531 | 2722 |
SOME info => (* inductive datatype *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2723 |
let |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2724 |
val (typs, _) = model |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2725 |
val index = #index info |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2726 |
val descr = #descr info |
21985
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
webertj
parents:
21931
diff
changeset
|
2727 |
val (_, dtyps, constrs) = (Option.valOf o AList.lookup (op =) descr) index |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2728 |
val typ_assoc = dtyps ~~ Ts |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2729 |
(* sanity check: every element in 'dtyps' must be a 'DtTFree' *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2730 |
val _ = (if Library.exists (fn d => |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2731 |
case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2732 |
then |
21992 | 2733 |
raise REFUTE ("IDT_printer", "datatype argument (for type " ^ Sign.string_of_typ thy (Type (s, Ts)) ^ ") is not a variable") |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2734 |
else |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2735 |
()) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2736 |
(* the index of the element in the datatype *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2737 |
val element = (case intr of |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2738 |
Leaf xs => find_index (PropLogic.eval assignment) xs |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2739 |
| Node _ => raise REFUTE ("IDT_printer", "interpretation is not a leaf")) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2740 |
in |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2741 |
if element < 0 then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2742 |
SOME (Const ("arbitrary", Type (s, Ts))) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2743 |
else let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2744 |
(* takes a datatype constructor, and if for some arguments this constructor *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2745 |
(* generates the datatype's element that is given by 'element', returns the *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2746 |
(* constructor (as a term) as well as the indices of the arguments *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2747 |
(* string * DatatypeAux.dtyp list -> (Term.term * int list) option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2748 |
fun get_constr_args (cname, cargs) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2749 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2750 |
val cTerm = Const (cname, (map (typ_of_dtyp descr typ_assoc) cargs) ---> Type (s, Ts)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2751 |
val (iC, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} cTerm |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2752 |
(* interpretation -> int list option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2753 |
fun get_args (Leaf xs) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2754 |
if find_index_eq True xs = element then |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2755 |
SOME [] |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2756 |
else |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2757 |
NONE |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2758 |
| get_args (Node xs) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2759 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2760 |
(* interpretation * int -> int list option *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2761 |
fun search ([], _) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2762 |
NONE |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2763 |
| search (x::xs, n) = |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2764 |
(case get_args x of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2765 |
SOME result => SOME (n::result) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2766 |
| NONE => search (xs, n+1)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2767 |
in |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2768 |
search (xs, 0) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2769 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2770 |
in |
15570 | 2771 |
Option.map (fn args => (cTerm, cargs, args)) (get_args iC) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2772 |
end |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2773 |
(* Term.term * DatatypeAux.dtyp list * int list *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2774 |
val (cTerm, cargs, args) = (case get_first get_constr_args constrs of |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2775 |
SOME x => x |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2776 |
| NONE => raise REFUTE ("IDT_printer", "no matching constructor found for element " ^ string_of_int element)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2777 |
val argsTerms = map (fn (d, n) => |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2778 |
let |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2779 |
val dT = typ_of_dtyp descr typ_assoc d |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2780 |
val (i, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", dT)) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2781 |
val consts = make_constants i (* we only need the n-th element of this *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2782 |
(* list, so there might be a more efficient implementation that does *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2783 |
(* not generate all constants *) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2784 |
in |
15570 | 2785 |
print thy (typs, []) (Free ("dummy", dT)) (List.nth (consts, n)) assignment |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2786 |
end) (cargs ~~ args) |
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2787 |
in |
15570 | 2788 |
SOME (Library.foldl op$ (cTerm, argsTerms)) |
15547
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents:
15531
diff
changeset
|
2789 |
end |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2790 |
end |
15531 | 2791 |
| NONE => (* not an inductive datatype *) |
2792 |
NONE) |
|
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2793 |
| _ => (* a (free or schematic) type variable *) |
15531 | 2794 |
NONE |
14350 | 2795 |
end; |
2796 |
||
2797 |
||
2798 |
(* ------------------------------------------------------------------------- *) |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
2799 |
(* use 'setup Refute.setup' in an Isabelle theory to initialize the 'Refute' *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
2800 |
(* structure *) |
14350 | 2801 |
(* ------------------------------------------------------------------------- *) |
2802 |
||
2803 |
(* ------------------------------------------------------------------------- *) |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
2804 |
(* Note: the interpreters and printers are used in reverse order; however, *) |
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
2805 |
(* an interpreter that can handle non-atomic terms ends up being *) |
14807
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2806 |
(* applied before the 'stlc_interpreter' breaks the term apart into *) |
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents:
14604
diff
changeset
|
2807 |
(* subterms that are then passed to other interpreters! *) |
14350 | 2808 |
(* ------------------------------------------------------------------------- *) |
2809 |
||
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
2810 |
(* (theory -> theory) list *) |
14350 | 2811 |
|
14456
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents:
14351
diff
changeset
|
2812 |
val setup = |
18708 | 2813 |
RefuteData.init #> |
2814 |
add_interpreter "stlc" stlc_interpreter #> |
|
2815 |
add_interpreter "Pure" Pure_interpreter #> |
|
2816 |
add_interpreter "HOLogic" HOLogic_interpreter #> |
|
2817 |
add_interpreter "set" set_interpreter #> |
|
2818 |
add_interpreter "IDT" IDT_interpreter #> |
|
2819 |
add_interpreter "IDT_constructor" IDT_constructor_interpreter #> |
|
2820 |
add_interpreter "IDT_recursion" IDT_recursion_interpreter #> |
|
2821 |
add_interpreter "Finite_Set.card" Finite_Set_card_interpreter #> |
|
2822 |
add_interpreter "Finite_Set.Finites" Finite_Set_Finites_interpreter #> |
|
2823 |
add_interpreter "Nat.op <" Nat_less_interpreter #> |
|
2824 |
add_interpreter "Nat.op +" Nat_plus_interpreter #> |
|
2825 |
add_interpreter "Nat.op -" Nat_minus_interpreter #> |
|
2826 |
add_interpreter "Nat.op *" Nat_mult_interpreter #> |
|
2827 |
add_interpreter "List.op @" List_append_interpreter #> |
|
2828 |
add_interpreter "Lfp.lfp" Lfp_lfp_interpreter #> |
|
2829 |
add_interpreter "Gfp.gfp" Gfp_gfp_interpreter #> |
|
21267 | 2830 |
add_interpreter "fst" Product_Type_fst_interpreter #> |
2831 |
add_interpreter "snd" Product_Type_snd_interpreter #> |
|
18708 | 2832 |
add_printer "stlc" stlc_printer #> |
2833 |
add_printer "set" set_printer #> |
|
2834 |
add_printer "IDT" IDT_printer; |
|
14350 | 2835 |
|
2836 |
end |