Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 813a191

Browse files
committed
chore(logic/basic): Make higher forall_congr/exists_congr lemmas dependent (#11490)
Currently, `forall₂_congr` and friends take as arguments non dependent propositions like `p q : α → β → Prop`. This prevents them being useful virtually anywhere as most often foralls are nested like `∀ a, a ∈ s → ...` and `a ∈ s` depends on `a`. This PR turns them into `Π a, β a → Prop` (and similar for higher arities). As a bonus, it adds the `5`-ary version and golfs all occurrences of nested `forall_congr`s.
1 parent 99e9036 commit 813a191

File tree

31 files changed

+114
-127
lines changed

31 files changed

+114
-127
lines changed

src/algebra/associated.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,7 @@ begin
625625
apply and_congr mk_ne_zero,
626626
apply and_congr,
627627
{ rw [is_unit_mk], },
628-
apply forall_congr, assume a,
629-
apply forall_congr, assume b,
628+
refine forall₂_congr (λ a b, _),
630629
rw [mk_mul_mk, mk_dvd_mk, mk_dvd_mk, mk_dvd_mk],
631630
end
632631

src/analysis/asymptotics/asymptotics.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ by { unfold is_O, exact exists_congr (λ _, is_O_with_norm_right) }
418418
alias is_O_norm_right ↔ asymptotics.is_O.of_norm_right asymptotics.is_O.norm_right
419419

420420
@[simp] theorem is_o_norm_right : is_o f (λ x, ∥g' x∥) l ↔ is_o f g' l :=
421-
by { unfold is_o, exact forall_congr (λ _, forall_congr $ λ _, is_O_with_norm_right) }
421+
by { unfold is_o, exact forall₂_congr (λ _ _, is_O_with_norm_right) }
422422

423423
alias is_o_norm_right ↔ asymptotics.is_o.of_norm_right asymptotics.is_o.norm_right
424424

@@ -433,7 +433,7 @@ by { unfold is_O, exact exists_congr (λ _, is_O_with_norm_left) }
433433
alias is_O_norm_left ↔ asymptotics.is_O.of_norm_left asymptotics.is_O.norm_left
434434

435435
@[simp] theorem is_o_norm_left : is_o (λ x, ∥f' x∥) g l ↔ is_o f' g l :=
436-
by { unfold is_o, exact forall_congr (λ _, forall_congr $ λ _, is_O_with_norm_left) }
436+
by { unfold is_o, exact forall₂_congr (λ _ _, is_O_with_norm_left) }
437437

438438
alias is_o_norm_left ↔ asymptotics.is_o.of_norm_left asymptotics.is_o.norm_left
439439

@@ -468,7 +468,7 @@ by { unfold is_O, exact exists_congr (λ _, is_O_with_neg_right) }
468468
alias is_O_neg_right ↔ asymptotics.is_O.of_neg_right asymptotics.is_O.neg_right
469469

470470
@[simp] theorem is_o_neg_right : is_o f (λ x, -(g' x)) l ↔ is_o f g' l :=
471-
by { unfold is_o, exact forall_congr (λ _, (forall_congr (λ _, is_O_with_neg_right))) }
471+
by { unfold is_o, exact forall₂_congr (λ _ _, is_O_with_neg_right) }
472472

473473
alias is_o_neg_right ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_right
474474

@@ -483,7 +483,7 @@ by { unfold is_O, exact exists_congr (λ _, is_O_with_neg_left) }
483483
alias is_O_neg_left ↔ asymptotics.is_O.of_neg_left asymptotics.is_O.neg_left
484484

485485
@[simp] theorem is_o_neg_left : is_o (λ x, -(f' x)) g l ↔ is_o f' g l :=
486-
by { unfold is_o, exact forall_congr (λ _, (forall_congr (λ _, is_O_with_neg_left))) }
486+
by { unfold is_o, exact forall₂_congr (λ _ _, is_O_with_neg_left) }
487487

488488
alias is_o_neg_left ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_left
489489

@@ -1463,7 +1463,7 @@ by { unfold is_O, exact exists_congr (λ C, e.is_O_with_congr hb) }
14631463
/-- Transfer `is_o` over a `local_homeomorph`. -/
14641464
lemma is_o_congr (e : local_homeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} :
14651465
is_o f g (𝓝 b) ↔ is_o (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=
1466-
by { unfold is_o, exact (forall_congr $ λ c, forall_congr $ λ hc, e.is_O_with_congr hb) }
1466+
by { unfold is_o, exact forall₂_congr (λ c hc, e.is_O_with_congr hb) }
14671467

14681468
end local_homeomorph
14691469

@@ -1488,6 +1488,6 @@ by { unfold is_O, exact exists_congr (λ C, e.is_O_with_congr) }
14881488
/-- Transfer `is_o` over a `homeomorph`. -/
14891489
lemma is_o_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} :
14901490
is_o f g (𝓝 b) ↔ is_o (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=
1491-
by { unfold is_o, exact forall_congr (λ c, forall_congr (λ hc, e.is_O_with_congr)) }
1491+
by { unfold is_o, exact forall₂_congr (λ c hc, e.is_O_with_congr) }
14921492

14931493
end homeomorph

src/analysis/box_integral/basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ lemma integrable_iff_cauchy_basis [complete_space F] :
205205
begin
206206
rw [integrable_iff_cauchy, cauchy_map_iff',
207207
(l.has_basis_to_filter_Union_top _).prod_self.tendsto_iff uniformity_basis_dist_le],
208-
refine forall_congr (λ ε, forall_congr $ λ ε0, exists_congr $ λ r, _),
208+
refine forall₂_congr (λ ε ε0, exists_congr $ λ r, _),
209209
simp only [exists_prop, prod.forall, set.mem_Union, exists_imp_distrib,
210210
prod_mk_mem_set_prod_eq, and_imp, mem_inter_eq, mem_set_of_eq],
211211
exact and_congr iff.rfl ⟨λ H c₁ c₂ π₁ π₂ h₁ hU₁ h₂ hU₂, H π₁ π₂ c₁ h₁ hU₁ c₂ h₂ hU₂,

src/analysis/convex/basic.lean

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,9 @@ variables {𝕜 s}
479479
lemma convex_iff_segment_subset :
480480
convex 𝕜 s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → [x -[𝕜] y] ⊆ s :=
481481
begin
482-
split,
483-
{ rintro h x y hx hy z ⟨a, b, ha, hb, hab, rfl⟩,
484-
exact h hx hy ha hb hab },
485-
{ rintro h x y hx hy a b ha hb hab,
486-
exact h hx hy ⟨a, b, ha, hb, hab, rfl⟩ }
482+
refine forall₄_congr (λ x y hx hy, ⟨_, λ h a b ha hb hab, h ⟨a, b, ha, hb, hab, rfl⟩⟩),
483+
rintro h _ ⟨a, b, ha, hb, hab, rfl⟩,
484+
exact h ha hb hab,
487485
end
488486

489487
lemma convex.segment_subset (h : convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) :
@@ -591,11 +589,8 @@ end
591589

592590
lemma convex_iff_open_segment_subset :
593591
convex 𝕜 s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → open_segment 𝕜 x y ⊆ s :=
594-
begin
595-
rw convex_iff_segment_subset,
596-
exact forall₂_congr (λ x y, forall₂_congr $ λ hx hy,
597-
(open_segment_subset_iff_segment_subset hx hy).symm),
598-
end
592+
convex_iff_segment_subset.trans $ forall₄_congr $ λ x y hx hy,
593+
(open_segment_subset_iff_segment_subset hx hy).symm
599594

600595
lemma convex_singleton (c : E) : convex 𝕜 ({c} : set E) :=
601596
begin

src/analysis/convex/star.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ end
193193

194194
lemma star_convex_iff_open_segment_subset (hx : x ∈ s) :
195195
star_convex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → open_segment 𝕜 x y ⊆ s :=
196-
star_convex_iff_segment_subset.trans $ forall_congr $ λ y, forall_congr $ λ hy,
196+
star_convex_iff_segment_subset.trans $ forall₂_congr $ λ y hy,
197197
(open_segment_subset_iff_segment_subset hx hy).symm
198198

199199
lemma star_convex_singleton (x : E) : star_convex 𝕜 x {x} :=

src/analysis/normed/group/quotient.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ begin
191191
... ↔ ∀ ε > 0, (∃ x ∈ S, x ∈ metric.ball m ε) : by simp [dist_eq_norm, ← sub_eq_add_neg,
192192
norm_sub_rev]
193193
... ↔ m ∈ closure ↑S : by simp [metric.mem_closure_iff, dist_comm],
194-
apply forall_congr, intro ε, apply forall_congr, intro ε_pos,
194+
refine forall₂_congr (λ ε ε_pos, _),
195195
rw [← S.exists_neg_mem_iff_exists_mem],
196196
simp },
197197
{ use 0,

src/category_theory/sites/sheaf.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ lemma is_sheaf_iff_multiequalizer
266266
(∀ (X : C) (S : J.cover X), is_iso (S.to_multiequalizer P)) :=
267267
begin
268268
rw is_sheaf_iff_multifork,
269-
apply forall_congr (λ X, _), apply forall_congr (λ S, _), split,
269+
refine forall₂_congr (λ X S, ⟨_, _⟩),
270270
{ rintros ⟨h⟩,
271271
let e : P.obj (op X) ≅ multiequalizer (S.index P) :=
272272
h.cone_point_unique_up_to_iso (limit.is_limit _),

src/combinatorics/additive/salem_spencer.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ section nat
210210
lemma add_salem_spencer_iff_eq_right {s : set ℕ} :
211211
add_salem_spencer s ↔ ∀ ⦃a b c⦄, a ∈ s → b ∈ s → c ∈ s → a + b = c + c → a = c :=
212212
begin
213-
refine forall_congr (λ a, forall_congr $ λ b, forall_congr $ λ c, forall_congr $
214-
λ _, forall_congr $ λ _, forall_congr $ λ _, forall_congr $ λ habc, ⟨_, _⟩),
213+
refine forall₄_congr (λ a b c _, forall₃_congr $ λ _ _ habc, ⟨_, _⟩),
215214
{ rintro rfl,
216215
simp_rw ←two_mul at habc,
217216
exact mul_left_cancel₀ two_ne_zero habc },

src/data/multiset/basic.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,8 +1868,7 @@ lemma rel_cons_right {as b bs} :
18681868
rel r as (b ::ₘ bs) ↔ (∃a as', r a b ∧ rel r as' bs ∧ as = a ::ₘ as') :=
18691869
begin
18701870
rw [← rel_flip, rel_cons_left],
1871-
apply exists_congr, assume a,
1872-
apply exists_congr, assume as',
1871+
refine exists₂_congr (λ a as', _),
18731872
rw [rel_flip, flip]
18741873
end
18751874

src/data/set/function.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,7 @@ lemma injective_piecewise_iff {f g : α → β} :
951951
begin
952952
rw [injective_iff_inj_on_univ, ← union_compl_self s, inj_on_union (@disjoint_compl_right _ s _),
953953
(piecewise_eq_on s f g).inj_on_iff, (piecewise_eq_on_compl s f g).inj_on_iff],
954-
refine and_congr iff.rfl (and_congr iff.rfl $ forall_congr $ λ x, forall_congr $ λ hx,
955-
forall_congr $ λ y, forall_congr $ λ hy, _),
954+
refine and_congr iff.rfl (and_congr iff.rfl $ forall₄_congr $ λ x hx y hy, _),
956955
rw [piecewise_eq_of_mem s f g hx, piecewise_eq_of_not_mem s f g hy]
957956
end
958957

0 commit comments

Comments
 (0)