-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathExcercism.v
145 lines (108 loc) · 2.19 KB
/
Excercism.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
Module Excercism.
Inductive bool : Set :=
| true : bool
| false : bool.
Check true.
Check false.
Eval compute in true.
Definition not ( b : bool ) : bool :=
match b with
| true => false
| false => true
end.
Check not true.
Eval compute in not true.
Example bool_not : not true = false.
Proof.
simpl.
reflexivity.
Qed.
Definition or ( b1 : bool ) ( b2 : bool ) : bool :=
match b1 with
| true => true
| false => b2
end.
Inductive nat :=
| O : nat
| S : nat -> nat.
Definition pred ( n : nat ) : nat :=
match n with
| O => O
| S n' => n'
end.
Eval compute in ( S ( S ( S O ))).
End Excercism.
Module Excercism2.
Fixpoint plus ( n : nat ) ( m : nat ) : nat :=
match n with
| O => m
| S n' => S ( plus n' m )
end.
Eval compute in ( plus 4 5 ).
Fixpoint mult ( n : nat ) ( m : nat ) : nat :=
match n with
| O => O
| S n' => plus m ( mult n' m )
end.
Eval compute in ( mult 12 3 ).
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.
End Excercism2.
Fixpoint evenb ( n : nat ) : bool :=
match n with
| O => true
| S O => false
| S ( S n' ) => evenb n'
end.
Extraction Language Haskell.
Extraction plus.
Extraction Language Ocaml.
Extraction plus.
Theorem plus_0_n : forall n : nat, 0 + n = n.
Proof.
intros n.
simpl.
reflexivity.
Qed.
Theorem plus_id_example : forall n m : nat,
m = n -> m + n = n + n .
Proof.
intros n m.
intros H.
rewrite H.
reflexivity.
Qed.
Require Import Arith.
Theorem plus_1_neg_0 : forall n : nat,
beq_nat ( n + 1 ) 0 = false.
Proof.
intros n.
destruct n as [|n'].
simpl.
reflexivity.
simpl.
reflexivity.
Qed.
Theorem plus_0_r : forall n : nat,
n + 0 = n .
Proof.
intros n.
induction n as [|n'].
reflexivity.
simpl.
rewrite -> IHn'.
reflexivity.
Qed.
Check Type.
Inductive even : nat -> Prop :=
| ev_O : even O
| ev_SS : forall n : nat, even n -> even ( S ( S n ) ).