(forall q,n< q * 3) - >的短(er)证明。 n + n<> k * 3`

时间:2017-09-05 06:22:59

标签: coq

在证明中我需要表明“如果 n 不是三的倍数,那么 n + n 也不是三的倍数。”我认为我的证据太长而且不太优雅。是否有一些更漂亮的写作方式?有没有ssreflect? (我确定在ssreflect中有一个oneliner :))。

我的证据以{3}的步数对n进行归纳。

Require Import Omega.
Lemma math_helper n: forall k, (forall q, n <> q * 3) ->  n + n <> k * 3.
  (* name the predicate Q and strengthen induction hypothesis *)
  pattern n; match goal with [ _:_ |- ?P ?n] => let X := fresh Q in remember P as X end.
  enough (Q n /\ Q (1+n) /\ Q (2+n)) by tauto.
  induction n; subst Q;
    [| destruct IHn as [IH1 [IH2 IH3]]];
    repeat split; simpl; intros; auto; try omega.
  intro C; assert (k>=2) by omega; do 2 (try destruct k); try omega.
  assert (n+n = k*3) by omega.
  apply (IH1 k); auto; intros q HH; eapply (H (1+q)); subst n; omega.
Qed.

5 个答案:

答案 0 :(得分:6)

通常情况下,答案是ssreflect one-liner:

From mathcomp Require Import ssreflect ssrbool ssrnat div.

Lemma math_helper n : 3 %| n.*2 -> 3 %| n.
Proof. by rewrite -muln2 Gauss_dvdl. Qed.
好吧,我作弊了一点,因为我改变了定理的陈述。这是您实际要求的证据。

Lemma math_helper n k : (forall q, n <> q * 3) -> n + n <> k * 3.
Proof.
rewrite addnn -mul2n mulnC => h1 h2.
suff/dvdnP [q /h1]: 3 %| n by [].
by rewrite -(@Gauss_dvdl _ _ 2) //; apply/dvdnP; eauto.
Qed.

答案 1 :(得分:6)

有一个更简单的解决方案,只依靠分裂,并让欧米茄做出推理。

Lemma math_helper2 n : forall k, (forall q, n <> q * 3) ->  n + n <> k * 3.
Proof.
intros k kq A.
assert (k = 2 * (k / 2) + k mod 2) by (apply Nat.div_mod; omega).
assert (k mod 2 < 2) by (apply (Nat.mod_bound_pos k 2); omega).
apply (kq (k/2)); omega.
Qed.

答案 2 :(得分:5)

这也可以使用标准库中的高斯引理在vanilla Coq中解决(所以以下仅仅是对Arthur已经展示的内容的重新阐述):

Require Import Coq.Numbers.Natural.Peano.NPeano.

Lemma math_helper n k : (forall q, n <> q * 3) -> n + n <> k * 3.
Proof.
  fold (Nat.double n); rewrite Nat.double_twice, (Nat.mul_comm k 3); intros H1 H2.
  assert (3 | 2 * n) as H3 by (rewrite H2; apply Nat.divide_factor_l).
  apply Nat.gauss in H3 as [x contra]; auto.
  apply (H1 _ contra).
Qed.

答案 3 :(得分:3)

这是没有ssreflect的答案。

您可以使用well_founded_induction和lt_wf通过过程归纳替换您的三步感应,然后您可以使用所有数字样张进行 欧米茄。你仍然需要手工处理普遍量化的否定。

Require Import Wellfounded Arith Omega.

Lemma math_helper n : forall k, (forall q, n <> q * 3) ->  n + n <> k * 3.
Proof.
induction n as [n' Ih] using (well_founded_ind lt_wf).
intros k pn' A; destruct (eq_nat_dec n' 0) as [n0 | nn0];[now intros; case (pn' 0); omega| ].
assert (cnd: n' - 3 < n') by omega.
apply (Ih _ cnd (k - 2));[intros q A'; apply (pn' (S q))|]; omega.
Qed.

答案 4 :(得分:2)

我对Arthur的答案进行了改进:

Lemma forall_negP T (P : T -> Prop) : (forall k, ~ P k) <-> ~ (exists k, P k).
Proof.
split; first by move=> H [w Hw]; apply: (H w).
by move=> H k Hk; apply: H; exists k.
Qed.

Lemma dvdnPN d m : (forall k, m <> k * d) <-> ~~ (d %| m).
Proof. by rewrite forall_negP; split=> /dvdnP. Qed.

Lemma math_helper n : (forall q, n <> q * 3) -> forall k, n + n <> k * 3.
Proof. by move/dvdnPN=> ?; apply/dvdnPN; rewrite addnn -muln2 Gauss_dvdl. Qed.

@AntonTrunov建议:

Lemma math_helper n : (forall q, n <> q * 3) -> forall k, n + n <> k * 3.
Proof. by rewrite !dvdnPN addnn -muln2 Gauss_dvdl. Qed.

这相当不错!

无论如何,正如亚瑟指出的那样,OP应该通过更加谨慎地陈述来彻底摆脱这个引理。