Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat(data/sym): Provide API for data.sym #11032

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e773d99
Provide instances for sym
huynhtrankhanh Dec 24, 2021
dbb2894
Provide instances for sym2
huynhtrankhanh Dec 24, 2021
c18b779
Define sym.erase
huynhtrankhanh Dec 24, 2021
85e204e
Prove sym.equiv_congr
huynhtrankhanh Dec 24, 2021
0dacf7d
Break long lines
huynhtrankhanh Dec 24, 2021
0729df6
Move lines out of unfreezingI
huynhtrankhanh Dec 24, 2021
b2d85e4
Incorporate suggestions
huynhtrankhanh Dec 25, 2021
40756df
Use refine in sym.is_empty
huynhtrankhanh Dec 25, 2021
5a7ff25
Rename ob to heq in sym.subsingleton
huynhtrankhanh Dec 25, 2021
9c2e4c1
Assume n ≠ 0 in repeat_left_injective
huynhtrankhanh Dec 25, 2021
57f3474
Use dot notation for false.elim
huynhtrankhanh Dec 25, 2021
fb86148
Make the n argument for sym.subsingleton explicit
huynhtrankhanh Dec 25, 2021
29b891e
Provide docstring
huynhtrankhanh Dec 25, 2021
84a31ef
Use rw and add @[simps] in sym.equiv_congr
huynhtrankhanh Dec 25, 2021
59f4d5c
Make β implicit in sym.equiv_congr
huynhtrankhanh Dec 25, 2021
2dc2f5a
Incorporate suggestions
huynhtrankhanh Dec 26, 2021
a3c474a
Fix docstring for sym.equiv_congr
huynhtrankhanh Dec 26, 2021
b946afd
Remove instance names
huynhtrankhanh Dec 26, 2021
be59a9e
Add docstring for sym.map, copied from multiset.map
huynhtrankhanh Dec 26, 2021
e2aaff6
Fix argument order for sym.subsingleton
huynhtrankhanh Dec 26, 2021
ea464a9
Fix docstring for sym.map
huynhtrankhanh Dec 26, 2021
62c630a
Use Kyle Miller's docstring
huynhtrankhanh Dec 26, 2021
bfd5950
Merge branch 'master' into huynhtrankhanh/api-for-sym
urkud Dec 27, 2021
c245ed1
Merge branch 'master' of git://github.com/leanprover-community/mathli…
urkud Dec 27, 2021
d2704c3
Golf some proofs
urkud Dec 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/data/multiset/basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,20 @@ by simp only [repeat_succ, singleton_eq_cons, eq_self_iff_true, repeat_zero, con

theorem eq_of_mem_repeat {a b : α} {n} : b ∈ repeat a n → b = a := eq_of_mem_repeat

lemma repeat_left_injective (n : ℕ) (h : n ≠ 0) : function.injective (λ a : α, repeat a n) :=
urkud marked this conversation as resolved.
Show resolved Hide resolved
begin
intros a b x,
simp only at x,
apply @eq_of_mem_repeat _ b a n,
cases n,
{ exact false.elim (h rfl) },
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved
{ rw [x.symm, repeat_succ],
exact mem_cons_self a (repeat a n) },
end

@[simp] lemma repeat_left_inj (a b : α) (n : ℕ) (h : n ≠ 0) : repeat a n = repeat b n ↔ a = b :=
(repeat_left_injective n h).eq_iff

theorem eq_repeat' {a : α} {s : multiset α} : s = repeat a s.card ↔ ∀ b ∈ s, b = a :=
quot.induction_on s $ λ l, iff.trans ⟨λ h,
(perm_repeat.1 $ (quotient.exact h)), congr_arg coe⟩ eq_repeat'
Expand Down
96 changes: 96 additions & 0 deletions src/data/sym/basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ begin
exact h,
end

def erase [decidable_eq α] (s : sym α (n + 1)) (a : α) (h : a ∈ s) : sym α n :=
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved
⟨s.val.erase a, (multiset.card_erase_of_mem h).trans $ s.property.symm ▸ n.pred_succ⟩

/--
Another definition of the nth symmetric power, using vectors modulo permutations. (See `sym`.)
-/
Expand Down Expand Up @@ -150,4 +153,97 @@ instance inhabited_sym' [inhabited α] (n : ℕ) : inhabited (sym' α n) :=

end inhabited

instance has_zero : has_zero (sym α 0) := ⟨⟨0, rfl⟩⟩
instance has_emptyc : has_emptyc (sym α 0) := ⟨0⟩

