author | bulwahn |
Tue, 23 Feb 2010 13:36:15 +0100 | |
changeset 35324 | c9f428269b38 |
parent 35267 | 8dfd816713c6 |
child 35402 | 115a5a95710a |
permissions | -rw-r--r-- |
33265 | 1 |
(* Title: HOL/Tools/Predicate_Compile/predicate_compile_core.ML |
2 |
Author: Lukas Bulwahn, TU Muenchen |
|
32667 | 3 |
|
33265 | 4 |
A compiler from predicates specified by intro/elim rules to equations. |
32667 | 5 |
*) |
6 |
||
7 |
signature PREDICATE_COMPILE_CORE = |
|
8 |
sig |
|
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33476
diff
changeset
|
9 |
val setup : theory -> theory |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33476
diff
changeset
|
10 |
val code_pred : Predicate_Compile_Aux.options -> string -> Proof.context -> Proof.state |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33476
diff
changeset
|
11 |
val code_pred_cmd : Predicate_Compile_Aux.options -> string -> Proof.context -> Proof.state |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
12 |
val values_cmd : string list -> Predicate_Compile_Aux.mode option list option |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
13 |
-> (string option * (Predicate_Compile_Aux.compilation * int list)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
14 |
-> int -> string -> Toplevel.state -> unit |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
15 |
val register_predicate : (string * thm list * thm) -> theory -> theory |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
16 |
val register_intros : string * thm list -> theory -> theory |
32667 | 17 |
val is_registered : theory -> string -> bool |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
18 |
val function_name_of : Predicate_Compile_Aux.compilation -> theory |
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:
35267
diff
changeset
|
19 |
-> string -> bool * Predicate_Compile_Aux.mode -> string |
33328
1d93dd8a02c9
moved datatype mode and string functions to the auxillary structure
bulwahn
parents:
33327
diff
changeset
|
20 |
val predfun_intro_of: theory -> string -> Predicate_Compile_Aux.mode -> thm |
1d93dd8a02c9
moved datatype mode and string functions to the auxillary structure
bulwahn
parents:
33327
diff
changeset
|
21 |
val predfun_elim_of: theory -> string -> Predicate_Compile_Aux.mode -> thm |
32667 | 22 |
val all_preds_of : theory -> string list |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
23 |
val modes_of: Predicate_Compile_Aux.compilation |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
24 |
-> theory -> string -> Predicate_Compile_Aux.mode list |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
25 |
val all_modes_of : Predicate_Compile_Aux.compilation |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
26 |
-> theory -> (string * Predicate_Compile_Aux.mode list) list |
33484
e96a0c52d74b
renamed generator to random_function in the predicate compiler
bulwahn
parents:
33483
diff
changeset
|
27 |
val all_random_modes_of : theory -> (string * Predicate_Compile_Aux.mode list) list |
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33476
diff
changeset
|
28 |
val intros_of : theory -> string -> thm list |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33476
diff
changeset
|
29 |
val add_intro : thm -> theory -> theory |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33476
diff
changeset
|
30 |
val set_elim : thm -> theory -> theory |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
31 |
val preprocess_intro : theory -> thm -> thm |
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33476
diff
changeset
|
32 |
val print_stored_rules : theory -> unit |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
33 |
val print_all_modes : Predicate_Compile_Aux.compilation -> theory -> unit |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
34 |
val mk_casesrule : Proof.context -> term -> thm list -> term |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
35 |
|
33137
0d16c07f8d24
added option to generate random values to values command in the predicate compiler
bulwahn
parents:
33135
diff
changeset
|
36 |
val eval_ref : (unit -> term Predicate.pred) option Unsynchronized.ref |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
37 |
val random_eval_ref : (unit -> int * int -> term Predicate.pred * (int * int)) |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
38 |
option Unsynchronized.ref |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
39 |
val dseq_eval_ref : (unit -> term DSequence.dseq) option Unsynchronized.ref |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
40 |
val random_dseq_eval_ref : (unit -> int -> int -> int * int -> term DSequence.dseq * (int * int)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
41 |
option Unsynchronized.ref |
33628 | 42 |
val code_pred_intro_attrib : attribute |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
43 |
|
32667 | 44 |
(* used by Quickcheck_Generator *) |
45 |
(* temporary for testing of the compilation *) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
46 |
|
32667 | 47 |
datatype compilation_funs = CompilationFuns of { |
48 |
mk_predT : typ -> typ, |
|
49 |
dest_predT : typ -> typ, |
|
50 |
mk_bot : typ -> term, |
|
51 |
mk_single : term -> term, |
|
52 |
mk_bind : term * term -> term, |
|
53 |
mk_sup : term * term -> term, |
|
54 |
mk_if : term -> term, |
|
55 |
mk_not : term -> term, |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
56 |
mk_map : typ -> typ -> term -> term -> term |
33140
83951822bfd0
cleaning the signature of the predicate compiler core; renaming signature and structures to uniform long names
bulwahn
parents:
33139
diff
changeset
|
57 |
}; |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
58 |
|
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
59 |
val pred_compfuns : compilation_funs |
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
60 |
val randompred_compfuns : compilation_funs |
33256
b350516cb1f9
adding a prototype of a counter-example generator based on the predicate compiler to HOL/ex
bulwahn
parents:
33251
diff
changeset
|
61 |
val add_equations : Predicate_Compile_Aux.options -> string list -> theory -> theory |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
62 |
val add_random_dseq_equations : Predicate_Compile_Aux.options -> string list -> theory -> theory |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
63 |
val mk_tracing : string -> term -> term |
32667 | 64 |
end; |
65 |
||
66 |
structure Predicate_Compile_Core : PREDICATE_COMPILE_CORE = |
|
67 |
struct |
|
68 |
||
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
69 |
open Predicate_Compile_Aux; |
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
70 |
|
32667 | 71 |
(** auxiliary **) |
72 |
||
73 |
(* debug stuff *) |
|
74 |
||
33108
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
75 |
fun print_tac s = Seq.single; |
33139
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33138
diff
changeset
|
76 |
|
33127 | 77 |
fun print_tac' options s = |
78 |
if show_proof_trace options then Tactical.print_tac s else Seq.single; |
|
79 |
||
32667 | 80 |
fun debug_tac msg = Seq.single; (* (fn st => (Output.tracing msg; Seq.single st)); *) |
81 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
82 |
fun assert b = if not b then error "Assertion failed" else warning "Assertion holds" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
83 |
|
33108
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
84 |
datatype assertion = Max_number_of_subgoals of int |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
85 |
fun assert_tac (Max_number_of_subgoals i) st = |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
86 |
if (nprems_of st <= i) then Seq.single st |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
87 |
else error ("assert_tac: Numbers of subgoals mismatch at goal state :" |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
88 |
^ "\n" ^ Pretty.string_of (Pretty.chunks |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
89 |
(Goal_Display.pretty_goals_without_context (! Goal_Display.goals_limit) st))); |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
90 |
|
32667 | 91 |
(** fundamentals **) |
92 |
||
93 |
(* syntactic operations *) |
|
94 |
||
95 |
fun mk_eq (x, xs) = |
|
96 |
let fun mk_eqs _ [] = [] |
|
97 |
| mk_eqs a (b::cs) = |
|
98 |
HOLogic.mk_eq (Free (a, fastype_of b), b) :: mk_eqs a cs |
|
99 |
in mk_eqs x xs end; |
|
100 |
||
101 |
fun mk_scomp (t, u) = |
|
102 |
let |
|
103 |
val T = fastype_of t |
|
104 |
val U = fastype_of u |
|
105 |
val [A] = binder_types T |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
106 |
val D = body_type U |
32667 | 107 |
in |
108 |
Const (@{const_name "scomp"}, T --> U --> A --> D) $ t $ u |
|
109 |
end; |
|
110 |
||
111 |
fun dest_funT (Type ("fun",[S, T])) = (S, T) |
|
112 |
| dest_funT T = raise TYPE ("dest_funT", [T], []) |
|
113 |
||
114 |
fun mk_fun_comp (t, u) = |
|
115 |
let |
|
116 |
val (_, B) = dest_funT (fastype_of t) |
|
117 |
val (C, A) = dest_funT (fastype_of u) |
|
118 |
in |
|
119 |
Const(@{const_name "Fun.comp"}, (A --> B) --> (C --> A) --> C --> B) $ t $ u |
|
120 |
end; |
|
121 |
||
122 |
fun dest_randomT (Type ("fun", [@{typ Random.seed}, |
|
32674
b629fbcc5313
merged; adopted to changes from Code_Evaluation in the predicate compiler
bulwahn
parents:
32673
diff
changeset
|
123 |
Type ("*", [Type ("*", [T, @{typ "unit => Code_Evaluation.term"}]) ,@{typ Random.seed}])])) = T |
32667 | 124 |
| dest_randomT T = raise TYPE ("dest_randomT", [T], []) |
125 |
||
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
126 |
fun mk_tracing s t = |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
127 |
Const(@{const_name Code_Evaluation.tracing}, |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
128 |
@{typ String.literal} --> (fastype_of t) --> (fastype_of t)) $ (HOLogic.mk_literal s) $ t |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
129 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
130 |
val strip_intro_concl = (strip_comb o HOLogic.dest_Trueprop o Logic.strip_imp_concl o prop_of) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
131 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
132 |
(* derivation trees for modes of premises *) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
133 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
134 |
datatype mode_derivation = Mode_App of mode_derivation * mode_derivation | Context of mode |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
135 |
| Mode_Pair of mode_derivation * mode_derivation | Term of mode |
32667 | 136 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
137 |
fun string_of_derivation (Mode_App (m1, m2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
138 |
"App (" ^ string_of_derivation m1 ^ ", " ^ string_of_derivation m2 ^ ")" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
139 |
| string_of_derivation (Mode_Pair (m1, m2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
140 |
"Pair (" ^ string_of_derivation m1 ^ ", " ^ string_of_derivation m2 ^ ")" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
141 |
| string_of_derivation (Term m) = "Term (" ^ string_of_mode m ^ ")" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
142 |
| string_of_derivation (Context m) = "Context (" ^ string_of_mode m ^ ")" |
32667 | 143 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
144 |
fun strip_mode_derivation deriv = |
32667 | 145 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
146 |
fun strip (Mode_App (deriv1, deriv2)) ds = strip deriv1 (deriv2 :: ds) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
147 |
| strip deriv ds = (deriv, ds) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
148 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
149 |
strip deriv [] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
150 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
151 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
152 |
fun mode_of (Context m) = m |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
153 |
| mode_of (Term m) = m |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
154 |
| mode_of (Mode_App (d1, d2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
155 |
(case mode_of d1 of Fun (m, m') => |
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:
35267
diff
changeset
|
156 |
(if eq_mode (m, mode_of d2) then m' else error "mode_of") |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
157 |
| _ => error "mode_of2") |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
158 |
| mode_of (Mode_Pair (d1, d2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
159 |
Pair (mode_of d1, mode_of d2) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
160 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
161 |
fun head_mode_of deriv = mode_of (fst (strip_mode_derivation deriv)) |
32667 | 162 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
163 |
fun param_derivations_of deriv = |
32667 | 164 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
165 |
val (_, argument_derivs) = strip_mode_derivation deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
166 |
fun param_derivation (Mode_Pair (m1, m2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
167 |
param_derivation m1 @ param_derivation m2 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
168 |
| param_derivation (Term _) = [] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
169 |
| param_derivation m = [m] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
170 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
171 |
maps param_derivation argument_derivs |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
172 |
end |
32667 | 173 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
174 |
fun collect_context_modes (Mode_App (m1, m2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
175 |
collect_context_modes m1 @ collect_context_modes m2 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
176 |
| collect_context_modes (Mode_Pair (m1, m2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
177 |
collect_context_modes m1 @ collect_context_modes m2 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
178 |
| collect_context_modes (Context m) = [m] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
179 |
| collect_context_modes (Term _) = [] |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
180 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
181 |
(* representation of inferred clauses with modes *) |
32667 | 182 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
183 |
type moded_clause = term list * (indprem * mode_derivation) list |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
184 |
|
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:
35267
diff
changeset
|
185 |
type 'a pred_mode_table = (string * ((bool * mode) * 'a) list) list |
32667 | 186 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
187 |
(* book-keeping *) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
188 |
|
32667 | 189 |
datatype predfun_data = PredfunData of { |
190 |
definition : thm, |
|
191 |
intro : thm, |
|
192 |
elim : thm |
|
193 |
}; |
|
194 |
||
195 |
fun rep_predfun_data (PredfunData data) = data; |
|
196 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
197 |
fun mk_predfun_data (definition, intro, elim) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
198 |
PredfunData {definition = definition, intro = intro, elim = elim} |
32667 | 199 |
|
200 |
datatype pred_data = PredData of { |
|
201 |
intros : thm list, |
|
202 |
elim : thm option, |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
203 |
function_names : (compilation * (mode * string) list) list, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
204 |
predfun_data : (mode * predfun_data) list, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
205 |
needs_random : mode list |
32667 | 206 |
}; |
207 |
||
208 |
fun rep_pred_data (PredData data) = data; |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
209 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
210 |
fun mk_pred_data ((intros, elim), (function_names, predfun_data, needs_random)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
211 |
PredData {intros = intros, elim = elim, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
212 |
function_names = function_names, predfun_data = predfun_data, needs_random = needs_random} |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
213 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
214 |
fun map_pred_data f (PredData {intros, elim, function_names, predfun_data, needs_random}) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
215 |
mk_pred_data (f ((intros, elim), (function_names, predfun_data, needs_random))) |
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
216 |
|
32667 | 217 |
fun eq_option eq (NONE, NONE) = true |
218 |
| eq_option eq (SOME x, SOME y) = eq (x, y) |
|
219 |
| eq_option eq _ = false |
|
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
220 |
|
32667 | 221 |
fun eq_pred_data (PredData d1, PredData d2) = |
222 |
eq_list (Thm.eq_thm) (#intros d1, #intros d2) andalso |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
223 |
eq_option (Thm.eq_thm) (#elim d1, #elim d2) |
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
224 |
|
33522 | 225 |
structure PredData = Theory_Data |
32667 | 226 |
( |
227 |
type T = pred_data Graph.T; |
|
228 |
val empty = Graph.empty; |
|
229 |
val extend = I; |
|
33522 | 230 |
val merge = Graph.merge eq_pred_data; |
32667 | 231 |
); |
232 |
||
233 |
(* queries *) |
|
234 |
||
235 |
fun lookup_pred_data thy name = |
|
236 |
Option.map rep_pred_data (try (Graph.get_node (PredData.get thy)) name) |
|
237 |
||
238 |
fun the_pred_data thy name = case lookup_pred_data thy name |
|
239 |
of NONE => error ("No such predicate " ^ quote name) |
|
240 |
| SOME data => data; |
|
241 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
242 |
val is_registered = is_some oo lookup_pred_data |
32667 | 243 |
|
244 |
val all_preds_of = Graph.keys o PredData.get |
|
245 |
||
246 |
fun intros_of thy = map (Thm.transfer thy) o #intros o the_pred_data thy |
|
247 |
||
248 |
fun the_elim_of thy name = case #elim (the_pred_data thy name) |
|
249 |
of NONE => error ("No elimination rule for predicate " ^ quote name) |
|
250 |
| SOME thm => Thm.transfer thy thm |
|
251 |
||
252 |
val has_elim = is_some o #elim oo the_pred_data; |
|
253 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
254 |
fun function_names_of compilation thy name = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
255 |
case AList.lookup (op =) (#function_names (the_pred_data thy name)) compilation of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
256 |
NONE => error ("No " ^ string_of_compilation compilation |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
257 |
^ "functions defined for predicate " ^ quote name) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
258 |
| SOME fun_names => fun_names |
32667 | 259 |
|
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:
35267
diff
changeset
|
260 |
fun function_name_of compilation thy name (pol, mode) = |
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:
35267
diff
changeset
|
261 |
case AList.lookup eq_mode |
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:
35267
diff
changeset
|
262 |
(function_names_of (compilation_for_polarity pol compilation) thy name) mode of |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
263 |
NONE => error ("No " ^ string_of_compilation compilation |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
264 |
^ "function defined for mode " ^ string_of_mode mode ^ " of predicate " ^ quote name) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
265 |
| SOME function_name => function_name |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
266 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
267 |
fun modes_of compilation thy name = map fst (function_names_of compilation thy name) |
32667 | 268 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
269 |
fun all_modes_of compilation thy = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
270 |
map_filter (fn name => Option.map (pair name) (try (modes_of compilation thy) name)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
271 |
(all_preds_of thy) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
272 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
273 |
val all_random_modes_of = all_modes_of Random |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
274 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
275 |
fun defined_functions compilation thy name = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
276 |
AList.defined (op =) (#function_names (the_pred_data thy name)) compilation |
32667 | 277 |
|
278 |
fun lookup_predfun_data thy name mode = |
|
33483
a15a2f7f7560
improved handling of already defined functions in the predicate compiler; could cause trouble before when no modes for a predicate were infered
bulwahn
parents:
33482
diff
changeset
|
279 |
Option.map rep_predfun_data |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
280 |
(AList.lookup (op =) (#predfun_data (the_pred_data thy name)) mode) |
32667 | 281 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
282 |
fun the_predfun_data thy name mode = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
283 |
case lookup_predfun_data thy name mode of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
284 |
NONE => error ("No function defined for mode " ^ string_of_mode mode ^ |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
285 |
" of predicate " ^ name) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
286 |
| SOME data => data; |
32667 | 287 |
|
288 |
val predfun_definition_of = #definition ooo the_predfun_data |
|
289 |
||
290 |
val predfun_intro_of = #intro ooo the_predfun_data |
|
291 |
||
292 |
val predfun_elim_of = #elim ooo the_predfun_data |
|
293 |
||
294 |
(* diagnostic display functions *) |
|
295 |
||
33619
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
bulwahn
parents:
33526
diff
changeset
|
296 |
fun print_modes options thy modes = |
33251 | 297 |
if show_modes options then |
33326
7d0288d90535
improved handling of alternative rules; added test cases for alternative rules; normalized tracing in the predicate compiler
bulwahn
parents:
33268
diff
changeset
|
298 |
tracing ("Inferred modes:\n" ^ |
33251 | 299 |
cat_lines (map (fn (s, ms) => s ^ ": " ^ commas (map |
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:
35267
diff
changeset
|
300 |
(fn (p, m) => string_of_mode m ^ (if p then "pos" else "neg")) ms)) modes)) |
33251 | 301 |
else () |
32667 | 302 |
|
303 |
fun print_pred_mode_table string_of_entry thy pred_mode_table = |
|
304 |
let |
|
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:
35267
diff
changeset
|
305 |
fun print_mode pred ((pol, mode), entry) = "mode : " ^ 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:
33526
diff
changeset
|
306 |
^ string_of_entry pred mode entry |
32667 | 307 |
fun print_pred (pred, modes) = |
308 |
"predicate " ^ pred ^ ": " ^ cat_lines (map (print_mode pred) modes) |
|
33326
7d0288d90535
improved handling of alternative rules; added test cases for alternative rules; normalized tracing in the predicate compiler
bulwahn
parents:
33268
diff
changeset
|
309 |
val _ = tracing (cat_lines (map print_pred pred_mode_table)) |
32667 | 310 |
in () end; |
311 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
312 |
fun string_of_prem thy (Prem t) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
313 |
(Syntax.string_of_term_global thy t) ^ "(premise)" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
314 |
| string_of_prem thy (Negprem t) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
315 |
(Syntax.string_of_term_global thy (HOLogic.mk_not t)) ^ "(negative premise)" |
33130
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
316 |
| string_of_prem thy (Sidecond t) = |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
317 |
(Syntax.string_of_term_global thy t) ^ "(sidecondition)" |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
318 |
| string_of_prem thy _ = error "string_of_prem: unexpected input" |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
319 |
|
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
320 |
fun string_of_clause thy pred (ts, prems) = |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
321 |
(space_implode " --> " |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
322 |
(map (string_of_prem thy) prems)) ^ " --> " ^ pred ^ " " |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
323 |
^ (space_implode " " (map (Syntax.string_of_term_global thy) ts)) |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
324 |
|
33139
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33138
diff
changeset
|
325 |
fun print_compiled_terms options thy = |
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33138
diff
changeset
|
326 |
if show_compilation options then |
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33138
diff
changeset
|
327 |
print_pred_mode_table (fn _ => fn _ => Syntax.string_of_term_global thy) thy |
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33138
diff
changeset
|
328 |
else K () |
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33138
diff
changeset
|
329 |
|
32667 | 330 |
fun print_stored_rules thy = |
331 |
let |
|
332 |
val preds = (Graph.keys o PredData.get) thy |
|
333 |
fun print pred () = let |
|
334 |
val _ = writeln ("predicate: " ^ pred) |
|
335 |
val _ = writeln ("introrules: ") |
|
336 |
val _ = fold (fn thm => fn u => writeln (Display.string_of_thm_global thy thm)) |
|
337 |
(rev (intros_of thy pred)) () |
|
338 |
in |
|
339 |
if (has_elim thy pred) then |
|
340 |
writeln ("elimrule: " ^ Display.string_of_thm_global thy (the_elim_of thy pred)) |
|
341 |
else |
|
342 |
writeln ("no elimrule defined") |
|
343 |
end |
|
344 |
in |
|
345 |
fold print preds () |
|
346 |
end; |
|
347 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
348 |
fun print_all_modes compilation thy = |
32667 | 349 |
let |
350 |
val _ = writeln ("Inferred modes:") |
|
351 |
fun print (pred, modes) u = |
|
352 |
let |
|
353 |
val _ = writeln ("predicate: " ^ pred) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
354 |
val _ = writeln ("modes: " ^ (commas (map string_of_mode modes))) |
33619
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
bulwahn
parents:
33526
diff
changeset
|
355 |
in u end |
32667 | 356 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
357 |
fold print (all_modes_of compilation thy) () |
32667 | 358 |
end |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
359 |
|
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
360 |
(* validity checks *) |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
361 |
(* EXPECTED MODE and PROPOSED_MODE are largely the same; define a clear semantics for those! *) |
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
362 |
|
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
363 |
fun check_expected_modes preds options modes = |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
364 |
case expected_modes options of |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
365 |
SOME (s, ms) => (case AList.lookup (op =) modes s of |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
366 |
SOME modes => |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
367 |
let |
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:
35267
diff
changeset
|
368 |
val modes' = map snd modes |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
369 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
370 |
if not (eq_set eq_mode (ms, modes')) then |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
371 |
error ("expected modes were not inferred:\n" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
372 |
^ " inferred modes for " ^ s ^ ": " ^ commas (map string_of_mode modes') ^ "\n" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
373 |
^ " expected modes for " ^ s ^ ": " ^ commas (map string_of_mode ms)) |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
374 |
else () |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
375 |
end |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
376 |
| NONE => ()) |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
377 |
| NONE => () |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
378 |
|
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
379 |
fun check_proposed_modes preds options modes extra_modes errors = |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
380 |
case proposed_modes options of |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
381 |
SOME (s, ms) => (case AList.lookup (op =) modes s of |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
382 |
SOME inferred_ms => |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
383 |
let |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
384 |
val preds_without_modes = map fst (filter (null o snd) (modes @ extra_modes)) |
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:
35267
diff
changeset
|
385 |
val modes' = map snd inferred_ms |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
386 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
387 |
if not (eq_set eq_mode (ms, modes')) then |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
388 |
error ("expected modes were not inferred:\n" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
389 |
^ " inferred modes for " ^ s ^ ": " ^ commas (map string_of_mode modes') ^ "\n" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
390 |
^ " expected modes for " ^ s ^ ": " ^ commas (map string_of_mode ms) ^ "\n" |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
391 |
^ "For the following clauses, the following modes could not be inferred: " ^ "\n" |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
392 |
^ cat_lines errors ^ |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
393 |
(if not (null preds_without_modes) then |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
394 |
"\n" ^ "No mode inferred for the predicates " ^ commas preds_without_modes |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
395 |
else "")) |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
396 |
else () |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
397 |
end |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
398 |
| NONE => ()) |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
399 |
| NONE => () |
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
400 |
|
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
401 |
(* importing introduction rules *) |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
402 |
|
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
403 |
fun unify_consts thy cs intr_ts = |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
404 |
(let |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
405 |
val add_term_consts_2 = fold_aterms (fn Const c => insert (op =) c | _ => I); |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
406 |
fun varify (t, (i, ts)) = |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
407 |
let val t' = map_types (Logic.incr_tvar (i + 1)) (#2 (Type.varify [] t)) |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
408 |
in (maxidx_of_term t', t'::ts) end; |
33150
75eddea4abef
further changes due to the previous merge in the predicate compiler
bulwahn
parents:
33149
diff
changeset
|
409 |
val (i, cs') = List.foldr varify (~1, []) cs; |
75eddea4abef
further changes due to the previous merge in the predicate compiler
bulwahn
parents:
33149
diff
changeset
|
410 |
val (i', intr_ts') = List.foldr varify (i, []) intr_ts; |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
411 |
val rec_consts = fold add_term_consts_2 cs' []; |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
412 |
val intr_consts = fold add_term_consts_2 intr_ts' []; |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
413 |
fun unify (cname, cT) = |
33317 | 414 |
let val consts = map snd (filter (fn c => fst c = cname) intr_consts) |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
415 |
in fold (Sign.typ_unify thy) ((replicate (length consts) cT) ~~ consts) end; |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
416 |
val (env, _) = fold unify rec_consts (Vartab.empty, i'); |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
417 |
val subst = map_types (Envir.norm_type env) |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
418 |
in (map subst cs', map subst intr_ts') |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
419 |
end) handle Type.TUNIFY => |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
420 |
(warning "Occurrences of recursive constant have non-unifiable types"; (cs, intr_ts)); |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
421 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
422 |
fun import_intros inp_pred [] ctxt = |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
423 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
424 |
val ([outp_pred], ctxt') = Variable.import_terms true [inp_pred] ctxt |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
425 |
val T = fastype_of outp_pred |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
426 |
(* TODO: put in a function for this next line! *) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
427 |
val paramTs = ho_argsT_of (hd (all_modes_of_typ T)) (binder_types T) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
428 |
val (param_names, ctxt'') = Variable.variant_fixes |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
429 |
(map (fn i => "p" ^ (string_of_int i)) (1 upto (length paramTs))) ctxt' |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
430 |
val params = map2 (curry Free) param_names paramTs |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
431 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
432 |
(((outp_pred, params), []), ctxt') |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
433 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
434 |
| import_intros inp_pred (th :: ths) ctxt = |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
435 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
436 |
val ((_, [th']), ctxt') = Variable.import true [th] ctxt |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
437 |
val thy = ProofContext.theory_of ctxt' |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
438 |
val (pred, args) = strip_intro_concl th' |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
439 |
val T = fastype_of pred |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
440 |
val ho_args = ho_args_of (hd (all_modes_of_typ T)) args |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
441 |
fun subst_of (pred', pred) = |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
442 |
let |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
443 |
val subst = Sign.typ_match thy (fastype_of pred', fastype_of pred) Vartab.empty |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
444 |
in map (fn (indexname, (s, T)) => ((indexname, s), T)) (Vartab.dest subst) end |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
445 |
fun instantiate_typ th = |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
446 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
447 |
val (pred', _) = strip_intro_concl th |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
448 |
val _ = if not (fst (dest_Const pred) = fst (dest_Const pred')) then |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
449 |
error "Trying to instantiate another predicate" else () |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
450 |
in Thm.certify_instantiate (subst_of (pred', pred), []) th end; |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
451 |
fun instantiate_ho_args th = |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
452 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
453 |
val (_, args') = (strip_comb o HOLogic.dest_Trueprop o Logic.strip_imp_concl o prop_of) th |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
454 |
val ho_args' = map dest_Var (ho_args_of (hd (all_modes_of_typ T)) args') |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
455 |
in Thm.certify_instantiate ([], ho_args' ~~ ho_args) th end |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
456 |
val outp_pred = |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
457 |
Term_Subst.instantiate (subst_of (inp_pred, pred), []) inp_pred |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
458 |
val ((_, ths'), ctxt1) = |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
459 |
Variable.import false (map (instantiate_typ #> instantiate_ho_args) ths) ctxt' |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
460 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
461 |
(((outp_pred, ho_args), th' :: ths'), ctxt1) |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
462 |
end |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
463 |
|
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
464 |
(* generation of case rules from user-given introduction rules *) |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
465 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
466 |
fun mk_args2 (Type ("*", [T1, T2])) st = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
467 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
468 |
val (t1, st') = mk_args2 T1 st |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
469 |
val (t2, st'') = mk_args2 T2 st' |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
470 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
471 |
(HOLogic.mk_prod (t1, t2), st'') |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
472 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
473 |
| mk_args2 (T as Type ("fun", _)) (params, ctxt) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
474 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
475 |
val (S, U) = strip_type T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
476 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
477 |
if U = HOLogic.boolT then |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
478 |
(hd params, (tl params, ctxt)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
479 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
480 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
481 |
val ([x], ctxt') = Variable.variant_fixes ["x"] ctxt |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
482 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
483 |
(Free (x, T), (params, ctxt')) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
484 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
485 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
486 |
| mk_args2 T (params, ctxt) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
487 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
488 |
val ([x], ctxt') = Variable.variant_fixes ["x"] ctxt |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
489 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
490 |
(Free (x, T), (params, ctxt')) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
491 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
492 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
493 |
fun mk_casesrule ctxt pred introrules = |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
494 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
495 |
val (((pred, params), intros_th), ctxt1) = import_intros pred introrules ctxt |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
496 |
val intros = map prop_of intros_th |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
497 |
val ([propname], ctxt2) = Variable.variant_fixes ["thesis"] ctxt1 |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
498 |
val prop = HOLogic.mk_Trueprop (Free (propname, HOLogic.boolT)) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
499 |
val argsT = binder_types (fastype_of pred) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
500 |
val (argvs, _) = fold_map mk_args2 argsT (params, ctxt2) |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
501 |
fun mk_case intro = |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
502 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
503 |
val (_, args) = (strip_comb o HOLogic.dest_Trueprop o Logic.strip_imp_concl) intro |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
504 |
val prems = Logic.strip_imp_prems intro |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
505 |
val eqprems = map2 (HOLogic.mk_Trueprop oo (curry HOLogic.mk_eq)) argvs args |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
506 |
val frees = (fold o fold_aterms) |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
507 |
(fn t as Free _ => |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
508 |
if member (op aconv) params t then I else insert (op aconv) t |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
509 |
| _ => I) (args @ prems) [] |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
510 |
in fold Logic.all frees (Logic.list_implies (eqprems @ prems, prop)) end |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
511 |
val assm = HOLogic.mk_Trueprop (list_comb (pred, argvs)) |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
512 |
val cases = map mk_case intros |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
513 |
in Logic.list_implies (assm :: cases, prop) end; |
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
514 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
515 |
(** preprocessing rules **) |
32667 | 516 |
|
517 |
fun imp_prems_conv cv ct = |
|
518 |
case Thm.term_of ct of |
|
519 |
Const ("==>", _) $ _ $ _ => Conv.combination_conv (Conv.arg_conv cv) (imp_prems_conv cv) ct |
|
520 |
| _ => Conv.all_conv ct |
|
521 |
||
522 |
fun Trueprop_conv cv ct = |
|
523 |
case Thm.term_of ct of |
|
524 |
Const ("Trueprop", _) $ _ => Conv.arg_conv cv ct |
|
525 |
| _ => error "Trueprop_conv" |
|
526 |
||
527 |
fun preprocess_intro thy rule = |
|
528 |
Conv.fconv_rule |
|
529 |
(imp_prems_conv |
|
530 |
(Trueprop_conv (Conv.try_conv (Conv.rewr_conv (Thm.symmetric @{thm Predicate.eq_is_eq}))))) |
|
531 |
(Thm.transfer thy rule) |
|
532 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
533 |
fun preprocess_elim thy elimrule = |
32667 | 534 |
let |
535 |
fun replace_eqs (Const ("Trueprop", _) $ (Const ("op =", T) $ lhs $ rhs)) = |
|
536 |
HOLogic.mk_Trueprop (Const (@{const_name Predicate.eq}, T) $ lhs $ rhs) |
|
537 |
| replace_eqs t = t |
|
33128 | 538 |
val ctxt = ProofContext.init thy |
539 |
val ((_, [elimrule]), ctxt') = Variable.import false [elimrule] ctxt |
|
540 |
val prems = Thm.prems_of elimrule |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
541 |
val nargs = length (snd (strip_comb (HOLogic.dest_Trueprop (hd prems)))) |
32667 | 542 |
fun preprocess_case t = |
33128 | 543 |
let |
32667 | 544 |
val params = Logic.strip_params t |
545 |
val (assums1, assums2) = chop nargs (Logic.strip_assums_hyp t) |
|
546 |
val assums_hyp' = assums1 @ (map replace_eqs assums2) |
|
33128 | 547 |
in |
32667 | 548 |
list_all (params, Logic.list_implies (assums_hyp', Logic.strip_assums_concl t)) |
33128 | 549 |
end |
32667 | 550 |
val cases' = map preprocess_case (tl prems) |
551 |
val elimrule' = Logic.list_implies ((hd prems) :: cases', Thm.concl_of elimrule) |
|
552 |
val bigeq = (Thm.symmetric (Conv.implies_concl_conv |
|
553 |
(MetaSimplifier.rewrite true [@{thm Predicate.eq_is_eq}]) |
|
554 |
(cterm_of thy elimrule'))) |
|
33150
75eddea4abef
further changes due to the previous merge in the predicate compiler
bulwahn
parents:
33149
diff
changeset
|
555 |
val tac = (fn _ => Skip_Proof.cheat_tac thy) |
33109
7025bc7a5054
changed elimination preprocessing due to an error with a JinjaThread predicate
bulwahn
parents:
33108
diff
changeset
|
556 |
val eq = Goal.prove ctxt' [] [] (Logic.mk_equals ((Thm.prop_of elimrule), elimrule')) tac |
32667 | 557 |
in |
33109
7025bc7a5054
changed elimination preprocessing due to an error with a JinjaThread predicate
bulwahn
parents:
33108
diff
changeset
|
558 |
Thm.equal_elim eq elimrule |> singleton (Variable.export ctxt' ctxt) |
32667 | 559 |
end; |
560 |
||
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
561 |
fun expand_tuples_elim th = th |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
562 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
563 |
val no_compilation = ([], [], []) |
33483
a15a2f7f7560
improved handling of already defined functions in the predicate compiler; could cause trouble before when no modes for a predicate were infered
bulwahn
parents:
33482
diff
changeset
|
564 |
|
32667 | 565 |
fun fetch_pred_data thy name = |
566 |
case try (Inductive.the_inductive (ProofContext.init thy)) name of |
|
567 |
SOME (info as (_, result)) => |
|
568 |
let |
|
569 |
fun is_intro_of intro = |
|
570 |
let |
|
571 |
val (const, _) = strip_comb (HOLogic.dest_Trueprop (concl_of intro)) |
|
572 |
in (fst (dest_Const const) = name) end; |
|
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
573 |
val intros = |
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
574 |
(map (expand_tuples thy #> preprocess_intro thy) (filter is_intro_of (#intrs result))) |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
575 |
val index = find_index (fn s => s = name) (#names (fst info)) |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
576 |
val pre_elim = nth (#elims result) index |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
577 |
val pred = nth (#preds result) index |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
578 |
(*val elim = singleton (Inductive_Set.codegen_preproc thy) (preprocess_elim thy nparams |
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
579 |
(expand_tuples_elim pre_elim))*) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
580 |
val elim = |
35021
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34974
diff
changeset
|
581 |
(Drule.export_without_context o Skip_Proof.make_thm thy) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
582 |
(mk_casesrule (ProofContext.init thy) pred intros) |
32667 | 583 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
584 |
mk_pred_data ((intros, SOME elim), no_compilation) |
33483
a15a2f7f7560
improved handling of already defined functions in the predicate compiler; could cause trouble before when no modes for a predicate were infered
bulwahn
parents:
33482
diff
changeset
|
585 |
end |
32667 | 586 |
| NONE => error ("No such predicate: " ^ quote name) |
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
587 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
588 |
fun add_predfun_data name mode data = |
32667 | 589 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
590 |
val add = (apsnd o apsnd3) (cons (mode, mk_predfun_data data)) |
32667 | 591 |
in PredData.map (Graph.map_node name (map_pred_data add)) end |
592 |
||
593 |
fun is_inductive_predicate thy name = |
|
594 |
is_some (try (Inductive.the_inductive (ProofContext.init thy)) name) |
|
595 |
||
596 |
fun depending_preds_of thy (key, value) = |
|
597 |
let |
|
598 |
val intros = (#intros o rep_pred_data) value |
|
599 |
in |
|
600 |
fold Term.add_const_names (map Thm.prop_of intros) [] |
|
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
601 |
|> filter (fn c => (not (c = key)) andalso |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
602 |
(is_inductive_predicate thy c orelse is_registered thy c)) |
32667 | 603 |
end; |
604 |
||
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
605 |
fun add_intro thm thy = |
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
606 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
607 |
val (name, T) = dest_Const (fst (strip_intro_concl thm)) |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
608 |
fun cons_intro gr = |
32667 | 609 |
case try (Graph.get_node gr) name of |
610 |
SOME pred_data => Graph.map_node name (map_pred_data |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
611 |
(apfst (fn (intros, elim) => (intros @ [thm], elim)))) gr |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
612 |
| NONE => Graph.new_node (name, mk_pred_data (([thm], NONE), no_compilation)) gr |
32667 | 613 |
in PredData.map cons_intro thy end |
614 |
||
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
615 |
fun set_elim thm = |
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
616 |
let |
32667 | 617 |
val (name, _) = dest_Const (fst |
618 |
(strip_comb (HOLogic.dest_Trueprop (hd (prems_of thm))))) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
619 |
fun set (intros, _) = (intros, SOME thm) |
32667 | 620 |
in PredData.map (Graph.map_node name (map_pred_data (apfst set))) end |
621 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
622 |
fun register_predicate (constname, pre_intros, pre_elim) thy = |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
623 |
let |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
624 |
val intros = map (preprocess_intro thy) pre_intros |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
625 |
val elim = preprocess_elim thy pre_elim |
32667 | 626 |
in |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
627 |
if not (member (op =) (Graph.keys (PredData.get thy)) constname) then |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
628 |
PredData.map |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
629 |
(Graph.new_node (constname, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
630 |
mk_pred_data ((intros, SOME elim), no_compilation))) thy |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
631 |
else thy |
32667 | 632 |
end |
633 |
||
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
634 |
fun register_intros (constname, pre_intros) thy = |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
635 |
let |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
636 |
val T = Sign.the_const_type thy constname |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
637 |
fun constname_of_intro intr = fst (dest_Const (fst (strip_intro_concl intr))) |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
638 |
val _ = if not (forall (fn intr => constname_of_intro intr = constname) pre_intros) then |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
639 |
error ("register_intros: Introduction rules of different constants are used\n" ^ |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
640 |
"expected rules for " ^ constname ^ ", but received rules for " ^ |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
641 |
commas (map constname_of_intro pre_intros)) |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
642 |
else () |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
643 |
val pred = Const (constname, T) |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
644 |
val pre_elim = |
35021
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34974
diff
changeset
|
645 |
(Drule.export_without_context o Skip_Proof.make_thm thy) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
646 |
(mk_casesrule (ProofContext.init thy) pred pre_intros) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
647 |
in register_predicate (constname, pre_intros, pre_elim) thy end |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
648 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
649 |
fun defined_function_of compilation pred = |
32667 | 650 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
651 |
val set = (apsnd o apfst3) (cons (compilation, [])) |
32667 | 652 |
in |
653 |
PredData.map (Graph.map_node pred (map_pred_data set)) |
|
654 |
end |
|
655 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
656 |
fun set_function_name compilation pred mode name = |
32667 | 657 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
658 |
val set = (apsnd o apfst3) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
659 |
(AList.map_default (op =) (compilation, [(mode, name)]) (cons (mode, name))) |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
660 |
in |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
661 |
PredData.map (Graph.map_node pred (map_pred_data set)) |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
662 |
end |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
663 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
664 |
fun set_needs_random name modes = |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
665 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
666 |
val set = (apsnd o aptrd3) (K modes) |
32667 | 667 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
668 |
PredData.map (Graph.map_node name (map_pred_data set)) |
32667 | 669 |
end |
670 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
671 |
(* datastructures and setup for generic compilation *) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
672 |
|
32667 | 673 |
datatype compilation_funs = CompilationFuns of { |
674 |
mk_predT : typ -> typ, |
|
675 |
dest_predT : typ -> typ, |
|
676 |
mk_bot : typ -> term, |
|
677 |
mk_single : term -> term, |
|
678 |
mk_bind : term * term -> term, |
|
679 |
mk_sup : term * term -> term, |
|
680 |
mk_if : term -> term, |
|
681 |
mk_not : term -> term, |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
682 |
mk_map : typ -> typ -> term -> term -> term |
32667 | 683 |
}; |
684 |
||
685 |
fun mk_predT (CompilationFuns funs) = #mk_predT funs |
|
686 |
fun dest_predT (CompilationFuns funs) = #dest_predT funs |
|
687 |
fun mk_bot (CompilationFuns funs) = #mk_bot funs |
|
688 |
fun mk_single (CompilationFuns funs) = #mk_single funs |
|
689 |
fun mk_bind (CompilationFuns funs) = #mk_bind funs |
|
690 |
fun mk_sup (CompilationFuns funs) = #mk_sup funs |
|
691 |
fun mk_if (CompilationFuns funs) = #mk_if funs |
|
692 |
fun mk_not (CompilationFuns funs) = #mk_not funs |
|
693 |
fun mk_map (CompilationFuns funs) = #mk_map funs |
|
694 |
||
695 |
structure PredicateCompFuns = |
|
696 |
struct |
|
697 |
||
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
698 |
fun mk_predT T = Type (@{type_name Predicate.pred}, [T]) |
32667 | 699 |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
700 |
fun dest_predT (Type (@{type_name Predicate.pred}, [T])) = T |
32667 | 701 |
| dest_predT T = raise TYPE ("dest_predT", [T], []); |
702 |
||
703 |
fun mk_bot T = Const (@{const_name Orderings.bot}, mk_predT T); |
|
704 |
||
705 |
fun mk_single t = |
|
706 |
let val T = fastype_of t |
|
707 |
in Const(@{const_name Predicate.single}, T --> mk_predT T) $ t end; |
|
708 |
||
709 |
fun mk_bind (x, f) = |
|
710 |
let val T as Type ("fun", [_, U]) = fastype_of f |
|
711 |
in |
|
712 |
Const (@{const_name Predicate.bind}, fastype_of x --> T --> U) $ x $ f |
|
713 |
end; |
|
714 |
||
715 |
val mk_sup = HOLogic.mk_binop @{const_name sup}; |
|
716 |
||
717 |
fun mk_if cond = Const (@{const_name Predicate.if_pred}, |
|
718 |
HOLogic.boolT --> mk_predT HOLogic.unitT) $ cond; |
|
719 |
||
720 |
fun mk_not t = let val T = mk_predT HOLogic.unitT |
|
721 |
in Const (@{const_name Predicate.not_pred}, T --> T) $ t end |
|
722 |
||
723 |
fun mk_Enum f = |
|
724 |
let val T as Type ("fun", [T', _]) = fastype_of f |
|
725 |
in |
|
726 |
Const (@{const_name Predicate.Pred}, T --> mk_predT T') $ f |
|
727 |
end; |
|
728 |
||
729 |
fun mk_Eval (f, x) = |
|
730 |
let |
|
731 |
val T = fastype_of x |
|
732 |
in |
|
733 |
Const (@{const_name Predicate.eval}, mk_predT T --> T --> HOLogic.boolT) $ f $ x |
|
734 |
end; |
|
735 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
736 |
fun dest_Eval (Const (@{const_name Predicate.eval}, _) $ f $ x) = (f, x) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
737 |
|
32667 | 738 |
fun mk_map T1 T2 tf tp = Const (@{const_name Predicate.map}, |
739 |
(T1 --> T2) --> mk_predT T1 --> mk_predT T2) $ tf $ tp; |
|
740 |
||
741 |
val compfuns = CompilationFuns {mk_predT = mk_predT, dest_predT = dest_predT, mk_bot = mk_bot, |
|
742 |
mk_single = mk_single, mk_bind = mk_bind, mk_sup = mk_sup, mk_if = mk_if, mk_not = mk_not, |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
743 |
mk_map = mk_map}; |
32667 | 744 |
|
745 |
end; |
|
746 |
||
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
747 |
structure RandomPredCompFuns = |
32667 | 748 |
struct |
749 |
||
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
750 |
fun mk_randompredT T = |
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
751 |
@{typ Random.seed} --> HOLogic.mk_prodT (PredicateCompFuns.mk_predT T, @{typ Random.seed}) |
32667 | 752 |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
753 |
fun dest_randompredT (Type ("fun", [@{typ Random.seed}, Type (@{type_name "*"}, |
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
754 |
[Type (@{type_name "Predicate.pred"}, [T]), @{typ Random.seed}])])) = T |
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
755 |
| dest_randompredT T = raise TYPE ("dest_randompredT", [T], []); |
32667 | 756 |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
757 |
fun mk_bot T = Const(@{const_name Quickcheck.empty}, mk_randompredT T) |
32667 | 758 |
|
759 |
fun mk_single t = |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
760 |
let |
32667 | 761 |
val T = fastype_of t |
762 |
in |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
763 |
Const (@{const_name Quickcheck.single}, T --> mk_randompredT T) $ t |
32667 | 764 |
end; |
765 |
||
766 |
fun mk_bind (x, f) = |
|
767 |
let |
|
768 |
val T as (Type ("fun", [_, U])) = fastype_of f |
|
769 |
in |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
770 |
Const (@{const_name Quickcheck.bind}, fastype_of x --> T --> U) $ x $ f |
32667 | 771 |
end |
772 |
||
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
773 |
val mk_sup = HOLogic.mk_binop @{const_name Quickcheck.union} |
32667 | 774 |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
775 |
fun mk_if cond = Const (@{const_name Quickcheck.if_randompred}, |
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
776 |
HOLogic.boolT --> mk_randompredT HOLogic.unitT) $ cond; |
32667 | 777 |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
778 |
fun mk_not t = let val T = mk_randompredT HOLogic.unitT |
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
779 |
in Const (@{const_name Quickcheck.not_randompred}, T --> T) $ t end |
32667 | 780 |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
781 |
fun mk_map T1 T2 tf tp = Const (@{const_name Quickcheck.map}, |
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
782 |
(T1 --> T2) --> mk_randompredT T1 --> mk_randompredT T2) $ tf $ tp |
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
33150
diff
changeset
|
783 |
|
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
784 |
val compfuns = CompilationFuns {mk_predT = mk_randompredT, dest_predT = dest_randompredT, |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
785 |
mk_bot = mk_bot, mk_single = mk_single, mk_bind = mk_bind, mk_sup = mk_sup, mk_if = mk_if, |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
786 |
mk_not = mk_not, mk_map = mk_map}; |
32667 | 787 |
|
788 |
end; |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
789 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
790 |
structure DSequence_CompFuns = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
791 |
struct |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
792 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
793 |
fun mk_dseqT T = Type ("fun", [@{typ code_numeral}, Type ("fun", [@{typ bool}, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
794 |
Type (@{type_name Option.option}, [Type ("Lazy_Sequence.lazy_sequence", [T])])])]) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
795 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
796 |
fun dest_dseqT (Type ("fun", [@{typ code_numeral}, Type ("fun", [@{typ bool}, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
797 |
Type (@{type_name Option.option}, [Type ("Lazy_Sequence.lazy_sequence", [T])])])])) = T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
798 |
| dest_dseqT T = raise TYPE ("dest_dseqT", [T], []); |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
799 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
800 |
fun mk_bot T = Const ("DSequence.empty", mk_dseqT T); |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
801 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
802 |
fun mk_single t = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
803 |
let val T = fastype_of t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
804 |
in Const("DSequence.single", T --> mk_dseqT T) $ t end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
805 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
806 |
fun mk_bind (x, f) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
807 |
let val T as Type ("fun", [_, U]) = fastype_of f |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
808 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
809 |
Const ("DSequence.bind", fastype_of x --> T --> U) $ x $ f |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
810 |
end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
811 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
812 |
val mk_sup = HOLogic.mk_binop "DSequence.union"; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
813 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
814 |
fun mk_if cond = Const ("DSequence.if_seq", |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
815 |
HOLogic.boolT --> mk_dseqT HOLogic.unitT) $ cond; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
816 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
817 |
fun mk_not t = let val T = mk_dseqT HOLogic.unitT |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
818 |
in Const ("DSequence.not_seq", T --> T) $ t end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
819 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
820 |
fun mk_map T1 T2 tf tp = Const ("DSequence.map", |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
821 |
(T1 --> T2) --> mk_dseqT T1 --> mk_dseqT T2) $ tf $ tp |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
822 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
823 |
val compfuns = CompilationFuns {mk_predT = mk_dseqT, dest_predT = dest_dseqT, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
824 |
mk_bot = mk_bot, mk_single = mk_single, mk_bind = mk_bind, mk_sup = mk_sup, mk_if = mk_if, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
825 |
mk_not = mk_not, mk_map = mk_map} |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
826 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
827 |
end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
828 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
829 |
structure Random_Sequence_CompFuns = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
830 |
struct |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
831 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
832 |
fun mk_random_dseqT T = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
833 |
@{typ code_numeral} --> @{typ code_numeral} --> @{typ Random.seed} --> |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
834 |
HOLogic.mk_prodT (DSequence_CompFuns.mk_dseqT T, @{typ Random.seed}) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
835 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
836 |
fun dest_random_dseqT (Type ("fun", [@{typ code_numeral}, Type ("fun", [@{typ code_numeral}, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
837 |
Type ("fun", [@{typ Random.seed}, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
838 |
Type (@{type_name "*"}, [T, @{typ Random.seed}])])])])) = DSequence_CompFuns.dest_dseqT T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
839 |
| dest_random_dseqT T = raise TYPE ("dest_random_dseqT", [T], []); |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
840 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
841 |
fun mk_bot T = Const ("Random_Sequence.empty", mk_random_dseqT T); |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
842 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
843 |
fun mk_single t = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
844 |
let val T = fastype_of t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
845 |
in Const("Random_Sequence.single", T --> mk_random_dseqT T) $ t end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
846 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
847 |
fun mk_bind (x, f) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
848 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
849 |
val T as Type ("fun", [_, U]) = fastype_of f |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
850 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
851 |
Const ("Random_Sequence.bind", fastype_of x --> T --> U) $ x $ f |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
852 |
end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
853 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
854 |
val mk_sup = HOLogic.mk_binop "Random_Sequence.union"; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
855 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
856 |
fun mk_if cond = Const ("Random_Sequence.if_random_dseq", |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
857 |
HOLogic.boolT --> mk_random_dseqT HOLogic.unitT) $ cond; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
858 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
859 |
fun mk_not t = let val T = mk_random_dseqT HOLogic.unitT |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
860 |
in Const ("Random_Sequence.not_random_dseq", T --> T) $ t end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
861 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
862 |
fun mk_map T1 T2 tf tp = Const ("Random_Sequence.map", |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
863 |
(T1 --> T2) --> mk_random_dseqT T1 --> mk_random_dseqT T2) $ tf $ tp |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
864 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
865 |
val compfuns = CompilationFuns {mk_predT = mk_random_dseqT, dest_predT = dest_random_dseqT, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
866 |
mk_bot = mk_bot, mk_single = mk_single, mk_bind = mk_bind, mk_sup = mk_sup, mk_if = mk_if, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
867 |
mk_not = mk_not, mk_map = mk_map} |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
868 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
869 |
end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
870 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
871 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
872 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
873 |
fun mk_random T = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
874 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
875 |
val random = Const ("Quickcheck.random_class.random", |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
876 |
@{typ code_numeral} --> @{typ Random.seed} --> |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
877 |
HOLogic.mk_prodT (HOLogic.mk_prodT (T, @{typ "unit => term"}), @{typ Random.seed})) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
878 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
879 |
Const ("Random_Sequence.Random", (@{typ code_numeral} --> @{typ Random.seed} --> |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
880 |
HOLogic.mk_prodT (HOLogic.mk_prodT (T, @{typ "unit => term"}), @{typ Random.seed})) --> |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
881 |
Random_Sequence_CompFuns.mk_random_dseqT T) $ random |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
882 |
end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
883 |
|
32667 | 884 |
(* for external use with interactive mode *) |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
885 |
val pred_compfuns = PredicateCompFuns.compfuns |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
886 |
val randompred_compfuns = Random_Sequence_CompFuns.compfuns; |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
887 |
|
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
888 |
(* function types and names of different compilations *) |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
889 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
890 |
fun funT_of compfuns mode T = |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
891 |
let |
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
892 |
val Ts = binder_types T |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
893 |
val (inTs, outTs) = split_map_modeT (fn m => fn T => (SOME (funT_of compfuns m T), NONE)) mode Ts |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
894 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
895 |
inTs ---> (mk_predT compfuns (HOLogic.mk_tupleT outTs)) |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
896 |
end; |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
897 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
898 |
(** mode analysis **) |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
899 |
|
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:
35267
diff
changeset
|
900 |
(* options for mode analysis are: #use_random, #reorder_premises *) |
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:
35267
diff
changeset
|
901 |
|
32667 | 902 |
fun is_constrt thy = |
903 |
let |
|
904 |
val cnstrs = flat (maps |
|
905 |
(map (fn (_, (Tname, _, cs)) => map (apsnd (rpair Tname o length)) cs) o #descr o snd) |
|
906 |
(Symtab.dest (Datatype.get_all thy))); |
|
907 |
fun check t = (case strip_comb t of |
|
908 |
(Free _, []) => true |
|
909 |
| (Const (s, T), ts) => (case (AList.lookup (op =) cnstrs s, body_type T) of |
|
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
910 |
(SOME (i, Tname), Type (Tname', _)) => |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
911 |
length ts = i andalso Tname = Tname' andalso forall check ts |
32667 | 912 |
| _ => false) |
913 |
| _ => false) |
|
914 |
in check end; |
|
915 |
||
916 |
(*** check if a type is an equality type (i.e. doesn't contain fun) |
|
917 |
FIXME this is only an approximation ***) |
|
918 |
fun is_eqT (Type (s, Ts)) = s <> "fun" andalso forall is_eqT Ts |
|
919 |
| is_eqT _ = true; |
|
920 |
||
921 |
fun term_vs tm = fold_aterms (fn Free (x, T) => cons x | _ => I) tm []; |
|
922 |
val terms_vs = distinct (op =) o maps term_vs; |
|
923 |
||
924 |
(** collect all Frees in a term (with duplicates!) **) |
|
925 |
fun term_vTs tm = |
|
926 |
fold_aterms (fn Free xT => cons xT | _ => I) tm []; |
|
927 |
||
33138
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
928 |
fun subsets i j = |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
929 |
if i <= j then |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
930 |
let |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
931 |
fun merge xs [] = xs |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
932 |
| merge [] ys = ys |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
933 |
| merge (x::xs) (y::ys) = if length x >= length y then x::merge xs (y::ys) |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
934 |
else y::merge (x::xs) ys; |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
935 |
val is = subsets (i+1) j |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
936 |
in merge (map (fn ks => i::ks) is) is end |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
937 |
else [[]]; |
32667 | 938 |
|
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:
35267
diff
changeset
|
939 |
fun print_failed_mode options thy modes p (pol, m) rs is = |
33130
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
940 |
if show_mode_inference options then |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
941 |
let |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
942 |
val _ = tracing ("Clauses " ^ commas (map (fn i => string_of_int (i + 1)) is) ^ " of " ^ |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
943 |
p ^ " violates mode " ^ string_of_mode m) |
33130
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
944 |
in () end |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
945 |
else () |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
946 |
|
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:
35267
diff
changeset
|
947 |
fun error_of p (pol, m) is = |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
948 |
(" Clauses " ^ commas (map (fn i => string_of_int (i + 1)) is) ^ " of " ^ |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
949 |
p ^ " violates mode " ^ string_of_mode m) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
950 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
951 |
fun is_all_input mode = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
952 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
953 |
fun is_all_input' (Fun _) = true |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
954 |
| is_all_input' (Pair (m1, m2)) = is_all_input' m1 andalso is_all_input' m2 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
955 |
| is_all_input' Input = true |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
956 |
| is_all_input' Output = false |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
957 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
958 |
forall is_all_input' (strip_fun_mode mode) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
959 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
960 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
961 |
fun all_input_of T = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
962 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
963 |
val (Ts, U) = strip_type T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
964 |
fun input_of (Type ("*", [T1, T2])) = Pair (input_of T1, input_of T2) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
965 |
| input_of _ = Input |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
966 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
967 |
if U = HOLogic.boolT then |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
968 |
fold_rev (curry Fun) (map input_of Ts) Bool |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
969 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
970 |
error "all_input_of: not a predicate" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
971 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
972 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
973 |
fun partial_hd [] = NONE |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
974 |
| partial_hd (x :: xs) = SOME x |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
975 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
976 |
fun term_vs tm = fold_aterms (fn Free (x, T) => cons x | _ => I) tm []; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
977 |
val terms_vs = distinct (op =) o maps term_vs; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
978 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
979 |
fun input_mode T = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
980 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
981 |
val (Ts, U) = strip_type T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
982 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
983 |
fold_rev (curry Fun) (map (K Input) Ts) Input |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
984 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
985 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
986 |
fun output_mode T = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
987 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
988 |
val (Ts, U) = strip_type T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
989 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
990 |
fold_rev (curry Fun) (map (K Output) Ts) Output |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
991 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
992 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
993 |
fun is_invertible_function thy (Const (f, _)) = is_constr thy f |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
994 |
| is_invertible_function thy _ = false |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
995 |
|
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:
35267
diff
changeset
|
996 |
fun non_invertible_subterms thy (t as Free _) = [] |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
997 |
| non_invertible_subterms thy t = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
998 |
case (strip_comb t) of (f, args) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
999 |
if is_invertible_function thy f then |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1000 |
maps (non_invertible_subterms thy) args |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1001 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1002 |
[t] |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1003 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1004 |
fun collect_non_invertible_subterms thy (f as Free _) (names, eqs) = (f, (names, eqs)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1005 |
| collect_non_invertible_subterms thy t (names, eqs) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1006 |
case (strip_comb t) of (f, args) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1007 |
if is_invertible_function thy f then |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1008 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1009 |
val (args', (names', eqs')) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1010 |
fold_map (collect_non_invertible_subterms thy) args (names, eqs) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1011 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1012 |
(list_comb (f, args'), (names', eqs')) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1013 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1014 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1015 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1016 |
val s = Name.variant names "x" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1017 |
val v = Free (s, fastype_of t) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1018 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1019 |
(v, (s :: names, HOLogic.mk_eq (v, t) :: eqs)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1020 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1021 |
(* |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1022 |
if is_constrt thy t then (t, (names, eqs)) else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1023 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1024 |
val s = Name.variant names "x" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1025 |
val v = Free (s, fastype_of t) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1026 |
in (v, (s::names, HOLogic.mk_eq (v, t)::eqs)) end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1027 |
*) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1028 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1029 |
fun is_possible_output thy vs t = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1030 |
forall |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1031 |
(fn t => is_eqT (fastype_of t) andalso forall (member (op =) vs) (term_vs t)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1032 |
(non_invertible_subterms thy 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:
35267
diff
changeset
|
1033 |
andalso |
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:
35267
diff
changeset
|
1034 |
(forall (is_eqT o snd) |
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:
35267
diff
changeset
|
1035 |
(inter (fn ((f', _), f) => f = f') vs (Term.add_frees t []))) |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1036 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1037 |
fun vars_of_destructable_term thy (Free (x, _)) = [x] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1038 |
| vars_of_destructable_term thy t = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1039 |
case (strip_comb t) of (f, args) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1040 |
if is_invertible_function thy f then |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1041 |
maps (vars_of_destructable_term thy) args |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1042 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1043 |
[] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1044 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1045 |
fun is_constructable thy vs t = forall (member (op =) vs) (term_vs t) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1046 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1047 |
fun missing_vars vs t = subtract (op =) vs (term_vs t) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1048 |
|
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:
35267
diff
changeset
|
1049 |
fun output_terms (Const ("Pair", _) $ t1 $ t2, Mode_Pair (d1, d2)) = |
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:
35267
diff
changeset
|
1050 |
output_terms (t1, d1) @ output_terms (t2, d2) |
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:
35267
diff
changeset
|
1051 |
| output_terms (t1 $ t2, Mode_App (d1, d2)) = |
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:
35267
diff
changeset
|
1052 |
output_terms (t1, d1) @ output_terms (t2, d2) |
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:
35267
diff
changeset
|
1053 |
| output_terms (t, Term Output) = [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:
35267
diff
changeset
|
1054 |
| output_terms _ = [] |
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:
35267
diff
changeset
|
1055 |
|
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:
35267
diff
changeset
|
1056 |
fun lookup_mode modes (Const (s, 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:
35267
diff
changeset
|
1057 |
(case (AList.lookup (op =) modes s) of |
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:
35267
diff
changeset
|
1058 |
SOME ms => SOME (map (fn m => (Context m, [])) ms) |
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:
35267
diff
changeset
|
1059 |
| NONE => 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:
35267
diff
changeset
|
1060 |
| lookup_mode modes (Free (x, _)) = |
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:
35267
diff
changeset
|
1061 |
(case (AList.lookup (op =) modes x) of |
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:
35267
diff
changeset
|
1062 |
SOME ms => SOME (map (fn m => (Context m , [])) ms) |
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:
35267
diff
changeset
|
1063 |
| NONE => 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:
35267
diff
changeset
|
1064 |
|
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:
35267
diff
changeset
|
1065 |
fun derivations_of thy modes vs (Const ("Pair", _) $ t1 $ t2) (Pair (m1, m2)) = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1066 |
map_product |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1067 |
(fn (m1, mvars1) => fn (m2, mvars2) => (Mode_Pair (m1, m2), union (op =) mvars1 mvars2)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1068 |
(derivations_of thy modes vs t1 m1) (derivations_of thy modes vs t2 m2) |
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:
35267
diff
changeset
|
1069 |
| derivations_of thy modes vs t (m as 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:
35267
diff
changeset
|
1070 |
(*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:
35267
diff
changeset
|
1071 |
val (p, args) = strip_comb 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:
35267
diff
changeset
|
1072 |
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:
35267
diff
changeset
|
1073 |
(case lookup_mode modes p of |
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:
35267
diff
changeset
|
1074 |
SOME ms => map_filter (fn (Context m, []) => 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:
35267
diff
changeset
|
1075 |
val ms = strip_fun_mode m |
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:
35267
diff
changeset
|
1076 |
val (argms, restms) = chop (length args) ms |
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:
35267
diff
changeset
|
1077 |
val m' = fold_rev (curry Fun) restms 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:
35267
diff
changeset
|
1078 |
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:
35267
diff
changeset
|
1079 |
if forall (fn m => eq_mode (Input, m)) argms andalso eq_mode (m', mode) 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:
35267
diff
changeset
|
1080 |
SOME (fold (curry Mode_App) (map Term argms) (Context m), missing_vars vs 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:
35267
diff
changeset
|
1081 |
else 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:
35267
diff
changeset
|
1082 |
end) ms |
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:
35267
diff
changeset
|
1083 |
| NONE => (if is_all_input mode then [(Context mode, [])] 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:
35267
diff
changeset
|
1084 |
end*) |
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:
35267
diff
changeset
|
1085 |
(case try (all_derivations_of thy modes vs) t of |
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:
35267
diff
changeset
|
1086 |
SOME derivs => |
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:
35267
diff
changeset
|
1087 |
filter (fn (d, mvars) => eq_mode (mode_of d, m) andalso null (output_terms (t, d))) derivs |
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:
35267
diff
changeset
|
1088 |
| NONE => (if is_all_input m then [(Context m, [])] else [])) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1089 |
| derivations_of thy modes vs t m = |
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:
35267
diff
changeset
|
1090 |
if eq_mode (m, Input) 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:
35267
diff
changeset
|
1091 |
[(Term Input, missing_vars vs 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:
35267
diff
changeset
|
1092 |
else if eq_mode (m, Output) 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:
35267
diff
changeset
|
1093 |
(if is_possible_output thy vs t then [(Term Output, [])] 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:
35267
diff
changeset
|
1094 |
else [] |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1095 |
and all_derivations_of thy modes vs (Const ("Pair", _) $ t1 $ t2) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1096 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1097 |
val derivs1 = all_derivations_of thy modes vs t1 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1098 |
val derivs2 = all_derivations_of thy modes vs t2 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1099 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1100 |
map_product |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1101 |
(fn (m1, mvars1) => fn (m2, mvars2) => (Mode_Pair (m1, m2), union (op =) mvars1 mvars2)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1102 |
derivs1 derivs2 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1103 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1104 |
| all_derivations_of thy modes vs (t1 $ t2) = |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
1105 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1106 |
val derivs1 = all_derivations_of thy modes vs t1 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1107 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1108 |
maps (fn (d1, mvars1) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1109 |
case mode_of d1 of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1110 |
Fun (m', _) => map (fn (d2, mvars2) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1111 |
(Mode_App (d1, d2), union (op =) mvars1 mvars2)) (derivations_of thy modes vs t2 m') |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1112 |
| _ => error "Something went wrong") derivs1 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1113 |
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:
35267
diff
changeset
|
1114 |
| all_derivations_of thy modes vs (Const (s, T)) = the (lookup_mode modes (Const (s, 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:
35267
diff
changeset
|
1115 |
| all_derivations_of thy modes vs (Free (x, T)) = the (lookup_mode modes (Free (x, T))) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1116 |
| all_derivations_of _ modes vs _ = error "all_derivations_of" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1117 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1118 |
fun rev_option_ord ord (NONE, NONE) = EQUAL |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1119 |
| rev_option_ord ord (NONE, SOME _) = GREATER |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1120 |
| rev_option_ord ord (SOME _, NONE) = LESS |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1121 |
| rev_option_ord ord (SOME x, SOME y) = ord (x, y) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1122 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1123 |
fun term_of_prem (Prem t) = t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1124 |
| term_of_prem (Negprem t) = t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1125 |
| term_of_prem (Sidecond t) = t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1126 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1127 |
fun random_mode_in_deriv modes t deriv = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1128 |
case try dest_Const (fst (strip_comb t)) of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1129 |
SOME (s, _) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1130 |
(case AList.lookup (op =) modes s of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1131 |
SOME ms => |
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:
35267
diff
changeset
|
1132 |
(case AList.lookup (op =) (map (fn ((p, m), r) => (m, r)) ms) (head_mode_of deriv) of |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1133 |
SOME r => r |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1134 |
| NONE => false) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1135 |
| NONE => false) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1136 |
| NONE => false |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1137 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1138 |
fun number_of_output_positions mode = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1139 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1140 |
val args = strip_fun_mode mode |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1141 |
fun contains_output (Fun _) = false |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1142 |
| contains_output Input = false |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1143 |
| contains_output Output = true |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1144 |
| contains_output (Pair (m1, m2)) = contains_output m1 orelse contains_output m2 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1145 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1146 |
length (filter contains_output args) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1147 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1148 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1149 |
fun lex_ord ord1 ord2 (x, x') = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1150 |
case ord1 (x, x') of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1151 |
EQUAL => ord2 (x, x') |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1152 |
| ord => ord |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1153 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1154 |
fun deriv_ord2' thy modes t1 t2 ((deriv1, mvars1), (deriv2, mvars2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1155 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1156 |
fun mvars_ord ((t1, deriv1, mvars1), (t2, deriv2, mvars2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1157 |
int_ord (length mvars1, length mvars2) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1158 |
fun random_mode_ord ((t1, deriv1, mvars1), (t2, deriv2, mvars2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1159 |
int_ord (if random_mode_in_deriv modes t1 deriv1 then 1 else 0, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1160 |
if random_mode_in_deriv modes t1 deriv1 then 1 else 0) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1161 |
fun output_mode_ord ((t1, deriv1, mvars1), (t2, deriv2, mvars2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1162 |
int_ord (number_of_output_positions (head_mode_of deriv1), |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1163 |
number_of_output_positions (head_mode_of deriv2)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1164 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1165 |
lex_ord mvars_ord (lex_ord random_mode_ord output_mode_ord) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1166 |
((t1, deriv1, mvars1), (t2, deriv2, mvars2)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1167 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1168 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1169 |
fun deriv_ord2 thy modes t = deriv_ord2' thy modes t t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1170 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1171 |
fun deriv_ord ((deriv1, mvars1), (deriv2, mvars2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1172 |
int_ord (length mvars1, length mvars2) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1173 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1174 |
fun premise_ord thy modes ((prem1, a1), (prem2, a2)) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1175 |
rev_option_ord (deriv_ord2' thy modes (term_of_prem prem1) (term_of_prem prem2)) (a1, a2) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1176 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1177 |
fun print_mode_list modes = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1178 |
tracing ("modes: " ^ (commas (map (fn (s, ms) => s ^ ": " ^ |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1179 |
commas (map (fn (m, r) => string_of_mode m ^ (if r then " random " else " not ")) ms)) modes))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1180 |
|
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:
35267
diff
changeset
|
1181 |
fun select_mode_prem mode_analysis_options thy pol (modes, (pos_modes, neg_modes)) vs ps = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1182 |
let |
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:
35267
diff
changeset
|
1183 |
fun choose_mode_of_prem (Prem t) = partial_hd |
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:
35267
diff
changeset
|
1184 |
(sort (deriv_ord2 thy modes t) (all_derivations_of thy pos_modes vs 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:
35267
diff
changeset
|
1185 |
| choose_mode_of_prem (Sidecond t) = SOME (Context Bool, missing_vars vs 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:
35267
diff
changeset
|
1186 |
| choose_mode_of_prem (Negprem t) = partial_hd |
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:
35267
diff
changeset
|
1187 |
(sort (deriv_ord2 thy modes t) (filter (fn (d, missing_vars) => is_all_input (head_mode_of d)) |
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:
35267
diff
changeset
|
1188 |
(all_derivations_of thy neg_modes vs 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:
35267
diff
changeset
|
1189 |
| choose_mode_of_prem p = error ("choose_mode_of_prem: " ^ string_of_prem thy p) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1190 |
in |
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:
35267
diff
changeset
|
1191 |
if #reorder_premises mode_analysis_options 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:
35267
diff
changeset
|
1192 |
partial_hd (sort (premise_ord thy modes) (ps ~~ map choose_mode_of_prem ps)) |
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:
35267
diff
changeset
|
1193 |
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:
35267
diff
changeset
|
1194 |
SOME (hd ps, choose_mode_of_prem (hd ps)) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1195 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1196 |
|
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:
35267
diff
changeset
|
1197 |
fun check_mode_clause' mode_analysis_options thy param_vs (modes : |
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:
35267
diff
changeset
|
1198 |
(string * ((bool * mode) * bool) list) list) ((pol, mode) : bool * mode) (ts, ps) = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1199 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1200 |
val vTs = distinct (op =) (fold Term.add_frees (map term_of_prem ps) (fold Term.add_frees ts [])) |
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:
35267
diff
changeset
|
1201 |
val modes' = modes @ (param_vs ~~ map (fn x => [((true, x), false), ((false, x), false)]) (ho_arg_modes_of mode)) |
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:
35267
diff
changeset
|
1202 |
fun retrieve_modes_of_pol pol = map (fn (s, ms) => |
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:
35267
diff
changeset
|
1203 |
(s, map_filter (fn ((p, m), r) => if p = pol then SOME m else NONE | _ => NONE) ms)) |
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:
35267
diff
changeset
|
1204 |
val (pos_modes', neg_modes') = |
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:
35267
diff
changeset
|
1205 |
if #infer_pos_and_neg_modes mode_analysis_options 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:
35267
diff
changeset
|
1206 |
(retrieve_modes_of_pol pol modes', retrieve_modes_of_pol (not pol) modes') |
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:
35267
diff
changeset
|
1207 |
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:
35267
diff
changeset
|
1208 |
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:
35267
diff
changeset
|
1209 |
val modes = map (fn (s, ms) => (s, map (fn ((p, m), r) => m) ms)) modes' |
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:
35267
diff
changeset
|
1210 |
in (modes, modes) end |
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:
35267
diff
changeset
|
1211 |
val (in_ts, out_ts) = split_mode mode ts |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1212 |
val in_vs = maps (vars_of_destructable_term thy) in_ts |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1213 |
val out_vs = terms_vs out_ts |
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:
35267
diff
changeset
|
1214 |
fun known_vs_after p vs = (case p of |
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:
35267
diff
changeset
|
1215 |
Prem t => union (op =) vs (term_vs 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:
35267
diff
changeset
|
1216 |
| Sidecond t => union (op =) vs (term_vs 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:
35267
diff
changeset
|
1217 |
| Negprem t => union (op =) vs (term_vs 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:
35267
diff
changeset
|
1218 |
| _ => error "I do not know") |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1219 |
fun check_mode_prems acc_ps rnd vs [] = SOME (acc_ps, vs, rnd) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1220 |
| check_mode_prems acc_ps rnd vs ps = |
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:
35267
diff
changeset
|
1221 |
(case |
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:
35267
diff
changeset
|
1222 |
(select_mode_prem mode_analysis_options thy pol (modes', (pos_modes', neg_modes')) vs ps) of |
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:
35267
diff
changeset
|
1223 |
SOME (p, SOME (deriv, [])) => check_mode_prems ((p, deriv) :: acc_ps) rnd |
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:
35267
diff
changeset
|
1224 |
(known_vs_after p vs) (filter_out (equal p) ps) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1225 |
| SOME (p, SOME (deriv, missing_vars)) => |
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:
35267
diff
changeset
|
1226 |
if #use_random mode_analysis_options andalso pol then |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1227 |
check_mode_prems ((p, deriv) :: (map |
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:
35267
diff
changeset
|
1228 |
(fn v => (Generator (v, the (AList.lookup (op =) vTs v)), Term 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:
35267
diff
changeset
|
1229 |
(distinct (op =) missing_vars)) |
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:
35267
diff
changeset
|
1230 |
@ acc_ps) true (known_vs_after p vs) (filter_out (equal p) ps) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1231 |
else NONE |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1232 |
| SOME (p, NONE) => NONE |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1233 |
| NONE => NONE) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1234 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1235 |
case check_mode_prems [] false in_vs ps of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1236 |
NONE => NONE |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1237 |
| SOME (acc_ps, vs, rnd) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1238 |
if forall (is_constructable thy vs) (in_ts @ out_ts) then |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1239 |
SOME (ts, rev acc_ps, rnd) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1240 |
else |
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:
35267
diff
changeset
|
1241 |
if #use_random mode_analysis_options andalso pol then |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1242 |
let |
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:
35267
diff
changeset
|
1243 |
val generators = map |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1244 |
(fn v => (Generator (v, the (AList.lookup (op =) vTs v)), Term Output)) |
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:
35267
diff
changeset
|
1245 |
(subtract (op =) vs (terms_vs (in_ts @ out_ts))) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1246 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1247 |
SOME (ts, rev (generators @ acc_ps), true) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1248 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1249 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1250 |
NONE |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1251 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1252 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1253 |
datatype result = Success of bool | Error of string |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1254 |
|
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:
35267
diff
changeset
|
1255 |
fun check_modes_pred' mode_analysis_options options thy param_vs clauses modes (p, (ms : ((bool * mode) * bool) list)) = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1256 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1257 |
fun split xs = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1258 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1259 |
fun split' [] (ys, zs) = (rev ys, rev zs) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1260 |
| split' ((m, Error z) :: xs) (ys, zs) = split' xs (ys, z :: zs) |
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:
35267
diff
changeset
|
1261 |
| split' (((m : bool * mode), Success rnd) :: xs) (ys, zs) = split' xs ((m, rnd) :: ys, zs) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1262 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1263 |
split' xs ([], []) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1264 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1265 |
val rs = these (AList.lookup (op =) clauses p) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1266 |
fun check_mode m = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1267 |
let |
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:
35267
diff
changeset
|
1268 |
val res = Output.cond_timeit false "work part of check_mode for one mode" (fn _ => |
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:
35267
diff
changeset
|
1269 |
map (check_mode_clause' mode_analysis_options thy param_vs modes m) rs) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1270 |
in |
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:
35267
diff
changeset
|
1271 |
Output.cond_timeit false "aux part of check_mode for one mode" (fn _ => |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1272 |
case find_indices is_none res of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1273 |
[] => Success (exists (fn SOME (_, _, true) => true | _ => false) res) |
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:
35267
diff
changeset
|
1274 |
| is => (print_failed_mode options thy modes p m rs is; Error (error_of p m is))) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1275 |
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:
35267
diff
changeset
|
1276 |
val _ = if show_mode_inference options 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:
35267
diff
changeset
|
1277 |
tracing ("checking " ^ string_of_int (length ms) ^ " modes ...") |
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:
35267
diff
changeset
|
1278 |
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:
35267
diff
changeset
|
1279 |
val res = Output.cond_timeit false "check_mode" (fn _ => map (fn (m, _) => (m, check_mode m)) ms) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1280 |
val (ms', errors) = split res |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1281 |
in |
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:
35267
diff
changeset
|
1282 |
((p, (ms' : ((bool * mode) * bool) list)), errors) |
32667 | 1283 |
end; |
1284 |
||
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:
35267
diff
changeset
|
1285 |
fun get_modes_pred' mode_analysis_options thy param_vs clauses modes (p, ms) = |
32667 | 1286 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1287 |
val rs = these (AList.lookup (op =) clauses p) |
32667 | 1288 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1289 |
(p, map (fn (m, rnd) => |
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:
35267
diff
changeset
|
1290 |
(m, map |
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:
35267
diff
changeset
|
1291 |
((fn (ts, ps, rnd) => (ts, ps)) o the o |
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:
35267
diff
changeset
|
1292 |
check_mode_clause' mode_analysis_options thy param_vs modes m) rs)) ms) |
32667 | 1293 |
end; |
33137
0d16c07f8d24
added option to generate random values to values command in the predicate compiler
bulwahn
parents:
33135
diff
changeset
|
1294 |
|
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:
35267
diff
changeset
|
1295 |
fun fixp f (x : (string * ((bool * mode) * bool) list) list) = |
32667 | 1296 |
let val y = f x |
1297 |
in if x = y then x else fixp f y end; |
|
1298 |
||
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:
35267
diff
changeset
|
1299 |
fun fixp_with_state f (x : (string * ((bool * mode) * bool) list) list, state) = |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1300 |
let |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1301 |
val (y, state') = f (x, state) |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1302 |
in |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1303 |
if x = y then (y, state') else fixp_with_state f (y, state') |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1304 |
end |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1305 |
|
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:
35267
diff
changeset
|
1306 |
fun string_of_ext_mode ((pol, mode), rnd) = |
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:
35267
diff
changeset
|
1307 |
string_of_mode mode ^ "(" ^ (if pol then "pos" else "neg") ^ ", " |
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:
35267
diff
changeset
|
1308 |
^ (if rnd then "rnd" else "nornd") ^ ")" |
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:
35267
diff
changeset
|
1309 |
|
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:
35267
diff
changeset
|
1310 |
fun print_extra_modes options modes = |
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:
35267
diff
changeset
|
1311 |
if show_mode_inference options 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:
35267
diff
changeset
|
1312 |
tracing ("Modes of inferred predicates: " ^ |
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:
35267
diff
changeset
|
1313 |
cat_lines (map (fn (s, ms) => s ^ ": " ^ commas (map string_of_ext_mode ms)) modes)) |
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:
35267
diff
changeset
|
1314 |
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:
35267
diff
changeset
|
1315 |
|
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:
35267
diff
changeset
|
1316 |
fun infer_modes mode_analysis_options options compilation preds all_modes param_vs clauses thy = |
32667 | 1317 |
let |
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:
35267
diff
changeset
|
1318 |
val collect_errors = 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:
35267
diff
changeset
|
1319 |
fun appair f (x1, x2) (y1, y2) = (f x1 y1, f x2 y2) |
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:
35267
diff
changeset
|
1320 |
fun needs_random s (false, m) = ((false, m), 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:
35267
diff
changeset
|
1321 |
| needs_random s (true, m) = ((true, m), member (op =) (#needs_random (the_pred_data thy s)) m) |
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:
35267
diff
changeset
|
1322 |
fun add_polarity_and_random_bit s b ms = map (fn m => needs_random s (b, m)) ms |
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:
35267
diff
changeset
|
1323 |
val prednames = map fst preds |
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:
35267
diff
changeset
|
1324 |
(* extramodes contains all modes of all constants, should we only use the necessary ones |
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:
35267
diff
changeset
|
1325 |
- what is the impact on performance? *) |
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:
35267
diff
changeset
|
1326 |
val extra_modes = |
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:
35267
diff
changeset
|
1327 |
if #infer_pos_and_neg_modes mode_analysis_options then |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1328 |
let |
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:
35267
diff
changeset
|
1329 |
val pos_extra_modes = |
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:
35267
diff
changeset
|
1330 |
all_modes_of compilation thy |> filter_out (fn (name, _) => member (op =) prednames name) |
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:
35267
diff
changeset
|
1331 |
val neg_extra_modes = |
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:
35267
diff
changeset
|
1332 |
all_modes_of (negative_compilation_of compilation) thy |
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:
35267
diff
changeset
|
1333 |
|> filter_out (fn (name, _) => member (op =) prednames name) |
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:
35267
diff
changeset
|
1334 |
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:
35267
diff
changeset
|
1335 |
map (fn (s, ms) => (s, (add_polarity_and_random_bit s true ms) |
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:
35267
diff
changeset
|
1336 |
@ add_polarity_and_random_bit s false (the (AList.lookup (op =) neg_extra_modes s)))) |
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:
35267
diff
changeset
|
1337 |
pos_extra_modes |
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:
35267
diff
changeset
|
1338 |
end |
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:
35267
diff
changeset
|
1339 |
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:
35267
diff
changeset
|
1340 |
map (fn (s, ms) => (s, (add_polarity_and_random_bit s true ms))) |
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:
35267
diff
changeset
|
1341 |
(all_modes_of compilation thy |> filter_out (fn (name, _) => member (op =) prednames name)) |
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:
35267
diff
changeset
|
1342 |
val _ = print_extra_modes options extra_modes |
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:
35267
diff
changeset
|
1343 |
val start_modes = |
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:
35267
diff
changeset
|
1344 |
if #infer_pos_and_neg_modes mode_analysis_options 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:
35267
diff
changeset
|
1345 |
map (fn (s, ms) => (s, map (fn m => ((true, m), false)) ms @ |
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:
35267
diff
changeset
|
1346 |
(map (fn m => ((false, m), false)) ms))) all_modes |
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:
35267
diff
changeset
|
1347 |
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:
35267
diff
changeset
|
1348 |
map (fn (s, ms) => (s, map (fn m => ((true, m), false)) ms)) all_modes |
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:
35267
diff
changeset
|
1349 |
fun iteration modes = map |
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:
35267
diff
changeset
|
1350 |
(check_modes_pred' mode_analysis_options options thy param_vs clauses (modes @ extra_modes)) |
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:
35267
diff
changeset
|
1351 |
modes |
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:
35267
diff
changeset
|
1352 |
val ((modes : (string * ((bool * mode) * bool) list) list), errors) = |
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:
35267
diff
changeset
|
1353 |
Output.cond_timeit false "Fixpount computation of mode analysis" (fn () => |
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:
35267
diff
changeset
|
1354 |
if collect_errors 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:
35267
diff
changeset
|
1355 |
fixp_with_state (fn (modes, errors) => |
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:
35267
diff
changeset
|
1356 |
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:
35267
diff
changeset
|
1357 |
val (modes', new_errors) = split_list (iteration modes) |
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:
35267
diff
changeset
|
1358 |
in (modes', errors @ flat new_errors) end) (start_modes, []) |
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:
35267
diff
changeset
|
1359 |
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:
35267
diff
changeset
|
1360 |
(fixp (fn modes => map fst (iteration modes)) start_modes, [])) |
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:
35267
diff
changeset
|
1361 |
val moded_clauses = map (get_modes_pred' mode_analysis_options thy param_vs clauses |
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:
35267
diff
changeset
|
1362 |
(modes @ extra_modes)) modes |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1363 |
val thy' = fold (fn (s, ms) => if member (op =) (map fst preds) s then |
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:
35267
diff
changeset
|
1364 |
set_needs_random s (map_filter (fn ((true, m), true) => SOME m | _ => NONE) ms) else I) |
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:
35267
diff
changeset
|
1365 |
modes thy |
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:
35267
diff
changeset
|
1366 |
|
32667 | 1367 |
in |
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:
35267
diff
changeset
|
1368 |
((moded_clauses, errors), thy') |
32667 | 1369 |
end; |
1370 |
||
1371 |
(* term construction *) |
|
1372 |
||
1373 |
fun mk_v (names, vs) s T = (case AList.lookup (op =) vs s of |
|
1374 |
NONE => (Free (s, T), (names, (s, [])::vs)) |
|
1375 |
| SOME xs => |
|
1376 |
let |
|
1377 |
val s' = Name.variant names s; |
|
1378 |
val v = Free (s', T) |
|
1379 |
in |
|
1380 |
(v, (s'::names, AList.update (op =) (s, v::xs) vs)) |
|
1381 |
end); |
|
1382 |
||
1383 |
fun distinct_v (Free (s, T)) nvs = mk_v nvs s T |
|
1384 |
| distinct_v (t $ u) nvs = |
|
1385 |
let |
|
1386 |
val (t', nvs') = distinct_v t nvs; |
|
1387 |
val (u', nvs'') = distinct_v u nvs'; |
|
1388 |
in (t' $ u', nvs'') end |
|
1389 |
| distinct_v x nvs = (x, nvs); |
|
1390 |
||
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1391 |
(** specific rpred functions -- move them to the correct place in this file *) |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1392 |
|
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1393 |
fun mk_Eval_of additional_arguments ((x, T), NONE) names = (x, names) |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1394 |
| mk_Eval_of additional_arguments ((x, T), SOME mode) names = |
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1395 |
let |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1396 |
val Ts = binder_types T |
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1397 |
fun mk_split_lambda [] t = lambda (Free (Name.variant names "x", HOLogic.unitT)) t |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1398 |
| mk_split_lambda [x] t = lambda x t |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1399 |
| mk_split_lambda xs t = |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1400 |
let |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1401 |
fun mk_split_lambda' (x::y::[]) t = HOLogic.mk_split (lambda x (lambda y t)) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1402 |
| mk_split_lambda' (x::xs) t = HOLogic.mk_split (lambda x (mk_split_lambda' xs t)) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1403 |
in |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1404 |
mk_split_lambda' xs t |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1405 |
end; |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1406 |
fun mk_arg (i, T) = |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1407 |
let |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1408 |
val vname = Name.variant names ("x" ^ string_of_int i) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1409 |
val default = Free (vname, T) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1410 |
in |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1411 |
case AList.lookup (op =) mode i of |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1412 |
NONE => (([], [default]), [default]) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1413 |
| SOME NONE => (([default], []), [default]) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1414 |
| SOME (SOME pis) => |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1415 |
case HOLogic.strip_tupleT T of |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1416 |
[] => error "pair mode but unit tuple" (*(([default], []), [default])*) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1417 |
| [_] => error "pair mode but not a tuple" (*(([default], []), [default])*) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1418 |
| Ts => |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1419 |
let |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1420 |
val vnames = Name.variant_list names |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1421 |
(map (fn j => "x" ^ string_of_int i ^ "p" ^ string_of_int j) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1422 |
(1 upto length Ts)) |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
1423 |
val args = map2 (curry Free) vnames Ts |
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1424 |
fun split_args (i, arg) (ins, outs) = |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1425 |
if member (op =) pis i then |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1426 |
(arg::ins, outs) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1427 |
else |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1428 |
(ins, arg::outs) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1429 |
val (inargs, outargs) = fold_rev split_args ((1 upto length Ts) ~~ args) ([], []) |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1430 |
fun tuple args = if null args then [] else [HOLogic.mk_tuple args] |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1431 |
in ((tuple inargs, tuple outargs), args) end |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1432 |
end |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1433 |
val (inoutargs, args) = split_list (map mk_arg (1 upto (length Ts) ~~ Ts)) |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1434 |
val (inargs, outargs) = pairself flat (split_list inoutargs) |
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1435 |
val r = PredicateCompFuns.mk_Eval |
33148
0808f7d0d0d7
removed tuple functions from the predicate compiler
bulwahn
parents:
33147
diff
changeset
|
1436 |
(list_comb (x, inargs @ additional_arguments), HOLogic.mk_tuple outargs) |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1437 |
val t = fold_rev mk_split_lambda args r |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1438 |
in |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1439 |
(t, names) |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1440 |
end; |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1441 |
|
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1442 |
structure Comp_Mod = |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1443 |
struct |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1444 |
|
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1445 |
datatype comp_modifiers = Comp_Modifiers of |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1446 |
{ |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1447 |
compilation : compilation, |
33485
0df4f6e46e5e
made definition of functions generically for the different instances
bulwahn
parents:
33484
diff
changeset
|
1448 |
function_name_prefix : string, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1449 |
compfuns : compilation_funs, |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1450 |
additional_arguments : string list -> term list, |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1451 |
wrap_compilation : compilation_funs -> string -> typ -> mode -> term list -> term -> term, |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1452 |
transform_additional_arguments : indprem -> term list -> term list |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1453 |
} |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1454 |
|
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1455 |
fun dest_comp_modifiers (Comp_Modifiers c) = c |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1456 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1457 |
val compilation = #compilation o dest_comp_modifiers |
33485
0df4f6e46e5e
made definition of functions generically for the different instances
bulwahn
parents:
33484
diff
changeset
|
1458 |
val function_name_prefix = #function_name_prefix o dest_comp_modifiers |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1459 |
val compfuns = #compfuns o dest_comp_modifiers |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1460 |
val funT_of = funT_of o compfuns |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1461 |
val additional_arguments = #additional_arguments o dest_comp_modifiers |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1462 |
val wrap_compilation = #wrap_compilation o dest_comp_modifiers |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1463 |
val transform_additional_arguments = #transform_additional_arguments o dest_comp_modifiers |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1464 |
|
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1465 |
end; |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1466 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1467 |
(* TODO: uses param_vs -- change necessary for compilation with new modes *) |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1468 |
fun compile_arg compilation_modifiers compfuns additional_arguments thy param_vs iss arg = |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1469 |
let |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1470 |
fun map_params (t as Free (f, T)) = |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1471 |
if member (op =) param_vs f then |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1472 |
case (AList.lookup (op =) (param_vs ~~ iss) f) of |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1473 |
SOME is => |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1474 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1475 |
val _ = error "compile_arg: A parameter in a input position -- do we have a test case?" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1476 |
val T' = Comp_Mod.funT_of compilation_modifiers is T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1477 |
in t(*fst (mk_Eval_of additional_arguments ((Free (f, T'), T), is) [])*) end |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1478 |
| NONE => t |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1479 |
else t |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1480 |
| map_params t = t |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1481 |
in map_aterms map_params arg end |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1482 |
|
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1483 |
fun compile_match compilation_modifiers compfuns additional_arguments |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1484 |
param_vs iss thy eqs eqs' out_ts success_t = |
32667 | 1485 |
let |
1486 |
val eqs'' = maps mk_eq eqs @ eqs' |
|
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1487 |
val eqs'' = |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1488 |
map (compile_arg compilation_modifiers compfuns additional_arguments thy param_vs iss) eqs'' |
32667 | 1489 |
val names = fold Term.add_free_names (success_t :: eqs'' @ out_ts) []; |
1490 |
val name = Name.variant names "x"; |
|
1491 |
val name' = Name.variant (name :: names) "y"; |
|
33148
0808f7d0d0d7
removed tuple functions from the predicate compiler
bulwahn
parents:
33147
diff
changeset
|
1492 |
val T = HOLogic.mk_tupleT (map fastype_of out_ts); |
32667 | 1493 |
val U = fastype_of success_t; |
1494 |
val U' = dest_predT compfuns U; |
|
1495 |
val v = Free (name, T); |
|
1496 |
val v' = Free (name', T); |
|
1497 |
in |
|
1498 |
lambda v (fst (Datatype.make_case |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33754
diff
changeset
|
1499 |
(ProofContext.init thy) Datatype_Case.Quiet [] v |
33148
0808f7d0d0d7
removed tuple functions from the predicate compiler
bulwahn
parents:
33147
diff
changeset
|
1500 |
[(HOLogic.mk_tuple out_ts, |
32667 | 1501 |
if null eqs'' then success_t |
1502 |
else Const (@{const_name HOL.If}, HOLogic.boolT --> U --> U --> U) $ |
|
1503 |
foldr1 HOLogic.mk_conj eqs'' $ success_t $ |
|
1504 |
mk_bot compfuns U'), |
|
1505 |
(v', mk_bot compfuns U')])) |
|
1506 |
end; |
|
1507 |
||
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:
35267
diff
changeset
|
1508 |
fun string_of_tderiv thy (t, deriv) = |
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:
35267
diff
changeset
|
1509 |
(case (t, deriv) of |
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:
35267
diff
changeset
|
1510 |
(t1 $ t2, Mode_App (deriv1, deriv2)) => |
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:
35267
diff
changeset
|
1511 |
string_of_tderiv thy (t1, deriv1) ^ " $ " ^ string_of_tderiv thy (t2, deriv2) |
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:
35267
diff
changeset
|
1512 |
| (Const ("Pair", _) $ t1 $ t2, Mode_Pair (deriv1, deriv2)) => |
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:
35267
diff
changeset
|
1513 |
"(" ^ string_of_tderiv thy (t1, deriv1) ^ ", " ^ string_of_tderiv thy (t2, deriv2) ^ ")" |
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:
35267
diff
changeset
|
1514 |
| (t, Term Input) => Syntax.string_of_term_global thy t ^ "[Input]" |
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:
35267
diff
changeset
|
1515 |
| (t, Term Output) => Syntax.string_of_term_global thy t ^ "[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:
35267
diff
changeset
|
1516 |
| (t, Context m) => Syntax.string_of_term_global thy t ^ "[" ^ string_of_mode m ^ "]") |
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:
35267
diff
changeset
|
1517 |
|
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:
35267
diff
changeset
|
1518 |
fun compile_expr compilation_modifiers compfuns thy pol (t, deriv) additional_arguments = |
32667 | 1519 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1520 |
fun expr_of (t, deriv) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1521 |
(case (t, deriv) of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1522 |
(t, Term Input) => SOME t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1523 |
| (t, Term Output) => NONE |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1524 |
| (Const (name, T), Context mode) => |
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:
35267
diff
changeset
|
1525 |
SOME (Const (function_name_of (Comp_Mod.compilation compilation_modifiers) thy name |
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:
35267
diff
changeset
|
1526 |
(pol, mode), |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1527 |
Comp_Mod.funT_of compilation_modifiers mode T)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1528 |
| (Free (s, T), Context m) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1529 |
SOME (Free (s, Comp_Mod.funT_of compilation_modifiers m T)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1530 |
| (t, Context m) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1531 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1532 |
val bs = map (pair "x") (binder_types (fastype_of t)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1533 |
val bounds = map Bound (rev (0 upto (length bs) - 1)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1534 |
in SOME (list_abs (bs, mk_if compfuns (list_comb (t, bounds)))) end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1535 |
| (Const ("Pair", _) $ t1 $ t2, Mode_Pair (d1, d2)) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1536 |
(case (expr_of (t1, d1), expr_of (t2, d2)) of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1537 |
(NONE, NONE) => NONE |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1538 |
| (NONE, SOME t) => SOME t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1539 |
| (SOME t, NONE) => SOME t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1540 |
| (SOME t1, SOME t2) => SOME (HOLogic.mk_prod (t1, t2))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1541 |
| (t1 $ t2, Mode_App (deriv1, deriv2)) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1542 |
(case (expr_of (t1, deriv1), expr_of (t2, deriv2)) of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1543 |
(SOME t, NONE) => SOME t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1544 |
| (SOME t, SOME u) => SOME (t $ u) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1545 |
| _ => error "something went wrong here!")) |
32667 | 1546 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1547 |
the (expr_of (t, deriv)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1548 |
end |
33145 | 1549 |
|
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1550 |
fun compile_clause compilation_modifiers compfuns thy all_vs param_vs additional_arguments |
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:
35267
diff
changeset
|
1551 |
(pol, mode) inp (ts, moded_ps) = |
32667 | 1552 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1553 |
val iss = ho_arg_modes_of mode |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1554 |
val compile_match = compile_match compilation_modifiers compfuns |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1555 |
additional_arguments param_vs iss thy |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1556 |
val (in_ts, out_ts) = split_mode mode ts; |
32667 | 1557 |
val (in_ts', (all_vs', eqs)) = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1558 |
fold_map (collect_non_invertible_subterms thy) in_ts (all_vs, []); |
32667 | 1559 |
fun compile_prems out_ts' vs names [] = |
1560 |
let |
|
1561 |
val (out_ts'', (names', eqs')) = |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1562 |
fold_map (collect_non_invertible_subterms thy) out_ts' (names, []); |
32667 | 1563 |
val (out_ts''', (names'', constr_vs)) = fold_map distinct_v |
1564 |
out_ts'' (names', map (rpair []) vs); |
|
1565 |
in |
|
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1566 |
compile_match constr_vs (eqs @ eqs') out_ts''' |
33148
0808f7d0d0d7
removed tuple functions from the predicate compiler
bulwahn
parents:
33147
diff
changeset
|
1567 |
(mk_single compfuns (HOLogic.mk_tuple out_ts)) |
32667 | 1568 |
end |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1569 |
| compile_prems out_ts vs names ((p, deriv) :: ps) = |
32667 | 1570 |
let |
1571 |
val vs' = distinct (op =) (flat (vs :: map term_vs out_ts)); |
|
1572 |
val (out_ts', (names', eqs)) = |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1573 |
fold_map (collect_non_invertible_subterms thy) out_ts (names, []) |
32667 | 1574 |
val (out_ts'', (names'', constr_vs')) = fold_map distinct_v |
1575 |
out_ts' ((names', map (rpair []) vs)) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1576 |
val mode = head_mode_of deriv |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1577 |
val additional_arguments' = |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1578 |
Comp_Mod.transform_additional_arguments compilation_modifiers p additional_arguments |
32667 | 1579 |
val (compiled_clause, rest) = case p of |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1580 |
Prem t => |
32667 | 1581 |
let |
33138
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
1582 |
val u = |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1583 |
compile_expr compilation_modifiers compfuns thy |
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:
35267
diff
changeset
|
1584 |
pol (t, deriv) additional_arguments' |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1585 |
val (_, out_ts''') = split_mode mode (snd (strip_comb t)) |
32667 | 1586 |
val rest = compile_prems out_ts''' vs' names'' ps |
1587 |
in |
|
1588 |
(u, rest) |
|
1589 |
end |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1590 |
| Negprem t => |
32667 | 1591 |
let |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1592 |
val u = mk_not compfuns |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1593 |
(compile_expr compilation_modifiers compfuns thy |
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:
35267
diff
changeset
|
1594 |
(not pol) (t, deriv) additional_arguments') |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1595 |
val (_, out_ts''') = split_mode mode (snd (strip_comb t)) |
32667 | 1596 |
val rest = compile_prems out_ts''' vs' names'' ps |
1597 |
in |
|
1598 |
(u, rest) |
|
1599 |
end |
|
1600 |
| Sidecond t => |
|
1601 |
let |
|
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1602 |
val t = compile_arg compilation_modifiers compfuns additional_arguments |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1603 |
thy param_vs iss t |
32667 | 1604 |
val rest = compile_prems [] vs' names'' ps; |
1605 |
in |
|
1606 |
(mk_if compfuns t, rest) |
|
1607 |
end |
|
1608 |
| Generator (v, T) => |
|
1609 |
let |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1610 |
val u = mk_random 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:
35267
diff
changeset
|
1611 |
|
32667 | 1612 |
val rest = compile_prems [Free (v, T)] vs' names'' ps; |
1613 |
in |
|
1614 |
(u, rest) |
|
1615 |
end |
|
1616 |
in |
|
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1617 |
compile_match constr_vs' eqs out_ts'' |
32667 | 1618 |
(mk_bind compfuns (compiled_clause, rest)) |
1619 |
end |
|
1620 |
val prem_t = compile_prems in_ts' param_vs all_vs' moded_ps; |
|
1621 |
in |
|
1622 |
mk_bind compfuns (mk_single compfuns inp, prem_t) |
|
1623 |
end |
|
1624 |
||
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:
35267
diff
changeset
|
1625 |
fun compile_pred compilation_modifiers thy all_vs param_vs s T (pol, mode) moded_cls = |
32667 | 1626 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1627 |
(* TODO: val additional_arguments = Comp_Mod.additional_arguments compilation_modifiers |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1628 |
(all_vs @ param_vs) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1629 |
*) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1630 |
val compfuns = Comp_Mod.compfuns compilation_modifiers |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1631 |
fun is_param_type (T as Type ("fun",[_ , T'])) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1632 |
is_some (try (dest_predT compfuns) T) orelse is_param_type T' |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1633 |
| is_param_type T = is_some (try (dest_predT compfuns) T) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1634 |
val additional_arguments = [] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1635 |
val (inpTs, outTs) = split_map_modeT (fn m => fn T => (SOME (funT_of compfuns m T), NONE)) mode |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1636 |
(binder_types T) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1637 |
val predT = mk_predT compfuns (HOLogic.mk_tupleT outTs) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1638 |
val funT = Comp_Mod.funT_of compilation_modifiers mode T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1639 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1640 |
val (in_ts, _) = fold_map (fold_map_aterms_prodT (curry HOLogic.mk_prod) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1641 |
(fn T => fn (param_vs, names) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1642 |
if is_param_type T then |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1643 |
(Free (hd param_vs, T), (tl param_vs, names)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1644 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1645 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1646 |
val new = Name.variant names "x" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1647 |
in (Free (new, T), (param_vs, new :: names)) end)) inpTs |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1648 |
(param_vs, (all_vs @ param_vs)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1649 |
val in_ts' = map_filter (map_filter_prod |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1650 |
(fn t as Free (x, _) => if member (op =) param_vs x then NONE else SOME t | t => SOME t)) in_ts |
32667 | 1651 |
val cl_ts = |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1652 |
map (compile_clause compilation_modifiers compfuns |
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:
35267
diff
changeset
|
1653 |
thy all_vs param_vs additional_arguments (pol, mode) (HOLogic.mk_tuple in_ts')) moded_cls; |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1654 |
val compilation = Comp_Mod.wrap_compilation compilation_modifiers compfuns |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1655 |
s T mode additional_arguments |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
1656 |
(if null cl_ts then |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1657 |
mk_bot compfuns (HOLogic.mk_tupleT outTs) |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
1658 |
else foldr1 (mk_sup compfuns) cl_ts) |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1659 |
val fun_const = |
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:
35267
diff
changeset
|
1660 |
Const (function_name_of (Comp_Mod.compilation compilation_modifiers) thy s (pol, mode), funT) |
32667 | 1661 |
in |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1662 |
HOLogic.mk_Trueprop |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1663 |
(HOLogic.mk_eq (list_comb (fun_const, in_ts @ additional_arguments), compilation)) |
32667 | 1664 |
end; |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1665 |
|
32667 | 1666 |
(* special setup for simpset *) |
34974
18b41bba42b5
new theory Algebras.thy for generic algebraic structures
haftmann
parents:
34963
diff
changeset
|
1667 |
val HOL_basic_ss' = HOL_basic_ss addsimps (@{thms HOL.simp_thms} @ [@{thm Pair_eq}]) |
32667 | 1668 |
setSolver (mk_solver "all_tac_solver" (fn _ => fn _ => all_tac)) |
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1669 |
setSolver (mk_solver "True_solver" (fn _ => rtac @{thm TrueI})) |
32667 | 1670 |
|
1671 |
(* Definition of executable functions and their intro and elim rules *) |
|
1672 |
||
1673 |
fun print_arities arities = tracing ("Arities:\n" ^ |
|
1674 |
cat_lines (map (fn (s, (ks, k)) => s ^ ": " ^ |
|
1675 |
space_implode " -> " (map |
|
1676 |
(fn NONE => "X" | SOME k' => string_of_int k') |
|
1677 |
(ks @ [SOME k]))) arities)); |
|
1678 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1679 |
fun split_lambda (x as Free _) t = lambda x t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1680 |
| split_lambda (Const ("Pair", _) $ t1 $ t2) t = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1681 |
HOLogic.mk_split (split_lambda t1 (split_lambda t2 t)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1682 |
| split_lambda (Const ("Product_Type.Unity", _)) t = Abs ("x", HOLogic.unitT, t) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1683 |
| split_lambda t _ = raise (TERM ("split_lambda", [t])) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1684 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1685 |
fun strip_split_abs (Const ("split", _) $ t) = strip_split_abs t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1686 |
| strip_split_abs (Abs (_, _, t)) = strip_split_abs t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1687 |
| strip_split_abs t = t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1688 |
|
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:
35267
diff
changeset
|
1689 |
fun mk_args is_eval (m as Pair (m1, m2), T as Type ("*", [T1, T2])) names = |
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:
35267
diff
changeset
|
1690 |
if eq_mode (m, Input) orelse eq_mode (m, Output) 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:
35267
diff
changeset
|
1691 |
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:
35267
diff
changeset
|
1692 |
val x = Name.variant names "x" |
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:
35267
diff
changeset
|
1693 |
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:
35267
diff
changeset
|
1694 |
(Free (x, T), x :: names) |
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:
35267
diff
changeset
|
1695 |
end |
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:
35267
diff
changeset
|
1696 |
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:
35267
diff
changeset
|
1697 |
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:
35267
diff
changeset
|
1698 |
val (t1, names') = mk_args is_eval (m1, T1) names |
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:
35267
diff
changeset
|
1699 |
val (t2, names'') = mk_args is_eval (m2, T2) names' |
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:
35267
diff
changeset
|
1700 |
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:
35267
diff
changeset
|
1701 |
(HOLogic.mk_prod (t1, t2), names'') |
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:
35267
diff
changeset
|
1702 |
end |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1703 |
| mk_args is_eval ((m as Fun _), T) names = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1704 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1705 |
val funT = funT_of PredicateCompFuns.compfuns m T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1706 |
val x = Name.variant names "x" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1707 |
val (args, _) = fold_map (mk_args is_eval) (strip_fun_mode m ~~ binder_types T) (x :: names) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1708 |
val (inargs, outargs) = split_map_mode (fn _ => fn t => (SOME t, NONE)) m args |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1709 |
val t = fold_rev split_lambda args (PredicateCompFuns.mk_Eval |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1710 |
(list_comb (Free (x, funT), inargs), HOLogic.mk_tuple outargs)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1711 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1712 |
(if is_eval then t else Free (x, funT), x :: names) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1713 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1714 |
| mk_args is_eval (_, T) names = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1715 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1716 |
val x = Name.variant names "x" |
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1717 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1718 |
(Free (x, T), x :: names) |
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1719 |
end |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1720 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1721 |
fun create_intro_elim_rule mode defthm mode_id funT pred thy = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1722 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1723 |
val funtrm = Const (mode_id, funT) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1724 |
val Ts = binder_types (fastype_of pred) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1725 |
val (args, argnames) = fold_map (mk_args true) (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:
34028
diff
changeset
|
1726 |
fun strip_eval _ t = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1727 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1728 |
val t' = strip_split_abs t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1729 |
val (r, _) = PredicateCompFuns.dest_Eval t' |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1730 |
in (SOME (fst (strip_comb r)), NONE) end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1731 |
val (inargs, outargs) = split_map_mode strip_eval mode args |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1732 |
val eval_hoargs = ho_args_of mode args |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1733 |
val hoargTs = 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:
34028
diff
changeset
|
1734 |
val hoarg_names' = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1735 |
Name.variant_list argnames ((map (fn i => "x" ^ string_of_int i)) (1 upto (length hoargTs))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1736 |
val hoargs' = map2 (curry Free) hoarg_names' hoargTs |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1737 |
val args' = replace_ho_args mode hoargs' args |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1738 |
val predpropI = HOLogic.mk_Trueprop (list_comb (pred, args')) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1739 |
val predpropE = HOLogic.mk_Trueprop (list_comb (pred, args)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1740 |
val param_eqs = map2 (HOLogic.mk_Trueprop oo (curry HOLogic.mk_eq)) eval_hoargs hoargs' |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1741 |
val funpropE = HOLogic.mk_Trueprop (PredicateCompFuns.mk_Eval (list_comb (funtrm, inargs), |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1742 |
if null outargs then Free("y", HOLogic.unitT) else HOLogic.mk_tuple outargs)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1743 |
val funpropI = HOLogic.mk_Trueprop (PredicateCompFuns.mk_Eval (list_comb (funtrm, inargs), |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1744 |
HOLogic.mk_tuple outargs)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1745 |
val introtrm = Logic.list_implies (predpropI :: param_eqs, funpropI) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1746 |
val simprules = [defthm, @{thm eval_pred}, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1747 |
@{thm "split_beta"}, @{thm "fst_conv"}, @{thm "snd_conv"}, @{thm pair_collapse}] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1748 |
val unfolddef_tac = Simplifier.asm_full_simp_tac (HOL_basic_ss addsimps simprules) 1 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1749 |
val introthm = Goal.prove (ProofContext.init thy) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1750 |
(argnames @ hoarg_names' @ ["y"]) [] introtrm (fn _ => unfolddef_tac) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1751 |
val P = HOLogic.mk_Trueprop (Free ("P", HOLogic.boolT)); |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1752 |
val elimtrm = Logic.list_implies ([funpropE, Logic.mk_implies (predpropE, P)], P) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1753 |
val elimthm = Goal.prove (ProofContext.init thy) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1754 |
(argnames @ ["y", "P"]) [] elimtrm (fn _ => unfolddef_tac) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1755 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1756 |
(introthm, elimthm) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1757 |
end |
32667 | 1758 |
|
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
1759 |
fun create_constname_of_mode options thy prefix name T mode = |
32667 | 1760 |
let |
33626
42f69386943a
new names for predicate functions in the predicate compiler
bulwahn
parents:
33623
diff
changeset
|
1761 |
val system_proposal = prefix ^ (Long_Name.base_name name) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1762 |
^ "_" ^ ascii_string_of_mode mode |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1763 |
val name = the_default system_proposal (proposed_names options name mode) |
32667 | 1764 |
in |
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
1765 |
Sign.full_bname thy name |
32667 | 1766 |
end; |
1767 |
||
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
1768 |
fun create_definitions options preds (name, modes) thy = |
32667 | 1769 |
let |
1770 |
val compfuns = PredicateCompFuns.compfuns |
|
1771 |
val T = AList.lookup (op =) preds name |> the |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1772 |
fun create_definition mode thy = |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1773 |
let |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1774 |
val mode_cname = create_constname_of_mode options thy "" name T mode |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1775 |
val mode_cbasename = Long_Name.base_name mode_cname |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1776 |
val funT = funT_of compfuns mode T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1777 |
val (args, _) = fold_map (mk_args true) ((strip_fun_mode mode) ~~ (binder_types T)) [] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1778 |
fun strip_eval m t = |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1779 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1780 |
val t' = strip_split_abs t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1781 |
val (r, _) = PredicateCompFuns.dest_Eval t' |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1782 |
in (SOME (fst (strip_comb r)), NONE) end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1783 |
val (inargs, outargs) = split_map_mode strip_eval mode args |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1784 |
val predterm = fold_rev split_lambda inargs |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1785 |
(PredicateCompFuns.mk_Enum (split_lambda (HOLogic.mk_tuple outargs) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1786 |
(list_comb (Const (name, T), args)))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1787 |
val lhs = Const (mode_cname, funT) |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1788 |
val def = Logic.mk_equals (lhs, predterm) |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1789 |
val ([definition], thy') = thy |> |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1790 |
Sign.add_consts_i [(Binding.name mode_cbasename, funT, NoSyn)] |> |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1791 |
PureThy.add_defs false [((Binding.name (mode_cbasename ^ "_def"), def), [])] |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1792 |
val (intro, elim) = |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1793 |
create_intro_elim_rule mode definition mode_cname funT (Const (name, T)) thy' |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1794 |
in thy' |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1795 |
|> set_function_name Pred name mode mode_cname |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1796 |
|> add_predfun_data name mode (definition, intro, elim) |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1797 |
|> PureThy.store_thm (Binding.name (mode_cbasename ^ "I"), intro) |> snd |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1798 |
|> PureThy.store_thm (Binding.name (mode_cbasename ^ "E"), elim) |> snd |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1799 |
|> Theory.checkpoint |
32667 | 1800 |
end; |
1801 |
in |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1802 |
thy |> defined_function_of Pred name |> fold create_definition modes |
32667 | 1803 |
end; |
1804 |
||
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
1805 |
fun define_functions comp_modifiers compfuns options preds (name, modes) thy = |
32667 | 1806 |
let |
1807 |
val T = AList.lookup (op =) preds name |> the |
|
1808 |
fun create_definition mode thy = |
|
1809 |
let |
|
33485
0df4f6e46e5e
made definition of functions generically for the different instances
bulwahn
parents:
33484
diff
changeset
|
1810 |
val function_name_prefix = Comp_Mod.function_name_prefix comp_modifiers |
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
1811 |
val mode_cname = create_constname_of_mode options thy function_name_prefix name T mode |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1812 |
val funT = Comp_Mod.funT_of comp_modifiers mode T |
32667 | 1813 |
in |
1814 |
thy |> Sign.add_consts_i [(Binding.name (Long_Name.base_name mode_cname), funT, NoSyn)] |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1815 |
|> set_function_name (Comp_Mod.compilation comp_modifiers) name mode mode_cname |
32667 | 1816 |
end; |
1817 |
in |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1818 |
thy |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1819 |
|> defined_function_of (Comp_Mod.compilation comp_modifiers) name |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1820 |
|> fold create_definition modes |
32667 | 1821 |
end; |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
1822 |
|
32667 | 1823 |
(* Proving equivalence of term *) |
1824 |
||
1825 |
fun is_Type (Type _) = true |
|
1826 |
| is_Type _ = false |
|
1827 |
||
1828 |
(* returns true if t is an application of an datatype constructor *) |
|
1829 |
(* which then consequently would be splitted *) |
|
1830 |
(* else false *) |
|
1831 |
fun is_constructor thy t = |
|
1832 |
if (is_Type (fastype_of t)) then |
|
1833 |
(case Datatype.get_info thy ((fst o dest_Type o fastype_of) t) of |
|
1834 |
NONE => false |
|
1835 |
| SOME info => (let |
|
1836 |
val constr_consts = maps (fn (_, (_, _, constrs)) => map fst constrs) (#descr info) |
|
1837 |
val (c, _) = strip_comb t |
|
1838 |
in (case c of |
|
1839 |
Const (name, _) => name mem_string constr_consts |
|
1840 |
| _ => false) end)) |
|
1841 |
else false |
|
1842 |
||
1843 |
(* MAJOR FIXME: prove_params should be simple |
|
1844 |
- different form of introrule for parameters ? *) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1845 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1846 |
fun prove_param options thy t deriv = |
32667 | 1847 |
let |
1848 |
val (f, args) = strip_comb (Envir.eta_contract t) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1849 |
val mode = head_mode_of deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1850 |
val param_derivations = param_derivations_of deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1851 |
val ho_args = ho_args_of mode args |
32667 | 1852 |
val f_tac = case f of |
1853 |
Const (name, T) => simp_tac (HOL_basic_ss addsimps |
|
1854 |
([@{thm eval_pred}, (predfun_definition_of thy name mode), |
|
1855 |
@{thm "split_eta"}, @{thm "split_beta"}, @{thm "fst_conv"}, |
|
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1856 |
@{thm "snd_conv"}, @{thm pair_collapse}, @{thm "Product_Type.split_conv"}])) 1 |
32667 | 1857 |
| Free _ => TRY (rtac @{thm refl} 1) |
1858 |
| Abs _ => error "prove_param: No valid parameter term" |
|
1859 |
in |
|
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1860 |
REPEAT_DETERM (rtac @{thm ext} 1) |
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1861 |
THEN print_tac' options "prove_param" |
32667 | 1862 |
THEN f_tac |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1863 |
THEN print_tac' options "after simplification in prove_args" |
32667 | 1864 |
THEN (REPEAT_DETERM (atac 1)) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1865 |
THEN (EVERY (map2 (prove_param options thy) ho_args param_derivations)) |
32667 | 1866 |
end |
1867 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1868 |
fun prove_expr options thy (premposition : int) (t, deriv) = |
32667 | 1869 |
case strip_comb t of |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1870 |
(Const (name, T), args) => |
32667 | 1871 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1872 |
val mode = head_mode_of deriv |
32667 | 1873 |
val introrule = predfun_intro_of thy name mode |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1874 |
val param_derivations = param_derivations_of deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1875 |
val ho_args = ho_args_of mode args |
32667 | 1876 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1877 |
print_tac' options "before intro rule:" |
32667 | 1878 |
(* for the right assumption in first position *) |
1879 |
THEN rotate_tac premposition 1 |
|
1880 |
THEN debug_tac (Display.string_of_thm (ProofContext.init thy) introrule) |
|
1881 |
THEN rtac introrule 1 |
|
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1882 |
THEN print_tac' options "after intro rule" |
32667 | 1883 |
(* work with parameter arguments *) |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1884 |
THEN atac 1 |
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1885 |
THEN print_tac' options "parameter goal" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1886 |
THEN (EVERY (map2 (prove_param options thy) ho_args param_derivations)) |
32667 | 1887 |
THEN (REPEAT_DETERM (atac 1)) |
1888 |
end |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1889 |
| _ => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1890 |
asm_full_simp_tac |
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1891 |
(HOL_basic_ss' addsimps [@{thm "split_eta"}, @{thm "split_beta"}, @{thm "fst_conv"}, |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1892 |
@{thm "snd_conv"}, @{thm pair_collapse}]) 1 |
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
1893 |
THEN (atac 1) |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1894 |
THEN print_tac' options "after prove parameter call" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1895 |
|
32667 | 1896 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1897 |
fun SOLVED tac st = FILTER (fn st' => nprems_of st' = nprems_of st - 1) tac st; |
32667 | 1898 |
|
1899 |
fun SOLVEDALL tac st = FILTER (fn st' => nprems_of st' = 0) tac st |
|
1900 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1901 |
fun check_format thy st = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1902 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1903 |
val concl' = Logic.strip_assums_concl (hd (prems_of st)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1904 |
val concl = HOLogic.dest_Trueprop concl' |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1905 |
val expr = fst (strip_comb (fst (PredicateCompFuns.dest_Eval concl))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1906 |
fun valid_expr (Const (@{const_name Predicate.bind}, _)) = true |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1907 |
| valid_expr (Const (@{const_name Predicate.single}, _)) = true |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1908 |
| valid_expr _ = false |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1909 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1910 |
if valid_expr expr then |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1911 |
((*tracing "expression is valid";*) Seq.single st) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1912 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1913 |
((*tracing "expression is not valid";*) Seq.empty) (*error "check_format: wrong format"*) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1914 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1915 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1916 |
fun prove_match options thy (out_ts : term list) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1917 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1918 |
fun get_case_rewrite t = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1919 |
if (is_constructor thy t) then let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1920 |
val case_rewrites = (#case_rewrites (Datatype.the_info thy |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1921 |
((fst o dest_Type o fastype_of) t))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1922 |
in case_rewrites @ maps get_case_rewrite (snd (strip_comb t)) end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1923 |
else [] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1924 |
val simprules = @{thm "unit.cases"} :: @{thm "prod.cases"} :: maps get_case_rewrite out_ts |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1925 |
(* replace TRY by determining if it necessary - are there equations when calling compile match? *) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1926 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1927 |
(* make this simpset better! *) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1928 |
asm_full_simp_tac (HOL_basic_ss' addsimps simprules) 1 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1929 |
THEN print_tac' options "after prove_match:" |
34974
18b41bba42b5
new theory Algebras.thy for generic algebraic structures
haftmann
parents:
34963
diff
changeset
|
1930 |
THEN (DETERM (TRY (EqSubst.eqsubst_tac (ProofContext.init thy) [0] [@{thm HOL.if_P}] 1 |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1931 |
THEN (REPEAT_DETERM (rtac @{thm conjI} 1 THEN (SOLVED (asm_simp_tac HOL_basic_ss' 1)))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1932 |
THEN print_tac' options "if condition to be solved:" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1933 |
THEN (SOLVED (asm_simp_tac HOL_basic_ss' 1 THEN print_tac' options "after if simp; in SOLVED:")) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1934 |
THEN check_format thy |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1935 |
THEN print_tac' options "after if simplification - a TRY block"))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1936 |
THEN print_tac' options "after if simplification" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1937 |
end; |
32667 | 1938 |
|
1939 |
(* corresponds to compile_fun -- maybe call that also compile_sidecond? *) |
|
1940 |
||
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:
35267
diff
changeset
|
1941 |
fun prove_sidecond thy t = |
32667 | 1942 |
let |
1943 |
fun preds_of t nameTs = case strip_comb t of |
|
1944 |
(f as Const (name, T), args) => |
|
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:
35267
diff
changeset
|
1945 |
if is_registered thy name then (name, T) :: nameTs |
32667 | 1946 |
else fold preds_of args nameTs |
1947 |
| _ => nameTs |
|
1948 |
val preds = preds_of t [] |
|
1949 |
val defs = map |
|
1950 |
(fn (pred, T) => predfun_definition_of thy pred |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1951 |
(all_input_of T)) |
32667 | 1952 |
preds |
1953 |
in |
|
1954 |
(* remove not_False_eq_True when simpset in prove_match is better *) |
|
1955 |
simp_tac (HOL_basic_ss addsimps |
|
34974
18b41bba42b5
new theory Algebras.thy for generic algebraic structures
haftmann
parents:
34963
diff
changeset
|
1956 |
(@{thms HOL.simp_thms} @ (@{thm not_False_eq_True} :: @{thm eval_pred} :: defs))) 1 |
32667 | 1957 |
(* need better control here! *) |
1958 |
end |
|
1959 |
||
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:
35267
diff
changeset
|
1960 |
fun prove_clause options thy nargs mode (_, clauses) (ts, moded_ps) = |
32667 | 1961 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1962 |
val (in_ts, clause_out_ts) = split_mode mode ts; |
32667 | 1963 |
fun prove_prems out_ts [] = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1964 |
(prove_match options thy out_ts) |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1965 |
THEN print_tac' options "before simplifying assumptions" |
32667 | 1966 |
THEN asm_full_simp_tac HOL_basic_ss' 1 |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1967 |
THEN print_tac' options "before single intro rule" |
32667 | 1968 |
THEN (rtac (if null clause_out_ts then @{thm singleI_unit} else @{thm singleI}) 1) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1969 |
| prove_prems out_ts ((p, deriv) :: ps) = |
32667 | 1970 |
let |
1971 |
val premposition = (find_index (equal p) clauses) + nargs |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1972 |
val mode = head_mode_of deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1973 |
val rest_tac = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1974 |
rtac @{thm bindI} 1 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1975 |
THEN (case p of Prem t => |
32667 | 1976 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1977 |
val (_, us) = strip_comb t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1978 |
val (_, out_ts''') = split_mode mode us |
32667 | 1979 |
val rec_tac = prove_prems out_ts''' ps |
1980 |
in |
|
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1981 |
print_tac' options "before clause:" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1982 |
(*THEN asm_simp_tac HOL_basic_ss 1*) |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1983 |
THEN print_tac' options "before prove_expr:" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1984 |
THEN prove_expr options thy premposition (t, deriv) |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
1985 |
THEN print_tac' options "after prove_expr:" |
32667 | 1986 |
THEN rec_tac |
1987 |
end |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1988 |
| Negprem t => |
32667 | 1989 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1990 |
val (t, args) = strip_comb t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1991 |
val (_, out_ts''') = split_mode mode args |
32667 | 1992 |
val rec_tac = prove_prems out_ts''' ps |
1993 |
val name = (case strip_comb t of (Const (c, _), _) => SOME c | _ => NONE) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1994 |
val param_derivations = param_derivations_of deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1995 |
val params = ho_args_of mode args |
32667 | 1996 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1997 |
print_tac' options "before prove_neg_expr:" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1998 |
THEN full_simp_tac (HOL_basic_ss addsimps |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1999 |
[@{thm split_eta}, @{thm split_beta}, @{thm fst_conv}, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2000 |
@{thm snd_conv}, @{thm pair_collapse}, @{thm Product_Type.split_conv}]) 1 |
32667 | 2001 |
THEN (if (is_some name) then |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
2002 |
print_tac' options ("before unfolding definition " ^ |
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
2003 |
(Display.string_of_thm_global thy |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2004 |
(predfun_definition_of thy (the name) mode))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2005 |
|
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
2006 |
THEN simp_tac (HOL_basic_ss addsimps |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2007 |
[predfun_definition_of thy (the name) mode]) 1 |
32667 | 2008 |
THEN rtac @{thm not_predI} 1 |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
2009 |
THEN print_tac' options "after applying rule not_predI" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2010 |
THEN full_simp_tac (HOL_basic_ss addsimps [@{thm not_False_eq_True}, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2011 |
@{thm split_eta}, @{thm split_beta}, @{thm fst_conv}, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2012 |
@{thm snd_conv}, @{thm pair_collapse}, @{thm Product_Type.split_conv}]) 1 |
32667 | 2013 |
THEN (REPEAT_DETERM (atac 1)) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2014 |
THEN (EVERY (map2 (prove_param options thy) params param_derivations)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2015 |
THEN (REPEAT_DETERM (atac 1)) |
32667 | 2016 |
else |
2017 |
rtac @{thm not_predI'} 1) |
|
2018 |
THEN simp_tac (HOL_basic_ss addsimps [@{thm not_False_eq_True}]) 1 |
|
2019 |
THEN rec_tac |
|
2020 |
end |
|
2021 |
| Sidecond t => |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2022 |
rtac @{thm if_predI} 1 |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
2023 |
THEN print_tac' options "before sidecond:" |
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:
35267
diff
changeset
|
2024 |
THEN prove_sidecond thy t |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
2025 |
THEN print_tac' options "after sidecond:" |
32667 | 2026 |
THEN prove_prems [] ps) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2027 |
in (prove_match options thy out_ts) |
32667 | 2028 |
THEN rest_tac |
2029 |
end; |
|
2030 |
val prems_tac = prove_prems in_ts moded_ps |
|
2031 |
in |
|
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2032 |
print_tac' options "Proving clause..." |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2033 |
THEN rtac @{thm bindI} 1 |
32667 | 2034 |
THEN rtac @{thm singleI} 1 |
2035 |
THEN prems_tac |
|
2036 |
end; |
|
2037 |
||
2038 |
fun select_sup 1 1 = [] |
|
2039 |
| select_sup _ 1 = [rtac @{thm supI1}] |
|
2040 |
| select_sup n i = (rtac @{thm supI2})::(select_sup (n - 1) (i - 1)); |
|
2041 |
||
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:
35267
diff
changeset
|
2042 |
fun prove_one_direction options thy clauses preds pred mode moded_clauses = |
32667 | 2043 |
let |
2044 |
val T = the (AList.lookup (op =) preds pred) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2045 |
val nargs = length (binder_types T) |
32667 | 2046 |
val pred_case_rule = the_elim_of thy pred |
2047 |
in |
|
2048 |
REPEAT_DETERM (CHANGED (rewtac @{thm "split_paired_all"})) |
|
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
2049 |
THEN print_tac' options "before applying elim rule" |
32667 | 2050 |
THEN etac (predfun_elim_of thy pred mode) 1 |
2051 |
THEN etac pred_case_rule 1 |
|
2052 |
THEN (EVERY (map |
|
2053 |
(fn i => EVERY' (select_sup (length moded_clauses) i) i) |
|
2054 |
(1 upto (length moded_clauses)))) |
|
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:
35267
diff
changeset
|
2055 |
THEN (EVERY (map2 (prove_clause options thy nargs mode) clauses moded_clauses)) |
33753
1344e9bb611e
changing the proof procedure for parameters; adding a testcase for negation and parameters; adopting print_tac to the latest function print_tac' in the predicate compiler
bulwahn
parents:
33752
diff
changeset
|
2056 |
THEN print_tac' options "proved one direction" |
32667 | 2057 |
end; |
2058 |
||
2059 |
(** Proof in the other direction **) |
|
2060 |
||
2061 |
fun prove_match2 thy out_ts = let |
|
2062 |
fun split_term_tac (Free _) = all_tac |
|
2063 |
| split_term_tac t = |
|
2064 |
if (is_constructor thy t) then let |
|
2065 |
val info = Datatype.the_info thy ((fst o dest_Type o fastype_of) t) |
|
2066 |
val num_of_constrs = length (#case_rewrites info) |
|
2067 |
(* special treatment of pairs -- because of fishing *) |
|
2068 |
val split_rules = case (fst o dest_Type o fastype_of) t of |
|
2069 |
"*" => [@{thm prod.split_asm}] |
|
2070 |
| _ => PureThy.get_thms thy (((fst o dest_Type o fastype_of) t) ^ ".split_asm") |
|
2071 |
val (_, ts) = strip_comb t |
|
2072 |
in |
|
33108
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
2073 |
(print_tac ("Term " ^ (Syntax.string_of_term_global thy t) ^ |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
2074 |
"splitting with rules \n" ^ |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
2075 |
commas (map (Display.string_of_thm_global thy) split_rules))) |
33115
f765c3234059
changed proof method to handle widen predicate in JinjaThreads
bulwahn
parents:
33114
diff
changeset
|
2076 |
THEN TRY ((Splitter.split_asm_tac split_rules 1) |
33108
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
2077 |
THEN (print_tac "after splitting with split_asm rules") |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
2078 |
(* THEN (Simplifier.asm_full_simp_tac HOL_basic_ss 1) |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
2079 |
THEN (DETERM (TRY (etac @{thm Pair_inject} 1)))*) |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2080 |
THEN (REPEAT_DETERM_N (num_of_constrs - 1) |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2081 |
(etac @{thm botE} 1 ORELSE etac @{thm botE} 2))) |
33108
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
2082 |
THEN (assert_tac (Max_number_of_subgoals 2)) |
32667 | 2083 |
THEN (EVERY (map split_term_tac ts)) |
2084 |
end |
|
2085 |
else all_tac |
|
2086 |
in |
|
33148
0808f7d0d0d7
removed tuple functions from the predicate compiler
bulwahn
parents:
33147
diff
changeset
|
2087 |
split_term_tac (HOLogic.mk_tuple out_ts) |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2088 |
THEN (DETERM (TRY ((Splitter.split_asm_tac [@{thm "split_if_asm"}] 1) |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2089 |
THEN (etac @{thm botE} 2)))) |
32667 | 2090 |
end |
2091 |
||
2092 |
(* VERY LARGE SIMILIRATIY to function prove_param |
|
2093 |
-- join both functions |
|
2094 |
*) |
|
2095 |
(* TODO: remove function *) |
|
2096 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2097 |
fun prove_param2 thy t deriv = |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2098 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2099 |
val (f, args) = strip_comb (Envir.eta_contract t) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2100 |
val mode = head_mode_of deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2101 |
val param_derivations = param_derivations_of deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2102 |
val ho_args = ho_args_of mode args |
32667 | 2103 |
val f_tac = case f of |
2104 |
Const (name, T) => full_simp_tac (HOL_basic_ss addsimps |
|
2105 |
(@{thm eval_pred}::(predfun_definition_of thy name mode) |
|
2106 |
:: @{thm "Product_Type.split_conv"}::[])) 1 |
|
2107 |
| Free _ => all_tac |
|
2108 |
| _ => error "prove_param2: illegal parameter term" |
|
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2109 |
in |
32667 | 2110 |
print_tac "before simplification in prove_args:" |
2111 |
THEN f_tac |
|
2112 |
THEN print_tac "after simplification in prove_args" |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2113 |
THEN EVERY (map2 (prove_param2 thy) ho_args param_derivations) |
32667 | 2114 |
end |
2115 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2116 |
fun prove_expr2 thy (t, deriv) = |
32667 | 2117 |
(case strip_comb t of |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2118 |
(Const (name, T), args) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2119 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2120 |
val mode = head_mode_of deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2121 |
val param_derivations = param_derivations_of deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2122 |
val ho_args = ho_args_of mode args |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2123 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2124 |
etac @{thm bindE} 1 |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2125 |
THEN (REPEAT_DETERM (CHANGED (rewtac @{thm "split_paired_all"}))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2126 |
THEN print_tac "prove_expr2-before" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2127 |
THEN (debug_tac (Syntax.string_of_term_global thy |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2128 |
(prop_of (predfun_elim_of thy name mode)))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2129 |
THEN (etac (predfun_elim_of thy name mode) 1) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2130 |
THEN print_tac "prove_expr2" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2131 |
THEN (EVERY (map2 (prove_param2 thy) ho_args param_derivations)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2132 |
THEN print_tac "finished prove_expr2" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2133 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2134 |
| _ => etac @{thm bindE} 1) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2135 |
|
32667 | 2136 |
(* FIXME: what is this for? *) |
2137 |
(* replace defined by has_mode thy pred *) |
|
2138 |
(* TODO: rewrite function *) |
|
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:
35267
diff
changeset
|
2139 |
fun prove_sidecond2 thy t = let |
32667 | 2140 |
fun preds_of t nameTs = case strip_comb t of |
2141 |
(f as Const (name, T), args) => |
|
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:
35267
diff
changeset
|
2142 |
if is_registered thy name then (name, T) :: nameTs |
32667 | 2143 |
else fold preds_of args nameTs |
2144 |
| _ => nameTs |
|
2145 |
val preds = preds_of t [] |
|
2146 |
val defs = map |
|
2147 |
(fn (pred, T) => predfun_definition_of thy pred |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2148 |
(all_input_of T)) |
32667 | 2149 |
preds |
2150 |
in |
|
2151 |
(* only simplify the one assumption *) |
|
2152 |
full_simp_tac (HOL_basic_ss' addsimps @{thm eval_pred} :: defs) 1 |
|
2153 |
(* need better control here! *) |
|
2154 |
THEN print_tac "after sidecond2 simplification" |
|
2155 |
end |
|
2156 |
||
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:
35267
diff
changeset
|
2157 |
fun prove_clause2 thy pred mode (ts, ps) i = |
32667 | 2158 |
let |
2159 |
val pred_intro_rule = nth (intros_of thy pred) (i - 1) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2160 |
val (in_ts, clause_out_ts) = split_mode mode ts; |
32667 | 2161 |
fun prove_prems2 out_ts [] = |
2162 |
print_tac "before prove_match2 - last call:" |
|
2163 |
THEN prove_match2 thy out_ts |
|
2164 |
THEN print_tac "after prove_match2 - last call:" |
|
2165 |
THEN (etac @{thm singleE} 1) |
|
2166 |
THEN (REPEAT_DETERM (etac @{thm Pair_inject} 1)) |
|
2167 |
THEN (asm_full_simp_tac HOL_basic_ss' 1) |
|
2168 |
THEN (REPEAT_DETERM (etac @{thm Pair_inject} 1)) |
|
2169 |
THEN (asm_full_simp_tac HOL_basic_ss' 1) |
|
2170 |
THEN SOLVED (print_tac "state before applying intro rule:" |
|
2171 |
THEN (rtac pred_intro_rule 1) |
|
2172 |
(* How to handle equality correctly? *) |
|
2173 |
THEN (print_tac "state before assumption matching") |
|
2174 |
THEN (REPEAT (atac 1 ORELSE |
|
2175 |
(CHANGED (asm_full_simp_tac (HOL_basic_ss' addsimps |
|
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2176 |
[@{thm split_eta}, @{thm "split_beta"}, @{thm "fst_conv"}, |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2177 |
@{thm "snd_conv"}, @{thm pair_collapse}]) 1) |
32667 | 2178 |
THEN print_tac "state after simp_tac:")))) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2179 |
| prove_prems2 out_ts ((p, deriv) :: ps) = |
32667 | 2180 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2181 |
val mode = head_mode_of deriv |
32667 | 2182 |
val rest_tac = (case p of |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2183 |
Prem t => |
32667 | 2184 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2185 |
val (_, us) = strip_comb t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2186 |
val (_, out_ts''') = split_mode mode us |
32667 | 2187 |
val rec_tac = prove_prems2 out_ts''' ps |
2188 |
in |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2189 |
(prove_expr2 thy (t, deriv)) THEN rec_tac |
32667 | 2190 |
end |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2191 |
| Negprem t => |
32667 | 2192 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2193 |
val (_, args) = strip_comb t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2194 |
val (_, out_ts''') = split_mode mode args |
32667 | 2195 |
val rec_tac = prove_prems2 out_ts''' ps |
2196 |
val name = (case strip_comb t of (Const (c, _), _) => SOME c | _ => NONE) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2197 |
val param_derivations = param_derivations_of deriv |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2198 |
val ho_args = ho_args_of mode args |
32667 | 2199 |
in |
2200 |
print_tac "before neg prem 2" |
|
2201 |
THEN etac @{thm bindE} 1 |
|
2202 |
THEN (if is_some name then |
|
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2203 |
full_simp_tac (HOL_basic_ss addsimps |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2204 |
[predfun_definition_of thy (the name) mode]) 1 |
32667 | 2205 |
THEN etac @{thm not_predE} 1 |
2206 |
THEN simp_tac (HOL_basic_ss addsimps [@{thm not_False_eq_True}]) 1 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2207 |
THEN (EVERY (map2 (prove_param2 thy) ho_args param_derivations)) |
32667 | 2208 |
else |
2209 |
etac @{thm not_predE'} 1) |
|
2210 |
THEN rec_tac |
|
2211 |
end |
|
2212 |
| Sidecond t => |
|
2213 |
etac @{thm bindE} 1 |
|
2214 |
THEN etac @{thm if_predE} 1 |
|
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:
35267
diff
changeset
|
2215 |
THEN prove_sidecond2 thy t |
32667 | 2216 |
THEN prove_prems2 [] ps) |
2217 |
in print_tac "before prove_match2:" |
|
2218 |
THEN prove_match2 thy out_ts |
|
2219 |
THEN print_tac "after prove_match2:" |
|
2220 |
THEN rest_tac |
|
2221 |
end; |
|
2222 |
val prems_tac = prove_prems2 in_ts ps |
|
2223 |
in |
|
2224 |
print_tac "starting prove_clause2" |
|
2225 |
THEN etac @{thm bindE} 1 |
|
2226 |
THEN (etac @{thm singleE'} 1) |
|
2227 |
THEN (TRY (etac @{thm Pair_inject} 1)) |
|
2228 |
THEN print_tac "after singleE':" |
|
2229 |
THEN prems_tac |
|
2230 |
end; |
|
2231 |
||
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:
35267
diff
changeset
|
2232 |
fun prove_other_direction options thy pred mode moded_clauses = |
32667 | 2233 |
let |
2234 |
fun prove_clause clause i = |
|
2235 |
(if i < length moded_clauses then etac @{thm supE} 1 else all_tac) |
|
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:
35267
diff
changeset
|
2236 |
THEN (prove_clause2 thy pred mode clause i) |
32667 | 2237 |
in |
2238 |
(DETERM (TRY (rtac @{thm unit.induct} 1))) |
|
2239 |
THEN (REPEAT_DETERM (CHANGED (rewtac @{thm split_paired_all}))) |
|
2240 |
THEN (rtac (predfun_intro_of thy pred mode) 1) |
|
2241 |
THEN (REPEAT_DETERM (rtac @{thm refl} 2)) |
|
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2242 |
THEN (if null moded_clauses then |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2243 |
etac @{thm botE} 1 |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2244 |
else EVERY (map2 prove_clause moded_clauses (1 upto (length moded_clauses)))) |
32667 | 2245 |
end; |
2246 |
||
2247 |
(** proof procedure **) |
|
2248 |
||
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:
35267
diff
changeset
|
2249 |
fun prove_pred options thy clauses preds pred (pol, mode) (moded_clauses, compiled_term) = |
32667 | 2250 |
let |
2251 |
val ctxt = ProofContext.init thy |
|
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2252 |
val clauses = case AList.lookup (op =) clauses pred of SOME rs => rs | NONE => [] |
32667 | 2253 |
in |
2254 |
Goal.prove ctxt (Term.add_free_names compiled_term []) [] compiled_term |
|
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2255 |
(if not (skip_proof options) then |
32667 | 2256 |
(fn _ => |
2257 |
rtac @{thm pred_iffI} 1 |
|
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
2258 |
THEN print_tac' options "after pred_iffI" |
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:
35267
diff
changeset
|
2259 |
THEN prove_one_direction options thy clauses preds pred mode moded_clauses |
33127 | 2260 |
THEN print_tac' options "proved one direction" |
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:
35267
diff
changeset
|
2261 |
THEN prove_other_direction options thy pred mode moded_clauses |
33127 | 2262 |
THEN print_tac' options "proved other direction") |
33150
75eddea4abef
further changes due to the previous merge in the predicate compiler
bulwahn
parents:
33149
diff
changeset
|
2263 |
else (fn _ => Skip_Proof.cheat_tac thy)) |
32667 | 2264 |
end; |
2265 |
||
2266 |
(* composition of mode inference, definition, compilation and proof *) |
|
2267 |
||
2268 |
(** auxillary combinators for table of preds and modes **) |
|
2269 |
||
2270 |
fun map_preds_modes f preds_modes_table = |
|
2271 |
map (fn (pred, modes) => |
|
2272 |
(pred, map (fn (mode, value) => (mode, f pred mode value)) modes)) preds_modes_table |
|
2273 |
||
2274 |
fun join_preds_modes table1 table2 = |
|
2275 |
map_preds_modes (fn pred => fn mode => fn value => |
|
2276 |
(value, the (AList.lookup (op =) (the (AList.lookup (op =) table2 pred)) mode))) table1 |
|
2277 |
||
2278 |
fun maps_modes preds_modes_table = |
|
2279 |
map (fn (pred, modes) => |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2280 |
(pred, map (fn (mode, value) => value) modes)) preds_modes_table |
32667 | 2281 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2282 |
fun compile_preds comp_modifiers thy all_vs param_vs preds moded_clauses = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2283 |
map_preds_modes (fn pred => compile_pred comp_modifiers thy all_vs param_vs pred |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2284 |
(the (AList.lookup (op =) preds pred))) moded_clauses |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2285 |
|
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:
35267
diff
changeset
|
2286 |
fun prove options thy clauses preds moded_clauses compiled_terms = |
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:
35267
diff
changeset
|
2287 |
map_preds_modes (prove_pred options thy clauses preds) |
32667 | 2288 |
(join_preds_modes moded_clauses compiled_terms) |
2289 |
||
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:
35267
diff
changeset
|
2290 |
fun prove_by_skip options thy _ _ _ compiled_terms = |
35021
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34974
diff
changeset
|
2291 |
map_preds_modes |
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34974
diff
changeset
|
2292 |
(fn pred => fn mode => fn t => Drule.export_without_context (Skip_Proof.make_thm thy t)) |
32667 | 2293 |
compiled_terms |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2294 |
|
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2295 |
(* preparation of introduction rules into special datastructures *) |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2296 |
|
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2297 |
fun dest_prem thy params t = |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2298 |
(case strip_comb t of |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2299 |
(v as Free _, ts) => if member (op =) params v then Prem t else Sidecond t |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2300 |
| (c as Const (@{const_name Not}, _), [t]) => (case dest_prem thy params t of |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2301 |
Prem t => Negprem t |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2302 |
| Negprem _ => error ("Double negation not allowed in premise: " ^ |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2303 |
Syntax.string_of_term_global thy (c $ t)) |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2304 |
| Sidecond t => Sidecond (c $ t)) |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2305 |
| (c as Const (s, _), ts) => |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2306 |
if is_registered thy s then Prem t else Sidecond t |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2307 |
| _ => Sidecond t) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2308 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2309 |
fun prepare_intrs options compilation thy prednames intros = |
32667 | 2310 |
let |
33126
bb8806eb5da7
importing of polymorphic introduction rules with different schematic variable names
bulwahn
parents:
33124
diff
changeset
|
2311 |
val intrs = map prop_of intros |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2312 |
val preds = map (fn c => Const (c, Sign.the_const_type thy c)) prednames |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2313 |
val (preds, intrs) = unify_consts thy preds intrs |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2314 |
val ([preds, intrs], _) = fold_burrow (Variable.import_terms false) [preds, intrs] |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2315 |
(ProofContext.init thy) |
33126
bb8806eb5da7
importing of polymorphic introduction rules with different schematic variable names
bulwahn
parents:
33124
diff
changeset
|
2316 |
val preds = map dest_Const preds |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2317 |
val all_vs = terms_vs intrs |
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:
35267
diff
changeset
|
2318 |
val all_modes = |
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:
35267
diff
changeset
|
2319 |
map (fn (s, 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:
35267
diff
changeset
|
2320 |
(s, |
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:
35267
diff
changeset
|
2321 |
(if member (op =) (no_higher_order_predicate options) s 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:
35267
diff
changeset
|
2322 |
(all_smodes_of_typ 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:
35267
diff
changeset
|
2323 |
else (all_modes_of_typ T)))) preds |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2324 |
val params = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2325 |
case intrs of |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2326 |
[] => |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2327 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2328 |
val T = snd (hd preds) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2329 |
val paramTs = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2330 |
ho_argsT_of (hd (all_modes_of_typ T)) (binder_types T) |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2331 |
val param_names = Name.variant_list [] (map (fn i => "p" ^ string_of_int i) |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2332 |
(1 upto length paramTs)) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2333 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2334 |
map2 (curry Free) param_names paramTs |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2335 |
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:
35267
diff
changeset
|
2336 |
| (intr :: _) => |
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:
35267
diff
changeset
|
2337 |
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:
35267
diff
changeset
|
2338 |
val (p, args) = strip_comb (HOLogic.dest_Trueprop (Logic.strip_imp_concl intr)) |
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:
35267
diff
changeset
|
2339 |
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:
35267
diff
changeset
|
2340 |
ho_args_of (hd (the (AList.lookup (op =) all_modes (fst (dest_Const p))))) args |
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:
35267
diff
changeset
|
2341 |
end |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2342 |
val param_vs = map (fst o dest_Free) params |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2343 |
fun add_clause intr clauses = |
32667 | 2344 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2345 |
val (Const (name, T), ts) = strip_comb (HOLogic.dest_Trueprop (Logic.strip_imp_concl intr)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2346 |
val prems = map (dest_prem thy params o HOLogic.dest_Trueprop) (Logic.strip_imp_prems intr) |
32667 | 2347 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2348 |
AList.update op = (name, these (AList.lookup op = clauses name) @ |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2349 |
[(ts, prems)]) clauses |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2350 |
end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2351 |
val clauses = fold add_clause intrs [] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2352 |
in |
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:
35267
diff
changeset
|
2353 |
(preds, all_vs, param_vs, all_modes, clauses) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2354 |
end; |
32667 | 2355 |
|
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2356 |
(* sanity check of introduction rules *) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2357 |
(* TODO: rethink check with new modes *) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2358 |
(* |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2359 |
fun check_format_of_intro_rule thy intro = |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2360 |
let |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2361 |
val concl = Logic.strip_imp_concl (prop_of intro) |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2362 |
val (p, args) = strip_comb (HOLogic.dest_Trueprop concl) |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2363 |
val params = fst (chop (nparams_of thy (fst (dest_Const p))) args) |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2364 |
fun check_arg arg = case HOLogic.strip_tupleT (fastype_of arg) of |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2365 |
(Ts as _ :: _ :: _) => |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2366 |
if length (HOLogic.strip_tuple arg) = length Ts then |
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2367 |
true |
33114
4785ef554dcc
added further examples; added mode to code_pred command; tuned; some temporary things in Predicate_Compile_ex
bulwahn
parents:
33113
diff
changeset
|
2368 |
else |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2369 |
error ("Format of introduction rule is invalid: tuples must be expanded:" |
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2370 |
^ (Syntax.string_of_term_global thy arg) ^ " in " ^ |
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2371 |
(Display.string_of_thm_global thy intro)) |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2372 |
| _ => true |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2373 |
val prems = Logic.strip_imp_prems (prop_of intro) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2374 |
fun check_prem (Prem t) = forall check_arg args |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2375 |
| check_prem (Negprem t) = forall check_arg args |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2376 |
| check_prem _ = true |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2377 |
in |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2378 |
forall check_arg args andalso |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2379 |
forall (check_prem o dest_prem thy params o HOLogic.dest_Trueprop) prems |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2380 |
end |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2381 |
*) |
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2382 |
(* |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2383 |
fun check_intros_elim_match thy prednames = |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2384 |
let |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2385 |
fun check predname = |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2386 |
let |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2387 |
val intros = intros_of thy predname |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2388 |
val elim = the_elim_of thy predname |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2389 |
val nparams = nparams_of thy predname |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2390 |
val elim' = |
35021
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34974
diff
changeset
|
2391 |
(Drule.export_without_context o Skip_Proof.make_thm thy) |
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2392 |
(mk_casesrule (ProofContext.init thy) nparams intros) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2393 |
in |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2394 |
if not (Thm.equiv_thm (elim, elim')) then |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2395 |
error "Introduction and elimination rules do not match!" |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2396 |
else true |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2397 |
end |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2398 |
in forall check prednames end |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2399 |
*) |
33113 | 2400 |
|
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2401 |
(* create code equation *) |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2402 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2403 |
fun add_code_equations thy preds result_thmss = |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2404 |
let |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2405 |
fun add_code_equation (predname, T) (pred, result_thms) = |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2406 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2407 |
val full_mode = fold_rev (curry Fun) (map (K Input) (binder_types T)) Bool |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2408 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2409 |
if member (op =) (modes_of Pred thy predname) full_mode then |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2410 |
let |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2411 |
val Ts = binder_types T |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2412 |
val arg_names = Name.variant_list [] |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2413 |
(map (fn i => "x" ^ string_of_int i) (1 upto length Ts)) |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2414 |
val args = map2 (curry Free) arg_names Ts |
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:
35267
diff
changeset
|
2415 |
val predfun = Const (function_name_of Pred thy predname (true, full_mode), |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2416 |
Ts ---> PredicateCompFuns.mk_predT @{typ unit}) |
33754
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33753
diff
changeset
|
2417 |
val rhs = @{term Predicate.holds} $ (list_comb (predfun, args)) |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2418 |
val eq_term = HOLogic.mk_Trueprop |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2419 |
(HOLogic.mk_eq (list_comb (Const (predname, T), args), rhs)) |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2420 |
val def = predfun_definition_of thy predname full_mode |
33441
99a5f22a967d
eliminated funny record patterns and made SML/NJ happy;
wenzelm
parents:
33377
diff
changeset
|
2421 |
val tac = fn _ => Simplifier.simp_tac |
33754
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33753
diff
changeset
|
2422 |
(HOL_basic_ss addsimps [def, @{thm holds_eq}, @{thm eval_pred}]) 1 |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2423 |
val eq = Goal.prove (ProofContext.init thy) arg_names [] eq_term tac |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2424 |
in |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2425 |
(pred, result_thms @ [eq]) |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2426 |
end |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2427 |
else |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2428 |
(pred, result_thms) |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2429 |
end |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2430 |
in |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2431 |
map2 add_code_equation preds result_thmss |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2432 |
end |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2433 |
|
32667 | 2434 |
(** main function of predicate compiler **) |
2435 |
||
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2436 |
datatype steps = Steps of |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2437 |
{ |
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:
35267
diff
changeset
|
2438 |
define_functions : options -> (string * typ) list -> string * (bool * mode) list -> theory -> theory, |
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:
35267
diff
changeset
|
2439 |
(*infer_modes : options -> (string * typ) list -> (string * mode list) list |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2440 |
-> string list -> (string * (term list * indprem list) list) list |
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:
35267
diff
changeset
|
2441 |
-> theory -> ((moded_clause list pred_mode_table * string list) * theory),*) |
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:
35267
diff
changeset
|
2442 |
prove : options -> theory -> (string * (term list * indprem list) list) list -> (string * typ) list |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2443 |
-> moded_clause list pred_mode_table -> term pred_mode_table -> thm pred_mode_table, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2444 |
add_code_equations : theory -> (string * typ) list |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2445 |
-> (string * thm list) list -> (string * thm list) list, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2446 |
comp_modifiers : Comp_Mod.comp_modifiers, |
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:
35267
diff
changeset
|
2447 |
use_random : bool, |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2448 |
qname : bstring |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2449 |
} |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2450 |
|
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:
35267
diff
changeset
|
2451 |
fun add_equations_of steps mode_analysis_options options prednames thy = |
32667 | 2452 |
let |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2453 |
fun dest_steps (Steps s) = s |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2454 |
val _ = print_step options |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2455 |
("Starting predicate compiler for predicates " ^ commas prednames ^ "...") |
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2456 |
(*val _ = check_intros_elim_match thy prednames*) |
33114
4785ef554dcc
added further examples; added mode to code_pred command; tuned; some temporary things in Predicate_Compile_ex
bulwahn
parents:
33113
diff
changeset
|
2457 |
(*val _ = map (check_format_of_intro_rule thy) (maps (intros_of thy) prednames)*) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2458 |
val compilation = Comp_Mod.compilation (#comp_modifiers (dest_steps steps)) |
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:
35267
diff
changeset
|
2459 |
val _ = |
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:
35267
diff
changeset
|
2460 |
if show_intermediate_results options 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:
35267
diff
changeset
|
2461 |
tracing (commas (map (Display.string_of_thm_global thy) (maps (intros_of thy) prednames))) |
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:
35267
diff
changeset
|
2462 |
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:
35267
diff
changeset
|
2463 |
val (preds, all_vs, param_vs, all_modes, clauses) = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2464 |
prepare_intrs options compilation thy prednames (maps (intros_of thy) prednames) |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33120
diff
changeset
|
2465 |
val _ = print_step options "Infering modes..." |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2466 |
val ((moded_clauses, errors), thy') = |
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:
35267
diff
changeset
|
2467 |
(*Output.cond_timeit true "Infering modes" |
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:
35267
diff
changeset
|
2468 |
(fn _ =>*) infer_modes mode_analysis_options |
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:
35267
diff
changeset
|
2469 |
options compilation preds all_modes param_vs clauses thy |
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
2470 |
val modes = map (fn (p, mps) => (p, map fst mps)) moded_clauses |
33619
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
bulwahn
parents:
33526
diff
changeset
|
2471 |
val _ = check_expected_modes preds options modes |
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:
35267
diff
changeset
|
2472 |
(*val _ = check_proposed_modes preds options modes (fst extra_modes) errors*) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2473 |
val _ = print_modes options thy' modes |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33120
diff
changeset
|
2474 |
val _ = print_step options "Defining executable functions..." |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2475 |
val thy'' = fold (#define_functions (dest_steps steps) options preds) modes thy' |
32667 | 2476 |
|> Theory.checkpoint |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33120
diff
changeset
|
2477 |
val _ = print_step options "Compiling equations..." |
32667 | 2478 |
val compiled_terms = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2479 |
compile_preds (#comp_modifiers (dest_steps steps)) thy'' all_vs param_vs preds moded_clauses |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2480 |
val _ = print_compiled_terms options thy'' compiled_terms |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33120
diff
changeset
|
2481 |
val _ = print_step options "Proving equations..." |
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:
35267
diff
changeset
|
2482 |
val result_thms = |
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:
35267
diff
changeset
|
2483 |
#prove (dest_steps steps) options thy'' clauses preds moded_clauses compiled_terms |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2484 |
val result_thms' = #add_code_equations (dest_steps steps) thy'' preds |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2485 |
(maps_modes result_thms) |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2486 |
val qname = #qname (dest_steps steps) |
32667 | 2487 |
val attrib = fn thy => Attrib.attribute_i thy (Attrib.internal (K (Thm.declaration_attribute |
2488 |
(fn thm => Context.mapping (Code.add_eqn thm) I)))) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2489 |
val thy''' = fold (fn (name, result_thms) => fn thy => snd (PureThy.add_thmss |
32667 | 2490 |
[((Binding.qualify true (Long_Name.base_name name) (Binding.name qname), result_thms), |
2491 |
[attrib thy ])] thy)) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2492 |
result_thms' thy'' |> Theory.checkpoint |
32667 | 2493 |
in |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2494 |
thy''' |
32667 | 2495 |
end |
2496 |
||
2497 |
fun extend' value_of edges_of key (G, visited) = |
|
2498 |
let |
|
2499 |
val (G', v) = case try (Graph.get_node G) key of |
|
2500 |
SOME v => (G, v) |
|
2501 |
| NONE => (Graph.new_node (key, value_of key) G, value_of key) |
|
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2502 |
val (G'', visited') = fold (extend' value_of edges_of) |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2503 |
(subtract (op =) visited (edges_of (key, v))) |
33326
7d0288d90535
improved handling of alternative rules; added test cases for alternative rules; normalized tracing in the predicate compiler
bulwahn
parents:
33268
diff
changeset
|
2504 |
(G', key :: visited) |
32667 | 2505 |
in |
2506 |
(fold (Graph.add_edge o (pair key)) (edges_of (key, v)) G'', visited') |
|
2507 |
end; |
|
2508 |
||
2509 |
fun extend value_of edges_of key G = fst (extend' value_of edges_of key (G, [])) |
|
2510 |
||
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
2511 |
fun gen_add_equations steps options names thy = |
32667 | 2512 |
let |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2513 |
fun dest_steps (Steps s) = s |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2514 |
val defined = defined_functions (Comp_Mod.compilation (#comp_modifiers (dest_steps steps))) |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2515 |
val thy' = thy |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2516 |
|> PredData.map (fold (extend (fetch_pred_data thy) (depending_preds_of thy)) names) |
32667 | 2517 |
|> Theory.checkpoint; |
2518 |
fun strong_conn_of gr keys = |
|
2519 |
Graph.strong_conn (Graph.subgraph (member (op =) (Graph.all_succs gr keys)) gr) |
|
2520 |
val scc = strong_conn_of (PredData.get thy') names |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2521 |
|
32667 | 2522 |
val thy'' = fold_rev |
2523 |
(fn preds => fn thy => |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2524 |
if not (forall (defined thy) preds) then |
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:
35267
diff
changeset
|
2525 |
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:
35267
diff
changeset
|
2526 |
val mode_analysis_options = {use_random = #use_random (dest_steps steps), |
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:
35267
diff
changeset
|
2527 |
reorder_premises = |
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:
35267
diff
changeset
|
2528 |
not (no_topmost_reordering options andalso not (null (inter (op =) preds names))), |
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:
35267
diff
changeset
|
2529 |
infer_pos_and_neg_modes = #use_random (dest_steps steps)} |
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:
35267
diff
changeset
|
2530 |
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:
35267
diff
changeset
|
2531 |
add_equations_of steps mode_analysis_options options preds thy |
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:
35267
diff
changeset
|
2532 |
end |
33483
a15a2f7f7560
improved handling of already defined functions in the predicate compiler; could cause trouble before when no modes for a predicate were infered
bulwahn
parents:
33482
diff
changeset
|
2533 |
else thy) |
32667 | 2534 |
scc thy' |> Theory.checkpoint |
2535 |
in thy'' end |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2536 |
(* |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2537 |
val depth_limited_comp_modifiers = Comp_Mod.Comp_Modifiers |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2538 |
{ |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2539 |
compilation = Depth_Limited, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2540 |
function_name_of = function_name_of Depth_Limited, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2541 |
set_function_name = set_function_name Depth_Limited, |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2542 |
funT_of = depth_limited_funT_of : (compilation_funs -> mode -> typ -> typ), |
33485
0df4f6e46e5e
made definition of functions generically for the different instances
bulwahn
parents:
33484
diff
changeset
|
2543 |
function_name_prefix = "depth_limited_", |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2544 |
additional_arguments = fn names => |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2545 |
let |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2546 |
val [depth_name, polarity_name] = Name.variant_list names ["depth", "polarity"] |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2547 |
in [Free (polarity_name, @{typ "bool"}), Free (depth_name, @{typ "code_numeral"})] end, |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2548 |
wrap_compilation = |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2549 |
fn compfuns => fn s => fn T => fn mode => fn additional_arguments => fn compilation => |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2550 |
let |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2551 |
val [polarity, depth] = additional_arguments |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2552 |
val (_, Ts2) = chop (length (fst mode)) (binder_types T) |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2553 |
val (_, Us2) = split_smodeT (snd mode) Ts2 |
33148
0808f7d0d0d7
removed tuple functions from the predicate compiler
bulwahn
parents:
33147
diff
changeset
|
2554 |
val T' = mk_predT compfuns (HOLogic.mk_tupleT Us2) |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2555 |
val if_const = Const (@{const_name "If"}, @{typ bool} --> T' --> T' --> T') |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2556 |
val full_mode = null Us2 |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2557 |
in |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2558 |
if_const $ HOLogic.mk_eq (depth, @{term "0 :: code_numeral"}) |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2559 |
$ (if_const $ polarity $ mk_bot compfuns (dest_predT compfuns T') |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2560 |
$ (if full_mode then mk_single compfuns HOLogic.unit else |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2561 |
Const (@{const_name undefined}, T'))) |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2562 |
$ compilation |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2563 |
end, |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2564 |
transform_additional_arguments = |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2565 |
fn prem => fn additional_arguments => |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2566 |
let |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2567 |
val [polarity, depth] = additional_arguments |
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
2568 |
val polarity' = (case prem of Prem _ => I | Negprem _ => HOLogic.mk_not | _ => I) polarity |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2569 |
val depth' = |
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35021
diff
changeset
|
2570 |
Const (@{const_name Groups.minus}, @{typ "code_numeral => code_numeral => code_numeral"}) |
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35021
diff
changeset
|
2571 |
$ depth $ Const (@{const_name Groups.one}, @{typ "Code_Numeral.code_numeral"}) |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2572 |
in [polarity', depth'] end |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2573 |
} |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2574 |
|
33375 | 2575 |
val random_comp_modifiers = Comp_Mod.Comp_Modifiers |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2576 |
{ |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2577 |
compilation = Random, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2578 |
function_name_of = function_name_of Random, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2579 |
set_function_name = set_function_name Random, |
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
2580 |
function_name_prefix = "random_", |
33484
e96a0c52d74b
renamed generator to random_function in the predicate compiler
bulwahn
parents:
33483
diff
changeset
|
2581 |
funT_of = K random_function_funT_of : (compilation_funs -> mode -> typ -> typ), |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2582 |
additional_arguments = fn names => [Free (Name.variant names "size", @{typ code_numeral})], |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2583 |
wrap_compilation = K (K (K (K (K I)))) |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2584 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2585 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2586 |
} |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2587 |
*) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2588 |
(* different instantiantions of the predicate compiler *) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2589 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2590 |
val predicate_comp_modifiers = Comp_Mod.Comp_Modifiers |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2591 |
{ |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2592 |
compilation = Pred, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2593 |
function_name_prefix = "", |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2594 |
compfuns = PredicateCompFuns.compfuns, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2595 |
additional_arguments = K [], |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2596 |
wrap_compilation = K (K (K (K (K I)))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2597 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2598 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2599 |
} |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2600 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2601 |
val add_equations = gen_add_equations |
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:
35267
diff
changeset
|
2602 |
(Steps { |
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:
35267
diff
changeset
|
2603 |
define_functions = |
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:
35267
diff
changeset
|
2604 |
fn options => fn preds => fn (s, modes) => |
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:
35267
diff
changeset
|
2605 |
create_definitions |
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:
35267
diff
changeset
|
2606 |
options preds (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes), |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2607 |
prove = prove, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2608 |
add_code_equations = add_code_equations, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2609 |
comp_modifiers = predicate_comp_modifiers, |
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:
35267
diff
changeset
|
2610 |
use_random = false, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2611 |
qname = "equation"}) |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2612 |
|
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2613 |
val annotated_comp_modifiers = Comp_Mod.Comp_Modifiers |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2614 |
{ |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2615 |
compilation = Annotated, |
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
2616 |
function_name_prefix = "annotated_", |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2617 |
compfuns = PredicateCompFuns.compfuns, |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2618 |
additional_arguments = K [], |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2619 |
wrap_compilation = |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2620 |
fn compfuns => fn s => fn T => fn mode => fn additional_arguments => fn compilation => |
33619
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
bulwahn
parents:
33526
diff
changeset
|
2621 |
mk_tracing ("calling predicate " ^ s ^ |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2622 |
" with mode " ^ string_of_mode mode) compilation, |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2623 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2624 |
} |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2625 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2626 |
val dseq_comp_modifiers = Comp_Mod.Comp_Modifiers |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2627 |
{ |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2628 |
compilation = DSeq, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2629 |
function_name_prefix = "dseq_", |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2630 |
compfuns = DSequence_CompFuns.compfuns, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2631 |
additional_arguments = K [], |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2632 |
wrap_compilation = K (K (K (K (K I)))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2633 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2634 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2635 |
} |
32667 | 2636 |
|
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:
35267
diff
changeset
|
2637 |
val pos_random_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2638 |
{ |
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:
35267
diff
changeset
|
2639 |
compilation = Pos_Random_DSeq, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2640 |
function_name_prefix = "random_dseq_", |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2641 |
compfuns = Random_Sequence_CompFuns.compfuns, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2642 |
additional_arguments = K [], |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2643 |
wrap_compilation = K (K (K (K (K I)))) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2644 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2645 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2646 |
} |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2647 |
|
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:
35267
diff
changeset
|
2648 |
val neg_random_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers |
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:
35267
diff
changeset
|
2649 |
{ |
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:
35267
diff
changeset
|
2650 |
compilation = 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:
35267
diff
changeset
|
2651 |
function_name_prefix = "random_dseq_neg_", |
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:
35267
diff
changeset
|
2652 |
compfuns = Random_Sequence_CompFuns.compfuns, |
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:
35267
diff
changeset
|
2653 |
additional_arguments = K [], |
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:
35267
diff
changeset
|
2654 |
wrap_compilation = K (K (K (K (K I)))) |
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:
35267
diff
changeset
|
2655 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
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:
35267
diff
changeset
|
2656 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
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:
35267
diff
changeset
|
2657 |
} |
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:
35267
diff
changeset
|
2658 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2659 |
(* |
33134
88c9c3460fe7
renamed functions from sizelim to more natural name depth_limited for compilation of depth-limited search in the predicate compiler
bulwahn
parents:
33133
diff
changeset
|
2660 |
val add_depth_limited_equations = gen_add_equations |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2661 |
(Steps {infer_modes = infer_modes, |
33485
0df4f6e46e5e
made definition of functions generically for the different instances
bulwahn
parents:
33484
diff
changeset
|
2662 |
define_functions = define_functions depth_limited_comp_modifiers PredicateCompFuns.compfuns, |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2663 |
compile_preds = compile_preds depth_limited_comp_modifiers PredicateCompFuns.compfuns, |
32667 | 2664 |
prove = prove_by_skip, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2665 |
add_code_equations = K (K I), |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2666 |
defined = defined_functions Depth_Limited, |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2667 |
qname = "depth_limited_equation"}) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2668 |
*) |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2669 |
val add_annotated_equations = gen_add_equations |
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:
35267
diff
changeset
|
2670 |
(Steps { |
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:
35267
diff
changeset
|
2671 |
define_functions = |
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:
35267
diff
changeset
|
2672 |
fn options => fn preds => fn (s, modes) => |
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:
35267
diff
changeset
|
2673 |
define_functions annotated_comp_modifiers PredicateCompFuns.compfuns options preds |
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:
35267
diff
changeset
|
2674 |
(s, map_filter (fn (true, m) => SOME m | _ => NONE) modes), |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2675 |
prove = prove_by_skip, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2676 |
add_code_equations = K (K I), |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2677 |
comp_modifiers = annotated_comp_modifiers, |
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:
35267
diff
changeset
|
2678 |
use_random = false, |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2679 |
qname = "annotated_equation"}) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2680 |
(* |
32667 | 2681 |
val add_quickcheck_equations = gen_add_equations |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2682 |
(Steps {infer_modes = infer_modes_with_generator, |
33485
0df4f6e46e5e
made definition of functions generically for the different instances
bulwahn
parents:
33484
diff
changeset
|
2683 |
define_functions = define_functions random_comp_modifiers RandomPredCompFuns.compfuns, |
33375 | 2684 |
compile_preds = compile_preds random_comp_modifiers RandomPredCompFuns.compfuns, |
32667 | 2685 |
prove = prove_by_skip, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2686 |
add_code_equations = K (K I), |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2687 |
defined = defined_functions Random, |
33375 | 2688 |
qname = "random_equation"}) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2689 |
*) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2690 |
val add_dseq_equations = gen_add_equations |
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:
35267
diff
changeset
|
2691 |
(Steps { |
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:
35267
diff
changeset
|
2692 |
define_functions = |
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:
35267
diff
changeset
|
2693 |
fn options => fn preds => fn (s, modes) => |
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:
35267
diff
changeset
|
2694 |
define_functions dseq_comp_modifiers DSequence_CompFuns.compfuns |
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:
35267
diff
changeset
|
2695 |
options preds (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes), |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2696 |
prove = prove_by_skip, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2697 |
add_code_equations = K (K I), |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2698 |
comp_modifiers = dseq_comp_modifiers, |
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:
35267
diff
changeset
|
2699 |
use_random = false, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2700 |
qname = "dseq_equation"}) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2701 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2702 |
val add_random_dseq_equations = gen_add_equations |
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:
35267
diff
changeset
|
2703 |
(Steps { |
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:
35267
diff
changeset
|
2704 |
define_functions = |
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:
35267
diff
changeset
|
2705 |
fn options => fn preds => fn (s, modes) => |
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:
35267
diff
changeset
|
2706 |
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:
35267
diff
changeset
|
2707 |
val pos_modes = map_filter (fn (true, m) => SOME m | _ => NONE) modes |
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:
35267
diff
changeset
|
2708 |
val neg_modes = map_filter (fn (false, m) => SOME m | _ => NONE) modes |
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:
35267
diff
changeset
|
2709 |
in define_functions pos_random_dseq_comp_modifiers Random_Sequence_CompFuns.compfuns |
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:
35267
diff
changeset
|
2710 |
options preds (s, pos_modes) |
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:
35267
diff
changeset
|
2711 |
#> define_functions neg_random_dseq_comp_modifiers Random_Sequence_CompFuns.compfuns |
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:
35267
diff
changeset
|
2712 |
options preds (s, neg_modes) |
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:
35267
diff
changeset
|
2713 |
end, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2714 |
prove = prove_by_skip, |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2715 |
add_code_equations = K (K I), |
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:
35267
diff
changeset
|
2716 |
comp_modifiers = pos_random_dseq_comp_modifiers, |
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:
35267
diff
changeset
|
2717 |
use_random = true, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2718 |
qname = "random_dseq_equation"}) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2719 |
|
32667 | 2720 |
|
2721 |
(** user interface **) |
|
2722 |
||
2723 |
(* code_pred_intro attribute *) |
|
2724 |
||
2725 |
fun attrib f = Thm.declaration_attribute (fn thm => Context.mapping (f thm) I); |
|
2726 |
||
33628 | 2727 |
val code_pred_intro_attrib = attrib add_intro; |
32667 | 2728 |
|
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
2729 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
2730 |
(*FIXME |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
2731 |
- Naming of auxiliary rules necessary? |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
2732 |
*) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
2733 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
2734 |
val setup = PredData.put (Graph.empty) #> |
33628 | 2735 |
Attrib.setup @{binding code_pred_intro} (Scan.succeed (attrib add_intro)) |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
2736 |
"adding alternative introduction rules for code generation of inductive predicates" |
32667 | 2737 |
|
33522 | 2738 |
(* TODO: make Theory_Data to Generic_Data & remove duplication of local theory and theory *) |
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
2739 |
fun generic_code_pred prep_const options raw_const lthy = |
32667 | 2740 |
let |
2741 |
val thy = ProofContext.theory_of lthy |
|
2742 |
val const = prep_const thy raw_const |
|
33671 | 2743 |
val lthy' = Local_Theory.theory (PredData.map |
32667 | 2744 |
(extend (fetch_pred_data thy) (depending_preds_of thy) const)) lthy |
33671 | 2745 |
|> Local_Theory.checkpoint |
32667 | 2746 |
val thy' = ProofContext.theory_of lthy' |
33326
7d0288d90535
improved handling of alternative rules; added test cases for alternative rules; normalized tracing in the predicate compiler
bulwahn
parents:
33268
diff
changeset
|
2747 |
val preds = Graph.all_succs (PredData.get thy') [const] |> filter_out (has_elim thy') |
32667 | 2748 |
fun mk_cases const = |
2749 |
let |
|
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2750 |
val T = Sign.the_const_type thy const |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2751 |
val pred = Const (const, T) |
32667 | 2752 |
val intros = intros_of thy' const |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2753 |
in mk_casesrule lthy' pred intros end |
32667 | 2754 |
val cases_rules = map mk_cases preds |
2755 |
val cases = |
|
33368 | 2756 |
map (fn case_rule => Rule_Cases.Case {fixes = [], |
32667 | 2757 |
assumes = [("", Logic.strip_imp_prems case_rule)], |
2758 |
binds = [], cases = []}) cases_rules |
|
2759 |
val case_env = map2 (fn p => fn c => (Long_Name.base_name p, SOME c)) preds cases |
|
2760 |
val lthy'' = lthy' |
|
2761 |
|> fold Variable.auto_fixes cases_rules |
|
2762 |
|> ProofContext.add_cases true case_env |
|
2763 |
fun after_qed thms goal_ctxt = |
|
2764 |
let |
|
2765 |
val global_thms = ProofContext.export goal_ctxt |
|
2766 |
(ProofContext.init (ProofContext.theory_of goal_ctxt)) (map the_single thms) |
|
2767 |
in |
|
33671 | 2768 |
goal_ctxt |> Local_Theory.theory (fold set_elim global_thms #> |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2769 |
((case compilation options of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2770 |
Pred => add_equations |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2771 |
| DSeq => add_dseq_equations |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2772 |
| Random_DSeq => add_random_dseq_equations |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2773 |
| compilation => error ("Compilation not supported") |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2774 |
(*| Random => (fn opt => fn cs => add_equations opt cs #> add_quickcheck_equations opt cs) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2775 |
| Depth_Limited => add_depth_limited_equations |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2776 |
| Annotated => add_annotated_equations*) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2777 |
) options [const])) |
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
2778 |
end |
32667 | 2779 |
in |
2780 |
Proof.theorem_i NONE after_qed (map (single o (rpair [])) cases_rules) lthy'' |
|
2781 |
end; |
|
2782 |
||
2783 |
val code_pred = generic_code_pred (K I); |
|
2784 |
val code_pred_cmd = generic_code_pred Code.read_const |
|
2785 |
||
2786 |
(* transformation for code generation *) |
|
2787 |
||
32740 | 2788 |
val eval_ref = Unsynchronized.ref (NONE : (unit -> term Predicate.pred) option); |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2789 |
val random_eval_ref = |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2790 |
Unsynchronized.ref (NONE : (unit -> int * int -> term Predicate.pred * (int * int)) option); |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2791 |
val dseq_eval_ref = Unsynchronized.ref (NONE : (unit -> term DSequence.dseq) option); |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2792 |
val random_dseq_eval_ref = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2793 |
Unsynchronized.ref (NONE : (unit -> int -> int -> int * int -> term DSequence.dseq * (int * int)) option); |
32667 | 2794 |
|
2795 |
(*FIXME turn this into an LCF-guarded preprocessor for comprehensions*) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2796 |
fun analyze_compr thy compfuns param_user_modes (compilation, arguments) t_compr = |
32667 | 2797 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2798 |
val all_modes_of = all_modes_of compilation |
32667 | 2799 |
val split = case t_compr of (Const (@{const_name Collect}, _) $ t) => t |
2800 |
| _ => error ("Not a set comprehension: " ^ Syntax.string_of_term_global thy t_compr); |
|
2801 |
val (body, Ts, fp) = HOLogic.strip_psplits split; |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2802 |
val output_names = Name.variant_list (Term.add_free_names body []) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2803 |
(map (fn i => "x" ^ string_of_int i) (1 upto length Ts)) |
34963 | 2804 |
val output_frees = map2 (curry Free) output_names (rev Ts) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2805 |
val body = subst_bounds (output_frees, body) |
34963 | 2806 |
val T_compr = HOLogic.mk_ptupleT fp Ts |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2807 |
val output_tuple = HOLogic.mk_ptuple fp T_compr (rev output_frees) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2808 |
val (pred as Const (name, T), all_args) = strip_comb body |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2809 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2810 |
if defined_functions compilation thy name then |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
2811 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2812 |
fun extract_mode (Const ("Pair", _) $ t1 $ t2) = Pair (extract_mode t1, extract_mode t2) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2813 |
| extract_mode (Free (x, _)) = if member (op =) output_names x then Output else Input |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2814 |
| extract_mode _ = Input |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2815 |
val user_mode = fold_rev (curry Fun) (map extract_mode all_args) Bool |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2816 |
fun valid modes1 modes2 = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2817 |
case int_ord (length modes1, length modes2) of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2818 |
GREATER => error "Not enough mode annotations" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2819 |
| LESS => error "Too many mode annotations" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2820 |
| EQUAL => forall (fn (m, NONE) => true | (m, SOME m2) => eq_mode (m, m2)) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2821 |
(modes1 ~~ modes2) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2822 |
fun mode_instance_of (m1, m2) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2823 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2824 |
fun instance_of (Fun _, Input) = true |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2825 |
| instance_of (Input, Input) = true |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2826 |
| instance_of (Output, Output) = true |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2827 |
| instance_of (Pair (m1, m2), Pair (m1', m2')) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2828 |
instance_of (m1, m1') andalso instance_of (m2, m2') |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2829 |
| instance_of (Pair (m1, m2), Input) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2830 |
instance_of (m1, Input) andalso instance_of (m2, Input) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2831 |
| instance_of (Pair (m1, m2), Output) = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2832 |
instance_of (m1, Output) andalso instance_of (m2, Output) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2833 |
| instance_of _ = false |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2834 |
in forall instance_of (strip_fun_mode m1 ~~ strip_fun_mode m2) end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2835 |
val derivs = all_derivations_of thy (all_modes_of thy) [] body |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2836 |
|> filter (fn (d, missing_vars) => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2837 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2838 |
val (p_mode :: modes) = collect_context_modes d |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2839 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2840 |
null missing_vars andalso |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2841 |
mode_instance_of (p_mode, user_mode) andalso |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2842 |
the_default true (Option.map (valid modes) param_user_modes) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2843 |
end) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2844 |
|> map fst |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2845 |
val deriv = case derivs of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2846 |
[] => error ("No mode possible for comprehension " |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2847 |
^ Syntax.string_of_term_global thy t_compr) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2848 |
| [d] => d |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2849 |
| d :: _ :: _ => (warning ("Multiple modes possible for comprehension " |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2850 |
^ Syntax.string_of_term_global thy t_compr); d); |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2851 |
val (_, outargs) = split_mode (head_mode_of deriv) all_args |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2852 |
val additional_arguments = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2853 |
case compilation of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2854 |
Pred => [] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2855 |
| Random => [@{term "5 :: code_numeral"}] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2856 |
| Annotated => [] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2857 |
| Depth_Limited => [@{term "True"}, HOLogic.mk_number @{typ "code_numeral"} (hd arguments)] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2858 |
| DSeq => [] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2859 |
| Random_DSeq => [] |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2860 |
val comp_modifiers = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2861 |
case compilation of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2862 |
Pred => predicate_comp_modifiers |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2863 |
(*| Random => random_comp_modifiers |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2864 |
| Depth_Limited => depth_limited_comp_modifiers |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2865 |
| Annotated => annotated_comp_modifiers*) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2866 |
| DSeq => dseq_comp_modifiers |
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:
35267
diff
changeset
|
2867 |
| Random_DSeq => pos_random_dseq_comp_modifiers |
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:
35267
diff
changeset
|
2868 |
val t_pred = compile_expr comp_modifiers compfuns thy true (body, deriv) additional_arguments; |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2869 |
val T_pred = dest_predT compfuns (fastype_of t_pred) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2870 |
val arrange = split_lambda (HOLogic.mk_tuple outargs) output_tuple |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2871 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2872 |
if null outargs then t_pred else mk_map compfuns T_pred T_compr arrange t_pred |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2873 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2874 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2875 |
error "Evaluation with values is not possible because compilation with code_pred was not invoked" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2876 |
end |
32667 | 2877 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2878 |
fun eval thy param_user_modes (options as (compilation, arguments)) k t_compr = |
32667 | 2879 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2880 |
val compfuns = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2881 |
case compilation of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2882 |
Random => RandomPredCompFuns.compfuns |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2883 |
| DSeq => DSequence_CompFuns.compfuns |
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:
35267
diff
changeset
|
2884 |
| Pos_Random_DSeq => Random_Sequence_CompFuns.compfuns |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2885 |
| _ => PredicateCompFuns.compfuns |
33479
428ddcc16e7b
added optional mode annotations for parameters in the values command
bulwahn
parents:
33478
diff
changeset
|
2886 |
val t = analyze_compr thy compfuns param_user_modes options t_compr; |
33137
0d16c07f8d24
added option to generate random values to values command in the predicate compiler
bulwahn
parents:
33135
diff
changeset
|
2887 |
val T = dest_predT compfuns (fastype_of t); |
0d16c07f8d24
added option to generate random values to values command in the predicate compiler
bulwahn
parents:
33135
diff
changeset
|
2888 |
val t' = mk_map compfuns T HOLogic.termT (HOLogic.term_of_const T) t; |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2889 |
val ts = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2890 |
case compilation of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2891 |
Random => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2892 |
fst (Predicate.yieldn k |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2893 |
(Code_Eval.eval NONE ("Predicate_Compile_Core.random_eval_ref", random_eval_ref) |
33137
0d16c07f8d24
added option to generate random values to values command in the predicate compiler
bulwahn
parents:
33135
diff
changeset
|
2894 |
(fn proc => fn g => fn s => g s |>> Predicate.map proc) thy t' [] |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2895 |
|> Random_Engine.run)) |
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:
35267
diff
changeset
|
2896 |
| Pos_Random_DSeq => |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2897 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2898 |
val [nrandom, size, depth] = arguments |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2899 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2900 |
fst (DSequence.yieldn k |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2901 |
(Code_Eval.eval NONE ("Predicate_Compile_Core.random_dseq_eval_ref", random_dseq_eval_ref) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2902 |
(fn proc => fn g => fn nrandom => fn size => fn s => g nrandom size s |>> DSequence.map proc) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2903 |
thy t' [] nrandom size |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2904 |
|> Random_Engine.run) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2905 |
depth true) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2906 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2907 |
| DSeq => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2908 |
fst (DSequence.yieldn k |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2909 |
(Code_Eval.eval NONE ("Predicate_Compile_Core.dseq_eval_ref", dseq_eval_ref) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2910 |
DSequence.map thy t' []) (the_single arguments) true) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2911 |
| _ => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2912 |
fst (Predicate.yieldn k |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2913 |
(Code_Eval.eval NONE ("Predicate_Compile_Core.eval_ref", eval_ref) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2914 |
Predicate.map thy t' [])) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2915 |
in (T, ts) end; |
32667 | 2916 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2917 |
fun values ctxt param_user_modes (raw_expected, comp_options) k t_compr = |
32667 | 2918 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2919 |
val thy = ProofContext.theory_of ctxt |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2920 |
val (T, ts) = eval thy param_user_modes comp_options k t_compr |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2921 |
val setT = HOLogic.mk_setT T |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2922 |
val elems = HOLogic.mk_set T ts |
33476 | 2923 |
val cont = Free ("...", setT) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2924 |
(* check expected values *) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2925 |
val () = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2926 |
case raw_expected of |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2927 |
NONE => () |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2928 |
| SOME s => |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2929 |
if eq_set (op =) (HOLogic.dest_set (Syntax.read_term ctxt s), ts) then () |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2930 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2931 |
error ("expected and computed values do not match:\n" ^ |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2932 |
"expected values: " ^ Syntax.string_of_term ctxt (Syntax.read_term ctxt s) ^ "\n" ^ |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2933 |
"computed values: " ^ Syntax.string_of_term ctxt elems ^ "\n") |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2934 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2935 |
if k = ~1 orelse length ts < k then elems |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2936 |
else Const (@{const_name Set.union}, setT --> setT --> setT) $ elems $ cont |
32667 | 2937 |
end; |
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
2938 |
|
33479
428ddcc16e7b
added optional mode annotations for parameters in the values command
bulwahn
parents:
33478
diff
changeset
|
2939 |
fun values_cmd print_modes param_user_modes options k raw_t state = |
32667 | 2940 |
let |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2941 |
val ctxt = Toplevel.context_of state |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2942 |
val t = Syntax.read_term ctxt raw_t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2943 |
val t' = values ctxt param_user_modes options k t |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2944 |
val ty' = Term.type_of t' |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2945 |
val ctxt' = Variable.auto_fixes t' ctxt |
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33476
diff
changeset
|
2946 |
val p = PrintMode.with_modes print_modes (fn () => |
32667 | 2947 |
Pretty.block [Pretty.quote (Syntax.pretty_term ctxt' t'), Pretty.fbrk, |
2948 |
Pretty.str "::", Pretty.brk 1, Pretty.quote (Syntax.pretty_typ ctxt' ty')]) (); |
|
2949 |
in Pretty.writeln p end; |
|
2950 |
||
2951 |
end; |