Documentation

Mathlib.Data.Bitvec.Defs

Basic operations on bitvectors #

This is a work-in-progress, and contains additions to other theories.

This file was moved to mathlib from core Lean in the switch to Lean 3.20.0c. It is not fully in compliance with mathlib style standards.

@[reducible]
def Bitvec (n : ) :

Bitvec n is a Vector of Bool with length n.

Instances For
    @[reducible]
    def Bitvec.zero (n : ) :

    Create a zero bitvector

    Instances For
      @[reducible]
      def Bitvec.one (n : ) :

      Create a bitvector of length n whose n-1st entry is 1 and other entries are 0.

      Instances For
        def Bitvec.cong {a : } {b : } :
        a = bBitvec aBitvec b

        Create a bitvector from another with a provably equal length.

        Instances For
          def Bitvec.append {m : } {n : } :
          Bitvec mBitvec nBitvec (m + n)

          Bitvec specific version of Vector.append

          Instances For

            Shift operations #

            def Bitvec.shl {n : } (x : Bitvec n) (i : ) :

            shl x i is the bitvector obtained by left-shifting x i times and padding with false. If x.length < i then this will return the all-falses bitvector.

            Instances For
              def Bitvec.ushr {n : } (x : Bitvec n) (i : ) :

              unsigned shift right

              Instances For
                def Bitvec.sshr {m : } :
                Bitvec mBitvec m

                signed shift right

                Instances For

                  Bitwise operations #

                  def Bitvec.not {n : } (bv : Bitvec n) :

                  bitwise not

                  Instances For
                    def Bitvec.and {n : } :
                    Bitvec nBitvec nBitvec n

                    bitwise and

                    Instances For
                      def Bitvec.or {n : } :
                      Bitvec nBitvec nBitvec n

                      bitwise or

                      Instances For
                        def Bitvec.xor {n : } :
                        Bitvec nBitvec nBitvec n

                        bitwise xor

                        Instances For

                          Arithmetic operators #

                          def Bitvec.neg {n : } (x : Bitvec n) :

                          neg x is the two's complement of x.

                          Instances For
                            def Bitvec.adc {n : } (x : Bitvec n) (y : Bitvec n) (c : Bool) :
                            Bitvec (n + 1)

                            Add with carry (no overflow)

                            Instances For
                              def Bitvec.add {n : } (x : Bitvec n) (y : Bitvec n) :

                              The sum of two bitvectors

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

                                Subtract with borrow

                                Instances For
                                  def Bitvec.sub {n : } (x : Bitvec n) (y : Bitvec n) :

                                  The difference of two bitvectors

                                  Instances For
                                    def Bitvec.mul {n : } (x : Bitvec n) (y : Bitvec n) :

                                    The product of two bitvectors

                                    Instances For

                                      Comparison operators #

                                      def Bitvec.uborrow {n : } (x : Bitvec n) (y : Bitvec n) :

                                      uborrow x y returns true iff the "subtract with borrow" operation on x, y and false required a borrow.

                                      Instances For
                                        def Bitvec.Ult {n : } (x : Bitvec n) (y : Bitvec n) :

                                        unsigned less-than proposition

                                        Instances For
                                          def Bitvec.Ugt {n : } (x : Bitvec n) (y : Bitvec n) :

                                          unsigned greater-than proposition

                                          Instances For
                                            def Bitvec.Ule {n : } (x : Bitvec n) (y : Bitvec n) :

                                            unsigned less-than-or-equal-to proposition

                                            Instances For
                                              def Bitvec.Uge {n : } (x : Bitvec n) (y : Bitvec n) :

                                              unsigned greater-than-or-equal-to proposition

                                              Instances For
                                                def Bitvec.sborrow {n : } :
                                                Bitvec nBitvec nBool

                                                sborrow x y returns true iff x < y as two's complement integers

                                                Instances For
                                                  def Bitvec.Slt {n : } (x : Bitvec n) (y : Bitvec n) :

                                                  signed less-than proposition

                                                  Instances For
                                                    def Bitvec.Sgt {n : } (x : Bitvec n) (y : Bitvec n) :

                                                    signed greater-than proposition

                                                    Instances For
                                                      def Bitvec.Sle {n : } (x : Bitvec n) (y : Bitvec n) :

                                                      signed less-than-or-equal-to proposition

                                                      Instances For
                                                        def Bitvec.Sge {n : } (x : Bitvec n) (y : Bitvec n) :

                                                        signed greater-than-or-equal-to proposition

                                                        Instances For

                                                          Conversion to nat and int #

                                                          def Bitvec.ofNat (n : ) :
                                                          Bitvec n

                                                          Create a bitvector from a nat

                                                          Equations
                                                          Instances For
                                                            def Bitvec.ofInt (n : ) :
                                                            Bitvec n

                                                            Create a bitvector from an Int. The ring homomorphism from Int to bitvectors.

                                                            Instances For
                                                              def Bitvec.addLsb (r : ) (b : Bool) :

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

                                                              Instances For

                                                                Given a List of Bools, return the nat they represent as a list of binary digits.

                                                                Instances For
                                                                  def Bitvec.toNat {n : } (v : Bitvec n) :

                                                                  Return the natural number encoded by the input bitvector

                                                                  Instances For
                                                                    def Bitvec.ofFin {n : } (i : Fin (2 ^ n)) :

                                                                    convert fin to Bitvec

                                                                    Instances For
                                                                      def Bitvec.toFin {n : } (i : Bitvec n) :
                                                                      Fin (2 ^ n)

                                                                      convert Bitvec to fin

                                                                      Instances For
                                                                        def Bitvec.toInt {n : } :
                                                                        Bitvec n

                                                                        Return the integer encoded by the input bitvector

                                                                        Instances For

                                                                          Miscellaneous instances #

                                                                          instance instDecidableUlt {n : } {x : Bitvec n} {y : Bitvec n} :
                                                                          instance instDecidableUgt {n : } {x : Bitvec n} {y : Bitvec n} :