1
(************************************************************************)
3
(* Micromega: A reflexive tactic using the Positivstellensatz *)
5
(* Frédéric Besson (Irisa/Inria) 2006-2008 *)
7
(************************************************************************)
9
Require Import ZArith Zwf Psatz QArith.
12
Lemma Zabs_square : forall x, (Zabs x)^2 = x^2.
14
intros ; case (Zabs_dec x) ; intros ; psatz Z 2.
16
Hint Resolve Zabs_pos Zabs_square.
18
Lemma integer_statement : ~exists n, exists p, n^2 = 2*p^2 /\ n <> 0.
20
intros [n [p [Heq Hnz]]]; pose (n' := Zabs n); pose (p':=Zabs p).
21
assert (facts : 0 <= Zabs n /\ 0 <= Zabs p /\ Zabs n^2=n^2
22
/\ Zabs p^2 = p^2) by auto.
23
assert (H : (0 < n' /\ 0 <= p' /\ n' ^2 = 2* p' ^2)) by
24
(destruct facts as [Hf1 [Hf2 [Hf3 Hf4]]]; unfold n', p' ; psatz Z 2).
25
generalize p' H; elim n' using (well_founded_ind (Zwf_well_founded 0)); clear.
26
intros n IHn p [Hn [Hp Heq]].
27
assert (Hzwf : Zwf 0 (2*p-n) n) by (unfold Zwf; psatz Z 2).
28
assert (Hdecr : 0 < 2*p-n /\ 0 <= n-p /\ (2*p-n)^2=2*(n-p)^2) by psatz Z 2.
29
apply (IHn (2*p-n) Hzwf (n-p) Hdecr).
34
Lemma QnumZpower : forall x : Q, Qnum (x ^ 2)%Q = ((Qnum x) ^ 2) %Z.
38
cbv beta iota zeta delta - [Zmult].
43
Lemma QdenZpower : forall x : Q, ' Qden (x ^ 2)%Q = ('(Qden x) ^ 2) %Z.
54
Theorem sqrt2_not_rational : ~exists x:Q, x^2==2#1.
56
unfold Qeq; intros [x]; simpl (Qden (2#1)); rewrite Zmult_1_r.
58
assert (Heq : (Qnum x ^ 2 = 2 * ' Qden x ^ 2%Q)%Z) by
59
(rewrite QnumZpower in HQeq ; rewrite QdenZpower in HQeq ; auto).
60
assert (Hnx : (Qnum x <> 0)%Z)
61
by (intros Hx; simpl in HQeq; rewrite Hx in HQeq; discriminate HQeq).
62
apply integer_statement; exists (Qnum x); exists (' Qden x); auto.