| author | haftmann | 
| Wed, 22 Jul 2009 18:02:10 +0200 | |
| changeset 32139 | e271a64f03ff | 
| parent 31986 | a68f88d264f7 | 
| child 32857 | 394d37f19e0a | 
| permissions | -rw-r--r-- | 
| 14350 | 1 | (* Title: HOL/Tools/refute.ML | 
| 29265 
5b4247055bd7
moved old add_term_vars, add_term_frees etc. to structure OldTerm;
 wenzelm parents: 
29004diff
changeset | 2 | Author: Tjark Weber, TU Muenchen | 
| 14350 | 3 | |
| 14965 | 4 | Finite model generation for HOL formulas, using a SAT solver. | 
| 14350 | 5 | *) | 
| 6 | ||
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 7 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 8 | (* 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 | 9 | (* Documentation is available in the Isabelle/Isar theory 'HOL/Refute.thy'. *) | 
| 14350 | 10 | (* ------------------------------------------------------------------------- *) | 
| 11 | ||
| 12 | signature REFUTE = | |
| 13 | sig | |
| 14 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 15 | exception REFUTE of string * string | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 16 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 17 | (* ------------------------------------------------------------------------- *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 18 | (* Model/interpretation related code (translation HOL -> propositional logic *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 19 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 20 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 21 | type params | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 22 | type interpretation | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 23 | type model | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 24 | type arguments | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 25 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 26 | exception MAXVARS_EXCEEDED | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 27 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 28 | val add_interpreter : string -> (theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 29 | (interpretation * model * arguments) option) -> theory -> theory | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 30 | val add_printer : string -> (theory -> model -> Term.typ -> | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 31 | 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 33 | val interpret : theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 34 | (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 | 35 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 36 | val print : theory -> model -> Term.typ -> interpretation -> | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 37 | (int -> bool) -> Term.term | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 38 | val print_model : theory -> model -> (int -> bool) -> string | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 39 | |
| 
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 | (* Interface *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 42 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 43 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 44 | val set_default_param : (string * string) -> theory -> theory | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 45 | val get_default_param : theory -> string -> string option | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 46 | val get_default_params : theory -> (string * string) list | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 47 | val actual_params : theory -> (string * string) list -> params | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 48 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 49 | 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 | 50 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 51 | (* tries to find a model for a formula: *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 52 | val satisfy_term : theory -> (string * string) list -> Term.term -> unit | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 53 | (* tries to find a model that refutes a formula: *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 54 | val refute_term : theory -> (string * string) list -> Term.term -> unit | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 55 | val refute_subgoal : | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 56 | theory -> (string * string) list -> Thm.thm -> int -> unit | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 57 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 58 | val setup : theory -> theory | 
| 22092 | 59 | |
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 60 | (* ------------------------------------------------------------------------- *) | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 61 | (* Additional functions used by Nitpick (to be factored out) *) | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 62 | (* ------------------------------------------------------------------------- *) | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 63 | |
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 64 | val close_form : Term.term -> Term.term | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 65 | val get_classdef : theory -> string -> (string * Term.term) option | 
| 30275 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 66 | val norm_rhs : Term.term -> Term.term | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 67 | val get_def : theory -> string * Term.typ -> (string * Term.term) option | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 68 | val get_typedef : theory -> Term.typ -> (string * Term.term) option | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 69 | val is_IDT_constructor : theory -> string * Term.typ -> bool | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 70 | val is_IDT_recursor : theory -> string * Term.typ -> bool | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 71 | val is_const_of_class: theory -> string * Term.typ -> bool | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 72 | val monomorphic_term : Type.tyenv -> Term.term -> Term.term | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 73 | val specialize_type : theory -> (string * Term.typ) -> Term.term -> Term.term | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 74 | val string_of_typ : Term.typ -> string | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 75 | val typ_of_dtyp : | 
| 31737 | 76 | Datatype.descr -> (Datatype.dtyp * Term.typ) list -> Datatype.dtyp | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 77 | -> Term.typ | 
| 22092 | 78 | end; (* signature REFUTE *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 79 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 80 | structure Refute : REFUTE = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 81 | struct | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 82 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 83 | open PropLogic; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 84 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 85 | (* We use 'REFUTE' only for internal error conditions that should *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 86 | (* never occur in the first place (i.e. errors caused by bugs in our *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 87 | (* code). Otherwise (e.g. to indicate invalid input data) we use *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 88 | (* 'error'. *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 89 |   exception REFUTE of string * string;  (* ("in function", "cause") *)
 | 
| 14350 | 90 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 91 | (* should be raised by an interpreter when more variables would be *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 92 | (* required than allowed by 'maxvars' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 93 | exception MAXVARS_EXCEEDED; | 
| 14350 | 94 | |
| 95 | (* ------------------------------------------------------------------------- *) | |
| 96 | (* TREES *) | |
| 97 | (* ------------------------------------------------------------------------- *) | |
| 98 | ||
| 99 | (* ------------------------------------------------------------------------- *) | |
| 100 | (* tree: implements an arbitrarily (but finitely) branching tree as a list *) | |
| 101 | (* of (lists of ...) elements *) | |
| 102 | (* ------------------------------------------------------------------------- *) | |
| 103 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 104 | datatype 'a tree = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 105 | Leaf of 'a | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 106 |     | Node of ('a tree) list;
 | 
| 14350 | 107 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 108 |   (* ('a -> 'b) -> 'a tree -> 'b tree *)
 | 
| 14350 | 109 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 110 | fun tree_map f tr = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 111 | case tr of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 112 | Leaf x => Leaf (f x) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 113 | | Node xs => Node (map (tree_map f) xs); | 
| 14350 | 114 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 115 |   (* ('a * 'b -> 'a) -> 'a * ('b tree) -> 'a *)
 | 
| 14350 | 116 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 117 | fun tree_foldl f = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 118 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 119 | fun itl (e, Leaf x) = f(e,x) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 120 | | itl (e, Node xs) = Library.foldl (tree_foldl f) (e,xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 121 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 122 | itl | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 123 | end; | 
| 14350 | 124 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 125 |   (* 'a tree * 'b tree -> ('a * 'b) tree *)
 | 
| 14350 | 126 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 127 | fun tree_pair (t1, t2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 128 | case t1 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 129 | Leaf x => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 130 | (case t2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 131 | Leaf y => Leaf (x,y) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 132 |         | Node _ => raise REFUTE ("tree_pair",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 133 | "trees are of different height (second tree is higher)")) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 134 | | Node xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 135 | (case t2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 136 | (* '~~' will raise an exception if the number of branches in *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 137 | (* both trees is different at the current node *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 138 | Node ys => Node (map tree_pair (xs ~~ ys)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 139 |         | Leaf _  => raise REFUTE ("tree_pair",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 140 | "trees are of different height (first tree is higher)")); | 
| 14350 | 141 | |
| 142 | (* ------------------------------------------------------------------------- *) | |
| 14807 
e8ccb13d7774
major code change: refute can 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 | (* 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 | 144 | (* 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 | 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 | (* The following parameters are supported (and required (!), except for *) | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 147 | (* "sizes" and "expect"): *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 148 | (* *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 149 | (* 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 | 150 | (* *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 151 | (* "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 | 152 | (* 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 | 153 | (* "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 | 154 | (* "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 | 155 | (* "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 | 156 | (* 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 | 157 | (* 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 | 158 | (* "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 | 159 | (* "satsolver" string SAT solver to be used. *) | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 160 | (* "expect"      string  Expected result ("genuine", "potential", "none", or *)
 | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 161 | (* "unknown") *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 162 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 163 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 164 | type params = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 165 |     {
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 166 | sizes : (string * int) list, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 167 | minsize : int, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 168 | maxsize : int, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 169 | maxvars : int, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 170 | maxtime : int, | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 171 | satsolver: string, | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 172 | expect : string | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 173 | }; | 
| 14807 
e8ccb13d7774
major code change: refute can 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 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 175 | (* ------------------------------------------------------------------------- *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 176 | (* 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 | 177 | (* 'interpretation' *) | 
| 14350 | 178 | (* ------------------------------------------------------------------------- *) | 
| 179 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 180 | type interpretation = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 181 | prop_formula list tree; | 
| 14350 | 182 | |
| 183 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 184 | (* 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 | 185 | (* terms *) | 
| 14350 | 186 | (* ------------------------------------------------------------------------- *) | 
| 187 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 188 | type model = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 189 | (Term.typ * int) list * (Term.term * interpretation) list; | 
| 14350 | 190 | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 191 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 192 | (* arguments: additional arguments required during interpretation of terms *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 193 | (* ------------------------------------------------------------------------- *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 194 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 195 | type arguments = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 196 |     {
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 197 | (* just passed unchanged from 'params': *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 198 | maxvars : int, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 199 | (* whether to use 'make_equality' or 'make_def_equality': *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 200 | def_eq : bool, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 201 | (* the following may change during the translation: *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 202 | next_idx : int, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 203 | bounds : interpretation list, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 204 | wellformed: prop_formula | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 205 | }; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 206 | |
| 14350 | 207 | |
| 22846 | 208 | structure RefuteData = TheoryDataFun | 
| 209 | ( | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 210 | type T = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 211 |       {interpreters: (string * (theory -> model -> arguments -> Term.term ->
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 212 | (interpretation * model * arguments) option)) list, | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 213 | printers: (string * (theory -> model -> Term.typ -> interpretation -> | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 214 | (int -> bool) -> Term.term option)) list, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 215 | parameters: string Symtab.table}; | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 216 |     val empty = {interpreters = [], printers = [], parameters = Symtab.empty};
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 217 | val copy = I; | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 218 | val extend = I; | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 219 | fun merge _ | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 220 |       ({interpreters = in1, printers = pr1, parameters = pa1},
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 221 |        {interpreters = in2, printers = pr2, parameters = pa2}) =
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 222 |       {interpreters = AList.merge (op =) (K true) (in1, in2),
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 223 | printers = AList.merge (op =) (K true) (pr1, pr2), | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 224 | parameters = Symtab.merge (op=) (pa1, pa2)}; | 
| 22846 | 225 | ); | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 226 | |
| 14350 | 227 | |
| 228 | (* ------------------------------------------------------------------------- *) | |
| 15334 
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
 webertj parents: 
15333diff
changeset | 229 | (* 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 | 230 | (* 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 | 231 | (* track of the interpretation of subterms *) | 
| 14350 | 232 | (* ------------------------------------------------------------------------- *) | 
| 233 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 234 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 235 | (interpretation * model * arguments) *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 236 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 237 | fun interpret thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 238 | case get_first (fn (_, f) => f thy model args t) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 239 | (#interpreters (RefuteData.get thy)) of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 240 |       NONE   => raise REFUTE ("interpret",
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 241 | "no interpreter for term " ^ quote (Syntax.string_of_term_global thy t)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 242 | | SOME x => x; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 243 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 244 | (* ------------------------------------------------------------------------- *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 245 | (* print: converts the interpretation 'intr', which must denote a term of *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 246 | (* type 'T', into a term using a suitable printer *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 247 | (* ------------------------------------------------------------------------- *) | 
| 14350 | 248 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 249 | (* theory -> model -> Term.typ -> interpretation -> (int -> bool) -> | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 250 | Term.term *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 251 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 252 | fun print thy model T intr assignment = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 253 | case get_first (fn (_, f) => f thy model T intr assignment) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 254 | (#printers (RefuteData.get thy)) of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 255 |       NONE   => raise REFUTE ("print",
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 256 | "no printer for type " ^ quote (Syntax.string_of_typ_global thy T)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 257 | | SOME x => x; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 258 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 259 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 260 | (* 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 | 261 | (* (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 | 262 | (* printers *) | 
| 
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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 265 | (* theory -> model -> (int -> bool) -> string *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 266 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 267 | fun print_model thy model assignment = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 268 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 269 | val (typs, terms) = model | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 270 | val typs_msg = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 271 | if null typs then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 272 | "empty universe (no type variables in term)\n" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 273 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 274 | "Size of types: " ^ commas (map (fn (T, i) => | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 275 | Syntax.string_of_typ_global thy T ^ ": " ^ string_of_int i) typs) ^ "\n" | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 276 | val show_consts_msg = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 277 | if not (!show_consts) andalso Library.exists (is_Const o fst) terms then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 278 | "set \"show_consts\" to show the interpretation of constants\n" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 279 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 280 | "" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 281 | val terms_msg = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 282 | if null terms then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 283 | "empty interpretation (no free variables in term)\n" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 284 | else | 
| 26931 | 285 | cat_lines (List.mapPartial (fn (t, intr) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 286 | (* print constants only if 'show_consts' is true *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 287 | if (!show_consts) orelse not (is_Const t) then | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 288 | SOME (Syntax.string_of_term_global thy t ^ ": " ^ | 
| 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 289 | Syntax.string_of_term_global thy | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 290 | (print thy model (Term.type_of t) intr assignment)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 291 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 292 | NONE) terms) ^ "\n" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 293 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 294 | typs_msg ^ show_consts_msg ^ terms_msg | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 295 | end; | 
| 14456 
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 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 298 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 299 | (* PARAMETER MANAGEMENT *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 300 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 301 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 302 | (* string -> (theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 303 | (interpretation * model * arguments) option) -> theory -> theory *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 304 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 305 | fun add_interpreter name f thy = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 306 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 307 |     val {interpreters, printers, parameters} = RefuteData.get thy
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 308 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 309 | case AList.lookup (op =) interpreters name of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 310 |       NONE   => RefuteData.put {interpreters = (name, f) :: interpreters,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 311 | printers = printers, parameters = parameters} thy | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 312 |     | SOME _ => error ("Interpreter " ^ name ^ " already declared")
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 313 | end; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 314 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 315 | (* string -> (theory -> model -> Term.typ -> interpretation -> | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 316 | (int -> bool) -> Term.term option) -> theory -> theory *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 317 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 318 | fun add_printer name f thy = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 319 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 320 |     val {interpreters, printers, parameters} = RefuteData.get thy
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 321 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 322 | case AList.lookup (op =) printers name of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 323 |       NONE   => RefuteData.put {interpreters = interpreters,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 324 | printers = (name, f) :: printers, parameters = parameters} thy | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 325 |     | SOME _ => error ("Printer " ^ name ^ " already declared")
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 326 | end; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 327 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 328 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 329 | (* 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 | 330 | (* parameter table *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 331 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 332 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 333 | (* (string * string) -> theory -> theory *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 334 | |
| 29004 | 335 | fun set_default_param (name, value) = RefuteData.map | 
| 336 |     (fn {interpreters, printers, parameters} =>
 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 337 |       {interpreters = interpreters, printers = printers,
 | 
| 29004 | 338 | parameters = Symtab.update (name, value) parameters}); | 
| 14350 | 339 | |
| 340 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 341 | (* 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 | 342 | (* RefuteData's parameter table *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 343 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 344 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 345 | (* theory -> string -> string option *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 346 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 347 | 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 | 348 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 349 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 350 | (* 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 | 351 | (* stored in RefuteData's parameter table *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 352 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 353 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 354 | (* theory -> (string * string) list *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 355 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 356 | 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 | 357 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 358 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 359 | (* 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 | 360 | (* 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 | 361 | (* 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 | 362 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 363 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 364 | (* theory -> (string * string) list -> params *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 365 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 366 | fun actual_params thy override = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 367 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 368 | (* (string * string) list * string -> int *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 369 | fun read_int (parms, name) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 370 | case AList.lookup (op =) parms name of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 371 | SOME s => (case Int.fromString s of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 372 | SOME i => i | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 373 |         | NONE   => error ("parameter " ^ quote name ^
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 374 | " (value is " ^ quote s ^ ") must be an integer value")) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 375 |       | NONE   => error ("parameter " ^ quote name ^
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 376 | " must be assigned a value") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 377 | (* (string * string) list * string -> string *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 378 | fun read_string (parms, name) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 379 | case AList.lookup (op =) parms name of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 380 | SOME s => s | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 381 |       | NONE   => error ("parameter " ^ quote name ^
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 382 | " must be assigned a value") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 383 | (* 'override' first, defaults last: *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 384 | (* (string * string) list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 385 | val allparams = override @ (get_default_params thy) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 386 | (* int *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 387 | val minsize = read_int (allparams, "minsize") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 388 | val maxsize = read_int (allparams, "maxsize") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 389 | val maxvars = read_int (allparams, "maxvars") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 390 | val maxtime = read_int (allparams, "maxtime") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 391 | (* string *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 392 | val satsolver = read_string (allparams, "satsolver") | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 393 | val expect = the_default "" (AList.lookup (op =) allparams "expect") | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 394 | (* all remaining parameters of the form "string=int" are collected in *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 395 | (* 'sizes' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 396 | (* TODO: it is currently not possible to specify a size for a type *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 397 | (* whose name is one of the other parameters (e.g. 'maxvars') *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 398 | (* (string * int) list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 399 | val sizes = List.mapPartial | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 400 | (fn (name, value) => Option.map (pair name) (Int.fromString value)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 401 | (List.filter (fn (name, _) => name<>"minsize" andalso name<>"maxsize" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 402 | andalso name<>"maxvars" andalso name<>"maxtime" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 403 | andalso name<>"satsolver") allparams) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 404 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 405 |     {sizes=sizes, minsize=minsize, maxsize=maxsize, maxvars=maxvars,
 | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 406 | maxtime=maxtime, satsolver=satsolver, expect=expect} | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 407 | 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 | 408 | |
| 
e8ccb13d7774
major code change: refute can 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 | |
| 
e8ccb13d7774
major code change: refute can 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 | (* 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 | 412 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 414 | fun typ_of_dtyp descr typ_assoc (DatatypeAux.DtTFree a) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 415 | (* replace a 'DtTFree' variable by the associated type *) | 
| 29288 | 416 | the (AList.lookup (op =) typ_assoc (DatatypeAux.DtTFree a)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 417 | | typ_of_dtyp descr typ_assoc (DatatypeAux.DtType (s, ds)) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 418 | Type (s, map (typ_of_dtyp descr typ_assoc) ds) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 419 | | typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec i) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 420 | let | 
| 29288 | 421 | val (s, ds, _) = the (AList.lookup (op =) descr i) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 422 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 423 | Type (s, map (typ_of_dtyp descr typ_assoc) ds) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 424 | end; | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 425 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 426 | (* ------------------------------------------------------------------------- *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 427 | (* close_form: universal closure over schematic variables in 't' *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 428 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 429 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 430 | (* Term.term -> Term.term *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 431 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 432 | fun close_form t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 433 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 434 | (* (Term.indexname * Term.typ) list *) | 
| 29265 
5b4247055bd7
moved old add_term_vars, add_term_frees etc. to structure OldTerm;
 wenzelm parents: 
29004diff
changeset | 435 | val vars = sort_wrt (fst o fst) (map dest_Var (OldTerm.term_vars t)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 436 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 437 | Library.foldl (fn (t', ((x, i), T)) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 438 | (Term.all T) $ Abs (x, T, abstract_over (Var ((x, i), T), t'))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 439 | (t, vars) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 440 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 441 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 442 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 443 | (* monomorphic_term: applies a type substitution 'typeSubs' for all type *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 444 | (* variables in a term 't' *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 445 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 446 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 447 | (* Type.tyenv -> Term.term -> Term.term *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 448 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 449 | fun monomorphic_term typeSubs t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 450 | map_types (map_type_tvar | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 451 | (fn v => | 
| 26328 | 452 | case Type.lookup typeSubs v of | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 453 | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 454 | (* schematic type variable not instantiated *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 455 |           raise REFUTE ("monomorphic_term",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 456 | "no substitution for type variable " ^ fst (fst v) ^ | 
| 26957 | 457 | " in term " ^ Syntax.string_of_term_global Pure.thy t) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 458 | | SOME typ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 459 | typ)) t; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 460 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 461 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 462 | (* specialize_type: given a constant 's' of type 'T', which is a subterm of *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 463 | (* 't', where 't' has a (possibly) more general type, the *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 464 | (* schematic type variables in 't' are instantiated to *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 465 | (* match the type 'T' (may raise Type.TYPE_MATCH) *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 466 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 467 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 468 | (* theory -> (string * Term.typ) -> Term.term -> Term.term *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 469 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 470 | fun specialize_type thy (s, T) t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 471 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 472 | fun find_typeSubs (Const (s', T')) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 473 | if s=s' then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 474 | SOME (Sign.typ_match thy (T', T) Vartab.empty) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 475 | handle Type.TYPE_MATCH => NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 476 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 477 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 478 | | find_typeSubs (Free _) = NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 479 | | find_typeSubs (Var _) = NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 480 | | find_typeSubs (Bound _) = NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 481 | | find_typeSubs (Abs (_, _, body)) = find_typeSubs body | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 482 | | find_typeSubs (t1 $ t2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 483 | (case find_typeSubs t1 of SOME x => SOME x | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 484 | | NONE => find_typeSubs t2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 485 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 486 | case find_typeSubs t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 487 | SOME typeSubs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 488 | monomorphic_term typeSubs t | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 489 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 490 | (* no match found - perhaps due to sort constraints *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 491 | raise Type.TYPE_MATCH | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 492 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 493 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 494 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 495 | (* is_const_of_class: returns 'true' iff 'Const (s, T)' is a constant that *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 496 | (* denotes membership to an axiomatic type class *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 497 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 498 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 499 | (* theory -> string * Term.typ -> bool *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 500 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 501 | fun is_const_of_class thy (s, T) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 502 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 503 | val class_const_names = map Logic.const_of_class (Sign.all_classes thy) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 504 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 505 | (* I'm not quite sure if checking the name 's' is sufficient, *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 506 | (* or if we should also check the type 'T'. *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 507 | s mem_string class_const_names | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 508 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 509 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 510 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 511 | (* is_IDT_constructor: returns 'true' iff 'Const (s, T)' is the constructor *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 512 | (* of an inductive datatype in 'thy' *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 513 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 514 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 515 | (* theory -> string * Term.typ -> bool *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 516 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 517 | fun is_IDT_constructor thy (s, T) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 518 | (case body_type T of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 519 | Type (s', _) => | 
| 31784 | 520 | (case Datatype.get_constrs thy s' of | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 521 | SOME constrs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 522 | List.exists (fn (cname, cty) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 523 | cname = s andalso Sign.typ_instance thy (T, cty)) constrs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 524 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 525 | false) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 526 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 527 | false); | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 528 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 529 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 530 | (* is_IDT_recursor: returns 'true' iff 'Const (s, T)' is the recursion *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 531 | (* operator of an inductive datatype in 'thy' *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 532 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 533 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 534 | (* theory -> string * Term.typ -> bool *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 535 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 536 | fun is_IDT_recursor thy (s, T) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 537 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 538 | val rec_names = Symtab.fold (append o #rec_names o snd) | 
| 31784 | 539 | (Datatype.get_all thy) [] | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 540 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 541 | (* I'm not quite sure if checking the name 's' is sufficient, *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 542 | (* or if we should also check the type 'T'. *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 543 | s mem_string rec_names | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 544 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 545 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 546 | (* ------------------------------------------------------------------------- *) | 
| 30275 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 547 | (* norm_rhs: maps f ?t1 ... ?tn == rhs to %t1...tn. rhs *) | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 548 | (* ------------------------------------------------------------------------- *) | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 549 | |
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 550 | fun norm_rhs eqn = | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 551 | let | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 552 | fun lambda (v as Var ((x, _), T)) t = Abs (x, T, abstract_over (v, t)) | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 553 |       | lambda v t                      = raise TERM ("lambda", [v, t])
 | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 554 | val (lhs, rhs) = Logic.dest_equals eqn | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 555 | val (_, args) = Term.strip_comb lhs | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 556 | in | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 557 | fold lambda (rev args) rhs | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 558 | end | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 559 | |
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 560 | (* ------------------------------------------------------------------------- *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 561 | (* get_def: looks up the definition of a constant, as created by "constdefs" *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 562 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 563 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 564 | (* theory -> string * Term.typ -> (string * Term.term) option *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 565 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 566 | fun get_def thy (s, T) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 567 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 568 | (* (string * Term.term) list -> (string * Term.term) option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 569 | fun get_def_ax [] = NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 570 | | get_def_ax ((axname, ax) :: axioms) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 571 | (let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 572 | val (lhs, _) = Logic.dest_equals ax (* equations only *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 573 | val c = Term.head_of lhs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 574 | val (s', T') = Term.dest_Const c | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 575 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 576 | if s=s' then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 577 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 578 | val typeSubs = Sign.typ_match thy (T', T) Vartab.empty | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 579 | val ax' = monomorphic_term typeSubs ax | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 580 | val rhs = norm_rhs ax' | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 581 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 582 | SOME (axname, rhs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 583 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 584 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 585 | get_def_ax axioms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 586 | end handle ERROR _ => get_def_ax axioms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 587 | | TERM _ => get_def_ax axioms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 588 | | Type.TYPE_MATCH => get_def_ax axioms) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 589 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 590 | get_def_ax (Theory.all_axioms_of thy) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 591 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 592 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 593 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 594 | (* get_typedef: looks up the definition of a type, as created by "typedef" *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 595 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 596 | |
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 597 | (* theory -> Term.typ -> (string * Term.term) option *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 598 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 599 | fun get_typedef thy T = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 600 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 601 | (* (string * Term.term) list -> (string * Term.term) option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 602 | fun get_typedef_ax [] = NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 603 | | get_typedef_ax ((axname, ax) :: axioms) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 604 | (let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 605 | (* Term.term -> Term.typ option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 606 | fun type_of_type_definition (Const (s', T')) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 607 | if s'="Typedef.type_definition" then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 608 | SOME T' | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 609 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 610 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 611 | | type_of_type_definition (Free _) = NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 612 | | type_of_type_definition (Var _) = NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 613 | | type_of_type_definition (Bound _) = NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 614 | | type_of_type_definition (Abs (_, _, body)) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 615 | type_of_type_definition body | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 616 | | type_of_type_definition (t1 $ t2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 617 | (case type_of_type_definition t1 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 618 | SOME x => SOME x | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 619 | | NONE => type_of_type_definition t2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 620 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 621 | case type_of_type_definition ax of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 622 | SOME T' => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 623 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 624 | val T'' = (domain_type o domain_type) T' | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 625 | val typeSubs = Sign.typ_match thy (T'', T) Vartab.empty | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 626 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 627 | SOME (axname, monomorphic_term typeSubs ax) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 628 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 629 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 630 | get_typedef_ax axioms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 631 | end handle ERROR _ => get_typedef_ax axioms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 632 | | MATCH => get_typedef_ax axioms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 633 | | Type.TYPE_MATCH => get_typedef_ax axioms) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 634 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 635 | get_typedef_ax (Theory.all_axioms_of thy) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 636 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 637 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 638 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 639 | (* get_classdef: looks up the defining axiom for an axiomatic type class, as *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 640 | (* created by the "axclass" command *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 641 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 642 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 643 | (* theory -> string -> (string * Term.term) option *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 644 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 645 | fun get_classdef thy class = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 646 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 647 | val axname = class ^ "_class_def" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 648 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 649 | Option.map (pair axname) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 650 | (AList.lookup (op =) (Theory.all_axioms_of thy) axname) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 651 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 652 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 653 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 654 | (* unfold_defs: unfolds all defined constants in a term 't', beta-eta *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 655 | (* normalizes the result term; certain constants are not *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 656 | (* unfolded (cf. 'collect_axioms' and the various interpreters *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 657 | (* below): if the interpretation respects a definition anyway, *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 658 | (* that definition does not need to be unfolded *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 659 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 660 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 661 | (* theory -> Term.term -> Term.term *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 662 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 663 | (* Note: we could intertwine unfolding of constants and beta-(eta-) *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 664 | (* normalization; this would save some unfolding for terms where *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 665 | (* constants are eliminated by beta-reduction (e.g. 'K c1 c2'). On *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 666 | (* the other hand, this would cause additional work for terms where *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 667 | (* constants are duplicated by beta-reduction (e.g. 'S c1 c2 c3'). *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 668 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 669 | fun unfold_defs thy t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 670 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 671 | (* Term.term -> Term.term *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 672 | fun unfold_loop t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 673 | case t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 674 | (* Pure *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 675 |         Const (@{const_name all}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 676 |       | Const (@{const_name "=="}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 677 |       | Const (@{const_name "==>"}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 678 |       | Const (@{const_name TYPE}, _) => t  (* axiomatic type classes *)
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 679 | (* HOL *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 680 |       | Const (@{const_name Trueprop}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 681 |       | Const (@{const_name Not}, _) => t
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 682 | | (* redundant, since 'True' is also an IDT constructor *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 683 |         Const (@{const_name True}, _) => t
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 684 | | (* redundant, since 'False' is also an IDT constructor *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 685 |         Const (@{const_name False}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 686 |       | Const (@{const_name undefined}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 687 |       | Const (@{const_name The}, _) => t
 | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 688 |       | Const (@{const_name Hilbert_Choice.Eps}, _) => t
 | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 689 |       | Const (@{const_name All}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 690 |       | Const (@{const_name Ex}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 691 |       | Const (@{const_name "op ="}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 692 |       | Const (@{const_name "op &"}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 693 |       | Const (@{const_name "op |"}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 694 |       | Const (@{const_name "op -->"}, _) => t
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 695 | (* sets *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 696 |       | Const (@{const_name Collect}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 697 |       | Const (@{const_name "op :"}, _) => t
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 698 | (* other optimizations *) | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 699 |       | Const (@{const_name Finite_Set.card}, _) => t
 | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 700 |       | Const (@{const_name Finite_Set.finite}, _) => t
 | 
| 23881 | 701 |       | Const (@{const_name HOL.less}, Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 702 |         Type ("fun", [Type ("nat", []), Type ("bool", [])])])) => t
 | 
| 22997 | 703 |       | Const (@{const_name HOL.plus}, Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 704 |         Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t
 | 
| 22997 | 705 |       | Const (@{const_name HOL.minus}, Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 706 |         Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t
 | 
| 22997 | 707 |       | Const (@{const_name HOL.times}, Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 708 |         Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t
 | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 709 |       | Const (@{const_name List.append}, _) => t
 | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 710 |       | Const (@{const_name lfp}, _) => t
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 711 |       | Const (@{const_name gfp}, _) => t
 | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 712 |       | Const (@{const_name fst}, _) => t
 | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 713 |       | Const (@{const_name snd}, _) => t
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 714 | (* simply-typed lambda calculus *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 715 | | Const (s, T) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 716 | (if is_IDT_constructor thy (s, T) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 717 | orelse is_IDT_recursor thy (s, T) then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 718 | t (* do not unfold IDT constructors/recursors *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 719 | (* unfold the constant if there is a defining equation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 720 | else case get_def thy (s, T) of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 721 | SOME (axname, rhs) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 722 | (* Note: if the term to be unfolded (i.e. 'Const (s, T)') *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 723 | (* occurs on the right-hand side of the equation, i.e. in *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 724 | (* 'rhs', we must not use this equation to unfold, because *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 725 | (* that would loop. Here would be the right place to *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 726 | (* check this. However, getting this really right seems *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 727 | (* difficult because the user may state arbitrary axioms, *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 728 | (* which could interact with overloading to create loops. *) | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 729 |           ((*Output.tracing (" unfolding: " ^ axname);*)
 | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 730 | unfold_loop rhs) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 731 | | NONE => t) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 732 | | Free _ => t | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 733 | | Var _ => t | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 734 | | Bound _ => t | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 735 | | Abs (s, T, body) => Abs (s, T, unfold_loop body) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 736 | | t1 $ t2 => (unfold_loop t1) $ (unfold_loop t2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 737 | val result = Envir.beta_eta_contract (unfold_loop t) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 738 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 739 | result | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 740 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 741 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 742 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 743 | (* collect_axioms: collects (monomorphic, universally quantified, unfolded *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 744 | (* versions of) all HOL axioms that are relevant w.r.t 't' *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 745 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 747 | (* Note: to make the collection of axioms more easily extensible, this *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 748 | (* function could be based on user-supplied "axiom collectors", *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 749 | (* similar to 'interpret'/interpreters or 'print'/printers *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 750 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 751 | (* Note: currently we use "inverse" functions to the definitional *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 752 | (* mechanisms provided by Isabelle/HOL, e.g. for "axclass", *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 753 | (* "typedef", "constdefs". A more general approach could consider *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 754 | (* *every* axiom of the theory and collect it if it has a constant/ *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 755 | (* type/typeclass in common with the term 't'. *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 756 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 757 | (* theory -> Term.term -> Term.term 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 | 758 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 759 | (* Which axioms are "relevant" for a particular term/type goes hand in *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 760 | (* hand with the interpretation of that term/type by its interpreter (see *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 761 | (* way below): if the interpretation respects an axiom anyway, the axiom *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 762 | (* does not need to be added as a constraint here. *) | 
| 14807 
e8ccb13d7774
major code change: refute can 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 764 | (* To avoid collecting the same axiom multiple times, we use an *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 765 | (* accumulator 'axs' which contains all axioms collected so far. *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 766 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 767 | fun collect_axioms thy t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 768 | let | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 769 | val _ = Output.tracing "Adding axioms..." | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 770 | (* (string * Term.term) list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 771 | val axioms = Theory.all_axioms_of thy | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 772 | (* string * Term.term -> Term.term list -> Term.term list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 773 | fun collect_this_axiom (axname, ax) axs = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 774 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 775 | val ax' = unfold_defs thy ax | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 776 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 777 | if member (op aconv) axs ax' then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 778 | axs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 779 | else ( | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 780 | Output.tracing axname; | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 781 | collect_term_axioms (ax' :: axs, ax') | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 782 | ) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 783 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 784 | (* Term.term list * Term.typ -> Term.term list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 785 | and collect_sort_axioms (axs, T) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 786 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 787 | (* string list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 788 | val sort = (case T of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 789 | TFree (_, sort) => sort | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 790 | | TVar (_, sort) => sort | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 791 |         | _               => raise REFUTE ("collect_axioms", "type " ^
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 792 | Syntax.string_of_typ_global thy T ^ " is not a variable")) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 793 | (* obtain axioms for all superclasses *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 794 | val superclasses = sort @ (maps (Sign.super_classes thy) sort) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 795 | (* merely an optimization, because 'collect_this_axiom' disallows *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 796 | (* duplicate axioms anyway: *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 797 | val superclasses = distinct (op =) superclasses | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 798 | val class_axioms = maps (fn class => map (fn ax => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 799 |         ("<" ^ class ^ ">", Thm.prop_of ax))
 | 
| 24928 
3419943838f5
renamed AxClass.get_definition to AxClass.get_info (again);
 wenzelm parents: 
24688diff
changeset | 800 | (#axioms (AxClass.get_info thy class) handle ERROR _ => [])) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 801 | superclasses | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 802 | (* replace the (at most one) schematic type variable in each axiom *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 803 | (* by the actual type 'T' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 804 | val monomorphic_class_axioms = map (fn (axname, ax) => | 
| 29272 | 805 | (case Term.add_tvars ax [] of | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 806 | [] => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 807 | (axname, ax) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 808 | | [(idx, S)] => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 809 | (axname, monomorphic_term (Vartab.make [(idx, (S, T))]) ax) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 810 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 811 |           raise REFUTE ("collect_axioms", "class axiom " ^ axname ^ " (" ^
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 812 | Syntax.string_of_term_global thy ax ^ | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 813 | ") contains more than one type variable"))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 814 | class_axioms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 815 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 816 | fold collect_this_axiom monomorphic_class_axioms axs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 817 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 818 | (* Term.term list * Term.typ -> Term.term list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 819 | and collect_type_axioms (axs, T) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 820 | case T of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 821 | (* simple types *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 822 |         Type ("prop", [])      => axs
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 823 |       | Type ("fun", [T1, T2]) => collect_type_axioms
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 824 | (collect_type_axioms (axs, T1), T2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 825 | (* axiomatic type classes *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 826 |       | Type ("itself", [T1])  => collect_type_axioms (axs, T1)
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 827 | | Type (s, Ts) => | 
| 31784 | 828 | (case Datatype.get_info thy s of | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 829 | SOME info => (* inductive datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 830 | (* only collect relevant type axioms for the argument types *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 831 | Library.foldl collect_type_axioms (axs, Ts) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 832 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 833 | (case get_typedef thy T of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 834 | SOME (axname, ax) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 835 | collect_this_axiom (axname, ax) axs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 836 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 837 | (* unspecified type, perhaps introduced with "typedecl" *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 838 | (* at least collect relevant type axioms for the argument types *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 839 | Library.foldl collect_type_axioms (axs, Ts))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 840 | (* axiomatic type classes *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 841 | | TFree _ => collect_sort_axioms (axs, T) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 842 | (* axiomatic type classes *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 843 | | TVar _ => collect_sort_axioms (axs, T) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 844 | (* Term.term list * Term.term -> Term.term list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 845 | and collect_term_axioms (axs, t) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 846 | case t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 847 | (* Pure *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 848 |         Const (@{const_name all}, _) => axs
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 849 |       | Const (@{const_name "=="}, _) => axs
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 850 |       | Const (@{const_name "==>"}, _) => axs
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 851 | (* axiomatic type classes *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 852 |       | Const (@{const_name TYPE}, T) => collect_type_axioms (axs, T)
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 853 | (* HOL *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 854 |       | Const (@{const_name Trueprop}, _) => axs
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 855 |       | Const (@{const_name Not}, _) => axs
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 856 | (* redundant, since 'True' is also an IDT constructor *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 857 |       | Const (@{const_name True}, _) => axs
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 858 | (* redundant, since 'False' is also an IDT constructor *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 859 |       | Const (@{const_name False}, _) => axs
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 860 |       | Const (@{const_name undefined}, T) => collect_type_axioms (axs, T)
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 861 |       | Const (@{const_name The}, T) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 862 | let | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 863 |           val ax = specialize_type thy (@{const_name The}, T)
 | 
| 29288 | 864 | (the (AList.lookup (op =) axioms "HOL.the_eq_trivial")) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 865 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 866 |           collect_this_axiom ("HOL.the_eq_trivial", ax) axs
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 867 | end | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 868 |       | Const (@{const_name Hilbert_Choice.Eps}, T) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 869 | let | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 870 |           val ax = specialize_type thy (@{const_name Hilbert_Choice.Eps}, T)
 | 
| 29288 | 871 | (the (AList.lookup (op =) axioms "Hilbert_Choice.someI")) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 872 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 873 |           collect_this_axiom ("Hilbert_Choice.someI", ax) axs
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 874 | end | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 875 |       | Const (@{const_name All}, T) => collect_type_axioms (axs, T)
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 876 |       | Const (@{const_name Ex}, T) => collect_type_axioms (axs, T)
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 877 |       | Const (@{const_name "op ="}, T) => collect_type_axioms (axs, T)
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 878 |       | Const (@{const_name "op &"}, _) => axs
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 879 |       | Const (@{const_name "op |"}, _) => axs
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 880 |       | Const (@{const_name "op -->"}, _) => axs
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 881 | (* sets *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 882 |       | Const (@{const_name Collect}, T) => collect_type_axioms (axs, T)
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 883 |       | Const (@{const_name "op :"}, T) => collect_type_axioms (axs, T)
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 884 | (* other optimizations *) | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 885 |       | Const (@{const_name Finite_Set.card}, T) => collect_type_axioms (axs, T)
 | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 886 |       | Const (@{const_name Finite_Set.finite}, T) =>
 | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 887 | collect_type_axioms (axs, T) | 
| 23881 | 888 |       | Const (@{const_name HOL.less}, T as Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 889 |         Type ("fun", [Type ("nat", []), Type ("bool", [])])])) =>
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 890 | collect_type_axioms (axs, T) | 
| 22997 | 891 |       | Const (@{const_name HOL.plus}, T as Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 892 |         Type ("fun", [Type ("nat", []), Type ("nat", [])])])) =>
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 893 | collect_type_axioms (axs, T) | 
| 22997 | 894 |       | Const (@{const_name HOL.minus}, T as Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 895 |         Type ("fun", [Type ("nat", []), Type ("nat", [])])])) =>
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 896 | collect_type_axioms (axs, T) | 
| 22997 | 897 |       | Const (@{const_name HOL.times}, T as Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 898 |         Type ("fun", [Type ("nat", []), Type ("nat", [])])])) =>
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 899 | collect_type_axioms (axs, T) | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 900 |       | Const (@{const_name List.append}, T) => collect_type_axioms (axs, T)
 | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 901 |       | Const (@{const_name lfp}, T) => collect_type_axioms (axs, T)
 | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 902 |       | Const (@{const_name gfp}, T) => collect_type_axioms (axs, T)
 | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 903 |       | Const (@{const_name fst}, T) => collect_type_axioms (axs, T)
 | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 904 |       | Const (@{const_name snd}, T) => collect_type_axioms (axs, T)
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 905 | (* simply-typed lambda calculus *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 906 | | Const (s, T) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 907 | if is_const_of_class thy (s, T) then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 908 | (* axiomatic type classes: add "OFCLASS(?'a::c, c_class)" *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 909 | (* and the class definition *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 910 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 911 | val class = Logic.class_of_const s | 
| 31943 
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
 wenzelm parents: 
31784diff
changeset | 912 |               val of_class = Logic.mk_of_class (TVar (("'a", 0), [class]), class)
 | 
| 
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
 wenzelm parents: 
31784diff
changeset | 913 | val ax_in = SOME (specialize_type thy (s, T) of_class) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 914 | (* type match may fail due to sort constraints *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 915 | handle Type.TYPE_MATCH => NONE | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 916 | val ax_1 = Option.map (fn ax => (Syntax.string_of_term_global thy ax, ax)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 917 | ax_in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 918 | val ax_2 = Option.map (apsnd (specialize_type thy (s, T))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 919 | (get_classdef thy class) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 920 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 921 | collect_type_axioms (fold collect_this_axiom | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 922 | (map_filter I [ax_1, ax_2]) axs, T) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 923 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 924 | else if is_IDT_constructor thy (s, T) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 925 | orelse is_IDT_recursor thy (s, T) then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 926 | (* only collect relevant type axioms *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 927 | collect_type_axioms (axs, T) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 928 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 929 | (* other constants should have been unfolded, with some *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 930 | (* exceptions: e.g. Abs_xxx/Rep_xxx functions for *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 931 | (* typedefs, or type-class related constants *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 932 | (* only collect relevant type axioms *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 933 | collect_type_axioms (axs, T) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 934 | | Free (_, T) => collect_type_axioms (axs, T) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 935 | | Var (_, T) => collect_type_axioms (axs, T) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 936 | | Bound i => axs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 937 | | Abs (_, T, body) => collect_term_axioms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 938 | (collect_type_axioms (axs, T), body) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 939 | | t1 $ t2 => collect_term_axioms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 940 | (collect_term_axioms (axs, t1), t2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 941 | (* Term.term list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 942 | val result = map close_form (collect_term_axioms ([], t)) | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 943 | val _ = Output.tracing " ...done." | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 944 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 945 | result | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 946 | end; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 947 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 948 | (* ------------------------------------------------------------------------- *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 949 | (* 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 | 950 | (* 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 | 951 | (* 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 | 952 | (* 'propT'. For IDTs, also the argument types of constructors *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 953 | (* and all mutually recursive IDTs are considered. *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 954 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 955 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 956 | fun ground_types thy t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 957 | let | 
| 29272 | 958 | fun collect_types T acc = | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 959 | (case T of | 
| 29272 | 960 |         Type ("fun", [T1, T2]) => collect_types T1 (collect_types T2 acc)
 | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 961 |       | Type ("prop", [])      => acc
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 962 | | Type (s, Ts) => | 
| 31784 | 963 | (case Datatype.get_info thy s of | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 964 | SOME info => (* inductive datatype *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 965 | let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 966 | val index = #index info | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 967 | val descr = #descr info | 
| 29288 | 968 | val (_, typs, _) = the (AList.lookup (op =) descr index) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 969 | val typ_assoc = typs ~~ Ts | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 970 | (* sanity check: every element in 'dtyps' must be a *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 971 | (* 'DtTFree' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 972 | val _ = if Library.exists (fn d => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 973 | case d of DatatypeAux.DtTFree _ => false | _ => true) typs then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 974 |               raise REFUTE ("ground_types", "datatype argument (for type "
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 975 | ^ Syntax.string_of_typ_global thy T ^ ") is not a variable") | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 976 | else () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 977 | (* required for mutually recursive datatypes; those need to *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 978 | (* be added even if they are an instance of an otherwise non- *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 979 | (* recursive datatype *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 980 | fun collect_dtyp (d, acc) = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 981 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 982 | val dT = typ_of_dtyp descr typ_assoc d | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 983 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 984 | case d of | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 985 | DatatypeAux.DtTFree _ => | 
| 29272 | 986 | collect_types dT acc | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 987 | | DatatypeAux.DtType (_, ds) => | 
| 30190 | 988 | collect_types dT (List.foldr collect_dtyp acc ds) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 989 | | DatatypeAux.DtRec i => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 990 | if dT mem acc then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 991 | acc (* prevent infinite recursion *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 992 | else | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 993 | let | 
| 29288 | 994 | val (_, dtyps, dconstrs) = the (AList.lookup (op =) descr i) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 995 | (* if the current type is a recursive IDT (i.e. a depth *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 996 | (* is required), add it to 'acc' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 997 | val acc_dT = if Library.exists (fn (_, ds) => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 998 | Library.exists DatatypeAux.is_rec_type ds) dconstrs then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 999 | insert (op =) dT acc | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1000 | else acc | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1001 | (* collect argument types *) | 
| 30190 | 1002 | val acc_dtyps = List.foldr collect_dtyp acc_dT dtyps | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1003 | (* collect constructor types *) | 
| 30190 | 1004 | val acc_dconstrs = List.foldr collect_dtyp acc_dtyps | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1005 | (List.concat (map snd dconstrs)) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1006 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1007 | acc_dconstrs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1008 | end | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1009 | end | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1010 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1011 | (* argument types 'Ts' could be added here, but they are also *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1012 | (* added by 'collect_dtyp' automatically *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1013 | collect_dtyp (DatatypeAux.DtRec index, acc) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1014 | end | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1015 | | NONE => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1016 | (* not an inductive datatype, e.g. defined via "typedef" or *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1017 | (* "typedecl" *) | 
| 29272 | 1018 | insert (op =) T (fold collect_types Ts acc)) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1019 | | TFree _ => insert (op =) T acc | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1020 | | TVar _ => insert (op =) T acc) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1021 | in | 
| 29272 | 1022 | fold_types collect_types t [] | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1023 | 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 | 1024 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1025 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1026 | (* 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 | 1027 | (* 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 | 1028 | (* 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 | 1029 | (* 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 | 1030 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1031 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1032 | (* Term.typ -> string *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1033 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1034 | fun string_of_typ (Type (s, _)) = s | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1035 | | string_of_typ (TFree (s, _)) = s | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1036 | | string_of_typ (TVar ((s,_), _)) = s; | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1037 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1038 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1039 | (* 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 | 1040 | (* '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 | 1041 | (* '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 | 1042 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1043 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1044 | (* Term.typ list -> (string * int) list -> int -> (Term.typ * int) 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 | 1045 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1046 | fun first_universe xs sizes minsize = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1047 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1048 | fun size_of_typ T = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1049 | case AList.lookup (op =) sizes (string_of_typ T) of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1050 | SOME n => n | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1051 | | NONE => minsize | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1052 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1053 | map (fn T => (T, size_of_typ T)) xs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1054 | 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 | 1055 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1056 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1057 | (* 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 | 1058 | (* 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 | 1059 | (* '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 | 1060 | (* 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 | 1061 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1062 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1063 | (* (Term.typ * int) list -> (string * int) list -> int -> int -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1064 | (Term.typ * int) list option *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1065 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1066 | fun next_universe xs sizes minsize maxsize = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1067 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1068 | (* creates the "first" list of length 'len', where the sum of all list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1069 | (* elements is 'sum', and the length of the list is 'len' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1070 | (* int -> int -> int -> int list option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1071 | fun make_first _ 0 sum = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1072 | if sum=0 then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1073 | SOME [] | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1074 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1075 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1076 | | make_first max len sum = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1077 | if sum<=max orelse max<0 then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1078 | Option.map (fn xs' => sum :: xs') (make_first max (len-1) 0) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1079 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1080 | Option.map (fn xs' => max :: xs') (make_first max (len-1) (sum-max)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1081 | (* enumerates all int lists with a fixed length, where 0<=x<='max' for *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1082 | (* all list elements x (unless 'max'<0) *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1083 | (* int -> int -> int -> int list -> int list option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1084 | fun next max len sum [] = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1085 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1086 | | next max len sum [x] = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1087 | (* we've reached the last list element, so there's no shift possible *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1088 | make_first max (len+1) (sum+x+1) (* increment 'sum' by 1 *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1089 | | next max len sum (x1::x2::xs) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1090 | if x1>0 andalso (x2<max orelse max<0) then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1091 | (* we can shift *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1092 | SOME (valOf (make_first max (len+1) (sum+x1-1)) @ (x2+1) :: xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1093 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1094 | (* continue search *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1095 | next max (len+1) (sum+x1) (x2::xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1096 | (* only consider those types for which the size is not fixed *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1097 | val mutables = List.filter | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1098 | (not o (AList.defined (op =) sizes) o string_of_typ o fst) xs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1099 | (* subtract 'minsize' from every size (will be added again at the end) *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1100 | val diffs = map (fn (_, n) => n-minsize) mutables | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1101 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1102 | case next (maxsize-minsize) 0 0 diffs of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1103 | SOME diffs' => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1104 | (* merge with those types for which the size is fixed *) | 
| 30190 | 1105 | SOME (snd (Library.foldl_map (fn (ds, (T, _)) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1106 | case AList.lookup (op =) sizes (string_of_typ T) of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1107 | (* return the fixed size *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1108 | SOME n => (ds, (T, n)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1109 | (* consume the head of 'ds', add 'minsize' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1110 | | NONE => (tl ds, (T, minsize + hd ds))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1111 | (diffs', xs))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1112 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1113 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1114 | 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 | 1115 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1116 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1117 | (* 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 | 1118 | (* 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 | 1119 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1120 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1121 | (* interpretation -> prop_formula *) | 
| 14807 
e8ccb13d7774
major code change: refute can 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1123 | fun toTrue (Leaf [fm, _]) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1124 | fm | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1125 | | toTrue _ = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1126 |     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 | 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 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can 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 | (* 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 | 1130 | (* 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 | 1131 | (* 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 | 1132 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1134 | (* interpretation -> prop_formula *) | 
| 14807 
e8ccb13d7774
major code change: refute can 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1136 | fun toFalse (Leaf [_, fm]) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1137 | fm | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1138 | | toFalse _ = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1139 |     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 | 1140 | |
| 
e8ccb13d7774
major code change: refute can 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 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can 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 | (* 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 | 1143 | (* 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 | 1144 | (* 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 | 1145 | (* 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 | 1146 | (* {...}     : 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 | 1147 | (* 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 | 1148 | (* 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 | 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1151 | (* theory -> params -> Term.term -> bool -> unit *) | 
| 14807 
e8ccb13d7774
major code change: refute can 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 | |
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1153 |   fun find_model thy {sizes, minsize, maxsize, maxvars, maxtime, satsolver,
 | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1154 | expect} t negate = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1155 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1156 | (* unit -> unit *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1157 | fun wrapper () = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1158 | let | 
| 30349 | 1159 | val timer = Timer.startRealTimer () | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1160 | val u = unfold_defs thy t | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1161 |       val _      = Output.tracing ("Unfolded term: " ^
 | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1162 | Syntax.string_of_term_global thy u) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1163 | val axioms = collect_axioms thy u | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1164 | (* Term.typ list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1165 | val types = Library.foldl (fn (acc, t') => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1166 | acc union (ground_types thy t')) ([], u :: axioms) | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1167 |       val _     = Output.tracing ("Ground types: "
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1168 | ^ (if null types then "none." | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 1169 | else commas (map (Syntax.string_of_typ_global thy) types))) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1170 | (* we can only consider fragments of recursive IDTs, so we issue a *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1171 | (* warning if the formula contains a recursive IDT *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1172 | (* TODO: no warning needed for /positive/ occurrences of IDTs *) | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1173 | val maybe_spurious = Library.exists (fn | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1174 | Type (s, _) => | 
| 31784 | 1175 | (case Datatype.get_info thy s of | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1176 | SOME info => (* inductive datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1177 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1178 | val index = #index info | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1179 | val descr = #descr info | 
| 29288 | 1180 | val (_, _, constrs) = the (AList.lookup (op =) descr index) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1181 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1182 | (* recursive datatype? *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1183 | Library.exists (fn (_, ds) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1184 | Library.exists DatatypeAux.is_rec_type ds) constrs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1185 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1186 | | NONE => false) | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1187 | | _ => false) types | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1188 | val _ = if maybe_spurious then | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1189 |           warning ("Term contains a recursive datatype; "
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1190 | ^ "countermodel(s) may be spurious!") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1191 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1192 | () | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1193 | (* (Term.typ * int) list -> string *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1194 | fun find_model_loop universe = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1195 | let | 
| 30349 | 1196 | val msecs_spent = Time.toMilliseconds (Timer.checkRealTimer timer) | 
| 1197 | val _ = maxtime = 0 orelse msecs_spent < 1000 * maxtime | |
| 1198 | orelse raise TimeLimit.TimeOut | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1199 | val init_model = (universe, []) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1200 |         val init_args  = {maxvars = maxvars, def_eq = false, next_idx = 1,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1201 | bounds = [], wellformed = True} | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1202 |         val _          = Output.tracing ("Translating term (sizes: "
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1203 | ^ commas (map (fn (_, n) => string_of_int n) universe) ^ ") ...") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1204 | (* translate 'u' and all axioms *) | 
| 30190 | 1205 | val ((model, args), intrs) = Library.foldl_map (fn ((m, a), t') => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1206 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1207 | val (i, m', a') = interpret thy m a t' | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1208 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1209 | (* set 'def_eq' to 'true' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1210 |             ((m', {maxvars = #maxvars a', def_eq = true,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1211 | next_idx = #next_idx a', bounds = #bounds a', | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1212 | wellformed = #wellformed a'}), i) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1213 | end) ((init_model, init_args), u :: axioms) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1214 | (* make 'u' either true or false, and make all axioms true, and *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1215 | (* add the well-formedness side condition *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1216 | val fm_u = (if negate then toFalse else toTrue) (hd intrs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1217 | val fm_ax = PropLogic.all (map toTrue (tl intrs)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1218 | val fm = PropLogic.all [#wellformed args, fm_ax, fm_u] | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1219 | in | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1220 | Output.priority "Invoking SAT solver..."; | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1221 | (case SatSolver.invoke_solver satsolver fm of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1222 | SatSolver.SATISFIABLE assignment => | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1223 |           (Output.priority ("*** Model found: ***\n" ^ print_model thy model
 | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1224 | (fn i => case assignment i of SOME b => b | NONE => true)); | 
| 30347 
91f73b2997f9
Refute: Distinguish between "genuine" and "potential" in the newly added "expect" option.
 blanchet parents: 
30314diff
changeset | 1225 | if maybe_spurious then "potential" else "genuine") | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1226 | | SatSolver.UNSATISFIABLE _ => | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1227 | (Output.priority "No model exists."; | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1228 | case next_universe universe sizes minsize maxsize of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1229 | SOME universe' => find_model_loop universe' | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1230 | | NONE => (Output.priority | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1231 | "Search terminated, no larger universe within the given limits."; | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1232 | "none")) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1233 | | SatSolver.UNKNOWN => | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1234 | (Output.priority "No model found."; | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1235 | case next_universe universe sizes minsize maxsize of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1236 | SOME universe' => find_model_loop universe' | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1237 | | NONE => (Output.priority | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1238 | "Search terminated, no larger universe within the given limits."; | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1239 | "unknown")) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1240 | ) handle SatSolver.NOT_CONFIGURED => | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1241 |           (error ("SAT solver " ^ quote satsolver ^ " is not configured.");
 | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1242 | "unknown") | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1243 | end handle MAXVARS_EXCEEDED => | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1244 |         (Output.priority ("Search terminated, number of Boolean variables ("
 | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1245 | ^ string_of_int maxvars ^ " allowed) exceeded."); | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1246 | "unknown") | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1247 | val outcome_code = find_model_loop (first_universe types sizes minsize) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1248 | in | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1249 | if expect = "" orelse outcome_code = expect then () | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1250 |         else error ("Unexpected outcome: " ^ quote outcome_code ^ ".")
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1251 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1252 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1253 | (* some parameter sanity checks *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1254 | minsize>=1 orelse | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1255 |         error ("\"minsize\" is " ^ string_of_int minsize ^ ", must be at least 1");
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1256 | maxsize>=1 orelse | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1257 |         error ("\"maxsize\" is " ^ string_of_int maxsize ^ ", must be at least 1");
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1258 | maxsize>=minsize orelse | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1259 |         error ("\"maxsize\" (=" ^ string_of_int maxsize ^
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1260 | ") is less than \"minsize\" (=" ^ string_of_int minsize ^ ")."); | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1261 | maxvars>=0 orelse | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1262 |         error ("\"maxvars\" is " ^ string_of_int maxvars ^ ", must be at least 0");
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1263 | maxtime>=0 orelse | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1264 |         error ("\"maxtime\" is " ^ string_of_int maxtime ^ ", must be at least 0");
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1265 | (* enter loop with or without time limit *) | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1266 |       Output.priority ("Trying to find a model that "
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1267 | ^ (if negate then "refutes" else "satisfies") ^ ": " | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 1268 | ^ Syntax.string_of_term_global thy t); | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1269 | if maxtime>0 then ( | 
| 24688 
a5754ca5c510
replaced interrupt_timeout by TimeLimit.timeLimit (available on SML/NJ and Poly/ML 5.1);
 wenzelm parents: 
23881diff
changeset | 1270 | TimeLimit.timeLimit (Time.fromSeconds maxtime) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1271 | wrapper () | 
| 24688 
a5754ca5c510
replaced interrupt_timeout by TimeLimit.timeLimit (available on SML/NJ and Poly/ML 5.1);
 wenzelm parents: 
23881diff
changeset | 1272 | handle TimeLimit.TimeOut => | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1273 |           Output.priority ("Search terminated, time limit (" ^
 | 
| 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1274 | string_of_int maxtime | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1275 | ^ (if maxtime=1 then " second" else " seconds") ^ ") exceeded.") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1276 | ) else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1277 | wrapper () | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1278 | end; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1279 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1280 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1281 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1282 | (* INTERFACE, PART 2: FINDING A MODEL *) | 
| 14350 | 1283 | (* ------------------------------------------------------------------------- *) | 
| 1284 | ||
| 1285 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1286 | (* 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 | 1287 | (* 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 | 1288 | (* parameters *) | 
| 14350 | 1289 | (* ------------------------------------------------------------------------- *) | 
| 1290 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1291 | (* theory -> (string * string) list -> Term.term -> unit *) | 
| 14350 | 1292 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1293 | fun satisfy_term thy params t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1294 | find_model thy (actual_params thy params) t false; | 
| 14350 | 1295 | |
| 1296 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1297 | (* 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 | 1298 | (* 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 | 1299 | (* parameters *) | 
| 14350 | 1300 | (* ------------------------------------------------------------------------- *) | 
| 1301 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1302 | (* theory -> (string * string) list -> Term.term -> unit *) | 
| 14350 | 1303 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1304 | fun refute_term thy params t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1305 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1306 | (* disallow schematic type variables, since we cannot properly negate *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1307 | (* terms containing them (their logical meaning is that there EXISTS a *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1308 | (* type s.t. ...; to refute such a formula, we would have to show that *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1309 | (* for ALL types, not ...) *) | 
| 29272 | 1310 | val _ = null (Term.add_tvars t []) orelse | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1311 | error "Term to be refuted contains schematic type variables" | 
| 21556 | 1312 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1313 | (* existential closure over schematic variables *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1314 | (* (Term.indexname * Term.typ) list *) | 
| 29265 
5b4247055bd7
moved old add_term_vars, add_term_frees etc. to structure OldTerm;
 wenzelm parents: 
29004diff
changeset | 1315 | val vars = sort_wrt (fst o fst) (map dest_Var (OldTerm.term_vars t)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1316 | (* Term.term *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1317 | val ex_closure = Library.foldl (fn (t', ((x, i), T)) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1318 | (HOLogic.exists_const T) $ | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1319 | Abs (x, T, abstract_over (Var ((x, i), T), t'))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1320 | (t, vars) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1321 | (* Note: If 't' is of type 'propT' (rather than 'boolT'), applying *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1322 | (* 'HOLogic.exists_const' is not type-correct. However, this is not *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1323 | (* really a problem as long as 'find_model' still interprets the *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1324 | (* resulting term correctly, without checking its type. *) | 
| 21556 | 1325 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1326 | (* replace outermost universally quantified variables by Free's: *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1327 | (* refuting a term with Free's is generally faster than refuting a *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1328 | (* term with (nested) quantifiers, because quantifiers are expanded, *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1329 | (* while the SAT solver searches for an interpretation for Free's. *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1330 | (* Also we get more information back that way, namely an *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1331 | (* interpretation which includes values for the (formerly) *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1332 | (* quantified variables. *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1333 | (* maps !!x1...xn. !xk...xm. t to t *) | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 1334 |     fun strip_all_body (Const (@{const_name all}, _) $ Abs (_, _, t)) =
 | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 1335 | strip_all_body t | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 1336 |       | strip_all_body (Const (@{const_name Trueprop}, _) $ t) =
 | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 1337 | strip_all_body t | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 1338 |       | strip_all_body (Const (@{const_name All}, _) $ Abs (_, _, t)) =
 | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 1339 | strip_all_body t | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1340 | | strip_all_body t = t | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1341 | (* maps !!x1...xn. !xk...xm. t to [x1, ..., xn, xk, ..., xm] *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1342 |     fun strip_all_vars (Const (@{const_name all}, _) $ Abs (a, T, t)) =
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1343 | (a, T) :: strip_all_vars t | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1344 |       | strip_all_vars (Const (@{const_name Trueprop}, _) $ t) =
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1345 | strip_all_vars t | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1346 |       | strip_all_vars (Const (@{const_name All}, _) $ Abs (a, T, t)) =
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1347 | (a, T) :: strip_all_vars t | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1348 | | strip_all_vars t = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1349 | [] : (string * typ) list | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1350 | val strip_t = strip_all_body ex_closure | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1351 | val frees = Term.rename_wrt_term strip_t (strip_all_vars ex_closure) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1352 | val subst_t = Term.subst_bounds (map Free frees, strip_t) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1353 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1354 | find_model thy (actual_params thy params) subst_t true | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1355 | end; | 
| 14350 | 1356 | |
| 1357 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1358 | (* refute_subgoal: calls 'refute_term' on a specific subgoal *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1359 | (* 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 | 1360 | (* parameters *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1361 | (* subgoal : 0-based index specifying the subgoal number *) | 
| 14350 | 1362 | (* ------------------------------------------------------------------------- *) | 
| 1363 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1364 | (* theory -> (string * string) list -> Thm.thm -> int -> unit *) | 
| 14350 | 1365 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1366 | fun refute_subgoal thy params thm subgoal = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1367 | refute_term thy params (List.nth (Thm.prems_of thm, subgoal)); | 
| 14350 | 1368 | |
| 1369 | ||
| 1370 | (* ------------------------------------------------------------------------- *) | |
| 15292 | 1371 | (* INTERPRETERS: Auxiliary Functions *) | 
| 14350 | 1372 | (* ------------------------------------------------------------------------- *) | 
| 1373 | ||
| 1374 | (* ------------------------------------------------------------------------- *) | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1375 | (* make_constants: returns all interpretations for type 'T' that consist of *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1376 | (* unit vectors with 'True'/'False' only (no Boolean *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1377 | (* variables) *) | 
| 14350 | 1378 | (* ------------------------------------------------------------------------- *) | 
| 1379 | ||
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1380 | (* theory -> model -> Term.typ -> interpretation list *) | 
| 14350 | 1381 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1382 | fun make_constants thy model T = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1383 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1384 | (* returns a list with all unit vectors of length n *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1385 | (* int -> interpretation list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1386 | fun unit_vectors n = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1387 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1388 | (* returns the k-th unit vector of length n *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1389 | (* int * int -> interpretation *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1390 | fun unit_vector (k, n) = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1391 | Leaf ((replicate (k-1) False) @ (True :: (replicate (n-k) False))) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1392 | (* int -> interpretation list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1393 | fun unit_vectors_loop k = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1394 | if k>n then [] else unit_vector (k,n) :: unit_vectors_loop (k+1) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1395 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1396 | unit_vectors_loop 1 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1397 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1398 | (* returns a list of lists, each one consisting of n (possibly *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1399 | (* identical) elements from 'xs' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1400 | (* int -> 'a list -> 'a list list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1401 | fun pick_all 1 xs = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1402 | map single xs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1403 | | pick_all n xs = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1404 | let val rec_pick = pick_all (n-1) xs in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1405 | List.concat (map (fn x => map (cons x) rec_pick) xs) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1406 | end | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1407 | (* returns all constant interpretations that have the same tree *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1408 | (* structure as the interpretation argument *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1409 | (* interpretation -> interpretation list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1410 | fun make_constants_intr (Leaf xs) = unit_vectors (length xs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1411 | | make_constants_intr (Node xs) = map Node (pick_all (length xs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1412 | (make_constants_intr (hd xs))) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1413 | (* obtain the interpretation for a variable of type 'T' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1414 |     val (i, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1,
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1415 |       bounds=[], wellformed=True} (Free ("dummy", T))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1416 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1417 | make_constants_intr i | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1418 | 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 | 1419 | |
| 
e8ccb13d7774
major code change: refute can 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 | (* ------------------------------------------------------------------------- *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1421 | (* power: 'power (a, b)' computes a^b, for a>=0, b>=0 *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1422 | (* ------------------------------------------------------------------------- *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1423 | |
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1424 | (* int * int -> int *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1425 | |
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1426 | fun power (a, 0) = 1 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1427 | | power (a, 1) = a | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1428 | | power (a, b) = let val ab = power(a, b div 2) in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1429 | ab * ab * power(a, b mod 2) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1430 | end; | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1431 | |
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1432 | (* ------------------------------------------------------------------------- *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1433 | (* size_of_type: returns the number of elements in a type 'T' (i.e. 'length *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1434 | (* (make_constants T)', but implemented more efficiently) *) | 
| 14807 
e8ccb13d7774
major code change: refute can 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 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can 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 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1437 | (* theory -> model -> Term.typ -> int *) | 
| 14807 
e8ccb13d7774
major code change: refute can 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 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1439 | (* returns 0 for an empty ground type or a function type with empty *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1440 | (* codomain, but fails for a function type with empty domain -- *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1441 | (* admissibility of datatype constructor argument types (see "Inductive *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1442 | (* datatypes in HOL - lessons learned ...", S. Berghofer, M. Wenzel, *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1443 | (* TPHOLs 99) ensures that recursive, possibly empty, datatype fragments *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1444 | (* never occur as the domain of a function type that is the type of a *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1445 | (* constructor argument *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1446 | |
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1447 | fun size_of_type thy model T = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1448 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1449 | (* returns the number of elements that have the same tree structure as a *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1450 | (* given interpretation *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1451 | fun size_of_intr (Leaf xs) = length xs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1452 | | size_of_intr (Node xs) = power (size_of_intr (hd xs), length xs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1453 | (* obtain the interpretation for a variable of type 'T' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1454 |     val (i, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1,
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1455 |       bounds=[], wellformed=True} (Free ("dummy", T))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1456 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1457 | size_of_intr i | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1458 | 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 | 1459 | |
| 
e8ccb13d7774
major code change: refute can 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 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can 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 | (* 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 | 1462 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1463 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1464 | (* 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 | 1465 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1466 | val TT = Leaf [True, 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 | 1467 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1468 | val FF = Leaf [False, True]; | 
| 14807 
e8ccb13d7774
major code change: refute can 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 | |
| 
e8ccb13d7774
major code change: refute can 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 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can 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 | (* 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 | 1472 | (* 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 | 1473 | (* - 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 | 1474 | (* 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 | 1475 | (* - 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 | 1476 | (* 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 | 1477 | (* - 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 | 1478 | (* '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 | 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1481 | (* We could in principle represent '=' on a type T by a particular *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1482 | (* interpretation. However, the size of that interpretation is quadratic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1483 | (* in the size of T. Therefore comparing the interpretations 'i1' and *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1484 | (* 'i2' directly is more efficient than constructing the interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1485 | (* for equality on T first, and "applying" this interpretation to 'i1' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1486 | (* and 'i2' in the usual way (cf. 'interpretation_apply') 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 | 1487 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1488 | (* interpretation * interpretation -> 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 | 1489 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1490 | fun make_equality (i1, i2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1491 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1492 | (* interpretation * interpretation -> prop_formula *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1493 | fun equal (i1, i2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1494 | (case i1 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1495 | Leaf xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1496 | (case i2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1497 | Leaf ys => PropLogic.dot_product (xs, ys) (* defined and equal *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1498 |         | Node _  => raise REFUTE ("make_equality",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1499 | "second interpretation is higher")) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1500 | | Node xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1501 | (case i2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1502 |           Leaf _  => raise REFUTE ("make_equality",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1503 | "first interpretation is higher") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1504 | | Node ys => PropLogic.all (map equal (xs ~~ ys)))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1505 | (* interpretation * interpretation -> prop_formula *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1506 | fun not_equal (i1, i2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1507 | (case i1 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1508 | Leaf xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1509 | (case i2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1510 | (* defined and not equal *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1511 | Leaf ys => PropLogic.all ((PropLogic.exists xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1512 | :: (PropLogic.exists ys) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1513 | :: (map (fn (x,y) => SOr (SNot x, SNot y)) (xs ~~ ys))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1514 |         | Node _  => raise REFUTE ("make_equality",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1515 | "second interpretation is higher")) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1516 | | Node xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1517 | (case i2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1518 |           Leaf _  => raise REFUTE ("make_equality",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1519 | "first interpretation is higher") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1520 | | Node ys => PropLogic.exists (map not_equal (xs ~~ ys)))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1521 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1522 | (* a value may be undefined; therefore 'not_equal' is not just the *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1523 | (* negation of 'equal' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1524 | Leaf [equal (i1, i2), not_equal (i1, i2)] | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1525 | 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 | 1526 | |
| 15292 | 1527 | (* ------------------------------------------------------------------------- *) | 
| 15547 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1528 | (* 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 | 1529 | (* 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 | 1530 | (* 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 | 1531 | (* 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 | 1532 | (* 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 | 1533 | (* 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 | 1534 | (* ------------------------------------------------------------------------- *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1535 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1536 | (* interpretation * interpretation -> 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 | 1537 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1538 | fun make_def_equality (i1, i2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1539 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1540 | (* interpretation * interpretation -> prop_formula *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1541 | fun equal (i1, i2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1542 | (case i1 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1543 | Leaf xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1544 | (case i2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1545 | (* defined and equal, or both undefined *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1546 | Leaf ys => SOr (PropLogic.dot_product (xs, ys), | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1547 | SAnd (PropLogic.all (map SNot xs), PropLogic.all (map SNot ys))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1548 |         | Node _  => raise REFUTE ("make_def_equality",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1549 | "second interpretation is higher")) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1550 | | Node xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1551 | (case i2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1552 |           Leaf _  => raise REFUTE ("make_def_equality",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1553 | "first interpretation is higher") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1554 | | Node ys => PropLogic.all (map equal (xs ~~ ys)))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1555 | (* interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1556 | val eq = equal (i1, i2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1557 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1558 | Leaf [eq, SNot eq] | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1559 | 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 | 1560 | |
| 
f08e2d83681e
major code 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 | (* ------------------------------------------------------------------------- *) | 
| 
f08e2d83681e
major code 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 | (* interpretation_apply: returns an interpretation that denotes the result *) | 
| 22092 | 1563 | (* of applying the function denoted by 'i1' to 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 | 1564 | (* 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 | 1565 | (* ------------------------------------------------------------------------- *) | 
| 
f08e2d83681e
major code 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1567 | (* interpretation * interpretation -> 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 | 1568 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1569 | fun interpretation_apply (i1, i2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1570 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1571 | (* interpretation * interpretation -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1572 | fun interpretation_disjunction (tr1,tr2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1573 | tree_map (fn (xs,ys) => map (fn (x,y) => SOr(x,y)) (xs ~~ ys)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1574 | (tree_pair (tr1,tr2)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1575 | (* prop_formula * interpretation -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1576 | fun prop_formula_times_interpretation (fm,tr) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1577 | tree_map (map (fn x => SAnd (fm,x))) tr | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1578 | (* prop_formula list * interpretation list -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1579 | fun prop_formula_list_dot_product_interpretation_list ([fm],[tr]) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1580 | prop_formula_times_interpretation (fm,tr) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1581 | | prop_formula_list_dot_product_interpretation_list (fm::fms,tr::trees) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1582 | interpretation_disjunction (prop_formula_times_interpretation (fm,tr), | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1583 | prop_formula_list_dot_product_interpretation_list (fms,trees)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1584 | | prop_formula_list_dot_product_interpretation_list (_,_) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1585 |       raise REFUTE ("interpretation_apply", "empty list (in dot product)")
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1586 | (* concatenates 'x' with every list in 'xss', returning a new list of *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1587 | (* lists *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1588 | (* 'a -> 'a list list -> 'a list list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1589 | fun cons_list x xss = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1590 | map (cons x) xss | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1591 | (* returns a list of lists, each one consisting of one element from each *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1592 | (* element of 'xss' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1593 | (* 'a list list -> 'a list list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1594 | fun pick_all [xs] = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1595 | map single xs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1596 | | pick_all (xs::xss) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1597 | let val rec_pick = pick_all xss in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1598 | List.concat (map (fn x => map (cons x) rec_pick) xs) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1599 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1600 | | pick_all _ = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1601 |       raise REFUTE ("interpretation_apply", "empty list (in pick_all)")
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1602 | (* interpretation -> prop_formula list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1603 | fun interpretation_to_prop_formula_list (Leaf xs) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1604 | xs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1605 | | interpretation_to_prop_formula_list (Node trees) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1606 | map PropLogic.all (pick_all | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1607 | (map interpretation_to_prop_formula_list trees)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1608 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1609 | case i1 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1610 | Leaf _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1611 |       raise REFUTE ("interpretation_apply", "first interpretation is a leaf")
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1612 | | Node xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1613 | prop_formula_list_dot_product_interpretation_list | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1614 | (interpretation_to_prop_formula_list i2, xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1615 | 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 | 1616 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1617 | (* ------------------------------------------------------------------------- *) | 
| 15292 | 1618 | (* eta_expand: eta-expands a term 't' by adding 'i' lambda abstractions *) | 
| 1619 | (* ------------------------------------------------------------------------- *) | |
| 1620 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1621 | (* Term.term -> int -> Term.term *) | 
| 15292 | 1622 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1623 | fun eta_expand t i = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1624 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1625 | val Ts = Term.binder_types (Term.fastype_of t) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1626 | val t' = Term.incr_boundvars i t | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1627 | in | 
| 30190 | 1628 |     List.foldr (fn (T, term) => Abs ("<eta_expand>", T, term))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1629 | (Term.list_comb (t', map Bound (i-1 downto 0))) (List.take (Ts, i)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1630 | end; | 
| 15292 | 1631 | |
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1632 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1633 | (* sum: returns the sum of a list 'xs' of integers *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1634 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1635 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1636 | (* int list -> int *) | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1637 | |
| 30190 | 1638 | fun sum xs = List.foldl op+ 0 xs; | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1639 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1640 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1641 | (* product: returns the product of a list 'xs' of integers *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1642 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1643 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1644 | (* int list -> int *) | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1645 | |
| 30190 | 1646 | fun product xs = List.foldl op* 1 xs; | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1647 | |
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1648 | (* ------------------------------------------------------------------------- *) | 
| 15547 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1649 | (* 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 | 1650 | (* 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 | 1651 | (* their arguments) of the size of the argument types *) | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1652 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1653 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1654 | fun size_of_dtyp thy typ_sizes descr typ_assoc constructors = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1655 | sum (map (fn (_, dtyps) => | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1656 | product (map (size_of_type thy (typ_sizes, []) o | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1657 | (typ_of_dtyp descr typ_assoc)) dtyps)) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1658 | constructors); | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1659 | |
| 15292 | 1660 | |
| 1661 | (* ------------------------------------------------------------------------- *) | |
| 1662 | (* INTERPRETERS: Actual Interpreters *) | |
| 1663 | (* ------------------------------------------------------------------------- *) | |
| 14807 
e8ccb13d7774
major code change: refute can 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1665 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1666 | (interpretation * model * arguments) option *) | 
| 14807 
e8ccb13d7774
major code change: refute can 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1668 | (* simply typed lambda calculus: Isabelle's basic term syntax, with type *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1669 | (* variables, function types, and propT *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1670 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1671 | fun stlc_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1672 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1673 | val (typs, terms) = model | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1674 |     val {maxvars, def_eq, next_idx, bounds, wellformed} = args
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1675 | (* Term.typ -> (interpretation * model * arguments) option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1676 | fun interpret_groundterm T = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1677 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1678 | (* unit -> (interpretation * model * arguments) option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1679 | fun interpret_groundtype () = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1680 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1681 | (* the model must specify a size for ground types *) | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 1682 | val size = if T = Term.propT then 2 | 
| 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 1683 | else the (AList.lookup (op =) typs T) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1684 | val next = next_idx+size | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1685 | (* check if 'maxvars' is large enough *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1686 | val _ = (if next-1>maxvars andalso maxvars>0 then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1687 | raise MAXVARS_EXCEEDED else ()) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1688 | (* prop_formula list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1689 | val fms = map BoolVar (next_idx upto (next_idx+size-1)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1690 | (* interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1691 | val intr = Leaf fms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1692 | (* prop_formula list -> prop_formula *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1693 | fun one_of_two_false [] = True | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1694 | | one_of_two_false (x::xs) = SAnd (PropLogic.all (map (fn x' => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1695 | SOr (SNot x, SNot x')) xs), one_of_two_false xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1696 | (* prop_formula *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1697 | val wf = one_of_two_false fms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1698 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1699 | (* extend the model, increase 'next_idx', add well-formedness *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1700 | (* condition *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1701 |         SOME (intr, (typs, (t, intr)::terms), {maxvars = maxvars,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1702 | def_eq = def_eq, next_idx = next, bounds = bounds, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1703 | wellformed = SAnd (wellformed, wf)}) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1704 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1705 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1706 | case T of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1707 |         Type ("fun", [T1, T2]) =>
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1708 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1709 | (* we create 'size_of_type ... T1' different copies of the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1710 | (* interpretation for 'T2', which are then combined into a single *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1711 | (* new interpretation *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1712 | (* make fresh copies, with different variable indices *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1713 | (* 'idx': next variable index *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1714 | (* 'n' : number of copies *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1715 | (* int -> int -> (int * interpretation list * prop_formula *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1716 | fun make_copies idx 0 = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1717 | (idx, [], True) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1718 | | make_copies idx n = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1719 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1720 | val (copy, _, new_args) = interpret thy (typs, []) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1721 |                 {maxvars = maxvars, def_eq = false, next_idx = idx,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1722 |                 bounds = [], wellformed = True} (Free ("dummy", T2))
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1723 | val (idx', copies, wf') = make_copies (#next_idx new_args) (n-1) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1724 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1725 | (idx', copy :: copies, SAnd (#wellformed new_args, wf')) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1726 | end | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1727 | val (next, copies, wf) = make_copies next_idx | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1728 | (size_of_type thy model T1) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1729 | (* combine copies into a single interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1730 | val intr = Node copies | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1731 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1732 | (* extend the model, increase 'next_idx', add well-formedness *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1733 | (* condition *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1734 |           SOME (intr, (typs, (t, intr)::terms), {maxvars = maxvars,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1735 | def_eq = def_eq, next_idx = next, bounds = bounds, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1736 | wellformed = SAnd (wellformed, wf)}) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1737 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1738 | | Type _ => interpret_groundtype () | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1739 | | TFree _ => interpret_groundtype () | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1740 | | TVar _ => interpret_groundtype () | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1741 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1742 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1743 | case AList.lookup (op =) terms t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1744 | SOME intr => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1745 | (* return an existing interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1746 | SOME (intr, model, args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1747 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1748 | (case t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1749 | Const (_, T) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1750 | interpret_groundterm T | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1751 | | Free (_, T) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1752 | interpret_groundterm T | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1753 | | Var (_, T) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1754 | interpret_groundterm T | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1755 | | Bound i => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1756 | SOME (List.nth (#bounds args, i), model, args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1757 | | Abs (x, T, body) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1758 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1759 | (* create all constants of type 'T' *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1760 | val constants = make_constants thy model T | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1761 | (* interpret the 'body' separately for each constant *) | 
| 30190 | 1762 | val ((model', args'), bodies) = Library.foldl_map | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1763 | (fn ((m, a), c) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1764 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1765 | (* add 'c' to 'bounds' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1766 |                 val (i', m', a') = interpret thy m {maxvars = #maxvars a,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1767 | def_eq = #def_eq a, next_idx = #next_idx a, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1768 | bounds = (c :: #bounds a), wellformed = #wellformed a} body | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1769 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1770 | (* keep the new model m' and 'next_idx' and 'wellformed', *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1771 | (* but use old 'bounds' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1772 |                 ((m', {maxvars = maxvars, def_eq = def_eq,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1773 | next_idx = #next_idx a', bounds = bounds, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1774 | wellformed = #wellformed a'}), i') | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1775 | end) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1776 | ((model, args), constants) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1777 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1778 | SOME (Node bodies, model', args') | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1779 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1780 | | t1 $ t2 => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1781 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1782 | (* interpret 't1' and 't2' separately *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1783 | val (intr1, model1, args1) = interpret thy model args t1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1784 | val (intr2, model2, args2) = interpret thy model1 args1 t2 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1785 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1786 | SOME (interpretation_apply (intr1, intr2), model2, args2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1787 | end) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1788 | 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 | 1789 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1790 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1791 | (interpretation * model * arguments) option *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1792 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1793 | fun Pure_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1794 | case t of | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1795 |       Const (@{const_name all}, _) $ t1 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1796 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1797 | val (i, m, a) = interpret thy model args t1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1798 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1799 | case i of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1800 | Node xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1801 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1802 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1803 | val fmTrue = PropLogic.all (map toTrue xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1804 | val fmFalse = PropLogic.exists (map toFalse xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1805 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1806 | SOME (Leaf [fmTrue, fmFalse], m, a) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1807 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1808 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1809 |           raise REFUTE ("Pure_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1810 | "\"all\" is followed by a non-function") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1811 | end | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1812 |     | Const (@{const_name all}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1813 | SOME (interpret thy model args (eta_expand t 1)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1814 |     | Const (@{const_name "=="}, _) $ t1 $ t2 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1815 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1816 | val (i1, m1, a1) = interpret thy model args t1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1817 | val (i2, m2, a2) = interpret thy m1 a1 t2 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1818 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1819 | (* we use either 'make_def_equality' or 'make_equality' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1820 | SOME ((if #def_eq args then make_def_equality else make_equality) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1821 | (i1, i2), m2, a2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1822 | end | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1823 |     | Const (@{const_name "=="}, _) $ t1 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1824 | SOME (interpret thy model args (eta_expand t 1)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1825 |     | Const (@{const_name "=="}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1826 | SOME (interpret thy model args (eta_expand t 2)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1827 |     | Const (@{const_name "==>"}, _) $ t1 $ t2 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1828 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1829 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1830 | val (i1, m1, a1) = interpret thy model args t1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1831 | val (i2, m2, a2) = interpret thy m1 a1 t2 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1832 | val fmTrue = PropLogic.SOr (toFalse i1, toTrue i2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1833 | val fmFalse = PropLogic.SAnd (toTrue i1, toFalse i2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1834 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1835 | SOME (Leaf [fmTrue, fmFalse], m2, a2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1836 | end | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1837 |     | Const (@{const_name "==>"}, _) $ t1 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1838 | SOME (interpret thy model args (eta_expand t 1)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1839 |     | Const (@{const_name "==>"}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1840 | SOME (interpret thy model args (eta_expand t 2)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1841 | | _ => 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 | 1842 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1843 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1844 | (interpretation * model * arguments) option *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1845 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1846 | fun HOLogic_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1847 | (* Providing interpretations directly is more efficient than unfolding the *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1848 | (* logical constants. In HOL however, logical constants can themselves be *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1849 | (* arguments. They are then translated using eta-expansion. *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1850 | case t of | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1851 |       Const (@{const_name Trueprop}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1852 | SOME (Node [TT, FF], model, args) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1853 |     | Const (@{const_name Not}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1854 | SOME (Node [FF, TT], model, args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1855 | (* redundant, since 'True' is also an IDT constructor *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1856 |     | Const (@{const_name True}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1857 | SOME (TT, model, args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1858 | (* redundant, since 'False' is also an IDT constructor *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1859 |     | Const (@{const_name False}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1860 | SOME (FF, model, args) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1861 |     | Const (@{const_name All}, _) $ t1 =>  (* similar to "all" (Pure) *)
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1862 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1863 | val (i, m, a) = interpret thy model args t1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1864 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1865 | case i of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1866 | Node xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1867 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1868 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1869 | val fmTrue = PropLogic.all (map toTrue xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1870 | val fmFalse = PropLogic.exists (map toFalse xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1871 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1872 | SOME (Leaf [fmTrue, fmFalse], m, a) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1873 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1874 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1875 |           raise REFUTE ("HOLogic_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1876 | "\"All\" is followed by a non-function") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1877 | end | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1878 |     | Const (@{const_name All}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1879 | SOME (interpret thy model args (eta_expand t 1)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1880 |     | Const (@{const_name Ex}, _) $ t1 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1881 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1882 | val (i, m, a) = interpret thy model args t1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1883 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1884 | case i of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1885 | Node xs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1886 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1887 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1888 | val fmTrue = PropLogic.exists (map toTrue xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1889 | val fmFalse = PropLogic.all (map toFalse xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1890 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1891 | SOME (Leaf [fmTrue, fmFalse], m, a) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1892 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1893 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1894 |           raise REFUTE ("HOLogic_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1895 | "\"Ex\" is followed by a non-function") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1896 | end | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1897 |     | Const (@{const_name Ex}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1898 | SOME (interpret thy model args (eta_expand t 1)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1899 |     | Const (@{const_name "op ="}, _) $ t1 $ t2 =>  (* similar to "==" (Pure) *)
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1900 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1901 | val (i1, m1, a1) = interpret thy model args t1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1902 | val (i2, m2, a2) = interpret thy m1 a1 t2 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1903 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1904 | SOME (make_equality (i1, i2), m2, a2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1905 | end | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1906 |     | Const (@{const_name "op ="}, _) $ t1 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1907 | SOME (interpret thy model args (eta_expand t 1)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1908 |     | Const (@{const_name "op ="}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1909 | SOME (interpret thy model args (eta_expand t 2)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1910 |     | Const (@{const_name "op &"}, _) $ t1 $ t2 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1911 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1912 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1913 | val (i1, m1, a1) = interpret thy model args t1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1914 | val (i2, m2, a2) = interpret thy m1 a1 t2 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1915 | val fmTrue = PropLogic.SAnd (toTrue i1, toTrue i2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1916 | val fmFalse = PropLogic.SOr (toFalse i1, toFalse i2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1917 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1918 | SOME (Leaf [fmTrue, fmFalse], m2, a2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1919 | end | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1920 |     | Const (@{const_name "op &"}, _) $ t1 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1921 | SOME (interpret thy model args (eta_expand t 1)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1922 |     | Const (@{const_name "op &"}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1923 | SOME (interpret thy model args (eta_expand t 2)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1924 | (* this would make "undef" propagate, even for formulae like *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1925 | (* "False & undef": *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1926 | (* SOME (Node [Node [TT, FF], Node [FF, FF]], model, args) *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1927 |     | Const (@{const_name "op |"}, _) $ t1 $ t2 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1928 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1929 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1930 | val (i1, m1, a1) = interpret thy model args t1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1931 | val (i2, m2, a2) = interpret thy m1 a1 t2 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1932 | val fmTrue = PropLogic.SOr (toTrue i1, toTrue i2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1933 | val fmFalse = PropLogic.SAnd (toFalse i1, toFalse i2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1934 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1935 | SOME (Leaf [fmTrue, fmFalse], m2, a2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1936 | end | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1937 |     | Const (@{const_name "op |"}, _) $ t1 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1938 | SOME (interpret thy model args (eta_expand t 1)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1939 |     | Const (@{const_name "op |"}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1940 | SOME (interpret thy model args (eta_expand t 2)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1941 | (* this would make "undef" propagate, even for formulae like *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1942 | (* "True | undef": *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1943 | (* SOME (Node [Node [TT, TT], Node [TT, FF]], model, args) *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1944 |     | Const (@{const_name "op -->"}, _) $ t1 $ t2 =>  (* similar to "==>" (Pure) *)
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1945 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1946 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1947 | val (i1, m1, a1) = interpret thy model args t1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1948 | val (i2, m2, a2) = interpret thy m1 a1 t2 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1949 | val fmTrue = PropLogic.SOr (toFalse i1, toTrue i2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1950 | val fmFalse = PropLogic.SAnd (toTrue i1, toFalse i2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1951 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1952 | SOME (Leaf [fmTrue, fmFalse], m2, a2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1953 | end | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1954 |     | Const (@{const_name "op -->"}, _) $ t1 =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1955 | SOME (interpret thy model args (eta_expand t 1)) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1956 |     | Const (@{const_name "op -->"}, _) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1957 | SOME (interpret thy model args (eta_expand t 2)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1958 | (* this would make "undef" propagate, even for formulae like *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1959 | (* "False --> undef": *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1960 | (* SOME (Node [Node [TT, FF], Node [TT, TT]], model, args) *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1961 | | _ => 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 | 1962 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1963 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1964 | (interpretation * model * arguments) option *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1965 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1966 | (* interprets variables and constants whose type is an IDT (this is *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1967 | (* relatively easy and merely requires us to compute the size of the IDT); *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1968 | (* constructors of IDTs however are properly interpreted by *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1969 | (* 'IDT_constructor_interpreter' *) | 
| 15547 
f08e2d83681e
major code 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 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1971 | fun IDT_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1972 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1973 | val (typs, terms) = model | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1974 | (* Term.typ -> (interpretation * model * arguments) option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1975 | fun interpret_term (Type (s, Ts)) = | 
| 31784 | 1976 | (case Datatype.get_info thy s of | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1977 | SOME info => (* inductive datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1978 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1979 | (* int option -- only recursive IDTs have an associated depth *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1980 | val depth = AList.lookup (op =) typs (Type (s, Ts)) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1981 | (* sanity check: depth must be at least 0 *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1982 | val _ = (case depth of SOME n => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1983 | if n<0 then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1984 |               raise REFUTE ("IDT_interpreter", "negative depth")
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1985 | else () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1986 | | _ => ()) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1987 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1988 | (* termination condition to avoid infinite recursion *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1989 | if depth = (SOME 0) then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1990 | (* return a leaf of size 0 *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1991 | SOME (Leaf [], model, args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1992 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1993 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1994 | val index = #index info | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1995 | val descr = #descr info | 
| 29288 | 1996 | val (_, dtyps, constrs) = the (AList.lookup (op =) descr index) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1997 | val typ_assoc = dtyps ~~ Ts | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1998 | (* sanity check: every element in 'dtyps' must be a 'DtTFree' *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1999 | val _ = if Library.exists (fn d => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2000 | case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2001 | then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2002 |                   raise REFUTE ("IDT_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2003 | "datatype argument (for type " | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 2004 | ^ Syntax.string_of_typ_global thy (Type (s, Ts)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2005 | ^ ") is not a variable") | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2006 | else () | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2007 | (* if the model specifies a depth for the current type, *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2008 | (* decrement it to avoid infinite recursion *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2009 | val typs' = case depth of NONE => typs | SOME n => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2010 | AList.update (op =) (Type (s, Ts), n-1) typs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2011 | (* recursively compute the size of the datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2012 | val size = size_of_dtyp thy typs' descr typ_assoc constrs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2013 | val next_idx = #next_idx args | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2014 | val next = next_idx+size | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2015 | (* check if 'maxvars' is large enough *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2016 | val _ = (if next-1 > #maxvars args andalso | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2017 | #maxvars args > 0 then raise MAXVARS_EXCEEDED else ()) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2018 | (* prop_formula list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2019 | val fms = map BoolVar (next_idx upto (next_idx+size-1)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2020 | (* interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2021 | val intr = Leaf fms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2022 | (* prop_formula list -> prop_formula *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2023 | fun one_of_two_false [] = True | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2024 | | one_of_two_false (x::xs) = SAnd (PropLogic.all (map (fn x' => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2025 | SOr (SNot x, SNot x')) xs), one_of_two_false xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2026 | (* prop_formula *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2027 | val wf = one_of_two_false fms | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2028 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2029 | (* extend the model, increase 'next_idx', add well-formedness *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2030 | (* condition *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2031 |               SOME (intr, (typs, (t, intr)::terms), {maxvars = #maxvars args,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2032 | def_eq = #def_eq args, next_idx = next, bounds = #bounds args, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2033 | wellformed = SAnd (#wellformed args, wf)}) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2034 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2035 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2036 | | NONE => (* not an inductive datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2037 | NONE) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2038 | | interpret_term _ = (* a (free or schematic) type variable *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2039 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2040 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2041 | case AList.lookup (op =) terms t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2042 | SOME intr => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2043 | (* return an existing interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2044 | SOME (intr, model, args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2045 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2046 | (case t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2047 | Free (_, T) => interpret_term T | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2048 | | Var (_, T) => interpret_term T | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2049 | | Const (_, T) => interpret_term T | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2050 | | _ => NONE) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2051 | 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 | 2052 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2053 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2054 | (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 | 2055 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2056 | (* This function imposes an order on the elements of a datatype fragment *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2057 | (* as follows: C_i x_1 ... x_n < C_j y_1 ... y_m iff i < j or *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2058 | (* (x_1, ..., x_n) < (y_1, ..., y_m). With this order, a constructor is *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2059 | (* a function C_i that maps some argument indices x_1, ..., x_n to the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2060 | (* datatype element given by index C_i x_1 ... x_n. The idea remains the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2061 | (* same for recursive datatypes, although the computation of indices gets *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2062 | (* a little tricky. *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2063 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2064 | fun IDT_constructor_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2065 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2066 | (* returns a list of canonical representations for terms of the type 'T' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2067 | (* It would be nice if we could just use 'print' for this, but 'print' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2068 | (* for IDTs calls 'IDT_constructor_interpreter' again, and this could *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2069 | (* lead to infinite recursion when we have (mutually) recursive IDTs. *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2070 | (* (Term.typ * int) list -> Term.typ -> Term.term list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2071 | fun canonical_terms typs T = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2072 | (case T of | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2073 |         Type ("fun", [T1, T2]) =>
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2074 | (* 'T2' might contain a recursive IDT, so we cannot use 'print' (at *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2075 | (* least not for 'T2' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2076 | let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2077 | (* returns a list of lists, each one consisting of n (possibly *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2078 | (* identical) elements from 'xs' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2079 | (* int -> 'a list -> 'a list list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2080 | fun pick_all 1 xs = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2081 | map single xs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2082 | | pick_all n xs = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2083 | let val rec_pick = pick_all (n-1) xs in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2084 | List.concat (map (fn x => map (cons x) rec_pick) xs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2085 | end | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2086 | (* ["x1", ..., "xn"] *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2087 | val terms1 = canonical_terms typs T1 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2088 | (* ["y1", ..., "ym"] *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2089 | val terms2 = canonical_terms typs T2 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2090 |           (* [[("x1", "y1"), ..., ("xn", "y1")], ..., *)
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2091 |           (*   [("x1", "ym"), ..., ("xn", "ym")]]     *)
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2092 | val functions = map (curry (op ~~) terms1) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2093 | (pick_all (length terms1) terms2) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2094 | (* [["(x1, y1)", ..., "(xn, y1)"], ..., *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2095 | (* ["(x1, ym)", ..., "(xn, ym)"]] *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2096 | val pairss = map (map HOLogic.mk_prod) functions | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2097 | (* Term.typ *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2098 | val HOLogic_prodT = HOLogic.mk_prodT (T1, T2) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2099 | val HOLogic_setT = HOLogic.mk_setT HOLogic_prodT | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2100 | (* Term.term *) | 
| 30450 | 2101 | val HOLogic_empty_set = HOLogic.mk_set HOLogic_prodT [] | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2102 | val HOLogic_insert = | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 2103 |             Const (@{const_name insert}, HOLogic_prodT --> HOLogic_setT --> HOLogic_setT)
 | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2104 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2105 | (* functions as graphs, i.e. as a (HOL) set of pairs "(x, y)" *) | 
| 30190 | 2106 | map (List.foldr (fn (pair, acc) => HOLogic_insert $ pair $ acc) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2107 | HOLogic_empty_set) pairss | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2108 | end | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2109 | | Type (s, Ts) => | 
| 31784 | 2110 | (case Datatype.get_info thy s of | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2111 | SOME info => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2112 | (case AList.lookup (op =) typs T of | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2113 | SOME 0 => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2114 | (* termination condition to avoid infinite recursion *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2115 | [] (* at depth 0, every IDT is empty *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2116 | | _ => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2117 | let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2118 | val index = #index info | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2119 | val descr = #descr info | 
| 29288 | 2120 | val (_, dtyps, constrs) = the (AList.lookup (op =) descr index) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2121 | val typ_assoc = dtyps ~~ Ts | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2122 | (* sanity check: every element in 'dtyps' must be a 'DtTFree' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2123 | val _ = if Library.exists (fn d => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2124 | case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2125 | then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2126 |                   raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2127 | "datatype argument (for type " | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 2128 | ^ Syntax.string_of_typ_global thy T | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2129 | ^ ") is not a variable") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2130 | else () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2131 | (* decrement depth for the IDT 'T' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2132 | val typs' = (case AList.lookup (op =) typs T of NONE => typs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2133 | | SOME n => AList.update (op =) (T, n-1) typs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2134 | fun constructor_terms terms [] = terms | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2135 | | constructor_terms terms (d::ds) = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2136 | let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2137 | val dT = typ_of_dtyp descr typ_assoc d | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2138 | val d_terms = canonical_terms typs' dT | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2139 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2140 | (* C_i x_1 ... x_n < C_i y_1 ... y_n if *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2141 | (* (x_1, ..., x_n) < (y_1, ..., y_n) *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2142 | constructor_terms | 
| 25538 | 2143 | (map_product (curry op $) terms d_terms) ds | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2144 | end | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2145 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2146 | (* C_i ... < C_j ... if i < j *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2147 | List.concat (map (fn (cname, ctyps) => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2148 | let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2149 | val cTerm = Const (cname, | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2150 | map (typ_of_dtyp descr typ_assoc) ctyps ---> T) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2151 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2152 | constructor_terms [cTerm] ctyps | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2153 | end) constrs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2154 | end) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2155 | | NONE => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2156 | (* not an inductive datatype; in this case the argument types in *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2157 | (* 'Ts' may not be IDTs either, so 'print' should be safe *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2158 | map (fn intr => print thy (typs, []) T intr (K false)) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2159 | (make_constants thy (typs, []) T)) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2160 | | _ => (* TFree ..., TVar ... *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2161 | map (fn intr => print thy (typs, []) T intr (K false)) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2162 | (make_constants thy (typs, []) T)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2163 | val (typs, terms) = model | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2164 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2165 | case AList.lookup (op =) terms t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2166 | SOME intr => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2167 | (* return an existing interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2168 | SOME (intr, model, args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2169 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2170 | (case t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2171 | Const (s, T) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2172 | (case body_type T of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2173 | Type (s', Ts') => | 
| 31784 | 2174 | (case Datatype.get_info thy s' of | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2175 | SOME info => (* body type is an inductive datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2176 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2177 | val index = #index info | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2178 | val descr = #descr info | 
| 29288 | 2179 | val (_, dtyps, constrs) = the (AList.lookup (op =) descr index) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2180 | val typ_assoc = dtyps ~~ Ts' | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2181 | (* sanity check: every element in 'dtyps' must be a 'DtTFree' *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2182 | val _ = if Library.exists (fn d => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2183 | case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2184 | then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2185 |                   raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2186 | "datatype argument (for type " | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 2187 | ^ Syntax.string_of_typ_global thy (Type (s', Ts')) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2188 | ^ ") is not a variable") | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2189 | else () | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2190 | (* split the constructors into those occuring before/after *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2191 | (* 'Const (s, T)' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2192 | val (constrs1, constrs2) = take_prefix (fn (cname, ctypes) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2193 | not (cname = s andalso Sign.typ_instance thy (T, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2194 | map (typ_of_dtyp descr typ_assoc) ctypes | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2195 | ---> Type (s', Ts')))) constrs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2196 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2197 | case constrs2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2198 | [] => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2199 | (* 'Const (s, T)' is not a constructor of this datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2200 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2201 | | (_, ctypes)::cs => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2202 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2203 | (* int option -- only /recursive/ IDTs have an associated *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2204 | (* depth *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2205 | val depth = AList.lookup (op =) typs (Type (s', Ts')) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2206 | (* this should never happen: at depth 0, this IDT fragment *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2207 | (* is definitely empty, and in this case we don't need to *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2208 | (* interpret its constructors *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2209 | val _ = (case depth of SOME 0 => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2210 |                       raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2211 | "depth is 0") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2212 | | _ => ()) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2213 | val typs' = (case depth of NONE => typs | SOME n => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2214 | AList.update (op =) (Type (s', Ts'), n-1) typs) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2215 | (* elements of the datatype come before elements generated *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2216 | (* by 'Const (s, T)' iff they are generated by a *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2217 | (* constructor in constrs1 *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2218 | val offset = size_of_dtyp thy typs' descr typ_assoc constrs1 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2219 | (* compute the total (current) size of the datatype *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2220 | val total = offset + | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2221 | size_of_dtyp thy typs' descr typ_assoc constrs2 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2222 | (* sanity check *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2223 | val _ = if total <> size_of_type thy (typs, []) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2224 | (Type (s', Ts')) then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2225 |                       raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2226 | "total is not equal to current size") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2227 | else () | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2228 | (* returns an interpretation where everything is mapped to *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2229 | (* an "undefined" element of the datatype *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2230 | fun make_undef [] = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2231 | Leaf (replicate total False) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2232 | | make_undef (d::ds) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2233 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2234 | (* compute the current size of the type 'd' *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2235 | val dT = typ_of_dtyp descr typ_assoc d | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2236 | val size = size_of_type thy (typs, []) dT | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2237 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2238 | Node (replicate size (make_undef ds)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2239 | end | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2240 | (* returns the interpretation for a constructor *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2241 | fun make_constr (offset, []) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2242 | if offset<total then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2243 | (offset+1, Leaf ((replicate offset False) @ True :: | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2244 | (replicate (total-offset-1) False))) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2245 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2246 |                       raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2247 | "offset >= total") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2248 | | make_constr (offset, d::ds) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2249 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2250 | (* Term.typ *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2251 | val dT = typ_of_dtyp descr typ_assoc d | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2252 | (* compute canonical term representations for all *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2253 | (* elements of the type 'd' (with the reduced depth *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2254 | (* for the IDT) *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2255 | val terms' = canonical_terms typs' dT | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2256 | (* sanity check *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2257 | val _ = if length terms' <> | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2258 | size_of_type thy (typs', []) dT | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2259 | then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2260 |                           raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2261 | "length of terms' is not equal to old size") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2262 | else () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2263 | (* compute canonical term representations for all *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2264 | (* elements of the type 'd' (with the current depth *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2265 | (* for the IDT) *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2266 | val terms = canonical_terms typs dT | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2267 | (* sanity check *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2268 | val _ = if length terms <> size_of_type thy (typs, []) dT | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2269 | then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2270 |                           raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2271 | "length of terms is not equal to current size") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2272 | else () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2273 | (* sanity check *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2274 | val _ = if length terms < length terms' then | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2275 |                           raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2276 | "current size is less than old size") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2277 | else () | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2278 | (* sanity check: every element of terms' must also be *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2279 | (* present in terms *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2280 | val _ = if List.all (member op= terms) terms' then () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2281 | else | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2282 |                           raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2283 | "element has disappeared") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2284 | (* sanity check: the order on elements of terms' is *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2285 | (* the same in terms, for those elements *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2286 | val _ = let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2287 | fun search (x::xs) (y::ys) = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2288 | if x = y then search xs ys else search (x::xs) ys | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2289 | | search (x::xs) [] = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2290 |                             raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2291 | "element order not preserved") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2292 | | search [] _ = () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2293 | in search terms' terms end | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2294 | (* int * interpretation list *) | 
| 30190 | 2295 | val (new_offset, intrs) = Library.foldl_map (fn (off, t_elem) => | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2296 | (* if 't_elem' existed at the previous depth, *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2297 | (* proceed recursively, otherwise map the entire *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2298 | (* subtree to "undefined" *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2299 | if t_elem mem terms' then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2300 | make_constr (off, ds) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2301 | else | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2302 | (off, make_undef ds)) (offset, terms) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2303 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2304 | (new_offset, Node intrs) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2305 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2306 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2307 | SOME (snd (make_constr (offset, ctypes)), model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2308 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2309 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2310 | | NONE => (* body type is not an inductive datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2311 | NONE) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2312 | | _ => (* body type is a (free or schematic) type variable *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2313 | NONE) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2314 | | _ => (* term is not a constant *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2315 | NONE) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2316 | 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 | 2317 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2318 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2319 | (interpretation * model * arguments) option *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2320 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2321 | (* Difficult code ahead. Make sure you understand the *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2322 | (* 'IDT_constructor_interpreter' and the order in which it enumerates *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2323 | (* elements of an IDT before you try to understand this function. *) | 
| 15547 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 2324 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2325 | fun IDT_recursion_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2326 | (* careful: here we descend arbitrarily deep into 't', possibly before *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2327 | (* any other interpreter for atomic terms has had a chance to look at *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2328 | (* 't' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2329 | case strip_comb t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2330 | (Const (s, T), params) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2331 | (* iterate over all datatypes in 'thy' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2332 | Symtab.fold (fn (_, info) => fn result => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2333 | case result of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2334 | SOME _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2335 | result (* just keep 'result' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2336 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2337 | if member (op =) (#rec_names info) s then | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2338 | (* we do have a recursion operator of one of the (mutually *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2339 | (* recursive) datatypes given by 'info' *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2340 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2341 | (* number of all constructors, including those of different *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2342 | (* (mutually recursive) datatypes within the same descriptor *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2343 | val mconstrs_count = sum (map (fn (_, (_, _, cs)) => length cs) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2344 | (#descr info)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2345 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2346 | if mconstrs_count < length params then | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2347 | (* too many actual parameters; for now we'll use the *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2348 | (* 'stlc_interpreter' to strip off one application *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2349 | NONE | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2350 | else if mconstrs_count > length params then | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2351 | (* too few actual parameters; we use eta expansion *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2352 | (* Note that the resulting expansion of lambda abstractions *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2353 | (* by the 'stlc_interpreter' may be rather slow (depending *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2354 | (* on the argument types and the size of the IDT, of *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2355 | (* course). *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2356 | SOME (interpret thy model args (eta_expand t | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2357 | (mconstrs_count - length params))) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2358 | else (* mconstrs_count = length params *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2359 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2360 | (* interpret each parameter separately *) | 
| 30190 | 2361 | val ((model', args'), p_intrs) = Library.foldl_map (fn ((m, a), p) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2362 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2363 | val (i, m', a') = interpret thy m a p | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2364 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2365 | ((m', a'), i) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2366 | end) ((model, args), params) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2367 | val (typs, _) = model' | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2368 | (* 'index' is /not/ necessarily the index of the IDT that *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2369 | (* the recursion operator is associated with, but merely *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2370 | (* the index of some mutually recursive IDT *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2371 | val index = #index info | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2372 | val descr = #descr info | 
| 29288 | 2373 | val (_, dtyps, _) = the (AList.lookup (op =) descr index) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2374 | (* sanity check: we assume that the order of constructors *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2375 | (* in 'descr' is the same as the order of *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2376 | (* corresponding parameters, otherwise the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2377 | (* association code below won't match the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2378 | (* right constructors/parameters; we also *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2379 | (* assume that the order of recursion *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2380 | (* operators in '#rec_names info' is the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2381 | (* same as the order of corresponding *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2382 | (* datatypes in 'descr' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2383 | val _ = if map fst descr <> (0 upto (length descr - 1)) then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2384 |                       raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2385 | "order of constructors and corresponding parameters/" ^ | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2386 | "recursion operators and corresponding datatypes " ^ | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2387 | "different?") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2388 | else () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2389 | (* sanity check: every element in 'dtyps' must be a *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2390 | (* 'DtTFree' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2391 | val _ = if Library.exists (fn d => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2392 | case d of DatatypeAux.DtTFree _ => false | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2393 | | _ => true) dtyps | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2394 | then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2395 |                       raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2396 | "datatype argument is not a variable") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2397 | else () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2398 | (* the type of a recursion operator is *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2399 | (* [T1, ..., Tn, IDT] ---> Tresult *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2400 | val IDT = List.nth (binder_types T, mconstrs_count) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2401 | (* by our assumption on the order of recursion operators *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2402 | (* and datatypes, this is the index of the datatype *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2403 | (* corresponding to the given recursion operator *) | 
| 31986 | 2404 | val idt_index = find_index (fn s' => s' = s) (#rec_names info) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2405 | (* mutually recursive types must have the same type *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2406 | (* parameters, unless the mutual recursion comes from *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2407 | (* indirect recursion *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2408 | fun rec_typ_assoc acc [] = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2409 | acc | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2410 | | rec_typ_assoc acc ((d, T)::xs) = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2411 | (case AList.lookup op= acc d of | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2412 | NONE => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2413 | (case d of | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2414 | DatatypeAux.DtTFree _ => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2415 | (* add the association, proceed *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2416 | rec_typ_assoc ((d, T)::acc) xs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2417 | | DatatypeAux.DtType (s, ds) => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2418 | let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2419 | val (s', Ts) = dest_Type T | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2420 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2421 | if s=s' then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2422 | rec_typ_assoc ((d, T)::acc) ((ds ~~ Ts) @ xs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2423 | else | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2424 |                             raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2425 | "DtType/Type mismatch") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2426 | end | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2427 | | DatatypeAux.DtRec i => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2428 | let | 
| 29288 | 2429 | val (_, ds, _) = the (AList.lookup (op =) descr i) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2430 | val (_, Ts) = dest_Type T | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2431 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2432 | rec_typ_assoc ((d, T)::acc) ((ds ~~ Ts) @ xs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2433 | end) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2434 | | SOME T' => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2435 | if T=T' then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2436 | (* ignore the association since it's already *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2437 | (* present, proceed *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2438 | rec_typ_assoc acc xs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2439 | else | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2440 |                         raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2441 | "different type associations for the same dtyp")) | 
| 29288 | 2442 | val typ_assoc = filter | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2443 | (fn (DatatypeAux.DtTFree _, _) => true | (_, _) => false) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2444 | (rec_typ_assoc [] | 
| 29288 | 2445 | (#2 (the (AList.lookup (op =) descr idt_index)) ~~ (snd o dest_Type) IDT)) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2446 | (* sanity check: typ_assoc must associate types to the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2447 | (* elements of 'dtyps' (and only to those) *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2448 | val _ = if not (Library.eq_set (dtyps, map fst typ_assoc)) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2449 | then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2450 |                       raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2451 | "type association has extra/missing elements") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2452 | else () | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2453 | (* interpret each constructor in the descriptor (including *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2454 | (* those of mutually recursive datatypes) *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2455 | (* (int * interpretation list) list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2456 | val mc_intrs = map (fn (idx, (_, _, cs)) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2457 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2458 | val c_return_typ = typ_of_dtyp descr typ_assoc | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2459 | (DatatypeAux.DtRec idx) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2460 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2461 | (idx, map (fn (cname, cargs) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2462 |                         (#1 o interpret thy (typs, []) {maxvars=0,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2463 | def_eq=false, next_idx=1, bounds=[], | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2464 | wellformed=True}) (Const (cname, map (typ_of_dtyp | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2465 | descr typ_assoc) cargs ---> c_return_typ))) cs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2466 | end) descr | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2467 | (* associate constructors with corresponding parameters *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2468 | (* (int * (interpretation * interpretation) list) list *) | 
| 30190 | 2469 | val (p_intrs', mc_p_intrs) = Library.foldl_map | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2470 | (fn (p_intrs', (idx, c_intrs)) => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2471 | let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2472 | val len = length c_intrs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2473 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2474 | (List.drop (p_intrs', len), | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2475 | (idx, c_intrs ~~ List.take (p_intrs', len))) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2476 | end) (p_intrs, mc_intrs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2477 | (* sanity check: no 'p_intr' may be left afterwards *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2478 | val _ = if p_intrs' <> [] then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2479 |                       raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2480 | "more parameter than constructor interpretations") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2481 | else () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2482 | (* The recursion operator, applied to 'mconstrs_count' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2483 | (* arguments, is a function that maps every element of the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2484 | (* inductive datatype to an element of some result type. *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2485 | (* Recursion operators for mutually recursive IDTs are *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2486 | (* translated simultaneously. *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2487 | (* Since the order on datatype elements is given by an *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2488 | (* order on constructors (and then by the order on *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2489 | (* argument tuples), we can simply copy corresponding *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2490 | (* subtrees from 'p_intrs', in the order in which they are *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2491 | (* given. *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2492 | (* interpretation * interpretation -> interpretation list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2493 | fun ci_pi (Leaf xs, pi) = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2494 | (* if the constructor does not match the arguments to a *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2495 | (* defined element of the IDT, the corresponding value *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2496 | (* of the parameter must be ignored *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2497 | if List.exists (equal True) xs then [pi] else [] | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2498 | | ci_pi (Node xs, Node ys) = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2499 | List.concat (map ci_pi (xs ~~ ys)) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2500 | | ci_pi (Node _, Leaf _) = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2501 |                     raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2502 | "constructor takes more arguments than the " ^ | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2503 | "associated parameter") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2504 | (* (int * interpretation list) list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2505 | val rec_operators = map (fn (idx, c_p_intrs) => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2506 | (idx, List.concat (map ci_pi c_p_intrs))) mc_p_intrs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2507 | (* sanity check: every recursion operator must provide as *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2508 | (* many values as the corresponding datatype *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2509 | (* has elements *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2510 | val _ = map (fn (idx, intrs) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2511 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2512 | val T = typ_of_dtyp descr typ_assoc | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2513 | (DatatypeAux.DtRec idx) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2514 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2515 | if length intrs <> size_of_type thy (typs, []) T then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2516 |                         raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2517 | "wrong number of interpretations for rec. operator") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2518 | else () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2519 | end) rec_operators | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2520 | (* For non-recursive datatypes, we are pretty much done at *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2521 | (* this point. For recursive datatypes however, we still *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2522 | (* need to apply the interpretations in 'rec_operators' to *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2523 | (* (recursively obtained) interpretations for recursive *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2524 | (* constructor arguments. To do so more efficiently, we *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2525 | (* copy 'rec_operators' into arrays first. Each Boolean *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2526 | (* indicates whether the recursive arguments have been *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2527 | (* considered already. *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2528 | (* (int * (bool * interpretation) Array.array) list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2529 | val REC_OPERATORS = map (fn (idx, intrs) => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2530 | (idx, Array.fromList (map (pair false) intrs))) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2531 | rec_operators | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2532 | (* takes an interpretation, and if some leaf of this *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2533 | (* interpretation is the 'elem'-th element of the type, *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2534 | (* the indices of the arguments leading to this leaf are *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2535 | (* returned *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2536 | (* interpretation -> int -> int list option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2537 | fun get_args (Leaf xs) elem = | 
| 31986 | 2538 | if find_index (fn x => x = True) xs = elem then | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2539 | SOME [] | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2540 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2541 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2542 | | get_args (Node xs) elem = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2543 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2544 | (* interpretation list * int -> int list option *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2545 | fun search ([], _) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2546 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2547 | | search (x::xs, n) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2548 | (case get_args x elem of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2549 | SOME result => SOME (n::result) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2550 | | NONE => search (xs, n+1)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2551 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2552 | search (xs, 0) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2553 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2554 | (* returns the index of the constructor and indices for *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2555 | (* its arguments that generate the 'elem'-th element of *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2556 | (* the datatype given by 'idx' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2557 | (* int -> int -> int * int list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2558 | fun get_cargs idx elem = | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2559 | let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2560 | (* int * interpretation list -> int * int list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2561 | fun get_cargs_rec (_, []) = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2562 |                       raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2563 | "no matching constructor found for datatype element") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2564 | | get_cargs_rec (n, x::xs) = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2565 | (case get_args x elem of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2566 | SOME args => (n, args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2567 | | NONE => get_cargs_rec (n+1, xs)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2568 | in | 
| 29288 | 2569 | get_cargs_rec (0, the (AList.lookup (op =) mc_intrs idx)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2570 | end | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2571 | (* computes one entry in 'REC_OPERATORS', and recursively *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2572 | (* all entries needed for it, where 'idx' gives the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2573 | (* datatype and 'elem' the element of it *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2574 | (* int -> int -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2575 | fun compute_array_entry idx elem = | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2576 | let | 
| 29288 | 2577 | val arr = the (AList.lookup (op =) REC_OPERATORS idx) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2578 | val (flag, intr) = Array.sub (arr, elem) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2579 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2580 | if flag then | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2581 | (* simply return the previously computed result *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2582 | intr | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2583 | else | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2584 | (* we have to apply 'intr' to interpretations for all *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2585 | (* recursive arguments *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2586 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2587 | (* int * int list *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2588 | val (c, args) = get_cargs idx elem | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2589 | (* find the indices of the constructor's /recursive/ *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2590 | (* arguments *) | 
| 29288 | 2591 | val (_, _, constrs) = the (AList.lookup (op =) descr idx) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2592 | val (_, dtyps) = List.nth (constrs, c) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2593 | val rec_dtyps_args = List.filter | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2594 | (DatatypeAux.is_rec_type o fst) (dtyps ~~ args) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2595 | (* map those indices to interpretations *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2596 | val rec_dtyps_intrs = map (fn (dtyp, arg) => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2597 | let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2598 | val dT = typ_of_dtyp descr typ_assoc dtyp | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2599 | val consts = make_constants thy (typs, []) dT | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2600 | val arg_i = List.nth (consts, arg) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2601 | in | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2602 | (dtyp, arg_i) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2603 | end) rec_dtyps_args | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2604 | (* takes the dtyp and interpretation of an element, *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2605 | (* and computes the interpretation for the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2606 | (* corresponding recursive argument *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2607 | fun rec_intr (DatatypeAux.DtRec i) (Leaf xs) = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2608 | (* recursive argument is "rec_i params elem" *) | 
| 31986 | 2609 | compute_array_entry i (find_index (fn x => x = True) xs) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2610 | | rec_intr (DatatypeAux.DtRec _) (Node _) = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2611 |                           raise REFUTE ("IDT_recursion_interpreter",
 | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2612 | "interpretation for IDT is a node") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2613 |                           | rec_intr (DatatypeAux.DtType ("fun", [dt1, dt2]))
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2614 | (Node xs) = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2615 | (* recursive argument is something like *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2616 | (* "\<lambda>x::dt1. rec_? params (elem x)" *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2617 | Node (map (rec_intr dt2) xs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2618 |                           | rec_intr (DatatypeAux.DtType ("fun", [_, _]))
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2619 | (Leaf _) = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2620 |                           raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2621 | "interpretation for function dtyp is a leaf") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2622 | | rec_intr _ _ = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2623 | (* admissibility ensures that every recursive type *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2624 | (* is of the form 'Dt_1 -> ... -> Dt_k -> *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2625 | (* (DtRec i)' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2626 |                           raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2627 | "non-recursive codomain in recursive dtyp") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2628 | (* obtain interpretations for recursive arguments *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2629 | (* interpretation list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2630 | val arg_intrs = map (uncurry rec_intr) rec_dtyps_intrs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2631 | (* apply 'intr' to all recursive arguments *) | 
| 30190 | 2632 | val result = List.foldl (fn (arg_i, i) => | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2633 | interpretation_apply (i, arg_i)) intr arg_intrs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2634 | (* update 'REC_OPERATORS' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2635 | val _ = Array.update (arr, elem, (true, result)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2636 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2637 | result | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2638 | end | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2639 | end | 
| 29288 | 2640 | val idt_size = Array.length (the (AList.lookup (op =) REC_OPERATORS idt_index)) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2641 | (* sanity check: the size of 'IDT' should be 'idt_size' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2642 | val _ = if idt_size <> size_of_type thy (typs, []) IDT then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2643 |                         raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2644 | "unexpected size of IDT (wrong type associated?)") | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2645 | else () | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2646 | (* interpretation *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2647 | val rec_op = Node (map (compute_array_entry idt_index) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2648 | (0 upto (idt_size - 1))) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2649 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2650 | SOME (rec_op, model', args') | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2651 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2652 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2653 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2654 | NONE (* not a recursion operator of this datatype *) | 
| 31784 | 2655 | ) (Datatype.get_all thy) NONE | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2656 | | _ => (* head of term is not a constant *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2657 | 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 | 2658 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2659 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2660 | (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 | 2661 | |
| 29956 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2662 | fun set_interpreter thy model args t = | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2663 | let | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2664 | val (typs, terms) = model | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2665 | in | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2666 | case AList.lookup (op =) terms t of | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2667 | SOME intr => | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2668 | (* return an existing interpretation *) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2669 | SOME (intr, model, args) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2670 | | NONE => | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2671 | (case t of | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2672 | (* 'Collect' == identity *) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2673 |         Const (@{const_name Collect}, _) $ t1 =>
 | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2674 | SOME (interpret thy model args t1) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2675 |       | Const (@{const_name Collect}, _) =>
 | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2676 | SOME (interpret thy model args (eta_expand t 1)) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2677 | (* 'op :' == application *) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2678 |       | Const (@{const_name "op :"}, _) $ t1 $ t2 =>
 | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2679 | SOME (interpret thy model args (t2 $ t1)) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2680 |       | Const (@{const_name "op :"}, _) $ t1 =>
 | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2681 | SOME (interpret thy model args (eta_expand t 1)) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2682 |       | Const (@{const_name "op :"}, _) =>
 | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2683 | SOME (interpret thy model args (eta_expand t 2)) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2684 | | _ => NONE) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2685 | end; | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2686 | |
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2687 | (* theory -> model -> arguments -> Term.term -> | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2688 | (interpretation * model * arguments) option *) | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2689 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2690 | (* only an optimization: 'card' could in principle be interpreted with *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2691 | (* interpreters available already (using its definition), but the code *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2692 | (* 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 | 2693 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2694 | fun Finite_Set_card_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2695 | case t of | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 2696 |       Const (@{const_name Finite_Set.card},
 | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2697 |         Type ("fun", [Type ("fun", [T, Type ("bool", [])]),
 | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2698 |                       Type ("nat", [])])) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2699 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2700 | (* interpretation -> int *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2701 | fun number_of_elements (Node xs) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2702 | Library.foldl (fn (n, x) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2703 | if x=TT then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2704 | n+1 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2705 | else if x=FF then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2706 | n | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2707 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2708 |               raise REFUTE ("Finite_Set_card_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2709 | "interpretation for set type does not yield a Boolean")) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2710 | (0, xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2711 | | number_of_elements (Leaf _) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2712 |           raise REFUTE ("Finite_Set_card_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2713 | "interpretation for set type is a leaf") | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2714 |         val size_of_nat = size_of_type thy model (Type ("nat", []))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2715 | (* takes an interpretation for a set and returns an interpretation *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2716 | (* for a 'nat' denoting the set's cardinality *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2717 | (* interpretation -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2718 | fun card i = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2719 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2720 | val n = number_of_elements i | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2721 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2722 | if n<size_of_nat then | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2723 | Leaf ((replicate n False) @ True :: | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2724 | (replicate (size_of_nat-n-1) False)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2725 | else | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2726 | Leaf (replicate size_of_nat False) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2727 | end | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2728 | val set_constants = | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2729 |           make_constants thy model (Type ("fun", [T, Type ("bool", [])]))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2730 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2731 | SOME (Node (map card set_constants), model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2732 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2733 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2734 | 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 | 2735 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2736 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2737 | (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 | 2738 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2739 | (* only an optimization: 'finite' could in principle be interpreted with *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2740 | (* interpreters available already (using its definition), but the code *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2741 | (* below is more efficient *) | 
| 22093 | 2742 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2743 | fun Finite_Set_finite_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2744 | case t of | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 2745 |       Const (@{const_name Finite_Set.finite},
 | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2746 |         Type ("fun", [Type ("fun", [T, Type ("bool", [])]),
 | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2747 |                       Type ("bool", [])])) $ _ =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2748 | (* we only consider finite models anyway, hence EVERY set is *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2749 | (* "finite" *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2750 | SOME (TT, model, args) | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 2751 |     | Const (@{const_name Finite_Set.finite},
 | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2752 |         Type ("fun", [Type ("fun", [T, Type ("bool", [])]),
 | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2753 |                       Type ("bool", [])])) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2754 | let | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2755 | val size_of_set = | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2756 |           size_of_type thy model (Type ("fun", [T, Type ("bool", [])]))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2757 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2758 | (* we only consider finite models anyway, hence EVERY set is *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2759 | (* "finite" *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2760 | SOME (Node (replicate size_of_set TT), model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2761 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2762 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2763 | NONE; | 
| 22093 | 2764 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2765 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2766 | (interpretation * model * arguments) option *) | 
| 22093 | 2767 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2768 | (* only an optimization: 'HOL.less' could in principle be interpreted with *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2769 | (* interpreters available already (using its definition), but the code *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2770 | (* 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 | 2771 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2772 | fun Nat_less_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2773 | case t of | 
| 23881 | 2774 |       Const (@{const_name HOL.less}, Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2775 |         Type ("fun", [Type ("nat", []), Type ("bool", [])])])) =>
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2776 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2777 |         val size_of_nat = size_of_type thy model (Type ("nat", []))
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2778 | (* the 'n'-th nat is not less than the first 'n' nats, while it *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2779 | (* is less than the remaining 'size_of_nat - n' nats *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2780 | (* int -> interpretation *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2781 | fun less n = Node ((replicate n FF) @ (replicate (size_of_nat - n) TT)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2782 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2783 | SOME (Node (map less (1 upto size_of_nat)), model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2784 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2785 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2786 | 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 | 2787 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2788 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2789 | (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 | 2790 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2791 | (* only an optimization: 'HOL.plus' could in principle be interpreted with *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2792 | (* interpreters available already (using its definition), but the code *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2793 | (* 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 | 2794 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2795 | fun Nat_plus_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2796 | case t of | 
| 22997 | 2797 |       Const (@{const_name HOL.plus}, Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2798 |         Type ("fun", [Type ("nat", []), Type ("nat", [])])])) =>
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2799 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2800 |         val size_of_nat = size_of_type thy model (Type ("nat", []))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2801 | (* int -> int -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2802 | fun plus m n = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2803 | let | 
| 25032 | 2804 | val element = m + n | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2805 | in | 
| 25032 | 2806 | if element > size_of_nat - 1 then | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2807 | Leaf (replicate size_of_nat False) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2808 | else | 
| 25032 | 2809 | Leaf ((replicate element False) @ True :: | 
| 2810 | (replicate (size_of_nat - element - 1) False)) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2811 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2812 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2813 | SOME (Node (map (fn m => Node (map (plus m) (0 upto size_of_nat-1))) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2814 | (0 upto size_of_nat-1)), model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2815 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2816 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2817 | 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 | 2818 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2819 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2820 | (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 | 2821 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2822 | (* only an optimization: 'HOL.minus' could in principle be interpreted *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2823 | (* with interpreters available already (using its definition), but the *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2824 | (* code 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 | 2825 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2826 | fun Nat_minus_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2827 | case t of | 
| 22997 | 2828 |       Const (@{const_name HOL.minus}, Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2829 |         Type ("fun", [Type ("nat", []), Type ("nat", [])])])) =>
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2830 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2831 |         val size_of_nat = size_of_type thy model (Type ("nat", []))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2832 | (* int -> int -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2833 | fun minus m n = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2834 | let | 
| 25032 | 2835 | val element = Int.max (m-n, 0) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2836 | in | 
| 25032 | 2837 | Leaf ((replicate element False) @ True :: | 
| 2838 | (replicate (size_of_nat - element - 1) False)) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2839 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2840 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2841 | SOME (Node (map (fn m => Node (map (minus m) (0 upto size_of_nat-1))) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2842 | (0 upto size_of_nat-1)), model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2843 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2844 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2845 | 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 | 2846 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2847 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2848 | (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 | 2849 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2850 | (* only an optimization: 'HOL.times' could in principle be interpreted *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2851 | (* with interpreters available already (using its definition), but the *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2852 | (* code 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 | 2853 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2854 | fun Nat_times_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2855 | case t of | 
| 22997 | 2856 |       Const (@{const_name HOL.times}, Type ("fun", [Type ("nat", []),
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2857 |         Type ("fun", [Type ("nat", []), Type ("nat", [])])])) =>
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2858 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2859 |         val size_of_nat = size_of_type thy model (Type ("nat", []))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2860 | (* nat -> nat -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2861 | fun mult m n = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2862 | let | 
| 25032 | 2863 | val element = m * n | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2864 | in | 
| 25032 | 2865 | if element > size_of_nat - 1 then | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2866 | Leaf (replicate size_of_nat False) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2867 | else | 
| 25032 | 2868 | Leaf ((replicate element False) @ True :: | 
| 2869 | (replicate (size_of_nat - element - 1) False)) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2870 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2871 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2872 | SOME (Node (map (fn m => Node (map (mult m) (0 upto size_of_nat-1))) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2873 | (0 upto size_of_nat-1)), model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2874 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2875 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2876 | 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 | 2877 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2878 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2879 | (interpretation * model * arguments) option *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2880 | |
| 23029 | 2881 | (* only an optimization: 'append' could in principle be interpreted with *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2882 | (* interpreters available already (using its definition), but the code *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2883 | (* below is more efficient *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2884 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2885 | fun List_append_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2886 | case t of | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 2887 |       Const (@{const_name List.append}, Type ("fun", [Type ("List.list", [T]), Type ("fun",
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2888 |         [Type ("List.list", [_]), Type ("List.list", [_])])])) =>
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2889 | let | 
| 25032 | 2890 | val size_elem = size_of_type thy model T | 
| 2891 |         val size_list   = size_of_type thy model (Type ("List.list", [T]))
 | |
| 2892 | (* maximal length of lists; 0 if we only consider the empty list *) | |
| 2893 | val list_length = let | |
| 2894 | (* int -> int -> int -> int *) | |
| 2895 | fun list_length_acc len lists total = | |
| 2896 | if lists = total then | |
| 2897 | len | |
| 2898 | else if lists < total then | |
| 2899 | list_length_acc (len+1) (lists*size_elem) (total-lists) | |
| 2900 | else | |
| 2901 |                 raise REFUTE ("List_append_interpreter",
 | |
| 2902 | "size_list not equal to 1 + size_elem + ... + " ^ | |
| 2903 | "size_elem^len, for some len") | |
| 2904 | in | |
| 2905 | list_length_acc 0 1 size_list | |
| 2906 | end | |
| 2907 | val elements = 0 upto (size_list-1) | |
| 2908 | (* FIXME: there should be a nice formula, which computes the same as *) | |
| 2909 | (* the following, but without all this intermediate tree *) | |
| 2910 | (* length/offset stuff *) | |
| 2911 | (* associate each list with its length and offset in a complete tree *) | |
| 2912 | (* of width 'size_elem' and depth 'length_list' (with 'size_list' *) | |
| 2913 | (* nodes total) *) | |
| 2914 | (* (int * (int * int)) list *) | |
| 30190 | 2915 | val (_, lenoff_lists) = Library.foldl_map (fn ((offsets, off), elem) => | 
| 25032 | 2916 | (* corresponds to a pre-order traversal of the tree *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2917 | let | 
| 25032 | 2918 | val len = length offsets | 
| 2919 | (* associate the given element with len/off *) | |
| 2920 | val assoc = (elem, (len, off)) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2921 | in | 
| 25032 | 2922 | if len < list_length then | 
| 2923 | (* go to first child node *) | |
| 2924 | ((off :: offsets, off * size_elem), assoc) | |
| 2925 | else if off mod size_elem < size_elem - 1 then | |
| 2926 | (* go to next sibling node *) | |
| 2927 | ((offsets, off + 1), assoc) | |
| 2928 | else | |
| 2929 | (* go back up the stack until we find a level where we can go *) | |
| 2930 | (* to the next sibling node *) | |
| 2931 | let | |
| 2932 | val offsets' = Library.dropwhile | |
| 2933 | (fn off' => off' mod size_elem = size_elem - 1) offsets | |
| 2934 | in | |
| 2935 | case offsets' of | |
| 2936 | [] => | |
| 2937 | (* we're at the last node in the tree; the next value *) | |
| 2938 | (* won't be used anyway *) | |
| 2939 | (([], 0), assoc) | |
| 2940 | | off'::offs' => | |
| 2941 | (* go to next sibling node *) | |
| 2942 | ((offs', off' + 1), assoc) | |
| 2943 | end | |
| 2944 | end) (([], 0), elements) | |
| 2945 | (* we also need the reverse association (from length/offset to *) | |
| 2946 | (* index) *) | |
| 2947 | val lenoff'_lists = map Library.swap lenoff_lists | |
| 2948 | (* returns the interpretation for "(list no. m) @ (list no. n)" *) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2949 | (* nat -> nat -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2950 | fun append m n = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2951 | let | 
| 29288 | 2952 | val (len_m, off_m) = the (AList.lookup (op =) lenoff_lists m) | 
| 2953 | val (len_n, off_n) = the (AList.lookup (op =) lenoff_lists n) | |
| 25032 | 2954 | val len_elem = len_m + len_n | 
| 2955 | val off_elem = off_m * power (size_elem, len_n) + off_n | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2956 | in | 
| 25032 | 2957 | case AList.lookup op= lenoff'_lists (len_elem, off_elem) of | 
| 2958 | NONE => | |
| 2959 | (* undefined *) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2960 | Leaf (replicate size_list False) | 
| 25032 | 2961 | | SOME element => | 
| 2962 | Leaf ((replicate element False) @ True :: | |
| 2963 | (replicate (size_list - element - 1) False)) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2964 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2965 | in | 
| 25032 | 2966 | SOME (Node (map (fn m => Node (map (append m) elements)) elements), | 
| 2967 | model, args) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2968 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2969 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2970 | NONE; | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2971 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2972 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2973 | (interpretation * model * arguments) option *) | 
| 16050 | 2974 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2975 | (* only an optimization: 'lfp' could in principle be interpreted with *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2976 | (* interpreters available already (using its definition), but the code *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2977 | (* below is more efficient *) | 
| 16050 | 2978 | |
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 2979 | fun lfp_interpreter thy model args t = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2980 | case t of | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 2981 |       Const (@{const_name lfp}, Type ("fun", [Type ("fun",
 | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2982 |         [Type ("fun", [T, Type ("bool", [])]),
 | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2983 |          Type ("fun", [_, Type ("bool", [])])]),
 | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2984 |          Type ("fun", [_, Type ("bool", [])])])) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2985 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2986 | val size_elem = size_of_type thy model T | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2987 | (* the universe (i.e. the set that contains every element) *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2988 | val i_univ = Node (replicate size_elem TT) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2989 | (* all sets with elements from type 'T' *) | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2990 | val i_sets = | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2991 |           make_constants thy model (Type ("fun", [T, Type ("bool", [])]))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2992 | (* all functions that map sets to sets *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2993 |         val i_funs = make_constants thy model (Type ("fun",
 | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2994 |           [Type ("fun", [T, Type ("bool", [])]),
 | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 2995 |            Type ("fun", [T, Type ("bool", [])])]))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2996 |         (* "lfp(f) == Inter({u. f(u) <= u})" *)
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2997 | (* interpretation * interpretation -> bool *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2998 | fun is_subset (Node subs, Node sups) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2999 | List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3000 | (subs ~~ sups) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3001 | | is_subset (_, _) = | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3002 |           raise REFUTE ("lfp_interpreter",
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3003 | "is_subset: interpretation for set is not a node") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3004 | (* interpretation * interpretation -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3005 | fun intersection (Node xs, Node ys) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3006 | Node (map (fn (x, y) => if x=TT andalso y=TT then TT else FF) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3007 | (xs ~~ ys)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3008 | | intersection (_, _) = | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3009 |           raise REFUTE ("lfp_interpreter",
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3010 | "intersection: interpretation for set is not a node") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3011 | (* interpretation -> interpretaion *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3012 | fun lfp (Node resultsets) = | 
| 30190 | 3013 | List.foldl (fn ((set, resultset), acc) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3014 | if is_subset (resultset, set) then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3015 | intersection (acc, set) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3016 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3017 | acc) i_univ (i_sets ~~ resultsets) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3018 | | lfp _ = | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3019 |             raise REFUTE ("lfp_interpreter",
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3020 | "lfp: interpretation for function is not a node") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3021 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3022 | SOME (Node (map lfp i_funs), model, args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3023 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3024 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3025 | NONE; | 
| 16050 | 3026 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3027 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3028 | (interpretation * model * arguments) option *) | 
| 16050 | 3029 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3030 | (* only an optimization: 'gfp' could in principle be interpreted with *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3031 | (* interpreters available already (using its definition), but the code *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3032 | (* below is more efficient *) | 
| 16050 | 3033 | |
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3034 | fun gfp_interpreter thy model args t = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3035 | case t of | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3036 |       Const (@{const_name gfp}, Type ("fun", [Type ("fun",
 | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 3037 |         [Type ("fun", [T, Type ("bool", [])]),
 | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 3038 |          Type ("fun", [_, Type ("bool", [])])]),
 | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 3039 |          Type ("fun", [_, Type ("bool", [])])])) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3040 | let nonfix union (* because "union" is used below *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3041 | val size_elem = size_of_type thy model T | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3042 | (* the universe (i.e. the set that contains every element) *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3043 | val i_univ = Node (replicate size_elem TT) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3044 | (* all sets with elements from type 'T' *) | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 3045 | val i_sets = | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 3046 |           make_constants thy model (Type ("fun", [T, Type ("bool", [])]))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3047 | (* all functions that map sets to sets *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3048 |         val i_funs = make_constants thy model (Type ("fun",
 | 
| 30312 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 3049 |           [Type ("fun", [T, Type ("bool", [])]),
 | 
| 
0e0cb7ac0281
Fix remaining occurrences of "'a set" in Refute, by using "'a => bool" instead.
 blanchet parents: 
30307diff
changeset | 3050 |            Type ("fun", [T, Type ("bool", [])])]))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3051 |         (* "gfp(f) == Union({u. u <= f(u)})" *)
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3052 | (* interpretation * interpretation -> bool *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3053 | fun is_subset (Node subs, Node sups) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3054 | List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3055 | (subs ~~ sups) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3056 | | is_subset (_, _) = | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3057 |           raise REFUTE ("gfp_interpreter",
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3058 | "is_subset: interpretation for set is not a node") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3059 | (* interpretation * interpretation -> interpretation *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3060 | fun union (Node xs, Node ys) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3061 | Node (map (fn (x,y) => if x=TT orelse y=TT then TT else FF) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3062 | (xs ~~ ys)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3063 | | union (_, _) = | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3064 |           raise REFUTE ("gfp_interpreter",
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3065 | "union: interpretation for set is not a node") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3066 | (* interpretation -> interpretaion *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3067 | fun gfp (Node resultsets) = | 
| 30190 | 3068 | List.foldl (fn ((set, resultset), acc) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3069 | if is_subset (set, resultset) then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3070 | union (acc, set) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3071 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3072 | acc) i_univ (i_sets ~~ resultsets) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3073 | | gfp _ = | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3074 |             raise REFUTE ("gfp_interpreter",
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3075 | "gfp: interpretation for function is not a node") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3076 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3077 | SOME (Node (map gfp i_funs), model, args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3078 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3079 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3080 | NONE; | 
| 16050 | 3081 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3082 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3083 | (interpretation * model * arguments) option *) | 
| 21267 | 3084 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3085 | (* only an optimization: 'fst' could in principle be interpreted with *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3086 | (* interpreters available already (using its definition), but the code *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3087 | (* below is more efficient *) | 
| 21267 | 3088 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3089 | fun Product_Type_fst_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3090 | case t of | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 3091 |       Const (@{const_name fst}, Type ("fun", [Type ("*", [T, U]), _])) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3092 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3093 | val constants_T = make_constants thy model T | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3094 | val size_U = size_of_type thy model U | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3095 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3096 | SOME (Node (List.concat (map (replicate size_U) constants_T)), | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3097 | model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3098 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3099 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3100 | NONE; | 
| 21267 | 3101 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3102 | (* theory -> model -> arguments -> Term.term -> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3103 | (interpretation * model * arguments) option *) | 
| 21267 | 3104 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3105 | (* only an optimization: 'snd' could in principle be interpreted with *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3106 | (* interpreters available already (using its definition), but the code *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3107 | (* below is more efficient *) | 
| 21267 | 3108 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3109 | fun Product_Type_snd_interpreter thy model args t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3110 | case t of | 
| 29820 
07f53494cf20
Rearrange Refute/SAT theory dependencies so as to use even more antiquotations in refute.ML +
 blanchet parents: 
29802diff
changeset | 3111 |       Const (@{const_name snd}, Type ("fun", [Type ("*", [T, U]), _])) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3112 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3113 | val size_T = size_of_type thy model T | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3114 | val constants_U = make_constants thy model U | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3115 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3116 | SOME (Node (List.concat (replicate size_T constants_U)), model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3117 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3118 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3119 | NONE; | 
| 21267 | 3120 | |
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 3121 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 3122 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 3123 | (* 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 | 3124 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 3125 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3126 | (* theory -> model -> Term.typ -> interpretation -> (int -> bool) -> | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3127 | Term.term option *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 3128 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3129 | fun stlc_printer thy model T intr assignment = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3130 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3131 | (* string -> string *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3132 | fun strip_leading_quote s = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3133 | (implode o (fn [] => [] | x::xs => if x="'" then xs else x::xs) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3134 | o explode) s | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3135 | (* Term.typ -> string *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3136 | fun string_of_typ (Type (s, _)) = s | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3137 | | string_of_typ (TFree (x, _)) = strip_leading_quote x | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3138 | | string_of_typ (TVar ((x,i), _)) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3139 | strip_leading_quote x ^ string_of_int i | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3140 | (* interpretation -> int *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3141 | fun index_from_interpretation (Leaf xs) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3142 | find_index (PropLogic.eval assignment) xs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3143 | | index_from_interpretation _ = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3144 |       raise REFUTE ("stlc_printer",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3145 | "interpretation for ground type is not a leaf") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3146 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3147 | case T of | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3148 |       Type ("fun", [T1, T2]) =>
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3149 | let | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3150 | (* create all constants of type 'T1' *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3151 | val constants = make_constants thy model T1 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3152 | (* interpretation list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3153 | val results = (case intr of | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3154 | Node xs => xs | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3155 |           | _       => raise REFUTE ("stlc_printer",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3156 | "interpretation for function type is a leaf")) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3157 | (* Term.term list *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3158 | val pairs = map (fn (arg, result) => | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3159 | HOLogic.mk_prod | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3160 | (print thy model T1 arg assignment, | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3161 | print thy model T2 result assignment)) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3162 | (constants ~~ results) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3163 | (* Term.typ *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3164 | val HOLogic_prodT = HOLogic.mk_prodT (T1, T2) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3165 | val HOLogic_setT = HOLogic.mk_setT HOLogic_prodT | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3166 | (* Term.term *) | 
| 30450 | 3167 | val HOLogic_empty_set = HOLogic.mk_set HOLogic_prodT [] | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3168 | val HOLogic_insert = | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3169 |           Const (@{const_name insert}, HOLogic_prodT --> HOLogic_setT --> HOLogic_setT)
 | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3170 | in | 
| 30190 | 3171 | SOME (List.foldr (fn (pair, acc) => HOLogic_insert $ pair $ acc) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3172 | HOLogic_empty_set pairs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3173 | end | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3174 |     | Type ("prop", [])      =>
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3175 | (case index_from_interpretation intr of | 
| 28524 | 3176 |         ~1 => SOME (HOLogic.mk_Trueprop (Const (@{const_name undefined}, HOLogic.boolT)))
 | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3177 | | 0 => SOME (HOLogic.mk_Trueprop HOLogic.true_const) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3178 | | 1 => SOME (HOLogic.mk_Trueprop HOLogic.false_const) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3179 |       | _  => raise REFUTE ("stlc_interpreter",
 | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3180 | "illegal interpretation for a propositional value")) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3181 | | Type _ => if index_from_interpretation intr = (~1) then | 
| 28524 | 3182 |         SOME (Const (@{const_name undefined}, T))
 | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3183 | else | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3184 | SOME (Const (string_of_typ T ^ | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3185 | string_of_int (index_from_interpretation intr), T)) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3186 | | TFree _ => if index_from_interpretation intr = (~1) then | 
| 28524 | 3187 |         SOME (Const (@{const_name undefined}, T))
 | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3188 | else | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3189 | SOME (Const (string_of_typ T ^ | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3190 | string_of_int (index_from_interpretation intr), T)) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3191 | | TVar _ => if index_from_interpretation intr = (~1) then | 
| 28524 | 3192 |         SOME (Const (@{const_name undefined}, T))
 | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3193 | else | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3194 | SOME (Const (string_of_typ T ^ | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3195 | string_of_int (index_from_interpretation intr), T)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3196 | end; | 
| 14350 | 3197 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3198 | (* theory -> model -> Term.typ -> interpretation -> (int -> bool) -> | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3199 | Term.term option *) | 
| 14350 | 3200 | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3201 | fun IDT_printer thy model T intr assignment = | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3202 | (case T of | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3203 | Type (s, Ts) => | 
| 31784 | 3204 | (case Datatype.get_info thy s of | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3205 | SOME info => (* inductive datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3206 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3207 | val (typs, _) = model | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3208 | val index = #index info | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3209 | val descr = #descr info | 
| 29288 | 3210 | val (_, dtyps, constrs) = the (AList.lookup (op =) descr index) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3211 | val typ_assoc = dtyps ~~ Ts | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3212 | (* sanity check: every element in 'dtyps' must be a 'DtTFree' *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3213 | val _ = if Library.exists (fn d => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3214 | case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3215 | then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3216 |               raise REFUTE ("IDT_printer", "datatype argument (for type " ^
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26931diff
changeset | 3217 | Syntax.string_of_typ_global thy (Type (s, Ts)) ^ ") is not a variable") | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3218 | else () | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3219 | (* the index of the element in the datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3220 | val element = (case intr of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3221 | Leaf xs => find_index (PropLogic.eval assignment) xs | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3222 |             | Node _  => raise REFUTE ("IDT_printer",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3223 | "interpretation is not a leaf")) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3224 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3225 | if element < 0 then | 
| 28524 | 3226 |             SOME (Const (@{const_name undefined}, Type (s, Ts)))
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3227 | else let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3228 | (* takes a datatype constructor, and if for some arguments this *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3229 | (* constructor generates the datatype's element that is given by *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3230 | (* 'element', returns the constructor (as a term) as well as the *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3231 | (* indices of the arguments *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3232 | fun get_constr_args (cname, cargs) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3233 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3234 | val cTerm = Const (cname, | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3235 | map (typ_of_dtyp descr typ_assoc) cargs ---> Type (s, Ts)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3236 |                 val (iC, _, _) = interpret thy (typs, []) {maxvars=0,
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3237 | def_eq=false, next_idx=1, bounds=[], wellformed=True} cTerm | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3238 | (* interpretation -> int list option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3239 | fun get_args (Leaf xs) = | 
| 31986 | 3240 | if find_index (fn x => x = True) xs = element then | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3241 | SOME [] | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3242 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3243 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3244 | | get_args (Node xs) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3245 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3246 | (* interpretation * int -> int list option *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3247 | fun search ([], _) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3248 | NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3249 | | search (x::xs, n) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3250 | (case get_args x of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3251 | SOME result => SOME (n::result) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3252 | | NONE => search (xs, n+1)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3253 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3254 | search (xs, 0) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3255 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3256 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3257 | Option.map (fn args => (cTerm, cargs, args)) (get_args iC) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3258 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3259 | val (cTerm, cargs, args) = | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3260 | (* we could speed things up by computing the correct *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3261 | (* constructor directly (rather than testing all *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3262 | (* constructors), based on the order in which constructors *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3263 | (* generate elements of datatypes; the current implementation *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3264 | (* of 'IDT_printer' however is independent of the internals *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3265 | (* of 'IDT_constructor_interpreter' *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3266 | (case get_first get_constr_args constrs of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3267 | SOME x => x | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3268 |               | NONE   => raise REFUTE ("IDT_printer",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3269 | "no matching constructor found for element " ^ | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3270 | string_of_int element)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3271 | val argsTerms = map (fn (d, n) => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3272 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3273 | val dT = typ_of_dtyp descr typ_assoc d | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3274 | (* we only need the n-th element of this list, so there *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3275 | (* might be a more efficient implementation that does not *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3276 | (* generate all constants *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3277 | val consts = make_constants thy (typs, []) dT | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3278 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3279 | print thy (typs, []) dT (List.nth (consts, n)) assignment | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3280 | end) (cargs ~~ args) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3281 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3282 | SOME (Library.foldl op$ (cTerm, argsTerms)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3283 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3284 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3285 | | NONE => (* not an inductive datatype *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3286 | NONE) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3287 | | _ => (* a (free or schematic) type variable *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 3288 | NONE); | 
| 14350 | 3289 | |
| 3290 | ||
| 3291 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 3292 | (* 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 | 3293 | (* structure *) | 
| 14350 | 3294 | (* ------------------------------------------------------------------------- *) | 
| 3295 | ||
| 3296 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 3297 | (* 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 | 3298 | (* 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 | 3299 | (* 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 | 3300 | (* subterms that are then passed to other interpreters! *) | 
| 14350 | 3301 | (* ------------------------------------------------------------------------- *) | 
| 3302 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3303 | val setup = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3304 | add_interpreter "stlc" stlc_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3305 | add_interpreter "Pure" Pure_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3306 | add_interpreter "HOLogic" HOLogic_interpreter #> | 
| 29956 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 3307 | add_interpreter "set" set_interpreter #> | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3308 | add_interpreter "IDT" IDT_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3309 | add_interpreter "IDT_constructor" IDT_constructor_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3310 | add_interpreter "IDT_recursion" IDT_recursion_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3311 | add_interpreter "Finite_Set.card" Finite_Set_card_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3312 | add_interpreter "Finite_Set.finite" Finite_Set_finite_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3313 | add_interpreter "Nat_Orderings.less" Nat_less_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3314 | add_interpreter "Nat_HOL.plus" Nat_plus_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3315 | add_interpreter "Nat_HOL.minus" Nat_minus_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3316 | add_interpreter "Nat_HOL.times" Nat_times_interpreter #> | 
| 25032 | 3317 | add_interpreter "List.append" List_append_interpreter #> | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3318 | add_interpreter "lfp" lfp_interpreter #> | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 3319 | add_interpreter "gfp" gfp_interpreter #> | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3320 | add_interpreter "fst" Product_Type_fst_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3321 | add_interpreter "snd" Product_Type_snd_interpreter #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3322 | add_printer "stlc" stlc_printer #> | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 3323 | add_printer "IDT" IDT_printer; | 
| 14350 | 3324 | |
| 22092 | 3325 | end (* structure Refute *) |