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

add corres_cases method #649

Merged
merged 3 commits into from
Jun 26, 2023
Merged

add corres_cases method #649

merged 3 commits into from
Jun 26, 2023

Conversation

lsf37
Copy link
Member

@lsf37 lsf37 commented Jun 23, 2023

Add safe datatype case distinction for corres -- wpc turns out to be insufficient even after generalisation of the helper predicate.

  • corres_cases_left: case distinction on abstract monad
  • corres_cases_right: case distinction on concrete monad
  • corres_cases: case distinction first of abstract/concrete monad
  • corres_cases_both: simultaneous (quadratic) case distinction on both sides, with safe elimination of trivially contradictory cases

Main intended benefit is less thinking about safety of schematics, fewer mentions of goal parameter names, and fewer manual guard instantiations.

The PR also removes the old defunct wpc setup for corres and changes a few proofs in refine/ARM to demonstrate how the method is intended to be used.

@lsf37 lsf37 force-pushed the corres-cases branch 2 times, most recently from dd87188 to 855554c Compare June 23, 2023 00:41
@lsf37 lsf37 self-assigned this Jun 23, 2023
@lsf37 lsf37 added proof engineering nicer, shorter, more maintainable etc proofs proof tools convenience, automation, productivity tools labels Jun 23, 2023
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
Copy link
Member

@Xaphiosis Xaphiosis left a comment

Choose a reason for hiding this comment

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

I am happy with the methods and the improvement they provide. Nice! I also like that they manage to do what they do concisely. If I tried to to it, it could've ended up an over-engineered mess. This approach ends up very neat.

I do have some difficulty following some of the textual descriptions, and wonder if I'm too ignorant to be the target audience, or whether the descriptions could become easier. A few Englishisms snuck in there as well.

@lsf37 lsf37 force-pushed the corres-cases branch 2 times, most recently from c57a697 to bae8646 Compare June 26, 2023 01:37
@lsf37
Copy link
Member Author

lsf37 commented Jun 26, 2023

(updated with Raf's review feedback)

lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Outdated Show resolved Hide resolved
@Xaphiosis
Copy link
Member

Last typos, otherwise I'm happy with it, the explanations are now ones I can follow. Thank you!

lib/Corres_Cases.thy Outdated Show resolved Hide resolved
lib/Corres_Cases.thy Show resolved Hide resolved
Copy link
Member

@corlewis corlewis left a comment

Choose a reason for hiding this comment

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

Very cool work, the examples demonstrating the reduced need for manual instantiation are particularly encouraging.

My only remaining confusion is why wpc seems to work in crefine. Do we just avoid the cases where the guards don't depend on the bound variable being split? If so that suggests we might want something very similar to this for ccorres as well.

@lsf37
Copy link
Member Author

lsf37 commented Jun 26, 2023

My only remaining confusion is why wpc seems to work in crefine. Do we just avoid the cases where the guards don't depend on the bound variable being split? If so that suggests we might want something very similar to this for ccorres as well.

I was thinking that the problem doesn't occur in ccorres, because we don't have a normal rv thing going on on the C side, and I thought that eliminates the problem. But a) we do have things like symbolic execution, and b) that actually makes the problem worse, because the abstract guard will depend on abstract goal parameters, and the C guard will not, which is exactly the case I'm trying to solve.

So I think you're right and we should probably be doing the same thing for ccorres. Do we have cases where wpc mysteriously doesn't work on ccorres? (because that's probably because of exactly this issue).

@lsf37
Copy link
Member Author

lsf37 commented Jun 26, 2023

I'll leave ccorres for another time, but I think Corey is right and it would probably benefit from the same treatment, which means we can likely reduce wpc to just single-guard cases which should make it a bit simpler again.

Doing ccorres properly is going to be slightly annoying, because for corres the abstract and concrete guard are interchangeable, so the same processing rules work for them. But for ccorres the type determines which one is concrete and which one is abstract. On the other hand, I don't think we want to do cases on the C side anyway, so maybe it's not so bad.

All of this now gives me ideas that we could include a thing for if .. then .. else in corres_cases as well. Hm. Tempting.

@corlewis
Copy link
Member

So I think you're right and we should probably be doing the same thing for ccorres. Do we have cases where wpc mysteriously doesn't work on ccorres? (because that's probably because of exactly this issue).

I don't know about one with wpc, but I have definitely had cases in ccorres where I wanted to split a concrete IF .. THEN .. ELSE .. and the abstract precondition didn't have the required bound variable.

@lsf37
Copy link
Member Author

lsf37 commented Jun 26, 2023

So I think you're right and we should probably be doing the same thing for ccorres. Do we have cases where wpc mysteriously doesn't work on ccorres? (because that's probably because of exactly this issue).

I don't know about one with wpc, but I have definitely had cases in ccorres where I wanted to split a concrete IF .. THEN .. ELSE .. and the abstract precondition didn't have the required bound variable.

Right, that's another case we should treat. I should probably start collecting these in an issue.

Add safe datatype case distinction for corres -- wpc turns out to be
insufficient even after generalisation of the helper predicate.

- corres_cases_left: case distinction on abstract monad
- corres_cases_right: case distinction on concrete monad
- corres_cases: try first corres_cases_left, then corres_cases_right
- corres_cases_both: simultaneous (quadratic) case distinction on
  both sides, with safe elimination of trivially contradictory cases.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
This setup didn't actually work. Replaced by corres_cases.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
Demonstrates use of corres_cases and corres_cases_both. Main intended
benefit is less thinking about safety of schematics, fewer mentions
of goal parameter names, and fewer manual guard instantiations.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
@lsf37 lsf37 merged commit 59759ed into master Jun 26, 2023
14 checks passed
@lsf37 lsf37 deleted the corres-cases branch June 26, 2023 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proof engineering nicer, shorter, more maintainable etc proofs proof tools convenience, automation, productivity tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants