@@ -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/--
2830Convert a bitheap into a new bitheap that has a single row,
2931by using the naive compression algorithm.
3032-/
3133def 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
3537namespace 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
6960def toCircuitVector (c : ArithCircuit w) : CircuitVector :=
7061 let bh := c.toBitHeap
71- bh .toSingleRow
62+ BitHeap .toSingleRow bh
7263
7364end ArithCircuit
7465
0 commit comments