coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Yannick Forster <yannick AT yforster.de>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] How do I simplify a particular redex exactly once?
- Date: Thu, 28 May 2020 16:15:20 +0200
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=Pass smtp.pra=yannick AT yforster.de; spf=Pass smtp.mailfrom=yannick AT yforster.de; spf=None smtp.helo=postmaster AT vela.uberspace.de
- Ironport-phdr: 9a23:Oq104RBClYtzgbLUZc7uUyQJP3N1i/DPJgcQr6AfoPdwSPTzocbcNUDSrc9gkEXOFd2Cra4d1qyP6f6rAz1IyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfLN/IA+roQnPt8QajpVuJ6IswRbVv3VEfPhby3l1LlyJhRb84cmw/J9n8ytOvv8q6tBNX6bncakmVLJUFDspPXw7683trhnDUBCA5mAAXWUMkxpHGBbK4RfnVZrsqCT6t+592C6HPc3qSL0/RDqv47t3RBLulSwIMCM38HzMisxokq1UvA6hqRJ4w47Reo6VNfx+db7Zcd4VQWdNW8BcXDFDDIyhdYsCF/cPM/hWr4f9pFUAoxWxCgauC+zzxTFFnWP20K4g3ug9DQ3L0g4tEtQTu3rUttX1M6ISXPi3w6bSyzXDafJW1iv+6IPVch4hpuuMXalsccXP00kkCgTIj1WKpozjOTOV1/gCs2uA4utgW+KvjHQnqxptojex3McgkJTGiZwMx13C6C52z5o7K8eiR05nfd6rDoFQtyeCOoZ4XM4sTWNltTg1x7MJpJO1cikHxZsjyhPddfCKcYaF7B3tWuuQPTt2hGxodbChixu29UWtxe3xWMa73ltKsCdIlMTHuH4K1xzW8MeHS/1981+u2TaOywDT6vxELlsumaraLJ4t2r8wlpwJsUTCBCD6gkv2jLWQe045+eao8/zqb7Hmq5OGKoN5hQ/zPr4zlsG9H+g0KBUCUmyF9em6ybbt51f2QK9Qgf0ziqTZsI7VJcAcpqOhHQ9azIIj5AylAze7y9sXg2MHLEldeB2dk4fmJUvCL+3mAvunglSslilkx+zeM7DlApjBNGXPnbjvcLpn9kJRyhQ/wcpC659QFL0NOPfzVVXwtNzcAB85KQu0w+P/BdR9zIweX2SPAq6FP6PRqlKJ5uwvI+6WZI8OpDbyNeIl6+TzgnAngVMdZ7Wm3YMLaHCkGfRrO1mWYX31gtsYDWgKuhc+Q/fxhV2ZUT9TYm6yULgm6jE6DoKmF4bDSZq3jLyPxifoVqFRM2tBExWHFWriX4SCQfYFLiyIceF7lTlRZLGnTY4q1lmAsxXh17d9Zr7F8ysetJng/Ml74PfIiRwoszB5WZfOm1qRRn15yztbDwQ927py9BAskwrR4e1Dm/VdUOdrybZJXwM9bM+O0eF+ApbvUA/bZc+AQ1vgTtj0WWhtHOJ0+McHZgNGI/vnlgrKhnH4ErESjaeXCYZy/q+OhiGgdfY48G7P0ewat3djR8JOMWO8gasmrFrCCYnTiFmUjeCmePZF0Q==
Expanding on Maximilian's second idea, if you define eval using the Equations package (http://mattam82.github.io/Coq-Equations/), the wanted equation is auto-generated for you:
Inductive Formula {A : Type} : Type :=
| FAtomic : (A -> bool) -> Formula
| FAnd : Formula -> Formula -> Formula
| FOr : Formula -> Formula -> Formula
.
Require Import Equations.Equations.
Equations eval {A : Type} (f : @Formula A) (x : A) : bool :=
eval (FAtomic f) x := f x ;
eval (FAnd f g) x := (eval f x) && (eval g x) ;
eval (FOr f g) x := (eval f x) || (eval g x)
.
Goal forall f g h, eval (FAnd (FOr f g) h) true = false.
Proof.
intros. rewrite eval_equation_2.
Abort.
Alternatively using the FunInd package (https://coq.inria.fr/refman/language/gallina-extensions.html#coq:cmd.function):
Require Import FunInd.
Function eval {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 f g h, eval (FAnd (FOr f g) h) true = false.
Proof.
intros. rewrite eval_equation.
Abort.
Or completely without changing your definition using Functional Scheme (https://coq.inria.fr/refman/user-extensions/proof-schemes.html#functional-scheme):
Fixpoint eval {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.
Require Import FunInd.
Functional Scheme eval_ind := Induction for eval Sort Prop.
Goal forall f g h, eval (FAnd (FOr f g) h) true = false.
Proof.
intros. rewrite eval_equation.
Abort.
On 28/05/2020 15:54, Maximilian Wuttke wrote:
Hi, I have two ideas.
1. You could use `change` with patterns, like `change eval (FAnd ?t1
?t2) with (eval ?t1 && eval ?t2)`. This way you wouldn't have to spell
out t1 and t2. Also `change` supports `at`.
2. You could use rewriting. Have a rewriting lemma for every 'rule'.
`setoid_rewrite lem at num` could be used to specify the position where
to rewrite (I usually try out different values for `num`).
On 28/05/2020 15:41, Agnishom Chattopadhyay wrote:
I realized that hnf was not working because what I had was something
like "(eval (FAnd (FOr f g) h) x) = ...." but it does seem to work when
I pull out the term and use hnf on it. Is there a way I can use hnf on
one branch of the equality?
The issue with most strategies I can think of is that they are becoming
rather long-winded, and I am having to copy-paste large chunks of the
terms obscuring my proof text, especially for something which is a
rather simple algebraic manipulation
On Wed, May 27, 2020 at 7:08 PM jonikelee AT gmail.com
<mailto:jonikelee AT gmail.com> <jonikelee AT gmail.com
<mailto:jonikelee AT gmail.com>> wrote:
On Wed, 27 May 2020 17:45:55 -0400
"jonikelee AT gmail.com <mailto:jonikelee AT gmail.com>"
<jonikelee AT gmail.com <mailto:jonikelee AT gmail.com>> wrote:
> Sorry, did a non-list send by accident. Resending...
>
> On Wed, 27 May 2020 16:25:29 -0500
> Agnishom Chattopadhyay <agnishom AT cmi.ac.in
<mailto:agnishom AT cmi.ac.in>> wrote:
>
> > No, it did not.
> >
> > Is there a tactic which says "do one step of reduction"?
>
> I have developed beta1 and zeta1 tactics that do one step of those
> reductions, but none that would help here.
>
> Are you sure hnf doesn't work? I tried it, and it seemed to work for
> me:
It might not be working for you if the term is "e = (eval (FAnd
(FOr f g) h) x)" - meaning that the head is equals, not eval. You can
use the set tactic to pull out the rhs of that equation, and use a match
tactic to drive the set:
For instance, if your goal is "e = (eval (FAnd (FOr f g) h) x)", one can
do something like:
match goal with |- e = ?R => let t:=fresh in set (t:=R) in *; hnf in t;
subst t end.
If the equation is intead the type of some hyp H, use "match type of H
with e = ?R ..." instead.
- [Coq-Club] Fw: 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?, jonikelee AT gmail.com, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Agnishom Chattopadhyay, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Maximilian Wuttke, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Yannick Forster, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Agnishom Chattopadhyay, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Yannick Forster, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Maximilian Wuttke, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, Agnishom Chattopadhyay, 05/28/2020
- Re: [Coq-Club] How do I simplify a particular redex exactly once?, jonikelee AT gmail.com, 05/28/2020
Archive powered by MHonArc 2.6.19+.