Documentation

SSA.Experimental.Bits.Fast.Tactic

BitVec Automata Tactic #

There are two ways of expressing BitVec expressions. One is:

(x &&& y) ||| y + 0

the other way is:

Term.add (Term.or (Term.and (Term.var 0) (Term.var 1)) (Term.var 1)) Term.zero

The goal of this tactic is to convert expressions of the first kind into the second kind, because we have a decision procedure that decides equality on expressions of the second kind.

theorem eval_sub {x : Term} {y : Term} {vars : BitStream} :
(x.sub y).eval vars = x.eval vars - y.eval vars
theorem eval_add {x : Term} {y : Term} {vars : BitStream} :
(x.add y).eval vars = x.eval vars + y.eval vars
theorem eval_neg {x : Term} {vars : BitStream} :
x.neg.eval vars = -x.eval vars
theorem eval_not {x : Term} {vars : BitStream} :
x.not.eval vars = ~~~x.eval vars
theorem eval_and {x : Term} {y : Term} {vars : BitStream} :
(x.and y).eval vars = x.eval vars &&& y.eval vars
theorem eval_xor {x : Term} {y : Term} {vars : BitStream} :
(x.xor y).eval vars = x.eval vars ^^^ y.eval vars
theorem eval_or {x : Term} {y : Term} {vars : BitStream} :
(x.or y).eval vars = x.eval vars ||| y.eval vars
def quoteFVar (x : Lean.FVarId) :
Q()
Equations
Instances For
    def termNat (n : ) :
    Equations
    Instances For
      def quoteThm (qMapIndexToFVar : Q(BitStream)) (w : Q()) (nat : ) :
      Q(BitStream.EqualUpTo «$w» (BitStream.ofBitVec (BitVec.ofNat «$w» «$nat»)) ((termNat «$nat»).eval «$qMapIndexToFVar»))
      Equations
      Instances For
        partial def first_rep (w : Q()) (e : Q(BitStream)) :
        Lean.Meta.SimpM ((x : Q(BitStream)) × Q(BitStream.EqualUpTo «$w» «$e» «$x»))

        Given an Expr e, return a pair e', p where e' is an expression and p is a proof that e and e' are equal on the fist w bits

        Push all ofBitVecs down to the lowest level

        Instances For

          Introduce vars which maps variable ids to the variable values.

          let vars (n : Nat) : BitStream := BitStream.ofBitVec (if n = 0 then v0 else if n = 1 then v1 else if n = 2 then v2 ......)

          Term.var 0 -- represent the 0th variable Term.var 1 -- represent the 1st variable

          Instances For
            Equations
            Instances For

              Create bv_automata tactic which solves equalities on bitvectors.

              Equations
              Instances For

                Test Cases #

                def alive_1 {w : } (x : BitVec w) (x_1 : BitVec w) (x_2 : BitVec w) :
                (x_2 &&& x_1 ^^^ x_1) + 1#w + x = x - (x_2 ||| ~~~x_1)
                Equations
                • =
                Instances For
                  def false_statement {w : } (x : BitVec w) (y : BitVec w) :
                  x = y
                  Equations
                  • =
                  Instances For
                    def test_OfNat_ofNat (x : BitVec 1) :
                    1 + x = x + 1
                    Equations
                    • =
                    Instances For
                      def test_BitVec_ofNat (x : BitVec 1) :
                      1 + x = x + 1#1
                      Equations
                      • =
                      Instances For
                        def test0 {w : } (x : BitVec (w + 1)) (y : BitVec (w + 1)) :
                        x + 0 = x
                        Equations
                        • =
                        Instances For
                          def test_simple2 {w : } (x : BitVec (w + 1)) (y : BitVec (w + 1)) :
                          x = x
                          Equations
                          • =
                          Instances For
                            def test1 {w : } (x : BitVec (w + 1)) (y : BitVec (w + 1)) :
                            (x ||| y) - (x ^^^ y) = x &&& y
                            Equations
                            • =
                            Instances For
                              def test2 (x : BitVec 300) (y : BitVec 300) :
                              (x &&& y) + (x ||| y) = x + y
                              Equations
                              • =
                              Instances For
                                def test3 (x : BitVec 300) (y : BitVec 300) :
                                (x ||| y) - (x ^^^ y) = x &&& y
                                Equations
                                • =
                                Instances For
                                  def test4 (x : BitVec 2) (y : BitVec 2) :
                                  x + -y = x - y
                                  Equations
                                  • =
                                  Instances For
                                    def test5 (x : BitVec 2) (y : BitVec 2) (z : BitVec 2) :
                                    x + y + z = z + y + x
                                    Equations
                                    • =
                                    Instances For
                                      def test6 (x : BitVec 2) (y : BitVec 2) (z : BitVec 2) :
                                      x + (y + z) = x + y + z
                                      Equations
                                      • =
                                      Instances For
                                        def test11 (x : BitVec 2) (y : BitVec 2) :
                                        x + y = (x ||| y) + (x &&& y)
                                        Equations
                                        • =
                                        Instances For
                                          def test15 (x : BitVec 2) (y : BitVec 2) :
                                          x - y = (x &&& ~~~y) - (~~~x &&& y)
                                          Equations
                                          • =
                                          Instances For
                                            def test17 (x : BitVec 2) (y : BitVec 2) :
                                            x ^^^ y = (x ||| y) - (x &&& y)
                                            Equations
                                            • =
                                            Instances For
                                              def test18 (x : BitVec 2) (y : BitVec 2) :
                                              x &&& ~~~y = (x ||| y) - y
                                              Equations
                                              • =
                                              Instances For
                                                def test19 (x : BitVec 2) (y : BitVec 2) :
                                                x &&& ~~~y = x - (x &&& y)
                                                Equations
                                                • =
                                                Instances For
                                                  def test21 (x : BitVec 2) (y : BitVec 2) :
                                                  ~~~(x - y) = ~~~x + y
                                                  Equations
                                                  • =
                                                  Instances For
                                                    def test23 (x : BitVec 2) (y : BitVec 2) :
                                                    ~~~(x ^^^ y) = (x &&& y) + ~~~(x ||| y)
                                                    Equations
                                                    • =
                                                    Instances For
                                                      def test24 (x : BitVec 2) (y : BitVec 2) :
                                                      x ||| y = (x &&& ~~~y) + y
                                                      Equations
                                                      • =
                                                      Instances For
                                                        def test25 (x : BitVec 2) (y : BitVec 2) :
                                                        x &&& y = (~~~x ||| y) - ~~~x
                                                        Equations
                                                        • =
                                                        Instances For
                                                          def test26 {w : } (x : BitVec (w + 1)) (y : BitVec (w + 1)) :
                                                          1 + x + 0 = 1 + x
                                                          Equations
                                                          • =
                                                          Instances For
                                                            def test27 (x : BitVec 5) (y : BitVec 5) :
                                                            2 + x = 1 + x + 1
                                                            Equations
                                                            • =
                                                            Instances For
                                                              def test28 {w : } (x : BitVec (w + 1)) (y : BitVec (w + 1)) :
                                                              x &&& x &&& x &&& x &&& x &&& x = x
                                                              Equations
                                                              • =
                                                              Instances For