doc-next-gen

Mathlib.Algebra.GCDMonoid.Finset

Module docstring

{"# GCD and LCM operations on finsets

Main definitions

  • Finset.gcd - the greatest common denominator of a Finset of elements of a GCDMonoid
  • Finset.lcm - the least common multiple of a Finset of elements of a GCDMonoid

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 ","### gcd "}

Finset.lcm definition
(s : Finset β) (f : β → α) : α
Full source
/-- Least common multiple of a finite set -/
def lcm (s : Finset β) (f : β → α) : α :=
  s.fold GCDMonoid.lcm 1 f
Least common multiple of a finite set under a function
Informal description
Given a finite set \( s \) of elements of type \( \beta \) and a function \( f : \beta \to \alpha \) where \( \alpha \) is a normalized GCD monoid, the least common multiple of the images \( f(x) \) for all \( x \in s \) is computed by folding the `lcm` operation over the set with initial value \( 1 \). More precisely, for a finite set \( s = \{x_1, \ldots, x_n\} \), the value \( \text{lcm}(s, f) \) is defined as: \[ \text{lcm}(f(x_1), \text{lcm}(f(x_2), \ldots, \text{lcm}(f(x_n), 1) \ldots)). \]
Finset.lcm_def theorem
: s.lcm f = (s.1.map f).lcm
Full source
theorem lcm_def : s.lcm f = (s.1.map f).lcm :=
  rfl
Least Common Multiple of Finite Set Equals LCM of Multiset Image
Informal description
For a finite set $s$ and a function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the least common multiple of $f$ over $s$ is equal to the least common multiple of the multiset obtained by applying $f$ to each element of the underlying multiset of $s$. That is, \[ \mathrm{lcm}(s, f) = \mathrm{lcm}(\mathrm{map}\, f\, s.1), \] where $s.1$ denotes the underlying multiset of $s$.
Finset.lcm_empty theorem
: (∅ : Finset β).lcm f = 1
Full source
@[simp]
theorem lcm_empty : ( : Finset β).lcm f = 1 :=
  fold_empty
Least Common Multiple of Empty Set is One
Informal description
For any function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the least common multiple of $f$ over the empty finite set $\emptyset$ is equal to $1$, i.e., \[ \mathrm{lcm}(\emptyset, f) = 1. \]
Finset.lcm_dvd_iff theorem
{a : α} : s.lcm f ∣ a ↔ ∀ b ∈ s, f b ∣ a
Full source
@[simp]
theorem lcm_dvd_iff {a : α} : s.lcm f ∣ as.lcm f ∣ a ↔ ∀ b ∈ s, f b ∣ a := by
  apply Iff.trans Multiset.lcm_dvd
  simp only [Multiset.mem_map, and_imp, exists_imp]
  exact ⟨fun k b hb ↦ k _ _ hb rfl, fun k a' b hb h ↦ h ▸ k _ hb⟩
Divisibility Criterion for Least Common Multiple of Finite Set under a Function: $\mathrm{lcm}(s, f) \mid a \leftrightarrow \forall b \in s, f(b) \mid a$
Informal description
For a finite set $s$ of elements of type $\beta$, a function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, and an element $a \in \alpha$, the least common multiple of the images $f(b)$ for all $b \in s$ divides $a$ if and only if $f(b)$ divides $a$ for every $b \in s$. That is, \[ \mathrm{lcm}(s, f) \mid a \leftrightarrow \forall b \in s, f(b) \mid a. \]
Finset.lcm_dvd theorem
{a : α} : (∀ b ∈ s, f b ∣ a) → s.lcm f ∣ a
Full source
theorem lcm_dvd {a : α} : (∀ b ∈ s, f b ∣ a) → s.lcm f ∣ a :=
  lcm_dvd_iff.2
Divisibility by Least Common Multiple of Finite Set under a Function
Informal description
For a finite set $s$ of elements of type $\beta$, a function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, and an element $a \in \alpha$, if $f(b)$ divides $a$ for every $b \in s$, then the least common multiple of the images $f(b)$ for all $b \in s$ divides $a$. That is, \[ (\forall b \in s, f(b) \mid a) \rightarrow \mathrm{lcm}(s, f) \mid a. \]
Finset.dvd_lcm theorem
{b : β} (hb : b ∈ s) : f b ∣ s.lcm f
Full source
theorem dvd_lcm {b : β} (hb : b ∈ s) : f b ∣ s.lcm f :=
  lcm_dvd_iff.1 dvd_rfl _ hb
Element Divides Least Common Multiple of Finite Set under a Function: $f(b) \mid \mathrm{lcm}(s, f)$
Informal description
For any element $b$ in a finite set $s$ of type $\beta$ and any function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the value $f(b)$ divides the least common multiple of the images $f(x)$ for all $x \in s$. That is, \[ f(b) \mid \mathrm{lcm}(s, f). \]
Finset.lcm_insert theorem
[DecidableEq β] {b : β} : (insert b s : Finset β).lcm f = GCDMonoid.lcm (f b) (s.lcm f)
Full source
@[simp]
theorem lcm_insert [DecidableEq β] {b : β} :
    (insert b s : Finset β).lcm f = GCDMonoid.lcm (f b) (s.lcm f) := by
  by_cases h : b ∈ s
  · rw [insert_eq_of_mem h,
      (lcm_eq_right_iff (f b) (s.lcm f) (Multiset.normalize_lcm (s.1.map f))).2 (dvd_lcm h)]
  apply fold_insert h
Insertion Property of Least Common Multiple for Finite Sets: $\mathrm{lcm}(\{b\} \cup s, f) = \mathrm{lcm}(f(b), \mathrm{lcm}(s, f))$
Informal description
For any finite set $s$ of elements of type $\beta$ with decidable equality, any element $b \in \beta$, and any function $f : \beta \to \alpha$ where $\alpha$ is a GCD monoid, the least common multiple of the images under $f$ of the elements in the set $\{b\} \cup s$ is equal to the least common multiple of $f(b)$ and the least common multiple of the images under $f$ of the elements in $s$. That is, \[ \mathrm{lcm}(f(x) \mid x \in \{b\} \cup s) = \mathrm{lcm}(f(b), \mathrm{lcm}(f(x) \mid x \in s)). \]
Finset.lcm_singleton theorem
{b : β} : ({ b } : Finset β).lcm f = normalize (f b)
Full source
@[simp]
theorem lcm_singleton {b : β} : ({b} : Finset β).lcm f = normalize (f b) :=
  Multiset.lcm_singleton
Least Common Multiple of Singleton Finite Set Equals Normalization of Function Value
Informal description
For any element $b$ in a type $\beta$ and any function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the least common multiple of the singleton finite set $\{b\}$ under $f$ is equal to the normalized form of $f(b)$, i.e., \[ \mathrm{lcm}(\{b\}, f) = \mathrm{normalize}(f(b)). \]
Finset.normalize_lcm theorem
: normalize (s.lcm f) = s.lcm f
Full source
@[local simp] -- This will later be provable by other `simp` lemmas.
theorem normalize_lcm : normalize (s.lcm f) = s.lcm f := by simp [lcm_def]
Normalization of Finite Set Least Common Multiple: $\text{normalize}(\text{lcm}(s, f)) = \text{lcm}(s, f)$
Informal description
For any finite set $s$ of elements of type $\beta$ and any function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the normalization of the least common multiple of the images $f(x)$ for $x \in s$ is equal to the least common multiple itself, i.e., \[ \text{normalize}(\text{lcm}(f(x) \mid x \in s)) = \text{lcm}(f(x) \mid x \in s). \]
Finset.lcm_union theorem
[DecidableEq β] : (s₁ ∪ s₂).lcm f = GCDMonoid.lcm (s₁.lcm f) (s₂.lcm f)
Full source
theorem lcm_union [DecidableEq β] : (s₁ ∪ s₂).lcm f = GCDMonoid.lcm (s₁.lcm f) (s₂.lcm f) :=
  Finset.induction_on s₁ (by rw [empty_union, lcm_empty, lcm_one_left, normalize_lcm])
    fun a s _ ih ↦ by rw [insert_union, lcm_insert, lcm_insert, ih, lcm_assoc]
Least Common Multiple of Union of Finite Sets: $\mathrm{lcm}(s_1 \cup s_2, f) = \mathrm{lcm}(\mathrm{lcm}(s_1, f), \mathrm{lcm}(s_2, f))$
Informal description
For any finite sets $s_1$ and $s_2$ of elements of type $\beta$ with decidable equality, and any function $f : \beta \to \alpha$ where $\alpha$ is a GCD monoid, the least common multiple of the images under $f$ of the elements in the union $s_1 \cup s_2$ is equal to the least common multiple of the least common multiples of the images under $f$ of the elements in $s_1$ and $s_2$ respectively. That is, \[ \mathrm{lcm}(f(x) \mid x \in s_1 \cup s_2) = \mathrm{lcm}(\mathrm{lcm}(f(x) \mid x \in s_1), \mathrm{lcm}(f(x) \mid x \in s_2)). \]
Finset.lcm_congr theorem
{f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) : s₁.lcm f = s₂.lcm g
Full source
theorem lcm_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) :
    s₁.lcm f = s₂.lcm g := by
  subst hs
  exact Finset.fold_congr hfg
