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

Commit 7fea719

Browse files
committed
feat(data/set/basic): Laws for n-ary image (#13011)
Prove left/right commutativity, distributivity of `set.image2` in the style of `set.image2_assoc`. Also add `forall₃_imp` and `Exists₃.imp`.
1 parent 9480029 commit 7fea719

File tree

2 files changed

+65
-20
lines changed

2 files changed

+65
-20
lines changed

src/data/set/basic.lean

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,15 @@ end
23282328
@[simp] lemma image2_empty_left : image2 f ∅ t = ∅ := ext $ by simp
23292329
@[simp] lemma image2_empty_right : image2 f s ∅ = ∅ := ext $ by simp
23302330

2331+
lemma nonempty.image2 : s.nonempty → t.nonempty → (image2 f s t).nonempty :=
2332+
λ ⟨a, ha⟩ ⟨b, hb⟩, ⟨_, mem_image2_of_mem ha hb⟩
2333+
2334+
@[simp] lemma image2_nonempty_iff : (image2 f s t).nonempty ↔ s.nonempty ∧ t.nonempty :=
2335+
⟨λ ⟨_, a, b, ha, hb, _⟩, ⟨⟨a, ha⟩, b, hb⟩, λ h, h.1.image2 h.2
2336+
2337+
@[simp] lemma image2_eq_empty_iff : image2 f s t = ∅ ↔ s = ∅ ∨ t = ∅ :=
2338+
by simp_rw [←not_nonempty_iff_eq_empty, image2_nonempty_iff, not_and_distrib]
2339+
23312340
lemma image2_inter_subset_left : image2 f (s ∩ s') t ⊆ image2 f s t ∩ image2 f s' t :=
23322341
by { rintro _ ⟨a, b, ⟨h1a, h2a⟩, hb, rfl⟩, split; exact ⟨_, _, ‹_›, ‹_›, rfl⟩ }
23332342

@@ -2360,6 +2369,9 @@ def image3 (g : α → β → γ → δ) (s : set α) (t : set β) (u : set γ)
23602369
@[simp] lemma mem_image3 : d ∈ image3 g s t u ↔ ∃ a b c, a ∈ s ∧ b ∈ t ∧ c ∈ u ∧ g a b c = d :=
23612370
iff.rfl
23622371

2372+
lemma image3_mono (hs : s ⊆ s') (ht : t ⊆ t') (hu : u ⊆ u') : image3 g s t u ⊆ image3 g s' t' u' :=
2373+
λ x, Exists₃.imp $ λ a b c ⟨ha, hb, hc, hx⟩, ⟨hs ha, ht hb, hu hc, hx⟩
2374+
23632375
@[congr] lemma image3_congr (h : ∀ (a ∈ s) (b ∈ t) (c ∈ u), g a b c = g' a b c) :
23642376
image3 g s t u = image3 g' s t u :=
23652377
by { ext x,
@@ -2385,11 +2397,6 @@ begin
23852397
{ rintro ⟨a, b, c, ha, hb, hc, rfl⟩, refine ⟨a, _, ha, ⟨b, c, hb, hc, rfl⟩, rfl⟩ }
23862398
end
23872399

2388-
lemma image2_assoc {ε'} {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'}
2389-
(h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) :
2390-
image2 f (image2 g s t) u = image2 f' s (image2 g' t u) :=
2391-
by simp only [image2_image2_left, image2_image2_right, h_assoc]
2392-
23932400
lemma image_image2 (f : α → β → γ) (g : γ → δ) :
23942401
g '' image2 f s t = image2 (λ a b, g (f a b)) s t :=
23952402
begin
@@ -2424,8 +2431,38 @@ by simp [nonempty_def.mp h, ext_iff]
24242431
@[simp] lemma image2_right (h : s.nonempty) : image2 (λ x y, y) s t = t :=
24252432
by simp [nonempty_def.mp h, ext_iff]
24262433

2427-
lemma nonempty.image2 (hs : s.nonempty) (ht : t.nonempty) : (image2 f s t).nonempty :=
2428-
by { cases hs with a ha, cases ht with b hb, exact ⟨f a b, ⟨a, b, ha, hb, rfl⟩⟩ }
2434+
lemma image2_assoc {ε'} {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'}
2435+
(h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) :
2436+
image2 f (image2 g s t) u = image2 f' s (image2 g' t u) :=
2437+
by simp only [image2_image2_left, image2_image2_right, h_assoc]
2438+
2439+
lemma image2_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : image2 f s t = image2 g t s :=
2440+
(image2_swap _ _ _).trans $ by simp_rw h_comm
2441+
2442+
lemma image2_left_comm {δ'} {f : α → δ → ε} {g : β → γ → δ} {f' : α → γ → δ'} {g' : β → δ' → ε}
2443+
(h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) :
2444+
image2 f s (image2 g t u) = image2 g' t (image2 f' s u) :=
2445+
by { rw [image2_swap f', image2_swap f], exact image2_assoc (λ _ _ _, h_left_comm _ _ _) }
2446+
2447+
lemma image2_right_comm {δ'} {f : δ → γ → ε} {g : α → β → δ} {f' : α → γ → δ'} {g' : δ' → β → ε}
2448+
(h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) :
2449+
image2 f (image2 g s t) u = image2 g' (image2 f' s u) t :=
2450+
by { rw [image2_swap g, image2_swap g'], exact image2_assoc (λ _ _ _, h_right_comm _ _ _) }
2451+
2452+
lemma image_image2_distrib {α' β'} {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'}
2453+
(h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) :
2454+
(image2 f s t).image g = image2 f' (s.image g₁) (t.image g₂) :=
2455+
by simp_rw [image_image2, image2_image_left, image2_image_right, h_distrib]
2456+
2457+
lemma image_image2_distrib_left {α'} {g : γ → δ} {f' : α' → β → δ} {g' : α → α'}
2458+
(h_distrib : ∀ a b, g (f a b) = f' (g' a) b) :
2459+
(image2 f s t).image g = image2 f' (s.image g') t :=
2460+
(image_image2_distrib h_distrib).trans $ by rw image_id'
2461+
2462+
lemma image_image2_distrib_right {β'} {g : γ → δ} {f' : α → β' → δ} {g' : β → β'}
2463+
(h_distrib : ∀ a b, g (f a b) = f' a (g' b)) :
2464+
(image2 f s t).image g = image2 f' s (t.image g') :=
2465+
(image_image2_distrib h_distrib).trans $ by rw image_id'
24292466

24302467
end n_ary_image
24312468

src/logic/basic.lean

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ end equality
878878
section quantifiers
879879
variables {α : Sort*}
880880

881-
section congr
881+
section dependent
882882
variables {β : α → Sort*} {γ : Π a, β a → Sort*} {δ : Π a b, γ a b → Sort*}
883883
{ε : Π a b c, δ a b c → Sort*}
884884

@@ -899,7 +899,7 @@ lemma forall₅_congr {p q : Π a b c d, ε a b c d → Prop}
899899
(∀ a b c d e, p a b c d e) ↔ ∀ a b c d e, q a b c d e :=
900900
forall_congr $ λ a, forall₄_congr $ h a
901901

902-
lemma exists₂_congr {p q : Π a, β a → Prop} (h : ∀ a b, p a b ↔ q a b) :
902+
lemma exists₂_congr {p q : Π a, β a → Prop} (h : ∀ a b, p a b ↔ q a b) :
903903
(∃ a b, p a b) ↔ ∃ a b, q a b :=
904904
exists_congr $ λ a, exists_congr $ h a
905905

@@ -916,22 +916,30 @@ lemma exists₅_congr {p q : Π a b c d, ε a b c d → Prop}
916916
(∃ a b c d e, p a b c d e) ↔ ∃ a b c d e, q a b c d e :=
917917
exists_congr $ λ a, exists₄_congr $ h a
918918

919-
end congr
919+
lemma forall_imp {p q : α → Prop} (h : ∀ a, p a → q a) : (∀ a, p a) → ∀ a, q a := λ h' a, h a (h' a)
920920

921-
variables {ι β : Sort*} {κ : ι → Sort*} {p q : α → Prop} {b : Prop}
921+
lemma forall₂_imp {p q : Π a, β a → Prop} (h : ∀ a b, p a b → q a b) :
922+
(∀ a b, p a b) → ∀ a b, q a b :=
923+
forall_imp $ λ i, forall_imp $ h i
922924

923-
lemma forall_imp (h : ∀ a, p a → q a) : (∀ a, p a) → ∀ a, q a :=
924-
λ h' a, h a (h' a)
925+
lemma forall₃_imp {p q : Π a b, γ a b → Prop} (h : ∀ a b c, p a b c → q a b c) :
926+
(∀ a b c, p a b c) → ∀ a b c, q a b c :=
927+
forall_imp $ λ a, forall₂_imp $ h a
925928

926-
lemma forall₂_imp {p q : Π i, κ i → Prop} (h : ∀ i j, p i j → q i j) :
927-
(∀ i j, p i j) → ∀ i j, q i j :=
928-
forall_imp $ λ i, forall_imp $ h i
929+
lemma Exists.imp {p q : α → Prop} (h : ∀ a, (p a → q a)) : (∃ a, p a) → ∃ a, q a :=
930+
exists_imp_exists h
929931

930-
lemma Exists.imp (h : ∀ a, (p a → q a)) (p : ∃ a, p a) : ∃ a, q a := exists_imp_exists h p
932+
lemma Exists₂.imp {p q : Π a, β a → Prop} (h : ∀ a b, p a b → q a b) :
933+
(∃ a b, p a b) → ∃ a b, q a b :=
934+
Exists.imp $ λ a, Exists.imp $ h a
931935

932-
lemma Exists₂.imp {p q : Π i, κ i → Prop} (h : ∀ i j, p i j → q i j) :
933-
(∃ i j, p i j) → ∃ i j, q i j :=
934-
Exists.imp $ λ i, Exists.imp $ h i
936+
lemma Exists₃.imp {p q : Π a b, γ a b → Prop} (h : ∀ a b c, p a b c → q a b c) :
937+
(∃ a b c, p a b c) → ∃ a b c, q a b c :=
938+
Exists.imp $ λ a, Exists₂.imp $ h a
939+
940+
end dependent
941+
942+
variables {ι β : Sort*} {κ : ι → Sort*} {p q : α → Prop} {b : Prop}
935943

936944
lemma exists_imp_exists' {p : α → Prop} {q : β → Prop} (f : α → β) (hpq : ∀ a, p a → q (f a))
937945
(hp : ∃ a, p a) : ∃ b, q b :=

0 commit comments

Comments
 (0)