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

Commit 655994e

Browse files
committed
refactor(data/set/n_ary): extract from data/set/basic (#17836)
This is essentially just a copy paste, with one or two whitespace fixes. This split is consistent with how `finset/n_ary` is its own file, and does a nice job of making `data/set/basic` a bit shorter. The comment fixes referring to this new file are thanks to #17825.
1 parent 07fee0c commit 655994e

6 files changed

Lines changed: 296 additions & 283 deletions

File tree

src/data/finset/n_ary.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ This file defines `finset.image₂`, the binary image of finsets. This is the fi
1313
1414
## Notes
1515
16-
This file is very similar to the n-ary section of `data.set.basic`, to `order.filter.n_ary` and to
17-
`data.option.n_ary`. Please keep them in sync.
16+
This file is very similar to `data.set.n_ary`, `order.filter.n_ary` and `data.option.n_ary`. Please
17+
keep them in sync.
1818
1919
We do not define `finset.image₃` as its only purpose would be to prove properties of `finset.image₂`
2020
and `set.image2` already fulfills this task.

src/data/option/n_ary.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ on intervals.
2121
2222
## Notes
2323
24-
This file is very similar to the n-ary section of `data.set.basic`, to `data.finset.n_ary` and to
25-
`order.filter.n_ary`. Please keep them in sync.
24+
This file is very similar to `data.set.n_ary`, `data.finset.n_ary` and `order.filter.n_ary`. Please
25+
keep them in sync.
2626
2727
We do not define `option.map₃` as its only purpose so far would be to prove properties of
2828
`option.map₂` and casing already fulfills this task.

src/data/set/basic.lean

Lines changed: 0 additions & 277 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,283 +2773,6 @@ by rw [← image_eq_image hf.1, hf.2.image_preimage]
27732773

27742774
end image_preimage
27752775

2776-
/-!
2777-
### Images of binary and ternary functions
2778-
2779-
This section is very similar to `order.filter.n_ary`, `data.finset.n_ary`, `data.option.n_ary`.
2780-
Please keep them in sync.
2781-
-/
2782-
2783-
section n_ary_image
2784-
2785-
variables {α α' β β' γ γ' δ δ' ε ε' : Type*} {f f' : α → β → γ} {g g' : α → β → γ → δ}
2786-
variables {s s' : set α} {t t' : set β} {u u' : set γ} {a a' : α} {b b' : β} {c c' : γ} {d d' : δ}
2787-
2788-
2789-
/-- The image of a binary function `f : α → β → γ` as a function `set α → set β → set γ`.
2790-
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`.
2791-
-/
2792-
def image2 (f : α → β → γ) (s : set α) (t : set β) : set γ :=
2793-
{c | ∃ a b, a ∈ s ∧ b ∈ t ∧ f a b = c }
2794-
2795-
@[simp] lemma mem_image2 : c ∈ image2 f s t ↔ ∃ a b, a ∈ s ∧ b ∈ t ∧ f a b = c := iff.rfl
2796-
2797-
lemma mem_image2_of_mem (h1 : a ∈ s) (h2 : b ∈ t) : f a b ∈ image2 f s t :=
2798-
⟨a, b, h1, h2, rfl⟩
2799-
2800-
lemma mem_image2_iff (hf : injective2 f) : f a b ∈ image2 f s t ↔ a ∈ s ∧ b ∈ t :=
2801-
by { rintro ⟨a', b', ha', hb', h⟩, rcases hf h with ⟨rfl, rfl⟩, exact ⟨ha', hb'⟩ },
2802-
λ ⟨ha, hb⟩, mem_image2_of_mem ha hb⟩
2803-
2804-
/-- image2 is monotone with respect to `⊆`. -/
2805-
lemma image2_subset (hs : s ⊆ s') (ht : t ⊆ t') : image2 f s t ⊆ image2 f s' t' :=
2806-
by { rintro _ ⟨a, b, ha, hb, rfl⟩, exact mem_image2_of_mem (hs ha) (ht hb) }
2807-
2808-
lemma image2_subset_left (ht : t ⊆ t') : image2 f s t ⊆ image2 f s t' := image2_subset subset.rfl ht
2809-
2810-
lemma image2_subset_right (hs : s ⊆ s') : image2 f s t ⊆ image2 f s' t :=
2811-
image2_subset hs subset.rfl
2812-
2813-
lemma image_subset_image2_left (hb : b ∈ t) : (λ a, f a b) '' s ⊆ image2 f s t :=
2814-
ball_image_of_ball $ λ a ha, mem_image2_of_mem ha hb
2815-
2816-
lemma image_subset_image2_right (ha : a ∈ s) : f a '' t ⊆ image2 f s t :=
2817-
ball_image_of_ball $ λ b, mem_image2_of_mem ha
2818-
2819-
lemma forall_image2_iff {p : γ → Prop} :
2820-
(∀ z ∈ image2 f s t, p z) ↔ ∀ (x ∈ s) (y ∈ t), p (f x y) :=
2821-
⟨λ h x hx y hy, h _ ⟨x, y, hx, hy, rfl⟩, λ h z ⟨x, y, hx, hy, hz⟩, hz ▸ h x hx y hy⟩
2822-
2823-
@[simp] lemma image2_subset_iff {u : set γ} :
2824-
image2 f s t ⊆ u ↔ ∀ (x ∈ s) (y ∈ t), f x y ∈ u :=
2825-
forall_image2_iff
2826-
2827-
lemma image2_union_left : image2 f (s ∪ s') t = image2 f s t ∪ image2 f s' t :=
2828-
begin
2829-
ext c, split,
2830-
{ rintros ⟨a, b, h1a|h2a, hb, rfl⟩;[left, right]; exact ⟨_, _, ‹_›, ‹_›, rfl⟩ },
2831-
{ rintro (⟨_, _, _, _, rfl⟩|⟨_, _, _, _, rfl⟩); refine ⟨_, _, _, ‹_›, rfl⟩;
2832-
simp [mem_union, *] }
2833-
end
2834-
2835-
lemma image2_union_right : image2 f s (t ∪ t') = image2 f s t ∪ image2 f s t' :=
2836-
begin
2837-
ext c, split,
2838-
{ rintros ⟨a, b, ha, h1b|h2b, rfl⟩;[left, right]; exact ⟨_, _, ‹_›, ‹_›, rfl⟩ },
2839-
{ rintro (⟨_, _, _, _, rfl⟩|⟨_, _, _, _, rfl⟩); refine ⟨_, _, ‹_›, _, rfl⟩;
2840-
simp [mem_union, *] }
2841-
end
2842-
2843-
@[simp] lemma image2_empty_left : image2 f ∅ t = ∅ := ext $ by simp
2844-
@[simp] lemma image2_empty_right : image2 f s ∅ = ∅ := ext $ by simp
2845-
2846-
lemma nonempty.image2 : s.nonempty → t.nonempty → (image2 f s t).nonempty :=
2847-
λ ⟨a, ha⟩ ⟨b, hb⟩, ⟨_, mem_image2_of_mem ha hb⟩
2848-
2849-
@[simp] lemma image2_nonempty_iff : (image2 f s t).nonempty ↔ s.nonempty ∧ t.nonempty :=
2850-
⟨λ ⟨_, a, b, ha, hb, _⟩, ⟨⟨a, ha⟩, b, hb⟩, λ h, h.1.image2 h.2
2851-
2852-
lemma nonempty.of_image2_left (h : (image2 f s t).nonempty) : s.nonempty :=
2853-
(image2_nonempty_iff.1 h).1
2854-
2855-
lemma nonempty.of_image2_right (h : (image2 f s t).nonempty) : t.nonempty :=
2856-
(image2_nonempty_iff.1 h).2
2857-
2858-
@[simp] lemma image2_eq_empty_iff : image2 f s t = ∅ ↔ s = ∅ ∨ t = ∅ :=
2859-
by simp_rw [←not_nonempty_iff_eq_empty, image2_nonempty_iff, not_and_distrib]
2860-
2861-
lemma image2_inter_subset_left : image2 f (s ∩ s') t ⊆ image2 f s t ∩ image2 f s' t :=
2862-
by { rintro _ ⟨a, b, ⟨h1a, h2a⟩, hb, rfl⟩, split; exact ⟨_, _, ‹_›, ‹_›, rfl⟩ }
2863-
2864-
lemma image2_inter_subset_right : image2 f s (t ∩ t') ⊆ image2 f s t ∩ image2 f s t' :=
2865-
by { rintro _ ⟨a, b, ha, ⟨h1b, h2b⟩, rfl⟩, split; exact ⟨_, _, ‹_›, ‹_›, rfl⟩ }
2866-
2867-
@[simp] lemma image2_singleton_left : image2 f {a} t = f a '' t :=
2868-
ext $ λ x, by simp
2869-
2870-
@[simp] lemma image2_singleton_right : image2 f s {b} = (λ a, f a b) '' s :=
2871-
ext $ λ x, by simp
2872-
2873-
lemma image2_singleton : image2 f {a} {b} = {f a b} := by simp
2874-
2875-
@[congr] lemma image2_congr (h : ∀ (a ∈ s) (b ∈ t), f a b = f' a b) :
2876-
image2 f s t = image2 f' s t :=
2877-
by { ext, split; rintro ⟨a, b, ha, hb, rfl⟩; refine ⟨a, b, ha, hb, by rw h a ha b hb⟩ }
2878-
2879-
/-- A common special case of `image2_congr` -/
2880-
lemma image2_congr' (h : ∀ a b, f a b = f' a b) : image2 f s t = image2 f' s t :=
2881-
image2_congr (λ a _ b _, h a b)
2882-
2883-
/-- The image of a ternary function `f : α → β → γ → δ` as a function
2884-
`set α → set β → set γ → set δ`. Mathematically this should be thought of as the image of the
2885-
corresponding function `α × β × γ → δ`.
2886-
-/
2887-
def image3 (g : α → β → γ → δ) (s : set α) (t : set β) (u : set γ) : set δ :=
2888-
{d | ∃ a b c, a ∈ s ∧ b ∈ t ∧ c ∈ u ∧ g a b c = d }
2889-
2890-
@[simp] lemma mem_image3 : d ∈ image3 g s t u ↔ ∃ a b c, a ∈ s ∧ b ∈ t ∧ c ∈ u ∧ g a b c = d :=
2891-
iff.rfl
2892-
2893-
lemma image3_mono (hs : s ⊆ s') (ht : t ⊆ t') (hu : u ⊆ u') : image3 g s t u ⊆ image3 g s' t' u' :=
2894-
λ x, Exists₃.imp $ λ a b c ⟨ha, hb, hc, hx⟩, ⟨hs ha, ht hb, hu hc, hx⟩
2895-
2896-
@[congr] lemma image3_congr (h : ∀ (a ∈ s) (b ∈ t) (c ∈ u), g a b c = g' a b c) :
2897-
image3 g s t u = image3 g' s t u :=
2898-
by { ext x,
2899-
split; rintro ⟨a, b, c, ha, hb, hc, rfl⟩; exact ⟨a, b, c, ha, hb, hc, by rw h a ha b hb c hc⟩ }
2900-
2901-
/-- A common special case of `image3_congr` -/
2902-
lemma image3_congr' (h : ∀ a b c, g a b c = g' a b c) : image3 g s t u = image3 g' s t u :=
2903-
image3_congr (λ a _ b _ c _, h a b c)
2904-
2905-
lemma image2_image2_left (f : δ → γ → ε) (g : α → β → δ) :
2906-
image2 f (image2 g s t) u = image3 (λ a b c, f (g a b) c) s t u :=
2907-
begin
2908-
ext, split,
2909-
{ rintro ⟨_, c, ⟨a, b, ha, hb, rfl⟩, hc, rfl⟩, refine ⟨a, b, c, ha, hb, hc, rfl⟩ },
2910-
{ rintro ⟨a, b, c, ha, hb, hc, rfl⟩, refine ⟨_, c, ⟨a, b, ha, hb, rfl⟩, hc, rfl⟩ }
2911-
end
2912-
2913-
lemma image2_image2_right (f : α → δ → ε) (g : β → γ → δ) :
2914-
image2 f s (image2 g t u) = image3 (λ a b c, f a (g b c)) s t u :=
2915-
begin
2916-
ext, split,
2917-
{ rintro ⟨a, _, ha, ⟨b, c, hb, hc, rfl⟩, rfl⟩, refine ⟨a, b, c, ha, hb, hc, rfl⟩ },
2918-
{ rintro ⟨a, b, c, ha, hb, hc, rfl⟩, refine ⟨a, _, ha, ⟨b, c, hb, hc, rfl⟩, rfl⟩ }
2919-
end
2920-
2921-
lemma image_image2 (f : α → β → γ) (g : γ → δ) :
2922-
g '' image2 f s t = image2 (λ a b, g (f a b)) s t :=
2923-
begin
2924-
ext, split,
2925-
{ rintro ⟨_, ⟨a, b, ha, hb, rfl⟩, rfl⟩, refine ⟨a, b, ha, hb, rfl⟩ },
2926-
{ rintro ⟨a, b, ha, hb, rfl⟩, refine ⟨_, ⟨a, b, ha, hb, rfl⟩, rfl⟩ }
2927-
end
2928-
2929-
lemma image2_image_left (f : γ → β → δ) (g : α → γ) :
2930-
image2 f (g '' s) t = image2 (λ a b, f (g a) b) s t :=
2931-
begin
2932-
ext, split,
2933-
{ rintro ⟨_, b, ⟨a, ha, rfl⟩, hb, rfl⟩, refine ⟨a, b, ha, hb, rfl⟩ },
2934-
{ rintro ⟨a, b, ha, hb, rfl⟩, refine ⟨_, b, ⟨a, ha, rfl⟩, hb, rfl⟩ }
2935-
end
2936-
2937-
lemma image2_image_right (f : α → γ → δ) (g : β → γ) :
2938-
image2 f s (g '' t) = image2 (λ a b, f a (g b)) s t :=
2939-
begin
2940-
ext, split,
2941-
{ rintro ⟨a, _, ha, ⟨b, hb, rfl⟩, rfl⟩, refine ⟨a, b, ha, hb, rfl⟩ },
2942-
{ rintro ⟨a, b, ha, hb, rfl⟩, refine ⟨a, _, ha, ⟨b, hb, rfl⟩, rfl⟩ }
2943-
end
2944-
2945-
lemma image2_swap (f : α → β → γ) (s : set α) (t : set β) :
2946-
image2 f s t = image2 (λ a b, f b a) t s :=
2947-
by { ext, split; rintro ⟨a, b, ha, hb, rfl⟩; refine ⟨b, a, hb, ha, rfl⟩ }
2948-
2949-
@[simp] lemma image2_left (h : t.nonempty) : image2 (λ x y, x) s t = s :=
2950-
by simp [nonempty_def.mp h, ext_iff]
2951-
2952-
@[simp] lemma image2_right (h : s.nonempty) : image2 (λ x y, y) s t = t :=
2953-
by simp [nonempty_def.mp h, ext_iff]
2954-
2955-
lemma image2_assoc {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'}
2956-
(h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) :
2957-
image2 f (image2 g s t) u = image2 f' s (image2 g' t u) :=
2958-
by simp only [image2_image2_left, image2_image2_right, h_assoc]
2959-
2960-
lemma image2_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : image2 f s t = image2 g t s :=
2961-
(image2_swap _ _ _).trans $ by simp_rw h_comm
2962-
2963-
lemma image2_left_comm {f : α → δ → ε} {g : β → γ → δ} {f' : α → γ → δ'} {g' : β → δ' → ε}
2964-
(h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) :
2965-
image2 f s (image2 g t u) = image2 g' t (image2 f' s u) :=
2966-
by { rw [image2_swap f', image2_swap f], exact image2_assoc (λ _ _ _, h_left_comm _ _ _) }
2967-
2968-
lemma image2_right_comm {f : δ → γ → ε} {g : α → β → δ} {f' : α → γ → δ'} {g' : δ' → β → ε}
2969-
(h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) :
2970-
image2 f (image2 g s t) u = image2 g' (image2 f' s u) t :=
2971-
by { rw [image2_swap g, image2_swap g'], exact image2_assoc (λ _ _ _, h_right_comm _ _ _) }
2972-
2973-
lemma image_image2_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'}
2974-
(h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) :
2975-
(image2 f s t).image g = image2 f' (s.image g₁) (t.image g₂) :=
2976-
by simp_rw [image_image2, image2_image_left, image2_image_right, h_distrib]
2977-
2978-
/-- Symmetric statement to `set.image2_image_left_comm`. -/
2979-
lemma image_image2_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'}
2980-
(h_distrib : ∀ a b, g (f a b) = f' (g' a) b) :
2981-
(image2 f s t).image g = image2 f' (s.image g') t :=
2982-
(image_image2_distrib h_distrib).trans $ by rw image_id'
2983-
2984-
/-- Symmetric statement to `set.image_image2_right_comm`. -/
2985-
lemma image_image2_distrib_right {g : γ → δ} {f' : α → β' → δ} {g' : β → β'}
2986-
(h_distrib : ∀ a b, g (f a b) = f' a (g' b)) :
2987-
(image2 f s t).image g = image2 f' s (t.image g') :=
2988-
(image_image2_distrib h_distrib).trans $ by rw image_id'
2989-
2990-
/-- Symmetric statement to `set.image_image2_distrib_left`. -/
2991-
lemma image2_image_left_comm {f : α' → β → γ} {g : α → α'} {f' : α → β → δ} {g' : δ → γ}
2992-
(h_left_comm : ∀ a b, f (g a) b = g' (f' a b)) :
2993-
image2 f (s.image g) t = (image2 f' s t).image g' :=
2994-
(image_image2_distrib_left $ λ a b, (h_left_comm a b).symm).symm
2995-
2996-
/-- Symmetric statement to `set.image_image2_distrib_right`. -/
2997-
lemma image_image2_right_comm {f : α → β' → γ} {g : β → β'} {f' : α → β → δ} {g' : δ → γ}
2998-
(h_right_comm : ∀ a b, f a (g b) = g' (f' a b)) :
2999-
image2 f s (t.image g) = (image2 f' s t).image g' :=
3000-
(image_image2_distrib_right $ λ a b, (h_right_comm a b).symm).symm
3001-
3002-
/-- The other direction does not hold because of the `s`-`s` cross terms on the RHS. -/
3003-
lemma image2_distrib_subset_left {f : α → δ → ε} {g : β → γ → δ} {f₁ : α → β → β'} {f₂ : α → γ → γ'}
3004-
{g' : β' → γ' → ε} (h_distrib : ∀ a b c, f a (g b c) = g' (f₁ a b) (f₂ a c)) :
3005-
image2 f s (image2 g t u) ⊆ image2 g' (image2 f₁ s t) (image2 f₂ s u) :=
3006-
begin
3007-
rintro _ ⟨a, _, ha, ⟨b, c, hb, hc, rfl⟩, rfl⟩,
3008-
rw h_distrib,
3009-
exact mem_image2_of_mem (mem_image2_of_mem ha hb) (mem_image2_of_mem ha hc),
3010-
end
3011-
3012-
/-- The other direction does not hold because of the `u`-`u` cross terms on the RHS. -/
3013-
lemma image2_distrib_subset_right {f : δ → γ → ε} {g : α → β → δ} {f₁ : α → γ → α'}
3014-
{f₂ : β → γ → β'} {g' : α' → β' → ε} (h_distrib : ∀ a b c, f (g a b) c = g' (f₁ a c) (f₂ b c)) :
3015-
image2 f (image2 g s t) u ⊆ image2 g' (image2 f₁ s u) (image2 f₂ t u) :=
3016-
begin
3017-
rintro _ ⟨_, c, ⟨a, b, ha, hb, rfl⟩, hc, rfl⟩,
3018-
rw h_distrib,
3019-
exact mem_image2_of_mem (mem_image2_of_mem ha hc) (mem_image2_of_mem hb hc),
3020-
end
3021-
3022-
lemma image_image2_antidistrib {g : γ → δ} {f' : β' → α' → δ} {g₁ : β → β'} {g₂ : α → α'}
3023-
(h_antidistrib : ∀ a b, g (f a b) = f' (g₁ b) (g₂ a)) :
3024-
(image2 f s t).image g = image2 f' (t.image g₁) (s.image g₂) :=
3025-
by { rw image2_swap f, exact image_image2_distrib (λ _ _, h_antidistrib _ _) }
3026-
3027-
/-- Symmetric statement to `set.image2_image_left_anticomm`. -/
3028-
lemma image_image2_antidistrib_left {g : γ → δ} {f' : β' → α → δ} {g' : β → β'}
3029-
(h_antidistrib : ∀ a b, g (f a b) = f' (g' b) a) :
3030-
(image2 f s t).image g = image2 f' (t.image g') s :=
3031-
(image_image2_antidistrib h_antidistrib).trans $ by rw image_id'
3032-
3033-
/-- Symmetric statement to `set.image_image2_right_anticomm`. -/
3034-
lemma image_image2_antidistrib_right {g : γ → δ} {f' : β → α' → δ} {g' : α → α'}
3035-
(h_antidistrib : ∀ a b, g (f a b) = f' b (g' a)) :
3036-
(image2 f s t).image g = image2 f' t (s.image g') :=
3037-
(image_image2_antidistrib h_antidistrib).trans $ by rw image_id'
3038-
3039-
/-- Symmetric statement to `set.image_image2_antidistrib_left`. -/
3040-
lemma image2_image_left_anticomm {f : α' → β → γ} {g : α → α'} {f' : β → α → δ} {g' : δ → γ}
3041-
(h_left_anticomm : ∀ a b, f (g a) b = g' (f' b a)) :
3042-
image2 f (s.image g) t = (image2 f' t s).image g' :=
3043-
(image_image2_antidistrib_left $ λ a b, (h_left_anticomm b a).symm).symm
3044-
3045-
/-- Symmetric statement to `set.image_image2_antidistrib_right`. -/
3046-
lemma image_image2_right_anticomm {f : α → β' → γ} {g : β → β'} {f' : β → α → δ} {g' : δ → γ}
3047-
(h_right_anticomm : ∀ a b, f a (g b) = g' (f' b a)) :
3048-
image2 f s (t.image g) = (image2 f' t s).image g' :=
3049-
(image_image2_antidistrib_right $ λ a b, (h_right_anticomm b a).symm).symm
3050-
3051-
end n_ary_image
3052-
30532776
end set
30542777

30552778
namespace subsingleton

0 commit comments

Comments
 (0)