Documentation

Mathlib.Data.BitVec.Defs

Basic operations on bitvectors #

Std has defined bitvector of length w as Fin (2^w). Here we define a few more operations on these bitvectors

Main definitions #

Constants #

@[inline, reducible]
abbrev BitVec.one (w : ) :

The bitvector representing 1. That is, the bitvector with least-significant bit 1 and all other bits 0

Equations
Instances For

    Bitwise operations #

    Arithmetic operators #

    def BitVec.adc' {n : } (x : BitVec n) (y : BitVec n) (c : Bool) :
    BitVec (n + 1)

    Add with carry (no overflow)

    See also Std.BitVec.adc, which stores the carry bit separately.

    Equations
    Instances For
      def BitVec.sbb {n : } (x : BitVec n) (y : BitVec n) (b : Bool) :

      Subtract with borrow

      Equations
      Instances For

        Comparison operators #

        def BitVec.ugt {w : } (x : BitVec w) (y : BitVec w) :

        Unsigned greater than for bitvectors.

        Equations
        Instances For
          def BitVec.uge {w : } (x : BitVec w) (y : BitVec w) :

          Signed greater than or equal to for bitvectors.

          Equations
          Instances For
            def BitVec.sgt {w : } (x : BitVec w) (y : BitVec w) :

            Signed greater than for bitvectors.

            Equations
            Instances For
              def BitVec.sge {w : } (x : BitVec w) (y : BitVec w) :

              Signed greater than or equal to for bitvectors.

              Equations
              Instances For

                Conversion to nat and int #

                def BitVec.addLsb (r : ) (b : Bool) :

                addLsb r b is r + r + 1 if b is true and r + r otherwise.

                Equations
                Instances For
                  def BitVec.getLsb' {w : } (x : BitVec w) (i : Fin w) :

                  Return the i-th least significant bit, where i is a statically known in-bounds index

                  Equations
                  Instances For
                    def BitVec.getMsb' {w : } (x : BitVec w) (i : Fin w) :

                    Return the i-th most significant bit, where i is a statically known in-bounds index

                    Equations
                    Instances For
                      def BitVec.toLEList {w : } (x : BitVec w) :

                      Convert a bitvector to a little-endian list of Booleans. That is, the head of the list is the least significant bit

                      Equations
                      Instances For
                        def BitVec.toBEList {w : } (x : BitVec w) :

                        Convert a bitvector to a big-endian list of Booleans. That is, the head of the list is the most significant bit

                        Equations
                        Instances For
                          Equations
                          • BitVec.instSMulNatBitVec = { smul := fun (x : ) (y : BitVec w) => { toFin := x y.toFin } }
                          Equations
                          • BitVec.instSMulIntBitVec = { smul := fun (x : ) (y : BitVec w) => { toFin := x y.toFin } }
                          Equations
                          • BitVec.instPowBitVecNat = { pow := fun (x : BitVec w) (n : ) => { toFin := x.toFin ^ n } }