Advertisement
tinyevil

Untitled

Jan 31st, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. Inductive even : nat -> Prop :=
  2. | ev_0 : even 0
  3. | ev_2 : even 2
  4. | ev_sum : forall n m, even n -> even m -> even (n + m).
  5.  
  6. Inductive ev : nat -> Prop :=
  7. | e_0 : ev 0
  8. | e_SS : forall n, ev n -> ev (S (S n)).
  9.  
  10. Lemma induction_2 : forall P:nat->Prop,
  11. P 0 ->
  12. P 1 ->
  13. (forall n, P n -> P (S (S n))) ->
  14. forall n, P n.
  15. Proof.
  16. intros P P_0 P_1 P_SS n.
  17. refine ((fix F (n:nat) := match n as n0 return P n0 with
  18. | O => _
  19. | S O => _
  20. | S (S n') => _
  21. end) n).
  22. - assumption.
  23. - assumption.
  24. - apply P_SS.
  25. apply F.
  26. Qed.
  27.  
  28. Require Import Omega.
  29.  
  30. Theorem even_plus : forall n m, ev n -> ev m -> ev (n + m).
  31. Proof.
  32. apply (induction_2 (fun n => forall m : nat, ev n -> ev m -> ev (n + m))).
  33. - trivial.
  34. - intros.
  35. inversion H.
  36. - intros.
  37. inversion H0.
  38. assert (K : S (S n) + m = n + (S (S m))).
  39. { omega. }
  40. rewrite K.
  41. apply H.
  42. + assumption.
  43. + constructor. assumption.
  44. Qed.
  45.  
  46. Theorem ev_implies_even : forall n, ev n -> even n.
  47. Proof.
  48. apply (induction_2 (fun n => ev n -> even n )).
  49. - constructor.
  50. - intros H. inversion H.
  51. - intros n IHn H.
  52. inversion H.
  53. apply (ev_sum 2 n).
  54. + exact ev_2.
  55. + apply IHn. assumption.
  56. Qed.
  57.  
  58. Theorem even_implies_ev : forall n, even n -> ev n.
  59. Proof.
  60. intros n H.
  61. induction H.
  62. - constructor.
  63. - exact (e_SS 0 e_0).
  64. - apply even_plus.
  65. + assumption.
  66. + assumption.
  67. Qed.
  68.  
  69. Theorem even_eq_ev : forall n, even n <-> ev n.
  70. Proof.
  71. split.
  72. - apply even_implies_ev.
  73. - apply ev_implies_even.
  74. Qed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement