eksperymenty.v 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. From mathcomp Require Import all_ssreflect.
  2. From mathcomp Require Import algebra.rat.
  3. From mathcomp Require Import ssrint seq.
  4. Set Implicit Arguments.
  5. Unset Strict Implicit.
  6. Unset Printing Implicit Defensive.
  7. (*****************************
  8. Próby stworzenia biekcji (N*N) <-> N
  9. *****************************)
  10. Notation "√ n" := (Nat.sqrt n) (at level 51).
  11. (*
  12. 0: 0,0
  13. 1: 0,1
  14. 2: 1,0
  15. 3: 1,1
  16. 4: 0,2
  17. 5: 1,2
  18. 6: 2,0
  19. 7: 2,1
  20. 8: 2,2
  21. 9: 0,3
  22. *)
  23. Definition zgn (kw : nat) : (nat * nat) :=
  24. let n := √kw in
  25. let r := kw - n^2 in
  26. if r < n then (r,n) else (n,r-n).
  27. Eval compute in (map (fun x => (x, zgn x)) (iota 0 20)).
  28. Definition odgn (k : nat * nat) : nat :=
  29. let (a, b) := k in
  30. if a < b then b^2 + a else a^2+a +b.
  31. Eval compute in (map (fun x => (odgn (zgn x)) == x) (iota 0 70)).
  32. Lemma roznica_miedzy_kwadratami n : n.+1^2 = n^2 + 2*n +1.
  33. Proof.
  34. rewrite -addn1 sqrnD -![n^2 + _ + _]addnA [1 ^2 + 2*_]addnC -[1^2]/1 muln1 //.
  35. Qed.
  36. Lemma roznica_miedzy_kwadratami' n : n.+1^2 = (n^2 + 2*n).+1.
  37. Proof.
  38. rewrite -[in RHS]addn1. apply: roznica_miedzy_kwadratami.
  39. Qed.
  40. Lemma xqnat n m : (n*m)%coq_nat = n*m.
  41. Proof.
  42. done.
  43. Qed.
  44. Print xqnat.
  45. Lemma sqrt_specif (n: nat): (((√ n) ^ 2) <= n) && (n < ((√ n).+1)^2).
  46. Proof.
  47. move : (PeanoNat.Nat.sqrt_specif n) .
  48. rewrite !xqnat => [[h1 h2]].
  49. move : h1 h2 => /leP h1 /ltP h2.
  50. by apply /andP; split.
  51. Qed.
  52. Print sqrt_specif.
  53. Eval compute in (map (fun n => (√ n) ^ 2 + (n - ((√ n) ^ 2)) == n) (iota 0 40)).
  54. Lemma coo a b : a <= b -> a + (b - a) == b.
  55. Proof.
  56. move=>H.
  57. apply /eqP .
  58. apply: subnKC.
  59. assumption.
  60. Qed.
  61. Lemma xd n : (√ n) ^ 2 + (n - ((√ n) ^ 2)) == n.
  62. Proof.
  63. apply /eqP.
  64. apply: subnKC.
  65. by move: (sqrt_specif n) => /andP; case.
  66. Qed.
  67. Lemma roznica_miedzy_kwadratami'' n :
  68. ((√ (n.+1))^2 == ((√ n)^2 + 2*√(n)).+1) || ((√ (n.+1)) == √ n).
  69. Proof.
  70. apply /orP.
  71. case: (PeanoNat.Nat.sqrt_succ_or n) => -> ; [left| by right].
  72. rewrite roznica_miedzy_kwadratami' => //.
  73. Qed.
  74. Lemma roznica_miedzy_kwadratami''' n :
  75. (√ (n)) < √ (n.+1) -> (√ (n.+1))^2 == ((√ n)^2 + 2*√(n)).+1.
  76. Proof.
  77. move => H.
  78. move : (roznica_miedzy_kwadratami'' n) => /orP. case => // .
  79. by rewrite gtn_eqF.
  80. Qed.
  81. Lemma roznica_miedzy_kwadratami'''' n :
  82. (√ (n)) < √ (n.+1) -> (√ (n.+1))^2 = ((√ n)^2 + 2*√(n)).+1.
  83. Proof.
  84. move => H.
  85. apply /eqP.
  86. apply: roznica_miedzy_kwadratami'''.
  87. done.
  88. Qed.
  89. Lemma reszta_ogr n : (n - ((√ n) ^ 2)) <= (√ n).*2.
  90. elim: n => // n H.
  91. case: (PeanoNat.Nat.sqrt_succ_or n).
  92. move => Hx. rewrite Hx.
  93. rewrite roznica_miedzy_kwadratami'.
  94. rewrite subSS.
  95. (*
  96. subnDA: forall m n p : nat, n - (m + p) = n - m - p
  97. subnDr: forall p m n : nat, m + p - (n + p) = m - n
  98. subnDl: forall p m n : nat, p + m - (p + n) = m - n
  99. *)
  100. apply: (@leq_trans (n - (√ n) ^ 2)).
  101. apply: leq_sub2l.
  102. apply: leq_addr.
  103. apply: (@leq_trans (√ n).*2).
  104. apply: H.
  105. rewrite doubleS.
  106. rewrite -addn1 -addn1 -addnA.
  107. apply: leq_addr.
  108. (***************)
  109. move => Hx. rewrite Hx. (* rewrite [√ n.+1 in X in _ <= X]Hx.*)
  110. Lemma zo1 n : odgn (zgn n) == n.
  111. rewrite /zgn /odgn .
  112. case: ifP; [by move => ->; rewrite xd|rewrite ltnNge; move => /negbFE H].
  113. case: ifP.
  114. move => J.
  115. move: (roznica_miedzy_kwadratami'' n).
  116. (*
  117. H : nq <= r
  118. J : 2*nq < r (H potrzebne żeby to wywnioskować)
  119. Q: r <= 2*n
  120. 2*nq < r <= 2*n
  121. *)