coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Agnishom Chattopadhyay <agnishom AT cmi.ac.in>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] How do I simplify a particular redex exactly once?
- Date: Thu, 28 May 2020 09:19:28 -0500
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=agnishom AT cmi.ac.in; spf=Pass smtp.mailfrom=agnishom AT cmi.ac.in; spf=None smtp.helo=postmaster AT mail.cmi.ac.in
- Ironport-phdr: 9a23:rDJgABPi0dFWSu7abX4l6mtUPXoX/o7sNwtQ0KIMzox0I/77rarrMEGX3/hxlliBBdydt6sZzbOM7eu6CCQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTagYb5+Ngi6oRvQu8UZn4dvLrs6xwfUrHdPZ+lY335jK0iJnxb76Mew/Zpj/DpVtvk86cNOUrj0crohQ7BAAzsoL2465MvwtRneVgSP/WcTUn8XkhVTHQfI6gzxU4rrvSv7sup93zSaPdHzQLspVzmu87tnRRn1gygAKjA57XrXitRug61HvBKvqRt/w4vOb4GUMvp1Y6fRcNweSGZEWMtaSi5PDZ6mb4YXAOUBM+RXoYnzqVUNsBWwGxWjCfj1xTNUnHL7x7E23/gjHAzAwQcuH8gOsHPRrNjtKKoSXua1zKjTzTXDaPNW3Cr25ZbIch87vfGMQbVwcdLLxkYyFwPEjk+fqIz4ND6SzOsNvG6b7+t7VeKvjG4nrhp8rSSqxsctkIXGnJ4axkrF9SV/2Ys4I8CzR0Fnb9C+CpRQqz2aOJVsQsMkW2xkpDo2x78FtJOnfyUEx5Yqyh7BZvGJc4WG7BztWfuMLDpli39reK+ziRa9/ES8xODyVse63VVEoydZjNTBqnEA2hrO4caJTft9+12u2TeJ1w3L5eFEIFw0larGK5E62LIwl50TvVzCHi/wgkX2jbWZel8q+uiy7ensf7bopoeEOoNplw3zMr4iltKwDOk7KAQCQXWX9f6h2LDg4UH1WKtGguEyn6XDs53XJd4XqrO4DgJUyIou5AuzAjG729oCh3YHNkhKeBefgojpJV7OJPf4AO+6g1u2kTdrw+rKMaHkApXMNHTMiqvucax8605a0AYzzNZf6IxICrwZPf7/R0/8uMbGAhI2MAG42fjrBMhn2o8DWm+DHreVMKbIvl+J4uIvLfOMZIgQuDvlMfcl6PjujX4imV8deqmp2IAaZ2y9HvRnOUmWe2bjjs0AEWcMpgY+VvDliEWeUT5PYHa/R74z5jYiCI6/EYjDQp2tj6ea0SegHpxWY3hGBUqWHXfpcYWEQfYMZziILs9viDxXHYSmHoQmzFSlsBLw47thNOvdvCMC5rz5090gzuLVlAoy8jk8JMSUz32KV2h4nnIBVndi1a95oFd9zVKr2q15xfVTU91VsaAaGjwmPILRmrQpQ+v5XRjMK4vYEQf0cpCdGTg0C+kJ7ZoLakd5Fc+li0majSGvAvkcnPqKAs5tq/6O7z3KP894jk3++uw5lVB/G5lEMGzgj6U59g6BX9eUwXXcrL6jcOEn5ACI9GqHyjPQ7kRRUQo2WqDEG3kUIErQ/4z0
Change with patterns seem like a very good idea. I have not used patterns very much yet.
I should also look into the Equations package.
Thanks all!
On Thu, May 28, 2020 at 9:15 AM Yannick Forster <yannick AT yforster.de> wrote:
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+.