-
Notifications
You must be signed in to change notification settings - Fork 0
/
helloworld.v
114 lines (90 loc) · 1.81 KB
/
helloworld.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
Require Import Bool.
Require Import Arith.
Require Import List.
Compute if true then 3 else 5.
Check 0.
Definition double (n : nat) := plus n n.
Check S 0.
Check double (S 0).
Compute double (S 0).
Definition is_zero (n : nat) :=
match n with
0 => true
| S _ => false
end.
Compute is_zero 0.
Compute is_zero (S 0).
Print pred.
Print Init.Nat.pred.
Fixpoint sum_n n :=
match n with
0 => 0
| S p => p + sum_n p
end.
Fixpoint sum_n2 n s :=
match n with
0 => s
| S p => sum_n2 p (p + s)
end.
Search Nat.eqb.
Fixpoint list_n n :=
match n with
0 => nil
| S p => (list_n p)++p::nil
end.
Compute list_n 5.
Definition is_sorted_head list :=
match list with
nil => true
| a :: nil => true
| a :: b :: tail => a <=? b
end.
SearchPattern (bool -> bool -> bool).
Fixpoint is_sorted list :=
match list with
nil => true
| a :: tail => andb (is_sorted_head list) (is_sorted tail)
end.
Compute is_sorted (1::2::3::nil).
Compute is_sorted (1::2::3::1::nil).
Fixpoint count_occurrences list n :=
match list with
nil => 0
| a :: tail => (if a =? n then 1 else 0) + (count_occurrences tail n)
end.
Compute count_occurrences (1::2::3::nil) 2.
Compute count_occurrences (1::2::3::1::nil) 1.
Compute count_occurrences (1::2::3::nil) 4.
Lemma example2 : forall a b:Prop, a /\ b -> b /\ a.
Proof.
intros a b H.
split.
destruct H as [H1 H2].
exact H2.
destruct H as [H1 H2].
exact H1.
Qed.
(*intuition.
Qed.*)
Lemma example3 : forall A B, A \/ B -> B \/ A.
Proof.
intros A B H.
destruct H as [H1 | H1].
right.
(*exact H1.*)
assumption.
left ; assumption.
Qed.
Lemma example4 : 3 <= 5.
Proof.
apply le_S.
apply le_S.
apply le_n.
Qed.
Lemma example5 : forall x y, x <= 10 -> 10 <= y -> x <= y.
Proof.
intros x y x10 y10.
apply le_trans with (m := 10).
assumption.
assumption.
Qed.