| author | wenzelm | 
| Tue, 11 Apr 2006 16:00:03 +0200 | |
| changeset 19407 | 7c7a2e337504 | 
| parent 19346 | c4c003abd830 | 
| child 19642 | ea7162f84677 | 
| permissions | -rw-r--r-- | 
| 14350 | 1 | (* Title: HOL/Tools/refute.ML | 
| 2 | ID: $Id$ | |
| 3 | Author: Tjark Weber | |
| 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: 
15531diff
changeset | 4 | Copyright 2003-2005 | 
| 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: 
14351diff
changeset | 9 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
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: 
14351diff
changeset | 17 | exception REFUTE of string * string | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 18 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
changeset | 20 | (* Model/interpretation related code (translation HOL -> propositional logic *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 21 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
changeset | 23 | type params | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 24 | type interpretation | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 25 | type model | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 26 | type arguments | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
changeset | 28 | exception MAXVARS_EXCEEDED | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
14604diff
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: 
14351diff
changeset | 32 | |
| 15334 
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
 webertj parents: 
15333diff
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: 
14604diff
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: 
14604diff
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: 
14351diff
changeset | 36 | val print_model : theory -> model -> (int -> bool) -> string | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 37 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 38 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 39 | (* Interface *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 40 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 41 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 42 | val set_default_param : (string * string) -> theory -> theory | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 43 | val get_default_param : theory -> string -> string option | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
changeset | 45 | val actual_params : theory -> (string * string) list -> params | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
14351diff
changeset | 48 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
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: 
14351diff
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: 
14351diff
changeset | 52 | |
| 18708 | 53 | val setup : theory -> theory | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 54 | end; | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 55 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 56 | structure Refute : REFUTE = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 57 | struct | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 58 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 59 | open PropLogic; | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
15574diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
changeset | 146 | (* ------------------------------------------------------------------------- *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 148 | (* 'interpretation' *) | 
| 14350 | 149 | (* ------------------------------------------------------------------------- *) | 
| 150 | ||
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 151 | type interpretation = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 152 | prop_formula list tree; | 
| 14350 | 153 | |
| 154 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 156 | (* terms *) | 
| 14350 | 157 | (* ------------------------------------------------------------------------- *) | 
| 158 | ||
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 159 | type model = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 162 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 163 | (* arguments: additional arguments required during interpretation of terms *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
changeset | 165 | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
15531diff
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: 
15531diff
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: 
15531diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
changeset | 174 | }; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 175 | |
| 14350 | 176 | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 177 | structure RefuteDataArgs = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 178 | struct | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 179 | val name = "HOL/refute"; | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 180 | type T = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
14351diff
changeset | 183 | parameters: string Symtab.table}; | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 184 | 		val empty = {interpreters = [], printers = [], parameters = Symtab.empty};
 | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 188 | 			({interpreters = in1, printers = pr1, parameters = pa1},
 | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 189 | 			 {interpreters = in2, printers = pr2, parameters = pa2}) =
 | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 190 | 			{interpreters = rev (merge_alists (rev in1) (rev in2)),
 | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 191 | printers = rev (merge_alists (rev pr1) (rev pr2)), | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 192 | parameters = Symtab.merge (op=) (pa1, pa2)}; | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 193 | 		fun print sg {interpreters, printers, parameters} =
 | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 194 | Pretty.writeln (Pretty.chunks | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
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: 
14351diff
changeset | 196 | 				 Pretty.strs ("interpreters:" :: map fst interpreters),
 | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 197 | 				 Pretty.strs ("printers:" :: map fst printers)]);
 | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 198 | end; | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 199 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 200 | structure RefuteData = TheoryDataFun(RefuteDataArgs); | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 201 | |
| 14350 | 202 | |
| 203 | (* ------------------------------------------------------------------------- *) | |
| 15334 
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
 webertj parents: 
15333diff
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: 
15333diff
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: 
15333diff
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: 
14604diff
changeset | 209 | (* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 210 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 211 | fun interpret thy model args t = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 212 | (case get_first (fn (_, f) => f thy model args t) (#interpreters (RefuteData.get thy)) 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: 
15531diff
changeset | 213 | 		  NONE   => raise REFUTE ("interpret", "no interpreter for term " ^ quote (Sign.string_of_term (sign_of thy) t))
 | 
| 15531 | 214 | | SOME x => x); | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 215 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
15531diff
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: 
15531diff
changeset | 218 | (* suitable printer *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
14351diff
changeset | 222 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 223 | fun print thy model t intr assignment = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 224 | (case get_first (fn (_, f) => f thy model t intr assignment) (#printers (RefuteData.get thy)) 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: 
15531diff
changeset | 225 | 		  NONE   => raise REFUTE ("print", "no printer for term " ^ quote (Sign.string_of_term (sign_of thy) t))
 | 
| 15531 | 226 | | SOME x => x); | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 227 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 228 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
14351diff
changeset | 231 | (* printers *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 232 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
14604diff
changeset | 235 | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 236 | fun print_model thy model assignment = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 237 | let | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
changeset | 242 | else | 
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 243 | "Size of types: " ^ commas (map (fn (T, i) => Sign.string_of_typ (sign_of 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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
changeset | 252 | else | 
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
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: 
14604diff
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: 
14604diff
changeset | 255 | if (!show_consts) orelse not (is_Const t) then | 
| 15531 | 256 | SOME (Sign.string_of_term (sign_of thy) t ^ ": " ^ Sign.string_of_term (sign_of 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: 
14604diff
changeset | 257 | else | 
| 15531 | 258 | NONE) terms) ^ "\n" | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
changeset | 260 | typs_msg ^ show_consts_msg ^ terms_msg | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 261 | end; | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 262 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 263 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 264 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 265 | (* PARAMETER MANAGEMENT *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 266 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 267 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 269 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 270 | fun add_interpreter name f thy = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 271 | let | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 272 | 		val {interpreters, printers, parameters} = RefuteData.get thy
 | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 277 | end; | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
14351diff
changeset | 280 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 281 | fun add_printer name f thy = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 282 | let | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 283 | 		val {interpreters, printers, parameters} = RefuteData.get thy
 | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 288 | end; | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 289 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 290 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 292 | (* parameter table *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 293 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 294 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 295 | (* (string * string) -> theory -> theory *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 296 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 297 | fun set_default_param (name, value) thy = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 298 | let | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 299 | 		val {interpreters, printers, parameters} = RefuteData.get thy
 | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
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: 
14351diff
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: 
14351diff
changeset | 310 | (* RefuteData's parameter table *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 311 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 312 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 313 | (* theory -> string -> string option *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 316 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 317 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 319 | (* stored in RefuteData's parameter table *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 320 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 321 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 322 | (* theory -> (string * string) list *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 325 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 326 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
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: 
14604diff
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: 
14351diff
changeset | 330 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
changeset | 332 | (* theory -> (string * string) list -> params *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
changeset | 334 | fun actual_params thy override = | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 335 | let | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 336 | (* (string * string) list * string -> int *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 340 | SOME i => i | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
changeset | 343 | (* (string * string) list * string -> string *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14351diff
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: 
14604diff
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: 
14351diff
changeset | 350 | (* int *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 351 | val minsize = read_int (allparams, "minsize") | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 352 | val maxsize = read_int (allparams, "maxsize") | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 353 | val maxvars = read_int (allparams, "maxvars") | 
| 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: 
14604diff
changeset | 354 | val maxtime = read_int (allparams, "maxtime") | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 355 | (* string *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
changeset | 365 | allparams) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
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: 
14604diff
changeset | 375 | (* ------------------------------------------------------------------------- *) | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
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: 
15334diff
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: 
15334diff
changeset | 378 | (* arguments *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 379 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 380 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
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: 
15334diff
changeset | 382 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 383 | fun typ_of_dtyp descr typ_assoc (DatatypeAux.DtTFree a) = | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 384 | (* replace a 'DtTFree' variable by the associated type *) | 
| 17314 | 385 | (the 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: 
15531diff
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: 
15531diff
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: 
15334diff
changeset | 388 | | typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec i) = | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 389 | let | 
| 17314 | 390 | val (s, ds, _) = (the o AList.lookup (op =) descr) i | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 391 | in | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
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: 
15531diff
changeset | 393 | end; | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 394 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 395 | (* ------------------------------------------------------------------------- *) | 
| 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: 
14604diff
changeset | 396 | (* collect_axioms: collects (monomorphic, universally quantified versions *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 397 | (* of) all HOL axioms that are relevant w.r.t '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: 
14604diff
changeset | 398 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 399 | |
| 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: 
15531diff
changeset | 400 | (* 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: 
14604diff
changeset | 401 | (* 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: 
14604diff
changeset | 402 | (* 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: 
14604diff
changeset | 403 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 404 | (* 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: 
14604diff
changeset | 405 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 406 | (* 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: 
14604diff
changeset | 407 | (* 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: 
14604diff
changeset | 408 | (* 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: 
14604diff
changeset | 409 | (* 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: 
14604diff
changeset | 410 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 411 | (* When an axiom is added as relevant, further axioms may need to 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: 
14604diff
changeset | 412 | (* added as well (e.g. when a constant is defined in terms of other *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 413 | (* constants). To avoid infinite recursion (which should not happen 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: 
14604diff
changeset | 414 | (* constants anyway, but it could happen for "typedef"-related axioms, *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 415 | (* since they contain the type again), we use an accumulator 'axs' 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: 
14604diff
changeset | 416 | (* add a relevant axiom only if it is not in 'axs' yet. *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 417 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 418 | 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: 
14604diff
changeset | 419 | let | 
| 14984 | 420 | 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: 
14604diff
changeset | 421 | (* (string * Term.term) list *) | 
| 16331 | 422 | val axioms = Theory.all_axioms_of thy; | 
| 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: 
15531diff
changeset | 423 | (* string 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: 
15531diff
changeset | 424 | val rec_names = Symtab.foldl (fn (acc, (_, 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: 
15531diff
changeset | 425 | #rec_names info @ acc) ([], DatatypePackage.get_datatypes thy) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 426 | (* string list *) | 
| 18932 | 427 | val const_of_class_names = map Logic.const_of_class (Sign.classes (sign_of thy)) | 
| 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: 
14604diff
changeset | 428 | (* given a constant 's' of type 'T', which is a subterm of 't', where *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 429 | (* 't' has a (possibly) more general type, the schematic type *) | 
| 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: 
15531diff
changeset | 430 | (* variables in 't' are instantiated to match the type 'T' (may raise *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 431 | (* Type.TYPE_MATCH) *) | 
| 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: 
14604diff
changeset | 432 | (* (string * Term.typ) * Term.term -> 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: 
14604diff
changeset | 433 | fun specialize_type ((s, T), 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: 
14604diff
changeset | 434 | 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: 
14604diff
changeset | 435 | fun find_typeSubs (Const (s', 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: 
14604diff
changeset | 436 | (if s=s' then | 
| 16935 | 437 | SOME (Sign.typ_match thy (T', T) Vartab.empty) handle Type.TYPE_MATCH => 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: 
14604diff
changeset | 438 | 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: 
15531diff
changeset | 439 | NONE) | 
| 15531 | 440 | | find_typeSubs (Free _) = NONE | 
| 441 | | find_typeSubs (Var _) = NONE | |
| 442 | | find_typeSubs (Bound _) = 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: 
14604diff
changeset | 443 | | find_typeSubs (Abs (_, _, body)) = find_typeSubs body | 
| 15531 | 444 | | find_typeSubs (t1 $ t2) = (case find_typeSubs t1 of SOME x => SOME x | NONE => find_typeSubs 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: 
14604diff
changeset | 445 | val typeSubs = (case find_typeSubs t of | 
| 15531 | 446 | SOME x => 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: 
15531diff
changeset | 447 | | NONE => raise Type.TYPE_MATCH (* no match found - perhaps due to sort constraints *)) | 
| 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: 
14604diff
changeset | 448 | 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: 
14604diff
changeset | 449 | map_term_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: 
14604diff
changeset | 450 | (map_type_tvar | 
| 15794 
5de27a5fc5ed
Adapted to new interface of instantiation and unification / matching functions.
 berghofe parents: 
15783diff
changeset | 451 | (fn v => | 
| 
5de27a5fc5ed
Adapted to new interface of instantiation and unification / matching functions.
 berghofe parents: 
15783diff
changeset | 452 | case Type.lookup (typeSubs, v) of | 
| 15531 | 453 | 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: 
14604diff
changeset | 454 | (* schematic type variable not instantiated *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 455 | 							raise REFUTE ("collect_axioms", "term " ^ Sign.string_of_term (sign_of thy) t ^ " still has a polymorphic type (after instantiating type of " ^ quote s ^ ")")
 | 
| 15531 | 456 | | SOME typ => | 
| 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: 
14604diff
changeset | 457 | 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: 
14604diff
changeset | 458 | 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: 
14604diff
changeset | 459 | end | 
| 15280 | 460 | (* applies a type substitution 'typeSubs' for all type variables in a *) | 
| 461 | (* term 't' *) | |
| 15794 
5de27a5fc5ed
Adapted to new interface of instantiation and unification / matching functions.
 berghofe parents: 
15783diff
changeset | 462 | (* (Term.sort * Term.typ) Term.Vartab.table -> Term.term -> Term.term *) | 
| 15280 | 463 | fun monomorphic_term typeSubs t = | 
| 464 | map_term_types (map_type_tvar | |
| 15794 
5de27a5fc5ed
Adapted to new interface of instantiation and unification / matching functions.
 berghofe parents: 
15783diff
changeset | 465 | (fn v => | 
| 
5de27a5fc5ed
Adapted to new interface of instantiation and unification / matching functions.
 berghofe parents: 
15783diff
changeset | 466 | case Type.lookup (typeSubs, v) of | 
| 15531 | 467 | NONE => | 
| 15280 | 468 | (* schematic type variable not instantiated *) | 
| 18678 | 469 | error "" | 
| 15531 | 470 | | SOME typ => | 
| 15280 | 471 | typ)) 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: 
14604diff
changeset | 472 | (* Term.term list * Term.typ -> Term.term 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: 
15531diff
changeset | 473 | fun collect_sort_axioms (axs, 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: 
15531diff
changeset | 474 | 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: 
15531diff
changeset | 475 | (* collect the axioms for a single 'class' (but not for its superclasses) *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 476 | (* Term.term list * string -> 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: 
15531diff
changeset | 477 | fun collect_class_axioms (axs, class) = | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 478 | 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: 
15531diff
changeset | 479 | (* obtain the axioms generated by the "axclass" command *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 480 | (* (string * Term.term) list *) | 
| 18932 | 481 | val class_axioms = List.filter (fn (s, _) => String.isPrefix (Logic.const_of_class class ^ ".axioms_") s) axioms | 
| 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: 
15531diff
changeset | 482 | (* replace the one schematic type variable in each axiom by the actual type '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: 
15531diff
changeset | 483 | (* (string * 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: 
15531diff
changeset | 484 | val monomorphic_class_axioms = map (fn (axname, ax) => | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 485 | let | 
| 15794 
5de27a5fc5ed
Adapted to new interface of instantiation and unification / matching functions.
 berghofe parents: 
15783diff
changeset | 486 | val (idx, S) = (case term_tvars ax 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: 
15531diff
changeset | 487 | [is] => is | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 488 | 									| _    => raise REFUTE ("collect_axioms", "class axiom " ^ axname ^ " (" ^ Sign.string_of_term (sign_of thy) ax ^ ") does not contain exactly one 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: 
15531diff
changeset | 489 | in | 
| 15794 
5de27a5fc5ed
Adapted to new interface of instantiation and unification / matching functions.
 berghofe parents: 
15783diff
changeset | 490 | (axname, monomorphic_term (Vartab.make [(idx, (S, T))]) ax) | 
| 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: 
15531diff
changeset | 491 | end) class_axioms | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 492 | (* Term.term list * (string * Term.term) list -> 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: 
15531diff
changeset | 493 | fun collect_axiom (axs, (axname, ax)) = | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 494 | if mem_term (ax, axs) 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: 
15531diff
changeset | 495 | axs | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 496 | 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: 
15531diff
changeset | 497 | 								immediate_output (" " ^ axname);
 | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 498 | collect_term_axioms (ax :: axs, ax) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 499 | ) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 500 | in | 
| 15570 | 501 | Library.foldl collect_axiom (axs, monomorphic_class_axioms) | 
| 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: 
15531diff
changeset | 502 | 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: 
15531diff
changeset | 503 | (* string 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: 
15531diff
changeset | 504 | val sort = (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: 
15531diff
changeset | 505 | TFree (_, sort) => sort | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 506 | | TVar (_, sort) => sort | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 507 | 					| _               => raise REFUTE ("collect_axioms", "type " ^ Sign.string_of_typ (sign_of thy) T ^ " is not a 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: 
15531diff
changeset | 508 | (* obtain all superclasses of classes in 'sort' *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 509 | (* string list *) | 
| 16366 | 510 | val superclasses = Graph.all_succs ((#2 o #classes o Type.rep_tsig o Sign.tsig_of o sign_of) thy) sort | 
| 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: 
15531diff
changeset | 511 | in | 
| 15570 | 512 | Library.foldl collect_class_axioms (axs, superclasses) | 
| 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: 
15531diff
changeset | 513 | 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: 
15531diff
changeset | 514 | (* 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: 
15531diff
changeset | 515 | 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: 
14604diff
changeset | 516 | 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: 
14604diff
changeset | 517 | (* 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: 
14604diff
changeset | 518 | 			  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: 
14604diff
changeset | 519 | 			| 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: 
14604diff
changeset | 520 | 			| 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: 
15531diff
changeset | 521 | 			| 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: 
14604diff
changeset | 522 | | Type (s, 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: 
14604diff
changeset | 523 | 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: 
14604diff
changeset | 524 | (* look up the definition of a type, as created by "typedef" *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 525 | (* (string * Term.term) list -> (string * 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: 
14604diff
changeset | 526 | fun get_typedefn [] = | 
| 15531 | 527 | 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: 
14604diff
changeset | 528 | | get_typedefn ((axname,ax)::axms) = | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 529 | (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: 
14604diff
changeset | 530 | (* Term.term -> Term.typ 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: 
14604diff
changeset | 531 | fun type_of_type_definition (Const (s', 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: 
14604diff
changeset | 532 | if s'="Typedef.type_definition" then | 
| 15531 | 533 | 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: 
14604diff
changeset | 534 | else | 
| 15531 | 535 | NONE | 
| 536 | | type_of_type_definition (Free _) = NONE | |
| 537 | | type_of_type_definition (Var _) = NONE | |
| 538 | | type_of_type_definition (Bound _) = 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: 
14604diff
changeset | 539 | | type_of_type_definition (Abs (_, _, body)) = type_of_type_definition body | 
| 15531 | 540 | | type_of_type_definition (t1 $ t2) = (case type_of_type_definition t1 of SOME x => SOME x | NONE => type_of_type_definition 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: 
14604diff
changeset | 541 | 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: 
14604diff
changeset | 542 | case type_of_type_definition ax of | 
| 15531 | 543 | 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: 
14604diff
changeset | 544 | 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: 
14604diff
changeset | 545 | val T'' = (domain_type o domain_type) T' | 
| 16935 | 546 | val typeSubs = Sign.typ_match thy (T'', T) Vartab.empty | 
| 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: 
14604diff
changeset | 547 | in | 
| 15531 | 548 | SOME (axname, monomorphic_term typeSubs 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: 
14604diff
changeset | 549 | end | 
| 15531 | 550 | | 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: 
14604diff
changeset | 551 | get_typedefn axms | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 552 | end | 
| 18678 | 553 | handle ERROR _ => get_typedefn axms | 
| 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: 
14604diff
changeset | 554 | | MATCH => get_typedefn axms | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 555 | | Type.TYPE_MATCH => get_typedefn axms) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 556 | in | 
| 19346 | 557 | case DatatypePackage.get_datatype thy s of | 
| 15531 | 558 | 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: 
14604diff
changeset | 559 | (* only collect relevant type axioms for the argument types *) | 
| 15570 | 560 | Library.foldl collect_type_axioms (axs, Ts) | 
| 15531 | 561 | | 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: 
14604diff
changeset | 562 | (case get_typedefn axioms of | 
| 15531 | 563 | SOME (axname, 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: 
14604diff
changeset | 564 | if mem_term (ax, axs) 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: 
15531diff
changeset | 565 | (* only collect relevant type axioms for the argument types *) | 
| 15570 | 566 | Library.foldl collect_type_axioms (axs, 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: 
14604diff
changeset | 567 | else | 
| 14984 | 568 | 								(immediate_output (" " ^ axname);
 | 
| 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: 
14604diff
changeset | 569 | collect_term_axioms (ax :: axs, ax)) | 
| 15531 | 570 | | 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: 
15531diff
changeset | 571 | (* unspecified type, perhaps introduced with 'typedecl' *) | 
| 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: 
14604diff
changeset | 572 | (* at least collect relevant type axioms for the argument types *) | 
| 15570 | 573 | Library.foldl collect_type_axioms (axs, 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: 
14604diff
changeset | 574 | 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: 
15531diff
changeset | 575 | | 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: 
15531diff
changeset | 576 | | 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: 
14604diff
changeset | 577 | (* 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: 
14604diff
changeset | 578 | 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: 
14604diff
changeset | 579 | 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: 
14604diff
changeset | 580 | (* 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: 
14604diff
changeset | 581 | 			  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: 
14604diff
changeset | 582 | 			| 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: 
14604diff
changeset | 583 | 			| 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: 
15531diff
changeset | 584 | 			| 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: 
14604diff
changeset | 585 | (* 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: 
14604diff
changeset | 586 | 			| 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: 
14604diff
changeset | 587 | 			| 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: 
14604diff
changeset | 588 | 			| 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: 
14604diff
changeset | 589 | 			| 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: 
14604diff
changeset | 590 | 			| 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: 
14604diff
changeset | 591 | 			| 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: 
14604diff
changeset | 592 | let | 
| 17314 | 593 | 					val ax = specialize_type (("The", T), (the 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: 
14604diff
changeset | 594 | 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: 
14604diff
changeset | 595 | if mem_term (ax, axs) 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: 
14604diff
changeset | 596 | 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: 
14604diff
changeset | 597 | else | 
| 14984 | 598 | (immediate_output " 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: 
14604diff
changeset | 599 | collect_term_axioms (ax :: axs, ax)) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 600 | 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: 
14604diff
changeset | 601 | 			| 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: 
14604diff
changeset | 602 | let | 
| 17314 | 603 | 					val ax = specialize_type (("Hilbert_Choice.Eps", T),
 | 
| 604 | (the 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: 
14604diff
changeset | 605 | 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: 
14604diff
changeset | 606 | if mem_term (ax, axs) 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: 
14604diff
changeset | 607 | 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: 
14604diff
changeset | 608 | else | 
| 14984 | 609 | (immediate_output " 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: 
14604diff
changeset | 610 | collect_term_axioms (ax :: axs, ax)) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 611 | 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: 
14604diff
changeset | 612 | 			| Const ("All", _) $ t1           => collect_term_axioms (axs, 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: 
14604diff
changeset | 613 | 			| Const ("Ex", _) $ t1            => collect_term_axioms (axs, 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: 
14604diff
changeset | 614 | 			| 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: 
14604diff
changeset | 615 | 			| 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: 
14604diff
changeset | 616 | 			| 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: 
14604diff
changeset | 617 | 			| 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: 
14604diff
changeset | 618 | (* 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: 
14604diff
changeset | 619 | 			| 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: 
14604diff
changeset | 620 | 			| 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: 
14604diff
changeset | 621 | (* 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: 
14604diff
changeset | 622 | 			| Const ("Finite_Set.card", T)    => collect_type_axioms (axs, T)
 | 
| 15571 | 623 | 			| Const ("Finite_Set.Finites", T) => collect_type_axioms (axs, T)
 | 
| 19277 | 624 | 			| 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: 
18932diff
changeset | 625 | 			| 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: 
18932diff
changeset | 626 | 			| 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: 
18932diff
changeset | 627 | 			| 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: 
15611diff
changeset | 628 | 			| Const ("List.op @", T)          => collect_type_axioms (axs, T)
 | 
| 16050 | 629 | 			| Const ("Lfp.lfp", T)            => collect_type_axioms (axs, T)
 | 
| 630 | 			| Const ("Gfp.gfp", 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: 
14604diff
changeset | 631 | (* 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: 
14604diff
changeset | 632 | | Const (s, 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: 
14604diff
changeset | 633 | 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: 
14604diff
changeset | 634 | (* look up the definition of a constant, as created by "constdefs" *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 635 | (* string -> Term.typ -> (string * Term.term) list -> (string * 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: 
14604diff
changeset | 636 | fun get_defn [] = | 
| 15531 | 637 | 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: 
15531diff
changeset | 638 | | get_defn ((axname, ax)::axms) = | 
| 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: 
14604diff
changeset | 639 | (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: 
14604diff
changeset | 640 | val (lhs, _) = Logic.dest_equals ax (* equations only *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 641 | val c = head_of lhs | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 642 | val (s', T') = dest_Const c | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 643 | 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: 
14604diff
changeset | 644 | if s=s' 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: 
14604diff
changeset | 645 | let | 
| 16935 | 646 | val typeSubs = Sign.typ_match thy (T', T) Vartab.empty | 
| 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: 
14604diff
changeset | 647 | in | 
| 15531 | 648 | SOME (axname, monomorphic_term typeSubs 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: 
14604diff
changeset | 649 | 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: 
14604diff
changeset | 650 | 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: 
14604diff
changeset | 651 | get_defn axms | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 652 | end | 
| 18678 | 653 | handle ERROR _ => get_defn axms | 
| 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: 
14604diff
changeset | 654 | | TERM _ => get_defn axms | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 655 | | Type.TYPE_MATCH => get_defn axms) | 
| 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: 
15531diff
changeset | 656 | (* 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: 
15531diff
changeset | 657 | (* unit -> 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: 
15531diff
changeset | 658 | fun is_const_of_class () = | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 659 | (* I'm not quite sure if checking the name 's' is sufficient, *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 660 | (* or if we should also check the type '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: 
15531diff
changeset | 661 | s mem const_of_class_names | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 662 | (* inductive data types *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 663 | (* unit -> 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: 
15531diff
changeset | 664 | fun is_IDT_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: 
15531diff
changeset | 665 | (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: 
15531diff
changeset | 666 | Type (s', _) => | 
| 19346 | 667 | (case DatatypePackage.get_datatype_constrs 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: 
15531diff
changeset | 668 | SOME constrs => | 
| 19346 | 669 | Library.exists (fn (cname, cty) => | 
| 670 | cname = s andalso Sign.typ_instance thy (T, cty)) | |
| 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: 
15531diff
changeset | 671 | 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: 
15531diff
changeset | 672 | | 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: 
14604diff
changeset | 673 | false) | 
| 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: 
15531diff
changeset | 674 | | _ => | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 675 | 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: 
15531diff
changeset | 676 | (* unit -> 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: 
15531diff
changeset | 677 | fun is_IDT_recursor () = | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 678 | (* I'm not quite sure if checking the name 's' is sufficient, *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 679 | (* or if we should also check the type '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: 
15531diff
changeset | 680 | s mem rec_names | 
| 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: 
14604diff
changeset | 681 | 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: 
15531diff
changeset | 682 | if is_const_of_class () 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: 
15531diff
changeset | 683 | (* axiomatic type classes: add "OFCLASS(?'a::c, c_class)" and *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 684 | (* the introduction rule "class.intro" as axioms *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 685 | let | 
| 18932 | 686 | 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: 
15531diff
changeset | 687 | 							val inclass = Logic.mk_inclass (TVar (("'a", 0), [class]), class)
 | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 688 | (* Term.term 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: 
15531diff
changeset | 689 | val ofclass_ax = (SOME (specialize_type ((s, T), inclass)) handle Type.TYPE_MATCH => NONE) | 
| 17314 | 690 | val intro_ax = (Option.map (fn t => specialize_type ((s, T), t)) | 
| 691 | (AList.lookup (op =) axioms (class ^ ".intro")) handle Type.TYPE_MATCH => 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: 
15531diff
changeset | 692 | val axs' = (case ofclass_ax of NONE => axs | SOME ax => if mem_term (ax, axs) 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: 
15531diff
changeset | 693 | (* collect relevant type axioms *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 694 | collect_type_axioms (axs, 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: 
15531diff
changeset | 695 | 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: 
15531diff
changeset | 696 | 									(immediate_output (" " ^ Sign.string_of_term (sign_of thy) ax);
 | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 697 | collect_term_axioms (ax :: axs, ax))) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 698 | val axs'' = (case intro_ax of NONE => axs' | SOME ax => if mem_term (ax, axs') 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: 
15531diff
changeset | 699 | (* collect relevant type axioms *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 700 | collect_type_axioms (axs', 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: 
15531diff
changeset | 701 | else | 
| 17274 
746bb4c56800
axclass: name space prefix is now "c_class" instead of just "c";
 wenzelm parents: 
17261diff
changeset | 702 | 									(immediate_output (" " ^ s ^ ".intro");
 | 
| 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: 
15531diff
changeset | 703 | collect_term_axioms (ax :: axs', ax))) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 704 | 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: 
15531diff
changeset | 705 | axs'' | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 706 | 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: 
15531diff
changeset | 707 | else if is_IDT_constructor () then | 
| 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: 
14604diff
changeset | 708 | (* only collect relevant type axioms *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 709 | collect_type_axioms (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: 
15531diff
changeset | 710 | else if is_IDT_recursor () then | 
| 15125 | 711 | (* only collect relevant type axioms *) | 
| 712 | collect_type_axioms (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: 
15531diff
changeset | 713 | 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: 
15531diff
changeset | 714 | case get_defn axioms of | 
| 15531 | 715 | SOME (axname, 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: 
14604diff
changeset | 716 | if mem_term (ax, axs) 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: 
14604diff
changeset | 717 | (* collect relevant type axioms *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 718 | 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: 
14604diff
changeset | 719 | else | 
| 14984 | 720 | 								(immediate_output (" " ^ axname);
 | 
| 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: 
14604diff
changeset | 721 | collect_term_axioms (ax :: axs, ax)) | 
| 15531 | 722 | | 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: 
14604diff
changeset | 723 | (* collect relevant type axioms *) | 
| 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: 
15531diff
changeset | 724 | collect_type_axioms (axs, 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: 
15531diff
changeset | 725 | ) | 
| 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: 
14604diff
changeset | 726 | 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: 
14604diff
changeset | 727 | | Free (_, 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: 
14604diff
changeset | 728 | | Var (_, 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: 
14604diff
changeset | 729 | | Bound i => 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: 
14604diff
changeset | 730 | | Abs (_, T, body) => collect_term_axioms (collect_type_axioms (axs, 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: 
14604diff
changeset | 731 | | t1 $ t2 => collect_term_axioms (collect_term_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: 
14604diff
changeset | 732 | (* universal closure over schematic 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: 
14604diff
changeset | 733 | (* Term.term -> 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: 
14604diff
changeset | 734 | fun close_form 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: 
14604diff
changeset | 735 | 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: 
14604diff
changeset | 736 | (* (Term.indexname * 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: 
14604diff
changeset | 737 | val vars = sort_wrt (fst o fst) (map dest_Var (term_vars 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: 
14604diff
changeset | 738 | in | 
| 15570 | 739 | Library.foldl | 
| 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: 
15531diff
changeset | 740 | (fn (t', ((x, i), T)) => (Term.all T) $ Abs (x, T, abstract_over (Var((x, i), 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: 
14604diff
changeset | 741 | (t, vars) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
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: 
14604diff
changeset | 743 | (* 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: 
14604diff
changeset | 744 | 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: 
14604diff
changeset | 745 | 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: 
14604diff
changeset | 746 | 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: 
14604diff
changeset | 747 | result | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 748 | end; | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 749 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 750 | (* ------------------------------------------------------------------------- *) | 
| 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: 
14604diff
changeset | 751 | (* 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: 
14604diff
changeset | 752 | (* 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: 
14604diff
changeset | 753 | (* 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: 
14604diff
changeset | 754 | (* '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: 
14604diff
changeset | 755 | (* 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: 
14604diff
changeset | 756 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 757 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 758 | (* 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: 
14604diff
changeset | 759 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 760 | 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: 
14604diff
changeset | 761 | 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: 
14604diff
changeset | 762 | (* 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: 
14604diff
changeset | 763 | 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: 
14604diff
changeset | 764 | 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: 
14604diff
changeset | 765 | 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: 
14604diff
changeset | 766 | 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: 
14604diff
changeset | 767 | (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: 
14604diff
changeset | 768 | 				  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: 
14604diff
changeset | 769 | 				| 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: 
14604diff
changeset | 770 | 				| 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: 
14604diff
changeset | 771 | | Type (s, Ts) => | 
| 19346 | 772 | (case DatatypePackage.get_datatype thy s of | 
| 15531 | 773 | 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: 
14604diff
changeset | 774 | 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: 
14604diff
changeset | 775 | 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: 
14604diff
changeset | 776 | val descr = #descr info | 
| 17314 | 777 | val (_, dtyps, constrs) = (the 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: 
14604diff
changeset | 778 | 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: 
14604diff
changeset | 779 | (* 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: 
14604diff
changeset | 780 | 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: 
14604diff
changeset | 781 | 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: 
14604diff
changeset | 782 | 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: 
14604diff
changeset | 783 | 									raise REFUTE ("ground_types", "datatype argument (for type " ^ Sign.string_of_typ (sign_of thy) (Type (s, Ts)) ^ ") is not a variable")
 | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 784 | 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: 
14604diff
changeset | 785 | ()) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 786 | (* 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: 
14604diff
changeset | 787 | val acc' = (if Library.exists (fn (_, ds) => Library.exists DatatypeAux.is_rec_type ds) constrs 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: 
14604diff
changeset | 788 | T ins 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: 
14604diff
changeset | 789 | 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: 
14604diff
changeset | 790 | 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: 
14604diff
changeset | 791 | (* collect argument types *) | 
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15571diff
changeset | 792 | 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: 
14604diff
changeset | 793 | (* collect constructor types *) | 
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15571diff
changeset | 794 | 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: 
14604diff
changeset | 795 | 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: 
14604diff
changeset | 796 | 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: 
14604diff
changeset | 797 | end | 
| 15531 | 798 | | NONE => (* not an inductive datatype, e.g. defined via "typedef" or "typedecl" *) | 
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15571diff
changeset | 799 | T ins (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: 
14604diff
changeset | 800 | | TFree _ => T ins 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: 
14604diff
changeset | 801 | | TVar _ => T ins 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: 
14604diff
changeset | 802 | 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: 
14604diff
changeset | 803 | 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: 
14604diff
changeset | 804 | 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: 
14604diff
changeset | 805 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 806 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 807 | (* 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: 
14604diff
changeset | 808 | (* 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: 
14604diff
changeset | 809 | (* 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: 
14604diff
changeset | 810 | (* 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: 
14604diff
changeset | 811 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 812 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 813 | (* 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: 
14604diff
changeset | 814 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 815 | 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: 
14604diff
changeset | 816 | | 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: 
14604diff
changeset | 817 | | 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: 
14604diff
changeset | 818 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 819 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 820 | (* 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: 
14604diff
changeset | 821 | (* '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: 
14604diff
changeset | 822 | (* '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: 
14604diff
changeset | 823 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 824 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 825 | (* 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: 
14604diff
changeset | 826 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 827 | 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: 
14604diff
changeset | 828 | 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: 
14604diff
changeset | 829 | fun size_of_typ T = | 
| 17314 | 830 | case AList.lookup (op =) sizes (string_of_typ T) of | 
| 15531 | 831 | SOME n => n | 
| 832 | | 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: 
14604diff
changeset | 833 | 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: 
14604diff
changeset | 834 | 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: 
14604diff
changeset | 835 | 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: 
14604diff
changeset | 836 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 837 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 838 | (* 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: 
14604diff
changeset | 839 | (* 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: 
14604diff
changeset | 840 | (* '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: 
14604diff
changeset | 841 | (* type may have a fixed size given in 'sizes' *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 842 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 843 | |
| 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: 
14604diff
changeset | 844 | (* (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: 
14351diff
changeset | 845 | |
| 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: 
14604diff
changeset | 846 | fun next_universe xs sizes minsize maxsize = | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 847 | 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: 
14604diff
changeset | 848 | (* 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: 
14604diff
changeset | 849 | (* 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: 
14604diff
changeset | 850 | (* 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: 
15531diff
changeset | 851 | 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: 
14604diff
changeset | 852 | if sum=0 then | 
| 15531 | 853 | 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: 
14604diff
changeset | 854 | else | 
| 15531 | 855 | 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: 
15531diff
changeset | 856 | | 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: 
14604diff
changeset | 857 | if sum<=max orelse max<0 then | 
| 15570 | 858 | 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: 
14604diff
changeset | 859 | else | 
| 15570 | 860 | 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: 
14604diff
changeset | 861 | (* 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: 
14604diff
changeset | 862 | (* 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: 
15531diff
changeset | 863 | (* 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: 
15531diff
changeset | 864 | 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: 
15531diff
changeset | 865 | 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: 
15531diff
changeset | 866 | | 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: 
15531diff
changeset | 867 | (* 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: 
15531diff
changeset | 868 | 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: 
15531diff
changeset | 869 | | 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: 
15531diff
changeset | 870 | 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: 
15531diff
changeset | 871 | (* we can shift *) | 
| 15570 | 872 | 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: 
15531diff
changeset | 873 | 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: 
15531diff
changeset | 874 | (* 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: 
15531diff
changeset | 875 | 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: 
14604diff
changeset | 876 | (* only consider those types for which the size is not fixed *) | 
| 17314 | 877 | 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: 
14604diff
changeset | 878 | (* 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: 
14604diff
changeset | 879 | 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: 
14604diff
changeset | 880 | 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: 
15531diff
changeset | 881 | case next (maxsize-minsize) 0 0 diffs of | 
| 15531 | 882 | 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: 
14604diff
changeset | 883 | (* merge with those types for which the size is fixed *) | 
| 15531 | 884 | SOME (snd (foldl_map (fn (ds, (T, _)) => | 
| 17314 | 885 | 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: 
15531diff
changeset | 886 | 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: 
15531diff
changeset | 887 | | 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: 
14604diff
changeset | 888 | (diffs', xs))) | 
| 15531 | 889 | | NONE => | 
| 890 | 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: 
14604diff
changeset | 891 | 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: 
14604diff
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: 
14604diff
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: 
14604diff
changeset | 894 | (* 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: 
14604diff
changeset | 895 | (* 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: 
14604diff
changeset | 896 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 897 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 898 | (* 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: 
14604diff
changeset | 899 | |
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 900 | fun toTrue (Leaf [fm, _]) = fm | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 901 | 	  | 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: 
14604diff
changeset | 902 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 903 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 904 | (* 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: 
14604diff
changeset | 905 | (* 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: 
14604diff
changeset | 906 | (* 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: 
14604diff
changeset | 907 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 908 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 909 | (* 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: 
14604diff
changeset | 910 | |
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 911 | fun toFalse (Leaf [_, fm]) = fm | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 912 | 	  | 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: 
14604diff
changeset | 913 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 914 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 915 | (* 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: 
14604diff
changeset | 916 | (* 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: 
14604diff
changeset | 917 | (* 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: 
14604diff
changeset | 918 | (* 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: 
14604diff
changeset | 919 | (* {...}     : 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: 
14604diff
changeset | 920 | (* 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: 
14604diff
changeset | 921 | (* 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: 
14604diff
changeset | 922 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 923 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 924 | (* 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: 
14604diff
changeset | 925 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 926 | 	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: 
14604diff
changeset | 927 | 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: 
14604diff
changeset | 928 | (* 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: 
14604diff
changeset | 929 | 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: 
14604diff
changeset | 930 | 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: 
14604diff
changeset | 931 | (* 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: 
14604diff
changeset | 932 | val axioms = 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: 
14604diff
changeset | 933 | (* Term.typ list *) | 
| 15570 | 934 | val types = Library.foldl (fn (acc, t') => acc union (ground_types thy t')) ([], t :: 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: 
14604diff
changeset | 935 | 			val _      = writeln ("Ground 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: 
14604diff
changeset | 936 | ^ (if null types then "none." | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 937 | else commas (map (Sign.string_of_typ (sign_of 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: 
15531diff
changeset | 938 | (* 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: 
15531diff
changeset | 939 | (* 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: 
15531diff
changeset | 940 | (* 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: 
15531diff
changeset | 941 | 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: 
15531diff
changeset | 942 | Type (s, _) => | 
| 19346 | 943 | (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: 
15531diff
changeset | 944 | 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: 
15531diff
changeset | 945 | 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: 
15531diff
changeset | 946 | 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: 
15531diff
changeset | 947 | val descr = #descr info | 
| 17314 | 948 | val (_, _, constrs) = (the 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: 
15531diff
changeset | 949 | 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: 
15531diff
changeset | 950 | (* 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: 
15531diff
changeset | 951 | 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: 
15531diff
changeset | 952 | 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: 
15531diff
changeset | 953 | | 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: 
15531diff
changeset | 954 | | _ => 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: 
15531diff
changeset | 955 | 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: 
15531diff
changeset | 956 | 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: 
15531diff
changeset | 957 | () | 
| 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: 
14604diff
changeset | 958 | (* (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: 
14604diff
changeset | 959 | fun find_model_loop universe = | 
| 15334 
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
 webertj parents: 
15333diff
changeset | 960 | 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: 
14604diff
changeset | 961 | 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: 
15531diff
changeset | 962 | 				val init_args              = {maxvars = maxvars, def_eq = false, next_idx = 1, bounds = [], wellformed = True}
 | 
| 14984 | 963 | 				val _                      = immediate_output ("Translating term (sizes: " ^ commas (map (fn (_, n) => string_of_int n) universe) ^ ") ...")
 | 
| 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: 
14604diff
changeset | 964 | (* translate 't' and all axioms *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 965 | 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: 
14604diff
changeset | 966 | 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: 
14604diff
changeset | 967 | 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: 
14604diff
changeset | 968 | 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: 
15531diff
changeset | 969 | (* 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: 
15531diff
changeset | 970 | 						((m', {maxvars = #maxvars a', def_eq = true, next_idx = #next_idx a', bounds = #bounds a', 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: 
14604diff
changeset | 971 | end) ((init_model, init_args), t :: axioms) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 972 | (* make 't' either true or false, and make all axioms true, 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: 
14604diff
changeset | 973 | (* add the well-formedness side condition *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 974 | val fm_t = (if negate then toFalse else toTrue) (hd intrs) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 975 | val fm_ax = PropLogic.all (map toTrue (tl intrs)) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 976 | val fm = PropLogic.all [#wellformed args, fm_ax, fm_t] | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 977 | in | 
| 14984 | 978 | immediate_output " invoking SAT solver..."; | 
| 14965 | 979 | (case SatSolver.invoke_solver satsolver fm of | 
| 980 | 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: 
15531diff
changeset | 981 | (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: 
15531diff
changeset | 982 | 					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: 
17412diff
changeset | 983 | | 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: 
15531diff
changeset | 984 | (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: 
15531diff
changeset | 985 | 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: 
15531diff
changeset | 986 | 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: 
15531diff
changeset | 987 | | 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: 
15531diff
changeset | 988 | | SatSolver.UNKNOWN => | 
| 14984 | 989 | (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: 
14604diff
changeset | 990 | case next_universe universe sizes minsize maxsize of | 
| 15531 | 991 | 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: 
15531diff
changeset | 992 | | 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: 
15531diff
changeset | 993 | ) handle SatSolver.NOT_CONFIGURED => | 
| 14965 | 994 | 					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: 
14604diff
changeset | 995 | 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: 
14604diff
changeset | 996 | 				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: 
14604diff
changeset | 997 | 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: 
14604diff
changeset | 998 | find_model_loop (first_universe types sizes minsize) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 999 | 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: 
14604diff
changeset | 1000 | 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: 
14604diff
changeset | 1001 | (* 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: 
14604diff
changeset | 1002 | 			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: 
14604diff
changeset | 1003 | 			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: 
14604diff
changeset | 1004 | 			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: 
14604diff
changeset | 1005 | 			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: 
14604diff
changeset | 1006 | 			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: 
15531diff
changeset | 1007 | (* 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: 
14604diff
changeset | 1008 | 			writeln ("Trying to find a model that " ^ (if negate then "refutes" else "satisfies") ^ ": "
 | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1009 | ^ Sign.string_of_term (sign_of 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: 
15531diff
changeset | 1010 | if maxtime>0 then ( | 
| 18760 | 1011 | 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: 
14604diff
changeset | 1012 | wrapper () | 
| 18760 | 1013 | 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: 
14604diff
changeset | 1014 | 					writeln ("\nSearch terminated, time limit ("
 | 
| 14965 | 1015 | ^ 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: 
15531diff
changeset | 1016 | ^ ") 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: 
15531diff
changeset | 1017 | ) 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: 
14604diff
changeset | 1018 | 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: 
14604diff
changeset | 1019 | end; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1020 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1021 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1022 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1023 | (* INTERFACE, PART 2: FINDING A MODEL *) | 
| 14350 | 1024 | (* ------------------------------------------------------------------------- *) | 
| 1025 | ||
| 1026 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1027 | (* 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: 
14351diff
changeset | 1028 | (* params : list of '(name, value)' pairs used to override default *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1029 | (* parameters *) | 
| 14350 | 1030 | (* ------------------------------------------------------------------------- *) | 
| 1031 | ||
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1032 | (* theory -> (string * string) list -> Term.term -> unit *) | 
| 14350 | 1033 | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1034 | 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: 
14604diff
changeset | 1035 | find_model thy (actual_params thy params) t false; | 
| 14350 | 1036 | |
| 1037 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1038 | (* 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: 
14351diff
changeset | 1039 | (* params : list of '(name, value)' pairs used to override default *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1040 | (* parameters *) | 
| 14350 | 1041 | (* ------------------------------------------------------------------------- *) | 
| 1042 | ||
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1043 | (* theory -> (string * string) list -> Term.term -> unit *) | 
| 14350 | 1044 | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1045 | fun refute_term thy params t = | 
| 14350 | 1046 | 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: 
14604diff
changeset | 1047 | (* 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: 
14604diff
changeset | 1048 | (* 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: 
14604diff
changeset | 1049 | (* 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: 
14604diff
changeset | 1050 | (* for ALL types, not ...) *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1051 | val _ = assert (null (term_tvars t)) "Term to be refuted contains schematic type variables" | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1052 | (* existential closure over schematic variables *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1053 | (* (Term.indexname * Term.typ) list *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1054 | 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: 
14351diff
changeset | 1055 | (* Term.term *) | 
| 15570 | 1056 | val ex_closure = Library.foldl | 
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1057 | (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: 
14351diff
changeset | 1058 | (t, vars) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1059 | (* If 't' is of type 'propT' (rather than 'boolT'), applying *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1060 | (* 'HOLogic.exists_const' is not type-correct. However, 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: 
14604diff
changeset | 1061 | (* is not really a problem as long as 'find_model' still *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1062 | (* interprets the resulting term correctly, without checking *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1063 | (* its type. *) | 
| 14350 | 1064 | 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: 
14604diff
changeset | 1065 | find_model thy (actual_params thy params) ex_closure true | 
| 14350 | 1066 | end; | 
| 1067 | ||
| 1068 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1069 | (* refute_subgoal: calls 'refute_term' on a specific subgoal *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1070 | (* params : list of '(name, value)' pairs used to override default *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1071 | (* parameters *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1072 | (* subgoal : 0-based index specifying the subgoal number *) | 
| 14350 | 1073 | (* ------------------------------------------------------------------------- *) | 
| 1074 | ||
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1075 | (* theory -> (string * string) list -> Thm.thm -> int -> unit *) | 
| 14350 | 1076 | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1077 | fun refute_subgoal thy params thm subgoal = | 
| 15570 | 1078 | refute_term thy params (List.nth (prems_of thm, subgoal)); | 
| 14350 | 1079 | |
| 1080 | ||
| 1081 | (* ------------------------------------------------------------------------- *) | |
| 15292 | 1082 | (* INTERPRETERS: Auxiliary Functions *) | 
| 14350 | 1083 | (* ------------------------------------------------------------------------- *) | 
| 1084 | ||
| 1085 | (* ------------------------------------------------------------------------- *) | |
| 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: 
14604diff
changeset | 1086 | (* 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: 
14604diff
changeset | 1087 | (* 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: 
14604diff
changeset | 1088 | (* 'True'/'False' only (no Boolean variables) *) | 
| 14350 | 1089 | (* ------------------------------------------------------------------------- *) | 
| 1090 | ||
| 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: 
14604diff
changeset | 1091 | (* interpretation -> interpretation list *) | 
| 14350 | 1092 | |
| 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: 
14604diff
changeset | 1093 | fun make_constants intr = | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1094 | let | 
| 14350 | 1095 | (* returns a list with all unit vectors of length n *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1096 | (* int -> interpretation list *) | 
| 14350 | 1097 | fun unit_vectors n = | 
| 1098 | let | |
| 1099 | (* returns the k-th unit vector of length n *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1100 | (* int * int -> interpretation *) | 
| 14350 | 1101 | fun unit_vector (k,n) = | 
| 1102 | Leaf ((replicate (k-1) False) @ (True :: (replicate (n-k) False))) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1103 | (* int -> interpretation list -> interpretation list *) | 
| 14350 | 1104 | fun unit_vectors_acc k vs = | 
| 1105 | if k>n then [] else (unit_vector (k,n))::(unit_vectors_acc (k+1) vs) | |
| 1106 | in | |
| 1107 | unit_vectors_acc 1 [] | |
| 1108 | end | |
| 1109 | (* concatenates 'x' with every list in 'xss', returning a new list of lists *) | |
| 1110 | (* 'a -> 'a list list -> 'a list list *) | |
| 1111 | fun cons_list x xss = | |
| 1112 | map (fn xs => x::xs) xss | |
| 1113 | (* returns a list of lists, each one consisting of n (possibly identical) elements from 'xs' *) | |
| 1114 | (* int -> 'a list -> 'a list list *) | |
| 1115 | fun pick_all 1 xs = | |
| 1116 | map (fn x => [x]) xs | |
| 1117 | | pick_all n xs = | |
| 1118 | let val rec_pick = pick_all (n-1) xs in | |
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1119 | Library.foldl (fn (acc, x) => (cons_list x rec_pick) @ acc) ([], xs) | 
| 14350 | 1120 | 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: 
14604diff
changeset | 1121 | 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: 
14604diff
changeset | 1122 | 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: 
14604diff
changeset | 1123 | 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: 
14604diff
changeset | 1124 | | 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: 
14604diff
changeset | 1125 | 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: 
14604diff
changeset | 1126 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1127 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1128 | (* 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: 
14604diff
changeset | 1129 | (* (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: 
14604diff
changeset | 1130 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1131 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1132 | (* 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: 
14604diff
changeset | 1133 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1134 | 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: 
14604diff
changeset | 1135 | let | 
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1136 | (* 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: 
14604diff
changeset | 1137 | (* int * int -> int *) | 
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1138 | fun power (a, 0) = 1 | 
| 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1139 | | power (a, 1) = a | 
| 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1140 | | 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: 
14604diff
changeset | 1141 | 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: 
14604diff
changeset | 1142 | 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: 
14604diff
changeset | 1143 | 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: 
14604diff
changeset | 1144 | | 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: 
14604diff
changeset | 1145 | 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: 
14604diff
changeset | 1146 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1147 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1148 | (* 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: 
14604diff
changeset | 1149 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1150 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1151 | (* 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: 
14604diff
changeset | 1152 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1153 | 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: 
14604diff
changeset | 1154 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1155 | 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: 
14604diff
changeset | 1156 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1157 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1158 | (* 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: 
14604diff
changeset | 1159 | (* 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: 
15531diff
changeset | 1160 | (* - 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: 
15531diff
changeset | 1161 | (* 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: 
15531diff
changeset | 1162 | (* - 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: 
15531diff
changeset | 1163 | (* 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: 
15531diff
changeset | 1164 | (* - 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: 
15531diff
changeset | 1165 | (* '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: 
14604diff
changeset | 1166 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1167 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1168 | (* 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: 
14604diff
changeset | 1169 | (* 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: 
14604diff
changeset | 1170 | (* 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: 
14604diff
changeset | 1171 | (* '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: 
14604diff
changeset | 1172 | (* 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: 
14604diff
changeset | 1173 | (* 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: 
14604diff
changeset | 1174 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1175 | (* 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: 
14604diff
changeset | 1176 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1177 | 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: 
14604diff
changeset | 1178 | 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: 
14604diff
changeset | 1179 | (* 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: 
14604diff
changeset | 1180 | 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: 
14604diff
changeset | 1181 | (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: 
14604diff
changeset | 1182 | 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: 
14604diff
changeset | 1183 | (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: 
15531diff
changeset | 1184 | 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: 
14604diff
changeset | 1185 | 				| 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: 
14604diff
changeset | 1186 | | 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: 
14604diff
changeset | 1187 | (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: 
14604diff
changeset | 1188 | 				  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: 
14604diff
changeset | 1189 | | 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: 
14604diff
changeset | 1190 | (* 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: 
14604diff
changeset | 1191 | 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: 
14604diff
changeset | 1192 | (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: 
14604diff
changeset | 1193 | 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: 
14604diff
changeset | 1194 | (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: 
14604diff
changeset | 1195 | 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: 
14604diff
changeset | 1196 | (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: 
14604diff
changeset | 1197 | 				| 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: 
14604diff
changeset | 1198 | | 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: 
14604diff
changeset | 1199 | (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: 
14604diff
changeset | 1200 | 				  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: 
14604diff
changeset | 1201 | | Node ys => PropLogic.exists (map not_equal (xs ~~ ys)))) | 
| 14350 | 1202 | 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: 
14604diff
changeset | 1203 | (* 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: 
15531diff
changeset | 1204 | (* 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: 
14604diff
changeset | 1205 | 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: 
14604diff
changeset | 1206 | 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: 
14604diff
changeset | 1207 | |
| 15292 | 1208 | (* ------------------------------------------------------------------------- *) | 
| 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: 
15531diff
changeset | 1209 | (* 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: 
15531diff
changeset | 1210 | (* 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: 
15531diff
changeset | 1211 | (* 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: 
15531diff
changeset | 1212 | (* 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: 
15531diff
changeset | 1213 | (* 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: 
15531diff
changeset | 1214 | (* 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: 
15531diff
changeset | 1215 | (* ------------------------------------------------------------------------- *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1216 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1217 | (* 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: 
15531diff
changeset | 1218 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1219 | 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: 
15531diff
changeset | 1220 | 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: 
15531diff
changeset | 1221 | (* 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: 
15531diff
changeset | 1222 | 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: 
15531diff
changeset | 1223 | (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: 
15531diff
changeset | 1224 | 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: 
15531diff
changeset | 1225 | (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: 
15531diff
changeset | 1226 | 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: 
15531diff
changeset | 1227 | 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: 
15531diff
changeset | 1228 | 				| 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: 
15531diff
changeset | 1229 | | 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: 
15531diff
changeset | 1230 | (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: 
15531diff
changeset | 1231 | 				  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: 
15531diff
changeset | 1232 | | 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: 
15531diff
changeset | 1233 | (* 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: 
15531diff
changeset | 1234 | 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: 
15531diff
changeset | 1235 | 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: 
15531diff
changeset | 1236 | 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: 
15531diff
changeset | 1237 | 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: 
15531diff
changeset | 1238 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1239 | (* ------------------------------------------------------------------------- *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1240 | (* 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: 
15531diff
changeset | 1241 | (* 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: 
15531diff
changeset | 1242 | (* 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: 
15531diff
changeset | 1243 | (* ------------------------------------------------------------------------- *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1244 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1245 | (* 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: 
15531diff
changeset | 1246 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1247 | 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: 
15531diff
changeset | 1248 | 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: 
15531diff
changeset | 1249 | (* 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: 
15531diff
changeset | 1250 | 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: 
15531diff
changeset | 1251 | 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: 
15531diff
changeset | 1252 | (* 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: 
15531diff
changeset | 1253 | 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: 
15531diff
changeset | 1254 | 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: 
15531diff
changeset | 1255 | (* 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: 
15531diff
changeset | 1256 | 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: 
15531diff
changeset | 1257 | 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: 
15531diff
changeset | 1258 | | 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: 
15531diff
changeset | 1259 | 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: 
15531diff
changeset | 1260 | | 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: 
15531diff
changeset | 1261 | 			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: 
15531diff
changeset | 1262 | (* 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: 
15531diff
changeset | 1263 | (* '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: 
15531diff
changeset | 1264 | 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: 
15531diff
changeset | 1265 | 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: 
15531diff
changeset | 1266 | (* 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: 
15531diff
changeset | 1267 | (* '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: 
15531diff
changeset | 1268 | 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: 
15531diff
changeset | 1269 | 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: 
15531diff
changeset | 1270 | | 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: 
15531diff
changeset | 1271 | let val rec_pick = pick_all xss in | 
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1272 | 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: 
15531diff
changeset | 1273 | 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: 
15531diff
changeset | 1274 | | 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: 
15531diff
changeset | 1275 | 			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: 
15531diff
changeset | 1276 | (* 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: 
15531diff
changeset | 1277 | 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: 
15531diff
changeset | 1278 | 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: 
15531diff
changeset | 1279 | | 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: 
15531diff
changeset | 1280 | 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: 
15531diff
changeset | 1281 | 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: 
15531diff
changeset | 1282 | 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: 
15531diff
changeset | 1283 | 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: 
15531diff
changeset | 1284 | 			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: 
15531diff
changeset | 1285 | | 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: 
15531diff
changeset | 1286 | 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: 
15531diff
changeset | 1287 | 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: 
15531diff
changeset | 1288 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1289 | (* ------------------------------------------------------------------------- *) | 
| 15292 | 1290 | (* eta_expand: eta-expands a term 't' by adding 'i' lambda abstractions *) | 
| 1291 | (* ------------------------------------------------------------------------- *) | |
| 1292 | ||
| 1293 | (* Term.term -> int -> Term.term *) | |
| 1294 | ||
| 1295 | fun eta_expand t i = | |
| 1296 | let | |
| 1297 | val Ts = binder_types (fastype_of t) | |
| 1298 | in | |
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15571diff
changeset | 1299 | 		foldr (fn (T, t) => Abs ("<eta_expand>", T, t))
 | 
| 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15571diff
changeset | 1300 | (list_comb (t, map Bound (i-1 downto 0))) (Library.take (i, Ts)) | 
| 15292 | 1301 | end; | 
| 1302 | ||
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1303 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1304 | (* sum: returns the sum of a list 'xs' of integers *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1305 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1306 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1307 | (* int list -> int *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1308 | |
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1309 | fun sum xs = foldl op+ 0 xs; | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1310 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1311 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1312 | (* product: returns the product of a list 'xs' of integers *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1313 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1314 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1315 | (* int list -> int *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1316 | |
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1317 | fun product xs = foldl op* 1 xs; | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1318 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1319 | (* ------------------------------------------------------------------------- *) | 
| 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: 
15531diff
changeset | 1320 | (* 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: 
15531diff
changeset | 1321 | (* 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: 
15531diff
changeset | 1322 | (* their arguments) of the size of the argument types *) | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1323 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1324 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1325 | (* 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: 
15334diff
changeset | 1326 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1327 | fun size_of_dtyp thy typ_sizes descr typ_assoc constructors = | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1328 | sum (map (fn (_, dtyps) => | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1329 | product (map (fn dtyp => | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1330 | let | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1331 | 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: 
15531diff
changeset | 1332 | 					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: 
15334diff
changeset | 1333 | in | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1334 | size_of_type i | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1335 | end) dtyps)) constructors); | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1336 | |
| 15292 | 1337 | |
| 1338 | (* ------------------------------------------------------------------------- *) | |
| 1339 | (* INTERPRETERS: Actual Interpreters *) | |
| 1340 | (* ------------------------------------------------------------------------- *) | |
| 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: 
14604diff
changeset | 1341 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1342 | (* 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: 
14604diff
changeset | 1343 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1344 | (* 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: 
14604diff
changeset | 1345 | (* 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: 
14604diff
changeset | 1346 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1347 | 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: 
14604diff
changeset | 1348 | 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: 
15531diff
changeset | 1349 | 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: 
15531diff
changeset | 1350 | 		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: 
14604diff
changeset | 1351 | (* 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: 
14604diff
changeset | 1352 | 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: 
14604diff
changeset | 1353 | 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: 
14604diff
changeset | 1354 | (* 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: 
14604diff
changeset | 1355 | 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: 
14604diff
changeset | 1356 | let | 
| 17314 | 1357 | val size = (if T = Term.propT then 2 else (the 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: 
15531diff
changeset | 1358 | 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: 
15531diff
changeset | 1359 | 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: 
14604diff
changeset | 1360 | (* 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: 
15531diff
changeset | 1361 | 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: 
14604diff
changeset | 1362 | (* 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: 
14604diff
changeset | 1363 | 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: 
14604diff
changeset | 1364 | (* 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: 
14604diff
changeset | 1365 | 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: 
14604diff
changeset | 1366 | | 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: 
14604diff
changeset | 1367 | (* 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: 
15531diff
changeset | 1368 | 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: 
14604diff
changeset | 1369 | 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: 
14604diff
changeset | 1370 | (* 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: 
15531diff
changeset | 1371 | 				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: 
14604diff
changeset | 1372 | 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: 
14604diff
changeset | 1373 | 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: 
14604diff
changeset | 1374 | 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: 
14604diff
changeset | 1375 | 			  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: 
14604diff
changeset | 1376 | 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: 
14604diff
changeset | 1377 | (* 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: 
14604diff
changeset | 1378 | (* 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: 
14604diff
changeset | 1379 | (* 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: 
15531diff
changeset | 1380 | 					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: 
14604diff
changeset | 1381 | (* 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: 
14604diff
changeset | 1382 | (* '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: 
14604diff
changeset | 1383 | (* '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: 
14604diff
changeset | 1384 | (* 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: 
14604diff
changeset | 1385 | 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: 
14604diff
changeset | 1386 | (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: 
14604diff
changeset | 1387 | | 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: 
14604diff
changeset | 1388 | 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: 
15531diff
changeset | 1389 | 							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: 
14604diff
changeset | 1390 | 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: 
14604diff
changeset | 1391 | 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: 
14604diff
changeset | 1392 | (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: 
14604diff
changeset | 1393 | 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: 
14604diff
changeset | 1394 | 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: 
14604diff
changeset | 1395 | (* 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: 
14604diff
changeset | 1396 | 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: 
14604diff
changeset | 1397 | 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: 
14604diff
changeset | 1398 | (* 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: 
15531diff
changeset | 1399 | 					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: 
14604diff
changeset | 1400 | 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: 
14604diff
changeset | 1401 | | 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: 
14604diff
changeset | 1402 | | 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: 
14604diff
changeset | 1403 | | 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: 
14604diff
changeset | 1404 | 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: 
14604diff
changeset | 1405 | in | 
| 17314 | 1406 | case AList.lookup (op =) terms t of | 
| 15531 | 1407 | 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: 
14604diff
changeset | 1408 | (* return an existing interpretation *) | 
| 15531 | 1409 | SOME (intr, model, args) | 
| 1410 | | 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: 
14604diff
changeset | 1411 | (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: 
14604diff
changeset | 1412 | 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: 
14604diff
changeset | 1413 | 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: 
14604diff
changeset | 1414 | | 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: 
14604diff
changeset | 1415 | 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: 
14604diff
changeset | 1416 | | 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: 
14604diff
changeset | 1417 | 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: 
14604diff
changeset | 1418 | | Bound i => | 
| 15570 | 1419 | 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: 
14604diff
changeset | 1420 | | 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: 
14604diff
changeset | 1421 | 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: 
14604diff
changeset | 1422 | (* 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: 
15531diff
changeset | 1423 | 					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: 
14604diff
changeset | 1424 | 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: 
14604diff
changeset | 1425 | (* 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: 
14604diff
changeset | 1426 | 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: 
15531diff
changeset | 1427 | (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: 
14604diff
changeset | 1428 | 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: 
14604diff
changeset | 1429 | (* 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: 
15531diff
changeset | 1430 | 								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: 
14604diff
changeset | 1431 | 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: 
14604diff
changeset | 1432 | (* 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: 
15531diff
changeset | 1433 | 								((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: 
14604diff
changeset | 1434 | 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: 
14604diff
changeset | 1435 | ((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: 
14604diff
changeset | 1436 | in | 
| 15531 | 1437 | 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: 
14604diff
changeset | 1438 | 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: 
14604diff
changeset | 1439 | | 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: 
14604diff
changeset | 1440 | 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: 
14604diff
changeset | 1441 | (* 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: 
14604diff
changeset | 1442 | 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: 
14604diff
changeset | 1443 | 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: 
14604diff
changeset | 1444 | 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: 
15531diff
changeset | 1445 | 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: 
14604diff
changeset | 1446 | 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: 
14604diff
changeset | 1447 | 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: 
14604diff
changeset | 1448 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1449 | (* 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: 
14604diff
changeset | 1450 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1451 | fun Pure_interpreter thy model args t = | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1452 | case t 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: 
14604diff
changeset | 1453 | 		  Const ("all", _) $ t1 =>  (* in the meta-logic, 'all' MUST be followed by an argument 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: 
14604diff
changeset | 1454 | 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: 
14604diff
changeset | 1455 | 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: 
14604diff
changeset | 1456 | 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: 
14604diff
changeset | 1457 | 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: 
14604diff
changeset | 1458 | 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: 
14604diff
changeset | 1459 | 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: 
14604diff
changeset | 1460 | 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: 
14604diff
changeset | 1461 | 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: 
14604diff
changeset | 1462 | in | 
| 15531 | 1463 | 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: 
14604diff
changeset | 1464 | 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: 
14604diff
changeset | 1465 | | _ => | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1466 | 					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: 
14604diff
changeset | 1467 | 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: 
14604diff
changeset | 1468 | 		| 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: 
14604diff
changeset | 1469 | 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: 
14604diff
changeset | 1470 | 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: 
14604diff
changeset | 1471 | 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: 
14604diff
changeset | 1472 | 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: 
15531diff
changeset | 1473 | (* 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: 
15531diff
changeset | 1474 | 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: 
14604diff
changeset | 1475 | 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: 
14604diff
changeset | 1476 | 		| Const ("==>", _) =>  (* simpler than translating 'Const ("==>", _) $ t1 $ t2' *)
 | 
| 15531 | 1477 | SOME (Node [Node [TT, FF], Node [TT, TT]], model, args) | 
| 1478 | | _ => 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: 
14604diff
changeset | 1479 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1480 | (* 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: 
14604diff
changeset | 1481 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1482 | 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: 
14604diff
changeset | 1483 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1484 | (* Providing interpretations directly is more efficient than unfolding the *) | 
| 15283 | 1485 | (* logical constants. In HOL however, logical constants can themselves be *) | 
| 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: 
14604diff
changeset | 1486 | (* arguments. "All" and "Ex" are then translated just like any other *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1487 | (* constant, with the relevant axiom being added by 'collect_axioms'. *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1488 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1489 | 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: 
14604diff
changeset | 1490 | 		  Const ("Trueprop", _) =>
 | 
| 15531 | 1491 | 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: 
14604diff
changeset | 1492 | 		| Const ("Not", _) =>
 | 
| 15531 | 1493 | 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: 
14604diff
changeset | 1494 | 		| Const ("True", _) =>  (* redundant, since 'True' is also an IDT constructor *)
 | 
| 15531 | 1495 | 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: 
14604diff
changeset | 1496 | 		| Const ("False", _) =>  (* redundant, since 'False' is also an IDT constructor *)
 | 
| 15531 | 1497 | SOME (FF, model, args) | 
| 15333 | 1498 | 		| Const ("All", _) $ t1 =>
 | 
| 1499 | (* if "All" occurs without an argument (i.e. as argument to a higher-order *) | |
| 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: 
15531diff
changeset | 1500 | (* function or predicate), it is handled by the 'stlc_interpreter' (i.e. *) | 
| 15333 | 1501 | (* by unfolding its definition) *) | 
| 14350 | 1502 | 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: 
14604diff
changeset | 1503 | 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: 
14604diff
changeset | 1504 | 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: 
14604diff
changeset | 1505 | 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: 
14604diff
changeset | 1506 | 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: 
14604diff
changeset | 1507 | 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: 
14604diff
changeset | 1508 | 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: 
14604diff
changeset | 1509 | 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: 
14604diff
changeset | 1510 | in | 
| 15531 | 1511 | 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: 
14604diff
changeset | 1512 | 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: 
14604diff
changeset | 1513 | | _ => | 
| 15292 | 1514 | 					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: 
14604diff
changeset | 1515 | end | 
| 15333 | 1516 | 		| Const ("Ex", _) $ t1 =>
 | 
| 1517 | (* if "Ex" occurs without an argument (i.e. as argument to a higher-order *) | |
| 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: 
15531diff
changeset | 1518 | (* function or predicate), it is handled by the 'stlc_interpreter' (i.e. *) | 
| 15333 | 1519 | (* by unfolding its definition) *) | 
| 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: 
14604diff
changeset | 1520 | 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: 
14604diff
changeset | 1521 | 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: 
14604diff
changeset | 1522 | 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: 
14604diff
changeset | 1523 | 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: 
14604diff
changeset | 1524 | 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: 
14604diff
changeset | 1525 | 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: 
14604diff
changeset | 1526 | 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: 
14604diff
changeset | 1527 | 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: 
14604diff
changeset | 1528 | in | 
| 15531 | 1529 | 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: 
14604diff
changeset | 1530 | 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: 
14604diff
changeset | 1531 | | _ => | 
| 15292 | 1532 | 					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: 
14604diff
changeset | 1533 | 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: 
14604diff
changeset | 1534 | 		| Const ("op =", _) $ 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: 
14604diff
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: 
14604diff
changeset | 1536 | 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: 
14604diff
changeset | 1537 | 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: 
14604diff
changeset | 1538 | in | 
| 15531 | 1539 | 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: 
14604diff
changeset | 1540 | 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: 
14604diff
changeset | 1541 | 		| Const ("op =", _) $ t1 =>
 | 
| 15531 | 1542 | 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: 
14604diff
changeset | 1543 | 		| Const ("op =", _) =>
 | 
| 15531 | 1544 | 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: 
15531diff
changeset | 1545 | 		| 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: 
15531diff
changeset | 1546 | (* 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: 
15531diff
changeset | 1547 | 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: 
15531diff
changeset | 1548 | 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: 
15531diff
changeset | 1549 | 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: 
15531diff
changeset | 1550 | 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: 
15531diff
changeset | 1551 | 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: 
15531diff
changeset | 1552 | 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: 
15531diff
changeset | 1553 | 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: 
15531diff
changeset | 1554 | 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: 
15531diff
changeset | 1555 | 		| 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: 
15531diff
changeset | 1556 | 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: 
14604diff
changeset | 1557 | 		| 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: 
15531diff
changeset | 1558 | SOME (interpret thy model args (eta_expand t 2)) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1559 | (* 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: 
15531diff
changeset | 1560 | 		| 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: 
15531diff
changeset | 1561 | (* 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: 
15531diff
changeset | 1562 | 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: 
15531diff
changeset | 1563 | 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: 
15531diff
changeset | 1564 | 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: 
15531diff
changeset | 1565 | 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: 
15531diff
changeset | 1566 | 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: 
15531diff
changeset | 1567 | 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: 
15531diff
changeset | 1568 | 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: 
15531diff
changeset | 1569 | 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: 
15531diff
changeset | 1570 | 		| 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: 
15531diff
changeset | 1571 | 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: 
14604diff
changeset | 1572 | 		| 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: 
15531diff
changeset | 1573 | SOME (interpret thy model args (eta_expand t 2)) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1574 | (* SOME (Node [Node [TT, TT], Node [TT, 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: 
15531diff
changeset | 1575 | 		| 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: 
15531diff
changeset | 1576 | (* 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: 
15531diff
changeset | 1577 | 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: 
15531diff
changeset | 1578 | 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: 
15531diff
changeset | 1579 | 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: 
15531diff
changeset | 1580 | 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: 
15531diff
changeset | 1581 | 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: 
15531diff
changeset | 1582 | 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: 
15531diff
changeset | 1583 | 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: 
15531diff
changeset | 1584 | 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: 
14604diff
changeset | 1585 | 		| 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: 
15531diff
changeset | 1586 | (* SOME (Node [Node [TT, FF], Node [TT, TT]], 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: 
15531diff
changeset | 1587 | SOME (interpret thy model args (eta_expand t 2)) | 
| 15531 | 1588 | | _ => 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: 
14604diff
changeset | 1589 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1590 | (* 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: 
14604diff
changeset | 1591 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1592 | 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: 
14604diff
changeset | 1593 | (* "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: 
14604diff
changeset | 1594 | 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: 
14604diff
changeset | 1595 | 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: 
14604diff
changeset | 1596 | in | 
| 17314 | 1597 | case AList.lookup (op =) terms t of | 
| 15531 | 1598 | 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: 
14604diff
changeset | 1599 | (* return an existing interpretation *) | 
| 15531 | 1600 | SOME (intr, model, args) | 
| 1601 | | 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: 
14604diff
changeset | 1602 | (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: 
14604diff
changeset | 1603 | 			  Free (x, Type ("set", [T])) =>
 | 
| 15334 
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
 webertj parents: 
15333diff
changeset | 1604 | 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: 
14604diff
changeset | 1605 | 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: 
14604diff
changeset | 1606 | in | 
| 15531 | 1607 | 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: 
15333diff
changeset | 1608 | end | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1609 | 			| 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: 
15333diff
changeset | 1610 | 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: 
14604diff
changeset | 1611 | 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: 
14604diff
changeset | 1612 | in | 
| 15531 | 1613 | 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: 
15333diff
changeset | 1614 | 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: 
14604diff
changeset | 1615 | 			| Const (s, Type ("set", [T])) =>
 | 
| 15334 
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
 webertj parents: 
15333diff
changeset | 1616 | 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: 
14604diff
changeset | 1617 | 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: 
14604diff
changeset | 1618 | in | 
| 15531 | 1619 | 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: 
15333diff
changeset | 1620 | 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: 
14604diff
changeset | 1621 | (* '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: 
14604diff
changeset | 1622 | 			| Const ("Collect", _) $ t1 =>
 | 
| 15531 | 1623 | 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: 
14604diff
changeset | 1624 | 			| Const ("Collect", _) =>
 | 
| 15531 | 1625 | 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: 
14604diff
changeset | 1626 | (* '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: 
14604diff
changeset | 1627 | 			| Const ("op :", _) $ t1 $ t2 =>
 | 
| 15531 | 1628 | 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: 
14604diff
changeset | 1629 | 			| Const ("op :", _) $ t1 =>
 | 
| 15531 | 1630 | 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: 
14604diff
changeset | 1631 | 			| Const ("op :", _) =>
 | 
| 15531 | 1632 | SOME (interpret thy model args (eta_expand t 2)) | 
| 1633 | | _ => 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: 
14604diff
changeset | 1634 | 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: 
14604diff
changeset | 1635 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1636 | (* 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: 
14604diff
changeset | 1637 | |
| 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: 
15531diff
changeset | 1638 | (* 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: 
15531diff
changeset | 1639 | (* 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: 
15531diff
changeset | 1640 | |
| 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: 
14604diff
changeset | 1641 | 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: 
14604diff
changeset | 1642 | 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: 
14604diff
changeset | 1643 | 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: 
14604diff
changeset | 1644 | (* 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: 
15531diff
changeset | 1645 | fun interpret_term (Type (s, Ts)) = | 
| 19346 | 1646 | (case DatatypePackage.get_datatype thy s of | 
| 15531 | 1647 | 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: 
14604diff
changeset | 1648 | 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: 
14604diff
changeset | 1649 | (* int option -- only recursive IDTs have an associated depth *) | 
| 17314 | 1650 | 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: 
14604diff
changeset | 1651 | in | 
| 15531 | 1652 | 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: 
14604diff
changeset | 1653 | (* return a leaf of size 0 *) | 
| 15531 | 1654 | 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: 
14604diff
changeset | 1655 | 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: 
14604diff
changeset | 1656 | 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: 
14604diff
changeset | 1657 | 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: 
14604diff
changeset | 1658 | val descr = #descr info | 
| 17314 | 1659 | val (_, dtyps, constrs) = (the 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: 
14604diff
changeset | 1660 | 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: 
14604diff
changeset | 1661 | (* 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: 
14604diff
changeset | 1662 | 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: 
14604diff
changeset | 1663 | 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: 
14604diff
changeset | 1664 | 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: 
14604diff
changeset | 1665 | 									raise REFUTE ("IDT_interpreter", "datatype argument (for type " ^ Sign.string_of_typ (sign_of thy) (Type (s, Ts)) ^ ") is not a variable")
 | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1666 | 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: 
14604diff
changeset | 1667 | ()) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1668 | (* if the model specifies a depth for the current type, decrement it to avoid infinite recursion *) | 
| 17314 | 1669 | val typs' = case depth of NONE => typs | SOME n => | 
| 1670 | 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: 
14604diff
changeset | 1671 | (* recursively compute the size of the datatype *) | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1672 | 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: 
14604diff
changeset | 1673 | 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: 
15531diff
changeset | 1674 | 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: 
14604diff
changeset | 1675 | 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: 
14604diff
changeset | 1676 | (* 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: 
15531diff
changeset | 1677 | 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: 
14604diff
changeset | 1678 | (* 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: 
14604diff
changeset | 1679 | 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: 
14604diff
changeset | 1680 | (* 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: 
14604diff
changeset | 1681 | 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: 
14604diff
changeset | 1682 | | 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: 
14604diff
changeset | 1683 | (* 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: 
15531diff
changeset | 1684 | 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: 
14604diff
changeset | 1685 | 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: 
14604diff
changeset | 1686 | (* 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: 
15531diff
changeset | 1687 | 							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: 
14604diff
changeset | 1688 | 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: 
14604diff
changeset | 1689 | end | 
| 15531 | 1690 | | NONE => (* not an inductive datatype *) | 
| 1691 | 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: 
15531diff
changeset | 1692 | | interpret_term _ = (* a (free or schematic) type variable *) | 
| 15531 | 1693 | 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: 
14604diff
changeset | 1694 | in | 
| 17314 | 1695 | case AList.lookup (op =) terms t of | 
| 15531 | 1696 | 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: 
14604diff
changeset | 1697 | (* return an existing interpretation *) | 
| 15531 | 1698 | SOME (intr, model, args) | 
| 1699 | | 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: 
14604diff
changeset | 1700 | (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: 
15531diff
changeset | 1701 | 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: 
15531diff
changeset | 1702 | | 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: 
15531diff
changeset | 1703 | | 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: 
15531diff
changeset | 1704 | | _ => 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: 
15531diff
changeset | 1705 | 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: 
15531diff
changeset | 1706 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1707 | (* 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: 
15531diff
changeset | 1708 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1709 | 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: 
15531diff
changeset | 1710 | 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: 
15531diff
changeset | 1711 | 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: 
15531diff
changeset | 1712 | in | 
| 17314 | 1713 | 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: 
15531diff
changeset | 1714 | 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: 
15531diff
changeset | 1715 | (* 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: 
15531diff
changeset | 1716 | 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: 
15531diff
changeset | 1717 | | 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: 
15531diff
changeset | 1718 | (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: 
15531diff
changeset | 1719 | 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: 
15531diff
changeset | 1720 | (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: 
15531diff
changeset | 1721 | Type (s', Ts') => | 
| 19346 | 1722 | (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: 
15531diff
changeset | 1723 | 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: 
15531diff
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: 
15531diff
changeset | 1725 | 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: 
15531diff
changeset | 1726 | val descr = #descr info | 
| 17314 | 1727 | val (_, dtyps, constrs) = (the 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: 
15531diff
changeset | 1728 | 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: 
15531diff
changeset | 1729 | (* 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: 
15531diff
changeset | 1730 | 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: 
15531diff
changeset | 1731 | 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: 
15531diff
changeset | 1732 | 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: 
15531diff
changeset | 1733 | 									raise REFUTE ("IDT_constructor_interpreter", "datatype argument (for type " ^ Sign.string_of_typ (sign_of thy) (Type (s', Ts')) ^ ") is not a 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: 
15531diff
changeset | 1734 | 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: 
15531diff
changeset | 1735 | ()) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1736 | (* 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: 
15531diff
changeset | 1737 | val (constrs1, constrs2) = take_prefix (fn (cname, ctypes) => | 
| 16935 | 1738 | 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: 
15531diff
changeset | 1739 | 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: 
15531diff
changeset | 1740 | 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: 
15531diff
changeset | 1741 | 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: 
15531diff
changeset | 1742 | [] => | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1743 | (* '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: 
15531diff
changeset | 1744 | 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: 
15531diff
changeset | 1745 | | (_, 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: 
14604diff
changeset | 1746 | 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: 
15531diff
changeset | 1747 | (* 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: 
15531diff
changeset | 1748 | 									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: 
15531diff
changeset | 1749 | 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: 
15531diff
changeset | 1750 | (* int option -- only recursive IDTs have an associated depth *) | 
| 17314 | 1751 | val depth = AList.lookup (op =) typs (Type (s', Ts')) | 
| 1752 | val typs' = (case depth of NONE => typs | SOME n => | |
| 1753 | AList.update (op =) (Type (s', Ts'), n-1) typs) | |
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1754 | (* 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: 
15531diff
changeset | 1755 | (* 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: 
15531diff
changeset | 1756 | 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: 
15531diff
changeset | 1757 | 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: 
15531diff
changeset | 1758 | | 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: 
15531diff
changeset | 1759 | 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: 
15531diff
changeset | 1760 | (* 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: 
15531diff
changeset | 1761 | 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: 
15531diff
changeset | 1762 | 											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: 
15531diff
changeset | 1763 | 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: 
15531diff
changeset | 1764 | 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: 
15531diff
changeset | 1765 | 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: 
15531diff
changeset | 1766 | 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: 
15531diff
changeset | 1767 | (* 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: 
15531diff
changeset | 1768 | (* 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: 
15531diff
changeset | 1769 | 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: 
15531diff
changeset | 1770 | 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: 
15531diff
changeset | 1771 | (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: 
14604diff
changeset | 1772 | 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: 
15531diff
changeset | 1773 | 											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: 
15531diff
changeset | 1774 | | 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: 
14604diff
changeset | 1775 | 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: 
15531diff
changeset | 1776 | (* 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: 
15531diff
changeset | 1777 | 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: 
15531diff
changeset | 1778 | 											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: 
15531diff
changeset | 1779 | 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: 
15531diff
changeset | 1780 | 											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: 
15531diff
changeset | 1781 | 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: 
15531diff
changeset | 1782 | (* 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: 
15531diff
changeset | 1783 | 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: 
15531diff
changeset | 1784 | 													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: 
14604diff
changeset | 1785 | 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: 
15531diff
changeset | 1786 | () | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1787 | (* 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: 
15531diff
changeset | 1788 | 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: 
15531diff
changeset | 1789 | (* 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: 
15531diff
changeset | 1790 | 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: 
15531diff
changeset | 1791 | in | 
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1792 | (* elements that exist at the previous depth are mapped to a defined *) | 
| 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1793 | (* value, while new elements are mapped to "undefined" by the *) | 
| 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1794 | (* 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: 
15531diff
changeset | 1795 | (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: 
15531diff
changeset | 1796 | 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: 
15531diff
changeset | 1797 | (* 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: 
15531diff
changeset | 1798 | (* 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: 
15531diff
changeset | 1799 | (* 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: 
15531diff
changeset | 1800 | 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: 
15531diff
changeset | 1801 | 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: 
15531diff
changeset | 1802 | (* 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: 
15531diff
changeset | 1803 | (* int * int -> interpretation *) | 
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1804 | 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: 
15531diff
changeset | 1805 | 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: 
15531diff
changeset | 1806 | (* 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: 
15531diff
changeset | 1807 | 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: 
14604diff
changeset | 1808 | 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: 
15531diff
changeset | 1809 | 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: 
15531diff
changeset | 1810 | (* 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: 
15531diff
changeset | 1811 | (* 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: 
15531diff
changeset | 1812 | (* 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: 
15531diff
changeset | 1813 | (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: 
15531diff
changeset | 1814 | 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: 
15531diff
changeset | 1815 | (* 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: 
15531diff
changeset | 1816 | (* to the same value again, just extend the length of the leaf, *) | 
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1817 | (* 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: 
15531diff
changeset | 1818 | (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: 
15531diff
changeset | 1819 | 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: 
15531diff
changeset | 1820 | | 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: 
15531diff
changeset | 1821 | 										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: 
15531diff
changeset | 1822 | | 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: 
15531diff
changeset | 1823 | 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: 
15531diff
changeset | 1824 | (* 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: 
15531diff
changeset | 1825 | 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: 
15531diff
changeset | 1826 | 											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: 
15531diff
changeset | 1827 | 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: 
15531diff
changeset | 1828 | (* 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: 
15531diff
changeset | 1829 | 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: 
15531diff
changeset | 1830 | 													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: 
15531diff
changeset | 1831 | 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: 
15531diff
changeset | 1832 | () | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1833 | (* 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: 
15531diff
changeset | 1834 | (* 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: 
15531diff
changeset | 1835 | 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: 
15531diff
changeset | 1836 | (* 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: 
15531diff
changeset | 1837 | 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: 
15531diff
changeset | 1838 | 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: 
15531diff
changeset | 1839 | (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: 
15531diff
changeset | 1840 | 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: 
15531diff
changeset | 1841 | | 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: 
15531diff
changeset | 1842 | 										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: 
15531diff
changeset | 1843 | (* 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: 
15531diff
changeset | 1844 | (* 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: 
15531diff
changeset | 1845 | 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: 
15531diff
changeset | 1846 | Library.exists DatatypeAux.is_rec_type ds | 
| 15611 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1847 | (* constructors before 'Const (s, T)' generate elements of the datatype *) | 
| 
c01f11cd08f9
Bugfix related to the interpretation of IDT constructors
 webertj parents: 
15574diff
changeset | 1848 | 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: 
15531diff
changeset | 1849 | 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: 
15531diff
changeset | 1850 | 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: 
15531diff
changeset | 1851 | 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: 
15531diff
changeset | 1852 | 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: 
15531diff
changeset | 1853 | | 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: 
15531diff
changeset | 1854 | 										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: 
15531diff
changeset | 1855 | | 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: 
15531diff
changeset | 1856 | 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: 
15531diff
changeset | 1857 | | 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: 
15531diff
changeset | 1858 | 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: 
15531diff
changeset | 1859 | (* 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: 
15531diff
changeset | 1860 | 											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: 
15531diff
changeset | 1861 | (* 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: 
15531diff
changeset | 1862 | (* 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: 
15531diff
changeset | 1863 | 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: 
15531diff
changeset | 1864 | 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: 
15531diff
changeset | 1865 | | 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: 
15531diff
changeset | 1866 | 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: 
15531diff
changeset | 1867 | (* 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: 
15531diff
changeset | 1868 | 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: 
15531diff
changeset | 1869 | 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: 
15531diff
changeset | 1870 | 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: 
14604diff
changeset | 1871 | 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: 
14604diff
changeset | 1872 | 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: 
15531diff
changeset | 1873 | 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: 
15531diff
changeset | 1874 | | 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: 
15531diff
changeset | 1875 | 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: 
15531diff
changeset | 1876 | | _ => (* 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: 
15531diff
changeset | 1877 | 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: 
15531diff
changeset | 1878 | | _ => (* 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: 
15531diff
changeset | 1879 | 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: 
14604diff
changeset | 1880 | 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: 
14604diff
changeset | 1881 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1882 | (* 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: 
14604diff
changeset | 1883 | |
| 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: 
15531diff
changeset | 1884 | (* 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: 
15531diff
changeset | 1885 | (* 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: 
15531diff
changeset | 1886 | (* 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: 
15531diff
changeset | 1887 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1888 | 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: 
15531diff
changeset | 1889 | 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: 
15531diff
changeset | 1890 | (* 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: 
15531diff
changeset | 1891 | (* 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: 
15531diff
changeset | 1892 | (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: 
15531diff
changeset | 1893 | (* iterate over all datatypes in 'thy' *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1894 | Symtab.foldl (fn (result, (_, 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: 
15531diff
changeset | 1895 | 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: 
15531diff
changeset | 1896 | 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: 
15531diff
changeset | 1897 | 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: 
15531diff
changeset | 1898 | | 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: 
15531diff
changeset | 1899 | if s mem (#rec_names info) then | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1900 | (* we do have a recursion operator of the datatype given by 'info', *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1901 | (* 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: 
15531diff
changeset | 1902 | let | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1903 | val index = #index info | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1904 | val descr = #descr info | 
| 17314 | 1905 | val (dtname, dtyps, _) = (the o AList.lookup (op =) descr) index | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1906 | (* number of all constructors, including those of different *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1907 | (* (mutually recursive) datatypes within the same descriptor 'descr' *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1908 | val mconstrs_count = sum (map (fn (_, (_, _, cs)) => length cs) descr) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1909 | val params_count = length params | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1910 | (* the type of a recursion operator: [T1, ..., Tn, IDT] ---> Tresult *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1911 | 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: 
15531diff
changeset | 1912 | in | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1913 | if (fst o dest_Type) IDT <> dtname then | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1914 | (* recursion operator of a mutually recursive datatype *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1915 | NONE | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1916 | 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: 
15531diff
changeset | 1917 | (* 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: 
15531diff
changeset | 1918 | (* '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: 
15531diff
changeset | 1919 | NONE | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1920 | 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: 
15531diff
changeset | 1921 | (* 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: 
15531diff
changeset | 1922 | (* 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: 
15531diff
changeset | 1923 | (* 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: 
15531diff
changeset | 1924 | (* the argument types and the size of the IDT, of course). *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1925 | SOME (interpret thy model args (eta_expand t (mconstrs_count - params_count))) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1926 | 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: 
15531diff
changeset | 1927 | 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: 
15531diff
changeset | 1928 | (* 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: 
15531diff
changeset | 1929 | 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: 
15531diff
changeset | 1930 | 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: 
15531diff
changeset | 1931 | 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: 
15531diff
changeset | 1932 | 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: 
15531diff
changeset | 1933 | ((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: 
15531diff
changeset | 1934 | end) ((model, args), params) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1935 | 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: 
15531diff
changeset | 1936 | val typ_assoc = dtyps ~~ (snd o dest_Type) IDT | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1937 | (* interpret each constructor in the descriptor (including *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1938 | (* those of mutually recursive datatypes) *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1939 | (* (int * interpretation list) list *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1940 | val mc_intrs = map (fn (idx, (_, _, cs)) => | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1941 | let | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1942 | val c_return_typ = typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec idx) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1943 | in | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1944 | (idx, map (fn (cname, cargs) => | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1945 | 												(#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: 
15611diff
changeset | 1946 | (Const (cname, map (typ_of_dtyp descr typ_assoc) cargs ---> c_return_typ))) cs) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1947 | 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: 
15531diff
changeset | 1948 | (* the recursion operator is a function that maps every element of *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1949 | (* the inductive datatype (and of mutually recursive types) to an *) | 
| 15783 | 1950 | (* element of some result type; an array entry of NONE means that *) | 
| 1951 | (* the actual result has not been computed yet *) | |
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1952 | (* (int * interpretation option Array.array) list *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1953 | val INTRS = map (fn (idx, _) => | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1954 | let | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1955 | val T = typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec idx) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1956 | 											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: 
15611diff
changeset | 1957 | val size = size_of_type i | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1958 | in | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1959 | (idx, Array.array (size, NONE)) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1960 | end) descr | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1961 | (* takes an interpretation, and if some leaf of this interpretation *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1962 | (* is the 'elem'-th element of the type, the indices of the arguments *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1963 | (* 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: 
15531diff
changeset | 1964 | (* 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: 
15531diff
changeset | 1965 | 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: 
15531diff
changeset | 1966 | 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: 
15531diff
changeset | 1967 | 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: 
15531diff
changeset | 1968 | 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: 
15531diff
changeset | 1969 | 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: 
15531diff
changeset | 1970 | | 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: 
15531diff
changeset | 1971 | 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: 
15531diff
changeset | 1972 | (* 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: 
15531diff
changeset | 1973 | 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: 
15531diff
changeset | 1974 | 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: 
15531diff
changeset | 1975 | | 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: 
15531diff
changeset | 1976 | (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: 
15531diff
changeset | 1977 | 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: 
15531diff
changeset | 1978 | | 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: 
15531diff
changeset | 1979 | 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: 
15531diff
changeset | 1980 | 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: 
15531diff
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: 
15531diff
changeset | 1982 | (* 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: 
15531diff
changeset | 1983 | (* arguments that generate the 'elem'-th element of the datatype *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1984 | (* given by 'idx' *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1985 | (* int -> int -> int * int list *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1986 | 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: 
15531diff
changeset | 1987 | 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: 
15531diff
changeset | 1988 | (* 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: 
15531diff
changeset | 1989 | fun get_cargs_rec (_, []) = | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1990 | 												raise REFUTE ("IDT_recursion_interpreter", "no matching constructor found for element " ^ string_of_int elem ^ " in datatype " ^ Sign.string_of_typ (sign_of 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: 
15531diff
changeset | 1991 | | 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: 
15531diff
changeset | 1992 | (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: 
15531diff
changeset | 1993 | 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: 
15531diff
changeset | 1994 | | 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: 
15531diff
changeset | 1995 | in | 
| 17314 | 1996 | get_cargs_rec (0, (the 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: 
15531diff
changeset | 1997 | end | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1998 | (* returns the number of constructors in datatypes that occur in *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 1999 | (* the descriptor 'descr' before the datatype given by 'idx' *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2000 | fun get_coffset idx = | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2001 | let | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2002 | fun get_coffset_acc _ [] = | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2003 | 												raise REFUTE ("IDT_recursion_interpreter", "index " ^ string_of_int idx ^ " not found in descriptor")
 | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2004 | | get_coffset_acc sum ((i, (_, _, cs))::descr') = | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2005 | if i=idx then | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2006 | sum | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2007 | else | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2008 | get_coffset_acc (sum + length cs) descr' | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2009 | in | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2010 | get_coffset_acc 0 descr | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2011 | end | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2012 | (* computes one entry in INTRS, and recursively all entries needed for it, *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2013 | (* where 'idx' gives the datatype and 'elem' the element of it *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2014 | (* int -> int -> interpretation *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2015 | fun compute_array_entry idx elem = | 
| 17314 | 2016 | case Array.sub ((the o AList.lookup (op =) INTRS) idx, elem) of | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2017 | SOME result => | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2018 | (* simply return the previously computed result *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2019 | result | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2020 | | 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: 
15531diff
changeset | 2021 | 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: 
15531diff
changeset | 2022 | (* int * int list *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2023 | 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: 
15531diff
changeset | 2024 | (* 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: 
15531diff
changeset | 2025 | 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: 
15531diff
changeset | 2026 | 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: 
15531diff
changeset | 2027 | | 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: 
15531diff
changeset | 2028 | 													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: 
15531diff
changeset | 2029 | | select_subtree (Node tr, x::xs) = | 
| 15570 | 2030 | 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: 
15531diff
changeset | 2031 | (* select the correct subtree of the parameter corresponding to constructor 'c' *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2032 | val p_intr = select_subtree (List.nth (p_intrs, get_coffset idx + c), args) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2033 | (* find the indices of the constructor's recursive arguments *) | 
| 17314 | 2034 | val (_, _, constrs) = (the o AList.lookup (op =) descr) idx | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2035 | val constr_args = (snd o List.nth) (constrs, c) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2036 | val rec_args = List.filter (DatatypeAux.is_rec_type o fst) (constr_args ~~ args) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2037 | 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: 
15531diff
changeset | 2038 | (* apply 'p_intr' to recursively computed results *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2039 | val result = foldl (fn ((idx, elem), intr) => | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2040 | 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: 
15531diff
changeset | 2041 | (* update 'INTRS' *) | 
| 17314 | 2042 | val _ = Array.update ((the 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: 
15531diff
changeset | 2043 | in | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2044 | 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: 
15531diff
changeset | 2045 | end | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2046 | (* compute all entries in INTRS for the current datatype (given by 'index') *) | 
| 15783 | 2047 | (* TODO: we can use Array.modify instead once PolyML conforms to the ML standard *) | 
| 2048 | (* (int * 'a -> 'a) -> 'a array -> unit *) | |
| 2049 | fun modifyi f arr = | |
| 2050 | let | |
| 2051 | val size = Array.length arr | |
| 2052 | fun modifyi_loop i = | |
| 2053 | if i < size then ( | |
| 2054 | Array.update (arr, i, f (i, Array.sub (arr, i))); | |
| 2055 | modifyi_loop (i+1) | |
| 2056 | ) else | |
| 2057 | () | |
| 2058 | in | |
| 2059 | modifyi_loop 0 | |
| 2060 | end | |
| 17314 | 2061 | val _ = modifyi (fn (i, _) => SOME (compute_array_entry index i)) ((the 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: 
15531diff
changeset | 2062 | (* '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: 
15531diff
changeset | 2063 | 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: 
15531diff
changeset | 2064 | 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: 
15531diff
changeset | 2065 | in | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2066 | (* return the part of 'INTRS' that corresponds to the current datatype *) | 
| 17314 | 2067 | SOME ((Node o map the o toList o the 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: 
15531diff
changeset | 2068 | 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: 
15531diff
changeset | 2069 | 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: 
15531diff
changeset | 2070 | 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: 
15531diff
changeset | 2071 | NONE (* not a recursion operator 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: 
15531diff
changeset | 2072 | ) (NONE, DatatypePackage.get_datatypes thy) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2073 | | _ => (* 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: 
15531diff
changeset | 2074 | 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: 
15531diff
changeset | 2075 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2076 | (* 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: 
15531diff
changeset | 2077 | |
| 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: 
14604diff
changeset | 2078 | (* 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: 
14604diff
changeset | 2079 | (* 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: 
15531diff
changeset | 2080 | (* 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: 
14604diff
changeset | 2081 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2082 | 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: 
14604diff
changeset | 2083 | 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: 
14604diff
changeset | 2084 | 		  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: 
14604diff
changeset | 2085 | 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: 
15531diff
changeset | 2086 | 				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: 
14604diff
changeset | 2087 | 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: 
15531diff
changeset | 2088 | 				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: 
14604diff
changeset | 2089 | 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: 
14604diff
changeset | 2090 | (* 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: 
14604diff
changeset | 2091 | fun number_of_elements (Node xs) = | 
| 15570 | 2092 | 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: 
15531diff
changeset | 2093 | 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: 
15531diff
changeset | 2094 | 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: 
15531diff
changeset | 2095 | 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: 
15531diff
changeset | 2096 | 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: 
15531diff
changeset | 2097 | 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: 
15531diff
changeset | 2098 | 							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: 
14604diff
changeset | 2099 | | 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: 
14604diff
changeset | 2100 | 					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: 
14604diff
changeset | 2101 | (* 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: 
14604diff
changeset | 2102 | (* 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: 
14604diff
changeset | 2103 | 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: 
14604diff
changeset | 2104 | 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: 
14604diff
changeset | 2105 | 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: 
14604diff
changeset | 2106 | 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: 
14604diff
changeset | 2107 | 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: 
14604diff
changeset | 2108 | 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: 
14351diff
changeset | 2109 | 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: 
14604diff
changeset | 2110 | 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: 
14604diff
changeset | 2111 | end | 
| 14350 | 2112 | in | 
| 15531 | 2113 | SOME (Node (map card constants), model, args) | 
| 14350 | 2114 | 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: 
14604diff
changeset | 2115 | | _ => | 
| 15531 | 2116 | 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: 
14604diff
changeset | 2117 | |
| 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: 
15531diff
changeset | 2118 | (* 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: 
15531diff
changeset | 2119 | |
| 15571 | 2120 | (* only an optimization: 'Finites' could in principle be interpreted with *) | 
| 2121 | (* interpreters available already (using its definition), but the code *) | |
| 2122 | (* below is more efficient *) | |
| 2123 | ||
| 2124 | fun Finite_Set_Finites_interpreter thy model args t = | |
| 2125 | case t of | |
| 2126 | 		  Const ("Finite_Set.Finites", Type ("set", [Type ("set", [T])])) =>
 | |
| 2127 | let | |
| 2128 | 				val (i_set, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T])))
 | |
| 2129 | val size_set = size_of_type i_set | |
| 2130 | in | |
| 2131 | (* we only consider finite models anyway, hence EVERY set is in "Finites" *) | |
| 2132 | SOME (Node (replicate size_set TT), model, args) | |
| 2133 | end | |
| 2134 | | _ => | |
| 2135 | NONE; | |
| 2136 | ||
| 2137 | (* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) | |
| 2138 | ||
| 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: 
15531diff
changeset | 2139 | (* 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: 
15531diff
changeset | 2140 | (* 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: 
15531diff
changeset | 2141 | (* 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: 
15531diff
changeset | 2142 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2143 | 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: 
15531diff
changeset | 2144 | case t of | 
| 19277 | 2145 | 		  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: 
15531diff
changeset | 2146 | 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: 
15531diff
changeset | 2147 | 				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: 
15531diff
changeset | 2148 | 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: 
15531diff
changeset | 2149 | (* 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: 
15531diff
changeset | 2150 | (* 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: 
15531diff
changeset | 2151 | (* 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: 
15531diff
changeset | 2152 | 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: 
15531diff
changeset | 2153 | 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: 
15531diff
changeset | 2154 | 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: 
15531diff
changeset | 2155 | 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: 
15531diff
changeset | 2156 | | _ => | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2157 | 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: 
15531diff
changeset | 2158 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2159 | (* 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: 
15531diff
changeset | 2160 | |
| 19233 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
18932diff
changeset | 2161 | (* 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: 
15531diff
changeset | 2162 | (* 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: 
15531diff
changeset | 2163 | (* 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: 
15531diff
changeset | 2164 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2165 | 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: 
15531diff
changeset | 2166 | case t of | 
| 19233 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
18932diff
changeset | 2167 | 		  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: 
15531diff
changeset | 2168 | 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: 
15531diff
changeset | 2169 | 				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: 
15531diff
changeset | 2170 | 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: 
15531diff
changeset | 2171 | (* int -> int -> interpretation *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2172 | fun plus m n = | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2173 | 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: 
15531diff
changeset | 2174 | 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: 
15531diff
changeset | 2175 | 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: 
15531diff
changeset | 2176 | 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: 
15531diff
changeset | 2177 | 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: 
15531diff
changeset | 2178 | 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: 
15531diff
changeset | 2179 | 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: 
15531diff
changeset | 2180 | 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: 
15531diff
changeset | 2181 | 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: 
15531diff
changeset | 2182 | 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: 
15531diff
changeset | 2183 | 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: 
15531diff
changeset | 2184 | | _ => | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2185 | 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: 
15531diff
changeset | 2186 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2187 | (* 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: 
15531diff
changeset | 2188 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2189 | (* 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: 
15531diff
changeset | 2190 | (* 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: 
15531diff
changeset | 2191 | (* 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: 
15531diff
changeset | 2192 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2193 | 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: 
15531diff
changeset | 2194 | case t of | 
| 19233 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
18932diff
changeset | 2195 | 		  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: 
15531diff
changeset | 2196 | 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: 
15531diff
changeset | 2197 | 				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: 
15531diff
changeset | 2198 | 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: 
15531diff
changeset | 2199 | (* int -> int -> interpretation *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2200 | fun minus m n = | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2201 | 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: 
15531diff
changeset | 2202 | 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: 
15531diff
changeset | 2203 | 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: 
15531diff
changeset | 2204 | 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: 
15531diff
changeset | 2205 | 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: 
15531diff
changeset | 2206 | 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: 
15531diff
changeset | 2207 | 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: 
15531diff
changeset | 2208 | 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: 
15531diff
changeset | 2209 | | _ => | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2210 | 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: 
15531diff
changeset | 2211 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2212 | (* 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: 
15531diff
changeset | 2213 | |
| 19233 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
18932diff
changeset | 2214 | (* 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: 
18932diff
changeset | 2215 | (* interpreters available already (using its definition), but the code *) | 
| 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
18932diff
changeset | 2216 | (* 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: 
15531diff
changeset | 2217 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2218 | 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: 
15531diff
changeset | 2219 | case t of | 
| 19233 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
18932diff
changeset | 2220 | 		  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: 
15531diff
changeset | 2221 | 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: 
15531diff
changeset | 2222 | 				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: 
15531diff
changeset | 2223 | 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: 
15531diff
changeset | 2224 | (* nat -> nat -> interpretation *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2225 | fun mult m n = | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2226 | 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: 
15531diff
changeset | 2227 | 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: 
15531diff
changeset | 2228 | 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: 
15531diff
changeset | 2229 | 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: 
15531diff
changeset | 2230 | 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: 
15531diff
changeset | 2231 | 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: 
15531diff
changeset | 2232 | 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: 
15531diff
changeset | 2233 | 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: 
15531diff
changeset | 2234 | 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: 
15531diff
changeset | 2235 | 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: 
15531diff
changeset | 2236 | 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: 
15531diff
changeset | 2237 | | _ => | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2238 | 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: 
15531diff
changeset | 2239 | |
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2240 | (* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2241 | |
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2242 | (* only an optimization: 'op @' could in principle be interpreted with *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2243 | (* interpreters available already (using its definition), but the code *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2244 | (* below is more efficient *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2245 | |
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2246 | fun List_append_interpreter thy model args t = | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2247 | case t of | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2248 | 		  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: 
15611diff
changeset | 2249 | let | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2250 | 				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: 
15611diff
changeset | 2251 | val size_elem = size_of_type i_elem | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2252 | 				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: 
15611diff
changeset | 2253 | val size_list = size_of_type i_list | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2254 | (* power (a, b) computes a^b, for a>=0, b>=0 *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2255 | (* int * int -> int *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2256 | fun power (a, 0) = 1 | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2257 | | power (a, 1) = a | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2258 | | 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: 
15611diff
changeset | 2259 | (* 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: 
15611diff
changeset | 2260 | (* int * int -> int *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2261 | fun log (a, b) = | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2262 | let | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2263 | fun logloop (ax, x) = | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2264 | if ax > b then x-1 else logloop (a * ax, x+1) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2265 | in | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2266 | logloop (1, 0) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2267 | end | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2268 | (* nat -> nat -> interpretation *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2269 | fun append m n = | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2270 | let | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2271 | (* The following formula depends on the order in which lists are *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2272 | (* enumerated by the 'IDT_constructor_interpreter'. It took me *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2273 | (* a while to come up with this formula. *) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2274 | 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: 
15611diff
changeset | 2275 | in | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2276 | if element > size_list then | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2277 | Leaf (replicate size_list False) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2278 | else | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2279 | Leaf ((replicate (element-1) False) @ True :: (replicate (size_list - element) False)) | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2280 | end | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2281 | in | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2282 | 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: 
15611diff
changeset | 2283 | end | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2284 | | _ => | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2285 | NONE; | 
| 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2286 | |
| 16050 | 2287 | (* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) | 
| 2288 | ||
| 2289 | (* only an optimization: 'lfp' could in principle be interpreted with *) | |
| 2290 | (* interpreters available already (using its definition), but the code *) | |
| 2291 | (* below is more efficient *) | |
| 2292 | ||
| 2293 | fun Lfp_lfp_interpreter thy model args t = | |
| 2294 | case t of | |
| 2295 | 		  Const ("Lfp.lfp", Type ("fun", [Type ("fun", [Type ("set", [T]), Type ("set", [_])]), Type ("set", [_])])) =>
 | |
| 2296 | let | |
| 2297 | 				val (i_elem, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
 | |
| 2298 | val size_elem = size_of_type i_elem | |
| 2299 | (* the universe (i.e. the set that contains every element) *) | |
| 2300 | val i_univ = Node (replicate size_elem TT) | |
| 2301 | (* all sets with elements from type 'T' *) | |
| 2302 | 				val (i_set, _, _)  = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T])))
 | |
| 2303 | val i_sets = make_constants i_set | |
| 2304 | (* all functions that map sets to sets *) | |
| 2305 | 				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])])))
 | |
| 2306 | val i_funs = make_constants i_fun | |
| 2307 | 				(* "lfp(f) == Inter({u. f(u) <= u})" *)
 | |
| 2308 | (* interpretation * interpretation -> bool *) | |
| 2309 | fun is_subset (Node subs, Node sups) = | |
| 2310 | List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) (subs ~~ sups) | |
| 2311 | | is_subset (_, _) = | |
| 2312 | 					raise REFUTE ("Lfp_lfp_interpreter", "is_subset: interpretation for set is not a node")
 | |
| 2313 | (* interpretation * interpretation -> interpretation *) | |
| 2314 | fun intersection (Node xs, Node ys) = | |
| 2315 | Node (map (fn (x, y) => if (x = TT) andalso (y = TT) then TT else FF) (xs ~~ ys)) | |
| 2316 | | intersection (_, _) = | |
| 2317 | 					raise REFUTE ("Lfp_lfp_interpreter", "intersection: interpretation for set is not a node")
 | |
| 2318 | (* interpretation -> interpretaion *) | |
| 2319 | fun lfp (Node resultsets) = | |
| 2320 | foldl (fn ((set, resultset), acc) => | |
| 2321 | if is_subset (resultset, set) then | |
| 2322 | intersection (acc, set) | |
| 2323 | else | |
| 2324 | acc) i_univ (i_sets ~~ resultsets) | |
| 2325 | | lfp _ = | |
| 2326 | 						raise REFUTE ("Lfp_lfp_interpreter", "lfp: interpretation for function is not a node")
 | |
| 2327 | in | |
| 2328 | SOME (Node (map lfp i_funs), model, args) | |
| 2329 | end | |
| 2330 | | _ => | |
| 2331 | NONE; | |
| 2332 | ||
| 2333 | (* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *) | |
| 2334 | ||
| 2335 | (* only an optimization: 'gfp' could in principle be interpreted with *) | |
| 2336 | (* interpreters available already (using its definition), but the code *) | |
| 2337 | (* below is more efficient *) | |
| 2338 | ||
| 2339 | fun Gfp_gfp_interpreter thy model args t = | |
| 2340 | case t of | |
| 2341 | 		  Const ("Gfp.gfp", Type ("fun", [Type ("fun", [Type ("set", [T]), Type ("set", [_])]), Type ("set", [_])])) =>
 | |
| 16073 | 2342 | let nonfix union (*because "union" is used below*) | 
| 16050 | 2343 | 				val (i_elem, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
 | 
| 2344 | val size_elem = size_of_type i_elem | |
| 2345 | (* the universe (i.e. the set that contains every element) *) | |
| 2346 | val i_univ = Node (replicate size_elem TT) | |
| 2347 | (* all sets with elements from type 'T' *) | |
| 2348 | 				val (i_set, _, _)  = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T])))
 | |
| 2349 | val i_sets = make_constants i_set | |
| 2350 | (* all functions that map sets to sets *) | |
| 2351 | 				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])])))
 | |
| 2352 | val i_funs = make_constants i_fun | |
| 2353 | 				(* "gfp(f) == Union({u. u <= f(u)})" *)
 | |
| 2354 | (* interpretation * interpretation -> bool *) | |
| 2355 | fun is_subset (Node subs, Node sups) = | |
| 2356 | List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) (subs ~~ sups) | |
| 2357 | | is_subset (_, _) = | |
| 2358 | 					raise REFUTE ("Gfp_gfp_interpreter", "is_subset: interpretation for set is not a node")
 | |
| 2359 | (* interpretation * interpretation -> interpretation *) | |
| 2360 | fun union (Node xs, Node ys) = | |
| 16073 | 2361 | Node (map (fn (x,y) => if x=TT orelse y=TT then TT else FF) | 
| 2362 | (xs ~~ ys)) | |
| 16050 | 2363 | | union (_, _) = | 
| 16200 | 2364 | 					raise REFUTE ("Gfp_gfp_interpreter", "union: interpretation for set is not a node")
 | 
| 16050 | 2365 | (* interpretation -> interpretaion *) | 
| 2366 | fun gfp (Node resultsets) = | |
| 2367 | foldl (fn ((set, resultset), acc) => | |
| 16073 | 2368 | if is_subset (set, resultset) then union (acc, set) | 
| 2369 | else acc) | |
| 2370 | i_univ (i_sets ~~ resultsets) | |
| 16050 | 2371 | | gfp _ = | 
| 2372 | 						raise REFUTE ("Gfp_gfp_interpreter", "gfp: interpretation for function is not a node")
 | |
| 2373 | in | |
| 2374 | SOME (Node (map gfp i_funs), model, args) | |
| 2375 | end | |
| 2376 | | _ => | |
| 2377 | NONE; | |
| 2378 | ||
| 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: 
14604diff
changeset | 2379 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2380 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2381 | (* 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: 
14604diff
changeset | 2382 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2383 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2384 | (* 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: 
14604diff
changeset | 2385 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2386 | 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: 
14604diff
changeset | 2387 | 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: 
14604diff
changeset | 2388 | (* Term.term -> Term.typ option *) | 
| 15531 | 2389 | fun typeof (Free (_, T)) = SOME T | 
| 2390 | | typeof (Var (_, T)) = SOME T | |
| 2391 | | typeof (Const (_, T)) = SOME T | |
| 2392 | | 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: 
14604diff
changeset | 2393 | (* 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: 
14604diff
changeset | 2394 | 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: 
14604diff
changeset | 2395 | (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: 
14604diff
changeset | 2396 | (* 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: 
14604diff
changeset | 2397 | 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: 
14604diff
changeset | 2398 | | 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: 
14604diff
changeset | 2399 | | 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: 
14604diff
changeset | 2400 | (* 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: 
14604diff
changeset | 2401 | 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: 
15531diff
changeset | 2402 | 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: 
14604diff
changeset | 2403 | | 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: 
14604diff
changeset | 2404 | 			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: 
14604diff
changeset | 2405 | 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: 
14604diff
changeset | 2406 | case typeof t of | 
| 15531 | 2407 | 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: 
14604diff
changeset | 2408 | (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: 
14604diff
changeset | 2409 | 			  Type ("fun", [T1, T2]) =>
 | 
| 15334 
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
 webertj parents: 
15333diff
changeset | 2410 | 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: 
14604diff
changeset | 2411 | (* 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: 
15531diff
changeset | 2412 | 					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: 
14604diff
changeset | 2413 | 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: 
14604diff
changeset | 2414 | (* 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: 
14604diff
changeset | 2415 | 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: 
14604diff
changeset | 2416 | 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: 
14604diff
changeset | 2417 | 						| _       => 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: 
14604diff
changeset | 2418 | (* 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: 
14604diff
changeset | 2419 | 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: 
14604diff
changeset | 2420 | 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: 
14604diff
changeset | 2421 | 							(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: 
14604diff
changeset | 2422 | 							 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: 
14604diff
changeset | 2423 | (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: 
14604diff
changeset | 2424 | (* 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: 
14604diff
changeset | 2425 | 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: 
14604diff
changeset | 2426 | 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: 
14604diff
changeset | 2427 | (* 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: 
14604diff
changeset | 2428 | 					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: 
14604diff
changeset | 2429 | 					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: 
14604diff
changeset | 2430 | in | 
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15571diff
changeset | 2431 | 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: 
15333diff
changeset | 2432 | 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: 
14604diff
changeset | 2433 | 			| 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: 
14604diff
changeset | 2434 | (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: 
15531diff
changeset | 2435 | 				  (~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: 
15531diff
changeset | 2436 | | 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: 
15531diff
changeset | 2437 | | 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: 
15531diff
changeset | 2438 | 				| _    => 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: 
15531diff
changeset | 2439 | | 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: 
15531diff
changeset | 2440 | 					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: 
15531diff
changeset | 2441 | 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: 
15531diff
changeset | 2442 | 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: 
15531diff
changeset | 2443 | | 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: 
15531diff
changeset | 2444 | 					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: 
15531diff
changeset | 2445 | 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: 
15531diff
changeset | 2446 | 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: 
15531diff
changeset | 2447 | | 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: 
15531diff
changeset | 2448 | 					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: 
15531diff
changeset | 2449 | 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: 
15531diff
changeset | 2450 | SOME (Const (string_of_typ T ^ string_of_int (index_from_interpretation intr), T))) | 
| 15531 | 2451 | | NONE => | 
| 2452 | NONE | |
| 14350 | 2453 | end; | 
| 2454 | ||
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 2455 | (* theory -> model -> Term.term -> interpretation -> (int -> bool) -> string option *) | 
| 14350 | 2456 | |
| 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: 
14604diff
changeset | 2457 | 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: 
14604diff
changeset | 2458 | 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: 
14604diff
changeset | 2459 | (* Term.term -> Term.typ option *) | 
| 15531 | 2460 | fun typeof (Free (_, T)) = SOME T | 
| 2461 | | typeof (Var (_, T)) = SOME T | |
| 2462 | | typeof (Const (_, T)) = SOME T | |
| 2463 | | 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: 
14604diff
changeset | 2464 | 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: 
14604diff
changeset | 2465 | case typeof t of | 
| 15531 | 2466 | 		  SOME (Type ("set", [T])) =>
 | 
| 15334 
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
 webertj parents: 
15333diff
changeset | 2467 | 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: 
14604diff
changeset | 2468 | (* 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: 
15531diff
changeset | 2469 | 				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: 
14604diff
changeset | 2470 | 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: 
14604diff
changeset | 2471 | (* 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: 
14604diff
changeset | 2472 | 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: 
14604diff
changeset | 2473 | 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: 
14604diff
changeset | 2474 | 					| _       => 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: 
14604diff
changeset | 2475 | (* Term.term list *) | 
| 15570 | 2476 | 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: 
14604diff
changeset | 2477 | 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: 
14604diff
changeset | 2478 | 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: 
14604diff
changeset | 2479 | if PropLogic.eval assignment fmTrue then | 
| 15531 | 2480 | 							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: 
15531diff
changeset | 2481 | else (*if PropLogic.eval assignment fmFalse then*) | 
| 15531 | 2482 | 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: 
14604diff
changeset | 2483 | | _ => | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2484 | 						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: 
14604diff
changeset | 2485 | (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: 
14604diff
changeset | 2486 | (* 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: 
14604diff
changeset | 2487 | 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: 
14604diff
changeset | 2488 | (* 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: 
14604diff
changeset | 2489 | 				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: 
14604diff
changeset | 2490 | 				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: 
14604diff
changeset | 2491 | in | 
| 15570 | 2492 | 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: 
15333diff
changeset | 2493 | end | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 2494 | | _ => | 
| 15531 | 2495 | 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: 
14604diff
changeset | 2496 | end; | 
| 14350 | 2497 | |
| 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: 
14604diff
changeset | 2498 | (* theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option *) | 
| 14350 | 2499 | |
| 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: 
14604diff
changeset | 2500 | fun IDT_printer thy model t intr assignment = | 
| 14350 | 2501 | 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: 
14604diff
changeset | 2502 | (* Term.term -> Term.typ option *) | 
| 15531 | 2503 | fun typeof (Free (_, T)) = SOME T | 
| 2504 | | typeof (Var (_, T)) = SOME T | |
| 2505 | | typeof (Const (_, T)) = SOME T | |
| 2506 | | typeof _ = NONE | |
| 14350 | 2507 | 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: 
14604diff
changeset | 2508 | case typeof t of | 
| 15531 | 2509 | SOME (Type (s, Ts)) => | 
| 19346 | 2510 | (case DatatypePackage.get_datatype thy s of | 
| 15531 | 2511 | 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: 
14604diff
changeset | 2512 | 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: 
14604diff
changeset | 2513 | 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: 
14604diff
changeset | 2514 | 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: 
14604diff
changeset | 2515 | val descr = #descr info | 
| 17314 | 2516 | val (_, dtyps, constrs) = (the 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: 
14604diff
changeset | 2517 | 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: 
14604diff
changeset | 2518 | (* 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: 
14604diff
changeset | 2519 | 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: 
14604diff
changeset | 2520 | 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: 
14604diff
changeset | 2521 | 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: 
14604diff
changeset | 2522 | 							raise REFUTE ("IDT_printer", "datatype argument (for type " ^ Sign.string_of_typ (sign_of thy) (Type (s, Ts)) ^ ") is not a variable")
 | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2523 | 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: 
14604diff
changeset | 2524 | ()) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2525 | (* 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: 
14604diff
changeset | 2526 | 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: 
14604diff
changeset | 2527 | 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: 
14604diff
changeset | 2528 | 						| 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: 
14604diff
changeset | 2529 | 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: 
15531diff
changeset | 2530 | 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: 
15531diff
changeset | 2531 | 						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: 
15531diff
changeset | 2532 | 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: 
15531diff
changeset | 2533 | (* 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: 
15531diff
changeset | 2534 | (* 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: 
15531diff
changeset | 2535 | (* 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: 
15531diff
changeset | 2536 | (* 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: 
15531diff
changeset | 2537 | 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: 
15531diff
changeset | 2538 | 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: 
15531diff
changeset | 2539 | 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: 
15531diff
changeset | 2540 | 								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: 
15531diff
changeset | 2541 | (* 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: 
15531diff
changeset | 2542 | 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: 
15531diff
changeset | 2543 | 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: 
15531diff
changeset | 2544 | 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: 
15531diff
changeset | 2545 | 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: 
15531diff
changeset | 2546 | 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: 
15531diff
changeset | 2547 | | 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: 
15531diff
changeset | 2548 | 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: 
15531diff
changeset | 2549 | (* 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: 
15531diff
changeset | 2550 | 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: 
15531diff
changeset | 2551 | 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: 
15531diff
changeset | 2552 | | 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: 
15531diff
changeset | 2553 | (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: 
15531diff
changeset | 2554 | 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: 
15531diff
changeset | 2555 | | 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: 
15531diff
changeset | 2556 | 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: 
15531diff
changeset | 2557 | 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: 
15531diff
changeset | 2558 | 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: 
15531diff
changeset | 2559 | in | 
| 15570 | 2560 | 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: 
15531diff
changeset | 2561 | 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: 
15531diff
changeset | 2562 | (* 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: 
15531diff
changeset | 2563 | 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: 
15531diff
changeset | 2564 | 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: 
15531diff
changeset | 2565 | 							| 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: 
15531diff
changeset | 2566 | 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: 
15531diff
changeset | 2567 | 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: 
15531diff
changeset | 2568 | 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: 
15531diff
changeset | 2569 | 								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: 
15531diff
changeset | 2570 | 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: 
15531diff
changeset | 2571 | (* 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: 
15531diff
changeset | 2572 | (* 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: 
15531diff
changeset | 2573 | in | 
| 15570 | 2574 | 								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: 
15531diff
changeset | 2575 | 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: 
15531diff
changeset | 2576 | in | 
| 15570 | 2577 | 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: 
15531diff
changeset | 2578 | 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: 
14604diff
changeset | 2579 | end | 
| 15531 | 2580 | | NONE => (* not an inductive datatype *) | 
| 2581 | 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: 
14604diff
changeset | 2582 | | _ => (* a (free or schematic) type variable *) | 
| 15531 | 2583 | NONE | 
| 14350 | 2584 | end; | 
| 2585 | ||
| 2586 | ||
| 2587 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 2588 | (* 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: 
14351diff
changeset | 2589 | (* structure *) | 
| 14350 | 2590 | (* ------------------------------------------------------------------------- *) | 
| 2591 | ||
| 2592 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 2593 | (* Note: the interpreters and printers are used in reverse order; however, *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 2594 | (* 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: 
14604diff
changeset | 2595 | (* 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: 
14604diff
changeset | 2596 | (* subterms that are then passed to other interpreters! *) | 
| 14350 | 2597 | (* ------------------------------------------------------------------------- *) | 
| 2598 | ||
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 2599 | (* (theory -> theory) list *) | 
| 14350 | 2600 | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 2601 | val setup = | 
| 18708 | 2602 | RefuteData.init #> | 
| 2603 | add_interpreter "stlc" stlc_interpreter #> | |
| 2604 | add_interpreter "Pure" Pure_interpreter #> | |
| 2605 | add_interpreter "HOLogic" HOLogic_interpreter #> | |
| 2606 | add_interpreter "set" set_interpreter #> | |
| 2607 | add_interpreter "IDT" IDT_interpreter #> | |
| 2608 | add_interpreter "IDT_constructor" IDT_constructor_interpreter #> | |
| 2609 | add_interpreter "IDT_recursion" IDT_recursion_interpreter #> | |
| 2610 | add_interpreter "Finite_Set.card" Finite_Set_card_interpreter #> | |
| 2611 | add_interpreter "Finite_Set.Finites" Finite_Set_Finites_interpreter #> | |
| 2612 | add_interpreter "Nat.op <" Nat_less_interpreter #> | |
| 2613 | add_interpreter "Nat.op +" Nat_plus_interpreter #> | |
| 2614 | add_interpreter "Nat.op -" Nat_minus_interpreter #> | |
| 2615 | add_interpreter "Nat.op *" Nat_mult_interpreter #> | |
| 2616 | add_interpreter "List.op @" List_append_interpreter #> | |
| 2617 | add_interpreter "Lfp.lfp" Lfp_lfp_interpreter #> | |
| 2618 | add_interpreter "Gfp.gfp" Gfp_gfp_interpreter #> | |
| 2619 | add_printer "stlc" stlc_printer #> | |
| 2620 | add_printer "set" set_printer #> | |
| 2621 | add_printer "IDT" IDT_printer; | |
| 14350 | 2622 | |
| 2623 | end |