@enumeratio/numerals
Numeral-system extensions for @cortex-js/compute-engine. compute-engine's IntegerDigits and FromDigits already do fixed radix, so this package adds no head for that case — it widens the base slot to accept a system value, the way Wolfram's IntegerDigits[n, MixedRadix[…]] does: FactorialNumerals, ZeckendorfNumerals, BalancedNumerals(b), NegativeNumerals(b), BijectiveNumerals(k), MixedRadixNumerals([…]), PrimorialNumerals, CombinatorialNumerals(k), ResidueNumerals([…]), AdicNumerals(b, prec?) and PositionalNumerals(b) are all just values passed where an integer base would go. An integer base still goes to the native handler, unchanged. Builds on @enumeratio/residues for the residue system and gcd.
AdicNumeral (singular) is a separate value head: the -adic number itself, with its own arithmetic (Add/Multiply/Negate/Divide/Power widened to carry it), infinite to the left rather than the right.
The old one-word-per-flavour names (Factoradic, Zeckendorf, BalancedRadix, Radix, …) still evaluate to their …Numerals spelling — see NUMERAL_ALIASES.
Usage
import { declareNumerals } from "@enumeratio/numerals";
import { declareAdic } from "@enumeratio/numerals"; // AdicNumeral alone, without the systems
declareNumerals(ce); // declares AdicNumeral too./src is exported for workspace packages needing the plain TypeScript.
IntegerDigits(42, AdicNumerals(10, 6)) // the 10-adic digits of 42, width 6
IntegerDigits(-3, BalancedNumerals(3)) // balanced ternary spells the sign in the digitsHeads
Numeral systems (values for the base slot)
Radix/PositionalNumerals— ordinary base , as a system valueBalancedNumerals/BalancedRadix— signless negatives, digitsNegativeNumerals/NegativeRadix— signless negatives over baseBijectiveNumerals/BijectiveRadix— digits , no zero (spreadsheet columns)FactorialNumerals— place holds at most (the Lehmer code)PrimorialNumerals— factoradic with primesCombinatorialNumerals/CombinatorialSystem— a strictly decreasing -tuple (subset unranking)ResidueNumerals/ResidueSystem— independent residues, no place values at allZeckendorfNumerals— Fibonacci place values, no two adjacent onesOstrowskiNumerals— digits over a continued fraction, generalises ZeckendorfAdicNumerals— fixed-width -adic digits, negatives are all nines
b-adic values
AdicNumeral— the -adic value, exact or truncated to a precisionAdicExpansion/AdicDigits— its digit stringAdicValuation/AdicUnitPart— the power of dividing it, and what's left after dividing it outAdicSqrt/HenselLift— square roots and Newton lifting in
Digits and strings
IntegerDigits/FromDigits— compute-engine's own heads, widened to take a system in the base slotRealDigits— digits of a rational, including the repeating partDigitCount/DigitSum/IntegerLength/IntegerReverse— per-digit statistics and reversalIntegerString/RomanNumeral— string spellingsNumberExpand/NumeralSystemShape/Fraction— expanding a number over a system, and describing a system's shape
See also
See Numeral systems for why a numeral system is a bijection between integers and digit strings, and a table of every system this package adds. See b-adic numbers for how AdicNumeral and AdicNumerals relate, and where they part ways off the non-negative integers.
Builds on @enumeratio/residues (residues) for ResidueNumerals and gcd. @enumeratio/number-theory (number-theory) depends on this package.
Pages
- Source:
packages/symbols/arithmetic/numerals - Depends on:
boxes,engine,residues,structures - In development, also:
config,manifest,utils