author | krauss |
Tue, 28 Sep 2010 12:34:41 +0200 | |
changeset 39756 | 6c8e83d94536 |
parent 39685 | d8071cddb877 |
child 39768 | 1c46d4f8afd2 |
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 |
|
36048 | 9 |
type mode = Predicate_Compile_Aux.mode |
10 |
type options = Predicate_Compile_Aux.options |
|
11 |
type compilation = Predicate_Compile_Aux.compilation |
|
12 |
type compilation_funs = Predicate_Compile_Aux.compilation_funs |
|
13 |
||
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33476
diff
changeset
|
14 |
val setup : theory -> theory |
36048 | 15 |
val code_pred : options -> string -> Proof.context -> Proof.state |
16 |
val code_pred_cmd : options -> string -> Proof.context -> Proof.state |
|
17 |
val values_cmd : string list -> mode option list option |
|
18 |
-> ((string option * bool) * (compilation * int list)) -> int -> string -> Toplevel.state -> 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
|
19 |
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
|
20 |
val register_intros : string * thm list -> theory -> theory |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
21 |
val is_registered : Proof.context -> string -> bool |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
22 |
val function_name_of : compilation -> Proof.context -> string -> mode -> string |
36048 | 23 |
val predfun_intro_of: Proof.context -> string -> mode -> thm |
24 |
val predfun_elim_of: Proof.context -> string -> mode -> thm |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
25 |
val all_preds_of : Proof.context -> string list |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
26 |
val modes_of: compilation -> Proof.context -> string -> mode list |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
27 |
val all_modes_of : compilation -> Proof.context -> (string * mode list) list |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
28 |
val all_random_modes_of : Proof.context -> (string * mode list) list |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
29 |
val intros_of : Proof.context -> string -> thm list |
38072
7b8c295af291
exporting retrieval function for graph of introduction rules in the predicate compiler core
bulwahn
parents:
37678
diff
changeset
|
30 |
val intros_graph_of : Proof.context -> thm list Graph.T |
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
31 |
val add_intro : string option * thm -> theory -> theory |
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33476
diff
changeset
|
32 |
val set_elim : thm -> theory -> theory |
36048 | 33 |
val register_alternative_function : string -> mode -> string -> theory -> theory |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
34 |
val alternative_compilation_of_global : theory -> string -> mode -> |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
35 |
(compilation_funs -> typ -> term) option |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
36 |
val alternative_compilation_of : Proof.context -> string -> mode -> |
36038
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
37 |
(compilation_funs -> typ -> term) option |
36048 | 38 |
val functional_compilation : string -> mode -> compilation_funs -> typ -> term |
39 |
val force_modes_and_functions : string -> (mode * (string * bool)) list -> theory -> theory |
|
36038
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
40 |
val force_modes_and_compilations : string -> |
36048 | 41 |
(mode * ((compilation_funs -> typ -> term) * bool)) 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
|
42 |
val preprocess_intro : theory -> thm -> thm |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
43 |
val print_stored_rules : Proof.context -> unit |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
44 |
val print_all_modes : compilation -> Proof.context -> 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
|
45 |
val mk_casesrule : Proof.context -> term -> thm list -> term |
39388
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
46 |
|
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
47 |
val put_pred_result : (unit -> term Predicate.pred) -> Proof.context -> Proof.context |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
48 |
val put_pred_random_result : (unit -> int * int -> term Predicate.pred * (int * int)) -> |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
49 |
Proof.context -> Proof.context |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
50 |
val put_dseq_result : (unit -> term DSequence.dseq) -> Proof.context -> Proof.context |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
51 |
val put_dseq_random_result : (unit -> int -> int -> int * int -> term DSequence.dseq * (int * int)) -> |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
52 |
Proof.context -> Proof.context |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
53 |
val put_lseq_random_result : |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
54 |
(unit -> int -> int -> int * int -> int -> term Lazy_Sequence.lazy_sequence) -> |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
55 |
Proof.context -> Proof.context |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
56 |
val put_lseq_random_stats_result : |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
57 |
(unit -> int -> int -> int * int -> int -> (term * int) Lazy_Sequence.lazy_sequence) -> |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
58 |
Proof.context -> Proof.context |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
59 |
|
33628 | 60 |
val code_pred_intro_attrib : attribute |
32667 | 61 |
(* used by Quickcheck_Generator *) |
62 |
(* temporary for testing of the compilation *) |
|
36048 | 63 |
val add_equations : options -> string list -> theory -> theory |
64 |
val add_depth_limited_random_equations : options -> string list -> theory -> theory |
|
65 |
val add_random_dseq_equations : options -> string list -> theory -> theory |
|
66 |
val add_new_random_dseq_equations : options -> string list -> theory -> theory |
|
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
67 |
val mk_tracing : string -> term -> term |
39310
17ef4415b17c
removing obsolete argument in prepare_intrs; passing context instead of theory in prepare_intrs
bulwahn
parents:
39299
diff
changeset
|
68 |
val prepare_intrs : options -> Proof.context -> string list -> thm list -> |
38957
2eb265efa1b0
exporting mode analysis for use in prolog generation
bulwahn
parents:
38864
diff
changeset
|
69 |
((string * typ) list * string list * string list * (string * mode list) list * |
2eb265efa1b0
exporting mode analysis for use in prolog generation
bulwahn
parents:
38864
diff
changeset
|
70 |
(string * (Term.term list * Predicate_Compile_Aux.indprem list) list) list) |
2eb265efa1b0
exporting mode analysis for use in prolog generation
bulwahn
parents:
38864
diff
changeset
|
71 |
type mode_analysis_options = {use_random : bool, reorder_premises : bool, infer_pos_and_neg_modes : bool} |
2eb265efa1b0
exporting mode analysis for use in prolog generation
bulwahn
parents:
38864
diff
changeset
|
72 |
datatype mode_derivation = Mode_App of mode_derivation * mode_derivation | Context of mode |
39310
17ef4415b17c
removing obsolete argument in prepare_intrs; passing context instead of theory in prepare_intrs
bulwahn
parents:
39299
diff
changeset
|
73 |
| Mode_Pair of mode_derivation * mode_derivation | Term of mode |
39461
0ed0f015d140
adding mode inference to prolog compilation; separate between (ad-hoc) code modifications and system_configuration; adapting quickcheck
bulwahn
parents:
39403
diff
changeset
|
74 |
val head_mode_of : mode_derivation -> mode |
38957
2eb265efa1b0
exporting mode analysis for use in prolog generation
bulwahn
parents:
38864
diff
changeset
|
75 |
type moded_clause = term list * (Predicate_Compile_Aux.indprem * mode_derivation) list |
2eb265efa1b0
exporting mode analysis for use in prolog generation
bulwahn
parents:
38864
diff
changeset
|
76 |
type 'a pred_mode_table = (string * ((bool * mode) * 'a) list) list |
2eb265efa1b0
exporting mode analysis for use in prolog generation
bulwahn
parents:
38864
diff
changeset
|
77 |
|
2eb265efa1b0
exporting mode analysis for use in prolog generation
bulwahn
parents:
38864
diff
changeset
|
78 |
val infer_modes : |
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
79 |
mode_analysis_options -> options -> |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
80 |
(string -> Predicate_Compile_Aux.mode list) * (string -> Predicate_Compile_Aux.mode list) |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
81 |
* (string -> Predicate_Compile_Aux.mode -> bool) -> Proof.context -> (string * typ) list -> |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
82 |
(string * mode list) list -> |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
83 |
string list -> (string * (Term.term list * Predicate_Compile_Aux.indprem list) list) list -> |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
84 |
((moded_clause list pred_mode_table * (string * mode list) list) * string list) |
32667 | 85 |
end; |
86 |
||
87 |
structure Predicate_Compile_Core : PREDICATE_COMPILE_CORE = |
|
88 |
struct |
|
89 |
||
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
90 |
open Predicate_Compile_Aux; |
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
91 |
|
32667 | 92 |
(** auxiliary **) |
93 |
||
94 |
(* debug stuff *) |
|
95 |
||
35886 | 96 |
fun print_tac options s = |
33127 | 97 |
if show_proof_trace options then Tactical.print_tac s else Seq.single; |
98 |
||
35885
7b39120a1494
some improvements thanks to Makarius source code review
bulwahn
parents:
35884
diff
changeset
|
99 |
fun assert b = if not b then raise Fail "Assertion failed" else warning "Assertion holds" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
100 |
|
33108
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
101 |
datatype assertion = Max_number_of_subgoals of int |
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
102 |
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
|
103 |
if (nprems_of st <= i) then Seq.single st |
35885
7b39120a1494
some improvements thanks to Makarius source code review
bulwahn
parents:
35884
diff
changeset
|
104 |
else raise Fail ("assert_tac: Numbers of subgoals mismatch at goal state :" |
33108
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
105 |
^ "\n" ^ Pretty.string_of (Pretty.chunks |
39125
f45d332a90e3
pretty_goals: turned some global references and function arguments into configuration options (goals_limit = 10, goals_total = true, show_main_goal = false) depending on the context;
wenzelm
parents:
39021
diff
changeset
|
106 |
(Goal_Display.pretty_goals_without_context st))); |
33108
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33106
diff
changeset
|
107 |
|
32667 | 108 |
(** fundamentals **) |
109 |
||
110 |
(* syntactic operations *) |
|
111 |
||
112 |
fun mk_eq (x, xs) = |
|
113 |
let fun mk_eqs _ [] = [] |
|
114 |
| mk_eqs a (b::cs) = |
|
115 |
HOLogic.mk_eq (Free (a, fastype_of b), b) :: mk_eqs a cs |
|
116 |
in mk_eqs x xs end; |
|
117 |
||
118 |
fun mk_scomp (t, u) = |
|
119 |
let |
|
120 |
val T = fastype_of t |
|
121 |
val U = fastype_of u |
|
122 |
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
|
123 |
val D = body_type U |
32667 | 124 |
in |
125 |
Const (@{const_name "scomp"}, T --> U --> A --> D) $ t $ u |
|
126 |
end; |
|
127 |
||
128 |
fun dest_funT (Type ("fun",[S, T])) = (S, T) |
|
129 |
| dest_funT T = raise TYPE ("dest_funT", [T], []) |
|
130 |
||
131 |
fun mk_fun_comp (t, u) = |
|
132 |
let |
|
133 |
val (_, B) = dest_funT (fastype_of t) |
|
134 |
val (C, A) = dest_funT (fastype_of u) |
|
135 |
in |
|
136 |
Const(@{const_name "Fun.comp"}, (A --> B) --> (C --> A) --> C --> B) $ t $ u |
|
137 |
end; |
|
138 |
||
139 |
fun dest_randomT (Type ("fun", [@{typ Random.seed}, |
|
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset
|
140 |
Type (@{type_name Product_Type.prod}, [Type (@{type_name Product_Type.prod}, [T, @{typ "unit => Code_Evaluation.term"}]) ,@{typ Random.seed}])])) = T |
32667 | 141 |
| dest_randomT T = raise TYPE ("dest_randomT", [T], []) |
142 |
||
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
143 |
fun mk_tracing s t = |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
144 |
Const(@{const_name Code_Evaluation.tracing}, |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
145 |
@{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
|
146 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
147 |
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
|
148 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
149 |
(* 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
|
150 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
151 |
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
|
152 |
| Mode_Pair of mode_derivation * mode_derivation | Term of mode |
32667 | 153 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
154 |
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
|
155 |
"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
|
156 |
| 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
|
157 |
"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
|
158 |
| 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
|
159 |
| string_of_derivation (Context m) = "Context (" ^ string_of_mode m ^ ")" |
32667 | 160 |
|
34948
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 strip_mode_derivation deriv = |
32667 | 162 |
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
|
163 |
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
|
164 |
| 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
|
165 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
166 |
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
|
167 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
168 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
169 |
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
|
170 |
| 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
|
171 |
| 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
|
172 |
(case mode_of d1 of Fun (m, m') => |
39193
0e505a4e500c
stating errors in error messages more verbose in predicate compiler
bulwahn
parents:
39191
diff
changeset
|
173 |
(if eq_mode (m, mode_of d2) then m' else raise Fail "mode_of: derivation has mismatching modes") |
0e505a4e500c
stating errors in error messages more verbose in predicate compiler
bulwahn
parents:
39191
diff
changeset
|
174 |
| _ => raise Fail "mode_of: derivation has a non-functional 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
|
175 |
| 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
|
176 |
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
|
177 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
178 |
fun head_mode_of deriv = mode_of (fst (strip_mode_derivation deriv)) |
32667 | 179 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
180 |
fun param_derivations_of deriv = |
32667 | 181 |
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
| 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
|
186 |
| 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
|
187 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
188 |
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
|
189 |
end |
32667 | 190 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
191 |
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
|
192 |
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
|
193 |
| 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
|
194 |
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
|
195 |
| 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
|
196 |
| collect_context_modes (Term _) = [] |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
197 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
198 |
(* representation of inferred clauses with modes *) |
32667 | 199 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
200 |
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
|
201 |
|
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
|
202 |
type 'a pred_mode_table = (string * ((bool * mode) * 'a) list) list |
32667 | 203 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
204 |
(* 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
|
205 |
|
32667 | 206 |
datatype predfun_data = PredfunData of { |
207 |
definition : thm, |
|
208 |
intro : thm, |
|
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
209 |
elim : thm, |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
210 |
neg_intro : thm option |
32667 | 211 |
}; |
212 |
||
213 |
fun rep_predfun_data (PredfunData data) = data; |
|
214 |
||
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
215 |
fun mk_predfun_data (definition, ((intro, elim), neg_intro)) = |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
216 |
PredfunData {definition = definition, intro = intro, elim = elim, neg_intro = neg_intro} |
32667 | 217 |
|
218 |
datatype pred_data = PredData of { |
|
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
219 |
intros : (string option * thm) list, |
32667 | 220 |
elim : thm option, |
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
221 |
preprocessed : 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
|
222 |
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
|
223 |
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
|
224 |
needs_random : mode list |
32667 | 225 |
}; |
226 |
||
227 |
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
|
228 |
|
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
229 |
fun mk_pred_data (((intros, elim), preprocessed), (function_names, (predfun_data, needs_random))) = |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
230 |
PredData {intros = intros, elim = elim, preprocessed = preprocessed, |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
231 |
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
|
232 |
|
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
233 |
fun map_pred_data f (PredData {intros, elim, preprocessed, function_names, predfun_data, needs_random}) = |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
234 |
mk_pred_data (f (((intros, elim), preprocessed), (function_names, (predfun_data, needs_random)))) |
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
235 |
|
32667 | 236 |
fun eq_option eq (NONE, NONE) = true |
237 |
| eq_option eq (SOME x, SOME y) = eq (x, y) |
|
238 |
| eq_option eq _ = false |
|
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
239 |
|
32667 | 240 |
fun eq_pred_data (PredData d1, PredData d2) = |
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
241 |
eq_list (eq_pair (op =) Thm.eq_thm) (#intros d1, #intros d2) andalso |
35885
7b39120a1494
some improvements thanks to Makarius source code review
bulwahn
parents:
35884
diff
changeset
|
242 |
eq_option Thm.eq_thm (#elim d1, #elim d2) |
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
243 |
|
33522 | 244 |
structure PredData = Theory_Data |
32667 | 245 |
( |
246 |
type T = pred_data Graph.T; |
|
247 |
val empty = Graph.empty; |
|
248 |
val extend = I; |
|
33522 | 249 |
val merge = Graph.merge eq_pred_data; |
32667 | 250 |
); |
251 |
||
252 |
(* queries *) |
|
253 |
||
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
254 |
fun lookup_pred_data ctxt name = |
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
255 |
Option.map rep_pred_data (try (Graph.get_node (PredData.get (ProofContext.theory_of ctxt))) name) |
32667 | 256 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
257 |
fun the_pred_data ctxt name = case lookup_pred_data ctxt name |
32667 | 258 |
of NONE => error ("No such predicate " ^ quote name) |
259 |
| SOME data => data; |
|
260 |
||
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
261 |
val is_registered = is_some oo lookup_pred_data |
32667 | 262 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
263 |
val all_preds_of = Graph.keys o PredData.get o ProofContext.theory_of |
32667 | 264 |
|
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
265 |
val intros_of = map snd o #intros oo the_pred_data |
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
266 |
|
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
267 |
val names_of = map fst o #intros oo the_pred_data |
32667 | 268 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
269 |
fun the_elim_of ctxt name = case #elim (the_pred_data ctxt name) |
32667 | 270 |
of NONE => error ("No elimination rule for predicate " ^ quote name) |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
271 |
| SOME thm => thm |
32667 | 272 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
273 |
val has_elim = is_some o #elim oo the_pred_data |
32667 | 274 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
275 |
fun function_names_of compilation ctxt name = |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
276 |
case AList.lookup (op =) (#function_names (the_pred_data ctxt name)) compilation 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
|
277 |
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
|
278 |
^ "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
|
279 |
| SOME fun_names => fun_names |
32667 | 280 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
281 |
fun function_name_of compilation ctxt name 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
|
282 |
case AList.lookup eq_mode |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
283 |
(function_names_of compilation ctxt 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
|
284 |
NONE => error ("No " ^ string_of_compilation compilation |
36019
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
285 |
^ " function defined for mode " ^ string_of_mode mode ^ " of predicate " ^ quote 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
|
286 |
| 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
|
287 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
288 |
fun modes_of compilation ctxt name = map fst (function_names_of compilation ctxt name) |
32667 | 289 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
290 |
fun all_modes_of compilation ctxt = |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
291 |
map_filter (fn name => Option.map (pair name) (try (modes_of compilation ctxt) name)) |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
292 |
(all_preds_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
|
293 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
294 |
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
|
295 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
296 |
fun defined_functions compilation ctxt name = case lookup_pred_data ctxt name of |
37001
bcffdb899167
improved behaviour of defined_functions in the predicate compiler
bulwahn
parents:
36692
diff
changeset
|
297 |
NONE => false |
bcffdb899167
improved behaviour of defined_functions in the predicate compiler
bulwahn
parents:
36692
diff
changeset
|
298 |
| SOME data => AList.defined (op =) (#function_names data) compilation |
32667 | 299 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
300 |
fun needs_random ctxt s m = |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
301 |
member (op =) (#needs_random (the_pred_data ctxt s)) m |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
302 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
303 |
fun lookup_predfun_data ctxt 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
|
304 |
Option.map rep_predfun_data |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
305 |
(AList.lookup (op =) (#predfun_data (the_pred_data ctxt name)) mode) |
32667 | 306 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
307 |
fun the_predfun_data ctxt name mode = |
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
308 |
case lookup_predfun_data ctxt 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
|
309 |
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
|
310 |
" 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
|
311 |
| SOME data => data; |
32667 | 312 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
313 |
val predfun_definition_of = #definition ooo the_predfun_data |
32667 | 314 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
315 |
val predfun_intro_of = #intro ooo the_predfun_data |
32667 | 316 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
317 |
val predfun_elim_of = #elim ooo the_predfun_data |
32667 | 318 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
319 |
val predfun_neg_intro_of = #neg_intro ooo the_predfun_data |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
320 |
|
38072
7b8c295af291
exporting retrieval function for graph of introduction rules in the predicate compiler core
bulwahn
parents:
37678
diff
changeset
|
321 |
val intros_graph_of = |
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
322 |
Graph.map (K (map snd o #intros o rep_pred_data)) o PredData.get o ProofContext.theory_of |
38072
7b8c295af291
exporting retrieval function for graph of introduction rules in the predicate compiler core
bulwahn
parents:
37678
diff
changeset
|
323 |
|
32667 | 324 |
(* diagnostic display functions *) |
325 |
||
37004 | 326 |
fun print_modes options modes = |
33251 | 327 |
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
|
328 |
tracing ("Inferred modes:\n" ^ |
33251 | 329 |
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
|
330 |
(fn (p, m) => string_of_mode m ^ (if p then "pos" else "neg")) ms)) modes)) |
33251 | 331 |
else () |
32667 | 332 |
|
37004 | 333 |
fun print_pred_mode_table string_of_entry pred_mode_table = |
32667 | 334 |
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
|
335 |
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
|
336 |
^ string_of_entry pred mode entry |
32667 | 337 |
fun print_pred (pred, modes) = |
338 |
"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
|
339 |
val _ = tracing (cat_lines (map print_pred pred_mode_table)) |
32667 | 340 |
in () end; |
341 |
||
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
342 |
fun string_of_prem ctxt (Prem t) = |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
343 |
(Syntax.string_of_term ctxt t) ^ "(premise)" |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
344 |
| string_of_prem ctxt (Negprem t) = |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
345 |
(Syntax.string_of_term ctxt (HOLogic.mk_not t)) ^ "(negative premise)" |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
346 |
| string_of_prem ctxt (Sidecond t) = |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
347 |
(Syntax.string_of_term ctxt t) ^ "(sidecondition)" |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
348 |
| string_of_prem ctxt _ = raise Fail "string_of_prem: unexpected input" |
33130
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
349 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
350 |
fun string_of_clause ctxt pred (ts, prems) = |
33130
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
351 |
(space_implode " --> " |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
352 |
(map (string_of_prem ctxt) prems)) ^ " --> " ^ pred ^ " " |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
353 |
^ (space_implode " " (map (Syntax.string_of_term ctxt) ts)) |
33130
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
354 |
|
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
355 |
fun print_compiled_terms options ctxt = |
33139
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33138
diff
changeset
|
356 |
if show_compilation options then |
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
357 |
print_pred_mode_table (fn _ => fn _ => Syntax.string_of_term ctxt) |
33139
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33138
diff
changeset
|
358 |
else K () |
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33138
diff
changeset
|
359 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
360 |
fun print_stored_rules ctxt = |
32667 | 361 |
let |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
362 |
val preds = Graph.keys (PredData.get (ProofContext.theory_of ctxt)) |
32667 | 363 |
fun print pred () = let |
364 |
val _ = writeln ("predicate: " ^ pred) |
|
365 |
val _ = writeln ("introrules: ") |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
366 |
val _ = fold (fn thm => fn u => writeln (Display.string_of_thm ctxt thm)) |
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
367 |
(rev (intros_of ctxt pred)) () |
32667 | 368 |
in |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
369 |
if (has_elim ctxt pred) then |
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
370 |
writeln ("elimrule: " ^ Display.string_of_thm ctxt (the_elim_of ctxt pred)) |
32667 | 371 |
else |
372 |
writeln ("no elimrule defined") |
|
373 |
end |
|
374 |
in |
|
375 |
fold print preds () |
|
376 |
end; |
|
377 |
||
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
378 |
fun print_all_modes compilation ctxt = |
32667 | 379 |
let |
380 |
val _ = writeln ("Inferred modes:") |
|
381 |
fun print (pred, modes) u = |
|
382 |
let |
|
383 |
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
|
384 |
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
|
385 |
in u end |
32667 | 386 |
in |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
387 |
fold print (all_modes_of compilation ctxt) () |
32667 | 388 |
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
|
389 |
|
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
390 |
(* validity checks *) |
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
391 |
|
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
392 |
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
|
393 |
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
|
394 |
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
|
395 |
SOME modes => |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
396 |
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
|
397 |
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
|
398 |
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
|
399 |
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
|
400 |
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
|
401 |
^ " 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
|
402 |
^ " 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
|
403 |
else () |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
404 |
end |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
405 |
| NONE => ()) |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
406 |
| NONE => () |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
407 |
|
39201
234e6ef4ff67
using the proposed modes for starting the fixpoint iteration in the mode analysis
bulwahn
parents:
39194
diff
changeset
|
408 |
fun check_proposed_modes preds options modes errors = |
39382
c797f3ab2ae1
proposed modes for code_pred now supports modes for mutual predicates
bulwahn
parents:
39310
diff
changeset
|
409 |
map (fn (s, _) => case proposed_modes options s of |
c797f3ab2ae1
proposed modes for code_pred now supports modes for mutual predicates
bulwahn
parents:
39310
diff
changeset
|
410 |
SOME ms => (case AList.lookup (op =) modes s of |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
411 |
SOME inferred_ms => |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
412 |
let |
39201
234e6ef4ff67
using the proposed modes for starting the fixpoint iteration in the mode analysis
bulwahn
parents:
39194
diff
changeset
|
413 |
val preds_without_modes = map fst (filter (null o snd) 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
|
414 |
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
|
415 |
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
|
416 |
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
|
417 |
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
|
418 |
^ " 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
|
419 |
^ " expected modes for " ^ s ^ ": " ^ commas (map string_of_mode ms) ^ "\n" |
39383
ddfafa97da2f
adding option show_invalid_clauses for a more detailed message when modes are not inferred
bulwahn
parents:
39382
diff
changeset
|
420 |
^ (if show_invalid_clauses options then |
ddfafa97da2f
adding option show_invalid_clauses for a more detailed message when modes are not inferred
bulwahn
parents:
39382
diff
changeset
|
421 |
("For the following clauses, the following modes could not be inferred: " ^ "\n" |
ddfafa97da2f
adding option show_invalid_clauses for a more detailed message when modes are not inferred
bulwahn
parents:
39382
diff
changeset
|
422 |
^ cat_lines errors) else "") ^ |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
423 |
(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
|
424 |
"\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
|
425 |
else "")) |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
426 |
else () |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
427 |
end |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
428 |
| NONE => ()) |
39382
c797f3ab2ae1
proposed modes for code_pred now supports modes for mutual predicates
bulwahn
parents:
39310
diff
changeset
|
429 |
| NONE => ()) preds |
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
430 |
|
39651
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
431 |
fun check_matches_type ctxt predname T ms = |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
432 |
let |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
433 |
fun check (m as Fun (m1, m2)) (Type("fun", [T1,T2])) = check m1 T1 andalso check m2 T2 |
39670 | 434 |
| check m (T as Type("fun", _)) = |
435 |
if body_type T = @{typ bool} then false else (m = Input orelse m = Output) |
|
39651
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
436 |
| check (Pair (m1, m2)) (Type (@{type_name Product_Type.prod}, [T1, T2])) = |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
437 |
check m1 T1 andalso check m2 T2 |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
438 |
| check Input T = true |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
439 |
| check Output T = true |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
440 |
| check Bool @{typ bool} = true |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
441 |
| check _ _ = false |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
442 |
val _ = map |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
443 |
(fn mode => |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
444 |
if (forall (uncurry check) (strip_fun_mode mode ~~ binder_types T)) then () |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
445 |
else error (string_of_mode mode ^ " is not a valid mode for " ^ Syntax.string_of_typ ctxt T |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
446 |
^ " at predicate " ^ predname)) ms |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
447 |
in |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
448 |
ms |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
449 |
end |
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
450 |
|
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
451 |
|
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
452 |
(* 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
|
453 |
|
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
454 |
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
|
455 |
(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
|
456 |
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
|
457 |
fun varify (t, (i, ts)) = |
35845
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents:
35411
diff
changeset
|
458 |
let val t' = map_types (Logic.incr_tvar (i + 1)) (#2 (Type.varify_global [] t)) |
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
|
459 |
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
|
460 |
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
|
461 |
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
|
462 |
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
|
463 |
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
|
464 |
fun unify (cname, cT) = |
33317 | 465 |
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
|
466 |
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
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
(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
|
472 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
473 |
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
|
474 |
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
|
475 |
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
|
476 |
val T = fastype_of outp_pred |
39299
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
bulwahn
parents:
39273
diff
changeset
|
477 |
val paramTs = ho_argsT_of_typ (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
|
478 |
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
|
479 |
(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
|
480 |
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
|
481 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
482 |
(((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
|
483 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
484 |
| 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
|
485 |
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
|
486 |
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
|
487 |
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
|
488 |
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
|
489 |
val T = fastype_of pred |
39299
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
bulwahn
parents:
39273
diff
changeset
|
490 |
val ho_args = ho_args_of_typ T args |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
491 |
fun subst_of (pred', pred) = |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
492 |
let |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
493 |
val subst = Sign.typ_match thy (fastype_of pred', fastype_of pred) Vartab.empty |
39685
d8071cddb877
actually handle Type.TYPE_MATCH, not arbitrary exceptions;
wenzelm
parents:
39670
diff
changeset
|
494 |
handle Type.TYPE_MATCH => error ("Type mismatch of predicate " ^ fst (dest_Const pred) |
39653
51e23b48a202
handling TYPE_MATCH error by raising user error message if user gives introduction rules with mismatching types
bulwahn
parents:
39652
diff
changeset
|
495 |
^ " (trying to match " ^ Syntax.string_of_typ ctxt (fastype_of pred') |
51e23b48a202
handling TYPE_MATCH error by raising user error message if user gives introduction rules with mismatching types
bulwahn
parents:
39652
diff
changeset
|
496 |
^ " and " ^ Syntax.string_of_typ ctxt (fastype_of pred) ^ ")" |
51e23b48a202
handling TYPE_MATCH error by raising user error message if user gives introduction rules with mismatching types
bulwahn
parents:
39652
diff
changeset
|
497 |
^ " in " ^ Display.string_of_thm ctxt th) |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
498 |
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
|
499 |
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
|
500 |
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
|
501 |
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
|
502 |
val _ = if not (fst (dest_Const pred) = fst (dest_Const pred')) then |
35885
7b39120a1494
some improvements thanks to Makarius source code review
bulwahn
parents:
35884
diff
changeset
|
503 |
raise Fail "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
|
504 |
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
|
505 |
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
|
506 |
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
|
507 |
val (_, args') = (strip_comb o HOLogic.dest_Trueprop o Logic.strip_imp_concl o prop_of) th |
39299
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
bulwahn
parents:
39273
diff
changeset
|
508 |
val ho_args' = map dest_Var (ho_args_of_typ T 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
|
509 |
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
|
510 |
val outp_pred = |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
511 |
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
|
512 |
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
|
513 |
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
|
514 |
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
|
515 |
(((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
|
516 |
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
|
517 |
|
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33128
diff
changeset
|
518 |
(* 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
|
519 |
|
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset
|
520 |
fun mk_args2 (Type (@{type_name Product_Type.prod}, [T1, T2])) st = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
521 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
522 |
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
|
523 |
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
|
524 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
525 |
(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
|
526 |
end |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
527 |
(*| mk_args2 (T as Type ("fun", _)) (params, 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
|
528 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
529 |
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
|
530 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
531 |
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
|
532 |
(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
|
533 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
534 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
535 |
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
|
536 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
537 |
(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
|
538 |
end |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
539 |
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
|
540 |
| 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
|
541 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
542 |
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
|
543 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
544 |
(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
|
545 |
end |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
546 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
547 |
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
|
548 |
let |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
549 |
(* TODO: can be simplified if parameters are not treated specially ? *) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
550 |
val (((pred, params), intros_th), ctxt1) = import_intros pred introrules ctxt |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
551 |
(* TODO: distinct required ? -- test case with more than one parameter! *) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
552 |
val params = distinct (op aconv) params |
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
|
553 |
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
|
554 |
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
|
555 |
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
|
556 |
val argsT = binder_types (fastype_of pred) |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
557 |
(* TODO: can be simplified if parameters are not treated specially ? <-- see uncommented code! *) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
558 |
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
|
559 |
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
|
560 |
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
|
561 |
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
|
562 |
val prems = Logic.strip_imp_prems intro |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
563 |
val eqprems = |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
564 |
map2 (HOLogic.mk_Trueprop oo (curry HOLogic.mk_eq)) argvs args |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
565 |
val frees = map Free (fold Term.add_frees (args @ prems) []) |
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
|
566 |
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
|
567 |
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
|
568 |
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
|
569 |
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
|
570 |
|
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
571 |
fun dest_conjunct_prem th = |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
572 |
case HOLogic.dest_Trueprop (prop_of th) of |
38795
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents:
38558
diff
changeset
|
573 |
(Const (@{const_name HOL.conj}, _) $ t $ t') => |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
574 |
dest_conjunct_prem (th RS @{thm conjunct1}) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
575 |
@ dest_conjunct_prem (th RS @{thm conjunct2}) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
576 |
| _ => [th] |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
577 |
|
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
578 |
fun prove_casesrule ctxt (pred, (pre_cases_rule, nparams)) cases_rule = |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
579 |
let |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
580 |
val thy = ProofContext.theory_of ctxt |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
581 |
val nargs = length (binder_types (fastype_of pred)) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
582 |
fun PEEK f dependent_tactic st = dependent_tactic (f st) st |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
583 |
fun meta_eq_of th = th RS @{thm eq_reflection} |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
584 |
val tuple_rew_rules = map meta_eq_of [@{thm fst_conv}, @{thm snd_conv}, @{thm Pair_eq}] |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
585 |
fun instantiate i n {context = ctxt, params = p, prems = prems, |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
586 |
asms = a, concl = cl, schematics = s} = |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
587 |
let |
36510 | 588 |
fun term_pair_of (ix, (ty,t)) = (Var (ix,ty), t) |
589 |
fun inst_of_matches tts = fold (Pattern.match thy) tts (Vartab.empty, Vartab.empty) |
|
590 |
|> snd |> Vartab.dest |> map (pairself (cterm_of thy) o term_pair_of) |
|
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
591 |
val (cases, (eqs, prems)) = apsnd (chop (nargs - nparams)) (chop n prems) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
592 |
val case_th = MetaSimplifier.simplify true |
36509
9cff57fc7113
improving proof procedure for transforming cases rule in the predicate compiler to handle free variables of function type
bulwahn
parents:
36323
diff
changeset
|
593 |
(@{thm Predicate.eq_is_eq} :: map meta_eq_of eqs) (nth cases (i - 1)) |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
594 |
val prems' = maps (dest_conjunct_prem o MetaSimplifier.simplify true tuple_rew_rules) prems |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
595 |
val pats = map (swap o HOLogic.dest_eq o HOLogic.dest_Trueprop) (take nargs (prems_of case_th)) |
36510 | 596 |
val case_th' = Thm.instantiate ([], inst_of_matches pats) case_th |
597 |
OF (replicate nargs @{thm refl}) |
|
598 |
val thesis = |
|
599 |
Thm.instantiate ([], inst_of_matches (prems_of case_th' ~~ map prop_of prems')) case_th' |
|
600 |
OF prems' |
|
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
601 |
in |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
602 |
(rtac thesis 1) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
603 |
end |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
604 |
val tac = |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
605 |
etac pre_cases_rule 1 |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
606 |
THEN |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
607 |
(PEEK nprems_of |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
608 |
(fn n => |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
609 |
ALLGOALS (fn i => |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
610 |
MetaSimplifier.rewrite_goal_tac [@{thm split_paired_all}] i |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
611 |
THEN (SUBPROOF (instantiate i n) ctxt i)))) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
612 |
in |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
613 |
Goal.prove ctxt (Term.add_free_names cases_rule []) [] cases_rule (fn _ => tac) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
614 |
end |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
615 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
616 |
(** preprocessing rules **) |
32667 | 617 |
|
618 |
fun Trueprop_conv cv ct = |
|
619 |
case Thm.term_of ct of |
|
38558 | 620 |
Const (@{const_name Trueprop}, _) $ _ => Conv.arg_conv cv ct |
35885
7b39120a1494
some improvements thanks to Makarius source code review
bulwahn
parents:
35884
diff
changeset
|
621 |
| _ => raise Fail "Trueprop_conv" |
32667 | 622 |
|
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
623 |
fun preprocess_equality thy rule = |
32667 | 624 |
Conv.fconv_rule |
625 |
(imp_prems_conv |
|
626 |
(Trueprop_conv (Conv.try_conv (Conv.rewr_conv (Thm.symmetric @{thm Predicate.eq_is_eq}))))) |
|
627 |
(Thm.transfer thy rule) |
|
628 |
||
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
629 |
fun preprocess_intro thy = expand_tuples thy #> preprocess_equality thy |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
630 |
|
39658
b3644e40f661
removing unneccessary expansion procedure for elimination rules; removing obsolete elim preprocessing; tuned
bulwahn
parents:
39657
diff
changeset
|
631 |
(* fetching introduction rules or registering introduction rules *) |
32667 | 632 |
|
35887
f704ba9875f6
making flat triples to nested tuple to remove general triple functions
bulwahn
parents:
35886
diff
changeset
|
633 |
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
|
634 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
635 |
fun fetch_pred_data ctxt name = |
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
636 |
case try (Inductive.the_inductive ctxt) name of |
32667 | 637 |
SOME (info as (_, result)) => |
638 |
let |
|
639 |
fun is_intro_of intro = |
|
640 |
let |
|
641 |
val (const, _) = strip_comb (HOLogic.dest_Trueprop (concl_of intro)) |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
642 |
in (fst (dest_Const const) = name) end; |
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
643 |
val thy = ProofContext.theory_of ctxt |
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
644 |
val intros = map (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
|
645 |
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
|
646 |
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
|
647 |
val pred = nth (#preds result) index |
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
648 |
val elim_t = mk_casesrule ctxt pred intros |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
649 |
val nparams = length (Inductive.params_of (#raw_induct result)) |
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
650 |
val elim = prove_casesrule ctxt (pred, (pre_elim, nparams)) elim_t |
32667 | 651 |
in |
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
652 |
mk_pred_data (((map (pair NONE) intros, SOME elim), true), 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
|
653 |
end |
32667 | 654 |
| NONE => error ("No such predicate: " ^ quote name) |
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
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 add_predfun_data name mode data = |
32667 | 657 |
let |
35887
f704ba9875f6
making flat triples to nested tuple to remove general triple functions
bulwahn
parents:
35886
diff
changeset
|
658 |
val add = (apsnd o apsnd o apfst) (cons (mode, mk_predfun_data data)) |
32667 | 659 |
in PredData.map (Graph.map_node name (map_pred_data add)) end |
660 |
||
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
661 |
fun is_inductive_predicate ctxt name = |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
662 |
is_some (try (Inductive.the_inductive ctxt) name) |
32667 | 663 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
664 |
fun depending_preds_of ctxt (key, value) = |
32667 | 665 |
let |
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
666 |
val intros = map (Thm.prop_of o snd) ((#intros o rep_pred_data) value) |
32667 | 667 |
in |
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
668 |
fold Term.add_const_names intros [] |
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
669 |
|> (fn cs => |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
670 |
if member (op =) cs @{const_name "HOL.eq"} then |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
671 |
insert (op =) @{const_name Predicate.eq} cs |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
672 |
else cs) |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
673 |
|> filter (fn c => (not (c = key)) andalso |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
674 |
(is_inductive_predicate ctxt c orelse is_registered ctxt c)) |
32667 | 675 |
end; |
676 |
||
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
677 |
fun add_intro (opt_case_name, thm) thy = |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
678 |
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
|
679 |
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
|
680 |
fun cons_intro gr = |
32667 | 681 |
case try (Graph.get_node gr) name of |
682 |
SOME pred_data => Graph.map_node name (map_pred_data |
|
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
683 |
(apfst (apfst (apfst (fn intros => intros @ [(opt_case_name, thm)]))))) gr |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
684 |
| NONE => Graph.new_node (name, mk_pred_data ((([(opt_case_name, thm)], NONE), false), no_compilation)) gr |
32667 | 685 |
in PredData.map cons_intro thy end |
686 |
||
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
687 |
fun set_elim thm = |
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
688 |
let |
32667 | 689 |
val (name, _) = dest_Const (fst |
690 |
(strip_comb (HOLogic.dest_Trueprop (hd (prems_of thm))))) |
|
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
691 |
in PredData.map (Graph.map_node name (map_pred_data (apfst (apfst (apsnd (K (SOME thm))))))) end |
32667 | 692 |
|
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
693 |
fun register_predicate (constname, intros, elim) thy = |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
694 |
let |
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
695 |
val named_intros = map (pair NONE) intros |
32667 | 696 |
in |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
697 |
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
|
698 |
PredData.map |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
699 |
(Graph.new_node (constname, |
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
700 |
mk_pred_data (((named_intros, SOME elim), false), no_compilation))) thy |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
701 |
else thy |
32667 | 702 |
end |
703 |
||
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
704 |
fun register_intros (constname, pre_intros) thy = |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
705 |
let |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
706 |
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
|
707 |
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
|
708 |
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
|
709 |
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
|
710 |
"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
|
711 |
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
|
712 |
else () |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
713 |
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
|
714 |
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
|
715 |
(Drule.export_without_context o Skip_Proof.make_thm thy) |
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36533
diff
changeset
|
716 |
(mk_casesrule (ProofContext.init_global thy) pred 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
|
717 |
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
|
718 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
719 |
fun defined_function_of compilation pred = |
32667 | 720 |
let |
35887
f704ba9875f6
making flat triples to nested tuple to remove general triple functions
bulwahn
parents:
35886
diff
changeset
|
721 |
val set = (apsnd o apfst) (cons (compilation, [])) |
32667 | 722 |
in |
723 |
PredData.map (Graph.map_node pred (map_pred_data set)) |
|
724 |
end |
|
725 |
||
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
726 |
fun set_function_name compilation pred mode name = |
32667 | 727 |
let |
35887
f704ba9875f6
making flat triples to nested tuple to remove general triple functions
bulwahn
parents:
35886
diff
changeset
|
728 |
val set = (apsnd o apfst) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
729 |
(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
|
730 |
in |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
731 |
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
|
732 |
end |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
733 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
734 |
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
|
735 |
let |
35887
f704ba9875f6
making flat triples to nested tuple to remove general triple functions
bulwahn
parents:
35886
diff
changeset
|
736 |
val set = (apsnd o apsnd o apsnd) (K modes) |
32667 | 737 |
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
|
738 |
PredData.map (Graph.map_node name (map_pred_data set)) |
32667 | 739 |
end |
740 |
||
36038
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
741 |
(* registration of alternative function names *) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
742 |
|
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
743 |
structure Alt_Compilations_Data = Theory_Data |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
744 |
( |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
745 |
type T = (mode * (compilation_funs -> typ -> term)) list Symtab.table; |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
746 |
val empty = Symtab.empty; |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
747 |
val extend = I; |
38759
37a9092de102
simplification/standardization of some theory data;
wenzelm
parents:
38757
diff
changeset
|
748 |
fun merge data : T = Symtab.merge (K true) data; |
36038
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
749 |
); |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
750 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
751 |
fun alternative_compilation_of_global thy pred_name mode = |
36038
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
752 |
AList.lookup eq_mode (Symtab.lookup_list (Alt_Compilations_Data.get thy) pred_name) mode |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
753 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
754 |
fun alternative_compilation_of ctxt pred_name mode = |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
755 |
AList.lookup eq_mode |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
756 |
(Symtab.lookup_list (Alt_Compilations_Data.get (ProofContext.theory_of ctxt)) pred_name) mode |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
757 |
|
36038
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
758 |
fun force_modes_and_compilations pred_name compilations = |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
759 |
let |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
760 |
(* thm refl is a dummy thm *) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
761 |
val modes = map fst compilations |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
762 |
val (needs_random, non_random_modes) = pairself (map fst) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
763 |
(List.partition (fn (m, (fun_name, random)) => random) compilations) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
764 |
val non_random_dummys = map (rpair "dummy") non_random_modes |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
765 |
val all_dummys = map (rpair "dummy") modes |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
766 |
val dummy_function_names = map (rpair all_dummys) Predicate_Compile_Aux.random_compilations |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
767 |
@ map (rpair non_random_dummys) Predicate_Compile_Aux.non_random_compilations |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
768 |
val alt_compilations = map (apsnd fst) compilations |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
769 |
in |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
770 |
PredData.map (Graph.new_node |
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
771 |
(pred_name, mk_pred_data ((([], SOME @{thm refl}), true), (dummy_function_names, ([], needs_random))))) |
36038
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
772 |
#> Alt_Compilations_Data.map (Symtab.insert (K false) (pred_name, alt_compilations)) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
773 |
end |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
774 |
|
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
775 |
fun functional_compilation fun_name mode compfuns T = |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
776 |
let |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
777 |
val (inpTs, outpTs) = split_map_modeT (fn _ => fn T => (SOME T, NONE)) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
778 |
mode (binder_types T) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
779 |
val bs = map (pair "x") inpTs |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
780 |
val bounds = map Bound (rev (0 upto (length bs) - 1)) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
781 |
val f = Const (fun_name, inpTs ---> HOLogic.mk_tupleT outpTs) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
782 |
in list_abs (bs, mk_single compfuns (list_comb (f, bounds))) end |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
783 |
|
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
784 |
fun register_alternative_function pred_name mode fun_name = |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
785 |
Alt_Compilations_Data.map (Symtab.insert_list (eq_pair eq_mode (K false)) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
786 |
(pred_name, (mode, functional_compilation fun_name mode))) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
787 |
|
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
788 |
fun force_modes_and_functions pred_name fun_names = |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
789 |
force_modes_and_compilations pred_name |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
790 |
(map (fn (mode, (fun_name, random)) => (mode, (functional_compilation fun_name mode, random))) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
791 |
fun_names) |
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
792 |
|
36019
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
793 |
(* compilation modifiers *) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
794 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
795 |
structure Comp_Mod = |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
796 |
struct |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
797 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
798 |
datatype comp_modifiers = Comp_Modifiers of |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
799 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
800 |
compilation : compilation, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
801 |
function_name_prefix : string, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
802 |
compfuns : compilation_funs, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
803 |
mk_random : typ -> term list -> term, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
804 |
modify_funT : typ -> typ, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
805 |
additional_arguments : string list -> term list, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
806 |
wrap_compilation : compilation_funs -> string -> typ -> mode -> term list -> term -> term, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
807 |
transform_additional_arguments : indprem -> term list -> term list |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
808 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
809 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
810 |
fun dest_comp_modifiers (Comp_Modifiers c) = c |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
811 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
812 |
val compilation = #compilation o dest_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
813 |
val function_name_prefix = #function_name_prefix o dest_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
814 |
val compfuns = #compfuns o dest_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
815 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
816 |
val mk_random = #mk_random o dest_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
817 |
val funT_of' = funT_of o compfuns |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
818 |
val modify_funT = #modify_funT o dest_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
819 |
fun funT_of comp mode = modify_funT comp o funT_of' comp mode |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
820 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
821 |
val additional_arguments = #additional_arguments o dest_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
822 |
val wrap_compilation = #wrap_compilation o dest_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
823 |
val transform_additional_arguments = #transform_additional_arguments o dest_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
824 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
825 |
end; |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
826 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
827 |
val depth_limited_comp_modifiers = Comp_Mod.Comp_Modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
828 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
829 |
compilation = Depth_Limited, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
830 |
function_name_prefix = "depth_limited_", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
831 |
compfuns = PredicateCompFuns.compfuns, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
832 |
mk_random = (fn _ => error "no random generation"), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
833 |
additional_arguments = fn names => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
834 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
835 |
val depth_name = Name.variant names "depth" |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
836 |
in [Free (depth_name, @{typ code_numeral})] end, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
837 |
modify_funT = (fn T => let val (Ts, U) = strip_type T |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
838 |
val Ts' = [@{typ code_numeral}] in (Ts @ Ts') ---> U end), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
839 |
wrap_compilation = |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
840 |
fn compfuns => fn s => fn T => fn mode => fn additional_arguments => fn compilation => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
841 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
842 |
val [depth] = additional_arguments |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
843 |
val (_, Ts) = split_modeT' mode (binder_types T) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
844 |
val T' = mk_predT compfuns (HOLogic.mk_tupleT Ts) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
845 |
val if_const = Const (@{const_name "If"}, @{typ bool} --> T' --> T' --> T') |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
846 |
in |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
847 |
if_const $ HOLogic.mk_eq (depth, @{term "0 :: code_numeral"}) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
848 |
$ mk_bot compfuns (dest_predT compfuns T') |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
849 |
$ compilation |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
850 |
end, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
851 |
transform_additional_arguments = |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
852 |
fn prem => fn additional_arguments => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
853 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
854 |
val [depth] = additional_arguments |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
855 |
val depth' = |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
856 |
Const (@{const_name Groups.minus}, @{typ "code_numeral => code_numeral => code_numeral"}) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
857 |
$ depth $ Const (@{const_name Groups.one}, @{typ "Code_Numeral.code_numeral"}) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
858 |
in [depth'] end |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
859 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
860 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
861 |
val random_comp_modifiers = Comp_Mod.Comp_Modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
862 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
863 |
compilation = Random, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
864 |
function_name_prefix = "random_", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
865 |
compfuns = PredicateCompFuns.compfuns, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
866 |
mk_random = (fn T => fn additional_arguments => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
867 |
list_comb (Const(@{const_name Quickcheck.iter}, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
868 |
[@{typ code_numeral}, @{typ code_numeral}, @{typ Random.seed}] ---> |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
869 |
PredicateCompFuns.mk_predT T), additional_arguments)), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
870 |
modify_funT = (fn T => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
871 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
872 |
val (Ts, U) = strip_type T |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
873 |
val Ts' = [@{typ code_numeral}, @{typ code_numeral}, @{typ "code_numeral * code_numeral"}] |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
874 |
in (Ts @ Ts') ---> U end), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
875 |
additional_arguments = (fn names => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
876 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
877 |
val [nrandom, size, seed] = Name.variant_list names ["nrandom", "size", "seed"] |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
878 |
in |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
879 |
[Free (nrandom, @{typ code_numeral}), Free (size, @{typ code_numeral}), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
880 |
Free (seed, @{typ "code_numeral * code_numeral"})] |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
881 |
end), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
882 |
wrap_compilation = K (K (K (K (K I)))) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
883 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
884 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
885 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
886 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
887 |
val depth_limited_random_comp_modifiers = Comp_Mod.Comp_Modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
888 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
889 |
compilation = Depth_Limited_Random, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
890 |
function_name_prefix = "depth_limited_random_", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
891 |
compfuns = PredicateCompFuns.compfuns, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
892 |
mk_random = (fn T => fn additional_arguments => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
893 |
list_comb (Const(@{const_name Quickcheck.iter}, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
894 |
[@{typ code_numeral}, @{typ code_numeral}, @{typ Random.seed}] ---> |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
895 |
PredicateCompFuns.mk_predT T), tl additional_arguments)), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
896 |
modify_funT = (fn T => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
897 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
898 |
val (Ts, U) = strip_type T |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
899 |
val Ts' = [@{typ code_numeral}, @{typ code_numeral}, @{typ code_numeral}, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
900 |
@{typ "code_numeral * code_numeral"}] |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
901 |
in (Ts @ Ts') ---> U end), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
902 |
additional_arguments = (fn names => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
903 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
904 |
val [depth, nrandom, size, seed] = Name.variant_list names ["depth", "nrandom", "size", "seed"] |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
905 |
in |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
906 |
[Free (depth, @{typ code_numeral}), Free (nrandom, @{typ code_numeral}), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
907 |
Free (size, @{typ code_numeral}), Free (seed, @{typ "code_numeral * code_numeral"})] |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
908 |
end), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
909 |
wrap_compilation = |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
910 |
fn compfuns => fn s => fn T => fn mode => fn additional_arguments => fn compilation => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
911 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
912 |
val depth = hd (additional_arguments) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
913 |
val (_, Ts) = split_map_modeT (fn m => fn T => (SOME (funT_of compfuns m T), NONE)) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
914 |
mode (binder_types T) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
915 |
val T' = mk_predT compfuns (HOLogic.mk_tupleT Ts) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
916 |
val if_const = Const (@{const_name "If"}, @{typ bool} --> T' --> T' --> T') |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
917 |
in |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
918 |
if_const $ HOLogic.mk_eq (depth, @{term "0 :: code_numeral"}) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
919 |
$ mk_bot compfuns (dest_predT compfuns T') |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
920 |
$ compilation |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
921 |
end, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
922 |
transform_additional_arguments = |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
923 |
fn prem => fn additional_arguments => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
924 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
925 |
val [depth, nrandom, size, seed] = additional_arguments |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
926 |
val depth' = |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
927 |
Const (@{const_name Groups.minus}, @{typ "code_numeral => code_numeral => code_numeral"}) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
928 |
$ depth $ Const (@{const_name Groups.one}, @{typ "Code_Numeral.code_numeral"}) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
929 |
in [depth', nrandom, size, seed] end |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
930 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
931 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
932 |
val predicate_comp_modifiers = Comp_Mod.Comp_Modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
933 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
934 |
compilation = Pred, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
935 |
function_name_prefix = "", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
936 |
compfuns = PredicateCompFuns.compfuns, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
937 |
mk_random = (fn _ => error "no random generation"), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
938 |
modify_funT = I, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
939 |
additional_arguments = K [], |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
940 |
wrap_compilation = K (K (K (K (K I)))) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
941 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
942 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
943 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
944 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
945 |
val annotated_comp_modifiers = Comp_Mod.Comp_Modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
946 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
947 |
compilation = Annotated, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
948 |
function_name_prefix = "annotated_", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
949 |
compfuns = PredicateCompFuns.compfuns, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
950 |
mk_random = (fn _ => error "no random generation"), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
951 |
modify_funT = I, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
952 |
additional_arguments = K [], |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
953 |
wrap_compilation = |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
954 |
fn compfuns => fn s => fn T => fn mode => fn additional_arguments => fn compilation => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
955 |
mk_tracing ("calling predicate " ^ s ^ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
956 |
" with mode " ^ string_of_mode mode) compilation, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
957 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
958 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
959 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
960 |
val dseq_comp_modifiers = Comp_Mod.Comp_Modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
961 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
962 |
compilation = DSeq, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
963 |
function_name_prefix = "dseq_", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
964 |
compfuns = DSequence_CompFuns.compfuns, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
965 |
mk_random = (fn _ => error "no random generation"), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
966 |
modify_funT = I, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
967 |
additional_arguments = K [], |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
968 |
wrap_compilation = K (K (K (K (K I)))) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
969 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
970 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
971 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
972 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
973 |
val pos_random_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
974 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
975 |
compilation = Pos_Random_DSeq, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
976 |
function_name_prefix = "random_dseq_", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
977 |
compfuns = Random_Sequence_CompFuns.compfuns, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
978 |
mk_random = (fn T => fn additional_arguments => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
979 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
980 |
val random = Const ("Quickcheck.random_class.random", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
981 |
@{typ code_numeral} --> @{typ Random.seed} --> |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
982 |
HOLogic.mk_prodT (HOLogic.mk_prodT (T, @{typ "unit => term"}), @{typ Random.seed})) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
983 |
in |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
984 |
Const ("Random_Sequence.Random", (@{typ code_numeral} --> @{typ Random.seed} --> |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
985 |
HOLogic.mk_prodT (HOLogic.mk_prodT (T, @{typ "unit => term"}), @{typ Random.seed})) --> |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
986 |
Random_Sequence_CompFuns.mk_random_dseqT T) $ random |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
987 |
end), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
988 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
989 |
modify_funT = I, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
990 |
additional_arguments = K [], |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
991 |
wrap_compilation = K (K (K (K (K I)))) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
992 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
993 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
994 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
995 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
996 |
val neg_random_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
997 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
998 |
compilation = Neg_Random_DSeq, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
999 |
function_name_prefix = "random_dseq_neg_", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1000 |
compfuns = Random_Sequence_CompFuns.compfuns, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1001 |
mk_random = (fn _ => error "no random generation"), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1002 |
modify_funT = I, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1003 |
additional_arguments = K [], |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1004 |
wrap_compilation = K (K (K (K (K I)))) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1005 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1006 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1007 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1008 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1009 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1010 |
val new_pos_random_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1011 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1012 |
compilation = New_Pos_Random_DSeq, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1013 |
function_name_prefix = "new_random_dseq_", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1014 |
compfuns = New_Pos_Random_Sequence_CompFuns.compfuns, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1015 |
mk_random = (fn T => fn additional_arguments => |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1016 |
let |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1017 |
val random = Const ("Quickcheck.random_class.random", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1018 |
@{typ code_numeral} --> @{typ Random.seed} --> |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1019 |
HOLogic.mk_prodT (HOLogic.mk_prodT (T, @{typ "unit => term"}), @{typ Random.seed})) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1020 |
in |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1021 |
Const ("New_Random_Sequence.Random", (@{typ code_numeral} --> @{typ Random.seed} --> |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1022 |
HOLogic.mk_prodT (HOLogic.mk_prodT (T, @{typ "unit => term"}), @{typ Random.seed})) --> |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1023 |
New_Pos_Random_Sequence_CompFuns.mk_pos_random_dseqT T) $ random |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1024 |
end), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1025 |
modify_funT = I, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1026 |
additional_arguments = K [], |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1027 |
wrap_compilation = K (K (K (K (K I)))) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1028 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1029 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1030 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1031 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1032 |
val new_neg_random_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1033 |
{ |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1034 |
compilation = New_Neg_Random_DSeq, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1035 |
function_name_prefix = "new_random_dseq_neg_", |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1036 |
compfuns = New_Neg_Random_Sequence_CompFuns.compfuns, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1037 |
mk_random = (fn _ => error "no random generation"), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1038 |
modify_funT = I, |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1039 |
additional_arguments = K [], |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1040 |
wrap_compilation = K (K (K (K (K I)))) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1041 |
: (compilation_funs -> string -> typ -> mode -> term list -> term -> term), |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1042 |
transform_additional_arguments = K I : (indprem -> term list -> term list) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1043 |
} |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1044 |
|
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1045 |
fun negative_comp_modifiers_of comp_modifiers = |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1046 |
(case Comp_Mod.compilation comp_modifiers of |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1047 |
Pos_Random_DSeq => neg_random_dseq_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1048 |
| Neg_Random_DSeq => pos_random_dseq_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1049 |
| New_Pos_Random_DSeq => new_neg_random_dseq_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1050 |
| New_Neg_Random_DSeq => new_pos_random_dseq_comp_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1051 |
| c => comp_modifiers) |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1052 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1053 |
(** mode analysis **) |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
1054 |
|
35411 | 1055 |
type mode_analysis_options = {use_random : bool, reorder_premises : bool, infer_pos_and_neg_modes : bool} |
35324
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
bulwahn
parents:
35267
diff
changeset
|
1056 |
|
32667 | 1057 |
fun is_constrt thy = |
1058 |
let |
|
1059 |
val cnstrs = flat (maps |
|
1060 |
(map (fn (_, (Tname, _, cs)) => map (apsnd (rpair Tname o length)) cs) o #descr o snd) |
|
1061 |
(Symtab.dest (Datatype.get_all thy))); |
|
1062 |
fun check t = (case strip_comb t of |
|
1063 |
(Free _, []) => true |
|
1064 |
| (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
|
1065 |
(SOME (i, Tname), Type (Tname', _)) => |
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
1066 |
length ts = i andalso Tname = Tname' andalso forall check ts |
32667 | 1067 |
| _ => false) |
1068 |
| _ => false) |
|
1069 |
in check end; |
|
1070 |
||
1071 |
(*** check if a type is an equality type (i.e. doesn't contain fun) |
|
1072 |
FIXME this is only an approximation ***) |
|
1073 |
fun is_eqT (Type (s, Ts)) = s <> "fun" andalso forall is_eqT Ts |
|
1074 |
| is_eqT _ = true; |
|
1075 |
||
1076 |
fun term_vs tm = fold_aterms (fn Free (x, T) => cons x | _ => I) tm []; |
|
1077 |
val terms_vs = distinct (op =) o maps term_vs; |
|
1078 |
||
1079 |
(** collect all Frees in a term (with duplicates!) **) |
|
1080 |
fun term_vTs tm = |
|
1081 |
fold_aterms (fn Free xT => cons xT | _ => I) tm []; |
|
1082 |
||
33138
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
1083 |
fun subsets i j = |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
1084 |
if i <= j then |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
1085 |
let |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
1086 |
fun merge xs [] = xs |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
1087 |
| merge [] ys = ys |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
1088 |
| 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
|
1089 |
else y::merge (x::xs) ys; |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
1090 |
val is = subsets (i+1) j |
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
1091 |
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
|
1092 |
else [[]]; |
32667 | 1093 |
|
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
|
1094 |
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
|
1095 |
if show_mode_inference options then |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
1096 |
let |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1097 |
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
|
1098 |
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
|
1099 |
in () end |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
1100 |
else () |
7eac458c2b22
added option show_mode_inference; added splitting of conjunctions in expand_tuples
bulwahn
parents:
33129
diff
changeset
|
1101 |
|
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
|
1102 |
fun error_of p (pol, m) is = |
35885
7b39120a1494
some improvements thanks to Makarius source code review
bulwahn
parents:
35884
diff
changeset
|
1103 |
" Clauses " ^ commas (map (fn i => string_of_int (i + 1)) is) ^ " of " ^ |
7b39120a1494
some improvements thanks to Makarius source code review
bulwahn
parents:
35884
diff
changeset
|
1104 |
p ^ " violates mode " ^ string_of_mode m |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1105 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1106 |
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
|
1107 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1108 |
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
|
1109 |
| 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
|
1110 |
| 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
|
1111 |
| 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
|
1112 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1113 |
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
|
1114 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1115 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1116 |
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
|
1117 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1118 |
val (Ts, U) = strip_type T |
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset
|
1119 |
fun input_of (Type (@{type_name Product_Type.prod}, [T1, T2])) = Pair (input_of T1, input_of T2) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1120 |
| 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
|
1121 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1122 |
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
|
1123 |
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
|
1124 |
else |
35885
7b39120a1494
some improvements thanks to Makarius source code review
bulwahn
parents:
35884
diff
changeset
|
1125 |
raise Fail "all_input_of: not a predicate" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1126 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1127 |
|
39191
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1128 |
fun find_least ord xs = |
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1129 |
let |
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1130 |
fun find' x y = (case y of NONE => SOME x | SOME y' => if ord (x, y') = LESS then SOME x else y) |
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1131 |
in |
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1132 |
fold find' xs NONE |
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1133 |
end |
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1134 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1135 |
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
|
1136 |
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
|
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 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
|
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 (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
|
1141 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1142 |
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
|
1143 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1144 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1145 |
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
|
1146 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1147 |
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
|
1148 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1149 |
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
|
1150 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1151 |
|
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1152 |
fun is_invertible_function ctxt (Const (f, _)) = is_constr ctxt f |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1153 |
| is_invertible_function ctxt _ = 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
|
1154 |
|
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1155 |
fun non_invertible_subterms ctxt (t as Free _) = [] |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1156 |
| non_invertible_subterms ctxt t = |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1157 |
let |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1158 |
val (f, args) = strip_comb t |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1159 |
in |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1160 |
if is_invertible_function ctxt f then |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1161 |
maps (non_invertible_subterms ctxt) 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
|
1162 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1163 |
[t] |
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1164 |
end |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1165 |
|
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1166 |
fun collect_non_invertible_subterms ctxt (f as Free _) (names, eqs) = (f, (names, eqs)) |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1167 |
| collect_non_invertible_subterms ctxt t (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
|
1168 |
case (strip_comb t) of (f, args) => |
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1169 |
if is_invertible_function ctxt 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
|
1170 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1171 |
val (args', (names', eqs')) = |
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1172 |
fold_map (collect_non_invertible_subterms ctxt) args (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
|
1173 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1174 |
(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
|
1175 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1176 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1177 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1178 |
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
|
1179 |
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
|
1180 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1181 |
(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
|
1182 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1183 |
(* |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1184 |
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
|
1185 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1186 |
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
|
1187 |
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
|
1188 |
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
|
1189 |
*) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1190 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1191 |
fun is_possible_output ctxt vs 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
|
1192 |
forall |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1193 |
(fn t => is_eqT (fastype_of t) andalso forall (member (op =) vs) (term_vs t)) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1194 |
(non_invertible_subterms ctxt 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
|
1195 |
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
|
1196 |
(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
|
1197 |
(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
|
1198 |
|
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1199 |
fun vars_of_destructable_term ctxt (Free (x, _)) = [x] |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1200 |
| vars_of_destructable_term ctxt t = |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1201 |
let |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1202 |
val (f, args) = strip_comb t |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1203 |
in |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1204 |
if is_invertible_function ctxt f then |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1205 |
maps (vars_of_destructable_term ctxt) 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
|
1206 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1207 |
[] |
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1208 |
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
|
1209 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1210 |
fun is_constructable vs t = forall (member (op =) vs) (term_vs 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
|
1211 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1212 |
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
|
1213 |
|
37391 | 1214 |
fun output_terms (Const (@{const_name Pair}, _) $ t1 $ t2, Mode_Pair (d1, d2)) = |
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
|
1215 |
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
|
1216 |
| 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
|
1217 |
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
|
1218 |
| 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
|
1219 |
| 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
|
1220 |
|
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype 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 |
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
|
1222 |
(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
|
1223 |
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
|
1224 |
| 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
|
1225 |
| 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
|
1226 |
(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
|
1227 |
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
|
1228 |
| 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
|
1229 |
|
37391 | 1230 |
fun derivations_of (ctxt : Proof.context) modes vs (Const (@{const_name 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
|
1231 |
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
|
1232 |
(fn (m1, mvars1) => fn (m2, mvars2) => (Mode_Pair (m1, m2), union (op =) mvars1 mvars2)) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1233 |
(derivations_of ctxt modes vs t1 m1) (derivations_of ctxt modes vs t2 m2) |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1234 |
| derivations_of ctxt modes vs t (m as Fun _) = |
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
|
1235 |
(*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
|
1236 |
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
|
1237 |
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
|
1238 |
(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
|
1239 |
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
|
1240 |
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
|
1241 |
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
|
1242 |
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
|
1243 |
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
|
1244 |
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
|
1245 |
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
|
1246 |
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
|
1247 |
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
|
1248 |
| 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
|
1249 |
end*) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1250 |
(case try (all_derivations_of ctxt modes vs) t of |
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
|
1251 |
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
|
1252 |
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
|
1253 |
| NONE => (if is_all_input m then [(Context m, [])] else [])) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1254 |
| derivations_of ctxt 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
|
1255 |
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
|
1256 |
[(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
|
1257 |
else if eq_mode (m, Output) then |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1258 |
(if is_possible_output ctxt vs t then [(Term Output, [])] 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
|
1259 |
else [] |
37391 | 1260 |
and all_derivations_of ctxt modes vs (Const (@{const_name Pair}, _) $ t1 $ t2) = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1261 |
let |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1262 |
val derivs1 = all_derivations_of ctxt modes vs t1 |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1263 |
val derivs2 = all_derivations_of ctxt modes vs t2 |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1264 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1265 |
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
|
1266 |
(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
|
1267 |
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
|
1268 |
end |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1269 |
| all_derivations_of ctxt modes vs (t1 $ t2) = |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
1270 |
let |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1271 |
val derivs1 = all_derivations_of ctxt modes vs t1 |
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 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1273 |
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
|
1274 |
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
|
1275 |
Fun (m', _) => map (fn (d2, mvars2) => |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1276 |
(Mode_App (d1, d2), union (op =) mvars1 mvars2)) (derivations_of ctxt modes vs t2 m') |
39193
0e505a4e500c
stating errors in error messages more verbose in predicate compiler
bulwahn
parents:
39191
diff
changeset
|
1277 |
| _ => raise Fail "all_derivations_of: derivation has an unexpected non-functional mode") derivs1 |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1278 |
end |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1279 |
| all_derivations_of _ modes vs (Const (s, T)) = the (lookup_mode modes (Const (s, T))) |
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1280 |
| all_derivations_of _ modes vs (Free (x, T)) = the (lookup_mode modes (Free (x, T))) |
39193
0e505a4e500c
stating errors in error messages more verbose in predicate compiler
bulwahn
parents:
39191
diff
changeset
|
1281 |
| all_derivations_of _ modes vs _ = raise Fail "all_derivations_of: unexpected term" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1282 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1283 |
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
|
1284 |
| 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
|
1285 |
| 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
|
1286 |
| 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
|
1287 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1288 |
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
|
1289 |
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
|
1290 |
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
|
1291 |
(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
|
1292 |
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
|
1293 |
(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
|
1294 |
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
|
1295 |
| 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
|
1296 |
| 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
|
1297 |
| 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
|
1298 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1299 |
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
|
1300 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1301 |
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
|
1302 |
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
|
1303 |
| 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
|
1304 |
| 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
|
1305 |
| 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
|
1306 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1307 |
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
|
1308 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1309 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1310 |
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
|
1311 |
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
|
1312 |
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
|
1313 |
| 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
|
1314 |
|
36247
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1315 |
fun lexl_ord [] (x, x') = EQUAL |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1316 |
| lexl_ord (ord :: ords') (x, x') = |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1317 |
case ord (x, x') of |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1318 |
EQUAL => lexl_ord ords' (x, x') |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1319 |
| ord => ord |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1320 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1321 |
fun deriv_ord' ctxt pol pred modes t1 t2 ((deriv1, mvars1), (deriv2, mvars2)) = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1322 |
let |
36247
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1323 |
(* prefer functional modes if it is a function *) |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1324 |
fun fun_ord ((t1, deriv1, mvars1), (t2, deriv2, mvars2)) = |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1325 |
let |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1326 |
fun is_functional t mode = |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1327 |
case try (fst o dest_Const o fst o strip_comb) t of |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1328 |
NONE => false |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1329 |
| SOME c => is_some (alternative_compilation_of ctxt c mode) |
36247
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1330 |
in |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1331 |
case (is_functional t1 (head_mode_of deriv1), is_functional t2 (head_mode_of deriv2)) of |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1332 |
(true, true) => EQUAL |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1333 |
| (true, false) => LESS |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1334 |
| (false, true) => GREATER |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1335 |
| (false, false) => EQUAL |
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1336 |
end |
36028
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1337 |
(* prefer modes without requirement for generating random values *) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1338 |
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
|
1339 |
int_ord (length mvars1, length mvars2) |
36028
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1340 |
(* prefer non-random 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
|
1341 |
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
|
1342 |
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
|
1343 |
if random_mode_in_deriv modes t1 deriv1 then 1 else 0) |
36028
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1344 |
(* prefer modes with more input and less output *) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1345 |
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
|
1346 |
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
|
1347 |
number_of_output_positions (head_mode_of deriv2)) |
36028
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1348 |
(* prefer recursive calls *) |
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1349 |
fun is_rec_premise t = |
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1350 |
case fst (strip_comb t) of Const (c, T) => c = pred | _ => false |
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1351 |
fun recursive_ord ((t1, deriv1, mvars1), (t2, deriv2, mvars2)) = |
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1352 |
int_ord (if is_rec_premise t1 then 0 else 1, |
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1353 |
if is_rec_premise t2 then 0 else 1) |
36247
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1354 |
val ord = lexl_ord [mvars_ord, fun_ord, random_mode_ord, output_mode_ord, recursive_ord] |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1355 |
in |
36028
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1356 |
ord ((t1, deriv1, mvars1), (t2, deriv2, mvars2)) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1357 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1358 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1359 |
fun deriv_ord ctxt pol pred modes t = deriv_ord' ctxt pol pred modes 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
|
1360 |
|
36247
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1361 |
fun premise_ord thy pol pred modes ((prem1, a1), (prem2, a2)) = |
36258
f459a0cc3241
removing dead code; clarifying function names; removing clone
bulwahn
parents:
36254
diff
changeset
|
1362 |
rev_option_ord (deriv_ord' thy pol pred modes (dest_indprem prem1) (dest_indprem prem2)) (a1, a2) |
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 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1364 |
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
|
1365 |
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
|
1366 |
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
|
1367 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1368 |
fun select_mode_prem (mode_analysis_options : mode_analysis_options) (ctxt : Proof.context) pred |
36028
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1369 |
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
|
1370 |
let |
39191
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1371 |
fun choose_mode_of_prem (Prem t) = |
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1372 |
find_least (deriv_ord ctxt pol pred modes t) (all_derivations_of ctxt pos_modes vs 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
|
1373 |
| choose_mode_of_prem (Sidecond t) = SOME (Context Bool, missing_vars vs t) |
39191
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1374 |
| choose_mode_of_prem (Negprem t) = find_least (deriv_ord ctxt (not pol) pred modes t) |
36247
bcf23027bca2
prefer functional modes of functions in the mode analysis
bulwahn
parents:
36056
diff
changeset
|
1375 |
(filter (fn (d, missing_vars) => is_all_input (head_mode_of d)) |
39191
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1376 |
(all_derivations_of ctxt neg_modes vs t)) |
39193
0e505a4e500c
stating errors in error messages more verbose in predicate compiler
bulwahn
parents:
39191
diff
changeset
|
1377 |
| choose_mode_of_prem p = raise Fail ("choose_mode_of_prem: unexpected premise " ^ string_of_prem ctxt 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
|
1378 |
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
|
1379 |
if #reorder_premises mode_analysis_options then |
39191
edaf5a6ffa99
using linear find_least instead of sorting in the mode analysis of the predicate compiler
bulwahn
parents:
39125
diff
changeset
|
1380 |
find_least (premise_ord ctxt pol pred modes) (ps ~~ map choose_mode_of_prem 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
|
1381 |
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
|
1382 |
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
|
1383 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1384 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1385 |
fun check_mode_clause' (mode_analysis_options : mode_analysis_options) ctxt pred param_vs (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
|
1386 |
(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
|
1387 |
let |
36258
f459a0cc3241
removing dead code; clarifying function names; removing clone
bulwahn
parents:
36254
diff
changeset
|
1388 |
val vTs = distinct (op =) (fold Term.add_frees (map dest_indprem 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
|
1389 |
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
|
1390 |
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
|
1391 |
(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
|
1392 |
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
|
1393 |
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
|
1394 |
(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
|
1395 |
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
|
1396 |
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
|
1397 |
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
|
1398 |
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
|
1399 |
val (in_ts, out_ts) = split_mode mode ts |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1400 |
val in_vs = union (op =) param_vs (maps (vars_of_destructable_term ctxt) in_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
|
1401 |
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
|
1402 |
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
|
1403 |
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
|
1404 |
| 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
|
1405 |
| Negprem t => union (op =) vs (term_vs t) |
39193
0e505a4e500c
stating errors in error messages more verbose in predicate compiler
bulwahn
parents:
39191
diff
changeset
|
1406 |
| _ => raise Fail "unexpected premise") |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1407 |
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
|
1408 |
| 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
|
1409 |
(case |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1410 |
(select_mode_prem mode_analysis_options ctxt pred pol (modes', (pos_modes', neg_modes')) vs ps) of |
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
|
1411 |
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
|
1412 |
(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
|
1413 |
| 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
|
1414 |
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
|
1415 |
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
|
1416 |
(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
|
1417 |
(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
|
1418 |
@ 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
|
1419 |
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
|
1420 |
| 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
|
1421 |
| 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
|
1422 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1423 |
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
|
1424 |
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
|
1425 |
| SOME (acc_ps, vs, rnd) => |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1426 |
if forall (is_constructable vs) (in_ts @ out_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
|
1427 |
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
|
1428 |
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
|
1429 |
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
|
1430 |
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
|
1431 |
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
|
1432 |
(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
|
1433 |
(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
|
1434 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1435 |
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
|
1436 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1437 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1438 |
NONE |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1439 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1440 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1441 |
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
|
1442 |
|
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
|
1443 |
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
|
1444 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1445 |
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
|
1446 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1447 |
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
|
1448 |
| 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
|
1449 |
| 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
|
1450 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1451 |
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
|
1452 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1453 |
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
|
1454 |
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
|
1455 |
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
|
1456 |
val res = Output.cond_timeit false "work part of check_mode for one mode" (fn _ => |
36028
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1457 |
map (check_mode_clause' mode_analysis_options thy p 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
|
1458 |
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
|
1459 |
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
|
1460 |
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
|
1461 |
[] => 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
|
1462 |
| 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
|
1463 |
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
|
1464 |
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
|
1465 |
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
|
1466 |
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
|
1467 |
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
|
1468 |
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
|
1469 |
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
|
1470 |
((p, (ms' : ((bool * mode) * bool) list)), errors) |
32667 | 1471 |
end; |
1472 |
||
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
|
1473 |
fun get_modes_pred' mode_analysis_options thy param_vs clauses modes (p, ms) = |
32667 | 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 rs = these (AList.lookup (op =) clauses p) |
32667 | 1476 |
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
|
1477 |
(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
|
1478 |
(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
|
1479 |
((fn (ts, ps, rnd) => (ts, ps)) o the o |
36028
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1480 |
check_mode_clause' mode_analysis_options thy p param_vs modes m) rs)) ms) |
32667 | 1481 |
end; |
33137
0d16c07f8d24
added option to generate random values to values command in the predicate compiler
bulwahn
parents:
33135
diff
changeset
|
1482 |
|
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
|
1483 |
fun fixp f (x : (string * ((bool * mode) * bool) list) list) = |
32667 | 1484 |
let val y = f x |
1485 |
in if x = y then x else fixp f y end; |
|
1486 |
||
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
|
1487 |
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
|
1488 |
let |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1489 |
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
|
1490 |
in |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1491 |
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
|
1492 |
end |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
1493 |
|
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
|
1494 |
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
|
1495 |
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
|
1496 |
^ (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
|
1497 |
|
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
bulwahn
parents:
35267
diff
changeset
|
1498 |
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
|
1499 |
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
|
1500 |
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
|
1501 |
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
|
1502 |
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
|
1503 |
|
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1504 |
fun infer_modes mode_analysis_options options (lookup_mode, lookup_neg_mode, needs_random) ctxt |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1505 |
preds all_modes param_vs clauses = |
32667 | 1506 |
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
|
1507 |
fun appair f (x1, x2) (y1, y2) = (f x1 y1, f x2 y2) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1508 |
fun add_needs_random s (false, m) = ((false, m), false) |
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1509 |
| add_needs_random s (true, m) = ((true, m), needs_random s m) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1510 |
fun add_polarity_and_random_bit s b ms = map (fn m => add_needs_random s (b, m)) 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
|
1511 |
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
|
1512 |
(* 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
|
1513 |
- what is the impact on performance? *) |
36251
5fd5d732a4ea
only add relevant predicates to the list of extra modes
bulwahn
parents:
36247
diff
changeset
|
1514 |
fun predname_of (Prem t) = |
5fd5d732a4ea
only add relevant predicates to the list of extra modes
bulwahn
parents:
36247
diff
changeset
|
1515 |
(case try dest_Const (fst (strip_comb t)) of SOME (c, _) => insert (op =) c | NONE => I) |
5fd5d732a4ea
only add relevant predicates to the list of extra modes
bulwahn
parents:
36247
diff
changeset
|
1516 |
| predname_of (Negprem t) = |
5fd5d732a4ea
only add relevant predicates to the list of extra modes
bulwahn
parents:
36247
diff
changeset
|
1517 |
(case try dest_Const (fst (strip_comb t)) of SOME (c, _) => insert (op =) c | NONE => I) |
5fd5d732a4ea
only add relevant predicates to the list of extra modes
bulwahn
parents:
36247
diff
changeset
|
1518 |
| predname_of _ = I |
5fd5d732a4ea
only add relevant predicates to the list of extra modes
bulwahn
parents:
36247
diff
changeset
|
1519 |
val relevant_prednames = fold (fn (_, clauses') => |
5fd5d732a4ea
only add relevant predicates to the list of extra modes
bulwahn
parents:
36247
diff
changeset
|
1520 |
fold (fn (_, ps) => fold Term.add_const_names (map dest_indprem ps)) clauses') clauses [] |
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1521 |
|> filter_out (fn name => member (op =) prednames name) |
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
|
1522 |
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
|
1523 |
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
|
1524 |
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
|
1525 |
val pos_extra_modes = |
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1526 |
map_filter (fn name => Option.map (pair name) (try lookup_mode name)) |
36251
5fd5d732a4ea
only add relevant predicates to the list of extra modes
bulwahn
parents:
36247
diff
changeset
|
1527 |
relevant_prednames |
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
|
1528 |
val neg_extra_modes = |
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1529 |
map_filter (fn name => Option.map (pair name) (try lookup_neg_mode name)) |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1530 |
relevant_prednames |
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
|
1531 |
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
|
1532 |
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
|
1533 |
@ 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
|
1534 |
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
|
1535 |
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
|
1536 |
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
|
1537 |
map (fn (s, ms) => (s, (add_polarity_and_random_bit s true ms))) |
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1538 |
(map_filter (fn name => Option.map (pair name) (try lookup_mode name)) |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1539 |
relevant_prednames) |
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
|
1540 |
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
|
1541 |
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
|
1542 |
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
|
1543 |
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
|
1544 |
(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
|
1545 |
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
|
1546 |
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
|
1547 |
fun iteration modes = map |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1548 |
(check_modes_pred' mode_analysis_options options ctxt param_vs clauses |
36028
3837493fe4ab
prefer recursive calls before others in the mode inference
bulwahn
parents:
36027
diff
changeset
|
1549 |
(modes @ extra_modes)) 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
|
1550 |
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
|
1551 |
Output.cond_timeit false "Fixpount computation of mode analysis" (fn () => |
39383
ddfafa97da2f
adding option show_invalid_clauses for a more detailed message when modes are not inferred
bulwahn
parents:
39382
diff
changeset
|
1552 |
if show_invalid_clauses options 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
|
1553 |
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
|
1554 |
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
|
1555 |
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
|
1556 |
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
|
1557 |
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
|
1558 |
(fixp (fn modes => map fst (iteration modes)) start_modes, [])) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1559 |
val moded_clauses = map (get_modes_pred' mode_analysis_options ctxt param_vs 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
|
1560 |
(modes @ extra_modes)) modes |
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1561 |
val need_random = fold (fn (s, ms) => if member (op =) (map fst preds) s then |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1562 |
cons (s, (map_filter (fn ((true, m), true) => SOME m | _ => NONE) ms)) else I) |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1563 |
modes [] |
32667 | 1564 |
in |
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
1565 |
((moded_clauses, need_random), errors) |
32667 | 1566 |
end; |
1567 |
||
1568 |
(* term construction *) |
|
1569 |
||
1570 |
fun mk_v (names, vs) s T = (case AList.lookup (op =) vs s of |
|
1571 |
NONE => (Free (s, T), (names, (s, [])::vs)) |
|
1572 |
| SOME xs => |
|
1573 |
let |
|
1574 |
val s' = Name.variant names s; |
|
1575 |
val v = Free (s', T) |
|
1576 |
in |
|
1577 |
(v, (s'::names, AList.update (op =) (s, v::xs) vs)) |
|
1578 |
end); |
|
1579 |
||
1580 |
fun distinct_v (Free (s, T)) nvs = mk_v nvs s T |
|
1581 |
| distinct_v (t $ u) nvs = |
|
1582 |
let |
|
1583 |
val (t', nvs') = distinct_v t nvs; |
|
1584 |
val (u', nvs'') = distinct_v u nvs'; |
|
1585 |
in (t' $ u', nvs'') end |
|
1586 |
| distinct_v x nvs = (x, nvs); |
|
1587 |
||
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1588 |
|
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1589 |
(** specific rpred functions -- move them to the correct place in this file *) |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1590 |
fun mk_Eval_of (P as (Free (f, _)), T) mode = |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1591 |
let |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1592 |
fun mk_bounds (Type (@{type_name Product_Type.prod}, [T1, T2])) i = |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1593 |
let |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1594 |
val (bs2, i') = mk_bounds T2 i |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1595 |
val (bs1, i'') = mk_bounds T1 i' |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1596 |
in |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1597 |
(HOLogic.pair_const T1 T2 $ bs1 $ bs2, i'' + 1) |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1598 |
end |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1599 |
| mk_bounds T i = (Bound i, i + 1) |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1600 |
fun mk_prod ((t1, T1), (t2, T2)) = (HOLogic.pair_const T1 T2 $ t1 $ t2, HOLogic.mk_prodT (T1, T2)) |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1601 |
fun mk_tuple [] = (HOLogic.unit, HOLogic.unitT) |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1602 |
| mk_tuple tTs = foldr1 mk_prod tTs; |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1603 |
fun mk_split_abs (T as Type (@{type_name Product_Type.prod}, [T1, T2])) t = absdummy (T, HOLogic.split_const (T1, T2, @{typ bool}) $ (mk_split_abs T1 (mk_split_abs T2 t))) |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1604 |
| mk_split_abs T t = absdummy (T, t) |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1605 |
val args = rev (fst (fold_map mk_bounds (rev (binder_types T)) 0)) |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1606 |
val (inargs, outargs) = split_mode mode args |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1607 |
val (inTs, outTs) = split_map_modeT (fn _ => fn T => (SOME T, NONE)) mode (binder_types T) |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1608 |
val inner_term = PredicateCompFuns.mk_Eval (list_comb (P, inargs), fst (mk_tuple (outargs ~~ outTs))) |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1609 |
in |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1610 |
fold_rev mk_split_abs (binder_types T) inner_term |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1611 |
end |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1612 |
|
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1613 |
fun compile_arg compilation_modifiers additional_arguments ctxt param_modes arg = |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1614 |
let |
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1615 |
fun map_params (t as Free (f, T)) = |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1616 |
(case (AList.lookup (op =) param_modes f) of |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1617 |
SOME mode => |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1618 |
let |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1619 |
val T' = Comp_Mod.funT_of compilation_modifiers mode T |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1620 |
in |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1621 |
mk_Eval_of (Free (f, T'), T) mode |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1622 |
end |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1623 |
| NONE => t) |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1624 |
| map_params t = t |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1625 |
in |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1626 |
map_aterms map_params arg |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1627 |
end |
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1628 |
|
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1629 |
fun compile_match compilation_modifiers additional_arguments ctxt param_modes |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1630 |
eqs eqs' out_ts success_t = |
32667 | 1631 |
let |
36019
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1632 |
val compfuns = Comp_Mod.compfuns compilation_modifiers |
32667 | 1633 |
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
|
1634 |
val eqs'' = |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1635 |
map (compile_arg compilation_modifiers additional_arguments ctxt param_modes) eqs'' |
32667 | 1636 |
val names = fold Term.add_free_names (success_t :: eqs'' @ out_ts) []; |
1637 |
val name = Name.variant names "x"; |
|
1638 |
val name' = Name.variant (name :: names) "y"; |
|
33148
0808f7d0d0d7
removed tuple functions from the predicate compiler
bulwahn
parents:
33147
diff
changeset
|
1639 |
val T = HOLogic.mk_tupleT (map fastype_of out_ts); |
32667 | 1640 |
val U = fastype_of success_t; |
36254 | 1641 |
val U' = dest_predT compfuns U; |
32667 | 1642 |
val v = Free (name, T); |
1643 |
val v' = Free (name', T); |
|
1644 |
in |
|
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1645 |
lambda v (fst (Datatype.make_case ctxt Datatype_Case.Quiet [] v |
33148
0808f7d0d0d7
removed tuple functions from the predicate compiler
bulwahn
parents:
33147
diff
changeset
|
1646 |
[(HOLogic.mk_tuple out_ts, |
32667 | 1647 |
if null eqs'' then success_t |
1648 |
else Const (@{const_name HOL.If}, HOLogic.boolT --> U --> U --> U) $ |
|
1649 |
foldr1 HOLogic.mk_conj eqs'' $ success_t $ |
|
1650 |
mk_bot compfuns U'), |
|
1651 |
(v', mk_bot compfuns U')])) |
|
1652 |
end; |
|
1653 |
||
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1654 |
fun string_of_tderiv ctxt (t, deriv) = |
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
|
1655 |
(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
|
1656 |
(t1 $ t2, Mode_App (deriv1, deriv2)) => |
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1657 |
string_of_tderiv ctxt (t1, deriv1) ^ " $ " ^ string_of_tderiv ctxt (t2, deriv2) |
37391 | 1658 |
| (Const (@{const_name Pair}, _) $ t1 $ t2, Mode_Pair (deriv1, deriv2)) => |
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1659 |
"(" ^ string_of_tderiv ctxt (t1, deriv1) ^ ", " ^ string_of_tderiv ctxt (t2, deriv2) ^ ")" |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1660 |
| (t, Term Input) => Syntax.string_of_term ctxt t ^ "[Input]" |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1661 |
| (t, Term Output) => Syntax.string_of_term ctxt t ^ "[Output]" |
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1662 |
| (t, Context m) => Syntax.string_of_term ctxt t ^ "[" ^ string_of_mode 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
|
1663 |
|
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1664 |
fun compile_expr compilation_modifiers ctxt (t, deriv) param_modes additional_arguments = |
32667 | 1665 |
let |
36019
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1666 |
val compfuns = Comp_Mod.compfuns compilation_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
|
1667 |
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
|
1668 |
(case (t, deriv) of |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1669 |
(t, Term Input) => SOME (compile_arg compilation_modifiers additional_arguments ctxt param_modes 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
|
1670 |
| (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
|
1671 |
| (Const (name, T), Context mode) => |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1672 |
(case alternative_compilation_of ctxt name mode of |
36038
385f706eff24
generalized alternative functions to alternative compilation to handle arithmetic functions better
bulwahn
parents:
36037
diff
changeset
|
1673 |
SOME alt_comp => SOME (alt_comp compfuns T) |
36034
ee84eac07290
added book-keeping, registration and compilation with alternative functions for predicates in the predicate compiler
bulwahn
parents:
36031
diff
changeset
|
1674 |
| NONE => |
ee84eac07290
added book-keeping, registration and compilation with alternative functions for predicates in the predicate compiler
bulwahn
parents:
36031
diff
changeset
|
1675 |
SOME (Const (function_name_of (Comp_Mod.compilation compilation_modifiers) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1676 |
ctxt name mode, |
36034
ee84eac07290
added book-keeping, registration and compilation with alternative functions for predicates in the predicate compiler
bulwahn
parents:
36031
diff
changeset
|
1677 |
Comp_Mod.funT_of compilation_modifiers mode 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
|
1678 |
| (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
|
1679 |
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
|
1680 |
| (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
|
1681 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1682 |
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
|
1683 |
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
|
1684 |
in SOME (list_abs (bs, mk_if compfuns (list_comb (t, bounds)))) end |
37391 | 1685 |
| (Const (@{const_name Pair}, _) $ t1 $ t2, Mode_Pair (d1, d2)) => |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1686 |
(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
|
1687 |
(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
|
1688 |
| (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
|
1689 |
| (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
|
1690 |
| (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
|
1691 |
| (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
|
1692 |
(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
|
1693 |
(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
|
1694 |
| (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
|
1695 |
| _ => error "something went wrong here!")) |
32667 | 1696 |
in |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
1697 |
list_comb (the (expr_of (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
|
1698 |
end |
33145 | 1699 |
|
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1700 |
fun compile_clause compilation_modifiers ctxt all_vs param_modes additional_arguments |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1701 |
inp (in_ts, out_ts) moded_ps = |
32667 | 1702 |
let |
36019
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1703 |
val compfuns = Comp_Mod.compfuns compilation_modifiers |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1704 |
val compile_match = compile_match compilation_modifiers |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1705 |
additional_arguments ctxt param_modes |
32667 | 1706 |
val (in_ts', (all_vs', eqs)) = |
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1707 |
fold_map (collect_non_invertible_subterms ctxt) in_ts (all_vs, []); |
32667 | 1708 |
fun compile_prems out_ts' vs names [] = |
1709 |
let |
|
1710 |
val (out_ts'', (names', eqs')) = |
|
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1711 |
fold_map (collect_non_invertible_subterms ctxt) out_ts' (names, []); |
32667 | 1712 |
val (out_ts''', (names'', constr_vs)) = fold_map distinct_v |
1713 |
out_ts'' (names', map (rpair []) vs); |
|
1714 |
in |
|
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1715 |
compile_match constr_vs (eqs @ eqs') out_ts''' |
33148
0808f7d0d0d7
removed tuple functions from the predicate compiler
bulwahn
parents:
33147
diff
changeset
|
1716 |
(mk_single compfuns (HOLogic.mk_tuple out_ts)) |
32667 | 1717 |
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
|
1718 |
| compile_prems out_ts vs names ((p, deriv) :: ps) = |
32667 | 1719 |
let |
1720 |
val vs' = distinct (op =) (flat (vs :: map term_vs out_ts)); |
|
1721 |
val (out_ts', (names', eqs)) = |
|
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1722 |
fold_map (collect_non_invertible_subterms ctxt) out_ts (names, []) |
32667 | 1723 |
val (out_ts'', (names'', constr_vs')) = fold_map distinct_v |
1724 |
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
|
1725 |
val mode = head_mode_of deriv |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1726 |
val additional_arguments' = |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
1727 |
Comp_Mod.transform_additional_arguments compilation_modifiers p additional_arguments |
32667 | 1728 |
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
|
1729 |
Prem t => |
32667 | 1730 |
let |
33138
e2e23987c59a
reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents:
33137
diff
changeset
|
1731 |
val u = |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1732 |
compile_expr compilation_modifiers ctxt (t, deriv) param_modes 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
|
1733 |
val (_, out_ts''') = split_mode mode (snd (strip_comb t)) |
32667 | 1734 |
val rest = compile_prems out_ts''' vs' names'' ps |
1735 |
in |
|
1736 |
(u, rest) |
|
1737 |
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
|
1738 |
| Negprem t => |
32667 | 1739 |
let |
36019
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1740 |
val neg_compilation_modifiers = |
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1741 |
negative_comp_modifiers_of compilation_modifiers |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1742 |
val u = mk_not compfuns |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1743 |
(compile_expr neg_compilation_modifiers ctxt (t, deriv) param_modes 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
|
1744 |
val (_, out_ts''') = split_mode mode (snd (strip_comb t)) |
32667 | 1745 |
val rest = compile_prems out_ts''' vs' names'' ps |
1746 |
in |
|
1747 |
(u, rest) |
|
1748 |
end |
|
1749 |
| Sidecond t => |
|
1750 |
let |
|
36019
64bbbd858c39
generalizing the compilation process of the predicate compiler
bulwahn
parents:
36018
diff
changeset
|
1751 |
val t = compile_arg compilation_modifiers additional_arguments |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1752 |
ctxt param_modes t |
32667 | 1753 |
val rest = compile_prems [] vs' names'' ps; |
1754 |
in |
|
1755 |
(mk_if compfuns t, rest) |
|
1756 |
end |
|
1757 |
| Generator (v, T) => |
|
1758 |
let |
|
35880
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
1759 |
val u = Comp_Mod.mk_random compilation_modifiers T additional_arguments |
32667 | 1760 |
val rest = compile_prems [Free (v, T)] vs' names'' ps; |
1761 |
in |
|
1762 |
(u, rest) |
|
1763 |
end |
|
1764 |
in |
|
33147
180dc60bd88c
improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents:
33146
diff
changeset
|
1765 |
compile_match constr_vs' eqs out_ts'' |
32667 | 1766 |
(mk_bind compfuns (compiled_clause, rest)) |
1767 |
end |
|
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1768 |
val prem_t = compile_prems in_ts' (map fst param_modes) all_vs' moded_ps; |
32667 | 1769 |
in |
1770 |
mk_bind compfuns (mk_single compfuns inp, prem_t) |
|
1771 |
end |
|
1772 |
||
36254 | 1773 |
(* switch detection *) |
1774 |
||
1775 |
(** argument position of an inductive predicates and the executable functions **) |
|
1776 |
||
1777 |
type position = int * int list |
|
1778 |
||
1779 |
fun input_positions_pair Input = [[]] |
|
1780 |
| input_positions_pair Output = [] |
|
1781 |
| input_positions_pair (Fun _) = [] |
|
1782 |
| input_positions_pair (Pair (m1, m2)) = |
|
1783 |
map (cons 1) (input_positions_pair m1) @ map (cons 2) (input_positions_pair m2) |
|
1784 |
||
1785 |
fun input_positions_of_mode mode = flat (map_index |
|
1786 |
(fn (i, Input) => [(i, [])] |
|
1787 |
| (_, Output) => [] |
|
1788 |
| (_, Fun _) => [] |
|
1789 |
| (i, m as Pair (m1, m2)) => map (pair i) (input_positions_pair m)) |
|
1790 |
(Predicate_Compile_Aux.strip_fun_mode mode)) |
|
1791 |
||
1792 |
fun argument_position_pair mode [] = [] |
|
1793 |
| argument_position_pair (Pair (Fun _, m2)) (2 :: is) = argument_position_pair m2 is |
|
1794 |
| argument_position_pair (Pair (m1, m2)) (i :: is) = |
|
1795 |
(if eq_mode (m1, Output) andalso i = 2 then |
|
1796 |
argument_position_pair m2 is |
|
1797 |
else if eq_mode (m2, Output) andalso i = 1 then |
|
1798 |
argument_position_pair m1 is |
|
1799 |
else (i :: argument_position_pair (if i = 1 then m1 else m2) is)) |
|
1800 |
||
1801 |
fun argument_position_of mode (i, is) = |
|
1802 |
(i - (length (filter (fn Output => true | Fun _ => true | _ => false) |
|
1803 |
(List.take (strip_fun_mode mode, i)))), |
|
1804 |
argument_position_pair (nth (strip_fun_mode mode) i) is) |
|
1805 |
||
1806 |
fun nth_pair [] t = t |
|
1807 |
| nth_pair (1 :: is) (Const (@{const_name Pair}, _) $ t1 $ _) = nth_pair is t1 |
|
1808 |
| nth_pair (2 :: is) (Const (@{const_name Pair}, _) $ _ $ t2) = nth_pair is t2 |
|
1809 |
| nth_pair _ _ = raise Fail "unexpected input for nth_tuple" |
|
1810 |
||
1811 |
(** switch detection analysis **) |
|
1812 |
||
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
1813 |
fun find_switch_test ctxt (i, is) (ts, prems) = |
36254 | 1814 |
let |
1815 |
val t = nth_pair is (nth ts i) |
|
1816 |
val T = fastype_of t |
|
1817 |
in |
|
1818 |
case T of |
|
1819 |
TFree _ => NONE |
|
1820 |
| Type (Tcon, _) => |
|
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
1821 |
(case Datatype_Data.get_constrs (ProofContext.theory_of ctxt) Tcon of |
36254 | 1822 |
NONE => NONE |
1823 |
| SOME cs => |
|
1824 |
(case strip_comb t of |
|
1825 |
(Var _, []) => NONE |
|
1826 |
| (Free _, []) => NONE |
|
1827 |
| (Const (c, T), _) => if AList.defined (op =) cs c then SOME (c, T) else NONE)) |
|
1828 |
end |
|
1829 |
||
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
1830 |
fun partition_clause ctxt pos moded_clauses = |
36254 | 1831 |
let |
1832 |
fun insert_list eq (key, value) = AList.map_default eq (key, []) (cons value) |
|
1833 |
fun find_switch_test' moded_clause (cases, left) = |
|
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
1834 |
case find_switch_test ctxt pos moded_clause of |
36254 | 1835 |
SOME (c, T) => (insert_list (op =) ((c, T), moded_clause) cases, left) |
1836 |
| NONE => (cases, moded_clause :: left) |
|
1837 |
in |
|
1838 |
fold find_switch_test' moded_clauses ([], []) |
|
1839 |
end |
|
1840 |
||
1841 |
datatype switch_tree = |
|
1842 |
Atom of moded_clause list | Node of (position * ((string * typ) * switch_tree) list) * switch_tree |
|
1843 |
||
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
1844 |
fun mk_switch_tree ctxt mode moded_clauses = |
36254 | 1845 |
let |
1846 |
fun select_best_switch moded_clauses input_position best_switch = |
|
1847 |
let |
|
1848 |
val ord = option_ord (rev_order o int_ord o (pairself (length o snd o snd))) |
|
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
1849 |
val partition = partition_clause ctxt input_position moded_clauses |
36254 | 1850 |
val switch = if (length (fst partition) > 1) then SOME (input_position, partition) else NONE |
1851 |
in |
|
1852 |
case ord (switch, best_switch) of LESS => best_switch |
|
1853 |
| EQUAL => best_switch | GREATER => switch |
|
1854 |
end |
|
1855 |
fun detect_switches moded_clauses = |
|
1856 |
case fold (select_best_switch moded_clauses) (input_positions_of_mode mode) NONE of |
|
1857 |
SOME (best_pos, (switched_on, left_clauses)) => |
|
1858 |
Node ((best_pos, map (apsnd detect_switches) switched_on), |
|
1859 |
detect_switches left_clauses) |
|
1860 |
| NONE => Atom moded_clauses |
|
1861 |
in |
|
1862 |
detect_switches moded_clauses |
|
1863 |
end |
|
1864 |
||
1865 |
(** compilation of detected switches **) |
|
1866 |
||
1867 |
fun destruct_constructor_pattern (pat, obj) = |
|
1868 |
(case strip_comb pat of |
|
1869 |
(f as Free _, []) => cons (pat, obj) |
|
1870 |
| (Const (c, T), pat_args) => |
|
1871 |
(case strip_comb obj of |
|
1872 |
(Const (c', T'), obj_args) => |
|
1873 |
(if c = c' andalso T = T' then |
|
1874 |
fold destruct_constructor_pattern (pat_args ~~ obj_args) |
|
1875 |
else raise Fail "pattern and object mismatch") |
|
1876 |
| _ => raise Fail "unexpected object") |
|
1877 |
| _ => raise Fail "unexpected pattern") |
|
1878 |
||
1879 |
||
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1880 |
fun compile_switch compilation_modifiers ctxt all_vs param_modes additional_arguments mode |
36254 | 1881 |
in_ts' outTs switch_tree = |
1882 |
let |
|
1883 |
val compfuns = Comp_Mod.compfuns compilation_modifiers |
|
1884 |
val thy = ProofContext.theory_of ctxt |
|
1885 |
fun compile_switch_tree _ _ (Atom []) = NONE |
|
1886 |
| compile_switch_tree all_vs ctxt_eqs (Atom moded_clauses) = |
|
1887 |
let |
|
1888 |
val in_ts' = map (Pattern.rewrite_term thy ctxt_eqs []) in_ts' |
|
1889 |
fun compile_clause' (ts, moded_ps) = |
|
1890 |
let |
|
1891 |
val (ts, out_ts) = split_mode mode ts |
|
1892 |
val subst = fold destruct_constructor_pattern (in_ts' ~~ ts) [] |
|
1893 |
val (fsubst, pat') = List.partition (fn (_, Free _) => true | _ => false) subst |
|
1894 |
val moded_ps' = (map o apfst o map_indprem) |
|
1895 |
(Pattern.rewrite_term thy (map swap fsubst) []) moded_ps |
|
1896 |
val inp = HOLogic.mk_tuple (map fst pat') |
|
1897 |
val in_ts' = map (Pattern.rewrite_term thy (map swap fsubst) []) (map snd pat') |
|
1898 |
val out_ts' = map (Pattern.rewrite_term thy (map swap fsubst) []) out_ts |
|
1899 |
in |
|
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1900 |
compile_clause compilation_modifiers ctxt all_vs param_modes additional_arguments |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1901 |
inp (in_ts', out_ts') moded_ps' |
36254 | 1902 |
end |
1903 |
in SOME (foldr1 (mk_sup compfuns) (map compile_clause' moded_clauses)) end |
|
1904 |
| compile_switch_tree all_vs ctxt_eqs (Node ((position, switched_clauses), left_clauses)) = |
|
1905 |
let |
|
1906 |
val (i, is) = argument_position_of mode position |
|
1907 |
val inp_var = nth_pair is (nth in_ts' i) |
|
1908 |
val x = Name.variant all_vs "x" |
|
1909 |
val xt = Free (x, fastype_of inp_var) |
|
1910 |
fun compile_single_case ((c, T), switched) = |
|
1911 |
let |
|
1912 |
val Ts = binder_types T |
|
1913 |
val argnames = Name.variant_list (x :: all_vs) |
|
1914 |
(map (fn i => "c" ^ string_of_int i) (1 upto length Ts)) |
|
1915 |
val args = map2 (curry Free) argnames Ts |
|
1916 |
val pattern = list_comb (Const (c, T), args) |
|
1917 |
val ctxt_eqs' = (inp_var, pattern) :: ctxt_eqs |
|
1918 |
val compilation = the_default (mk_bot compfuns (HOLogic.mk_tupleT outTs)) |
|
1919 |
(compile_switch_tree (argnames @ x :: all_vs) ctxt_eqs' switched) |
|
1920 |
in |
|
1921 |
(pattern, compilation) |
|
1922 |
end |
|
1923 |
val switch = fst (Datatype.make_case ctxt Datatype_Case.Quiet [] inp_var |
|
1924 |
((map compile_single_case switched_clauses) @ |
|
1925 |
[(xt, mk_bot compfuns (HOLogic.mk_tupleT outTs))])) |
|
1926 |
in |
|
1927 |
case compile_switch_tree all_vs ctxt_eqs left_clauses of |
|
1928 |
NONE => SOME switch |
|
1929 |
| SOME left_comp => SOME (mk_sup compfuns (switch, left_comp)) |
|
1930 |
end |
|
1931 |
in |
|
1932 |
compile_switch_tree all_vs [] switch_tree |
|
1933 |
end |
|
1934 |
||
1935 |
(* compilation of predicates *) |
|
1936 |
||
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
1937 |
fun compile_pred options compilation_modifiers ctxt all_vs param_vs s T (pol, mode) moded_cls = |
32667 | 1938 |
let |
36020
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
1939 |
val compilation_modifiers = if pol then compilation_modifiers else |
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
1940 |
negative_comp_modifiers_of compilation_modifiers |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
1941 |
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
|
1942 |
(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
|
1943 |
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
|
1944 |
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
|
1945 |
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
|
1946 |
| 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
|
1947 |
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
|
1948 |
(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
|
1949 |
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
|
1950 |
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
|
1951 |
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
|
1952 |
(fn T => fn (param_vs, names) => |
36018 | 1953 |
if is_param_type T 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
|
1954 |
(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
|
1955 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1956 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
1957 |
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
|
1958 |
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
|
1959 |
(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
|
1960 |
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
|
1961 |
(fn t as Free (x, _) => if member (op =) param_vs x then NONE else SOME t | t => SOME t)) in_ts |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1962 |
val param_modes = param_vs ~~ ho_arg_modes_of mode |
36254 | 1963 |
val compilation = |
1964 |
if detect_switches options then |
|
1965 |
the_default (mk_bot compfuns (HOLogic.mk_tupleT outTs)) |
|
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1966 |
(compile_switch compilation_modifiers ctxt all_vs param_modes additional_arguments mode |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1967 |
in_ts' outTs (mk_switch_tree ctxt mode moded_cls)) |
36254 | 1968 |
else |
1969 |
let |
|
1970 |
val cl_ts = |
|
1971 |
map (fn (ts, moded_prems) => |
|
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1972 |
compile_clause compilation_modifiers ctxt all_vs param_modes additional_arguments |
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
1973 |
(HOLogic.mk_tuple in_ts') (split_mode mode ts) moded_prems) moded_cls; |
36254 | 1974 |
in |
1975 |
Comp_Mod.wrap_compilation compilation_modifiers compfuns s T mode additional_arguments |
|
1976 |
(if null cl_ts then |
|
1977 |
mk_bot compfuns (HOLogic.mk_tupleT outTs) |
|
1978 |
else |
|
1979 |
foldr1 (mk_sup compfuns) cl_ts) |
|
1980 |
end |
|
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1981 |
val fun_const = |
35891
3122bdd95275
contextifying the compilation of the predicate compiler
bulwahn
parents:
35889
diff
changeset
|
1982 |
Const (function_name_of (Comp_Mod.compilation compilation_modifiers) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
1983 |
ctxt s mode, funT) |
32667 | 1984 |
in |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1985 |
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
|
1986 |
(HOLogic.mk_eq (list_comb (fun_const, in_ts @ additional_arguments), compilation)) |
32667 | 1987 |
end; |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
1988 |
|
36254 | 1989 |
(** special setup for simpset **) |
34974
18b41bba42b5
new theory Algebras.thy for generic algebraic structures
haftmann
parents:
34963
diff
changeset
|
1990 |
val HOL_basic_ss' = HOL_basic_ss addsimps (@{thms HOL.simp_thms} @ [@{thm Pair_eq}]) |
32667 | 1991 |
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
|
1992 |
setSolver (mk_solver "True_solver" (fn _ => rtac @{thm TrueI})) |
32667 | 1993 |
|
1994 |
(* Definition of executable functions and their intro and elim rules *) |
|
1995 |
||
1996 |
fun print_arities arities = tracing ("Arities:\n" ^ |
|
1997 |
cat_lines (map (fn (s, (ks, k)) => s ^ ": " ^ |
|
1998 |
space_implode " -> " (map |
|
1999 |
(fn NONE => "X" | SOME k' => string_of_int k') |
|
2000 |
(ks @ [SOME k]))) arities)); |
|
2001 |
||
37591 | 2002 |
fun strip_split_abs (Const (@{const_name prod_case}, _) $ t) = strip_split_abs 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
|
2003 |
| 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
|
2004 |
| 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
|
2005 |
|
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset
|
2006 |
fun mk_args is_eval (m as Pair (m1, m2), T as Type (@{type_name Product_Type.prod}, [T1, T2])) names = |
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
|
2007 |
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
|
2008 |
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
|
2009 |
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
|
2010 |
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
|
2011 |
(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
|
2012 |
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
|
2013 |
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
|
2014 |
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
|
2015 |
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
|
2016 |
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
|
2017 |
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
|
2018 |
(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
|
2019 |
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
|
2020 |
| 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
|
2021 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2022 |
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
|
2023 |
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
|
2024 |
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
|
2025 |
val (inargs, outargs) = split_map_mode (fn _ => fn t => (SOME t, NONE)) m args |
39756
6c8e83d94536
consolidated tupled_lambda; moved to structure HOLogic
krauss
parents:
39685
diff
changeset
|
2026 |
val t = fold_rev HOLogic.tupled_lambda args (PredicateCompFuns.mk_Eval |
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 |
(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
|
2028 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2029 |
(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
|
2030 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2031 |
| 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
|
2032 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2033 |
val x = Name.variant names "x" |
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
2034 |
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
|
2035 |
(Free (x, T), x :: names) |
33268
02de0317f66f
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
33265
diff
changeset
|
2036 |
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
|
2037 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2038 |
fun create_intro_elim_rule ctxt mode defthm mode_id funT 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
|
2039 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2040 |
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
|
2041 |
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
|
2042 |
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
|
2043 |
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
|
2044 |
let |
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 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
|
2046 |
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
|
2047 |
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
|
2048 |
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
|
2049 |
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
|
2050 |
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
|
2051 |
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
|
2052 |
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
|
2053 |
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
|
2054 |
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
|
2055 |
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
|
2056 |
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
|
2057 |
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
|
2058 |
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
|
2059 |
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
|
2060 |
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
|
2061 |
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
|
2062 |
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
|
2063 |
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
|
2064 |
@{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
|
2065 |
val unfolddef_tac = Simplifier.asm_full_simp_tac (HOL_basic_ss addsimps simprules) 1 |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2066 |
val introthm = Goal.prove 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
|
2067 |
(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
|
2068 |
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
|
2069 |
val elimtrm = Logic.list_implies ([funpropE, Logic.mk_implies (predpropE, P)], P) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2070 |
val elimthm = Goal.prove 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
|
2071 |
(argnames @ ["y", "P"]) [] elimtrm (fn _ => unfolddef_tac) |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2072 |
val opt_neg_introthm = |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2073 |
if is_all_input mode then |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2074 |
let |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2075 |
val neg_predpropI = HOLogic.mk_Trueprop (HOLogic.mk_not (list_comb (pred, args'))) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2076 |
val neg_funpropI = |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2077 |
HOLogic.mk_Trueprop (PredicateCompFuns.mk_Eval |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2078 |
(PredicateCompFuns.mk_not (list_comb (funtrm, inargs)), HOLogic.unit)) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2079 |
val neg_introtrm = Logic.list_implies (neg_predpropI :: param_eqs, neg_funpropI) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2080 |
val tac = |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2081 |
Simplifier.asm_full_simp_tac (HOL_basic_ss addsimps |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2082 |
(@{thm if_False} :: @{thm Predicate.not_pred_eq} :: simprules)) 1 |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2083 |
THEN rtac @{thm Predicate.singleI} 1 |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2084 |
in SOME (Goal.prove ctxt (argnames @ hoarg_names') [] |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2085 |
neg_introtrm (fn _ => tac)) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2086 |
end |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2087 |
else 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
|
2088 |
in |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2089 |
((introthm, elimthm), opt_neg_introthm) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2090 |
end |
32667 | 2091 |
|
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
2092 |
fun create_constname_of_mode options thy prefix name T mode = |
32667 | 2093 |
let |
33626
42f69386943a
new names for predicate functions in the predicate compiler
bulwahn
parents:
33623
diff
changeset
|
2094 |
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
|
2095 |
^ "_" ^ 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
|
2096 |
val name = the_default system_proposal (proposed_names options name mode) |
32667 | 2097 |
in |
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
2098 |
Sign.full_bname thy name |
32667 | 2099 |
end; |
2100 |
||
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
2101 |
fun create_definitions options preds (name, modes) thy = |
32667 | 2102 |
let |
2103 |
val compfuns = PredicateCompFuns.compfuns |
|
2104 |
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
|
2105 |
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
|
2106 |
let |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
2107 |
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
|
2108 |
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
|
2109 |
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
|
2110 |
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
|
2111 |
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
|
2112 |
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
|
2113 |
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
|
2114 |
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
|
2115 |
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
|
2116 |
val (inargs, outargs) = split_map_mode strip_eval mode args |
39756
6c8e83d94536
consolidated tupled_lambda; moved to structure HOLogic
krauss
parents:
39685
diff
changeset
|
2117 |
val predterm = fold_rev HOLogic.tupled_lambda inargs |
6c8e83d94536
consolidated tupled_lambda; moved to structure HOLogic
krauss
parents:
39685
diff
changeset
|
2118 |
(PredicateCompFuns.mk_Enum (HOLogic.tupled_lambda (HOLogic.mk_tuple outargs) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2119 |
(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
|
2120 |
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
|
2121 |
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
|
2122 |
val ([definition], thy') = thy |> |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
2123 |
Sign.add_consts_i [(Binding.name mode_cbasename, funT, NoSyn)] |> |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39545
diff
changeset
|
2124 |
Global_Theory.add_defs false [((Binding.name (mode_cbasename ^ "_def"), def), [])] |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2125 |
val ctxt' = ProofContext.init_global thy' |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2126 |
val rules as ((intro, elim), _) = |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2127 |
create_intro_elim_rule ctxt' mode definition mode_cname funT (Const (name, T)) |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
2128 |
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
|
2129 |
|> set_function_name Pred name mode mode_cname |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2130 |
|> add_predfun_data name mode (definition, rules) |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39545
diff
changeset
|
2131 |
|> Global_Theory.store_thm (Binding.name (mode_cbasename ^ "I"), intro) |> snd |
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39545
diff
changeset
|
2132 |
|> Global_Theory.store_thm (Binding.name (mode_cbasename ^ "E"), elim) |> snd |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
2133 |
|> Theory.checkpoint |
32667 | 2134 |
end; |
2135 |
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
|
2136 |
thy |> defined_function_of Pred name |> fold create_definition modes |
32667 | 2137 |
end; |
2138 |
||
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
2139 |
fun define_functions comp_modifiers compfuns options preds (name, modes) thy = |
32667 | 2140 |
let |
2141 |
val T = AList.lookup (op =) preds name |> the |
|
2142 |
fun create_definition mode thy = |
|
2143 |
let |
|
33485
0df4f6e46e5e
made definition of functions generically for the different instances
bulwahn
parents:
33484
diff
changeset
|
2144 |
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
|
2145 |
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
|
2146 |
val funT = Comp_Mod.funT_of comp_modifiers mode T |
32667 | 2147 |
in |
2148 |
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
|
2149 |
|> set_function_name (Comp_Mod.compilation comp_modifiers) name mode mode_cname |
32667 | 2150 |
end; |
2151 |
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
|
2152 |
thy |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2153 |
|> 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
|
2154 |
|> fold create_definition modes |
32667 | 2155 |
end; |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32671
diff
changeset
|
2156 |
|
32667 | 2157 |
(* Proving equivalence of term *) |
2158 |
||
2159 |
fun is_Type (Type _) = true |
|
2160 |
| is_Type _ = false |
|
2161 |
||
2162 |
(* returns true if t is an application of an datatype constructor *) |
|
2163 |
(* which then consequently would be splitted *) |
|
2164 |
(* else false *) |
|
2165 |
fun is_constructor thy t = |
|
2166 |
if (is_Type (fastype_of t)) then |
|
2167 |
(case Datatype.get_info thy ((fst o dest_Type o fastype_of) t) of |
|
2168 |
NONE => false |
|
2169 |
| SOME info => (let |
|
2170 |
val constr_consts = maps (fn (_, (_, _, constrs)) => map fst constrs) (#descr info) |
|
2171 |
val (c, _) = strip_comb t |
|
2172 |
in (case c of |
|
36692
54b64d4ad524
farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
haftmann
parents:
36610
diff
changeset
|
2173 |
Const (name, _) => member (op =) constr_consts name |
32667 | 2174 |
| _ => false) end)) |
2175 |
else false |
|
2176 |
||
2177 |
(* MAJOR FIXME: prove_params should be simple |
|
2178 |
- 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
|
2179 |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2180 |
fun prove_param options ctxt nargs t deriv = |
32667 | 2181 |
let |
2182 |
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
|
2183 |
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
|
2184 |
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
|
2185 |
val ho_args = ho_args_of mode args |
32667 | 2186 |
val f_tac = case f of |
2187 |
Const (name, T) => simp_tac (HOL_basic_ss addsimps |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2188 |
[@{thm eval_pred}, predfun_definition_of ctxt name mode, |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2189 |
@{thm split_eta}, @{thm split_beta}, @{thm fst_conv}, |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2190 |
@{thm snd_conv}, @{thm pair_collapse}, @{thm Product_Type.split_conv}]) 1 |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2191 |
| Free _ => |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2192 |
Subgoal.FOCUS_PREMS (fn {context = ctxt, params = params, prems, asms, concl, schematics} => |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2193 |
let |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2194 |
val prems' = maps dest_conjunct_prem (take nargs prems) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2195 |
in |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2196 |
MetaSimplifier.rewrite_goal_tac |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2197 |
(map (fn th => th RS @{thm sym} RS @{thm eq_reflection}) prems') 1 |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2198 |
end) ctxt 1 |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2199 |
| Abs _ => raise Fail "prove_param: No valid parameter term" |
32667 | 2200 |
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
|
2201 |
REPEAT_DETERM (rtac @{thm ext} 1) |
35886 | 2202 |
THEN print_tac options "prove_param" |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2203 |
THEN f_tac |
35886 | 2204 |
THEN print_tac options "after prove_param" |
32667 | 2205 |
THEN (REPEAT_DETERM (atac 1)) |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2206 |
THEN (EVERY (map2 (prove_param options ctxt nargs) ho_args param_derivations)) |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2207 |
THEN REPEAT_DETERM (rtac @{thm refl} 1) |
32667 | 2208 |
end |
2209 |
||
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2210 |
fun prove_expr options ctxt nargs (premposition : int) (t, deriv) = |
32667 | 2211 |
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
|
2212 |
(Const (name, T), args) => |
32667 | 2213 |
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
|
2214 |
val mode = head_mode_of deriv |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2215 |
val introrule = predfun_intro_of ctxt 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
|
2216 |
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
|
2217 |
val ho_args = ho_args_of mode args |
32667 | 2218 |
in |
35886 | 2219 |
print_tac options "before intro rule:" |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2220 |
THEN rtac introrule 1 |
35886 | 2221 |
THEN print_tac options "after intro rule" |
32667 | 2222 |
(* for the right assumption in first position *) |
2223 |
THEN rotate_tac premposition 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
|
2224 |
THEN atac 1 |
35886 | 2225 |
THEN print_tac options "parameter goal" |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2226 |
(* work with parameter arguments *) |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2227 |
THEN (EVERY (map2 (prove_param options ctxt nargs) ho_args param_derivations)) |
32667 | 2228 |
THEN (REPEAT_DETERM (atac 1)) |
2229 |
end |
|
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2230 |
| (Free _, _) => |
35886 | 2231 |
print_tac options "proving parameter call.." |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2232 |
THEN Subgoal.FOCUS_PREMS (fn {context = ctxt, params, prems, asms, concl, schematics} => |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2233 |
let |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2234 |
val param_prem = nth prems premposition |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2235 |
val (param, _) = strip_comb (HOLogic.dest_Trueprop (prop_of param_prem)) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2236 |
val prems' = maps dest_conjunct_prem (take nargs prems) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2237 |
fun param_rewrite prem = |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2238 |
param = snd (HOLogic.dest_eq (HOLogic.dest_Trueprop (prop_of prem))) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2239 |
val SOME rew_eq = find_first param_rewrite prems' |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2240 |
val param_prem' = MetaSimplifier.rewrite_rule |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2241 |
(map (fn th => th RS @{thm eq_reflection}) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2242 |
[rew_eq RS @{thm sym}, @{thm split_beta}, @{thm fst_conv}, @{thm snd_conv}]) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2243 |
param_prem |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2244 |
in |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2245 |
rtac param_prem' 1 |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2246 |
end) ctxt 1 |
35886 | 2247 |
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
|
2248 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2249 |
fun SOLVED tac st = FILTER (fn st' => nprems_of st' = nprems_of st - 1) tac st; |
32667 | 2250 |
|
2251 |
fun SOLVEDALL tac st = FILTER (fn st' => nprems_of st' = 0) tac st |
|
2252 |
||
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2253 |
fun check_format ctxt st = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2254 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2255 |
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
|
2256 |
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
|
2257 |
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
|
2258 |
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
|
2259 |
| 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
|
2260 |
| 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
|
2261 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2262 |
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
|
2263 |
((*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
|
2264 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2265 |
((*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
|
2266 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2267 |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2268 |
fun prove_match options ctxt 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
|
2269 |
let |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2270 |
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
|
2271 |
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
|
2272 |
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
|
2273 |
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
|
2274 |
((fst o dest_Type o fastype_of) t))) |
39194
c8406125193b
handling collection of simprules as sets rather than as lists
bulwahn
parents:
39193
diff
changeset
|
2275 |
in fold (union Thm.eq_thm) (case_rewrites :: map get_case_rewrite (snd (strip_comb t))) [] 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
|
2276 |
else [] |
39194
c8406125193b
handling collection of simprules as sets rather than as lists
bulwahn
parents:
39193
diff
changeset
|
2277 |
val simprules = insert Thm.eq_thm @{thm "unit.cases"} (insert Thm.eq_thm @{thm "prod.cases"} |
c8406125193b
handling collection of simprules as sets rather than as lists
bulwahn
parents:
39193
diff
changeset
|
2278 |
(fold (union Thm.eq_thm) (map get_case_rewrite 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
|
2279 |
(* 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
|
2280 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2281 |
(* 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
|
2282 |
asm_full_simp_tac (HOL_basic_ss' addsimps simprules) 1 |
35886 | 2283 |
THEN print_tac options "after prove_match:" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2284 |
THEN (DETERM (TRY (EqSubst.eqsubst_tac ctxt [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
|
2285 |
THEN (REPEAT_DETERM (rtac @{thm conjI} 1 THEN (SOLVED (asm_simp_tac HOL_basic_ss' 1)))) |
35886 | 2286 |
THEN print_tac options "if condition to be solved:" |
2287 |
THEN (SOLVED (asm_simp_tac HOL_basic_ss' 1 THEN print_tac options "after if simp; in SOLVED:")) |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2288 |
THEN check_format thy |
35886 | 2289 |
THEN print_tac options "after if simplification - a TRY block"))) |
2290 |
THEN print_tac options "after if simplification" |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2291 |
end; |
32667 | 2292 |
|
2293 |
(* corresponds to compile_fun -- maybe call that also compile_sidecond? *) |
|
2294 |
||
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2295 |
fun prove_sidecond ctxt t = |
32667 | 2296 |
let |
2297 |
fun preds_of t nameTs = case strip_comb t of |
|
2298 |
(f as Const (name, T), args) => |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2299 |
if is_registered ctxt name then (name, T) :: nameTs |
32667 | 2300 |
else fold preds_of args nameTs |
2301 |
| _ => nameTs |
|
2302 |
val preds = preds_of t [] |
|
2303 |
val defs = map |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2304 |
(fn (pred, T) => predfun_definition_of ctxt 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
|
2305 |
(all_input_of T)) |
32667 | 2306 |
preds |
2307 |
in |
|
2308 |
simp_tac (HOL_basic_ss addsimps |
|
39649
7186d338f2e1
removing duplicate rewrite rule from simpset in predicate compiler
bulwahn
parents:
39648
diff
changeset
|
2309 |
(@{thms HOL.simp_thms} @ (@{thm eval_pred} :: defs))) 1 |
32667 | 2310 |
(* need better control here! *) |
2311 |
end |
|
2312 |
||
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2313 |
fun prove_clause options ctxt nargs mode (_, clauses) (ts, moded_ps) = |
32667 | 2314 |
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
|
2315 |
val (in_ts, clause_out_ts) = split_mode mode ts; |
32667 | 2316 |
fun prove_prems out_ts [] = |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2317 |
(prove_match options ctxt out_ts) |
35886 | 2318 |
THEN print_tac options "before simplifying assumptions" |
32667 | 2319 |
THEN asm_full_simp_tac HOL_basic_ss' 1 |
35886 | 2320 |
THEN print_tac options "before single intro rule" |
32667 | 2321 |
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
|
2322 |
| prove_prems out_ts ((p, deriv) :: ps) = |
32667 | 2323 |
let |
2324 |
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
|
2325 |
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
|
2326 |
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
|
2327 |
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
|
2328 |
THEN (case p of Prem t => |
32667 | 2329 |
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
|
2330 |
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
|
2331 |
val (_, out_ts''') = split_mode mode us |
32667 | 2332 |
val rec_tac = prove_prems out_ts''' ps |
2333 |
in |
|
35886 | 2334 |
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
|
2335 |
(*THEN asm_simp_tac HOL_basic_ss 1*) |
35886 | 2336 |
THEN print_tac options "before prove_expr:" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2337 |
THEN prove_expr options ctxt nargs premposition (t, deriv) |
35886 | 2338 |
THEN print_tac options "after prove_expr:" |
32667 | 2339 |
THEN rec_tac |
2340 |
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
|
2341 |
| Negprem t => |
32667 | 2342 |
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
|
2343 |
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
|
2344 |
val (_, out_ts''') = split_mode mode args |
32667 | 2345 |
val rec_tac = prove_prems out_ts''' ps |
2346 |
val name = (case strip_comb t of (Const (c, _), _) => SOME c | _ => NONE) |
|
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2347 |
val neg_intro_rule = |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2348 |
Option.map (fn name => |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2349 |
the (predfun_neg_intro_of ctxt name mode)) 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
|
2350 |
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
|
2351 |
val params = ho_args_of mode args |
32667 | 2352 |
in |
35886 | 2353 |
print_tac options "before prove_neg_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
|
2354 |
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
|
2355 |
[@{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
|
2356 |
@{thm snd_conv}, @{thm pair_collapse}, @{thm Product_Type.split_conv}]) 1 |
32667 | 2357 |
THEN (if (is_some name) then |
35886 | 2358 |
print_tac options "before applying not introduction rule" |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2359 |
THEN rotate_tac premposition 1 |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2360 |
THEN etac (the neg_intro_rule) 1 |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2361 |
THEN rotate_tac (~premposition) 1 |
35886 | 2362 |
THEN print_tac options "after applying not introduction rule" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2363 |
THEN (EVERY (map2 (prove_param options ctxt nargs) params param_derivations)) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2364 |
THEN (REPEAT_DETERM (atac 1)) |
32667 | 2365 |
else |
35884
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2366 |
rtac @{thm not_predI'} 1 |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2367 |
(* test: *) |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2368 |
THEN dtac @{thm sym} 1 |
362bfc2ca0ee
adding proof procedure for cases rule with tuples; adding introduction rule for negated premises; improving proof procedure with negated premises
bulwahn
parents:
35881
diff
changeset
|
2369 |
THEN asm_full_simp_tac (HOL_basic_ss addsimps [@{thm not_False_eq_True}]) 1) |
32667 | 2370 |
THEN simp_tac (HOL_basic_ss addsimps [@{thm not_False_eq_True}]) 1 |
2371 |
THEN rec_tac |
|
2372 |
end |
|
2373 |
| 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
|
2374 |
rtac @{thm if_predI} 1 |
35886 | 2375 |
THEN print_tac options "before sidecond:" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2376 |
THEN prove_sidecond ctxt t |
35886 | 2377 |
THEN print_tac options "after sidecond:" |
32667 | 2378 |
THEN prove_prems [] ps) |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2379 |
in (prove_match options ctxt out_ts) |
32667 | 2380 |
THEN rest_tac |
2381 |
end; |
|
2382 |
val prems_tac = prove_prems in_ts moded_ps |
|
2383 |
in |
|
35886 | 2384 |
print_tac options "Proving clause..." |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2385 |
THEN rtac @{thm bindI} 1 |
32667 | 2386 |
THEN rtac @{thm singleI} 1 |
2387 |
THEN prems_tac |
|
2388 |
end; |
|
2389 |
||
2390 |
fun select_sup 1 1 = [] |
|
2391 |
| select_sup _ 1 = [rtac @{thm supI1}] |
|
2392 |
| select_sup n i = (rtac @{thm supI2})::(select_sup (n - 1) (i - 1)); |
|
2393 |
||
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2394 |
fun prove_one_direction options ctxt clauses preds pred mode moded_clauses = |
32667 | 2395 |
let |
2396 |
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
|
2397 |
val nargs = length (binder_types T) |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
2398 |
val pred_case_rule = the_elim_of ctxt pred |
32667 | 2399 |
in |
2400 |
REPEAT_DETERM (CHANGED (rewtac @{thm "split_paired_all"})) |
|
35886 | 2401 |
THEN print_tac options "before applying elim rule" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2402 |
THEN etac (predfun_elim_of ctxt pred mode) 1 |
32667 | 2403 |
THEN etac pred_case_rule 1 |
35886 | 2404 |
THEN print_tac options "after applying elim rule" |
32667 | 2405 |
THEN (EVERY (map |
2406 |
(fn i => EVERY' (select_sup (length moded_clauses) i) i) |
|
2407 |
(1 upto (length moded_clauses)))) |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2408 |
THEN (EVERY (map2 (prove_clause options ctxt nargs mode) clauses moded_clauses)) |
35886 | 2409 |
THEN print_tac options "proved one direction" |
32667 | 2410 |
end; |
2411 |
||
2412 |
(** Proof in the other direction **) |
|
2413 |
||
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2414 |
fun prove_match2 options ctxt out_ts = |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2415 |
let |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2416 |
val thy = ProofContext.theory_of ctxt |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2417 |
fun split_term_tac (Free _) = all_tac |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2418 |
| split_term_tac t = |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2419 |
if (is_constructor thy t) then |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2420 |
let |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2421 |
val info = Datatype.the_info thy ((fst o dest_Type o fastype_of) t) |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2422 |
val num_of_constrs = length (#case_rewrites info) |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2423 |
val (_, ts) = strip_comb t |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2424 |
in |
35889
c1f86c5d3827
avoiding fishing for split_asm rule in the predicate compiler
bulwahn
parents:
35888
diff
changeset
|
2425 |
print_tac options ("Term " ^ (Syntax.string_of_term ctxt t) ^ |
c1f86c5d3827
avoiding fishing for split_asm rule in the predicate compiler
bulwahn
parents:
35888
diff
changeset
|
2426 |
"splitting with rules \n" ^ Display.string_of_thm ctxt (#split_asm info)) |
c1f86c5d3827
avoiding fishing for split_asm rule in the predicate compiler
bulwahn
parents:
35888
diff
changeset
|
2427 |
THEN TRY ((Splitter.split_asm_tac [#split_asm info] 1) |
c1f86c5d3827
avoiding fishing for split_asm rule in the predicate compiler
bulwahn
parents:
35888
diff
changeset
|
2428 |
THEN (print_tac options "after splitting with split_asm rules") |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2429 |
(* THEN (Simplifier.asm_full_simp_tac HOL_basic_ss 1) |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2430 |
THEN (DETERM (TRY (etac @{thm Pair_inject} 1)))*) |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2431 |
THEN (REPEAT_DETERM_N (num_of_constrs - 1) |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2432 |
(etac @{thm botE} 1 ORELSE etac @{thm botE} 2))) |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2433 |
THEN (assert_tac (Max_number_of_subgoals 2)) |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2434 |
THEN (EVERY (map split_term_tac ts)) |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2435 |
end |
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2436 |
else all_tac |
32667 | 2437 |
in |
33148
0808f7d0d0d7
removed tuple functions from the predicate compiler
bulwahn
parents:
33147
diff
changeset
|
2438 |
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
|
2439 |
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
|
2440 |
THEN (etac @{thm botE} 2)))) |
32667 | 2441 |
end |
2442 |
||
2443 |
(* VERY LARGE SIMILIRATIY to function prove_param |
|
2444 |
-- join both functions |
|
2445 |
*) |
|
2446 |
(* TODO: remove function *) |
|
2447 |
||
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2448 |
fun prove_param2 options ctxt t deriv = |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2449 |
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
|
2450 |
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
|
2451 |
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
|
2452 |
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
|
2453 |
val ho_args = ho_args_of mode args |
32667 | 2454 |
val f_tac = case f of |
2455 |
Const (name, T) => full_simp_tac (HOL_basic_ss addsimps |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2456 |
(@{thm eval_pred}::(predfun_definition_of ctxt name mode) |
32667 | 2457 |
:: @{thm "Product_Type.split_conv"}::[])) 1 |
2458 |
| Free _ => all_tac |
|
2459 |
| _ => error "prove_param2: illegal parameter term" |
|
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2460 |
in |
35886 | 2461 |
print_tac options "before simplification in prove_args:" |
32667 | 2462 |
THEN f_tac |
35886 | 2463 |
THEN print_tac options "after simplification in prove_args" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2464 |
THEN EVERY (map2 (prove_param2 options ctxt) ho_args param_derivations) |
32667 | 2465 |
end |
2466 |
||
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2467 |
fun prove_expr2 options ctxt (t, deriv) = |
32667 | 2468 |
(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
|
2469 |
(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
|
2470 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2471 |
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
|
2472 |
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
|
2473 |
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
|
2474 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2475 |
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
|
2476 |
THEN (REPEAT_DETERM (CHANGED (rewtac @{thm "split_paired_all"}))) |
35886 | 2477 |
THEN print_tac options "prove_expr2-before" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2478 |
THEN etac (predfun_elim_of ctxt name mode) 1 |
35886 | 2479 |
THEN print_tac options "prove_expr2" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2480 |
THEN (EVERY (map2 (prove_param2 options ctxt) ho_args param_derivations)) |
35886 | 2481 |
THEN print_tac options "finished prove_expr2" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2482 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2483 |
| _ => 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
|
2484 |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2485 |
fun prove_sidecond2 options ctxt t = let |
32667 | 2486 |
fun preds_of t nameTs = case strip_comb t of |
2487 |
(f as Const (name, T), args) => |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2488 |
if is_registered ctxt name then (name, T) :: nameTs |
32667 | 2489 |
else fold preds_of args nameTs |
2490 |
| _ => nameTs |
|
2491 |
val preds = preds_of t [] |
|
2492 |
val defs = map |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2493 |
(fn (pred, T) => predfun_definition_of ctxt 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
|
2494 |
(all_input_of T)) |
32667 | 2495 |
preds |
2496 |
in |
|
2497 |
(* only simplify the one assumption *) |
|
2498 |
full_simp_tac (HOL_basic_ss' addsimps @{thm eval_pred} :: defs) 1 |
|
2499 |
(* need better control here! *) |
|
35886 | 2500 |
THEN print_tac options "after sidecond2 simplification" |
32667 | 2501 |
end |
2502 |
||
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2503 |
fun prove_clause2 options ctxt pred mode (ts, ps) i = |
32667 | 2504 |
let |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
2505 |
val pred_intro_rule = nth (intros_of ctxt 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
|
2506 |
val (in_ts, clause_out_ts) = split_mode mode ts; |
37544
456dd03e8cce
more precise tactic: do not escape to a different goal branch (REPEAT is still problematic, though)
haftmann
parents:
37391
diff
changeset
|
2507 |
val split_ss = HOL_basic_ss' addsimps [@{thm split_eta}, @{thm split_beta}, |
456dd03e8cce
more precise tactic: do not escape to a different goal branch (REPEAT is still problematic, though)
haftmann
parents:
37391
diff
changeset
|
2508 |
@{thm fst_conv}, @{thm snd_conv}, @{thm pair_collapse}] |
32667 | 2509 |
fun prove_prems2 out_ts [] = |
35886 | 2510 |
print_tac options "before prove_match2 - last call:" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2511 |
THEN prove_match2 options ctxt out_ts |
35886 | 2512 |
THEN print_tac options "after prove_match2 - last call:" |
32667 | 2513 |
THEN (etac @{thm singleE} 1) |
2514 |
THEN (REPEAT_DETERM (etac @{thm Pair_inject} 1)) |
|
2515 |
THEN (asm_full_simp_tac HOL_basic_ss' 1) |
|
2516 |
THEN (REPEAT_DETERM (etac @{thm Pair_inject} 1)) |
|
2517 |
THEN (asm_full_simp_tac HOL_basic_ss' 1) |
|
35886 | 2518 |
THEN SOLVED (print_tac options "state before applying intro rule:" |
37544
456dd03e8cce
more precise tactic: do not escape to a different goal branch (REPEAT is still problematic, though)
haftmann
parents:
37391
diff
changeset
|
2519 |
THEN (rtac pred_intro_rule |
32667 | 2520 |
(* How to handle equality correctly? *) |
37544
456dd03e8cce
more precise tactic: do not escape to a different goal branch (REPEAT is still problematic, though)
haftmann
parents:
37391
diff
changeset
|
2521 |
THEN_ALL_NEW (K (print_tac options "state before assumption matching") |
37558 | 2522 |
THEN' (atac ORELSE' ((CHANGED o asm_full_simp_tac split_ss) THEN' (TRY o atac))) |
2523 |
THEN' (K (print_tac options "state after pre-simplification:")) |
|
37544
456dd03e8cce
more precise tactic: do not escape to a different goal branch (REPEAT is still problematic, though)
haftmann
parents:
37391
diff
changeset
|
2524 |
THEN' (K (print_tac options "state after assumption matching:")))) 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
|
2525 |
| prove_prems2 out_ts ((p, deriv) :: ps) = |
32667 | 2526 |
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
|
2527 |
val mode = head_mode_of deriv |
32667 | 2528 |
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
|
2529 |
Prem t => |
32667 | 2530 |
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
|
2531 |
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
|
2532 |
val (_, out_ts''') = split_mode mode us |
32667 | 2533 |
val rec_tac = prove_prems2 out_ts''' ps |
2534 |
in |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2535 |
(prove_expr2 options ctxt (t, deriv)) THEN rec_tac |
32667 | 2536 |
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
|
2537 |
| Negprem t => |
32667 | 2538 |
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
|
2539 |
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
|
2540 |
val (_, out_ts''') = split_mode mode args |
32667 | 2541 |
val rec_tac = prove_prems2 out_ts''' ps |
2542 |
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
|
2543 |
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
|
2544 |
val ho_args = ho_args_of mode args |
32667 | 2545 |
in |
35886 | 2546 |
print_tac options "before neg prem 2" |
32667 | 2547 |
THEN etac @{thm bindE} 1 |
2548 |
THEN (if is_some name then |
|
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2549 |
full_simp_tac (HOL_basic_ss addsimps |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2550 |
[predfun_definition_of ctxt (the name) mode]) 1 |
32667 | 2551 |
THEN etac @{thm not_predE} 1 |
2552 |
THEN simp_tac (HOL_basic_ss addsimps [@{thm not_False_eq_True}]) 1 |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2553 |
THEN (EVERY (map2 (prove_param2 options ctxt) ho_args param_derivations)) |
32667 | 2554 |
else |
2555 |
etac @{thm not_predE'} 1) |
|
2556 |
THEN rec_tac |
|
2557 |
end |
|
2558 |
| Sidecond t => |
|
2559 |
etac @{thm bindE} 1 |
|
2560 |
THEN etac @{thm if_predE} 1 |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2561 |
THEN prove_sidecond2 options ctxt t |
32667 | 2562 |
THEN prove_prems2 [] ps) |
35886 | 2563 |
in print_tac options "before prove_match2:" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2564 |
THEN prove_match2 options ctxt out_ts |
35886 | 2565 |
THEN print_tac options "after prove_match2:" |
32667 | 2566 |
THEN rest_tac |
2567 |
end; |
|
2568 |
val prems_tac = prove_prems2 in_ts ps |
|
2569 |
in |
|
35886 | 2570 |
print_tac options "starting prove_clause2" |
32667 | 2571 |
THEN etac @{thm bindE} 1 |
2572 |
THEN (etac @{thm singleE'} 1) |
|
2573 |
THEN (TRY (etac @{thm Pair_inject} 1)) |
|
35886 | 2574 |
THEN print_tac options "after singleE':" |
32667 | 2575 |
THEN prems_tac |
2576 |
end; |
|
2577 |
||
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2578 |
fun prove_other_direction options ctxt pred mode moded_clauses = |
32667 | 2579 |
let |
2580 |
fun prove_clause clause i = |
|
2581 |
(if i < length moded_clauses then etac @{thm supE} 1 else all_tac) |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2582 |
THEN (prove_clause2 options ctxt pred mode clause i) |
32667 | 2583 |
in |
2584 |
(DETERM (TRY (rtac @{thm unit.induct} 1))) |
|
2585 |
THEN (REPEAT_DETERM (CHANGED (rewtac @{thm split_paired_all}))) |
|
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2586 |
THEN (rtac (predfun_intro_of ctxt pred mode) 1) |
32667 | 2587 |
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
|
2588 |
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
|
2589 |
etac @{thm botE} 1 |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2590 |
else EVERY (map2 prove_clause moded_clauses (1 upto (length moded_clauses)))) |
32667 | 2591 |
end; |
2592 |
||
2593 |
(** proof procedure **) |
|
2594 |
||
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
|
2595 |
fun prove_pred options thy clauses preds pred (pol, mode) (moded_clauses, compiled_term) = |
32667 | 2596 |
let |
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36533
diff
changeset
|
2597 |
val ctxt = ProofContext.init_global thy |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2598 |
val clauses = case AList.lookup (op =) clauses pred of SOME rs => rs | NONE => [] |
32667 | 2599 |
in |
2600 |
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
|
2601 |
(if not (skip_proof options) then |
32667 | 2602 |
(fn _ => |
2603 |
rtac @{thm pred_iffI} 1 |
|
35886 | 2604 |
THEN print_tac options "after pred_iffI" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2605 |
THEN prove_one_direction options ctxt clauses preds pred mode moded_clauses |
35886 | 2606 |
THEN print_tac options "proved one direction" |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2607 |
THEN prove_other_direction options ctxt pred mode moded_clauses |
35886 | 2608 |
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
|
2609 |
else (fn _ => Skip_Proof.cheat_tac thy)) |
32667 | 2610 |
end; |
2611 |
||
2612 |
(* composition of mode inference, definition, compilation and proof *) |
|
2613 |
||
2614 |
(** auxillary combinators for table of preds and modes **) |
|
2615 |
||
2616 |
fun map_preds_modes f preds_modes_table = |
|
2617 |
map (fn (pred, modes) => |
|
2618 |
(pred, map (fn (mode, value) => (mode, f pred mode value)) modes)) preds_modes_table |
|
2619 |
||
2620 |
fun join_preds_modes table1 table2 = |
|
2621 |
map_preds_modes (fn pred => fn mode => fn value => |
|
2622 |
(value, the (AList.lookup (op =) (the (AList.lookup (op =) table2 pred)) mode))) table1 |
|
36254 | 2623 |
|
32667 | 2624 |
fun maps_modes preds_modes_table = |
2625 |
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
|
2626 |
(pred, map (fn (mode, value) => value) modes)) preds_modes_table |
36254 | 2627 |
|
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
2628 |
fun compile_preds options comp_modifiers ctxt all_vs param_vs preds moded_clauses = |
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
2629 |
map_preds_modes (fn pred => compile_pred options comp_modifiers ctxt all_vs param_vs pred |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2630 |
(the (AList.lookup (op =) preds pred))) moded_clauses |
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2631 |
|
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
|
2632 |
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
|
2633 |
map_preds_modes (prove_pred options thy clauses preds) |
32667 | 2634 |
(join_preds_modes moded_clauses compiled_terms) |
2635 |
||
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
|
2636 |
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
|
2637 |
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
|
2638 |
(fn pred => fn mode => fn t => Drule.export_without_context (Skip_Proof.make_thm thy t)) |
32667 | 2639 |
compiled_terms |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2640 |
|
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2641 |
(* preparation of introduction rules into special datastructures *) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2642 |
fun dest_prem ctxt params t = |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2643 |
(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
|
2644 |
(v as Free _, ts) => if member (op =) params v then Prem t else Sidecond t |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2645 |
| (c as Const (@{const_name Not}, _), [t]) => (case dest_prem ctxt 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
|
2646 |
Prem t => Negprem t |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2647 |
| Negprem _ => error ("Double negation not allowed in premise: " ^ |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2648 |
Syntax.string_of_term ctxt (c $ t)) |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2649 |
| Sidecond t => Sidecond (c $ t)) |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2650 |
| (c as Const (s, _), ts) => |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2651 |
if is_registered ctxt 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
|
2652 |
| _ => 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
|
2653 |
|
39310
17ef4415b17c
removing obsolete argument in prepare_intrs; passing context instead of theory in prepare_intrs
bulwahn
parents:
39299
diff
changeset
|
2654 |
fun prepare_intrs options ctxt prednames intros = |
32667 | 2655 |
let |
39310
17ef4415b17c
removing obsolete argument in prepare_intrs; passing context instead of theory in prepare_intrs
bulwahn
parents:
39299
diff
changeset
|
2656 |
val thy = ProofContext.theory_of ctxt |
33126
bb8806eb5da7
importing of polymorphic introduction rules with different schematic variable names
bulwahn
parents:
33124
diff
changeset
|
2657 |
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
|
2658 |
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
|
2659 |
val (preds, intrs) = unify_consts thy preds intrs |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2660 |
val ([preds, intrs], _) = fold_burrow (Variable.import_terms false) [preds, intrs] ctxt |
33126
bb8806eb5da7
importing of polymorphic introduction rules with different schematic variable names
bulwahn
parents:
33124
diff
changeset
|
2661 |
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
|
2662 |
val all_vs = terms_vs intrs |
39201
234e6ef4ff67
using the proposed modes for starting the fixpoint iteration in the mode analysis
bulwahn
parents:
39194
diff
changeset
|
2663 |
fun generate_modes s T = |
234e6ef4ff67
using the proposed modes for starting the fixpoint iteration in the mode analysis
bulwahn
parents:
39194
diff
changeset
|
2664 |
if member (op =) (no_higher_order_predicate options) s then |
234e6ef4ff67
using the proposed modes for starting the fixpoint iteration in the mode analysis
bulwahn
parents:
39194
diff
changeset
|
2665 |
all_smodes_of_typ T |
234e6ef4ff67
using the proposed modes for starting the fixpoint iteration in the mode analysis
bulwahn
parents:
39194
diff
changeset
|
2666 |
else |
234e6ef4ff67
using the proposed modes for starting the fixpoint iteration in the mode analysis
bulwahn
parents:
39194
diff
changeset
|
2667 |
all_modes_of_typ 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
|
2668 |
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
|
2669 |
map (fn (s, T) => |
39382
c797f3ab2ae1
proposed modes for code_pred now supports modes for mutual predicates
bulwahn
parents:
39310
diff
changeset
|
2670 |
(s, case proposed_modes options s of |
39651
2e06dad03dd3
adding check if user-given modes match type of predicates; removed useless function expand_tuples_elim
bulwahn
parents:
39649
diff
changeset
|
2671 |
SOME ms => check_matches_type ctxt s T ms |
39201
234e6ef4ff67
using the proposed modes for starting the fixpoint iteration in the mode analysis
bulwahn
parents:
39194
diff
changeset
|
2672 |
| NONE => generate_modes s 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
|
2673 |
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
|
2674 |
case intrs of |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2675 |
[] => |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
2676 |
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
|
2677 |
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
|
2678 |
val paramTs = |
39299
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
bulwahn
parents:
39273
diff
changeset
|
2679 |
ho_argsT_of_typ (binder_types T) |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2680 |
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
|
2681 |
(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
|
2682 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2683 |
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
|
2684 |
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
|
2685 |
| (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
|
2686 |
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
|
2687 |
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
|
2688 |
in |
39382
c797f3ab2ae1
proposed modes for code_pred now supports modes for mutual predicates
bulwahn
parents:
39310
diff
changeset
|
2689 |
ho_args_of_typ (snd (dest_Const p)) 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
|
2690 |
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
|
2691 |
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
|
2692 |
fun add_clause intr clauses = |
32667 | 2693 |
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
|
2694 |
val (Const (name, T), ts) = strip_comb (HOLogic.dest_Trueprop (Logic.strip_imp_concl intr)) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2695 |
val prems = map (dest_prem ctxt params o HOLogic.dest_Trueprop) (Logic.strip_imp_prems intr) |
32667 | 2696 |
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
|
2697 |
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
|
2698 |
[(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
|
2699 |
end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2700 |
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
|
2701 |
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
|
2702 |
(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
|
2703 |
end; |
32667 | 2704 |
|
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2705 |
(* 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
|
2706 |
(* 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
|
2707 |
(* |
33106
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2708 |
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
|
2709 |
let |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2710 |
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
|
2711 |
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
|
2712 |
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
|
2713 |
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
|
2714 |
(Ts as _ :: _ :: _) => |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2715 |
if length (HOLogic.strip_tuple arg) = length Ts then |
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2716 |
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
|
2717 |
else |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2718 |
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
|
2719 |
^ (Syntax.string_of_term_global thy arg) ^ " in " ^ |
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2720 |
(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
|
2721 |
| _ => true |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2722 |
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
|
2723 |
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
|
2724 |
| 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
|
2725 |
| check_prem _ = true |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2726 |
in |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2727 |
forall check_arg args andalso |
7a1636c3ffc9
extended core of predicate compiler to expand tuples in introduction rules
bulwahn
parents:
32740
diff
changeset
|
2728 |
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
|
2729 |
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
|
2730 |
*) |
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2731 |
(* |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2732 |
fun check_intros_elim_match thy prednames = |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2733 |
let |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2734 |
fun check predname = |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2735 |
let |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2736 |
val intros = intros_of thy predname |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2737 |
val elim = the_elim_of thy predname |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2738 |
val nparams = nparams_of thy predname |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2739 |
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
|
2740 |
(Drule.export_without_context o Skip_Proof.make_thm thy) |
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36533
diff
changeset
|
2741 |
(mk_casesrule (ProofContext.init_global thy) nparams intros) |
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2742 |
in |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2743 |
if not (Thm.equiv_thm (elim, elim')) then |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2744 |
error "Introduction and elimination rules do not match!" |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2745 |
else true |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2746 |
end |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2747 |
in forall check prednames end |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2748 |
*) |
33113 | 2749 |
|
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2750 |
(* create code equation *) |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2751 |
|
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
2752 |
fun add_code_equations ctxt preds result_thmss = |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2753 |
let |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2754 |
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
|
2755 |
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
|
2756 |
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
|
2757 |
in |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2758 |
if member (op =) (modes_of Pred ctxt predname) full_mode then |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2759 |
let |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2760 |
val Ts = binder_types T |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2761 |
val arg_names = Name.variant_list [] |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2762 |
(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
|
2763 |
val args = map2 (curry Free) arg_names Ts |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2764 |
val predfun = Const (function_name_of Pred ctxt predname full_mode, |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2765 |
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
|
2766 |
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
|
2767 |
val eq_term = HOLogic.mk_Trueprop |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2768 |
(HOLogic.mk_eq (list_comb (Const (predname, T), args), rhs)) |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2769 |
val def = predfun_definition_of ctxt predname full_mode |
33441
99a5f22a967d
eliminated funny record patterns and made SML/NJ happy;
wenzelm
parents:
33377
diff
changeset
|
2770 |
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
|
2771 |
(HOL_basic_ss addsimps [def, @{thm holds_eq}, @{thm eval_pred}]) 1 |
35888
d902054e7ac6
contextifying the proof procedure in the predicate compiler
bulwahn
parents:
35887
diff
changeset
|
2772 |
val eq = Goal.prove ctxt arg_names [] eq_term tac |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2773 |
in |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2774 |
(pred, result_thms @ [eq]) |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2775 |
end |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2776 |
else |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2777 |
(pred, result_thms) |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2778 |
end |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2779 |
in |
33629
5f35cf91c6a4
improving code quality thanks to Florian's code review
bulwahn
parents:
33628
diff
changeset
|
2780 |
map2 add_code_equation preds result_thmss |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2781 |
end |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2782 |
|
32667 | 2783 |
(** main function of predicate compiler **) |
2784 |
||
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2785 |
datatype steps = Steps of |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2786 |
{ |
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
|
2787 |
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
|
2788 |
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
|
2789 |
-> moded_clause list pred_mode_table -> term pred_mode_table -> thm pred_mode_table, |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
2790 |
add_code_equations : Proof.context -> (string * typ) list |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2791 |
-> (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
|
2792 |
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
|
2793 |
use_random : bool, |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2794 |
qname : bstring |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2795 |
} |
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2796 |
|
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
|
2797 |
fun add_equations_of steps mode_analysis_options options prednames thy = |
32667 | 2798 |
let |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2799 |
fun dest_steps (Steps s) = s |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2800 |
val compilation = Comp_Mod.compilation (#comp_modifiers (dest_steps steps)) |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
2801 |
val ctxt = ProofContext.init_global thy |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2802 |
val _ = print_step options |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2803 |
("Starting predicate compiler (compilation: " ^ string_of_compilation compilation |
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2804 |
^ ") for predicates " ^ commas prednames ^ "...") |
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
2805 |
(*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
|
2806 |
(*val _ = map (check_format_of_intro_rule thy) (maps (intros_of thy) prednames)*) |
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
|
2807 |
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
|
2808 |
if show_intermediate_results options then |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
2809 |
tracing (commas (map (Display.string_of_thm ctxt) (maps (intros_of ctxt) prednames))) |
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
|
2810 |
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
|
2811 |
val (preds, all_vs, param_vs, all_modes, clauses) = |
39310
17ef4415b17c
removing obsolete argument in prepare_intrs; passing context instead of theory in prepare_intrs
bulwahn
parents:
39299
diff
changeset
|
2812 |
prepare_intrs options ctxt prednames (maps (intros_of ctxt) prednames) |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33120
diff
changeset
|
2813 |
val _ = print_step options "Infering modes..." |
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
2814 |
val (lookup_mode, lookup_neg_mode, needs_random) = (modes_of compilation ctxt, |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
2815 |
modes_of (negative_compilation_of compilation) ctxt, needs_random ctxt) |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
2816 |
val ((moded_clauses, needs_random), errors) = |
37009 | 2817 |
Output.cond_timeit (!Quickcheck.timing) "Infering modes" |
36251
5fd5d732a4ea
only add relevant predicates to the list of extra modes
bulwahn
parents:
36247
diff
changeset
|
2818 |
(fn _ => infer_modes mode_analysis_options |
39273
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
2819 |
options (lookup_mode, lookup_neg_mode, needs_random) ctxt preds all_modes param_vs clauses) |
92aa2a0f7399
refactoring mode inference so that the theory is not changed in the mode inference procedure
bulwahn
parents:
39201
diff
changeset
|
2820 |
val thy' = fold (fn (s, ms) => set_needs_random s ms) needs_random 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
|
2821 |
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
|
2822 |
val _ = check_expected_modes preds options modes |
39201
234e6ef4ff67
using the proposed modes for starting the fixpoint iteration in the mode analysis
bulwahn
parents:
39194
diff
changeset
|
2823 |
val _ = check_proposed_modes preds options modes errors |
37004 | 2824 |
val _ = print_modes options modes |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33120
diff
changeset
|
2825 |
val _ = print_step options "Defining executable functions..." |
36252 | 2826 |
val thy'' = |
36261
01ccbaa3f49f
make profiling depend on reference Quickcheck.timing
bulwahn
parents:
36258
diff
changeset
|
2827 |
Output.cond_timeit (!Quickcheck.timing) "Defining executable functions..." |
36252 | 2828 |
(fn _ => fold (#define_functions (dest_steps steps) options preds) modes thy' |
2829 |
|> Theory.checkpoint) |
|
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
2830 |
val ctxt'' = ProofContext.init_global thy'' |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33120
diff
changeset
|
2831 |
val _ = print_step options "Compiling equations..." |
32667 | 2832 |
val compiled_terms = |
36261
01ccbaa3f49f
make profiling depend on reference Quickcheck.timing
bulwahn
parents:
36258
diff
changeset
|
2833 |
Output.cond_timeit (!Quickcheck.timing) "Compiling equations...." (fn _ => |
36254 | 2834 |
compile_preds options |
37005
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
2835 |
(#comp_modifiers (dest_steps steps)) ctxt'' all_vs param_vs preds moded_clauses) |
842a73dc6d0e
changing compilation to work only with contexts; adapting quickcheck
bulwahn
parents:
37004
diff
changeset
|
2836 |
val _ = print_compiled_terms options ctxt'' compiled_terms |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33120
diff
changeset
|
2837 |
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
|
2838 |
val result_thms = |
36261
01ccbaa3f49f
make profiling depend on reference Quickcheck.timing
bulwahn
parents:
36258
diff
changeset
|
2839 |
Output.cond_timeit (!Quickcheck.timing) "Proving equations...." (fn _ => |
36252 | 2840 |
#prove (dest_steps steps) options thy'' clauses preds moded_clauses compiled_terms) |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
2841 |
val result_thms' = #add_code_equations (dest_steps steps) ctxt'' preds |
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
2842 |
(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
|
2843 |
val qname = #qname (dest_steps steps) |
32667 | 2844 |
val attrib = fn thy => Attrib.attribute_i thy (Attrib.internal (K (Thm.declaration_attribute |
2845 |
(fn thm => Context.mapping (Code.add_eqn thm) I)))) |
|
36252 | 2846 |
val thy''' = |
36261
01ccbaa3f49f
make profiling depend on reference Quickcheck.timing
bulwahn
parents:
36258
diff
changeset
|
2847 |
Output.cond_timeit (!Quickcheck.timing) "Setting code equations...." (fn _ => |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39545
diff
changeset
|
2848 |
fold (fn (name, result_thms) => fn thy => snd (Global_Theory.add_thmss |
32667 | 2849 |
[((Binding.qualify true (Long_Name.base_name name) (Binding.name qname), result_thms), |
2850 |
[attrib thy ])] thy)) |
|
36252 | 2851 |
result_thms' thy'' |> Theory.checkpoint) |
32667 | 2852 |
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
|
2853 |
thy''' |
32667 | 2854 |
end |
2855 |
||
2856 |
fun extend' value_of edges_of key (G, visited) = |
|
2857 |
let |
|
2858 |
val (G', v) = case try (Graph.get_node G) key of |
|
2859 |
SOME v => (G, v) |
|
2860 |
| 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
|
2861 |
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
|
2862 |
(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
|
2863 |
(G', key :: visited) |
32667 | 2864 |
in |
2865 |
(fold (Graph.add_edge o (pair key)) (edges_of (key, v)) G'', visited') |
|
2866 |
end; |
|
2867 |
||
2868 |
fun extend value_of edges_of key G = fst (extend' value_of edges_of key (G, [])) |
|
2869 |
||
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
2870 |
fun gen_add_equations steps options names thy = |
32667 | 2871 |
let |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2872 |
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
|
2873 |
val defined = defined_functions (Comp_Mod.compilation (#comp_modifiers (dest_steps steps))) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2874 |
val ctxt = ProofContext.init_global thy |
33482
5029ec373036
strictly respecting the line margin in the predicate compiler core
bulwahn
parents:
33479
diff
changeset
|
2875 |
val thy' = thy |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
2876 |
|> PredData.map (fold (extend (fetch_pred_data ctxt) (depending_preds_of ctxt)) names) |
32667 | 2877 |
|> Theory.checkpoint; |
2878 |
fun strong_conn_of gr keys = |
|
2879 |
Graph.strong_conn (Graph.subgraph (member (op =) (Graph.all_succs gr keys)) gr) |
|
2880 |
val scc = strong_conn_of (PredData.get thy') names |
|
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2881 |
fun preprocess name thy = |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2882 |
PredData.map (Graph.map_node name (map_pred_data (apfst (fn (rules, preprocessed) => |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2883 |
if preprocessed then (rules, preprocessed) |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2884 |
else |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2885 |
let |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2886 |
val (named_intros, SOME elim) = rules |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2887 |
val named_intros' = map (apsnd (preprocess_intro thy)) named_intros |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2888 |
val pred = Const (name, Sign.the_const_type thy name) |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2889 |
val ctxt = ProofContext.init_global thy |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2890 |
val elim_t = mk_casesrule ctxt pred (map snd named_intros') |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2891 |
val nparams = (case try (Inductive.the_inductive ctxt) name of |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2892 |
SOME (_, result) => length (Inductive.params_of (#raw_induct result)) |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2893 |
| NONE => 0) |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2894 |
val elim' = prove_casesrule ctxt (pred, (elim, 0)) elim_t |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2895 |
in |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2896 |
((named_intros', SOME elim'), true) |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2897 |
end)))) |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2898 |
thy |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2899 |
val thy'' = fold preprocess (flat scc) thy' |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2900 |
val thy''' = fold_rev |
32667 | 2901 |
(fn preds => fn thy => |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
2902 |
if not (forall (defined (ProofContext.init_global 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
|
2903 |
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
|
2904 |
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
|
2905 |
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
|
2906 |
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
|
2907 |
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
|
2908 |
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
|
2909 |
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
|
2910 |
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
|
2911 |
else thy) |
39657
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2912 |
scc thy'' |> Theory.checkpoint |
5e57675b7e40
moving the preprocessing of introduction rules after the code_pred command; added tuple expansion preprocessing of elimination rule
bulwahn
parents:
39653
diff
changeset
|
2913 |
in thy''' end |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2914 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2915 |
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
|
2916 |
(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
|
2917 |
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
|
2918 |
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
|
2919 |
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
|
2920 |
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
|
2921 |
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
|
2922 |
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
|
2923 |
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
|
2924 |
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
|
2925 |
qname = "equation"}) |
33143
730a2e8a6ec6
modularized the compilation in the predicate compiler
bulwahn
parents:
33141
diff
changeset
|
2926 |
|
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
|
2927 |
val add_depth_limited_equations = gen_add_equations |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2928 |
(Steps { |
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2929 |
define_functions = |
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2930 |
fn options => fn preds => fn (s, modes) => |
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2931 |
define_functions depth_limited_comp_modifiers PredicateCompFuns.compfuns |
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2932 |
options preds (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes), |
32667 | 2933 |
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
|
2934 |
add_code_equations = K (K I), |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2935 |
comp_modifiers = depth_limited_comp_modifiers, |
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2936 |
use_random = false, |
33330
d6eb7f19bfc6
encapsulating records with datatype constructors and adding type annotations to make SML/NJ happy
bulwahn
parents:
33328
diff
changeset
|
2937 |
qname = "depth_limited_equation"}) |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
2938 |
|
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2939 |
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
|
2940 |
(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
|
2941 |
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
|
2942 |
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
|
2943 |
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
|
2944 |
(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
|
2945 |
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
|
2946 |
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
|
2947 |
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
|
2948 |
use_random = false, |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33377
diff
changeset
|
2949 |
qname = "annotated_equation"}) |
35880
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
2950 |
|
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
2951 |
val add_random_equations = gen_add_equations |
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
2952 |
(Steps { |
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
2953 |
define_functions = |
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
2954 |
fn options => fn preds => fn (s, modes) => |
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
2955 |
define_functions random_comp_modifiers PredicateCompFuns.compfuns options preds |
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
2956 |
(s, map_filter (fn (true, m) => SOME m | _ => NONE) modes), |
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
2957 |
comp_modifiers = random_comp_modifiers, |
32667 | 2958 |
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
|
2959 |
add_code_equations = K (K I), |
35880
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
2960 |
use_random = true, |
33375 | 2961 |
qname = "random_equation"}) |
35880
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
2962 |
|
35881
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2963 |
val add_depth_limited_random_equations = gen_add_equations |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2964 |
(Steps { |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2965 |
define_functions = |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2966 |
fn options => fn preds => fn (s, modes) => |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2967 |
define_functions depth_limited_random_comp_modifiers PredicateCompFuns.compfuns options preds |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2968 |
(s, map_filter (fn (true, m) => SOME m | _ => NONE) modes), |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2969 |
comp_modifiers = depth_limited_random_comp_modifiers, |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2970 |
prove = prove_by_skip, |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2971 |
add_code_equations = K (K I), |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2972 |
use_random = true, |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2973 |
qname = "depth_limited_random_equation"}) |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
2974 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2975 |
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
|
2976 |
(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
|
2977 |
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
|
2978 |
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
|
2979 |
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
|
2980 |
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
|
2981 |
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
|
2982 |
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
|
2983 |
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
|
2984 |
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
|
2985 |
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
|
2986 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
2987 |
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
|
2988 |
(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
|
2989 |
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
|
2990 |
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
|
2991 |
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
|
2992 |
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
|
2993 |
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
|
2994 |
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
|
2995 |
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
|
2996 |
#> 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
|
2997 |
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
|
2998 |
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
|
2999 |
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
|
3000 |
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
|
3001 |
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
|
3002 |
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
|
3003 |
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
|
3004 |
|
36018 | 3005 |
val add_new_random_dseq_equations = gen_add_equations |
3006 |
(Steps { |
|
3007 |
define_functions = |
|
3008 |
fn options => fn preds => fn (s, modes) => |
|
3009 |
let |
|
3010 |
val pos_modes = map_filter (fn (true, m) => SOME m | _ => NONE) modes |
|
3011 |
val neg_modes = map_filter (fn (false, m) => SOME m | _ => NONE) modes |
|
3012 |
in define_functions new_pos_random_dseq_comp_modifiers New_Pos_Random_Sequence_CompFuns.compfuns |
|
3013 |
options preds (s, pos_modes) |
|
3014 |
#> define_functions new_neg_random_dseq_comp_modifiers New_Neg_Random_Sequence_CompFuns.compfuns |
|
3015 |
options preds (s, neg_modes) |
|
3016 |
end, |
|
3017 |
prove = prove_by_skip, |
|
3018 |
add_code_equations = K (K I), |
|
3019 |
comp_modifiers = new_pos_random_dseq_comp_modifiers, |
|
3020 |
use_random = true, |
|
3021 |
qname = "new_random_dseq_equation"}) |
|
32667 | 3022 |
|
3023 |
(** user interface **) |
|
3024 |
||
3025 |
(* code_pred_intro attribute *) |
|
3026 |
||
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
3027 |
fun attrib' f opt_case_name = |
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
3028 |
Thm.declaration_attribute (fn thm => Context.mapping (f (opt_case_name, thm)) I); |
32667 | 3029 |
|
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
3030 |
val code_pred_intro_attrib = attrib' add_intro NONE; |
32667 | 3031 |
|
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
3032 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
3033 |
(*FIXME |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
3034 |
- Naming of auxiliary rules necessary? |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
3035 |
*) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
3036 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
3037 |
val setup = PredData.put (Graph.empty) #> |
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
3038 |
Attrib.setup @{binding code_pred_intro} (Scan.lift (Scan.option Args.name) >> attrib' add_intro) |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
3039 |
"adding alternative introduction rules for code generation of inductive predicates" |
32667 | 3040 |
|
33522 | 3041 |
(* TODO: make Theory_Data to Generic_Data & remove duplication of local theory and theory *) |
38757
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38558
diff
changeset
|
3042 |
(* FIXME ... this is important to avoid changing the background theory below *) |
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
3043 |
fun generic_code_pred prep_const options raw_const lthy = |
32667 | 3044 |
let |
3045 |
val thy = ProofContext.theory_of lthy |
|
3046 |
val const = prep_const thy raw_const |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3047 |
val ctxt = ProofContext.init_global thy |
38757
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38558
diff
changeset
|
3048 |
val lthy' = Local_Theory.background_theory (PredData.map |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
3049 |
(extend (fetch_pred_data ctxt) (depending_preds_of ctxt) const)) lthy |
32667 | 3050 |
val thy' = ProofContext.theory_of lthy' |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
3051 |
val ctxt' = ProofContext.init_global thy' |
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
3052 |
val preds = Graph.all_succs (PredData.get thy') [const] |> filter_out (has_elim ctxt') |
32667 | 3053 |
fun mk_cases const = |
3054 |
let |
|
39299
e98a06145530
directly computing the values of interest instead of composing functions in an unintelligent way that causes exponential much garbage; using the latest theory
bulwahn
parents:
39273
diff
changeset
|
3055 |
val T = Sign.the_const_type thy' const |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33145
diff
changeset
|
3056 |
val pred = Const (const, T) |
37007
116670499530
changing operations for accessing data to work with contexts
bulwahn
parents:
37006
diff
changeset
|
3057 |
val intros = intros_of ctxt' 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
|
3058 |
in mk_casesrule lthy' pred intros end |
32667 | 3059 |
val cases_rules = map mk_cases preds |
3060 |
val cases = |
|
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
3061 |
map2 (fn pred_name => fn case_rule => Rule_Cases.Case {fixes = [], |
39652 | 3062 |
assumes = ("that", tl (Logic.strip_imp_prems case_rule)) |
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
3063 |
:: (map_filter (fn (fact_name, fact) => Option.map (rpair [fact]) fact_name) |
39652 | 3064 |
((SOME (Long_Name.base_name pred_name ^ ".prems") :: names_of ctxt' pred_name) ~~ Logic.strip_imp_prems case_rule)), |
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
3065 |
binds = [], cases = []}) preds cases_rules |
32667 | 3066 |
val case_env = map2 (fn p => fn c => (Long_Name.base_name p, SOME c)) preds cases |
3067 |
val lthy'' = lthy' |
|
39545
631cf48c7894
code_pred_intro can be used to name facts for the code_pred command
bulwahn
parents:
39477
diff
changeset
|
3068 |
|> fold Variable.auto_fixes cases_rules |
32667 | 3069 |
|> ProofContext.add_cases true case_env |
3070 |
fun after_qed thms goal_ctxt = |
|
3071 |
let |
|
3072 |
val global_thms = ProofContext.export goal_ctxt |
|
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36533
diff
changeset
|
3073 |
(ProofContext.init_global (ProofContext.theory_of goal_ctxt)) (map the_single thms) |
32667 | 3074 |
in |
38757
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38558
diff
changeset
|
3075 |
goal_ctxt |> Local_Theory.background_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
|
3076 |
((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
|
3077 |
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
|
3078 |
| DSeq => add_dseq_equations |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
3079 |
| Pos_Random_DSeq => add_random_dseq_equations |
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
3080 |
| Depth_Limited => add_depth_limited_equations |
35880
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
3081 |
| Random => add_random_equations |
35881
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
3082 |
| Depth_Limited_Random => add_depth_limited_random_equations |
36018 | 3083 |
| New_Pos_Random_DSeq => add_new_random_dseq_equations |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3084 |
| 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
|
3085 |
) options [const])) |
33144
1831516747d4
removed obsolete GeneratorPrem; clean-up after modularization; tuned
bulwahn
parents:
33143
diff
changeset
|
3086 |
end |
32667 | 3087 |
in |
36323
655e2d74de3a
modernized naming conventions of main Isar proof elements;
wenzelm
parents:
36261
diff
changeset
|
3088 |
Proof.theorem NONE after_qed (map (single o (rpair [])) cases_rules) lthy'' |
32667 | 3089 |
end; |
3090 |
||
3091 |
val code_pred = generic_code_pred (K I); |
|
3092 |
val code_pred_cmd = generic_code_pred Code.read_const |
|
3093 |
||
3094 |
(* transformation for code generation *) |
|
3095 |
||
39388
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3096 |
structure Pred_Result = Proof_Data ( |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3097 |
type T = unit -> term Predicate.pred |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3098 |
fun init _ () = error "Pred_Result" |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3099 |
); |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3100 |
val put_pred_result = Pred_Result.put; |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3101 |
|
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3102 |
structure Pred_Random_Result = Proof_Data ( |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3103 |
type T = unit -> int * int -> term Predicate.pred * (int * int) |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3104 |
fun init _ () = error "Pred_Random_Result" |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3105 |
); |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3106 |
val put_pred_random_result = Pred_Random_Result.put; |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3107 |
|
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3108 |
structure Dseq_Result = Proof_Data ( |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3109 |
type T = unit -> term DSequence.dseq |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3110 |
fun init _ () = error "Dseq_Result" |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3111 |
); |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3112 |
val put_dseq_result = Dseq_Result.put; |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3113 |
|
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3114 |
structure Dseq_Random_Result = Proof_Data ( |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3115 |
type T = unit -> int -> int -> int * int -> term DSequence.dseq * (int * int) |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3116 |
fun init _ () = error "Dseq_Random_Result" |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3117 |
); |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3118 |
val put_dseq_random_result = Dseq_Random_Result.put; |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3119 |
|
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3120 |
structure Lseq_Random_Result = Proof_Data ( |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3121 |
type T = unit -> int -> int -> int * int -> int -> term Lazy_Sequence.lazy_sequence |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3122 |
fun init _ () = error "Lseq_Random_Result" |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3123 |
); |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3124 |
val put_lseq_random_result = Lseq_Random_Result.put; |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3125 |
|
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3126 |
structure Lseq_Random_Stats_Result = Proof_Data ( |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3127 |
type T = unit -> int -> int -> int * int -> int -> (term * int) Lazy_Sequence.lazy_sequence |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3128 |
fun init _ () = error "Lseq_Random_Stats_Result" |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3129 |
); |
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3130 |
val put_lseq_random_stats_result = Lseq_Random_Stats_Result.put; |
32667 | 3131 |
|
3132 |
(*FIXME turn this into an LCF-guarded preprocessor for comprehensions*) |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3133 |
fun analyze_compr ctxt compfuns param_user_modes (compilation, arguments) t_compr = |
32667 | 3134 |
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
|
3135 |
val all_modes_of = all_modes_of compilation |
32667 | 3136 |
val split = case t_compr of (Const (@{const_name Collect}, _) $ t) => t |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3137 |
| _ => error ("Not a set comprehension: " ^ Syntax.string_of_term ctxt t_compr); |
32667 | 3138 |
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
|
3139 |
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
|
3140 |
(map (fn i => "x" ^ string_of_int i) (1 upto length Ts)) |
34963 | 3141 |
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
|
3142 |
val body = subst_bounds (output_frees, body) |
34963 | 3143 |
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
|
3144 |
val output_tuple = HOLogic.mk_ptuple fp T_compr (rev output_frees) |
36031
199fe16cdaab
returning an more understandable user error message in the values command
bulwahn
parents:
36030
diff
changeset
|
3145 |
val (pred as Const (name, T), all_args) = |
199fe16cdaab
returning an more understandable user error message in the values command
bulwahn
parents:
36030
diff
changeset
|
3146 |
case strip_comb body of |
199fe16cdaab
returning an more understandable user error message in the values command
bulwahn
parents:
36030
diff
changeset
|
3147 |
(Const (name, T), all_args) => (Const (name, T), all_args) |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3148 |
| (head, _) => error ("Not a constant: " ^ Syntax.string_of_term ctxt head) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3149 |
in |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3150 |
if defined_functions compilation ctxt name then |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
32667
diff
changeset
|
3151 |
let |
37391 | 3152 |
fun extract_mode (Const (@{const_name Pair}, _) $ t1 $ t2) = Pair (extract_mode t1, extract_mode t2) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3153 |
| 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
|
3154 |
| 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
|
3155 |
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
|
3156 |
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
|
3157 |
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
|
3158 |
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
|
3159 |
| 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
|
3160 |
| 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
|
3161 |
(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
|
3162 |
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
|
3163 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3164 |
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
|
3165 |
| 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
|
3166 |
| 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
|
3167 |
| 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
|
3168 |
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
|
3169 |
| 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
|
3170 |
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
|
3171 |
| 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
|
3172 |
instance_of (m1, Output) andalso instance_of (m2, Output) |
37002
34e73e8bab66
improved values command to handle a special case with tuples and polymorphic predicates more correctly
bulwahn
parents:
37001
diff
changeset
|
3173 |
| instance_of (Input, Pair (m1, m2)) = |
34e73e8bab66
improved values command to handle a special case with tuples and polymorphic predicates more correctly
bulwahn
parents:
37001
diff
changeset
|
3174 |
instance_of (Input, m1) andalso instance_of (Input, m2) |
34e73e8bab66
improved values command to handle a special case with tuples and polymorphic predicates more correctly
bulwahn
parents:
37001
diff
changeset
|
3175 |
| instance_of (Output, Pair (m1, m2)) = |
34e73e8bab66
improved values command to handle a special case with tuples and polymorphic predicates more correctly
bulwahn
parents:
37001
diff
changeset
|
3176 |
instance_of (Output, m1) andalso instance_of (Output, 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
|
3177 |
| 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
|
3178 |
in forall instance_of (strip_fun_mode m1 ~~ strip_fun_mode m2) end |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3179 |
val derivs = all_derivations_of ctxt (all_modes_of ctxt) [] body |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3180 |
|> 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
|
3181 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3182 |
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
|
3183 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3184 |
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
|
3185 |
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
|
3186 |
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
|
3187 |
end) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3188 |
|> 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
|
3189 |
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
|
3190 |
[] => error ("No mode possible for comprehension " |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3191 |
^ Syntax.string_of_term ctxt t_compr) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3192 |
| [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
|
3193 |
| d :: _ :: _ => (warning ("Multiple modes possible for comprehension " |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3194 |
^ Syntax.string_of_term ctxt t_compr); d); |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3195 |
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
|
3196 |
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
|
3197 |
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
|
3198 |
Pred => [] |
35880
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
3199 |
| Random => map (HOLogic.mk_number @{typ "code_numeral"}) arguments @ |
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
3200 |
[@{term "(1, 1) :: code_numeral * code_numeral"}] |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3201 |
| Annotated => [] |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
3202 |
| Depth_Limited => [HOLogic.mk_number @{typ "code_numeral"} (hd arguments)] |
35881
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
3203 |
| Depth_Limited_Random => map (HOLogic.mk_number @{typ "code_numeral"}) arguments @ |
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
3204 |
[@{term "(1, 1) :: code_numeral * code_numeral"}] |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3205 |
| DSeq => [] |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
3206 |
| Pos_Random_DSeq => [] |
36020
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
3207 |
| New_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
|
3208 |
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
|
3209 |
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
|
3210 |
Pred => predicate_comp_modifiers |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
3211 |
| Random => random_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
|
3212 |
| Depth_Limited => depth_limited_comp_modifiers |
35881
aa412e08bfee
adding depth_limited_random compilation to predicate compiler
bulwahn
parents:
35880
diff
changeset
|
3213 |
| Depth_Limited_Random => depth_limited_random_comp_modifiers |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
3214 |
(*| Annotated => annotated_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
|
3215 |
| DSeq => dseq_comp_modifiers |
35879
99818df5b8f5
reviving the classical depth-limited computation in the predicate compiler
bulwahn
parents:
35845
diff
changeset
|
3216 |
| Pos_Random_DSeq => pos_random_dseq_comp_modifiers |
36020
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
3217 |
| New_Pos_Random_DSeq => new_pos_random_dseq_comp_modifiers |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3218 |
val t_pred = compile_expr comp_modifiers ctxt |
39648
655307cb8489
rewriting function mk_Eval_of in predicate compiler
bulwahn
parents:
39557
diff
changeset
|
3219 |
(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
|
3220 |
val T_pred = dest_predT compfuns (fastype_of t_pred) |
39756
6c8e83d94536
consolidated tupled_lambda; moved to structure HOLogic
krauss
parents:
39685
diff
changeset
|
3221 |
val arrange = HOLogic.tupled_lambda (HOLogic.mk_tuple outargs) output_tuple |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3222 |
in |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3223 |
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
|
3224 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3225 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3226 |
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
|
3227 |
end |
32667 | 3228 |
|
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3229 |
fun eval ctxt stats param_user_modes (options as (compilation, arguments)) k t_compr = |
32667 | 3230 |
let |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3231 |
fun count xs x = |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3232 |
let |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3233 |
fun count' i [] = i |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3234 |
| count' i (x' :: xs) = if x = x' then count' (i + 1) xs else count' i xs |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3235 |
in count' 0 xs end |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3236 |
fun accumulate xs = map (fn x => (x, count xs x)) (sort int_ord (distinct (op =) xs)) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3237 |
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
|
3238 |
case compilation of |
35880
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
3239 |
Random => 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
|
3240 |
| 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
|
3241 |
| Pos_Random_DSeq => Random_Sequence_CompFuns.compfuns |
36020
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
3242 |
| New_Pos_Random_DSeq => New_Pos_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
|
3243 |
| _ => PredicateCompFuns.compfuns |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3244 |
val t = analyze_compr ctxt 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
|
3245 |
val T = dest_predT compfuns (fastype_of t); |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3246 |
val t' = |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3247 |
if stats andalso compilation = New_Pos_Random_DSeq then |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3248 |
mk_map compfuns T (HOLogic.mk_prodT (HOLogic.termT, @{typ code_numeral})) |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3249 |
(absdummy (T, HOLogic.mk_prod (HOLogic.term_of_const T $ Bound 0, |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3250 |
@{term Code_Numeral.of_nat} $ (HOLogic.size_const T $ Bound 0)))) t |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3251 |
else |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3252 |
mk_map compfuns T HOLogic.termT (HOLogic.term_of_const T) t |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3253 |
val thy = ProofContext.theory_of ctxt |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3254 |
val (ts, statistics) = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3255 |
case compilation of |
35880
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
3256 |
(* Random => |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3257 |
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
|
3258 |
(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
|
3259 |
(fn proc => fn g => fn s => g s |>> Predicate.map proc) thy t' [] |
35880
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
3260 |
|> Random_Engine.run))*) |
2623b23e41fc
a new simpler random compilation for the predicate compiler
bulwahn
parents:
35879
diff
changeset
|
3261 |
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
|
3262 |
let |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3263 |
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
|
3264 |
in |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3265 |
rpair NONE (fst (DSequence.yieldn k |
39471 | 3266 |
(Code_Runtime.dynamic_value_strict (Dseq_Random_Result.get, put_dseq_random_result, "Predicate_Compile_Core.put_dseq_random_result") |
3267 |
thy NONE (fn proc => fn g => fn nrandom => fn size => fn s => g nrandom size s |>> DSequence.map proc) |
|
3268 |
t' [] nrandom size |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3269 |
|> Random_Engine.run) |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3270 |
depth 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
|
3271 |
end |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3272 |
| DSeq => |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3273 |
rpair NONE (fst (DSequence.yieldn k |
39471 | 3274 |
(Code_Runtime.dynamic_value_strict (Dseq_Result.get, put_dseq_result, "Predicate_Compile_Core.put_dseq_result") |
3275 |
thy NONE DSequence.map t' []) (the_single arguments) true)) |
|
36020
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
3276 |
| New_Pos_Random_DSeq => |
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
3277 |
let |
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
3278 |
val [nrandom, size, depth] = arguments |
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
3279 |
val seed = Random_Engine.next_seed () |
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
3280 |
in |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3281 |
if stats then |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3282 |
apsnd (SOME o accumulate) (split_list |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3283 |
(fst (Lazy_Sequence.yieldn k |
39471 | 3284 |
(Code_Runtime.dynamic_value_strict |
39388
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3285 |
(Lseq_Random_Stats_Result.get, put_lseq_random_stats_result, "Predicate_Compile_Core.put_lseq_random_stats_result") |
39471 | 3286 |
thy NONE |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3287 |
(fn proc => fn g => fn nrandom => fn size => fn s => fn depth => g nrandom size s depth |
36533 | 3288 |
|> Lazy_Sequence.mapa (apfst proc)) |
39471 | 3289 |
t' [] nrandom size seed depth)))) |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3290 |
else rpair NONE |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3291 |
(fst (Lazy_Sequence.yieldn k |
39471 | 3292 |
(Code_Runtime.dynamic_value_strict |
39388
fdbb2c55ffc2
replaced ML_Context.evaluate by ML_Context.value -- using context data instead of bare metal references
haftmann
parents:
39310
diff
changeset
|
3293 |
(Lseq_Random_Result.get, put_lseq_random_result, "Predicate_Compile_Core.put_lseq_random_result") |
39471 | 3294 |
thy NONE |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3295 |
(fn proc => fn g => fn nrandom => fn size => fn s => fn depth => g nrandom size s depth |
36533 | 3296 |
|> Lazy_Sequence.mapa proc) |
39471 | 3297 |
t' [] nrandom size seed depth))) |
36020
3ee4c29ead7f
adding values command for new monad; added new random monad compilation to predicate_compile_quickcheck
bulwahn
parents:
36019
diff
changeset
|
3298 |
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
|
3299 |
| _ => |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3300 |
rpair NONE (fst (Predicate.yieldn k |
39471 | 3301 |
(Code_Runtime.dynamic_value_strict (Pred_Result.get, put_pred_result, "Predicate_Compile_Core.put_pred_result") |
3302 |
thy NONE Predicate.map t' []))) |
|
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3303 |
in ((T, ts), statistics) end; |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3304 |
|
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3305 |
fun values ctxt param_user_modes ((raw_expected, stats), comp_options) k t_compr = |
32667 | 3306 |
let |
37003
a393a588b82e
moving towards working with proof contexts in the predicate compiler
bulwahn
parents:
37002
diff
changeset
|
3307 |
val ((T, ts), statistics) = eval ctxt stats param_user_modes comp_options k t_compr |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3308 |
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
|
3309 |
val elems = HOLogic.mk_set T ts |
33476 | 3310 |
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
|
3311 |
(* 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
|
3312 |
val () = |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3313 |
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
|
3314 |
NONE => () |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3315 |
| 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
|
3316 |
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
|
3317 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
34028
diff
changeset
|
3318 |
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
|
3319 |
"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
|
3320 |
"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
|
3321 |
in |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3322 |
(if k = ~1 orelse length ts < k then elems |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3323 |
else Const (@{const_abbrev Set.union}, setT --> setT --> setT) $ elems $ cont, statistics) |
32667 | 3324 |
end; |
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
3325 |
|
33479
428ddcc16e7b
added optional mode annotations for parameters in the values command
bulwahn
parents:
33478
diff
changeset
|
3326 |
fun values_cmd print_modes param_user_modes options k raw_t state = |
32667 | 3327 |
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
|
3328 |
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
|
3329 |
val t = Syntax.read_term ctxt raw_t |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3330 |
val (t', stats) = values ctxt param_user_modes options k 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
|
3331 |
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
|
3332 |
val ctxt' = Variable.auto_fixes t' ctxt |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3333 |
val pretty_stat = |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3334 |
case stats of |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3335 |
NONE => [] |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3336 |
| SOME xs => |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3337 |
let |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3338 |
val total = fold (curry (op +)) (map snd xs) 0 |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3339 |
fun pretty_entry (s, n) = |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3340 |
[Pretty.str "size", Pretty.brk 1, |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3341 |
Pretty.str (string_of_int s), Pretty.str ":", Pretty.brk 1, |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3342 |
Pretty.str (string_of_int n), Pretty.fbrk] |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3343 |
in |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3344 |
[Pretty.fbrk, Pretty.str "Statistics:", Pretty.fbrk, |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3345 |
Pretty.str "total:", Pretty.brk 1, Pretty.str (string_of_int total), Pretty.fbrk] |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3346 |
@ maps pretty_entry xs |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3347 |
end |
37146
f652333bbf8e
renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
wenzelm
parents:
37135
diff
changeset
|
3348 |
val p = Print_Mode.with_modes print_modes (fn () => |
36027
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3349 |
Pretty.block ([Pretty.quote (Syntax.pretty_term ctxt' t'), Pretty.fbrk, |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3350 |
Pretty.str "::", Pretty.brk 1, Pretty.quote (Syntax.pretty_typ ctxt' ty')] |
29a15da9c63d
added statistics to values command for random generation
bulwahn
parents:
36025
diff
changeset
|
3351 |
@ pretty_stat)) (); |
32667 | 3352 |
in Pretty.writeln p end; |
3353 |
||
3354 |
end; |