Documentation

Interval.Int128

Int128: 128-bit signed integers #

structure Int128 :

128-bit twos complement signed integers

Instances For
    theorem Int128.ext_iff {x y : Int128} :
    x = y x.n = y.n
    theorem Int128.ext {x y : Int128} (n : x.n = y.n) :
    x = y
    def instDecidableEqInt128.decEq (x✝ x✝¹ : Int128) :
    Decidable (x✝ = x✝¹)
    Equations
    Instances For
      Equations
      Instances For
        @[irreducible]
        Equations
        Instances For
          @[irreducible]
          Equations
          Instances For
            Equations
            @[simp]
            theorem Int128.n_zero :
            n 0 = 0
            theorem Int128.isNeg_eq_le_toNat (x : Int128) :
            x.isNeg = decide (2 ^ 127 x.n.toNat)

            Alternative isNeg characterization in terms of n.toNat

            Conversion from other integer types #

            Equations
            • x = { n := { lo := x, hi := 0 } }
            Instances For
              @[irreducible]

              Wrap around conversion from

              Equations
              Instances For
                @[irreducible]

                Wrap around conversion from

                Equations
                Instances For

                  conversion #

                  The that an Int128 represents

                  Equations
                  Instances For

                    The that an Int64 represents

                    Equations
                    @[simp]
                    theorem Int128.coe_of_hi_eq_zero {x : Int128} (h0 : x.n.hi = 0) :
                    x.n.lo.toNat = x

                    If hi = 0, conversion is just lo

                    @[simp]
                    theorem Int128.isNeg_iff {x : Int128} :
                    x.isNeg = decide (x < 0)

                    isNeg is nicer in terms of integers

                    @[simp]
                    theorem Int128.ofInt_coe (x : Int128) :
                    ofInt x = x

                    Int128 → ℤ → Int128 is the identity

                    theorem Int128.coe_ofInt (x : ) :
                    (ofInt x) = (x + 2 ^ 127) % 2 ^ 128 - 2 ^ 127

                    ℤ → Int128 → ℤ almost roundtrips

                    @[simp]
                    theorem Int128.ofInt_ofUInt64 (x : UInt64) :
                    ofInt x.toNat = x

                    ofInt_coe if we start with UInt64

                    Additive group operations: negation, addition, subtraction #

                    Equations
                    Equations
                    Equations
                    theorem Int128.n_neg (x : Int128) :
                    (-x).n = -x.n
                    theorem Int128.n_add (x y : Int128) :
                    (x + y).n = x.n + y.n
                    theorem Int128.n_sub (x y : Int128) :
                    (x - y).n = x.n - y.n
                    @[simp]
                    theorem Int128.neg_ofInt (x : ) :

                    ofInt commutes with -

                    @[simp]
                    theorem Int128.add_ofInt (x y : ) :
                    ofInt (x + y) = ofInt x + ofInt y

                    ofInt commutes with +

                    @[simp]
                    theorem Int128.sub_ofInt (x y : ) :
                    ofInt (x - y) = ofInt x - ofInt y

                    ofInt commutes with -

                    Int128 inherits the additive group structure from UInt128

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

                    ℤ → Int128 is injective for small integers #

                    theorem Int128.coe_ofInt_of_abs_lt {x : } (sx : x Set.Ico (-2 ^ 127) (2 ^ 127)) :
                    (ofInt x) = x

                    Small integers roundtrip through ℤ → Int128 → ℤ

                    theorem Int128.eq_of_ofInt_eq {x y : } (e : ofInt x = ofInt y) (sx : x Set.Ico (-2 ^ 127) (2 ^ 127)) (sy : y Set.Ico (-2 ^ 127) (2 ^ 127)) :
                    x = y

                    Small integers are equal if their 128-bit wraps are equal

                    theorem Int128.coe_small {x : Int128} :
                    x Set.Ico (-2 ^ 127) (2 ^ 127)

                    coe is small