Equality of Least Common Multiples under Function Congruence
Informal description
Let $s_1$ and $s_2$ be finite sets of elements of type $\beta$, and let $f, g : \beta \to \alpha$ be functions where $\alpha$ is a normalized GCD monoid. If $s_1 = s_2$ and for every $a \in s_2$ we have $f(a) = g(a)$, then the least common multiple of the images of $f$ over $s_1$ is equal to the least common multiple of the images of $g$ over $s_2$, i.e., \[ \mathrm{lcm}(s_1, f) = \mathrm{lcm}(s_2, g). \]
Finset.lcm_mono_fun theorem
{g : β → α} (h : ∀ b ∈ s, f b ∣ g b) : s.lcm f ∣ s.lcm g
Full source
theorem lcm_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ∣ g b) : s.lcm f ∣ s.lcm g :=
  lcm_dvd fun b hb ↦ (h b hb).trans (dvd_lcm hb)
Monotonicity of Least Common Multiple under Function Comparison: $\mathrm{lcm}(s, f) \mid \mathrm{lcm}(s, g)$ when $f(b) \mid g(b)$ for all $b \in s$
Informal description
For a finite set $s$ of elements of type $\beta$ and functions $f, g : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, if $f(b)$ divides $g(b)$ for every $b \in s$, then the least common multiple of the images of $f$ over $s$ divides the least common multiple of the images of $g$ over $s$. That is, \[ (\forall b \in s, f(b) \mid g(b)) \rightarrow \mathrm{lcm}(s, f) \mid \mathrm{lcm}(s, g). \]
Finset.lcm_mono theorem
(h : s₁ ⊆ s₂) : s₁.lcm f ∣ s₂.lcm f
Full source
theorem lcm_mono (h : s₁ ⊆ s₂) : s₁.lcm f ∣ s₂.lcm f :=
  lcm_dvd fun _ hb ↦ dvd_lcm (h hb)
