src/HOL/Tools/refute.ML
author webertj
Mon, 23 May 2005 17:17:06 +0200
changeset 16050 828fc32f390f
parent 15794 5de27a5fc5ed
child 16073 794b37d08a2e
permissions -rw-r--r--
interpreters for lfp/gfp added
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
     1
(*  Title:      HOL/Tools/refute.ML
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
     2
    ID:         $Id$
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
     3
    Author:     Tjark Weber
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
     4
    Copyright   2003-2005
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
     5
14965
7155b319eafa new SAT solver interface
webertj
parents: 14818
diff changeset
     6
Finite model generation for HOL formulas, using a SAT solver.
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
     7
*)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
     8
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
     9
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    10
(* Declares the 'REFUTE' signature as well as a structure 'Refute'.          *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    11
(* Documentation is available in the Isabelle/Isar theory 'HOL/Refute.thy'.  *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    12
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    13
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    14
signature REFUTE =
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    15
sig
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    16
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    17
	exception REFUTE of string * string
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    18
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    19
(* ------------------------------------------------------------------------- *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    20
(* Model/interpretation related code (translation HOL -> propositional logic *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    21
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    22
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    23
	type params
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    24
	type interpretation
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    25
	type model
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    26
	type arguments
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    27
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    28
	exception MAXVARS_EXCEEDED
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    29
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    30
	val add_interpreter : string -> (theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option) -> theory -> theory
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    31
	val add_printer     : string -> (theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option) -> theory -> theory
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    32
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
    33
	val interpret : theory -> model -> arguments -> Term.term -> (interpretation * model * arguments)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    34
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    35
	val print       : theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    36
	val print_model : theory -> model -> (int -> bool) -> string
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    37
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    38
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    39
(* Interface                                                                 *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    40
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    41
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    42
	val set_default_param  : (string * string) -> theory -> theory
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    43
	val get_default_param  : theory -> string -> string option
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    44
	val get_default_params : theory -> (string * string) list
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    45
	val actual_params      : theory -> (string * string) list -> params
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    46
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    47
	val find_model : theory -> params -> Term.term -> bool -> unit
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    48
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    49
	val satisfy_term   : theory -> (string * string) list -> Term.term -> unit  (* tries to find a model for a formula *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    50
	val refute_term    : theory -> (string * string) list -> Term.term -> unit  (* tries to find a model that refutes a formula *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    51
	val refute_subgoal : theory -> (string * string) list -> Thm.thm -> int -> unit
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    52
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    53
	val setup : (theory -> theory) list
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    54
end;
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    55
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    56
structure Refute : REFUTE =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    57
struct
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    58
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    59
	open PropLogic;
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    60
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    61
	(* We use 'REFUTE' only for internal error conditions that should    *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    62
	(* never occur in the first place (i.e. errors caused by bugs in our *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    63
	(* code).  Otherwise (e.g. to indicate invalid input data) we use    *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    64
	(* 'error'.                                                          *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
    65
	exception REFUTE of string * string;  (* ("in function", "cause") *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    66
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    67
	(* should be raised by an interpreter when more variables would be *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    68
	(* required than allowed by 'maxvars'                              *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
    69
	exception MAXVARS_EXCEEDED;
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    70
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    71
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    72
(* TREES                                                                     *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    73
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    74
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    75
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    76
(* tree: implements an arbitrarily (but finitely) branching tree as a list   *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    77
(*       of (lists of ...) elements                                          *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    78
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    79
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    80
	datatype 'a tree =
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    81
		  Leaf of 'a
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    82
		| Node of ('a tree) list;
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    83
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    84
	(* ('a -> 'b) -> 'a tree -> 'b tree *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    85
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    86
	fun tree_map f tr =
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    87
		case tr of
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    88
		  Leaf x  => Leaf (f x)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    89
		| Node xs => Node (map (tree_map f) xs);
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    90
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    91
	(* ('a * 'b -> 'a) -> 'a * ('b tree) -> 'a *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    92
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    93
	fun tree_foldl f =
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    94
	let
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    95
		fun itl (e, Leaf x)  = f(e,x)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
    96
		  | itl (e, Node xs) = Library.foldl (tree_foldl f) (e,xs)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    97
	in
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    98
		itl
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
    99
	end;
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   100
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   101
	(* 'a tree * 'b tree -> ('a * 'b) tree *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   102
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
   103
	fun tree_pair (t1, t2) =
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   104
		case t1 of
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   105
		  Leaf x =>
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   106
			(case t2 of
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   107
				  Leaf y => Leaf (x,y)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   108
				| Node _ => raise REFUTE ("tree_pair", "trees are of different height (second tree is higher)"))
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   109
		| Node xs =>
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   110
			(case t2 of
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   111
				  (* '~~' will raise an exception if the number of branches in   *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   112
				  (* both trees is different at the current node                 *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   113
				  Node ys => Node (map tree_pair (xs ~~ ys))
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   114
				| Leaf _  => raise REFUTE ("tree_pair", "trees are of different height (first tree is higher)"));
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   115
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   116
(* ------------------------------------------------------------------------- *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   117
(* params: parameters that control the translation into a propositional      *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   118
(*         formula/model generation                                          *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   119
(*                                                                           *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   120
(* The following parameters are supported (and required (!), except for      *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   121
(* "sizes"):                                                                 *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   122
(*                                                                           *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   123
(* Name          Type    Description                                         *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   124
(*                                                                           *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   125
(* "sizes"       (string * int) list                                         *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   126
(*                       Size of ground types (e.g. 'a=2), or depth of IDTs. *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   127
(* "minsize"     int     If >0, minimal size of each ground type/IDT depth.  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   128
(* "maxsize"     int     If >0, maximal size of each ground type/IDT depth.  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   129
(* "maxvars"     int     If >0, use at most 'maxvars' Boolean variables      *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   130
(*                       when transforming the term into a propositional     *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   131
(*                       formula.                                            *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   132
(* "maxtime"     int     If >0, terminate after at most 'maxtime' seconds.   *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   133
(* "satsolver"   string  SAT solver to be used.                              *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   134
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   135
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   136
	type params =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   137
		{
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   138
			sizes    : (string * int) list,
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   139
			minsize  : int,
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   140
			maxsize  : int,
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   141
			maxvars  : int,
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   142
			maxtime  : int,
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   143
			satsolver: string
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   144
		};
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   145
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   146
(* ------------------------------------------------------------------------- *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   147
(* interpretation: a term's interpretation is given by a variable of type    *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   148
(*                 'interpretation'                                          *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   149
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   150
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   151
	type interpretation =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   152
		prop_formula list tree;
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   153
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   154
(* ------------------------------------------------------------------------- *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   155
(* model: a model specifies the size of types and the interpretation of      *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   156
(*        terms                                                              *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   157
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   158
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   159
	type model =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   160
		(Term.typ * int) list * (Term.term * interpretation) list;
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   161
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   162
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   163
(* arguments: additional arguments required during interpretation of terms   *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   164
(* ------------------------------------------------------------------------- *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   165
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   166
	type arguments =
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   167
		{
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   168
			maxvars   : int,   (* just passed unchanged from 'params' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   169
			def_eq    : bool,  (* whether to use 'make_equality' or 'make_def_equality' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   170
			(* the following may change during the translation *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   171
			next_idx  : int,
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   172
			bounds    : interpretation list,
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   173
			wellformed: prop_formula
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   174
		};
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   175
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   176
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   177
	structure RefuteDataArgs =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   178
	struct
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   179
		val name = "HOL/refute";
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   180
		type T =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   181
			{interpreters: (string * (theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option)) list,
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   182
			 printers: (string * (theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option)) list,
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   183
			 parameters: string Symtab.table};
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   184
		val empty = {interpreters = [], printers = [], parameters = Symtab.empty};
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   185
		val copy = I;
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   186
		val prep_ext = I;
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   187
		fun merge
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   188
			({interpreters = in1, printers = pr1, parameters = pa1},
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   189
			 {interpreters = in2, printers = pr2, parameters = pa2}) =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   190
			{interpreters = rev (merge_alists (rev in1) (rev in2)),
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   191
			 printers = rev (merge_alists (rev pr1) (rev pr2)),
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   192
			 parameters = Symtab.merge (op=) (pa1, pa2)};
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   193
		fun print sg {interpreters, printers, parameters} =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   194
			Pretty.writeln (Pretty.chunks
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
   195
				[Pretty.strs ("default parameters:" :: List.concat (map (fn (name, value) => [name, "=", value]) (Symtab.dest parameters))),
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   196
				 Pretty.strs ("interpreters:" :: map fst interpreters),
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   197
				 Pretty.strs ("printers:" :: map fst printers)]);
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   198
	end;
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   199
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   200
	structure RefuteData = TheoryDataFun(RefuteDataArgs);
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   201
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   202
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   203
(* ------------------------------------------------------------------------- *)
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
   204
(* interpret: interprets the term 't' using a suitable interpreter; returns  *)
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
   205
(*            the interpretation and a (possibly extended) model that keeps  *)
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
   206
(*            track of the interpretation of subterms                        *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   207
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   208
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   209
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   210
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   211
	fun interpret thy model args t =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   212
		(case get_first (fn (_, f) => f thy model args t) (#interpreters (RefuteData.get thy)) of
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   213
		  NONE   => raise REFUTE ("interpret", "no interpreter for term " ^ quote (Sign.string_of_term (sign_of thy) t))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   214
		| SOME x => x);
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   215
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   216
(* ------------------------------------------------------------------------- *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   217
(* print: converts the constant denoted by the term 't' into a term using a  *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   218
(*        suitable printer                                                   *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   219
(* ------------------------------------------------------------------------- *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   220
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   221
	(* theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   222
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   223
	fun print thy model t intr assignment =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   224
		(case get_first (fn (_, f) => f thy model t intr assignment) (#printers (RefuteData.get thy)) of
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   225
		  NONE   => raise REFUTE ("print", "no printer for term " ^ quote (Sign.string_of_term (sign_of thy) t))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   226
		| SOME x => x);
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   227
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   228
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   229
(* print_model: turns the model into a string, using a fixed interpretation  *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   230
(*              (given by an assignment for Boolean variables) and suitable  *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   231
(*              printers                                                     *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   232
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   233
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   234
	(* theory -> model -> (int -> bool) -> string *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   235
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   236
	fun print_model thy model assignment =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   237
	let
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   238
		val (typs, terms) = model
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   239
		val typs_msg =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   240
			if null typs then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   241
				"empty universe (no type variables in term)\n"
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   242
			else
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
   243
				"Size of types: " ^ commas (map (fn (T, i) => Sign.string_of_typ (sign_of thy) T ^ ": " ^ string_of_int i) typs) ^ "\n"
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   244
		val show_consts_msg =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   245
			if not (!show_consts) andalso Library.exists (is_Const o fst) terms then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   246
				"set \"show_consts\" to show the interpretation of constants\n"
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   247
			else
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   248
				""
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   249
		val terms_msg =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   250
			if null terms then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   251
				"empty interpretation (no free variables in term)\n"
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   252
			else
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
   253
				space_implode "\n" (List.mapPartial (fn (t, intr) =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   254
					(* print constants only if 'show_consts' is true *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   255
					if (!show_consts) orelse not (is_Const t) then
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   256
						SOME (Sign.string_of_term (sign_of thy) t ^ ": " ^ Sign.string_of_term (sign_of thy) (print thy model t intr assignment))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   257
					else
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   258
						NONE) terms) ^ "\n"
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   259
	in
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   260
		typs_msg ^ show_consts_msg ^ terms_msg
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   261
	end;
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   262
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   263
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   264
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   265
(* PARAMETER MANAGEMENT                                                      *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   266
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   267
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   268
	(* string -> (theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option) -> theory -> theory *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   269
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   270
	fun add_interpreter name f thy =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   271
	let
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   272
		val {interpreters, printers, parameters} = RefuteData.get thy
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   273
	in
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   274
		case assoc (interpreters, name) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   275
		  NONE   => RefuteData.put {interpreters = (name, f) :: interpreters, printers = printers, parameters = parameters} thy
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   276
		| SOME _ => error ("Interpreter " ^ name ^ " already declared")
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   277
	end;
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   278
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   279
	(* string -> (theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option) -> theory -> theory *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   280
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   281
	fun add_printer name f thy =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   282
	let
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   283
		val {interpreters, printers, parameters} = RefuteData.get thy
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   284
	in
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   285
		case assoc (printers, name) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   286
		  NONE   => RefuteData.put {interpreters = interpreters, printers = (name, f) :: printers, parameters = parameters} thy
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   287
		| SOME _ => error ("Printer " ^ name ^ " already declared")
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   288
	end;
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   289
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   290
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   291
(* set_default_param: stores the '(name, value)' pair in RefuteData's        *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   292
(*                    parameter table                                        *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   293
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   294
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   295
	(* (string * string) -> theory -> theory *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   296
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   297
	fun set_default_param (name, value) thy =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   298
	let
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   299
		val {interpreters, printers, parameters} = RefuteData.get thy
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   300
	in
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   301
		case Symtab.lookup (parameters, name) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   302
		  NONE   => RefuteData.put
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   303
			{interpreters = interpreters, printers = printers, parameters = Symtab.extend (parameters, [(name, value)])} thy
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   304
		| SOME _ => RefuteData.put
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   305
			{interpreters = interpreters, printers = printers, parameters = Symtab.update ((name, value), parameters)} thy
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   306
	end;
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   307
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
   308
(* ------------------------------------------------------------------------- *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   309
(* get_default_param: retrieves the value associated with 'name' from        *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   310
(*                    RefuteData's parameter table                           *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   311
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   312
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   313
	(* theory -> string -> string option *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   314
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   315
	fun get_default_param thy name = Symtab.lookup ((#parameters o RefuteData.get) thy, name);
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   316
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   317
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   318
(* get_default_params: returns a list of all '(name, value)' pairs that are  *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   319
(*                     stored in RefuteData's parameter table                *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   320
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   321
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   322
	(* theory -> (string * string) list *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   323
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   324
	fun get_default_params thy = (Symtab.dest o #parameters o RefuteData.get) thy;
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   325
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   326
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   327
(* actual_params: takes a (possibly empty) list 'params' of parameters that  *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   328
(*      override the default parameters currently specified in 'thy', and    *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   329
(*      returns a record that can be passed to 'find_model'.                 *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   330
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   331
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   332
	(* theory -> (string * string) list -> params *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   333
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   334
	fun actual_params thy override =
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   335
	let
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   336
		(* (string * string) list * string -> int *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   337
		fun read_int (parms, name) =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   338
			case assoc_string (parms, name) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   339
			  SOME s => (case Int.fromString s of
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   340
				  SOME i => i
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   341
				| NONE   => error ("parameter " ^ quote name ^ " (value is " ^ quote s ^ ") must be an integer value"))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   342
			| NONE   => error ("parameter " ^ quote name ^ " must be assigned a value")
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   343
		(* (string * string) list * string -> string *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   344
		fun read_string (parms, name) =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   345
			case assoc_string (parms, name) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   346
			  SOME s => s
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   347
			| NONE   => error ("parameter " ^ quote name ^ " must be assigned a value")
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   348
		(* (string * string) list *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   349
		val allparams = override @ (get_default_params thy)  (* 'override' first, defaults last *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   350
		(* int *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   351
		val minsize   = read_int (allparams, "minsize")
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   352
		val maxsize   = read_int (allparams, "maxsize")
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   353
		val maxvars   = read_int (allparams, "maxvars")
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   354
      val maxtime   = read_int (allparams, "maxtime")
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   355
		(* string *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   356
		val satsolver = read_string (allparams, "satsolver")
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   357
		(* all remaining parameters of the form "string=int" are collected in  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   358
		(* 'sizes'                                                             *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   359
		(* TODO: it is currently not possible to specify a size for a type     *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   360
		(*       whose name is one of the other parameters (e.g. 'maxvars')    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   361
		(* (string * int) list *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   362
		val sizes     = List.mapPartial
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   363
			(fn (name,value) => (case Int.fromString value of SOME i => SOME (name, i) | NONE => NONE))
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   364
			(List.filter (fn (name,_) => name<>"minsize" andalso name<>"maxsize" andalso name<>"maxvars" andalso name<>"maxtime" andalso name<>"satsolver")
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   365
				allparams)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   366
	in
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   367
		{sizes=sizes, minsize=minsize, maxsize=maxsize, maxvars=maxvars, maxtime=maxtime, satsolver=satsolver}
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   368
	end;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   369
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   370
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   371
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   372
(* TRANSLATION HOL -> PROPOSITIONAL LOGIC, BOOLEAN ASSIGNMENT -> MODEL       *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   373
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   374
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   375
(* ------------------------------------------------------------------------- *)
15335
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   376
(* typ_of_dtyp: converts a data type ('DatatypeAux.dtyp') into a type        *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   377
(*              ('Term.typ'), given type parameters for the data type's type *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   378
(*              arguments                                                    *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   379
(* ------------------------------------------------------------------------- *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   380
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   381
	(* DatatypeAux.descr -> (DatatypeAux.dtyp * Term.typ) list -> DatatypeAux.dtyp -> Term.typ *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   382
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   383
	fun typ_of_dtyp descr typ_assoc (DatatypeAux.DtTFree a) =
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   384
		(* replace a 'DtTFree' variable by the associated type *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   385
		(valOf o assoc) (typ_assoc, DatatypeAux.DtTFree a)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   386
	  | typ_of_dtyp descr typ_assoc (DatatypeAux.DtType (s, ds)) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   387
		Type (s, map (typ_of_dtyp descr typ_assoc) ds)
15335
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   388
	  | typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec i) =
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   389
		let
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   390
			val (s, ds, _) = (valOf o assoc) (descr, i)
15335
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   391
		in
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   392
			Type (s, map (typ_of_dtyp descr typ_assoc) ds)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   393
		end;
15335
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   394
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
   395
(* ------------------------------------------------------------------------- *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   396
(* collect_axioms: collects (monomorphic, universally quantified versions    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   397
(*                 of) all HOL axioms that are relevant w.r.t 't'            *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   398
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   399
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   400
	(* Note: to make the collection of axioms more easily extensible, this    *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   401
	(*       function could be based on user-supplied "axiom collectors",     *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   402
	(*       similar to 'interpret'/interpreters or 'print'/printers          *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   403
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   404
	(* theory -> Term.term -> Term.term list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   405
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   406
	(* Which axioms are "relevant" for a particular term/type goes hand in    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   407
	(* hand with the interpretation of that term/type by its interpreter (see *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   408
	(* way below): if the interpretation respects an axiom anyway, the axiom  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   409
	(* does not need to be added as a constraint here.                        *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   410
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   411
	(* When an axiom is added as relevant, further axioms may need to be      *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   412
	(* added as well (e.g. when a constant is defined in terms of other       *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   413
	(* constants).  To avoid infinite recursion (which should not happen for  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   414
	(* constants anyway, but it could happen for "typedef"-related axioms,    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   415
	(* since they contain the type again), we use an accumulator 'axs' and    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   416
	(* add a relevant axiom only if it is not in 'axs' yet.                   *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   417
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   418
	fun collect_axioms thy t =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   419
	let
14984
edbc81e60809 immediate_output;
wenzelm
parents: 14965
diff changeset
   420
		val _ = immediate_output "Adding axioms..."
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   421
		(* (string * Term.term) list *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   422
		val axioms = List.concat (map (Symtab.dest o #axioms o Theory.rep_theory) (thy :: Theory.ancestors_of thy))
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   423
		(* string list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   424
		val rec_names = Symtab.foldl (fn (acc, (_, info)) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   425
			#rec_names info @ acc) ([], DatatypePackage.get_datatypes thy)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   426
		(* string list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   427
		val const_of_class_names = map Sign.const_of_class (Sign.classes (sign_of thy))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   428
		(* given a constant 's' of type 'T', which is a subterm of 't', where  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   429
		(* 't' has a (possibly) more general type, the schematic type          *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   430
		(* variables in 't' are instantiated to match the type 'T' (may raise  *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   431
		(* Type.TYPE_MATCH)                                                    *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   432
		(* (string * Term.typ) * Term.term -> Term.term *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   433
		fun specialize_type ((s, T), t) =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   434
		let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   435
			fun find_typeSubs (Const (s', T')) =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   436
				(if s=s' then
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   437
					SOME (Type.typ_match (Sign.tsig_of (sign_of thy)) (Vartab.empty, (T', T))) handle Type.TYPE_MATCH => NONE
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   438
				else
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   439
					NONE)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   440
			  | find_typeSubs (Free _)           = NONE
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   441
			  | find_typeSubs (Var _)            = NONE
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   442
			  | find_typeSubs (Bound _)          = NONE
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   443
			  | find_typeSubs (Abs (_, _, body)) = find_typeSubs body
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   444
			  | find_typeSubs (t1 $ t2)          = (case find_typeSubs t1 of SOME x => SOME x | NONE => find_typeSubs t2)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   445
			val typeSubs = (case find_typeSubs t of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   446
				  SOME x => x
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   447
				| NONE   => raise Type.TYPE_MATCH (* no match found - perhaps due to sort constraints *))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   448
		in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   449
			map_term_types
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   450
				(map_type_tvar
15794
5de27a5fc5ed Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents: 15783
diff changeset
   451
					(fn v =>
5de27a5fc5ed Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents: 15783
diff changeset
   452
						case Type.lookup (typeSubs, v) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   453
						  NONE =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   454
							(* schematic type variable not instantiated *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   455
							raise REFUTE ("collect_axioms", "term " ^ Sign.string_of_term (sign_of thy) t ^ " still has a polymorphic type (after instantiating type of " ^ quote s ^ ")")
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   456
						| SOME typ =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   457
							typ))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   458
					t
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   459
		end
15280
e0e9bf44afad minor code refactoring
webertj
parents: 15125
diff changeset
   460
		(* applies a type substitution 'typeSubs' for all type variables in a  *)
e0e9bf44afad minor code refactoring
webertj
parents: 15125
diff changeset
   461
		(* term 't'                                                            *)
15794
5de27a5fc5ed Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents: 15783
diff changeset
   462
		(* (Term.sort * Term.typ) Term.Vartab.table -> Term.term -> Term.term *)
15280
e0e9bf44afad minor code refactoring
webertj
parents: 15125
diff changeset
   463
		fun monomorphic_term typeSubs t =
e0e9bf44afad minor code refactoring
webertj
parents: 15125
diff changeset
   464
			map_term_types (map_type_tvar
15794
5de27a5fc5ed Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents: 15783
diff changeset
   465
				(fn v =>
5de27a5fc5ed Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents: 15783
diff changeset
   466
					case Type.lookup (typeSubs, v) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   467
					  NONE =>
15280
e0e9bf44afad minor code refactoring
webertj
parents: 15125
diff changeset
   468
						(* schematic type variable not instantiated *)
e0e9bf44afad minor code refactoring
webertj
parents: 15125
diff changeset
   469
						raise ERROR
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   470
					| SOME typ =>
15280
e0e9bf44afad minor code refactoring
webertj
parents: 15125
diff changeset
   471
						typ)) t
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   472
		(* Term.term list * Term.typ -> Term.term list *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   473
		fun collect_sort_axioms (axs, T) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   474
			let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   475
				(* collect the axioms for a single 'class' (but not for its superclasses) *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   476
				(* Term.term list * string -> Term.term list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   477
				fun collect_class_axioms (axs, class) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   478
					let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   479
						(* obtain the axioms generated by the "axclass" command *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   480
						(* (string * Term.term) list *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   481
						val class_axioms             = List.filter (fn (s, _) => String.isPrefix (class ^ ".axioms_") s) axioms
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   482
						(* replace the one schematic type variable in each axiom by the actual type 'T' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   483
						(* (string * Term.term) list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   484
						val monomorphic_class_axioms = map (fn (axname, ax) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   485
							let
15794
5de27a5fc5ed Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents: 15783
diff changeset
   486
								val (idx, S) = (case term_tvars ax of
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   487
									  [is] => is
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   488
									| _    => raise REFUTE ("collect_axioms", "class axiom " ^ axname ^ " (" ^ Sign.string_of_term (sign_of thy) ax ^ ") does not contain exactly one type variable"))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   489
							in
15794
5de27a5fc5ed Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents: 15783
diff changeset
   490
								(axname, monomorphic_term (Vartab.make [(idx, (S, T))]) ax)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   491
							end) class_axioms
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   492
						(* Term.term list * (string * Term.term) list -> Term.term list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   493
						fun collect_axiom (axs, (axname, ax)) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   494
							if mem_term (ax, axs) then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   495
								axs
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   496
							else (
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   497
								immediate_output (" " ^ axname);
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   498
								collect_term_axioms (ax :: axs, ax)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   499
							)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   500
					in
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   501
						Library.foldl collect_axiom (axs, monomorphic_class_axioms)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   502
					end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   503
				(* string list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   504
				val sort = (case T of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   505
					  TFree (_, sort) => sort
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   506
					| TVar (_, sort)  => sort
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   507
					| _               => raise REFUTE ("collect_axioms", "type " ^ Sign.string_of_typ (sign_of thy) T ^ " is not a variable"))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   508
				(* obtain all superclasses of classes in 'sort' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   509
				(* string list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   510
				val superclasses = Graph.all_succs ((#classes o Type.rep_tsig o Sign.tsig_of o sign_of) thy) sort
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   511
			in
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   512
				Library.foldl collect_class_axioms (axs, superclasses)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   513
			end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   514
		(* Term.term list * Term.typ -> Term.term list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   515
		and collect_type_axioms (axs, T) =
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   516
			case T of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   517
			(* simple types *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   518
			  Type ("prop", [])      => axs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   519
			| Type ("fun", [T1, T2]) => collect_type_axioms (collect_type_axioms (axs, T1), T2)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   520
			| Type ("set", [T1])     => collect_type_axioms (axs, T1)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   521
			| Type ("itself", [T1])  => collect_type_axioms (axs, T1)  (* axiomatic type classes *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   522
			| Type (s, Ts)           =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   523
				let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   524
					(* look up the definition of a type, as created by "typedef" *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   525
					(* (string * Term.term) list -> (string * Term.term) option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   526
					fun get_typedefn [] =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   527
						NONE
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   528
					  | get_typedefn ((axname,ax)::axms) =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   529
						(let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   530
							(* Term.term -> Term.typ option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   531
							fun type_of_type_definition (Const (s', T')) =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   532
								if s'="Typedef.type_definition" then
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   533
									SOME T'
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   534
								else
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   535
									NONE
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   536
							  | type_of_type_definition (Free _)           = NONE
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   537
							  | type_of_type_definition (Var _)            = NONE
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   538
							  | type_of_type_definition (Bound _)          = NONE
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   539
							  | type_of_type_definition (Abs (_, _, body)) = type_of_type_definition body
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   540
							  | type_of_type_definition (t1 $ t2)          = (case type_of_type_definition t1 of SOME x => SOME x | NONE => type_of_type_definition t2)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   541
						in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   542
							case type_of_type_definition ax of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   543
							  SOME T' =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   544
								let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   545
									val T''      = (domain_type o domain_type) T'
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   546
									val typeSubs = Type.typ_match (Sign.tsig_of (sign_of thy)) (Vartab.empty, (T'', T))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   547
								in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   548
									SOME (axname, monomorphic_term typeSubs ax)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   549
								end
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   550
							| NONE =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   551
								get_typedefn axms
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   552
						end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   553
						handle ERROR           => get_typedefn axms
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   554
						     | MATCH           => get_typedefn axms
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   555
						     | Type.TYPE_MATCH => get_typedefn axms)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   556
				in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   557
					case DatatypePackage.datatype_info thy s of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   558
					  SOME info =>  (* inductive datatype *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   559
							(* only collect relevant type axioms for the argument types *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   560
							Library.foldl collect_type_axioms (axs, Ts)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   561
					| NONE =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   562
						(case get_typedefn axioms of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   563
						  SOME (axname, ax) => 
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   564
							if mem_term (ax, axs) then
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   565
								(* only collect relevant type axioms for the argument types *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   566
								Library.foldl collect_type_axioms (axs, Ts)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   567
							else
14984
edbc81e60809 immediate_output;
wenzelm
parents: 14965
diff changeset
   568
								(immediate_output (" " ^ axname);
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   569
								collect_term_axioms (ax :: axs, ax))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   570
						| NONE =>
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   571
							(* unspecified type, perhaps introduced with 'typedecl' *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   572
							(* at least collect relevant type axioms for the argument types *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   573
							Library.foldl collect_type_axioms (axs, Ts))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   574
				end
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   575
			| TFree _                => collect_sort_axioms (axs, T)  (* axiomatic type classes *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   576
			| TVar _                 => collect_sort_axioms (axs, T)  (* axiomatic type classes *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   577
		(* Term.term list * Term.term -> Term.term list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   578
		and collect_term_axioms (axs, t) =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   579
			case t of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   580
			(* Pure *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   581
			  Const ("all", _)                => axs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   582
			| Const ("==", _)                 => axs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   583
			| Const ("==>", _)                => axs
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   584
			| Const ("TYPE", T)               => collect_type_axioms (axs, T)  (* axiomatic type classes *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   585
			(* HOL *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   586
			| Const ("Trueprop", _)           => axs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   587
			| Const ("Not", _)                => axs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   588
			| Const ("True", _)               => axs  (* redundant, since 'True' is also an IDT constructor *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   589
			| Const ("False", _)              => axs  (* redundant, since 'False' is also an IDT constructor *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   590
			| Const ("arbitrary", T)          => collect_type_axioms (axs, T)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   591
			| Const ("The", T)                =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   592
				let
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   593
					val ax = specialize_type (("The", T), (valOf o assoc) (axioms, "HOL.the_eq_trivial"))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   594
				in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   595
					if mem_term (ax, axs) then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   596
						collect_type_axioms (axs, T)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   597
					else
14984
edbc81e60809 immediate_output;
wenzelm
parents: 14965
diff changeset
   598
						(immediate_output " HOL.the_eq_trivial";
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   599
						collect_term_axioms (ax :: axs, ax))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   600
				end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   601
			| Const ("Hilbert_Choice.Eps", T) =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   602
				let
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   603
					val ax = specialize_type (("Hilbert_Choice.Eps", T), (valOf o assoc) (axioms, "Hilbert_Choice.someI"))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   604
				in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   605
					if mem_term (ax, axs) then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   606
						collect_type_axioms (axs, T)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   607
					else
14984
edbc81e60809 immediate_output;
wenzelm
parents: 14965
diff changeset
   608
						(immediate_output " Hilbert_Choice.someI";
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   609
						collect_term_axioms (ax :: axs, ax))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   610
				end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   611
			| Const ("All", _) $ t1           => collect_term_axioms (axs, t1)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   612
			| Const ("Ex", _) $ t1            => collect_term_axioms (axs, t1)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   613
			| Const ("op =", T)               => collect_type_axioms (axs, T)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   614
			| Const ("op &", _)               => axs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   615
			| Const ("op |", _)               => axs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   616
			| Const ("op -->", _)             => axs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   617
			(* sets *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   618
			| Const ("Collect", T)            => collect_type_axioms (axs, T)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   619
			| Const ("op :", T)               => collect_type_axioms (axs, T)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   620
			(* other optimizations *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   621
			| Const ("Finite_Set.card", T)    => collect_type_axioms (axs, T)
15571
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
   622
			| Const ("Finite_Set.Finites", T) => collect_type_axioms (axs, T)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   623
			| Const ("op <", T as Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("bool", [])])])) => collect_type_axioms (axs, T)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   624
			| Const ("op +", T as Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => collect_type_axioms (axs, T)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   625
			| Const ("op -", T as Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => collect_type_axioms (axs, T)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   626
			| Const ("op *", T as Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => collect_type_axioms (axs, T)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
   627
			| Const ("List.op @", T)          => collect_type_axioms (axs, T)
16050
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
   628
			| Const ("Lfp.lfp", T)            => collect_type_axioms (axs, T)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
   629
			| Const ("Gfp.gfp", T)            => collect_type_axioms (axs, T)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   630
			(* simply-typed lambda calculus *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   631
			| Const (s, T)                    =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   632
				let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   633
					(* look up the definition of a constant, as created by "constdefs" *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   634
					(* string -> Term.typ -> (string * Term.term) list -> (string * Term.term) option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   635
					fun get_defn [] =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   636
						NONE
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   637
					  | get_defn ((axname, ax)::axms) =
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   638
						(let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   639
							val (lhs, _) = Logic.dest_equals ax  (* equations only *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   640
							val c        = head_of lhs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   641
							val (s', T') = dest_Const c
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   642
						in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   643
							if s=s' then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   644
								let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   645
									val typeSubs = Type.typ_match (Sign.tsig_of (sign_of thy)) (Vartab.empty, (T', T))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   646
								in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   647
									SOME (axname, monomorphic_term typeSubs ax)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   648
								end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   649
							else
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   650
								get_defn axms
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   651
						end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   652
						handle ERROR           => get_defn axms
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   653
						     | TERM _          => get_defn axms
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   654
						     | Type.TYPE_MATCH => get_defn axms)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   655
					(* axiomatic type classes *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   656
					(* unit -> bool *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   657
					fun is_const_of_class () =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   658
						(* I'm not quite sure if checking the name 's' is sufficient, *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   659
						(* or if we should also check the type 'T'                    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   660
						s mem const_of_class_names
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   661
					(* inductive data types *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   662
					(* unit -> bool *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   663
					fun is_IDT_constructor () =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   664
						(case body_type T of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   665
						  Type (s', _) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   666
							(case DatatypePackage.constrs_of thy s' of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   667
							  SOME constrs =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   668
								Library.exists (fn c =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   669
									(case c of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   670
									  Const (cname, ctype) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   671
										cname = s andalso Type.typ_instance (Sign.tsig_of (sign_of thy)) (T, ctype)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   672
									| _ =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   673
										raise REFUTE ("collect_axioms", "IDT constructor is not a constant")))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   674
									constrs
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   675
							| NONE =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   676
								false)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   677
						| _  =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   678
							false)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   679
					(* unit -> bool *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   680
					fun is_IDT_recursor () =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   681
						(* I'm not quite sure if checking the name 's' is sufficient, *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   682
						(* or if we should also check the type 'T'                    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   683
						s mem rec_names
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   684
				in
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   685
					if is_const_of_class () then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   686
						(* axiomatic type classes: add "OFCLASS(?'a::c, c_class)" and *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   687
						(* the introduction rule "class.intro" as axioms              *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   688
						let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   689
							val class   = Sign.class_of_const s
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   690
							val inclass = Logic.mk_inclass (TVar (("'a", 0), [class]), class)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   691
							(* Term.term option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   692
							val ofclass_ax = (SOME (specialize_type ((s, T), inclass)) handle Type.TYPE_MATCH => NONE)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   693
							val intro_ax   = (Option.map (fn t => specialize_type ((s, T), t)) (assoc (axioms, class ^ ".intro")) handle Type.TYPE_MATCH => NONE)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   694
							val axs'       = (case ofclass_ax of NONE => axs | SOME ax => if mem_term (ax, axs) then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   695
									(* collect relevant type axioms *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   696
									collect_type_axioms (axs, T)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   697
								else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   698
									(immediate_output (" " ^ Sign.string_of_term (sign_of thy) ax);
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   699
									collect_term_axioms (ax :: axs, ax)))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   700
							val axs''      = (case intro_ax of NONE => axs' | SOME ax => if mem_term (ax, axs') then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   701
									(* collect relevant type axioms *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   702
									collect_type_axioms (axs', T)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   703
								else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   704
									(immediate_output (" " ^ class ^ ".intro");
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   705
									collect_term_axioms (ax :: axs', ax)))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   706
						in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   707
							axs''
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   708
						end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   709
					else if is_IDT_constructor () then
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   710
						(* only collect relevant type axioms *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   711
						collect_type_axioms (axs, T)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   712
					else if is_IDT_recursor () then
15125
5224130bc0d6 warning for recursion over IDTs added
webertj
parents: 14984
diff changeset
   713
						(* only collect relevant type axioms *)
5224130bc0d6 warning for recursion over IDTs added
webertj
parents: 14984
diff changeset
   714
						collect_type_axioms (axs, T)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   715
					else (
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   716
						case get_defn axioms of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   717
						  SOME (axname, ax) => 
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   718
							if mem_term (ax, axs) then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   719
								(* collect relevant type axioms *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   720
								collect_type_axioms (axs, T)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   721
							else
14984
edbc81e60809 immediate_output;
wenzelm
parents: 14965
diff changeset
   722
								(immediate_output (" " ^ axname);
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   723
								collect_term_axioms (ax :: axs, ax))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   724
						| NONE =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   725
							(* collect relevant type axioms *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   726
							collect_type_axioms (axs, T)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   727
					)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   728
				end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   729
			| Free (_, T)                     => collect_type_axioms (axs, T)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   730
			| Var (_, T)                      => collect_type_axioms (axs, T)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   731
			| Bound i                         => axs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   732
			| Abs (_, T, body)                => collect_term_axioms (collect_type_axioms (axs, T), body)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   733
			| t1 $ t2                         => collect_term_axioms (collect_term_axioms (axs, t1), t2)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   734
		(* universal closure over schematic variables *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   735
		(* Term.term -> Term.term *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   736
		fun close_form t =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   737
		let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   738
			(* (Term.indexname * Term.typ) list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   739
			val vars = sort_wrt (fst o fst) (map dest_Var (term_vars t))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   740
		in
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   741
			Library.foldl
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   742
				(fn (t', ((x, i), T)) => (Term.all T) $ Abs (x, T, abstract_over (Var((x, i), T), t')))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   743
				(t, vars)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   744
		end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   745
		(* Term.term list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   746
		val result = map close_form (collect_term_axioms ([], t))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   747
		val _ = writeln " ...done."
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   748
	in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   749
		result
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   750
	end;
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   751
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   752
(* ------------------------------------------------------------------------- *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   753
(* ground_types: collects all ground types in a term (including argument     *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   754
(*               types of other types), suppressing duplicates.  Does not    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   755
(*               return function types, set types, non-recursive IDTs, or    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   756
(*               'propT'.  For IDTs, also the argument types of constructors *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   757
(*               are considered.                                             *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   758
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   759
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   760
	(* theory -> Term.term -> Term.typ list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   761
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   762
	fun ground_types thy t =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   763
	let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   764
		(* Term.typ * Term.typ list -> Term.typ list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   765
		fun collect_types (T, acc) =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   766
			if T mem acc then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   767
				acc  (* prevent infinite recursion (for IDTs) *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   768
			else
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   769
				(case T of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   770
				  Type ("fun", [T1, T2]) => collect_types (T1, collect_types (T2, acc))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   771
				| Type ("prop", [])      => acc
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   772
				| Type ("set", [T1])     => collect_types (T1, acc)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   773
				| Type (s, Ts)           =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   774
					(case DatatypePackage.datatype_info thy s of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   775
					  SOME info =>  (* inductive datatype *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   776
						let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   777
							val index               = #index info
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   778
							val descr               = #descr info
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   779
							val (_, dtyps, constrs) = (valOf o assoc) (descr, index)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   780
							val typ_assoc           = dtyps ~~ Ts
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   781
							(* sanity check: every element in 'dtyps' must be a 'DtTFree' *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   782
							val _ = (if Library.exists (fn d =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   783
									case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   784
								then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   785
									raise REFUTE ("ground_types", "datatype argument (for type " ^ Sign.string_of_typ (sign_of thy) (Type (s, Ts)) ^ ") is not a variable")
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   786
								else
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   787
									())
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   788
							(* if the current type is a recursive IDT (i.e. a depth is required), add it to 'acc' *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   789
							val acc' = (if Library.exists (fn (_, ds) => Library.exists DatatypeAux.is_rec_type ds) constrs then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   790
									T ins acc
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   791
								else
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   792
									acc)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   793
							(* collect argument types *)
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15571
diff changeset
   794
							val acc_args = foldr collect_types acc' Ts
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   795
							(* collect constructor types *)
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15571
diff changeset
   796
							val acc_constrs = foldr collect_types acc_args (List.concat (map (fn (_, ds) => map (typ_of_dtyp descr typ_assoc) ds) constrs))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   797
						in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   798
							acc_constrs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   799
						end
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   800
					| NONE =>  (* not an inductive datatype, e.g. defined via "typedef" or "typedecl" *)
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15571
diff changeset
   801
						T ins (foldr collect_types acc Ts))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   802
				| TFree _                => T ins acc
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   803
				| TVar _                 => T ins acc)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   804
	in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   805
		it_term_types collect_types (t, [])
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   806
	end;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   808
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   809
(* string_of_typ: (rather naive) conversion from types to strings, used to   *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   810
(*                look up the size of a type in 'sizes'.  Parameterized      *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   811
(*                types with different parameters (e.g. "'a list" vs. "bool  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   812
(*                list") are identified.                                     *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   813
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   814
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   815
	(* Term.typ -> string *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   816
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   817
	fun string_of_typ (Type (s, _))     = s
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   818
	  | string_of_typ (TFree (s, _))    = s
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   819
	  | string_of_typ (TVar ((s,_), _)) = s;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   820
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   821
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   822
(* first_universe: returns the "first" (i.e. smallest) universe by assigning *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   823
(*                 'minsize' to every type for which no size is specified in *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   824
(*                 'sizes'                                                   *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   825
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   826
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   827
	(* Term.typ list -> (string * int) list -> int -> (Term.typ * int) list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   828
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   829
	fun first_universe xs sizes minsize =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   830
	let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   831
		fun size_of_typ T =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   832
			case assoc (sizes, string_of_typ T) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   833
			  SOME n => n
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   834
			| NONE   => minsize
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   835
	in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   836
		map (fn T => (T, size_of_typ T)) xs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   837
	end;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   838
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   839
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   840
(* next_universe: enumerates all universes (i.e. assignments of sizes to     *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   841
(*                types), where the minimal size of a type is given by       *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   842
(*                'minsize', the maximal size is given by 'maxsize', and a   *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   843
(*                type may have a fixed size given in 'sizes'                *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   844
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   845
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   846
	(* (Term.typ * int) list -> (string * int) list -> int -> int -> (Term.typ * int) list option *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   847
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   848
	fun next_universe xs sizes minsize maxsize =
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   849
	let
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   850
		(* creates the "first" list of length 'len', where the sum of all list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   851
		(* elements is 'sum', and the length of the list is 'len'              *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   852
		(* int -> int -> int -> int list option *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   853
		fun make_first _ 0 sum =
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   854
			if sum=0 then
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   855
				SOME []
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   856
			else
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   857
				NONE
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   858
		  | make_first max len sum =
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   859
			if sum<=max orelse max<0 then
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   860
				Option.map (fn xs' => sum :: xs') (make_first max (len-1) 0)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   861
			else
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   862
				Option.map (fn xs' => max :: xs') (make_first max (len-1) (sum-max))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   863
		(* enumerates all int lists with a fixed length, where 0<=x<='max' for *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   864
		(* all list elements x (unless 'max'<0)                                *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   865
		(* int -> int -> int -> int list -> int list option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   866
		fun next max len sum [] =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   867
			NONE
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   868
		  | next max len sum [x] =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   869
			(* we've reached the last list element, so there's no shift possible *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   870
			make_first max (len+1) (sum+x+1)  (* increment 'sum' by 1 *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   871
		  | next max len sum (x1::x2::xs) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   872
			if x1>0 andalso (x2<max orelse max<0) then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   873
				(* we can shift *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   874
				SOME (valOf (make_first max (len+1) (sum+x1-1)) @ (x2+1) :: xs)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   875
			else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   876
				(* continue search *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   877
				next max (len+1) (sum+x1) (x2::xs)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   878
		(* only consider those types for which the size is not fixed *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   879
		val mutables = List.filter (fn (T, _) => assoc (sizes, string_of_typ T) = NONE) xs
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   880
		(* subtract 'minsize' from every size (will be added again at the end) *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   881
		val diffs = map (fn (_, n) => n-minsize) mutables
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   882
	in
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   883
		case next (maxsize-minsize) 0 0 diffs of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   884
		  SOME diffs' =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   885
			(* merge with those types for which the size is fixed *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   886
			SOME (snd (foldl_map (fn (ds, (T, _)) =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   887
				case assoc (sizes, string_of_typ T) of
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   888
				  SOME n => (ds, (T, n))                    (* return the fixed size *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   889
				| NONE   => (tl ds, (T, minsize + hd ds)))  (* consume the head of 'ds', add 'minsize' *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   890
				(diffs', xs)))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   891
		| NONE =>
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   892
			NONE
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   893
	end;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   894
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   895
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   896
(* toTrue: converts the interpretation of a Boolean value to a propositional *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   897
(*         formula that is true iff the interpretation denotes "true"        *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   898
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   899
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   900
	(* interpretation -> prop_formula *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   901
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
   902
	fun toTrue (Leaf [fm, _]) = fm
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
   903
	  | toTrue _              = raise REFUTE ("toTrue", "interpretation does not denote a Boolean value");
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   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: 14604
diff 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: 14604
diff changeset
   906
(* toFalse: converts the interpretation of a Boolean value to a              *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   907
(*          propositional formula that is true iff the interpretation        *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   908
(*          denotes "false"                                                  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   909
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   910
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   911
	(* interpretation -> prop_formula *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   912
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
   913
	fun toFalse (Leaf [_, fm]) = fm
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
   914
	  | toFalse _              = raise REFUTE ("toFalse", "interpretation does not denote a Boolean value");
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   915
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   916
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   917
(* find_model: repeatedly calls 'interpret' with appropriate parameters,     *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   918
(*             applies a SAT solver, and (in case a model is found) displays *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   919
(*             the model to the user by calling 'print_model'                *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   920
(* thy       : the current theory                                            *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   921
(* {...}     : parameters that control the translation/model generation      *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   922
(* t         : term to be translated into a propositional formula            *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   923
(* negate    : if true, find a model that makes 't' false (rather than true) *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   924
(* Note: exception 'TimeOut' is raised if the algorithm does not terminate   *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   925
(*       within 'maxtime' seconds (if 'maxtime' >0)                          *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   926
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   927
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   928
	(* theory -> params -> Term.term -> bool -> unit *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   929
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   930
	fun find_model thy {sizes, minsize, maxsize, maxvars, maxtime, satsolver} t negate =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   931
	let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   932
		(* unit -> unit *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   933
		fun wrapper () =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   934
		let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   935
			(* Term.term list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   936
			val axioms = collect_axioms thy t
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   937
			(* Term.typ list *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   938
			val types  = Library.foldl (fn (acc, t') => acc union (ground_types thy t')) ([], t :: axioms)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   939
			val _      = writeln ("Ground types: "
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   940
				^ (if null types then "none."
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   941
				   else commas (map (Sign.string_of_typ (sign_of thy)) types)))
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   942
			(* we can only consider fragments of recursive IDTs, so we issue a  *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   943
			(* warning if the formula contains a recursive IDT                  *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   944
			(* TODO: no warning needed for /positive/ occurrences of IDTs       *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   945
			val _ = if Library.exists (fn
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   946
				  Type (s, _) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   947
					(case DatatypePackage.datatype_info thy s of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   948
					  SOME info =>  (* inductive datatype *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   949
						let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   950
							val index           = #index info
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   951
							val descr           = #descr info
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
   952
							val (_, _, constrs) = (valOf o assoc) (descr, index)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   953
						in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   954
							(* recursive datatype? *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   955
							Library.exists (fn (_, ds) => Library.exists DatatypeAux.is_rec_type ds) constrs
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   956
						end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   957
					| NONE => false)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   958
				| _ => false) types then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   959
					warning "Term contains a recursive datatype; countermodel(s) may be spurious!"
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   960
				else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   961
					()
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   962
			(* (Term.typ * int) list -> unit *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   963
			fun find_model_loop universe =
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
   964
			let
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   965
				val init_model             = (universe, [])
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   966
				val init_args              = {maxvars = maxvars, def_eq = false, next_idx = 1, bounds = [], wellformed = True}
14984
edbc81e60809 immediate_output;
wenzelm
parents: 14965
diff changeset
   967
				val _                      = immediate_output ("Translating term (sizes: " ^ commas (map (fn (_, n) => string_of_int n) universe) ^ ") ...")
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   968
				(* translate 't' and all axioms *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   969
				val ((model, args), intrs) = foldl_map (fn ((m, a), t') =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   970
					let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   971
						val (i, m', a') = interpret thy m a t'
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   972
					in
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   973
						(* set 'def_eq' to 'true' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   974
						((m', {maxvars = #maxvars a', def_eq = true, next_idx = #next_idx a', bounds = #bounds a', wellformed = #wellformed a'}), i)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   975
					end) ((init_model, init_args), t :: axioms)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   976
				(* make 't' either true or false, and make all axioms true, and *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   977
				(* add the well-formedness side condition                       *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   978
				val fm_t  = (if negate then toFalse else toTrue) (hd intrs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   979
				val fm_ax = PropLogic.all (map toTrue (tl intrs))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   980
				val fm    = PropLogic.all [#wellformed args, fm_ax, fm_t]
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
   981
			in
14984
edbc81e60809 immediate_output;
wenzelm
parents: 14965
diff changeset
   982
				immediate_output " invoking SAT solver...";
14965
7155b319eafa new SAT solver interface
webertj
parents: 14818
diff changeset
   983
				(case SatSolver.invoke_solver satsolver fm of
7155b319eafa new SAT solver interface
webertj
parents: 14818
diff changeset
   984
				  SatSolver.SATISFIABLE assignment =>
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   985
					(writeln " model found!";
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   986
					writeln ("*** Model found: ***\n" ^ print_model thy model (fn i => case assignment i of SOME b => b | NONE => true)))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   987
				| SatSolver.UNSATISFIABLE =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   988
					(immediate_output " no model exists.\n";
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   989
					case next_universe universe sizes minsize maxsize of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   990
					  SOME universe' => find_model_loop universe'
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   991
					| NONE           => writeln "Search terminated, no larger universe within the given limits.")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   992
				| SatSolver.UNKNOWN =>
14984
edbc81e60809 immediate_output;
wenzelm
parents: 14965
diff changeset
   993
					(immediate_output " no model found.\n";
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   994
					case next_universe universe sizes minsize maxsize of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
   995
					  SOME universe' => find_model_loop universe'
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   996
					| NONE           => writeln "Search terminated, no larger universe within the given limits.")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
   997
				) handle SatSolver.NOT_CONFIGURED =>
14965
7155b319eafa new SAT solver interface
webertj
parents: 14818
diff changeset
   998
					error ("SAT solver " ^ quote satsolver ^ " is not configured.")
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
   999
			end handle MAXVARS_EXCEEDED =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1000
				writeln ("\nSearch terminated, number of Boolean variables (" ^ string_of_int maxvars ^ " allowed) exceeded.")
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1001
			in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1002
				find_model_loop (first_universe types sizes minsize)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1003
			end
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1004
		in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1005
			(* some parameter sanity checks *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1006
			assert (minsize>=1) ("\"minsize\" is " ^ string_of_int minsize ^ ", must be at least 1");
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1007
			assert (maxsize>=1) ("\"maxsize\" is " ^ string_of_int maxsize ^ ", must be at least 1");
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1008
			assert (maxsize>=minsize) ("\"maxsize\" (=" ^ string_of_int maxsize ^ ") is less than \"minsize\" (=" ^ string_of_int minsize ^ ").");
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1009
			assert (maxvars>=0) ("\"maxvars\" is " ^ string_of_int maxvars ^ ", must be at least 0");
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1010
			assert (maxtime>=0) ("\"maxtime\" is " ^ string_of_int maxtime ^ ", must be at least 0");
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1011
			(* enter loop with or without time limit *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1012
			writeln ("Trying to find a model that " ^ (if negate then "refutes" else "satisfies") ^ ": "
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1013
				^ Sign.string_of_term (sign_of thy) t);
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1014
			if maxtime>0 then (
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1015
				TimeLimit.timeLimit (Time.fromSeconds (Int.toLarge maxtime))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1016
					wrapper ()
14965
7155b319eafa new SAT solver interface
webertj
parents: 14818
diff changeset
  1017
				handle TimeLimit.TimeOut =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1018
					writeln ("\nSearch terminated, time limit ("
14965
7155b319eafa new SAT solver interface
webertj
parents: 14818
diff changeset
  1019
						^ string_of_int maxtime ^ (if maxtime=1 then " second" else " seconds")
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1020
						^ ") exceeded.")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1021
			) else
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1022
				wrapper ()
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1023
		end;
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1024
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1025
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1026
(* ------------------------------------------------------------------------- *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1027
(* INTERFACE, PART 2: FINDING A MODEL                                        *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1028
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1029
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1030
(* ------------------------------------------------------------------------- *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1031
(* satisfy_term: calls 'find_model' to find a model that satisfies 't'       *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1032
(* params      : list of '(name, value)' pairs used to override default      *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1033
(*               parameters                                                  *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1034
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1035
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1036
	(* theory -> (string * string) list -> Term.term -> unit *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1037
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1038
	fun satisfy_term thy params t =
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1039
		find_model thy (actual_params thy params) t false;
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1040
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1041
(* ------------------------------------------------------------------------- *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1042
(* refute_term: calls 'find_model' to find a model that refutes 't'          *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1043
(* params     : list of '(name, value)' pairs used to override default       *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1044
(*              parameters                                                   *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1045
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1046
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1047
	(* theory -> (string * string) list -> Term.term -> unit *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1048
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1049
	fun refute_term thy params t =
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1050
	let
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1051
		(* disallow schematic type variables, since we cannot properly negate  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1052
		(* terms containing them (their logical meaning is that there EXISTS a *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1053
		(* type s.t. ...; to refute such a formula, we would have to show that *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1054
		(* for ALL types, not ...)                                             *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1055
		val _ = assert (null (term_tvars t)) "Term to be refuted contains schematic type variables"
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1056
		(* existential closure over schematic variables *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1057
		(* (Term.indexname * Term.typ) list *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1058
		val vars = sort_wrt (fst o fst) (map dest_Var (term_vars t))
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1059
		(* Term.term *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  1060
		val ex_closure = Library.foldl
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1061
			(fn (t', ((x, i), T)) => (HOLogic.exists_const T) $ Abs (x, T, abstract_over (Var ((x, i), T), t')))
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1062
			(t, vars)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1063
		(* If 't' is of type 'propT' (rather than 'boolT'), applying  *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1064
		(* 'HOLogic.exists_const' is not type-correct.  However, this *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1065
		(* is not really a problem as long as 'find_model' still      *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1066
		(* interprets the resulting term correctly, without checking  *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1067
		(* its type.                                                  *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1068
	in
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1069
		find_model thy (actual_params thy params) ex_closure true
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1070
	end;
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1071
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1072
(* ------------------------------------------------------------------------- *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1073
(* refute_subgoal: calls 'refute_term' on a specific subgoal                 *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1074
(* params        : list of '(name, value)' pairs used to override default    *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1075
(*                 parameters                                                *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1076
(* subgoal       : 0-based index specifying the subgoal number               *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1077
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1078
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1079
	(* theory -> (string * string) list -> Thm.thm -> int -> unit *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1080
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1081
	fun refute_subgoal thy params thm subgoal =
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  1082
		refute_term thy params (List.nth (prems_of thm, subgoal));
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1083
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1084
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1085
(* ------------------------------------------------------------------------- *)
15292
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1086
(* INTERPRETERS: Auxiliary Functions                                         *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1087
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1088
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1089
(* ------------------------------------------------------------------------- *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1090
(* make_constants: returns all interpretations that have the same tree       *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1091
(*                 structure as 'intr', but consist of unit vectors with     *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1092
(*                 'True'/'False' only (no Boolean variables)                *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1093
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1094
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1095
	(* interpretation -> interpretation list *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1096
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1097
	fun make_constants intr =
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1098
	let
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1099
		(* returns a list with all unit vectors of length n *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1100
		(* int -> interpretation list *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1101
		fun unit_vectors n =
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1102
		let
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1103
			(* returns the k-th unit vector of length n *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1104
			(* int * int -> interpretation *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1105
			fun unit_vector (k,n) =
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1106
				Leaf ((replicate (k-1) False) @ (True :: (replicate (n-k) False)))
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1107
			(* int -> interpretation list -> interpretation list *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1108
			fun unit_vectors_acc k vs =
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1109
				if k>n then [] else (unit_vector (k,n))::(unit_vectors_acc (k+1) vs)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1110
		in
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1111
			unit_vectors_acc 1 []
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1112
		end
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1113
		(* concatenates 'x' with every list in 'xss', returning a new list of lists *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1114
		(* 'a -> 'a list list -> 'a list list *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1115
		fun cons_list x xss =
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1116
			map (fn xs => x::xs) xss
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1117
		(* returns a list of lists, each one consisting of n (possibly identical) elements from 'xs' *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1118
		(* int -> 'a list -> 'a list list *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1119
		fun pick_all 1 xs =
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1120
			map (fn x => [x]) xs
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1121
		  | pick_all n xs =
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1122
			let val rec_pick = pick_all (n-1) xs in
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1123
				Library.foldl (fn (acc, x) => (cons_list x rec_pick) @ acc) ([], xs)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1124
			end
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1125
	in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1126
		case intr of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1127
		  Leaf xs => unit_vectors (length xs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1128
		| Node xs => map (fn xs' => Node xs') (pick_all (length xs) (make_constants (hd xs)))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1129
	end;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1130
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1131
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1132
(* size_of_type: returns the number of constants in a type (i.e. 'length     *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1133
(*               (make_constants intr)', but implemented more efficiently)   *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1134
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1135
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1136
	(* interpretation -> int *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1137
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1138
	fun size_of_type intr =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1139
	let
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1140
		(* power (a, b) computes a^b, for a>=0, b>=0 *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1141
		(* int * int -> int *)
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1142
		fun power (a, 0) = 1
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1143
		  | power (a, 1) = a
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1144
		  | power (a, b) = let val ab = power(a, b div 2) in ab * ab * power(a, b mod 2) end
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1145
	in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1146
		case intr of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1147
		  Leaf xs => length xs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1148
		| Node xs => power (size_of_type (hd xs), length xs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1149
	end;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1150
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1151
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1152
(* TT/FF: interpretations that denote "true" or "false", respectively        *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1153
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1154
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1155
	(* interpretation *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1156
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1157
	val TT = Leaf [True, False];
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1158
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1159
	val FF = Leaf [False, True];
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1160
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1161
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1162
(* make_equality: returns an interpretation that denotes (extensional)       *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1163
(*                equality of two interpretations                            *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1164
(* - two interpretations are 'equal' iff they are both defined and denote    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1165
(*   the same value                                                          *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1166
(* - two interpretations are 'not_equal' iff they are both defined at least  *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1167
(*   partially, and a defined part denotes different values                  *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1168
(* - a completely undefined interpretation is neither 'equal' nor            *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1169
(*   'not_equal' to another interpretation                                   *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1170
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1171
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1172
	(* We could in principle represent '=' on a type T by a particular        *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1173
	(* interpretation.  However, the size of that interpretation is quadratic *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1174
	(* in the size of T.  Therefore comparing the interpretations 'i1' and    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1175
	(* 'i2' directly is more efficient than constructing the interpretation   *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1176
	(* for equality on T first, and "applying" this interpretation to 'i1'    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1177
	(* and 'i2' in the usual way (cf. 'interpretation_apply') then.           *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1178
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1179
	(* interpretation * interpretation -> interpretation *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1180
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1181
	fun make_equality (i1, i2) =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1182
	let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1183
		(* interpretation * interpretation -> prop_formula *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1184
		fun equal (i1, i2) =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1185
			(case i1 of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1186
			  Leaf xs =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1187
				(case i2 of
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1188
				  Leaf ys => PropLogic.dot_product (xs, ys)  (* defined and equal *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1189
				| Node _  => raise REFUTE ("make_equality", "second interpretation is higher"))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1190
			| Node xs =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1191
				(case i2 of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1192
				  Leaf _  => raise REFUTE ("make_equality", "first interpretation is higher")
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1193
				| Node ys => PropLogic.all (map equal (xs ~~ ys))))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1194
		(* interpretation * interpretation -> prop_formula *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1195
		fun not_equal (i1, i2) =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1196
			(case i1 of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1197
			  Leaf xs =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1198
				(case i2 of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1199
				  Leaf ys => PropLogic.all ((PropLogic.exists xs) :: (PropLogic.exists ys) ::
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1200
					(map (fn (x,y) => SOr (SNot x, SNot y)) (xs ~~ ys)))  (* defined and not equal *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1201
				| Node _  => raise REFUTE ("make_equality", "second interpretation is higher"))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1202
			| Node xs =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1203
				(case i2 of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1204
				  Leaf _  => raise REFUTE ("make_equality", "first interpretation is higher")
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1205
				| Node ys => PropLogic.exists (map not_equal (xs ~~ ys))))
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1206
	in
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1207
		(* a value may be undefined; therefore 'not_equal' is not just the     *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1208
		(* negation of 'equal'                                                 *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1209
		Leaf [equal (i1, i2), not_equal (i1, i2)]
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1210
	end;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1211
15292
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1212
(* ------------------------------------------------------------------------- *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1213
(* make_def_equality: returns an interpretation that denotes (extensional)   *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1214
(*                    equality of two interpretations                        *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1215
(* This function treats undefined/partially defined interpretations          *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1216
(* different from 'make_equality': two undefined interpretations are         *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1217
(* considered equal, while a defined interpretation is considered not equal  *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1218
(* to an undefined interpretation.                                           *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1219
(* ------------------------------------------------------------------------- *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1220
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1221
	(* interpretation * interpretation -> interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1222
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1223
	fun make_def_equality (i1, i2) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1224
	let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1225
		(* interpretation * interpretation -> prop_formula *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1226
		fun equal (i1, i2) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1227
			(case i1 of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1228
			  Leaf xs =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1229
				(case i2 of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1230
				  Leaf ys => SOr (PropLogic.dot_product (xs, ys),  (* defined and equal, or both undefined *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1231
					SAnd (PropLogic.all (map SNot xs), PropLogic.all (map SNot ys)))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1232
				| Node _  => raise REFUTE ("make_def_equality", "second interpretation is higher"))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1233
			| Node xs =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1234
				(case i2 of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1235
				  Leaf _  => raise REFUTE ("make_def_equality", "first interpretation is higher")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1236
				| Node ys => PropLogic.all (map equal (xs ~~ ys))))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1237
		(* interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1238
		val eq = equal (i1, i2)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1239
	in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1240
		Leaf [eq, SNot eq]
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1241
	end;
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1242
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1243
(* ------------------------------------------------------------------------- *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1244
(* interpretation_apply: returns an interpretation that denotes the result   *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1245
(*                       of applying the function denoted by 'i2' to the     *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1246
(*                       argument denoted by 'i2'                            *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1247
(* ------------------------------------------------------------------------- *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1248
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1249
	(* interpretation * interpretation -> interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1250
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1251
	fun interpretation_apply (i1, i2) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1252
	let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1253
		(* interpretation * interpretation -> interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1254
		fun interpretation_disjunction (tr1,tr2) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1255
			tree_map (fn (xs,ys) => map (fn (x,y) => SOr(x,y)) (xs ~~ ys)) (tree_pair (tr1,tr2))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1256
		(* prop_formula * interpretation -> interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1257
		fun prop_formula_times_interpretation (fm,tr) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1258
			tree_map (map (fn x => SAnd (fm,x))) tr
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1259
		(* prop_formula list * interpretation list -> interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1260
		fun prop_formula_list_dot_product_interpretation_list ([fm],[tr]) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1261
			prop_formula_times_interpretation (fm,tr)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1262
		  | prop_formula_list_dot_product_interpretation_list (fm::fms,tr::trees) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1263
			interpretation_disjunction (prop_formula_times_interpretation (fm,tr), prop_formula_list_dot_product_interpretation_list (fms,trees))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1264
		  | prop_formula_list_dot_product_interpretation_list (_,_) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1265
			raise REFUTE ("interpretation_apply", "empty list (in dot product)")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1266
		(* concatenates 'x' with every list in 'xss', returning a new list of lists *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1267
		(* 'a -> 'a list list -> 'a list list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1268
		fun cons_list x xss =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1269
			map (fn xs => x::xs) xss
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1270
		(* returns a list of lists, each one consisting of one element from each element of 'xss' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1271
		(* 'a list list -> 'a list list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1272
		fun pick_all [xs] =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1273
			map (fn x => [x]) xs
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1274
		  | pick_all (xs::xss) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1275
			let val rec_pick = pick_all xss in
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1276
				Library.foldl (fn (acc, x) => (cons_list x rec_pick) @ acc) ([], xs)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1277
			end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1278
		  | pick_all _ =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1279
			raise REFUTE ("interpretation_apply", "empty list (in pick_all)")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1280
		(* interpretation -> prop_formula list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1281
		fun interpretation_to_prop_formula_list (Leaf xs) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1282
			xs
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1283
		  | interpretation_to_prop_formula_list (Node trees) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1284
			map PropLogic.all (pick_all (map interpretation_to_prop_formula_list trees))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1285
	in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1286
		case i1 of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1287
		  Leaf _ =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1288
			raise REFUTE ("interpretation_apply", "first interpretation is a leaf")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1289
		| Node xs =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1290
			prop_formula_list_dot_product_interpretation_list (interpretation_to_prop_formula_list i2, xs)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1291
	end;
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1292
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1293
(* ------------------------------------------------------------------------- *)
15292
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1294
(* eta_expand: eta-expands a term 't' by adding 'i' lambda abstractions      *)
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1295
(* ------------------------------------------------------------------------- *)
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1296
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1297
	(* Term.term -> int -> Term.term *)
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1298
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1299
	fun eta_expand t i =
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1300
	let
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1301
		val Ts = binder_types (fastype_of t)
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1302
	in
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15571
diff changeset
  1303
		foldr (fn (T, t) => Abs ("<eta_expand>", T, t))
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15571
diff changeset
  1304
			(list_comb (t, map Bound (i-1 downto 0))) (Library.take (i, Ts))
15292
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1305
	end;
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1306
15335
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1307
(* ------------------------------------------------------------------------- *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1308
(* sum: returns the sum of a list 'xs' of integers                           *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1309
(* ------------------------------------------------------------------------- *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1310
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1311
	(* int list -> int *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1312
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1313
	fun sum xs = foldl op+ 0 xs;
15335
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1314
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1315
(* ------------------------------------------------------------------------- *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1316
(* product: returns the product of a list 'xs' of integers                   *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1317
(* ------------------------------------------------------------------------- *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1318
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1319
	(* int list -> int *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1320
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1321
	fun product xs = foldl op* 1 xs;
15335
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1322
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1323
(* ------------------------------------------------------------------------- *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1324
(* size_of_dtyp: the size of (an initial fragment of) an inductive data type *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1325
(*               is the sum (over its constructors) of the product (over     *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1326
(*               their arguments) of the size of the argument types          *)
15335
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1327
(* ------------------------------------------------------------------------- *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1328
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1329
	(* theory -> (Term.typ * int) list -> DatatypeAux.descr -> (DatatypeAux.dtyp * Term.typ) list -> (string * DatatypeAux.dtyp list) list -> int *)
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1330
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1331
	fun size_of_dtyp thy typ_sizes descr typ_assoc constructors =
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1332
		sum (map (fn (_, dtyps) =>
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1333
			product (map (fn dtyp =>
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1334
				let
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1335
					val T         = typ_of_dtyp descr typ_assoc dtyp
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1336
					val (i, _, _) = interpret thy (typ_sizes, []) {maxvars=0, def_eq = false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
15335
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1337
				in
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1338
					size_of_type i
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1339
				end) dtyps)) constructors);
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1340
15292
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1341
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1342
(* ------------------------------------------------------------------------- *)
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1343
(* INTERPRETERS: Actual Interpreters                                         *)
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1344
(* ------------------------------------------------------------------------- *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1345
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1346
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1347
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1348
	(* simply typed lambda calculus: Isabelle's basic term syntax, with type  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1349
	(* variables, function types, and propT                                   *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1350
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1351
	fun stlc_interpreter thy model args t =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1352
	let
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1353
		val (typs, terms)                                   = model
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1354
		val {maxvars, def_eq, next_idx, bounds, wellformed} = args
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1355
		(* Term.typ -> (interpretation * model * arguments) option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1356
		fun interpret_groundterm T =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1357
		let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1358
			(* unit -> (interpretation * model * arguments) option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1359
			fun interpret_groundtype () =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1360
			let
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  1361
				val size = (if T = Term.propT then 2 else (valOf o assoc) (typs, T))                    (* the model MUST specify a size for ground types *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1362
				val next = next_idx+size
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1363
				val _    = (if next-1>maxvars andalso maxvars>0 then raise MAXVARS_EXCEEDED else ())  (* check if 'maxvars' is large enough *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1364
				(* prop_formula list *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1365
				val fms  = map BoolVar (next_idx upto (next_idx+size-1))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1366
				(* interpretation *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1367
				val intr = Leaf fms
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1368
				(* prop_formula list -> prop_formula *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1369
				fun one_of_two_false []      = True
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1370
				  | one_of_two_false (x::xs) = SAnd (PropLogic.all (map (fn x' => SOr (SNot x, SNot x')) xs), one_of_two_false xs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1371
				(* prop_formula *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1372
				val wf   = one_of_two_false fms
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1373
			in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1374
				(* extend the model, increase 'next_idx', add well-formedness condition *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1375
				SOME (intr, (typs, (t, intr)::terms), {maxvars = maxvars, def_eq = def_eq, next_idx = next, bounds = bounds, wellformed = SAnd (wellformed, wf)})
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1376
			end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1377
		in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1378
			case T of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1379
			  Type ("fun", [T1, T2]) =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1380
				let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1381
					(* we create 'size_of_type (interpret (... T1))' different copies *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1382
					(* of the interpretation for 'T2', which are then combined into a *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1383
					(* single new interpretation                                      *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1384
					val (i1, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T1))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1385
					(* make fresh copies, with different variable indices *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1386
					(* 'idx': next variable index                         *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1387
					(* 'n'  : number of copies                            *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1388
					(* int -> int -> (int * interpretation list * prop_formula *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1389
					fun make_copies idx 0 =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1390
						(idx, [], True)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1391
					  | make_copies idx n =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1392
						let
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1393
							val (copy, _, new_args) = interpret thy (typs, []) {maxvars = maxvars, def_eq = false, next_idx = idx, bounds = [], wellformed = True} (Free ("dummy", T2))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1394
							val (idx', copies, wf') = make_copies (#next_idx new_args) (n-1)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1395
						in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1396
							(idx', copy :: copies, SAnd (#wellformed new_args, wf'))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1397
						end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1398
					val (next, copies, wf) = make_copies next_idx (size_of_type i1)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1399
					(* combine copies into a single interpretation *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1400
					val intr = Node copies
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1401
				in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1402
					(* extend the model, increase 'next_idx', add well-formedness condition *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1403
					SOME (intr, (typs, (t, intr)::terms), {maxvars = maxvars, def_eq = def_eq, next_idx = next, bounds = bounds, wellformed = SAnd (wellformed, wf)})
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1404
				end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1405
			| Type _  => interpret_groundtype ()
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1406
			| TFree _ => interpret_groundtype ()
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1407
			| TVar  _ => interpret_groundtype ()
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1408
		end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1409
	in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1410
		case assoc (terms, t) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1411
		  SOME intr =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1412
			(* return an existing interpretation *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1413
			SOME (intr, model, args)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1414
		| NONE =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1415
			(case t of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1416
			  Const (_, T)     =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1417
				interpret_groundterm T
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1418
			| Free (_, T)      =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1419
				interpret_groundterm T
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1420
			| Var (_, T)       =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1421
				interpret_groundterm T
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1422
			| Bound i          =>
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  1423
				SOME (List.nth (#bounds args, i), model, args)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1424
			| Abs (x, T, body) =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1425
				let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1426
					(* create all constants of type 'T' *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1427
					val (i, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1428
					val constants = make_constants i
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1429
					(* interpret the 'body' separately for each constant *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1430
					val ((model', args'), bodies) = foldl_map
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1431
						(fn ((m, a), c) =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1432
							let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1433
								(* add 'c' to 'bounds' *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1434
								val (i', m', a') = interpret thy m {maxvars = #maxvars a, def_eq = #def_eq a, next_idx = #next_idx a, bounds = (c :: #bounds a), wellformed = #wellformed a} body
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1435
							in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1436
								(* keep the new model m' and 'next_idx' and 'wellformed', but use old 'bounds' *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1437
								((m', {maxvars = maxvars, def_eq = def_eq, next_idx = #next_idx a', bounds = bounds, wellformed = #wellformed a'}), i')
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1438
							end)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1439
						((model, args), constants)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1440
				in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1441
					SOME (Node bodies, model', args')
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1442
				end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1443
			| t1 $ t2          =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1444
				let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1445
					(* interpret 't1' and 't2' separately *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1446
					val (intr1, model1, args1) = interpret thy model args t1
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1447
					val (intr2, model2, args2) = interpret thy model1 args1 t2
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1448
				in
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1449
					SOME (interpretation_apply (intr1, intr2), model2, args2)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1450
				end)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1451
	end;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1452
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1453
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1454
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1455
	fun Pure_interpreter thy model args t =
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  1456
		case t of
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1457
		  Const ("all", _) $ t1 =>  (* in the meta-logic, 'all' MUST be followed by an argument term *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1458
			let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1459
				val (i, m, a) = interpret thy model args t1
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1460
			in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1461
				case i of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1462
				  Node xs =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1463
					let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1464
						val fmTrue  = PropLogic.all (map toTrue xs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1465
						val fmFalse = PropLogic.exists (map toFalse xs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1466
					in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1467
						SOME (Leaf [fmTrue, fmFalse], m, a)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1468
					end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1469
				| _ =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1470
					raise REFUTE ("Pure_interpreter", "\"all\" is not followed by a function")
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1471
			end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1472
		| Const ("==", _) $ t1 $ t2 =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1473
			let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1474
				val (i1, m1, a1) = interpret thy model args t1
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1475
				val (i2, m2, a2) = interpret thy m1 a1 t2
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1476
			in
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1477
				(* we use either 'make_def_equality' or 'make_equality' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1478
				SOME ((if #def_eq args then make_def_equality else make_equality) (i1, i2), m2, a2)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1479
			end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1480
		| Const ("==>", _) =>  (* simpler than translating 'Const ("==>", _) $ t1 $ t2' *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1481
			SOME (Node [Node [TT, FF], Node [TT, TT]], model, args)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1482
		| _ => NONE;
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1483
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1484
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1485
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1486
	fun HOLogic_interpreter thy model args t =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1487
	(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1488
	(* Providing interpretations directly is more efficient than unfolding the   *)
15283
f21466450330 DOCTYPE declaration added
webertj
parents: 15280
diff changeset
  1489
	(* logical constants.  In HOL however, logical constants can themselves be   *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1490
	(* arguments.  "All" and "Ex" are then translated just like any other        *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1491
	(* constant, with the relevant axiom being added by 'collect_axioms'.        *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1492
	(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1493
		case t of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1494
		  Const ("Trueprop", _) =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1495
			SOME (Node [TT, FF], model, args)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1496
		| Const ("Not", _) =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1497
			SOME (Node [FF, TT], model, args)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1498
		| Const ("True", _) =>  (* redundant, since 'True' is also an IDT constructor *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1499
			SOME (TT, model, args)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1500
		| Const ("False", _) =>  (* redundant, since 'False' is also an IDT constructor *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1501
			SOME (FF, model, args)
15333
77b2bca7fcb5 comments edited
webertj
parents: 15292
diff changeset
  1502
		| Const ("All", _) $ t1 =>
77b2bca7fcb5 comments edited
webertj
parents: 15292
diff changeset
  1503
		(* if "All" occurs without an argument (i.e. as argument to a higher-order *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1504
		(* function or predicate), it is handled by the 'stlc_interpreter' (i.e.   *)
15333
77b2bca7fcb5 comments edited
webertj
parents: 15292
diff changeset
  1505
		(* by unfolding its definition)                                            *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  1506
			let
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1507
				val (i, m, a) = interpret thy model args t1
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1508
			in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1509
				case i of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1510
				  Node xs =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1511
					let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1512
						val fmTrue  = PropLogic.all (map toTrue xs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1513
						val fmFalse = PropLogic.exists (map toFalse xs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1514
					in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1515
						SOME (Leaf [fmTrue, fmFalse], m, a)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1516
					end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1517
				| _ =>
15292
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1518
					raise REFUTE ("HOLogic_interpreter", "\"All\" is followed by a non-function")
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1519
			end
15333
77b2bca7fcb5 comments edited
webertj
parents: 15292
diff changeset
  1520
		| Const ("Ex", _) $ t1 =>
77b2bca7fcb5 comments edited
webertj
parents: 15292
diff changeset
  1521
		(* if "Ex" occurs without an argument (i.e. as argument to a higher-order  *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1522
		(* function or predicate), it is handled by the 'stlc_interpreter' (i.e.   *)
15333
77b2bca7fcb5 comments edited
webertj
parents: 15292
diff changeset
  1523
		(* by unfolding its definition)                                            *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1524
			let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1525
				val (i, m, a) = interpret thy model args t1
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1526
			in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1527
				case i of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1528
				  Node xs =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1529
					let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1530
						val fmTrue  = PropLogic.exists (map toTrue xs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1531
						val fmFalse = PropLogic.all (map toFalse xs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1532
					in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1533
						SOME (Leaf [fmTrue, fmFalse], m, a)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1534
					end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1535
				| _ =>
15292
09e218879265 minor changes (comments/code refactoring)
webertj
parents: 15283
diff changeset
  1536
					raise REFUTE ("HOLogic_interpreter", "\"Ex\" is followed by a non-function")
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1537
			end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1538
		| Const ("op =", _) $ t1 $ t2 =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1539
			let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1540
				val (i1, m1, a1) = interpret thy model args t1
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1541
				val (i2, m2, a2) = interpret thy m1 a1 t2
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1542
			in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1543
				SOME (make_equality (i1, i2), m2, a2)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1544
			end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1545
		| Const ("op =", _) $ t1 =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1546
			SOME (interpret thy model args (eta_expand t 1))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1547
		| Const ("op =", _) =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1548
			SOME (interpret thy model args (eta_expand t 2))
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1549
		| Const ("op &", _) $ t1 $ t2 =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1550
			(* 3-valued logic *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1551
			let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1552
				val (i1, m1, a1) = interpret thy model args t1
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1553
				val (i2, m2, a2) = interpret thy m1 a1 t2
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1554
				val fmTrue       = PropLogic.SAnd (toTrue i1, toTrue i2)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1555
				val fmFalse      = PropLogic.SOr (toFalse i1, toFalse i2)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1556
			in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1557
				SOME (Leaf [fmTrue, fmFalse], m2, a2)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1558
			end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1559
		| Const ("op &", _) $ t1 =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1560
			SOME (interpret thy model args (eta_expand t 1))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1561
		| Const ("op &", _) =>
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1562
			SOME (interpret thy model args (eta_expand t 2))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1563
			(* SOME (Node [Node [TT, FF], Node [FF, FF]], model, args) *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1564
		| Const ("op |", _) $ t1 $ t2 =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1565
			(* 3-valued logic *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1566
			let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1567
				val (i1, m1, a1) = interpret thy model args t1
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1568
				val (i2, m2, a2) = interpret thy m1 a1 t2
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1569
				val fmTrue       = PropLogic.SOr (toTrue i1, toTrue i2)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1570
				val fmFalse      = PropLogic.SAnd (toFalse i1, toFalse i2)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1571
			in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1572
				SOME (Leaf [fmTrue, fmFalse], m2, a2)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1573
			end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1574
		| Const ("op |", _) $ t1 =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1575
			SOME (interpret thy model args (eta_expand t 1))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1576
		| Const ("op |", _) =>
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1577
			SOME (interpret thy model args (eta_expand t 2))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1578
			(* SOME (Node [Node [TT, TT], Node [TT, FF]], model, args) *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1579
		| Const ("op -->", _) $ t1 $ t2 =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1580
			(* 3-valued logic *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1581
			let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1582
				val (i1, m1, a1) = interpret thy model args t1
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1583
				val (i2, m2, a2) = interpret thy m1 a1 t2
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1584
				val fmTrue       = PropLogic.SOr (toFalse i1, toTrue i2)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1585
				val fmFalse      = PropLogic.SAnd (toTrue i1, toFalse i2)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1586
			in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1587
				SOME (Leaf [fmTrue, fmFalse], m2, a2)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1588
			end
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1589
		| Const ("op -->", _) =>
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1590
			(* SOME (Node [Node [TT, FF], Node [TT, TT]], model, args) *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1591
			SOME (interpret thy model args (eta_expand t 2))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1592
		| _ => NONE;
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1593
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1594
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1595
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1596
	fun set_interpreter thy model args t =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1597
	(* "T set" is isomorphic to "T --> bool" *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1598
	let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1599
		val (typs, terms) = model
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1600
	in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1601
		case assoc (terms, t) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1602
		  SOME intr =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1603
			(* return an existing interpretation *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1604
			SOME (intr, model, args)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff 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: 14604
diff changeset
  1606
			(case t of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1607
			  Free (x, Type ("set", [T])) =>
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
  1608
				let
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1609
					val (intr, _, args') = interpret thy (typs, []) args (Free (x, T --> HOLogic.boolT))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1610
				in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1611
					SOME (intr, (typs, (t, intr)::terms), args')
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
  1612
				end
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1613
			| Var ((x, i), Type ("set", [T])) =>
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
  1614
				let
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1615
					val (intr, _, args') = interpret thy (typs, []) args (Var ((x,i), T --> HOLogic.boolT))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1616
				in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1617
					SOME (intr, (typs, (t, intr)::terms), args')
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
  1618
				end
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1619
			| Const (s, Type ("set", [T])) =>
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
  1620
				let
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1621
					val (intr, _, args') = interpret thy (typs, []) args (Const (s, T --> HOLogic.boolT))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1622
				in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1623
					SOME (intr, (typs, (t, intr)::terms), args')
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
  1624
				end
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1625
			(* 'Collect' == identity *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1626
			| Const ("Collect", _) $ t1 =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1627
				SOME (interpret thy model args t1)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1628
			| Const ("Collect", _) =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1629
				SOME (interpret thy model args (eta_expand t 1))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1630
			(* 'op :' == application *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1631
			| Const ("op :", _) $ t1 $ t2 =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1632
				SOME (interpret thy model args (t2 $ t1))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1633
			| Const ("op :", _) $ t1 =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1634
				SOME (interpret thy model args (eta_expand t 1))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1635
			| Const ("op :", _) =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1636
				SOME (interpret thy model args (eta_expand t 2))
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1637
			| _ => NONE)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1638
	end;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1639
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1640
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1641
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1642
	(* interprets variables and constants whose type is an IDT; constructors of  *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1643
	(* IDTs are properly interpreted by 'IDT_constructor_interpreter' however    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1644
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1645
	fun IDT_interpreter thy model args t =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1646
	let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1647
		val (typs, terms) = model
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1648
		(* Term.typ -> (interpretation * model * arguments) option *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1649
		fun interpret_term (Type (s, Ts)) =
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1650
			(case DatatypePackage.datatype_info thy s of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1651
			  SOME info =>  (* inductive datatype *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1652
				let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1653
					(* int option -- only recursive IDTs have an associated depth *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1654
					val depth = assoc (typs, Type (s, Ts))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1655
				in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1656
					if depth = (SOME 0) then  (* termination condition to avoid infinite recursion *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1657
						(* return a leaf of size 0 *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1658
						SOME (Leaf [], model, args)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1659
					else
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1660
						let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1661
							val index               = #index info
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1662
							val descr               = #descr info
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  1663
							val (_, dtyps, constrs) = (valOf o assoc) (descr, index)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1664
							val typ_assoc           = dtyps ~~ Ts
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1665
							(* sanity check: every element in 'dtyps' must be a 'DtTFree' *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1666
							val _ = (if Library.exists (fn d =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1667
									case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1668
								then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1669
									raise REFUTE ("IDT_interpreter", "datatype argument (for type " ^ Sign.string_of_typ (sign_of thy) (Type (s, Ts)) ^ ") is not a variable")
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1670
								else
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1671
									())
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1672
							(* if the model specifies a depth for the current type, decrement it to avoid infinite recursion *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1673
							val typs'    = (case depth of NONE => typs | SOME n => overwrite (typs, (Type (s, Ts), n-1)))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1674
							(* recursively compute the size of the datatype *)
15335
f81e6e24351f minor code refactoring (typ_of_dtyp, size_of_dtyp)
webertj
parents: 15334
diff changeset
  1675
							val size     = size_of_dtyp thy typs' descr typ_assoc constrs
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1676
							val next_idx = #next_idx args
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1677
							val next     = next_idx+size
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1678
							val _        = (if next-1>(#maxvars args) andalso (#maxvars args)>0 then raise MAXVARS_EXCEEDED else ())  (* check if 'maxvars' is large enough *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1679
							(* prop_formula list *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1680
							val fms      = map BoolVar (next_idx upto (next_idx+size-1))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1681
							(* interpretation *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1682
							val intr     = Leaf fms
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1683
							(* prop_formula list -> prop_formula *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1684
							fun one_of_two_false []      = True
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1685
							  | one_of_two_false (x::xs) = SAnd (PropLogic.all (map (fn x' => SOr (SNot x, SNot x')) xs), one_of_two_false xs)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1686
							(* prop_formula *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1687
							val wf       = one_of_two_false fms
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1688
						in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1689
							(* extend the model, increase 'next_idx', add well-formedness condition *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1690
							SOME (intr, (typs, (t, intr)::terms), {maxvars = #maxvars args, def_eq = #def_eq args, next_idx = next, bounds = #bounds args, wellformed = SAnd (#wellformed args, wf)})
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1691
						end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1692
				end
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1693
			| NONE =>  (* not an inductive datatype *)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1694
				NONE)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1695
		  | interpret_term _ =  (* a (free or schematic) type variable *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1696
			NONE
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1697
	in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1698
		case assoc (terms, t) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1699
		  SOME intr =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1700
			(* return an existing interpretation *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1701
			SOME (intr, model, args)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  1702
		| NONE =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1703
			(case t of
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1704
			  Free (_, T)  => interpret_term T
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1705
			| Var (_, T)   => interpret_term T
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1706
			| Const (_, T) => interpret_term T
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1707
			| _            => NONE)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1708
	end;
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1709
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1710
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1711
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1712
	fun IDT_constructor_interpreter thy model args t =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1713
	let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1714
		val (typs, terms) = model
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1715
	in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1716
		case assoc (terms, t) of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1717
		  SOME intr =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1718
			(* return an existing interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1719
			SOME (intr, model, args)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1720
		| NONE =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1721
			(case t of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1722
			  Const (s, T) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1723
				(case body_type T of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1724
				  Type (s', Ts') =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1725
					(case DatatypePackage.datatype_info thy s' of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1726
					  SOME info =>  (* body type is an inductive datatype *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1727
						let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1728
							val index               = #index info
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1729
							val descr               = #descr info
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  1730
							val (_, dtyps, constrs) = (valOf o assoc) (descr, index)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1731
							val typ_assoc           = dtyps ~~ Ts'
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1732
							(* sanity check: every element in 'dtyps' must be a 'DtTFree' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1733
							val _ = (if Library.exists (fn d =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1734
									case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1735
								then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1736
									raise REFUTE ("IDT_constructor_interpreter", "datatype argument (for type " ^ Sign.string_of_typ (sign_of thy) (Type (s', Ts')) ^ ") is not a variable")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1737
								else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1738
									())
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1739
							(* split the constructors into those occuring before/after 'Const (s, T)' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1740
							val (constrs1, constrs2) = take_prefix (fn (cname, ctypes) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1741
								not (cname = s andalso Type.typ_instance (Sign.tsig_of (sign_of thy)) (T,
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1742
									map (typ_of_dtyp descr typ_assoc) ctypes ---> Type (s', Ts')))) constrs
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1743
						in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1744
							case constrs2 of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1745
							  [] =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1746
								(* 'Const (s, T)' is not a constructor of this datatype *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1747
								NONE
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1748
							| (_, ctypes)::cs =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1749
								let
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1750
									(* compute the total size of the datatype (with the current depth) *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1751
									val (i, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type (s', Ts')))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1752
									val total     = size_of_type i
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1753
									(* int option -- only recursive IDTs have an associated depth *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1754
									val depth = assoc (typs, Type (s', Ts'))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1755
									val typs' = (case depth of NONE => typs | SOME n => overwrite (typs, (Type (s', Ts'), n-1)))
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1756
									(* returns an interpretation where everything is mapped to "undefined" *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1757
									(* DatatypeAux.dtyp list -> interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1758
									fun make_undef [] =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1759
										Leaf (replicate total False)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1760
									  | make_undef (d::ds) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1761
										let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1762
											(* compute the current size of the type 'd' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1763
											val T           = typ_of_dtyp descr typ_assoc d
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1764
											val (i, _, _)   = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1765
											val size        = size_of_type i
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1766
										in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1767
											Node (replicate size (make_undef ds))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1768
										end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1769
									(* returns the interpretation for a constructor at depth 1 *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1770
									(* int * DatatypeAux.dtyp list -> int * interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1771
									fun make_constr (offset, []) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1772
										if offset<total then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1773
											(offset+1, Leaf ((replicate offset False) @ True :: (replicate (total-offset-1) False)))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1774
										else
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1775
											raise REFUTE ("IDT_constructor_interpreter", "offset >= total")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1776
									  | make_constr (offset, d::ds) =
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1777
										let
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1778
											(* compute the current and the old size of the type 'd' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1779
											val T           = typ_of_dtyp descr typ_assoc d
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1780
											val (i, _, _)   = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1781
											val size        = size_of_type i
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1782
											val (i', _, _)  = interpret thy (typs', []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1783
											val size'       = size_of_type i'
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1784
											(* sanity check *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1785
											val _           = if size < size' then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1786
													raise REFUTE ("IDT_constructor_interpreter", "current size is less than old size")
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1787
												else
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1788
													()
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1789
											(* int * interpretation list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1790
											val (new_offset, intrs) = foldl_map make_constr (offset, replicate size' ds)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1791
											(* interpretation list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1792
											val undefs              = replicate (size - size') (make_undef ds)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1793
										in
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1794
											(* elements that exist at the previous depth are mapped to a defined *)
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1795
											(* value, while new elements are mapped to "undefined" by the        *)
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1796
											(* recursive constructor                                             *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1797
											(new_offset, Node (intrs @ undefs))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1798
										end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1799
									(* extends the interpretation for a constructor (both recursive *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1800
									(* and non-recursive) obtained at depth n (n>=1) to depth n+1   *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1801
									(* int * DatatypeAux.dtyp list * interpretation -> int * interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1802
									fun extend_constr (offset, [], Leaf xs) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1803
										let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1804
											(* returns the k-th unit vector of length n *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1805
											(* int * int -> interpretation *)
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1806
											fun unit_vector (k, n) =
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1807
												Leaf ((replicate (k-1) False) @ (True :: (replicate (n-k) False)))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1808
											(* int *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1809
											val k = find_index_eq True xs
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1810
										in
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1811
											if k=(~1) then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1812
												(* if the element was mapped to "undefined" before, map it to   *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1813
												(* the value given by 'offset' now (and extend the length of    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1814
												(* the leaf)                                                    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1815
												(offset+1, unit_vector (offset+1, total))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1816
											else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1817
												(* if the element was already mapped to a defined value, map it *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1818
												(* to the same value again, just extend the length of the leaf, *)
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1819
												(* do not increment the 'offset'                                *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1820
												(offset, unit_vector (k+1, total))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1821
										end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1822
									  | extend_constr (_, [], Node _) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1823
										raise REFUTE ("IDT_constructor_interpreter", "interpretation for constructor (with no arguments left) is a node")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1824
									  | extend_constr (offset, d::ds, Node xs) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1825
										let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1826
											(* compute the size of the type 'd' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1827
											val T          = typ_of_dtyp descr typ_assoc d
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1828
											val (i, _, _)  = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1829
											val size       = size_of_type i
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1830
											(* sanity check *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1831
											val _          = if size < length xs then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1832
													raise REFUTE ("IDT_constructor_interpreter", "new size of type is less than old size")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1833
												else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1834
													()
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1835
											(* extend the existing interpretations *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1836
											(* int * interpretation list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1837
											val (new_offset, intrs) = foldl_map (fn (off, i) => extend_constr (off, ds, i)) (offset, xs)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1838
											(* new elements of the type 'd' are mapped to "undefined" *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1839
											val undefs = replicate (size - length xs) (make_undef ds)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1840
										in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1841
											(new_offset, Node (intrs @ undefs))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1842
										end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1843
									  | extend_constr (_, d::ds, Leaf _) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1844
										raise REFUTE ("IDT_constructor_interpreter", "interpretation for constructor (with arguments left) is a leaf")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1845
									(* returns 'true' iff the constructor has a recursive argument *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1846
									(* DatatypeAux.dtyp list -> bool *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1847
									fun is_rec_constr ds =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1848
										Library.exists DatatypeAux.is_rec_type ds
15611
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1849
									(* constructors before 'Const (s, T)' generate elements of the datatype *)
c01f11cd08f9 Bugfix related to the interpretation of IDT constructors
webertj
parents: 15574
diff changeset
  1850
									val offset = size_of_dtyp thy typs' descr typ_assoc constrs1
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1851
								in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1852
									case depth of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1853
									  NONE =>  (* equivalent to a depth of 1 *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1854
										SOME (snd (make_constr (offset, ctypes)), model, args)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1855
									| SOME 0 =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1856
										raise REFUTE ("IDT_constructor_interpreter", "depth is 0")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1857
									| SOME 1 =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1858
										SOME (snd (make_constr (offset, ctypes)), model, args)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1859
									| SOME n =>  (* n > 1 *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1860
										let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1861
											(* interpret the constructor at depth-1 *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1862
											val (iC, _, _) = interpret thy (typs', []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Const (s, T))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1863
											(* elements generated by the constructor at depth-1 must be added to 'offset' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1864
											(* interpretation -> int *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1865
											fun number_of_defined_elements (Leaf xs) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1866
												if find_index_eq True xs = (~1) then 0 else 1
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1867
											  | number_of_defined_elements (Node xs) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1868
												sum (map number_of_defined_elements xs)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1869
											(* int *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1870
											val offset' = offset + number_of_defined_elements iC
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1871
										in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1872
											SOME (snd (extend_constr (offset', ctypes, iC)), model, args)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1873
										end
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1874
								end
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1875
						end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1876
					| NONE =>  (* body type is not an inductive datatype *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1877
						NONE)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1878
				| _ =>  (* body type is a (free or schematic) type variable *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1879
					NONE)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1880
			| _ =>  (* term is not a constant *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1881
				NONE)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1882
	end;
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1883
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1884
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  1885
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1886
	(* Difficult code ahead.  Make sure you understand the 'IDT_constructor_interpreter' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1887
	(* and the order in which it enumerates elements of an IDT before you try to         *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1888
	(* understand this function.                                                         *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1889
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1890
	fun IDT_recursion_interpreter thy model args t =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1891
		case strip_comb t of  (* careful: here we descend arbitrarily deep into 't', *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1892
		                      (* possibly before any other interpreter for atomic    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1893
		                      (* terms has had a chance to look at 't'               *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1894
		  (Const (s, T), params) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1895
			(* iterate over all datatypes in 'thy' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1896
			Symtab.foldl (fn (result, (_, info)) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1897
				case result of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1898
				  SOME _ =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1899
					result  (* just keep 'result' *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1900
				| NONE =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1901
					if s mem (#rec_names info) then
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1902
						(* we do have a recursion operator of the datatype given by 'info', *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1903
						(* or of a mutually recursive datatype                              *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1904
						let
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1905
							val index              = #index info
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1906
							val descr              = #descr info
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1907
							val (dtname, dtyps, _) = (valOf o assoc) (descr, index)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1908
							(* number of all constructors, including those of different           *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1909
							(* (mutually recursive) datatypes within the same descriptor 'descr'  *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1910
							val mconstrs_count     = sum (map (fn (_, (_, _, cs)) => length cs) descr)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1911
							val params_count       = length params
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1912
							(* the type of a recursion operator: [T1, ..., Tn, IDT] ---> Tresult *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1913
							val IDT = List.nth (binder_types T, mconstrs_count)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1914
						in
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1915
							if (fst o dest_Type) IDT <> dtname then
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1916
								(* recursion operator of a mutually recursive datatype *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1917
								NONE
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1918
							else if mconstrs_count < params_count then
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1919
								(* too many actual parameters; for now we'll use the *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1920
								(* 'stlc_interpreter' to strip off one application   *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1921
								NONE
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1922
							else if mconstrs_count > params_count then
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1923
								(* too few actual parameters; we use eta expansion            *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1924
								(* Note that the resulting expansion of lambda abstractions   *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1925
								(* by the 'stlc_interpreter' may be rather slow (depending on *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1926
								(* the argument types and the size of the IDT, of course).    *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1927
								SOME (interpret thy model args (eta_expand t (mconstrs_count - params_count)))
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1928
							else  (* mconstrs_count = params_count *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1929
								let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1930
									(* interpret each parameter separately *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1931
									val ((model', args'), p_intrs) = foldl_map (fn ((m, a), p) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1932
										let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1933
											val (i, m', a') = interpret thy m a p
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1934
										in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1935
											((m', a'), i)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1936
										end) ((model, args), params)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1937
									val (typs, _) = model'
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1938
									val typ_assoc = dtyps ~~ (snd o dest_Type) IDT
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1939
									(* interpret each constructor in the descriptor (including *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1940
									(* those of mutually recursive datatypes)                  *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1941
									(* (int * interpretation list) list *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1942
									val mc_intrs = map (fn (idx, (_, _, cs)) =>
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1943
										let
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1944
											val c_return_typ = typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec idx)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1945
										in
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1946
											(idx, map (fn (cname, cargs) =>
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1947
												(#1 o interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True})
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1948
													(Const (cname, map (typ_of_dtyp descr typ_assoc) cargs ---> c_return_typ))) cs)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1949
										end) descr
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1950
									(* the recursion operator is a function that maps every element of *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1951
									(* the inductive datatype (and of mutually recursive types) to an  *)
15783
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  1952
									(* element of some result type; an array entry of NONE means that  *)
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  1953
									(* the actual result has not been computed yet                     *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1954
									(* (int * interpretation option Array.array) list *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1955
									val INTRS = map (fn (idx, _) =>
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1956
										let
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1957
											val T         = typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec idx)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1958
											val (i, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1959
											val size      = size_of_type i
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1960
										in
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1961
											(idx, Array.array (size, NONE))
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1962
										end) descr
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1963
									(* takes an interpretation, and if some leaf of this interpretation   *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1964
									(* is the 'elem'-th element of the type, the indices of the arguments *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1965
									(* leading to this leaf are returned                                  *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1966
									(* interpretation -> int -> int list option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1967
									fun get_args (Leaf xs) elem =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1968
										if find_index_eq True xs = elem then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1969
											SOME []
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1970
										else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1971
											NONE
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1972
									  | get_args (Node xs) elem =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1973
										let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1974
											(* interpretation * int -> int list option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1975
											fun search ([], _) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1976
												NONE
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1977
											  | search (x::xs, n) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1978
												(case get_args x elem of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1979
												  SOME result => SOME (n::result)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1980
												| NONE        => search (xs, n+1))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1981
										in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1982
											search (xs, 0)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1983
										end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1984
									(* returns the index of the constructor and indices for its      *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1985
									(* arguments that generate the 'elem'-th element of the datatype *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1986
									(* given by 'idx'                                                *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1987
									(* int -> int -> int * int list *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1988
									fun get_cargs idx elem =
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1989
										let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1990
											(* int * interpretation list -> int * int list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1991
											fun get_cargs_rec (_, []) =
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1992
												raise REFUTE ("IDT_recursion_interpreter", "no matching constructor found for element " ^ string_of_int elem ^ " in datatype " ^ Sign.string_of_typ (sign_of thy) IDT ^ " (datatype index " ^ string_of_int idx ^ ")")
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1993
											  | get_cargs_rec (n, x::xs) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1994
												(case get_args x elem of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1995
												  SOME args => (n, args)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1996
												| NONE      => get_cargs_rec (n+1, xs))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1997
										in
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  1998
											get_cargs_rec (0, (valOf o assoc) (mc_intrs, idx))
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  1999
										end
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2000
									(* returns the number of constructors in datatypes that occur in *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2001
									(* the descriptor 'descr' before the datatype given by 'idx'     *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2002
									fun get_coffset idx =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2003
										let
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2004
											fun get_coffset_acc _ [] =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2005
												raise REFUTE ("IDT_recursion_interpreter", "index " ^ string_of_int idx ^ " not found in descriptor")
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2006
											  | get_coffset_acc sum ((i, (_, _, cs))::descr') =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2007
												if i=idx then
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2008
													sum
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2009
												else
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2010
													get_coffset_acc (sum + length cs) descr'
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2011
										in
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2012
											get_coffset_acc 0 descr
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2013
										end
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2014
									(* computes one entry in INTRS, and recursively all entries needed for it, *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2015
									(* where 'idx' gives the datatype and 'elem' the element of it             *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2016
									(* int -> int -> interpretation *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2017
									fun compute_array_entry idx elem =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2018
										case Array.sub ((valOf o assoc) (INTRS, idx), elem) of
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2019
										  SOME result =>
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2020
											(* simply return the previously computed result *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2021
											result
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2022
										| NONE =>
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2023
											let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2024
												(* int * int list *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2025
												val (c, args) = get_cargs idx elem
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2026
												(* interpretation * int list -> interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2027
												fun select_subtree (tr, []) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2028
													tr  (* return the whole tree *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2029
												  | select_subtree (Leaf _, _) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2030
													raise REFUTE ("IDT_recursion_interpreter", "interpretation for parameter is a leaf; cannot select a subtree")
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2031
												  | select_subtree (Node tr, x::xs) =
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  2032
													select_subtree (List.nth (tr, x), xs)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2033
												(* select the correct subtree of the parameter corresponding to constructor 'c' *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2034
												val p_intr = select_subtree (List.nth (p_intrs, get_coffset idx + c), args)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2035
												(* find the indices of the constructor's recursive arguments *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2036
												val (_, _, constrs) = (valOf o assoc) (descr, idx)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2037
												val constr_args     = (snd o List.nth) (constrs, c)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2038
												val rec_args        = List.filter (DatatypeAux.is_rec_type o fst) (constr_args ~~ args)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2039
												val rec_args'       = map (fn (dtyp, elem) => (DatatypeAux.dest_DtRec dtyp, elem)) rec_args
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2040
												(* apply 'p_intr' to recursively computed results *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2041
												val result = foldl (fn ((idx, elem), intr) =>
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2042
													interpretation_apply (intr, compute_array_entry idx elem)) p_intr rec_args'
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2043
												(* update 'INTRS' *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2044
												val _ = Array.update ((valOf o assoc) (INTRS, idx), elem, SOME result)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2045
											in
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2046
												result
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2047
											end
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2048
									(* compute all entries in INTRS for the current datatype (given by 'index') *)
15783
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2049
									(* TODO: we can use Array.modify instead once PolyML conforms to the ML standard *)
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2050
									(* (int * 'a -> 'a) -> 'a array -> unit *)
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2051
									fun modifyi f arr =
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2052
										let
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2053
											val size = Array.length arr
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2054
											fun modifyi_loop i =
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2055
												if i < size then (
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2056
													Array.update (arr, i, f (i, Array.sub (arr, i)));
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2057
													modifyi_loop (i+1)
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2058
												) else
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2059
													()
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2060
										in
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2061
											modifyi_loop 0
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2062
										end
82e40c9a0f3f call to Array.modifyi replaced
webertj
parents: 15768
diff changeset
  2063
									val _ = modifyi (fn (i, _) => SOME (compute_array_entry index i)) ((valOf o assoc) (INTRS, index))
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2064
									(* 'a Array.array -> 'a list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2065
									fun toList arr =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2066
										Array.foldr op:: [] arr
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2067
								in
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2068
									(* return the part of 'INTRS' that corresponds to the current datatype *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2069
									SOME ((Node o (map valOf) o toList o valOf o assoc) (INTRS, index), model', args')
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2070
								end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2071
						end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2072
					else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2073
						NONE  (* not a recursion operator of this datatype *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2074
				) (NONE, DatatypePackage.get_datatypes thy)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2075
		| _ =>  (* head of term is not a constant *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2076
			NONE;
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2077
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2078
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2079
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2080
	(* only an optimization: 'card' could in principle be interpreted with    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2081
	(* interpreters available already (using its definition), but the code    *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2082
	(* below is more efficient                                                *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2083
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2084
	fun Finite_Set_card_interpreter thy model args t =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2085
		case t of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2086
		  Const ("Finite_Set.card", Type ("fun", [Type ("set", [T]), Type ("nat", [])])) =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2087
			let
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2088
				val (i_nat, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("nat", [])))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2089
				val size_nat      = size_of_type i_nat
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2090
				val (i_set, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T])))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2091
				val constants     = make_constants i_set
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2092
				(* interpretation -> int *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2093
				fun number_of_elements (Node xs) =
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  2094
					Library.foldl (fn (n, x) =>
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2095
						if x=TT then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2096
							n+1
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2097
						else if x=FF then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2098
							n
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2099
						else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2100
							raise REFUTE ("Finite_Set_card_interpreter", "interpretation for set type does not yield a Boolean")) (0, xs)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2101
				  | number_of_elements (Leaf _) =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2102
					raise REFUTE ("Finite_Set_card_interpreter", "interpretation for set type is a leaf")
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2103
				(* takes an interpretation for a set and returns an interpretation for a 'nat' *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2104
				(* interpretation -> interpretation *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2105
				fun card i =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2106
					let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2107
						val n = number_of_elements i
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2108
					in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2109
						if n<size_nat then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2110
							Leaf ((replicate n False) @ True :: (replicate (size_nat-n-1) False))
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  2111
						else
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2112
							Leaf (replicate size_nat False)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2113
					end
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2114
			in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2115
				SOME (Node (map card constants), model, args)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2116
			end
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2117
		| _ =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2118
			NONE;
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2119
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2120
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2121
15571
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2122
	(* only an optimization: 'Finites' could in principle be interpreted with *)
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2123
	(* interpreters available already (using its definition), but the code    *)
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2124
	(* below is more efficient                                                *)
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2125
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2126
	fun Finite_Set_Finites_interpreter thy model args t =
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2127
		case t of
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2128
		  Const ("Finite_Set.Finites", Type ("set", [Type ("set", [T])])) =>
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2129
			let
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2130
				val (i_set, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T])))
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2131
				val size_set      = size_of_type i_set
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2132
			in
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2133
				(* we only consider finite models anyway, hence EVERY set is in "Finites" *)
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2134
				SOME (Node (replicate size_set TT), model, args)
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2135
			end
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2136
		| _ =>
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2137
			NONE;
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2138
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2139
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2140
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2141
	(* only an optimization: 'op <' could in principle be interpreted with    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2142
	(* interpreters available already (using its definition), but the code    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2143
	(* below is more efficient                                                *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2144
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2145
	fun Nat_less_interpreter thy model args t =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2146
		case t of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2147
		  Const ("op <", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("bool", [])])])) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2148
			let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2149
				val (i_nat, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("nat", [])))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2150
				val size_nat      = size_of_type i_nat
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2151
				(* int -> interpretation *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2152
				(* the 'n'-th nat is not less than the first 'n' nats, while it *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2153
				(* is less than the remaining 'size_nat - n' nats               *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2154
				fun less n = Node ((replicate n FF) @ (replicate (size_nat - n) TT))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2155
			in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2156
				SOME (Node (map less (1 upto size_nat)), model, args)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2157
			end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2158
		| _ =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2159
			NONE;
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2160
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2161
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2162
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2163
	(* only an optimization: 'op +' could in principle be interpreted with    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2164
	(* interpreters available already (using its definition), but the code    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2165
	(* below is more efficient                                                *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2166
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2167
	fun Nat_plus_interpreter thy model args t =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2168
		case t of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2169
		  Const ("op +", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2170
			let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2171
				val (i_nat, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("nat", [])))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2172
				val size_nat      = size_of_type i_nat
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2173
				(* int -> int -> interpretation *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2174
				fun plus m n =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2175
					let
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2176
						val element = (m+n)+1
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2177
					in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2178
						if element > size_nat then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2179
							Leaf (replicate size_nat False)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2180
						else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2181
							Leaf ((replicate (element-1) False) @ True :: (replicate (size_nat - element) False))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2182
					end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2183
			in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2184
				SOME (Node (map (fn m => Node (map (plus m) (0 upto size_nat-1))) (0 upto size_nat-1)), model, args)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2185
			end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2186
		| _ =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2187
			NONE;
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2188
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2189
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2190
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2191
	(* only an optimization: 'op -' could in principle be interpreted with    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2192
	(* interpreters available already (using its definition), but the code    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2193
	(* below is more efficient                                                *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2194
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2195
	fun Nat_minus_interpreter thy model args t =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2196
		case t of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2197
		  Const ("op -", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2198
			let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2199
				val (i_nat, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("nat", [])))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2200
				val size_nat      = size_of_type i_nat
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2201
				(* int -> int -> interpretation *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2202
				fun minus m n =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2203
					let
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2204
						val element = Int.max (m-n, 0) + 1
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2205
					in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2206
						Leaf ((replicate (element-1) False) @ True :: (replicate (size_nat - element) False))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2207
					end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2208
			in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2209
				SOME (Node (map (fn m => Node (map (minus m) (0 upto size_nat-1))) (0 upto size_nat-1)), model, args)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2210
			end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2211
		| _ =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2212
			NONE;
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2213
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2214
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2215
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2216
	(* only an optimization: 'op *' could in principle be interpreted with    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2217
	(* interpreters available already (using its definition), but the code    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2218
	(* below is more efficient                                                *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2219
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2220
	fun Nat_mult_interpreter thy model args t =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2221
		case t of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2222
		  Const ("op *", Type ("fun", [Type ("nat", []), Type ("fun", [Type ("nat", []), Type ("nat", [])])])) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2223
			let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2224
				val (i_nat, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("nat", [])))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2225
				val size_nat      = size_of_type i_nat
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2226
				(* nat -> nat -> interpretation *)
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2227
				fun mult m n =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2228
					let
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2229
						val element = (m*n)+1
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2230
					in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2231
						if element > size_nat then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2232
							Leaf (replicate size_nat False)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2233
						else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2234
							Leaf ((replicate (element-1) False) @ True :: (replicate (size_nat - element) False))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2235
					end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2236
			in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2237
				SOME (Node (map (fn m => Node (map (mult m) (0 upto size_nat-1))) (0 upto size_nat-1)), model, args)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2238
			end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2239
		| _ =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2240
			NONE;
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2241
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2242
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2243
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2244
	(* only an optimization: 'op @' could in principle be interpreted with    *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2245
	(* interpreters available already (using its definition), but the code    *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2246
	(* below is more efficient                                                *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2247
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2248
	fun List_append_interpreter thy model args t =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2249
		case t of
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2250
		  Const ("List.op @", Type ("fun", [Type ("List.list", [T]), Type ("fun", [Type ("List.list", [_]), Type ("List.list", [_])])])) =>
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2251
			let
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2252
				val (i_elem, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2253
				val size_elem      = size_of_type i_elem
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2254
				val (i_list, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("List.list", [T])))
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2255
				val size_list      = size_of_type i_list
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2256
				(* power (a, b) computes a^b, for a>=0, b>=0 *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2257
				(* int * int -> int *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2258
				fun power (a, 0) = 1
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2259
				  | power (a, 1) = a
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2260
				  | power (a, b) = let val ab = power(a, b div 2) in ab * ab * power(a, b mod 2) end
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2261
				(* log (a, b) computes floor(log_a(b)), i.e. the largest integer x s.t. a^x <= b, for a>=2, b>=1 *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2262
				(* int * int -> int *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2263
				fun log (a, b) =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2264
					let
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2265
						fun logloop (ax, x) =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2266
							if ax > b then x-1 else logloop (a * ax, x+1)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2267
					in
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2268
						logloop (1, 0)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2269
					end
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2270
				(* nat -> nat -> interpretation *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2271
				fun append m n =
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2272
					let
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2273
						(* The following formula depends on the order in which lists are *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2274
						(* enumerated by the 'IDT_constructor_interpreter'.  It took me  *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2275
						(* a while to come up with this formula.                         *)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2276
						val element = n + m * (if size_elem = 1 then 1 else power (size_elem, log (size_elem, n+1))) + 1
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2277
					in
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2278
						if element > size_list then
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2279
							Leaf (replicate size_list False)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2280
						else
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2281
							Leaf ((replicate (element-1) False) @ True :: (replicate (size_list - element) False))
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2282
					end
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2283
			in
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2284
				SOME (Node (map (fn m => Node (map (append m) (0 upto size_list-1))) (0 upto size_list-1)), model, args)
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2285
			end
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2286
		| _ =>
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2287
			NONE;
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2288
16050
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2289
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2290
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2291
	(* only an optimization: 'lfp' could in principle be interpreted with     *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2292
	(* interpreters available already (using its definition), but the code    *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2293
	(* below is more efficient                                                *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2294
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2295
	fun Lfp_lfp_interpreter thy model args t =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2296
		case t of
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2297
		  Const ("Lfp.lfp", Type ("fun", [Type ("fun", [Type ("set", [T]), Type ("set", [_])]), Type ("set", [_])])) =>
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2298
			let
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2299
				val (i_elem, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2300
				val size_elem      = size_of_type i_elem
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2301
				(* the universe (i.e. the set that contains every element) *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2302
				val i_univ         = Node (replicate size_elem TT)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2303
				(* all sets with elements from type 'T' *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2304
				val (i_set, _, _)  = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T])))
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2305
				val i_sets         = make_constants i_set
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2306
				(* all functions that map sets to sets *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2307
				val (i_fun, _, _)  = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("fun", [Type ("set", [T]), Type ("set", [T])])))
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2308
				val i_funs         = make_constants i_fun
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2309
				(* "lfp(f) == Inter({u. f(u) <= u})" *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2310
				(* interpretation * interpretation -> bool *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2311
				fun is_subset (Node subs, Node sups) =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2312
					List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) (subs ~~ sups)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2313
				  | is_subset (_, _) =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2314
					raise REFUTE ("Lfp_lfp_interpreter", "is_subset: interpretation for set is not a node")
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2315
				(* interpretation * interpretation -> interpretation *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2316
				fun intersection (Node xs, Node ys) =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2317
					Node (map (fn (x, y) => if (x = TT) andalso (y = TT) then TT else FF) (xs ~~ ys))
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2318
				  | intersection (_, _) =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2319
					raise REFUTE ("Lfp_lfp_interpreter", "intersection: interpretation for set is not a node")
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2320
				(* interpretation -> interpretaion *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2321
				fun lfp (Node resultsets) =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2322
					foldl (fn ((set, resultset), acc) =>
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2323
						if is_subset (resultset, set) then
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2324
							intersection (acc, set)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2325
						else
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2326
							acc) i_univ (i_sets ~~ resultsets)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2327
				  | lfp _ =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2328
						raise REFUTE ("Lfp_lfp_interpreter", "lfp: interpretation for function is not a node")
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2329
			in
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2330
				SOME (Node (map lfp i_funs), model, args)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2331
			end
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2332
		| _ =>
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2333
			NONE;
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2334
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2335
	(* theory -> model -> arguments -> Term.term -> (interpretation * model * arguments) option *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2336
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2337
	(* only an optimization: 'gfp' could in principle be interpreted with     *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2338
	(* interpreters available already (using its definition), but the code    *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2339
	(* below is more efficient                                                *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2340
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2341
	fun Gfp_gfp_interpreter thy model args t =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2342
		case t of
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2343
		  Const ("Gfp.gfp", Type ("fun", [Type ("fun", [Type ("set", [T]), Type ("set", [_])]), Type ("set", [_])])) =>
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2344
			let
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2345
				val (i_elem, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2346
				val size_elem      = size_of_type i_elem
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2347
				(* the universe (i.e. the set that contains every element) *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2348
				val i_univ         = Node (replicate size_elem TT)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2349
				(* all sets with elements from type 'T' *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2350
				val (i_set, _, _)  = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("set", [T])))
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2351
				val i_sets         = make_constants i_set
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2352
				(* all functions that map sets to sets *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2353
				val (i_fun, _, _)  = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", Type ("fun", [Type ("set", [T]), Type ("set", [T])])))
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2354
				val i_funs         = make_constants i_fun
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2355
				(* "gfp(f) == Union({u. u <= f(u)})" *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2356
				(* interpretation * interpretation -> bool *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2357
				fun is_subset (Node subs, Node sups) =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2358
					List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) (subs ~~ sups)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2359
				  | is_subset (_, _) =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2360
					raise REFUTE ("Gfp_gfp_interpreter", "is_subset: interpretation for set is not a node")
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2361
				(* interpretation * interpretation -> interpretation *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2362
				fun union (Node xs, Node ys) =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2363
					Node (map (fn (x, y) => if (x = TT) orelse (y = TT) then TT else FF) (xs ~~ ys))
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2364
				  | union (_, _) =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2365
					raise REFUTE ("Lfp_lfp_interpreter", "union: interpretation for set is not a node")
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2366
				(* interpretation -> interpretaion *)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2367
				fun gfp (Node resultsets) =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2368
					foldl (fn ((set, resultset), acc) =>
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2369
						if is_subset (set, resultset) then
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2370
							union (acc, set)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2371
						else
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2372
							acc) i_univ (i_sets ~~ resultsets)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2373
				  | gfp _ =
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2374
						raise REFUTE ("Gfp_gfp_interpreter", "gfp: interpretation for function is not a node")
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2375
			in
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2376
				SOME (Node (map gfp i_funs), model, args)
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2377
			end
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2378
		| _ =>
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2379
			NONE;
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2380
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2381
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2382
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2383
(* PRINTERS                                                                  *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2384
(* ------------------------------------------------------------------------- *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2385
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2386
	(* theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2387
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2388
	fun stlc_printer thy model t intr assignment =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2389
	let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2390
		(* Term.term -> Term.typ option *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2391
		fun typeof (Free (_, T))  = SOME T
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2392
		  | typeof (Var (_, T))   = SOME T
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2393
		  | typeof (Const (_, T)) = SOME T
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2394
		  | typeof _              = NONE
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2395
		(* string -> string *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2396
		fun strip_leading_quote s =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2397
			(implode o (fn ss => case ss of [] => [] | x::xs => if x="'" then xs else ss) o explode) s
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2398
		(* Term.typ -> string *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2399
		fun string_of_typ (Type (s, _))     = s
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2400
		  | string_of_typ (TFree (x, _))    = strip_leading_quote x
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2401
		  | string_of_typ (TVar ((x,i), _)) = strip_leading_quote x ^ string_of_int i
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2402
		(* interpretation -> int *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2403
		fun index_from_interpretation (Leaf xs) =
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2404
			find_index (PropLogic.eval assignment) xs
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2405
		  | index_from_interpretation _ =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2406
			raise REFUTE ("stlc_printer", "interpretation for ground type is not a leaf")
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2407
	in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2408
		case typeof t of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2409
		  SOME T =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2410
			(case T of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2411
			  Type ("fun", [T1, T2]) =>
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
  2412
				let
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2413
					(* create all constants of type 'T1' *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2414
					val (i, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T1))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2415
					val constants = make_constants i
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2416
					(* interpretation list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2417
					val results = (case intr of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2418
						  Node xs => xs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2419
						| _       => raise REFUTE ("stlc_printer", "interpretation for function type is a leaf"))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2420
					(* Term.term list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2421
					val pairs = map (fn (arg, result) =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2422
						HOLogic.mk_prod
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2423
							(print thy model (Free ("dummy", T1)) arg assignment,
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2424
							 print thy model (Free ("dummy", T2)) result assignment))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2425
						(constants ~~ results)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2426
					(* Term.typ *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2427
					val HOLogic_prodT = HOLogic.mk_prodT (T1, T2)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2428
					val HOLogic_setT  = HOLogic.mk_setT HOLogic_prodT
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2429
					(* Term.term *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2430
					val HOLogic_empty_set = Const ("{}", HOLogic_setT)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2431
					val HOLogic_insert    = Const ("insert", HOLogic_prodT --> HOLogic_setT --> HOLogic_setT)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2432
				in
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15571
diff changeset
  2433
					SOME (foldr (fn (pair, acc) => HOLogic_insert $ pair $ acc) HOLogic_empty_set pairs)
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
  2434
				end
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2435
			| Type ("prop", [])      =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2436
				(case index_from_interpretation intr of
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2437
				  (~1) => SOME (HOLogic.mk_Trueprop (Const ("arbitrary", HOLogic.boolT)))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2438
				| 0    => SOME (HOLogic.mk_Trueprop HOLogic.true_const)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2439
				| 1    => SOME (HOLogic.mk_Trueprop HOLogic.false_const)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2440
				| _    => raise REFUTE ("stlc_interpreter", "illegal interpretation for a propositional value"))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2441
			| Type _  => if index_from_interpretation intr = (~1) then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2442
					SOME (Const ("arbitrary", T))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2443
				else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2444
					SOME (Const (string_of_typ T ^ string_of_int (index_from_interpretation intr), T))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2445
			| TFree _ => if index_from_interpretation intr = (~1) then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2446
					SOME (Const ("arbitrary", T))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2447
				else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2448
					SOME (Const (string_of_typ T ^ string_of_int (index_from_interpretation intr), T))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2449
			| TVar _  => if index_from_interpretation intr = (~1) then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2450
					SOME (Const ("arbitrary", T))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2451
				else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2452
					SOME (Const (string_of_typ T ^ string_of_int (index_from_interpretation intr), T)))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2453
		| NONE =>
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2454
			NONE
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2455
	end;
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2456
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  2457
	(* theory -> model -> Term.term -> interpretation -> (int -> bool) -> string option *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2458
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2459
	fun set_printer thy model t intr assignment =
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2460
	let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2461
		(* Term.term -> Term.typ option *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2462
		fun typeof (Free (_, T))  = SOME T
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2463
		  | typeof (Var (_, T))   = SOME T
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2464
		  | typeof (Const (_, T)) = SOME T
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2465
		  | typeof _              = NONE
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2466
	in
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2467
		case typeof t of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2468
		  SOME (Type ("set", [T])) =>
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
  2469
			let
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2470
				(* create all constants of type 'T' *)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2471
				val (i, _, _) = interpret thy model {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", T))
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2472
				val constants = make_constants i
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2473
				(* interpretation list *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2474
				val results = (case intr of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2475
					  Node xs => xs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2476
					| _       => raise REFUTE ("set_printer", "interpretation for set type is a leaf"))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2477
				(* Term.term list *)
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  2478
				val elements = List.mapPartial (fn (arg, result) =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2479
					case result of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2480
					  Leaf [fmTrue, fmFalse] =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2481
						if PropLogic.eval assignment fmTrue then
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2482
							SOME (print thy model (Free ("dummy", T)) arg assignment)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2483
						else (*if PropLogic.eval assignment fmFalse then*)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2484
							NONE
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2485
					| _ =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2486
						raise REFUTE ("set_printer", "illegal interpretation for a Boolean value"))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2487
					(constants ~~ results)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2488
				(* Term.typ *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2489
				val HOLogic_setT  = HOLogic.mk_setT T
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2490
				(* Term.term *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2491
				val HOLogic_empty_set = Const ("{}", HOLogic_setT)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2492
				val HOLogic_insert    = Const ("insert", T --> HOLogic_setT --> HOLogic_setT)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2493
			in
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  2494
				SOME (Library.foldl (fn (acc, elem) => HOLogic_insert $ elem $ acc) (HOLogic_empty_set, elements))
15334
d5a92997dc1b exception CANNOT_INTERPRET removed (not needed anymore since the stlc_interpreter can interpret any term)
webertj
parents: 15333
diff changeset
  2495
			end
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  2496
		| _ =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2497
			NONE
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2498
	end;
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2499
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2500
	(* theory -> model -> Term.term -> interpretation -> (int -> bool) -> Term.term option *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2501
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2502
	fun IDT_printer thy model t intr assignment =
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2503
	let
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2504
		(* Term.term -> Term.typ option *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2505
		fun typeof (Free (_, T))  = SOME T
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2506
		  | typeof (Var (_, T))   = SOME T
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2507
		  | typeof (Const (_, T)) = SOME T
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2508
		  | typeof _              = NONE
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2509
	in
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2510
		case typeof t of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2511
		  SOME (Type (s, Ts)) =>
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2512
			(case DatatypePackage.datatype_info thy s of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2513
			  SOME info =>  (* inductive datatype *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2514
				let
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2515
					val (typs, _)           = model
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2516
					val index               = #index info
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2517
					val descr               = #descr info
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  2518
					val (_, dtyps, constrs) = (valOf o assoc) (descr, index)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2519
					val typ_assoc           = dtyps ~~ Ts
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2520
					(* sanity check: every element in 'dtyps' must be a 'DtTFree' *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2521
					val _ = (if Library.exists (fn d =>
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2522
							case d of DatatypeAux.DtTFree _ => false | _ => true) dtyps
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2523
						then
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2524
							raise REFUTE ("IDT_printer", "datatype argument (for type " ^ Sign.string_of_typ (sign_of thy) (Type (s, Ts)) ^ ") is not a variable")
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2525
						else
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2526
							())
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2527
					(* the index of the element in the datatype *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2528
					val element = (case intr of
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2529
						  Leaf xs => find_index (PropLogic.eval assignment) xs
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2530
						| Node _  => raise REFUTE ("IDT_printer", "interpretation is not a leaf"))
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2531
				in
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2532
					if element < 0 then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2533
						SOME (Const ("arbitrary", Type (s, Ts)))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2534
					else let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2535
						(* takes a datatype constructor, and if for some arguments this constructor *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2536
						(* generates the datatype's element that is given by 'element', returns the *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2537
						(* constructor (as a term) as well as the indices of the arguments          *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2538
						(* string * DatatypeAux.dtyp list -> (Term.term * int list) option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2539
						fun get_constr_args (cname, cargs) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2540
							let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2541
								val cTerm      = Const (cname, (map (typ_of_dtyp descr typ_assoc) cargs) ---> Type (s, Ts))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2542
								val (iC, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} cTerm
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2543
								(* interpretation -> int list option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2544
								fun get_args (Leaf xs) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2545
									if find_index_eq True xs = element then
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2546
										SOME []
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2547
									else
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2548
										NONE
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2549
								  | get_args (Node xs) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2550
									let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2551
										(* interpretation * int -> int list option *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2552
										fun search ([], _) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2553
											NONE
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2554
										  | search (x::xs, n) =
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2555
											(case get_args x of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2556
											  SOME result => SOME (n::result)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2557
											| NONE        => search (xs, n+1))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2558
									in
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2559
										search (xs, 0)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2560
									end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2561
							in
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  2562
								Option.map (fn args => (cTerm, cargs, args)) (get_args iC)
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2563
							end
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2564
						(* Term.term * DatatypeAux.dtyp list * int list *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2565
						val (cTerm, cargs, args) = (case get_first get_constr_args constrs of
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2566
							  SOME x => x
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2567
							| NONE   => raise REFUTE ("IDT_printer", "no matching constructor found for element " ^ string_of_int element))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2568
						val argsTerms = map (fn (d, n) =>
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2569
							let
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2570
								val dT        = typ_of_dtyp descr typ_assoc d
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2571
								val (i, _, _) = interpret thy (typs, []) {maxvars=0, def_eq=false, next_idx=1, bounds=[], wellformed=True} (Free ("dummy", dT))
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2572
								val consts    = make_constants i  (* we only need the n-th element of this *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2573
									(* list, so there might be a more efficient implementation that does    *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2574
									(* not generate all constants                                           *)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2575
							in
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  2576
								print thy (typs, []) (Free ("dummy", dT)) (List.nth (consts, n)) assignment
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2577
							end) (cargs ~~ args)
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2578
					in
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15547
diff changeset
  2579
						SOME (Library.foldl op$ (cTerm, argsTerms))
15547
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2580
					end
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2581
				end
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2582
			| NONE =>  (* not an inductive datatype *)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2583
				NONE)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2584
		| _ =>  (* a (free or schematic) type variable *)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15335
diff changeset
  2585
			NONE
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2586
	end;
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2587
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2588
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2589
(* ------------------------------------------------------------------------- *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  2590
(* use 'setup Refute.setup' in an Isabelle theory to initialize the 'Refute' *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  2591
(* structure                                                                 *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2592
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2593
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2594
(* ------------------------------------------------------------------------- *)
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  2595
(* Note: the interpreters and printers are used in reverse order; however,   *)
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  2596
(*       an interpreter that can handle non-atomic terms ends up being       *)
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2597
(*       applied before the 'stlc_interpreter' breaks the term apart into    *)
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2598
(*       subterms that are then passed to other interpreters!                *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2599
(* ------------------------------------------------------------------------- *)
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2600
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  2601
	(* (theory -> theory) list *)
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2602
14456
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  2603
	val setup =
cca28ec5f9a6 support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
webertj
parents: 14351
diff changeset
  2604
		[RefuteData.init,
15571
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2605
		 add_interpreter "stlc"    stlc_interpreter,
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2606
		 add_interpreter "Pure"    Pure_interpreter,
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2607
		 add_interpreter "HOLogic" HOLogic_interpreter,
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2608
		 add_interpreter "set"     set_interpreter,
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2609
		 add_interpreter "IDT"             IDT_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: 15531
diff changeset
  2610
		 add_interpreter "IDT_constructor" IDT_constructor_interpreter,
f08e2d83681e major code change: refute can now handle recursion and axiomatic type classes; 3-valued logic with two kinds of equality; some bugfixes
webertj
parents: 15531
diff changeset
  2611
		 add_interpreter "IDT_recursion"   IDT_recursion_interpreter,
15571
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2612
		 add_interpreter "Finite_Set.card"    Finite_Set_card_interpreter,
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2613
		 add_interpreter "Finite_Set.Finites" Finite_Set_Finites_interpreter,
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2614
		 add_interpreter "Nat.op <" Nat_less_interpreter,
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2615
		 add_interpreter "Nat.op +" Nat_plus_interpreter,
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2616
		 add_interpreter "Nat.op -" Nat_minus_interpreter,
c166086feace interpreter for Finite_Set.Finites added
webertj
parents: 15570
diff changeset
  2617
		 add_interpreter "Nat.op *" Nat_mult_interpreter,
15767
8ed9fcc004fe support for recursion over mutually recursive IDTs
webertj
parents: 15611
diff changeset
  2618
		 add_interpreter "List.op @" List_append_interpreter,
16050
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2619
		 add_interpreter "Lfp.lfp" Lfp_lfp_interpreter,
828fc32f390f interpreters for lfp/gfp added
webertj
parents: 15794
diff changeset
  2620
		 add_interpreter "Gfp.gfp" Gfp_gfp_interpreter,
14807
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2621
		 add_printer "stlc" stlc_printer,
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2622
		 add_printer "set"  set_printer,
e8ccb13d7774 major code change: refute can now handle any Isabelle term, adds certain axioms automatically, and can handle inductive datatypes (but not yet recursion over them)
webertj
parents: 14604
diff changeset
  2623
		 add_printer "IDT"  IDT_printer];
14350
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2624
41b32020d0b3 Adding 'refute' to HOL.
webertj
parents:
diff changeset
  2625
end