Skip to content

Commit f2a99a1

Browse files
committed
Shorten apply-style proofs in Lens_Order
1 parent 0b6c7bc commit f2a99a1

File tree

2 files changed

+12
-44
lines changed

2 files changed

+12
-44
lines changed

Lens_Algebra.thy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ lemma id_vwb_lens [simp]: "vwb_lens 1\<^sub>L"
123123
lemma unit_vwb_lens [simp]: "vwb_lens 0\<^sub>L"
124124
by (unfold_locales, simp_all add: zero_lens_def)
125125

126-
lemma comp_vwb_lens: "\<lbrakk> vwb_lens x; vwb_lens y \<rbrakk> \<Longrightarrow> vwb_lens (x ;\<^sub>L y)"
126+
lemma comp_vwb_lens [intro]: "\<lbrakk> vwb_lens x; vwb_lens y \<rbrakk> \<Longrightarrow> vwb_lens (x ;\<^sub>L y)"
127127
by (unfold_locales, simp_all add: lens_comp_def weak_lens.put_closure)
128128

129129
lemma unit_ief_lens: "ief_lens 0\<^sub>L"

Lens_Order.thy

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,18 @@ text \<open>Sublens is a preorder as the following two theorems show.\<close>
3030

3131
lemma sublens_refl [simp]:
3232
"X \<subseteq>\<^sub>L X"
33-
using id_vwb_lens sublens_def by fastforce
33+
unfolding sublens_def by (auto intro: exI[where x="1\<^sub>L"])
3434

3535
lemma sublens_trans [trans]:
3636
"\<lbrakk> X \<subseteq>\<^sub>L Y; Y \<subseteq>\<^sub>L Z \<rbrakk> \<Longrightarrow> X \<subseteq>\<^sub>L Z"
37-
apply (auto simp add: sublens_def lens_comp_assoc)
38-
apply (rename_tac Z\<^sub>1 Z\<^sub>2)
39-
apply (rule_tac x="Z\<^sub>1 ;\<^sub>L Z\<^sub>2" in exI)
40-
apply (simp add: lens_comp_assoc)
41-
using comp_vwb_lens apply blast
42-
done
37+
by (auto simp add: sublens_def lens_comp_assoc)
4338

4439
text \<open>Sublens has a least element -- @{text "0\<^sub>L"} -- and a greatest element -- @{text "1\<^sub>L"}.
4540
Intuitively, this shows that sublens orders how large a portion of the source type a particular
4641
lens views, with @{text "0\<^sub>L"} observing the least, and @{text "1\<^sub>L"} observing the most.\<close>
4742

4843
lemma sublens_least: "wb_lens X \<Longrightarrow> 0\<^sub>L \<subseteq>\<^sub>L X"
49-
using sublens_def unit_vwb_lens by fastforce
44+
unfolding sublens_def by (auto intro: exI[where x="0\<^sub>L"])
5045

5146
lemma sublens_greatest: "vwb_lens X \<Longrightarrow> X \<subseteq>\<^sub>L 1\<^sub>L"
5247
by (simp add: sublens_def)
@@ -283,7 +278,7 @@ lemma lens_plus_left_unit: "0\<^sub>L +\<^sub>L X \<approx>\<^sub>L X"
283278
by (simp add: lens_equivI lens_unit_plus_sublens_1 lens_unit_prod_sublens_2)
284279

285280
lemma lens_plus_right_unit: "X +\<^sub>L 0\<^sub>L \<approx>\<^sub>L X"
286-
using lens_equiv_trans lens_indep_sym lens_plus_comm lens_plus_left_unit zero_lens_indep by blast
281+
using lens_equiv_trans lens_plus_comm lens_plus_left_unit zero_lens_indep' by blast
287282