Monotonicity of Least Common Multiple with Respect to Subset Inclusion
Informal description
For any finite sets $s_1$ and $s_2$ of elements of type $\beta$, a function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, if $s_1$ is a subset of $s_2$, then the least common multiple of the images of $f$ over $s_1$ divides the least common multiple of the images of $f$ over $s_2$. That is, \[ s_1 \subseteq s_2 \implies \mathrm{lcm}(s_1, f) \mid \mathrm{lcm}(s_2, f). \]
Finset.lcm_image theorem
[DecidableEq β] {g : γ → β} (s : Finset γ) : (s.image g).lcm f = s.lcm (f ∘ g)
Full source
theorem lcm_image [DecidableEq β] {g : γ → β} (s : Finset γ) :
    (s.image g).lcm f = s.lcm (f ∘ g) := by
  classical induction s using Finset.induction <;> simp [*]
Image LCM Formula: $\mathrm{lcm}(f \circ g)(s) = \mathrm{lcm}(f)(g(s))$
Informal description
Let $\alpha$ be a normalized GCD monoid, $\beta$ and $\gamma$ be types with decidable equality on $\beta$, $f : \beta \to \alpha$ a function, and $g : \gamma \to \beta$ a function. For any finite set $s \subseteq \gamma$, the least common multiple of $f$ over the image of $s$ under $g$ equals the least common multiple of $f \circ g$ over $s$. In symbols: \[ \mathrm{lcm}(f(y) \mid y \in g(s)) = \mathrm{lcm}(f(g(x)) \mid x \in s) \]
Finset.lcm_eq_lcm_image theorem
[DecidableEq α] : s.lcm f = (s.image f).lcm id
Full source
theorem lcm_eq_lcm_image [DecidableEq α] : s.lcm f = (s.image f).lcm id :=
  Eq.symm <| lcm_image _
LCM of Function Images Equals LCM of Image Set
Informal description
Let $\alpha$ be a normalized GCD monoid with decidable equality, $s$ be a finite set of elements of type $\beta$, and $f : \beta \to \alpha$ be a function. The least common multiple of the images of $f$ over $s$ is equal to the least common multiple of the identity function over the image of $s$ under $f$. In symbols: \[ \mathrm{lcm}_{x \in s} f(x) = \mathrm{lcm}_{y \in f(s)} y. \]
Finset.lcm_eq_zero_iff theorem
[Nontrivial α] : s.lcm f = 0 ↔ 0 ∈ f '' s
Full source
theorem lcm_eq_zero_iff [Nontrivial α] : s.lcm f = 0 ↔ 0 ∈ f '' s := by
  simp only [Multiset.mem_map, lcm_def, Multiset.lcm_eq_zero_iff, Set.mem_image, mem_coe, ←
    Finset.mem_def]
Least Common Multiple Vanishes if and only if Zero is in the Image
Informal description
Let $\alpha$ be a nontrivial normalized GCD monoid, $s$ be a finite set of elements of type $\beta$, and $f : \beta \to \alpha$ be a function. The least common multiple of the images of $f$ over $s$ is zero if and only if zero is in the image of $f$ on $s$, i.e., \[ \mathrm{lcm}_{x \in s} f(x) = 0 \iff 0 \in f(s). \]
Finset.gcd definition
(s : Finset β) (f : β → α) : α
Full source
/-- Greatest common divisor of a finite set -/
def gcd (s : Finset β) (f : β → α) : α :=
  s.fold GCDMonoid.gcd 0 f