instance subsingleton {n : ℕ} [subsingleton α] : subsingleton (sym α n) :=
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved
⟨begin
rintros ⟨a, ha⟩ ⟨b, hb⟩,
simp only [subtype.mk.inj_eq],
induction a using multiset.case_strong_induction_on with k hk ih generalizing n b,
{ rw [ha.symm, multiset.card_zero] at hb, exact (multiset.card_eq_zero.mp hb).symm, },
{ cases n,
{ exact false.elim (multiset.cons_ne_zero (multiset.card_eq_zero.mp ha)) },
{ by_cases hzero : b = 0,
{ rw [hzero, multiset.card_zero] at hb,
exact false.elim (nat.succ_ne_zero n hb.symm) },
{ have hmem := multiset.exists_mem_of_ne_zero hzero,
rcases hmem with ⟨r, hr⟩,
cases multiset.exists_cons_of_mem hr,
rw h,
have heq := @ih hk rfl.ge n w begin
rw multiset.card_cons at ha,
refine nat.succ.inj ha,
end begin
rw [h, multiset.card_cons] at hb,
refine nat.succ.inj hb,
end,
rw [heq, subsingleton.elim k r] } } }
end⟩

instance unique (n : ℕ) [unique α] : unique (sym α n) := unique.mk' _

instance is_empty (n : ℕ) [is_empty α] : is_empty (sym α n.succ) :=
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved
⟨begin
intro h,
rw sym at h,
refine is_empty.exists_iff.mp (@multiset.exists_mem_of_ne_zero _ h.val _),
intro y,
have z := h.property,
rw [y, multiset.card_zero] at z,
exact false.elim (nat.succ_ne_zero n z.symm),
end⟩
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved

def repeat (a : α) (n : ℕ) : sym α n := ⟨multiset.repeat a n, multiset.card_repeat _ _⟩
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved

lemma repeat_left_injective (n : ℕ) (h : n ≠ 0) : function.injective (λ x : α, repeat x n) :=
begin
intros a b x,
simp only [repeat, subtype.mk.inj_eq] at x,
exact (multiset.repeat_left_inj a b n h).mp x,
end

lemma repeat_left_inj (a b : α) (n : ℕ) (h : n ≠ 0) : repeat a n = repeat b n ↔ a = b :=
(repeat_left_injective n h).eq_iff

instance nontrivial (n : ℕ) [nontrivial α] : nontrivial (sym α (n + 1)) :=
(repeat_left_injective n.succ n.succ_ne_zero).nontrivial

def map {α β : Type*} {n : ℕ} (f : α → β) (x : sym α n) : sym β n :=
⟨x.val.map f, by simpa [multiset.card_map] using x.property⟩

@[simp] lemma mem_map {α β : Type*} {n : ℕ} {f : α → β} {b : β} {l : sym α n} :
b ∈ sym.map f l ↔ ∃ a, a ∈ l ∧ f a = b := multiset.mem_map

@[simp] lemma map_id {α : Type*} {n : ℕ} (s : sym α n) : sym.map id s = s :=
by simp [sym.map, subtype.mk.inj_eq]

@[simp] lemma map_map {α β γ : Type*} {n : ℕ} (g : β → γ) (f : α → β) (s : sym α n) :
sym.map g (sym.map f s) = sym.map (g ∘ f) s :=
by simp [sym.map, subtype.mk.inj_eq]

@[simp] lemma map_zero {α β : Type*} (f : α → β) :
sym.map f (0 : sym α 0) = (0 : sym β 0) :=
begin
rw sym.has_zero,
simp only [sym.map, multiset.map_zero],
rw sym.has_zero,
simp only [subtype.mk_eq_mk],
end
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved

@[simp] lemma map_cons {α β : Type*} {n : ℕ} (f : α → β) (a : α) (s : sym α n) :
sym.map f (a::s) = (f a)::sym.map f s :=
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved
begin
simp only [map, subtype.mk.inj_eq, cons],
convert multiset.map_cons f a s.val,
cases s,
rw sym.cons,
end
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved

def equiv_congr (β : Type u) (h : α ≃ β) : sym α n ≃ sym β n :=
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved
{ to_fun := sym.map h,
inv_fun := sym.map h.symm,
left_inv := λ x, by simp only [equiv.symm_comp_self, map_id, map_map],
right_inv := λ x, by simp only [equiv.self_comp_symm, map_id, map_map] }

end sym
9 changes: 9 additions & 0 deletions src/data/sym/sym2.lean
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,13 @@ end

end decidable

instance subsingleton [g : subsingleton α] : subsingleton (sym2 α) :=
huynhtrankhanh marked this conversation as resolved.
Show resolved Hide resolved
(equiv_sym α).injective.subsingleton

instance unique [unique α] : unique (sym2 α) := unique.mk' _

instance is_empty [is_empty α] : is_empty (sym2 α) := (equiv_sym α).is_empty

instance nontrivial [nontrivial α] : nontrivial (sym2 α) := diag_injective.nontrivial

end sym2