Documentation

Interval.Floating.Conversion

Conversion from , , , Float to Floating #

Normalization given n ∈ [2^62, 2^63] #

A normalized n, s pair ready for conversion to Floating

Instances For
    noncomputable def Floating.Convert.val (x : Convert) :
    Equations
    Instances For
      theorem Floating.Convert.n_mod (x : Convert) :
      x.n % 2 ^ 64 = x.n
      @[irreducible]

      Build a Floating out of n * 2^(s - 2^63), rounding if required

      Equations
      Instances For
        theorem Floating.valid_convert_tweak :
        2 ^ 62 Set.Ico (2 ^ 62) (2 ^ 63)
        @[irreducible]
        def Floating.convert_tweak (n : ) (s : ) (norm : n Set.Icc (2 ^ 62) (2 ^ 63)) :

        Build a Floating out of n * 2^(s - 2^63), rounding if required

        Equations
        Instances For
          theorem Floating.val_convert_tweak (n : ) (s : ) (norm : n Set.Icc (2 ^ 62) (2 ^ 63)) :
          (convert_tweak n s norm).val = n * 2 ^ (s - 2 ^ 63)

          convert_tweak is correct

          theorem Floating.approx_convert {a : } {n : } {s : } {norm : n Set.Icc (2 ^ 62) (2 ^ 63)} {up : Bool} (an : if up = true then a n * 2 ^ (s - 2 ^ 63) else n * 2 ^ (s - 2 ^ 63) a) :
          Rounds ((convert_tweak n s norm).finish up) a up

          Prove a (convert_tweak _ _ _).finish _ call is correct, in context.

          Conversion from #

          theorem Floating.ofNat_norm {n : } {up : Bool} :
          have t := n.log2; have s := t - 62; ¬t 62n.shiftRightRound s up Set.Icc (2 ^ 62) (2 ^ 63)
          @[irreducible]
          def Floating.ofNat (n : ) (up : Bool) :

          Conversion from to Floating, rounding up or down

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

            Conversion from literals to Floating, rounding down arbitrarily. Use Interval.ofNat if you want something trustworthy (it rounds both ways).

            Equations
            theorem Floating.val_ofNat' {n : } (lt : n < 2 ^ 63 := by norm_num) {up : Bool} :
            (ofNat n up).val = n

            Small naturals convert exactly

            theorem Floating.val_ofNat {n : } [n.AtLeastTwo] (lt : n < 2 ^ 63 := by norm_num) :
            val (OfNat.ofNat n) = n

            Small naturals convert exactly

            theorem Floating.ofNat_ne_nan {n : } (lt : n < 2 ^ 63) (up : Bool) :

            Small naturals do not overflow. Much larger values also do not overflow, but this is all we need at the moment.

            theorem Floating.approx_ofNat (n : ) (up : Bool) :
            Rounds (ofNat n up) (↑n) up

            ofNat rounds the desired way

            theorem Floating.ofNat_le {n : } (h : ofNat n false nan) :
            (ofNat n false).val n

            approx_ofNat, down version

            theorem Floating.le_ofNat {n : } (h : ofNat n true nan) :
            n (ofNat n true).val

            approx_ofNat, up version

            Combined version, for use in Interval construction

            Conversion from #

            @[irreducible]
            def Floating.ofInt (n : ) (up : Bool) :

            Conversion from

            Equations
            Instances For
              theorem Floating.approx_ofInt (n : ) (up : Bool) :
              Rounds (ofInt n up) (↑n) up

              ofInt rounds the desired way

              theorem Floating.ofInt_le {n : } (h : ofInt n false nan) :
              (ofInt n false).val n

              approx_ofInt, down version

              theorem Floating.le_ofInt {n : } (h : ofInt n true nan) :
              n (ofInt n true).val

              approx_ofInt, up version

              Combined version, for use in Interval construction

              Conversion from #

              theorem Floating.ofRat_norm {x : } {up : Bool} (x0 : ¬x = 0) :
              have r := x.log2; have n := x.num.natAbs; have p := if r 62 then (n <<< (62 - r).toNat, x.den) else (n, x.den <<< (r - 62).toNat); p.1.rdiv p.2 up Set.Icc (2 ^ 62) (2 ^ 63)

              ofRat_abs gives the right input to convert_tweak

              @[irreducible, inline]

              Conversion from , taking absolute values and rounding up or down

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                @[irreducible]
                def Floating.ofRat (x : ) (up : Bool) :

                Conversion from , rounding up or down

                Equations
                Instances For
                  theorem Floating.approx_ofRat_abs (x : ) (up : Bool) :
                  Rounds (ofRat_abs x up) (↑|x|) up

                  ofRat_abs rounds the desired way

                  theorem Floating.approx_ofRat (x : ) (up : Bool) :
                  Rounds (ofRat x up) (↑x) up

                  ofRat rounds the desired way

                  theorem Floating.ofRat_le {x : } (h : ofRat x false nan) :
                  (ofRat x false).val x

                  approx_ofRat, down version

                  theorem Floating.le_ofRat {x : } (h : ofRat x true nan) :
                  x (ofRat x true).val

                  approx_ofRat, up version

                  Combined version, for use in Interval construction

                  Conversion from Float #

                  @[irreducible]

                  Convert a Float to Floating. This could be fast, but we don't need it to be.

                  Equations
                  Instances For

                    ofFloat rounding is self-consistent