Greatest common divisor of a finite set under a function
Informal description
Given a finite set $s$ of elements of type $\beta$ and a function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the function $\text{Finset.gcd}$ computes the greatest common divisor of the images $f(x)$ for all $x \in s$. For the empty set, it returns $0$.
Finset.gcd_def theorem
: s.gcd f = (s.1.map f).gcd
Full source
theorem gcd_def : s.gcd f = (s.1.map f).gcd :=
  rfl
Finite Set GCD as Multiset GCD
Informal description
For a finite set $s$ of elements of type $\beta$ and a function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the greatest common divisor of $f$ over $s$ equals the greatest common divisor of the multiset obtained by applying $f$ to the underlying multiset of $s$. In other words, $\gcd_{x \in s} f(x) = \gcd (f[\text{multiset}(s)])$.
Finset.gcd_empty theorem
: (∅ : Finset β).gcd f = 0
Full source
@[simp]
theorem gcd_empty : ( : Finset β).gcd f = 0 :=
  fold_empty
GCD of Empty Set is Zero
Informal description
For any function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the greatest common divisor of the images of the empty set under $f$ is $0$, i.e., $$\gcd_{x \in \emptyset} f(x) = 0.$$
Finset.dvd_gcd_iff theorem
{a : α} : a ∣ s.gcd f ↔ ∀ b ∈ s, a ∣ f b
Full source
theorem dvd_gcd_iff {a : α} : a ∣ s.gcd fa ∣ s.gcd f ↔ ∀ b ∈ s, a ∣ f b := by
  apply Iff.trans Multiset.dvd_gcd
  simp only [Multiset.mem_map, and_imp, exists_imp]
  exact ⟨fun k b hb ↦ k _ _ hb rfl, fun k a' b hb h ↦ h ▸ k _ hb⟩
Divisibility Condition for Finite Set GCD: $a \mid \gcd_s f \leftrightarrow \forall b \in s, a \mid f(b)$
Informal description
Let $\alpha$ be a normalized GCD monoid, $s$ a finite set of elements of type $\beta$, and $f : \beta \to \alpha$ a function. For any element $a \in \alpha$, we have that $a$ divides the greatest common divisor of $f$ over $s$ if and only if $a$ divides $f(b)$ for every $b \in s$. In symbols: \[ a \mid \gcd_{x \in s} f(x) \leftrightarrow \forall b \in s, a \mid f(b). \]
Finset.gcd_dvd theorem
{b : β} (hb : b ∈ s) : s.gcd f ∣ f b
Full source
theorem gcd_dvd {b : β} (hb : b ∈ s) : s.gcd f ∣ f b :=
  dvd_gcd_iff.1 dvd_rfl _ hb
GCD of Finite Set Divides Each Element
Informal description
Let $\alpha$ be a normalized GCD monoid, $s$ a finite set of elements of type $\beta$, and $f : \beta \to \alpha$ a function. For any element $b \in s$, the greatest common divisor of $f$ over $s$ divides $f(b)$. In symbols: \[ \gcd_{x \in s} f(x) \mid f(b). \]
Finset.dvd_gcd theorem
{a : α} : (∀ b ∈ s, a ∣ f b) → a ∣ s.gcd f
Full source
theorem dvd_gcd {a : α} : (∀ b ∈ s, a ∣ f b) → a ∣ s.gcd f :=
  dvd_gcd_iff.2
Divisibility Implication for Finite Set GCD: $(\forall b \in s, a \mid f(b)) \rightarrow a \mid \gcd_s f$
Informal description
Let $\alpha$ be a normalized GCD monoid, $s$ a finite set of elements of type $\beta$, and $f : \beta \to \alpha$ a function. For any element $a \in \alpha$, if $a$ divides $f(b)$ for every $b \in s$, then $a$ divides the greatest common divisor of $f$ over $s$. In symbols: \[ (\forall b \in s, a \mid f(b)) \rightarrow a \mid \gcd_{x \in s} f(x). \]
Finset.gcd_insert theorem
[DecidableEq β] {b : β} : (insert b s : Finset β).gcd f = GCDMonoid.gcd (f b) (s.gcd f)
Full source
@[simp]
theorem gcd_insert [DecidableEq β] {b : β} :
    (insert b s : Finset β).gcd f = GCDMonoid.gcd (f b) (s.gcd f) := by
  by_cases h : b ∈ s
  · rw [insert_eq_of_mem h,
      (gcd_eq_right_iff (f b) (s.gcd f) (Multiset.normalize_gcd (s.1.map f))).2 (gcd_dvd h)]
  apply fold_insert h
GCD of Inserted Element in Finite Set: $\gcd(\{b\} \cup s, f) = \gcd(f(b), \gcd(s, f))$
Informal description
Let $\alpha$ be a normalized GCD monoid and $\beta$ a type with decidable equality. For any finite set $s \subseteq \beta$, any function $f : \beta \to \alpha$, and any element $b \in \beta$, the greatest common divisor of $f$ over the set $\{b\} \cup s$ equals the greatest common divisor of $f(b)$ and the greatest common divisor of $f$ over $s$. In symbols: \[ \gcd_{x \in \{b\} \cup s} f(x) = \gcd(f(b), \gcd_{x \in s} f(x)). \]
Finset.gcd_singleton theorem
{b : β} : ({ b } : Finset β).gcd f = normalize (f b)
Full source
@[simp]
theorem gcd_singleton {b : β} : ({b} : Finset β).gcd f = normalize (f b) :=
  Multiset.gcd_singleton
