TorchLean API

NN.Floats.Interval.IEEEExec32ArbTrans

Arb-backed transcendentals for IEEE32Exec.Interval32 #

NN/Floats/Interval/IEEEExec32.lean provides an executable endpoint-interval type IEEE32Exec.Interval32 with outward-rounded endpoint arithmetic for add/sub/mul:

For transcendentals (exp/log/tanh/sqrt/...) the situation is different:

This file implements a pragmatic “sound route” for interval endpoints of transcendentals:

  1. Call the Arb oracle (NN/Floats/Arb) to obtain a rigorous real enclosure [L,U] ⊇ f([a,b]).
  2. Convert L,U : ℚ to float32 endpoints by rounding outward to the IEEE32Exec grid:
    • lower endpoint: round toward -∞ (using roundDyadicDown),
    • upper endpoint: round toward +∞ (using roundDyadicUp).

Trust boundary:

The result is useful when you want executable float32 endpoints and a clearly delineated source of transcendental soundness (Arb).

Render a rational in a format that Arb's parser accepts (e.g. -3/2, 5).

Instances For

    Exact rational view of float32 values #

    Convert an exact dyadic (-1)^sign * mant * 2^exp into an exact rational ().

    Instances For

      Exact rational value of a finite IEEE32Exec float.

      Returns none for NaN/Inf.

      Instances For

        Outward rounding from to IEEE32Exec #

        A rational view of 2^k.

        This is a small helper used to implement ratToDyadicDown/ratToDyadicUp.

        Instances For

          Approximate a rational q from below by a dyadic with denominator 2^k:

          d = floor(q * 2^k) * 2^{-k}.

          Instances For

            Approximate a rational q from above by a dyadic with denominator 2^k:

            d = ceil(q * 2^k) * 2^{-k}.

            Instances For

              Outward rounding down of a rational to the float32 grid (via a dyadic approximation).

              Instances For

                Outward rounding up of a rational to the float32 grid (via a dyadic approximation).

                Instances For

                  Arb-backed interval endpoints for transcendentals #

                  Decode a float endpoint as an exact rational, failing if the value is NaN/Inf.

                  This is used to feed exact endpoint strings into the Arb oracle.

                  Instances For

                    Call Arb on the real interval [X.lo, X.hi] (interpreted exactly as rationals) and return the oracle-provided rational enclosure bounds (L,U).

                    This is the only step that crosses the trust boundary.

                    Instances For
                      def TorchLean.Floats.IEEE754.IEEE32Exec.Interval32.arbUnary (func : String) (X : Interval32) (precBits digits dyadicBits : := 200) :

                      Compute an IEEE32Exec.Interval32 enclosure for a transcendental unary func by:

                      • getting a real enclosure [L,U] from Arb,
                      • rounding endpoints outward to the binary32 grid.

                      dyadicBits controls the internal dyadic approximation used when rounding rationals to float32; it can be increased if you want the outward rounding to be closer to the Arb bounds.

                      Instances For
                        @[inline]
                        def TorchLean.Floats.IEEE754.IEEE32Exec.Interval32.tanhArb (X : Interval32) (precBits digits dyadicBits : := 200) :

                        Arb-backed tanh enclosure for Interval32 (oracle + outward rounding to float32 endpoints).

                        Instances For
                          @[inline]
                          def TorchLean.Floats.IEEE754.IEEE32Exec.Interval32.expArb (X : Interval32) (precBits digits dyadicBits : := 200) :

                          Arb-backed exp enclosure for Interval32 (oracle + outward rounding to float32 endpoints).

                          Instances For
                            @[inline]
                            def TorchLean.Floats.IEEE754.IEEE32Exec.Interval32.logArb (X : Interval32) (precBits digits dyadicBits : := 200) :

                            Arb-backed log enclosure for Interval32 (oracle + outward rounding to float32 endpoints).

                            Instances For
                              @[inline]
                              def TorchLean.Floats.IEEE754.IEEE32Exec.Interval32.sqrtArb (X : Interval32) (precBits digits dyadicBits : := 200) :

                              Arb-backed sqrt enclosure for Interval32 (oracle + outward rounding to float32 endpoints).

                              Instances For