Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] how to proof in Z modulo?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] how to proof in Z modulo?


Chronological Thread 
  • From: Vincent Laporte <vincent.laporte AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] how to proof in Z modulo?
  • Date: Tue, 9 Aug 2016 11:37:31 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=vincent.laporte AT gmail.com; spf=Pass smtp.mailfrom=vincent.laporte AT gmail.com; spf=None smtp.helo=postmaster AT mail-wm0-f54.google.com
  • Ironport-phdr: 9a23:zD4VyRKRjlbvZZ5lRtmcpTZWNBhigK39O0sv0rFitYgUKfTxwZ3uMQTl6Ol3ixeRBMOAuqoC2rCd6vqocFdDyK7JiGoFfp1IWk1NouQttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXsq3G/pQQfBg/4fVIsYL+kQsiD1Y/ujaibwN76W01wnj2zYLd/fl2djD76kY0ou7ZkMbs70RDTo3FFKKx8zGJsIk+PzV6nvp/jtM0rzyMFsPU4ssVETK/SfqIiTLUeAi51HXoy4ZjVtB/IQA2Trl8VSmIMjhcAVxbE6hr3WIu3tiLisfBh1QGVOMT3SfY/XjH0vPQjcwPhlCpSb21xy2rQkMEl1K8=

> Is there a simple way to do that?

Hi,

Here is a method (Frédéric Besson taught it to me). Dealing with
division and modulo directly is indeed painful. However, these
operations can be completely specified in terms of multiplications,
additions, and less-than relations (see the Z_div_mod_full lemma).
Moreover, when the divisor is a constant (in your case, 3), these
specifications are linear. Therefore, your goal can be automatically
changed into an equivalent one that is linear (hence solved by lia).

Here is the code (tested with Coq 8.5pl2).

Require Import Psatz.
Import ZArith.

Ltac elim_mod :=
repeat match goal with
| |- context[Z.modulo ?a ?b] =>
unfold Z.modulo at 1;
generalize (Z_div_mod_full a b);
unfold Remainder;
destruct (Z.div_eucl a b)
end.

Goal forall x, (x mod 3)%Z =
(((x mod 3 - - x mod 3) mod 3 - (- x mod 3 - x mod 3) mod 3)
mod 3)%Z.
intros.
elim_mod.
lia.
Qed.

Cheers,
--
Vincent.




Archive powered by MHonArc 2.6.18.

Top of Page