GCD of Singleton Finite Set Equals Normalization of Element
Informal description
For any element $b$ of type $\beta$ and any function $f : \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the greatest common divisor of the singleton finite set $\{b\}$ under $f$ equals the normalization of $f(b)$, i.e., $\gcd(\{b\}, f) = \mathrm{normalize}(f(b))$.
Finset.normalize_gcd theorem
: normalize (s.gcd f) = s.gcd f
Full source
@[local simp] -- This will later be provable by other `simp` lemmas.
theorem normalize_gcd : normalize (s.gcd f) = s.gcd f := by simp [gcd_def]
Normalization of GCD over Finite Set: $\mathrm{normalize}(\gcd(f(s))) = \gcd(f(s))$
Informal description
For any finite set $s$ and any function $f$ mapping elements of $s$ to a normalized GCD monoid $\alpha$, the normalized form of the greatest common divisor of the images of $f$ over $s$ is equal to the greatest common divisor itself, i.e., \[ \mathrm{normalize}(\gcd(f(s))) = \gcd(f(s)). \]
Finset.gcd_union theorem
[DecidableEq β] : (s₁ ∪ s₂).gcd f = GCDMonoid.gcd (s₁.gcd f) (s₂.gcd f)
Full source
theorem gcd_union [DecidableEq β] : (s₁ ∪ s₂).gcd f = GCDMonoid.gcd (s₁.gcd f) (s₂.gcd f) :=
  Finset.induction_on s₁ (by rw [empty_union, gcd_empty, gcd_zero_left, normalize_gcd])
    fun a s _ ih ↦ by rw [insert_union, gcd_insert, gcd_insert, ih, gcd_assoc]
GCD of Union of Finite Sets: $\gcd(f(s_1 \cup s_2)) = \gcd(\gcd(f(s_1)), \gcd(f(s_2)))$
Informal description
Let $\alpha$ be a normalized GCD monoid and $\beta$ a type with decidable equality. For any two finite sets $s_1, s_2 \subseteq \beta$ and any function $f : \beta \to \alpha$, the greatest common divisor of $f$ over the union $s_1 \cup s_2$ equals the greatest common divisor of the greatest common divisors of $f$ over $s_1$ and $s_2$ separately. In symbols: \[ \gcd_{x \in s_1 \cup s_2} f(x) = \gcd\left(\gcd_{x \in s_1} f(x), \gcd_{x \in s_2} f(x)\right). \]
Finset.gcd_congr theorem
{f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) : s₁.gcd f = s₂.gcd g
Full source
theorem gcd_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) :
    s₁.gcd f = s₂.gcd g := by
  subst hs
  exact Finset.fold_congr hfg
Congruence of GCD under Function Equality on Finite Sets
Informal description
Let $s_1$ and $s_2$ be two finite sets of type $\beta$, and let $f, g : \beta \to \alpha$ be functions where $\alpha$ is a normalized GCD monoid. If $s_1 = s_2$ and for every element $a \in s_2$ we have $f(a) = g(a)$, then the greatest common divisor of the images of $f$ over $s_1$ is equal to the greatest common divisor of the images of $g$ over $s_2$, i.e., \[ \text{gcd}(f(s_1)) = \text{gcd}(g(s_2)). \]
Finset.gcd_mono_fun theorem
{g : β → α} (h : ∀ b ∈ s, f b ∣ g b) : s.gcd f ∣ s.gcd g
Full source
theorem gcd_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ∣ g b) : s.gcd f ∣ s.gcd g :=
  dvd_gcd fun b hb ↦ (gcd_dvd hb).trans (h b hb)
Monotonicity of GCD under Function Divisibility in Finite Sets
Informal description
Let $\alpha$ be a normalized GCD monoid, $s$ a finite set of elements of type $\beta$, and $f, g : \beta \to \alpha$ functions. If for every $b \in s$ we have $f(b) \mid g(b)$, then the greatest common divisor of $f$ over $s$ divides the greatest common divisor of $g$ over $s$, i.e., \[ \gcd_{x \in s} f(x) \mid \gcd_{x \in s} g(x). \]
Finset.gcd_mono theorem
(h : s₁ ⊆ s₂) : s₂.gcd f ∣ s₁.gcd f
Full source
theorem gcd_mono (h : s₁ ⊆ s₂) : s₂.gcd f ∣ s₁.gcd f :=
  dvd_gcd fun _ hb ↦ gcd_dvd (h hb)
