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

Issue with fold_right and polymorphism #1287

Open
amarshah1 opened this issue Sep 27, 2024 · 0 comments
Open

Issue with fold_right and polymorphism #1287

amarshah1 opened this issue Sep 27, 2024 · 0 comments

Comments

@amarshah1
Copy link

Running this code:

    pub closed spec fn pred<T> (seq1 : Seq<T>, seq2 : Seq<T>) -> bool
        where T: std::marker::Copy + Integer,
    {
        seq1.fold_right(|x, acc : nat| acc + (x as nat), 0) == seq2.fold_right(|x, acc : nat| acc + (x as nat), 0)
    }

    proof fn test (seq1 : Seq<u8>, seq2 : Seq<u8>)
        requires pred(seq1, seq2)
        ensures 
            seq1.fold_right(|x, acc : nat| acc + (x as nat), 0) == seq2.fold_right(|x, acc : nat| acc + (x as nat), 0)
    {}

Results in the verification failing:

error: postcondition not satisfied
  --> minimum_issue.rs:17:5
   |
16 |             seq1.fold_right(|x, acc : nat| acc + (x as nat), 0) == seq2.fold_right(|x, acc : nat| acc + (x as nat), 0)
   |             ---------------------------------------------------------------------------------------------------------- failed this postcondition
17 |     {}
   |     ^^ at the end of the function body

error: aborting due to 1 previous error

verification results:: 0 verified, 1 errors

We think this is an issue with the relationship between fold_right and polymorphism. It verifies if we get rid of the polymorphism. It also verifies if we just replace the body with seq1.fold_right(|x, acc : nat| acc + acc, 0) == seq2.fold_right(|x, acc : nat| acc + acc, 0)

See attached zip file. Thanks!
2024-09-27-16-09-22.zip

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

No branches or pull requests

1 participant