aboutsummaryrefslogtreecommitdiffhomepage
path: root/phox/sqrt2.phx
blob: 0f08dd5522a642d2904522d4df1074a0cbd5a357 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
tex
  title = "Proof that square root of 2 is not rational"
  author = "Christophe Raffalli, Paul Rozière"
  institute = "LAMA, Universit\\'e de Savoie, PPS, Universit\\'e Paris VII"
  documents = math
.

Import nat.

flag auto_lvl 2.
flag auto_type true.


(*! math
\section{The library.}


There are two  proof rules  used \underline{explicitely} from the library :

\begin{itemize}
\item \verb#elim (N n) with [case].# case reasonning on integers,
using \[ $$case.N \].
\item \verb#elim (N n) with [wf]#: well founded induction for the natural order
 on integers, using \[ $$well_founded.N \].
\end{itemize}

and the followings theorems.

\begin{itemize}
\item \verb#demorganl# a set of rewrite rules for Demorgan's law.
\item \verb#calcul.N# a set of rewrite rules for natural numbers.
\item \verb#odd_or_even.N#: \[ $$odd_or_even.N \].
\item \verb#lesseq.case1.N#: \[ $$lesseq.case1.N \].
\item \verb#lesseq.imply.not.greater.N#: \[ $$lesseq.imply.not.greater.N \].
\end{itemize}



Comments: As the default elimination rule on integers is structural
induction, it is natural to use explicitly these two rules.  The first
three theorems are also natural to use explicitly.  The last
 could probably be removed by adding some \verb#new_intro# or
\verb#new_elim# in the library.  \verb#lesseq.case1.N# is more
problematic, It would require to extend the system with some kind of
binary elimination rule (with two principal premices ?).

\section{Some basic lemmas.}

They should be included in the library ?
*)

lemma not_odd_and_even.N /\y,z:N( N2 * y != N1 + N2 * z).
(*! math
\begin{lemma}\label{not_odd_and_even.N}
An integer can not be odd and even:
$$ \[ $0 \] $$
\end{lemma}
\begin{proof}
By induction over \[ y \] , then by case over \[ z \] .
\end{proof}
*)
intro 2.
(* induction over y *)
elim H.
(* y := 0 *)
 trivial.
(* y0 -> S y0 *)
 intros.
 (* case over z *)
 elim H2 with [case].
 (* z := 0 *)
  trivial.
 (* z := S y1 *)
  intro.
  prove N2 + N2 * y0 = N2 + N1 + N2 * y1.
   from N2 * S y0 = N1 + N2 + N2 * y1.
   from N2 * S y0 = N1 + (N2 + N2 * y1).
   from H5.
  lefts G.
  elim H1 with H6.
save.



fact sum_square.N /\x,y:N (x + y)^N2 = x^N2 + N2*x*y + y^N2.
(*! math
\begin{lemma}\label{sum_square.N}
$$ \[ $0 \] $$
\end{lemma}
\begin{proof}
Easy.
\end{proof}
*)
intros.
rewrite calcul.N mul.left.distributive.N mul.right.distributive.N add.associative.N.
intro.
save.


fact less.exp.N /\n,x,y:N( x <= y -> x^n <= y^n).
(*! math
\begin{lemma}\label{less.exp.N}
$$ \[ $0 \] $$
\end{lemma}
\begin{proof}
By induction over \[ n \].
\end{proof}
*)
intros.
elim H.
trivial.
rewrite calcul.N.
trivial.
save.

fact less_r.exp.N  /\n,x,y:N( x^n < y^n -> x < y).
(*! math
\begin{lemma}\label{less_r.exp.N}
$$ \[ $0 \] $$
\end{lemma}
\begin{proof}
Follows from lemma \ref{less.exp.N}.
\end{proof}
*)
intros.
elim lesseq.case1.N with y and x.
apply less.exp.N with n and H3.
elim lesseq.imply.not.greater.N with y^n and x^n.
save.

fact less.ladd.N /\x,y:N (N0 < y -> x < x + y).
(*! math
\begin{lemma}\label{less.ladd.N}
$$ \[ $0 \] $$
\end{lemma}
\begin{proof}
Easy induction over \[ x \].
\end{proof}
*)
intros.
trivial.
(*
elim H.
 trivial.
 trivial.
*)
save.


(*! math
\section{The proof itself}
*)

(** The proof itself. *)

theorem n.square.pair /\n:N /\p:N( n^N2=N2*p -> \/q:N n=N2*q).
(*! math
\begin{lemma}\label{n.square.pair}
 If the square of \[ n \] is even then \[ n \] is even:
$$ \[ $0 \] $$
\end{lemma}
\begin{proof}
*)
intros.
apply odd_or_even.N with H.
lefts G $\/ $& $or.
(*! math
We assume \[ $$H1 \] ( \[ H1 \] ).
We distinguish two cases. If \[ n \] is even we get what we want.
*)
trivial.
(*! math
If  \[ n \] is odd we have \[ $$H3 \]
*)
prove  n^N2 = N1 + N2*(N2*y^N2+N2*y).
(*! math
which implies \[ $0 \]
*)
 rewrite  H3 sum_square.N.
 from N1+(N2*(N2*y)+ N2*(y *(N2*y)))= N1+N2 * ?1.
 intro.
(*! math
and this gives a contradiction by lemma \ref{not_odd_and_even.N} using ( \[ H1 \] ).
\end{proof}
*)
rewrite_hyp G H1.
elim not_odd_and_even.N with G.
save.

lem decrease /\m,n : N (m^ N2 = N2 * n^ N2 -> N0 < n -> n < m).
(*! math
\begin{lemma}\label{decrease}
$$ \[ $0 \] $$
\end{lemma}
\begin{proof}
Using lemma \ref{less_r.exp.N} and lemma \ref{less.ladd.N}.
\end{proof}
*)
intros.
elim less_r.exp.N with N2.
prove m^N2 = n^N2 + n^N2. axiom H1.  (* fonctionne sans *)
elim less.ladd.N.
trivial  =H0 H2.
save.

theorem square2_irrat /\m,n : N (m^ N2 = N2 * n^ N2 -> m = N0 & n = N0).
(*! math
\begin{theorem} The square-root of 2 is irrational. For this we just need to prove the following:
$$ \[ $0 \] $$
\end{theorem}
\begin{proof}
*)
intro 2.
elim H with [wf].
(*! math
We prove \[ $0 \] by well founded induction over \[ m \]. Induction hypothesis is
\[ H1 \] : \[ $$H1 \]. *)
intros.
elim H2 with [case].
(* cas n=0 *)
 intro.
 rewrite_hyp H3 H4 calcul.N.
 trivial.
(*! math
if \[ n = N0 \] the result is trivial. Suppose now that \[ n > N0 \].
*)
(* cas n > 0 *)
 apply decrease with H3 and N0 < n.
   trivial.
(*! math
Using lemma \ref{decrease} we get  \[ $$G \].
*)
 elim n.square.pair with H3.
 left H6.
(*! math
Using lemma \ref{n.square.pair} we get \[ q \] such that \[  $$H7 \]
*)
(*! math
The result follow by using induction hypothesis \[ H1 \] ,
*)
 elim H1 with G then q.
 rewrite_hyp H3 H7.
(*! math
using \[ $0 \] which follows from \[$$H3 \].
*)
 prove N2 * (N2 * q ^N2) = N2 * n ^ N2.
  from H3.
 left G0.
 trivial 0.
(*! math
\end{proof}
*)
save.