Repository navigation
1.2.0
·
19 commits
to master
since this release
FlameMath 1.2.0
New Functions
Language Improvements
Apply(f, list)— Splat a list as arguments to a function.Apply(Add, [1, 2, 3])→6Substitute(expr, symbol, value)— Substitute a symbol with a value in an expression.Substitute(x^2 + x, x, 3)→12Hold(expr)— Prevent evaluation of an expression, returning it unevaluated
Number Theory
GCD(a, b)/LCM(a, b)— Greatest common divisor and least common multipleIsPrime(n)— Primality testing via deterministic Miller-Rabin with 12 fixed bases; hybridly uses a global Sieve of Eratosthenes for small primesPrimesInRange(m, n)— Returns all primes in [m, n] using a segmented Sieve of EratosthenesPowerMod(base, exp, mod)— Modular exponentiation viaBigInteger.modPowBinomial(n, k)— Binomial coefficient using a multiplicative formula (avoids full factorials)Multinomial(n, k1, k2, ...)— Multinomial coefficientWieferichPrime(n)— Finds the smallest Wieferich prime up to nPrime(n)— Returns the n-th prime number using Meissel-Lehmer prime counting with binary search for large n, sieve for small n.Prime(4)→7
Inverse Trigonometric Functions
ArcSin(x)— Inverse sine with exact symbolic values for well-known angles (0, Pi/6, Pi/4, Pi/3, Pi/2)ArcCos(x)— Inverse cosine with exact symbolic values across [0, Pi], including negative argumentsArcTan(x)— Inverse tangent with exact symbolic values for 0, 1, Sqrt(3), 1/Sqrt(3)ArcTan2(y, x)— Two-argument (quadrant-aware) arctangent
Hyperbolic Functions
Sinh(x)— Hyperbolic sineCosh(x)— Hyperbolic cosineTanh(x)— Hyperbolic tangent
Numeric Utilities
Sign(n)— Returns the sign of an integer:-1,0, or1Clamp(n, low, hi)— Restricts a numeric value to a given range[low, hi]
List Operations
Join(list1, list2, ...)— Concatenate multiple lists into oneTake(list, n)— Return the firstnelements (positive) or last|n|elements (negative)Drop(list, n)— Remove the firstnelements (positive) or last|n|elements (negative)First(list)— Return the first element, orNullif emptyLast(list)— Return the last element, orNullif emptyCount(list, value)— Count occurrences of a value in a listTally(list)— Frequency count of elements, returning[[element, count], ...]pairs in first-occurrence order. Works with any element type including nested listsUnion(list1, list2, ...)— Set union across multiple lists, preserving first-occurrence orderIntersection(list1, list2, ...)— Set intersection across multiple listsFoldScan(f, start, list)— Cumulative fold (scan) over a list, returning all intermediate accumulator values.FoldScan(Add, 0, [1,2,3,4])→[0,1,3,6,10]
String Functions
StrHas(str, substring)— Tests whether a string contains a given substring. Case-sensitiveStrReplace(str, target, replacement)— Replaces all occurrences of a substring with a replacement string
Bug Fixes
- Flat functions not flattened when called via symbol alias — Built-in functions with the
isFlatattribute (e.g.,Add,Mul) were not being flattened when invoked indirectly through a symbol reference (e.g., passingAddtoFoldScan). This caused incorrect canonical ordering in the result, such asFoldScan(Add, 0, [a, b, c, d])producingc + a + binstead ofa + b + c
Improvements
Sqrt()simplifies radicals —Sqrtnow extracts the largest perfect-square factor from integer arguments and numeric factors in products.Sqrt(12)→2*√3,Sqrt(4*x^2)→2*√(x^2). Symbolic parts are left under the radical (no assumptions about variable signs)- Square root display —
Pow(n, (1/2))andSqrt(...)expressions now render with the√symbol instead of function-call notation Zip()generalized — Now accepts any number of lists (variadic), not just two.Zip([1,2], [3,4], [5,6])→[[1,3,5], [2,4,5]]Zip()bug fix — Fixed incorrect element indexing in the inner loop- Documentation reorganized — Function reference docs are now organized into category subfolders (math, list, ntheory, general, etc.)
- Mathematical functions return integers where applicable — Functions like
Sin(0)now return0instead of0.0 - Version tracking — Added
version.propertiesfor runtime version identification
FlameInt: Arbitrary-Precision Integer Migration
IntegerAtom has been migrated from long to FlameInt, a custom arbitrary-precision integer type using base-2^32 limb arrays. This removes the 64-bit ceiling on all integer arithmetic — functions like Binomial(100, 50), Factorial(50), and large Pow expressions now produce exact results instead of silently overflowing.
Arithmetic
- Addition, subtraction, multiplication — Schoolbook algorithms operating on
int[]magnitude arrays with unsigned limb arithmetic - Division (Knuth Algorithm D) — Multi-limb long division with normalization, replacing a previous repeated-subtraction implementation. O(m·n) per division
- Exponentiation (
FlameInt.pow) — Binary exponentiation (repeated squaring), replacingMath.pow/longcasts inPowFuncthat silently overflowed toLong.MAX_VALUE - Modular remainder —
mod()now extracts the remainder directly from the division algorithm instead of recomputing via separatedivide+multiply+subtract
Bug Fixes
- Knuth D unsigned comparison — The quotient refinement loop used signed
>whereLong.compareUnsignedwas needed, producing wrong results for large multi-limb divisions - Knuth D normalization overflow — Bits were lost during left-shift normalization; fixed by prepending a zero limb before shifting
leadingZeroscomputed popcount — The helper counted set bits instead of leading zeros; replaced withInteger.numberOfLeadingZeros
Internal
- Number theory utilities (
PrimeSieve,NumberTheoryUtils) added as shared infrastructure PrimeSievenow supports Meissel-Lehmer π(x) computation, cached prime list, and prefix count array for O(1) lookups- Function references compartmentalized into separate folders by category