Skip to content

Commit

Permalink
Support multi-binding var expressions in Lean backend (#983)
Browse files Browse the repository at this point in the history
This allows expressions of the form `var x, y := e1, e2; e3` to be
translated to Lean.

Also bumps the versions of lean and lean-auto.
  • Loading branch information
atomb authored Nov 14, 2024
1 parent 6450474 commit 331cdf6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
20 changes: 12 additions & 8 deletions Source/Provers/LeanAuto/LeanAutoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,21 @@ public override Expr VisitLambdaExpr(LambdaExpr node)

public override Expr VisitLetExpr(LetExpr node)
{
if (node.Dummies.Count > 1) {
if (node.Dummies.Count != node.Rhss.Count) {
throw new LeanConversionException(node.tok,
"Unsupported: LetExpr with more than one binder");
"Unsupported: LetExpr with differing LHS and RHS counts.");
}

var bindings = node.Dummies.Zip(node.Rhss);
foreach (var (x, e) in bindings) {
WriteText("(let ");
Visit(x.TypedIdent);
WriteText(" := ");
Visit(e);
WriteText("; ");
}
WriteText("(let");
node.Dummies.ForEach(x => Visit(x.TypedIdent));
WriteText(" := ");
node.Rhss.ForEach(e => Visit(e));
WriteText("; ");
Visit(node.Body);
WriteText(")");
bindings.ForEach(b => WriteText(")"));
return node;
}

Expand Down
2 changes: 1 addition & 1 deletion Test/lean-auto/lakefile.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package «test» {
}

require auto from git
"https://github.com/leanprover-community/lean-auto"@"0831a6eff8cbb456e90c616bd2f4db51aefea3d0"
"https://github.com/leanprover-community/lean-auto"@"60e546ca7a9d40d508e58847a9d0630406835178"

@[default_target]
lean_lib «ToBuild» {
Expand Down
2 changes: 1 addition & 1 deletion Test/lean-auto/lean-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
leanprover/lean4:v4.9.0
leanprover/lean4:v4.11.0
10 changes: 10 additions & 0 deletions Test/lean-auto/multi-let.bpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %parallel-boogie "%s" > "%t"
procedure P(x: int, y: int) {
var z: int;
var w: int;

z := (var a, b := x+1, y+1; a);
w := (var a, b := x+1, y+1; b);
assert (z - 1) == x;
assert (w - 1) == y;
}

0 comments on commit 331cdf6

Please sign in to comment.