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

[Assignment #5] finding good loop invariant #379

Closed
brongs2 opened this issue Oct 3, 2024 · 5 comments
Closed

[Assignment #5] finding good loop invariant #379

brongs2 opened this issue Oct 3, 2024 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@brongs2
Copy link

brongs2 commented Oct 3, 2024

Related Issue

No response

Googling Result

https://stackoverflow.com/questions/2935295/what-is-the-best-way-of-determining-a-loop-invariant

ChatGPT Result

https://chatgpt.com/c/66fe4982-506c-8003-abf7-9f09b1ae39bb

Your question here

To find the loop invariant of pascal's triangle
I can observe that elements of new_row is same to comb r k, but this invariant does not pass the test
loop invariant preservation error since my loop invariant is not good invariant
can anyone help what I missing?
thank you

@brongs2 brongs2 added the question Further information is requested label Oct 3, 2024
@Jaewookim08
Copy link
Collaborator

Jaewookim08 commented Oct 3, 2024

I can't tell exactly what's wrong just from the description, but here is some general advice:

  • Remember that the invariant must always hold at the start of the loop, even if not all elements of new_row have been assigned yet.
  • The invariant must carry enough information to ensure that each iteration’s invariant, combined with the loop body code, can be used to prove the invariant for the next iteration.

If you need more help, feel free to provide additional context.

@brongs2
Copy link
Author

brongs2 commented Oct 3, 2024

Thank you for your comment,
I wonder if I need to specify the characteristic of Combination which nCr = n-1Cr-1 + n-1Cr
if it does, then why?
thank you

@Jaewookim08
Copy link
Collaborator

I'll have to check, but I'm fairly certain you don't need to since the lemma should already be in the library.

@brongs2 brongs2 closed this as completed Oct 3, 2024
@brongs2 brongs2 reopened this Oct 3, 2024
@brongs2
Copy link
Author

brongs2 commented Oct 3, 2024

to induce row[c] = r-1Cc,
suppose row[c] = r-1Cc if new_row[0] =rC0 , new_row[r] = rCr, if 1 <= i < c, then new_row[i] = row[i] + row[i-1], then by lemma, new_row[i] = = r-1Ci + r-1Ci-1 = rCi, so I expect that row[c] = new_row[c] = rCc for all c
then why the machine cannot induce row[c] = rCc?

@Jaewookim08
Copy link
Collaborator

Jaewookim08 commented Oct 4, 2024

The issue was troubleshot during office hours. It was caused by using too few steps when working with www.why3.org/try/.

For all students, try using 1,000 to 5,000 steps if Why3 is not working as expected. I'll add warnings in the instructions.

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

No branches or pull requests

4 participants