Skip to content

Commit 47493ff

Browse files
Set up inductive synthesis
1 parent 56874d2 commit 47493ff

File tree

1 file changed

+41
-25
lines changed

1 file changed

+41
-25
lines changed

SSA/Experimental/Bits/Fast/Generalize.lean

+41-25
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,32 @@ def solver (bvExpr: BVLogicalExpr) : TermElabM (Option (Std.HashMap Nat BVExpr.P
8484
return .some equations
8585

8686

87-
def substitute (bvLogicalExpr: BVLogicalExpr) (assignment: Std.HashMap Nat BVExpr.PackedBitVec) : BVLogicalExpr :=
87+
---- Test Solver function ----
88+
def simpleArith : BVLogicalExpr :=
89+
let x := BVExpr.const (BitVec.ofNat 5 2)
90+
let y := BVExpr.const (BitVec.ofNat 5 4)
91+
let z : BVExpr 5 := BVExpr.var 0
92+
let sum : BVExpr 5 := BVExpr.bin x BVBinOp.add z
93+
BoolExpr.literal (BVPred.bin sum BVBinPred.eq y)
94+
95+
syntax (name := testExSolver) "test_solver" : tactic
96+
@[tactic testExSolver]
97+
def testSolverImpl : Tactic := fun _ => do
98+
let res ← solver simpleArith
99+
match res with
100+
| none => pure ()
101+
| some counterex =>
102+
for (id, var) in counterex do
103+
logInfo m! "Results: {id}={var.bv}"
104+
pure ()
105+
106+
theorem test_solver : False := by
107+
test_solver
108+
109+
110+
111+
def substitute (bvLogicalExpr: BVLogicalExpr) (assignment: Std.HashMap Nat BVExpr.PackedBitVec) :
112+
BVLogicalExpr :=
88113
let rec substituteBVExpr {w: Nat} (bvExpr : BVExpr w) : BVExpr w :=
89114
match bvExpr with
90115
| .var idx =>
@@ -152,30 +177,6 @@ partial def existsForAll (bvExpr: BVLogicalExpr) (existsVars: List Nat) (forAllV
152177
existsForAll (BoolExpr.gate Gate.and bvExpr newExpr) existsVars forAllVars
153178

154179

155-
156-
---- Test Solver function ----
157-
def simpleArith : BVLogicalExpr :=
158-
let x := BVExpr.const (BitVec.ofNat 5 2)
159-
let y := BVExpr.const (BitVec.ofNat 5 4)
160-
let z : BVExpr 5 := BVExpr.var 0
161-
let sum : BVExpr 5 := BVExpr.bin x BVBinOp.add z
162-
BoolExpr.literal (BVPred.bin sum BVBinPred.eq y)
163-
164-
syntax (name := testExSolver) "test_solver" : tactic
165-
@[tactic testExSolver]
166-
def testSolverImpl : Tactic := fun _ => do
167-
let res ← solver simpleArith
168-
match res with
169-
| none => pure ()
170-
| some counterex =>
171-
for (id, var) in counterex do
172-
logInfo m! "Results: {id}={var.bv}"
173-
pure ()
174-
175-
theorem test_solver : False := by
176-
test_solver
177-
178-
179180
---- Test ExistsForAll function ---
180181
def leftShiftRightShiftOne : BVLogicalExpr :=
181182
let bitwidth := 4
@@ -235,3 +236,18 @@ def testExFaImpl : Tactic := fun _ => do
235236

236237
theorem test_exists_for_all : False := by
237238
test_exists_for_all
239+
240+
241+
def binaryOperators : List BVBinOp :=
242+
[BVBinOp.add, BVBinOp.mul]
243+
244+
245+
def inductive_synthesis (expr: BVExpr w) (inputs: List Nat) (constants: Std.HashMap Nat (BVExpr w)) (target: BVExpr w) (depth: Nat) :
246+
TermElabM (Option (List (BVExpr w))) := do
247+
match depth with
248+
| 1 => return none -- enumerative synthesis
249+
| _ =>
250+
let res : List (BVExpr w) := []
251+
for (const, value) in constants.toArray do
252+
logInfo m! "Hello"
253+
return some []

0 commit comments

Comments
 (0)