| author | huffman | 
| Wed, 24 Aug 2011 11:56:57 -0700 | |
| changeset 44514 | d02b01e5ab8f | 
| parent 44241 | 7943b69f0188 | 
| child 45450 | dc2236b19a3d | 
| 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: 
36046diff
changeset | 7 | signature PREDICATE_COMPILE_AUX = | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 8 | sig | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 9 | (* general functions *) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
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: 
36046diff
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: 
36046diff
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: 
36046diff
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: 
36046diff
changeset | 14 | (* mode *) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 15 | 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: 
36046diff
changeset | 16 | val eq_mode : mode * mode -> bool | 
| 39311 | 17 | val mode_ord: mode * mode -> order | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 18 | val list_fun_mode : mode list -> mode | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 19 | val strip_fun_mode : mode -> mode list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 20 | val dest_fun_mode : mode -> mode list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 21 | val dest_tuple_mode : mode -> mode list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 22 | val all_modes_of_typ : typ -> mode list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 23 | val all_smodes_of_typ : typ -> mode list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
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: 
36046diff
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: 
36046diff
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: 
36046diff
changeset | 27 | val ho_arg_modes_of : mode -> mode list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
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: 
36046diff
changeset | 29 | val ho_args_of : mode -> term list -> term list | 
| 39299 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 30 | val ho_args_of_typ : typ -> term list -> term list | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 31 | val ho_argsT_of_typ : typ list -> typ list | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 32 | val split_map_mode : (mode -> term -> term option * term option) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 33 | -> mode -> term list -> term list * term list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 34 | val split_map_modeT : (mode -> typ -> typ option * typ option) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 35 | -> mode -> typ list -> typ list * typ list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 36 | val split_mode : mode -> term list -> term list * term list | 
| 40139 | 37 | val split_modeT : mode -> typ list -> typ list * typ list | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 38 | val string_of_mode : mode -> string | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 39 | val ascii_string_of_mode : mode -> string | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 40 | (* premises *) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 41 | 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: 
36046diff
changeset | 42 | | Generator of (string * typ) | 
| 36251 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 bulwahn parents: 
36248diff
changeset | 43 | val dest_indprem : indprem -> term | 
| 36254 | 44 | val map_indprem : (term -> term) -> indprem -> indprem | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 45 | (* general syntactic functions *) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 46 | val conjuncts : term -> term list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 47 | val is_equationlike : thm -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 48 | val is_pred_equation : thm -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 49 | val is_intro : string -> thm -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 50 | val is_predT : typ -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 51 | val is_constrt : theory -> term -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 52 | val is_constr : Proof.context -> string -> bool | 
| 42094 
e6867e9c6d10
allowing special set comprehensions in values command; adding an example for special set comprehension in values
 bulwahn parents: 
41228diff
changeset | 53 | val strip_ex : term -> (string * typ) list * term | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 54 | 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: 
36046diff
changeset | 55 | val strip_all : term -> (string * typ) list * term | 
| 40101 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 56 | val strip_intro_concl : thm -> term * term list | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 57 | (* introduction rule combinators *) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 58 | val map_atoms : (term -> term) -> term -> term | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 59 | val fold_atoms : (term -> 'a -> 'a) -> term -> 'a -> 'a | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 60 | 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: 
36046diff
changeset | 61 | val maps_premises : (term -> term list) -> term -> term | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 62 | val map_concl : (term -> term) -> term -> term | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 63 | val map_term : theory -> (term -> term) -> thm -> thm | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 64 | (* split theorems of case expressions *) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 65 | val prepare_split_thm : Proof.context -> thm -> thm | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 66 | val find_split_thm : theory -> term -> thm option | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 67 | (* datastructures and setup for generic compilation *) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 68 |   datatype compilation_funs = CompilationFuns of {
 | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 69 | mk_predT : typ -> typ, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 70 | dest_predT : typ -> typ, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 71 | mk_bot : typ -> term, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 72 | mk_single : term -> term, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 73 | mk_bind : term * term -> term, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 74 | mk_sup : term * term -> term, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 75 | 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: 
36047diff
changeset | 76 | mk_iterate_upto : typ -> term * term * term -> term, | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 77 | mk_not : term -> term, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 78 | mk_map : typ -> typ -> term -> term -> term | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 79 | }; | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 80 | val mk_predT : compilation_funs -> typ -> typ | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 81 | val dest_predT : compilation_funs -> typ -> typ | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 82 | val mk_bot : compilation_funs -> typ -> term | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 83 | val mk_single : compilation_funs -> term -> term | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 84 | val mk_bind : compilation_funs -> term * term -> term | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 85 | val mk_sup : compilation_funs -> term * term -> term | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 86 | 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: 
36047diff
changeset | 87 | 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: 
36046diff
changeset | 88 | val mk_not : compilation_funs -> term -> term | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 89 | val mk_map : compilation_funs -> typ -> typ -> term -> term -> term | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 90 | val funT_of : compilation_funs -> mode -> typ -> typ | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 91 | (* Different compilations *) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 92 | 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: 
36046diff
changeset | 93 | | Pos_Random_DSeq | Neg_Random_DSeq | New_Pos_Random_DSeq | New_Neg_Random_DSeq | 
| 40051 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 94 | | Pos_Generator_DSeq | Neg_Generator_DSeq | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 95 | val negative_compilation_of : compilation -> compilation | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 96 | val compilation_for_polarity : bool -> compilation -> compilation | 
| 40049 
75d9f57123d6
adding decreasing bind and non-decreasing bind; depth-limited and depth-unlimited compilation possible
 bulwahn parents: 
40048diff
changeset | 97 | val is_depth_limited_compilation : compilation -> bool | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 98 | val string_of_compilation : compilation -> string | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 99 | val compilation_names : (string * compilation) list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 100 | val non_random_compilations : compilation list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 101 | val random_compilations : compilation list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 102 | (* Different options for compiler *) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 103 |   datatype options = Options of {  
 | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 104 | expected_modes : (string * mode list) option, | 
| 39382 
c797f3ab2ae1
proposed modes for code_pred now supports modes for mutual predicates
 bulwahn parents: 
39312diff
changeset | 105 | proposed_modes : (string * mode list) list, | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 106 | proposed_names : ((string * mode) * string) list, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 107 | show_steps : bool, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 108 | show_proof_trace : bool, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 109 | show_intermediate_results : bool, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 110 | show_mode_inference : bool, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 111 | show_modes : bool, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 112 | show_compilation : bool, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 113 | show_caught_failures : bool, | 
| 39383 
ddfafa97da2f
adding option show_invalid_clauses for a more detailed message when modes are not inferred
 bulwahn parents: 
39382diff
changeset | 114 | show_invalid_clauses : bool, | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 115 | skip_proof : bool, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 116 | no_topmost_reordering : bool, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 117 | function_flattening : bool, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 118 | fail_safe_function_flattening : bool, | 
| 36248 
9ed1a37de465
added option for specialisation to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 119 | specialise : bool, | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 120 | no_higher_order_predicate : string list, | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 121 | inductify : bool, | 
| 36254 | 122 | detect_switches : bool, | 
| 40048 
f3a46d524101
adding option smart_depth_limiting to predicate compiler
 bulwahn parents: 
39802diff
changeset | 123 | smart_depth_limiting : bool, | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 124 | compilation : compilation | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 125 | }; | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 126 | val expected_modes : options -> (string * mode list) option | 
| 39382 
c797f3ab2ae1
proposed modes for code_pred now supports modes for mutual predicates
 bulwahn parents: 
39312diff
changeset | 127 | val proposed_modes : options -> string -> mode list option | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 128 | val proposed_names : options -> string -> mode -> string option | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 129 | val show_steps : options -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 130 | val show_proof_trace : options -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 131 | val show_intermediate_results : options -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 132 | val show_mode_inference : options -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 133 | val show_modes : options -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 134 | val show_compilation : options -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 135 | val show_caught_failures : options -> bool | 
| 39383 
ddfafa97da2f
adding option show_invalid_clauses for a more detailed message when modes are not inferred
 bulwahn parents: 
39382diff
changeset | 136 | val show_invalid_clauses : options -> bool | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 137 | val skip_proof : options -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 138 | val no_topmost_reordering : options -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 139 | val function_flattening : options -> bool | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 140 | val fail_safe_function_flattening : options -> bool | 
| 36248 
9ed1a37de465
added option for specialisation to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 141 | val specialise : options -> bool | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 142 | val no_higher_order_predicate : options -> string list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 143 | val is_inductify : options -> bool | 
| 36254 | 144 | val detect_switches : options -> bool | 
| 40048 
f3a46d524101
adding option smart_depth_limiting to predicate compiler
 bulwahn parents: 
39802diff
changeset | 145 | val smart_depth_limiting : options -> bool | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 146 | val compilation : options -> compilation | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 147 | val default_options : options | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 148 | val bool_options : string list | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 149 | val print_step : options -> string -> unit | 
| 39657 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 150 | (* conversions *) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 151 | val imp_prems_conv : conv -> conv | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 152 | (* simple transformations *) | 
| 39787 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 153 | val split_conjuncts_in_assms : Proof.context -> thm -> thm | 
| 40052 
ea46574ca815
splitting large core file into core_data, mode_inference and predicate_compile_proof
 bulwahn parents: 
