Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
2,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. (*
  2. p/q != sqrt(2)
  3. (p*p)/(q*q) != 2
  4. p*p != 2*q*q
  5. *)
  6. Require Import Arith.Even.
  7. Require Import Omega.
  8.  
  9. Check Nat.even.
  10.  
  11. Lemma two_times_x_is_even : forall x : nat,
  12. Nat.even (2*x) = true.
  13. Proof.
  14. simpl.
  15. induction x.
  16. - simpl.
  17. reflexivity.
  18. - rewrite Nat.add_0_r.
  19. rewrite Nat.add_0_r in IHx.
  20. replace (S x + S x) with (S (S (x+x))).
  21. + simpl.
  22. apply IHx.
  23. + simpl.
  24. rewrite (Nat.add_comm x (S x)).
  25. simpl.
  26. reflexivity.
  27. Qed.
  28.  
  29. Lemma even_exists : forall x : nat,
  30. Nat.even x = true -> exists k, 2*k = x.
  31. Proof.
  32. intros.
  33. apply Nat.even_spec in H.
  34. unfold Nat.Even in H.
  35. destruct H.
  36. exists x0.
  37. symmetry.
  38. apply H.
  39. Qed.
  40.  
  41. Lemma next_even_is_odd : forall x : nat,
  42. Nat.even x = negb (Nat.even (S x)).
  43. Proof.
  44. intros.
  45. induction x.
  46. - simpl.
  47. reflexivity.
  48. - simpl.
  49. rewrite -> IHx.
  50. rewrite -> Bool.negb_involutive.
  51. reflexivity.
  52. Qed.
  53.  
  54. Lemma cancel_negb : forall a b : bool,
  55. negb a = negb b -> a = b.
  56. Proof.
  57. intros.
  58. destruct a.
  59. - destruct b.
  60. + reflexivity.
  61. + simpl in H.
  62. symmetry.
  63. apply H.
  64. - destruct b.
  65. + simpl in H.
  66. symmetry.
  67. apply H.
  68. + reflexivity.
  69. Qed.
  70.  
  71. Lemma even_is_xor : forall x y : nat,
  72. Nat.even (x+y) = negb (xorb (Nat.even x) (Nat.even y)).
  73. Proof.
  74. intros.
  75. induction x.
  76. - simpl.
  77. case (Nat.even y); reflexivity.
  78. - rewrite next_even_is_odd in IHx.
  79. rewrite (next_even_is_odd x) in IHx.
  80. apply cancel_negb in IHx.
  81. rewrite Nat.add_succ_l.
  82. rewrite -> IHx.
  83. clear IHx.
  84. rewrite Bool.negb_xorb_l.
  85. reflexivity.
  86. Qed.
  87.  
  88.  
  89.  
  90. Lemma square_even_is_even : forall x : nat,
  91. Nat.even (x*x) = Nat.even x.
  92. Proof.
  93. intros.
  94.  
  95. induction x.
  96. - simpl.
  97. reflexivity.
  98. (* (x + 1) * (x + 1) = x * x + 2 * x + 1 *)
  99. - replace (S x * S x) with ((1 + x) * (1 + x)).
  100. 2 : {
  101. simpl.
  102. reflexivity.
  103. }
  104. rewrite Nat.mul_add_distr_r.
  105. rewrite Nat.mul_add_distr_l.
  106. rewrite Nat.mul_add_distr_l.
  107. rewrite Nat.add_assoc.
  108. repeat rewrite Nat.mul_1_l.
  109. rewrite Nat.mul_1_r.
  110. repeat rewrite <- Nat.add_assoc.
  111. repeat rewrite even_is_xor.
  112. repeat rewrite <- IHx.
  113. replace (Nat.even 1) with false.
  114. 2 : { trivial. }
  115. rewrite -> Bool.xorb_false_l.
  116. rewrite -> Bool.xorb_nilpotent.
  117. replace (negb false) with true.
  118. 2 : { trivial. }
  119. rewrite -> Bool.xorb_true_r.
  120. rewrite -> Bool.negb_involutive.
  121. rewrite -> IHx.
  122. clear IHx.
  123. induction x.
  124. + simpl.
  125. reflexivity.
  126. + rewrite <- IHx.
  127. rewrite -> Bool.negb_involutive.
  128. simpl.
  129. reflexivity.
  130. Qed.
  131.  
  132. Lemma cancel_2 : forall x y : nat,
  133. 2 * x = 2 * y -> x = y.
  134. Proof.
  135. intros.
  136. omega.
  137. Qed.
  138.  
  139.  
  140. Theorem sqrt2_infinite_descent : forall p q : nat,
  141. q <> 0 -> p * p = 2 * q * q -> exists pp qq : nat,
  142. pp * pp = 2 * qq * qq /\ qq < q.
  143. Proof.
  144. intros p q qnz eq.
  145. assert (eq' := eq).
  146.  
  147. assert (Nat.even (p * p) = true).
  148. {
  149. rewrite -> eq.
  150. rewrite <- Nat.mul_assoc.
  151. apply two_times_x_is_even.
  152. }
  153. assert (Nat.even p = true).
  154. {
  155. rewrite square_even_is_even in H.
  156. apply H.
  157. }
  158. apply even_exists in H0.
  159. destruct H0 as [p' Hp'].
  160. repeat rewrite <- Hp' in eq.
  161. repeat rewrite <- Nat.mul_assoc in eq.
  162. apply cancel_2 in eq.
  163. rewrite Nat.mul_comm in eq.
  164. clear H.
  165.  
  166. assert (Nat.even (q * q) = true).
  167. {
  168. rewrite <- eq.
  169. rewrite <- Nat.mul_assoc.
  170. apply two_times_x_is_even.
  171. }
  172. assert (Nat.even q = true).
  173. {
  174. rewrite square_even_is_even in H.
  175. apply H.
  176. }
  177. apply even_exists in H0.
  178. destruct H0 as [q' Hq'].
  179. rewrite <- Hq' in eq.
  180. repeat rewrite <- Nat.mul_assoc in eq.
  181. apply cancel_2 in eq.
  182. symmetry in eq.
  183. rewrite Nat.mul_comm in eq.
  184. clear H.
  185. symmetry in eq.
  186.  
  187. exists p'.
  188. exists q'.
  189. split.
  190. apply eq.
  191.  
  192. omega.
  193. Qed.
  194.  
  195. Check sqrt2_infinite_descent.
  196.  
  197. Definition lt_nat (q q' : nat*nat) := snd q < snd q'.
  198.  
  199. Theorem lt_wf : well_founded lt_nat.
  200. Proof.
  201. apply (well_founded_lt_compat (nat*nat) snd).
  202. intros.
  203. unfold lt_nat in H.
  204. apply H.
  205. Qed.
  206.  
  207. Check well_founded.
  208. Check well_founded_ind.
  209.  
  210. Theorem infinite_descent' : forall f : nat*nat -> Prop,
  211. (forall A : nat*nat, (f A -> exists B : nat*nat, (f B) /\ (snd B) < (snd A))) ->
  212. forall C : nat * nat, ~(f C).
  213. Proof.
  214. intros f H.
  215. apply (well_founded_ind lt_wf (fun x => ~(f x))).
  216. simpl.
  217. intros.
  218. specialize (H x).
  219. unfold not.
  220. intros HA.
  221. apply H in HA.
  222. destruct HA as [B HA].
  223. specialize (H0 B).
  224. unfold lt_nat in H0.
  225. destruct HA.
  226. apply H0 in H2.
  227. apply H2.
  228. apply H1.
  229. Qed.
  230.  
  231. (*
  232. Theorem infinite_descent' : forall f : nat*nat -> Prop,
  233. (forall A : nat*nat, (f A -> exists B : nat*nat, (f B) /\ (snd B) < (snd A))) ->
  234. forall C : nat * nat, ~(f C).
  235. Proof.
  236. *)
  237.  
  238. Theorem infinite_descent : forall f : nat -> nat -> Prop,
  239. (forall p q : nat, ((f p q) -> exists pp qq : nat, (f pp qq) /\ qq < q)) ->
  240. forall r s : nat, ~(f r s).
  241. Proof.
  242. intros f H.
  243. intros r s.
  244. pose (rs := (r,s)).
  245. replace r with (fst rs); try reflexivity.
  246. replace s with (snd rs); try reflexivity.
  247. apply (well_founded_ind lt_wf (fun x => ~(f (fst x) (snd x)))).
  248. intros.
  249. specialize (H (fst x) (snd x)).
  250. intros HA.
  251. apply H in HA.
  252. destruct HA as [pp HA].
  253. destruct HA as [qq HA].
  254. destruct HA.
  255. pose (ppqq := (pp, qq)).
  256. specialize (H0 ppqq).
  257. unfold lt_nat in H0.
  258. replace qq with (snd ppqq) in H2; try reflexivity.
  259. apply H0 in H2.
  260. apply H2.
  261. simpl.
  262. apply H1.
  263. Qed.
  264.  
  265.  
  266. Theorem sqrt2_is_irrational : forall p q : nat,
  267. q <> 0 -> p*p <> 2*q*q.
  268. Proof.
  269. intros p q qnz.
  270. unfold not.
  271. intros eq.
  272. specialize (infinite_descent (fun (p q: nat) => p*p = 2*q*q)).
  273. intros id.
  274. specialize (id p q).
  275. simpl in id.
  276. simpl in eq.
  277. apply id in eq.
  278. apply eq.
  279. apply (sqrt2_infinite_descent p q).
  280. apply qnz.
  281. simpl.
  282. apply eq.
  283. Qed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement