Executable binary32 transcendental approximations.
The functions in this file provide deterministic exp, log, and related operations for the
IEEE32 executable model. Stronger libm-style correctness claims live outside this layer.
fixedScale as an Int.
Instances For
Fixed-point encoding of 1 at scale fixedScale (i.e. 2^fixedScale).
Instances For
Round an integer quotient num/den to the nearest integer, ties-to-even.
Assumes den > 0.
Instances For
Divide by 2^shift, rounding to nearest with ties-to-even.
Instances For
Shift by a power of two: multiply when k ≥ 0, divide when k < 0.
Division uses ties-to-even rounding.
Instances For
Fixed-point multiplication at scale fixedScale (ties-to-even).
Instances For
Fixed-point division at scale fixedScale (ties-to-even).
If a and b are fixed-point at scale fixedScale, the result is at the same scale.
Instances For
Divide by a natural number, rounding to nearest with ties-to-even.
Instances For
Convert a dyadic number to a signed fixed-point integer at scale fixedScale.
Instances For
Convert a signed fixed-point integer at scale fixedScale to a dyadic number.
Instances For
Fixed-point approximation to ln 2 at scale fixedScale.
Instances For
Fixed-point approximation to 1/ln 2 at scale fixedScale.
Instances For
Fixed-point Taylor coefficients (highest degree first) for 2^x on [-1/2, 1/2].
Instances For
Evaluate the fixed-point 2^x polynomial approximation using Horner’s method.
Instances For
Deterministic sin/cos #
Unlike exp/log, sin and cos are used by the runtime FFT layer (NN.Runtime.*.Fft) to build
twiddle factors. Delegating to the host Float implementation makes results platform-dependent.
We implement sin/cos purely inside Lean:
- scale the input down by a power of two so
|y| < 1/2, - approximate
sin yandcos yby exact Taylor partial sums (degree 13 / 12), - scale back up using
mapplications of the double-angle formulas.
This is deterministic and uses only the IEEE32Exec kernel ops (roundRatToIEEE32, add/mul/sub,
etc.). We do not claim correctly-rounded libm behavior; the goal is reproducible execution.
Instances For
Dyadic 1.
Instances For
Round the exact rational d / den to binary32, where d is an exact dyadic mant * 2^exp.
We package the dyadic exponent into a rational numerator/denominator and call roundRatToIEEE32.
Instances For
Taylor partial sums on |y| < 1/2 #
We encode the partial sums using a common factorial denominator so the coefficients are exact integers, not approximations.
For z = y^2:
Instances For
Instances For
Instances For
Instances For
Instances For
Public sin / cos #
We expose sin/cos as executable ops on IEEE32Exec using the deterministic implementation
above, together with standard IEEE special-case conventions.
Deterministic sin for IEEE32Exec.
Instances For
Deterministic cos for IEEE32Exec.