Guest User

Untitled

a guest
Jan 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. Require Import Datatypes.
  2. Require Import Bool.Bool.
  3. Require Import Coq.Arith.Arith_base.
  4. Require Import Coq.Lists.List.
  5.  
  6. Definition set := list nat.
  7.  
  8. Open Scope list_scope.
  9.  
  10. Fixpoint member (n : nat) (l : list nat) : bool :=
  11. match l with
  12. | nil => false
  13. | x :: xs => match beq_nat x n with
  14. | true => true
  15. | false => member n xs
  16. end
  17. end.
  18.  
  19. Fixpoint check (s : set) : bool :=
  20. match s with
  21. | nil => true
  22. | x :: xs => andb (negb (member x xs)) (check xs)
  23. end.
  24.  
  25. Fixpoint union (s1 s2 : set) : set :=
  26. match s1 with
  27. | nil => s2
  28. | x :: xs => match member x s2 with
  29. | true => union xs s2
  30. | false => x :: (union xs s2)
  31. end
  32. end.
  33.  
  34. Fixpoint intersection (s1 s2 : set) : set :=
  35. match s1 with
  36. | nil => nil
  37. | x :: xs => match member x s2 with
  38. | true => x :: intersection xs s2
  39. | false => intersection xs s2
  40. end
  41. end.
  42. Fixpoint difference (s1 s2 : set) : set :=
  43. match s1 with
  44. | nil => nil
  45. | x :: xs => match member x s2 with
  46. | true => difference xs s2
  47. | false => x :: difference xs s2
  48. end
  49. end.
  50.  
  51. Fixpoint cardinality (s : set) : nat :=
  52. match s with
  53. | nil => O
  54. | _ :: xs => S (cardinality xs)
  55. end.
  56.  
  57. Fixpoint ble_nat (n1 n2 : nat) : bool :=
  58. match n1 with
  59. | O => true
  60. | S n1' => match n2 with
  61. | O => false
  62. | S n2' => ble_nat n1' n2'
  63. end
  64. end.
  65.  
  66. Lemma union_empty_r : forall (s : set), union s nil = s.
  67. Proof.
  68. intros s.
  69. induction s. reflexivity.
  70. simpl. f_equal. apply IHs.
  71. Qed.
  72.  
  73. Lemma ble_nat_refl : forall n, ble_nat n n = true.
  74. Proof.
  75. intros n.
  76. induction n. reflexivity. simpl. rewrite IHn. reflexivity.
  77. Qed.
  78.  
  79. Theorem union_card_l : forall (s1 s2 : set), ble_nat (cardinality s1) (cardinality (union s1 s2)) = true.
  80. Proof.
  81. Admitted.
Add Comment
Please, Sign In to add comment