Made fromIntegerNat use case
instead of if
#4357
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using
if
with anassert_smaller
could cause infinite compile-time looping. To prevent this, a pattern match on0
was needed, but functions that match on Integers don't reduce in proofs. This should fix that forfromIntegerNat
by avoiding the original issue (tested, this version doesn't loop on\i=>fromIntegerNat i
at the REPL, which the old version did without the0
match).The new code has been tested correct for (-1), 0, 5, 10, 100, 1000 and 1234. It does seem to be slightly slower than the original, but neither is very fast. Proving things for
Integer
is probably still not a good idea, but it should now at least be possible to convert aSo (i > 0)
to anIsSucc (fromIntegerNat i)
, in theory (untested, I'm bad at proofs, butcompute
does now reducefromIntegerNat i
to acase
block).As a minor simultaneous change, the
fromIntegerNat
takes an argumenti
, forInteger
, rather thann
forNat
.