luna-generic
This manual documents the intended v0.4.0 release of Luna-Flow/luna-generic.
Overview
luna-generic provides general algebraic traits and default numeric instances for Luna projects.
The current release candidate centers on three changes:
FromNatandFromIntegerdescribe the unique homomorphisms out of ℕ and ℤ as target-side traits.Integralis ℤ or a quotient ℤ/2^k, andnormalizemust be a section of its canonical map.lift_toandSectionkeep the choice of a representative apart from homomorphisms.
Install
moon add Luna-Flow/luna-generic@0.4.0
Then import "Luna-Flow/luna-generic" in your moon.pkg. The package needs
the MoonBit toolchain 0.10 or later (moonc ≥ 0.10).
Pages
The repository is one MoonBit package at src, documented as core. Its
certificate subsystem, Hom and Section, has its own pages as hom.
| Part | Tutorial | API | Design |
|---|---|---|---|
core: traits, conversions, instances | tutorial | API | design |
hom: homomorphisms and sections | tutorial | API | design |
Exported traits
AddMonoid,MulMonoidAddGroup,MulGroupSemiring,Ring,Field(commutative: )FromNat,FromIntegerIntegral,NatNum- Deprecated:
NatHomomorphism,IntegralHomomorphism
Exported operations and default types
- Operations:
One,Zero,Inverse,Conjugate - Default numeric types:
Int,Int16,Int64,UInt,UInt16,UInt64,BigInt,Float,Double
Integer model
Integralcovers signed integers, unsigned integers, andBigIntNatcovers the integral types with non-negative representatives:UInt,UInt16, andUInt64- Fixed-width integers are ℤ/2^k;
FromInteger::from_integerreduces modulo 2^k Integral::normalizepicks the representative of a value as aBigInt, andfrom_integer(normalize(x)) == x- Unsigned integer instances stop at
Semiring
Conversions
FromInteger::from_integeris the canonical map out of ℤ: exact forBigInt, modular for fixed-width integers, rounded forFloatandDoublelift_to(x)lifts to the representative and maps it into the target; it is a function, not a homomorphismNatHomomorphism::from_natandIntegralHomomorphism::from_integralare deprecated in favour ofFromNat,FromIntegerandlift_to
Generalized homomorphisms
Hom[S, A, B]: a certificate for maps preserving the signatureS, built only throughHom::postulate(which creates a proof obligation), the canonical mapHom::from_integer, or inference rulesSection[S, Q, A]: a certificate that a lift picks one representative per class of a quotient;Section::of_integralis the canonical one for integral types- Signature tags:
AddMonoidSig,MulMonoidSig,AddGroupSig,SemiringSig,RingSig - Algebra dictionaries
Algebra[S, A], operationsOp[A], the product typeProd[A, B]and reduct witnessesReduct[S, T] Hom::check/Hom::check_bytest the homomorphism laws on samples with strict, lax or approximate strength- See the hom API, tutorial and design
Where to read next
The core tutorial writes small generic algorithms against these traits. The core API lists every exported trait and instance, and the core design explains why the hierarchy and the conversions are shaped this way.
- New to the package: read the core tutorial, then the hom tutorial.
- Using it in a library: keep the core API and the hom API at hand; each trait lists the laws an instance must satisfy.
- Contributing: read both design pages, core and hom, before changing a trait or adding an inference rule.
Validation
Recommended release checks:
moon check
moon test