Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use axiom instead of variable for globals, consts #973

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions Source/Provers/LeanAuto/LeanAutoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public class LeanAutoGenerator : ReadOnlyVisitor
{
private readonly TextWriter writer;
private readonly VCGenOptions options;
private readonly List<NamedDeclaration> globalVars = new();
private readonly HashSet<string> usedNames = new();
private bool usesMaps;
private readonly List<string> mapAxiomNames =
new(new[]
Expand Down Expand Up @@ -216,7 +214,6 @@ public override ReturnCmd VisitReturnCmd(ReturnCmd node)
public override Expr VisitIdentifierExpr(IdentifierExpr node)
{
var name = SanitizeNameForLean(node.Name);
usedNames.Add(name);
WriteText(name);
return node;
}
Expand Down Expand Up @@ -279,13 +276,13 @@ public override Type VisitBvType(BvType node)
public override Constant VisitConstant(Constant node)
{
var ti = node.TypedIdent;
WriteText("variable ");
Visit(ti);
var name = SanitizeNameForLean(ti.Name);
WriteText($"axiom {name} : ");
Visit(ti.Type);
if (node.Unique) {
AddUniqueConst(ti.Type, Name(node));
}
WriteLine();
globalVars.Add(node);
return node;
}

Expand Down Expand Up @@ -340,10 +337,8 @@ public override QuantifierExpr VisitQuantifierExpr(QuantifierExpr node)

public override TypedIdent VisitTypedIdent(TypedIdent node)
{
WriteText("(");
var name = SanitizeNameForLean(node.Name);
WriteText(name);
WriteText(" : ");
WriteText($"( {name} : ");
Visit(node.Type);
WriteText(")");
return node;
Expand Down Expand Up @@ -385,10 +380,11 @@ public override Expr VisitLetExpr(LetExpr node)

public override GlobalVariable VisitGlobalVariable(GlobalVariable node)
{
WriteText("variable ");
Visit(node.TypedIdent);
var ti = node.TypedIdent;
var name = SanitizeNameForLean(ti.Name);
WriteText($"axiom {name} : ");
Visit(ti.Type);
WriteLine();
globalVars.Add(node);
return node;
}

Expand Down Expand Up @@ -822,7 +818,6 @@ public override Implementation VisitImplementation(Implementation node)
var name = Name(node);
var entryLabel = BlockName(node.Blocks[0]);

usedNames.Clear(); // Skip any globals used only by axioms, etc.
WriteLine();
WriteLine($"namespace impl_{name}");
WriteLine();
Expand All @@ -837,8 +832,7 @@ public override Implementation VisitImplementation(Implementation node)
WriteLine($"theorem {name}_correct");
WriteParams(node);
var paramNames =
globalVars.Select(Name).Where(x => usedNames.Contains(x))
.Concat(node.InParams.Select(Name))
node.InParams.Select(Name)
.Concat(node.OutParams.Select(Name))
.Concat(node.LocVars.Select(Name));
var paramString = String.Join(' ', paramNames);
Expand All @@ -852,7 +846,6 @@ public override Implementation VisitImplementation(Implementation node)
WriteLine($"end impl_{name}");

usesMaps = false; // Skip map axioms in the next implementation if it doesn't need them
usedNames.Clear(); // Skip any globals not used by the next implementation

return node;
}
Expand Down
10 changes: 10 additions & 0 deletions Test/lean-auto/lean-tests
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
../extractloops/detLoopExtract.bpl
../extractloops/detLoopExtractNested.bpl
../extractloops/t1.bpl
../extractloops/t2.bpl
../inline/expansion4.bpl
../inline/inline_n_0.bpl
../inline/test1.bpl
../inline/test2.bpl
../inline/test3.bpl
../inline/test6.bpl
../textbook/TuringFactorial.bpl
../textbook/DutchFlag.bpl
../textbook/Bubble.bpl
Expand Down
Loading