TorchLean API

NN.Floats.Interval.Quantized

Quantized interval arithmetic (rounding-on-, overflow-aware) #

This file provides a sound enclosure layer for real computations where interval endpoints are snapped outward to a chosen representable grid (a Flocq-style (β,fexp) format).

The main intended use is verification/bounding:

Compared to an executable IEEE kernel:

Overflow-awareness:

References:

A closed real interval [lo,hi].

Instances For

    Membership predicate: x ∈ I means I.lo ≤ x ≤ I.hi.

    Instances For
      @[implicit_reducible]

      Enable x ∈ I notation for real intervals.

      @[simp]

      Unfold membership: x ∈ I ↔ I.lo ≤ x ∧ x ≤ I.hi.

      Validity predicate: endpoints are ordered (lohi).

      Instances For
        @[inline]

        Degenerate interval [x,x].

        Instances For
          @[simp]

          Membership in a point interval is equality.

          @[inline]

          Interval negation: -[lo,hi] = [-hi,-lo].

          Instances For
            @[inline]

            Outward-rounded interval addition, using the provided endpoint Rounder.

            Instances For
              @[inline]

              Interval subtraction, implemented as A + (-B) so soundness reuses mem_add and mem_neg.

              Instances For

                Maximum absolute endpoint magnitude: max |lo| |hi|.

                This is a convenient (and very proof-stable) way to get a coarse enclosure for products.

                Instances For

                  If x ∈ I, then |x| ≤ absMax I.

                  Loose-but-sound multiplication enclosure.

                  For x ∈ A, y ∈ B we have |x*y| ≤ absMax A * absMax B, hence x*y ∈ [-M, M]. We then outward-round the endpoints via R.

                  This bound is conservative and serves as a generally applicable, proof-stable fallback. The executable IEEE interval layer provides the tighter four-corner multiplication theorem when that extra precision matters.

                  Instances For
                    theorem TorchLean.Floats.Interval.RInterval.mem_add {R : Rounder} {A B : RInterval} {x y : } (hx : x A) (hy : y B) :
                    x + y add R A B

                    Soundness of add: membership is preserved by real addition.

                    theorem TorchLean.Floats.Interval.RInterval.mem_sub {R : Rounder} {A B : RInterval} {x y : } (hx : x A) (hy : y B) :
                    x - y sub R A B

                    Soundness of sub: membership is preserved by real subtraction.

                    theorem TorchLean.Floats.Interval.RInterval.mem_mul {R : Rounder} {A B : RInterval} {x y : } (hx : x A) (hy : y B) :
                    x * y mul R A B

                    Soundness of the conservative mul enclosure: membership is preserved by real multiplication.

                    Outward-rounded interval enclosure for Real.exp, using monotonicity.

                    Instances For

                      Soundness of exp: membership is preserved by Real.exp.

                      Coarse tanh enclosure [-1, 1] with outward-rounded endpoints.

                      We use this instead of a tighter monotone bound because tanh is bounded everywhere and the uniform bound is often enough for verification pipelines.

                      Instances For

                        Interval tanh enclosure.

                        This deliberately returns the global codomain enclosure tanhBounds. It is a proof-stable fallback for pipelines that only need a sound bound; monotone interval refinements can live beside it without changing this simple contract.

                        Instances For

                          Soundness of tanh: membership is preserved by Real.tanh (via tanhBounds).

                          Outward-rounded interval enclosure for Real.sqrt (requires 0 ≤ lo).

                          Instances For
                            theorem TorchLean.Floats.Interval.RInterval.mem_sqrt {R : Rounder} {A : RInterval} {x : } (hA : 0 A.lo) (hx : x A) :
                            x sqrt R A

                            Soundness of sqrt: membership is preserved by Real.sqrt when A is nonnegative.

                            Outward-rounded interval enclosure for Real.log (requires 0 < lo).

                            Instances For
                              theorem TorchLean.Floats.Interval.RInterval.mem_log {R : Rounder} {A : RInterval} {x : } (hA : 0 < A.lo) (hx : x A) :

                              Soundness of log: membership is preserved by Real.log on positive intervals.

                              Extended-real intervals (for division by an interval containing 0) #

                              An EReal interval [lo,hi].

                              We use this for operations like division where a single interval may need to represent unbounded results (-∞/+∞) in a sound-but-coarse way.

                              Instances For

                                Membership predicate: x ∈ I means I.lo ≤ x ≤ I.hi in EReal.

                                Instances For
                                  @[implicit_reducible]

                                  Enable x ∈ I notation for EReal intervals.

                                  @[simp]

                                  Unfold membership: x ∈ I ↔ I.lo ≤ x ∧ x ≤ I.hi.

                                  Top interval [-∞,+∞] (the most conservative enclosure).

                                  Instances For
                                    @[simp]

                                    Every value lies in top = [-∞,+∞].

                                    @[inline]

                                    Embed a real interval into an extended-real interval.

                                    Instances For
                                      @[simp]

                                      Membership in ofRInterval is the same as membership in the underlying real interval.

                                      This is a small simp lemma that helps bridge between -level and EReal-level enclosures.

                                      Division with overflow-awareness.

                                      If the denominator interval contains 0, the result is unbounded ([-∞,+∞]). Otherwise we return a loose enclosure using absolute-value bounds.

                                      Outward-rounded interval division as an EReal enclosure.

                                      If the denominator interval contains 0, we return EInterval.top = [-∞,+∞]. Otherwise we use a coarse-but-sound absolute-value bound and outward-round the endpoints with R.

                                      Instances For
                                        theorem TorchLean.Floats.Interval.RInterval.mem_div_of_nozero {R : Rounder} {A B : RInterval} {x y : } (hx : x A) (hy : y B) (h0 : ¬(B.lo 0 0 B.hi)) :
                                        ↑(x / y) div R A B

                                        Soundness of div in the nonzero-denominator case (0 ∉ B).

                                        Under the hypothesis ¬ (B.lo ≤ 0 ∧ 0 ≤ B.hi), the constructed EInterval contains the true real quotient x/y (as an EReal).