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

Finished task 139 #22

Merged
merged 4 commits into from
Oct 3, 2024
Merged

Finished task 139 #22

merged 4 commits into from
Oct 3, 2024

Conversation

amarshah1
Copy link
Contributor

No description provided.

Copy link
Contributor

@parno parno left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this! Looks like there was some tricky math involved in your proof.

use vstd::prelude::*;

verus! {

// TODO: Put your solution (the specification, implementation, and proof) to the task here
// specification
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit tricky to map this spec to the one in the prompt. Could we instead use something like this?

    spec fn factorial(n: int) -> int 
        decreases n,
    {
        if n <= 1 {
            0
        } else {
            n * factorial(n - 1)
        }
    }

    spec fn brazilian_factorial(n: int) -> int 
        decreases n,
    {
        if n <= 1 {
            factorial(1)
        } else {
            factorial(n) * brazilian_factorial(n - 1)
        }
    }


pub fn brazilian_factorial_impl(n: u32) -> (bf: u32)
requires
0 < n < 4294967295,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you replace 4294967295 with u32::MAX to make the intent clearer?

I also suspect that the next requirement is a strictly stronger requirement, no?

I'm also a bit reluctant to have a requirement that asks that you already know something about the thing you're about to compute. Could we instead use a strategy similar to this version of fib?

@amarshah1
Copy link
Contributor Author

The changes have been made. Thanks for the suggestion! This way is much simpler. I also changed 255 to u8::MAX in task025 (everything else stays the same)

@parno
Copy link
Contributor

parno commented Oct 3, 2024

Great, thanks for the changes!

@parno parno merged commit ea898a4 into secure-foundations:main Oct 3, 2024
1 check passed
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.

2 participants