我如何证明简体中文剩余定理?

时间:2017-12-03 12:38:40

标签: coq

我设法证明

Theorem modulo_inv : forall m n : Z, rel_prime m n -> exists x : Z, (m * x == 1 [n]). Admitted.

我的问题是如何完成以下证明(可能使用modulo_inv定理?):

Variables m n : Z.
Hypothesis co_prime : rel_prime m n.

Theorem SimpleChineseRemainder :
  forall a b : Z, exists x : Z, (x == a [m]) /\ (x == b [n]).

这是我尝试过的,但我不知道它是否正确。

Proof.
    intros a b.
    exists ((a * n) * (n ^ (-1) mod m) + (b * m) * (m ^ (-1) mod n)).
    refine (conj _ _).
        (* case : ((a * n) * (n ^ (-1) mod m) + (b * m) * (m ^ (-1) mod n) == a [m]) *)
        red.
        rewrite Z.add_sub_swap.
        apply Z.divide_add_r.

        (* case : ((a * n) * (n ^ (-1) mod m) + (b * m) * (m ^ (-1) mod n) == b [n]) *)

有人可以提供任何建议吗?

2 个答案:

答案 0 :(得分:3)

重用基于proof的维基百科中的Bézout's lemma,我们得到以下内容:

From Coq Require Import ZArith Znumtheory.
Import Z.

Definition modulo (a b n : Z) : Prop := (n | (a - b)).
Notation "a == b [ n ]" := (modulo a b n) (at level 50).

Section SimpleChineseRemainder.
Variables m n : Z.
Hypothesis co_prime : rel_prime m n.

Theorem SimpleChineseRemainder a b :  exists x : Z, (x == a [[m]]) /\ (x == b [[n]]).
Proof.
  destruct (rel_prime_bezout _ _ co_prime) as [u v Eq].
  exists (a * v * n + b * u * m); split; [| rewrite add_comm in *];
  match goal with |- _ == ?c [_] => replace c with (c * 1) at 2 by apply mul_1_r end;
  rewrite <-Eq, mul_add_distr_l, !mul_assoc;
  now eexists; rewrite add_add_simpl_l_r, <-mul_sub_distr_r.
Qed.
End SimpleChineseRemainder.

答案 1 :(得分:3)

Code-golfing Anton的回答,我希望ring能够聪明地使用Eq信息,并且证明只是

Theorem SimpleChineseRemainder' a b :  exists x : Z, (x == a [m]) /\ (x == b [n]).
Proof.
  destruct (rel_prime_bezout _ _ co_prime) as [u v Eq];
  exists (a * v * n + b * u * m); split ; [ exists ((b-a)*u) | exists ((a-b)*v)]; ring.
Qed.

不幸的是,它没有自动利用u * m + v * n = 1 -> u * m = 1 - v * n。所以在我们有更强的策略之前,我想这必须手动添加,如下:

Theorem SimpleChineseRemainder' a b : exists x : Z, (x == a [m]) /\ (x == b [n]).
Proof.
  destruct (rel_prime_bezout _ _ co_prime) as [u v Eq].
  exists (a * (v * n) + b * (u * m)); split ; [ exists ((b-a)*u) | exists ((a-b)*v)].
  - replace (v*n) with (1-u*m) by (rewrite <- Eq; ring); ring.
  - replace (u*m) with (1-v*n) by (rewrite <- Eq; ring); ring.
Qed.


编辑:nsatz策略能够解决方程系统。但是,它引入了[ ... ]的符号与上面介绍的符号冲突,我不知道如何处理。但是,通过将符号更改为[[ ... ]],证明只变为两行:

Require Import Nsatz.
Theorem SimpleChineseRemainder' a b :
  exists x : Z, (x == a [[m]]) /\ (x == b [[n]]).
Proof.
  destruct (rel_prime_bezout _ _ co_prime) as [u v Eq];
  exists (a * v * n + b * u * m); split ; [ exists ((b-a)*u) | exists ((a-b)*v)]; nsatz.
Qed.