TorchLean API

NN.Floats.IEEEExec.Exec32.Transcendentals

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.

Fixed-point scale (in bits) used by the integer-only exp/log approximations.

Instances For

    Fixed-point encoding of 1 at scale fixedScale (i.e. 2^fixedScale).

    Instances For

      Integer power of two: pow2Int k = 2^k as an Int.

      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 exp (no delegation to Float): range-reduced 2^(x/ln2) with a fixedpoint polynomial.

                                Instances For

                                  Deterministic log (no delegation to Float): normalize x = m*2^k and use an atanh-series for log m.

                                  Instances For

                                    Deterministic sinh (no delegation to Float): defined via exp.

                                    Instances For

                                      Deterministic cosh (no delegation to Float): defined via exp.

                                      Instances For

                                        Deterministic tanh (no delegation to Float): stable form tanh x = s*(1 - 2/(exp(2*|x|)+1)).

                                        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:

                                          1. scale the input down by a power of two so |y| < 1/2,
                                          2. approximate sin y and cos y by exact Taylor partial sums (degree 13 / 12),
                                          3. scale back up using m applications 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.

                                          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:

                                            Joint deterministic sin/cos computation for IEEE32Exec.

                                            Instances For

                                              Deterministic sin implementation (shared core via sinCos).

                                              Instances For

                                                Deterministic cos implementation (shared core via sinCos).

                                                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.

                                                    Instances For