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.1 - BigInt Coverage and Integral Embeddings

This documentation tracks the intended v0.3.1 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.1

  • BigInt is now part of the default exported numeric surface.
  • Integral remains the marker for integral semiring types.
  • Nat now exposes to_integral for exact embeddings from natural-number types into BigInt.
  • NatHomomorphism and IntegralHomomorphism provide target-side constructors for natural and integral source types.
  • 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

  • Nat::to_integral provides an exact embedding from Nat values into BigInt
  • NatHomomorphism::{from_uint, from_uint16, from_uint64} exposes target-side natural embeddings
  • IntegralHomomorphism::{from_int, from_int16, from_int64, from_bigint} exposes target-side integral embeddings
  • 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.12026-06-06release candidateAdds 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

#
Integral

pub(open) trait Integral : Semiring {
}

impl Integral for Int
impl Integral for Int16
impl Integral for Int64
impl Integral for UInt
impl Integral for UInt16
impl Integral for UInt64
impl Integral for BigInt

#
IntegralHomomorphism

pub(open) trait IntegralHomomorphism : NatHomomorphism {
fn from_int(Int) -> Self
fn from_int16(Int16) -> Self
fn from_int64(Int64) -> Self
fn from_bigint(
BigInt
) -> 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 {
fn to_integral(Self) ->
BigInt

}

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

#
NatHomomorphism

pub(open) trait NatHomomorphism {
fn from_uint(UInt) -> Self
fn from_uint16(UInt16) -> Self
fn from_uint64(UInt64) -> 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