coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Clément Pit-Claudel <cpitclaudel AT gmail.com>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] How do I simplify a particular redex exactly once?
- Date: Thu, 28 May 2020 12:30:59 -0400
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=cpitclaudel AT gmail.com; spf=Pass smtp.mailfrom=cpitclaudel AT gmail.com; spf=None smtp.helo=postmaster AT mail-qt1-f172.google.com
- Ironport-phdr: 9a23:Zaz2XRK3tD+r/rpGy9mcpTZWNBhigK39O0sv0rFitYgfKvvxwZ3uMQTl6Ol3ixeRBMOHsq8C0rCI+PqxEUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCe9bL9oMRm6swTcusYIjYZmN6081gbHrnxUdupM2GhmP0iTnxHy5sex+J5s7SFdsO8/+sBDTKv3Yb02QaRXAzo6PW814tbrtQTYQguU+nQcSGQWnQFWDAXD8Rr3Q43+sir+tup6xSmaIcj7Rq06VDi+86tmTgLjhSEaPDA77W7XkNR9gr9FrhKvpxJxwIDab4+aO/V8YqzTcsgXRXZCU8tLSyBNHo2xYokJAuEcPehYtY79p14WoBagAQmrHubvxSFOhn/qxaI0yeUhER3f0AE+G9IBqmnUo8jrO6cWTOu4y7XHzS3Cb/NKxTj97JLHcg08rv6SWbJ9asXRyUw1GAPEilWcs5DqPzSQ1ukUtWWQ8uVvW/61hWE9twFxviagxt0qioTRhY8Yzl7J+Cp7zYg6J9C2R1J2bNykHZZRqyyXM4l7Tt0tTmxruis3yaALtIO1cSQXyJkpyQDSZv+FfoaI7RzuVOCcKip7inJ9YL+zmQq+/Ey6xuD/VsS4yktGoytZntXWq3wA1QLf5tCZRvZ84kutxDOC2x3Q5+xLJE05mrfXJp09zrM1l5cesFrMEy3zlUrtkaCZbEUp9+2y5Ov7YrjpupqRO5JphQ7gLqgjn9ewDOU6PwUMWWWQ5P6y26f5/ULjRbVHlv02nbfdsJDdPckbo7S2Aw5R0oo68ha/Eyqq3M0WnXUaLl9JZgiLj4fuO1HJL/D4Cemwj06wnzdswvDKJrzhApPTIXjfiLrtY6px5kpGxAcwzd1T/Y9YB7AdLP7pR0P8tsLUAgc8MwOuwubnDNt91pkZWWKKGqKWLLvSsV6U5u0zJ+mDfpIVtyvjJPgh/PPugno5lkUcfamtx5cYdHe4HvF+L0WDfXXsmssBEXsNvgcmUOPqj0SCXSdPaHa2QqIz/So2CJmmDIfGXoCimqaN3Ca9Hp1MZ2BJEEqAEXnyd9bMZ/BZYyWLZ8RljzYsVL67SoZn2wv9mhX9zu9MKmvR9ysEgqriyJ1e4+TOmRw2vWh/F8WB2GWEUm15mksHQjY32OZ0pkkrmQTL6rRxn/ENTY8b3PhOSApvbceBndw/MMj7X0f6RvnMSFuiRY/4UzQ4T9Z02sNXJkgkRI/kgRfE0C6nRbQSku7TXcBmwufnx3H0Yv1F5TPezqB41gspR8JOMSutgastr1GCVb6MqF2QkuORTYpZ2SfM8GmZym/X5RNXVQdxVePOWnVNP0Y=
On 27/05/2020 11.55, Agnishom Chattopadhyay wrote:
> Now, let's say I have a proof and I have an expression e = (FAnd (FOr f g)
> h), and I am trying to simplify (eval e x). If I simply suggest `simpl.`,
> Coq simplifies it all the way down. How can I control simpl so that only
> the first FAnd is simplified but the FOr is not?
>
> Currently, I am using "replace ... with ... " but this requires me to type
> out all the details, which is very painful. The actual formula and eval
> that I have are more complex than this.
>
> Another option seems to be `remember (FOr f g) as z.` and then doing
> `simpl.`, but this is also not very nice since I have to copy large chunks
> of the expression to my proof.
This is a common problem with recursive functions in Coq. Two tricks I like:
1. Define a set of equations for your function, which you can then use to
rewrite:
Open Scope bool_scope.
Lemma eval_FAnd {A : Type} (f g : @Formula A) (x : A) :
eval (FAnd f g) x = (eval f x) && (eval g x).
Proof. reflexivity. Qed.
(* more equations here *)
Goal forall {A} (f g h: @Formula A) x,
exists y, eval (FAnd (FOr f g) h) x = y.
Proof.
eexists.
rewrite eval_FAnd.
Abort.
You can also look at the Equation plug-ins — I keep hearing good things
about it. This solution quickly gets old quickly if you have many cases,
though, because you need to define the lemmas. Also, the rewrites can get
costly.
2. Define an unfolding function, which does one step of unfolding for you:
Definition eval1 {A : Type} (f : @Formula A) (x : A) : bool :=
match f with
| FAtomic f => f x
| FAnd f g => (eval f x) && (eval g x)
| FOr f g => (eval f x) || (eval g x)
end.
Goal forall {A} (f g h: @Formula A) x,
exists y, eval (FAnd (FOr f g) h) x = y.
Proof.
eexists.
change (eval ?f ?x) with (eval1 f x). (* No need to rewrite, even! *)
cbv [eval1].
Abort.
Of course, it's still annoying to have to duplicate the function, so you
can automatically define it:
Ltac unfold_once expr param :=
pose expr as result;
destruct param; cbn in result;
lazymatch goal with
| [ _ := ?result |- _ ] => exact result
end.
Definition eval1_auto' {A : Type} (f : @Formula A) (x : A) : bool.
unfold_once (eval f x) f.
Defined.
Goal forall {A} (f g h: @Formula A) x,
exists y, eval (FAnd (FOr f g) h) x = y.
Proof.
eexists.
change (eval ?f ?x) with (eval1_auto' f x).
cbv [eval1_auto'].
Abort.
Here's a slightly cleaner definition, too:
Definition eval1_auto {A : Type} (f : @Formula A) (x : A) : bool.
let r := constr:(ltac:(unfold_once (eval f x) f)) in
let r := eval cbv zeta in r in
exact r.
Defined.
- [Coq-Club] How do I simplify a particular redex exactly once?, Agnishom Chattopadhyay, 05/27/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, jonikelee AT gmail.com, 05/27/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Jan-Oliver Kaiser, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Clément Pit-Claudel, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Christian Doczkal, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, jonikelee AT gmail.com, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Christian Doczkal, 05/28/2020
Archive powered by MHonArc 2.6.19+.