40051diff
changeset | 154 | val dest_conjunct_prem : thm -> thm list | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 155 | val expand_tuples : theory -> thm -> thm | 
| 39802 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 156 | val case_betapply : theory -> term -> term | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 157 | val eta_contract_ho_arguments : theory -> thm -> thm | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 158 | 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: 
36049diff
changeset | 159 | 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: 
36049diff
changeset | 160 | val peephole_optimisation : theory -> thm -> thm option | 
| 40101 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 161 | (* auxillary *) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 162 | val unify_consts : theory -> term list -> term list -> (term list * term list) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 163 | val mk_casesrule : Proof.context -> term -> thm list -> term | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 164 | val preprocess_intro : theory -> thm -> thm | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 165 | |
| 39541 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 166 | val define_quickcheck_predicate : | 
| 40052 
ea46574ca815
splitting large core file into core_data, mode_inference and predicate_compile_proof
 bulwahn parents: 
40051diff
changeset | 167 | term -> theory -> (((string * typ) * (string * typ) list) * thm) * theory | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 168 | end; | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 169 | |
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 170 | 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 | 171 | struct | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 172 | |
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 173 | (* general functions *) | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 174 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 175 | 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: 
33752diff
changeset | 176 | 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: 
33752diff
changeset | 177 | 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: 
33752diff
changeset | 178 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 179 | 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: 
33752diff
changeset | 180 | | 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: 
33752diff
changeset | 181 | | 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: 
33752diff
changeset | 182 | | 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: 
33752diff
changeset | 183 | |
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 184 | 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: 
33752diff
changeset | 185 | | 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: 
33752diff
changeset | 186 | | map2_optional f [] [] = [] | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 187 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 188 | 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: 
33752diff
changeset | 189 | 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: 
33327diff
changeset | 190 | |
| 
1d93dd8a02c9
moved datatype mode and string functions to the auxillary structure
 bulwahn parents: 
33327diff
changeset | 191 | (* mode *) | 
| 
1d93dd8a02c9
moved datatype mode and string functions to the auxillary structure
 bulwahn parents: 
33327diff
changeset | 192 | |
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 193 | 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: 
33473diff
changeset | 194 | |
| 33623 
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
 bulwahn parents: 
