luna-generic

Algebraic traits and default numeric instances that define the generic foundation for LunaFlow math packages.

math
algebra
interface
moon add Luna-Flow/luna-generic@0.3.3
Download zip
Author
Version
0.3.3
License
Apache-2.0
Last updated
2 months ago
Downloads
5K
README

#Luna-Generic

General algebraic traits and default numeric instances for Luna projects.

#v0.3.3 - Normalize-Driven Homomorphism Cleanup

This documentation tracks the intended v0.3.3 release content.

#Package Positioning

  • luna-generic provides lightweight algebraic traits for additive, multiplicative, ring-like, field-like, and numeric behavior.
  • The package ships default instances for signed integers, unsigned integers, BigInt, Float, and Double.
  • Integral-to-target embeddings are now modeled explicitly through homomorphism traits instead of being mixed into Integral.

#What Defines v0.3.3

  • BigInt is now part of the default exported numeric surface.
  • Integral now provides normalize, which canonicalizes any integral value into BigInt.
  • NatHomomorphism and IntegralHomomorphism provide polymorphic target-side embeddings for natural and integral source types.
  • Integral::normalize is the canonical source-side entry point for both Integral and Nat.
  • Floating-point embeddings remain approximate and follow target floating-point precision limits.

#Public Surface

  • Traits: AddMonoid, MulMonoid, AddGroup, MulGroup, Semiring, Ring, Field, Integral, Nat, NatHomomorphism, IntegralHomomorphism, Num
  • Operations: One, Zero, Inverse, Conjugate
  • Default numeric types: Int, Int16, Int64, UInt, UInt16, UInt64, BigInt, Float, Double

#Integer Families

  • Nat covers pure unsigned integer types: UInt, UInt16, UInt64
  • Integral covers signed and unsigned integers plus BigInt: Int, Int16, Int64, UInt, UInt16, UInt64, BigInt
  • Byte is intentionally excluded from both traits
  • Unsigned integer instances stop at Semiring and do not implement AddGroup, Ring, or Num

#Embedding Guidance

  • Integral::normalize provides a canonical BigInt representation for any integral value
  • Nat sources reuse the same normalize(Self) -> BigInt path through trait inheritance
  • NatHomomorphism::from_nat embeds any Nat source via normalize
  • IntegralHomomorphism::from_integral embeds any Integral source via normalize
  • BigInt embeddings are exact
  • Float and Double embeddings are approximate and may round large values

#Documentation

Comprehensive API documentation is available at mooncakes.io.

We provide README-level documentation in multiple languages:

#Version History

VersionDateStatusNotes
0.3.32026-06-12release candidateRefactors homomorphism traits around polymorphic methods and unifies natural/integral embeddings through normalize
0.3.22026-06-06published on mooncakesAdds Integral::normalize as the canonical BigInt normalization entry point and aligns docs with the new integral embedding model
0.3.12026-06-06published on mooncakesAdds BigInt coverage, explicit integral embedding traits, and trilingual documentation refresh
0.3.02026-06-06previous release baselineEarlier generic algebraic trait surface before the current integral embedding redesign

#Development

Useful local commands:

moon check moon test

#Release Checklist

Before triggering the publish workflow:

  1. Confirm moon.mod contains the intended version.
  2. Confirm the README files match the exported package surface.
  3. Run moon check and moon test.
  4. Trigger publish-package after the release commit is pushed.

#
AddGroup

pub(open) trait AddGroup : AddMonoid + Neg + Sub {
}

impl AddGroup for Int
impl AddGroup for Int16
impl AddGroup for Int64
impl AddGroup for Float
impl AddGroup for Double
impl AddGroup for BigInt

#
AddMonoid

pub(open) trait AddMonoid : Add + Zero {
}

impl AddMonoid for Int
impl AddMonoid for Int16
impl AddMonoid for Int64
impl AddMonoid for UInt
impl AddMonoid for UInt16
impl AddMonoid for UInt64
impl AddMonoid for Float
impl AddMonoid for Double
impl AddMonoid for BigInt

#
Conjugate

pub(open) trait Conjugate {
fn conjugate(Self) -> Self
}

#
Field

pub(open) trait Field : Ring + Inverse + Div {
}

impl Field for Float
impl Field for Double

#
IntegralHomomorphism

pub(open) trait IntegralHomomorphism : NatHomomorphism {
fn[S : Integral + Semiring + AddMonoid + Add + Zero + MulMonoid + Mul + One] from_integral(value : S) -> Self
}

#
Inverse

pub(open) trait Inverse {
fn inv(Self) -> Self
}

impl Inverse for Float
impl Inverse for Double

#
MulGroup

pub(open) trait MulGroup : MulMonoid + Inverse + Div {
}

impl MulGroup for Float
impl MulGroup for Double

#
MulMonoid

pub(open) trait MulMonoid : Mul + One {
}

impl MulMonoid for Int
impl MulMonoid for Int16
impl MulMonoid for Int64
impl MulMonoid for UInt
impl MulMonoid for UInt16
impl MulMonoid for UInt64
impl MulMonoid for Float
impl MulMonoid for Double
impl MulMonoid for BigInt

#
Nat

pub(open) trait Nat : Integral {
}

impl Nat for UInt
impl Nat for UInt16
impl Nat for UInt64

#
NatHomomorphism

pub(open) trait NatHomomorphism {
fn[S : Nat + Integral + Semiring + AddMonoid + Add + Zero + MulMonoid + Mul + One] from_nat(value : S) -> Self
}

#
Num

pub(open) trait Num : Ring {
fn abs(Self) -> Self
fn signum(Self) -> Self
}

impl Num for Int
impl Num for Int16
impl Num for Int64
impl Num for Float
impl Num for Double

#
One

pub(open) trait One {
fn one() -> Self
}

impl One for Int
impl One for Int16
impl One for Int64
impl One for UInt
impl One for UInt16
impl One for UInt64
impl One for Float
impl One for Double

#
Ring

pub(open) trait Ring : Semiring + Neg + Sub {
}

impl Ring for Int
impl Ring for Int16
impl Ring for Int64
impl Ring for Float
impl Ring for Double
impl Ring for BigInt

#
Semiring

pub(open) trait Semiring : AddMonoid + MulMonoid {
}

impl Semiring for Int
impl Semiring for Int16
impl Semiring for Int64
impl Semiring for UInt
impl Semiring for UInt16
impl Semiring for UInt64
impl Semiring for Float
impl Semiring for Double
impl Semiring for BigInt

#
Zero

pub(open) trait Zero {
fn zero() -> Self
}

impl Zero for Int
impl Zero for Int16
impl Zero for Int64
impl Zero for UInt
impl Zero for UInt16
impl Zero for UInt64
impl Zero for Float
impl Zero for Double

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io