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

Integer Sequences #15

Merged
merged 12 commits into from
Oct 3, 2021
Merged

Integer Sequences #15

merged 12 commits into from
Oct 3, 2021

Conversation

sarahc7
Copy link
Contributor

@sarahc7 sarahc7 commented Sep 7, 2021

Hi everyone! Thanks for all of your valuable feedback on the Collections and NonlinearArithmetic sections of the library. We have since added NatSeq. Any comments are appreciated :)

Here is the original standard library discussion.

Copy link
Member

@robin-aws robin-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh look, Robin is nit-picking about naming once again. :)

This is really cool stuff, thanks for contributing it! I didn't look too hard at the lemmas just yet as I want to see how my suggestion of using FoldLeft and FoldRight plays out first.

Out of curiosity, do you also have an implementation of Base64 built on this waiting in the wings too?

src/NativeTypes.dfy Outdated Show resolved Hide resolved
src/NativeTypes.dfy Outdated Show resolved Hide resolved
src/NativeTypes.dfy Outdated Show resolved Hide resolved
examples/NatSeq/NatSeqExample.dfy Outdated Show resolved Hide resolved
examples/NatSeq/NatSeqExample.dfy Outdated Show resolved Hide resolved
src/Collections/Sequences/NatSeq.dfy Outdated Show resolved Hide resolved
}

/* Converts a sequence to a nat beginning from the most significant word. */
function method {:opaque} ToNatRev(xs: seq<uint>): nat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use the "Rev" suffix as I incorrectly assumed it meant this function would behave like ToNat(Seq.Reverse(xs)). Perhaps these two functions could be ToNatLeft and ToNatRight?

In fact, now I'm curious whether these could use Seq.FoldLeft and Seq.FoldRight instead. If they can't, that feels like an indication we need more lemmas on those Fold functions for them to be actually useful. :)

src/Collections/Sequences/NatSeq.dfy Outdated Show resolved Hide resolved
Comment on lines 28 to 29
function method BOUND(): nat
ensures BOUND() > 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative is to declare this nullary function as a const. To get the > 1 property, you can then either give a body-less lemma

lemma BoundAtLeastTwo()
  ensures 2 <= BOUND

or declare (here or, better, elsewhere) a type

type Plural = x | 2 <= x

and declare BOUND to be of this type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does seem cleaner, but we'd like to initialize BOUND in the refining modules

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting an error from this small example:

module Test {
  type LessThan10 = x | 0 <= x < 10
  const C: LessThan10
}

module Test' refines Test {
  const C: LessThan10 := 5
}
Process terminated. Assertion failed.
   at Microsoft.Dafny.Resolver.ResolveTopLevelDecls_Core(List`1 declarations, Graph`1 datatypeDependencies, Graph`1 codatatypeDependencies, Boolean isAnExport) in /private/tmp/dafny-20210205-34509-rqus4y/dafny-3.0.0/Source/Dafny/Resolver.cs:line 2644
   at Microsoft.Dafny.Resolver.ResolveModuleDefinition(ModuleDefinition m, ModuleSignature sig, Boolean isAnExport) in /private/tmp/dafny-20210205-34509-rqus4y/dafny-3.0.0/Source/Dafny/Resolver.cs:line 1002
...

Am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RustanLeino Did you have thoughts on this issue? I think this may be the last item holding up this PR. If function vs. const is a minor concern, perhaps we can merge this PR and then address the bug above and consider converting to a const in a future PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is the right path forward. It's unfortunate since fixing this later will be a breaking change for any refining users, but worth doing while we're still reserving the right to make such changes in these libraries.

I cut dafny-lang/dafny#1481 for the underlying issue and #21 to track the improvement once that is addressed.

src/Collections/Sequences/NatSeq.dfy Outdated Show resolved Hide resolved
src/Collections/Sequences/NatSeq.dfy Outdated Show resolved Hide resolved
src/NativeTypes.dfy Outdated Show resolved Hide resolved
src/Collections/Sequences/NatSeq.dfy Outdated Show resolved Hide resolved
@parno
Copy link
Contributor

parno commented Oct 2, 2021

@robin-aws Just to check in, where are we on merging this in?

@robin-aws
Copy link
Member

Apologies @parno, I misremembered Rustan's comment as the blocker and forgot I had requested changes.

@parno
Copy link
Contributor

parno commented Oct 3, 2021

No problem -- thanks for merging it in!

@sarahc7
Copy link
Contributor Author

sarahc7 commented Oct 4, 2021

Thank you @robin-aws and @RustanLeino for reviewing! I appreciate all the feedback on our PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants