Documentation

LeanPool.Flean.Basic

Floating-Point Numbers #

This module assembles the full Flean.Float type (combining normal and subnormal representations with infinities and NaN), the conversions toFloat and toRat between rationals and floats, and the round-trip and rounding-error correctness results such as to_float_to_rat.

def roundsub {C : FloatCfg} [R : Rounding] (q : ) :

Round a rational to a subnormal representation using the mode in scope.

Equations
Instances For
    inductive Flean.Float (C : FloatCfg) :

    A floating-point number of the format C: a signed infinity, NaN, a valid normal representation, or a valid subnormal representation.

    Instances For
      def toFloat {C : FloatCfg} [R : Rounding] (q : ) :

      Round a rational to the nearest representable float under the mode in scope.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def toRat {C : FloatCfg} :

        The exact rational value of a float (0 for infinities and NaN).

        Equations
        Instances For

          Whether a float is finite (not an infinity or NaN).

          Equations
          Instances For

            Whether a float is (a) zero.

            Equations
            Instances For
              theorem subnormal_range {C : FloatCfg} (f : SubnormRep C) (vm : f.m < C.prec) (ne_zero : f.nonzero) :

              The largest finite float of the format C.

              Equations
              Instances For
                theorem log_lt_emax_of_max_float {C : FloatCfg} {q : } (q_nonneg : q 0) (h : |q| maxFloatQ C) :
                theorem to_float_to_rat {C : FloatCfg} [R : Rounding] (f : Flean.Float C) (finite : f.IsFinite) (nonzero : ¬f.IsZero) :
                theorem coe_q_emin {C : FloatCfg} :
                coeQ { s := false, e := C.emin, m := 0 } = 2 ^ C.emin
                theorem coe_q_neg_emin {C : FloatCfg} :
                coeQ { s := true, e := C.emin, m := 0 } = -2 ^ C.emin
                theorem roundsub_emin {C : FloatCfg} [R : Rounding] :
                roundsub (2 ^ C.emin) = { s := false, m := C.prec }
                theorem roundsub_neg_emin {C : FloatCfg} [R : Rounding] :
                roundsub (-2 ^ C.emin) = { s := true, m := C.prec }
                theorem roundrep_emin {C : FloatCfg} [R : Rounding] :
                roundRep (2 ^ C.emin) = { s := false, e := C.emin, m := 0 }
                theorem roundrep_neg_emin {C : FloatCfg} [R : Rounding] :
                roundRep (-2 ^ C.emin) = { s := true, e := C.emin, m := 0 }
                def Flean.Float.neg {C : FloatCfg} :
                Float CFloat C

                Negate a float by flipping the sign of each case.

                Equations
                Instances For
                  theorem to_float_neg {C : FloatCfg} (f : Flean.Float C) (h : f.IsFinite) :
                  theorem float_le_float_of {C : FloatCfg} [R : Rounding] (q1 q2 : ) (h1 : (toFloat q1).IsFinite) (h2 : (toFloat q2).IsFinite) (h : q1 q2) :

                  Round a rational toward negative infinity to a float.

                  Equations
                  Instances For

                    Round a rational toward positive infinity to a float.

                    Equations
                    Instances For

                      Round a rational to the nearest float (ties to even).

                      Equations
                      Instances For
                        theorem le_float_up {C : FloatCfg} (q : ) (h : (toFloatUp q).IsFinite) :
                        theorem to_float_boundary {C : FloatCfg} (R : Rounding) {q : } (h : |q| = 2 ^ C.emin) :
                        theorem float_up_minus_down {C : FloatCfg} (q : ) (h : (toFloatDown q).IsFinite) (h' : (toFloatUp q).IsFinite) :
                        toRat (toFloatUp q) - toRat (toFloatDown q) max (2 ^ C.emin / C.prec) (2 ^ Int.log 2 |q| / C.prec)
                        theorem float_error_old {C : FloatCfg} [R : Rounding] (q : ) (h : (toFloatDown q).IsFinite) (h' : (toFloatUp q).IsFinite) :
                        |toRat (toFloat q) - q| max (2 ^ C.emin / C.prec) (2 ^ Int.log 2 |q| / C.prec)
                        theorem float_error {C : FloatCfg} [R : Rounding] (q : ) (h : (toFloat q).IsFinite) :
                        |toRat (toFloat q) - q| max (2 ^ C.emin / C.prec) (2 ^ Int.log 2 |q| / C.prec)
                        theorem to_float_in_range {C : FloatCfg} [R : Rounding] {q : } (h : |q| maxFloatQ C) :
                        theorem float_error' {C : FloatCfg} [R : Rounding] (q : ) (h : |q| maxFloatQ C) :
                        |toRat (toFloat q) - q| max (2 ^ C.emin / C.prec) (2 ^ Int.log 2 |q| / C.prec)
                        theorem float_nearest_error {C : FloatCfg} (q : ) (h : (toFloatNearest q).IsFinite) :
                        |q - toRat (toFloatNearest q)| max (2 ^ (Int.log 2 |q| - 1) / C.prec) (2 ^ (C.emin - 1) / C.prec)