-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaula3.v
128 lines (103 loc) · 2.65 KB
/
aula3.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Fixpoint evenb (n:nat) : bool :=
match n with
| O => true
| S O => false
| S (S n') => evenb n'
end.
Definition oddb (n:nat) : bool := negb (evenb n).
Example test_oddb1: oddb 1 = true.
Proof. simpl. reflexivity. Qed.
Example test_oddb2: oddb 4 = false.
Proof. simpl. reflexivity. Qed.
Module NatPlayground2.
Fixpoint plus (n : nat) (m : nat) : nat :=
match n with
| O => m
| S n' => S (plus n' m)
end.
Compute (plus 3 2).
(* plus (S (S (S O))) (S (S O))
==> S (plus (S (S O)) (S (S O)))
by the second clause of the match
==> S (S (plus (S O) (S (S O))))
by the second clause of the match
==> S (S (S (plus O (S (S O)))))
by the second clause of the match
==> S (S (S (S (S O))))
by the first clause of the match
*)
Fixpoint mult (n m : nat) : nat :=
match n with
| O => O
| S n' => plus m (mult n' m)
end.
Example test_mult1: (mult 3 3) = 9.
Proof. simpl. reflexivity. Qed.
Fixpoint minus (n m:nat) : nat :=
match n, m with
| O , _ => O
| S _ , O => n
| S n', S m' => minus n' m'
end.
End NatPlayground2.
Notation "x + y" := (plus x y)
(at level 50, left associativity)
: nat_scope.
Notation "x - y" := (minus x y)
(at level 50, left associativity)
: nat_scope.
Notation "x * y" := (mult x y)
(at level 40, left associativity)
: nat_scope.
Check ((0 + 1) + 1).
Fixpoint factorial (n:nat) : nat :=
match n with
| 0 => 1
| S n' => n * factorial n'
end.
Example test_factorial1: (factorial 3) = 6.
Proof.
simpl.
reflexivity.
Qed.
Example test_factorial2: (factorial 5) = (mult 10 12).
simpl.
reflexivity.
Qed.
Fixpoint beq_nat (n m : nat) : bool :=
match n with
| O => match m with
| O => true
| S m' => false
end
| S n' => match m with
| O => false
| S m' => beq_nat n' m'
end
end.
Fixpoint leb_nat (n m : nat) : bool :=
match n with
| O => true
| S n' =>
match m with
| O => false
| S m' => leb_nat n' m'
end
end.
Example test_leb1: (leb_nat 2 2) = true.
Proof. simpl. reflexivity. Qed.
Example test_leb2: (leb_nat 2 4) = true.
Proof. simpl. reflexivity. Qed.
Example test_leb3: (leb_nat 4 2) = false.
Proof. simpl. reflexivity. Qed.
Definition ltb_nat (n m : nat) : bool :=
leb_nat (S n) m.
Example test_ltb_nat1: (ltb_nat 2 2) = false.
Proof.
reflexivity.
Qed.
Example test_ltb_nat2: (ltb_nat 2 4) = true.
reflexivity.
Qed.
Example test_ltb_nat3: (ltb_nat 4 2) = false.
(* FILL IN HERE *) Admitted.