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

Commit 631207b

Browse files
committed
feat(data/multiset,...): card_eq_one
based on #200
1 parent ab8813a commit 631207b

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

algebra/group_power.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ by rw [add_monoid.smul_eq_mul', add_monoid.smul_eq_mul', mul_assoc]
308308
theorem add_monoid.mul_smul_assoc [semiring α] (a b : α) (n : ℕ) : n • (a * b) = n • a * b :=
309309
by rw [add_monoid.smul_eq_mul, add_monoid.smul_eq_mul, mul_assoc]
310310

311+
theorem neg_one_pow_eq_or {R} [ring R] : ∀ n : ℕ, (-1 : R)^n = 1 ∨ (-1 : R)^n = -1
312+
| 0 := by simp
313+
| (n+1) := by cases neg_one_pow_eq_or n; simp [pow_succ, h]
314+
311315
theorem gsmul_eq_mul [ring α] (a : α) : ∀ n, n •ℤ a = n * a
312316
| (n : ℕ) := by simp [add_monoid.smul_eq_mul]
313317
| -[1+ n] := by simp [add_monoid.smul_eq_mul, -add_comm, add_mul]

data/list/basic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ theorem exists_mem_of_length_pos : ∀ {l : list α}, 0 < length l → ∃ a, a
7171
theorem length_pos_iff_exists_mem {l : list α} : 0 < length l ↔ ∃ a, a ∈ l :=
7272
⟨exists_mem_of_length_pos, λ ⟨a, h⟩, length_pos_of_mem h⟩
7373

74+
theorem length_eq_one {l : list α} : length l = 1 ↔ ∃ a, l = [a] :=
75+
match l with [a], _ := ⟨a, rfl⟩ end, λ ⟨a, e⟩, e.symm ▸ rfl⟩
76+
7477
theorem mem_split {a : α} {l : list α} (h : a ∈ l) : ∃ s t : list α, l = s ++ a :: t :=
7578
begin
7679
induction l with b l ih; simp at h; cases h with h h,

data/multiset.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ instance : has_emptyc (multiset α) := ⟨0⟩
4949
instance : inhabited (multiset α) := ⟨0
5050

5151
@[simp] theorem coe_nil_eq_zero : (@nil α : multiset α) = 0 := rfl
52+
@[simp] theorem empty_eq_zero : (∅ : multiset α) = 0 := rfl
5253

5354
/- cons -/
5455

@@ -345,6 +346,11 @@ quot.induction_on s $ λ l, length_pos_iff_exists_mem
345346
strong_induction_on t ih
346347
using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf card⟩]}
347348

349+
theorem strong_induction_eq {p : multiset α → Sort*}
350+
(s : multiset α) (H) : @strong_induction_on _ p s H =
351+
H s (λ t h, @strong_induction_on _ p t H) :=
352+
by rw [strong_induction_on]
353+
348354
@[elab_as_eliminator] lemma case_strong_induction_on {p : multiset α → Prop}
349355
(s : multiset α) (h₀ : p 0) (h₁ : ∀ a s, (∀t ≤ s, p t) → p (a :: s)) : p s :=
350356
multiset.strong_induction_on s $ assume s,
@@ -366,6 +372,11 @@ ne_of_gt (lt_cons_self _ _)
366372
⟨λ h, mem_of_le h (mem_singleton_self _),
367373
λ h, let ⟨t, e⟩ := exists_cons_of_mem h in e.symm ▸ cons_le_cons _ (zero_le _)⟩
368374

375+
theorem card_eq_one {s : multiset α} : card s = 1 ↔ ∃ a, s = a::0 :=
376+
⟨quot.induction_on s $ λ l h,
377+
(list.length_eq_one.1 h).imp $ λ a, congr_arg coe,
378+
λ ⟨a, e⟩, e.symm ▸ rfl⟩
379+
369380
/- add -/
370381

371382
/-- The sum of two multisets is the lift of the list append operation.

logic/basic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ iff.intro and.left (λ ha, ⟨ha, h ha⟩)
150150
theorem and_iff_right_of_imp {a b : Prop} (h : b → a) : (a ∧ b) ↔ b :=
151151
iff.intro and.right (λ hb, ⟨h hb, hb⟩)
152152

153+
lemma and.congr_right_iff : (a ∧ b ↔ a ∧ c) ↔ (a → (b ↔ c)) :=
154+
⟨λ h ha, by simp [ha] at h; exact h, and_congr_right⟩
155+
153156
/- or -/
154157

155158
theorem or_of_or_of_imp_of_imp (h₁ : a ∨ b) (h₂ : a → c) (h₃ : b → d) : c ∨ d :=

0 commit comments

Comments
 (0)