| author | haftmann | 
| Tue, 11 May 2010 18:46:03 +0200 | |
| changeset 36832 | e6078ef937df | 
| parent 36610 | bafd82950e24 | 
| child 37391 | 476270a6c2dc | 
| permissions | -rw-r--r-- | 
| 33265 | 1  | 
(* Title: HOL/Tools/Predicate_Compile/predicate_compile_aux.ML  | 
2  | 
Author: Lukas Bulwahn, TU Muenchen  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
3  | 
|
| 33265 | 4  | 
Auxilary functions for predicate compiler.  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
5  | 
*)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
6  | 
|
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
7  | 
signature PREDICATE_COMPILE_AUX =  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
8  | 
sig  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
9  | 
(* general functions *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
10  | 
  val apfst3 : ('a -> 'd) -> 'a * 'b * 'c -> 'd * 'b * 'c
 | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
11  | 
  val apsnd3 : ('b -> 'd) -> 'a * 'b * 'c -> 'a * 'd * 'c
 | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
12  | 
  val aptrd3 : ('c -> 'd) -> 'a * 'b * 'c -> 'a * 'b * 'd
 | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
13  | 
  val find_indices : ('a -> bool) -> 'a list -> int list
 | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
14  | 
val assert : bool -> unit  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
15  | 
(* mode *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
16  | 
datatype mode = Bool | Input | Output | Pair of mode * mode | Fun of mode * mode  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
17  | 
val eq_mode : mode * mode -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
18  | 
val list_fun_mode : mode list -> mode  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
19  | 
val strip_fun_mode : mode -> mode list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
20  | 
val dest_fun_mode : mode -> mode list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
21  | 
val dest_tuple_mode : mode -> mode list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
22  | 
val all_modes_of_typ : typ -> mode list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
23  | 
val all_smodes_of_typ : typ -> mode list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
24  | 
  val fold_map_aterms_prodT : ('a -> 'a -> 'a) -> (typ -> 'b -> 'a * 'b) -> typ -> 'b -> 'a * 'b
 | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
25  | 
val map_filter_prod : (term -> term option) -> term -> term option  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
26  | 
val replace_ho_args : mode -> term list -> term list -> term list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
27  | 
val ho_arg_modes_of : mode -> mode list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
28  | 
val ho_argsT_of : mode -> typ list -> typ list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
29  | 
val ho_args_of : mode -> term list -> term list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
30  | 
val split_map_mode : (mode -> term -> term option * term option)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
31  | 
-> mode -> term list -> term list * term list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
32  | 
val split_map_modeT : (mode -> typ -> typ option * typ option)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
33  | 
-> mode -> typ list -> typ list * typ list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
34  | 
val split_mode : mode -> term list -> term list * term list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
35  | 
val split_modeT' : mode -> typ list -> typ list * typ list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
36  | 
val string_of_mode : mode -> string  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
37  | 
val ascii_string_of_mode : mode -> string  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
38  | 
(* premises *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
39  | 
datatype indprem = Prem of term | Negprem of term | Sidecond of term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
40  | 
| Generator of (string * typ)  | 
| 
36251
 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 
bulwahn 
parents: 
36248 
diff
changeset
 | 
41  | 
val dest_indprem : indprem -> term  | 
| 36254 | 42  | 
val map_indprem : (term -> term) -> indprem -> indprem  | 
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
43  | 
(* general syntactic functions *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
44  | 
val conjuncts : term -> term list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
45  | 
val is_equationlike : thm -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
46  | 
val is_pred_equation : thm -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
47  | 
val is_intro : string -> thm -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
48  | 
val is_predT : typ -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
49  | 
val is_constrt : theory -> term -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
50  | 
val is_constr : Proof.context -> string -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
51  | 
val focus_ex : term -> Name.context -> ((string * typ) list * term) * Name.context  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
52  | 
val strip_all : term -> (string * typ) list * term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
53  | 
(* introduction rule combinators *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
54  | 
val map_atoms : (term -> term) -> term -> term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
55  | 
val fold_atoms : (term -> 'a -> 'a) -> term -> 'a -> 'a  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
56  | 
val fold_map_atoms : (term -> 'a -> term * 'a) -> term -> 'a -> term * 'a  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
57  | 
val maps_premises : (term -> term list) -> term -> term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
58  | 
val map_concl : (term -> term) -> term -> term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
59  | 
val map_term : theory -> (term -> term) -> thm -> thm  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
60  | 
(* split theorems of case expressions *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
61  | 
val prepare_split_thm : Proof.context -> thm -> thm  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
62  | 
val find_split_thm : theory -> term -> thm option  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
63  | 
(* datastructures and setup for generic compilation *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
64  | 
  datatype compilation_funs = CompilationFuns of {
 | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
65  | 
mk_predT : typ -> typ,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
66  | 
dest_predT : typ -> typ,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
67  | 
mk_bot : typ -> term,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
68  | 
mk_single : term -> term,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
69  | 
mk_bind : term * term -> term,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
70  | 
mk_sup : term * term -> term,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
71  | 
mk_if : term -> term,  | 
| 
36049
 
0ce5b7a5c2fd
adding iterate_upto interface in compilations and iterate_upto functions in Isabelle theories for arithmetic setup of the predicate compiler
 
bulwahn 
parents: 
36047 
diff
changeset
 | 
72  | 
mk_iterate_upto : typ -> term * term * term -> term,  | 
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
73  | 
mk_not : term -> term,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
74  | 
mk_map : typ -> typ -> term -> term -> term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
75  | 
};  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
76  | 
val mk_predT : compilation_funs -> typ -> typ  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
77  | 
val dest_predT : compilation_funs -> typ -> typ  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
78  | 
val mk_bot : compilation_funs -> typ -> term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
79  | 
val mk_single : compilation_funs -> term -> term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
80  | 
val mk_bind : compilation_funs -> term * term -> term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
81  | 
val mk_sup : compilation_funs -> term * term -> term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
82  | 
val mk_if : compilation_funs -> term -> term  | 
| 
36049
 
0ce5b7a5c2fd
adding iterate_upto interface in compilations and iterate_upto functions in Isabelle theories for arithmetic setup of the predicate compiler
 
bulwahn 
parents: 
36047 
diff
changeset
 | 
83  | 
val mk_iterate_upto : compilation_funs -> typ -> term * term * term -> term  | 
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
84  | 
val mk_not : compilation_funs -> term -> term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
85  | 
val mk_map : compilation_funs -> typ -> typ -> term -> term -> term  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
86  | 
val funT_of : compilation_funs -> mode -> typ -> typ  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
87  | 
(* Different compilations *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
88  | 
datatype compilation = Pred | Depth_Limited | Random | Depth_Limited_Random | DSeq | Annotated  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
89  | 
| Pos_Random_DSeq | Neg_Random_DSeq | New_Pos_Random_DSeq | New_Neg_Random_DSeq  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
90  | 
val negative_compilation_of : compilation -> compilation  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
91  | 
val compilation_for_polarity : bool -> compilation -> compilation  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
92  | 
val string_of_compilation : compilation -> string  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
93  | 
val compilation_names : (string * compilation) list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
94  | 
val non_random_compilations : compilation list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
95  | 
val random_compilations : compilation list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
96  | 
(* Different options for compiler *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
97  | 
  datatype options = Options of {  
 | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
98  | 
expected_modes : (string * mode list) option,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
99  | 
proposed_modes : (string * mode list) option,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
100  | 
proposed_names : ((string * mode) * string) list,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
101  | 
show_steps : bool,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
102  | 
show_proof_trace : bool,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
103  | 
show_intermediate_results : bool,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
104  | 
show_mode_inference : bool,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
105  | 
show_modes : bool,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
106  | 
show_compilation : bool,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
107  | 
show_caught_failures : bool,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
108  | 
skip_proof : bool,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
109  | 
no_topmost_reordering : bool,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
110  | 
function_flattening : bool,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
111  | 
fail_safe_function_flattening : bool,  | 
| 
36248
 
9ed1a37de465
added option for specialisation to the predicate compiler
 
bulwahn 
parents: 
36246 
diff
changeset
 | 
112  | 
specialise : bool,  | 
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
113  | 
no_higher_order_predicate : string list,  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
114  | 
inductify : bool,  | 
| 36254 | 115  | 
detect_switches : bool,  | 
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
116  | 
compilation : compilation  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
117  | 
};  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
118  | 
val expected_modes : options -> (string * mode list) option  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
119  | 
val proposed_modes : options -> (string * mode list) option  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
120  | 
val proposed_names : options -> string -> mode -> string option  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
121  | 
val show_steps : options -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
122  | 
val show_proof_trace : options -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
123  | 
val show_intermediate_results : options -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
124  | 
val show_mode_inference : options -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
125  | 
val show_modes : options -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
126  | 
val show_compilation : options -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
127  | 
val show_caught_failures : options -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
128  | 
val skip_proof : options -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
129  | 
val no_topmost_reordering : options -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
130  | 
val function_flattening : options -> bool  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
131  | 
val fail_safe_function_flattening : options -> bool  | 
| 
36248
 
9ed1a37de465
added option for specialisation to the predicate compiler
 
bulwahn 
parents: 
36246 
diff
changeset
 | 
132  | 
val specialise : options -> bool  | 
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
133  | 
val no_higher_order_predicate : options -> string list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
134  | 
val is_inductify : options -> bool  | 
| 36254 | 135  | 
val detect_switches : options -> bool  | 
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
136  | 
val compilation : options -> compilation  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
137  | 
val default_options : options  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
138  | 
val bool_options : string list  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
139  | 
val print_step : options -> string -> unit  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
140  | 
(* simple transformations *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
141  | 
val expand_tuples : theory -> thm -> thm  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
142  | 
val eta_contract_ho_arguments : theory -> thm -> thm  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
143  | 
val remove_equalities : theory -> thm -> thm  | 
| 
36246
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
144  | 
val remove_pointless_clauses : thm -> thm list  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
145  | 
val peephole_optimisation : theory -> thm -> thm option  | 
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
146  | 
end;  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
147  | 
|
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
148  | 
structure Predicate_Compile_Aux : PREDICATE_COMPILE_AUX =  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
149  | 
struct  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
150  | 
|
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
151  | 
(* general functions *)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
152  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
153  | 
fun apfst3 f (x, y, z) = (f x, y, z)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
154  | 
fun apsnd3 f (x, y, z) = (x, f y, z)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
155  | 
fun aptrd3 f (x, y, z) = (x, y, f z)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
156  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
157  | 
fun comb_option f (SOME x1, SOME x2) = SOME (f (x1, x2))  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
158  | 
| comb_option f (NONE, SOME x2) = SOME x2  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
159  | 
| comb_option f (SOME x1, NONE) = SOME x1  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
160  | 
| comb_option f (NONE, NONE) = NONE  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
161  | 
|
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
162  | 
fun map2_optional f (x :: xs) (y :: ys) = f x (SOME y) :: (map2_optional f xs ys)  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
163  | 
| map2_optional f (x :: xs) [] = (f x NONE) :: (map2_optional f xs [])  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
164  | 
| map2_optional f [] [] = []  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
165  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
166  | 
fun find_indices f xs =  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
167  | 
map_filter (fn (i, true) => SOME i | (i, false) => NONE) (map_index (apsnd f) xs)  | 
| 
33328
 
1d93dd8a02c9
moved datatype mode and string functions to the auxillary structure
 
bulwahn 
parents: 
33327 
diff
changeset
 | 
168  | 
|
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
169  | 
fun assert check = if check then () else raise Fail "Assertion failed!"  | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
170  | 
|
| 
33328
 
1d93dd8a02c9
moved datatype mode and string functions to the auxillary structure
 
bulwahn 
parents: 
33327 
diff
changeset
 | 
171  | 
(* mode *)  | 
| 
 
1d93dd8a02c9
moved datatype mode and string functions to the auxillary structure
 
bulwahn 
parents: 
33327 
diff
changeset
 | 
172  | 
|
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
173  | 
datatype mode = Bool | Input | Output | Pair of mode * mode | Fun of mode * mode  | 
| 
33619
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
174  | 
|
| 
33623
 
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
 
bulwahn 
parents: 
33620 
diff
changeset
 | 
175  | 
(* equality of instantiatedness with respect to equivalences:  | 
| 
 
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
 
bulwahn 
parents: 
33620 
diff
changeset
 | 
176  | 
Pair Input Input == Input and Pair Output Output == Output *)  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
177  | 
fun eq_mode (Fun (m1, m2), Fun (m3, m4)) = eq_mode (m1, m3) andalso eq_mode (m2, m4)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
178  | 
| eq_mode (Pair (m1, m2), Pair (m3, m4)) = eq_mode (m1, m3) andalso eq_mode (m2, m4)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
179  | 
| eq_mode (Pair (m1, m2), Input) = eq_mode (m1, Input) andalso eq_mode (m2, Input)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
180  | 
| eq_mode (Pair (m1, m2), Output) = eq_mode (m1, Output) andalso eq_mode (m2, Output)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
181  | 
| eq_mode (Input, Pair (m1, m2)) = eq_mode (Input, m1) andalso eq_mode (Input, m2)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
182  | 
| eq_mode (Output, Pair (m1, m2)) = eq_mode (Output, m1) andalso eq_mode (Output, m2)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
183  | 
| eq_mode (Input, Input) = true  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
184  | 
| eq_mode (Output, Output) = true  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
185  | 
| eq_mode (Bool, Bool) = true  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
186  | 
| eq_mode _ = false  | 
| 
33623
 
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
 
bulwahn 
parents: 
33620 
diff
changeset
 | 
187  | 
|
| 
36035
 
d82682936c52
adding registration of functions in the function flattening
 
bulwahn 
parents: 
36032 
diff
changeset
 | 
188  | 
fun list_fun_mode [] = Bool  | 
| 
 
d82682936c52
adding registration of functions in the function flattening
 
bulwahn 
parents: 
36032 
diff
changeset
 | 
189  | 
| list_fun_mode (m :: ms) = Fun (m, list_fun_mode ms)  | 
| 
 
d82682936c52
adding registration of functions in the function flattening
 
bulwahn 
parents: 
36032 
diff
changeset
 | 
190  | 
|
| 
33619
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
191  | 
(* name: binder_modes? *)  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
192  | 
fun strip_fun_mode (Fun (mode, mode')) = mode :: strip_fun_mode mode'  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
193  | 
| strip_fun_mode Bool = []  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
194  | 
| strip_fun_mode _ = raise Fail "Bad mode for strip_fun_mode"  | 
| 
33619
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
195  | 
|
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
196  | 
(* name: strip_fun_mode? *)  | 
| 
33619
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
197  | 
fun dest_fun_mode (Fun (mode, mode')) = mode :: dest_fun_mode mode'  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
198  | 
| dest_fun_mode mode = [mode]  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
199  | 
|
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
200  | 
fun dest_tuple_mode (Pair (mode, mode')) = mode :: dest_tuple_mode mode'  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
201  | 
| dest_tuple_mode _ = []  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
202  | 
|
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
203  | 
fun all_modes_of_typ' (T as Type ("fun", _)) = 
 | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
204  | 
let  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
205  | 
val (S, U) = strip_type T  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
206  | 
in  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
207  | 
if U = HOLogic.boolT then  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
208  | 
fold_rev (fn m1 => fn m2 => map_product (curry Fun) m1 m2)  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
209  | 
(map all_modes_of_typ' S) [Bool]  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
210  | 
else  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
211  | 
[Input, Output]  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
212  | 
end  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
213  | 
  | all_modes_of_typ' (Type (@{type_name "*"}, [T1, T2])) = 
 | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
214  | 
map_product (curry Pair) (all_modes_of_typ' T1) (all_modes_of_typ' T2)  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
215  | 
| all_modes_of_typ' _ = [Input, Output]  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
216  | 
|
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
217  | 
fun all_modes_of_typ (T as Type ("fun", _)) =
 | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
218  | 
let  | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
219  | 
val (S, U) = strip_type T  | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
220  | 
in  | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
221  | 
      if U = @{typ bool} then
 | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
222  | 
fold_rev (fn m1 => fn m2 => map_product (curry Fun) m1 m2)  | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
223  | 
(map all_modes_of_typ' S) [Bool]  | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
224  | 
else  | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
225  | 
[Input, Output]  | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
226  | 
end  | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
227  | 
  | all_modes_of_typ @{typ bool} = [Bool]
 | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
228  | 
| all_modes_of_typ T = all_modes_of_typ' T  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
229  | 
|
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
230  | 
fun all_smodes_of_typ (T as Type ("fun", _)) =
 | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
231  | 
let  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
232  | 
val (S, U) = strip_type T  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
233  | 
    fun all_smodes (Type (@{type_name "*"}, [T1, T2])) = 
 | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
234  | 
map_product (curry Pair) (all_smodes T1) (all_smodes T2)  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
235  | 
| all_smodes _ = [Input, Output]  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
236  | 
in  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
237  | 
if U = HOLogic.boolT then  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
238  | 
fold_rev (fn m1 => fn m2 => map_product (curry Fun) m1 m2) (map all_smodes S) [Bool]  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
239  | 
else  | 
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
240  | 
raise Fail "invalid type for predicate"  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
241  | 
end  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
242  | 
|
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
243  | 
fun ho_arg_modes_of mode =  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
244  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
245  | 
fun ho_arg_mode (m as Fun _) = [m]  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
246  | 
| ho_arg_mode (Pair (m1, m2)) = ho_arg_mode m1 @ ho_arg_mode m2  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
247  | 
| ho_arg_mode _ = []  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
248  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
249  | 
maps ho_arg_mode (strip_fun_mode mode)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
250  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
251  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
252  | 
fun ho_args_of mode ts =  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
253  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
254  | 
fun ho_arg (Fun _) (SOME t) = [t]  | 
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
255  | 
| ho_arg (Fun _) NONE = raise Fail "mode and term do not match"  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
256  | 
      | ho_arg (Pair (m1, m2)) (SOME (Const (@{const_name Pair}, _) $ t1 $ t2)) =
 | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
257  | 
ho_arg m1 (SOME t1) @ ho_arg m2 (SOME t2)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
258  | 
| ho_arg (Pair (m1, m2)) NONE = ho_arg m1 NONE @ ho_arg m2 NONE  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
259  | 
| ho_arg _ _ = []  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
260  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
261  | 
flat (map2_optional ho_arg (strip_fun_mode mode) ts)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
262  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
263  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
264  | 
(* temporary function should be replaced by unsplit_input or so? *)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
265  | 
fun replace_ho_args mode hoargs ts =  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
266  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
267  | 
fun replace (Fun _, _) (arg' :: hoargs') = (arg', hoargs')  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
268  | 
      | replace (Pair (m1, m2), Const ("Pair", T) $ t1 $ t2) hoargs =
 | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
269  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
270  | 
val (t1', hoargs') = replace (m1, t1) hoargs  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
271  | 
val (t2', hoargs'') = replace (m2, t2) hoargs'  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
272  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
273  | 
          (Const ("Pair", T) $ t1' $ t2', hoargs'')
 | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
274  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
275  | 
| replace (_, t) hoargs = (t, hoargs)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
276  | 
in  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
277  | 
fst (fold_map replace (strip_fun_mode mode ~~ ts) hoargs)  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
278  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
279  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
280  | 
fun ho_argsT_of mode Ts =  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
281  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
282  | 
fun ho_arg (Fun _) T = [T]  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
283  | 
      | ho_arg (Pair (m1, m2)) (Type (@{type_name "*"}, [T1, T2])) = ho_arg m1 T1 @ ho_arg m2 T2
 | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
284  | 
| ho_arg _ _ = []  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
285  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
286  | 
flat (map2 ho_arg (strip_fun_mode mode) Ts)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
287  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
288  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
289  | 
(* splits mode and maps function to higher-order argument types *)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
290  | 
fun split_map_mode f mode ts =  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
291  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
292  | 
fun split_arg_mode' (m as Fun _) t = f m t  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
293  | 
      | split_arg_mode' (Pair (m1, m2)) (Const ("Pair", _) $ t1 $ t2) =
 | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
294  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
295  | 
val (i1, o1) = split_arg_mode' m1 t1  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
296  | 
val (i2, o2) = split_arg_mode' m2 t2  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
297  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
298  | 
(comb_option HOLogic.mk_prod (i1, i2), comb_option HOLogic.mk_prod (o1, o2))  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
299  | 
end  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
300  | 
| split_arg_mode' m t =  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
301  | 
if eq_mode (m, Input) then (SOME t, NONE)  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
302  | 
else if eq_mode (m, Output) then (NONE, SOME t)  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
303  | 
else raise Fail "split_map_mode: mode and term do not match"  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
304  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
305  | 
(pairself (map_filter I) o split_list) (map2 split_arg_mode' (strip_fun_mode mode) ts)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
306  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
307  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
308  | 
(* splits mode and maps function to higher-order argument types *)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
309  | 
fun split_map_modeT f mode Ts =  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
310  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
311  | 
fun split_arg_mode' (m as Fun _) T = f m T  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
312  | 
      | split_arg_mode' (Pair (m1, m2)) (Type (@{type_name "*"}, [T1, T2])) =
 | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
313  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
314  | 
val (i1, o1) = split_arg_mode' m1 T1  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
315  | 
val (i2, o2) = split_arg_mode' m2 T2  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
316  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
317  | 
(comb_option HOLogic.mk_prodT (i1, i2), comb_option HOLogic.mk_prodT (o1, o2))  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
318  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
319  | 
| split_arg_mode' Input T = (SOME T, NONE)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
320  | 
| split_arg_mode' Output T = (NONE, SOME T)  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
321  | 
| split_arg_mode' _ _ = raise Fail "split_modeT': mode and type do not match"  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
322  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
323  | 
(pairself (map_filter I) o split_list) (map2 split_arg_mode' (strip_fun_mode mode) Ts)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
324  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
325  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
326  | 
fun split_mode mode ts = split_map_mode (fn _ => fn _ => (NONE, NONE)) mode ts  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
327  | 
|
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
328  | 
fun fold_map_aterms_prodT comb f (Type (@{type_name "*"}, [T1, T2])) s =
 | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
329  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
330  | 
val (x1, s') = fold_map_aterms_prodT comb f T1 s  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
331  | 
val (x2, s'') = fold_map_aterms_prodT comb f T2 s'  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
332  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
333  | 
(comb x1 x2, s'')  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
334  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
335  | 
| fold_map_aterms_prodT comb f T s = f T s  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
336  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
337  | 
fun map_filter_prod f (Const ("Pair", _) $ t1 $ t2) =
 | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
338  | 
comb_option HOLogic.mk_prod (map_filter_prod f t1, map_filter_prod f t2)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
339  | 
| map_filter_prod f t = f t  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
340  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
341  | 
(* obviously, split_mode' and split_modeT' do not match? where does that cause problems? *)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
342  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
343  | 
fun split_modeT' mode Ts =  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
344  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
345  | 
fun split_arg_mode' (Fun _) T = ([], [])  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
346  | 
      | split_arg_mode' (Pair (m1, m2)) (Type (@{type_name "*"}, [T1, T2])) =
 | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
347  | 
let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
348  | 
val (i1, o1) = split_arg_mode' m1 T1  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
349  | 
val (i2, o2) = split_arg_mode' m2 T2  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
350  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
351  | 
(i1 @ i2, o1 @ o2)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
352  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
353  | 
| split_arg_mode' Input T = ([T], [])  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
354  | 
| split_arg_mode' Output T = ([], [T])  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
355  | 
| split_arg_mode' _ _ = raise Fail "split_modeT': mode and type do not match"  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
356  | 
in  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
357  | 
(pairself flat o split_list) (map2 split_arg_mode' (strip_fun_mode mode) Ts)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
358  | 
end  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
359  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
360  | 
fun string_of_mode mode =  | 
| 
33619
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
361  | 
let  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
362  | 
fun string_of_mode1 Input = "i"  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
363  | 
| string_of_mode1 Output = "o"  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
364  | 
| string_of_mode1 Bool = "bool"  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
365  | 
      | string_of_mode1 mode = "(" ^ (string_of_mode3 mode) ^ ")"
 | 
| 
33626
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
366  | 
and string_of_mode2 (Pair (m1, m2)) = string_of_mode3 m1 ^ " * " ^ string_of_mode2 m2  | 
| 
33619
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
367  | 
| string_of_mode2 mode = string_of_mode1 mode  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
368  | 
and string_of_mode3 (Fun (m1, m2)) = string_of_mode2 m1 ^ " => " ^ string_of_mode3 m2  | 
| 
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
369  | 
| string_of_mode3 mode = string_of_mode2 mode  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
370  | 
in string_of_mode3 mode end  | 
| 
33619
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
371  | 
|
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
372  | 
fun ascii_string_of_mode mode' =  | 
| 
33626
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
373  | 
let  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
374  | 
fun ascii_string_of_mode' Input = "i"  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
375  | 
| ascii_string_of_mode' Output = "o"  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
376  | 
| ascii_string_of_mode' Bool = "b"  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
377  | 
| ascii_string_of_mode' (Pair (m1, m2)) =  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
378  | 
"P" ^ ascii_string_of_mode' m1 ^ ascii_string_of_mode'_Pair m2  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
379  | 
| ascii_string_of_mode' (Fun (m1, m2)) =  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
380  | 
"F" ^ ascii_string_of_mode' m1 ^ ascii_string_of_mode'_Fun m2 ^ "B"  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
381  | 
and ascii_string_of_mode'_Fun (Fun (m1, m2)) =  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
382  | 
ascii_string_of_mode' m1 ^ (if m2 = Bool then "" else "_" ^ ascii_string_of_mode'_Fun m2)  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
383  | 
| ascii_string_of_mode'_Fun Bool = "B"  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
384  | 
| ascii_string_of_mode'_Fun m = ascii_string_of_mode' m  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
385  | 
and ascii_string_of_mode'_Pair (Pair (m1, m2)) =  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
386  | 
ascii_string_of_mode' m1 ^ ascii_string_of_mode'_Pair m2  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
387  | 
| ascii_string_of_mode'_Pair m = ascii_string_of_mode' m  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
388  | 
in ascii_string_of_mode'_Fun mode' end  | 
| 
 
42f69386943a
new names for predicate functions in the predicate compiler
 
bulwahn 
parents: 
33623 
diff
changeset
 | 
389  | 
|
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
390  | 
(* premises *)  | 
| 
33619
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
391  | 
|
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
392  | 
datatype indprem = Prem of term | Negprem of term | Sidecond of term  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
393  | 
| Generator of (string * typ);  | 
| 
33619
 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 
bulwahn 
parents: 
33473 
diff
changeset
 | 
394  | 
|
| 
36251
 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 
bulwahn 
parents: 
36248 
diff
changeset
 | 
395  | 
fun dest_indprem (Prem t) = t  | 
| 
 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 
bulwahn 
parents: 
36248 
diff
changeset
 | 
396  | 
| dest_indprem (Negprem t) = t  | 
| 
 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 
bulwahn 
parents: 
36248 
diff
changeset
 | 
397  | 
| dest_indprem (Sidecond t) = t  | 
| 
 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 
bulwahn 
parents: 
36248 
diff
changeset
 | 
398  | 
| dest_indprem (Generator _) = raise Fail "cannot destruct generator"  | 
| 
 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 
bulwahn 
parents: 
36248 
diff
changeset
 | 
399  | 
|
| 36254 | 400  | 
fun map_indprem f (Prem t) = Prem (f t)  | 
401  | 
| map_indprem f (Negprem t) = Negprem (f t)  | 
|
402  | 
| map_indprem f (Sidecond t) = Sidecond (f t)  | 
|
403  | 
| map_indprem f (Generator (v, T)) = Generator (dest_Free (f (Free (v, T))))  | 
|
404  | 
||
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
405  | 
(* general syntactic functions *)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
406  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
407  | 
(*Like dest_conj, but flattens conjunctions however nested*)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
408  | 
fun conjuncts_aux (Const ("op &", _) $ t $ t') conjs = conjuncts_aux t (conjuncts_aux t' conjs)
 | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
409  | 
| conjuncts_aux t conjs = t::conjs;  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
410  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
411  | 
fun conjuncts t = conjuncts_aux t [];  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
412  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
413  | 
fun is_equationlike_term (Const ("==", _) $ _ $ _) = true
 | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
414  | 
  | is_equationlike_term (Const ("Trueprop", _) $ (Const ("op =", _) $ _ $ _)) = true
 | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
415  | 
| is_equationlike_term _ = false  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
416  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
417  | 
val is_equationlike = is_equationlike_term o prop_of  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
418  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
419  | 
fun is_pred_equation_term (Const ("==", _) $ u $ v) =
 | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
420  | 
  (fastype_of u = @{typ bool}) andalso (fastype_of v = @{typ bool})
 | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
421  | 
| is_pred_equation_term _ = false  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
422  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
423  | 
val is_pred_equation = is_pred_equation_term o prop_of  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
424  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
425  | 
fun is_intro_term constname t =  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
426  | 
the_default false (try (fn t => case fst (strip_comb (HOLogic.dest_Trueprop (Logic.strip_imp_concl t))) of  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
427  | 
Const (c, _) => c = constname  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
428  | 
| _ => false) t)  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
429  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
430  | 
fun is_intro constname t = is_intro_term constname (prop_of t)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
431  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
432  | 
fun is_pred thy constname =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
433  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
434  | 
val T = (Sign.the_const_type thy constname)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
435  | 
  in body_type T = @{typ "bool"} end;
 | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
436  | 
|
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
437  | 
fun is_predT (T as Type("fun", [_, _])) = (snd (strip_type T) = @{typ bool})
 | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
438  | 
| is_predT _ = false  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
439  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
440  | 
(*** check if a term contains only constructor functions ***)  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
441  | 
(* TODO: another copy in the core! *)  | 
| 
33623
 
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
 
bulwahn 
parents: 
33620 
diff
changeset
 | 
442  | 
(* FIXME: constructor terms are supposed to be seen in the way the code generator  | 
| 
 
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
 
bulwahn 
parents: 
33620 
diff
changeset
 | 
443  | 
sees constructors.*)  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
444  | 
fun is_constrt thy =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
445  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
446  | 
val cnstrs = flat (maps  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
447  | 
(map (fn (_, (Tname, _, cs)) => map (apsnd (rpair Tname o length)) cs) o #descr o snd)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
448  | 
(Symtab.dest (Datatype.get_all thy)));  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
449  | 
fun check t = (case strip_comb t of  | 
| 
36032
 
dfd30b5b4e73
adding specialisation of predicates to the predicate compiler
 
bulwahn 
parents: 
36029 
diff
changeset
 | 
450  | 
(Var _, []) => true  | 
| 
 
dfd30b5b4e73
adding specialisation of predicates to the predicate compiler
 
bulwahn 
parents: 
36029 
diff
changeset
 | 
451  | 
| (Free _, []) => true  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
452  | 
| (Const (s, T), ts) => (case (AList.lookup (op =) cnstrs s, body_type T) of  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
453  | 
(SOME (i, Tname), Type (Tname', _)) => length ts = i andalso Tname = Tname' andalso forall check ts  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
454  | 
| _ => false)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
455  | 
| _ => false)  | 
| 
36032
 
dfd30b5b4e73
adding specialisation of predicates to the predicate compiler
 
bulwahn 
parents: 
36029 
diff
changeset
 | 
456  | 
in check end;  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
457  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
458  | 
fun is_funtype (Type ("fun", [_, _])) = true
 | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
459  | 
| is_funtype _ = false;  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
460  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
461  | 
fun is_Type (Type _) = true  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
462  | 
| is_Type _ = false  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
463  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
464  | 
(* returns true if t is an application of an datatype constructor *)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
465  | 
(* which then consequently would be splitted *)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
466  | 
(* else false *)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
467  | 
(*  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
468  | 
fun is_constructor thy t =  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
469  | 
if (is_Type (fastype_of t)) then  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
470  | 
(case DatatypePackage.get_datatype thy ((fst o dest_Type o fastype_of) t) of  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
471  | 
NONE => false  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
472  | 
| SOME info => (let  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
473  | 
val constr_consts = maps (fn (_, (_, _, constrs)) => map fst constrs) (#descr info)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
474  | 
val (c, _) = strip_comb t  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
475  | 
in (case c of  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
476  | 
Const (name, _) => name mem_string constr_consts  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
477  | 
| _ => false) end))  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
478  | 
else false  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
479  | 
*)  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
480  | 
|
| 
35891
 
3122bdd95275
contextifying the compilation of the predicate compiler
 
bulwahn 
parents: 
35885 
diff
changeset
 | 
481  | 
val is_constr = Code.is_constr o ProofContext.theory_of;  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
482  | 
|
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
483  | 
fun strip_all t = (Term.strip_all_vars t, Term.strip_all_body t)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
484  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
485  | 
fun strip_ex (Const ("Ex", _) $ Abs (x, T, t)) =
 | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
486  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
487  | 
val (xTs, t') = strip_ex t  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
488  | 
in  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
489  | 
((x, T) :: xTs, t')  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
490  | 
end  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
491  | 
| strip_ex t = ([], t)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
492  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
493  | 
fun focus_ex t nctxt =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
494  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
495  | 
val ((xs, Ts), t') = apfst split_list (strip_ex t)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
496  | 
val (xs', nctxt') = Name.variants xs nctxt;  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
497  | 
val ps' = xs' ~~ Ts;  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
498  | 
val vs = map Free ps';  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
499  | 
val t'' = Term.subst_bounds (rev vs, t');  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
500  | 
in ((ps', t''), nctxt') end;  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
501  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
502  | 
(* introduction rule combinators *)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
503  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
504  | 
fun map_atoms f intro =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
505  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
506  | 
val (literals, head) = Logic.strip_horn intro  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
507  | 
fun appl t = (case t of  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
508  | 
        (@{term Not} $ t') => HOLogic.mk_not (f t')
 | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
509  | 
| _ => f t)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
510  | 
in  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
511  | 
Logic.list_implies  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
512  | 
(map (HOLogic.mk_Trueprop o appl o HOLogic.dest_Trueprop) literals, head)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
513  | 
end  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
514  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
515  | 
fun fold_atoms f intro s =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
516  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
517  | 
val (literals, head) = Logic.strip_horn intro  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
518  | 
fun appl t s = (case t of  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
519  | 
      (@{term Not} $ t') => f t' s
 | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
520  | 
| _ => f t s)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
521  | 
in fold appl (map HOLogic.dest_Trueprop literals) s end  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
522  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
523  | 
fun fold_map_atoms f intro s =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
524  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
525  | 
val (literals, head) = Logic.strip_horn intro  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
526  | 
fun appl t s = (case t of  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
527  | 
      (@{term Not} $ t') => apfst HOLogic.mk_not (f t' s)
 | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
528  | 
| _ => f t s)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
529  | 
val (literals', s') = fold_map appl (map HOLogic.dest_Trueprop literals) s  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
530  | 
in  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
531  | 
(Logic.list_implies (map HOLogic.mk_Trueprop literals', head), s')  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
532  | 
end;  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
533  | 
|
| 
36246
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
534  | 
fun map_premises f intro =  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
535  | 
let  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
536  | 
val (premises, head) = Logic.strip_horn intro  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
537  | 
in  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
538  | 
Logic.list_implies (map f premises, head)  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
539  | 
end  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
540  | 
|
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
541  | 
fun map_filter_premises f intro =  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
542  | 
let  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
543  | 
val (premises, head) = Logic.strip_horn intro  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
544  | 
in  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
545  | 
Logic.list_implies (map_filter f premises, head)  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
546  | 
end  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
547  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
548  | 
fun maps_premises f intro =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
549  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
550  | 
val (premises, head) = Logic.strip_horn intro  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
551  | 
in  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
552  | 
Logic.list_implies (maps f premises, head)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
553  | 
end  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
554  | 
|
| 35875 | 555  | 
fun map_concl f intro =  | 
556  | 
let  | 
|
557  | 
val (premises, head) = Logic.strip_horn intro  | 
|
558  | 
in  | 
|
559  | 
Logic.list_implies (premises, f head)  | 
|
560  | 
end  | 
|
561  | 
||
562  | 
(* combinators to apply a function to all basic parts of nested products *)  | 
|
563  | 
||
564  | 
fun map_products f (Const ("Pair", T) $ t1 $ t2) =
 | 
|
565  | 
  Const ("Pair", T) $ map_products f t1 $ map_products f t2
 | 
|
566  | 
| map_products f t = f t  | 
|
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
567  | 
|
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
568  | 
(* split theorems of case expressions *)  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
569  | 
|
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
570  | 
fun prepare_split_thm ctxt split_thm =  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
571  | 
    (split_thm RS @{thm iffD2})
 | 
| 35624 | 572  | 
    |> Local_Defs.unfold ctxt [@{thm atomize_conjL[symmetric]},
 | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
573  | 
      @{thm atomize_all[symmetric]}, @{thm atomize_imp[symmetric]}]
 | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
574  | 
|
| 
36029
 
a790b94e090c
removing fishing for split thm in the predicate compiler
 
bulwahn 
parents: 
36022 
diff
changeset
 | 
575  | 
fun find_split_thm thy (Const (name, T)) = Option.map #split (Datatype_Data.info_of_case thy name)  | 
| 
 
a790b94e090c
removing fishing for split thm in the predicate compiler
 
bulwahn 
parents: 
36022 
diff
changeset
 | 
576  | 
| find_split_thm thy _ = NONE  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
577  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
578  | 
(* lifting term operations to theorems *)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
579  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
580  | 
fun map_term thy f th =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
581  | 
Skip_Proof.make_thm thy (f (prop_of th))  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
582  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
583  | 
(*  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
584  | 
fun equals_conv lhs_cv rhs_cv ct =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
585  | 
case Thm.term_of ct of  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
586  | 
    Const ("==", _) $ _ $ _ => Conv.arg_conv cv ct  
 | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
587  | 
| _ => error "equals_conv"  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
588  | 
*)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
589  | 
|
| 
36038
 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 
bulwahn 
parents: 
36035 
diff
changeset
 | 
590  | 
(* Different compilations *)  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
591  | 
|
| 
35881
 
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
 
bulwahn 
parents: 
35880 
diff
changeset
 | 
592  | 
datatype compilation = Pred | Depth_Limited | Random | Depth_Limited_Random | DSeq | Annotated  | 
| 36018 | 593  | 
| Pos_Random_DSeq | Neg_Random_DSeq | New_Pos_Random_DSeq | New_Neg_Random_DSeq  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
594  | 
|
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
595  | 
fun negative_compilation_of Pos_Random_DSeq = Neg_Random_DSeq  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
596  | 
| negative_compilation_of Neg_Random_DSeq = Pos_Random_DSeq  | 
| 36018 | 597  | 
| negative_compilation_of New_Pos_Random_DSeq = New_Neg_Random_DSeq  | 
598  | 
| negative_compilation_of New_Neg_Random_DSeq = New_Pos_Random_DSeq  | 
|
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
599  | 
| negative_compilation_of c = c  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
600  | 
|
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
601  | 
fun compilation_for_polarity false Pos_Random_DSeq = Neg_Random_DSeq  | 
| 36018 | 602  | 
| compilation_for_polarity false New_Pos_Random_DSeq = New_Neg_Random_DSeq  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
603  | 
| compilation_for_polarity _ c = c  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
604  | 
|
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
605  | 
fun string_of_compilation c =  | 
| 
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
606  | 
case c of  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
607  | 
Pred => ""  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
608  | 
| Random => "random"  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
609  | 
| Depth_Limited => "depth limited"  | 
| 
35881
 
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
 
bulwahn 
parents: 
35880 
diff
changeset
 | 
610  | 
| Depth_Limited_Random => "depth limited random"  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
611  | 
| DSeq => "dseq"  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
612  | 
| Annotated => "annotated"  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
613  | 
| Pos_Random_DSeq => "pos_random dseq"  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
614  | 
| Neg_Random_DSeq => "neg_random_dseq"  | 
| 36018 | 615  | 
| New_Pos_Random_DSeq => "new_pos_random dseq"  | 
616  | 
| New_Neg_Random_DSeq => "new_neg_random_dseq"  | 
|
| 
36038
 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 
bulwahn 
parents: 
36035 
diff
changeset
 | 
617  | 
|
| 36018 | 618  | 
val compilation_names = [("pred", Pred),
 | 
619  | 
  ("random", Random),
 | 
|
620  | 
  ("depth_limited", Depth_Limited),
 | 
|
621  | 
  ("depth_limited_random", Depth_Limited_Random),
 | 
|
622  | 
  (*("annotated", Annotated),*)
 | 
|
623  | 
  ("dseq", DSeq), ("random_dseq", Pos_Random_DSeq),
 | 
|
624  | 
  ("new_random_dseq", New_Pos_Random_DSeq)]
 | 
|
| 
36038
 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 
bulwahn 
parents: 
36035 
diff
changeset
 | 
625  | 
|
| 
 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 
bulwahn 
parents: 
36035 
diff
changeset
 | 
626  | 
val non_random_compilations = [Pred, Depth_Limited, DSeq, Annotated]  | 
| 
 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 
bulwahn 
parents: 
36035 
diff
changeset
 | 
627  | 
|
| 
 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 
bulwahn 
parents: 
36035 
diff
changeset
 | 
628  | 
|
| 
 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 
bulwahn 
parents: 
36035 
diff
changeset
 | 
629  | 
val random_compilations = [Random, Depth_Limited_Random,  | 
| 
 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 
bulwahn 
parents: 
36035 
diff
changeset
 | 
630  | 
Pos_Random_DSeq, Neg_Random_DSeq, New_Pos_Random_DSeq, New_Neg_Random_DSeq]  | 
| 
 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 
bulwahn 
parents: 
36035 
diff
changeset
 | 
631  | 
|
| 
36046
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
632  | 
(* datastructures and setup for generic compilation *)  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
633  | 
|
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
634  | 
datatype compilation_funs = CompilationFuns of {
 | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
635  | 
mk_predT : typ -> typ,  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
636  | 
dest_predT : typ -> typ,  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
637  | 
mk_bot : typ -> term,  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
638  | 
mk_single : term -> term,  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
639  | 
mk_bind : term * term -> term,  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
640  | 
mk_sup : term * term -> term,  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
641  | 
mk_if : term -> term,  | 
| 
36049
 
0ce5b7a5c2fd
adding iterate_upto interface in compilations and iterate_upto functions in Isabelle theories for arithmetic setup of the predicate compiler
 
bulwahn 
parents: 
36047 
diff
changeset
 | 
642  | 
mk_iterate_upto : typ -> term * term * term -> term,  | 
| 
36046
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
643  | 
mk_not : term -> term,  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
644  | 
mk_map : typ -> typ -> term -> term -> term  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
645  | 
};  | 
| 
36038
 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 
bulwahn 
parents: 
36035 
diff
changeset
 | 
646  | 
|
| 
36046
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
647  | 
fun mk_predT (CompilationFuns funs) = #mk_predT funs  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
648  | 
fun dest_predT (CompilationFuns funs) = #dest_predT funs  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
649  | 
fun mk_bot (CompilationFuns funs) = #mk_bot funs  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
650  | 
fun mk_single (CompilationFuns funs) = #mk_single funs  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
651  | 
fun mk_bind (CompilationFuns funs) = #mk_bind funs  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
652  | 
fun mk_sup (CompilationFuns funs) = #mk_sup funs  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
653  | 
fun mk_if (CompilationFuns funs) = #mk_if funs  | 
| 
36049
 
0ce5b7a5c2fd
adding iterate_upto interface in compilations and iterate_upto functions in Isabelle theories for arithmetic setup of the predicate compiler
 
bulwahn 
parents: 
36047 
diff
changeset
 | 
654  | 
fun mk_iterate_upto (CompilationFuns funs) = #mk_iterate_upto funs  | 
| 
36046
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
655  | 
fun mk_not (CompilationFuns funs) = #mk_not funs  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
656  | 
fun mk_map (CompilationFuns funs) = #mk_map funs  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
657  | 
|
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
658  | 
(** function types and names of different compilations **)  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
659  | 
|
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
660  | 
fun funT_of compfuns mode T =  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
661  | 
let  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
662  | 
val Ts = binder_types T  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
663  | 
val (inTs, outTs) = split_map_modeT (fn m => fn T => (SOME (funT_of compfuns m T), NONE)) mode Ts  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
664  | 
in  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
665  | 
inTs ---> (mk_predT compfuns (HOLogic.mk_tupleT outTs))  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
666  | 
end;  | 
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
667  | 
|
| 
 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 
bulwahn 
parents: 
36038 
diff
changeset
 | 
668  | 
(* Different options for compiler *)  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
669  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
670  | 
datatype options = Options of {  
 | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
671  | 
expected_modes : (string * mode list) option,  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
672  | 
proposed_modes : (string * mode list) option,  | 
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
673  | 
proposed_names : ((string * mode) * string) list,  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
674  | 
show_steps : bool,  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
675  | 
show_proof_trace : bool,  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
676  | 
show_intermediate_results : bool,  | 
| 33251 | 677  | 
show_mode_inference : bool,  | 
678  | 
show_modes : bool,  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
679  | 
show_compilation : bool,  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
680  | 
show_caught_failures : bool,  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
681  | 
skip_proof : bool,  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
682  | 
no_topmost_reordering : bool,  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
683  | 
function_flattening : bool,  | 
| 
36248
 
9ed1a37de465
added option for specialisation to the predicate compiler
 
bulwahn 
parents: 
36246 
diff
changeset
 | 
684  | 
specialise : bool,  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
685  | 
fail_safe_function_flattening : bool,  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
686  | 
no_higher_order_predicate : string list,  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
687  | 
inductify : bool,  | 
| 36254 | 688  | 
detect_switches : bool,  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
689  | 
compilation : compilation  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
690  | 
};  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
691  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
692  | 
fun expected_modes (Options opt) = #expected_modes opt  | 
| 
33752
 
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
 
bulwahn 
parents: 
33626 
diff
changeset
 | 
693  | 
fun proposed_modes (Options opt) = #proposed_modes opt  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
694  | 
fun proposed_names (Options opt) name mode = AList.lookup (eq_pair (op =) eq_mode)  | 
| 
33623
 
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
 
bulwahn 
parents: 
33620 
diff
changeset
 | 
695  | 
(#proposed_names opt) (name, mode)  | 
| 
33620
 
b6bf2dc5aed7
added interface of user proposals for names of generated constants
 
bulwahn 
parents: 
33619 
diff
changeset
 | 
696  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
697  | 
fun show_steps (Options opt) = #show_steps opt  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
698  | 
fun show_intermediate_results (Options opt) = #show_intermediate_results opt  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
699  | 
fun show_proof_trace (Options opt) = #show_proof_trace opt  | 
| 33251 | 700  | 
fun show_modes (Options opt) = #show_modes opt  | 
701  | 
fun show_mode_inference (Options opt) = #show_mode_inference opt  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
702  | 
fun show_compilation (Options opt) = #show_compilation opt  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
703  | 
fun show_caught_failures (Options opt) = #show_caught_failures opt  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
704  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
705  | 
fun skip_proof (Options opt) = #skip_proof opt  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
706  | 
|
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
707  | 
fun function_flattening (Options opt) = #function_flattening opt  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
708  | 
fun fail_safe_function_flattening (Options opt) = #fail_safe_function_flattening opt  | 
| 
36248
 
9ed1a37de465
added option for specialisation to the predicate compiler
 
bulwahn 
parents: 
36246 
diff
changeset
 | 
709  | 
fun specialise (Options opt) = #specialise opt  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
710  | 
fun no_topmost_reordering (Options opt) = #no_topmost_reordering opt  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
711  | 
fun no_higher_order_predicate (Options opt) = #no_higher_order_predicate opt  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
712  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
713  | 
fun is_inductify (Options opt) = #inductify opt  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
714  | 
|
| 
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
715  | 
fun compilation (Options opt) = #compilation opt  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
716  | 
|
| 36254 | 717  | 
fun detect_switches (Options opt) = #detect_switches opt  | 
718  | 
||
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
719  | 
val default_options = Options {
 | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
720  | 
expected_modes = NONE,  | 
| 
33752
 
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
 
bulwahn 
parents: 
33626 
diff
changeset
 | 
721  | 
proposed_modes = NONE,  | 
| 
33623
 
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
 
bulwahn 
parents: 
33620 
diff
changeset
 | 
722  | 
proposed_names = [],  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
723  | 
show_steps = false,  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
724  | 
show_intermediate_results = false,  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
725  | 
show_proof_trace = false,  | 
| 33251 | 726  | 
show_modes = false,  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
727  | 
show_mode_inference = false,  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
728  | 
show_compilation = false,  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
729  | 
show_caught_failures = false,  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
730  | 
skip_proof = true,  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
731  | 
no_topmost_reordering = false,  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
732  | 
function_flattening = false,  | 
| 
36248
 
9ed1a37de465
added option for specialisation to the predicate compiler
 
bulwahn 
parents: 
36246 
diff
changeset
 | 
733  | 
specialise = false,  | 
| 
35324
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
734  | 
fail_safe_function_flattening = false,  | 
| 
 
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
 
bulwahn 
parents: 
35224 
diff
changeset
 | 
735  | 
no_higher_order_predicate = [],  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
736  | 
inductify = false,  | 
| 36254 | 737  | 
detect_switches = true,  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
738  | 
compilation = Pred  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
739  | 
}  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
740  | 
|
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
741  | 
val bool_options = ["show_steps", "show_intermediate_results", "show_proof_trace", "show_modes",  | 
| 
35381
 
5038f36b5ea1
adding no_topmost_reordering as new option to the code_pred command
 
bulwahn 
parents: 
35324 
diff
changeset
 | 
742  | 
"show_mode_inference", "show_compilation", "skip_proof", "inductify", "no_function_flattening",  | 
| 36254 | 743  | 
"detect_switches", "specialise", "no_topmost_reordering"]  | 
| 
34948
 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 
bulwahn 
parents: 
33752 
diff
changeset
 | 
744  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
745  | 
fun print_step options s =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
746  | 
if show_steps options then tracing s else ()  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
747  | 
|
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
748  | 
(* simple transformations *)  | 
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
749  | 
|
| 
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
750  | 
(** tuple processing **)  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
751  | 
|
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
752  | 
fun expand_tuples thy intro =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
753  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
754  | 
fun rewrite_args [] (pats, intro_t, ctxt) = (pats, intro_t, ctxt)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
755  | 
| rewrite_args (arg::args) (pats, intro_t, ctxt) =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
756  | 
(case HOLogic.strip_tupleT (fastype_of arg) of  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
757  | 
(Ts as _ :: _ :: _) =>  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
758  | 
let  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
759  | 
          fun rewrite_arg' (Const (@{const_name "Pair"}, _) $ _ $ t2, Type (@{type_name "*"}, [_, T2]))
 | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
760  | 
(args, (pats, intro_t, ctxt)) = rewrite_arg' (t2, T2) (args, (pats, intro_t, ctxt))  | 
| 
35885
 
7b39120a1494
some improvements thanks to Makarius source code review
 
bulwahn 
parents: 
35881 
diff
changeset
 | 
761  | 
            | rewrite_arg' (t, Type (@{type_name "*"}, [T1, T2])) (args, (pats, intro_t, ctxt)) =
 | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
762  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
763  | 
val ([x, y], ctxt') = Variable.variant_fixes ["x", "y"] ctxt  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
764  | 
val pat = (t, HOLogic.mk_prod (Free (x, T1), Free (y, T2)))  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
765  | 
val intro_t' = Pattern.rewrite_term thy [pat] [] intro_t  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
766  | 
val args' = map (Pattern.rewrite_term thy [pat] []) args  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
767  | 
in  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
768  | 
rewrite_arg' (Free (y, T2), T2) (args', (pat::pats, intro_t', ctxt'))  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
769  | 
end  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
770  | 
| rewrite_arg' _ (args, (pats, intro_t, ctxt)) = (args, (pats, intro_t, ctxt))  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
771  | 
val (args', (pats, intro_t', ctxt')) = rewrite_arg' (arg, fastype_of arg)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
772  | 
(args, (pats, intro_t, ctxt))  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
773  | 
in  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
774  | 
rewrite_args args' (pats, intro_t', ctxt')  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
775  | 
end  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
776  | 
| _ => rewrite_args args (pats, intro_t, ctxt))  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
777  | 
fun rewrite_prem atom =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
778  | 
let  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
779  | 
val (_, args) = strip_comb atom  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
780  | 
in rewrite_args args end  | 
| 
36610
 
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
 
wenzelm 
parents: 
36254 
diff
changeset
 | 
781  | 
val ctxt = ProofContext.init_global thy  | 
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
782  | 
val (((T_insts, t_insts), [intro']), ctxt1) = Variable.import false [intro] ctxt  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
783  | 
val intro_t = prop_of intro'  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
784  | 
val concl = Logic.strip_imp_concl intro_t  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
785  | 
val (p, args) = strip_comb (HOLogic.dest_Trueprop concl)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
786  | 
val (pats', intro_t', ctxt2) = rewrite_args args ([], intro_t, ctxt1)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
787  | 
val (pats', intro_t', ctxt3) =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
788  | 
fold_atoms rewrite_prem intro_t' (pats', intro_t', ctxt2)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
789  | 
fun rewrite_pat (ct1, ct2) =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
790  | 
(ct1, cterm_of thy (Pattern.rewrite_term thy pats' [] (term_of ct2)))  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
791  | 
val t_insts' = map rewrite_pat t_insts  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
792  | 
val intro'' = Thm.instantiate (T_insts, t_insts') intro  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
793  | 
val [intro'''] = Variable.export ctxt3 ctxt [intro'']  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
794  | 
val intro'''' = Simplifier.full_simplify  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
795  | 
      (HOL_basic_ss addsimps [@{thm fst_conv}, @{thm snd_conv}, @{thm Pair_eq}])
 | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
796  | 
intro'''  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
797  | 
(* splitting conjunctions introduced by Pair_eq*)  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
798  | 
fun split_conj prem =  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
799  | 
map HOLogic.mk_Trueprop (conjuncts (HOLogic.dest_Trueprop prem))  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
800  | 
val intro''''' = map_term thy (maps_premises split_conj) intro''''  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
801  | 
in  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
802  | 
intro'''''  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
803  | 
end  | 
| 
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
804  | 
|
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
805  | 
(** eta contract higher-order arguments **)  | 
| 35875 | 806  | 
|
807  | 
fun eta_contract_ho_arguments thy intro =  | 
|
808  | 
let  | 
|
809  | 
fun f atom = list_comb (apsnd ((map o map_products) Envir.eta_contract) (strip_comb atom))  | 
|
810  | 
in  | 
|
811  | 
map_term thy (map_concl f o map_atoms f) intro  | 
|
812  | 
end  | 
|
813  | 
||
| 
36047
 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 
bulwahn 
parents: 
36046 
diff
changeset
 | 
814  | 
(** remove equalities **)  | 
| 
36022
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
815  | 
|
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
816  | 
fun remove_equalities thy intro =  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
817  | 
let  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
818  | 
fun remove_eqs intro_t =  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
819  | 
let  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
820  | 
val (prems, concl) = Logic.strip_horn intro_t  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
821  | 
fun remove_eq (prems, concl) =  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
822  | 
let  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
823  | 
fun removable_eq prem =  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
824  | 
case try (HOLogic.dest_eq o HOLogic.dest_Trueprop) prem of  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
825  | 
SOME (lhs, rhs) => (case lhs of  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
826  | 
Var _ => true  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
827  | 
| _ => (case rhs of Var _ => true | _ => false))  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
828  | 
| NONE => false  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
829  | 
in  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
830  | 
case find_first removable_eq prems of  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
831  | 
NONE => (prems, concl)  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
832  | 
| SOME eq =>  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
833  | 
let  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
834  | 
val (lhs, rhs) = HOLogic.dest_eq (HOLogic.dest_Trueprop eq)  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
835  | 
val prems' = remove (op =) eq prems  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
836  | 
val subst = (case lhs of  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
837  | 
(v as Var _) =>  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
838  | 
(fn t => if t = v then rhs else t)  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
839  | 
| _ => (case rhs of  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
840  | 
(v as Var _) => (fn t => if t = v then lhs else t)))  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
841  | 
in  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
842  | 
remove_eq (map (map_aterms subst) prems', map_aterms subst concl)  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
843  | 
end  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
844  | 
end  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
845  | 
in  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
846  | 
Logic.list_implies (remove_eq (prems, concl))  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
847  | 
end  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
848  | 
in  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
849  | 
map_term thy remove_eqs intro  | 
| 
 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 
bulwahn 
parents: 
36018 
diff
changeset
 | 
850  | 
end  | 
| 35875 | 851  | 
|
| 
36246
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
852  | 
(* Some last processing *)  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
853  | 
|
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
854  | 
fun remove_pointless_clauses intro =  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
855  | 
  if Logic.strip_imp_prems (prop_of intro) = [@{prop "False"}] then
 | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
856  | 
[]  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
857  | 
else [intro]  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
858  | 
|
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
859  | 
(* some peephole optimisations *)  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
860  | 
|
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
861  | 
fun peephole_optimisation thy intro =  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
862  | 
let  | 
| 
36610
 
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
 
wenzelm 
parents: 
36254 
diff
changeset
 | 
863  | 
val process =  | 
| 
 
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
 
wenzelm 
parents: 
36254 
diff
changeset
 | 
864  | 
MetaSimplifier.rewrite_rule (Predicate_Compile_Simps.get (ProofContext.init_global thy))  | 
| 
36246
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
865  | 
fun process_False intro_t =  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
866  | 
      if member (op =) (Logic.strip_imp_prems intro_t) @{prop "False"} then NONE else SOME intro_t
 | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
867  | 
fun process_True intro_t =  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
868  | 
      map_filter_premises (fn p => if p = @{prop True} then NONE else SOME p) intro_t
 | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
869  | 
in  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
870  | 
Option.map (Skip_Proof.make_thm thy)  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
871  | 
(process_False (process_True (prop_of (process intro))))  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
872  | 
end  | 
| 
 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 
bulwahn 
parents: 
36049 
diff
changeset
 | 
873  | 
|
| 
33250
 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 
bulwahn 
parents:  
diff
changeset
 | 
874  | 
end;  |