author | haftmann |
Thu, 19 Jun 2025 17:15:40 +0200 | |
changeset 82734 | 89347c0cc6a3 |
parent 82286 | 4042628fffa5 |
permissions | -rw-r--r-- |
47325 | 1 |
(* Title: HOL/Transfer.thy |
2 |
Author: Brian Huffman, TU Muenchen |
|
51956
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents:
51955
diff
changeset
|
3 |
Author: Ondrej Kuncar, TU Muenchen |
47325 | 4 |
*) |
5 |
||
60758 | 6 |
section \<open>Generic theorem transfer using relations\<close> |
47325 | 7 |
|
8 |
theory Transfer |
|
59275
77cd4992edcd
Add plugin to generate transfer theorem for primrec and primcorec
desharna
parents:
59141
diff
changeset
|
9 |
imports Basic_BNF_LFPs Hilbert_Choice Metis |
47325 | 10 |
begin |
11 |
||
60758 | 12 |
subsection \<open>Relator for function space\<close> |
47325 | 13 |
|
63343 | 14 |
bundle lifting_syntax |
53011
aeee0a4be6cf
introduce locale with syntax for fun_rel and map_fun and make thus ===> and ---> local
kuncar
parents:
52358
diff
changeset
|
15 |
begin |
81100 | 16 |
notation rel_fun (infixr \<open>===>\<close> 55) |
17 |
notation map_fun (infixr \<open>--->\<close> 55) |
|
53011
aeee0a4be6cf
introduce locale with syntax for fun_rel and map_fun and make thus ===> and ---> local
kuncar
parents:
52358
diff
changeset
|
18 |
end |
aeee0a4be6cf
introduce locale with syntax for fun_rel and map_fun and make thus ===> and ---> local
kuncar
parents:
52358
diff
changeset
|
19 |
|
63343 | 20 |
context includes lifting_syntax |
53011
aeee0a4be6cf
introduce locale with syntax for fun_rel and map_fun and make thus ===> and ---> local
kuncar
parents:
52358
diff
changeset
|
21 |
begin |
aeee0a4be6cf
introduce locale with syntax for fun_rel and map_fun and make thus ===> and ---> local
kuncar
parents:
52358
diff
changeset
|
22 |
|
55945 | 23 |
lemma rel_funD2: |
24 |
assumes "rel_fun A B f g" and "A x x" |
|
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:
47924
diff
changeset
|
25 |
shows "B (f x) (g x)" |
55945 | 26 |
using assms by (rule rel_funD) |
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:
47924
diff
changeset
|
27 |
|
55945 | 28 |
lemma rel_funE: |
29 |
assumes "rel_fun A B f g" and "A x y" |
|
47325 | 30 |
obtains "B (f x) (g y)" |
55945 | 31 |
using assms by (simp add: rel_fun_def) |
47325 | 32 |
|
55945 | 33 |
lemmas rel_fun_eq = fun.rel_eq |
47325 | 34 |
|
55945 | 35 |
lemma rel_fun_eq_rel: |
67399 | 36 |
shows "rel_fun (=) R = (\<lambda>f g. \<forall>x. R (f x) (g x))" |
55945 | 37 |
by (simp add: rel_fun_def) |
47325 | 38 |
|
39 |
||
60758 | 40 |
subsection \<open>Transfer method\<close> |
47325 | 41 |
|
60758 | 42 |
text \<open>Explicit tag for relation membership allows for |
43 |
backward proof methods.\<close> |
|
47325 | 44 |
|
45 |
definition Rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool" |
|
46 |
where "Rel r \<equiv> r" |
|
47 |
||
60758 | 48 |
text \<open>Handling of equality relations\<close> |
49975
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents:
48891
diff
changeset
|
49 |
|
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents:
48891
diff
changeset
|
50 |
definition is_equality :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" |
67399 | 51 |
where "is_equality R \<longleftrightarrow> R = (=)" |
49975
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents:
48891
diff
changeset
|
52 |
|
67399 | 53 |
lemma is_equality_eq: "is_equality (=)" |
51437
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
kuncar
parents:
51112
diff
changeset
|
54 |
unfolding is_equality_def by simp |
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
kuncar
parents:
51112
diff
changeset
|
55 |
|
60758 | 56 |
text \<open>Reverse implication for monotonicity rules\<close> |
52354
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
57 |
|
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
58 |
definition rev_implies where |
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
59 |
"rev_implies x y \<longleftrightarrow> (y \<longrightarrow> x)" |
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
60 |
|
60758 | 61 |
text \<open>Handling of meta-logic connectives\<close> |
47325 | 62 |
|
63 |
definition transfer_forall where |
|
64 |
"transfer_forall \<equiv> All" |
|
65 |
||
66 |
definition transfer_implies where |
|
67399 | 67 |
"transfer_implies \<equiv> (\<longrightarrow>)" |
47325 | 68 |
|
47355
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47325
diff
changeset
|
69 |
definition transfer_bforall :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" |
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47325
diff
changeset
|
70 |
where "transfer_bforall \<equiv> (\<lambda>P Q. \<forall>x. P x \<longrightarrow> Q x)" |
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47325
diff
changeset
|
71 |
|
47325 | 72 |
lemma transfer_forall_eq: "(\<And>x. P x) \<equiv> Trueprop (transfer_forall (\<lambda>x. P x))" |
73 |
unfolding atomize_all transfer_forall_def .. |
|
74 |
||
75 |
lemma transfer_implies_eq: "(A \<Longrightarrow> B) \<equiv> Trueprop (transfer_implies A B)" |
|
76 |
unfolding atomize_imp transfer_implies_def .. |
|
77 |
||
47355
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47325
diff
changeset
|
78 |
lemma transfer_bforall_unfold: |
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47325
diff
changeset
|
79 |
"Trueprop (transfer_bforall P (\<lambda>x. Q x)) \<equiv> (\<And>x. P x \<Longrightarrow> Q x)" |
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47325
diff
changeset
|
80 |
unfolding transfer_bforall_def atomize_imp atomize_all .. |
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47325
diff
changeset
|
81 |
|
67399 | 82 |
lemma transfer_start: "\<lbrakk>P; Rel (=) P Q\<rbrakk> \<Longrightarrow> Q" |
47325 | 83 |
unfolding Rel_def by simp |
84 |
||
67399 | 85 |
lemma transfer_start': "\<lbrakk>P; Rel (\<longrightarrow>) P Q\<rbrakk> \<Longrightarrow> Q" |
47325 | 86 |
unfolding Rel_def by simp |
87 |
||
47635
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
huffman
parents:
47627
diff
changeset
|
88 |
lemma transfer_prover_start: "\<lbrakk>x = x'; Rel R x' y\<rbrakk> \<Longrightarrow> Rel R x y" |
47618
1568dadd598a
make correspondence tactic more robust by replacing lhs with schematic variable before applying intro rules
huffman
parents:
47612
diff
changeset
|
89 |
by simp |
1568dadd598a
make correspondence tactic more robust by replacing lhs with schematic variable before applying intro rules
huffman
parents:
47612
diff
changeset
|
90 |
|
67399 | 91 |
lemma untransfer_start: "\<lbrakk>Q; Rel (=) P Q\<rbrakk> \<Longrightarrow> P" |
52358
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
huffman
parents:
52354
diff
changeset
|
92 |
unfolding Rel_def by simp |
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
huffman
parents:
52354
diff
changeset
|
93 |
|
67399 | 94 |
lemma Rel_eq_refl: "Rel (=) x x" |
47325 | 95 |
unfolding Rel_def .. |
96 |
||
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47684
diff
changeset
|
97 |
lemma Rel_app: |
47523
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset
|
98 |
assumes "Rel (A ===> B) f g" and "Rel A x y" |
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47684
diff
changeset
|
99 |
shows "Rel B (f x) (g y)" |
55945 | 100 |
using assms unfolding Rel_def rel_fun_def by fast |
47523
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset
|
101 |
|
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47684
diff
changeset
|
102 |
lemma Rel_abs: |
47523
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset
|
103 |
assumes "\<And>x y. Rel A x y \<Longrightarrow> Rel B (f x) (g y)" |
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47684
diff
changeset
|
104 |
shows "Rel (A ===> B) (\<lambda>x. f x) (\<lambda>y. g y)" |
55945 | 105 |
using assms unfolding Rel_def rel_fun_def by fast |
47523
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset
|
106 |
|
60758 | 107 |
subsection \<open>Predicates on relations, i.e. ``class constraints''\<close> |
47325 | 108 |
|
82284
a01ea04aa58f
removed lemmas left_unique_iff and right_unique_iff
desharna
parents:
82282
diff
changeset
|
109 |
text \<open>See also \<^const>\<open>Relation.left_unique\<close> and \<^const>\<open>Relation.right_unique\<close>.\<close> |
a01ea04aa58f
removed lemmas left_unique_iff and right_unique_iff
desharna
parents:
82282
diff
changeset
|
110 |
|
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
111 |
definition left_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
112 |
where "left_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y)" |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
113 |
|
47325 | 114 |
definition right_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" |
115 |
where "right_total R \<longleftrightarrow> (\<forall>y. \<exists>x. R x y)" |
|
116 |
||
117 |
definition bi_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" |
|
118 |
where "bi_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y) \<and> (\<forall>y. \<exists>x. R x y)" |
|
119 |
||
120 |
definition bi_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" |
|
121 |
where "bi_unique R \<longleftrightarrow> |
|
122 |
(\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z) \<and> |
|
123 |
(\<forall>x y z. R x z \<longrightarrow> R y z \<longrightarrow> x = y)" |
|
124 |
||
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
125 |
lemma left_totalI: |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
126 |
"(\<And>x. \<exists>y. R x y) \<Longrightarrow> left_total R" |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
127 |
unfolding left_total_def by blast |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
128 |
|
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
129 |
lemma left_totalE: |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
130 |
assumes "left_total R" |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
131 |
obtains "(\<And>x. \<exists>y. R x y)" |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
132 |
using assms unfolding left_total_def by blast |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
133 |
|
53927 | 134 |
lemma bi_uniqueDr: "\<lbrakk> bi_unique A; A x y; A x z \<rbrakk> \<Longrightarrow> y = z" |
71827 | 135 |
by(simp add: bi_unique_def) |
53927 | 136 |
|
137 |
lemma bi_uniqueDl: "\<lbrakk> bi_unique A; A x y; A z y \<rbrakk> \<Longrightarrow> x = z" |
|
71827 | 138 |
by(simp add: bi_unique_def) |
139 |
||
140 |
lemma bi_unique_iff: "bi_unique R \<longleftrightarrow> (\<forall>z. \<exists>\<^sub>\<le>\<^sub>1x. R x z) \<and> (\<forall>z. \<exists>\<^sub>\<le>\<^sub>1x. R z x)" |
|
141 |
unfolding Uniq_def bi_unique_def by force |
|
142 |
||
59514
509caf5edfa6
add intro and elim rules for right_total
Andreas Lochbihler
parents:
59276
diff
changeset
|
143 |
lemma right_totalI: "(\<And>y. \<exists>x. A x y) \<Longrightarrow> right_total A" |
509caf5edfa6
add intro and elim rules for right_total
Andreas Lochbihler
parents:
59276
diff
changeset
|
144 |
by(simp add: right_total_def) |
509caf5edfa6
add intro and elim rules for right_total
Andreas Lochbihler
parents:
59276
diff
changeset
|
145 |
|
509caf5edfa6
add intro and elim rules for right_total
Andreas Lochbihler
parents:
59276
diff
changeset
|
146 |
lemma right_totalE: |
509caf5edfa6
add intro and elim rules for right_total
Andreas Lochbihler
parents:
59276
diff
changeset
|
147 |
assumes "right_total A" |
509caf5edfa6
add intro and elim rules for right_total
Andreas Lochbihler
parents:
59276
diff
changeset
|
148 |
obtains x where "A x y" |
509caf5edfa6
add intro and elim rules for right_total
Andreas Lochbihler
parents:
59276
diff
changeset
|
149 |
using assms by(auto simp add: right_total_def) |
509caf5edfa6
add intro and elim rules for right_total
Andreas Lochbihler
parents:
59276
diff
changeset
|
150 |
|
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
151 |
lemma right_total_alt_def2: |
71697 | 152 |
"right_total R \<longleftrightarrow> ((R ===> (\<longrightarrow>)) ===> (\<longrightarrow>)) All All" (is "?lhs = ?rhs") |
153 |
proof |
|
154 |
assume ?lhs then show ?rhs |
|
155 |
unfolding right_total_def rel_fun_def by blast |
|
156 |
next |
|
157 |
assume \<section>: ?rhs |
|
158 |
show ?lhs |
|
159 |
using \<section> [unfolded rel_fun_def, rule_format, of "\<lambda>x. True" "\<lambda>y. \<exists>x. R x y"] |
|
160 |
unfolding right_total_def by blast |
|
161 |
qed |
|
47325 | 162 |
|
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
163 |
lemma right_unique_alt_def2: |
67399 | 164 |
"right_unique R \<longleftrightarrow> (R ===> R ===> (\<longrightarrow>)) (=) (=)" |
55945 | 165 |
unfolding right_unique_def rel_fun_def by auto |
47325 | 166 |
|
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
167 |
lemma bi_total_alt_def2: |
71697 | 168 |
"bi_total R \<longleftrightarrow> ((R ===> (=)) ===> (=)) All All" (is "?lhs = ?rhs") |
169 |
proof |
|
170 |
assume ?lhs then show ?rhs |
|
171 |
unfolding bi_total_def rel_fun_def by blast |
|
172 |
next |
|
173 |
assume \<section>: ?rhs |
|
174 |
show ?lhs |
|
175 |
using \<section> [unfolded rel_fun_def, rule_format, of "\<lambda>x. \<exists>y. R x y" "\<lambda>y. True"] |
|
176 |
using \<section> [unfolded rel_fun_def, rule_format, of "\<lambda>x. True" "\<lambda>y. \<exists>x. R x y"] |
|
177 |
by (auto simp: bi_total_def) |
|
178 |
qed |
|
47325 | 179 |
|
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
180 |
lemma bi_unique_alt_def2: |
67399 | 181 |
"bi_unique R \<longleftrightarrow> (R ===> R ===> (=)) (=) (=)" |
55945 | 182 |
unfolding bi_unique_def rel_fun_def by auto |
47325 | 183 |
|
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
184 |
lemma [simp]: |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
185 |
shows left_total_conversep: "left_total A\<inverse>\<inverse> \<longleftrightarrow> right_total A" |
71697 | 186 |
and right_total_conversep: "right_total A\<inverse>\<inverse> \<longleftrightarrow> left_total A" |
187 |
by(simp_all add: left_total_def right_total_def) |
|
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
188 |
|
53944 | 189 |
lemma bi_unique_conversep [simp]: "bi_unique R\<inverse>\<inverse> = bi_unique R" |
71697 | 190 |
by(auto simp add: bi_unique_def) |
53944 | 191 |
|
192 |
lemma bi_total_conversep [simp]: "bi_total R\<inverse>\<inverse> = bi_total R" |
|
71697 | 193 |
by(auto simp add: bi_total_def) |
53944 | 194 |
|
67399 | 195 |
lemma right_unique_alt_def: "right_unique R = (conversep R OO R \<le> (=))" unfolding right_unique_def by blast |
196 |
lemma left_unique_alt_def: "left_unique R = (R OO (conversep R) \<le> (=))" unfolding left_unique_def by blast |
|
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
197 |
|
67399 | 198 |
lemma right_total_alt_def: "right_total R = (conversep R OO R \<ge> (=))" unfolding right_total_def by blast |
199 |
lemma left_total_alt_def: "left_total R = (R OO conversep R \<ge> (=))" unfolding left_total_def by blast |
|
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
200 |
|
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
201 |
lemma bi_total_alt_def: "bi_total A = (left_total A \<and> right_total A)" |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
202 |
unfolding left_total_def right_total_def bi_total_def by blast |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
203 |
|
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
204 |
lemma bi_unique_alt_def: "bi_unique A = (left_unique A \<and> right_unique A)" |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
205 |
unfolding left_unique_def right_unique_def bi_unique_def by blast |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
206 |
|
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
207 |
lemma bi_totalI: "left_total R \<Longrightarrow> right_total R \<Longrightarrow> bi_total R" |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
208 |
unfolding bi_total_alt_def .. |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
209 |
|
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
210 |
lemma bi_uniqueI: "left_unique R \<Longrightarrow> right_unique R \<Longrightarrow> bi_unique R" |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
211 |
unfolding bi_unique_alt_def .. |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
212 |
|
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
213 |
end |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
214 |
|
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
215 |
|
70491 | 216 |
lemma is_equality_lemma: "(\<And>R. is_equality R \<Longrightarrow> PROP (P R)) \<equiv> PROP (P (=))" |
71697 | 217 |
unfolding is_equality_def |
218 |
proof (rule equal_intr_rule) |
|
219 |
show "(\<And>R. R = (=) \<Longrightarrow> PROP P R) \<Longrightarrow> PROP P (=)" |
|
220 |
apply (drule meta_spec) |
|
221 |
apply (erule meta_mp [OF _ refl]) |
|
222 |
done |
|
223 |
qed simp |
|
70491 | 224 |
|
225 |
lemma Domainp_lemma: "(\<And>R. Domainp T = R \<Longrightarrow> PROP (P R)) \<equiv> PROP (P (Domainp T))" |
|
71697 | 226 |
proof (rule equal_intr_rule) |
227 |
show "(\<And>R. Domainp T = R \<Longrightarrow> PROP P R) \<Longrightarrow> PROP P (Domainp T)" |
|
228 |
apply (drule meta_spec) |
|
229 |
apply (erule meta_mp [OF _ refl]) |
|
230 |
done |
|
231 |
qed simp |
|
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
232 |
|
69605 | 233 |
ML_file \<open>Tools/Transfer/transfer.ML\<close> |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
234 |
declare refl [transfer_rule] |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
235 |
|
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
236 |
hide_const (open) Rel |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
237 |
|
63343 | 238 |
context includes lifting_syntax |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
239 |
begin |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
240 |
|
60758 | 241 |
text \<open>Handling of domains\<close> |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
242 |
|
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
243 |
lemma Domainp_iff: "Domainp T x \<longleftrightarrow> (\<exists>y. T x y)" |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
244 |
by auto |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
245 |
|
58386 | 246 |
lemma Domainp_refl[transfer_domain_rule]: |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
247 |
"Domainp T = Domainp T" .. |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
248 |
|
67399 | 249 |
lemma Domain_eq_top[transfer_domain_rule]: "Domainp (=) = top" by auto |
60229
4cd6462c1fda
Workaround that allows us to execute lifted constants that have as a return type a datatype containing a subtype
kuncar
parents:
59523
diff
changeset
|
250 |
|
64425
b17acc1834e3
a more general relator domain rule for the function type
kuncar
parents:
64014
diff
changeset
|
251 |
lemma Domainp_pred_fun_eq[relator_domain]: |
b17acc1834e3
a more general relator domain rule for the function type
kuncar
parents:
64014
diff
changeset
|
252 |
assumes "left_unique T" |
71697 | 253 |
shows "Domainp (T ===> S) = pred_fun (Domainp T) (Domainp S)" (is "?lhs = ?rhs") |
254 |
proof (intro ext iffI) |
|
255 |
fix x |
|
256 |
assume "?lhs x" |
|
257 |
then show "?rhs x" |
|
258 |
using assms unfolding rel_fun_def pred_fun_def by blast |
|
259 |
next |
|
260 |
fix x |
|
261 |
assume "?rhs x" |
|
262 |
then have "\<exists>g. \<forall>y xa. T xa y \<longrightarrow> S (x xa) (g y)" |
|
263 |
using assms unfolding Domainp_iff left_unique_def pred_fun_def |
|
264 |
by (intro choice) blast |
|
265 |
then show "?lhs x" |
|
266 |
by blast |
|
267 |
qed |
|
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
268 |
|
60758 | 269 |
text \<open>Properties are preserved by relation composition.\<close> |
47660 | 270 |
|
271 |
lemma OO_def: "R OO S = (\<lambda>x z. \<exists>y. R x y \<and> S y z)" |
|
272 |
by auto |
|
273 |
||
274 |
lemma bi_total_OO: "\<lbrakk>bi_total A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A OO B)" |
|
56085 | 275 |
unfolding bi_total_def OO_def by fast |
47660 | 276 |
|
277 |
lemma bi_unique_OO: "\<lbrakk>bi_unique A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A OO B)" |
|
56085 | 278 |
unfolding bi_unique_def OO_def by blast |
47660 | 279 |
|
280 |
lemma right_total_OO: |
|
281 |
"\<lbrakk>right_total A; right_total B\<rbrakk> \<Longrightarrow> right_total (A OO B)" |
|
56085 | 282 |
unfolding right_total_def OO_def by fast |
47660 | 283 |
|
284 |
lemma right_unique_OO: |
|
285 |
"\<lbrakk>right_unique A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A OO B)" |
|
56085 | 286 |
unfolding right_unique_def OO_def by fast |
47660 | 287 |
|
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
288 |
lemma left_total_OO: "left_total R \<Longrightarrow> left_total S \<Longrightarrow> left_total (R OO S)" |
71697 | 289 |
unfolding left_total_def OO_def by fast |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
290 |
|
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
291 |
lemma left_unique_OO: "left_unique R \<Longrightarrow> left_unique S \<Longrightarrow> left_unique (R OO S)" |
71697 | 292 |
unfolding left_unique_def OO_def by blast |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
293 |
|
47325 | 294 |
|
60758 | 295 |
subsection \<open>Properties of relators\<close> |
47325 | 296 |
|
67399 | 297 |
lemma left_total_eq[transfer_rule]: "left_total (=)" |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
298 |
unfolding left_total_def by blast |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
299 |
|
67399 | 300 |
lemma left_unique_eq[transfer_rule]: "left_unique (=)" |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
301 |
unfolding left_unique_def by blast |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
302 |
|
67399 | 303 |
lemma right_total_eq [transfer_rule]: "right_total (=)" |
47325 | 304 |
unfolding right_total_def by simp |
305 |
||
67399 | 306 |
lemma right_unique_eq [transfer_rule]: "right_unique (=)" |
47325 | 307 |
unfolding right_unique_def by simp |
308 |
||
67399 | 309 |
lemma bi_total_eq[transfer_rule]: "bi_total (=)" |
47325 | 310 |
unfolding bi_total_def by simp |
311 |
||
67399 | 312 |
lemma bi_unique_eq[transfer_rule]: "bi_unique (=)" |
47325 | 313 |
unfolding bi_unique_def by simp |
314 |
||
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
315 |
lemma left_total_fun[transfer_rule]: |
71697 | 316 |
assumes "left_unique A" "left_total B" |
317 |
shows "left_total (A ===> B)" |
|
318 |
unfolding left_total_def |
|
319 |
proof |
|
320 |
fix f |
|
321 |
show "Ex ((A ===> B) f)" |
|
322 |
unfolding rel_fun_def |
|
323 |
proof (intro exI strip) |
|
324 |
fix x y |
|
325 |
assume A: "A x y" |
|
326 |
have "(THE x. A x y) = x" |
|
327 |
using A assms by (simp add: left_unique_def the_equality) |
|
328 |
then show "B (f x) (SOME z. B (f (THE x. A x y)) z)" |
|
329 |
using assms by (force simp: left_total_def intro: someI_ex) |
|
330 |
qed |
|
331 |
qed |
|
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
332 |
|
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
333 |
lemma left_unique_fun[transfer_rule]: |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
334 |
"\<lbrakk>left_total A; left_unique B\<rbrakk> \<Longrightarrow> left_unique (A ===> B)" |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
335 |
unfolding left_total_def left_unique_def rel_fun_def |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
336 |
by (clarify, rule ext, fast) |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
337 |
|
47325 | 338 |
lemma right_total_fun [transfer_rule]: |
71697 | 339 |
assumes "right_unique A" "right_total B" |
340 |
shows "right_total (A ===> B)" |
|
341 |
unfolding right_total_def |
|
342 |
proof |
|
343 |
fix g |
|
344 |
show "\<exists>x. (A ===> B) x g" |
|
345 |
unfolding rel_fun_def |
|
346 |
proof (intro exI strip) |
|
347 |
fix x y |
|
348 |
assume A: "A x y" |
|
349 |
have "(THE y. A x y) = y" |
|
350 |
using A assms by (simp add: right_unique_def the_equality) |
|
351 |
then show "B (SOME z. B z (g (THE y. A x y))) (g y)" |
|
352 |
using assms by (force simp: right_total_def intro: someI_ex) |
|
353 |
qed |
|
354 |
qed |
|
47325 | 355 |
|
356 |
lemma right_unique_fun [transfer_rule]: |
|
357 |
"\<lbrakk>right_total A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A ===> B)" |
|
55945 | 358 |
unfolding right_total_def right_unique_def rel_fun_def |
47325 | 359 |
by (clarify, rule ext, fast) |
360 |
||
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
361 |
lemma bi_total_fun[transfer_rule]: |
47325 | 362 |
"\<lbrakk>bi_unique A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A ===> B)" |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
363 |
unfolding bi_unique_alt_def bi_total_alt_def |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
364 |
by (blast intro: right_total_fun left_total_fun) |
47325 | 365 |
|
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
366 |
lemma bi_unique_fun[transfer_rule]: |
47325 | 367 |
"\<lbrakk>bi_total A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A ===> B)" |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
368 |
unfolding bi_unique_alt_def bi_total_alt_def |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
369 |
by (blast intro: right_unique_fun left_unique_fun) |
47325 | 370 |
|
56543
9bd56f2e4c10
bi_unique and co. rules from the BNF hook must be introduced after bi_unique op= and co. rules are introduced
kuncar
parents:
56524
diff
changeset
|
371 |
end |
9bd56f2e4c10
bi_unique and co. rules from the BNF hook must be introduced after bi_unique op= and co. rules are introduced
kuncar
parents:
56524
diff
changeset
|
372 |
|
59275
77cd4992edcd
Add plugin to generate transfer theorem for primrec and primcorec
desharna
parents:
59141
diff
changeset
|
373 |
lemma if_conn: |
77cd4992edcd
Add plugin to generate transfer theorem for primrec and primcorec
desharna
parents:
59141
diff
changeset
|
374 |
"(if P \<and> Q then t else e) = (if P then if Q then t else e else e)" |
77cd4992edcd
Add plugin to generate transfer theorem for primrec and primcorec
desharna
parents:
59141
diff
changeset
|
375 |
"(if P \<or> Q then t else e) = (if P then t else if Q then t else e)" |
77cd4992edcd
Add plugin to generate transfer theorem for primrec and primcorec
desharna
parents:
59141
diff
changeset
|
376 |
"(if P \<longrightarrow> Q then t else e) = (if P then if Q then t else e else t)" |
77cd4992edcd
Add plugin to generate transfer theorem for primrec and primcorec
desharna
parents:
59141
diff
changeset
|
377 |
"(if \<not> P then t else e) = (if P then e else t)" |
77cd4992edcd
Add plugin to generate transfer theorem for primrec and primcorec
desharna
parents:
59141
diff
changeset
|
378 |
by auto |
77cd4992edcd
Add plugin to generate transfer theorem for primrec and primcorec
desharna
parents:
59141
diff
changeset
|
379 |
|
69605 | 380 |
ML_file \<open>Tools/Transfer/transfer_bnf.ML\<close> |
381 |
ML_file \<open>Tools/BNF/bnf_fp_rec_sugar_transfer.ML\<close> |
|
59275
77cd4992edcd
Add plugin to generate transfer theorem for primrec and primcorec
desharna
parents:
59141
diff
changeset
|
382 |
|
56543
9bd56f2e4c10
bi_unique and co. rules from the BNF hook must be introduced after bi_unique op= and co. rules are introduced
kuncar
parents:
56524
diff
changeset
|
383 |
declare pred_fun_def [simp] |
9bd56f2e4c10
bi_unique and co. rules from the BNF hook must be introduced after bi_unique op= and co. rules are introduced
kuncar
parents:
56524
diff
changeset
|
384 |
declare rel_fun_eq [relator_eq] |
9bd56f2e4c10
bi_unique and co. rules from the BNF hook must be introduced after bi_unique op= and co. rules are introduced
kuncar
parents:
56524
diff
changeset
|
385 |
|
64425
b17acc1834e3
a more general relator domain rule for the function type
kuncar
parents:
64014
diff
changeset
|
386 |
(* Delete the automated generated rule from the bnf command; |
b17acc1834e3
a more general relator domain rule for the function type
kuncar
parents:
64014
diff
changeset
|
387 |
we have a more general rule (Domainp_pred_fun_eq) that subsumes it. *) |
b17acc1834e3
a more general relator domain rule for the function type
kuncar
parents:
64014
diff
changeset
|
388 |
declare fun.Domainp_rel[relator_domain del] |
b17acc1834e3
a more general relator domain rule for the function type
kuncar
parents:
64014
diff
changeset
|
389 |
|
60758 | 390 |
subsection \<open>Transfer rules\<close> |
47325 | 391 |
|
63343 | 392 |
context includes lifting_syntax |
56543
9bd56f2e4c10
bi_unique and co. rules from the BNF hook must be introduced after bi_unique op= and co. rules are introduced
kuncar
parents:
56524
diff
changeset
|
393 |
begin |
9bd56f2e4c10
bi_unique and co. rules from the BNF hook must be introduced after bi_unique op= and co. rules are introduced
kuncar
parents:
56524
diff
changeset
|
394 |
|
53952 | 395 |
lemma Domainp_forall_transfer [transfer_rule]: |
396 |
assumes "right_total A" |
|
67399 | 397 |
shows "((A ===> (=)) ===> (=)) |
53952 | 398 |
(transfer_bforall (Domainp A)) transfer_forall" |
399 |
using assms unfolding right_total_def |
|
55945 | 400 |
unfolding transfer_forall_def transfer_bforall_def rel_fun_def Domainp_iff |
56085 | 401 |
by fast |
53952 | 402 |
|
60758 | 403 |
text \<open>Transfer rules using implication instead of equality on booleans.\<close> |
47684 | 404 |
|
52354
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
405 |
lemma transfer_forall_transfer [transfer_rule]: |
67399 | 406 |
"bi_total A \<Longrightarrow> ((A ===> (=)) ===> (=)) transfer_forall transfer_forall" |
407 |
"right_total A \<Longrightarrow> ((A ===> (=)) ===> implies) transfer_forall transfer_forall" |
|
52354
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
408 |
"right_total A \<Longrightarrow> ((A ===> implies) ===> implies) transfer_forall transfer_forall" |
67399 | 409 |
"bi_total A \<Longrightarrow> ((A ===> (=)) ===> rev_implies) transfer_forall transfer_forall" |
52354
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
410 |
"bi_total A \<Longrightarrow> ((A ===> rev_implies) ===> rev_implies) transfer_forall transfer_forall" |
55945 | 411 |
unfolding transfer_forall_def rev_implies_def rel_fun_def right_total_def bi_total_def |
56085 | 412 |
by fast+ |
52354
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
413 |
|
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
414 |
lemma transfer_implies_transfer [transfer_rule]: |
67399 | 415 |
"((=) ===> (=) ===> (=) ) transfer_implies transfer_implies" |
52354
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
416 |
"(rev_implies ===> implies ===> implies ) transfer_implies transfer_implies" |
67399 | 417 |
"(rev_implies ===> (=) ===> implies ) transfer_implies transfer_implies" |
418 |
"((=) ===> implies ===> implies ) transfer_implies transfer_implies" |
|
419 |
"((=) ===> (=) ===> implies ) transfer_implies transfer_implies" |
|
52354
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
420 |
"(implies ===> rev_implies ===> rev_implies) transfer_implies transfer_implies" |
67399 | 421 |
"(implies ===> (=) ===> rev_implies) transfer_implies transfer_implies" |
422 |
"((=) ===> rev_implies ===> rev_implies) transfer_implies transfer_implies" |
|
423 |
"((=) ===> (=) ===> rev_implies) transfer_implies transfer_implies" |
|
55945 | 424 |
unfolding transfer_implies_def rev_implies_def rel_fun_def by auto |
52354
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
huffman
parents:
51956
diff
changeset
|
425 |
|
47684 | 426 |
lemma eq_imp_transfer [transfer_rule]: |
67399 | 427 |
"right_unique A \<Longrightarrow> (A ===> A ===> (\<longrightarrow>)) (=) (=)" |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
428 |
unfolding right_unique_alt_def2 . |
47684 | 429 |
|
60758 | 430 |
text \<open>Transfer rules using equality.\<close> |
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
431 |
|
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
432 |
lemma left_unique_transfer [transfer_rule]: |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
433 |
assumes "right_total A" |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
434 |
assumes "right_total B" |
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
435 |
assumes "bi_unique A" |
67399 | 436 |
shows "((A ===> B ===> (=)) ===> implies) left_unique left_unique" |
71697 | 437 |
using assms unfolding left_unique_def right_total_def bi_unique_def rel_fun_def |
438 |
by metis |
|
56518
beb3b6851665
left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents:
56085
diff
changeset
|
439 |
|
47636 | 440 |
lemma eq_transfer [transfer_rule]: |
47325 | 441 |
assumes "bi_unique A" |
67399 | 442 |
shows "(A ===> A ===> (=)) (=) (=)" |
55945 | 443 |
using assms unfolding bi_unique_def rel_fun_def by auto |
47325 | 444 |
|
51956
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents:
51955
diff
changeset
|
445 |
lemma right_total_Ex_transfer[transfer_rule]: |
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents:
51955
diff
changeset
|
446 |
assumes "right_total A" |
67399 | 447 |
shows "((A ===> (=)) ===> (=)) (Bex (Collect (Domainp A))) Ex" |
71697 | 448 |
using assms unfolding right_total_def Bex_def rel_fun_def Domainp_iff |
449 |
by fast |
|
51956
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents:
51955
diff
changeset
|
450 |
|
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents:
51955
diff
changeset
|
451 |
lemma right_total_All_transfer[transfer_rule]: |
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents:
51955
diff
changeset
|
452 |
assumes "right_total A" |
67399 | 453 |
shows "((A ===> (=)) ===> (=)) (Ball (Collect (Domainp A))) All" |
71697 | 454 |
using assms unfolding right_total_def Ball_def rel_fun_def Domainp_iff |
455 |
by fast |
|
51956
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents:
51955
diff
changeset
|
456 |
|
70927 | 457 |
context |
458 |
includes lifting_syntax |
|
459 |
begin |
|
460 |
||
68521 | 461 |
lemma right_total_fun_eq_transfer: |
462 |
assumes [transfer_rule]: "right_total A" "bi_unique B" |
|
463 |
shows "((A ===> B) ===> (A ===> B) ===> (=)) (\<lambda>f g. \<forall>x\<in>Collect(Domainp A). f x = g x) (=)" |
|
464 |
unfolding fun_eq_iff |
|
465 |
by transfer_prover |
|
466 |
||
70927 | 467 |
end |
468 |
||
47636 | 469 |
lemma All_transfer [transfer_rule]: |
47325 | 470 |
assumes "bi_total A" |
67399 | 471 |
shows "((A ===> (=)) ===> (=)) All All" |
55945 | 472 |
using assms unfolding bi_total_def rel_fun_def by fast |
47325 | 473 |
|
47636 | 474 |
lemma Ex_transfer [transfer_rule]: |
47325 | 475 |
assumes "bi_total A" |
67399 | 476 |
shows "((A ===> (=)) ===> (=)) Ex Ex" |
55945 | 477 |
using assms unfolding bi_total_def rel_fun_def by fast |
47325 | 478 |
|
59515 | 479 |
lemma Ex1_parametric [transfer_rule]: |
480 |
assumes [transfer_rule]: "bi_unique A" "bi_total A" |
|
67399 | 481 |
shows "((A ===> (=)) ===> (=)) Ex1 Ex1" |
71697 | 482 |
unfolding Ex1_def by transfer_prover |
59515 | 483 |
|
58448 | 484 |
declare If_transfer [transfer_rule] |
47325 | 485 |
|
47636 | 486 |
lemma Let_transfer [transfer_rule]: "(A ===> (A ===> B) ===> B) Let Let" |
55945 | 487 |
unfolding rel_fun_def by simp |
47612 | 488 |
|
58916 | 489 |
declare id_transfer [transfer_rule] |
47625 | 490 |
|
58444 | 491 |
declare comp_transfer [transfer_rule] |
47325 | 492 |
|
58916 | 493 |
lemma curry_transfer [transfer_rule]: |
494 |
"((rel_prod A B ===> C) ===> A ===> B ===> C) curry curry" |
|
495 |
unfolding curry_def by transfer_prover |
|
496 |
||
47636 | 497 |
lemma fun_upd_transfer [transfer_rule]: |
47325 | 498 |
assumes [transfer_rule]: "bi_unique A" |
499 |
shows "((A ===> B) ===> A ===> B ===> A ===> B) fun_upd fun_upd" |
|
71697 | 500 |
unfolding fun_upd_def by transfer_prover |
47325 | 501 |
|
55415 | 502 |
lemma case_nat_transfer [transfer_rule]: |
67399 | 503 |
"(A ===> ((=) ===> A) ===> (=) ===> A) case_nat case_nat" |
55945 | 504 |
unfolding rel_fun_def by (simp split: nat.split) |
47627
2b1d3eda59eb
add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents:
47625
diff
changeset
|
505 |
|
55415 | 506 |
lemma rec_nat_transfer [transfer_rule]: |
67399 | 507 |
"(A ===> ((=) ===> A ===> A) ===> (=) ===> A) rec_nat rec_nat" |
75669
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
71827
diff
changeset
|
508 |
unfolding rel_fun_def |
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
71827
diff
changeset
|
509 |
apply safe |
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
71827
diff
changeset
|
510 |
subgoal for _ _ _ _ _ n |
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
71827
diff
changeset
|
511 |
by (induction n) simp_all |
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
71827
diff
changeset
|
512 |
done |
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
71827
diff
changeset
|
513 |
|
47924 | 514 |
|
515 |
lemma funpow_transfer [transfer_rule]: |
|
67399 | 516 |
"((=) ===> (A ===> A) ===> (A ===> A)) compow compow" |
47924 | 517 |
unfolding funpow_def by transfer_prover |
518 |
||
53952 | 519 |
lemma mono_transfer[transfer_rule]: |
520 |
assumes [transfer_rule]: "bi_total A" |
|
67399 | 521 |
assumes [transfer_rule]: "(A ===> A ===> (=)) (\<le>) (\<le>)" |
522 |
assumes [transfer_rule]: "(B ===> B ===> (=)) (\<le>) (\<le>)" |
|
523 |
shows "((A ===> B) ===> (=)) mono mono" |
|
71697 | 524 |
unfolding mono_def by transfer_prover |
53952 | 525 |
|
58182 | 526 |
lemma right_total_relcompp_transfer[transfer_rule]: |
53952 | 527 |
assumes [transfer_rule]: "right_total B" |
67399 | 528 |
shows "((A ===> B ===> (=)) ===> (B ===> C ===> (=)) ===> A ===> C ===> (=)) |
529 |
(\<lambda>R S x z. \<exists>y\<in>Collect (Domainp B). R x y \<and> S y z) (OO)" |
|
71697 | 530 |
unfolding OO_def by transfer_prover |
53952 | 531 |
|
58182 | 532 |
lemma relcompp_transfer[transfer_rule]: |
53952 | 533 |
assumes [transfer_rule]: "bi_total B" |
67399 | 534 |
shows "((A ===> B ===> (=)) ===> (B ===> C ===> (=)) ===> A ===> C ===> (=)) (OO) (OO)" |
71697 | 535 |
unfolding OO_def by transfer_prover |
47627
2b1d3eda59eb
add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents:
47625
diff
changeset
|
536 |
|
53952 | 537 |
lemma right_total_Domainp_transfer[transfer_rule]: |
538 |
assumes [transfer_rule]: "right_total B" |
|
67399 | 539 |
shows "((A ===> B ===> (=)) ===> A ===> (=)) (\<lambda>T x. \<exists>y\<in>Collect(Domainp B). T x y) Domainp" |
53952 | 540 |
apply(subst(2) Domainp_iff[abs_def]) by transfer_prover |
541 |
||
542 |
lemma Domainp_transfer[transfer_rule]: |
|
543 |
assumes [transfer_rule]: "bi_total B" |
|
67399 | 544 |
shows "((A ===> B ===> (=)) ===> A ===> (=)) Domainp Domainp" |
71697 | 545 |
unfolding Domainp_iff by transfer_prover |
53952 | 546 |
|
58182 | 547 |
lemma reflp_transfer[transfer_rule]: |
67399 | 548 |
"bi_total A \<Longrightarrow> ((A ===> A ===> (=)) ===> (=)) reflp reflp" |
53952 | 549 |
"right_total A \<Longrightarrow> ((A ===> A ===> implies) ===> implies) reflp reflp" |
67399 | 550 |
"right_total A \<Longrightarrow> ((A ===> A ===> (=)) ===> implies) reflp reflp" |
53952 | 551 |
"bi_total A \<Longrightarrow> ((A ===> A ===> rev_implies) ===> rev_implies) reflp reflp" |
67399 | 552 |
"bi_total A \<Longrightarrow> ((A ===> A ===> (=)) ===> rev_implies) reflp reflp" |
71697 | 553 |
unfolding reflp_def rev_implies_def bi_total_def right_total_def rel_fun_def |
53952 | 554 |
by fast+ |
555 |
||
556 |
lemma right_unique_transfer [transfer_rule]: |
|
59523 | 557 |
"\<lbrakk> right_total A; right_total B; bi_unique B \<rbrakk> |
67399 | 558 |
\<Longrightarrow> ((A ===> B ===> (=)) ===> implies) right_unique right_unique" |
71697 | 559 |
unfolding right_unique_def right_total_def bi_unique_def rel_fun_def |
53952 | 560 |
by metis |
47325 | 561 |
|
59523 | 562 |
lemma left_total_parametric [transfer_rule]: |
563 |
assumes [transfer_rule]: "bi_total A" "bi_total B" |
|
67399 | 564 |
shows "((A ===> B ===> (=)) ===> (=)) left_total left_total" |
71697 | 565 |
unfolding left_total_def by transfer_prover |
59523 | 566 |
|
567 |
lemma right_total_parametric [transfer_rule]: |
|
568 |
assumes [transfer_rule]: "bi_total A" "bi_total B" |
|
67399 | 569 |
shows "((A ===> B ===> (=)) ===> (=)) right_total right_total" |
71697 | 570 |
unfolding right_total_def by transfer_prover |
59523 | 571 |
|
572 |
lemma left_unique_parametric [transfer_rule]: |
|
573 |
assumes [transfer_rule]: "bi_unique A" "bi_total A" "bi_total B" |
|
67399 | 574 |
shows "((A ===> B ===> (=)) ===> (=)) left_unique left_unique" |
71697 | 575 |
unfolding left_unique_def by transfer_prover |
59523 | 576 |
|
577 |
lemma prod_pred_parametric [transfer_rule]: |
|
67399 | 578 |
"((A ===> (=)) ===> (B ===> (=)) ===> rel_prod A B ===> (=)) pred_prod pred_prod" |
71697 | 579 |
unfolding prod.pred_set Basic_BNFs.fsts_def Basic_BNFs.snds_def fstsp.simps sndsp.simps |
59523 | 580 |
by simp transfer_prover |
581 |
||
582 |
lemma apfst_parametric [transfer_rule]: |
|
583 |
"((A ===> B) ===> rel_prod A C ===> rel_prod B C) apfst apfst" |
|
71697 | 584 |
unfolding apfst_def by transfer_prover |
59523 | 585 |
|
67399 | 586 |
lemma rel_fun_eq_eq_onp: "((=) ===> eq_onp P) = eq_onp (\<lambda>f. \<forall>x. P(f x))" |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
587 |
unfolding eq_onp_def rel_fun_def by auto |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
588 |
|
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
589 |
lemma rel_fun_eq_onp_rel: |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
590 |
shows "((eq_onp R) ===> S) = (\<lambda>f g. \<forall>x. R x \<longrightarrow> S (f x) (g x))" |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
591 |
by (auto simp add: eq_onp_def rel_fun_def) |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
592 |
|
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
593 |
lemma eq_onp_transfer [transfer_rule]: |
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
594 |
assumes [transfer_rule]: "bi_unique A" |
67399 | 595 |
shows "((A ===> (=)) ===> A ===> A ===> (=)) eq_onp eq_onp" |
71697 | 596 |
unfolding eq_onp_def by transfer_prover |
56524
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
kuncar
parents:
56520
diff
changeset
|
597 |
|
57599 | 598 |
lemma rtranclp_parametric [transfer_rule]: |
599 |
assumes "bi_unique A" "bi_total A" |
|
67399 | 600 |
shows "((A ===> A ===> (=)) ===> A ===> A ===> (=)) rtranclp rtranclp" |
57599 | 601 |
proof(rule rel_funI iffI)+ |
602 |
fix R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" and R' x y x' y' |
|
67399 | 603 |
assume R: "(A ===> A ===> (=)) R R'" and "A x x'" |
57599 | 604 |
{ |
605 |
assume "R\<^sup>*\<^sup>* x y" "A y y'" |
|
606 |
thus "R'\<^sup>*\<^sup>* x' y'" |
|
607 |
proof(induction arbitrary: y') |
|
608 |
case base |
|
60758 | 609 |
with \<open>bi_unique A\<close> \<open>A x x'\<close> have "x' = y'" by(rule bi_uniqueDr) |
57599 | 610 |
thus ?case by simp |
611 |
next |
|
612 |
case (step y z z') |
|
60758 | 613 |
from \<open>bi_total A\<close> obtain y' where "A y y'" unfolding bi_total_def by blast |
57599 | 614 |
hence "R'\<^sup>*\<^sup>* x' y'" by(rule step.IH) |
60758 | 615 |
moreover from R \<open>A y y'\<close> \<open>A z z'\<close> \<open>R y z\<close> |
57599 | 616 |
have "R' y' z'" by(auto dest: rel_funD) |
617 |
ultimately show ?case .. |
|
618 |
qed |
|
619 |
next |
|
620 |
assume "R'\<^sup>*\<^sup>* x' y'" "A y y'" |
|
621 |
thus "R\<^sup>*\<^sup>* x y" |
|
622 |
proof(induction arbitrary: y) |
|
623 |
case base |
|
60758 | 624 |
with \<open>bi_unique A\<close> \<open>A x x'\<close> have "x = y" by(rule bi_uniqueDl) |
57599 | 625 |
thus ?case by simp |
626 |
next |
|
627 |
case (step y' z' z) |
|
60758 | 628 |
from \<open>bi_total A\<close> obtain y where "A y y'" unfolding bi_total_def by blast |
57599 | 629 |
hence "R\<^sup>*\<^sup>* x y" by(rule step.IH) |
60758 | 630 |
moreover from R \<open>A y y'\<close> \<open>A z z'\<close> \<open>R' y' z'\<close> |
57599 | 631 |
have "R y z" by(auto dest: rel_funD) |
632 |
ultimately show ?case .. |
|
633 |
qed |
|
634 |
} |
|
635 |
qed |
|
636 |
||
59523 | 637 |
lemma right_unique_parametric [transfer_rule]: |
638 |
assumes [transfer_rule]: "bi_total A" "bi_unique B" "bi_total B" |
|
67399 | 639 |
shows "((A ===> B ===> (=)) ===> (=)) right_unique right_unique" |
71697 | 640 |
unfolding right_unique_def by transfer_prover |
59523 | 641 |
|
61630 | 642 |
lemma map_fun_parametric [transfer_rule]: |
643 |
"((A ===> B) ===> (C ===> D) ===> (B ===> C) ===> A ===> D) map_fun map_fun" |
|
71697 | 644 |
unfolding map_fun_def by transfer_prover |
61630 | 645 |
|
47325 | 646 |
end |
53011
aeee0a4be6cf
introduce locale with syntax for fun_rel and map_fun and make thus ===> and ---> local
kuncar
parents:
52358
diff
changeset
|
647 |
|
64014 | 648 |
|
71182 | 649 |
subsection \<open>\<^const>\<open>of_bool\<close> and \<^const>\<open>of_nat\<close>\<close> |
650 |
||
651 |
context |
|
652 |
includes lifting_syntax |
|
653 |
begin |
|
654 |
||
655 |
lemma transfer_rule_of_bool: |
|
656 |
\<open>((\<longleftrightarrow>) ===> (\<cong>)) of_bool of_bool\<close> |
|
657 |
if [transfer_rule]: \<open>0 \<cong> 0\<close> \<open>1 \<cong> 1\<close> |
|
658 |
for R :: \<open>'a::zero_neq_one \<Rightarrow> 'b::zero_neq_one \<Rightarrow> bool\<close> (infix \<open>\<cong>\<close> 50) |
|
71697 | 659 |
unfolding of_bool_def by transfer_prover |
64014 | 660 |
|
661 |
lemma transfer_rule_of_nat: |
|
71182 | 662 |
"((=) ===> (\<cong>)) of_nat of_nat" |
663 |
if [transfer_rule]: \<open>0 \<cong> 0\<close> \<open>1 \<cong> 1\<close> |
|
664 |
\<open>((\<cong>) ===> (\<cong>) ===> (\<cong>)) (+) (+)\<close> |
|
665 |
for R :: \<open>'a::semiring_1 \<Rightarrow> 'b::semiring_1 \<Rightarrow> bool\<close> (infix \<open>\<cong>\<close> 50) |
|
71697 | 666 |
unfolding of_nat_def by transfer_prover |
64014 | 667 |
|
53011
aeee0a4be6cf
introduce locale with syntax for fun_rel and map_fun and make thus ===> and ---> local
kuncar
parents:
52358
diff
changeset
|
668 |
end |
71182 | 669 |
|
670 |
end |