author  huffman 
Fri, 20 Apr 2012 10:18:08 +0200  
changeset 47618  1568dadd598a 
parent 47612  bc9c7b5c26fd 
child 47625  10cfaf771687 
permissions  rwrr 
47325  1 
(* Title: HOL/Transfer.thy 
2 
Author: Brian Huffman, TU Muenchen 

3 
*) 

4 

5 
header {* Generic theorem transfer using relations *} 

6 

7 
theory Transfer 

8 
imports Plain Hilbert_Choice 

9 
uses ("Tools/transfer.ML") 

10 
begin 

11 

12 
subsection {* Relator for function space *} 

13 

14 
definition 

15 
fun_rel :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('c \<Rightarrow> 'd) \<Rightarrow> bool" (infixr "===>" 55) 

16 
where 

17 
"fun_rel A B = (\<lambda>f g. \<forall>x y. A x y \<longrightarrow> B (f x) (g y))" 

18 

19 
lemma fun_relI [intro]: 

20 
assumes "\<And>x y. A x y \<Longrightarrow> B (f x) (g y)" 

21 
shows "(A ===> B) f g" 

22 
using assms by (simp add: fun_rel_def) 

23 

24 
lemma fun_relD: 

25 
assumes "(A ===> B) f g" and "A x y" 

26 
shows "B (f x) (g y)" 

27 
using assms by (simp add: fun_rel_def) 

28 

29 
lemma fun_relE: 

30 
assumes "(A ===> B) f g" and "A x y" 

31 
obtains "B (f x) (g y)" 

32 
using assms by (simp add: fun_rel_def) 

33 

34 
lemma fun_rel_eq: 

35 
shows "((op =) ===> (op =)) = (op =)" 

36 
by (auto simp add: fun_eq_iff elim: fun_relE) 

37 

38 
lemma fun_rel_eq_rel: 

39 
shows "((op =) ===> R) = (\<lambda>f g. \<forall>x. R (f x) (g x))" 

40 
by (simp add: fun_rel_def) 

41 

42 

43 
subsection {* Transfer method *} 

44 

45 
text {* Explicit tags for application, abstraction, and relation 

46 
membership allow for backward proof methods. *} 

47 

48 
definition App :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" 

49 
where "App f \<equiv> f" 

50 

51 
definition Abs :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" 

52 
where "Abs f \<equiv> f" 

53 

54 
definition Rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool" 

55 
where "Rel r \<equiv> r" 

56 

57 
text {* Handling of metalogic connectives *} 

58 

59 
definition transfer_forall where 

60 
"transfer_forall \<equiv> All" 

61 

62 
definition transfer_implies where 

63 
"transfer_implies \<equiv> op \<longrightarrow>" 

64 

47355
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47325
diff
changeset

65 
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

66 
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

67 

47325  68 
lemma transfer_forall_eq: "(\<And>x. P x) \<equiv> Trueprop (transfer_forall (\<lambda>x. P x))" 
69 
unfolding atomize_all transfer_forall_def .. 

70 

71 
lemma transfer_implies_eq: "(A \<Longrightarrow> B) \<equiv> Trueprop (transfer_implies A B)" 

72 
unfolding atomize_imp transfer_implies_def .. 

73 

47355
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47325
diff
changeset

74 
lemma transfer_bforall_unfold: 
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47325
diff
changeset

75 
"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

76 
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

77 

47325  78 
lemma transfer_start: "\<lbrakk>Rel (op =) P Q; P\<rbrakk> \<Longrightarrow> Q" 
79 
unfolding Rel_def by simp 

80 

81 
lemma transfer_start': "\<lbrakk>Rel (op \<longrightarrow>) P Q; P\<rbrakk> \<Longrightarrow> Q" 

82 
unfolding Rel_def by simp 

83 

47618
1568dadd598a
make correspondence tactic more robust by replacing lhs with schematic variable before applying intro rules
huffman
parents:
47612
diff
changeset