Monotonicity of GCD under Subset Inclusion: $\gcd_{s_2} f \mid \gcd_{s_1} f$ when $s_1 \subseteq s_2$
Informal description
Let $\alpha$ be a normalized GCD monoid, $s_1$ and $s_2$ finite sets of elements of type $\beta$, and $f : \beta \to \alpha$ a function. If $s_1 \subseteq s_2$, then the greatest common divisor of $f$ over $s_2$ divides the greatest common divisor of $f$ over $s_1$. In symbols: \[ \gcd_{x \in s_2} f(x) \mid \gcd_{x \in s_1} f(x). \]
Finset.gcd_image theorem
[DecidableEq β] {g : γ → β} (s : Finset γ) : (s.image g).gcd f = s.gcd (f ∘ g)
Full source
theorem gcd_image [DecidableEq β] {g : γ → β} (s : Finset γ) :
    (s.image g).gcd f = s.gcd (f ∘ g) := by
  classical induction s using Finset.induction <;> simp [*]
GCD of Image Equals GCD of Composition: $\gcd_{g(s)} f = \gcd_s (f \circ g)$
Informal description
Let $\alpha$ be a normalized GCD monoid, $\beta$ and $\gamma$ types with decidable equality on $\beta$, $f : \beta \to \alpha$ a function, $g : \gamma \to \beta$ a function, and $s$ a finite subset of $\gamma$. Then the greatest common divisor of $f$ over the image of $s$ under $g$ is equal to the greatest common divisor of the composition $f \circ g$ over $s$. In symbols: \[ \gcd_{y \in g(s)} f(y) = \gcd_{x \in s} (f \circ g)(x). \]
Finset.gcd_eq_gcd_image theorem
[DecidableEq α] : s.gcd f = (s.image f).gcd id
Full source
theorem gcd_eq_gcd_image [DecidableEq α] : s.gcd f = (s.image f).gcd id :=
  Eq.symm <| gcd_image _
GCD of Function Equals GCD of Image: $\gcd_s f = \gcd_{f(s)} \text{id}$
Informal description
Let $\alpha$ be a normalized GCD monoid with decidable equality, $s$ a finite set of elements of type $\beta$, and $f \colon \beta \to \alpha$ a function. Then the greatest common divisor of $f$ over $s$ is equal to the greatest common divisor of the identity function over the image of $s$ under $f$. In symbols: \[ \gcd_{x \in s} f(x) = \gcd_{y \in f(s)} y. \]
Finset.gcd_eq_zero_iff theorem
: s.gcd f = 0 ↔ ∀ x : β, x ∈ s → f x = 0
Full source
theorem gcd_eq_zero_iff : s.gcd f = 0 ↔ ∀ x : β, x ∈ s → f x = 0 := by
  rw [gcd_def, Multiset.gcd_eq_zero_iff]
  constructor <;> intro h
  · intro b bs
    apply h (f b)
    simp only [Multiset.mem_map, mem_def.1 bs]
    use b
    simp only [mem_def.1 bs, eq_self_iff_true, and_self]
  · intro a as
    rw [Multiset.mem_map] at as
    rcases as with ⟨b, ⟨bs, rfl⟩⟩
    apply h b (mem_def.1 bs)
GCD of Finite Set is Zero if and only if All Function Values are Zero
Informal description
For a finite set $s$ of elements of type $\beta$ and a function $f \colon \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the greatest common divisor of $f$ over $s$ is zero if and only if $f(x) = 0$ for all $x \in s$. That is, $$\gcd_{x \in s} f(x) = 0 \leftrightarrow \forall x \in s, f(x) = 0.$$
Finset.gcd_eq_gcd_filter_ne_zero theorem
[DecidablePred fun x : β ↦ f x = 0] : s.gcd f = {x ∈ s | f x ≠ 0}.gcd f
Full source
theorem gcd_eq_gcd_filter_ne_zero [DecidablePred fun x : β ↦ f x = 0] :
    s.gcd f = {x ∈ s | f x ≠ 0}.gcd f := by
  classical
    trans ({x ∈ s | f x = 0}{x ∈ s | f x = 0} ∪ {x ∈ s | f x ≠ 0}).gcd f
    · rw [filter_union_filter_neg_eq]
    rw [gcd_union]
    refine Eq.trans (?_ : _ = GCDMonoid.gcd (0 : α) ?_) (?_ : GCDMonoid.gcd (0 : α) _ = _)
    · exact gcd {x ∈ s | f x ≠ 0} f
    · refine congr (congr rfl <| s.induction_on ?_ ?_) (by simp)
      · simp
      · intro a s _ h
        rw [filter_insert]
        split_ifs with h1 <;> simp [h, h1]
    simp only [gcd_zero_left, normalize_gcd]