33620diff
changeset | 195 | (* 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: 
33620diff
changeset | 196 | 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: 
33752diff
changeset | 197 | 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: 
33752diff
changeset | 198 | | 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: 
33752diff
changeset | 199 | | 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: 
33752diff
changeset | 200 | | 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: 
33752diff
changeset | 201 | | 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: 
33752diff
changeset | 202 | | 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: 
33752diff
changeset | 203 | | 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: 
33752diff
changeset | 204 | | 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: 
33752diff
changeset | 205 | | 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: 
33752diff
changeset | 206 | | eq_mode _ = false | 
| 33623 
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
 bulwahn parents: 
33620diff
changeset | 207 | |
| 39311 | 208 | fun mode_ord (Input, Output) = LESS | 
| 209 | | mode_ord (Output, Input) = GREATER | |
| 210 | | mode_ord (Input, Input) = EQUAL | |
| 211 | | mode_ord (Output, Output) = EQUAL | |
| 212 | | mode_ord (Bool, Bool) = EQUAL | |
| 213 | | mode_ord (Pair (m1, m2), Pair (m3, m4)) = prod_ord mode_ord mode_ord ((m1, m2), (m3, m4)) | |
| 214 | | mode_ord (Fun (m1, m2), Fun (m3, m4)) = prod_ord mode_ord mode_ord ((m1, m2), (m3, m4)) | |
| 215 | ||
| 36035 
d82682936c52
adding registration of functions in the function flattening
 bulwahn parents: 
36032diff
changeset | 216 | fun list_fun_mode [] = Bool | 
| 
d82682936c52
adding registration of functions in the function flattening
 bulwahn parents: 
36032diff
changeset | 217 | | list_fun_mode (m :: ms) = Fun (m, list_fun_mode ms) | 
| 
d82682936c52
adding registration of functions in the function flattening
 bulwahn parents: 
36032diff
changeset | 218 | |
| 33619 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 bulwahn parents: 
33473diff
changeset | 219 | (* name: binder_modes? *) | 
| 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 bulwahn parents: 
33473diff
changeset | 220 | 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: 
33473diff
changeset | 221 | | strip_fun_mode Bool = [] | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 222 | | 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: 
33473diff
changeset | 223 | |
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 224 | (* 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: 
33473diff
changeset | 225 | 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: 
33473diff
changeset | 226 | | 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: 
33473diff
changeset | 227 | |
| 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 bulwahn parents: 
33473diff
changeset | 228 | 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: 
33473diff
changeset | 229 | | dest_tuple_mode _ = [] | 
| 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 bulwahn parents: 
33473diff
changeset | 230 | |
| 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: 
35224diff
changeset | 231 | 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: 
35224diff
changeset | 232 | 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: 
35224diff
changeset | 233 | 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: 
35224diff
changeset | 234 | 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: 
35224diff
changeset | 235 | 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: 
35224diff
changeset | 236 | 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: 
35224diff
changeset | 237 | (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: 
35224diff
changeset | 238 | 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: 
35224diff
changeset | 239 | [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: 
35224diff
changeset | 240 | end | 
| 37678 
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
 haftmann parents: 
37391diff
changeset | 241 |   | all_modes_of_typ' (Type (@{type_name Product_Type.prod}, [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: 
35224diff
changeset | 242 | 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: 
35224diff
changeset | 243 | | 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: 
35224diff
changeset | 244 | |
| 
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: 
35224diff
changeset | 245 | fun all_modes_of_typ (T as Type ("fun", _)) =
 | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 246 | let | 
| 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 247 | val (S, U) = strip_type T | 
| 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 248 | in | 
| 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 249 |       if U = @{typ bool} then
 | 
| 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 250 | fold_rev (fn m1 => fn m2 => map_product (curry Fun) m1 m2) | 
| 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 251 | (map all_modes_of_typ' S) [Bool] | 
| 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 252 | else | 
| 39192 
f302ed18f42f
raising an exception instead of guessing some reasonable behaviour for this function
 bulwahn parents: 
38864diff
changeset | 253 | raise Fail "Invocation of all_modes_of_typ with a non-predicate type" | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 254 | end | 
| 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 255 |   | all_modes_of_typ @{typ bool} = [Bool]
 | 
| 39192 
f302ed18f42f
raising an exception instead of guessing some reasonable behaviour for this function
 bulwahn parents: 
38864diff
changeset | 256 | | all_modes_of_typ T = | 
| 
f302ed18f42f
raising an exception instead of guessing some reasonable behaviour for this function
 bulwahn parents: 
38864diff
changeset | 257 | raise Fail "Invocation of all_modes_of_typ with a non-predicate type" | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 258 | |
| 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: 
35224diff
changeset | 259 | 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: 
35224diff
changeset | 260 | 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: 
35224diff
changeset | 261 | val (S, U) = strip_type T | 
| 37678 
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
 haftmann parents: 
37391diff
changeset | 262 |     fun all_smodes (Type (@{type_name Product_Type.prod}, [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: 
35224diff
changeset | 263 | 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: 
35224diff
changeset | 264 | | 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: 
35224diff
changeset | 265 | 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: 
35224diff
changeset | 266 | 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: 
35224diff
changeset | 267 | 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: 
35224diff
changeset | 268 | else | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 269 | 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: 
35224diff
changeset | 270 | end | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 271 | |
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 272 | 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: 
33752diff
changeset | 273 | let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 274 | 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: 
33752diff
changeset | 275 | | 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: 
33752diff
changeset | 276 | | ho_arg_mode _ = [] | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 277 | in | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 278 | 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: 
33752diff
changeset | 279 | end | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 280 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 281 | 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: 
33752diff
changeset | 282 | let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 283 | fun ho_arg (Fun _) (SOME t) = [t] | 
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 284 | | ho_arg (Fun _) NONE = raise Fail "mode and term do not match" | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 285 |       | 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: 
33752diff
changeset | 286 | 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: 
33752diff
changeset | 287 | | 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: 
33752diff
changeset | 288 | | ho_arg _ _ = [] | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 289 | in | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 290 | 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: 
33752diff
changeset | 291 | end | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 292 | |
| 39299 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 293 | fun ho_args_of_typ T ts = | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 294 | let | 
| 39312 
968c33be5c96
handling function types more carefully than in e98a06145530
 bulwahn parents: 
39311diff
changeset | 295 |     fun ho_arg (T as Type("fun", [_,_])) (SOME t) = if body_type T = @{typ bool} then [t] else []
 | 
| 39299 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 296 |       | ho_arg (Type("fun", [_,_])) NONE = raise Fail "mode and term do not match"
 | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 297 |       | ho_arg (Type(@{type_name "Product_Type.prod"}, [T1, T2]))
 | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 298 |          (SOME (Const (@{const_name Pair}, _) $ t1 $ t2)) =
 | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 299 | ho_arg T1 (SOME t1) @ ho_arg T2 (SOME t2) | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 300 |       | ho_arg (Type(@{type_name "Product_Type.prod"}, [T1, T2])) NONE =
 | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 301 | ho_arg T1 NONE @ ho_arg T2 NONE | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 302 | | ho_arg _ _ = [] | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 303 | in | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 304 | flat (map2_optional ho_arg (binder_types T) ts) | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 305 | end | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 306 | |
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 307 | fun ho_argsT_of_typ Ts = | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 308 | let | 
| 39312 
968c33be5c96
handling function types more carefully than in e98a06145530
 bulwahn parents: 
39311diff
changeset | 309 |     fun ho_arg (T as Type("fun", [_,_])) = if body_type T = @{typ bool} then [T] else []
 | 
| 39299 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 310 |       | ho_arg (Type(@{type_name "Product_Type.prod"}, [T1, T2])) =
 | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 311 | ho_arg T1 @ ho_arg T2 | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 312 | | ho_arg _ = [] | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 313 | in | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 314 | maps ho_arg Ts | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 315 | end | 
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 316 | |
| 
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
 bulwahn parents: 
39192diff
changeset | 317 | |
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 318 | (* 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: 
33752diff
changeset | 319 | 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: 
33752diff
changeset | 320 | let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 321 | fun replace (Fun _, _) (arg' :: hoargs') = (arg', hoargs') | 
| 37391 | 322 |       | replace (Pair (m1, m2), Const (@{const_name Pair}, T) $ t1 $ t2) hoargs =
 | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 323 | let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 324 | 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: 
33752diff
changeset | 325 | 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: 
33752diff
changeset | 326 | in | 
| 37391 | 327 |           (Const (@{const_name Pair}, T) $ t1' $ t2', hoargs'')
 | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 328 | end | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 329 | | 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: 
33752diff
changeset | 330 | in | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 331 | 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: 
33752diff
changeset | 332 | end | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 333 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 334 | 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: 
33752diff
changeset | 335 | let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 336 | fun ho_arg (Fun _) T = [T] | 
| 37678 
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
 haftmann parents: 
37391diff
changeset | 337 |       | ho_arg (Pair (m1, m2)) (Type (@{type_name Product_Type.prod}, [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: 
33752diff
changeset | 338 | | ho_arg _ _ = [] | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 339 | in | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 340 | 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: 
33752diff
changeset | 341 | end | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 342 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 343 | (* 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: 
33752diff
changeset | 344 | 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: 
33752diff
changeset | 345 | let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 346 | fun split_arg_mode' (m as Fun _) t = f m t | 
| 37391 | 347 |       | split_arg_mode' (Pair (m1, m2)) (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: 
33752diff
changeset | 348 | let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 349 | 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: 
33752diff
changeset | 350 | 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: 
33752diff
changeset | 351 | in | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 352 | (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: 
33752diff
changeset | 353 | 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: 
35224diff
changeset | 354 | | 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: 
35224diff
changeset | 355 | 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: 
35224diff
changeset | 356 | else if eq_mode (m, Output) then (NONE, SOME t) | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 357 | 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: 
33752diff
changeset | 358 | in | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 359 | (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: 
33752diff
changeset | 360 | end | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 361 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 362 | (* 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: 
33752diff
changeset | 363 | 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: 
33752diff
changeset | 364 | let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 365 | fun split_arg_mode' (m as Fun _) T = f m T | 
| 37678 
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
 haftmann parents: 
37391diff
changeset | 366 |       | split_arg_mode' (Pair (m1, m2)) (Type (@{type_name Product_Type.prod}, [T1, T2])) =
 | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 367 | let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 368 | 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: 
33752diff
changeset | 369 | 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: 
33752diff
changeset | 370 | in | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 371 | (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: 
33752diff
changeset | 372 | end | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 373 | | 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: 
33752diff
changeset | 374 | | split_arg_mode' Output T = (NONE, SOME T) | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 375 | | 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: 
33752diff
changeset | 376 | in | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 377 | (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: 
33752diff
changeset | 378 | end | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 379 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 380 | 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: 
33752diff
changeset | 381 | |
| 37678 
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
 haftmann parents: 
37391diff
changeset | 382 | fun fold_map_aterms_prodT comb f (Type (@{type_name Product_Type.prod}, [T1, T2])) s =
 | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 383 | let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 384 | 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: 
33752diff
changeset | 385 | 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: 
33752diff
changeset | 386 | in | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 387 | (comb x1 x2, s'') | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 388 | end | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 389 | | 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: 
33752diff
changeset | 390 | |
| 37391 | 391 | fun map_filter_prod f (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: 
33752diff
changeset | 392 | 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: 
33752diff
changeset | 393 | | 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: 
33752diff
changeset | 394 | |
| 40139 | 395 | fun split_modeT mode Ts = | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 396 | let | 
| 40139 | 397 | fun split_arg_mode (Fun _) T = ([], []) | 
| 398 |       | split_arg_mode (Pair (m1, m2)) (Type (@{type_name Product_Type.prod}, [T1, T2])) =
 | |
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 399 | let | 
| 40139 | 400 | val (i1, o1) = split_arg_mode m1 T1 | 
| 401 | val (i2, o2) = split_arg_mode m2 T2 | |
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 402 | in | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 403 | (i1 @ i2, o1 @ o2) | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 404 | end | 
| 40139 | 405 | | split_arg_mode Input T = ([T], []) | 
| 406 | | split_arg_mode Output T = ([], [T]) | |
| 407 | | 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: 
33752diff
changeset | 408 | in | 
| 40139 | 409 | (pairself flat o split_list) (map2 split_arg_mode (strip_fun_mode mode) Ts) | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 410 | end | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 411 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 412 | 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: 
33473diff
changeset | 413 | let | 
| 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 bulwahn parents: 
33473diff
changeset | 414 | 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: 
33473diff
changeset | 415 | | 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: 
33473diff
changeset | 416 | | 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: 
33473diff
changeset | 417 |       | string_of_mode1 mode = "(" ^ (string_of_mode3 mode) ^ ")"
 | 
| 33626 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 418 | 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: 
33473diff
changeset | 419 | | 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: 
33473diff
changeset | 420 | 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: 
33473diff
changeset | 421 | | 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: 
33752diff
changeset | 422 | 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: 
33473diff
changeset | 423 | |
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 424 | fun ascii_string_of_mode mode' = | 
| 33626 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 425 | let | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 426 | fun ascii_string_of_mode' Input = "i" | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 427 | | ascii_string_of_mode' Output = "o" | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 428 | | ascii_string_of_mode' Bool = "b" | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 429 | | ascii_string_of_mode' (Pair (m1, m2)) = | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 430 | "P" ^ ascii_string_of_mode' m1 ^ ascii_string_of_mode'_Pair m2 | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 431 | | ascii_string_of_mode' (Fun (m1, m2)) = | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 432 | "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: 
33623diff
changeset | 433 | and ascii_string_of_mode'_Fun (Fun (m1, m2)) = | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 434 | 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: 
33623diff
changeset | 435 | | ascii_string_of_mode'_Fun Bool = "B" | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 436 | | ascii_string_of_mode'_Fun m = ascii_string_of_mode' m | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 437 | and ascii_string_of_mode'_Pair (Pair (m1, m2)) = | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 438 | ascii_string_of_mode' m1 ^ ascii_string_of_mode'_Pair m2 | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 439 | | ascii_string_of_mode'_Pair m = ascii_string_of_mode' m | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 440 | in ascii_string_of_mode'_Fun mode' end | 
| 
42f69386943a
new names for predicate functions in the predicate compiler
 bulwahn parents: 
33623diff
changeset | 441 | |
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 442 | (* premises *) | 
| 33619 
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
 bulwahn parents: 
33473diff
changeset | 443 | |
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 444 | 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: 
33752diff
changeset | 445 | | 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: 
33473diff
changeset | 446 | |
| 36251 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 bulwahn parents: 
36248diff
changeset | 447 | fun dest_indprem (Prem t) = t | 
| 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 bulwahn parents: 
36248diff
changeset | 448 | | dest_indprem (Negprem t) = t | 
| 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 bulwahn parents: 
36248diff
changeset | 449 | | dest_indprem (Sidecond t) = t | 
| 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 bulwahn parents: 
36248diff
changeset | 450 | | dest_indprem (Generator _) = raise Fail "cannot destruct generator" | 
| 
5fd5d732a4ea
only add relevant predicates to the list of extra modes
 bulwahn parents: 
36248diff
changeset | 451 | |
| 36254 | 452 | fun map_indprem f (Prem t) = Prem (f t) | 
| 453 | | map_indprem f (Negprem t) = Negprem (f t) | |
| 454 | | map_indprem f (Sidecond t) = Sidecond (f t) | |
| 455 | | map_indprem f (Generator (v, T)) = Generator (dest_Free (f (Free (v, T)))) | |
| 456 | ||
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 457 | (* general syntactic functions *) | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 458 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 459 | (*Like dest_conj, but flattens conjunctions however nested*) | 
| 38795 
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
 haftmann parents: 
38558diff
changeset | 460 | fun conjuncts_aux (Const (@{const_name HOL.conj}, _) $ t $ t') conjs = conjuncts_aux t (conjuncts_aux t' conjs)
 | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 461 | | conjuncts_aux t conjs = t::conjs; | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 462 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 463 | fun conjuncts t = conjuncts_aux t []; | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 464 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 465 | fun is_equationlike_term (Const ("==", _) $ _ $ _) = true
 | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38795diff
changeset | 466 |   | is_equationlike_term (Const (@{const_name Trueprop}, _) $ (Const (@{const_name HOL.eq}, _) $ _ $ _)) = true
 | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 467 | | is_equationlike_term _ = false | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 468 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 469 | 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 | 470 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 471 | 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 | 472 |   (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 | 473 | | is_pred_equation_term _ = false | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 474 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 475 | 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 | 476 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 477 | 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: 
33752diff
changeset | 478 | 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 | 479 | 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: 
33752diff
changeset | 480 | | _ => false) t) | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 481 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 482 | 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 | 483 | |
| 38552 | 484 | fun is_pred thy constname = (body_type (Sign.the_const_type thy constname) = HOLogic.boolT); | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 485 | |
| 40844 | 486 | fun is_predT (T as Type("fun", [_, _])) = (body_type T = @{typ bool})
 | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 487 | | is_predT _ = false | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 488 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 489 | (*** 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: 
33752diff
changeset | 490 | (* 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: 
33620diff
changeset | 491 | (* 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: 
33620diff
changeset | 492 | sees constructors.*) | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 493 | fun is_constrt thy = | 
| 
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 cnstrs = flat (maps | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 496 | (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 | 497 | (Symtab.dest (Datatype.get_all thy))); | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 498 | fun check t = (case strip_comb t of | 
| 36032 
dfd30b5b4e73
adding specialisation of predicates to the predicate compiler
 bulwahn parents: 
36029diff
changeset | 499 | (Var _, []) => true | 
| 
dfd30b5b4e73
adding specialisation of predicates to the predicate compiler
 bulwahn parents: 
36029diff
changeset | 500 | | (Free _, []) => true | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 501 | | (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 | 502 | (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 | 503 | | _ => false) | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 504 | | _ => false) | 
| 36032 
dfd30b5b4e73
adding specialisation of predicates to the predicate compiler
 bulwahn parents: 
36029diff
changeset | 505 | in check end; | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 506 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 507 | 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: 
33752diff
changeset | 508 | | is_funtype _ = false; | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 509 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 510 | 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: 
33752diff
changeset | 511 | | is_Type _ = false | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 512 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 513 | (* 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: 
33752diff
changeset | 514 | (* 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: 
33752diff
changeset | 515 | (* else false *) | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 516 | (* | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 517 | 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: 
33752diff
changeset | 518 | 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: 
33752diff
changeset | 519 | (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: 
33752diff
changeset | 520 | NONE => false | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 521 | | SOME info => (let | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 522 | 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: 
33752diff
changeset | 523 | 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: 
33752diff
changeset | 524 | in (case c of | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 525 | 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: 
33752diff
changeset | 526 | | _ => false) end)) | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 527 | else false | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 528 | *) | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 529 | |
| 42361 | 530 | val is_constr = Code.is_constr o Proof_Context.theory_of; | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 531 | |
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 532 | 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: 
36046diff
changeset | 533 | |
| 38558 | 534 | fun strip_ex (Const (@{const_name Ex}, _) $ Abs (x, T, t)) =
 | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 535 | let | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 536 | val (xTs, t') = strip_ex t | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 537 | in | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 538 | ((x, T) :: xTs, t') | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 539 | end | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 540 | | strip_ex t = ([], t) | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 541 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 542 | fun focus_ex t nctxt = | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 543 | let | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 544 | val ((xs, Ts), t') = apfst split_list (strip_ex t) | 
| 43326 
47cf4bc789aa
simplified Name.variant -- discontinued builtin fold_map;
 wenzelm parents: 
43324diff
changeset | 545 | val (xs', nctxt') = fold_map Name.variant xs nctxt; | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 546 | val ps' = xs' ~~ Ts; | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 547 | val vs = map Free ps'; | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 548 | 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 | 549 | in ((ps', t''), nctxt') end; | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 550 | |
| 40101 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 551 | val strip_intro_concl = (strip_comb o HOLogic.dest_Trueprop o Logic.strip_imp_concl o prop_of) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 552 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 553 | (* introduction rule combinators *) | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 554 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 555 | fun map_atoms f intro = | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 556 | let | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 557 | val (literals, head) = Logic.strip_horn intro | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 558 | fun appl t = (case t of | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 559 |         (@{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 | 560 | | _ => f t) | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 561 | in | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 562 | Logic.list_implies | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 563 | (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 | 564 | end | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 565 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 566 | fun fold_atoms f intro s = | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 567 | let | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 568 | val (literals, head) = Logic.strip_horn intro | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 569 | fun appl t s = (case t of | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 570 |       (@{term Not} $ t') => f t' s
 | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 571 | | _ => f t s) | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 572 | 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 | 573 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 574 | fun fold_map_atoms f intro s = | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 575 | let | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 576 | val (literals, head) = Logic.strip_horn intro | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 577 | fun appl t s = (case t of | 
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 578 |       (@{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 | 579 | | _ => f t s) | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 580 | 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 | 581 | in | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 582 | (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 | 583 | end; | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 584 | |
| 36246 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 585 | fun map_premises f intro = | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 586 | let | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 587 | 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: 
36049diff
changeset | 588 | in | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 589 | 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: 
36049diff
changeset | 590 | end | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 591 | |
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 592 | fun map_filter_premises f intro = | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 593 | let | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 594 | 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: 
36049diff
changeset | 595 | in | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 596 | 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: 
36049diff
changeset | 597 | end | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 598 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 599 | fun maps_premises f intro = | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 600 | let | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 601 | val (premises, head) = Logic.strip_horn intro | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 602 | in | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 603 | Logic.list_implies (maps f premises, head) | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 604 | 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: 
35224diff
changeset | 605 | |
| 35875 | 606 | fun map_concl f intro = | 
| 607 | let | |
| 608 | val (premises, head) = Logic.strip_horn intro | |
| 609 | in | |
| 610 | Logic.list_implies (premises, f head) | |
| 611 | end | |
| 612 | ||
| 613 | (* combinators to apply a function to all basic parts of nested products *) | |
| 614 | ||
| 37391 | 615 | fun map_products f (Const (@{const_name Pair}, T) $ t1 $ t2) =
 | 
| 616 |   Const (@{const_name Pair}, T) $ map_products f t1 $ map_products f t2
 | |
| 35875 | 617 | | 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: 
35224diff
changeset | 618 | |
| 
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: 
35224diff
changeset | 619 | (* 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: 
35224diff
changeset | 620 | |
| 
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: 
35224diff
changeset | 621 | 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: 
35224diff
changeset | 622 |     (split_thm RS @{thm iffD2})
 | 
| 35624 | 623 |     |> 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: 
35224diff
changeset | 624 |       @{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: 
35224diff
changeset | 625 | |
| 36029 
a790b94e090c
removing fishing for split thm in the predicate compiler
 bulwahn parents: 
36022diff
changeset | 626 | 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: 
36022diff
changeset | 627 | | 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: 
35224diff
changeset | 628 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 629 | (* lifting term operations to theorems *) | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 630 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 631 | fun map_term thy f th = | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 632 | 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 | 633 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 634 | (* | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 635 | 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 | 636 | case Thm.term_of ct of | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 637 |     Const ("==", _) $ _ $ _ => Conv.arg_conv cv ct  
 | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 638 | | _ => error "equals_conv" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 639 | *) | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 640 | |
| 36038 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 bulwahn parents: 
36035diff
changeset | 641 | (* Different compilations *) | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 642 | |
| 35881 
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
 bulwahn parents: 
35880diff
changeset | 643 | datatype compilation = Pred | Depth_Limited | Random | Depth_Limited_Random | DSeq | Annotated | 
| 40051 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 644 | | Pos_Random_DSeq | Neg_Random_DSeq | New_Pos_Random_DSeq | New_Neg_Random_DSeq | | 
| 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 645 | Pos_Generator_DSeq | Neg_Generator_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: 
35224diff
changeset | 646 | |
| 
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: 
35224diff
changeset | 647 | 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: 
35224diff
changeset | 648 | | negative_compilation_of Neg_Random_DSeq = Pos_Random_DSeq | 
| 36018 | 649 | | negative_compilation_of New_Pos_Random_DSeq = New_Neg_Random_DSeq | 
| 650 | | negative_compilation_of New_Neg_Random_DSeq = New_Pos_Random_DSeq | |
| 40051 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 651 | | negative_compilation_of Pos_Generator_DSeq = Neg_Generator_DSeq | 
| 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 652 | | negative_compilation_of Pos_Generator_DSeq = Pos_Generator_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: 
35224diff
changeset | 653 | | 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: 
35224diff
changeset | 654 | |
| 
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: 
35224diff
changeset | 655 | fun compilation_for_polarity false Pos_Random_DSeq = Neg_Random_DSeq | 
| 36018 | 656 | | 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: 
35224diff
changeset | 657 | | 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: 
33752diff
changeset | 658 | |
| 40049 
75d9f57123d6
adding decreasing bind and non-decreasing bind; depth-limited and depth-unlimited compilation possible
 bulwahn parents: 
40048diff
changeset | 659 | fun is_depth_limited_compilation c = | 
| 40051 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 660 | (c = New_Pos_Random_DSeq) orelse (c = New_Neg_Random_DSeq) orelse | 
| 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 661 | (c = Pos_Generator_DSeq) orelse (c = Pos_Generator_DSeq) | 
| 40049 
75d9f57123d6
adding decreasing bind and non-decreasing bind; depth-limited and depth-unlimited compilation possible
 bulwahn parents: 
40048diff
changeset | 662 | |
| 35885 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 663 | fun string_of_compilation c = | 
| 
7b39120a1494
some improvements thanks to Makarius source code review
 bulwahn parents: 
35881diff
changeset | 664 | case c of | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 665 | Pred => "" | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 666 | | Random => "random" | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 667 | | Depth_Limited => "depth limited" | 
| 35881 
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
 bulwahn parents: 
35880diff
changeset | 668 | | 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: 
33752diff
changeset | 669 | | DSeq => "dseq" | 
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 670 | | 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: 
35224diff
changeset | 671 | | 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: 
35224diff
changeset | 672 | | Neg_Random_DSeq => "neg_random_dseq" | 
| 36018 | 673 | | New_Pos_Random_DSeq => "new_pos_random dseq" | 
| 674 | | New_Neg_Random_DSeq => "new_neg_random_dseq" | |
| 40051 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 675 | | Pos_Generator_DSeq => "pos_generator_dseq" | 
| 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 676 | | Neg_Generator_DSeq => "neg_generator_dseq" | 
| 36038 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 bulwahn parents: 
36035diff
changeset | 677 | |
| 36018 | 678 | val compilation_names = [("pred", Pred),
 | 
| 679 |   ("random", Random),
 | |
| 680 |   ("depth_limited", Depth_Limited),
 | |
| 681 |   ("depth_limited_random", Depth_Limited_Random),
 | |
| 682 |   (*("annotated", Annotated),*)
 | |
| 40054 
cd7b1fa20bce
adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
 bulwahn parents: 
40052diff
changeset | 683 |   ("dseq", DSeq),
 | 
| 
cd7b1fa20bce
adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
 bulwahn parents: 
40052diff
changeset | 684 |   ("random_dseq", Pos_Random_DSeq),
 | 
| 40051 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 685 |   ("new_random_dseq", New_Pos_Random_DSeq),
 | 
| 
b6acda4d1c29
added generator_dseq compilation for a sound depth-limited compilation with small value generators
 bulwahn parents: 
40049diff
changeset | 686 |   ("generator_dseq", Pos_Generator_DSeq)]
 | 
| 36038 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 bulwahn parents: 
36035diff
changeset | 687 | |
| 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 bulwahn parents: 
36035diff
changeset | 688 | val non_random_compilations = [Pred, Depth_Limited, DSeq, Annotated] | 
| 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 bulwahn parents: 
36035diff
changeset | 689 | |
| 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 bulwahn parents: 
36035diff
changeset | 690 | |
| 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 bulwahn parents: 
36035diff
changeset | 691 | val random_compilations = [Random, Depth_Limited_Random, | 
| 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 bulwahn parents: 
36035diff
changeset | 692 | 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: 
36035diff
changeset | 693 | |
| 36046 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 694 | (* datastructures and setup for generic compilation *) | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 695 | |
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 696 | datatype compilation_funs = CompilationFuns of {
 | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 697 | mk_predT : typ -> typ, | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 698 | dest_predT : typ -> typ, | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 699 | mk_bot : typ -> term, | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 700 | mk_single : term -> term, | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 701 | mk_bind : term * term -> term, | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 702 | mk_sup : term * term -> term, | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 703 | 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: 
36047diff
changeset | 704 | mk_iterate_upto : typ -> term * term * term -> term, | 
| 36046 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 705 | mk_not : term -> term, | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 706 | mk_map : typ -> typ -> term -> term -> term | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 707 | }; | 
| 36038 
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
 bulwahn parents: 
36035diff
changeset | 708 | |
| 36046 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 709 | fun mk_predT (CompilationFuns funs) = #mk_predT funs | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 710 | fun dest_predT (CompilationFuns funs) = #dest_predT funs | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 711 | fun mk_bot (CompilationFuns funs) = #mk_bot funs | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 712 | fun mk_single (CompilationFuns funs) = #mk_single funs | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 713 | fun mk_bind (CompilationFuns funs) = #mk_bind funs | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 714 | fun mk_sup (CompilationFuns funs) = #mk_sup funs | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 715 | 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: 
36047diff
changeset | 716 | fun mk_iterate_upto (CompilationFuns funs) = #mk_iterate_upto funs | 
| 36046 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 717 | fun mk_not (CompilationFuns funs) = #mk_not funs | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 718 | fun mk_map (CompilationFuns funs) = #mk_map funs | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 719 | |
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 720 | (** function types and names of different compilations **) | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 721 | |
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 722 | fun funT_of compfuns mode T = | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 723 | let | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 724 | val Ts = binder_types T | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 725 | 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: 
36038diff
changeset | 726 | in | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 727 | inTs ---> (mk_predT compfuns (HOLogic.mk_tupleT outTs)) | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 728 | end; | 
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 729 | |
| 
c3946372f556
putting compilation setup of predicate compiler in a separate file
 bulwahn parents: 
36038diff
changeset | 730 | (* 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: 
33752diff
changeset | 731 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 732 | 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: 
33752diff
changeset | 733 | expected_modes : (string * mode list) option, | 
| 39382 
c797f3ab2ae1
proposed modes for code_pred now supports modes for mutual predicates
 bulwahn parents: 
39312diff
changeset | 734 | proposed_modes : (string * mode list) list, | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 735 | proposed_names : ((string * mode) * string) list, | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 736 | show_steps : bool, | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 737 | show_proof_trace : bool, | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 738 | show_intermediate_results : bool, | 
| 33251 | 739 | show_mode_inference : bool, | 
| 740 | show_modes : bool, | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 741 | 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: 
35224diff
changeset | 742 | show_caught_failures : bool, | 
| 39383 
ddfafa97da2f
adding option show_invalid_clauses for a more detailed message when modes are not inferred
 bulwahn parents: 
39382diff
changeset | 743 | show_invalid_clauses : bool, | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 744 | 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: 
35224diff
changeset | 745 | 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: 
35224diff
changeset | 746 | function_flattening : bool, | 
| 36248 
9ed1a37de465
added option for specialisation to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 747 | 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: 
35224diff
changeset | 748 | 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: 
35224diff
changeset | 749 | no_higher_order_predicate : string list, | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 750 | inductify : bool, | 
| 36254 | 751 | detect_switches : bool, | 
| 40048 
f3a46d524101
adding option smart_depth_limiting to predicate compiler
 bulwahn parents: 
39802diff
changeset | 752 | smart_depth_limiting : bool, | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 753 | compilation : compilation | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 754 | }; | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 755 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 756 | fun expected_modes (Options opt) = #expected_modes opt | 
| 39382 
c797f3ab2ae1
proposed modes for code_pred now supports modes for mutual predicates
 bulwahn parents: 
39312diff
changeset | 757 | fun proposed_modes (Options opt) = AList.lookup (op =) (#proposed_modes opt) | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 758 | 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: 
33620diff
changeset | 759 | (#proposed_names opt) (name, mode) | 
| 33620 
b6bf2dc5aed7
added interface of user proposals for names of generated constants
 bulwahn parents: 
33619diff
changeset | 760 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 761 | 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 | 762 | 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 | 763 | fun show_proof_trace (Options opt) = #show_proof_trace opt | 
| 33251 | 764 | fun show_modes (Options opt) = #show_modes opt | 
| 765 | 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 | 766 | 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: 
35224diff
changeset | 767 | fun show_caught_failures (Options opt) = #show_caught_failures opt | 
| 39383 
ddfafa97da2f
adding option show_invalid_clauses for a more detailed message when modes are not inferred
 bulwahn parents: 
39382diff
changeset | 768 | fun show_invalid_clauses (Options opt) = #show_invalid_clauses opt | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 769 | 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 | 770 | |
| 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: 
35224diff
changeset | 771 | 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: 
35224diff
changeset | 772 | fun fail_safe_function_flattening (Options opt) = #fail_safe_function_flattening opt | 
| 36248 
9ed1a37de465
added option for specialisation to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 773 | 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: 
35224diff
changeset | 774 | 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: 
35224diff
changeset | 775 | 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: 
35224diff
changeset | 776 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 777 | 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: 
33752diff
changeset | 778 | |
| 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 779 | fun compilation (Options opt) = #compilation opt | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 780 | |
| 36254 | 781 | fun detect_switches (Options opt) = #detect_switches opt | 
| 782 | ||
| 40048 
f3a46d524101
adding option smart_depth_limiting to predicate compiler
 bulwahn parents: 
39802diff
changeset | 783 | fun smart_depth_limiting (Options opt) = #smart_depth_limiting opt | 
| 
f3a46d524101
adding option smart_depth_limiting to predicate compiler
 bulwahn parents: 
39802diff
changeset | 784 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 785 | val default_options = Options {
 | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 786 | expected_modes = NONE, | 
| 39382 
c797f3ab2ae1
proposed modes for code_pred now supports modes for mutual predicates
 bulwahn parents: 
39312diff
changeset | 787 | proposed_modes = [], | 
| 33623 
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
 bulwahn parents: 
33620diff
changeset | 788 | proposed_names = [], | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 789 | show_steps = false, | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 790 | show_intermediate_results = false, | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 791 | show_proof_trace = false, | 
| 33251 | 792 | show_modes = false, | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 793 | show_mode_inference = false, | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 794 | 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: 
35224diff
changeset | 795 | show_caught_failures = false, | 
| 39383 
ddfafa97da2f
adding option show_invalid_clauses for a more detailed message when modes are not inferred
 bulwahn parents: 
39382diff
changeset | 796 | show_invalid_clauses = false, | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 797 | 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: 
35224diff
changeset | 798 | 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: 
35224diff
changeset | 799 | function_flattening = false, | 
| 36248 
9ed1a37de465
added option for specialisation to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 800 | 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: 
35224diff
changeset | 801 | 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: 
35224diff
changeset | 802 | no_higher_order_predicate = [], | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 803 | inductify = false, | 
| 36254 | 804 | detect_switches = true, | 
| 40048 
f3a46d524101
adding option smart_depth_limiting to predicate compiler
 bulwahn parents: 
39802diff
changeset | 805 | smart_depth_limiting = false, | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 806 | compilation = Pred | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 807 | } | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 808 | |
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 809 | val bool_options = ["show_steps", "show_intermediate_results", "show_proof_trace", "show_modes", | 
| 39383 
ddfafa97da2f
adding option show_invalid_clauses for a more detailed message when modes are not inferred
 bulwahn parents: 
39382diff
changeset | 810 | "show_mode_inference", "show_compilation", "show_invalid_clauses", "skip_proof", "inductify", | 
| 40048 
f3a46d524101
adding option smart_depth_limiting to predicate compiler
 bulwahn parents: 
39802diff
changeset | 811 | "no_function_flattening", "detect_switches", "specialise", "no_topmost_reordering", | 
| 
f3a46d524101
adding option smart_depth_limiting to predicate compiler
 bulwahn parents: 
39802diff
changeset | 812 | "smart_depth_limiting"] | 
| 34948 
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
 bulwahn parents: 
33752diff
changeset | 813 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 814 | fun print_step options s = | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 815 | 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 | 816 | |
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 817 | (* simple transformations *) | 
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 818 | |
| 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 819 | (** tuple processing **) | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 820 | |
| 39657 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 821 | fun rewrite_args [] (pats, intro_t, ctxt) = (pats, intro_t, ctxt) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 822 | | rewrite_args (arg::args) (pats, intro_t, ctxt) = | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 823 | (case HOLogic.strip_tupleT (fastype_of arg) of | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 824 | (Ts as _ :: _ :: _) => | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 825 | let | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 826 |         fun rewrite_arg' (Const (@{const_name Pair}, _) $ _ $ t2, Type (@{type_name Product_Type.prod}, [_, T2]))
 | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 827 | (args, (pats, intro_t, ctxt)) = rewrite_arg' (t2, T2) (args, (pats, intro_t, ctxt)) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 828 |           | rewrite_arg' (t, Type (@{type_name Product_Type.prod}, [T1, T2])) (args, (pats, intro_t, ctxt)) =
 | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 829 | let | 
| 42361 | 830 | val thy = Proof_Context.theory_of ctxt | 
| 39657 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 831 | val ([x, y], ctxt') = Variable.variant_fixes ["x", "y"] ctxt | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 832 | val pat = (t, HOLogic.mk_prod (Free (x, T1), Free (y, T2))) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 833 | val intro_t' = Pattern.rewrite_term thy [pat] [] intro_t | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 834 | val args' = map (Pattern.rewrite_term thy [pat] []) args | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 835 | in | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 836 | rewrite_arg' (Free (y, T2), T2) (args', (pat::pats, intro_t', ctxt')) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 837 | end | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 838 | | rewrite_arg' _ (args, (pats, intro_t, ctxt)) = (args, (pats, intro_t, ctxt)) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 839 | val (args', (pats, intro_t', ctxt')) = rewrite_arg' (arg, fastype_of arg) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 840 | (args, (pats, intro_t, ctxt)) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 841 | in | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 842 | rewrite_args args' (pats, intro_t', ctxt') | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 843 | end | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 844 | | _ => rewrite_args args (pats, intro_t, ctxt)) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 845 | |
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 846 | fun rewrite_prem atom = | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 847 | let | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 848 | val (_, args) = strip_comb atom | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 849 | in rewrite_args args end | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 850 | |
| 39787 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 851 | fun split_conjuncts_in_assms ctxt th = | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 852 | let | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 853 | val ((_, [fixed_th]), ctxt') = Variable.import false [th] ctxt | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 854 | fun split_conjs i nprems th = | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 855 | if i > nprems then th | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 856 | else | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 857 |         case try Drule.RSN (@{thm conjI}, (i, th)) of
 | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 858 | SOME th' => split_conjs i (nprems+1) th' | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 859 | | NONE => split_conjs (i+1) nprems th | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 860 | in | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 861 | singleton (Variable.export ctxt' ctxt) (split_conjs 1 (Thm.nprems_of fixed_th) fixed_th) | 
| 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 862 | end | 
| 40052 
ea46574ca815
splitting large core file into core_data, mode_inference and predicate_compile_proof
 bulwahn parents: 
40051diff
changeset | 863 | |
| 
ea46574ca815
splitting large core file into core_data, mode_inference and predicate_compile_proof
 bulwahn parents: 
40051diff
changeset | 864 | fun dest_conjunct_prem th = | 
| 
ea46574ca815
splitting large core file into core_data, mode_inference and predicate_compile_proof
 bulwahn parents: 
40051diff
changeset | 865 | case HOLogic.dest_Trueprop (prop_of th) of | 
| 
ea46574ca815
splitting large core file into core_data, mode_inference and predicate_compile_proof
 bulwahn parents: 
40051diff
changeset | 866 |     (Const (@{const_name HOL.conj}, _) $ t $ t') =>
 | 
| 
ea46574ca815
splitting large core file into core_data, mode_inference and predicate_compile_proof
 bulwahn parents: 
40051diff
changeset | 867 |       dest_conjunct_prem (th RS @{thm conjunct1})
 | 
| 
ea46574ca815
splitting large core file into core_data, mode_inference and predicate_compile_proof
 bulwahn parents: 
40051diff
changeset | 868 |         @ dest_conjunct_prem (th RS @{thm conjunct2})
 | 
| 
ea46574ca815
splitting large core file into core_data, mode_inference and predicate_compile_proof
 bulwahn parents: 
40051diff
changeset | 869 | | _ => [th] | 
| 
ea46574ca815
splitting large core file into core_data, mode_inference and predicate_compile_proof
 bulwahn parents: 
40051diff
changeset | 870 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 871 | fun expand_tuples thy intro = | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 872 | let | 
| 42361 | 873 | val ctxt = Proof_Context.init_global thy | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 874 | 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 | 875 | val intro_t = prop_of intro' | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 876 | 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 | 877 | 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 | 878 | 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 | 879 | val (pats', intro_t', ctxt3) = | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 880 | 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 | 881 | fun rewrite_pat (ct1, ct2) = | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 882 | (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 | 883 | 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 | 884 | 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 | 885 | val [intro'''] = Variable.export ctxt3 ctxt [intro''] | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 886 | val intro'''' = Simplifier.full_simplify | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 887 |       (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 | 888 | intro''' | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 889 | (* splitting conjunctions introduced by Pair_eq*) | 
| 39787 
a44f6b11cdc4
adding splitting of conjuncts in assumptions as forward rule on theorems; replacing term transformation for splitting conjuncts by theorem transformation; removing obsolete functions; tuned
 bulwahn parents: 
39658diff
changeset | 890 | val intro''''' = split_conjuncts_in_assms ctxt intro'''' | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 891 | in | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 892 | intro''''' | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 893 | end | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 894 | |
| 39802 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 895 | (** making case distributivity rules **) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 896 | (*** this should be part of the datatype package ***) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 897 | |
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 898 | fun datatype_names_of_case_name thy case_name = | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 899 | map (#1 o #2) (#descr (the (Datatype_Data.info_of_case thy case_name))) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 900 | |
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 901 | fun make_case_distribs new_type_names descr sorts thy = | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 902 | let | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 903 | val case_combs = Datatype_Prop.make_case_combs new_type_names descr sorts thy "f"; | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 904 | fun make comb = | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 905 | let | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 906 |         val Type ("fun", [T, T']) = fastype_of comb;
 | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 907 | val (Const (case_name, _), fs) = strip_comb comb | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 908 | val used = Term.add_tfree_names comb [] | 
| 43324 
2b47822868e4
discontinued Name.variant to emphasize that this is old-style / indirect;
 wenzelm parents: 
42816diff
changeset | 909 | val U = TFree (singleton (Name.variant_list used) "'t", HOLogic.typeS) | 
| 39802 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 910 |         val x = Free ("x", T)
 | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 911 |         val f = Free ("f", T' --> U)
 | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 912 | fun apply_f f' = | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 913 | let | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 914 | val Ts = binder_types (fastype_of f') | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 915 | val bs = map Bound ((length Ts - 1) downto 0) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 916 | in | 
| 44241 | 917 | fold_rev absdummy Ts (f $ (list_comb (f', bs))) | 
| 39802 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 918 | end | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 919 | val fs' = map apply_f fs | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 920 | val case_c' = Const (case_name, (map fastype_of fs') @ [T] ---> U) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 921 | in | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 922 | HOLogic.mk_eq (f $ (comb $ x), list_comb (case_c', fs') $ x) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 923 | end | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 924 | in | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 925 | map make case_combs | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 926 | end | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 927 | |
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 928 | fun case_rewrites thy Tcon = | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 929 | let | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 930 | val info = Datatype.the_info thy Tcon | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 931 | val descr = #descr info | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 932 | val sorts = #sorts info | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 933 | val typ_names = the_default [Tcon] (#alt_names info) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 934 | in | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 935 | map (Drule.export_without_context o Skip_Proof.make_thm thy o HOLogic.mk_Trueprop) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 936 | (make_case_distribs typ_names [descr] sorts thy) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 937 | end | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 938 | |
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 939 | fun instantiated_case_rewrites thy Tcon = | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 940 | let | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 941 | val rew_ths = case_rewrites thy Tcon | 
| 42361 | 942 | val ctxt = Proof_Context.init_global thy | 
| 39802 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 943 | fun instantiate th = | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 944 | let | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 945 | val f = (fst (strip_comb (fst (HOLogic.dest_eq (HOLogic.dest_Trueprop (prop_of th)))))) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 946 |       val Type ("fun", [uninst_T, uninst_T']) = fastype_of f
 | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 947 | val ([tname, tname', uname, yname], ctxt') = Variable.add_fixes ["'t", "'t'", "'u", "y"] ctxt | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 948 | val T = TFree (tname, HOLogic.typeS) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 949 | val T' = TFree (tname', HOLogic.typeS) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 950 | val U = TFree (uname, HOLogic.typeS) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 951 | val y = Free (yname, U) | 
| 44241 | 952 | val f' = absdummy (U --> T') (Bound 0 $ y) | 
| 39802 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 953 | val th' = Thm.certify_instantiate | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 954 | ([(dest_TVar uninst_T, U --> T'), (dest_TVar uninst_T', T')], | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 955 | [((fst (dest_Var f), (U --> T') --> T'), f')]) th | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 956 | val [th'] = Variable.export ctxt' ctxt [th'] | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 957 | in | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 958 | th' | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 959 | end | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 960 | in | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 961 | map instantiate rew_ths | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 962 | end | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 963 | |
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 964 | fun case_betapply thy t = | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 965 | let | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 966 | val case_name = fst (dest_Const (fst (strip_comb t))) | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 967 | val Tcons = datatype_names_of_case_name thy case_name | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 968 | val ths = maps (instantiated_case_rewrites thy) Tcons | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 969 | in | 
| 41228 
e1fce873b814
renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
 wenzelm parents: 
40844diff
changeset | 970 | Raw_Simplifier.rewrite_term thy | 
| 39802 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 971 |       (map (fn th => th RS @{thm eq_reflection}) ths) [] t
 | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 972 | end | 
| 
7cadad6a18cc
applying case beta reduction to case term before matching in predicate compile function flattening; moving case beta reduction function to Predicate_Compile_Aux
 bulwahn parents: 
39787diff
changeset | 973 | |
| 39657 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 974 | (*** conversions ***) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 975 | |
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 976 | fun imp_prems_conv cv ct = | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 977 | case Thm.term_of ct of | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 978 |     Const ("==>", _) $ _ $ _ => Conv.combination_conv (Conv.arg_conv cv) (imp_prems_conv cv) ct
 | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 979 | | _ => Conv.all_conv ct | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 980 | |
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 981 | fun all_params_conv cv ctxt ct = | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 982 | if Logic.is_all (Thm.term_of ct) | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 983 | then Conv.arg_conv (Conv.abs_conv (all_params_conv cv o #2) ctxt) ct | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 984 | else cv ctxt ct; | 
| 
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
 bulwahn parents: 
39541diff
changeset | 985 | |
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 986 | (** eta contract higher-order arguments **) | 
| 35875 | 987 | |
| 988 | fun eta_contract_ho_arguments thy intro = | |
| 989 | let | |
| 990 | fun f atom = list_comb (apsnd ((map o map_products) Envir.eta_contract) (strip_comb atom)) | |
| 991 | in | |
| 992 | map_term thy (map_concl f o map_atoms f) intro | |
| 993 | end | |
| 994 | ||
| 36047 
f8297ebb21a7
adding signature to Predicate_Compile_Aux; tuning Predicate_Compile_Aux structure
 bulwahn parents: 
36046diff
changeset | 995 | (** remove equalities **) | 
| 36022 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 996 | |
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 997 | fun remove_equalities thy intro = | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 998 | let | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 999 | fun remove_eqs intro_t = | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1000 | let | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1001 | val (prems, concl) = Logic.strip_horn intro_t | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1002 | fun remove_eq (prems, concl) = | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1003 | let | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1004 | fun removable_eq prem = | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1005 | case try (HOLogic.dest_eq o HOLogic.dest_Trueprop) prem of | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1006 | SOME (lhs, rhs) => (case lhs of | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1007 | Var _ => true | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1008 | | _ => (case rhs of Var _ => true | _ => false)) | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1009 | | NONE => false | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1010 | in | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1011 | case find_first removable_eq prems of | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1012 | NONE => (prems, concl) | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1013 | | SOME eq => | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1014 | let | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1015 | val (lhs, rhs) = HOLogic.dest_eq (HOLogic.dest_Trueprop eq) | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1016 | val prems' = remove (op =) eq prems | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1017 | val subst = (case lhs of | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1018 | (v as Var _) => | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1019 | (fn t => if t = v then rhs else t) | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1020 | | _ => (case rhs of | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1021 | (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: 
36018diff
changeset | 1022 | in | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1023 | remove_eq (map (map_aterms subst) prems', map_aterms subst concl) | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1024 | end | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1025 | end | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1026 | in | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1027 | Logic.list_implies (remove_eq (prems, concl)) | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1028 | end | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1029 | in | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1030 | map_term thy remove_eqs intro | 
| 
c0fa8499e366
removing simple equalities in introduction rules in the predicate compiler
 bulwahn parents: 
36018diff
changeset | 1031 | end | 
| 35875 | 1032 | |
| 36246 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1033 | (* Some last processing *) | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1034 | |
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1035 | fun remove_pointless_clauses intro = | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1036 |   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: 
36049diff
changeset | 1037 | [] | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1038 | else [intro] | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1039 | |
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1040 | (* some peephole optimisations *) | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1041 | |
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1042 | fun peephole_optimisation thy intro = | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1043 | let | 
| 36610 
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
 wenzelm parents: 
36254diff
changeset | 1044 | val process = | 
| 42361 | 1045 | Raw_Simplifier.rewrite_rule (Predicate_Compile_Simps.get (Proof_Context.init_global thy)) | 
| 36246 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1046 | fun process_False intro_t = | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1047 |       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: 
36049diff
changeset | 1048 | fun process_True intro_t = | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1049 |       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: 
36049diff
changeset | 1050 | in | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1051 | 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: 
36049diff
changeset | 1052 | (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: 
36049diff
changeset | 1053 | end | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36049diff
changeset | 1054 | |
| 40101 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1055 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1056 | (* importing introduction rules *) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1057 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1058 | fun import_intros inp_pred [] ctxt = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1059 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1060 | val ([outp_pred], ctxt') = Variable.import_terms true [inp_pred] ctxt | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1061 | val T = fastype_of outp_pred | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1062 | val paramTs = ho_argsT_of_typ (binder_types T) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1063 | val (param_names, ctxt'') = Variable.variant_fixes | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1064 | (map (fn i => "p" ^ (string_of_int i)) (1 upto (length paramTs))) ctxt' | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1065 | val params = map2 (curry Free) param_names paramTs | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1066 | in | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1067 | (((outp_pred, params), []), ctxt') | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1068 | end | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1069 | | import_intros inp_pred (th :: ths) ctxt = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1070 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1071 | val ((_, [th']), ctxt') = Variable.import true [th] ctxt | 
| 42361 | 1072 | val thy = Proof_Context.theory_of ctxt' | 
| 40101 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1073 | val (pred, args) = strip_intro_concl th' | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1074 | val T = fastype_of pred | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1075 | val ho_args = ho_args_of_typ T args | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1076 | fun subst_of (pred', pred) = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1077 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1078 | val subst = Sign.typ_match thy (fastype_of pred', fastype_of pred) Vartab.empty | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1079 |             handle Type.TYPE_MATCH => error ("Type mismatch of predicate " ^ fst (dest_Const pred)
 | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1080 | ^ " (trying to match " ^ Syntax.string_of_typ ctxt (fastype_of pred') | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1081 | ^ " and " ^ Syntax.string_of_typ ctxt (fastype_of pred) ^ ")" | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1082 | ^ " in " ^ Display.string_of_thm ctxt th) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1083 | in map (fn (indexname, (s, T)) => ((indexname, s), T)) (Vartab.dest subst) end | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1084 | fun instantiate_typ th = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1085 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1086 | val (pred', _) = strip_intro_concl th | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1087 | val _ = if not (fst (dest_Const pred) = fst (dest_Const pred')) then | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1088 | raise Fail "Trying to instantiate another predicate" else () | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1089 | in Thm.certify_instantiate (subst_of (pred', pred), []) th end; | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1090 | fun instantiate_ho_args th = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1091 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1092 | val (_, args') = (strip_comb o HOLogic.dest_Trueprop o Logic.strip_imp_concl o prop_of) th | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1093 | val ho_args' = map dest_Var (ho_args_of_typ T args') | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1094 | in Thm.certify_instantiate ([], ho_args' ~~ ho_args) th end | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1095 | val outp_pred = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1096 | Term_Subst.instantiate (subst_of (inp_pred, pred), []) inp_pred | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1097 | val ((_, ths'), ctxt1) = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1098 | Variable.import false (map (instantiate_typ #> instantiate_ho_args) ths) ctxt' | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1099 | in | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1100 | (((outp_pred, ho_args), th' :: ths'), ctxt1) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1101 | end | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1102 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1103 | (* generation of case rules from user-given introduction rules *) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1104 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1105 | fun mk_args2 (Type (@{type_name Product_Type.prod}, [T1, T2])) st =
 | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1106 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1107 | val (t1, st') = mk_args2 T1 st | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1108 | val (t2, st'') = mk_args2 T2 st' | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1109 | in | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1110 | (HOLogic.mk_prod (t1, t2), st'') | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1111 | end | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1112 |   (*| mk_args2 (T as Type ("fun", _)) (params, ctxt) = 
 | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1113 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1114 | val (S, U) = strip_type T | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1115 | in | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1116 | if U = HOLogic.boolT then | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1117 | (hd params, (tl params, ctxt)) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1118 | else | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1119 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1120 | val ([x], ctxt') = Variable.variant_fixes ["x"] ctxt | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1121 | in | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1122 | (Free (x, T), (params, ctxt')) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1123 | end | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1124 | end*) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1125 | | mk_args2 T (params, ctxt) = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1126 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1127 | val ([x], ctxt') = Variable.variant_fixes ["x"] ctxt | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1128 | in | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1129 | (Free (x, T), (params, ctxt')) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1130 | end | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1131 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1132 | fun mk_casesrule ctxt pred introrules = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1133 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1134 | (* TODO: can be simplified if parameters are not treated specially ? *) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1135 | val (((pred, params), intros_th), ctxt1) = import_intros pred introrules ctxt | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1136 | (* TODO: distinct required ? -- test case with more than one parameter! *) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1137 | val params = distinct (op aconv) params | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1138 | val intros = map prop_of intros_th | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1139 | val ([propname], ctxt2) = Variable.variant_fixes ["thesis"] ctxt1 | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1140 | val prop = HOLogic.mk_Trueprop (Free (propname, HOLogic.boolT)) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1141 | val argsT = binder_types (fastype_of pred) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1142 | (* TODO: can be simplified if parameters are not treated specially ? <-- see uncommented code! *) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1143 | val (argvs, _) = fold_map mk_args2 argsT (params, ctxt2) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1144 | fun mk_case intro = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1145 | let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1146 | val (_, args) = (strip_comb o HOLogic.dest_Trueprop o Logic.strip_imp_concl) intro | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1147 | val prems = Logic.strip_imp_prems intro | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1148 | val eqprems = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1149 | map2 (HOLogic.mk_Trueprop oo (curry HOLogic.mk_eq)) argvs args | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1150 | val frees = map Free (fold Term.add_frees (args @ prems) []) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1151 | in fold Logic.all frees (Logic.list_implies (eqprems @ prems, prop)) end | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1152 | val assm = HOLogic.mk_Trueprop (list_comb (pred, argvs)) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1153 | val cases = map mk_case intros | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1154 | in Logic.list_implies (assm :: cases, prop) end; | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1155 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1156 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1157 | (* unifying constants to have the same type variables *) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1158 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1159 | fun unify_consts thy cs intr_ts = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1160 | (let | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1161 | val add_term_consts_2 = fold_aterms (fn Const c => insert (op =) c | _ => I); | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1162 | fun varify (t, (i, ts)) = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1163 | let val t' = map_types (Logic.incr_tvar (i + 1)) (#2 (Type.varify_global [] t)) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1164 | in (maxidx_of_term t', t'::ts) end; | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1165 | val (i, cs') = List.foldr varify (~1, []) cs; | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1166 | val (i', intr_ts') = List.foldr varify (i, []) intr_ts; | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1167 | val rec_consts = fold add_term_consts_2 cs' []; | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1168 | val intr_consts = fold add_term_consts_2 intr_ts' []; | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1169 | fun unify (cname, cT) = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1170 | let val consts = map snd (filter (fn c => fst c = cname) intr_consts) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1171 | in fold (Sign.typ_unify thy) ((replicate (length consts) cT) ~~ consts) end; | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1172 | val (env, _) = fold unify rec_consts (Vartab.empty, i'); | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1173 | val subst = map_types (Envir.norm_type env) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1174 | in (map subst cs', map subst intr_ts') | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1175 | end) handle Type.TUNIFY => | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1176 | (warning "Occurrences of recursive constant have non-unifiable types"; (cs, intr_ts)); | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1177 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1178 | (* preprocessing rules *) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1179 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1180 | fun Trueprop_conv cv ct = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1181 | case Thm.term_of ct of | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1182 |     Const (@{const_name Trueprop}, _) $ _ => Conv.arg_conv cv ct  
 | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1183 | | _ => raise Fail "Trueprop_conv" | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1184 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1185 | fun preprocess_equality thy rule = | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1186 | Conv.fconv_rule | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1187 | (imp_prems_conv | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1188 |       (Trueprop_conv (Conv.try_conv (Conv.rewr_conv (Thm.symmetric @{thm Predicate.eq_is_eq})))))
 | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1189 | (Thm.transfer thy rule) | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1190 | |
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1191 | fun preprocess_intro thy = expand_tuples thy #> preprocess_equality thy | 
| 
f7fc517e21c6
moving general functions from core_data to predicate_compile_aux
 bulwahn parents: 
40054diff
changeset | 1192 | |
| 39541 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1193 | (* defining a quickcheck predicate *) | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1194 | |
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1195 | fun strip_imp_prems (Const(@{const_name HOL.implies}, _) $ A $ B) = A :: strip_imp_prems B
 | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1196 | | strip_imp_prems _ = []; | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1197 | |
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1198 | fun strip_imp_concl (Const(@{const_name HOL.implies}, _) $ A $ B) = strip_imp_concl B
 | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1199 | | strip_imp_concl A = A : term; | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1200 | |
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1201 | fun strip_horn A = (strip_imp_prems A, strip_imp_concl A); | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1202 | |
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1203 | fun define_quickcheck_predicate t thy = | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1204 | let | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1205 | val (vs, t') = strip_abs t | 
| 42361 | 1206 | val vs' = Variable.variant_frees (Proof_Context.init_global thy) [] vs | 
| 39541 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1207 | val t'' = subst_bounds (map Free (rev vs'), t') | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1208 | val (prems, concl) = strip_horn t'' | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1209 | val constname = "quickcheck" | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1210 | val full_constname = Sign.full_bname thy constname | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1211 |     val constT = map snd vs' ---> @{typ bool}
 | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1212 | val thy1 = Sign.add_consts_i [(Binding.name constname, constT, NoSyn)] thy | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1213 | val const = Const (full_constname, constT) | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1214 | val t = Logic.list_implies | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1215 | (map HOLogic.mk_Trueprop (prems @ [HOLogic.mk_not concl]), | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1216 | HOLogic.mk_Trueprop (list_comb (const, map Free vs'))) | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1217 | val tac = fn _ => Skip_Proof.cheat_tac thy1 | 
| 42361 | 1218 | val intro = Goal.prove (Proof_Context.init_global thy1) (map fst vs') [] t tac | 
| 39541 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1219 | in | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1220 | ((((full_constname, constT), vs'), intro), thy1) | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1221 | end | 
| 
6605c1e87c7f
removing clone in code_prolog and predicate_compile_quickcheck
 bulwahn parents: 
39383diff
changeset | 1222 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: diff
changeset | 1223 | end; |