84 
lemma correspondence_start: "\<lbrakk>x = x'; Rel R x' y\<rbrakk> \<Longrightarrow> Rel R x y" 
1568dadd598a
make correspondence tactic more robust by replacing lhs with schematic variable before applying intro rules
huffman
parents:
47612
diff
changeset

85 
by simp 
1568dadd598a
make correspondence tactic more robust by replacing lhs with schematic variable before applying intro rules
huffman
parents:
47612
diff
changeset

86 

47325  87 
lemma Rel_eq_refl: "Rel (op =) x x" 
88 
unfolding Rel_def .. 

89 

47523
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset

90 
lemma Rel_App: 
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset

91 
assumes "Rel (A ===> B) f g" and "Rel A x y" 
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset

92 
shows "Rel B (App f x) (App g y)" 
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset

93 
using assms unfolding Rel_def App_def fun_rel_def by fast 
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset

94 

1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset

95 
lemma Rel_Abs: 
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset

96 
assumes "\<And>x y. Rel A x y \<Longrightarrow> Rel B (f x) (g y)" 
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset

97 
shows "Rel (A ===> B) (Abs (\<lambda>x. f x)) (Abs (\<lambda>y. g y))" 
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset

98 
using assms unfolding Rel_def Abs_def fun_rel_def by fast 
1bf0e92c1ca0
make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents:
47503
diff
changeset

99 

47325  100 
use "Tools/transfer.ML" 
101 

102 
setup Transfer.setup 

103 

47503  104 
declare fun_rel_eq [relator_eq] 
105 

47325  106 
hide_const (open) App Abs Rel 
107 

108 

109 
subsection {* Predicates on relations, i.e. ``class constraints'' *} 

110 

111 
definition right_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" 

112 
where "right_total R \<longleftrightarrow> (\<forall>y. \<exists>x. R x y)" 

113 

114 
definition right_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" 

115 
where "right_unique R \<longleftrightarrow> (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z)" 

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 

125 
lemma right_total_alt_def: 

126 
"right_total R \<longleftrightarrow> ((R ===> op \<longrightarrow>) ===> op \<longrightarrow>) All All" 

127 
unfolding right_total_def fun_rel_def 

128 
apply (rule iffI, fast) 

129 
apply (rule allI) 

130 
apply (drule_tac x="\<lambda>x. True" in spec) 

131 
apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec) 

132 
apply fast 

133 
done 

134 

135 
lemma right_unique_alt_def: 

136 
"right_unique R \<longleftrightarrow> (R ===> R ===> op \<longrightarrow>) (op =) (op =)" 

137 
unfolding right_unique_def fun_rel_def by auto 

138 

139 
lemma bi_total_alt_def: 

140 
"bi_total R \<longleftrightarrow> ((R ===> op =) ===> op =) All All" 

141 
unfolding bi_total_def fun_rel_def 

142 
apply (rule iffI, fast) 

143 
apply safe 

144 
apply (drule_tac x="\<lambda>x. \<exists>y. R x y" in spec) 

145 
apply (drule_tac x="\<lambda>y. True" in spec) 

146 
apply fast 

147 
apply (drule_tac x="\<lambda>x. True" in spec) 

148 
apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec) 

149 
apply fast 

150 
done 

151 

152 
lemma bi_unique_alt_def: 

153 
"bi_unique R \<longleftrightarrow> (R ===> R ===> op =) (op =) (op =)" 

154 
unfolding bi_unique_def fun_rel_def by auto 

155 

156 

157 
subsection {* Properties of relators *} 

158 

159 
lemma right_total_eq [transfer_rule]: "right_total (op =)" 

160 
unfolding right_total_def by simp 

161 

162 
lemma right_unique_eq [transfer_rule]: "right_unique (op =)" 

163 
unfolding right_unique_def by simp 

164 

165 
lemma bi_total_eq [transfer_rule]: "bi_total (op =)" 

166 
unfolding bi_total_def by simp 

167 

168 
lemma bi_unique_eq [transfer_rule]: "bi_unique (op =)" 

169 
unfolding bi_unique_def by simp 

170 

171 
lemma right_total_fun [transfer_rule]: 

