Skip to content

Commit d1bc3db

Browse files
committed
wip
1 parent 8346a4d commit d1bc3db

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

DatapathVerification/BitHeap/BVComb.lean

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ inductive ArithCircuit : Nat → Type
2424
-- | arithunop (kind : ArithUnopKind) (width : Nat) (arg : ArithCircuit)
2525
-- | bvbinop (kind : BooleanBinopKind) (width : Nat) (l r : ArithCircuit)
2626

27+
def BitVecEnv (w : Nat) := Nat → BitVec w
28+
2729
/--
2830
Convert a bitheap into a new bitheap that has a single row,
2931
by using the naive compression algorithm.
3032
-/
3133
def BitHeap.toSingleRow (bh : BitHeap w) : CircuitVector :=
32-
let (pp1, pp2) := NaiveCompression.naiveCompression bh
33-
sorry
34+
let (pp1, _) := NaiveCompression.naiveCompression bh
35+
pp1.columns.toArray.map fun col => col.elems.toList.headD (.const false)
3436

3537
namespace ArithCircuit
3638
/--
@@ -50,25 +52,14 @@ def toBitHeap : ArithCircuit w → BitHeap w
5052
| .add args => BitHeap.addBitHeap (args.map toBitHeap)
5153
| .mul l r => BitHeap.truncate ((toBitHeap l).mulBitHeap (toBitHeap r)) w (by omega)
5254

53-
-- def toBitHeap' (c : ArithCircuit) : BitHeap w :=
54-
-- match c with
55-
-- | .var width varIndex => bitheapOfVar width varIndex
56-
-- | .add width args => BitHeap.addBitHeap (args.map toBitHeap)
57-
-- | .mul width l r => BitHeap.truncate ((toBitHeap l).mulBitHeap (toBitHeap r)) width (by omega)
58-
-- | .arithunop kind width arg =>`
59-
-- match kind with
60-
-- | .neg => (toBitHeap arg).negBitHeap
61-
-- | .bvbinop kind width l r =>
62-
-- match kind with
63-
-- | .and =>
64-
-- let lRow := (l.toBitHeap).toSingleRow
65-
-- let rRow := (r.toBitHeap).toSingleRow
66-
-- let newRow := Array.zipWith (fun lBit rBit => Circuit.and lBit rBit) lRow rRow
67-
-- BitHeap.fromRow newRow
55+
def denote (ρ : BitVecEnv w) : ArithCircuit w → BitVec w
56+
| .var i => ρ i
57+
| .add args => (args.map (denote ρ)).foldl (· + ·) 0
58+
| .mul l r => denote ρ l * denote ρ r
6859

6960
def toCircuitVector (c : ArithCircuit w) : CircuitVector :=
7061
let bh := c.toBitHeap
71-
bh.toSingleRow
62+
BitHeap.toSingleRow bh
7263

7364
end ArithCircuit
7465

0 commit comments

Comments
 (0)