-
Notifications
You must be signed in to change notification settings - Fork 0
/
module1.v
104 lines (85 loc) · 1.69 KB
/
module1.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
Inductive nat : Type :=
| O : nat
| S : nat -> nat.
Definition pred (n : nat) : nat :=
match n with
| O => O
| S n' => n'
end.
Definition succ (n:nat) :nat :=
match n with
| O => (S O)
| S n' => S (S n')
end.
Definition minustwo (n: nat) : nat :=
match n with
| O => O
| S O => O
| S (S n') => n'
end.
Fixpoint evenb (n:nat) : bool :=
match n with
| O => true
| S O => false
| S n' => negb (evenb n')
end.
Definition oddb (n:nat) : bool := negb (evenb n).
Fixpoint plus (n:nat) (m:nat) : nat :=
match n with
| O => m
| S n' => S (plus n' m)
end.
Fixpoint mult (n m :nat) : nat :=
match n with
| O => O
| S O => m
| S n' => plus m (mult n' m)
end.
Fixpoint minus (n m : nat) : nat :=
match n, m with
| O, _ => O
| S n', O => n
| S n, S m => minus n m
end.
Fixpoint exp (base power :nat) : nat :=
match power with
| O => S O
| S n => mult base (exp base n)
end.
Fixpoint factorial (n:nat) : nat :=
match n with
| O => S O
| S O => S O
| S n' => mult n (factorial n')
end.
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.
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 blt_nat (n m : nat) : bool :=
match n with
| O => match m with
| O => false
| S _ => true
end
| S n' => match m with
| O => false
| S m' => blt_nat n' m'
end
end.