Advertisement
Guest User

Untitled

a guest
Apr 29th, 2020
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. Require Import Nat Arith Lia.
  2.  
  3. Section Q.
  4.  
  5. Open Scope nat_scope.
  6.  
  7. Section StrongInduction.
  8.  
  9. Variable P:nat -> Prop.
  10.  
  11. Hypothesis IH : forall m, (forall n, n < m -> P n) -> P m.
  12.  
  13. Lemma P0 : P 0.
  14. Proof.
  15. apply IH; intros.
  16. exfalso; inversion H.
  17. Qed.
  18.  
  19. Hint Resolve P0.
  20.  
  21. Lemma pred_increasing : forall n m,
  22. n <= m ->
  23. Nat.pred n <= Nat.pred m.
  24. Proof.
  25. induction n; cbn; intros.
  26. apply le_0_n.
  27. induction H; subst; cbn; eauto.
  28. destruct m; eauto.
  29. Qed.
  30.  
  31. Hint Resolve le_S_n.
  32.  
  33. Local Lemma strong_induction_all : forall n,
  34. (forall m, m <= n -> P m).
  35. Proof.
  36. induction n; intros;
  37. match goal with
  38. | [ H: _ <= _ |- _ ] =>
  39. inversion H
  40. end; eauto.
  41. Qed.
  42.  
  43. Theorem strong_induction : forall n, P n.
  44. Proof.
  45. eauto using strong_induction_all.
  46. Qed.
  47.  
  48. End StrongInduction.
  49.  
  50. Tactic Notation "strong" "induction" ident(n) := induction n using strong_induction.
  51.  
  52. Lemma evenEx: forall (n : nat),
  53. Nat.even n = true -> exists x, 2 * x = n.
  54. Proof.
  55. intros.
  56. strong induction n.
  57. destruct n.
  58. - exists 0; auto.
  59. - destruct n.
  60. + inversion H.
  61. + assert (exists x, 2 * x = n).
  62. { apply H0; auto. }
  63. inversion H1.
  64. exists (x + 1).
  65. lia.
  66. Qed.
  67.  
  68. Lemma p: forall x y,
  69. 0 < x -> 0 < y ->
  70. x * x <> 2 * y * y.
  71. Proof.
  72. intros x.
  73. strong induction x.
  74. intros y Zx Zy contra.
  75. destruct (even x)eqn:EX.
  76. - destruct (even y)eqn:EY.
  77. + apply evenEx in EX.
  78. inversion EX.
  79. apply evenEx in EY.
  80. inversion EY.
  81. subst.
  82. assert (HC: x0 * x0 = 2 * x1 * x1).
  83. { lia. }
  84. assert (x0 * x0 <> 2 * x1 * x1).
  85. { apply H; lia. }
  86. auto.
  87. + apply evenEx in EX.
  88. inversion EX.
  89. subst.
  90. rewrite <- Nat.negb_odd in EY.
  91. apply Bool.negb_false_iff in EY.
  92. assert (HC: 2 * x0 * x0 = y * y).
  93. { lia. }
  94. assert (Nat.odd (y * y) = true).
  95. {
  96. rewrite Nat.odd_mul.
  97. intuition.
  98. }
  99. assert (Nat.odd (y * y) = false).
  100. {
  101. rewrite <- HC.
  102. apply Bool.negb_false_iff.
  103. replace (2 * x0 * x0) with (0 + 2 * (x0 * x0)) by lia.
  104. apply Nat.even_add_mul_2.
  105. }
  106. rewrite H0 in H1.
  107. inversion H1.
  108. - rewrite <- Nat.negb_odd in EX.
  109. apply Bool.negb_false_iff in EX.
  110. assert (Nat.odd (x * x) = true).
  111. {
  112. rewrite Nat.odd_mul.
  113. intuition.
  114. }
  115. assert (Nat.even (2 * y * y) = true).
  116. {
  117. rewrite Nat.even_mul.
  118. replace (2 * y) with (0 + 2 * y) by lia.
  119. rewrite Nat.even_add_mul_2.
  120. auto.
  121. }
  122. rewrite contra in H0.
  123. apply Bool.negb_false_iff in H1.
  124. rewrite Nat.negb_even in H1.
  125. rewrite H0 in H1.
  126. inversion H1.
  127. Qed.
  128.  
  129.  
  130. End Q.
  131.  
  132. Require Import Reals Lra.
  133. Open Scope R_scope.
  134.  
  135. Lemma d: forall x y z,
  136. y <> 0 ->
  137. x / y = z -> x = z * y.
  138. Proof.
  139. intros.
  140. subst.
  141. unfold Rdiv.
  142. rewrite Rmult_assoc.
  143. field.
  144. auto.
  145. Qed.
  146.  
  147. Lemma sqrt2: forall x y,
  148. (0 < x)%nat -> (0 < y)%nat ->
  149. INR x / INR y <> sqrt 2.
  150. Proof.
  151. intros x y Zx Zy contra.
  152. symmetry in contra.
  153. apply sqrt_lem_0 in contra.
  154. * replace (INR x / INR y * (INR x / INR y)) with
  155. (INR x * INR x / (INR y * INR y)) in *.
  156. rewrite <- mult_INR in contra.
  157. rewrite <- mult_INR in contra.
  158. apply d in contra.
  159. assert (HC: (x * x)%nat <> (2 * y * y)%nat).
  160. { apply p; auto. }
  161. apply not_INR in HC.
  162. replace (INR (2 * y * y)) with (2 * INR (y * y)) in HC.
  163. auto.
  164. symmetry.
  165. replace ((2 * y * y)%nat) with ((2 * (y * y))%nat) by lia.
  166. rewrite mult_INR.
  167. auto.
  168. apply not_0_INR.
  169. intros HC.
  170. inversion HC.
  171. destruct y.
  172. inversion Zy.
  173. inversion HC.
  174. field.
  175. apply not_0_INR.
  176. lia.
  177. * lra.
  178. * apply Rlt_le.
  179. apply Rdiv_lt_0_compat;
  180. replace 0 with (INR 0);
  181. try apply lt_INR; auto.
  182. Qed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement