Documentation

Interval.Floating.Basic

Floating point arithmetic #

The floating point number ⟨n,s⟩ represents n * 2^(s - 2^63), where n : Int64, s : UInt64.

Floating basics #

structure Floating.Valid (n : Int64) (s : UInt64) :

Validity of a Floating as a single type

Instances For
    @[unbox]
    structure Floating :

    Floating point number

    • n : Int64

      Unscaled value

    • s : UInt64

      Binary exponent + 2^63

    • v : Valid self.n self.s

      We're valid and normalized

    Instances For
      def instDecidableEqFloating.decEq (x✝ x✝¹ : Floating) :
      Decidable (x✝ = x✝¹)
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Floating.zero_same (x : Floating) :
        x.n = 0x.s = 0
        theorem Floating.norm (x : Floating) :
        x.n 0x.n Int64.minValuex.s 02 ^ 62 x.n.uabs
        def Floating.valid (n : Int64) (s : UInt64) :

        Computational version of Floating.Valid

        Equations
        Instances For

          Valid is decidable

          Equations
          Equations
          theorem Floating.beq_def {x y : Floating} :
          (x == y) = (x.n == y.n && x.s == y.s)
          theorem Floating.ext_iff {x y : Floating} :
          x = y x.n = y.n x.s = y.s

          Standard floating point nan

          Equations
          noncomputable def Floating.val (x : Floating) :

          The that a Floating represents, if it's not nan

          Equations
          Instances For

            The that a Floating represents, if it's not nan

            Equations
            Instances For

              Floating approximates

              Equations

              1 : Floating

              Equations
              @[simp]
              theorem Floating.n_zero :
              n 0 = 0
              @[simp]
              theorem Floating.s_zero :
              s 0 = 0
              @[simp]
              theorem Floating.n_one :
              n 1 = 2 ^ 62
              @[simp]
              theorem Floating.s_one :
              s 1 = 2 ^ 63 - 62
              @[simp]
              theorem Floating.val_zero :
              val 0 = 0

              0 = 0

              @[simp]

              0 ≠ nan

              @[simp]

              nan ≠ 0

              @[simp]

              1 ≠ nan

              @[simp]

              nan ≠ 1

              @[simp]
              theorem Floating.approx_zero_iff {a : } :
              approx 0 a a = 0

              0 is just zero

              @[simp]
              theorem Floating.val_one :
              val 1 = 1

              1 = 1

              theorem Floating.val_nan :
              nan.val = -2 ^ 63 * 2 ^ (2 ^ 63 - 1)
              @[simp]
              theorem Floating.approx_eq_singleton {a : } {x : Floating} (n : x nan) :
              approx x a x.val = a

              If we're not nan, approx is a singleton

              @[simp]

              If we're not nan, x.n ≠ .min

              theorem Floating.n_ne_zero {x : Floating} (n : x 0) :
              x.n 0

              If we're not zero, x.n ≠ 0

              theorem Floating.n_ne_zero' {x : Floating} (n : x.s 0) :
              x.n 0

              If x.s ≠ 0, x.n ≠ 0

              theorem Floating.n_eq_zero_iff {x : Floating} :
              x.n = 0 x = 0

              x.n = 0 exactly at 0

              theorem Floating.norm' {x : Floating} (x0 : x 0) (s0 : x.s.toNat 0) :
              2 ^ 62 x.n.uabs.toNat

              More user friendly version of x.norm

              theorem Floating.val_eq_zero {x : Floating} :
              x.val = 0 x = 0

              Only 0 has zero val

              theorem Floating.val_ne_zero {x : Floating} :
              x.val 0 x 0

              Only 0 has zero val

              @[simp]
              theorem Floating.coe_valq {x : Floating} :
              x.valq = x.val

              valq = val

              Simplification lemmas used elsewhere #

              This should really be cleaned up

              @[simp]
              theorem Floating.u62 :
              @[simp]
              theorem Floating.u64 :
              @[simp]
              theorem Floating.u65 :
              @[simp]
              theorem Floating.u126 :
              UInt64.toNat 126 = 126
              @[simp]
              theorem Floating.u127 :
              UInt64.toNat 127 = 127
              @[simp]
              theorem Floating.up62 :
              (2 ^ 62).toNat = 2 ^ 62
              @[simp]
              theorem Floating.up63 :
              (2 ^ 63).toNat = 2 ^ 63
              @[simp]
              theorem Floating.rounds_iff {a : } {x : Floating} {up : Bool} :
              Rounds x a up x nanif up = true then a x.val else x.val a
              theorem Floating.rounds_of_ne_nan {a : } {x : Floating} {up : Bool} (h : x nanif up = true then a x.val else x.val a) :
              Rounds x a up

              Remove a nan possibility from a rounding statement

              theorem Floating.val_of_nonneg {x : Floating} (x0 : 0 x.val) :
              x.val = x.n.toUInt64.toNat * 2 ^ (x.s.toNat - 2 ^ 63)

              val if we're nonnegative

              The smallest normalized value #

              @[irreducible]

              The smallest normalized floating point value

              Instances For
                @[simp]
                theorem Floating.val_min_norm :
                min_norm.val = 2 ^ (62 - 2 ^ 63)

                Conversion to Float #

                @[irreducible]

                Approximate Floating by a Float

                Equations
                Instances For
                  @[irreducible]
                  def Floating.decimal (x : Floating) (prec : ) (up : Bool) :

                  Convert to Decimal with a given precision and rounding. Ignores nan and takes abs.

                  Equations
                  Instances For
                    theorem Floating.decimal_le (x : Floating) (prec : ) :
                    (x.decimal prec false).val x.val

                    decimal rounds down if desired

                    theorem Floating.le_decimal (x : Floating) (prec : ) :
                    x.val (x.decimal prec true).val

                    decimal rounds up if desired

                    We print Fixed s as an approximate floating point number

                    Equations
                    • One or more equations did not get rendered due to their size.

                    Print raw representation of a Floating

                    Equations