TorchLean API

FloatLib.Numerics.Enclosure.Elementary.BinaryGridRuntime

Elementary enclosures evaluated on a binary grid #

Taylor polynomials and remainder bounds use integer interval arithmetic at precision fractional bits. Each multiplication and scalar division rounds outward on that grid. Argument reduction and scalar factors use exact rational arithmetic, and only the final endpoints are decoded.

The degree selects the same Taylor polynomial as the rational kernels in Elementary.Runtime. Containment holds at every degree and precision, including zero, so the precision and degree estimates below guide refinement and never affect soundness. Coarse grids can give wide bounds.

Long logarithm polynomials share a table of powers through rectangular splitting, as in Section 4 of Fredrik Johansson, Efficient implementation of elementary functions in the medium-precision range.

Add guard bits and a degree-dependent rounding allowance to a target grid width.

Instances For

    Choose a grid width relative to a nonzero result scale.

    The integer logarithms estimate the extra fractional bits needed for a small result. Consumers handle exact zero themselves. A higher degree also raises the rounding allowance.

    Instances For
      def FloatLib.Numerics.Enclosure.BinaryGrid.expPrecision (targetBits : ℕ) (x : ℚ) (degree : ℕ) (subtractOne : Bool := false) :

      Allow for repeated squaring and small exponential results when choosing a grid width.

      Subtracting one also needs enough fractional bits to retain a small input's contribution.

      Instances For

        Allow for cancellation near one and scaling by a large binary logarithm.

        Instances For

          Decode the two final coefficients as rational endpoints.

          Instances For

            Scale an interval by an exact rational, rounding the integer coefficients outward.

            The rational denominator is positive, so scalar division remains defined on every grid.

            Instances For

              Divide the coefficients by a natural scalar with outward rounding.

              Instances For
                @[inline]

                Integer floor and ceiling division. A zero divisor gives the zero interval.

                Instances For
                  @[inline]

                  Grid multiplication with two corner products when either factor is a point, in any order.

                  Instances For
                    @[csimp]

                    divideNat equals the integer floor and ceiling division that compiled code runs.

                    @[csimp]

                    Grid multiplication equals Internal.mul, which needs two products for a point factor.

                    Expand a midpoint interval using the upper endpoint of a radius enclosure.

                    Instances For

                      Exponential Horner steps, with every product and division rounded on the chosen grid.

                      Instances For

                        Odd logarithm terms evaluated by Horner steps in the square of the argument.

                        Instances For
                          @[specialize #[]]

                          Apply Horner steps from the highest index down, keeping the partial result in an accumulator.

                          Instances For

                            Exponential Horner evaluation with an accumulator and one shared grid coefficient for one.

                            Instances For

                              Odd logarithm Horner evaluation with an accumulator.

                              Instances For
                                @[csimp]

                                Exponential Horner evaluation equals the accumulator loop that compiled code runs.

                                @[csimp]

                                Odd logarithm Horner evaluation equals the accumulator loop that compiled code runs.

                                Evaluate the exponential remainder bound without forming an exact rational power.

                                Instances For

                                  Enclose the exponential of a small argument with its Taylor polynomial and remainder bound.

                                  Instances For

                                    Square n times, rounding outward after each square, to undo exponential range reduction.

                                    Instances For

                                      Balance Taylor work against extra squarings using the degree and requested grid width.

                                      The square-root estimate limits squaring work while the degree is small, and the quotient reduces it as refinement raises the degree. A small input already supplies some reduction without squaring.

                                      Instances For

                                        Enclose the exponential, with extra grid bits to cover the extra range-restoring squares.

                                        Instances For

                                          Extend a table with successive rounded powers, including its final power.

                                          Instances For

                                            Store the powers from zero through n, using one rounded multiplication per new power.

                                            Instances For

                                              Add one block of scalar-divided powers, from the highest index down.

                                              Instances For

                                                Sum of one block, by scalar division and grid addition alone.

                                                Instances For
                                                  def FloatLib.Numerics.Enclosure.BinaryGrid.LogPolynomial.blockHorner (precision : ℕ) (powers : Array (Interval ℤ)) (stride : Interval ℤ) (start blockSize blocks : ℕ) (tail : Interval ℤ) :

                                                  Apply the block Horner steps from the highest block down.

                                                  Instances For

                                                    Rectangular evaluation with a positive block size and an unpadded final partial block.

                                                    Instances For

                                                      Odd logarithm polynomial: Horner steps up to four terms, rectangular splitting above.

                                                      Instances For

                                                        Evaluate the odd logarithm remainder with a grid power and an exact scalar denominator.

                                                        Using 1 - x² before rounding avoids a zero-crossing grid divisor at low precision.

                                                        Instances For

                                                          Enclose log x with the odd terms of its transformed series.

                                                          Instances For

                                                            A logarithm series degree for a positive value whose truncation error is below about 2 ^ -bits.

                                                            For value = n / d in lowest terms the series runs in t = (n - d) / (n + d), so each pair of degrees gains log₂ (1 / t²) bits. The estimate uses the integer part of 1 / t².

                                                            Instances For

                                                              Enclose log value for a positive rational on the grid of precision fractional bits with the transformed series in (value - 1) / (value + 1), without the argument reduction of log. It suits values near one.

                                                              Instances For

                                                                Remove a power of two and restore its multiple of log 2, omitting a zero multiple.

                                                                Instances For

                                                                  Enclose the logarithm of a positive rational, inverting arguments below one before reduction.

                                                                  Instances For