aboutsummaryrefslogtreecommitdiffhomepage
path: root/phox/square-root-2.phx
blob: 92a888b323da40de3c1ec310b432765f955362cf (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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
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 1.

(* Cette preuve est à peu près celle envoyée à F. Wiedijk -- Nijmegen
-- The Fifteen Provers of the World --
            http://www.cs.kun.nl/~freek/comparison/index.html 
Voir une preuve plus simple : sqrt2.phx 
*)

(*! math
\section{The library:}

The theorem used \underline{explicitely} from the library are

\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#well_founded.N#: \[ $$well_founded.N \].
\item \verb#odd_or_even.N#: \[ $$odd_or_even.N \].
\item \verb#lesseq.case1.N#: \[ $$lesseq.case1.N \].
\item \verb#neq.less_or_sup.N#: \[ $$neq.less_or_sup.N \].
\item \verb#not.lesseq.imply.less.N#: \[ $$not.lesseq.imply.less.N \].
\item \verb#lesseq.imply.not.greater.N#: \[ $$lesseq.imply.not.greater.N \].
\end{itemize}

Comments: The first four are natural to use explicitely.  The last two
could probably be removed by adding some \verb#new_intro# or
\verb#new_elim# in the library.  \verb#lesseq.case1.N# and
\verb#neq.less_or_sup.N# are more problematic, they 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 ? 
*)

theorem minimal.element /\X (\/n:N X n -> \/n:N (X n & /\p:N (X p -> n <= p))).
(*! math
\begin{lemma}\label{minimal.element}
Every non empty subset \[ X \] of \[ N \] admits a minimal element:
$$ \[ $0 \] $$
\end{lemma}
*)
intro 2.
by_absurd.
rewrite_hyp H0 demorganl.
(*! math
\begin{proof}
We assume \[ $$H \] and \[ $$H0 \] ( \[ H0 \] ).
*)
use /\n:N ~ X n.
(*! math
We get a contradiction from \[ $$G \] which is proven by well founded induction:
*)
trivial.
intros.
elim well_founded.N with H1.
intros.
(*! math
we assume \[ $$H3 \] and must prove \[ $0 \].
*)
intro.
apply H0 with H4.
lefts G $& $\/.
(*! math
Assuming \[ $$H4 \] and using ( \[ H0 \] ) we get an integer \[ x \] such that
\[ $$H6 \] and \[ $$H7 \]. This gives a contradiction with \[ $$H3 \].
\end{proof}
*)
elim H3 with H5.
elim not.lesseq.imply.less.N.
save.

theorem not_odd_and_even.N  /\x,y,z:N (~ (x = N2 * y & x = 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 \[ x \].
\end{proof}
*)
intro 2.
elim H.
trivial 6.
intros.
intro.
left H4.
elim H2 with [case].
trivial =H0 H4 H6.
elim H1.
axiom H3.
axiom H6.
intro.
rmh H4.
left H5.
rmh H5.
rewrite_hyp H4 H7 calcul.N.
left H4.
axiom H4.
save.

theorem 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 on \[ 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 ;; Try intros.
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.
elim H.
rewrite calcul.N.
trivial.
save.


(*! math
\section{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.
lefts H0 $\/ $&.
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 = N2*(N2*y^N2+N2*y) + N1.
(*! math
which implies \[ $0 \]
*) 
rewrite H3 sum_square.N.
rewrite add.associative.N mul.associative.N mul.left.distributive.N.
from N1 + N4 * y + (N2 * y) ^ N2 = N1 + N4 * y + N4 * y ^ N2.
intro.
(*! math
and this gives a contradiction by lemma \ref{not_odd_and_even.N} using ( \[ H1 \] )
\end{proof}
*) 
elim not_odd_and_even.N with N (n^N2).
intros.
select 3.
intro.
axiom H1.
axiom G.
axiom H0.
intros.
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 ;; Try intros.
prove m^N2 = n^N2 + n^N2. axiom H1.
elim less.ladd.N ;; Try intros.
trivial.
trivial.
trivial  =H0 H2.
save.

lem sup_zero /\m,n : N (m^ N2 = N2 * n^ N2 -> N0 < m -> N0 < n).
(*! math
\begin{lemma}\label{sup_zero}
$$ \[ $0 \] $$
\end{lemma}
\begin{proof}
Using lemma \[ $$ neq.less_or_sup.N \] from the library.
\end{proof}
*)
intros.
elim neq.less_or_sup.N with N0 and n ;; Try intros.
rewrite_hyp H1 H3 calcul.N.
trivial.
trivial.
save.

def  Q m = m > N0 & \/n:N (m^ N2 = N2 * n^ N2).
(*! math
\begin{definition}
We define \[ Q m = $$Q m \].
\end{definition}
*)

lem dec /\m:N (Q m -> \/m':N (Q m' & m' < m)).
(*! math
\begin{lemma}\label{dec}
$$ \[ $0 \] $$
\end{lemma}
\begin{proof}
*)
intros.
lefts H0 $Q $\/ $&.
(*! math
We assume that \[ $$H0 \] and \[ $$H2 \] (\[ H2 \]) and we must prove \[ $0 \].
*)
apply sup_zero with H2 and H0.
(*! math
By lemma \ref{sup_zero} we get \[ $$G \]. We show that \[ n \] is the integer we are looking for.
*)
intro.
instance ?1 n.
intros.
intros.
trivial.
(*! math
We just need to prove \[ $0 \] and \[1 $0 \].
*)
prove \/p:N (m ^ N2 = N2 * p).
intro.
instance ?2  n^N2.
trivial.
apply n.square.pair with G0.
lefts G1 $& $\/.
(*! math
Using lemma \ref{n.square.pair} we get \[ q \] such that \[  $$H4 \]
*)
prove n ^N2 = N2 * q ^N2.
rewrite_hyp H2 H4.
prove N2 * (N2 * q ^N2) = N2 * n ^ N2.
from H2.
left G1.
intro.
(*! math
and then \[ $$G1 \].
*)
trivial =H3 G1.
(*! math
Finally \[ $0 \] follows from lemma \ref{decrease}.
\end{proof}
*) 
elim decrease.
save.

lem sq2_irrat /\m:N ~Q m.
(*! math
\begin{lemma}\label{sq2_irrat}
$$ \[ $0 \] $$
\end{lemma}
\begin{proof}
Follows from the previous lemma by selecting the minimal element in \[ Q \] (using lemme \ref{minimal.element}) and getting a contradiction.
\end{proof}
*)
intros.
intro.
elim minimal.element with Q.
intros $\/ $&.
axiom H.
axiom H0.
lefts H1.
elim dec with H2.
lefts H4.
apply H3 with H5.
elim lesseq.imply.not.greater.N with n and m'.
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}
*)
intros.
apply sq2_irrat  with H.
(*! math
We assume \[ $$H1 \].
By the previous lemma we have \[ $$G \].
*)
elim H with [case].
intro.
intro.
(*! math
If \[ $$H2 \] we easely get \[ $0 \].
*)
elim H0 with [case].
intro.
rewrite_hyp H1 H2 H4 calcul.N.
left H1;; intros.
prove Q m.
(*! math
If \[ m > N0 \] then we have \[ Q m \] and a contradiction.
\end{proof}
*)
intros $Q $\/ $&.
trivial.
select 2.
axiom H1.
trivial.
elim G.
save.