/-
Copyright 2026 The Formal Conjectures Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
module
public import Mathlib.Algebra.Group.Submonoid.Operations
public import Mathlib.Data.Set.Card
public import Mathlib.Order.Lattice.Nat@[expose] public sectionNumerical semigroups
An additive submonoid $S \le \mathbb{N}$ with finite complement $\mathbb{N} \setminus S$ is a
numerical semigroup. This file defines the predicate AddSubmonoid.IsNumericalSemigroup, the
conductor $c(S)$, and the embedding dimension $e(S)$.
References:
Wikipedia, Numerical semigroup
R. Fröberg, C. Gottlieb, and R. Häggkvist, On numerical semigroups, Semigroup Forum 35 (1987), no. 1, 63–83.
namespace AddSubmonoid
An additive submonoid S : AddSubmonoid ℕ is a numerical semigroup when ℕ \ S is finite.
def IsNumericalSemigroup (S : AddSubmonoid ℕ) : Prop :=
(S : Set ℕ)ᶜ.FiniteConductor $c(S) = \min{c \in \mathbb{N} : \forall m \ge c,, m \in S}$.
noncomputable def conductor (S : AddSubmonoid ℕ) : ℕ :=
sInf {c : ℕ | ∀ m : ℕ, c ≤ m → m ∈ S}Embedding dimension $e(S) = |S_{>0} \setminus (S_{>0} + S_{>0})|$, counting minimal positive generators of $S$.
noncomputable def embeddingDim (S : AddSubmonoid ℕ) : ℕ :=
{x : ℕ | 0 < x ∧ x ∈ S ∧ ¬ ∃ a b : ℕ, 0 < a ∧ 0 < b ∧ a ∈ S ∧ b ∈ S ∧ x = a + b}.ncardEvery integer $m \ge \operatorname{conductor}(S)$ belongs to a numerical semigroup $S$.
S:AddSubmonoid ℕhS:S.IsNumericalSemigroupm:ℕhm:S.conductor ≤ mA:Set ℕ := {c | ∀ (k : ℕ), c ≤ k → k ∈ S}hA_ne:A.Nonempty⊢ m ∈ S
exact Nat.sInf_mem hA_ne m hm All goals completed! 🐙@[simp]
theorem isNumericalSemigroup_top : (⊤ : AddSubmonoid ℕ).IsNumericalSemigroup := by ⊢ ⊤.IsNumericalSemigroup
simp [IsNumericalSemigroup] All goals completed! 🐙@[simp]
theorem conductor_top : (⊤ : AddSubmonoid ℕ).conductor = 0 :=
Nat.sInf_eq_zero.mpr (Or.inl (fun _ _ => trivial))
@[simp]
theorem embeddingDim_top : (⊤ : AddSubmonoid ℕ).embeddingDim = 1 := by ⊢ ⊤.embeddingDim = 1
unfold embeddingDim ⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1
have hset : {x : ℕ | 0 < x ∧ x ∈ (⊤ : AddSubmonoid ℕ) ∧
¬ ∃ a b : ℕ, 0 < a ∧ 0 < b ∧
a ∈ (⊤ : AddSubmonoid ℕ) ∧ b ∈ (⊤ : AddSubmonoid ℕ) ∧ x = a + b} = {1} := by ⊢ ⊤.embeddingDim = 1 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1
ext x x:ℕ⊢ x ∈ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} ↔ x ∈ {1} hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1
simp only [Set.mem_ofPred_eq, AddSubmonoid.mem_top, true_and, Set.mem_singleton_iff] x:ℕ⊢ (0 < x ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + b) ↔ x = 1 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1
refine ⟨fun ⟨hx, hmin⟩ => ?_, ?_⟩ refine_1 x:ℕx✝:0 < x ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + bhx:0 < xhmin:¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + b⊢ x = 1refine_2 x:ℕ⊢ x = 1 → 0 < x ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + b hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1
· refine_1 x:ℕx✝:0 < x ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + bhx:0 < xhmin:¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + b⊢ x = 1 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1 by_contra hx1 refine_1 x:ℕx✝:0 < x ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + bhx:0 < xhmin:¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + bhx1:¬x = 1⊢ False hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1
exact hmin ⟨1, x - 1, by x:ℕx✝:0 < x ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + bhx:0 < xhmin:¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + bhx1:¬x = 1⊢ 0 < 1 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1 omega All goals completed! 🐙 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1, by x:ℕx✝:0 < x ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + bhx:0 < xhmin:¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + bhx1:¬x = 1⊢ 0 < x - 1 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1 omega All goals completed! 🐙 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1, by x:ℕx✝:0 < x ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + bhx:0 < xhmin:¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + bhx1:¬x = 1⊢ x = 1 + (x - 1) hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1 omega All goals completed! 🐙 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1⟩
· refine_2 x:ℕ⊢ x = 1 → 0 < x ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ x = a + b hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1 rintro rfl refine_2 ⊢ 0 < 1 ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ 1 = a + b hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1
exact ⟨by ⊢ 0 < 1 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1 omega All goals completed! 🐙 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1, fun ⟨a, b, ha, hb, hsum⟩ => by x✝:∃ a b, 0 < a ∧ 0 < b ∧ 1 = a + ba:ℕb:ℕha:0 < ahb:0 < bhsum:1 = a + b⊢ False hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1 omega All goals completed! 🐙 hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1⟩ hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b}.ncard = 1
rw [hset, hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ {1}.ncard = 1 All goals completed! 🐙 Set.ncard_singleton hset:{x | 0 < x ∧ x ∈ ⊤ ∧ ¬∃ a b, 0 < a ∧ 0 < b ∧ a ∈ ⊤ ∧ b ∈ ⊤ ∧ x = a + b} = {1}⊢ 1 = 1 All goals completed! 🐙] All goals completed! 🐙end AddSubmonoid