-
Notifications
You must be signed in to change notification settings - Fork 3
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
Groebner extension #53
base: master
Are you sure you want to change the base?
Conversation
a special exception on the `inout` branch for the "_default" module vs. the original master code, due to the presence of rank_is_less_than. Rustan then made the original logic more complex in support of "Revise export reference types", commit 3a9524f.
the linear pass more complete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do all of those examples go through? If so, that's really cool! I'm also impressed you could whip this together so quickly!
Source/Dafny/Translator.cs
Outdated
} | ||
|
||
string OpacifySubExpr(Expression expr) { | ||
if (expr is SeqSelectExpr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C# will let you write:
if (expr is SeqSelectExpr seqSelExpr) {
...
i.e., you can combine the test with the naming of the new variable. The name scoping is annoying though, each new variable needs to be unique, so you can't just call them all e
, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that's good to know. Thanks for the tip!
Source/Dafny/Translator.cs
Outdated
} | ||
var seq = this.OpacifySubExpr(seqSelExpr.Seq); | ||
var index = this.OpacifySubExpr(seqSelExpr.E0); | ||
return String.Format("{0}[{1}]", seq, index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this is going to emit something like x[5]
to Singular. Won't that confuse it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait, I see. The goal is just to create a unique string 'key' to use later in the opaqueExprs
dictionary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, exactly. We create a temp variable in place of the expression, and when the exact same expression shows up again, we will just use the temp variable. Singular will have next to no understanding of the expression, only knowing that it is some integer.
Source/Dafny/Translator.cs
Outdated
var mod = this.EncodeSubExpr(appplyExpr.Args[2]); | ||
// add the mod to the generators | ||
polys.Add(mod); | ||
return this.EncodeEqualityPoly(appplyExpr.Args[0], appplyExpr.Args[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aren't Args[0]
and Args[1]
encoded here? They were encoded in EncodeGeneratorPoly
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh in this case we are encoding the "question": is it true that Args[0]
and Args[1]
are congruent modulo Args[2]
? So Args[2]
goes into the ideal, while Args[0] - Args[1]
becomes the query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but I was expecting something like:
return this.EncodeEqualityPoly(this.EncodeSubExpr(appplyExpr.Args[0]),this.EncodeSubExpr(appplyExpr.Args[1]));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh in this case the Args[2]
needs to go into the ideal. The rest of the polys in the generators are effectively all 0, except this one. Then if the difference Args[0] - Args[1]
can be written in terms of a linear combination of the generators, it must be a multiple of Args[2]
, proving the congruence.
} | ||
} | ||
|
||
string EncodeQueryPoly(Expression expr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very similar to EncodeGeneratorPoly
. Would it make sense to factor out the common bits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true, I will try extract some common bits.
Source/Dafny/Translator.cs
Outdated
} else if (ss is AssumeStmt) { | ||
this.EncodeGeneratorPoly((ss as AssumeStmt).Expr); | ||
} else { | ||
Console.WriteLine("Error: Unexpected Grobner poorf body statement {0}", ss); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"proof body"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I can't English :)
var assumeFalse = new AssumeStmt(stmt.Tok, stmt.EndTok, falseBody, null); | ||
assertStmt.Proof.Body.Add(assumeFalse); | ||
} | ||
TrStmt(assertStmt.Proof, proofBuilder, locals, etran); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, this is a Dafny level change that adds a Dafny-level "assume false" to the proof body that's supplied in the by { ... }
clause of the assert? And it's added at the end of the body, so that Dafny will check the assertions the developer wrote, since Singular trusts that they are correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is exactly my intention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth adding a small comment explaining the overall intent, or even showing a "before" and "after" version of some sample Dafny code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will do.
close the `queryFile` for Singular solver. Otherwise there will be IOException error when deleting it on Windows.
[groebner-extension]: close query file after writing
No description provided.