TorchLean API

FloatLib.Floats.Interval.Quantized

Quantized real intervals and unbounded division enclosures #

Intervals are propagated over or EReal, then their endpoints are snapped outward to a chosen representable grid, a Flocq-style $(\beta,\mathtt{fexp})$ format.

The usual workflow is:

The layer is meant for real-valued enclosure proofs, not bit-level IEEE execution. It therefore has no NaN payloads, signed-zero rules, or status flags.

Division returns an EReal interval so that a denominator interval containing zero can be enclosed by $[-\infty,+\infty]$.

References:

A closed real interval $[\mathtt{lo},\mathtt{hi}]$, empty when hi < lo.

  • lo :

    Lower endpoint.

  • hi :

    Upper endpoint.

Instances For

    Membership predicate: $x\in I$ means $I.\mathtt{lo}\le x\le I.\mathtt{hi}$.

    Instances For
      @[instance_reducible]

      Enable $x\in I$ notation for real intervals.

      @[simp]

      Unfold membership: $x\in I\iff I.\mathtt{lo}\le x\land x\le I.\mathtt{hi}$.

      @[inline]

      Degenerate interval $[x,x]$.

      Instances For

        Membership in a point interval is equality.

        @[inline]

        Interval negation: $-[\mathtt{lo},\mathtt{hi}]=[-\mathtt{hi},-\mathtt{lo}]$.

        Instances For
          @[inline]

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

          Instances For
            @[inline]

            Outward-rounded interval subtraction, implemented as $A+(-B)$.

            Instances For

              Maximum absolute endpoint magnitude: $\max(|\mathtt{lo}|,|\mathtt{hi}|)$.

              For a member of the interval, this bounds its absolute value. It is useful for even functions such as Real.cosh, whose maximum over an interval occurs at an endpoint of largest magnitude.

              Instances For

                If $x\in I$, then $|x|\le\operatorname{absMax}(I)$.

                Outward-rounded multiplication using the four products of the endpoint pairs.

                Instances For
                  theorem FloatLib.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 FloatLib.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 FloatLib.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 mul: every product of members lies between the rounded corner bounds.

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

                  Instances For

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

                    Outward-rounded interval enclosure for the monotone function Real.tanh.

                    Instances For

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

                      Outward-rounded interval enclosure for Real.sqrt; informative when $0\le\mathtt{lo}$.

                      Instances For
                        theorem FloatLib.Floats.Interval.RInterval.mem_sqrt {R : Rounder} {A : RInterval} {x : } (hx : x A) :
                        x sqrt R A

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

                        Real.sqrt is monotone on all of (it sends every nonpositive input to 0), so no sign hypothesis on A is needed; the nonnegativity remark on sqrt only describes when the enclosure is informative.

                        Outward-rounded interval enclosure for Real.log (requires $0<\mathtt{lo}$).

                        Instances For
                          theorem FloatLib.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.

                          • lo : EReal

                            Lower endpoint.

                          • hi : EReal

                            Upper endpoint.

                          Instances For

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

                            Instances For
                              @[instance_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

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

                                @[inline]

                                Embed a real interval into an extended-real interval.

                                Instances For

                                  Embedding an interval into EReal preserves membership of real values.

                                  Division with possibly unbounded results.

                                  If the denominator interval contains 0, the enclosure is [-∞,+∞]. Otherwise the quotient is enclosed by the four endpoint quotients.

                                  Outward-rounded interval division as an EReal enclosure.

                                  If the denominator interval contains 0, we return EInterval.top = [-∞,+∞]. Otherwise we outward-round the minimum and maximum of the four endpoint quotients.

                                  Instances For
                                    theorem FloatLib.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).

                                    theorem FloatLib.Floats.Interval.RInterval.mem_div {R : Rounder} {A B : RInterval} {x y : } (hx : x A) (hy : y B) :
                                    ↑(x / y) div R A B

                                    Soundness of div without any hypothesis on the denominator interval.

                                    When B contains zero the result is EInterval.top, which contains everything; otherwise this is mem_div_of_nozero. Division by zero itself is Lean's totalized x / 0 = 0, which the top interval also contains.