coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Merlin Göttlinger <megoettlinger AT gmail.com>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] [HELP] All branches of `match` yield same value
- Date: Wed, 17 Jan 2018 15:43:37 +0000
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=megoettlinger AT gmail.com; spf=Pass smtp.mailfrom=megoettlinger AT gmail.com; spf=None smtp.helo=postmaster AT mail-io0-f175.google.com
- Ironport-phdr: 9a23:S/t+EBx5mndgQ1HXCy+O+j09IxM/srCxBDY+r6Qd1OgfIJqq85mqBkHD//Il1AaPAd2Craocw8Pt8InYEVQa5piAtH1QOLdtbDQizfssogo7HcSeAlf6JvO5JwYzHcBFSUM3tyrjaRsdF8nxfUDdrWOv5jAOBBr/KRB1JuPoEYLOksi7ze+/94HObwlSmDaxfa55IQmrownWqsQYm5ZpJLwryhvOrHtIeuBWyn1tKFmOgRvy5dq+8YB6/ShItP0v68BPUaPhf6QlVrNYFygpM3o05MLwqxbOSxaE62YGXWUXlhpIBBXF7A3/U5zsvCb2qvZx1S+HNsDwULs6Wymt771zRRDnhicINT43/m/UhMJtkqxUvAmsqAZjz4POeoyZKOZyc6HbcNgHRWRBRMFRVylZD427cYQPFe4BPeder4blplUWqwe+BRWoBOPuzD9IiWH53bcn2OkmFAHJwgMgH9UQv3TIsNX1MKYSUea6zKbW1zXOdPxW2TLn54jJdhAtu+2DXbV1ccfIz0QkCgDLjk2IpID7Iz+Y0v4Bvmub4uZ6S+6jlWAqpxtsrjWtxsohjJTCiJgPxVDe7yp5xZ44Jd2mR05/Zt6pCJ5QuDubN4tyW88iQmZotDojxr0IpJK2figHxI4oxx7YbPyHfIyI7Qz5WOmNJjd4gWppeLO5hxms7Uit0vPwWtWw3VpQrSdIksPAum4T2xHd8MSLV/lw80e51TaKzQ/T6+VEIU4ularcLp4s2rswmYQcsUTEACD2hFn2jKuXdkUi9ein9f7nb67ppp+ZLYB0iwX+Pr4ylcy4BOQ0KhIOUHSD+eSgyL3j+lX0T6lNjv0vi6XWrJTaJdkAqaOiGA9U0oMj6w6lADu80dQYm2MHLFNfdx6dgYjpIQKGHPetBvCmxl+ojT1DxvbcP7SnDI+eAGLEleLEcKx56khr55Qv0dRe4Z1ZEPlVJf/8XULtqNjZCBA0KSS7xu/mDJN20YZICjHHObOQLK6H6QzA3ekoOeTZPNZE6ga4EOAs4rvVtVF8nFYceaez2p5OMSK3G/1nJwOSZn++245dQ1dPhRI3SanRsHPHSSRaPi/gUKc15zV9A4WjX9+aG9KdxYeZ1SL+JaV4I2BLDlfWTyXtfoSAHvYLMGece5A81DMDUrelRskq0hT87AI=
Hi,
while not really being automated, I use this tactic to deal with equalities on match hypotheses:
Ltac match_hyp := match goal with
| [_ : match ?p with _ => _ end = _ |- _] => destruct p; simpl
end.
Note that you can match on match ... with ... in Ltac but not on the specific cases in the match.
If you run repeat match_hyp it should solve the original question, right?
Cheers,
Merlin
Heiko Becker <hbecker AT mpi-sws.org> schrieb am Mi., 17. Jan. 2018 um 16:02 Uhr:
Hello,
recently I had similar issues.
I tried automating similar reasoning over multiple proofs.
As it turns out, you cannot directly match on a "match ... with ..." in an ltac match-goal phrase.
So I came up with the following code that may help you:
Definition optionLift (X Y:Type) (v:option X) (f:X -> Y) (e:Y) :=
match v with
|Some val => f val
| None => e
end.
Lemma optionLift_eq (X Y:Type) v (f:X -> Y) (e:Y):
match v with |Some val => f val | None => e end = optionLift X Y v f e.
Proof.
reflexivity.
Qed.
Ltac remove_matches := rewrite optionLift_eq in *.
Ltac match_factorize_asm :=
match goal with
| [ H: ?t = ?u |- context [optionLift _ _ ?t _ _]]
=> rewrite H; cbn
| [ H1: ?t = ?u, H2: context [optionLift _ _ ?t _ _] |- _ ]
=> rewrite H1 in H2; cbn in H2
| [ H: context [optionLift _ _ ?t _ _] |- _ ]
=> destruct t eqn:?; cbn in H; try congruence
end.
Ltac match_factorize :=
match_factorize_asm ||
match goal with
| [ |- context [optionLift _ _ ?t _ _] ]
=> destruct t eqn:?; cbn; try congruence
end.
As I was dealing with a setting where it could be that I had previously inspected parts of the match, the tactic also checks that the term to be destructed is not already an assumption. If you need only prove your goal from below, you can drop these cases.
Additionally, you may want to change the last call in match_factorize, respectively match_factorize_asm into "auto" or "reflexivity" to automatically prove the "None = None" cases you will get.
Maybe this code helps you a bit.
Best,
Heiko
On 01/17/2018 01:28 AM, Ramkumar Ramachandra wrote:
Hi,
I have this code:
Definition augmentReg (reg : registration) (t : serverState) : option block :=let bals := clientBalances t inmatch reg with| mkRegistration _ n (directTransfer k amt) =>(match M.find n bals with| Some bal => (match M.find k bals with| Some bal2 => Some ((mkRegistration 1 n (balance (bal - amt))):: (mkRegistration 1 k (balance (bal2 + amt))) :: nil)| _ => Noneend)| _ => Noneend)| _ => Noneend.Definition augmentReg_zServerState : forall r, augmentReg r zServerState = None.Proof.intros.unfold augmentReg.simpl.Admitted.
And my hypotheses/goals window looks like:
- r: registration
- 1/1match r with | {| body := body |} => match body with | directTransfer _ _ => None | statusUpdate => None | commitment => None | balance _ => None | candidacy _ => None | electionVote _ => None | elected _ => None | resign _ => None | encSchedule _ => None | encScheduleVote _ => None | scheduleVerdict _ => None | encChallenge _ => None | encChallengeVote _ => None | challengeVerdict _ => None | decryption _ _ => None end end = None
What tactic can I use to collapse all the cases?
Thanks.
Ram
- [Coq-Club] [HELP] All branches of `match` yield same value, Ramkumar Ramachandra, 01/17/2018
- Re: [Coq-Club] [HELP] All branches of `match` yield same value, Joachim Breitner, 01/17/2018
- Re: [Coq-Club] [HELP] All branches of `match` yield same value, Heiko Becker, 01/17/2018
- Re: [Coq-Club] [HELP] All branches of `match` yield same value, Merlin Göttlinger, 01/17/2018
Archive powered by MHonArc 2.6.18.