Skip to content

IntegralSemiring proposal #2559

Open
Open
@mechvel

Description

@mechvel

Matthew Daggitt wrote on lib-2.2-rc1
on January 4, 2025

product≢0 : All NonZero ns → NonZero (product ns)
while I agree that it would be good to develop the theory in terms of an
appropriate algebraic structure, unfortunately the library is not
currently set up to do so. We would need someone to be motivated to make
those contributions, but regardless those changes would also not make it
into v2.2.

The --attached archive-- contains the .agda files that set up lib-2.2 to do so,
which makes it lib-2.2-next.
It is set in the standard library style.
It consists of the following files.

Algebra-Definitions.agda
to be merged to Algebra/Definitions.agda of lib-2.2.
It defines the property NoZeroDivisor
zero _∙_ = {x y : A} → (x ∙ y) ≈ zero → x ≈ zero ⊎ y ≈ zero

Algebra-Properties-Monoid.agda
to be set as Algebra/Properties/Monoid.agda.
It defines

Π₁ : C → List C → C    -- product of a nonempty list of elements,
Π : List C → C         -- product of a list of elements.
It proves
Π[x] : ∀ x → Π (x ∷ []) ≈ x

Algebra-Structures.agda
to be merged to Algebra/Structures.agda.
It defines

record IsIntegralSemiring (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
  field
    isSemiring    : IsSemiring + * 0# 1#
    0≉1           : ¬ 0# ≈ 1#
    noZeroDivisor : NoZeroDivisor 0# *

  open IsSemiring isSemiring public

Algebra-Bundles.agda
to merge to Algebra/Bundles.agda.
It defines

record IntegralSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
  ...
  isIntegralSemiring : IsIntegralSemiring _≈_ _+_ _*_ 0# 1#

Algebra-Properties-Semiring-Integral.agda
to set as Algebra/Properties/Semiring/Integral.agda.
It proves

nonzero*nonzero :  ∀ {x y} → x ≉ 0# → y ≉ 0# → (x * y) ≉ 0#
nonzero*nonzero {x} {y} x≉0 y≉0 xy≈0 with noZeroDivisor xy≈0
... | inj₁ x≈0 = x≉0 x≈0
... | inj₂ y≈0 = y≉0 y≈0

Π≉0 : {xs : List Carrier} → All (_≉ 0#) xs → Π xs ≉ 0#
Π≉0 {_}      []           = 1≉0
Π≉0 {x ∷ xs} (x≉0 ∷ xs≉0) = nonzero*nonzero x≉0 (Π≉0 xs≉0)

Data-Nat-Properties.agda
to be merged to Data/Nat/Properties.agda.
It proves

+-*-isIntegralSemiring : IsIntegralSemiring _+_ _*_ 0 1
+-*-isIntegralSemiring = record
  { isSemiring    = +-*-isSemiring
  ; 0≉1           = λ()
  ; noZeroDivisor = λ m {n} → m*n≡0⇒m≡0∨n≡0 m {n}
  }

But this latter instance is not type-checked, I do not know why, so far.
After it is fixed, it will be added there

integralSemiring : IntegralSemiring _ _

for .

If all this is accepted and merged, it will be easy to add

  1. IntegralRing, IntegralDomain to Algebra.Bundles,
  2. the instance of IntegralDomain to Integer.Properties,
  3. several more proofs for the fnction Π.

onIntegralSemiring.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions