Documentation

Mathlib.Data.Int.Bitwise

Bitwise operations on integers #

Possibly only of archaeological significance.

Recursors #

def Int.div2 :
โ„ค โ†’ โ„ค

div2 n = n/2

Instances For
    def Int.bodd :
    โ„ค โ†’ Bool

    bodd n returns true if n is odd

    Instances For
      def Int.bit (b : Bool) :
      โ„ค โ†’ โ„ค

      bit b appends the digit b to the binary representation of its integer input.

      Instances For
        def Int.natBitwise (f : Bool โ†’ Bool โ†’ Bool) (m n : โ„•) :
        โ„ค

        Int.natBitwise is an auxiliary definition for Int.bitwise.

        Instances For
          def Int.bitwise (f : Bool โ†’ Bool โ†’ Bool) :
          โ„ค โ†’ โ„ค โ†’ โ„ค

          Int.bitwise applies the function f to pairs of bits in the same position in the binary representations of its inputs.

          Instances For
            def Int.lnot :
            โ„ค โ†’ โ„ค

            lnot flips all the bits in the binary representation of its input

            Instances For
              def Int.lor :
              โ„ค โ†’ โ„ค โ†’ โ„ค

              lor takes two integers and returns their bitwise or

              Instances For
                def Int.land :
                โ„ค โ†’ โ„ค โ†’ โ„ค

                land takes two integers and returns their bitwise and

                Instances For
                  def Int.ldiff :
                  โ„ค โ†’ โ„ค โ†’ โ„ค

                  ldiff a b performs bitwise set difference. For each corresponding pair of bits taken as Booleans, say aแตข and bแตข, it applies the Boolean operation aแตข โˆง ยฌbแตข to obtain the iแต—สฐ bit of the result.

                  Instances For
                    def Int.xor :
                    โ„ค โ†’ โ„ค โ†’ โ„ค

                    xor computes the bitwise xor of two natural numbers

                    Instances For
                      @[implicit_reducible]
                      instance Int.instShiftLeft_mathlib :
                      ShiftLeft โ„ค

                      m <<< n produces an integer whose binary representation is obtained by left-shifting the binary representation of m by n places

                      @[implicit_reducible]
                      instance Int.instShiftRight_mathlib :
                      ShiftRight โ„ค

                      m >>> n produces an integer whose binary representation is obtained by right-shifting the binary representation of m by n places

                      bitwise ops #

                      @[simp]
                      theorem Int.bodd_coe (n : โ„•) :
                      (โ†‘n).bodd = n.bodd
                      @[simp]
                      theorem Int.bodd_subNatNat (m n : โ„•) :
                      (subNatNat m n).bodd = (m.bodd ^^ n.bodd)
                      @[simp]
                      theorem Int.bodd_negOfNat (n : โ„•) :
                      (negOfNat n).bodd = n.bodd
                      @[simp]
                      theorem Int.bodd_neg (n : โ„ค) :
                      (-n).bodd = n.bodd
                      @[simp]
                      theorem Int.bodd_add (m n : โ„ค) :
                      (m + n).bodd = (m.bodd ^^ n.bodd)
                      @[simp]
                      theorem Int.bodd_mul (m n : โ„ค) :
                      (m * n).bodd = (m.bodd && n.bodd)
                      theorem Int.bodd_add_div2 (n : โ„ค) :
                      (bif n.bodd then 1 else 0) + 2 * n.div2 = n
                      theorem Int.div2_val (n : โ„ค) :
                      n.div2 = n / 2
                      theorem Int.bit_val (b : Bool) (n : โ„ค) :
                      bit b n = 2 * n + bif b then 1 else 0
                      theorem Int.bit_decomp (n : โ„ค) :
                      bit n.bodd n.div2 = n
                      def Int.bitCasesOn {C : โ„ค โ†’ Sort u} (n : โ„ค) (h : (b : Bool) โ†’ (n : โ„ค) โ†’ C (bit b n)) :
                      C n

                      Defines a function from โ„ค conditionally, if it is defined for odd and even integers separately using bit.

                      Instances For
                        @[simp]
                        theorem Int.bit_zero :
                        bit false 0 = 0
                        @[simp]
                        theorem Int.bit_coe_nat (b : Bool) (n : โ„•) :
                        bit b โ†‘n = โ†‘(Nat.bit b n)
                        @[simp]
                        theorem Int.bit_negSucc (b : Bool) (n : โ„•) :
                        bit b (negSucc n) = negSucc (Nat.bit (!b) n)
                        @[simp]
                        theorem Int.bodd_bit (b : Bool) (n : โ„ค) :
                        (bit b n).bodd = b
                        @[simp]
                        theorem Int.testBit_bit_zero (b : Bool) (n : โ„ค) :
                        (bit b n).testBit 0 = b
                        @[simp]
                        theorem Int.testBit_bit_succ (m : โ„•) (b : Bool) (n : โ„ค) :
                        (bit b n).testBit m.succ = n.testBit m
                        theorem Int.bitwise_diff :
                        (bitwise fun (a b : Bool) => a && !b) = ldiff
                        @[simp]
                        theorem Int.bitwise_bit (f : Bool โ†’ Bool โ†’ Bool) (a : Bool) (m : โ„ค) (b : Bool) (n : โ„ค) :
                        bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n)
                        @[simp]
                        theorem Int.lor_bit (a : Bool) (m : โ„ค) (b : Bool) (n : โ„ค) :
                        (bit a m).lor (bit b n) = bit (a || b) (m.lor n)
                        @[simp]
                        theorem Int.land_bit (a : Bool) (m : โ„ค) (b : Bool) (n : โ„ค) :
                        (bit a m).land (bit b n) = bit (a && b) (m.land n)
                        @[simp]
                        theorem Int.ldiff_bit (a : Bool) (m : โ„ค) (b : Bool) (n : โ„ค) :
                        (bit a m).ldiff (bit b n) = bit (a && !b) (m.ldiff n)
                        @[simp]
                        theorem Int.lxor_bit (a : Bool) (m : โ„ค) (b : Bool) (n : โ„ค) :
                        (bit a m).xor (bit b n) = bit (a ^^ b) (m.xor n)
                        @[simp]
                        theorem Int.lnot_bit (b : Bool) (n : โ„ค) :
                        (bit b n).lnot = bit (!b) n.lnot
                        @[simp]
                        theorem Int.testBit_bitwise (f : Bool โ†’ Bool โ†’ Bool) (m n : โ„ค) (k : โ„•) :
                        (bitwise f m n).testBit k = f (m.testBit k) (n.testBit k)
                        @[simp]
                        theorem Int.testBit_lor (m n : โ„ค) (k : โ„•) :
                        (m.lor n).testBit k = (m.testBit k || n.testBit k)
                        @[simp]
                        theorem Int.testBit_land (m n : โ„ค) (k : โ„•) :
                        (m.land n).testBit k = (m.testBit k && n.testBit k)
                        @[simp]
                        theorem Int.testBit_ldiff (m n : โ„ค) (k : โ„•) :
                        (m.ldiff n).testBit k = (m.testBit k && !n.testBit k)
                        @[simp]
                        theorem Int.testBit_lxor (m n : โ„ค) (k : โ„•) :
                        (m.xor n).testBit k = (m.testBit k ^^ n.testBit k)
                        @[simp]
                        theorem Int.testBit_lnot (n : โ„ค) (k : โ„•) :
                        n.lnot.testBit k = !n.testBit k
                        @[simp]
                        theorem Int.shiftLeft_neg (m n : โ„ค) :
                        m <<< (-n) = m >>> n
                        @[simp]
                        theorem Int.shiftRight_neg (m n : โ„ค) :
                        m >>> (-n) = m <<< n
                        @[simp]
                        theorem Int.shiftLeft_natCast (m n : โ„•) :
                        โ†‘m <<< โ†‘n = โ†‘(m <<< n)
                        @[simp]
                        theorem Int.shiftRight_natCast (m n : โ„•) :
                        โ†‘m >>> โ†‘n = โ†‘(m >>> n)
                        @[simp]
                        theorem Int.shiftLeft_negSucc (m n : โ„•) :
                        negSucc m <<< โ†‘n = negSucc (Nat.shiftLeft' true m n)
                        @[simp]
                        theorem Int.shiftRight_negSucc (m n : โ„•) :
                        negSucc m >>> โ†‘n = negSucc (m >>> n)
                        theorem Int.shiftRight_add' (m : โ„ค) (n k : โ„•) :
                        m >>> (โ†‘n + โ†‘k) = m >>> โ†‘n >>> โ†‘k

                        Compare with Int.shiftRight_add, which doesn't have the coercions โ„• โ†’ โ„ค.

                        bitwise ops #

                        theorem Int.shiftLeft_natCast_right (m : โ„ค) (n : โ„•) :
                        m <<< โ†‘n = m <<< n

                        Connection of HShiftLeft Int Int Int and HShiftLeft Int Nat Int.

                        theorem Int.shiftRight_natCast_right (m : โ„ค) (n : โ„•) :
                        m >>> โ†‘n = m >>> n

                        Connection of HShiftRight Int Int Int and HShiftRight Int Nat Int.

                        theorem Int.shiftLeft_add' (m : โ„ค) (n : โ„•) (k : โ„ค) :
                        m <<< (โ†‘n + k) = m <<< โ†‘n <<< k
                        theorem Int.shiftLeft_sub (m : โ„ค) (n : โ„•) (k : โ„ค) :
                        m <<< (โ†‘n - k) = m <<< โ†‘n >>> k
                        theorem Int.shiftLeft_eq_mul_pow (m : โ„ค) (n : โ„•) :
                        m <<< โ†‘n = m * โ†‘(2 ^ n)
                        theorem Int.one_shiftLeft (n : โ„•) :
                        1 <<< โ†‘n = โ†‘(2 ^ n)
                        @[simp]
                        theorem Int.zero_shiftLeft' (n : โ„ค) :
                        0 <<< n = 0

                        Compare with Int.zero_shiftLeft, which has n : โ„•.

                        @[simp]
                        theorem Int.zero_shiftRight' (n : โ„ค) :
                        0 >>> n = 0

                        Compare with Int.zero_shiftRight, which has n : โ„•.