-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Added transformations for quantification over special integer sets #1431
Conversation
Codecov Report
@@ Coverage Diff @@
## unstable #1431 +/- ##
============================================
+ Coverage 74.57% 74.61% +0.03%
============================================
Files 358 359 +1
Lines 11357 11373 +16
Branches 559 542 -17
============================================
+ Hits 8470 8486 +16
Misses 2887 2887
Continue to review full report at Codecov.
|
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.
LGTM, I just left some opinion/questions for the testing part.
tla-pp/src/test/scala/at/forsyte/apalache/tla/pp/TestQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
tla-pp/src/test/scala/at/forsyte/apalache/tla/pp/TestQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
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.
A few small comments and suggestions, one one more substantive (but totally optional) suggestion about the organization of the logic in the transformation.
* This transformation rewrites expressions of the form `(\A | \E) x \in S: P`, where S is one of `Int`, `Nat`, `a..b`, | ||
* into `(\A | \E) x: Q` (unbounded quantification). |
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.
Should this communicate that the rewriting generally moves the bounds from variable binding in the quantifier into constraints in the expression that is quantified over? iiuc, this is part of the key idea, not simply that that it produces unbounded quantification.
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/IntegerQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/IntegerQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/IntegerQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
test("Translation of Nat") { | ||
val natSet = tla.natSet().as(SetT1(IntT1())) | ||
|
||
forSetWithPredicates(Gen.const(natSet), postPredE, postPredA) | ||
} | ||
|
||
test("Translation of Int") { | ||
val intSet = tla.intSet().as(SetT1(IntT1())) | ||
|
||
forSetWithPredicates(Gen.const(intSet), postPredE, postPredA) | ||
} | ||
|
||
test("Translation of a..b") { | ||
forSetWithPredicates(rangeGen, postPredE, postPredA) | ||
} |
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.
What are the properties being tested for here? It's not clear to me from the names of the test. I can see that you are testing certain transformations, but it would help with readability of the tests IMO to include in the name what properties of the transformations are being checked for.
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.
In my experience, the point of property based tests it to end up with something that looks like: "forall x: T. P(x)where the
Tis determined by generators of expressions of the appropriate type, and
Pis the test of what should hold of every instance of
x`. I am not really able to figure out whether that is happening in these tests in some way. Maybe after the fix discussed with Gabriela that will be clearer for me. I'll check back after those changes are int!
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.
If you want the above formulation, P(ex) := transform((\E | \A) x \in S: p(ex)) = (\E | \A) x: q(ex)
,
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.
Basically, does the transformation have the expected shape for Q
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.
I like the implementation, only a few comments there.
The tests, I found rather difficult to follow. I think this can be resolved with some restructuring and renaming, see my comments inline.
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/IntegerQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/IntegerQuantificationOptimizer.scala
Show resolved
Hide resolved
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/IntegerQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/IntegerQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/IntegerQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/IntegerQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
*/ | ||
|
||
@Singleton | ||
class IntegerQuantificationOptimizer(tracker: TransformationTracker) extends TlaExTransformation { |
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.
General question, do we have a naming scheme for these? I see both Optimizer
s and Simplifier
s in the codebase, is there any difference?
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.
Not really. IMO a simplifier translates an expression into another expression that is equivalent under certain conditions and structurally simpler. An optimizer may produce a more complex expression, which nevertheless improves performance.
tla-pp/src/test/scala/at/forsyte/apalache/tla/pp/TestQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
tla-pp/src/test/scala/at/forsyte/apalache/tla/pp/TestQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
tla-pp/src/test/scala/at/forsyte/apalache/tla/pp/TestQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
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 a few comments, as there are good reviews already. I agree with Thomas that these transformations are not about optimizations. Maybe they are simplifications.
*/ | ||
|
||
@Singleton | ||
class IntegerQuantificationOptimizer(tracker: TransformationTracker) extends TlaExTransformation { |
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.
Not really. IMO a simplifier translates an expression into another expression that is equivalent under certain conditions and structurally simpler. An optimizer may produce a more complex expression, which nevertheless improves performance.
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/IntegerQuantificationOptimizer.scala
Outdated
Show resolved
Hide resolved
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.
LGTM!
Thank you for taking the time to add this feature in incrementally! :)
* https://github.com/apalache-mc/apalache/blob/main/docs/src/apalache/known-issues.md#integer-ranges-with-non-constant-bounds * apalache-mc/apalache#425 * apalache-mc/apalache#1431 Github issue heidihoward#5 heidihoward#5 [Apalache] Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
* https://github.com/apalache-mc/apalache/blob/main/docs/src/apalache/known-issues.md#integer-ranges-with-non-constant-bounds * apalache-mc/apalache#425 * apalache-mc/apalache#1431 Github issue #5 #5 [Apalache] Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
make fmt-fix
(or had formatting run automatically on all files edited)First part of #1407, without the plumbing.