Documentation

LeanPool.Flean.FloatRep

Floating-Point Representations #

This module defines FloatRep, a sign/exponent/mantissa representation of floating-point numbers parameterized by a FloatCfg, together with its rational interpretation coeQ, negation, validity predicates, and an ordering floatrepLe proved equivalent to the order on the underlying rationals.

structure FloatRep (α : FloatCfg) :

A sign/exponent/mantissa representation of a (normal) floating-point number in the format α.

  • s : Bool

    The sign bit (true for negative).

  • e :

    The exponent.

  • m :

    The mantissa (an offset into [1, 2)).

Instances For
    @[implicit_reducible]
    Equations
    • One or more equations did not get rendered due to their size.
    def FloatRep.decEq {C : FloatCfg} (f1 f2 : FloatRep C) :
    Decidable (f1 = f2)

    Decidable equality on FloatRep.

    Equations
    Instances For

      A representation has a valid mantissa when it is below the precision.

      Equations
      Instances For
        def coeQ {C : FloatCfg} :

        The rational value represented by a FloatRep.

        Equations
        Instances For
          theorem coe_q_false_pos {C : FloatCfg} {e : } {m : } :
          0 < coeQ { s := false, e := e, m := m }

          Negate a representation by flipping its sign bit.

          Equations
          • { s := s, e := e, m := m }.neg = { s := !s, e := e, m := m }
          Instances For
            theorem coe_q_of_neg {C : FloatCfg} (f : FloatRep C) :
            theorem neg_false {C : FloatCfg} (e : ) (m : ) :
            { s := true, e := e, m := m } = { s := false, e := e, m := m }.neg
            theorem neg_true {C : FloatCfg} (e : ) (m : ) :
            { s := false, e := e, m := m } = { s := true, e := e, m := m }.neg
            theorem coe_q_true_neg {C : FloatCfg} {e : } {m : } :
            coeQ { s := true, e := e, m := m } < 0
            theorem coe_q_nezero {C : FloatCfg} {f : FloatRep C} :
            coeQ f 0
            theorem floatrep_of_false₁ {C : FloatCfg} (P : FloatRep CProp) (h1 : ∀ (f : FloatRep C), P f.negP f) (h2 : ∀ (e : ) (m : ), P { s := false, e := e, m := m }) (f : FloatRep C) :
            P f
            theorem floatrep_of_false₂ {C : FloatCfg} (P : FloatRep CFloatRep CProp) (h1 : ∀ (f1 f2 : FloatRep C), P f1.neg f2P f1 f2) (h2 : ∀ (f1 f2 : FloatRep C), P f1 f2.negP f1 f2) (h3 : ∀ (e e' : ) (m m' : ), P { s := false, e := e, m := m } { s := false, e := e', m := m' }) (f1 f2 : FloatRep C) :
            P f1 f2
            theorem coe_q_of_Cprec {C : FloatCfg} (b : Bool) (e : ) :
            coeQ { s := b, e := e, m := C.prec } = (if b = true then -1 else 1) * 2 ^ (e + 1)

            A representation has a valid exponent when it lies in [emin, emax].

            Equations
            Instances For
              theorem floatrep_e_le_of_coe_q {C : FloatCfg} (f1 f2 : FloatRep C) (vm2 : f2.validM) (h : |coeQ f1| |coeQ f2|) :
              f1.e f2.e
              theorem max_mantissa_q (C : FloatCfg) :
              1 2 - 1 / C.prec 2 - 1 / C.prec < 2
              theorem normal_range {C : FloatCfg} (f : FloatRep C) (ve : f.validE) (vm : f.validM) :
              theorem normal_range' {C : FloatCfg} (m : ) (e : ) (vm : m < C.prec) (ve2 : e C.emax) :
              |(m / C.prec + 1) * 2 ^ e| (2 - 1 / C.prec) * 2 ^ C.emax

              The largest finite rational representable in the format C.

              Equations
              Instances For

                The representation of the largest finite float of the format C.

                Equations
                Instances For
                  def floatrepLePos {C : FloatCfg} (f1 f2 : FloatRep C) :

                  Ordering on positive representations: larger exponent, or equal exponent and larger-or-equal mantissa.

                  Equations
                  Instances For
                    def floatrepLePos' {C : FloatCfg} (f1 f2 : FloatRep C) :

                    An equivalent formulation of floatrepLePos as a conjunction.

                    Equations
                    Instances For
                      theorem floatrep_le_pos_coe_q {C : FloatCfg} (f1 f2 : FloatRep C) (vm1 : f1.m C.prec) :
                      floatrepLePos f1 f2|coeQ f1| |coeQ f2|
                      theorem coe_q_le_floatrep_pos {C : FloatCfg} (f1 f2 : FloatRep C) (vm2 : f2.validM) :
                      |coeQ f1| |coeQ f2|floatrepLePos f1 f2
                      theorem floatrep_le_pos_iff_coe_q {C : FloatCfg} (f1 f2 : FloatRep C) (vm1 : f1.m C.prec) (vm2 : f2.validM) :
                      def floatrepLe {C : FloatCfg} (f1 f2 : FloatRep C) :

                      The full ordering on representations, accounting for signs.

                      Equations
                      Instances For
                        theorem floatrep_le_iff_coe_q_le {C : FloatCfg} (f1 f2 : FloatRep C) (vm1 : f1.validM) (vm2 : f2.validM) :
                        floatrepLe f1 f2 coeQ f1 coeQ f2