coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Armaël Guéneau <armael.gueneau AT ens-lyon.fr>
- To: coq-club AT inria.fr
- Subject: [Coq-Club] Rewriting in arithmetic expressions wrt Z.le
- Date: Tue, 6 Dec 2016 18:02:36 +0100
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=armael.gueneau AT ens-lyon.fr; spf=Pass smtp.mailfrom=armael.gueneau AT ens-lyon.fr; spf=None smtp.helo=postmaster AT labbe.ens-lyon.fr
- Ironport-phdr: 9a23:1ftSmRdv0OgQxbbmsV2OwLNalGMj4u6mDksu8pMizoh2WeGdxcS6YB7h7PlgxGXEQZ/co6odzbGH6Oa9ASdcut6oizMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpTEdFQ/iOgVrO+/7BpDdj9it1+C15pbffxhEiCCzbL52Ihi6twXcutUZjYZtJKs61wfErGZPd+lK321jOEidnwz75se+/Z5j9zpftvc8/MNeUqv0Yro1Q6VAADspL2466svrtQLeTQSU/XsTTn8WkhtTDAfb6hzxQ4r8vTH7tup53ymaINH2QLUpUjms86tnVBnlgzoBOjUk8m/Yl9ZwgbpFrhyhuhJxwIDab4+aO/ViZa7deM8WSHBbU8pNWSFMAIWxZJYPAeobOuZYqpHwqkcUrRu7HwarGOfvxSdJiH/rx6o61fouHhvb3Ac9GN8Bqm7UrNDvO6gMVeC51qbIzSjdYPNQxzjy8pXIfws/rvGKRrJ8aM7RyEkoFwPDlFmQp5blMiqT2+8QvWab6O9gWviui24hswx+uCWgydo2honPmI0UxUzE+T14wIYzP924SVR0bcSqEJtKsSyRKoh4Qts6Tm11tys21qcKtJy5cSQQ1ZgqxhzSZ+aZf4SW/B7vTPudLSl7iX5/fL+yiQy+/Emhx+HmWMS51ktBoDBfndnWrH8N0gTe6siZRft5+UeswTKP2BrI5e5fP084j7TUK5g6wrIpkpoSsUPDHinslEX4lq+abkQk+u625OT7erjqu5CRO5Nuhgz8MKkigNGzDOU6PwQUQWSX5/qw2KXm/ULjQbVKivM2krPesJDfPckUvLS5AwpP3Yk97xazFTim0MkGknkBMl1KYg+HgpP3NFHIO/D0FPO/glSrkDdt3fzGMKfhDo3XLnffiLfhYap960lExQUvytBf/otYBa0FIPLuQUD8r8fYDx88Mwys2enrEtR91oUEWWKOGKCVKq3SsUXbrt4oduKLfcoevCv3A/kj/f/ny3EjynEHeqz89IESYfO8Kdt7okOUaGek1t4bFG4HukwxUeHshVSfeTNVfDO2TqU6oD8hXtH1RbzfT5yg1eTSlBywGYdbMzhL
Hi list,
I'm trying to setup definitions to be able to rewrite wrt Z.le in arithmetic expressions (which live in Z).
For example, I can define the following instance to be able to rewrite under Z.add:
Program Instance proper_Zplus: Proper (Z.le ++> Z.le ++> Z.le) Z.add.
Next Obligation. do 6 intro. omega. Qed.
This one works well, as illustrated in the following example:
Goal (forall a b c d, a <= b -> c + b <= c + d -> c + a <= c + d).
intros ? ? ? ? a_le_b cb_le_cd.
rewrite a_le_b.
assumption.
Qed.
However, I have issues trying to do the same with multiplication. "Proper (Z.le ++> Z.le ++> Z.le) Z.mul" is
not true in general, so I'd like to add a side condition asserting that the constant under which I rewrite
is non-negative.
This gives me this first instance, which allows to rewrite on the right of Z.mul:
Program Instance proper_Zmult_right:
forall x, 0 <= x ->
Proper (Z.le ++> Z.le) (Z.mul x).
Next Obligation. do 3 intro. nia. Qed.
This instance doesn't work as is; a previous thread (https://sympa.inria.fr/sympa/arc/coq-club/2013-03/msg00101.html)
seems to suggest that a way to make it work is by adding a hint
Hint Extern 100 (0 <= _) => assumption : typeclass_instances.
and then asserting the side-condition before rewriting with this instance.
Inserting this hint feels a bit hackish, and having to assert the side condition beforehand is not super convenient.
Moreover, I can't manage to define an similar instance to rewrite on the left of Z.mul. The following doesn't work:
Program Instance proper_Zmult_left:
forall y, 0 <= y ->
Proper (Z.le ++> Z.le) (fun x => Z.mul x y).
Next Obligation. do 3 intro. nia. Qed.
(attached is a minimal Coq script with the definitions & test cases)
Is there a better way of doing this setup so that rewriting under Z.mul works?
More generally, how do people prove and handle inequalities between arithmetic expressions?
— Armaël
Require Import ZArith.
Require Import Psatz.
Local Open Scope Z_scope.
Require Import Coq.Setoids.Setoid.
Require Import Coq.Classes.Morphisms.
Program Instance proper_Zplus: Proper (Z.le ++> Z.le ++> Z.le) Z.add.
Next Obligation. do 6 intro. omega. Qed.
Goal (forall a b c d, a <= b -> c + b <= c + d -> c + a <= c + d).
intros ? ? ? ? a_le_b cb_le_cd.
rewrite a_le_b.
assumption.
Qed.
Program Instance proper_Zmult_left:
forall x, 0 <= x ->
Proper (Z.le ++> Z.le) (Z.mul x).
Next Obligation. do 3 intro. nia. Qed.
Hint Extern 100 (0 <= _) => assumption : typeclass_instances.
Goal forall a b c d, a <= b -> 0 <= c -> c * b <= c * d -> c * a <= c * d.
intros ? ? ? ? a_le_b O_le_c cb_le_cd.
rewrite a_le_b.
assumption.
Qed.
Program Instance proper_Zmult_right:
forall y, 0 <= y ->
Proper (Z.le ++> Z.le) (fun x => Z.mul x y).
Next Obligation. do 3 intro. nia. Qed.
Goal forall a b c d, a <= b -> 0 <= c -> b * c <= d * c -> a * c <= d * c.
intros ? ? ? ? a_le_b O_le_c bc_le_dc.
(* rewrite a_le_b. *)
Abort.
- [Coq-Club] Rewriting in arithmetic expressions wrt Z.le, Armaël Guéneau, 12/06/2016
- Re: [Coq-Club] Rewriting in arithmetic expressions wrt Z.le, Théo Zimmermann, 12/06/2016
- Re: [Coq-Club] Rewriting in arithmetic expressions wrt Z.le, Armaël Guéneau, 12/06/2016
- Re: [Coq-Club] Rewriting in arithmetic expressions wrt Z.le, Théo Zimmermann, 12/06/2016
- Re: [Coq-Club] Rewriting in arithmetic expressions wrt Z.le, Armaël Guéneau, 12/06/2016
- Re: [Coq-Club] Rewriting in arithmetic expressions wrt Z.le, Théo Zimmermann, 12/06/2016
Archive powered by MHonArc 2.6.18.