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

Commit 95535a3

Browse files
refactor(ring_theory/unique_factorization_domain): golf some factor_set lemmas (#9889)
1 parent e1c0dbc commit 95535a3

File tree

1 file changed

+49
-52
lines changed

1 file changed

+49
-52
lines changed

src/ring_theory/unique_factorization_domain.lean

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,17 @@ theorem prod_mono : ∀{a b : factor_set α}, a ≤ b → a.prod ≤ b.prod
749749
| a none h := show a.prod ≤ (⊤ : factor_set α).prod, by simp; exact le_top
750750
| (some a) (some b) h := prod_le_prod $ multiset.map_le_map $ with_top.coe_le_coe.1 $ h
751751

752+
theorem factor_set.prod_eq_zero_iff [nontrivial α] (p : factor_set α) :
753+
p.prod = 0 ↔ p = ⊤ :=
754+
begin
755+
induction p using with_top.rec_top_coe,
756+
{ simp only [iff_self, eq_self_iff_true, associates.prod_top] },
757+
simp only [prod_coe, with_top.coe_ne_top, iff_false, prod_eq_zero_iff, multiset.mem_map],
758+
rintro ⟨⟨a, ha⟩, -, eq⟩,
759+
rw [subtype.coe_mk] at eq,
760+
exact ha.ne_zero eq,
761+
end
762+
752763
/-- `bcount p s` is the multiplicity of `p` in the factor_set `s` (with bundled `p`)-/
753764
def bcount [decidable_eq (associates α)] (p : {a : associates α // irreducible a}) :
754765
factor_set α → ℕ
@@ -831,12 +842,19 @@ begin
831842
simpa [quot_mk_eq_mk, prod_mk, mk_eq_mk_iff_associated] using eq
832843
end
833844

834-
private theorem forall_map_mk_factors_irreducible [decidable_eq α] (x : α) (hx : x ≠ 0) :
835-
∀(a : associates α), a ∈ multiset.map associates.mk (factors x) → irreducible a :=
845+
theorem factor_set.unique [nontrivial α] {p q : factor_set α} (h : p.prod = q.prod) : p = q :=
836846
begin
837-
assume a ha,
838-
rcases multiset.mem_map.1 ha with ⟨c, hc, rfl⟩,
839-
exact (irreducible_mk c).2 (irreducible_of_factor _ hc)
847+
induction p using with_top.rec_top_coe;
848+
induction q using with_top.rec_top_coe,
849+
{ refl },
850+
{ rw [eq_comm, ←factor_set.prod_eq_zero_iff, ←h, associates.prod_top] },
851+
{ rw [←factor_set.prod_eq_zero_iff, h, associates.prod_top] },
852+
{ congr' 1,
853+
rw ←multiset.map_eq_map subtype.coe_injective,
854+
apply unique' _ _ h;
855+
{ intros a ha,
856+
obtain ⟨⟨a', irred⟩, -, rfl⟩ := multiset.mem_map.mp ha,
857+
rwa [subtype.coe_mk] } },
840858
end
841859

842860
theorem prod_le_prod_iff_le [nontrivial α] {p q : multiset (associates α)}
@@ -845,20 +863,16 @@ theorem prod_le_prod_iff_le [nontrivial α] {p q : multiset (associates α)}
845863
iff.intro
846864
begin
847865
classical,
848-
rintros ⟨⟨c⟩, eqc⟩,
849-
have : c ≠ 0, from (mt mk_eq_zero.2 $
850-
assume (hc : quot.mk setoid.r c = 0),
851-
have (0 : associates α) ∈ q, from prod_eq_zero_iff.1 $ eqc.symm ▸ hc.symm ▸ mul_zero _,
852-
not_irreducible_zero ((irreducible_mk 0).1 $ hq _ this)),
853-
have : associates.mk (factors c).prod = quot.mk setoid.r c,
854-
from mk_eq_mk_iff_associated.2 (factors_prod this),
855-
856-
refine multiset.le_iff_exists_add.2 ⟨(factors c).map associates.mk, unique' hq _ _⟩,
857-
{ assume x hx,
858-
rcases multiset.mem_add.1 hx with h | h,
859-
exact hp x h,
860-
exact forall_map_mk_factors_irreducible c ‹c ≠ 0› _ h },
861-
{ simp [multiset.prod_add, prod_mk, *] at * }
866+
rintros ⟨c, eqc⟩,
867+
refine multiset.le_iff_exists_add.2 ⟨factors c, unique' hq (λ x hx, _) _⟩,
868+
{ obtain h|h := multiset.mem_add.1 hx,
869+
{ exact hp x h },
870+
{ exact irreducible_of_factor _ h } },
871+
{ rw [eqc, multiset.prod_add],
872+
congr,
873+
refine associated_iff_eq.mp (factors_prod (λ hc, _)).symm,
874+
refine not_irreducible_zero (hq _ _),
875+
rw [←prod_eq_zero_iff, eqc, hc, mul_zero] }
862876
end
863877
prod_le_prod
864878

@@ -876,12 +890,20 @@ noncomputable def factors' (a : α) :
876890
(factors' a).map coe = (factors a).map associates.mk :=
877891
by simp [factors', multiset.map_pmap, multiset.pmap_eq_map]
878892

879-
theorem factors'_cong {a b : α} (ha : a ≠ 0) (hb : b ≠ 0) (h : a ~ᵤ b) :
893+
theorem factors'_cong {a b : α} (h : a ~ᵤ b) :
880894
factors' a = factors' b :=
881-
have multiset.rel associated (factors a) (factors b), from
882-
factors_unique irreducible_of_factor irreducible_of_factor
895+
begin
896+
obtain rfl|hb := eq_or_ne b 0,
897+
{ rw associated_zero_iff_eq_zero at h, rw h },
898+
have ha : a ≠ 0,
899+
{ contrapose! hb with ha,
900+
rw [←associated_zero_iff_eq_zero, ←ha],
901+
exact h.symm },
902+
rw [←multiset.map_eq_map subtype.coe_injective, map_subtype_coe_factors',
903+
map_subtype_coe_factors', ←rel_associated_iff_map_eq_map],
904+
exact factors_unique irreducible_of_factor irreducible_of_factor
883905
((factors_prod ha).trans $ h.trans $ (factors_prod hb).symm),
884-
by simpa [(multiset.map_eq_map subtype.coe_injective).symm, rel_associated_iff_map_eq_map.symm]
906+
end
885907

886908
include dec'
887909

@@ -898,8 +920,7 @@ begin
898920
iff.intro (assume ha0, hab.symm.trans ha0) (assume hb0, hab.trans hb0),
899921
simp only [associated_zero_iff_eq_zero] at this,
900922
simp only [quotient_mk_eq_mk, this, mk_eq_zero] },
901-
exact (assume ha hb eq, heq_of_eq $ congr_arg some $ factors'_cong
902-
(λ c, ha (mk_eq_zero.2 c)) (λ c, hb (mk_eq_zero.2 c)) hab)
923+
exact (assume ha hb eq, heq_of_eq $ congr_arg some $ factors'_cong hab)
903924
end
904925

905926
@[simp] theorem factors_0 : (0 : associates α).factors = ⊤ :=
@@ -909,33 +930,6 @@ dif_pos rfl
909930
(associates.mk a).factors = factors' a :=
910931
by { classical, apply dif_neg, apply (mt mk_eq_zero.1 h) }
911932

912-
theorem prod_factors [nontrivial α] : ∀(s : factor_set α), s.prod.factors = s
913-
| none := by simp [factor_set.prod]; refl
914-
| (some s) :=
915-
begin
916-
unfold factor_set.prod,
917-
generalize eq_a : (s.map coe).prod = a,
918-
rcases a with ⟨a⟩,
919-
rw quot_mk_eq_mk at *,
920-
921-
have : (s.map (coe : _ → associates α)).prod ≠ 0, from assume ha,
922-
let ⟨⟨a, ha⟩, h, eq⟩ := multiset.mem_map.1 (prod_eq_zero_iff.1 ha) in
923-
have irreducible (0 : associates α), from eq ▸ ha,
924-
not_irreducible_zero ((irreducible_mk _).1 this),
925-
have ha : a ≠ 0, by simp [*] at *,
926-
suffices : (unique_factorization_monoid.factors a).map associates.mk = s.map coe,
927-
{ rw [factors_mk a ha],
928-
apply congr_arg some _,
929-
simpa [(multiset.map_eq_map subtype.coe_injective).symm] },
930-
931-
refine unique'
932-
(forall_map_mk_factors_irreducible _ ha)
933-
(assume a ha, let ⟨⟨x, hx⟩, ha, eq⟩ := multiset.mem_map.1 ha in eq ▸ hx)
934-
_,
935-
rw [prod_mk, eq_a, mk_eq_mk_iff_associated],
936-
exact factors_prod ha
937-
end
938-
939933
@[simp]
940934
theorem factors_prod (a : associates α) : a.factors.prod = a :=
941935
quotient.induction_on a $ assume a, decidable.by_cases
@@ -945,6 +939,9 @@ quotient.induction_on a $ assume a, decidable.by_cases
945939
by simp [this, quotient_mk_eq_mk, prod_mk,
946940
mk_eq_mk_iff_associated.2 (factors_prod this)])
947941

942+
theorem prod_factors [nontrivial α] (s : factor_set α) : s.prod.factors = s :=
943+
factor_set.unique $ factors_prod _
944+
948945
theorem eq_of_factors_eq_factors {a b : associates α} (h : a.factors = b.factors) : a = b :=
949946
have a.factors.prod = b.factors.prod, by rw h,
950947
by rwa [factors_prod, factors_prod] at this

0 commit comments

Comments
 (0)