172 
"\<lbrakk>right_unique A; right_total B\<rbrakk> \<Longrightarrow> right_total (A ===> B)" 

173 
unfolding right_total_def fun_rel_def 

174 
apply (rule allI, rename_tac g) 

175 
apply (rule_tac x="\<lambda>x. SOME z. B z (g (THE y. A x y))" in exI) 

176 
apply clarify 

177 
apply (subgoal_tac "(THE y. A x y) = y", simp) 

178 
apply (rule someI_ex) 

179 
apply (simp) 

180 
apply (rule the_equality) 

181 
apply assumption 

182 
apply (simp add: right_unique_def) 

183 
done 

184 

185 
lemma right_unique_fun [transfer_rule]: 

186 
"\<lbrakk>right_total A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A ===> B)" 

187 
unfolding right_total_def right_unique_def fun_rel_def 

188 
by (clarify, rule ext, fast) 

189 

190 
lemma bi_total_fun [transfer_rule]: 

191 
"\<lbrakk>bi_unique A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A ===> B)" 

192 
unfolding bi_total_def fun_rel_def 

193 
apply safe 

194 
apply (rename_tac f) 

195 
apply (rule_tac x="\<lambda>y. SOME z. B (f (THE x. A x y)) z" in exI) 

196 
apply clarify 

197 
apply (subgoal_tac "(THE x. A x y) = x", simp) 

198 
apply (rule someI_ex) 

199 
apply (simp) 

200 
apply (rule the_equality) 

201 
apply assumption 

202 
apply (simp add: bi_unique_def) 

203 
apply (rename_tac g) 

204 
apply (rule_tac x="\<lambda>x. SOME z. B z (g (THE y. A x y))" in exI) 

205 
apply clarify 

206 
apply (subgoal_tac "(THE y. A x y) = y", simp) 

207 
apply (rule someI_ex) 

208 
apply (simp) 

209 
apply (rule the_equality) 

210 
apply assumption 

211 
apply (simp add: bi_unique_def) 

212 
done 

213 

214 
lemma bi_unique_fun [transfer_rule]: 

215 
"\<lbrakk>bi_total A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A ===> B)" 

216 
unfolding bi_total_def bi_unique_def fun_rel_def fun_eq_iff 

217 
by (safe, metis, fast) 

218 

219 

220 
subsection {* Correspondence rules *} 

221 

222 
lemma eq_parametric [transfer_rule]: 

223 
assumes "bi_unique A" 

224 
shows "(A ===> A ===> op =) (op =) (op =)" 

225 
using assms unfolding bi_unique_def fun_rel_def by auto 

226 

227 
lemma All_parametric [transfer_rule]: 

228 
assumes "bi_total A" 

229 
shows "((A ===> op =) ===> op =) All All" 

230 
using assms unfolding bi_total_def fun_rel_def by fast 

231 

232 
lemma Ex_parametric [transfer_rule]: 

233 
assumes "bi_total A" 

234 
shows "((A ===> op =) ===> op =) Ex Ex" 

235 
using assms unfolding bi_total_def fun_rel_def by fast 

236 

237 
lemma If_parametric [transfer_rule]: "(op = ===> A ===> A ===> A) If If" 

238 
unfolding fun_rel_def by simp 

239 

47612  240 
lemma Let_parametric [transfer_rule]: "(A ===> (A ===> B) ===> B) Let Let" 
241 
unfolding fun_rel_def by simp 

242 

47325  243 
lemma comp_parametric [transfer_rule]: 
244 
"((B ===> C) ===> (A ===> B) ===> (A ===> C)) (op \<circ>) (op \<circ>)" 

245 
unfolding fun_rel_def by simp 

246 

247 
lemma fun_upd_parametric [transfer_rule]: 

248 
assumes [transfer_rule]: "bi_unique A" 

249 
shows "((A ===> B) ===> A ===> B ===> A ===> B) fun_upd fun_upd" 

250 
unfolding fun_upd_def [abs_def] by correspondence 

251 

252 
lemmas transfer_forall_parametric [transfer_rule] 

253 
= All_parametric [folded transfer_forall_def] 

254 

255 
end 