author | haftmann |
Wed, 28 Jan 2015 08:29:08 +0100 | |
changeset 59458 | 9de8ac92cafa |
parent 59058 | a78612c67ec0 |
child 59498 | 50b60f501b05 |
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 |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
9 |
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
|
10 |
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
|
11 |
|
47308 | 12 |
val add_lift_def: |
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
13 |
(binding * mixfix) -> typ -> term -> thm -> thm list -> local_theory -> local_theory |
47308 | 14 |
|
15 |
val lift_def_cmd: |
|
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
57664
diff
changeset
|
16 |
(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
|
17 |
local_theory -> Proof.state |
47308 | 18 |
|
19 |
val can_generate_code_cert: thm -> bool |
|
53651 | 20 |
end |
47308 | 21 |
|
22 |
structure Lifting_Def: LIFTING_DEF = |
|
23 |
struct |
|
24 |
||
47698 | 25 |
open Lifting_Util |
47308 | 26 |
|
27 |
infix 0 MRSL |
|
28 |
||
51994 | 29 |
(* Reflexivity prover *) |
30 |
||
55609 | 31 |
fun mono_eq_prover ctxt prop = |
51994 | 32 |
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
|
33 |
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
|
34 |
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
|
35 |
|
56540 | 36 |
fun main_tac i = (REPEAT_ALL_NEW (DETERM o resolve_tac refl_rules) THEN_ALL_NEW |
37 |
(REPEAT_ALL_NEW (DETERM o resolve_tac transfer_rules))) i |
|
51994 | 38 |
in |
56540 | 39 |
SOME (Goal.prove ctxt [] [] prop (K (main_tac 1))) |
55609 | 40 |
handle ERROR _ => NONE |
51994 | 41 |
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
|
42 |
|
57642
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
43 |
fun try_prove_refl_rel ctxt rel = |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
44 |
let |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
45 |
fun mk_ge_eq x = |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
46 |
let |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
47 |
val T = fastype_of x |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
48 |
in |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
49 |
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
|
50 |
(Const (@{const_name HOL.eq}, T)) $ x |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
51 |
end; |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
52 |
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
|
53 |
in |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
54 |
mono_eq_prover ctxt goal |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
55 |
end; |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
56 |
|
51994 | 57 |
fun try_prove_reflexivity ctxt prop = |
55609 | 58 |
let |
59 |
val thy = Proof_Context.theory_of ctxt |
|
60 |
val cprop = cterm_of thy prop |
|
61 |
val rule = @{thm ge_eq_refl} |
|
62 |
val concl_pat = Drule.strip_imp_concl (cprop_of rule) |
|
63 |
val insts = Thm.first_order_match (concl_pat, cprop) |
|
64 |
val rule = Drule.instantiate_normalize insts rule |
|
65 |
val prop = hd (prems_of rule) |
|
66 |
in |
|
67 |
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
|
68 |
SOME thm => SOME (thm RS rule) |
55609 | 69 |
| NONE => NONE |
70 |
end |
|
51994 | 71 |
|
54335
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
72 |
(* |
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
73 |
Generates a parametrized transfer rule. |
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
74 |
transfer_rule - of the form T t f |
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
75 |
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
|
76 |
|
54947 | 77 |
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
|
78 |
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
|
79 |
using Lifting_Term.merge_transfer_relations |
03b10317ba78
update documentation of important public ML functions in Lifting
kuncar
parents:
53951
diff
changeset
|
80 |
*) |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
81 |
|
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
82 |
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
|
83 |
let |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
84 |
fun preprocess ctxt thm = |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
85 |
let |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
86 |
val tm = (strip_args 2 o HOLogic.dest_Trueprop o concl_of) thm; |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
87 |
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
|
88 |
val thy = Proof_Context.theory_of ctxt; |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
89 |
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
|
90 |
|
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
91 |
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
|
92 |
let |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
93 |
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
|
94 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
95 |
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
|
96 |
(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
|
97 |
else |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
98 |
subst |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
99 |
end; |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
100 |
|
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
101 |
val subst = fold make_subst free_vars []; |
59058
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents:
58112
diff
changeset
|
102 |
val csubst = map (apply2 (cterm_of thy)) subst; |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
103 |
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
|
104 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
105 |
Conv.fconv_rule |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
106 |
((Conv.concl_conv (nprems_of inst_thm) o 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
|
107 |
(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
|
108 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
109 |
|
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
110 |
fun inst_relcomppI thy ant1 ant2 = |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
111 |
let |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
112 |
val t1 = (HOLogic.dest_Trueprop o concl_of) ant1 |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
113 |
val t2 = (HOLogic.dest_Trueprop o prop_of) ant2 |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
114 |
val fun1 = cterm_of thy (strip_args 2 t1) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
115 |
val args1 = map (cterm_of thy) (get_args 2 t1) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
116 |
val fun2 = cterm_of thy (strip_args 2 t2) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
117 |
val args2 = map (cterm_of thy) (get_args 1 t2) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
118 |
val relcomppI = Drule.incr_indexes2 ant1 ant2 @{thm relcomppI} |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
119 |
val vars = (rev (Term.add_vars (prop_of relcomppI) [])) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
120 |
val subst = map (apfst ((cterm_of thy) o Var)) (vars ~~ ([fun1] @ args1 @ [fun2] @ args2)) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
121 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
122 |
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
|
123 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
124 |
|
54995 | 125 |
fun zip_transfer_rules ctxt thm = |
126 |
let |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
127 |
val thy = Proof_Context.theory_of ctxt |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
128 |
fun mk_POS ty = Const (@{const_name POS}, ty --> ty --> HOLogic.boolT) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
129 |
val rel = (Thm.dest_fun2 o Thm.dest_arg o cprop_of) thm |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
130 |
val typ = (typ_of o ctyp_of_term) rel |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
131 |
val POS_const = cterm_of thy (mk_POS typ) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
132 |
val var = cterm_of thy (Var (("X", #maxidx (rep_cterm (rel)) + 1), typ)) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
133 |
val goal = Thm.apply (cterm_of thy HOLogic.Trueprop) (Thm.apply (Thm.apply POS_const rel) var) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
134 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
135 |
[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
|
136 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
137 |
|
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
138 |
val thm = (inst_relcomppI (Proof_Context.theory_of ctxt) parametric_transfer_rule transfer_rule) |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
139 |
OF [parametric_transfer_rule, transfer_rule] |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
140 |
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
|
141 |
val orig_ctxt = ctxt |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
142 |
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
|
143 |
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
|
144 |
val add_transfer_rule = Thm.attribute_declaration Transfer.transfer_add |
54995 | 145 |
val (prems, ctxt) = fold_map Thm.assume_hyps assms ctxt |
146 |
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
|
147 |
val zipped_thm = |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
148 |
fixed_thm |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
149 |
|> undisch_all |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
150 |
|> zip_transfer_rules ctxt |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
151 |
|> implies_intr_list assms |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
152 |
|> 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
|
153 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
154 |
zipped_thm |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
155 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
156 |
|
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
157 |
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
|
158 |
let |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
159 |
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
|
160 |
["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
|
161 |
(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
|
162 |
[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
|
163 |
in |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
164 |
error error_msg |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
165 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
166 |
|
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
167 |
fun map_ter _ x [] = x |
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
168 |
| map_ter f _ xs = map f xs |
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
169 |
|
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
170 |
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
|
171 |
let |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
172 |
val transfer_rule = |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
173 |
([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
|
174 |
|> 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
|
175 |
in |
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
176 |
(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
|
177 |
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
|
178 |
end |
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
179 |
|
47698 | 180 |
(* Generation of the code certificate from the rsp theorem *) |
47308 | 181 |
|
182 |
fun get_body_types (Type ("fun", [_, U]), Type ("fun", [_, V])) = get_body_types (U, V) |
|
183 |
| get_body_types (U, V) = (U, V) |
|
184 |
||
185 |
fun get_binder_types (Type ("fun", [T, U]), Type ("fun", [V, W])) = (T, V) :: get_binder_types (U, W) |
|
186 |
| get_binder_types _ = [] |
|
187 |
||
55945 | 188 |
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
|
189 |
(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
|
190 |
| 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
|
191 |
|
55945 | 192 |
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
|
193 |
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
|
194 |
| 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
|
195 |
|
57642
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
196 |
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
|
197 |
| get_binder_rels _ = [] |
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
198 |
|
47308 | 199 |
fun force_rty_type ctxt rty rhs = |
200 |
let |
|
201 |
val thy = Proof_Context.theory_of ctxt |
|
202 |
val rhs_schematic = singleton (Variable.polymorphic ctxt) rhs |
|
203 |
val rty_schematic = fastype_of rhs_schematic |
|
204 |
val match = Sign.typ_match thy (rty_schematic, rty) Vartab.empty |
|
205 |
in |
|
206 |
Envir.subst_term_types match rhs_schematic |
|
207 |
end |
|
208 |
||
209 |
fun unabs_def ctxt def = |
|
210 |
let |
|
211 |
val (_, rhs) = Thm.dest_equals (cprop_of def) |
|
212 |
fun dest_abs (Abs (var_name, T, _)) = (var_name, T) |
|
213 |
| dest_abs tm = raise TERM("get_abs_var",[tm]) |
|
214 |
val (var_name, T) = dest_abs (term_of rhs) |
|
215 |
val (new_var_names, ctxt') = Variable.variant_fixes [var_name] ctxt |
|
216 |
val thy = Proof_Context.theory_of ctxt' |
|
217 |
val refl_thm = Thm.reflexive (cterm_of thy (Free (hd new_var_names, T))) |
|
218 |
in |
|
219 |
Thm.combination def refl_thm |> |
|
220 |
singleton (Proof_Context.export ctxt' ctxt) |
|
221 |
end |
|
222 |
||
223 |
fun unabs_all_def ctxt def = |
|
224 |
let |
|
225 |
val (_, rhs) = Thm.dest_equals (cprop_of def) |
|
226 |
val xs = strip_abs_vars (term_of rhs) |
|
227 |
in |
|
228 |
fold (K (unabs_def ctxt)) xs def |
|
229 |
end |
|
230 |
||
231 |
val map_fun_unfolded = |
|
232 |
@{thm map_fun_def[abs_def]} |> |
|
233 |
unabs_def @{context} |> |
|
234 |
unabs_def @{context} |> |
|
235 |
Local_Defs.unfold @{context} [@{thm comp_def}] |
|
236 |
||
237 |
fun unfold_fun_maps ctm = |
|
238 |
let |
|
239 |
fun unfold_conv ctm = |
|
240 |
case (Thm.term_of ctm) of |
|
241 |
Const (@{const_name "map_fun"}, _) $ _ $ _ => |
|
242 |
(Conv.arg_conv unfold_conv then_conv Conv.rewr_conv map_fun_unfolded) ctm |
|
243 |
| _ => Conv.all_conv ctm |
|
244 |
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
|
245 |
(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
|
246 |
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
|
247 |
|
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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
(unfold_fun_maps then_conv try_beta_conv) ctm |
47308 | 252 |
end |
253 |
||
254 |
fun prove_rel ctxt rsp_thm (rty, qty) = |
|
255 |
let |
|
256 |
val ty_args = get_binder_types (rty, qty) |
|
257 |
fun disch_arg args_ty thm = |
|
258 |
let |
|
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
259 |
val quot_thm = Lifting_Term.prove_quot_thm ctxt args_ty |
47308 | 260 |
in |
261 |
[quot_thm, thm] MRSL @{thm apply_rsp''} |
|
262 |
end |
|
263 |
in |
|
264 |
fold disch_arg ty_args rsp_thm |
|
265 |
end |
|
266 |
||
267 |
exception CODE_CERT_GEN of string |
|
268 |
||
269 |
fun simplify_code_eq ctxt def_thm = |
|
48024 | 270 |
Local_Defs.unfold ctxt [@{thm o_apply}, @{thm map_fun_def}, @{thm id_apply}] def_thm |
47308 | 271 |
|
47852
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
272 |
(* |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
273 |
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
|
274 |
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
|
275 |
represented by quot_thm |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
276 |
*) |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
277 |
|
47308 | 278 |
fun can_generate_code_cert quot_thm = |
47951
8c8a03765de7
quot_del attribute, it allows us to deregister quotient types
kuncar
parents:
47937
diff
changeset
|
279 |
case quot_thm_rel quot_thm of |
47308 | 280 |
Const (@{const_name HOL.eq}, _) => true |
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
281 |
| Const (@{const_name eq_onp}, _) $ _ => true |
47308 | 282 |
| _ => false |
283 |
||
55610
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
284 |
fun generate_rep_eq ctxt def_thm rsp_thm (rty, qty) = |
47308 | 285 |
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
|
286 |
val unfolded_def = Conv.fconv_rule (Conv.arg_conv unfold_fun_maps_beta) def_thm |
47308 | 287 |
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
|
288 |
in |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
289 |
if body_type rty = body_type qty then |
55723 | 290 |
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
|
291 |
else |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
292 |
let |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
293 |
val thy = Proof_Context.theory_of ctxt |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
294 |
val quot_thm = Lifting_Term.prove_quot_thm ctxt (get_body_types (rty, qty)) |
55945 | 295 |
val rel_fun = prove_rel ctxt rsp_thm (rty, qty) |
296 |
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
|
297 |
in |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
298 |
case mono_eq_prover ctxt (hd(prems_of rep_abs_thm)) of |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
299 |
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
|
300 |
let |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
301 |
val rep_abs_eq = mono_eq_thm RS rep_abs_thm |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
302 |
val rep = (cterm_of thy o quot_thm_rep) quot_thm |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
in |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
307 |
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
|
308 |
end |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
309 |
| NONE => NONE |
9066b603dff6
refactoring; generate rep_eq always, not only when it would be accepted by the code generator
kuncar
parents:
55609
diff
changeset
|
310 |
end |
47308 | 311 |
end |
312 |
||
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
|
313 |
fun generate_abs_eq ctxt def_thm rsp_thm quot_thm = |
47308 | 314 |
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
|
315 |
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
|
316 |
let |
47951
8c8a03765de7
quot_del attribute, it allows us to deregister quotient types
kuncar
parents:
47937
diff
changeset
|
317 |
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
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
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
|
322 |
|
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
|
323 |
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
|
324 |
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
|
325 |
val rep_id = [quot_thm, def_thm] MRSL @{thm Quotient_Rep_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
|
326 |
val ctm = Thm.dest_equals_lhs (cprop_of rep_id) |
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
|
327 |
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
|
328 |
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
|
329 |
val prems_pat = (hd o Drule.cprems_of) 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
|
330 |
val insts = Thm.first_order_match (prems_pat, cprop_of unfolded_maps_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
|
331 |
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
|
332 |
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
|
333 |
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
|
334 |
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
|
335 |
rep_abs_folded_unmapped_thm |
55945 | 336 |
|> 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
|
337 |
|> (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
|
338 |
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
|
339 |
|
57642
5bc43a73d768
prevent beta-contraction in proving extra assumptions for abs_eq
kuncar
parents:
56540
diff
changeset
|
340 |
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
|
341 |
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
|
342 |
|> 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
|
343 |
|> 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
|
344 |
val abs_eq = fold_rev (fn (i, assm) => fn thm => assm RSN (i, thm)) proved_assms abs_eq_with_assms |
47308 | 345 |
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
|
346 |
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
|
347 |
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
|
348 |
|
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
|
349 |
|
55724 | 350 |
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
|
351 |
let |
55724 | 352 |
fun no_abstr (t $ u) = no_abstr t andalso no_abstr u |
353 |
| no_abstr (Abs (_, _, t)) = no_abstr t |
|
354 |
| no_abstr (Const (name, _)) = not (Code.is_abstr thy name) |
|
355 |
| no_abstr _ = true |
|
356 |
fun is_valid_eq eqn = can (Code.assert_eqn thy) (mk_meta_eq eqn, true) |
|
357 |
andalso no_abstr (prop_of eqn) |
|
358 |
fun is_valid_abs_eq abs_eq = can (Code.assert_abs_eqn thy NONE) (mk_meta_eq abs_eq) |
|
47308 | 359 |
|
360 |
in |
|
55724 | 361 |
if is_valid_eq abs_eq_thm then |
362 |
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
|
363 |
else |
55724 | 364 |
let |
365 |
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
|
366 |
in |
55724 | 367 |
if rty_body = qty_body then |
368 |
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
|
369 |
else |
55724 | 370 |
if is_some opt_rep_eq_thm andalso is_valid_abs_eq (the opt_rep_eq_thm) |
371 |
then |
|
59458 | 372 |
Code.add_abs_default_eqn (the opt_rep_eq_thm) thy |
55724 | 373 |
else |
374 |
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
|
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 |
end |
47308 | 377 |
|
55724 | 378 |
local |
379 |
fun encode_code_eq thy abs_eq opt_rep_eq (rty, qty) = |
|
380 |
let |
|
381 |
fun mk_type typ = typ |> Logic.mk_type |> cterm_of thy |> Drule.mk_term |
|
382 |
in |
|
383 |
Conjunction.intr_balanced [abs_eq, (the_default TrueI opt_rep_eq), mk_type rty, mk_type qty] |
|
384 |
end |
|
385 |
||
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
|
386 |
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
|
387 |
|
55724 | 388 |
fun decode_code_eq thm = |
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
|
389 |
if nprems_of thm > 0 then raise 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
|
390 |
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
|
391 |
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
|
392 |
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
|
393 |
val opt_rep_eq = if Thm.eq_thm_prop (rep_eq, TrueI) then NONE else SOME rep_eq |
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
|
394 |
fun dest_type typ = typ |> Drule.dest_term |> term_of |> Logic.dest_type |
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
|
395 |
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
|
396 |
(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
|
397 |
end |
55724 | 398 |
|
399 |
fun register_encoded_code_eq thm thy = |
|
400 |
let |
|
401 |
val (abs_eq_thm, opt_rep_eq_thm, (rty, qty)) = decode_code_eq thm |
|
402 |
in |
|
403 |
register_code_eq_thy abs_eq_thm opt_rep_eq_thm (rty, qty) thy |
|
404 |
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
|
405 |
handle DECODE => thy |
55724 | 406 |
|
407 |
val register_code_eq_attribute = Thm.declaration_attribute |
|
408 |
(fn thm => Context.mapping (register_encoded_code_eq thm) I) |
|
409 |
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
|
410 |
|
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
411 |
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
|
412 |
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
|
413 |
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
|
414 |
else |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
415 |
if is_Type qty then |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
416 |
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
|
417 |
else |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
418 |
let |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
419 |
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
|
420 |
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
|
421 |
in |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
422 |
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
|
423 |
end |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
424 |
else |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
425 |
true |
55724 | 426 |
in |
427 |
||
428 |
fun register_code_eq abs_eq_thm opt_rep_eq_thm (rty, qty) lthy = |
|
429 |
let |
|
430 |
val thy = Proof_Context.theory_of lthy |
|
431 |
val encoded_code_eq = encode_code_eq thy abs_eq_thm opt_rep_eq_thm (rty, qty) |
|
432 |
in |
|
57663
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
433 |
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
|
434 |
(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
|
435 |
else |
b590fcd03a4a
store explicitly quotient types with no_code => more precise registration of code equations
kuncar
parents:
57642
diff
changeset
|
436 |
lthy |
55724 | 437 |
end |
438 |
end |
|
439 |
||
47852
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
440 |
(* |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
441 |
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
|
442 |
on a representation type. |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
443 |
|
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
444 |
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
|
445 |
qty - an abstract type of the new constant |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
446 |
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
|
447 |
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
|
448 |
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
|
449 |
par_thms - a parametricity theorem for rhs |
47852
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
450 |
*) |
47308 | 451 |
|
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
452 |
fun add_lift_def var qty rhs rsp_thm par_thms lthy = |
47308 | 453 |
let |
454 |
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
|
455 |
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
|
456 |
val absrep_trm = quot_thm_abs quot_thm |
47308 | 457 |
val rty_forced = (domain_type o fastype_of) absrep_trm |
458 |
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
|
459 |
val lhs = Free (Binding.name_of (#1 var), qty) |
47308 | 460 |
val prop = Logic.mk_equals (lhs, absrep_trm $ forced_rhs) |
461 |
val (_, prop') = Local_Defs.cert_def lthy prop |
|
462 |
val (_, newrhs) = Local_Defs.abs_def prop' |
|
463 |
||
464 |
val ((_, (_ , def_thm)), lthy') = |
|
465 |
Local_Theory.define (var, ((Thm.def_binding (#1 var), []), newrhs)) lthy |
|
466 |
||
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
467 |
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
|
468 |
|
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
|
469 |
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
|
470 |
val opt_rep_eq_thm = generate_rep_eq lthy' def_thm rsp_thm (rty_forced, qty) |
47351 | 471 |
|
47545 | 472 |
fun qualify defname suffix = Binding.qualified true suffix defname |
47308 | 473 |
|
47545 | 474 |
val lhs_name = (#1 var) |
47308 | 475 |
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
|
476 |
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
|
477 |
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
|
478 |
val transfer_rule_name = qualify lhs_name "transfer" |
47373 | 479 |
val transfer_attr = Attrib.internal (K Transfer.transfer_add) |
47308 | 480 |
in |
481 |
lthy' |
|
482 |
|> (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
|
483 |
|> (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
|
484 |
|> (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
|
485 |
|> (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
|
486 |
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
|
487 |
| NONE => I) |
55724 | 488 |
|> register_code_eq abs_eq_thm opt_rep_eq_thm (rty_forced, qty) |
47308 | 489 |
end |
490 |
||
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
|
491 |
local |
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
492 |
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
|
493 |
[@{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
|
494 |
@{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
|
495 |
in |
47308 | 496 |
fun mk_readable_rsp_thm_eq tm lthy = |
497 |
let |
|
498 |
val ctm = cterm_of (Proof_Context.theory_of lthy) tm |
|
499 |
||
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
|
500 |
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
|
501 |
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
|
502 |
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
|
503 |
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
|
504 |
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
|
505 |
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
|
506 |
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
|
507 |
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
|
508 |
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
|
509 |
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
|
510 |
|
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
|
511 |
fun cconl_of thm = Drule.strip_imp_concl (cprop_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
|
512 |
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
|
513 |
fun rhs_of thm = snd (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
|
514 |
val rule1 = Thm.incr_indexes (#maxidx (Thm.rep_cterm ct) + 1) rule; |
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
|
515 |
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
|
516 |
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
|
517 |
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
|
518 |
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
|
519 |
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
|
520 |
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
|
521 |
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
|
522 |
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
|
523 |
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
|
524 |
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
|
525 |
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
|
526 |
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
|
527 |
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
|
528 |
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
|
529 |
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
|
530 |
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
|
531 |
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
|
532 |
| 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
|
533 |
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
|
534 |
|
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 |
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
|
536 |
|
47308 | 537 |
fun simp_arrows_conv ctm = |
538 |
let |
|
539 |
val unfold_conv = Conv.rewrs_conv |
|
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
540 |
[@{thm rel_fun_eq_eq_onp[THEN eq_reflection]}, |
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
541 |
@{thm rel_fun_eq_onp_rel[THEN eq_reflection]}, |
55945 | 542 |
@{thm rel_fun_eq[THEN eq_reflection]}, |
543 |
@{thm rel_fun_eq_rel[THEN eq_reflection]}, |
|
544 |
@{thm rel_fun_def[THEN eq_reflection]}] |
|
47308 | 545 |
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
|
546 |
val eq_onp_assms_tac_rules = @{thm left_unique_OO} :: |
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
547 |
eq_onp_assms_tac_fixed_rules @ (Transfer.get_transfer_raw lthy) |
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
548 |
val eq_onp_assms_tac = (TRY o REPEAT_ALL_NEW (resolve_tac 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
|
549 |
THEN_ALL_NEW (DETERM o Transfer.eq_tac lthy)) 1 |
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
550 |
val relator_eq_onp_conv = Conv.bottom_conv |
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
551 |
(K (Conv.try_conv (assms_rewrs_conv eq_onp_assms_tac |
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
552 |
(Lifting_Info.get_relator_eq_onp_rules lthy)))) lthy |
49626 | 553 |
val relator_eq_conv = Conv.bottom_conv |
554 |
(K (Conv.try_conv (Conv.rewrs_conv (Transfer.get_relator_eq lthy)))) lthy |
|
47308 | 555 |
in |
556 |
case (Thm.term_of ctm) of |
|
55945 | 557 |
Const (@{const_name "rel_fun"}, _) $ _ $ _ => |
49626 | 558 |
(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
|
559 |
| _ => (relator_eq_onp_conv then_conv relator_eq_conv) ctm |
47308 | 560 |
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
|
561 |
|
47308 | 562 |
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
|
563 |
(K (Conv.try_conv (Conv.rewr_conv @{thm eq_onp_same_args[THEN eq_reflection]}))) lthy |
55773 | 564 |
val unfold_inv_conv = |
56519
c1048f5bbb45
more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents:
56518
diff
changeset
|
565 |
Conv.top_sweep_conv (K (Conv.rewr_conv @{thm eq_onp_def[THEN eq_reflection]})) lthy |
56540 | 566 |
val simp_conv = HOLogic.Trueprop_conv (Conv.fun2_conv simp_arrows_conv) |
47308 | 567 |
val univq_conv = Conv.rewr_conv @{thm HOL.all_simps(6)[symmetric, THEN eq_reflection]} |
568 |
val univq_prenex_conv = Conv.top_conv (K (Conv.try_conv univq_conv)) lthy |
|
569 |
val beta_conv = Thm.beta_conversion true |
|
570 |
val eq_thm = |
|
55773 | 571 |
(simp_conv then_conv univq_prenex_conv then_conv beta_conv then_conv unfold_ret_val_invs |
572 |
then_conv unfold_inv_conv) ctm |
|
47308 | 573 |
in |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54335
diff
changeset
|
574 |
Object_Logic.rulify lthy (eq_thm RS Drule.equal_elim_rule2) |
47308 | 575 |
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
|
576 |
end |
47308 | 577 |
|
47607 | 578 |
fun rename_to_tnames ctxt term = |
579 |
let |
|
56245 | 580 |
fun all_typs (Const (@{const_name Pure.all}, _) $ Abs (_, T, t)) = T :: all_typs t |
47607 | 581 |
| all_typs _ = [] |
47308 | 582 |
|
56245 | 583 |
fun rename (Const (@{const_name Pure.all}, T1) $ Abs (_, T2, t)) (new_name :: names) = |
584 |
(Const (@{const_name Pure.all}, T1) $ Abs (new_name, T2, rename t names)) |
|
47607 | 585 |
| rename t _ = t |
586 |
||
587 |
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
|
588 |
val new_names = Old_Datatype_Prop.make_tnames (all_typs fixed_def_t) |
47607 | 589 |
in |
590 |
rename term new_names |
|
591 |
end |
|
47308 | 592 |
|
56540 | 593 |
(* This is not very cheap way of getting the rules but we have only few active |
594 |
liftings in the current setting *) |
|
595 |
fun get_cr_pcr_eqs ctxt = |
|
596 |
let |
|
597 |
fun collect (data : Lifting_Info.quotient) l = |
|
598 |
if is_some (#pcr_info data) |
|
599 |
then ((Thm.symmetric o safe_mk_meta_eq o #pcr_cr_eq o the o #pcr_info) data :: l) |
|
600 |
else l |
|
601 |
val table = Lifting_Info.get_quotients ctxt |
|
602 |
in |
|
603 |
Symtab.fold (fn (_, data) => fn l => collect data l) table [] |
|
604 |
end |
|
605 |
||
47852
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
606 |
(* |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
607 |
|
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
608 |
lifting_definition command. It opens a proof of a corresponding respectfulness |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
609 |
theorem in a user-friendly, readable form. Then add_lift_def is called internally. |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
610 |
|
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
611 |
*) |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47699
diff
changeset
|
612 |
|
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
613 |
fun lift_def_cmd (raw_var, rhs_raw, par_xthms) lthy = |
47308 | 614 |
let |
51994 | 615 |
val ((binding, SOME qty, mx), lthy) = yield_singleton Proof_Context.read_vars raw_var lthy |
616 |
val rhs = (Syntax.check_term lthy o Syntax.parse_term lthy) rhs_raw |
|
617 |
val rsp_rel = Lifting_Term.equiv_relation lthy (fastype_of rhs, qty) |
|
47308 | 618 |
val rty_forced = (domain_type o fastype_of) rsp_rel; |
51994 | 619 |
val forced_rhs = force_rty_type lthy rty_forced rhs; |
56540 | 620 |
val cr_to_pcr_conv = HOLogic.Trueprop_conv (Conv.fun2_conv |
621 |
(Raw_Simplifier.rewrite lthy false (get_cr_pcr_eqs lthy))) |
|
622 |
val (prsp_tm, rsp_prsp_eq) = HOLogic.mk_Trueprop (rsp_rel $ forced_rhs $ forced_rhs) |
|
623 |
|> cterm_of (Proof_Context.theory_of lthy) |
|
624 |
|> cr_to_pcr_conv |
|
625 |
|> ` concl_of |
|
626 |
|>> Logic.dest_equals |
|
627 |
|>> snd |
|
628 |
val to_rsp = rsp_prsp_eq RS Drule.equal_elim_rule2 |
|
629 |
val opt_proven_rsp_thm = try_prove_reflexivity lthy prsp_tm |
|
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
630 |
val par_thms = Attrib.eval_thms lthy par_xthms |
51994 | 631 |
|
632 |
fun after_qed internal_rsp_thm lthy = |
|
56540 | 633 |
add_lift_def (binding, mx) qty rhs (internal_rsp_thm RS to_rsp) par_thms lthy |
47308 | 634 |
in |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
635 |
case opt_proven_rsp_thm of |
51994 | 636 |
SOME thm => Proof.theorem NONE (K (after_qed thm)) [] lthy |
637 |
| NONE => |
|
638 |
let |
|
56540 | 639 |
val readable_rsp_thm_eq = mk_readable_rsp_thm_eq prsp_tm lthy |
51994 | 640 |
val (readable_rsp_tm, _) = Logic.dest_implies (prop_of readable_rsp_thm_eq) |
641 |
val readable_rsp_tm_tnames = rename_to_tnames lthy readable_rsp_tm |
|
642 |
||
643 |
fun after_qed' thm_list lthy = |
|
644 |
let |
|
56540 | 645 |
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
|
646 |
(fn {context = ctxt, ...} => |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54335
diff
changeset
|
647 |
rtac readable_rsp_thm_eq 1 THEN Proof_Context.fact_tac ctxt (hd thm_list) 1) |
51994 | 648 |
in |
649 |
after_qed internal_rsp_thm lthy |
|
650 |
end |
|
651 |
in |
|
652 |
Proof.theorem NONE after_qed' [[(readable_rsp_tm_tnames,[])]] lthy |
|
653 |
end |
|
47308 | 654 |
end |
655 |
||
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
656 |
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
|
657 |
let |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
658 |
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
|
659 |
["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
|
660 |
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
|
661 |
[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
|
662 |
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
|
663 |
[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
|
664 |
"", |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
665 |
(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
|
666 |
[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
|
667 |
in |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
668 |
error error_msg |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
669 |
end |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
670 |
|
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
671 |
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
|
672 |
let |
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
673 |
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
|
674 |
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
|
675 |
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
|
676 |
["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
|
677 |
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
|
678 |
[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
|
679 |
Pretty.string_of (Pretty.block |
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
680 |
[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
|
681 |
"", |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
682 |
(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
|
683 |
[Pretty.str "Reason:", |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
684 |
Pretty.brk 2, |
51957 | 685 |
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
|
686 |
Pretty.brk 1, |
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
687 |
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
|
688 |
Pretty.str "."]))] |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
689 |
in |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
690 |
error error_msg |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
691 |
end |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47373
diff
changeset
|
692 |
|
53951
03b74ef6d7c6
allow to specify multiple parametricity transfer rules in lift_definition
kuncar
parents:
53651
diff
changeset
|
693 |
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
|
694 |
(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
|
695 |
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
|
696 |
handle Lifting_Term.CHECK_RTY (rty_schematic, rty_forced) => |
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47503
diff
changeset
|
697 |
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
|
698 |
|
47308 | 699 |
(* parser and command *) |
700 |
val liftdef_parser = |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
51314
diff
changeset
|
701 |
(((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
|
702 |
--| @{keyword "is"} -- Parse.term -- |
58028
e4250d370657
tuned signature -- define some elementary operations earlier;
wenzelm
parents:
58011
diff
changeset
|
703 |
Scan.optional (@{keyword "parametric"} |-- Parse.!!! Parse.xthms1) []) >> Parse.triple1 |
47308 | 704 |
val _ = |
705 |
Outer_Syntax.local_theory_to_proof @{command_spec "lift_definition"} |
|
706 |
"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
|
707 |
(liftdef_parser >> lift_def_cmd_with_err_handling) |
47308 | 708 |
|
709 |
||
53651 | 710 |
end (* structure *) |