GCD of Finite Set Equals GCD of Nonzero Elements: $\gcd(f(s)) = \gcd(f(\{x \in s \mid f(x) \neq 0\}))$
Informal description
For a finite set $s$ of elements of type $\beta$ and a function $f \colon \beta \to \alpha$ where $\alpha$ is a normalized GCD monoid, the greatest common divisor of $f$ over $s$ is equal to the greatest common divisor of $f$ over the subset of $s$ where $f(x) \neq 0$. That is, \[ \gcd_{x \in s} f(x) = \gcd_{x \in \{y \in s \mid f(y) \neq 0\}} f(x). \]
Finset.gcd_mul_left theorem
{a : α} : (s.gcd fun x ↦ a * f x) = normalize a * s.gcd f
Full source
nonrec theorem gcd_mul_left {a : α} : (s.gcd fun x ↦ a * f x) = normalize a * s.gcd f := by
  classical
    refine s.induction_on ?_ ?_
    · simp
    · intro b t _ h
      rw [gcd_insert, gcd_insert, h, ← gcd_mul_left]
      apply ((normalize_associated a).mul_right _).gcd_eq_right
Left Multiplication Property of GCD for Finite Sets: $\gcd_s (a \cdot f) = \mathrm{normalize}(a) \cdot \gcd_s f$
Informal description
Let $\alpha$ be a normalized GCD monoid. For any finite set $s$ of elements of type $\beta$, any function $f \colon \beta \to \alpha$, and any element $a \in \alpha$, the greatest common divisor of the function $a \cdot f(x)$ over $s$ equals the normalized form of $a$ multiplied by the greatest common divisor of $f$ over $s$. That is, \[ \gcd_{x \in s} (a \cdot f(x)) = \mathrm{normalize}(a) \cdot \gcd_{x \in s} f(x). \]
Finset.gcd_mul_right theorem
{a : α} : (s.gcd fun x ↦ f x * a) = s.gcd f * normalize a
Full source
nonrec theorem gcd_mul_right {a : α} : (s.gcd fun x ↦ f x * a) = s.gcd f * normalize a := by
  classical
    refine s.induction_on ?_ ?_
    · simp
    · intro b t _ h
      rw [gcd_insert, gcd_insert, h, ← gcd_mul_right]
      apply ((normalize_associated a).mul_left _).gcd_eq_right
Right Multiplication Identity for Finite Set GCD: $\gcd_{x \in s} (f(x) \cdot a) = \gcd_{x \in s} f(x) \cdot \mathrm{normalize}(a)$
Informal description
Let $\alpha$ be a normalized GCD monoid. For any finite set $s$ of elements of type $\beta$, any function $f : \beta \to \alpha$, and any element $a \in \alpha$, the greatest common divisor of the function $x \mapsto f(x) * a$ over $s$ equals the greatest common divisor of $f$ over $s$ multiplied by the normalization of $a$. In symbols: \[ \gcd_{x \in s} (f(x) \cdot a) = \left(\gcd_{x \in s} f(x)\right) \cdot \mathrm{normalize}(a). \]
Finset.extract_gcd' theorem
(f g : β → α) (hs : ∃ x, x ∈ s ∧ f x ≠ 0) (hg : ∀ b ∈ s, f b = s.gcd f * g b) : s.gcd g = 1
Full source
theorem extract_gcd' (f g : β → α) (hs : ∃ x, x ∈ s ∧ f x ≠ 0)
    (hg : ∀ b ∈ s, f b = s.gcd f * g b) : s.gcd g = 1 :=
  ((@mul_right_eq_self₀ _ _ (s.gcd f) _).1 <| by
        conv_lhs => rw [← normalize_gcd, ← gcd_mul_left, ← gcd_congr rfl hg]).resolve_right <| by
    contrapose! hs
    exact gcd_eq_zero_iff.1 hs
Extraction of GCD from Finite Set Yields Coprime Function
Informal description
Let $s$ be a finite set of elements of type $\beta$, and let $f, g : \beta \to \alpha$ be functions where $\alpha$ is a normalized GCD monoid. Suppose there exists an element $x \in s$ such that $f(x) \neq 0$, and for every $b \in s$, $f(b) = \gcd_{x \in s} f(x) \cdot g(b)$. Then the greatest common divisor of $g$ over $s$ is equal to $1$, i.e., \[ \gcd_{x \in s} g(x) = 1. \]
Finset.extract_gcd theorem
(f : β → α) (hs : s.Nonempty) : ∃ g : β → α, (∀ b ∈ s, f b = s.gcd f * g b) ∧ s.gcd g = 1
Full source
theorem extract_gcd (f : β → α) (hs : s.Nonempty) :
    ∃ g : β → α, (∀ b ∈ s, f b = s.gcd f * g b) ∧ s.gcd g = 1 := by
  classical
    by_cases h : ∀ x ∈ s, f x = (0 : α)
    · refine ⟨fun _ ↦ 1, fun b hb ↦ by rw [h b hb, gcd_eq_zero_iff.2 h, mul_one], ?_⟩
      rw [gcd_eq_gcd_image, image_const hs, gcd_singleton, id, normalize_one]
    · choose g' hg using @gcd_dvd _ _ _ _ s f
      push_neg at h
      refine ⟨fun b ↦ if hb : b ∈ s then g' hb else 0, fun b hb ↦ ?_,
          extract_gcd' f _ h fun b hb ↦ ?_⟩
      · simp only [hb, hg, dite_true]
      rw [dif_pos hb, hg hb]
