背景
我正在独自学习帮助,Coq。到目前为止,我已经匆匆完成了Yves Bertot的Coq阅读。现在,我的目标是证明与自然数有关的一些基本结果,并以所谓的除法算法结束。但是,在实现该目标的过程中,我遇到了一些挫折。特别是,以下两个结果已经证明(双关语意)比我最初想象的要困难得多。实际上,经过多次徒劳的尝试之后,我不得不手工证明它们(如下所示)。显然,这并不能帮助我更加精通Coq。这就是为什么我转向这个论坛。我希望这个网站上的某人能够并且愿意帮助我将下面的证明转换为Coq接受的证明。衷心感谢所有帮助!
定理A
对于所有证明:
假设。因此,存在一个与 因此,通过(皮亚诺1b和3)
定义一个谓词
证明就足够了。我们通过对的归纳来证明这一点。要看,不是说成立,那么Peano 1a就是为真。因此,。现在,我们证明:假设。根据这个定义,我们有,因此在这种情况下也有。最后,皮亚诺的第五个公理给出,通过我们得到。 Ž Q (0 )我(Ñ ,X + 0 ,ÿ )我(Ñ ,X ,ÿ )X < Ý ∨ 我(Ñ ,X ,ÿ )Q (小号(v ))我(Ñ ,x + S (v ),y )x <X < Ý ∨ 我(Ñ ,X ,ÿ )Q (Ž )(* )X < Ý ∨ 我(Ñ ,X ,ÿ )
定理B
对于所有证明:X < Ý ∨ 我(Ñ ,X ,ÿ )∨ ÿ < X
如果则根据定义,如果则也根据定义。如果和那么根据传递性和自反性,我们有,这是一个矛盾。因此,不超过一种说法是正确的。¬ 我(Ñ ,X ,ÿ )X > Ý ¬ 我(Ñ ,X ,ÿ )X > ý ý > X 我(Ñ ,X ,ÿ )
我们使固定并在归纳。当对于所有,我们都有,这证明了基本情况。接下来,假设定理对成立;现在我们要证明的定理。从对的三分法中可以看出三种情况:和。如果,则显然。如果,则(对于所有都是)。最后,假设X 我(Ñ ,0 ,ÿ )0 < Ý ∨ 我(Ñ ,0 ,ÿ )ÿ X 小号(X )X X < Ý ,我(Ñ ,X ,ÿ )X > ý X > Ý 小号(X )> y I (N ,x ,y )小号(X )> X X ∈ Ñ X < Ý 小号(X )< Ý 我(Ñ ,小号(X ),ÿ )然后,根据定理A,我们得到或,无论哪种情况,我们都完成了。
我希望证明的定理可以在Coq中表示如下。
引理less_lem(xy:N):less x(成功y)->或(less xy)(IN xy)。
定理Ntrichotomy:(总xy:N或(较少xy)(或(IN xy)(较少yx)))。
有用的结果
在这里,我收集了一些已定义的结果,并证明了这一点。这些是我上面提到的。* 这是到目前为止我设法编写的代码,请注意,大多数代码都由定义组成。*
(* Sigma types *)
Inductive Sigma (A:Set)(B:A -> Set) :Set :=
Spair: forall a:A, forall b : B a,Sigma A B.
Definition E (A:Set)(B:A -> Set)
(C: Sigma A B -> Set)
(c: Sigma A B)
(d: (forall x:A, forall y:B x,
C (Spair A B x y))): C c :=
match c as c0 return (C c0) with
| Spair a b => d a b
end.
(* Binary sum type *)
Inductive sum' (A B:Set):Set :=
inl': A -> sum' A B | inr': B -> sum' A B.
Print sum'_rect.
Definition D (A B : Set)(C: sum' A B -> Set)
(c: sum' A B)
(d: (forall x:A, C (inl' A B x)))
(e: (forall y:B, C (inr' A B y))): C c :=
match c as c0 return C c0 with
| inl' x => d x
| inr' y => e y
end.
(* Three useful finite sets *)
Inductive N_0: Set :=.
Definition R_0
(C:N_0 -> Set)
(c: N_0): C c :=
match c as c0 return (C c0) with
end.
Inductive N_1: Set := zero_1:N_1.
Definition R_1
(C:N_1 -> Set)
(c: N_1)
(d_zero: C zero_1): C c :=
match c as c0 return (C c0) with
| zero_1 => d_zero
end.
Inductive N_2: Set := zero_2:N_2 | one_2:N_2.
Definition R_2
(C:N_2 -> Set)
(c: N_2)
(d_zero: C zero_2)
(d_one: C one_2): C c :=
match c as c0 return (C c0) with
| zero_2 => d_zero
| one_2 => d_one
end.
(* Natural numbers *)
Inductive N:Set :=
zero: N | succ : N -> N.
Print N.
Print N_rect.
Definition R
(C:N -> Set)
(d: C zero)
(e: (forall x:N, C x -> C (succ x))):
(forall n:N, C n) :=
fix F (n: N): C n :=
match n as n0 return (C n0) with
| zero => d
| succ n0 => e n0 (F n0)
end.
(* Boolean to truth-value converter *)
Definition Tr (c:N_2) : Set :=
match c as c0 with
| zero_2 => N_0
| one_2 => N_1
end.
(* Identity type *)
Inductive I (A: Set)(x: A) : A -> Set :=
r : I A x x.
Print I_rect.
Theorem J
(A:Set)
(C: (forall x y:A,
forall z: I A x y, Set))
(d: (forall x:A, C x x (r A x)))
(a:A)(b:A)(c:I A a b): C a b c.
induction c.
apply d.
Defined.
(* functions are extensional wrt
identity types *)
Theorem I_I_extensionality (A B: Set)(f: A -> B):
(forall x y:A, I A x y -> I B (f x) (f y)).
Proof.
intros x y P.
induction P.
apply r.
Defined.
(* addition *)
Definition add (m n:N) : N
:= R (fun z=> N) m (fun x y => succ y) n.
(* multiplication *)
Definition mul (m n:N) : N
:= R (fun z=> N) zero (fun x y => add y m) n.
(* Axioms of Peano verified *)
Theorem P1a: (forall x: N, I N (add x zero) x).
intro x.
(* force use of definitional equality
by applying reflexivity *)
apply r.
Defined.
Theorem P1b: (forall x y: N,
I N (add x (succ y)) (succ (add x y))).
intros.
apply r.
Defined.
Theorem P2a: (forall x: N, I N (mul x zero) zero).
intros.
apply r.
Defined.
Theorem P2b: (forall x y: N,
I N (mul x (succ y)) (add (mul x y) x)).
intros.
apply r.
Defined.
Definition pd (n: N): N :=
R (fun _=> N) zero (fun x y=> x) n.
(* alternatively
Definition pd (x: N): N :=
match x as x0 with
| zero => zero
| succ n0 => n0
end.
*)
Theorem P3: (forall x y:N,
I N (succ x) (succ y) -> I N x y).
intros x y p.
apply (I_I_extensionality N N pd (succ x) (succ y)).
apply p.
Defined.
Definition not (A:Set): Set:= (A -> N_0).
Definition isnonzero (n: N): N_2:=
R (fun _ => N_2) zero_2 (fun x y => one_2) n.
Theorem P4 : (forall x:N,
not (I N (succ x) zero)).
intro x.
intro p.
apply (J N (fun x y z =>
Tr (isnonzero x) -> Tr (isnonzero y))
(fun x => (fun t => t)) (succ x) zero)
.
apply p.
simpl.
apply zero_1.
Defined.
Theorem P5 (P:N -> Set):
P zero -> (forall x:N, P x -> P (succ x))
-> (forall x:N, P x).
intros base step n.
apply R.
apply base.
apply step.
Defined.
(* I(A,-,-) is an equivalence relation *)
Lemma Ireflexive (A:Set): (forall x:A, I A x x).
intro x.
apply r.
Defined.
Lemma Isymmetric (A:Set): (forall x y:A, I A x y -> I A y x).
intros x y P.
induction P.
apply r.
Defined.
Lemma Itransitive (A:Set):
(forall x y z:A, I A x y -> I A y z -> I A x z).
intros x y z P Q.
induction P.
assumption.
Defined.
Lemma succ_cong : (forall m n:N, I N m n -> I N (succ m) (succ n)).
intros m n H.
induction H.
apply r.
Defined.
Lemma zeroadd: (forall n:N, I N (add zero n) n).
intro n.
induction n.
simpl.
apply r.
apply succ_cong.
auto.
Defined.
Lemma succadd: (forall m n:N, I N (add (succ m) n) (succ (add m n))).
intros.
induction n.
simpl.
apply r.
simpl.
apply succ_cong.
auto.
Defined.
Lemma commutative_add: (forall m n:N, I N (add m n) (add n m)).
intros n m; elim n.
apply zeroadd.
intros y H; elim (succadd m y).
simpl.
rewrite succadd.
apply succ_cong.
assumption.
Defined.
Lemma associative_add: (forall m n k:N,
I N (add (add m n) k) (add m (add n k))).
intros m n k.
induction k.
simpl.
apply Ireflexive.
simpl.
apply succ_cong.
assumption.
Defined.
Definition or (A B : Set):= sum' A B.
Definition less (m n: N) :=
Sigma N (fun z => I N (add m (succ z)) n).
Lemma less_lem (x y:N) :
less x (succ y) -> or (less x y) (I N x y).
intro.
destruct H.
right.
(* Here is where I'm working right now *)
Defined.
Theorem Ntrichotomy: (forall x y:N,
or (less x y) (or (I N x y) (less y x))).