Documentation

Init.Data.Dyadic.Basic

The dyadic rationals #

Constructs the dyadic rationals as an ordered ring, equipped with a compatible embedding into the rationals.

The number of trailing zeros in the binary representation of i.

Equations
Instances For
    def Int.trailingZeros.aux (k : Nat) (i : Int) (hi : i 0) (hk : i.natAbs k) (acc : Nat) :
    Equations
    Instances For
      @[irreducible]
      @[irreducible]
      theorem Int.two_pow_trailingZeros_dvd {i : Int} (h : i 0) :
      theorem Int.trailingZeros_shiftLeft {x : Int} (hx : x 0) (n : Nat) :
      @[simp, irreducible]
      inductive Dyadic :

      A dyadic rational is either zero or of the form n * 2^(-k) for some (unique) n k : Int where n is odd.

      • zero : Dyadic

        The dyadic number 0.

      • ofOdd (n k : Int) (hn : n % 2 = 1) : Dyadic

        The dyadic number n * 2^(-k) for some odd n and integer k.

      Instances For
        def instDecidableEqDyadic.decEq (x✝ x✝¹ : Dyadic) :
        Decidable (x✝ = x✝¹)
        Equations
        Instances For

          Returns the dyadic number representation of i * 2 ^ (-exp).

          Equations
          Instances For

            Convert an integer to a dyadic number (which will necessarily have non-positive precision).

            Equations
            Instances For
              instance Dyadic.instOfNat (n : Nat) :
              Equations
              Equations
              def Dyadic.add (x y : Dyadic) :

              Add two dyadic numbers.

              Equations
              Instances For
                def Dyadic.mul (x y : Dyadic) :

                Multiply two dyadic numbers.

                Equations
                Instances For
                  def Dyadic.pow (x : Dyadic) (i : Nat) :

                  Multiply two dyadic numbers.

                  Equations
                  Instances For

                    Negate a dyadic number.

                    Equations
                    Instances For
                      def Dyadic.sub (x y : Dyadic) :

                      Subtract two dyadic numbers.

                      Equations
                      Instances For

                        Shift a dyadic number left by i bits.

                        Equations
                        Instances For

                          Shift a dyadic number right by i bits.

                          Equations
                          Instances For
                            Equations
                            Equations
                            theorem Int.natAbs_emod_two (i : Int) :
                            i.natAbs % 2 = (i % 2).natAbs

                            Convert a dyadic number to a rational number.

                            Equations
                            Instances For
                              @[simp]
                              theorem Dyadic.zero_eq :
                              @[simp]
                              theorem Dyadic.add_zero (x : Dyadic) :
                              x + 0 = x
                              @[simp]
                              theorem Dyadic.zero_add (x : Dyadic) :
                              0 + x = x
                              @[simp]
                              theorem Dyadic.neg_zero :
                              -0 = 0
                              @[simp]
                              theorem Dyadic.mul_zero (x : Dyadic) :
                              x * 0 = 0
                              @[simp]
                              theorem Dyadic.zero_mul (x : Dyadic) :
                              0 * x = 0
                              @[simp]
                              theorem Rat.mkRat_one (x : Int) :
                              mkRat x 1 = x
                              theorem Dyadic.toRat_ofOdd_eq_mkRat {n k : Int} {hn : n % 2 = 1} :
                              (ofOdd n k hn).toRat = mkRat (n <<< (-k).toNat) (1 <<< k.toNat)
                              @[simp]
                              theorem Dyadic.toRat_add (x y : Dyadic) :
                              (x + y).toRat = x.toRat + y.toRat
                              @[simp]
                              theorem Dyadic.toRat_neg (x : Dyadic) :
                              @[simp]
                              theorem Dyadic.toRat_sub (x y : Dyadic) :
                              (x - y).toRat = x.toRat - y.toRat
                              @[simp]
                              theorem Dyadic.toRat_mul (x y : Dyadic) :
                              (x * y).toRat = x.toRat * y.toRat
                              @[simp]
                              theorem Dyadic.pow_zero (x : Dyadic) :
                              x ^ 0 = 1
                              theorem Dyadic.pow_succ (x : Dyadic) (n : Nat) :
                              x ^ (n + 1) = x ^ n * x
                              @[simp]
                              theorem Dyadic.toRat_pow (x : Dyadic) (n : Nat) :
                              (x ^ n).toRat = x.toRat ^ n
                              @[simp]
                              theorem Dyadic.toRat_intCast (x : Int) :
                              (↑x).toRat = x
                              @[simp]
                              theorem Dyadic.toRat_natCast (x : Nat) :
                              (↑x).toRat = x
                              @[simp]
                              theorem Dyadic.of_ne_zero {n k : Int} {hn : n % 2 = 1} :
                              ofOdd n k hn 0
                              @[simp]
                              theorem Dyadic.zero_ne_of {n k : Int} {hn : n % 2 = 1} :
                              0 ofOdd n k hn
                              @[simp]
                              theorem Dyadic.toRat_eq_zero_iff {x : Dyadic} :
                              x.toRat = 0 x = 0
                              theorem Dyadic.ofOdd_eq_ofIntWithPrec {n k : Int} {hn : n % 2 = 1} :
                              ofOdd n k hn = ofIntWithPrec n k
                              theorem Dyadic.toRat_ofOdd_eq_mul_two_pow {n k : Int} {hn : n % 2 = 1} :
                              (ofOdd n k hn).toRat = n * 2 ^ (-k)
                              @[simp]
                              @[simp]
                              theorem Dyadic.neg_ofOdd {n k : Int} {hn : n % 2 = 1} :
                              -ofOdd n k hn = ofOdd (-n) k
                              @[simp]
                              theorem Dyadic.neg_ofIntWithPrec {i prec : Int} :

                              The "precision" of a dyadic number, i.e. in n * 2^(-p) with n odd the precision is p.

                              Equations
                              Instances For
                                theorem Dyadic.precision_ofIntWithPrec_le {i : Int} (h : i 0) (prec : Int) :
                                def Rat.toDyadic (x : Rat) (prec : Int) :

                                Convert a rational number x to the greatest dyadic number with precision at most prec which is less than or equal to x.

                                Equations
                                Instances For
                                  theorem Rat.toDyadic_mkRat (a : Int) (b : Nat) (prec : Int) :
                                  (mkRat a b).toDyadic prec = Dyadic.ofIntWithPrec (a <<< prec.toNat / ↑(b <<< (-prec).toNat)) prec
                                  theorem Rat.toDyadic_eq_ofIntWithPrec (x : Rat) (prec : Int) :
                                  x.toDyadic prec = Dyadic.ofIntWithPrec (x.num <<< prec.toNat / ↑(x.den <<< (-prec).toNat)) prec
                                  theorem Rat.toRat_toDyadic (x : Rat) (prec : Int) :
                                  (x.toDyadic prec).toRat = (x * 2 ^ prec).floor / 2 ^ prec

                                  Converting a rational to a dyadic at a given precision and then back to a rational gives the same result as taking the floor of the rational at precision 2 ^ prec.

                                  theorem Rat.toRat_toDyadic_le {x : Rat} {prec : Int} :
                                  (x.toDyadic prec).toRat x
                                  theorem Rat.lt_toRat_toDyadic_add {x : Rat} {prec : Int} :
                                  def Dyadic.roundDown (x : Dyadic) (prec : Int) :

                                  Rounds a dyadic rational x down to the greatest dyadic number with precision at most prec which is less than or equal to x.

                                  Equations
                                  Instances For
                                    theorem Dyadic.roundDown_eq_self_of_le {x : Dyadic} {prec : Int} (h : x.precision some prec) :
                                    x.roundDown prec = x
                                    @[simp]
                                    theorem Dyadic.toDyadic_toRat (x : Dyadic) (prec : Int) :
                                    x.toRat.toDyadic prec = x.roundDown prec
                                    theorem Dyadic.toRat_inj {x y : Dyadic} :
                                    x.toRat = y.toRat x = y
                                    theorem Dyadic.add_comm (x y : Dyadic) :
                                    x + y = y + x
                                    theorem Dyadic.add_assoc (x y z : Dyadic) :
                                    x + y + z = x + (y + z)
                                    theorem Dyadic.mul_comm (x y : Dyadic) :
                                    x * y = y * x
                                    theorem Dyadic.mul_assoc (x y z : Dyadic) :
                                    x * y * z = x * (y * z)
                                    theorem Dyadic.mul_one (x : Dyadic) :
                                    x * 1 = x
                                    theorem Dyadic.one_mul (x : Dyadic) :
                                    1 * x = x
                                    theorem Dyadic.add_mul (x y z : Dyadic) :
                                    (x + y) * z = x * z + y * z
                                    theorem Dyadic.mul_add (x y z : Dyadic) :
                                    x * (y + z) = x * y + x * z
                                    theorem Dyadic.neg_add_cancel (x : Dyadic) :
                                    -x + x = 0
                                    theorem Dyadic.neg_mul (x y : Dyadic) :
                                    -x * y = -(x * y)
                                    def Dyadic.blt (x y : Dyadic) :

                                    Determine if a dyadic rational is strictly less than another.

                                    Equations
                                    Instances For
                                      def Dyadic.ble (x y : Dyadic) :

                                      Determine if a dyadic rational is less than or equal to another.

                                      Equations
                                      Instances For
                                        Equations
                                        Equations
                                        theorem Dyadic.lt_iff_toRat {x y : Dyadic} :
                                        x < y x.toRat < y.toRat
                                        @[simp]
                                        theorem Dyadic.not_le {x y : Dyadic} :
                                        ¬x < y y x
                                        @[simp]
                                        theorem Dyadic.not_lt {x y : Dyadic} :
                                        ¬x y y < x
                                        @[simp]
                                        theorem Dyadic.le_refl (x : Dyadic) :
                                        x x
                                        theorem Dyadic.le_trans {x y z : Dyadic} (h : x y) (h' : y z) :
                                        x z
                                        theorem Dyadic.le_antisymm {x y : Dyadic} (h : x y) (h' : y x) :
                                        x = y
                                        theorem Dyadic.le_total (x y : Dyadic) :
                                        x y y x
                                        def Dyadic.roundUp (x : Dyadic) (prec : Int) :

                                        roundUp x prec is the least dyadic number with precision at most prec which is greater than or equal to x.

                                        Equations
                                        Instances For