coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Sylvain Boulmé <Sylvain.Boulme AT univ-grenoble-alpes.fr>
- To: coq-club AT inria.fr, Armaël Guéneau <armael.gueneau AT ens-lyon.fr>
- Cc: François Pottier <francois.pottier AT inria.fr>
- Subject: Re: [Coq-Club] How to evaluate reflexive tactics? (in a robust way)
- Date: Thu, 8 Nov 2018 13:19:29 +0100
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=Sylvain.Boulme AT univ-grenoble-alpes.fr; spf=Pass smtp.mailfrom=Sylvain.Boulme AT univ-grenoble-alpes.fr; spf=None smtp.helo=postmaster AT zm-mta-out-1.u-ga.fr
- Ironport-phdr: 9a23:zDlu2hMTJohkRmfuMhcl6mtUPXoX/o7sNwtQ0KIMzox0I/X5rarrMEGX3/hxlliBBdydt6obzbKO+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxlKiTanfb9+MAi9oBnMuMURnYZsMLs6xAHTontPdeRWxGdoKkyWkh3h+Mq+/4Nt/jpJtf45+MFOTav1f6IjTbxFFzsmKHw65NfqtRbYUwSC4GYXX3gMnRpJBwjF6wz6Xov0vyDnuOdxxDWWMMvrRr0vRz+s87lkRwPpiCcfNj427mfXitBrjKlGpB6tvgFzz5LIbI2QMvd1Y6HTcs4ARWdZQ8hfSSJBDIO/YYUBAeUOMuRXoJXmqlsLsRezHxOhCP/hxzJKgHL9wK000/4mEQHDxAEuAtIPsHDKrNrvNacSV/i6wbTPzTXea/NW3C3645XPfx48ofCMWaxwftDQyUkpDQ/Ik1KQqZHhPzOQyOsAqHWb7+xhVeKxkmInpBtxrSapxscrkYbJgpwaxkne+iV92IY6O8a4RFR1Yd6+CZZdsTyROYVxQsMnWW5ouSA6x6UHuZ69ZigKyY4oywTRa/yddYWD/xHtVP6JLDtlhH9pZqizihSw/ES61OHwStW43ExKoydEitXAq24B2hjJ5sWESfZx5Eis1DiV2wzO6exJIUY5nrfBJZE72L4/jJ8TvFzDHiDonEX2i7ebd0Qh+uSx7uTnfq/pqoabN49plgHyK7kiltaiAeghPQgBRXKX+eqm1LH7/E35RqtFjuEun6XEsJ3WO94Xq6y7DgNPzIov9wqzAy2m3dkZhXUHKUhKeBODj4jnIVHOJ/X4AO+ijVWslDdr2erJPrznApnXM3XDl6rhfbJ460FC0wcz0NZf55NKCr0YL/LzQFH+tNrfDhAiNwy73f/rB8951oMGR22PGbWVMK3IsVOQ/OIgP/GMZJMJuDb6M/Uq+/nujWYglVABeampwIAYZWujHvVmJkWZeWDjjs0AEWcMpAo+TfblhEeMUT5Jf3yyRb4z5iknCIK6CofOXo6tgKSG3CenAp1WZ35JCkqXHHbpdoWEXuwDaDiILcN7kzwEU6KhS4472h20ug/60ekvEu2B8SoB8JnnydJd5uvJlBh0+yYwR+2H1mgOS1Zbg+IOSjYrlPR2u0l0x1PF3rV1hfFRCPRe4egMVhY9M9jS1bopJcr1X1f6b9OXQVegdf+hHDU0z5pl+M4KfU98HZOIiQ3H2ieCHrkUifmEHpEy9ajY0j34I95w0DDIzv9y3BEdXsJTODj+1eZE/A/JCtuMyh3Bzvf4ReEnxCfIsVy74y+LtUBcXhR3VP+ZD20ZZ1WTos704ETIS7LrALA/PxAHx9TQc/IWOO2stk1PQbLYAPqbe3i4wTviGBCJ2PaDdofsfG8Z0WDUDFAJiEYd5yTebFVsNmKau2vbSQdWOxfvbkfrq7Msunb+S1M9igaXcwg4kafw9RdTi+bOE/4=
Hello,
I provide below an other example related to Armaël's question.
By default, ring does not benefit from computations over "constants".
This could be painful (see the proof of "painful_test" in attachment).
But, ring provides a way to overcome this limitation, see:
https://coq.inria.fr/refman/addendum/ring.html#adding-a-ring-structure
In particular, the user can provide a tactic (like dummy_cte in attachment) to discriminate between "constants" and other terms.
Is there a standard way to do it ?
In order to have a robust tactic (instead of dummy_cte), we could define a tactic that recognizes closed terms in normal formal form (ie built from constructors of inductive types). But this might not be sufficient in practice (e.g. the rational (4#2) would not be considered as a constant).
Any ideas ?
Sylvain.
Le 08/11/2018 à 11:24, Armaël Guéneau a écrit :
Dear Coq-club,
I'm writing a reflexive tactic that (roughly speaking) simplifies
arithmetic expressions. It first reifies the goal into something like:
Inductive expr :=
| EAdd : expr -> expr -> expr
| EMul : expr -> expr -> expr
| ECst : Z -> expr.
ECst is a catch-all case: it may store arbitrary-looking terms, not only
numerical constants. These should be treated as abstract by the tactic.
Then, I implemented a [simplify : expr -> expr] Coq function, and proved
that it is meaning-preserving. Finally, my tactic reifies the goal,
applies the theorem specialized to the reified expression, and reduces
the result to obtain the simplified goal.
The issue I have is with this last part: I want to evaluate [simplify],
but I do not want the reduction tactic to reduce the contents of [ECst
..], since these can contain arbitrary terms that should be treated as
abstract.
How do I evaluate my tactic in a robust way? I feel like this is a
relatively fundamental issue, and for example I wonder how
[ring_simplifies] works around it? Does anyone know?
For the moment I thought about:
- Listing all the functions transitively used by [simplify] and reduce
with a whitelist (cbv [the functions...]). However: 1) there is a lot of
them 2) it's bad from a maintainability perspective 3) it does not quite
work as the whitelist will include stuff like Nat.eqb that might very
well be used in a [ECst ..].
- Introducing local definitions for the terms in [ECst foo] (using [set
(x := foo)]); and blacklisting these local definitions during reduction.
There is a technical issue: the blacklist is discovered dynamically, so
I cannot specify it in Ltac using cbv -[foo bar baz]. I guess I could
write a small plugin to handle dynamically constructing the blacklist,
if that's what it takes...
Any ideas?
— Armaël
Require Import ZArith. Require Import QArith. Require Import Qcanon. Notation "a # b" := (Q2Qc (a#b)%Q) (at level 55, no associativity) : Qc_scope. Local Open Scope Z_scope. Local Open Scope Qc_scope. Definition Z2Qc z := z#1. Coercion Z2Qc: Z >-> Qc. Lemma painful_test (x:Qc): (2*x-2*(x-1))*x+3*x = 5*x. Proof. ring_simplify. (* ring fails to reduce this to a trivial equality *) cutrewrite (2*x + x*3 = x*(2+3)). - try ring. (* ring fails *) cutrewrite (2+3=5); auto. - ring. Qed. (* Now, we can import computation on scalar into ring we need a tactic to discriminate "constants" over other terms. Here is a simple (non-robust) tactic *) Ltac dummy_cte t := match t with | (Q2Qc _) => t | (Z2Qc _) => t | _ => InitialRing.NotConstant end. Global Add Ring Qcring: Qcrt (decidable Qc_eq_bool_correct, constants [dummy_cte]). Lemma perfect_test (x:Qc): (2*x-2*(x-1))*x+3*x = 5*x. Proof. ring_simplify. auto. Qed. (* An example showing the lack of robustness in dummy_cte *) Lemma test_failure (x:Z): (2*x-2*(x-1))*x+3*x = 5*x. Proof. ring_simplify. auto. Qed.
- [Coq-Club] How to evaluate reflexive tactics? (in a robust way), Armaël Guéneau, 11/08/2018
- Re: [Coq-Club] How to evaluate reflexive tactics? (in a robust way), Guillaume Melquiond, 11/08/2018
- Re: [Coq-Club] How to evaluate reflexive tactics? (in a robust way), Armaël Guéneau, 11/08/2018
- Re: [Coq-Club] How to evaluate reflexive tactics? (in a robust way), Guillaume Melquiond, 11/08/2018
- Re: [Coq-Club] How to evaluate reflexive tactics? (in a robust way), Guillaume Melquiond, 11/08/2018
- Re: [Coq-Club] How to evaluate reflexive tactics? (in a robust way), Armaël Guéneau, 11/08/2018
- Re: [Coq-Club] How to evaluate reflexive tactics? (in a robust way), Gabriel Scherer, 11/08/2018
- Re: [Coq-Club] How to evaluate reflexive tactics? (in a robust way), Sylvain Boulmé, 11/08/2018
- Re: [Coq-Club] How to evaluate reflexive tactics? (in a robust way), Guillaume Melquiond, 11/08/2018
Archive powered by MHonArc 2.6.18.