TorchLean API

NN.Floats.IEEEExec.Exec32.Directed

Directed executable IEEE32 operations.

This file provides lower and upper rounding variants for arithmetic operations, forming the runtime side of the interval-enclosure story.

ceil(n / 2^shift) for naturals, implemented via shifts (used for directed rounding).

Instances For

    Directed rounding down (toward -∞) for a positive dyadic mant * 2^exp.

    Instances For

      Directed rounding up (toward +∞) for a positive dyadic mant * 2^exp.

      Instances For

        Directed rounding down (toward -∞) of an exact dyadic to float32.

        Instances For

          Directed rounding up (toward +∞) of an exact dyadic to float32.

          Instances For

            addDown x y is a float32 lower bound for the exact real sum (when finite).

            Instances For

              addUp x y is a float32 upper bound for the exact real sum (when finite).

              Instances For
                @[inline]

                subDown x y is a float32 lower bound for the exact real difference (when finite).

                Instances For
                  @[inline]

                  subUp x y is a float32 upper bound for the exact real difference (when finite).

                  Instances For

                    mulDown x y is a float32 lower bound for the exact real product (when finite).

                    Instances For

                      mulUp x y is a float32 upper bound for the exact real product (when finite).

                      Instances For

                        fmaDown x y z computes the exact value x * y + z and rounds once toward -∞.

                        This is a directed fused multiply-add: the product is not rounded before the addition. The special-value cases agree with fma; finite inputs are converted to exact dyadics, and each nonzero exact product-plus-sum is passed once to roundDyadicDown. Exact cancellation bypasses the generic rounder and returns the signed zero required by round-toward-negative.

                        Instances For

                          fmaUp x y z computes the exact value x * y + z and rounds once toward +∞.

                          As with fmaDown, no intermediate product rounding occurs. Keeping both operations in terms of the same exact dyadic expression makes their enclosure theorems share one semantic statement.

                          Instances For

                            Directed square root #

                            For a positive dyadic mant * 2^exp, parity normalization rewrites the radicand as mant' * 2^(2 * expHalf). After scaling mant' by an even power of two, Nat.sqrt gives the lower integer endpoint and its remainder tells us whether the upper endpoint is distinct. The resulting dyadics enclose the exact square root before they are rounded to binary32.

                            Dyadic lower and upper endpoints for a nonnegative square root.

                            Instances For

                              Compute both square-root endpoints from one parity normalization and integer square root.

                              Instances For

                                Square root rounded toward -∞; negative finite inputs produce NaN.

                                Instances For

                                  Square root rounded toward +∞; negative finite inputs produce NaN.

                                  Instances For

                                    Directed rounding for exact rationals (division-friendly) #

                                    For divDown/divUp we need outward rounding of an exact rational num/den to the float32 grid. Our dyadic-directed rounders (roundDyadicDown/roundDyadicUp) already have a clean soundness proof, so we reduce rational rounding to dyadic rounding by building a dyadic enclosure of num/den:

                                    We then apply roundDyadicDown/roundDyadicUp to these dyadics.

                                    This is sound (it produces outward-rounded endpoints), but it is not necessarily optimally tight; a larger ratApproxShift improves tightness at some computational cost.

                                    Number of extra bits used when turning num/den into a dyadic enclosure.

                                    Instances For

                                      ceil(num/den) for naturals, totalized (returns 0 when den = 0).

                                      Instances For

                                        Lower dyadic mantissa for num/den at scale 2^ratApproxShift.

                                        Instances For

                                          Upper dyadic mantissa for num/den at scale 2^ratApproxShift.

                                          Instances For

                                            Directed rounding down (toward -∞) for a rational ±(num/den) with den > 0.

                                            We do not attempt to be "correctly rounded" in the IEEE-754 sense; we only need a sound lower bound.

                                            Instances For

                                              Directed rounding up (toward +∞) for a rational ±(num/den) with den > 0.

                                              Instances For

                                                divDown x y is a float32 lower bound for the exact real quotient (when finite and y ≠ 0).

                                                Instances For

                                                  divUp x y is a float32 upper bound for the exact real quotient (when finite and y ≠ 0).

                                                  Instances For