288283
text \<open>We can also show that both sublens and equivalence are congruences with respect to lens plus
289284
and lens product.\<close>
@@ -453,25 +448,12 @@ text \<open>Consequently, if composition of two lenses $X$ and $Y$ yields @{text
453448

454449
lemma bij_lens_via_comp_id_left:
455450
"\<lbrakk> wb_lens X; wb_lens Y; X ;\<^sub>L Y = 1\<^sub>L \<rbrakk> \<Longrightarrow> bij_lens X"
456-
apply (cases Y)
457-
apply (cases X)
458-
apply (auto simp add: lens_comp_def comp_def id_lens_def fun_eq_iff)
459-
apply (unfold_locales)
460-
apply (simp_all)
461-
using vwb_lens_wb wb_lens_weak weak_lens.put_get apply fastforce
462-
apply (metis select_convs(1) select_convs(2) wb_lens_weak weak_lens.put_get)
463-
done
451+
by (smt (z3) bij_lens.intro bij_lens_axioms.intro id_lens_def lens_comp_def lens_comp_right_id
452+
select_convs(1,2) wb_lens_weak weak_lens.put_get)
464453

465454
lemma bij_lens_via_comp_id_right:
466455
"\<lbrakk> wb_lens X; wb_lens Y; X ;\<^sub>L Y = 1\<^sub>L \<rbrakk> \<Longrightarrow> bij_lens Y"
467-
apply (cases Y)
468-
apply (cases X)
469-
apply (auto simp add: lens_comp_def comp_def id_lens_def fun_eq_iff)
470-
apply (unfold_locales)
471-
apply (simp_all)
472-
using vwb_lens_wb wb_lens_weak weak_lens.put_get apply fastforce
473-
apply (metis select_convs(1) select_convs(2) wb_lens_weak weak_lens.put_get)
474-
done
456+
by (metis bij_lens_via_comp_id_left lens_comp_assoc lens_comp_right_id lens_id_unique wb_lens_weak)
475457

476458
text \<open>Importantly, an equivalence between two lenses can be demonstrated by showing that one lens
477459
can be converted to the other by application of a suitable bijective lens $Z$. This $Z$ lens
@@ -480,13 +462,7 @@ text \<open>Importantly, an equivalence between two lenses can be demonstrated b
480462
lemma lens_equiv_via_bij:
481463
assumes "bij_lens Z" "X = Z ;\<^sub>L Y"
482464
shows "X \<approx>\<^sub>L Y"
483-
using assms
484-
apply (auto simp add: lens_equiv_def sublens_def)
485-
using bij_lens_vwb apply blast
486-
apply (rule_tac x="lens_inv Z" in exI)
487-
apply (auto simp add: lens_comp_assoc bij_lens_inv_left)
488-
using bij_lens_vwb lens_inv_bij apply blast
489-
done
465+
by (metis assms(1,2) bij_lens_equiv_id lens_comp_cong_1 lens_comp_left_id)
490466

491467
text \<open>Indeed, we actually have a stronger result than this -- the equivalent lenses are precisely
492468
those than can be converted to one another through a suitable bijective lens. Bijective lenses
@@ -495,20 +471,12 @@ text \<open>Indeed, we actually have a stronger result than this -- the equivale
495471
lemma lens_equiv_iff_bij:
496472
assumes "weak_lens Y"
497473
shows "X \<approx>\<^sub>L Y \<longleftrightarrow> (\<exists> Z. bij_lens Z \<and> X = Z ;\<^sub>L Y)"
498-
apply (rule iffI)
499-
apply (auto simp add: lens_equiv_def sublens_def lens_id_unique)[1]
500-
apply (rename_tac Z\<^sub>1 Z\<^sub>2)
501-
apply (rule_tac x="Z\<^sub>1" in exI)
502-
apply (simp)
503-
apply (subgoal_tac "Z\<^sub>2 ;\<^sub>L Z\<^sub>1 = 1\<^sub>L")
504-
apply (meson bij_lens_via_comp_id_right vwb_lens_wb)
505-
apply (metis assms lens_comp_assoc lens_id_unique)
506-
using lens_equiv_via_bij apply blast
507-
done
474+
by (smt (verit, best) assms bij_lens_equiv_id lens_comp_assoc lens_equiv_def lens_equiv_via_bij
475+
lens_id_unique sublens_def)
508476

509477
lemma pbij_plus_commute:
510478
"\<lbrakk> a \<bowtie> b; mwb_lens a; mwb_lens b; pbij_lens (b +\<^sub>L a) \<rbrakk> \<Longrightarrow> pbij_lens (a +\<^sub>L b)"
511-
apply (unfold_locales, simp_all add:lens_defs lens_indep_sym prod.case_eq_if)
479+
apply (unfold_locales, simp_all add: lens_defs lens_indep_sym prod.case_eq_if)
512480
using lens_indep.lens_put_comm pbij_lens.put_det apply fastforce
513481
done
514482

0 commit comments

Comments
 (0)