Existence of Coprime Factorization for Nonempty Finite Sets in GCD Monoids
Informal description
Let $\alpha$ be a normalized GCD monoid, $s$ a nonempty finite set of elements of type $\beta$, and $f : \beta \to \alpha$ a function. Then there exists a function $g : \beta \to \alpha$ such that for all $b \in s$, $f(b) = \gcd_{x \in s} f(x) \cdot g(b)$, and the greatest common divisor of $g$ over $s$ is $1$.
Finset.gcd_div_eq_one theorem
(his : i ∈ s) (hfi : f i ≠ 0) : s.gcd (fun j ↦ f j / s.gcd f) = 1
Full source
/-- 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`. -/
lemma gcd_div_eq_one (his : i ∈ s) (hfi : f i ≠ 0) : s.gcd (fun j ↦ f j / s.gcd f) = 1 := by
  obtain ⟨g, he, hg⟩ := Finset.extract_gcd f ⟨i, his⟩
  refine (Finset.gcd_congr rfl fun a ha ↦ ?_).trans hg
  rw [he a ha, mul_div_cancel_left₀]
  exact mt Finset.gcd_eq_zero_iff.1 fun h ↦ hfi <| h i his
GCD of Scaled Values is One in Nonempty Finite Sets
Informal description
Let $\alpha$ be a normalized GCD monoid, $s$ a finite set of elements of type $\beta$, and $f : \beta \to \alpha$ a function. For any $i \in s$ with $f(i) \neq 0$, the greatest common divisor of the scaled values $\frac{f(j)}{\gcd_{x \in s} f(x)}$ for $j \in s$ is equal to $1$. That is, \[ \gcd_{j \in s} \left( \frac{f(j)}{\gcd_{x \in s} f(x)} \right) = 1. \]
Finset.gcd_div_id_eq_one theorem
{s : Finset α} {a : α} (has : a ∈ s) (ha : a ≠ 0) : s.gcd (fun b ↦ b / s.gcd id) = 1
Full source
lemma gcd_div_id_eq_one {s : Finset α} {a : α} (has : a ∈ s) (ha : a ≠ 0) :
    s.gcd (fun b ↦ b / s.gcd id) = 1 := gcd_div_eq_one has ha
GCD of Scaled Elements is One in Nonempty Finite Sets
Informal description
Let $\alpha$ be a normalized GCD monoid and $s$ a finite subset of $\alpha$. For any element $a \in s$ with $a \neq 0$, the greatest common divisor of the scaled elements $\frac{b}{\gcd_{x \in s} x}$ for $b \in s$ is equal to $1$. That is, \[ \gcd_{b \in s} \left( \frac{b}{\gcd_{x \in s} x} \right) = 1. \]
Finset.gcd_eq_of_dvd_sub theorem
{s : Finset β} {f g : β → α} {a : α} (h : ∀ x : β, x ∈ s → a ∣ f x - g x) : GCDMonoid.gcd a (s.gcd f) = GCDMonoid.gcd a (s.gcd g)
Full source
theorem gcd_eq_of_dvd_sub {s : Finset β} {f g : β → α} {a : α}
    (h : ∀ x : β, x ∈ sa ∣ f x - g x) :
    GCDMonoid.gcd a (s.gcd f) = GCDMonoid.gcd a (s.gcd g) := by
  classical
    revert h
    refine s.induction_on ?_ ?_
    · simp
    intro b s _ hi h
    rw [gcd_insert, gcd_insert, gcd_comm (f b), ← gcd_assoc,
      hi fun x hx ↦ h _ (mem_insert_of_mem hx), gcd_comm a, gcd_assoc,
      gcd_comm a (GCDMonoid.gcd _ _), gcd_comm (g b), gcd_assoc _ _ a, gcd_comm _ a]
    exact congr_arg _ (gcd_eq_of_dvd_sub_right (h _ (mem_insert_self _ _)))
GCD Equality under Divisibility of Differences in Finite Sets: $\gcd(a, \gcd_s f) = \gcd(a, \gcd_s g)$ when $a \mid f(x) - g(x)$ for all $x \in s$
Informal description
Let $\alpha$ be a normalized GCD monoid and $\beta$ a type. For any finite set $s \subseteq \beta$, any functions $f, g : \beta \to \alpha$, and any element $a \in \alpha$, if for every $x \in s$ we have $a$ divides $f(x) - g(x)$, then the greatest common divisor of $a$ and the greatest common divisor of $f$ over $s$ equals the greatest common divisor of $a$ and the greatest common divisor of $g$ over $s$. In symbols: \[ \gcd(a, \gcd_{x \in s} f(x)) = \gcd(a, \gcd_{x \in s} g(x)). \]