coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Heiko Becker <hbecker AT mpi-sws.org>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] [HELP] All branches of `match` yield same value
- Date: Wed, 17 Jan 2018 16:01:27 +0100
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=hbecker AT mpi-sws.org; spf=Pass smtp.mailfrom=hbecker AT mpi-sws.org; spf=None smtp.helo=postmaster AT juno.mpi-klsb.mpg.de
- Ironport-phdr: 9a23:4pmdKh2yYzN94oqhsmDT+DRfVm0co7zxezQtwd8Zse0WIvad9pjvdHbS+e9qxAeQG9mDsrQc06L/iOPJYSQ4+5GPsXQPItRndiQuroEopTEmG9OPEkbhLfTnPGQQFcVGU0J5rTngaRAGUMnxaEfPrXKs8DUcBgvwNRZvJuTyB4Xek9m72/q99pHPfglEniaxba9vJxiqsAvdsdUbj5F/Iagr0BvJpXVIe+VSxWx2IF+Yggjx6MSt8pN96ipco/0u+dJOXqX8ZKQ4UKdXDC86PGAv5c3krgfMQA2S7XYBSGoWkx5IAw/Y7BHmW5r6ryX3uvZh1CScIMb7S60/Vza/4KdxUBLmiDoJOSA38G/UhMJ/gq1UrxC9qBFk2YHYfJuYOeBicq7Tf94XQ3dKUMZLVyxGB4Oxd4kBAPQAPeZbqIn2ukYDogWiCgmvGuzv0CJDi3j23aIhzesuDQLG0xI6H98VtXTUtNT1OL4JUeG716nE1zLDb+lZ2Trk7oXDbxMvoemUUL5tf8fczVMjGx7Bg1mKqoHoPimZ2+sRv2SD8uZtW+aih3Q6pwx1uDSj28Yhh4rTio8a1FzJ8zhyzpwvKt2iUkF7ZMapEJtOuCGeMIt7WsEiQ3xuuCY90LEGvIa7fCkTxJQkwx7fcOeIf5KN4hL7W+adOyp3i2x9dLK+gRa971Sgx/XhWsS61FtGtDdJn93Wun0O1hHf8MeKRudl8kekwzmP1gTT6u9eIUAzkKrWM54hzaUumZUPskTMADX2lV7zjK+Od0Uo4/Oo6ur8Yrn8oZ+cLYB0hhnkMqsygsy/Hfg4Mg8WUmeH/uS8zaTv8lH9QLVXlfI7ibLZsZDfJcQDvKG1GQ5V0oA56xa+FTiqytoYnWNUZG5CLRmAls3iP0zECPH+F/a2xVq2wxlxwPWTHrDgAZKFBHXIk7r7NeJ94UNXywcp5dVH5tdPFapHJ+j8DByi/OfEBwM0ZlTni93sD89wg9tHCDC/R5SBOaaXimemo+cmIu2CfogQ4W2vLuAkouXxljk+g1BPJPD1j6tSU2ixG7FdG2vceWDl24xTFH8L+xEhV6rtklLQCWcONUb3ZLo143QAMKzjDYrHQdr30r6c2iD9G4VXI2NCEVrKFG/nMYmJCa8B
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 in match 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) | _ => None end) | _ => None end) | _ => None end.
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.