| author | paulson <lp15@cam.ac.uk> | 
| Mon, 24 Oct 2022 15:58:06 +0100 | |
| changeset 76368 | 943f99825f39 | 
| parent 74561 | 8e6c973003c8 | 
| child 77896 | a9626bcb0c3b | 
| permissions | -rw-r--r-- | 
| 50530 | 1 | (* Title: HOL/Library/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 | ||
| 7 | signature REFUTE = | |
| 8 | sig | |
| 9 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 10 | exception REFUTE of string * string | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 11 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 12 | (* ------------------------------------------------------------------------- *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 13 | (* Model/interpretation related code (translation HOL -> propositional logic *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 14 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 15 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 16 | type params | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 17 | type interpretation | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 18 | type model | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 19 | type arguments | 
| 14456 
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 | exception MAXVARS_EXCEEDED | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 22 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 23 | val add_interpreter : string -> (Proof.context -> model -> arguments -> term -> | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 24 | (interpretation * model * arguments) option) -> theory -> theory | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 25 | val add_printer : string -> (Proof.context -> model -> typ -> | 
| 33243 | 26 | interpretation -> (int -> bool) -> term option) -> theory -> theory | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 27 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 28 | val interpret : Proof.context -> model -> arguments -> term -> | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 29 | (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 | 30 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 31 | val print : Proof.context -> model -> typ -> interpretation -> (int -> bool) -> term | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 32 | val print_model : Proof.context -> model -> (int -> bool) -> string | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 33 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 34 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 35 | (* Interface *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 36 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 37 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 38 | val set_default_param : (string * string) -> theory -> theory | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 39 | val get_default_param : Proof.context -> string -> string option | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 40 | val get_default_params : Proof.context -> (string * string) list | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 41 | val actual_params : Proof.context -> (string * string) list -> params | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 42 | |
| 45387 
ccffb3f9f42b
return outcome code, so that it can be picked up by Mutabelle
 blanchet parents: 
44121diff
changeset | 43 | val find_model : | 
| 
ccffb3f9f42b
return outcome code, so that it can be picked up by Mutabelle
 blanchet parents: 
44121diff
changeset | 44 | Proof.context -> params -> term list -> term -> bool -> string | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 45 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 46 | (* tries to find a model for a formula: *) | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 47 | val satisfy_term : | 
| 45387 
ccffb3f9f42b
return outcome code, so that it can be picked up by Mutabelle
 blanchet parents: 
44121diff
changeset | 48 | Proof.context -> (string * string) list -> term list -> term -> string | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 49 | (* tries to find a model that refutes a formula: *) | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 50 | val refute_term : | 
| 45387 
ccffb3f9f42b
return outcome code, so that it can be picked up by Mutabelle
 blanchet parents: 
44121diff
changeset | 51 | Proof.context -> (string * string) list -> term list -> term -> string | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 52 | val refute_goal : | 
| 45387 
ccffb3f9f42b
return outcome code, so that it can be picked up by Mutabelle
 blanchet parents: 
44121diff
changeset | 53 | Proof.context -> (string * string) list -> thm -> int -> string | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 54 | |
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 55 | (* ------------------------------------------------------------------------- *) | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 56 | (* 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 | 57 | (* ------------------------------------------------------------------------- *) | 
| 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 58 | |
| 33243 | 59 | val get_classdef : theory -> string -> (string * term) option | 
| 60 | val norm_rhs : term -> term | |
| 61 | val get_def : theory -> string * typ -> (string * term) option | |
| 62 | val get_typedef : theory -> typ -> (string * term) option | |
| 63 | val is_IDT_constructor : theory -> string * typ -> bool | |
| 64 | val is_IDT_recursor : theory -> string * typ -> bool | |
| 65 | val is_const_of_class: theory -> string * typ -> bool | |
| 66 | val string_of_typ : typ -> string | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 67 | end; | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 68 | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 69 | structure Refute : REFUTE = | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 70 | struct | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 71 | |
| 41471 | 72 | open Prop_Logic; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 73 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 74 | (* We use 'REFUTE' only for internal error conditions that should *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 75 | (* never occur in the first place (i.e. errors caused by bugs in our *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 76 | (* code). Otherwise (e.g. to indicate invalid input data) we use *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 77 | (* 'error'. *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 78 | exception REFUTE of string * string;  (* ("in function", "cause") *)
 | 
| 14350 | 79 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 80 | (* should be raised by an interpreter when more variables would be *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 81 | (* required than allowed by 'maxvars' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 82 | exception MAXVARS_EXCEEDED; | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 83 | |
| 14350 | 84 | |
| 85 | (* ------------------------------------------------------------------------- *) | |
| 86 | (* TREES *) | |
| 87 | (* ------------------------------------------------------------------------- *) | |
| 88 | ||
| 89 | (* ------------------------------------------------------------------------- *) | |
| 90 | (* tree: implements an arbitrarily (but finitely) branching tree as a list *) | |
| 91 | (* of (lists of ...) elements *) | |
| 92 | (* ------------------------------------------------------------------------- *) | |
| 93 | ||
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 94 | datatype 'a tree = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 95 | Leaf of 'a | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 96 |   | Node of ('a tree) list;
 | 
| 14350 | 97 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 98 | fun tree_map f tr = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 99 | case tr of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 100 | Leaf x => Leaf (f x) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 101 | | Node xs => Node (map (tree_map f) xs); | 
| 14350 | 102 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 103 | fun tree_pair (t1, t2) = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 104 | case t1 of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 105 | Leaf x => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 106 | (case t2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 107 | Leaf y => Leaf (x,y) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 108 |         | Node _ => raise REFUTE ("tree_pair",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 109 | "trees are of different height (second tree is higher)")) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 110 | | Node xs => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 111 | (case t2 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 112 | (* '~~' 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 | 113 | (* 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 | 114 | 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 | 115 |         | Leaf _  => raise REFUTE ("tree_pair",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 116 | "trees are of different height (first tree is higher)")); | 
| 14350 | 117 | |
| 118 | (* ------------------------------------------------------------------------- *) | |
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 119 | (* 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 | 120 | (* 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 | 121 | (* *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 122 | (* 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 | 123 | (* "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 | 124 | (* *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 125 | (* 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 | 126 | (* *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 127 | (* "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 | 128 | (* 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 | 129 | (* "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 | 130 | (* "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 | 131 | (* "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 | 132 | (* 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 | 133 | (* 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 | 134 | (* "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 | 135 | (* "satsolver" string SAT solver to be used. *) | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 136 | (* "no_assms" bool If "true", assumptions in structured proofs are *) | 
| 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 137 | (* not considered. *) | 
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 138 | (* "expect"      string  Expected result ("genuine", "potential", "none", or *)
 | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 139 | (* "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 | 140 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 141 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 142 | type params = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 143 |   {
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 144 | sizes : (string * int) list, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 145 | minsize : int, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 146 | maxsize : int, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 147 | maxvars : int, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 148 | maxtime : int, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 149 | satsolver: string, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 150 | no_assms : bool, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 151 | expect : string | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 152 | }; | 
| 14807 
e8ccb13d7774
major code change: refute can 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 | |
| 
e8ccb13d7774
major code change: refute can 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 | (* ------------------------------------------------------------------------- *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 155 | (* 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 | 156 | (* 'interpretation' *) | 
| 14350 | 157 | (* ------------------------------------------------------------------------- *) | 
| 158 | ||
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 159 | type interpretation = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 160 | prop_formula list tree; | 
| 14350 | 161 | |
| 162 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 163 | (* 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 | 164 | (* terms *) | 
| 14350 | 165 | (* ------------------------------------------------------------------------- *) | 
| 166 | ||
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 167 | type model = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 168 | (typ * int) list * (term * interpretation) list; | 
| 14350 | 169 | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 170 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 171 | (* arguments: additional arguments required during interpretation of terms *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 172 | (* ------------------------------------------------------------------------- *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 173 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 174 | type arguments = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 175 |   {
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 176 | (* just passed unchanged from 'params': *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 177 | maxvars : int, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 178 | (* whether to use 'make_equality' or 'make_def_equality': *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 179 | def_eq : bool, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 180 | (* the following may change during the translation: *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 181 | next_idx : int, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 182 | bounds : interpretation list, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 183 | wellformed: prop_formula | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 184 | }; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 185 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 186 | structure Data = Theory_Data | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 187 | ( | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 188 | type T = | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 189 |     {interpreters: (string * (Proof.context -> model -> arguments -> term ->
 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 190 | (interpretation * model * arguments) option)) list, | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 191 | printers: (string * (Proof.context -> model -> typ -> interpretation -> | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 192 | (int -> bool) -> term option)) list, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 193 | parameters: string Symtab.table}; | 
| 46960 | 194 |   val empty = {interpreters = [], printers = [], parameters = Symtab.empty};
 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 195 | fun merge | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 196 |     ({interpreters = in1, printers = pr1, parameters = pa1},
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 197 |      {interpreters = in2, printers = pr2, parameters = pa2}) : T =
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 198 |     {interpreters = AList.merge (op =) (K true) (in1, in2),
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 199 | printers = AList.merge (op =) (K true) (pr1, pr2), | 
| 41472 
f6ab14e61604
misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
 wenzelm parents: 
41471diff
changeset | 200 | parameters = Symtab.merge (op =) (pa1, pa2)}; | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 201 | ); | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 202 | |
| 42361 | 203 | val get_data = Data.get o Proof_Context.theory_of; | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 204 | |
| 14350 | 205 | |
| 206 | (* ------------------------------------------------------------------------- *) | |
| 15334 
d5a92997dc1b
exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
 webertj parents: 
15333diff
changeset | 207 | (* 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 | 208 | (* 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 | 209 | (* track of the interpretation of subterms *) | 
| 14350 | 210 | (* ------------------------------------------------------------------------- *) | 
| 211 | ||
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 212 | fun interpret ctxt model args t = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 213 | case get_first (fn (_, f) => f ctxt model args t) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 214 | (#interpreters (get_data ctxt)) of | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 215 |     NONE => raise REFUTE ("interpret",
 | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 216 | "no interpreter for term " ^ quote (Syntax.string_of_term ctxt t)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 217 | | SOME x => x; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 218 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 219 | (* ------------------------------------------------------------------------- *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 220 | (* print: converts the interpretation 'intr', which must denote a term of *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 221 | (* 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 | 222 | (* ------------------------------------------------------------------------- *) | 
| 14350 | 223 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 224 | fun print ctxt model T intr assignment = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 225 | case get_first (fn (_, f) => f ctxt model T intr assignment) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 226 | (#printers (get_data ctxt)) of | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 227 |     NONE => raise REFUTE ("print",
 | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 228 | "no printer for type " ^ quote (Syntax.string_of_typ ctxt T)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 229 | | SOME x => x; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 230 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 231 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 232 | (* 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 | 233 | (* (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 | 234 | (* printers *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 235 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 236 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 237 | fun print_model ctxt model assignment = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 238 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 239 | val (typs, terms) = model | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 240 | val typs_msg = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 241 | if null typs then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 242 | "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 | 243 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 244 | "Size of types: " ^ commas (map (fn (T, i) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 245 | Syntax.string_of_typ ctxt 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 | 246 | val show_consts_msg = | 
| 39050 
600de0485859
turned show_consts into proper configuration option;
 wenzelm parents: 
39049diff
changeset | 247 | if not (Config.get ctxt show_consts) andalso Library.exists (is_Const o fst) terms then | 
| 
600de0485859
turned show_consts into proper configuration option;
 wenzelm parents: 
39049diff
changeset | 248 | "enable \"show_consts\" to show the interpretation of constants\n" | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 249 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 250 | "" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 251 | val terms_msg = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 252 | if null terms then | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 253 | "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 | 254 | else | 
| 32952 | 255 | cat_lines (map_filter (fn (t, intr) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 256 | (* print constants only if 'show_consts' is true *) | 
| 39050 
600de0485859
turned show_consts into proper configuration option;
 wenzelm parents: 
39049diff
changeset | 257 | if Config.get ctxt show_consts orelse not (is_Const t) then | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 258 | SOME (Syntax.string_of_term ctxt t ^ ": " ^ | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 259 | Syntax.string_of_term ctxt | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 260 | (print ctxt 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 | 261 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 262 | NONE) terms) ^ "\n" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 263 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 264 | 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 | 265 | end; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 266 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 267 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 268 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 269 | (* PARAMETER MANAGEMENT *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 270 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 271 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 272 | fun add_interpreter name f = Data.map (fn {interpreters, printers, parameters} =>
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 273 | case AList.lookup (op =) interpreters name of | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 274 |     NONE => {interpreters = (name, f) :: interpreters,
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 275 | printers = printers, parameters = parameters} | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 276 |   | SOME _ => error ("Interpreter " ^ name ^ " already declared"));
 | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 277 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 278 | fun add_printer name f = Data.map (fn {interpreters, printers, parameters} =>
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 279 | case AList.lookup (op =) printers name of | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 280 |     NONE => {interpreters = interpreters,
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 281 | printers = (name, f) :: printers, parameters = parameters} | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 282 |   | SOME _ => error ("Printer " ^ name ^ " already declared"));
 | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 283 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 284 | (* ------------------------------------------------------------------------- *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 285 | (* set_default_param: stores the '(name, value)' pair in Data's *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 286 | (* parameter table *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 287 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 288 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 289 | fun set_default_param (name, value) = Data.map | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 290 |   (fn {interpreters, printers, parameters} =>
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 291 |     {interpreters = interpreters, printers = printers,
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 292 | parameters = Symtab.update (name, value) parameters}); | 
| 14350 | 293 | |
| 294 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 295 | (* get_default_param: retrieves the value associated with 'name' from *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 296 | (* Data's parameter table *) | 
| 14456 
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 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 299 | val get_default_param = Symtab.lookup o #parameters o get_data; | 
| 14456 
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 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 302 | (* get_default_params: returns a list of all '(name, value)' pairs that are *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 303 | (* stored in Data's parameter table *) | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 304 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 305 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 306 | val get_default_params = Symtab.dest o #parameters o get_data; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 307 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 308 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 309 | (* actual_params: takes a (possibly empty) list 'params' of parameters that *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 310 | (* override the default parameters currently specified, 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 | 311 | (* 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 | 312 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 313 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 314 | fun actual_params ctxt override = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 315 | let | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 316 | fun read_bool (parms, name) = | 
| 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 317 | case AList.lookup (op =) parms name of | 
| 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 318 | SOME "true" => true | 
| 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 319 | | SOME "false" => false | 
| 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 320 |       | SOME s => error ("parameter " ^ quote name ^
 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 321 | " (value is " ^ quote s ^ ") must be \"true\" or \"false\"") | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 322 |       | NONE   => error ("parameter " ^ quote name ^
 | 
| 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 323 | " must be assigned a value") | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 324 | fun read_int (parms, name) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 325 | case AList.lookup (op =) parms name of | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 326 | SOME s => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 327 | (case Int.fromString s of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 328 | SOME i => i | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 329 |           | NONE   => error ("parameter " ^ quote name ^
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 330 | " (value is " ^ quote s ^ ") must be an integer value")) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 331 |       | NONE => error ("parameter " ^ quote name ^
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 332 | " must be assigned a value") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 333 | fun read_string (parms, name) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 334 | 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 | 335 | SOME s => s | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 336 |       | NONE => error ("parameter " ^ quote name ^
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 337 | " must be assigned a value") | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 338 | (* 'override' first, defaults last: *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 339 | val allparams = override @ get_default_params ctxt | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 340 | val minsize = read_int (allparams, "minsize") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 341 | val maxsize = read_int (allparams, "maxsize") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 342 | val maxvars = read_int (allparams, "maxvars") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 343 | val maxtime = read_int (allparams, "maxtime") | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 344 | val satsolver = read_string (allparams, "satsolver") | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 345 | val no_assms = read_bool (allparams, "no_assms") | 
| 67405 
e9ab4ad7bd15
uniform use of Standard ML op-infix -- eliminated warnings;
 wenzelm parents: 
67399diff
changeset | 346 | 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 | 347 | (* 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 | 348 | (* 'sizes' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 349 | (* 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 | 350 | (* 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 | 351 | (* (string * int) list *) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 352 | val sizes = map_filter | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 353 | (fn (name, value) => Option.map (pair name) (Int.fromString value)) | 
| 33317 | 354 | (filter (fn (name, _) => name<>"minsize" andalso name<>"maxsize" | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 355 | andalso name<>"maxvars" andalso name<>"maxtime" | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 356 | andalso name<>"satsolver" andalso name<>"no_assms") allparams) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 357 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 358 |     {sizes=sizes, minsize=minsize, maxsize=maxsize, maxvars=maxvars,
 | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 359 | maxtime=maxtime, satsolver=satsolver, no_assms=no_assms, expect=expect} | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 360 | 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 | 361 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 362 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 363 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 364 | (* 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 | 365 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 366 | |
| 58120 | 367 | fun typ_of_dtyp _ typ_assoc (Old_Datatype_Aux.DtTFree a) = | 
| 368 | the (AList.lookup (op =) typ_assoc (Old_Datatype_Aux.DtTFree a)) | |
| 369 | | typ_of_dtyp descr typ_assoc (Old_Datatype_Aux.DtType (s, Us)) = | |
| 55891 
d1a9b07783ab
support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
 blanchet parents: 
55507diff
changeset | 370 | Type (s, map (typ_of_dtyp descr typ_assoc) Us) | 
| 58120 | 371 | | typ_of_dtyp descr typ_assoc (Old_Datatype_Aux.DtRec i) = | 
| 55891 
d1a9b07783ab
support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
 blanchet parents: 
55507diff
changeset | 372 | let val (s, ds, _) = the (AList.lookup (op =) descr i) in | 
| 
d1a9b07783ab
support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
 blanchet parents: 
55507diff
changeset | 373 | Type (s, map (typ_of_dtyp descr typ_assoc) ds) | 
| 
d1a9b07783ab
support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
 blanchet parents: 
55507diff
changeset | 374 | end | 
| 
d1a9b07783ab
support 'datatype_new'-defined datatypes in Nitpick + better support for 'codatatype's
 blanchet parents: 
55507diff
changeset | 375 | |
| 54757 
4960647932ec
use 'prop' rather than 'bool' systematically in Isar reconstruction code
 blanchet parents: 
54556diff
changeset | 376 | val close_form = ATP_Util.close_form | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: 
42680diff
changeset | 377 | val specialize_type = ATP_Util.specialize_type | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 378 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 379 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 380 | (* 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 | 381 | (* denotes membership to an axiomatic type class *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 382 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 383 | |
| 46096 | 384 | fun is_const_of_class thy (s, _) = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 385 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 386 | 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 | 387 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 388 | (* 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 | 389 | (* or if we should also check the type 'T'. *) | 
| 36692 
54b64d4ad524
farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
 haftmann parents: 
36555diff
changeset | 390 | member (op =) class_const_names s | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 391 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 392 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 393 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 394 | (* 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 | 395 | (* of an inductive datatype in 'thy' *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 396 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 397 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 398 | fun is_IDT_constructor thy (s, T) = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 399 | (case body_type T of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 400 | Type (s', _) => | 
| 58129 
3ec65a7f2b50
ported Refute to use new datatypes when possible
 blanchet parents: 
58120diff
changeset | 401 | (case BNF_LFP_Compat.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 | 402 | SOME constrs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 403 | List.exists (fn (cname, cty) => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 404 | cname = s andalso Sign.typ_instance thy (T, cty)) constrs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 405 | | NONE => false) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 406 | | _ => false); | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 407 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 408 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 409 | (* 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 | 410 | (* operator of an inductive datatype in 'thy' *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 411 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 412 | |
| 46096 | 413 | fun is_IDT_recursor thy (s, _) = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 414 | let | 
| 58354 
04ac60da613e
support (finite values of) codatatypes in Quickcheck
 blanchet parents: 
58322diff
changeset | 415 | val rec_names = Symtab.fold (append o #rec_names o snd) (BNF_LFP_Compat.get_all thy []) [] | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 416 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 417 | (* 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 | 418 | (* or if we should also check the type 'T'. *) | 
| 36692 
54b64d4ad524
farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
 haftmann parents: 
36555diff
changeset | 419 | member (op =) rec_names s | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 420 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 421 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 422 | (* ------------------------------------------------------------------------- *) | 
| 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 | 423 | (* 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 | 424 | (* ------------------------------------------------------------------------- *) | 
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 425 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 426 | fun norm_rhs eqn = | 
| 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 | 427 | 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 | 428 | fun lambda (v as Var ((x, _), T)) t = Abs (x, T, abstract_over (v, t)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 429 |       | lambda v t = raise TERM ("lambda", [v, t])
 | 
| 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 | 430 | val (lhs, rhs) = Logic.dest_equals eqn | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 431 | val (_, args) = Term.strip_comb lhs | 
| 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 | 432 | 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 | 433 | 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 | 434 | 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 | 435 | |
| 
381ce8d88cb8
Reintroduced previous changes: Made "Refute.norm_rhs" public and simplified the configuration of the BerkMin and zChaff SAT solvers.
 blanchet parents: 
30242diff
changeset | 436 | (* ------------------------------------------------------------------------- *) | 
| 37405 | 437 | (* get_def: looks up the definition of a constant *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 438 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 439 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 440 | fun get_def thy (s, T) = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 441 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 442 | fun get_def_ax [] = NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 443 | | get_def_ax ((axname, ax) :: axioms) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 444 | (let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 445 | val (lhs, _) = Logic.dest_equals ax (* equations only *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 446 | val c = Term.head_of lhs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 447 | val (s', T') = Term.dest_Const c | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 448 | in | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 449 | if s=s' then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 450 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 451 | val typeSubs = Sign.typ_match thy (T', T) Vartab.empty | 
| 61770 | 452 | val ax' = Envir.subst_term_types typeSubs ax | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 453 | val rhs = norm_rhs ax' | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 454 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 455 | SOME (axname, rhs) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 456 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 457 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 458 | get_def_ax axioms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 459 | end handle ERROR _ => get_def_ax axioms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 460 | | TERM _ => get_def_ax axioms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 461 | | Type.TYPE_MATCH => get_def_ax axioms) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 462 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 463 | 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 | 464 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 465 | |
| 
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 | (* 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 | 468 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 469 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 470 | fun get_typedef thy T = | 
| 22567 
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 get_typedef_ax [] = NONE | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 473 | | get_typedef_ax ((axname, ax) :: axioms) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 474 | (let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 475 | fun type_of_type_definition (Const (s', T')) = | 
| 69593 | 476 | if s'= \<^const_name>\<open>type_definition\<close> then | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 477 | SOME T' | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 478 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 479 | NONE | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 480 | | type_of_type_definition (Free _) = NONE | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 481 | | type_of_type_definition (Var _) = NONE | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 482 | | type_of_type_definition (Bound _) = NONE | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 483 | | type_of_type_definition (Abs (_, _, body)) = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 484 | type_of_type_definition body | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 485 | | type_of_type_definition (t1 $ t2) = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 486 | (case type_of_type_definition t1 of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 487 | SOME x => SOME x | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 488 | | NONE => type_of_type_definition t2) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 489 | in | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 490 | case type_of_type_definition ax of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 491 | SOME T' => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 492 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 493 | val T'' = domain_type (domain_type T') | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 494 | val typeSubs = Sign.typ_match thy (T'', T) Vartab.empty | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 495 | in | 
| 61770 | 496 | SOME (axname, Envir.subst_term_types typeSubs ax) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 497 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 498 | | NONE => get_typedef_ax axioms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 499 | end handle ERROR _ => get_typedef_ax axioms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 500 | | TERM _ => get_typedef_ax axioms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 501 | | Type.TYPE_MATCH => get_typedef_ax axioms) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 502 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 503 | 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 | 504 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 505 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 506 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 507 | (* 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 | 508 | (* created by the "axclass" command *) | 
| 
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 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 511 | fun get_classdef thy class = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 512 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 513 | val axname = class ^ "_class_def" | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 514 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 515 | Option.map (pair axname) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 516 | (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 | 517 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 518 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 519 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 520 | (* 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 | 521 | (* normalizes the result term; certain constants are not *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 522 | (* unfolded (cf. 'collect_axioms' and the various interpreters *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 523 | (* below): if the interpretation respects a definition anyway, *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 524 | (* that definition does not need to be unfolded *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 525 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 526 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 527 | (* Note: we could intertwine unfolding of constants and beta-(eta-) *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 528 | (* normalization; this would save some unfolding for terms where *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 529 | (* constants are eliminated by beta-reduction (e.g. 'K c1 c2'). On *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 530 | (* the other hand, this would cause additional work for terms where *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 531 | (* 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 | 532 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 533 | fun unfold_defs thy t = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 534 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 535 | fun unfold_loop t = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 536 | case t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 537 | (* Pure *) | 
| 69593 | 538 | Const (\<^const_name>\<open>Pure.all\<close>, _) => t | 
| 539 | | Const (\<^const_name>\<open>Pure.eq\<close>, _) => t | |
| 540 | | Const (\<^const_name>\<open>Pure.imp\<close>, _) => t | |
| 541 | | Const (\<^const_name>\<open>Pure.type\<close>, _) => t (* axiomatic type classes *) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 542 | (* HOL *) | 
| 69593 | 543 | | Const (\<^const_name>\<open>Trueprop\<close>, _) => t | 
| 544 | | Const (\<^const_name>\<open>Not\<close>, _) => t | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 545 | | (* redundant, since 'True' is also an IDT constructor *) | 
| 69593 | 546 | Const (\<^const_name>\<open>True\<close>, _) => t | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 547 | | (* redundant, since 'False' is also an IDT constructor *) | 
| 69593 | 548 | Const (\<^const_name>\<open>False\<close>, _) => t | 
| 549 | | Const (\<^const_name>\<open>undefined\<close>, _) => t | |
| 550 | | Const (\<^const_name>\<open>The\<close>, _) => t | |
| 551 | | Const (\<^const_name>\<open>Hilbert_Choice.Eps\<close>, _) => t | |
| 552 | | Const (\<^const_name>\<open>All\<close>, _) => t | |
| 553 | | Const (\<^const_name>\<open>Ex\<close>, _) => t | |
| 554 | | Const (\<^const_name>\<open>HOL.eq\<close>, _) => t | |
| 555 | | Const (\<^const_name>\<open>HOL.conj\<close>, _) => t | |
| 556 | | Const (\<^const_name>\<open>HOL.disj\<close>, _) => t | |
| 557 | | Const (\<^const_name>\<open>HOL.implies\<close>, _) => t | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 558 | (* sets *) | 
| 69593 | 559 | | Const (\<^const_name>\<open>Collect\<close>, _) => t | 
| 560 | | Const (\<^const_name>\<open>Set.member\<close>, _) => t | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 561 | (* other optimizations *) | 
| 69593 | 562 | | Const (\<^const_name>\<open>Finite_Set.card\<close>, _) => t | 
| 563 | | Const (\<^const_name>\<open>Finite_Set.finite\<close>, _) => t | |
| 564 |       | Const (\<^const_name>\<open>Orderings.less\<close>, Type ("fun", [\<^typ>\<open>nat\<close>,
 | |
| 565 |           Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>bool\<close>])])) => t
 | |
| 566 |       | Const (\<^const_name>\<open>Groups.plus\<close>, Type ("fun", [\<^typ>\<open>nat\<close>,
 | |
| 567 |           Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>nat\<close>])])) => t
 | |
| 568 |       | Const (\<^const_name>\<open>Groups.minus\<close>, Type ("fun", [\<^typ>\<open>nat\<close>,
 | |
| 569 |           Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>nat\<close>])])) => t
 | |
| 570 |       | Const (\<^const_name>\<open>Groups.times\<close>, Type ("fun", [\<^typ>\<open>nat\<close>,
 | |
| 571 |           Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>nat\<close>])])) => t
 | |
| 572 | | Const (\<^const_name>\<open>append\<close>, _) => t | |
| 573 | | Const (\<^const_name>\<open>fst\<close>, _) => t | |
| 574 | | Const (\<^const_name>\<open>snd\<close>, _) => t | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 575 | (* simply-typed lambda calculus *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 576 | | Const (s, T) => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 577 | (if is_IDT_constructor thy (s, T) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 578 | orelse is_IDT_recursor thy (s, T) then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 579 | t (* do not unfold IDT constructors/recursors *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 580 | (* unfold the constant if there is a defining equation *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 581 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 582 | case get_def thy (s, T) of | 
| 46096 | 583 | SOME ((*axname*) _, rhs) => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 584 | (* Note: if the term to be unfolded (i.e. 'Const (s, T)') *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 585 | (* occurs on the right-hand side of the equation, i.e. in *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 586 | (* 'rhs', we must not use this equation to unfold, because *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 587 | (* that would loop. Here would be the right place to *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 588 | (* check this. However, getting this really right seems *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 589 | (* difficult because the user may state arbitrary axioms, *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 590 | (* which could interact with overloading to create loops. *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 591 |               ((*tracing (" unfolding: " ^ axname);*)
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 592 | unfold_loop rhs) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 593 | | NONE => t) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 594 | | Free _ => t | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 595 | | Var _ => t | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 596 | | Bound _ => t | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 597 | | Abs (s, T, body) => Abs (s, T, unfold_loop body) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 598 | | t1 $ t2 => (unfold_loop t1) $ (unfold_loop t2) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 599 | 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 | 600 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 601 | result | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 602 | end; | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 603 | |
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 604 | (* ------------------------------------------------------------------------- *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 605 | (* collect_axioms: collects (monomorphic, universally quantified, unfolded *) | 
| 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 606 | (* 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 | 607 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 608 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 609 | (* Note: to make the collection of axioms more easily extensible, this *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 610 | (* function could be based on user-supplied "axiom collectors", *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 611 | (* 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 | 612 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 613 | (* Note: currently we use "inverse" functions to the definitional *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 614 | (* mechanisms provided by Isabelle/HOL, e.g. for "axclass", *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 615 | (* "typedef", "definition". A more general approach could consider *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 616 | (* *every* axiom of the theory and collect it if it has a constant/ *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 617 | (* type/typeclass in common with the term 't'. *) | 
| 21985 
acfb13e8819e
constants are unfolded, universal quantifiers are stripped, some minor changes
 webertj parents: 
21931diff
changeset | 618 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 619 | (* Which axioms are "relevant" for a particular term/type goes hand in *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 620 | (* hand with the interpretation of that term/type by its interpreter (see *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 621 | (* way below): if the interpretation respects an axiom anyway, the axiom *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 622 | (* 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 | 623 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 624 | (* To avoid collecting the same axiom multiple times, we use an *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 625 | (* 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 | 626 | |
| 56256 | 627 | local | 
| 628 | ||
| 629 | fun get_axiom thy xname = | |
| 630 | Name_Space.check (Context.Theory thy) (Theory.axiom_table thy) (xname, Position.none); | |
| 631 | ||
| 69593 | 632 | val the_eq_trivial = get_axiom \<^theory>\<open>HOL\<close> "the_eq_trivial"; | 
| 633 | val someI = get_axiom \<^theory>\<open>Hilbert_Choice\<close> "someI"; | |
| 56256 | 634 | |
| 635 | in | |
| 636 | ||
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 637 | fun collect_axioms ctxt t = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 638 | let | 
| 42361 | 639 | val thy = Proof_Context.theory_of ctxt | 
| 32950 | 640 | val _ = tracing "Adding axioms..." | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 641 | fun collect_this_axiom (axname, ax) axs = | 
| 33246 | 642 | let | 
| 643 | val ax' = unfold_defs thy ax | |
| 644 | in | |
| 645 | if member (op aconv) axs ax' then axs | |
| 646 | else (tracing axname; collect_term_axioms ax' (ax' :: axs)) | |
| 647 | end | |
| 648 | and collect_sort_axioms T axs = | |
| 649 | let | |
| 650 | val sort = | |
| 651 | (case T of | |
| 652 | TFree (_, sort) => sort | |
| 653 | | TVar (_, sort) => sort | |
| 654 |           | _ => raise REFUTE ("collect_axioms",
 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 655 | "type " ^ Syntax.string_of_typ ctxt T ^ " is not a variable")) | 
| 33246 | 656 | (* obtain axioms for all superclasses *) | 
| 657 | val superclasses = sort @ maps (Sign.super_classes thy) sort | |
| 658 | (* merely an optimization, because 'collect_this_axiom' disallows *) | |
| 659 | (* duplicate axioms anyway: *) | |
| 660 | val superclasses = distinct (op =) superclasses | |
| 661 | val class_axioms = maps (fn class => map (fn ax => | |
| 662 |           ("<" ^ class ^ ">", Thm.prop_of ax))
 | |
| 51685 
385ef6706252
more standard module name Axclass (according to file name);
 wenzelm parents: 
51557diff
changeset | 663 | (#axioms (Axclass.get_info thy class) handle ERROR _ => [])) | 
| 33246 | 664 | superclasses | 
| 665 | (* replace the (at most one) schematic type variable in each axiom *) | |
| 666 | (* by the actual type 'T' *) | |
| 667 | val monomorphic_class_axioms = map (fn (axname, ax) => | |
| 668 | (case Term.add_tvars ax [] of | |
| 669 | [] => (axname, ax) | |
| 61770 | 670 | | [(idx, S)] => (axname, Envir.subst_term_types (Vartab.make [(idx, (S, T))]) ax) | 
| 33246 | 671 | | _ => | 
| 672 |             raise REFUTE ("collect_axioms", "class axiom " ^ axname ^ " (" ^
 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 673 | Syntax.string_of_term ctxt ax ^ | 
| 33246 | 674 | ") contains more than one type variable"))) | 
| 675 | class_axioms | |
| 676 | in | |
| 677 | fold collect_this_axiom monomorphic_class_axioms axs | |
| 678 | end | |
| 679 | and collect_type_axioms T axs = | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 680 | case T of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 681 | (* simple types *) | 
| 69593 | 682 | Type (\<^type_name>\<open>prop\<close>, []) => axs | 
| 683 | | Type (\<^type_name>\<open>fun\<close>, [T1, T2]) => collect_type_axioms T2 (collect_type_axioms T1 axs) | |
| 684 | | Type (\<^type_name>\<open>set\<close>, [T1]) => collect_type_axioms T1 axs | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 685 | (* axiomatic type classes *) | 
| 69593 | 686 | | Type (\<^type_name>\<open>itself\<close>, [T1]) => collect_type_axioms T1 axs | 
| 33246 | 687 | | Type (s, Ts) => | 
| 58354 
04ac60da613e
support (finite values of) codatatypes in Quickcheck
 blanchet parents: 
58322diff
changeset | 688 | (case BNF_LFP_Compat.get_info thy [] s of | 
| 46096 | 689 | SOME _ => (* inductive datatype *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 690 | (* only collect relevant type axioms for the argument types *) | 
| 33246 | 691 | fold collect_type_axioms Ts axs | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 692 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 693 | (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 | 694 | SOME (axname, ax) => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 695 | collect_this_axiom (axname, ax) axs | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 696 | | NONE => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 697 | (* 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 | 698 | (* at least collect relevant type axioms for the argument types *) | 
| 33246 | 699 | fold collect_type_axioms Ts axs)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 700 | (* axiomatic type classes *) | 
| 33246 | 701 | | TFree _ => collect_sort_axioms T axs | 
| 702 | (* axiomatic type classes *) | |
| 703 | | TVar _ => collect_sort_axioms T axs | |
| 704 | and collect_term_axioms t axs = | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 705 | case t of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 706 | (* Pure *) | 
| 69593 | 707 | Const (\<^const_name>\<open>Pure.all\<close>, _) => axs | 
| 708 | | Const (\<^const_name>\<open>Pure.eq\<close>, _) => axs | |
| 709 | | Const (\<^const_name>\<open>Pure.imp\<close>, _) => axs | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 710 | (* axiomatic type classes *) | 
| 69593 | 711 | | Const (\<^const_name>\<open>Pure.type\<close>, T) => collect_type_axioms T axs | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 712 | (* HOL *) | 
| 69593 | 713 | | Const (\<^const_name>\<open>Trueprop\<close>, _) => axs | 
| 714 | | Const (\<^const_name>\<open>Not\<close>, _) => axs | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 715 | (* redundant, since 'True' is also an IDT constructor *) | 
| 69593 | 716 | | Const (\<^const_name>\<open>True\<close>, _) => axs | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 717 | (* redundant, since 'False' is also an IDT constructor *) | 
| 69593 | 718 | | Const (\<^const_name>\<open>False\<close>, _) => axs | 
| 719 | | Const (\<^const_name>\<open>undefined\<close>, T) => collect_type_axioms T axs | |
| 720 | | Const (\<^const_name>\<open>The\<close>, T) => | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 721 | let | 
| 69593 | 722 | val ax = specialize_type thy (\<^const_name>\<open>The\<close>, T) (#2 the_eq_trivial) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 723 | in | 
| 56256 | 724 | collect_this_axiom (#1 the_eq_trivial, ax) axs | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 725 | end | 
| 69593 | 726 | | Const (\<^const_name>\<open>Hilbert_Choice.Eps\<close>, T) => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 727 | let | 
| 69593 | 728 | val ax = specialize_type thy (\<^const_name>\<open>Hilbert_Choice.Eps\<close>, T) (#2 someI) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 729 | in | 
| 56256 | 730 | collect_this_axiom (#1 someI, ax) axs | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 731 | end | 
| 69593 | 732 | | Const (\<^const_name>\<open>All\<close>, T) => collect_type_axioms T axs | 
| 733 | | Const (\<^const_name>\<open>Ex\<close>, T) => collect_type_axioms T axs | |
| 734 | | Const (\<^const_name>\<open>HOL.eq\<close>, T) => collect_type_axioms T axs | |
| 735 | | Const (\<^const_name>\<open>HOL.conj\<close>, _) => axs | |
| 736 | | Const (\<^const_name>\<open>HOL.disj\<close>, _) => axs | |
| 737 | | Const (\<^const_name>\<open>HOL.implies\<close>, _) => axs | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 738 | (* sets *) | 
| 69593 | 739 | | Const (\<^const_name>\<open>Collect\<close>, T) => collect_type_axioms T axs | 
| 740 | | Const (\<^const_name>\<open>Set.member\<close>, T) => collect_type_axioms T axs | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 741 | (* other optimizations *) | 
| 69593 | 742 | | Const (\<^const_name>\<open>Finite_Set.card\<close>, T) => collect_type_axioms T axs | 
| 743 | | Const (\<^const_name>\<open>Finite_Set.finite\<close>, T) => | |
| 33246 | 744 | collect_type_axioms T axs | 
| 69593 | 745 |       | Const (\<^const_name>\<open>Orderings.less\<close>, T as Type ("fun", [\<^typ>\<open>nat\<close>,
 | 
| 746 |         Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>bool\<close>])])) =>
 | |
| 33246 | 747 | collect_type_axioms T axs | 
| 69593 | 748 |       | Const (\<^const_name>\<open>Groups.plus\<close>, T as Type ("fun", [\<^typ>\<open>nat\<close>,
 | 
| 749 |         Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>nat\<close>])])) =>
 | |
| 33246 | 750 | collect_type_axioms T axs | 
| 69593 | 751 |       | Const (\<^const_name>\<open>Groups.minus\<close>, T as Type ("fun", [\<^typ>\<open>nat\<close>,
 | 
| 752 |         Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>nat\<close>])])) =>
 | |
| 33246 | 753 | collect_type_axioms T axs | 
| 69593 | 754 |       | Const (\<^const_name>\<open>Groups.times\<close>, T as Type ("fun", [\<^typ>\<open>nat\<close>,
 | 
| 755 |         Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>nat\<close>])])) =>
 | |
| 33246 | 756 | collect_type_axioms T axs | 
| 69593 | 757 | | Const (\<^const_name>\<open>append\<close>, T) => collect_type_axioms T axs | 
| 758 | | Const (\<^const_name>\<open>fst\<close>, T) => collect_type_axioms T axs | |
| 759 | | Const (\<^const_name>\<open>snd\<close>, T) => collect_type_axioms T axs | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 760 | (* simply-typed lambda calculus *) | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 761 | | Const (s, T) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 762 | 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 | 763 | (* 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 | 764 | (* and the class definition *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 765 | let | 
| 33246 | 766 | 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 | 767 |               val of_class = Logic.mk_of_class (TVar (("'a", 0), [class]), class)
 | 
| 33246 | 768 | 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 | 769 | (* 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 | 770 | handle Type.TYPE_MATCH => NONE | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 771 | val ax_1 = Option.map (fn ax => (Syntax.string_of_term ctxt ax, ax)) ax_in | 
| 33246 | 772 | val ax_2 = Option.map (apsnd (specialize_type thy (s, T))) (get_classdef thy class) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 773 | in | 
| 33246 | 774 | collect_type_axioms T (fold collect_this_axiom (map_filter I [ax_1, ax_2]) axs) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 775 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 776 | else if is_IDT_constructor thy (s, T) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 777 | orelse is_IDT_recursor thy (s, T) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 778 | then | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 779 | (* only collect relevant type axioms *) | 
| 33246 | 780 | collect_type_axioms T axs | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 781 | else | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 782 | (* 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 | 783 | (* 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 | 784 | (* 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 | 785 | (* only collect relevant type axioms *) | 
| 33246 | 786 | collect_type_axioms T axs | 
| 787 | | Free (_, T) => collect_type_axioms T axs | |
| 788 | | Var (_, T) => collect_type_axioms T axs | |
| 789 | | Bound _ => axs | |
| 790 | | Abs (_, T, body) => collect_term_axioms body (collect_type_axioms T axs) | |
| 791 | | t1 $ t2 => collect_term_axioms t2 (collect_term_axioms t1 axs) | |
| 792 | val result = map close_form (collect_term_axioms t []) | |
| 32950 | 793 | val _ = tracing " ...done." | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 794 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 795 | result | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 796 | end; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 797 | |
| 56256 | 798 | end; | 
| 799 | ||
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 800 | (* ------------------------------------------------------------------------- *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 801 | (* 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 | 802 | (* 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 | 803 | (* 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 | 804 | (* 'propT'. For IDTs, also the argument types of constructors *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 805 | (* 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 | 806 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 807 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 808 | fun ground_types ctxt t = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 809 | let | 
| 42361 | 810 | val thy = Proof_Context.theory_of ctxt | 
| 29272 | 811 | fun collect_types T acc = | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 812 | (case T of | 
| 69593 | 813 | Type (\<^type_name>\<open>fun\<close>, [T1, T2]) => collect_types T1 (collect_types T2 acc) | 
| 814 | | Type (\<^type_name>\<open>prop\<close>, []) => acc | |
| 815 | | Type (\<^type_name>\<open>set\<close>, [T1]) => collect_types T1 acc | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 816 | | Type (s, Ts) => | 
| 58354 
04ac60da613e
support (finite values of) codatatypes in Quickcheck
 blanchet parents: 
58322diff
changeset | 817 | (case BNF_LFP_Compat.get_info thy [] s of | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 818 | SOME info => (* inductive datatype *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 819 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 820 | val index = #index info | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 821 | val descr = #descr info | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 822 | val (_, typs, _) = the (AList.lookup (op =) descr index) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 823 | val typ_assoc = typs ~~ Ts | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 824 | (* sanity check: every element in 'dtyps' must be a *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 825 | (* 'DtTFree' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 826 | val _ = if Library.exists (fn d => | 
| 58120 | 827 | case d of Old_Datatype_Aux.DtTFree _ => false | _ => true) typs then | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 828 |                   raise REFUTE ("ground_types", "datatype argument (for type "
 | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 829 | ^ Syntax.string_of_typ ctxt T ^ ") is not a variable") | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 830 | else () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 831 | (* required for mutually recursive datatypes; those need to *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 832 | (* be added even if they are an instance of an otherwise non- *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 833 | (* recursive datatype *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 834 | fun collect_dtyp d acc = | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 835 | let | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 836 | val dT = typ_of_dtyp descr typ_assoc d | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 837 | in | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 838 | case d of | 
| 58120 | 839 | Old_Datatype_Aux.DtTFree _ => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 840 | collect_types dT acc | 
| 58120 | 841 | | Old_Datatype_Aux.DtType (_, ds) => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 842 | collect_types dT (fold_rev collect_dtyp ds acc) | 
| 58120 | 843 | | Old_Datatype_Aux.DtRec i => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 844 | if member (op =) acc dT then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 845 | acc (* prevent infinite recursion *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 846 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 847 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 848 | val (_, dtyps, dconstrs) = the (AList.lookup (op =) descr i) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 849 | (* if the current type is a recursive IDT (i.e. a depth *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 850 | (* is required), add it to 'acc' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 851 | val acc_dT = if Library.exists (fn (_, ds) => | 
| 58120 | 852 | Library.exists Old_Datatype_Aux.is_rec_type ds) dconstrs then | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 853 | insert (op =) dT acc | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 854 | else acc | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 855 | (* collect argument types *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 856 | val acc_dtyps = fold_rev collect_dtyp dtyps acc_dT | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 857 | (* collect constructor types *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 858 | val acc_dconstrs = fold_rev collect_dtyp (maps snd dconstrs) acc_dtyps | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 859 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 860 | acc_dconstrs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 861 | end | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 862 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 863 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 864 | (* argument types 'Ts' could be added here, but they are also *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 865 | (* added by 'collect_dtyp' automatically *) | 
| 58120 | 866 | collect_dtyp (Old_Datatype_Aux.DtRec index) acc | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 867 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 868 | | NONE => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 869 | (* not an inductive datatype, e.g. defined via "typedef" or *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 870 | (* "typedecl" *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 871 | insert (op =) T (fold collect_types Ts acc)) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 872 | | TFree _ => insert (op =) T acc | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 873 | | 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 | 874 | in | 
| 29272 | 875 | 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 | 876 | 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 | 877 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 878 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 879 | (* 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 | 880 | (* 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 | 881 | (* 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 | 882 | (* 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 | 883 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 884 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 885 | fun string_of_typ (Type (s, _)) = s | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 886 | | string_of_typ (TFree (s, _)) = s | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 887 | | 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 | 888 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 889 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 890 | (* 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 | 891 | (* '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 | 892 | (* '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 | 893 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 894 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 895 | fun first_universe xs sizes minsize = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 896 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 897 | fun size_of_typ T = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 898 | 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 | 899 | SOME n => n | 
| 33246 | 900 | | NONE => minsize | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 901 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 902 | 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 | 903 | 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 | 904 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 905 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 906 | (* 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 | 907 | (* 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 | 908 | (* '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 | 909 | (* 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 | 910 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 911 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 912 | fun next_universe xs sizes minsize maxsize = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 913 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 914 | (* 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 | 915 | (* 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 | 916 | fun make_first _ 0 sum = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 917 | if sum = 0 then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 918 | SOME [] | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 919 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 920 | NONE | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 921 | | make_first max len sum = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 922 | if sum <= max orelse max < 0 then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 923 | Option.map (fn xs' => sum :: xs') (make_first max (len-1) 0) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 924 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 925 | Option.map (fn xs' => max :: xs') (make_first max (len-1) (sum-max)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 926 | (* 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 | 927 | (* all list elements x (unless 'max'<0) *) | 
| 46096 | 928 | fun next _ _ _ [] = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 929 | NONE | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 930 | | next max len sum [x] = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 931 | (* we've reached the last list element, so there's no shift possible *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 932 | make_first max (len+1) (sum+x+1) (* increment 'sum' by 1 *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 933 | | next max len sum (x1::x2::xs) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 934 | if x1>0 andalso (x2<max orelse max<0) then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 935 | (* we can shift *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 936 | SOME (the (make_first max (len+1) (sum+x1-1)) @ (x2+1) :: xs) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 937 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 938 | (* continue search *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 939 | next max (len+1) (sum+x1) (x2::xs) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 940 | (* only consider those types for which the size is not fixed *) | 
| 33317 | 941 | val mutables = filter_out (AList.defined (op =) sizes o string_of_typ o fst) xs | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 942 | (* 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 | 943 | 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 | 944 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 945 | 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 | 946 | SOME diffs' => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 947 | (* merge with those types for which the size is fixed *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 948 | SOME (fst (fold_map (fn (T, _) => fn ds => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 949 | case AList.lookup (op =) sizes (string_of_typ T) of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 950 | (* return the fixed size *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 951 | SOME n => ((T, n), ds) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 952 | (* consume the head of 'ds', add 'minsize' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 953 | | NONE => ((T, minsize + hd ds), tl ds)) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 954 | xs diffs')) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 955 | | NONE => NONE | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 956 | 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 | 957 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 958 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 959 | (* 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 | 960 | (* 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 | 961 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 962 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 963 | fun toTrue (Leaf [fm, _]) = fm | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 964 |   | toTrue _ = raise REFUTE ("toTrue", "interpretation does not denote a Boolean value");
 | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 965 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 966 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 967 | (* 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 | 968 | (* 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 | 969 | (* 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 | 970 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 971 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 972 | fun toFalse (Leaf [_, fm]) = fm | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 973 |   | toFalse _ = raise REFUTE ("toFalse", "interpretation does not denote a Boolean value");
 | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 974 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 975 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 976 | (* 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 | 977 | (* 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 | 978 | (* 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 | 979 | (* {...}     : parameters that control the translation/model generation      *)
 | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 980 | (* assm_ts : assumptions to be considered unless "no_assms" is specified *) | 
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 981 | (* 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 | 982 | (* 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 | 983 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 984 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 985 | fun find_model ctxt | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 986 |     {sizes, minsize, maxsize, maxvars, maxtime, satsolver, no_assms, expect}
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 987 | assm_ts t negate = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 988 | let | 
| 42361 | 989 | val thy = Proof_Context.theory_of ctxt | 
| 33054 
dd1192a96968
fixed the "expect" mechanism of Refute in the face of timeouts
 blanchet parents: 
32952diff
changeset | 990 | fun check_expect outcome_code = | 
| 45387 
ccffb3f9f42b
return outcome code, so that it can be picked up by Mutabelle
 blanchet parents: 
44121diff
changeset | 991 | if expect = "" orelse outcome_code = expect then outcome_code | 
| 33054 
dd1192a96968
fixed the "expect" mechanism of Refute in the face of timeouts
 blanchet parents: 
32952diff
changeset | 992 |       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 | 993 | fun wrapper () = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 994 | let | 
| 73387 | 995 | val time_start = Time.now () | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 996 | val t = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 997 | if no_assms then t | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 998 | else if negate then Logic.list_implies (assm_ts, t) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 999 | else Logic.mk_conjunction_list (t :: assm_ts) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1000 | val u = unfold_defs thy t | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1001 |         val _ = tracing ("Unfolded term: " ^ Syntax.string_of_term ctxt u)
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1002 | val axioms = collect_axioms ctxt u | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1003 | val types = fold (union (op =) o ground_types ctxt) (u :: axioms) [] | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1004 |         val _ = tracing ("Ground types: "
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1005 | ^ (if null types then "none." | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1006 | else commas (map (Syntax.string_of_typ ctxt) types))) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1007 | (* we can only consider fragments of recursive IDTs, so we issue a *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1008 | (* warning if the formula contains a recursive IDT *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1009 | (* TODO: no warning needed for /positive/ occurrences of IDTs *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1010 | val maybe_spurious = Library.exists (fn | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1011 | Type (s, _) => | 
| 58354 
04ac60da613e
support (finite values of) codatatypes in Quickcheck
 blanchet parents: 
58322diff
changeset | 1012 | (case BNF_LFP_Compat.get_info thy [] s of | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1013 | SOME info => (* inductive datatype *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1014 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1015 | val index = #index info | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1016 | val descr = #descr info | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1017 | val (_, _, constrs) = the (AList.lookup (op =) descr index) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1018 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1019 | (* recursive datatype? *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1020 | Library.exists (fn (_, ds) => | 
| 58120 | 1021 | Library.exists Old_Datatype_Aux.is_rec_type ds) constrs | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1022 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1023 | | NONE => false) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1024 | | _ => false) types | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1025 | val _ = | 
| 59352 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
58893diff
changeset | 1026 | if maybe_spurious andalso Context_Position.is_visible ctxt then | 
| 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
58893diff
changeset | 1027 | warning "Term contains a recursive datatype; countermodel(s) may be spurious!" | 
| 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
58893diff
changeset | 1028 | else () | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1029 | fun find_model_loop universe = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1030 | let | 
| 73387 | 1031 | val time_spent = Time.now () - time_start | 
| 1032 | val _ = maxtime = 0 orelse time_spent < Timeout.scale_time (Time.fromSeconds maxtime) | |
| 1033 | orelse raise Timeout.TIMEOUT time_spent | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1034 | val init_model = (universe, []) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1035 |             val init_args  = {maxvars = maxvars, def_eq = false, next_idx = 1,
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1036 | bounds = [], wellformed = True} | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1037 |             val _ = tracing ("Translating term (sizes: "
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1038 | ^ commas (map (fn (_, n) => string_of_int n) universe) ^ ") ...") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1039 | (* translate 'u' and all axioms *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1040 | val (intrs, (model, args)) = fold_map (fn t' => fn (m, a) => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1041 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1042 | val (i, m', a') = interpret ctxt m a t' | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1043 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1044 | (* set 'def_eq' to 'true' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1045 |                 (i, (m', {maxvars = #maxvars a', def_eq = true,
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1046 | next_idx = #next_idx a', bounds = #bounds a', | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1047 | wellformed = #wellformed a'})) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1048 | end) (u :: axioms) (init_model, init_args) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1049 | (* make 'u' either true or false, and make all axioms true, and *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1050 | (* add the well-formedness side condition *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1051 | val fm_u = (if negate then toFalse else toTrue) (hd intrs) | 
| 41471 | 1052 | val fm_ax = Prop_Logic.all (map toTrue (tl intrs)) | 
| 1053 | val fm = Prop_Logic.all [#wellformed args, fm_ax, fm_u] | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1054 | val _ = | 
| 67405 
e9ab4ad7bd15
uniform use of Standard ML op-infix -- eliminated warnings;
 wenzelm parents: 
67399diff
changeset | 1055 | (if member (op =) ["cdclite"] satsolver andalso Context_Position.is_visible ctxt then | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1056 |                 warning ("Using SAT solver " ^ quote satsolver ^
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1057 | "; for better performance, consider installing an \ | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1058 | \external solver.") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1059 | else ()); | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1060 | val solver = | 
| 56853 | 1061 | SAT_Solver.invoke_solver satsolver | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1062 | handle Option.Option => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1063 |                      error ("Unknown SAT solver: " ^ quote satsolver ^
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1064 | ". Available solvers: " ^ | 
| 56853 | 1065 | commas (map (quote o fst) (SAT_Solver.get_solvers ())) ^ ".") | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1066 | in | 
| 58843 | 1067 | writeln "Invoking SAT solver..."; | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1068 | (case solver fm of | 
| 56853 | 1069 | SAT_Solver.SATISFIABLE assignment => | 
| 58843 | 1070 |                 (writeln ("Model found:\n" ^ print_model ctxt model
 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1071 | (fn i => case assignment i of SOME b => b | NONE => true)); | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1072 | if maybe_spurious then "potential" else "genuine") | 
| 56853 | 1073 | | SAT_Solver.UNSATISFIABLE _ => | 
| 58843 | 1074 | (writeln "No model exists."; | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1075 | case next_universe universe sizes minsize maxsize of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1076 | SOME universe' => find_model_loop universe' | 
| 58843 | 1077 | | NONE => (writeln | 
| 40132 
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
 wenzelm parents: 
39811diff
changeset | 1078 | "Search terminated, no larger universe within the given limits."; | 
| 
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
 wenzelm parents: 
39811diff
changeset | 1079 | "none")) | 
| 56853 | 1080 | | SAT_Solver.UNKNOWN => | 
| 58843 | 1081 | (writeln "No model found."; | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1082 | case next_universe universe sizes minsize maxsize of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1083 | SOME universe' => find_model_loop universe' | 
| 58843 | 1084 | | NONE => (writeln | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1085 | "Search terminated, no larger universe within the given limits."; | 
| 56853 | 1086 | "unknown"))) handle SAT_Solver.NOT_CONFIGURED => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1087 |               (error ("SAT solver " ^ quote satsolver ^ " is not configured.");
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1088 | "unknown") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1089 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1090 | handle MAXVARS_EXCEEDED => | 
| 58843 | 1091 |             (writeln ("Search terminated, number of Boolean variables ("
 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1092 | ^ string_of_int maxvars ^ " allowed) exceeded."); | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1093 | "unknown") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1094 | |
| 30314 
853778f6ef7d
Added "expect" option to Refute, like in Nitpick, that allows to write regression tests.
 blanchet parents: 
30312diff
changeset | 1095 | 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 | 1096 | in | 
| 33054 
dd1192a96968
fixed the "expect" mechanism of Refute in the face of timeouts
 blanchet parents: 
32952diff
changeset | 1097 | check_expect outcome_code | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1098 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1099 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1100 | (* some parameter sanity checks *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1101 | minsize>=1 orelse | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1102 |       error ("\"minsize\" is " ^ string_of_int minsize ^ ", must be at least 1");
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1103 | maxsize>=1 orelse | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1104 |       error ("\"maxsize\" is " ^ string_of_int maxsize ^ ", must be at least 1");
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1105 | maxsize>=minsize orelse | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1106 |       error ("\"maxsize\" (=" ^ string_of_int maxsize ^
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1107 | ") is less than \"minsize\" (=" ^ string_of_int minsize ^ ")."); | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1108 | maxvars>=0 orelse | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1109 |       error ("\"maxvars\" is " ^ string_of_int maxvars ^ ", must be at least 0");
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1110 | maxtime>=0 orelse | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1111 |       error ("\"maxtime\" is " ^ string_of_int maxtime ^ ", must be at least 0");
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1112 | (* enter loop with or without time limit *) | 
| 58843 | 1113 |     writeln ("Trying to find a model that "
 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1114 | ^ (if negate then "refutes" else "satisfies") ^ ": " | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1115 | ^ Syntax.string_of_term ctxt t); | 
| 73387 | 1116 | Timeout.apply (Time.fromSeconds maxtime) | 
| 1117 | wrapper () | |
| 1118 | handle Timeout.TIMEOUT _ => | |
| 1119 |       (writeln ("Search terminated, time limit (" ^
 | |
| 1120 | string_of_int maxtime | |
| 1121 | ^ (if maxtime=1 then " second" else " seconds") ^ ") exceeded."); | |
| 1122 | check_expect "unknown") | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1123 | end; | 
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1124 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1125 | |
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1126 | (* ------------------------------------------------------------------------- *) | 
| 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1127 | (* INTERFACE, PART 2: FINDING A MODEL *) | 
| 14350 | 1128 | (* ------------------------------------------------------------------------- *) | 
| 1129 | ||
| 1130 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1131 | (* 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 | 1132 | (* 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 | 1133 | (* parameters *) | 
| 14350 | 1134 | (* ------------------------------------------------------------------------- *) | 
| 1135 | ||
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1136 | fun satisfy_term ctxt params assm_ts t = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1137 | find_model ctxt (actual_params ctxt params) assm_ts t false; | 
| 14350 | 1138 | |
| 1139 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 1140 | (* 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 | 1141 | (* 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 | 1142 | (* parameters *) | 
| 14350 | 1143 | (* ------------------------------------------------------------------------- *) | 
| 1144 | ||
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1145 | fun refute_term ctxt params assm_ts t = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1146 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1147 | (* 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 | 1148 | (* 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 | 1149 | (* 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 | 1150 | (* for ALL types, not ...) *) | 
| 29272 | 1151 | 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 | 1152 | error "Term to be refuted contains schematic type variables" | 
| 21556 | 1153 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1154 | (* existential closure over schematic variables *) | 
| 60924 
610794dff23c
tuned signature, in accordance to sortBy in Scala;
 wenzelm parents: 
60190diff
changeset | 1155 | val vars = sort_by (fst o fst) (Term.add_vars t []) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1156 | (* Term.term *) | 
| 33246 | 1157 | val ex_closure = fold (fn ((x, i), T) => fn t' => | 
| 1158 | HOLogic.exists_const T $ | |
| 1159 | Abs (x, T, abstract_over (Var ((x, i), T), t'))) vars t | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1160 | (* 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 | 1161 | (* '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 | 1162 | (* 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 | 1163 | (* resulting term correctly, without checking its type. *) | 
| 21556 | 1164 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1165 | (* 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 | 1166 | (* 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 | 1167 | (* 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 | 1168 | (* 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 | 1169 | (* 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 | 1170 | (* 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 | 1171 | (* quantified variables. *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1172 | (* maps !!x1...xn. !xk...xm. t to t *) | 
| 69593 | 1173 | fun strip_all_body (Const (\<^const_name>\<open>Pure.all\<close>, _) $ Abs (_, _, t)) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1174 | strip_all_body t | 
| 69593 | 1175 | | strip_all_body (Const (\<^const_name>\<open>Trueprop\<close>, _) $ t) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1176 | strip_all_body t | 
| 69593 | 1177 | | strip_all_body (Const (\<^const_name>\<open>All\<close>, _) $ Abs (_, _, t)) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1178 | strip_all_body t | 
| 29802 
d201a838d0f7
Make some Refute functions public so I can use them in Nitpick,
 blanchet parents: 
29288diff
changeset | 1179 | | 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 | 1180 | (* maps !!x1...xn. !xk...xm. t to [x1, ..., xn, xk, ..., xm] *) | 
| 69593 | 1181 | fun strip_all_vars (Const (\<^const_name>\<open>Pure.all\<close>, _) $ Abs (a, T, t)) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1182 | (a, T) :: strip_all_vars t | 
| 69593 | 1183 | | strip_all_vars (Const (\<^const_name>\<open>Trueprop\<close>, _) $ t) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1184 | strip_all_vars t | 
| 69593 | 1185 | | strip_all_vars (Const (\<^const_name>\<open>All\<close>, _) $ Abs (a, T, t)) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1186 | (a, T) :: strip_all_vars t | 
| 46096 | 1187 | | strip_all_vars _ = [] : (string * typ) list | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1188 | val strip_t = strip_all_body ex_closure | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1189 | val frees = Term.rename_wrt_term strip_t (strip_all_vars ex_closure) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1190 | 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 | 1191 | in | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1192 | find_model ctxt (actual_params ctxt params) assm_ts subst_t true | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1193 | end; | 
| 14350 | 1194 | |
| 1195 | (* ------------------------------------------------------------------------- *) | |
| 32857 
394d37f19e0a
Refute.refute_goal: canonical goal addresses from 1 (renamed from refute_subgoal to clarify change in semantics);
 wenzelm parents: 
31986diff
changeset | 1196 | (* refute_goal *) | 
| 14350 | 1197 | (* ------------------------------------------------------------------------- *) | 
| 1198 | ||
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1199 | fun refute_goal ctxt params th i = | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 1200 | let | 
| 59582 | 1201 | val t = th |> Thm.prop_of | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 1202 | in | 
| 74509 | 1203 | if Logic.no_prems t then | 
| 58843 | 1204 | (writeln "No subgoal!"; "none") | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 1205 | else | 
| 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 1206 | let | 
| 59582 | 1207 | val assms = map Thm.term_of (Assumption.all_assms_of ctxt) | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 1208 | val (t, frees) = Logic.goal_params t i | 
| 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 1209 | in | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1210 | refute_term ctxt params assms (subst_bounds (frees, t)) | 
| 34120 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 1211 | end | 
| 
f9920a3ddf50
added "no_assms" option to Refute, and include structured proof assumptions by default;
 blanchet parents: 
34017diff
changeset | 1212 | end | 
| 14350 | 1213 | |
| 1214 | ||
| 1215 | (* ------------------------------------------------------------------------- *) | |
| 15292 | 1216 | (* INTERPRETERS: Auxiliary Functions *) | 
| 14350 | 1217 | (* ------------------------------------------------------------------------- *) | 
| 1218 | ||
| 1219 | (* ------------------------------------------------------------------------- *) | |
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1220 | (* make_constants: returns all interpretations for type 'T' that consist of *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1221 | (* unit vectors with 'True'/'False' only (no Boolean *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1222 | (* variables) *) | 
| 14350 | 1223 | (* ------------------------------------------------------------------------- *) | 
| 1224 | ||
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1225 | fun make_constants ctxt model T = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1226 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1227 | (* 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 | 1228 | fun unit_vectors n = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1229 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1230 | (* returns the k-th unit vector of length n *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1231 | fun unit_vector (k, n) = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1232 | Leaf ((replicate (k-1) False) @ (True :: (replicate (n-k) False))) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1233 | fun unit_vectors_loop k = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1234 | if k>n then [] else unit_vector (k,n) :: unit_vectors_loop (k+1) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1235 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1236 | unit_vectors_loop 1 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1237 | end | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1238 | (* 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 | 1239 | (* identical) elements from 'xs' *) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1240 | fun pick_all 1 xs = map single xs | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1241 | | pick_all n xs = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1242 | let val rec_pick = pick_all (n - 1) xs in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1243 | maps (fn x => map (cons x) rec_pick) xs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1244 | end | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1245 | (* returns all constant interpretations that have the same tree *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1246 | (* structure as the interpretation argument *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1247 | fun make_constants_intr (Leaf xs) = unit_vectors (length xs) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1248 | | make_constants_intr (Node xs) = map Node (pick_all (length xs) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1249 | (make_constants_intr (hd xs))) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1250 | (* obtain the interpretation for a variable of type 'T' *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1251 |     val (i, _, _) = interpret ctxt model {maxvars=0, def_eq=false, next_idx=1,
 | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1252 |       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 | 1253 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1254 | make_constants_intr i | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1255 | 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 | 1256 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1257 | (* ------------------------------------------------------------------------- *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1258 | (* 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 | 1259 | (* (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 | 1260 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1261 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1262 | (* returns 0 for an empty ground type or a function type with empty *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1263 | (* codomain, but fails for a function type with empty domain -- *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1264 | (* admissibility of datatype constructor argument types (see "Inductive *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1265 | (* datatypes in HOL - lessons learned ...", S. Berghofer, M. Wenzel, *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1266 | (* TPHOLs 99) ensures that recursive, possibly empty, datatype fragments *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1267 | (* never occur as the domain of a function type that is the type of a *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1268 | (* constructor argument *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1269 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1270 | fun size_of_type ctxt model T = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1271 | let | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1272 | (* 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 | 1273 | (* given interpretation *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1274 | fun size_of_intr (Leaf xs) = length xs | 
| 39047 
cdff476ba39e
use existing Integer.pow, despite its slightly odd argument order;
 wenzelm parents: 
39046diff
changeset | 1275 | | size_of_intr (Node xs) = Integer.pow (length xs) (size_of_intr (hd xs)) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1276 | (* obtain the interpretation for a variable of type 'T' *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1277 |     val (i, _, _) = interpret ctxt model {maxvars=0, def_eq=false, next_idx=1,
 | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1278 |       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 | 1279 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1280 | size_of_intr i | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1281 | 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 | 1282 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1283 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1284 | (* 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 | 1285 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1286 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1287 | 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 | 1288 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1289 | 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 | 1290 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1291 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1292 | (* 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 | 1293 | (* 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 | 1294 | (* - 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 | 1295 | (* 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 | 1296 | (* - 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 | 1297 | (* 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 | 1298 | (* - 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 | 1299 | (* '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 | 1300 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1301 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1302 | (* We could in principle represent '=' on a type T by a particular *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1303 | (* interpretation. However, the size of that interpretation is quadratic *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1304 | (* in the size of T. Therefore comparing the interpretations 'i1' and *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1305 | (* 'i2' directly is more efficient than constructing the interpretation *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1306 | (* for equality on T first, and "applying" this interpretation to 'i1' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1307 | (* 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 | 1308 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1309 | fun make_equality (i1, i2) = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1310 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1311 | fun equal (i1, i2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1312 | (case i1 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1313 | Leaf xs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1314 | (case i2 of | 
| 41471 | 1315 | Leaf ys => Prop_Logic.dot_product (xs, ys) (* defined and equal *) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1316 |           | Node _  => raise REFUTE ("make_equality",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1317 | "second interpretation is higher")) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1318 | | Node xs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1319 | (case i2 of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1320 |             Leaf _  => raise REFUTE ("make_equality",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1321 | "first interpretation is higher") | 
| 41471 | 1322 | | Node ys => Prop_Logic.all (map equal (xs ~~ ys)))) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1323 | fun not_equal (i1, i2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1324 | (case i1 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1325 | Leaf xs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1326 | (case i2 of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1327 | (* defined and not equal *) | 
| 41471 | 1328 | Leaf ys => Prop_Logic.all ((Prop_Logic.exists xs) | 
| 1329 | :: (Prop_Logic.exists ys) | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1330 | :: (map (fn (x,y) => SOr (SNot x, SNot y)) (xs ~~ ys))) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1331 |           | Node _  => raise REFUTE ("make_equality",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1332 | "second interpretation is higher")) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1333 | | Node xs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1334 | (case i2 of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1335 |             Leaf _  => raise REFUTE ("make_equality",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1336 | "first interpretation is higher") | 
| 41471 | 1337 | | Node ys => Prop_Logic.exists (map not_equal (xs ~~ ys)))) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1338 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1339 | (* 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 | 1340 | (* negation of 'equal' *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1341 | 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 | 1342 | 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 | 1343 | |
| 15292 | 1344 | (* ------------------------------------------------------------------------- *) | 
| 15547 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1345 | (* 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 | 1346 | (* 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 | 1347 | (* 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 | 1348 | (* 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 | 1349 | (* 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 | 1350 | (* 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 | 1351 | (* ------------------------------------------------------------------------- *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1352 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1353 | fun make_def_equality (i1, i2) = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1354 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1355 | fun equal (i1, i2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1356 | (case i1 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1357 | Leaf xs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1358 | (case i2 of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1359 | (* defined and equal, or both undefined *) | 
| 41471 | 1360 | Leaf ys => SOr (Prop_Logic.dot_product (xs, ys), | 
| 1361 | SAnd (Prop_Logic.all (map SNot xs), Prop_Logic.all (map SNot ys))) | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1362 |           | Node _  => raise REFUTE ("make_def_equality",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1363 | "second interpretation is higher")) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1364 | | Node xs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1365 | (case i2 of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1366 |             Leaf _  => raise REFUTE ("make_def_equality",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1367 | "first interpretation is higher") | 
| 41471 | 1368 | | Node ys => Prop_Logic.all (map equal (xs ~~ ys)))) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1369 | val eq = equal (i1, i2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1370 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1371 | Leaf [eq, SNot eq] | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1372 | 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 | 1373 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1374 | (* ------------------------------------------------------------------------- *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1375 | (* interpretation_apply: returns an interpretation that denotes the result *) | 
| 22092 | 1376 | (* 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 | 1377 | (* 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 | 1378 | (* ------------------------------------------------------------------------- *) | 
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1379 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1380 | fun interpretation_apply (i1, i2) = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1381 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1382 | fun interpretation_disjunction (tr1,tr2) = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1383 | 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 | 1384 | (tree_pair (tr1,tr2)) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1385 | 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 | 1386 | 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 | 1387 | fun prop_formula_list_dot_product_interpretation_list ([fm],[tr]) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1388 | prop_formula_times_interpretation (fm,tr) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1389 | | prop_formula_list_dot_product_interpretation_list (fm::fms,tr::trees) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1390 | interpretation_disjunction (prop_formula_times_interpretation (fm,tr), | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1391 | prop_formula_list_dot_product_interpretation_list (fms,trees)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1392 | | prop_formula_list_dot_product_interpretation_list (_,_) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1393 |           raise REFUTE ("interpretation_apply", "empty list (in dot product)")
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1394 | (* 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 | 1395 | (* element of 'xss' *) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1396 | fun pick_all [xs] = map single xs | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1397 | | pick_all (xs::xss) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1398 | let val rec_pick = pick_all xss in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1399 | maps (fn x => map (cons x) rec_pick) xs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1400 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1401 |       | pick_all _ = raise REFUTE ("interpretation_apply", "empty list (in pick_all)")
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1402 | fun interpretation_to_prop_formula_list (Leaf xs) = xs | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1403 | | interpretation_to_prop_formula_list (Node trees) = | 
| 41471 | 1404 | map Prop_Logic.all (pick_all | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1405 | (map interpretation_to_prop_formula_list trees)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1406 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1407 | case i1 of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1408 | Leaf _ => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1409 |         raise REFUTE ("interpretation_apply", "first interpretation is a leaf")
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1410 | | Node xs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1411 | prop_formula_list_dot_product_interpretation_list | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1412 | (interpretation_to_prop_formula_list i2, xs) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1413 | 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 | 1414 | |
| 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1415 | (* ------------------------------------------------------------------------- *) | 
| 15292 | 1416 | (* eta_expand: eta-expands a term 't' by adding 'i' lambda abstractions *) | 
| 1417 | (* ------------------------------------------------------------------------- *) | |
| 1418 | ||
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1419 | fun eta_expand t i = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1420 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1421 | 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 | 1422 | 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 | 1423 | in | 
| 33339 | 1424 |     fold_rev (fn T => fn term => Abs ("<eta_expand>", T, term))
 | 
| 1425 | (List.take (Ts, i)) | |
| 1426 | (Term.list_comb (t', map Bound (i-1 downto 0))) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1427 | end; | 
| 15292 | 1428 | |
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1429 | (* ------------------------------------------------------------------------- *) | 
| 15547 
f08e2d83681e
major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
 webertj parents: 
15531diff
changeset | 1430 | (* 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 | 1431 | (* 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 | 1432 | (* their arguments) of the size of the argument types *) | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1433 | (* ------------------------------------------------------------------------- *) | 
| 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1434 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1435 | fun size_of_dtyp ctxt typ_sizes descr typ_assoc constructors = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1436 | Integer.sum (map (fn (_, dtyps) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1437 | Integer.prod (map (size_of_type ctxt (typ_sizes, []) o | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1438 | (typ_of_dtyp descr typ_assoc)) dtyps)) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1439 | constructors); | 
| 15335 
f81e6e24351f
minor code refactoring (typ_of_dtyp, size_of_dtyp)
 webertj parents: 
15334diff
changeset | 1440 | |
| 15292 | 1441 | |
| 1442 | (* ------------------------------------------------------------------------- *) | |
| 1443 | (* INTERPRETERS: Actual Interpreters *) | |
| 1444 | (* ------------------------------------------------------------------------- *) | |
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 1445 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1446 | (* simply typed lambda calculus: Isabelle's basic term syntax, with type *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1447 | (* 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 | 1448 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1449 | fun stlc_interpreter ctxt model args t = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1450 | let | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1451 | val (typs, terms) = model | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1452 |     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 | 1453 | fun interpret_groundterm T = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1454 | let | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1455 | fun interpret_groundtype () = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1456 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1457 | (* the model must specify a size for ground types *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1458 | val size = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1459 | if T = Term.propT then 2 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1460 | else the (AList.lookup (op =) typs T) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1461 | val next = next_idx + size | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1462 | (* check if 'maxvars' is large enough *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1463 | val _ = (if next - 1 > maxvars andalso maxvars > 0 then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1464 | raise MAXVARS_EXCEEDED else ()) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1465 | val fms = map BoolVar (next_idx upto (next_idx + size - 1)) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1466 | val intr = Leaf fms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1467 | fun one_of_two_false [] = True | 
| 41471 | 1468 | | one_of_two_false (x::xs) = SAnd (Prop_Logic.all (map (fn x' => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1469 | SOr (SNot x, SNot x')) xs), one_of_two_false xs) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1470 | val wf = one_of_two_false fms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1471 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1472 | (* extend the model, increase 'next_idx', add well-formedness *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1473 | (* condition *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1474 |             SOME (intr, (typs, (t, intr)::terms), {maxvars = maxvars,
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1475 | def_eq = def_eq, next_idx = next, bounds = bounds, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1476 | wellformed = SAnd (wellformed, wf)}) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1477 | end | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1478 | in | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1479 | case T of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1480 |           Type ("fun", [T1, T2]) =>
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1481 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1482 | (* we create 'size_of_type ... T1' different copies of the *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1483 | (* interpretation for 'T2', which are then combined into a single *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1484 | (* new interpretation *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1485 | (* make fresh copies, with different variable indices *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1486 | (* 'idx': next variable index *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1487 | (* 'n' : number of copies *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1488 | fun make_copies idx 0 = (idx, [], True) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1489 | | make_copies idx n = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1490 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1491 | val (copy, _, new_args) = interpret ctxt (typs, []) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1492 |                         {maxvars = maxvars, def_eq = false, next_idx = idx,
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1493 |                         bounds = [], wellformed = True} (Free ("dummy", T2))
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1494 | val (idx', copies, wf') = make_copies (#next_idx new_args) (n-1) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1495 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1496 | (idx', copy :: copies, SAnd (#wellformed new_args, wf')) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1497 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1498 | val (next, copies, wf) = make_copies next_idx | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1499 | (size_of_type ctxt model T1) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1500 | (* combine copies into a single interpretation *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1501 | val intr = Node copies | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1502 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1503 | (* extend the model, increase 'next_idx', add well-formedness *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1504 | (* condition *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1505 |               SOME (intr, (typs, (t, intr)::terms), {maxvars = maxvars,
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1506 | def_eq = def_eq, next_idx = next, bounds = bounds, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1507 | wellformed = SAnd (wellformed, wf)}) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1508 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1509 | | Type _ => interpret_groundtype () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1510 | | TFree _ => interpret_groundtype () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1511 | | TVar _ => interpret_groundtype () | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1512 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1513 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1514 | 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 | 1515 | SOME intr => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1516 | (* return an existing interpretation *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1517 | SOME (intr, model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1518 | | NONE => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1519 | (case t of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1520 | Const (_, T) => interpret_groundterm T | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1521 | | Free (_, T) => interpret_groundterm T | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1522 | | Var (_, T) => interpret_groundterm T | 
| 42364 | 1523 | | Bound i => SOME (nth (#bounds args) i, model, args) | 
| 46096 | 1524 | | Abs (_, T, body) => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1525 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1526 | (* create all constants of type 'T' *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1527 | val constants = make_constants ctxt model T | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1528 | (* interpret the 'body' separately for each constant *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1529 | val (bodies, (model', args')) = fold_map | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1530 | (fn c => fn (m, a) => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1531 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1532 | (* add 'c' to 'bounds' *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1533 |                     val (i', m', a') = interpret ctxt m {maxvars = #maxvars a,
 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1534 | def_eq = #def_eq a, next_idx = #next_idx a, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1535 | bounds = (c :: #bounds a), wellformed = #wellformed a} body | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1536 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1537 | (* keep the new model m' and 'next_idx' and 'wellformed', *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1538 | (* but use old 'bounds' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1539 |                     (i', (m', {maxvars = maxvars, def_eq = def_eq,
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1540 | next_idx = #next_idx a', bounds = bounds, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1541 | wellformed = #wellformed a'})) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1542 | end) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1543 | constants (model, args) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1544 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1545 | SOME (Node bodies, model', args') | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1546 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1547 | | t1 $ t2 => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1548 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1549 | (* interpret 't1' and 't2' separately *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1550 | val (intr1, model1, args1) = interpret ctxt model args t1 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1551 | val (intr2, model2, args2) = interpret ctxt model1 args1 t2 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1552 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1553 | SOME (interpretation_apply (intr1, intr2), model2, args2) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1554 | end) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1555 | 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 | 1556 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1557 | fun Pure_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1558 | case t of | 
| 69593 | 1559 | Const (\<^const_name>\<open>Pure.all\<close>, _) $ t1 => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1560 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1561 | val (i, m, a) = interpret ctxt model args t1 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1562 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1563 | case i of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1564 | Node xs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1565 | (* 3-valued logic *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1566 | let | 
| 41471 | 1567 | val fmTrue = Prop_Logic.all (map toTrue xs) | 
| 1568 | val fmFalse = Prop_Logic.exists (map toFalse xs) | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1569 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1570 | SOME (Leaf [fmTrue, fmFalse], m, a) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1571 | end | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1572 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1573 |           raise REFUTE ("Pure_interpreter",
 | 
| 56245 | 1574 | "\"Pure.all\" is followed by a non-function") | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1575 | end | 
| 69593 | 1576 | | Const (\<^const_name>\<open>Pure.all\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1577 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 69593 | 1578 | | Const (\<^const_name>\<open>Pure.eq\<close>, _) $ t1 $ t2 => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1579 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1580 | val (i1, m1, a1) = interpret ctxt model args t1 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1581 | val (i2, m2, a2) = interpret ctxt m1 a1 t2 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1582 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1583 | (* 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 | 1584 | 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 | 1585 | (i1, i2), m2, a2) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1586 | end | 
| 69593 | 1587 | | Const (\<^const_name>\<open>Pure.eq\<close>, _) $ _ => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1588 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 69593 | 1589 | | Const (\<^const_name>\<open>Pure.eq\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1590 | SOME (interpret ctxt model args (eta_expand t 2)) | 
| 69593 | 1591 | | Const (\<^const_name>\<open>Pure.imp\<close>, _) $ t1 $ t2 => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1592 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1593 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1594 | val (i1, m1, a1) = interpret ctxt model args t1 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1595 | val (i2, m2, a2) = interpret ctxt m1 a1 t2 | 
| 41471 | 1596 | val fmTrue = Prop_Logic.SOr (toFalse i1, toTrue i2) | 
| 1597 | val fmFalse = Prop_Logic.SAnd (toTrue i1, toFalse i2) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1598 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1599 | 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 | 1600 | end | 
| 69593 | 1601 | | Const (\<^const_name>\<open>Pure.imp\<close>, _) $ _ => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1602 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 69593 | 1603 | | Const (\<^const_name>\<open>Pure.imp\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1604 | SOME (interpret ctxt model args (eta_expand t 2)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1605 | | _ => 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 | 1606 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1607 | fun HOLogic_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1608 | (* Providing interpretations directly is more efficient than unfolding the *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1609 | (* logical constants. In HOL however, logical constants can themselves be *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1610 | (* arguments. They are then translated using eta-expansion. *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1611 | case t of | 
| 69593 | 1612 | Const (\<^const_name>\<open>Trueprop\<close>, _) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1613 | SOME (Node [TT, FF], model, args) | 
| 69593 | 1614 | | Const (\<^const_name>\<open>Not\<close>, _) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1615 | SOME (Node [FF, TT], model, args) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1616 | (* redundant, since 'True' is also an IDT constructor *) | 
| 69593 | 1617 | | Const (\<^const_name>\<open>True\<close>, _) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1618 | SOME (TT, model, args) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1619 | (* redundant, since 'False' is also an IDT constructor *) | 
| 69593 | 1620 | | Const (\<^const_name>\<open>False\<close>, _) => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1621 | SOME (FF, model, args) | 
| 69593 | 1622 | | Const (\<^const_name>\<open>All\<close>, _) $ t1 => (* similar to "Pure.all" *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1623 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1624 | val (i, m, a) = interpret ctxt model args t1 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1625 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1626 | case i of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1627 | Node xs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1628 | (* 3-valued logic *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1629 | let | 
| 41471 | 1630 | val fmTrue = Prop_Logic.all (map toTrue xs) | 
| 1631 | val fmFalse = Prop_Logic.exists (map toFalse xs) | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1632 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1633 | SOME (Leaf [fmTrue, fmFalse], m, a) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1634 | end | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1635 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1636 |           raise REFUTE ("HOLogic_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1637 | "\"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 | 1638 | end | 
| 69593 | 1639 | | Const (\<^const_name>\<open>All\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1640 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 69593 | 1641 | | Const (\<^const_name>\<open>Ex\<close>, _) $ t1 => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1642 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1643 | val (i, m, a) = interpret ctxt model args t1 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1644 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1645 | case i of | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1646 | Node xs => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1647 | (* 3-valued logic *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1648 | let | 
| 41471 | 1649 | val fmTrue = Prop_Logic.exists (map toTrue xs) | 
| 1650 | val fmFalse = Prop_Logic.all (map toFalse xs) | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1651 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1652 | SOME (Leaf [fmTrue, fmFalse], m, a) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1653 | end | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1654 | | _ => | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1655 |           raise REFUTE ("HOLogic_interpreter",
 | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1656 | "\"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 | 1657 | end | 
| 69593 | 1658 | | Const (\<^const_name>\<open>Ex\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1659 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 69593 | 1660 | | Const (\<^const_name>\<open>HOL.eq\<close>, _) $ t1 $ t2 => (* similar to Pure.eq *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1661 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1662 | val (i1, m1, a1) = interpret ctxt model args t1 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1663 | val (i2, m2, a2) = interpret ctxt m1 a1 t2 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1664 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1665 | 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 | 1666 | end | 
| 69593 | 1667 | | Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1668 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 69593 | 1669 | | Const (\<^const_name>\<open>HOL.eq\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1670 | SOME (interpret ctxt model args (eta_expand t 2)) | 
| 69593 | 1671 | | Const (\<^const_name>\<open>HOL.conj\<close>, _) $ t1 $ t2 => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1672 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1673 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1674 | val (i1, m1, a1) = interpret ctxt model args t1 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1675 | val (i2, m2, a2) = interpret ctxt m1 a1 t2 | 
| 41471 | 1676 | val fmTrue = Prop_Logic.SAnd (toTrue i1, toTrue i2) | 
| 1677 | val fmFalse = Prop_Logic.SOr (toFalse i1, toFalse i2) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1678 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1679 | 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 | 1680 | end | 
| 69593 | 1681 | | Const (\<^const_name>\<open>HOL.conj\<close>, _) $ _ => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1682 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 69593 | 1683 | | Const (\<^const_name>\<open>HOL.conj\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1684 | SOME (interpret ctxt model args (eta_expand t 2)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1685 | (* 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 | 1686 | (* "False & undef": *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1687 | (* SOME (Node [Node [TT, FF], Node [FF, FF]], model, args) *) | 
| 69593 | 1688 | | Const (\<^const_name>\<open>HOL.disj\<close>, _) $ t1 $ t2 => | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1689 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1690 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1691 | val (i1, m1, a1) = interpret ctxt model args t1 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1692 | val (i2, m2, a2) = interpret ctxt m1 a1 t2 | 
| 41471 | 1693 | val fmTrue = Prop_Logic.SOr (toTrue i1, toTrue i2) | 
| 1694 | val fmFalse = Prop_Logic.SAnd (toFalse i1, toFalse i2) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1695 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1696 | 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 | 1697 | end | 
| 69593 | 1698 | | Const (\<^const_name>\<open>HOL.disj\<close>, _) $ _ => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1699 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 69593 | 1700 | | Const (\<^const_name>\<open>HOL.disj\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1701 | SOME (interpret ctxt model args (eta_expand t 2)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1702 | (* 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 | 1703 | (* "True | undef": *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1704 | (* SOME (Node [Node [TT, TT], Node [TT, FF]], model, args) *) | 
| 69593 | 1705 | | Const (\<^const_name>\<open>HOL.implies\<close>, _) $ t1 $ t2 => (* similar to Pure.imp *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1706 | (* 3-valued logic *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1707 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1708 | val (i1, m1, a1) = interpret ctxt model args t1 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1709 | val (i2, m2, a2) = interpret ctxt m1 a1 t2 | 
| 41471 | 1710 | val fmTrue = Prop_Logic.SOr (toFalse i1, toTrue i2) | 
| 1711 | val fmFalse = Prop_Logic.SAnd (toTrue i1, toFalse i2) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1712 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1713 | 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 | 1714 | end | 
| 69593 | 1715 | | Const (\<^const_name>\<open>HOL.implies\<close>, _) $ _ => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1716 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 69593 | 1717 | | Const (\<^const_name>\<open>HOL.implies\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1718 | SOME (interpret ctxt model args (eta_expand t 2)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1719 | (* 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 | 1720 | (* "False --> undef": *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1721 | (* SOME (Node [Node [TT, FF], Node [TT, TT]], model, args) *) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1722 | | _ => 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 | 1723 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1724 | (* interprets variables and constants whose type is an IDT (this is *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1725 | (* relatively easy and merely requires us to compute the size of the IDT); *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1726 | (* constructors of IDTs however are properly interpreted by *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1727 | (* '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 | 1728 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1729 | fun IDT_interpreter ctxt model args t = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1730 | let | 
| 42361 | 1731 | val thy = Proof_Context.theory_of ctxt | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1732 | val (typs, terms) = model | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1733 | fun interpret_term (Type (s, Ts)) = | 
| 58354 
04ac60da613e
support (finite values of) codatatypes in Quickcheck
 blanchet parents: 
58322diff
changeset | 1734 | (case BNF_LFP_Compat.get_info thy [] s of | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1735 | SOME info => (* inductive datatype *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1736 | let | 
| 55507 
5f27fb2110e0
removed odd comments -- inferred types are shown by Prover IDE;
 wenzelm parents: 
55411diff
changeset | 1737 | (* only recursive IDTs have an associated depth *) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1738 | val depth = AList.lookup (op =) typs (Type (s, Ts)) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1739 | (* sanity check: depth must be at least 0 *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1740 | val _ = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1741 | (case depth of SOME n => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1742 | if n < 0 then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1743 |                       raise REFUTE ("IDT_interpreter", "negative depth")
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1744 | else () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1745 | | _ => ()) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1746 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1747 | (* termination condition to avoid infinite recursion *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1748 | if depth = (SOME 0) then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1749 | (* return a leaf of size 0 *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1750 | SOME (Leaf [], model, args) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1751 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1752 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1753 | val index = #index info | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1754 | val descr = #descr info | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1755 | val (_, dtyps, constrs) = the (AList.lookup (op =) descr index) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1756 | val typ_assoc = dtyps ~~ Ts | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1757 | (* sanity check: every element in 'dtyps' must be a 'DtTFree' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1758 | val _ = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1759 | if Library.exists (fn d => | 
| 58120 | 1760 | case d of Old_Datatype_Aux.DtTFree _ => false | _ => true) dtyps | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1761 | then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1762 |                         raise REFUTE ("IDT_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1763 | "datatype argument (for type " | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1764 | ^ Syntax.string_of_typ ctxt (Type (s, Ts)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1765 | ^ ") is not a variable") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1766 | else () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1767 | (* if the model specifies a depth for the current type, *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1768 | (* decrement it to avoid infinite recursion *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1769 | val typs' = case depth of NONE => typs | SOME n => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1770 | AList.update (op =) (Type (s, Ts), n-1) typs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1771 | (* recursively compute the size of the datatype *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1772 | val size = size_of_dtyp ctxt typs' descr typ_assoc constrs | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1773 | val next_idx = #next_idx args | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1774 | val next = next_idx+size | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1775 | (* check if 'maxvars' is large enough *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1776 | val _ = (if next-1 > #maxvars args andalso | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1777 | #maxvars args > 0 then raise MAXVARS_EXCEEDED else ()) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1778 | val fms = map BoolVar (next_idx upto (next_idx+size-1)) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1779 | val intr = Leaf fms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1780 | fun one_of_two_false [] = True | 
| 41471 | 1781 | | one_of_two_false (x::xs) = SAnd (Prop_Logic.all (map (fn x' => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1782 | SOr (SNot x, SNot x')) xs), one_of_two_false xs) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1783 | val wf = one_of_two_false fms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1784 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1785 | (* extend the model, increase 'next_idx', add well-formedness *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1786 | (* condition *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1787 |                     SOME (intr, (typs, (t, intr)::terms), {maxvars = #maxvars args,
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1788 | def_eq = #def_eq args, next_idx = next, bounds = #bounds args, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1789 | wellformed = SAnd (#wellformed args, wf)}) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1790 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1791 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1792 | | NONE => (* not an inductive datatype *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1793 | NONE) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1794 | | interpret_term _ = (* a (free or schematic) type variable *) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1795 | NONE | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1796 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1797 | 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 | 1798 | SOME intr => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1799 | (* return an existing interpretation *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1800 | SOME (intr, model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1801 | | NONE => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1802 | (case t of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1803 | Free (_, T) => interpret_term T | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1804 | | Var (_, T) => interpret_term T | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1805 | | Const (_, T) => interpret_term T | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1806 | | _ => NONE) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1807 | 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 | 1808 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1809 | (* This function imposes an order on the elements of a datatype fragment *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1810 | (* as follows: C_i x_1 ... x_n < C_j y_1 ... y_m iff i < j or *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1811 | (* (x_1, ..., x_n) < (y_1, ..., y_m). With this order, a constructor is *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1812 | (* a function C_i that maps some argument indices x_1, ..., x_n to the *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1813 | (* datatype element given by index C_i x_1 ... x_n. The idea remains the *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1814 | (* same for recursive datatypes, although the computation of indices gets *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1815 | (* a little tricky. *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1816 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1817 | fun IDT_constructor_interpreter ctxt model args t = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1818 | let | 
| 42361 | 1819 | val thy = Proof_Context.theory_of ctxt | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1820 | (* 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 | 1821 | (* 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 | 1822 | (* for IDTs calls 'IDT_constructor_interpreter' again, and this could *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1823 | (* lead to infinite recursion when we have (mutually) recursive IDTs. *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1824 | fun canonical_terms typs T = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1825 | (case T of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1826 |             Type ("fun", [T1, T2]) =>
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1827 | (* 'T2' might contain a recursive IDT, so we cannot use 'print' (at *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1828 | (* least not for 'T2' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1829 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1830 | (* returns a list of lists, each one consisting of n (possibly *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1831 | (* identical) elements from 'xs' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1832 | fun pick_all 1 xs = map single xs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1833 | | pick_all n xs = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1834 | let val rec_pick = pick_all (n-1) xs in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1835 | maps (fn x => map (cons x) rec_pick) xs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1836 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1837 | (* ["x1", ..., "xn"] *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1838 | val terms1 = canonical_terms typs T1 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1839 | (* ["y1", ..., "ym"] *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1840 | val terms2 = canonical_terms typs T2 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1841 |               (* [[("x1", "y1"), ..., ("xn", "y1")], ..., *)
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1842 |               (*   [("x1", "ym"), ..., ("xn", "ym")]]     *)
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1843 | val functions = map (curry (op ~~) terms1) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1844 | (pick_all (length terms1) terms2) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1845 | (* [["(x1, y1)", ..., "(xn, y1)"], ..., *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1846 | (* ["(x1, ym)", ..., "(xn, ym)"]] *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1847 | val pairss = map (map HOLogic.mk_prod) functions | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1848 | val HOLogic_prodT = HOLogic.mk_prodT (T1, T2) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1849 | val HOLogic_setT = HOLogic.mk_setT HOLogic_prodT | 
| 69593 | 1850 | val HOLogic_empty_set = Const (\<^const_abbrev>\<open>Set.empty\<close>, HOLogic_setT) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1851 | val HOLogic_insert = | 
| 69593 | 1852 | Const (\<^const_name>\<open>insert\<close>, HOLogic_prodT --> HOLogic_setT --> HOLogic_setT) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1853 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1854 | (* functions as graphs, i.e. as a (HOL) set of pairs "(x, y)" *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1855 | map (fn ps => fold_rev (fn pair => fn acc => HOLogic_insert $ pair $ acc) ps | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1856 | HOLogic_empty_set) pairss | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1857 | end | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1858 | | Type (s, Ts) => | 
| 58354 
04ac60da613e
support (finite values of) codatatypes in Quickcheck
 blanchet parents: 
58322diff
changeset | 1859 | (case BNF_LFP_Compat.get_info thy [] s of | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1860 | SOME info => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1861 | (case AList.lookup (op =) typs T of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1862 | SOME 0 => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1863 | (* termination condition to avoid infinite recursion *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1864 | [] (* at depth 0, every IDT is empty *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1865 | | _ => | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1866 | let | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1867 | val index = #index info | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1868 | val descr = #descr info | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1869 | val (_, dtyps, constrs) = the (AList.lookup (op =) descr index) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1870 | val typ_assoc = dtyps ~~ Ts | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1871 | (* sanity check: every element in 'dtyps' must be a 'DtTFree' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1872 | val _ = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1873 | if Library.exists (fn d => | 
| 58120 | 1874 | case d of Old_Datatype_Aux.DtTFree _ => false | _ => true) dtyps | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1875 | then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1876 |                       raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1877 | "datatype argument (for type " | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1878 | ^ Syntax.string_of_typ ctxt T | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1879 | ^ ") is not a variable") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1880 | else () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1881 | (* decrement depth for the IDT 'T' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1882 | val typs' = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1883 | (case AList.lookup (op =) typs T of NONE => typs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1884 | | SOME n => AList.update (op =) (T, n-1) typs) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1885 | fun constructor_terms terms [] = terms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1886 | | constructor_terms terms (d::ds) = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1887 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1888 | val dT = typ_of_dtyp descr typ_assoc d | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1889 | val d_terms = canonical_terms typs' dT | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1890 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1891 | (* C_i x_1 ... x_n < C_i y_1 ... y_n if *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1892 | (* (x_1, ..., x_n) < (y_1, ..., y_n) *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1893 | constructor_terms | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1894 | (map_product (curry op $) terms d_terms) ds | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1895 | end | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1896 | in | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1897 | (* C_i ... < C_j ... if i < j *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1898 | maps (fn (cname, ctyps) => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1899 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1900 | val cTerm = Const (cname, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1901 | map (typ_of_dtyp descr typ_assoc) ctyps ---> T) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1902 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1903 | constructor_terms [cTerm] ctyps | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1904 | end) constrs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1905 | end) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1906 | | NONE => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1907 | (* not an inductive datatype; in this case the argument types in *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1908 | (* 'Ts' may not be IDTs either, so 'print' should be safe *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1909 | map (fn intr => print ctxt (typs, []) T intr (K false)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1910 | (make_constants ctxt (typs, []) T)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1911 | | _ => (* TFree ..., TVar ... *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1912 | map (fn intr => print ctxt (typs, []) T intr (K false)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1913 | (make_constants ctxt (typs, []) T)) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1914 | val (typs, terms) = model | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1915 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1916 | 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 | 1917 | SOME intr => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1918 | (* return an existing interpretation *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1919 | SOME (intr, model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1920 | | NONE => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1921 | (case t of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1922 | Const (s, T) => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1923 | (case body_type T of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1924 | Type (s', Ts') => | 
| 58354 
04ac60da613e
support (finite values of) codatatypes in Quickcheck
 blanchet parents: 
58322diff
changeset | 1925 | (case BNF_LFP_Compat.get_info thy [] s' of | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1926 | SOME info => (* body type is an inductive datatype *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1927 | let | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1928 | val index = #index info | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1929 | val descr = #descr info | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1930 | val (_, dtyps, constrs) = the (AList.lookup (op =) descr index) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1931 | val typ_assoc = dtyps ~~ Ts' | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1932 | (* sanity check: every element in 'dtyps' must be a 'DtTFree' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1933 | val _ = if Library.exists (fn d => | 
| 58120 | 1934 | case d of Old_Datatype_Aux.DtTFree _ => false | _ => true) dtyps | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1935 | then | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 1936 |                           raise REFUTE ("IDT_constructor_interpreter",
 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1937 | "datatype argument (for type " | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1938 | ^ Syntax.string_of_typ ctxt (Type (s', Ts')) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1939 | ^ ") is not a variable") | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 1940 | else () | 
| 58322 | 1941 | (* split the constructors into those occurring before/after *) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1942 | (* 'Const (s, T)' *) | 
| 67522 | 1943 | val (constrs1, constrs2) = chop_prefix (fn (cname, ctypes) => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1944 | not (cname = s andalso Sign.typ_instance thy (T, | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1945 | map (typ_of_dtyp descr typ_assoc) ctypes | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1946 | ---> Type (s', Ts')))) constrs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1947 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1948 | case constrs2 of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1949 | [] => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1950 | (* 'Const (s, T)' is not a constructor of this datatype *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1951 | NONE | 
| 46096 | 1952 | | (_, ctypes)::_ => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1953 | let | 
| 55507 
5f27fb2110e0
removed odd comments -- inferred types are shown by Prover IDE;
 wenzelm parents: 
55411diff
changeset | 1954 | (* only /recursive/ IDTs have an associated depth *) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1955 | val depth = AList.lookup (op =) typs (Type (s', Ts')) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1956 | (* this should never happen: at depth 0, this IDT fragment *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1957 | (* is definitely empty, and in this case we don't need to *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1958 | (* interpret its constructors *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1959 | val _ = (case depth of SOME 0 => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1960 |                                 raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1961 | "depth is 0") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1962 | | _ => ()) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1963 | val typs' = (case depth of NONE => typs | SOME n => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1964 | AList.update (op =) (Type (s', Ts'), n-1) typs) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1965 | (* elements of the datatype come before elements generated *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1966 | (* by 'Const (s, T)' iff they are generated by a *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1967 | (* constructor in constrs1 *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1968 | val offset = size_of_dtyp ctxt typs' descr typ_assoc constrs1 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1969 | (* compute the total (current) size of the datatype *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1970 | val total = offset + | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1971 | size_of_dtyp ctxt typs' descr typ_assoc constrs2 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1972 | (* sanity check *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1973 | val _ = if total <> size_of_type ctxt (typs, []) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1974 | (Type (s', Ts')) then | 
| 33246 | 1975 |                                 raise REFUTE ("IDT_constructor_interpreter",
 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1976 | "total is not equal to current size") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1977 | else () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1978 | (* returns an interpretation where everything is mapped to *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1979 | (* an "undefined" element of the datatype *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1980 | fun make_undef [] = Leaf (replicate total False) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1981 | | make_undef (d::ds) = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1982 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1983 | (* compute the current size of the type 'd' *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1984 | val dT = typ_of_dtyp descr typ_assoc d | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 1985 | val size = size_of_type ctxt (typs, []) dT | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1986 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1987 | Node (replicate size (make_undef ds)) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1988 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1989 | (* returns the interpretation for a constructor *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1990 | fun make_constr [] offset = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1991 | if offset < total then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1992 | (Leaf (replicate offset False @ True :: | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1993 | (replicate (total - offset - 1) False)), offset + 1) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1994 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1995 |                                     raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1996 | "offset >= total") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1997 | | make_constr (d::ds) offset = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1998 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 1999 | val dT = typ_of_dtyp descr typ_assoc d | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2000 | (* compute canonical term representations for all *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2001 | (* elements of the type 'd' (with the reduced depth *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2002 | (* for the IDT) *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2003 | val terms' = canonical_terms typs' dT | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2004 | (* sanity check *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2005 | val _ = | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2006 | if length terms' <> size_of_type ctxt (typs', []) dT | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2007 | then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2008 |                                         raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2009 | "length of terms' is not equal to old size") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2010 | else () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2011 | (* compute canonical term representations for all *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2012 | (* elements of the type 'd' (with the current depth *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2013 | (* for the IDT) *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2014 | val terms = canonical_terms typs dT | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2015 | (* sanity check *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2016 | val _ = | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2017 | if length terms <> size_of_type ctxt (typs, []) dT | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2018 | then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2019 |                                         raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2020 | "length of terms is not equal to current size") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2021 | else () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2022 | (* sanity check *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2023 | val _ = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2024 | if length terms < length terms' then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2025 |                                         raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2026 | "current size is less than old size") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2027 | else () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2028 | (* sanity check: every element of terms' must also be *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2029 | (* present in terms *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2030 | val _ = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2031 | if forall (member (op =) terms) terms' then () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2032 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2033 |                                         raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2034 | "element has disappeared") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2035 | (* sanity check: the order on elements of terms' is *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2036 | (* the same in terms, for those elements *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2037 | val _ = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2038 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2039 | fun search (x::xs) (y::ys) = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2040 | if x = y then search xs ys else search (x::xs) ys | 
| 46096 | 2041 | | search (_::_) [] = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2042 |                                               raise REFUTE ("IDT_constructor_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2043 | "element order not preserved") | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2044 | | search [] _ = () | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2045 | in search terms' terms end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2046 | val (intrs, new_offset) = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2047 | fold_map (fn t_elem => fn off => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2048 | (* if 't_elem' existed at the previous depth, *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2049 | (* proceed recursively, otherwise map the entire *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2050 | (* subtree to "undefined" *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2051 | if member (op =) terms' t_elem then | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2052 | make_constr ds off | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2053 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2054 | (make_undef ds, off)) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2055 | terms offset | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2056 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2057 | (Node intrs, new_offset) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2058 | end | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2059 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2060 | SOME (fst (make_constr ctypes offset), model, args) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2061 | end | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2062 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2063 | | NONE => (* body type is not an inductive datatype *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2064 | NONE) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2065 | | _ => (* body type is a (free or schematic) type variable *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2066 | NONE) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2067 | | _ => (* term is not a constant *) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2068 | NONE) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2069 | 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 | 2070 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2071 | (* Difficult code ahead. Make sure you understand the *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2072 | (* 'IDT_constructor_interpreter' and the order in which it enumerates *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2073 | (* 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 | 2074 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2075 | fun IDT_recursion_interpreter ctxt model args t = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2076 | let | 
| 42361 | 2077 | val thy = Proof_Context.theory_of ctxt | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2078 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2079 | (* careful: here we descend arbitrarily deep into 't', possibly before *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2080 | (* any other interpreter for atomic terms has had a chance to look at *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2081 | (* 't' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2082 | case strip_comb t of | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2083 | (Const (s, T), params) => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2084 | (* iterate over all datatypes in 'thy' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2085 | Symtab.fold (fn (_, info) => fn result => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2086 | case result of | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2087 | SOME _ => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2088 | result (* just keep 'result' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2089 | | NONE => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2090 | if member (op =) (#rec_names info) s then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2091 | (* we do have a recursion operator of one of the (mutually *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2092 | (* recursive) datatypes given by 'info' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2093 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2094 | (* number of all constructors, including those of different *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2095 | (* (mutually recursive) datatypes within the same descriptor *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2096 | val mconstrs_count = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2097 | Integer.sum (map (fn (_, (_, _, cs)) => length cs) (#descr info)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2098 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2099 | if mconstrs_count < length params then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2100 | (* too many actual parameters; for now we'll use the *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2101 | (* 'stlc_interpreter' to strip off one application *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2102 | NONE | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2103 | else if mconstrs_count > length params then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2104 | (* too few actual parameters; we use eta expansion *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2105 | (* Note that the resulting expansion of lambda abstractions *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2106 | (* by the 'stlc_interpreter' may be rather slow (depending *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2107 | (* on the argument types and the size of the IDT, of *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2108 | (* course). *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2109 | SOME (interpret ctxt model args (eta_expand t | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2110 | (mconstrs_count - length params))) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2111 | else (* mconstrs_count = length params *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2112 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2113 | (* interpret each parameter separately *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2114 | val (p_intrs, (model', args')) = fold_map (fn p => fn (m, a) => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2115 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2116 | val (i, m', a') = interpret ctxt m a p | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2117 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2118 | (i, (m', a')) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2119 | end) params (model, args) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2120 | val (typs, _) = model' | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2121 | (* 'index' is /not/ necessarily the index of the IDT that *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2122 | (* the recursion operator is associated with, but merely *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2123 | (* the index of some mutually recursive IDT *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2124 | val index = #index info | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2125 | val descr = #descr info | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2126 | val (_, dtyps, _) = the (AList.lookup (op =) descr index) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2127 | (* sanity check: we assume that the order of constructors *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2128 | (* in 'descr' is the same as the order of *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2129 | (* corresponding parameters, otherwise the *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2130 | (* association code below won't match the *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2131 | (* right constructors/parameters; we also *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2132 | (* assume that the order of recursion *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2133 | (* operators in '#rec_names info' is the *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2134 | (* same as the order of corresponding *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2135 | (* datatypes in 'descr' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2136 | val _ = if map fst descr <> (0 upto (length descr - 1)) then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2137 |                           raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2138 | "order of constructors and corresponding parameters/" ^ | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2139 | "recursion operators and corresponding datatypes " ^ | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2140 | "different?") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2141 | else () | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2142 | (* sanity check: every element in 'dtyps' must be a *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2143 | (* 'DtTFree' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2144 | val _ = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2145 | if Library.exists (fn d => | 
| 58120 | 2146 | case d of Old_Datatype_Aux.DtTFree _ => false | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2147 | | _ => true) dtyps | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2148 | then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2149 |                           raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2150 | "datatype argument is not a variable") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2151 | else () | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2152 | (* the type of a recursion operator is *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2153 | (* [T1, ..., Tn, IDT] ---> Tresult *) | 
| 42364 | 2154 | val IDT = nth (binder_types T) mconstrs_count | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2155 | (* by our assumption on the order of recursion operators *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2156 | (* and datatypes, this is the index of the datatype *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2157 | (* corresponding to the given recursion operator *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2158 | val idt_index = find_index (fn s' => s' = s) (#rec_names info) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2159 | (* mutually recursive types must have the same type *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2160 | (* parameters, unless the mutual recursion comes from *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2161 | (* indirect recursion *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2162 | fun rec_typ_assoc acc [] = acc | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2163 | | rec_typ_assoc acc ((d, T)::xs) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2164 | (case AList.lookup op= acc d of | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2165 | NONE => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2166 | (case d of | 
| 58120 | 2167 | Old_Datatype_Aux.DtTFree _ => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2168 | (* add the association, proceed *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2169 | rec_typ_assoc ((d, T)::acc) xs | 
| 58120 | 2170 | | Old_Datatype_Aux.DtType (s, ds) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2171 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2172 | val (s', Ts) = dest_Type T | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2173 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2174 | if s=s' then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2175 | rec_typ_assoc ((d, T)::acc) ((ds ~~ Ts) @ xs) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2176 | else | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2177 |                                         raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2178 | "DtType/Type mismatch") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2179 | end | 
| 58120 | 2180 | | Old_Datatype_Aux.DtRec i => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2181 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2182 | val (_, ds, _) = the (AList.lookup (op =) descr i) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2183 | val (_, Ts) = dest_Type T | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2184 | in | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2185 | rec_typ_assoc ((d, T)::acc) ((ds ~~ Ts) @ xs) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2186 | end) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2187 | | SOME T' => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2188 | if T=T' then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2189 | (* ignore the association since it's already *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2190 | (* present, proceed *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2191 | rec_typ_assoc acc xs | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2192 | else | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2193 |                                   raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2194 | "different type associations for the same dtyp")) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2195 | val typ_assoc = filter | 
| 58120 | 2196 | (fn (Old_Datatype_Aux.DtTFree _, _) => true | (_, _) => false) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2197 | (rec_typ_assoc [] | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2198 | (#2 (the (AList.lookup (op =) descr idt_index)) ~~ (snd o dest_Type) IDT)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2199 | (* sanity check: typ_assoc must associate types to the *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2200 | (* elements of 'dtyps' (and only to those) *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2201 | val _ = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2202 | if not (eq_set (op =) (dtyps, map fst typ_assoc)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2203 | then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2204 |                           raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2205 | "type association has extra/missing elements") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2206 | else () | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2207 | (* interpret each constructor in the descriptor (including *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2208 | (* those of mutually recursive datatypes) *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2209 | (* (int * interpretation list) list *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2210 | val mc_intrs = map (fn (idx, (_, _, cs)) => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2211 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2212 | val c_return_typ = typ_of_dtyp descr typ_assoc | 
| 58120 | 2213 | (Old_Datatype_Aux.DtRec idx) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2214 | in | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2215 | (idx, map (fn (cname, cargs) => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2216 |                             (#1 o interpret ctxt (typs, []) {maxvars=0,
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2217 | def_eq=false, next_idx=1, bounds=[], | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2218 | wellformed=True}) (Const (cname, map (typ_of_dtyp | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2219 | descr typ_assoc) cargs ---> c_return_typ))) cs) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2220 | end) descr | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2221 | (* associate constructors with corresponding parameters *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2222 | (* (int * (interpretation * interpretation) list) list *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2223 | val (mc_p_intrs, p_intrs') = fold_map | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2224 | (fn (idx, c_intrs) => fn p_intrs' => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2225 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2226 | val len = length c_intrs | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2227 | in | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2228 | ((idx, c_intrs ~~ List.take (p_intrs', len)), | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2229 | List.drop (p_intrs', len)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2230 | end) mc_intrs p_intrs | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2231 | (* sanity check: no 'p_intr' may be left afterwards *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2232 | val _ = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2233 | if p_intrs' <> [] then | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2234 |                           raise REFUTE ("IDT_recursion_interpreter",
 | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2235 | "more parameter than constructor interpretations") | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2236 | else () | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2237 | (* The recursion operator, applied to 'mconstrs_count' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2238 | (* arguments, is a function that maps every element of the *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2239 | (* inductive datatype to an element of some result type. *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2240 | (* Recursion operators for mutually recursive IDTs are *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2241 | (* translated simultaneously. *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2242 | (* Since the order on datatype elements is given by an *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2243 | (* order on constructors (and then by the order on *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2244 | (* argument tuples), we can simply copy corresponding *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2245 | (* subtrees from 'p_intrs', in the order in which they are *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2246 | (* given. *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2247 | fun ci_pi (Leaf xs, pi) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2248 | (* if the constructor does not match the arguments to a *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2249 | (* defined element of the IDT, the corresponding value *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2250 | (* of the parameter must be ignored *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2251 | if List.exists (equal True) xs then [pi] else [] | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2252 | | ci_pi (Node xs, Node ys) = maps ci_pi (xs ~~ ys) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2253 | | ci_pi (Node _, Leaf _) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2254 |                             raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2255 | "constructor takes more arguments than the " ^ | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2256 | "associated parameter") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2257 | val rec_operators = map (fn (idx, c_p_intrs) => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2258 | (idx, maps ci_pi c_p_intrs)) mc_p_intrs | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2259 | (* sanity check: every recursion operator must provide as *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2260 | (* many values as the corresponding datatype *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2261 | (* has elements *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2262 | val _ = map (fn (idx, intrs) => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2263 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2264 | val T = typ_of_dtyp descr typ_assoc | 
| 58120 | 2265 | (Old_Datatype_Aux.DtRec idx) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2266 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2267 | if length intrs <> size_of_type ctxt (typs, []) T then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2268 |                             raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2269 | "wrong number of interpretations for rec. operator") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2270 | else () | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2271 | end) rec_operators | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2272 | (* For non-recursive datatypes, we are pretty much done at *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2273 | (* this point. For recursive datatypes however, we still *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2274 | (* need to apply the interpretations in 'rec_operators' to *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2275 | (* (recursively obtained) interpretations for recursive *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2276 | (* constructor arguments. To do so more efficiently, we *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2277 | (* copy 'rec_operators' into arrays first. Each Boolean *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2278 | (* indicates whether the recursive arguments have been *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2279 | (* considered already. *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2280 | val REC_OPERATORS = map (fn (idx, intrs) => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2281 | (idx, Array.fromList (map (pair false) intrs))) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2282 | rec_operators | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2283 | (* takes an interpretation, and if some leaf of this *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2284 | (* interpretation is the 'elem'-th element of the type, *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2285 | (* the indices of the arguments leading to this leaf are *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2286 | (* returned *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2287 | fun get_args (Leaf xs) elem = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2288 | if find_index (fn x => x = True) xs = elem then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2289 | SOME [] | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2290 | else | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2291 | NONE | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2292 | | get_args (Node xs) elem = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2293 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2294 | fun search ([], _) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2295 | NONE | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2296 | | search (x::xs, n) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2297 | (case get_args x elem of | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2298 | SOME result => SOME (n::result) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2299 | | NONE => search (xs, n+1)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2300 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2301 | search (xs, 0) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2302 | end | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2303 | (* returns the index of the constructor and indices for *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2304 | (* its arguments that generate the 'elem'-th element of *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2305 | (* the datatype given by 'idx' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2306 | fun get_cargs idx elem = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2307 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2308 | fun get_cargs_rec (_, []) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2309 |                                 raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2310 | "no matching constructor found for datatype element") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2311 | | get_cargs_rec (n, x::xs) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2312 | (case get_args x elem of | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2313 | SOME args => (n, args) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2314 | | NONE => get_cargs_rec (n+1, xs)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2315 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2316 | get_cargs_rec (0, the (AList.lookup (op =) mc_intrs idx)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2317 | end | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2318 | (* computes one entry in 'REC_OPERATORS', and recursively *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2319 | (* all entries needed for it, where 'idx' gives the *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2320 | (* datatype and 'elem' the element of it *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2321 | fun compute_array_entry idx elem = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2322 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2323 | val arr = the (AList.lookup (op =) REC_OPERATORS idx) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2324 | val (flag, intr) = Array.sub (arr, elem) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2325 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2326 | if flag then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2327 | (* simply return the previously computed result *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2328 | intr | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2329 | else | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2330 | (* we have to apply 'intr' to interpretations for all *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2331 | (* recursive arguments *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2332 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2333 | val (c, args) = get_cargs idx elem | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2334 | (* find the indices of the constructor's /recursive/ *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2335 | (* arguments *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2336 | val (_, _, constrs) = the (AList.lookup (op =) descr idx) | 
| 42364 | 2337 | val (_, dtyps) = nth constrs c | 
| 2338 | val rec_dtyps_args = filter | |
| 58120 | 2339 | (Old_Datatype_Aux.is_rec_type o fst) (dtyps ~~ args) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2340 | (* map those indices to interpretations *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2341 | val rec_dtyps_intrs = map (fn (dtyp, arg) => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2342 | let | 
| 42364 | 2343 | val dT = typ_of_dtyp descr typ_assoc dtyp | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2344 | val consts = make_constants ctxt (typs, []) dT | 
| 42364 | 2345 | val arg_i = nth consts arg | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2346 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2347 | (dtyp, arg_i) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2348 | end) rec_dtyps_args | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2349 | (* takes the dtyp and interpretation of an element, *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2350 | (* and computes the interpretation for the *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2351 | (* corresponding recursive argument *) | 
| 58120 | 2352 | fun rec_intr (Old_Datatype_Aux.DtRec i) (Leaf xs) = | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2353 | (* recursive argument is "rec_i params elem" *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2354 | compute_array_entry i (find_index (fn x => x = True) xs) | 
| 58120 | 2355 | | rec_intr (Old_Datatype_Aux.DtRec _) (Node _) = | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2356 |                                     raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2357 | "interpretation for IDT is a node") | 
| 58120 | 2358 |                                 | rec_intr (Old_Datatype_Aux.DtType ("fun", [_, dt2])) (Node xs) =
 | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2359 | (* recursive argument is something like *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2360 | (* "\<lambda>x::dt1. rec_? params (elem x)" *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2361 | Node (map (rec_intr dt2) xs) | 
| 58120 | 2362 |                                 | rec_intr (Old_Datatype_Aux.DtType ("fun", [_, _])) (Leaf _) =
 | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2363 |                                     raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2364 | "interpretation for function dtyp is a leaf") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2365 | | rec_intr _ _ = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2366 | (* admissibility ensures that every recursive type *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2367 | (* is of the form 'Dt_1 -> ... -> Dt_k -> *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2368 | (* (DtRec i)' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2369 |                                     raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2370 | "non-recursive codomain in recursive dtyp") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2371 | (* obtain interpretations for recursive arguments *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2372 | (* interpretation list *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2373 | val arg_intrs = map (uncurry rec_intr) rec_dtyps_intrs | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2374 | (* apply 'intr' to all recursive arguments *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2375 | val result = fold (fn arg_i => fn i => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2376 | interpretation_apply (i, arg_i)) arg_intrs intr | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2377 | (* update 'REC_OPERATORS' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2378 | val _ = Array.update (arr, elem, (true, result)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2379 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2380 | result | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2381 | end | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2382 | end | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2383 | val idt_size = Array.length (the (AList.lookup (op =) REC_OPERATORS idt_index)) | 
| 56846 
9df717fef2bb
renamed 'xxx_size' to 'size_xxx' for old datatype package
 blanchet parents: 
56845diff
changeset | 2384 | (* sanity check: the size of 'IDT' should be 'size_idt' *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2385 | val _ = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2386 | if idt_size <> size_of_type ctxt (typs, []) IDT then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2387 |                             raise REFUTE ("IDT_recursion_interpreter",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2388 | "unexpected size of IDT (wrong type associated?)") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2389 | else () | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2390 | val rec_op = Node (map_range (compute_array_entry idt_index) idt_size) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2391 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2392 | SOME (rec_op, model', args') | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2393 | end | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2394 | end | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2395 | else | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2396 | NONE (* not a recursion operator of this datatype *) | 
| 58354 
04ac60da613e
support (finite values of) codatatypes in Quickcheck
 blanchet parents: 
58322diff
changeset | 2397 | ) (BNF_LFP_Compat.get_all thy []) NONE | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2398 | | _ => (* head of term is not a constant *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2399 | NONE | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2400 | 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 | 2401 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2402 | fun set_interpreter ctxt model args t = | 
| 29956 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2403 | let | 
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2404 | val (typs, terms) = model | 
| 29956 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2405 | in | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2406 | case AList.lookup (op =) terms t of | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2407 | SOME intr => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2408 | (* return an existing interpretation *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2409 | SOME (intr, model, args) | 
| 29956 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2410 | | NONE => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2411 | (case t of | 
| 69593 | 2412 | Free (x, Type (\<^type_name>\<open>set\<close>, [T])) => | 
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2413 | let | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2414 | val (intr, _, args') = | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2415 | interpret ctxt (typs, []) args (Free (x, T --> HOLogic.boolT)) | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2416 | in | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2417 | SOME (intr, (typs, (t, intr)::terms), args') | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2418 | end | 
| 69593 | 2419 | | Var ((x, i), Type (\<^type_name>\<open>set\<close>, [T])) => | 
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2420 | let | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2421 | val (intr, _, args') = | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2422 | interpret ctxt (typs, []) args (Var ((x,i), T --> HOLogic.boolT)) | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2423 | in | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2424 | SOME (intr, (typs, (t, intr)::terms), args') | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2425 | end | 
| 69593 | 2426 | | Const (s, Type (\<^type_name>\<open>set\<close>, [T])) => | 
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2427 | let | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2428 | val (intr, _, args') = | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2429 | interpret ctxt (typs, []) args (Const (s, T --> HOLogic.boolT)) | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2430 | in | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2431 | SOME (intr, (typs, (t, intr)::terms), args') | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2432 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2433 | (* 'Collect' == identity *) | 
| 69593 | 2434 | | Const (\<^const_name>\<open>Collect\<close>, _) $ t1 => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2435 | SOME (interpret ctxt model args t1) | 
| 69593 | 2436 | | Const (\<^const_name>\<open>Collect\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2437 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2438 | (* 'op :' == application *) | 
| 69593 | 2439 | | Const (\<^const_name>\<open>Set.member\<close>, _) $ t1 $ t2 => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2440 | SOME (interpret ctxt model args (t2 $ t1)) | 
| 69593 | 2441 | | Const (\<^const_name>\<open>Set.member\<close>, _) $ _ => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2442 | SOME (interpret ctxt model args (eta_expand t 1)) | 
| 69593 | 2443 | | Const (\<^const_name>\<open>Set.member\<close>, _) => | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2444 | SOME (interpret ctxt model args (eta_expand t 2)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2445 | | _ => NONE) | 
| 29956 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2446 | end; | 
| 
62f931b257b7
Reintroduce set_interpreter for Collect and op :.
 blanchet parents: 
29820diff
changeset | 2447 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2448 | (* only an optimization: 'card' could in principle be interpreted with *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2449 | (* interpreters available already (using its definition), but the code *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2450 | (* 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 | 2451 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2452 | fun Finite_Set_card_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2453 | case t of | 
| 69593 | 2454 | Const (\<^const_name>\<open>Finite_Set.card\<close>, | 
| 2455 |         Type ("fun", [Type (\<^type_name>\<open>set\<close>, [T]), \<^typ>\<open>nat\<close>])) =>
 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2456 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2457 | fun number_of_elements (Node xs) = | 
| 33246 | 2458 | fold (fn x => fn n => | 
| 2459 | if x = TT then | |
| 2460 | n + 1 | |
| 2461 | else if x = FF then | |
| 2462 | n | |
| 2463 | else | |
| 2464 |                 raise REFUTE ("Finite_Set_card_interpreter",
 | |
| 2465 | "interpretation for set type does not yield a Boolean")) | |
| 2466 | xs 0 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2467 | | number_of_elements (Leaf _) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2468 |               raise REFUTE ("Finite_Set_card_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2469 | "interpretation for set type is a leaf") | 
| 69593 | 2470 | val size_of_nat = size_of_type ctxt model (\<^typ>\<open>nat\<close>) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2471 | (* takes an interpretation for a set and returns an interpretation *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2472 | (* 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 | 2473 | fun card i = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2474 | let | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2475 | 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 | 2476 | in | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2477 | 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 | 2478 | Leaf ((replicate n False) @ True :: | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2479 | (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 | 2480 | else | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2481 | 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 | 2482 | end | 
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2483 | val set_constants = make_constants ctxt model (HOLogic.mk_setT T) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2484 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2485 | 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 | 2486 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2487 | | _ => 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 | 2488 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2489 | (* only an optimization: 'finite' could in principle be interpreted with *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2490 | (* interpreters available already (using its definition), but the code *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2491 | (* below is more efficient *) | 
| 22093 | 2492 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2493 | fun Finite_Set_finite_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2494 | case t of | 
| 69593 | 2495 | Const (\<^const_name>\<open>Finite_Set.finite\<close>, | 
| 2496 |            Type ("fun", [_, \<^typ>\<open>bool\<close>])) $ _ =>
 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2497 | (* 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 | 2498 | (* "finite" *) | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2499 | SOME (TT, model, args) | 
| 69593 | 2500 | | Const (\<^const_name>\<open>Finite_Set.finite\<close>, | 
| 2501 |            Type ("fun", [set_T, \<^typ>\<open>bool\<close>])) =>
 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2502 | let | 
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2503 | val size_of_set = size_of_type ctxt model set_T | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2504 | in | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2505 | (* 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 | 2506 | (* "finite" *) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2507 | 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 | 2508 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2509 | | _ => NONE; | 
| 22093 | 2510 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2511 | (* only an optimization: 'less' could in principle be interpreted with *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2512 | (* interpreters available already (using its definition), but the code *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2513 | (* 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 | 2514 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2515 | fun Nat_less_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2516 | case t of | 
| 69593 | 2517 |     Const (\<^const_name>\<open>Orderings.less\<close>, Type ("fun", [\<^typ>\<open>nat\<close>,
 | 
| 2518 |         Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>bool\<close>])])) =>
 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2519 | let | 
| 69593 | 2520 | val size_of_nat = size_of_type ctxt model (\<^typ>\<open>nat\<close>) | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2521 | (* 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 | 2522 | (* is less than the remaining 'size_of_nat - n' nats *) | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2523 | 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 | 2524 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2525 | 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 | 2526 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2527 | | _ => 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 | 2528 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2529 | (* only an optimization: 'plus' could in principle be interpreted with *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2530 | (* interpreters available already (using its definition), but the code *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2531 | (* 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 | 2532 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2533 | fun Nat_plus_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2534 | case t of | 
| 69593 | 2535 |     Const (\<^const_name>\<open>Groups.plus\<close>, Type ("fun", [\<^typ>\<open>nat\<close>,
 | 
| 2536 |         Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>nat\<close>])])) =>
 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2537 | let | 
| 69593 | 2538 | val size_of_nat = size_of_type ctxt model (\<^typ>\<open>nat\<close>) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2539 | fun plus m n = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2540 | let | 
| 25032 | 2541 | val element = m + n | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2542 | in | 
| 25032 | 2543 | if element > size_of_nat - 1 then | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2544 | 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 | 2545 | else | 
| 25032 | 2546 | Leaf ((replicate element False) @ True :: | 
| 2547 | (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 | 2548 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2549 | in | 
| 33063 | 2550 | SOME (Node (map_range (fn m => Node (map_range (plus m) size_of_nat)) size_of_nat), | 
| 2551 | model, args) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2552 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2553 | | _ => 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 | 2554 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2555 | (* only an optimization: 'minus' could in principle be interpreted *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2556 | (* with interpreters available already (using its definition), but the *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2557 | (* 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 | 2558 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2559 | fun Nat_minus_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2560 | case t of | 
| 69593 | 2561 |     Const (\<^const_name>\<open>Groups.minus\<close>, Type ("fun", [\<^typ>\<open>nat\<close>,
 | 
| 2562 |         Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>nat\<close>])])) =>
 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2563 | let | 
| 69593 | 2564 | val size_of_nat = size_of_type ctxt model (\<^typ>\<open>nat\<close>) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2565 | fun minus m n = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2566 | let | 
| 25032 | 2567 | 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 | 2568 | in | 
| 25032 | 2569 | Leaf ((replicate element False) @ True :: | 
| 2570 | (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 | 2571 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2572 | in | 
| 33063 | 2573 | SOME (Node (map_range (fn m => Node (map_range (minus m) size_of_nat)) size_of_nat), | 
| 2574 | model, args) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2575 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2576 | | _ => 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 | 2577 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2578 | (* only an optimization: 'times' could in principle be interpreted *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2579 | (* with interpreters available already (using its definition), but the *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2580 | (* 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 | 2581 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2582 | fun Nat_times_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2583 | case t of | 
| 69593 | 2584 |     Const (\<^const_name>\<open>Groups.times\<close>, Type ("fun", [\<^typ>\<open>nat\<close>,
 | 
| 2585 |         Type ("fun", [\<^typ>\<open>nat\<close>, \<^typ>\<open>nat\<close>])])) =>
 | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2586 | let | 
| 69593 | 2587 | val size_of_nat = size_of_type ctxt model (\<^typ>\<open>nat\<close>) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2588 | fun mult m n = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2589 | let | 
| 25032 | 2590 | val element = m * n | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2591 | in | 
| 25032 | 2592 | if element > size_of_nat - 1 then | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2593 | 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 | 2594 | else | 
| 25032 | 2595 | Leaf ((replicate element False) @ True :: | 
| 2596 | (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 | 2597 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2598 | in | 
| 33063 | 2599 | SOME (Node (map_range (fn m => Node (map_range (mult m) size_of_nat)) size_of_nat), | 
| 2600 | model, args) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2601 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2602 | | _ => 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 | 2603 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2604 | (* only an optimization: 'append' could in principle be interpreted with *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2605 | (* interpreters available already (using its definition), but the code *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2606 | (* below is more efficient *) | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2607 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2608 | fun List_append_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2609 | case t of | 
| 69593 | 2610 | Const (\<^const_name>\<open>append\<close>, | 
| 2611 | Type (\<^type_name>\<open>fun\<close>, [Type (\<^type_name>\<open>list\<close>, [T]), | |
| 2612 | Type (\<^type_name>\<open>fun\<close>, [Type (\<^type_name>\<open>list\<close>, [_]), Type (\<^type_name>\<open>list\<close>, [_])])])) => | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2613 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2614 | val size_elem = size_of_type ctxt model T | 
| 69593 | 2615 | val size_list = size_of_type ctxt model (Type (\<^type_name>\<open>list\<close>, [T])) | 
| 25032 | 2616 | (* maximal length of lists; 0 if we only consider the empty list *) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2617 | val list_length = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2618 | let | 
| 25032 | 2619 | fun list_length_acc len lists total = | 
| 2620 | if lists = total then | |
| 2621 | len | |
| 2622 | else if lists < total then | |
| 2623 | list_length_acc (len+1) (lists*size_elem) (total-lists) | |
| 2624 | else | |
| 2625 |                 raise REFUTE ("List_append_interpreter",
 | |
| 2626 | "size_list not equal to 1 + size_elem + ... + " ^ | |
| 2627 | "size_elem^len, for some len") | |
| 2628 | in | |
| 2629 | list_length_acc 0 1 size_list | |
| 2630 | end | |
| 2631 | val elements = 0 upto (size_list-1) | |
| 2632 | (* FIXME: there should be a nice formula, which computes the same as *) | |
| 2633 | (* the following, but without all this intermediate tree *) | |
| 2634 | (* length/offset stuff *) | |
| 2635 | (* associate each list with its length and offset in a complete tree *) | |
| 2636 | (* of width 'size_elem' and depth 'length_list' (with 'size_list' *) | |
| 2637 | (* nodes total) *) | |
| 2638 | (* (int * (int * int)) list *) | |
| 33246 | 2639 | val (lenoff_lists, _) = fold_map (fn elem => fn (offsets, off) => | 
| 25032 | 2640 | (* 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 | 2641 | let | 
| 25032 | 2642 | val len = length offsets | 
| 2643 | (* associate the given element with len/off *) | |
| 2644 | 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 | 2645 | in | 
| 25032 | 2646 | if len < list_length then | 
| 2647 | (* go to first child node *) | |
| 33246 | 2648 | (assoc, (off :: offsets, off * size_elem)) | 
| 25032 | 2649 | else if off mod size_elem < size_elem - 1 then | 
| 2650 | (* go to next sibling node *) | |
| 33246 | 2651 | (assoc, (offsets, off + 1)) | 
| 25032 | 2652 | else | 
| 2653 | (* go back up the stack until we find a level where we can go *) | |
| 2654 | (* to the next sibling node *) | |
| 2655 | let | |
| 67522 | 2656 | val offsets' = drop_prefix (fn off' => off' mod size_elem = size_elem - 1) offsets | 
| 25032 | 2657 | in | 
| 2658 | case offsets' of | |
| 2659 | [] => | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2660 | (* we're at the last node in the tree; the next value *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2661 | (* won't be used anyway *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2662 | (assoc, ([], 0)) | 
| 25032 | 2663 | | off'::offs' => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2664 | (* go to next sibling node *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2665 | (assoc, (offs', off' + 1)) | 
| 25032 | 2666 | end | 
| 33246 | 2667 | end) elements ([], 0) | 
| 25032 | 2668 | (* we also need the reverse association (from length/offset to *) | 
| 2669 | (* index) *) | |
| 2670 | val lenoff'_lists = map Library.swap lenoff_lists | |
| 2671 | (* 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 | 2672 | fun append m n = | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2673 | let | 
| 29288 | 2674 | val (len_m, off_m) = the (AList.lookup (op =) lenoff_lists m) | 
| 2675 | val (len_n, off_n) = the (AList.lookup (op =) lenoff_lists n) | |
| 25032 | 2676 | val len_elem = len_m + len_n | 
| 39047 
cdff476ba39e
use existing Integer.pow, despite its slightly odd argument order;
 wenzelm parents: 
39046diff
changeset | 2677 | val off_elem = off_m * Integer.pow len_n size_elem + off_n | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2678 | in | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2679 | case AList.lookup op= lenoff'_lists (len_elem, off_elem) of | 
| 25032 | 2680 | NONE => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2681 | (* undefined *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2682 | Leaf (replicate size_list False) | 
| 25032 | 2683 | | SOME element => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2684 | Leaf ((replicate element False) @ True :: | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2685 | (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 | 2686 | end | 
| 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2687 | in | 
| 25032 | 2688 | SOME (Node (map (fn m => Node (map (append m) elements)) elements), | 
| 2689 | model, args) | |
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2690 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2691 | | _ => NONE; | 
| 15767 
8ed9fcc004fe
support for recursion over mutually recursive IDTs
 webertj parents: 
15611diff
changeset | 2692 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2693 | (* only an optimization: 'fst' could in principle be interpreted with *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2694 | (* interpreters available already (using its definition), but the code *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2695 | (* below is more efficient *) | 
| 21267 | 2696 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2697 | fun Product_Type_fst_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2698 | case t of | 
| 69593 | 2699 |     Const (\<^const_name>\<open>fst\<close>, Type ("fun", [Type (\<^type_name>\<open>Product_Type.prod\<close>, [T, U]), _])) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2700 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2701 | val constants_T = make_constants ctxt model T | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2702 | val size_U = size_of_type ctxt model U | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2703 | in | 
| 32952 | 2704 | SOME (Node (maps (replicate size_U) constants_T), model, args) | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2705 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2706 | | _ => NONE; | 
| 21267 | 2707 | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2708 | (* only an optimization: 'snd' could in principle be interpreted with *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2709 | (* interpreters available already (using its definition), but the code *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2710 | (* below is more efficient *) | 
| 21267 | 2711 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2712 | fun Product_Type_snd_interpreter ctxt model args t = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2713 | case t of | 
| 69593 | 2714 |     Const (\<^const_name>\<open>snd\<close>, Type ("fun", [Type (\<^type_name>\<open>Product_Type.prod\<close>, [T, U]), _])) =>
 | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2715 | let | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2716 | val size_T = size_of_type ctxt model T | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2717 | val constants_U = make_constants ctxt model U | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2718 | in | 
| 32952 | 2719 | SOME (Node (flat (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 | 2720 | end | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2721 | | _ => NONE; | 
| 21267 | 2722 | |
| 14807 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2723 | |
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2724 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2725 | (* 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 | 2726 | (* ------------------------------------------------------------------------- *) | 
| 
e8ccb13d7774
major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
 webertj parents: 
14604diff
changeset | 2727 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2728 | fun stlc_printer ctxt model T intr assignment = | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2729 | let | 
| 40720 | 2730 | val strip_leading_quote = perhaps (try (unprefix "'")) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2731 | fun string_of_typ (Type (s, _)) = s | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2732 | | string_of_typ (TFree (x, _)) = strip_leading_quote x | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2733 | | string_of_typ (TVar ((x,i), _)) = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2734 | strip_leading_quote x ^ string_of_int i | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2735 | fun index_from_interpretation (Leaf xs) = | 
| 41471 | 2736 | find_index (Prop_Logic.eval assignment) xs | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2737 | | index_from_interpretation _ = | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2738 |           raise REFUTE ("stlc_printer",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2739 | "interpretation for ground type is not a leaf") | 
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22093diff
changeset | 2740 | in | 
| 25014 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2741 | case T of | 
| 
b711b0af178e
significant code overhaul, bugfix for inductive data types
 webertj parents: 
24928diff
changeset | 2742 |       Type ("fun", [T1, T2]) =>
 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2743 | let | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2744 | (* create all constants of type 'T1' *) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2745 | val constants = make_constants ctxt model T1 | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2746 | val results = | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2747 | (case intr of | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2748 | Node xs => xs | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2749 |             | _ => raise REFUTE ("stlc_printer",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2750 | "interpretation for function type is a leaf")) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2751 | (* Term.term list *) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2752 | val pairs = map (fn (arg, result) => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2753 | HOLogic.mk_prod | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2754 | (print ctxt model T1 arg assignment, | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2755 | print ctxt model T2 result assignment)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2756 | (constants ~~ results) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2757 | val HOLogic_prodT = HOLogic.mk_prodT (T1, T2) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2758 | val HOLogic_setT = HOLogic.mk_setT HOLogic_prodT | 
| 69593 | 2759 | val HOLogic_empty_set = Const (\<^const_abbrev>\<open>Set.empty\<close>, HOLogic_setT) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2760 | val HOLogic_insert = | 
| 69593 | 2761 | Const (\<^const_name>\<open>insert\<close>, HOLogic_prodT --> HOLogic_setT --> HOLogic_setT) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2762 | in | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2763 | SOME (fold_rev (fn pair => fn acc => HOLogic_insert $ pair $ acc) pairs HOLogic_empty_set) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2764 | end | 
| 69593 | 2765 | | Type (\<^type_name>\<open>prop\<close>, []) => | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2766 | (case index_from_interpretation intr of | 
| 69593 | 2767 | ~1 => SOME (HOLogic.mk_Trueprop (Const (\<^const_name>\<open>undefined\<close>, HOLogic.boolT))) | 
| 2768 | | 0 => SOME (HOLogic.mk_Trueprop \<^term>\<open>True\<close>) | |
| 2769 | | 1 => SOME (HOLogic.mk_Trueprop \<^term>\<open>False\<close>) | |
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2770 |         | _  => raise REFUTE ("stlc_interpreter",
 | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2771 | "illegal interpretation for a propositional value")) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2772 | | Type _ => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2773 | if index_from_interpretation intr = (~1) then | 
| 69593 | 2774 | SOME (Const (\<^const_name>\<open>undefined\<close>, T)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2775 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2776 | SOME (Const (string_of_typ T ^ | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2777 | string_of_int (index_from_interpretation intr), T)) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2778 | | TFree _ => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2779 | if index_from_interpretation intr = (~1) then | 
| 69593 | 2780 | SOME (Const (\<^const_name>\<open>undefined\<close>, T)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2781 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2782 | SOME (Const (string_of_typ T ^ | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2783 | string_of_int (index_from_interpretation intr), T)) | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2784 | | TVar _ => | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2785 | if index_from_interpretation intr = (~1) then | 
| 69593 | 2786 | SOME (Const (\<^const_name>\<open>undefined\<close>, T)) | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2787 | else | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2788 | SOME (Const (string_of_typ T ^ | 
| 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2789 | 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 | 2790 | end; | 
| 14350 | 2791 | |
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2792 | fun set_printer ctxt model T intr assignment = | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2793 | (case T of | 
| 69593 | 2794 | Type (\<^type_name>\<open>set\<close>, [T1]) => | 
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2795 | let | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2796 | (* create all constants of type 'T1' *) | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2797 | val constants = make_constants ctxt model T1 | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2798 | val results = (case intr of | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2799 | Node xs => xs | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2800 |         | _       => raise REFUTE ("set_printer",
 | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2801 | "interpretation for set type is a leaf")) | 
| 57820 | 2802 | val elements = map_filter (fn (arg, result) => | 
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2803 | case result of | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2804 | Leaf [fmTrue, (* fmFalse *) _] => | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2805 | if Prop_Logic.eval assignment fmTrue then | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2806 | SOME (print ctxt model T1 arg assignment) | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2807 | else (* if Prop_Logic.eval assignment fmFalse then *) | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2808 | NONE | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2809 | | _ => | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2810 |           raise REFUTE ("set_printer",
 | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2811 | "illegal interpretation for a Boolean value")) | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2812 | (constants ~~ results) | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2813 | val HOLogic_setT1 = HOLogic.mk_setT T1 | 
| 69593 | 2814 | val HOLogic_empty_set = Const (\<^const_abbrev>\<open>Set.empty\<close>, HOLogic_setT1) | 
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2815 | val HOLogic_insert = | 
| 69593 | 2816 | Const (\<^const_name>\<open>insert\<close>, T1 --> HOLogic_setT1 --> HOLogic_setT1) | 
| 46098 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2817 | in | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2818 | SOME (Library.foldl (fn (acc, elem) => HOLogic_insert $ elem $ acc) | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2819 | (HOLogic_empty_set, elements)) | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2820 | end | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2821 | | _ => | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2822 | NONE); | 
| 
ce939621a1fe
handle "set" correctly in Refute -- inspired by old code from Isabelle2007
 blanchet parents: 
46096diff
changeset | 2823 | |
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2824 | fun IDT_printer ctxt model T intr assignment = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2825 | let | 
| 42361 | 2826 | val thy = Proof_Context.theory_of ctxt | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2827 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2828 | (case T of | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2829 | Type (s, Ts) => | 
| 58354 
04ac60da613e
support (finite values of) codatatypes in Quickcheck
 blanchet parents: 
58322diff
changeset | 2830 | (case BNF_LFP_Compat.get_info thy [] s of | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2831 | SOME info => (* inductive datatype *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2832 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2833 | val (typs, _) = model | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2834 | val index = #index info | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2835 | val descr = #descr info | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2836 | val (_, dtyps, constrs) = the (AList.lookup (op =) descr index) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2837 | val typ_assoc = dtyps ~~ Ts | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2838 | (* sanity check: every element in 'dtyps' must be a 'DtTFree' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2839 | val _ = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2840 | if Library.exists (fn d => | 
| 58120 | 2841 | case d of Old_Datatype_Aux.DtTFree _ => false | _ => true) dtyps | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2842 | then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2843 |                   raise REFUTE ("IDT_printer", "datatype argument (for type " ^
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2844 | Syntax.string_of_typ ctxt (Type (s, Ts)) ^ ") is not a variable") | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2845 | else () | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2846 | (* the index of the element in the datatype *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2847 | val element = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2848 | (case intr of | 
| 41471 | 2849 | Leaf xs => find_index (Prop_Logic.eval assignment) xs | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2850 |                 | Node _  => raise REFUTE ("IDT_printer",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2851 | "interpretation is not a leaf")) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2852 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2853 | if element < 0 then | 
| 69593 | 2854 | SOME (Const (\<^const_name>\<open>undefined\<close>, Type (s, Ts))) | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2855 | else | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2856 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2857 | (* takes a datatype constructor, and if for some arguments this *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2858 | (* constructor generates the datatype's element that is given by *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2859 | (* 'element', returns the constructor (as a term) as well as the *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2860 | (* indices of the arguments *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2861 | fun get_constr_args (cname, cargs) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2862 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2863 | val cTerm = Const (cname, | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2864 | map (typ_of_dtyp descr typ_assoc) cargs ---> Type (s, Ts)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2865 |                       val (iC, _, _) = interpret ctxt (typs, []) {maxvars=0,
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2866 | def_eq=false, next_idx=1, bounds=[], wellformed=True} cTerm | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2867 | fun get_args (Leaf xs) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2868 | if find_index (fn x => x = True) xs = element then | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2869 | SOME [] | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2870 | else | 
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2871 | NONE | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2872 | | get_args (Node xs) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2873 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2874 | fun search ([], _) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2875 | NONE | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2876 | | search (x::xs, n) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2877 | (case get_args x of | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2878 | SOME result => SOME (n::result) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2879 | | NONE => search (xs, n+1)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2880 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2881 | search (xs, 0) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2882 | end | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2883 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2884 | Option.map (fn args => (cTerm, cargs, args)) (get_args iC) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2885 | end | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2886 | val (cTerm, cargs, args) = | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2887 | (* we could speed things up by computing the correct *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2888 | (* constructor directly (rather than testing all *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2889 | (* constructors), based on the order in which constructors *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2890 | (* generate elements of datatypes; the current implementation *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2891 | (* of 'IDT_printer' however is independent of the internals *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2892 | (* of 'IDT_constructor_interpreter' *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2893 | (case get_first get_constr_args constrs of | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2894 | SOME x => x | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2895 |                     | NONE   => raise REFUTE ("IDT_printer",
 | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2896 | "no matching constructor found for element " ^ | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2897 | string_of_int element)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2898 | val argsTerms = map (fn (d, n) => | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2899 | let | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2900 | val dT = typ_of_dtyp descr typ_assoc d | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2901 | (* we only need the n-th element of this list, so there *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2902 | (* might be a more efficient implementation that does not *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2903 | (* generate all constants *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2904 | val consts = make_constants ctxt (typs, []) dT | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2905 | in | 
| 42364 | 2906 | print ctxt (typs, []) dT (nth consts n) assignment | 
| 39049 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2907 | end) (cargs ~~ args) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2908 | in | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2909 | SOME (list_comb (cTerm, argsTerms)) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2910 | end | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2911 | end | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2912 | | NONE => (* not an inductive datatype *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2913 | NONE) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2914 | | _ => (* a (free or schematic) type variable *) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2915 | NONE) | 
| 
423b72f2d242
prefer regular Proof.context over background theory;
 wenzelm parents: 
39048diff
changeset | 2916 | end; | 
| 14350 | 2917 | |
| 2918 | ||
| 2919 | (* ------------------------------------------------------------------------- *) | |
| 14456 
cca28ec5f9a6
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
 webertj parents: 
14351diff
changeset | 2920 | (* 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 | 2921 | (* 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 | 2922 | (* 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 | 2923 | (* subterms that are then passed to other interpreters! *) | 
| 14350 | 2924 | (* ------------------------------------------------------------------------- *) | 
| 56256 | 2925 | (* FIXME formal @{const_name} for some entries (!??) *)
 | 
| 58825 | 2926 | val _ = | 
| 2927 | Theory.setup | |
| 2928 | (add_interpreter "stlc" stlc_interpreter #> | |
| 2929 | add_interpreter "Pure" Pure_interpreter #> | |
| 2930 | add_interpreter "HOLogic" HOLogic_interpreter #> | |
| 2931 | add_interpreter "set" set_interpreter #> | |
| 2932 | add_interpreter "IDT" IDT_interpreter #> | |
| 2933 | add_interpreter "IDT_constructor" IDT_constructor_interpreter #> | |
| 2934 | add_interpreter "IDT_recursion" IDT_recursion_interpreter #> | |
| 2935 | add_interpreter "Finite_Set.card" Finite_Set_card_interpreter #> | |
| 2936 | add_interpreter "Finite_Set.finite" Finite_Set_finite_interpreter #> | |
| 2937 | add_interpreter "Nat_Orderings.less" Nat_less_interpreter #> | |
| 2938 | add_interpreter "Nat_HOL.plus" Nat_plus_interpreter #> | |
| 2939 | add_interpreter "Nat_HOL.minus" Nat_minus_interpreter #> | |
| 2940 | add_interpreter "Nat_HOL.times" Nat_times_interpreter #> | |
| 2941 | add_interpreter "List.append" List_append_interpreter #> | |
| 2942 | add_interpreter "Product_Type.prod.fst" Product_Type_fst_interpreter #> | |
| 2943 | add_interpreter "Product_Type.prod.snd" Product_Type_snd_interpreter #> | |
| 2944 | add_printer "stlc" stlc_printer #> | |
| 2945 | add_printer "set" set_printer #> | |
| 2946 | add_printer "IDT" IDT_printer); | |
| 14350 | 2947 | |
| 39048 | 2948 | |
| 2949 | ||
| 2950 | (** outer syntax commands 'refute' and 'refute_params' **) | |
| 2951 | ||
| 2952 | (* argument parsing *) | |
| 2953 | ||
| 2954 | (*optional list of arguments of the form [name1=value1, name2=value2, ...]*) | |
| 2955 | ||
| 69593 | 2956 | val scan_parm = Parse.name -- (Scan.optional (\<^keyword>\<open>=\<close> |-- Parse.name) "true") | 
| 2957 | val scan_parms = Scan.optional (\<^keyword>\<open>[\<close> |-- Parse.list scan_parm --| \<^keyword>\<open>]\<close>) []; | |
| 39048 | 2958 | |
| 2959 | ||
| 2960 | (* 'refute' command *) | |
| 2961 | ||
| 2962 | val _ = | |
| 69593 | 2963 | Outer_Syntax.command \<^command_keyword>\<open>refute\<close> | 
| 46961 
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
 wenzelm parents: 
46960diff
changeset | 2964 | "try to find a model that refutes a given subgoal" | 
| 39048 | 2965 | (scan_parms -- Scan.optional Parse.nat 1 >> | 
| 2966 | (fn (parms, i) => | |
| 60190 
906de96ba68a
allow diagnostic proof commands with skip_proofs;
 wenzelm parents: 
60094diff
changeset | 2967 | Toplevel.keep_proof (fn state => | 
| 39048 | 2968 | let | 
| 2969 | val ctxt = Toplevel.context_of state; | |
| 2970 |             val {goal = st, ...} = Proof.raw_goal (Toplevel.proof_of state);
 | |
| 45387 
ccffb3f9f42b
return outcome code, so that it can be picked up by Mutabelle
 blanchet parents: 
44121diff
changeset | 2971 | in refute_goal ctxt parms st i; () end))); | 
| 39048 | 2972 | |
| 2973 | ||
| 2974 | (* 'refute_params' command *) | |
| 2975 | ||
| 2976 | val _ = | |
| 69593 | 2977 | Outer_Syntax.command \<^command_keyword>\<open>refute_params\<close> | 
| 46961 
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
 wenzelm parents: 
46960diff
changeset | 2978 | "show/store default parameters for the 'refute' command" | 
| 39048 | 2979 | (scan_parms >> (fn parms => | 
| 2980 | Toplevel.theory (fn thy => | |
| 2981 | let | |
| 2982 | val thy' = fold set_default_param parms thy; | |
| 2983 | val output = | |
| 42361 | 2984 | (case get_default_params (Proof_Context.init_global thy') of | 
| 39048 | 2985 | [] => "none" | 
| 2986 | | new_defaults => cat_lines (map (fn (x, y) => x ^ "=" ^ y) new_defaults)); | |
| 2987 |           val _ = writeln ("Default parameters for 'refute':\n" ^ output);
 | |
| 2988 | in thy' end))); | |
| 2989 | ||
| 39046 
5b38730f3e12
tuned whitespace and indentation, emphasizing the logical structure of this long text;
 wenzelm parents: 
38864diff
changeset | 2990 | end; |