author | kuncar |
Tue, 18 Nov 2014 16:19:57 +0100 | |
changeset 60221 | 45545e6c0984 |
parent 60219 | 2bce9a690b1e |
child 60224 | e759afe46a8c |
permissions | -rw-r--r-- |
47308 | 1 |
(* Title: HOL/Tools/Lifting/lifting_def.ML |
2 |
Author: Ondrej Kuncar |
|
3 |
||
4 |
Definitions for constants on quotient types. |
|
5 |
*) |
|
6 |
||
7 |
signature LIFTING_DEF = |
|
8 |
sig |
|
60219 | 9 |
type lift_def |
10 |
val rty_of_lift_def: lift_def -> typ |
|
11 |
val qty_of_lift_def: lift_def -> typ |
|
12 |
val rhs_of_lift_def: lift_def -> term |
|
13 |
val lift_const_of_lift_def: lift_def -> term |
|
14 |
val def_thm_of_lift_def: lift_def -> thm |
|
15 |
val rsp_thm_of_lift_def: lift_def -> thm |
|
16 |
val abs_eq_of_lift_def: lift_def -> thm |
|
17 |
val rep_eq_of_lift_def: lift_def -> thm option |
|
18 |
val transfer_rules_of_lift_def: lift_def -> thm list |
|
19 |
||
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
20 |
val generate_parametric_transfer_rule: |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
21 |
Proof.context -> thm -> thm -> thm |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
22 |
|
47308 | 23 |
val add_lift_def: |
60219 | 24 |
binding * mixfix -> typ -> term -> thm -> thm list -> local_theory -> lift_def * local_theory |
60218 | 25 |
|
26 |
val lift_def: |
|
27 |
binding * mixfix -> typ -> term -> (Proof.context -> tactic) -> thm list -> |
|
60219 | 28 |
local_theory -> lift_def * local_theory |
47308 | 29 |
|
30 |
val lift_def_cmd: |
|
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
57664
diff
changeset
|
31 |
(binding * string option * mixfix) * string * (Facts.ref * Token.src list) list -> |
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
57664
diff
changeset
|
32 |
local_theory -> Proof.state |
47308 | 33 |
|
34 |
val can_generate_code_cert: thm -> bool |
|
53651 | 35 |
end |
47308 | 36 |
|
37 |
structure Lifting_Def: LIFTING_DEF = |
|
38 |
struct |
|
39 |
||
47698 | 40 |
open Lifting_Util |
47308 | 41 |
|
42 |
infix 0 MRSL |
|
43 |
||
60219 | 44 |
datatype lift_def = LIFT_DEF of { |
45 |
rty: typ, |
|
46 |
qty: typ, |
|
47 |
rhs: term, |
|
48 |
lift_const: term, |
|
49 |
def_thm: thm, |
|
50 |
rsp_thm: thm, |
|
51 |
abs_eq: thm, |
|
52 |
rep_eq: thm option, |
|
53 |
transfer_rules: thm list |
|
54 |
}; |
|
55 |
||
56 |
fun rep_lift_def (LIFT_DEF lift_def) = lift_def; |
|
57 |
val rty_of_lift_def = #rty o rep_lift_def; |
|
58 |
val qty_of_lift_def = #qty o rep_lift_def; |
|
59 |
val rhs_of_lift_def = #rhs o rep_lift_def; |
|
60 |
val lift_const_of_lift_def = #lift_const o rep_lift_def; |
|
61 |
val def_thm_of_lift_def = #def_thm o rep_lift_def; |
|
62 |
val rsp_thm_of_lift_def = #rsp_thm o rep_lift_def; |
|
63 |
val abs_eq_of_lift_def = #abs_eq o rep_lift_def; |
|
64 |
val rep_eq_of_lift_def = #rep_eq o rep_lift_def; |
|
65 |
val transfer_rules_of_lift_def = #transfer_rules o rep_lift_def; |
|
66 |
||
67 |
fun mk_lift_def rty qty rhs lift_const def_thm rsp_thm abs_eq rep_eq transfer_rules = |
|
68 |
LIFT_DEF {rty = rty, qty = qty, |
|
69 |
rhs = rhs, lift_const = lift_const, |
|
70 |
def_thm = def_thm, rsp_thm = rsp_thm, abs_eq = abs_eq, rep_eq = rep_eq, |
|
71 |
transfer_rules = transfer_rules }; |
|
72 |
||
51994 | 73 |
(* Reflexivity prover *) |
74 |
||
55609 | 75 |
fun mono_eq_prover ctxt prop = |
51994 | 76 |
let |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56245
diff
changeset
|
77 |
val refl_rules = Lifting_Info.get_reflexivity_rules ctxt |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56245
diff
changeset
|
78 |
val transfer_rules = Transfer.get_transfer_raw ctxt |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56245
diff
changeset
|
79 |
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59458
diff
changeset
|
80 |
fun main_tac i = (REPEAT_ALL_NEW (DETERM o resolve_tac ctxt refl_rules) THEN_ALL_NEW |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59458
diff
changeset
|
81 |
(REPEAT_ALL_NEW (DETERM o resolve_tac ctxt transfer_rules))) i |
51994 | 82 |
in |
56540 | 83 |
SOME (Goal.prove ctxt [] [] prop (K (main_tac 1))) |
55609 | 84 |
handle ERROR _ => NONE |
51994 | 85 |
end |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56245
diff
changeset
|
86 |
|
57642
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
87 |
fun try_prove_refl_rel ctxt rel = |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
88 |
let |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
89 |
fun mk_ge_eq x = |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
90 |
let |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
91 |
val T = fastype_of x |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
92 |
in |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
93 |
Const (@{const_name "less_eq"}, T --> T --> HOLogic.boolT) $ |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
94 |
(Const (@{const_name HOL.eq}, T)) $ x |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
95 |
end; |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
96 |
val goal = HOLogic.mk_Trueprop (mk_ge_eq rel); |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
97 |
in |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
98 |
mono_eq_prover ctxt goal |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
99 |
end; |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
100 |
|
51994 | 101 |
fun try_prove_reflexivity ctxt prop = |
55609 | 102 |
let |
59630 | 103 |
val cprop = Thm.cterm_of ctxt prop |
55609 | 104 |
val rule = @{thm ge_eq_refl} |
59582 | 105 |
val concl_pat = Drule.strip_imp_concl (Thm.cprop_of rule) |
55609 | 106 |
val insts = Thm.first_order_match (concl_pat, cprop) |
107 |
val rule = Drule.instantiate_normalize insts rule |
|
59582 | 108 |
val prop = hd (Thm.prems_of rule) |
55609 | 109 |
in |
110 |
case mono_eq_prover ctxt prop of |
|
55610
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
111 |
SOME thm => SOME (thm RS rule) |
55609 | 112 |
| NONE => NONE |
113 |
end |
|
51994 | 114 |
|
54335
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
115 |
(* |
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
116 |
Generates a parametrized transfer rule. |
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
117 |
transfer_rule - of the form T t f |
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
118 |
parametric_transfer_rule - of the form par_R t' t |
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
119 |
|
54947 | 120 |
Result: par_T t' f, after substituing op= for relations in par_R that relate |
54335
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
121 |
a type constructor to the same type constructor, it is a merge of (par_R' OO T) t' f |
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
122 |
using Lifting_Term.merge_transfer_relations |
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
123 |
*) |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
124 |
|
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
125 |
fun generate_parametric_transfer_rule ctxt transfer_rule parametric_transfer_rule = |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
126 |
let |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
127 |
fun preprocess ctxt thm = |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
128 |
let |
59582 | 129 |
val tm = (strip_args 2 o HOLogic.dest_Trueprop o Thm.concl_of) thm; |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
130 |
val param_rel = (snd o dest_comb o fst o dest_comb) tm; |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
131 |
val free_vars = Term.add_vars param_rel []; |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
132 |
|
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
133 |
fun make_subst (var as (_, typ)) subst = |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
134 |
let |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
135 |
val [rty, rty'] = binder_types typ |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
136 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
137 |
if (Term.is_TVar rty andalso is_Type rty') then |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
138 |
(Var var, HOLogic.eq_const rty')::subst |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
139 |
else |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
140 |
subst |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
141 |
end; |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
142 |
|
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
143 |
val subst = fold make_subst free_vars []; |
59630 | 144 |
val csubst = map (apply2 (Thm.cterm_of ctxt)) subst; |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
145 |
val inst_thm = Drule.cterm_instantiate csubst thm; |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
146 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
147 |
Conv.fconv_rule |
59582 | 148 |
((Conv.concl_conv (Thm.nprems_of inst_thm) o |
149 |
HOLogic.Trueprop_conv o Conv.fun2_conv o Conv.arg1_conv) |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54335
diff
changeset
|
150 |
(Raw_Simplifier.rewrite ctxt false (Transfer.get_sym_relator_eq ctxt))) inst_thm |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
151 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
152 |
|
59630 | 153 |
fun inst_relcomppI ctxt ant1 ant2 = |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
154 |
let |
59582 | 155 |
val t1 = (HOLogic.dest_Trueprop o Thm.concl_of) ant1 |
156 |
val t2 = (HOLogic.dest_Trueprop o Thm.prop_of) ant2 |
|
59630 | 157 |
val fun1 = Thm.cterm_of ctxt (strip_args 2 t1) |
158 |
val args1 = map (Thm.cterm_of ctxt) (get_args 2 t1) |
|
159 |
val fun2 = Thm.cterm_of ctxt (strip_args 2 t2) |
|
160 |
val args2 = map (Thm.cterm_of ctxt) (get_args 1 t2) |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
161 |
val relcomppI = Drule.incr_indexes2 ant1 ant2 @{thm relcomppI} |
59582 | 162 |
val vars = (rev (Term.add_vars (Thm.prop_of relcomppI) [])) |
59630 | 163 |
val subst = map (apfst (Thm.cterm_of ctxt o Var)) (vars ~~ ([fun1] @ args1 @ [fun2] @ args2)) |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
164 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
165 |
Drule.cterm_instantiate subst relcomppI |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
166 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
167 |
|
54995 | 168 |
fun zip_transfer_rules ctxt thm = |
169 |
let |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
170 |
fun mk_POS ty = Const (@{const_name POS}, ty --> ty --> HOLogic.boolT) |
59582 | 171 |
val rel = (Thm.dest_fun2 o Thm.dest_arg o Thm.cprop_of) thm |
59586 | 172 |
val typ = Thm.typ_of_cterm rel |
59630 | 173 |
val POS_const = Thm.cterm_of ctxt (mk_POS typ) |
174 |
val var = Thm.cterm_of ctxt (Var (("X", Thm.maxidx_of_cterm rel + 1), typ)) |
|
59582 | 175 |
val goal = |
59630 | 176 |
Thm.apply (Thm.cterm_of ctxt HOLogic.Trueprop) (Thm.apply (Thm.apply POS_const rel) var) |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
177 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
178 |
[Lifting_Term.merge_transfer_relations ctxt goal, thm] MRSL @{thm POS_apply} |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
179 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
180 |
|
59630 | 181 |
val thm = |
182 |
inst_relcomppI ctxt parametric_transfer_rule transfer_rule |
|
183 |
OF [parametric_transfer_rule, transfer_rule] |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
184 |
val preprocessed_thm = preprocess ctxt thm |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
185 |
val orig_ctxt = ctxt |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
186 |
val (fixed_thm, ctxt) = yield_singleton (apfst snd oo Variable.import true) preprocessed_thm ctxt |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
187 |
val assms = cprems_of fixed_thm |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
188 |
val add_transfer_rule = Thm.attribute_declaration Transfer.transfer_add |
54995 | 189 |
val (prems, ctxt) = fold_map Thm.assume_hyps assms ctxt |
190 |
val ctxt = Context.proof_map (fold add_transfer_rule prems) ctxt |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
191 |
val zipped_thm = |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
192 |
fixed_thm |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
193 |
|> undisch_all |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
194 |
|> zip_transfer_rules ctxt |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
195 |
|> implies_intr_list assms |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
196 |
|> singleton (Variable.export ctxt orig_ctxt) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
197 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
198 |
zipped_thm |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
199 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
200 |
|
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
201 |
fun print_generate_transfer_info msg = |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
202 |
let |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
203 |
val error_msg = cat_lines |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
204 |
["Generation of a parametric transfer rule failed.", |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
205 |
(Pretty.string_of (Pretty.block |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
206 |
[Pretty.str "Reason:", Pretty.brk 2, msg]))] |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
207 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
208 |
error error_msg |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
209 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
210 |
|
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
211 |
fun map_ter _ x [] = x |
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
212 |
| map_ter f _ xs = map f xs |
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
213 |
|
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
214 |
fun generate_transfer_rules lthy quot_thm rsp_thm def_thm par_thms = |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
215 |
let |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
216 |
val transfer_rule = |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
217 |
([quot_thm, rsp_thm, def_thm] MRSL @{thm Quotient_to_transfer}) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
218 |
|> Lifting_Term.parametrize_transfer_rule lthy |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
219 |
in |
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
220 |
(map_ter (generate_parametric_transfer_rule lthy transfer_rule) [transfer_rule] par_thms |
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
221 |
handle Lifting_Term.MERGE_TRANSFER_REL msg => (print_generate_transfer_info msg; [transfer_rule])) |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
222 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
223 |
|
47698 | 224 |
(* Generation of the code certificate from the rsp theorem *) |
47308 | 225 |
|
226 |
fun get_body_types (Type ("fun", [_, U]), Type ("fun", [_, V])) = get_body_types (U, V) |
|
227 |
| get_body_types (U, V) = (U, V) |
|
228 |
||
229 |
fun get_binder_types (Type ("fun", [T, U]), Type ("fun", [V, W])) = (T, V) :: get_binder_types (U, W) |
|
230 |
| get_binder_types _ = [] |
|
231 |
||
55945 | 232 |
fun get_binder_types_by_rel (Const (@{const_name "rel_fun"}, _) $ _ $ S) (Type ("fun", [T, U]), Type ("fun", [V, W])) = |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
233 |
(T, V) :: get_binder_types_by_rel S (U, W) |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
234 |
| get_binder_types_by_rel _ _ = [] |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
235 |
|
55945 | 236 |
fun get_body_type_by_rel (Const (@{const_name "rel_fun"}, _) $ _ $ S) (Type ("fun", [_, U]), Type ("fun", [_, V])) = |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
237 |
get_body_type_by_rel S (U, V) |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
238 |
| get_body_type_by_rel _ (U, V) = (U, V) |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
239 |
|
57642
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
240 |
fun get_binder_rels (Const (@{const_name "rel_fun"}, _) $ R $ S) = R :: get_binder_rels S |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
241 |
| get_binder_rels _ = [] |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
242 |
|
47308 | 243 |
fun force_rty_type ctxt rty rhs = |
244 |
let |
|
245 |
val thy = Proof_Context.theory_of ctxt |
|
246 |
val rhs_schematic = singleton (Variable.polymorphic ctxt) rhs |
|
247 |
val rty_schematic = fastype_of rhs_schematic |
|
248 |
val match = Sign.typ_match thy (rty_schematic, rty) Vartab.empty |
|
249 |
in |
|
250 |
Envir.subst_term_types match rhs_schematic |
|
251 |
end |
|
252 |
||
253 |
fun unabs_def ctxt def = |
|
254 |
let |
|
59582 | 255 |
val (_, rhs) = Thm.dest_equals (Thm.cprop_of def) |
47308 | 256 |
fun dest_abs (Abs (var_name, T, _)) = (var_name, T) |
257 |
| dest_abs tm = raise TERM("get_abs_var",[tm]) |
|
59582 | 258 |
val (var_name, T) = dest_abs (Thm.term_of rhs) |
47308 | 259 |
val (new_var_names, ctxt') = Variable.variant_fixes [var_name] ctxt |
59630 | 260 |
val refl_thm = Thm.reflexive (Thm.cterm_of ctxt' (Free (hd new_var_names, T))) |
47308 | 261 |
in |
262 |
Thm.combination def refl_thm |> |
|
263 |
singleton (Proof_Context.export ctxt' ctxt) |
|
264 |
end |
|
265 |
||
266 |
fun unabs_all_def ctxt def = |
|
267 |
let |
|
59582 | 268 |
val (_, rhs) = Thm.dest_equals (Thm.cprop_of def) |
269 |
val xs = strip_abs_vars (Thm.term_of rhs) |
|
47308 | 270 |
in |
271 |
fold (K (unabs_def ctxt)) xs def |
|
272 |
end |
|
273 |
||
274 |
val map_fun_unfolded = |
|
275 |
@{thm map_fun_def[abs_def]} |> |
|
276 |
unabs_def @{context} |> |
|
277 |
unabs_def @{context} |> |
|
278 |
Local_Defs.unfold @{context} [@{thm comp_def}] |
|
279 |
||
280 |
fun unfold_fun_maps ctm = |
|
281 |
let |
|
282 |
fun unfold_conv ctm = |
|
283 |
case (Thm.term_of ctm) of |
|
284 |
Const (@{const_name "map_fun"}, _) $ _ $ _ => |
|
285 |
(Conv.arg_conv unfold_conv then_conv Conv.rewr_conv map_fun_unfolded) ctm |
|
286 |
| _ => Conv.all_conv ctm |
|
287 |
in |
|
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
288 |
(Conv.fun_conv unfold_conv) ctm |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
289 |
end |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
290 |
|
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
291 |
fun unfold_fun_maps_beta ctm = |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
292 |
let val try_beta_conv = Conv.try_conv (Thm.beta_conversion false) |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
293 |
in |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
294 |
(unfold_fun_maps then_conv try_beta_conv) ctm |
47308 | 295 |
end |
296 |
||
297 |
fun prove_rel ctxt rsp_thm (rty, qty) = |
|
298 |
let |
|
299 |
val ty_args = get_binder_types (rty, qty) |
|
300 |
fun disch_arg args_ty thm = |
|
301 |
let |
|
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
302 |
val quot_thm = Lifting_Term.prove_quot_thm ctxt args_ty |
47308 | 303 |
in |
304 |
[quot_thm, thm] MRSL @{thm apply_rsp''} |
|
305 |
end |
|
306 |
in |
|
307 |
fold disch_arg ty_args rsp_thm |
|
308 |
end |
|
309 |
||
310 |
exception CODE_CERT_GEN of string |
|
311 |
||
312 |
fun simplify_code_eq ctxt def_thm = |
|
48024 | 313 |
Local_Defs.unfold ctxt [@{thm o_apply}, @{thm map_fun_def}, @{thm id_apply}] def_thm |
47308 | 314 |
|
47852
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
315 |
(* |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
316 |
quot_thm - quotient theorem (Quotient R Abs Rep T). |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
317 |
returns: whether the Lifting package is capable to generate code for the abstract type |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
318 |
represented by quot_thm |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
319 |
*) |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
320 |
|
47308 | 321 |
fun can_generate_code_cert quot_thm = |
47951
8c8a03765de7
quot_del attribute, it allows us to deregister quotient types
kuncar
parents:
47937
diff
changeset
|
322 |
case quot_thm_rel quot_thm of |
47308 | 323 |
Const (@{const_name HOL.eq}, _) => true |
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
324 |
| Const (@{const_name eq_onp}, _) $ _ => true |
47308 | 325 |
| _ => false |
326 |
||
55610
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
327 |
fun generate_rep_eq ctxt def_thm rsp_thm (rty, qty) = |
47308 | 328 |
let |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
329 |
val unfolded_def = Conv.fconv_rule (Conv.arg_conv unfold_fun_maps_beta) def_thm |
47308 | 330 |
val unabs_def = unabs_all_def ctxt unfolded_def |
55610
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
331 |
in |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
332 |
if body_type rty = body_type qty then |
55723 | 333 |
SOME (simplify_code_eq ctxt (unabs_def RS @{thm meta_eq_to_obj_eq})) |
55610
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
334 |
else |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
335 |
let |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
336 |
val quot_thm = Lifting_Term.prove_quot_thm ctxt (get_body_types (rty, qty)) |
55945 | 337 |
val rel_fun = prove_rel ctxt rsp_thm (rty, qty) |
338 |
val rep_abs_thm = [quot_thm, rel_fun] MRSL @{thm Quotient_rep_abs_eq} |
|
55610
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
339 |
in |
59582 | 340 |
case mono_eq_prover ctxt (hd (Thm.prems_of rep_abs_thm)) of |
55610
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
341 |
SOME mono_eq_thm => |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
342 |
let |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
343 |
val rep_abs_eq = mono_eq_thm RS rep_abs_thm |
59630 | 344 |
val rep = Thm.cterm_of ctxt (quot_thm_rep quot_thm) |
55610
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
345 |
val rep_refl = Thm.reflexive rep RS @{thm meta_eq_to_obj_eq} |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
346 |
val repped_eq = [rep_refl, unabs_def RS @{thm meta_eq_to_obj_eq}] MRSL @{thm cong} |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
347 |
val code_cert = [repped_eq, rep_abs_eq] MRSL trans |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
348 |
in |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
349 |
SOME (simplify_code_eq ctxt code_cert) |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
350 |
end |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
351 |
| NONE => NONE |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
352 |
end |
47308 | 353 |
end |
354 |
||
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
355 |
fun generate_abs_eq ctxt def_thm rsp_thm quot_thm = |
47308 | 356 |
let |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
357 |
val abs_eq_with_assms = |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
358 |
let |
47951
8c8a03765de7
quot_del attribute, it allows us to deregister quotient types
kuncar
parents:
47937
diff
changeset
|
359 |
val (rty, qty) = quot_thm_rty_qty quot_thm |
8c8a03765de7
quot_del attribute, it allows us to deregister quotient types
kuncar
parents:
47937
diff
changeset
|
360 |
val rel = quot_thm_rel quot_thm |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
361 |
val ty_args = get_binder_types_by_rel rel (rty, qty) |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
362 |
val body_type = get_body_type_by_rel rel (rty, qty) |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
363 |
val quot_ret_thm = Lifting_Term.prove_quot_thm ctxt body_type |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
364 |
|
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
365 |
val rep_abs_folded_unmapped_thm = |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
366 |
let |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
367 |
val rep_id = [quot_thm, def_thm] MRSL @{thm Quotient_Rep_eq} |
59582 | 368 |
val ctm = Thm.dest_equals_lhs (Thm.cprop_of rep_id) |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
369 |
val unfolded_maps_eq = unfold_fun_maps ctm |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
370 |
val t1 = [quot_thm, def_thm, rsp_thm] MRSL @{thm Quotient_rep_abs_fold_unmap} |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
371 |
val prems_pat = (hd o Drule.cprems_of) t1 |
59582 | 372 |
val insts = Thm.first_order_match (prems_pat, Thm.cprop_of unfolded_maps_eq) |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
373 |
in |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
374 |
unfolded_maps_eq RS (Drule.instantiate_normalize insts t1) |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
375 |
end |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
376 |
in |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
377 |
rep_abs_folded_unmapped_thm |
55945 | 378 |
|> fold (fn _ => fn thm => thm RS @{thm rel_funD2}) ty_args |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
379 |
|> (fn x => x RS (@{thm Quotient_rel_abs2} OF [quot_ret_thm])) |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
380 |
end |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
381 |
|
57642
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
382 |
val prem_rels = get_binder_rels (quot_thm_rel quot_thm); |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
383 |
val proved_assms = prem_rels |> map (try_prove_refl_rel ctxt) |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
384 |
|> map_index (apfst (fn x => x + 1)) |> filter (is_some o snd) |> map (apsnd the) |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
385 |
|> map (apsnd (fn assm => assm RS @{thm ge_eq_refl})) |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
386 |
val abs_eq = fold_rev (fn (i, assm) => fn thm => assm RSN (i, thm)) proved_assms abs_eq_with_assms |
47308 | 387 |
in |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
388 |
simplify_code_eq ctxt abs_eq |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
389 |
end |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
390 |
|
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
391 |
|
55724 | 392 |
fun register_code_eq_thy abs_eq_thm opt_rep_eq_thm (rty, qty) thy = |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
393 |
let |
55724 | 394 |
fun no_abstr (t $ u) = no_abstr t andalso no_abstr u |
395 |
| no_abstr (Abs (_, _, t)) = no_abstr t |
|
396 |
| no_abstr (Const (name, _)) = not (Code.is_abstr thy name) |
|
397 |
| no_abstr _ = true |
|
398 |
fun is_valid_eq eqn = can (Code.assert_eqn thy) (mk_meta_eq eqn, true) |
|
59582 | 399 |
andalso no_abstr (Thm.prop_of eqn) |
55724 | 400 |
fun is_valid_abs_eq abs_eq = can (Code.assert_abs_eqn thy NONE) (mk_meta_eq abs_eq) |
47308 | 401 |
|
402 |
in |
|
55724 | 403 |
if is_valid_eq abs_eq_thm then |
404 |
Code.add_default_eqn abs_eq_thm thy |
|
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
405 |
else |
55724 | 406 |
let |
407 |
val (rty_body, qty_body) = get_body_types (rty, qty) |
|
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
408 |
in |
55724 | 409 |
if rty_body = qty_body then |
410 |
Code.add_default_eqn (the opt_rep_eq_thm) thy |
|
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
411 |
else |
55724 | 412 |
if is_some opt_rep_eq_thm andalso is_valid_abs_eq (the opt_rep_eq_thm) |
413 |
then |
|
59458 | 414 |
Code.add_abs_default_eqn (the opt_rep_eq_thm) thy |
55724 | 415 |
else |
416 |
thy |
|
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
417 |
end |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
418 |
end |
47308 | 419 |
|
55724 | 420 |
local |
59630 | 421 |
fun encode_code_eq ctxt abs_eq opt_rep_eq (rty, qty) = |
55724 | 422 |
let |
59630 | 423 |
fun mk_type typ = typ |> Logic.mk_type |> Thm.cterm_of ctxt |> Drule.mk_term |
55724 | 424 |
in |
425 |
Conjunction.intr_balanced [abs_eq, (the_default TrueI opt_rep_eq), mk_type rty, mk_type qty] |
|
426 |
end |
|
427 |
||
57664
179b9c43fe84
having extra assumptions (typically from a context) means there is no chance to have a valid code equation => skip decoding and registration of the code equations
kuncar
parents:
57663
diff
changeset
|
428 |
exception DECODE |
179b9c43fe84
having extra assumptions (typically from a context) means there is no chance to have a valid code equation => skip decoding and registration of the code equations
kuncar
parents:
57663
diff
changeset
|
429 |
|
55724 | 430 |
fun decode_code_eq thm = |
59582 | 431 |
if Thm.nprems_of thm > 0 then raise DECODE |
57664
179b9c43fe84
having extra assumptions (typically from a context) means there is no chance to have a valid code equation => skip decoding and registration of the code equations
kuncar
parents:
57663
diff
changeset
|
432 |
else |
179b9c43fe84
having extra assumptions (typically from a context) means there is no chance to have a valid code equation => skip decoding and registration of the code equations
kuncar
parents:
57663
diff
changeset
|
433 |
let |
179b9c43fe84
having extra assumptions (typically from a context) means there is no chance to have a valid code equation => skip decoding and registration of the code equations
kuncar
parents:
57663
diff
changeset
|
434 |
val [abs_eq, rep_eq, rty, qty] = Conjunction.elim_balanced 4 thm |
179b9c43fe84
having extra assumptions (typically from a context) means there is no chance to have a valid code equation => skip decoding and registration of the code equations
kuncar
parents:
57663
diff
changeset
|
435 |
val opt_rep_eq = if Thm.eq_thm_prop (rep_eq, TrueI) then NONE else SOME rep_eq |
59582 | 436 |
fun dest_type typ = typ |> Drule.dest_term |> Thm.term_of |> Logic.dest_type |
57664
179b9c43fe84
having extra assumptions (typically from a context) means there is no chance to have a valid code equation => skip decoding and registration of the code equations
kuncar
parents:
57663
diff
changeset
|
437 |
in |
179b9c43fe84
having extra assumptions (typically from a context) means there is no chance to have a valid code equation => skip decoding and registration of the code equations
kuncar
parents:
57663
diff
changeset
|
438 |
(abs_eq, opt_rep_eq, (dest_type rty, dest_type qty)) |
179b9c43fe84
having extra assumptions (typically from a context) means there is no chance to have a valid code equation => skip decoding and registration of the code equations
kuncar
parents:
57663
diff
changeset
|
439 |
end |
55724 | 440 |
|
441 |
fun register_encoded_code_eq thm thy = |
|
442 |
let |
|
443 |
val (abs_eq_thm, opt_rep_eq_thm, (rty, qty)) = decode_code_eq thm |
|
444 |
in |
|
445 |
register_code_eq_thy abs_eq_thm opt_rep_eq_thm (rty, qty) thy |
|
446 |
end |
|
57664
179b9c43fe84
having extra assumptions (typically from a context) means there is no chance to have a valid code equation => skip decoding and registration of the code equations
kuncar
parents:
57663
diff
changeset
|
447 |
handle DECODE => thy |
55724 | 448 |
|
449 |
val register_code_eq_attribute = Thm.declaration_attribute |
|
450 |
(fn thm => Context.mapping (register_encoded_code_eq thm) I) |
|
451 |
val register_code_eq_attrib = Attrib.internal (K register_code_eq_attribute) |
|
57663
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
452 |
|
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
453 |
fun no_no_code ctxt (rty, qty) = |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
454 |
if same_type_constrs (rty, qty) then |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
455 |
forall (no_no_code ctxt) (Targs rty ~~ Targs qty) |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
456 |
else |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
457 |
if is_Type qty then |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
458 |
if Lifting_Info.is_no_code_type ctxt (Tname qty) then false |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
459 |
else |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
460 |
let |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
461 |
val (rty', rtyq) = Lifting_Term.instantiate_rtys ctxt (rty, qty) |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
462 |
val (rty's, rtyqs) = (Targs rty', Targs rtyq) |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
463 |
in |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
464 |
forall (no_no_code ctxt) (rty's ~~ rtyqs) |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
465 |
end |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
466 |
else |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
467 |
true |
55724 | 468 |
in |
469 |
||
470 |
fun register_code_eq abs_eq_thm opt_rep_eq_thm (rty, qty) lthy = |
|
471 |
let |
|
59630 | 472 |
val encoded_code_eq = encode_code_eq lthy abs_eq_thm opt_rep_eq_thm (rty, qty) |
55724 | 473 |
in |
57663
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
474 |
if no_no_code lthy (rty, qty) then |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
475 |
(snd oo Local_Theory.note) ((Binding.empty, [register_code_eq_attrib]), [encoded_code_eq]) lthy |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
476 |
else |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
477 |
lthy |
55724 | 478 |
end |
479 |
end |
|
480 |
||
47852
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
481 |
(* |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
482 |
Defines an operation on an abstract type in terms of a corresponding operation |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
483 |
on a representation type. |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
484 |
|
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
485 |
var - a binding and a mixfix of the new constant being defined |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
486 |
qty - an abstract type of the new constant |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
487 |
rhs - a term representing the new constant on the raw level |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
488 |
rsp_thm - a respectfulness theorem in the internal tagged form (like '(R ===> R ===> R) f f'), |
47852
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
489 |
i.e. "(Lifting_Term.equiv_relation (fastype_of rhs, qty)) $ rhs $ rhs" |
54335
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
490 |
par_thms - a parametricity theorem for rhs |
47852
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
491 |
*) |
47308 | 492 |
|
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
493 |
fun add_lift_def var qty rhs rsp_thm par_thms lthy = |
47308 | 494 |
let |
495 |
val rty = fastype_of rhs |
|
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
496 |
val quot_thm = Lifting_Term.prove_quot_thm lthy (rty, qty) |
47951
8c8a03765de7
quot_del attribute, it allows us to deregister quotient types
kuncar
parents:
47937
diff
changeset
|
497 |
val absrep_trm = quot_thm_abs quot_thm |
47308 | 498 |
val rty_forced = (domain_type o fastype_of) absrep_trm |
499 |
val forced_rhs = force_rty_type lthy rty_forced rhs |
|
53207
9745b7d4cc79
prefer Binding.name_of over Binding.print -- the latter leads to funny quotes and markup within the constructed term;
wenzelm
parents:
53205
diff
changeset
|
500 |
val lhs = Free (Binding.name_of (#1 var), qty) |
47308 | 501 |
val prop = Logic.mk_equals (lhs, absrep_trm $ forced_rhs) |
502 |
val (_, prop') = Local_Defs.cert_def lthy prop |
|
503 |
val (_, newrhs) = Local_Defs.abs_def prop' |
|
504 |
||
60219 | 505 |
val ((lift_const, (_ , def_thm)), lthy') = |
47308 | 506 |
Local_Theory.define (var, ((Thm.def_binding (#1 var), []), newrhs)) lthy |
507 |
||
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
508 |
val transfer_rules = generate_transfer_rules lthy' quot_thm rsp_thm def_thm par_thms |
49975
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents:
49885
diff
changeset
|
509 |
|
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
510 |
val abs_eq_thm = generate_abs_eq lthy' def_thm rsp_thm quot_thm |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
511 |
val opt_rep_eq_thm = generate_rep_eq lthy' def_thm rsp_thm (rty_forced, qty) |
47351 | 512 |
|
47545 | 513 |
fun qualify defname suffix = Binding.qualified true suffix defname |
47308 | 514 |
|
47545 | 515 |
val lhs_name = (#1 var) |
47308 | 516 |
val rsp_thm_name = qualify lhs_name "rsp" |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
517 |
val abs_eq_thm_name = qualify lhs_name "abs_eq" |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
518 |
val rep_eq_thm_name = qualify lhs_name "rep_eq" |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
519 |
val transfer_rule_name = qualify lhs_name "transfer" |
47373 | 520 |
val transfer_attr = Attrib.internal (K Transfer.transfer_add) |
60219 | 521 |
val lift_def = mk_lift_def rty_forced qty newrhs lift_const def_thm rsp_thm abs_eq_thm |
522 |
opt_rep_eq_thm transfer_rules |
|
47308 | 523 |
in |
524 |
lthy' |
|
525 |
|> (snd oo Local_Theory.note) ((rsp_thm_name, []), [rsp_thm]) |
|
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
526 |
|> (snd oo Local_Theory.note) ((transfer_rule_name, [transfer_attr]), transfer_rules) |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
527 |
|> (snd oo Local_Theory.note) ((abs_eq_thm_name, []), [abs_eq_thm]) |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
528 |
|> (case opt_rep_eq_thm of |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
529 |
SOME rep_eq_thm => (snd oo Local_Theory.note) ((rep_eq_thm_name, []), [rep_eq_thm]) |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
530 |
| NONE => I) |
55724 | 531 |
|> register_code_eq abs_eq_thm opt_rep_eq_thm (rty_forced, qty) |
60219 | 532 |
|> pair lift_def |
47308 | 533 |
end |
534 |
||
55731
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
535 |
local |
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
536 |
val eq_onp_assms_tac_fixed_rules = map (Transfer.prep_transfer_domain_thm @{context}) |
55731
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
537 |
[@{thm pcr_Domainp_total}, @{thm pcr_Domainp_par_left_total}, @{thm pcr_Domainp_par}, |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
538 |
@{thm pcr_Domainp}] |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
539 |
in |
47308 | 540 |
fun mk_readable_rsp_thm_eq tm lthy = |
541 |
let |
|
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59586
diff
changeset
|
542 |
val ctm = Thm.cterm_of lthy tm |
47308 | 543 |
|
55731
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
544 |
fun assms_rewr_conv tactic rule ct = |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
545 |
let |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
546 |
fun prove_extra_assms thm = |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
547 |
let |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
548 |
val assms = cprems_of thm |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
549 |
fun finish thm = if Thm.no_prems thm then SOME (Goal.conclude thm) else NONE |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
550 |
fun prove ctm = Option.mapPartial finish (SINGLE tactic (Goal.init ctm)) |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
551 |
in |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
552 |
map_interrupt prove assms |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
553 |
end |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
554 |
|
59582 | 555 |
fun cconl_of thm = Drule.strip_imp_concl (Thm.cprop_of thm) |
55731
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
556 |
fun lhs_of thm = fst (Thm.dest_equals (cconl_of thm)) |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
557 |
fun rhs_of thm = snd (Thm.dest_equals (cconl_of thm)) |
59586 | 558 |
val rule1 = Thm.incr_indexes (Thm.maxidx_of_cterm ct + 1) rule; |
55731
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
559 |
val lhs = lhs_of rule1; |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
560 |
val rule2 = Thm.rename_boundvars (Thm.term_of lhs) (Thm.term_of ct) rule1; |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
561 |
val rule3 = |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
562 |
Thm.instantiate (Thm.match (lhs, ct)) rule2 |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
563 |
handle Pattern.MATCH => raise CTERM ("assms_rewr_conv", [lhs, ct]); |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
564 |
val proved_assms = prove_extra_assms rule3 |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
565 |
in |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
566 |
case proved_assms of |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
567 |
SOME proved_assms => |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
568 |
let |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
569 |
val rule3 = proved_assms MRSL rule3 |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
570 |
val rule4 = |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
571 |
if lhs_of rule3 aconvc ct then rule3 |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
572 |
else |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
573 |
let val ceq = Thm.dest_fun2 (Thm.cprop_of rule3) |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
574 |
in rule3 COMP Thm.trivial (Thm.mk_binop ceq ct (rhs_of rule3)) end |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
575 |
in Thm.transitive rule4 (Thm.beta_conversion true (rhs_of rule4)) end |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
576 |
| NONE => Conv.no_conv ct |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
577 |
end |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
578 |
|
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
579 |
fun assms_rewrs_conv tactic rules = Conv.first_conv (map (assms_rewr_conv tactic) rules) |
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
580 |
|
47308 | 581 |
fun simp_arrows_conv ctm = |
582 |
let |
|
583 |
val unfold_conv = Conv.rewrs_conv |
|
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
584 |
[@{thm rel_fun_eq_eq_onp[THEN eq_reflection]}, |
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
585 |
@{thm rel_fun_eq_onp_rel[THEN eq_reflection]}, |
55945 | 586 |
@{thm rel_fun_eq[THEN eq_reflection]}, |
587 |
@{thm rel_fun_eq_rel[THEN eq_reflection]}, |
|
588 |
@{thm rel_fun_def[THEN eq_reflection]}] |
|
47308 | 589 |
fun binop_conv2 cv1 cv2 = Conv.combination_conv (Conv.arg_conv cv1) cv2 |
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
590 |
val eq_onp_assms_tac_rules = @{thm left_unique_OO} :: |
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
591 |
eq_onp_assms_tac_fixed_rules @ (Transfer.get_transfer_raw lthy) |
60221 | 592 |
val intro_top_rule = @{thm eq_onp_top_eq_eq[symmetric, THEN eq_reflection]} |
593 |
val kill_tops = Transfer.top_sweep_rewr_conv [@{thm eq_onp_top_eq_eq[THEN eq_reflection]}] |
|
594 |
val eq_onp_assms_tac = (CONVERSION kill_tops THEN' |
|
595 |
TRY o REPEAT_ALL_NEW (resolve_tac lthy eq_onp_assms_tac_rules) |
|
55731
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
596 |
THEN_ALL_NEW (DETERM o Transfer.eq_tac lthy)) 1 |
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
597 |
val relator_eq_onp_conv = Conv.bottom_conv |
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
598 |
(K (Conv.try_conv (assms_rewrs_conv eq_onp_assms_tac |
60221 | 599 |
(intro_top_rule :: Lifting_Info.get_relator_eq_onp_rules lthy)))) lthy |
600 |
then_conv kill_tops |
|
49626 | 601 |
val relator_eq_conv = Conv.bottom_conv |
602 |
(K (Conv.try_conv (Conv.rewrs_conv (Transfer.get_relator_eq lthy)))) lthy |
|
47308 | 603 |
in |
604 |
case (Thm.term_of ctm) of |
|
55945 | 605 |
Const (@{const_name "rel_fun"}, _) $ _ $ _ => |
49626 | 606 |
(binop_conv2 simp_arrows_conv simp_arrows_conv then_conv unfold_conv) ctm |
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
607 |
| _ => (relator_eq_onp_conv then_conv relator_eq_conv) ctm |
47308 | 608 |
end |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47852
diff
changeset
|
609 |
|
47308 | 610 |
val unfold_ret_val_invs = Conv.bottom_conv |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56519
diff
changeset
|
611 |
(K (Conv.try_conv (Conv.rewr_conv @{thm eq_onp_same_args[THEN eq_reflection]}))) lthy |
55773 | 612 |
val unfold_inv_conv = |
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
613 |
Conv.top_sweep_conv (K (Conv.rewr_conv @{thm eq_onp_def[THEN eq_reflection]})) lthy |
56540 | 614 |
val simp_conv = HOLogic.Trueprop_conv (Conv.fun2_conv simp_arrows_conv) |
47308 | 615 |
val univq_conv = Conv.rewr_conv @{thm HOL.all_simps(6)[symmetric, THEN eq_reflection]} |
616 |
val univq_prenex_conv = Conv.top_conv (K (Conv.try_conv univq_conv)) lthy |
|
617 |
val beta_conv = Thm.beta_conversion true |
|
618 |
val eq_thm = |
|
55773 | 619 |
(simp_conv then_conv univq_prenex_conv then_conv beta_conv then_conv unfold_ret_val_invs |
620 |
then_conv unfold_inv_conv) ctm |
|
47308 | 621 |
in |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54335
diff
changeset
|
622 |
Object_Logic.rulify lthy (eq_thm RS Drule.equal_elim_rule2) |
47308 | 623 |
end |
55731
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
kuncar
parents:
55724
diff
changeset
|
624 |
end |
47308 | 625 |
|
47607 | 626 |
fun rename_to_tnames ctxt term = |
627 |
let |
|
56245 | 628 |
fun all_typs (Const (@{const_name Pure.all}, _) $ Abs (_, T, t)) = T :: all_typs t |
47607 | 629 |
| all_typs _ = [] |
47308 | 630 |
|
56245 | 631 |
fun rename (Const (@{const_name Pure.all}, T1) $ Abs (_, T2, t)) (new_name :: names) = |
632 |
(Const (@{const_name Pure.all}, T1) $ Abs (new_name, T2, rename t names)) |
|
47607 | 633 |
| rename t _ = t |
634 |
||
635 |
val (fixed_def_t, _) = yield_singleton (Variable.importT_terms) term ctxt |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58028
diff
changeset
|
636 |
val new_names = Old_Datatype_Prop.make_tnames (all_typs fixed_def_t) |
47607 | 637 |
in |
638 |
rename term new_names |
|
639 |
end |
|
47308 | 640 |
|
56540 | 641 |
(* This is not very cheap way of getting the rules but we have only few active |
642 |
liftings in the current setting *) |
|
643 |
fun get_cr_pcr_eqs ctxt = |
|
644 |
let |
|
645 |
fun collect (data : Lifting_Info.quotient) l = |
|
646 |
if is_some (#pcr_info data) |
|
647 |
then ((Thm.symmetric o safe_mk_meta_eq o #pcr_cr_eq o the o #pcr_info) data :: l) |
|
648 |
else l |
|
649 |
val table = Lifting_Info.get_quotients ctxt |
|
650 |
in |
|
651 |
Symtab.fold (fn (_, data) => fn l => collect data l) table [] |
|
652 |
end |
|
653 |
||
60218 | 654 |
fun prepare_lift_def var qty rhs par_thms lthy = |
47308 | 655 |
let |
51994 | 656 |
val rsp_rel = Lifting_Term.equiv_relation lthy (fastype_of rhs, qty) |
47308 | 657 |
val rty_forced = (domain_type o fastype_of) rsp_rel; |
51994 | 658 |
val forced_rhs = force_rty_type lthy rty_forced rhs; |
56540 | 659 |
val cr_to_pcr_conv = HOLogic.Trueprop_conv (Conv.fun2_conv |
660 |
(Raw_Simplifier.rewrite lthy false (get_cr_pcr_eqs lthy))) |
|
661 |
val (prsp_tm, rsp_prsp_eq) = HOLogic.mk_Trueprop (rsp_rel $ forced_rhs $ forced_rhs) |
|
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59586
diff
changeset
|
662 |
|> Thm.cterm_of lthy |
56540 | 663 |
|> cr_to_pcr_conv |
59582 | 664 |
|> `Thm.concl_of |
56540 | 665 |
|>> Logic.dest_equals |
666 |
|>> snd |
|
667 |
val to_rsp = rsp_prsp_eq RS Drule.equal_elim_rule2 |
|
668 |
val opt_proven_rsp_thm = try_prove_reflexivity lthy prsp_tm |
|
51994 | 669 |
|
670 |
fun after_qed internal_rsp_thm lthy = |
|
60218 | 671 |
add_lift_def var qty rhs (internal_rsp_thm RS to_rsp) par_thms lthy |
47308 | 672 |
in |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
673 |
case opt_proven_rsp_thm of |
60218 | 674 |
SOME thm => (NONE, K (after_qed thm)) |
51994 | 675 |
| NONE => |
676 |
let |
|
56540 | 677 |
val readable_rsp_thm_eq = mk_readable_rsp_thm_eq prsp_tm lthy |
59582 | 678 |
val (readable_rsp_tm, _) = Logic.dest_implies (Thm.prop_of readable_rsp_thm_eq) |
51994 | 679 |
val readable_rsp_tm_tnames = rename_to_tnames lthy readable_rsp_tm |
680 |
||
681 |
fun after_qed' thm_list lthy = |
|
682 |
let |
|
56540 | 683 |
val internal_rsp_thm = Goal.prove lthy [] [] prsp_tm |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54335
diff
changeset
|
684 |
(fn {context = ctxt, ...} => |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54335
diff
changeset
|
685 |
rtac readable_rsp_thm_eq 1 THEN Proof_Context.fact_tac ctxt (hd thm_list) 1) |
51994 | 686 |
in |
687 |
after_qed internal_rsp_thm lthy |
|
688 |
end |
|
689 |
in |
|
60218 | 690 |
(SOME readable_rsp_tm_tnames, after_qed') |
51994 | 691 |
end |
47308 | 692 |
end |
693 |
||
60218 | 694 |
fun lift_def var qty rhs tac par_thms lthy = |
695 |
let |
|
696 |
val (goal, after_qed) = prepare_lift_def var qty rhs par_thms lthy |
|
697 |
in |
|
698 |
case goal of |
|
699 |
SOME goal => |
|
700 |
let |
|
701 |
val rsp_thm = Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, ...} => tac ctxt) |
|
702 |
|> Thm.close_derivation |
|
703 |
in |
|
704 |
after_qed [[rsp_thm]] lthy |
|
705 |
end |
|
706 |
| NONE => after_qed [[Drule.dummy_thm]] lthy |
|
707 |
end |
|
708 |
||
709 |
(* |
|
710 |
||
711 |
lifting_definition command. It opens a proof of a corresponding respectfulness |
|
712 |
theorem in a user-friendly, readable form. Then add_lift_def is called internally. |
|
713 |
||
714 |
*) |
|
715 |
||
716 |
fun lift_def_cmd (raw_var, rhs_raw, par_xthms) lthy = |
|
717 |
let |
|
718 |
val ((binding, SOME qty, mx), lthy) = yield_singleton Proof_Context.read_vars raw_var lthy |
|
719 |
val var = (binding, mx) |
|
720 |
val rhs = (Syntax.check_term lthy o Syntax.parse_term lthy) rhs_raw |
|
721 |
val par_thms = Attrib.eval_thms lthy par_xthms |
|
722 |
val (goal, after_qed) = prepare_lift_def var qty rhs par_thms lthy |
|
723 |
in |
|
60219 | 724 |
Proof.theorem NONE (snd oo after_qed) [map (rpair []) (the_list goal)] lthy |
60218 | 725 |
end |
726 |
||
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
727 |
fun quot_thm_err ctxt (rty, qty) pretty_msg = |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
728 |
let |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
729 |
val error_msg = cat_lines |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
730 |
["Lifting failed for the following types:", |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
731 |
Pretty.string_of (Pretty.block |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
732 |
[Pretty.str "Raw type:", Pretty.brk 2, Syntax.pretty_typ ctxt rty]), |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
733 |
Pretty.string_of (Pretty.block |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
734 |
[Pretty.str "Abstract type:", Pretty.brk 2, Syntax.pretty_typ ctxt qty]), |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
735 |
"", |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
736 |
(Pretty.string_of (Pretty.block |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
737 |
[Pretty.str "Reason:", Pretty.brk 2, pretty_msg]))] |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
738 |
in |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
739 |
error error_msg |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
740 |
end |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
741 |
|
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
742 |
fun check_rty_err ctxt (rty_schematic, rty_forced) (raw_var, rhs_raw) = |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
743 |
let |
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
744 |
val (_, ctxt') = yield_singleton Proof_Context.read_vars raw_var ctxt |
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
745 |
val rhs = (Syntax.check_term ctxt' o Syntax.parse_term ctxt') rhs_raw |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
746 |
val error_msg = cat_lines |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
747 |
["Lifting failed for the following term:", |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
748 |
Pretty.string_of (Pretty.block |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
749 |
[Pretty.str "Term:", Pretty.brk 2, Syntax.pretty_term ctxt rhs]), |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
750 |
Pretty.string_of (Pretty.block |
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
751 |
[Pretty.str "Type:", Pretty.brk 2, Syntax.pretty_typ ctxt rty_schematic]), |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
752 |
"", |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
753 |
(Pretty.string_of (Pretty.block |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
754 |
[Pretty.str "Reason:", |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
755 |
Pretty.brk 2, |
51957 | 756 |
Pretty.str "The type of the term cannot be instantiated to", |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
757 |
Pretty.brk 1, |
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
758 |
Pretty.quote (Syntax.pretty_typ ctxt rty_forced), |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
759 |
Pretty.str "."]))] |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
760 |
in |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
761 |
error error_msg |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
762 |
end |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
763 |
|
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
764 |
fun lift_def_cmd_with_err_handling (raw_var, rhs_raw, par_xthms) lthy = |
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
765 |
(lift_def_cmd (raw_var, rhs_raw, par_xthms) lthy |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
766 |
handle Lifting_Term.QUOT_THM (rty, qty, msg) => quot_thm_err lthy (rty, qty) msg) |
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
767 |
handle Lifting_Term.CHECK_RTY (rty_schematic, rty_forced) => |
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
768 |
check_rty_err lthy (rty_schematic, rty_forced) (raw_var, rhs_raw) |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
769 |
|
47308 | 770 |
(* parser and command *) |
771 |
val liftdef_parser = |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
772 |
(((Parse.binding -- (@{keyword "::"} |-- (Parse.typ >> SOME) -- Parse.opt_mixfix')) >> Parse.triple2) |
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
773 |
--| @{keyword "is"} -- Parse.term -- |
58028
e4250d370657
tuned signature -- define some elementary operations earlier;
wenzelm
parents:
58011
diff
changeset
|
774 |
Scan.optional (@{keyword "parametric"} |-- Parse.!!! Parse.xthms1) []) >> Parse.triple1 |
47308 | 775 |
val _ = |
59936
b8ffc3dc9e24
@{command_spec} is superseded by @{command_keyword};
wenzelm
parents:
59630
diff
changeset
|
776 |
Outer_Syntax.local_theory_to_proof @{command_keyword lift_definition} |
47308 | 777 |
"definition for constants over the quotient type" |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
778 |
(liftdef_parser >> lift_def_cmd_with_err_handling) |
47308 | 779 |
|
780 |
||
53651 | 781 |
end (* structure *) |