GCD and LCM operations on finsets #
Main definitions #
Finset.gcd
- the greatest common denominator of aFinset
of elements of aGCDMonoid
Finset.lcm
- the least common multiple of aFinset
of elements of aGCDMonoid
Implementation notes #
Many of the proofs use the lemmas gcd_def
and lcm_def
, which relate Finset.gcd
and Finset.lcm
to Multiset.gcd
and Multiset.lcm
.
TODO: simplify with a tactic and Data.Finset.Lattice
Tags #
finset, gcd
lcm #
def
Finset.lcm
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
(s : Finset β)
(f : β → α)
:
α
Least common multiple of a finite set
Equations
- s.lcm f = Finset.fold lcm 1 f s
Instances For
theorem
Finset.lcm_def
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
:
s.lcm f = (Multiset.map f s.val).lcm
@[simp]
theorem
Finset.lcm_empty
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{f : β → α}
:
@[simp]
theorem
Finset.lcm_dvd_iff
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
{a : α}
:
theorem
Finset.lcm_dvd
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
{a : α}
:
theorem
Finset.dvd_lcm
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
{b : β}
(hb : b ∈ s)
:
f b ∣ s.lcm f
@[simp]
theorem
Finset.lcm_insert
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
[DecidableEq β]
{b : β}
:
@[simp]
theorem
Finset.lcm_singleton
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{f : β → α}
{b : β}
:
{b}.lcm f = normalize (f b)
@[simp]
theorem
Finset.normalize_lcm
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
:
normalize (s.lcm f) = s.lcm f
theorem
Finset.lcm_union
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s₁ s₂ : Finset β}
{f : β → α}
[DecidableEq β]
:
theorem
Finset.lcm_congr
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s₁ s₂ : Finset β}
{f g : β → α}
(hs : s₁ = s₂)
(hfg : ∀ a ∈ s₂, f a = g a)
:
s₁.lcm f = s₂.lcm g
theorem
Finset.lcm_mono_fun
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f g : β → α}
(h : ∀ b ∈ s, f b ∣ g b)
:
s.lcm f ∣ s.lcm g
theorem
Finset.lcm_mono
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s₁ s₂ : Finset β}
{f : β → α}
(h : s₁ ⊆ s₂)
:
s₁.lcm f ∣ s₂.lcm f
theorem
Finset.lcm_image
{α : Type u_2}
{β : Type u_3}
{γ : Type u_4}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{f : β → α}
[DecidableEq β]
{g : γ → β}
(s : Finset γ)
:
(Finset.image g s).lcm f = s.lcm (f ∘ g)
theorem
Finset.lcm_eq_lcm_image
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
[DecidableEq α]
:
s.lcm f = (Finset.image f s).lcm id
theorem
Finset.lcm_eq_zero_iff
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
[Nontrivial α]
:
gcd #
def
Finset.gcd
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
(s : Finset β)
(f : β → α)
:
α
Greatest common divisor of a finite set
Equations
- s.gcd f = Finset.fold gcd 0 f s
Instances For
theorem
Finset.gcd_def
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
:
s.gcd f = (Multiset.map f s.val).gcd
@[simp]
theorem
Finset.gcd_empty
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{f : β → α}
:
theorem
Finset.dvd_gcd_iff
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
{a : α}
:
theorem
Finset.gcd_dvd
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
{b : β}
(hb : b ∈ s)
:
s.gcd f ∣ f b
theorem
Finset.dvd_gcd
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
{a : α}
:
@[simp]
theorem
Finset.gcd_insert
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
[DecidableEq β]
{b : β}
:
@[simp]
theorem
Finset.gcd_singleton
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{f : β → α}
{b : β}
:
{b}.gcd f = normalize (f b)
@[simp]
theorem
Finset.normalize_gcd
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
:
normalize (s.gcd f) = s.gcd f
theorem
Finset.gcd_union
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s₁ s₂ : Finset β}
{f : β → α}
[DecidableEq β]
:
theorem
Finset.gcd_congr
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s₁ s₂ : Finset β}
{f g : β → α}
(hs : s₁ = s₂)
(hfg : ∀ a ∈ s₂, f a = g a)
:
s₁.gcd f = s₂.gcd g
theorem
Finset.gcd_mono_fun
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f g : β → α}
(h : ∀ b ∈ s, f b ∣ g b)
:
s.gcd f ∣ s.gcd g
theorem
Finset.gcd_mono
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s₁ s₂ : Finset β}
{f : β → α}
(h : s₁ ⊆ s₂)
:
s₂.gcd f ∣ s₁.gcd f
theorem
Finset.gcd_image
{α : Type u_2}
{β : Type u_3}
{γ : Type u_4}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{f : β → α}
[DecidableEq β]
{g : γ → β}
(s : Finset γ)
:
(Finset.image g s).gcd f = s.gcd (f ∘ g)
theorem
Finset.gcd_eq_gcd_image
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
[DecidableEq α]
:
s.gcd f = (Finset.image f s).gcd id
theorem
Finset.gcd_eq_zero_iff
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
:
theorem
Finset.gcd_eq_gcd_filter_ne_zero
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
[DecidablePred fun (x : β) => f x = 0]
:
s.gcd f = (Finset.filter (fun (x : β) => f x ≠ 0) s).gcd f
theorem
Finset.gcd_mul_left
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
{a : α}
:
theorem
Finset.gcd_mul_right
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
{f : β → α}
{a : α}
:
theorem
Finset.extract_gcd'
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
(f g : β → α)
(hs : ∃ x ∈ s, f x ≠ 0)
(hg : ∀ b ∈ s, f b = s.gcd f * g b)
:
s.gcd g = 1
theorem
Finset.extract_gcd
{α : Type u_2}
{β : Type u_3}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
{s : Finset β}
(f : β → α)
(hs : s.Nonempty)
:
theorem
Finset.gcd_div_eq_one
{ι : Type u_1}
{α : Type u_2}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
[Div α]
[MulDivCancelClass α]
{f : ι → α}
{s : Finset ι}
{i : ι}
(his : i ∈ s)
(hfi : f i ≠ 0)
:
Given a nonempty Finset s
and a function f
from s
to ℕ
, if d = s.gcd
,
then the gcd
of (f i) / d
is equal to 1
.
theorem
Finset.gcd_div_id_eq_one
{α : Type u_2}
[CancelCommMonoidWithZero α]
[NormalizedGCDMonoid α]
[Div α]
[MulDivCancelClass α]
{s : Finset α}
{a : α}
(has : a ∈ s)
(ha : a ≠ 0)
: