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pqr Hp Hq))
|
11 |
+
*)
|
12 |
+
|
13 |
+
Check false.
|
14 |
+
|
15 |
+
Check True.
|
16 |
+
|
17 |
+
Print True.
|
18 |
+
|
19 |
+
Theorem T3 : (not (1 = 2)).
|
20 |
+
Proof.
|
21 |
+
unfold not.
|
22 |
+
intros H.
|
23 |
+
discriminate H.
|
24 |
+
Qed.
|
25 |
+
|
26 |
+
Definition and_1 (p: P /\ Q) : P :=
|
27 |
+
match p with
|
28 |
+
| conj Hp Hq => Hp
|
29 |
+
end.
|
30 |
+
|
31 |
+
(*
|
32 |
+
(define-struct conj [a b])
|
33 |
+
(define-contract (And P Q (Struct conj P Q))
|
34 |
+
|
35 |
+
(: and_1 (All (P Q) (-> (And P Q) P)))
|
36 |
+
(define (and_1 p)
|
37 |
+
(conj-a p)))
|
38 |
+
*)
|
39 |
+
|
40 |
+
(*Theorem demorgan1 : forall P Q: Prop,
|
41 |
+
not(P \/ Q) <-> not P /\ not Q.
|
42 |
+
Proof.
|
43 |
+
intros P Q.
|
44 |
+
split.
|
45 |
+
constructor.
|
46 |
+
- (* intros H.*)
|
47 |
+
refine (fun H => _).
|
48 |
+
unfold not in *.
|
49 |
+
(* constructor *)
|
50 |
+
refine (conj _ _).
|
51 |
+
eauto.
|
52 |
+
eauto.*)
|
53 |
+
|
54 |
+
Theorem demorganprop: forall P Q: bool,
|
55 |
+
negb (orb P Q) = andb (negb P) (negb Q).
|
56 |
+
Proof.
|
57 |
+
intros P Q.
|
58 |
+
destruct P; destruct Q; reflexivity.
|
59 |
+
Qed.
|
60 |
+
|
61 |
+
Theorem demorganliteauto : forall P Q : Prop,
|
62 |
+
not (P \/ Q) <-> not P /\ not Q.
|
63 |
+
Proof.
|
64 |
+
intros P Q.
|
65 |
+
constructor.
|
66 |
+
- intros. constructor; info_eauto.
|
67 |
+
- intros. destruct H. unfold not. intros.
|
68 |
+
destruct H1; eauto.
|
69 |
+
Qed.
|
70 |
+
|
71 |
+
|
72 |
+
Inductive ArithExp : Set :=
|
73 |
+
| num : nat -> ArithExp
|
74 |
+
| add : ArithExp -> ArithExp -> ArithExp.
|
75 |
+
|
76 |
+
Definition a1 := num 1.
|
77 |
+
Definition a2 := add (num 2) a1.
|
78 |
+
Definition a4:= match a2 with
|
79 |
+
| add sub1 _ => sub1
|
80 |
+
| num _ => a1
|
81 |
+
end.
|
82 |
+
|
83 |
+
Eval compute in a4.
|
84 |
+
|
85 |
+
Inductive ArithExp1 : Set :=
|
86 |
+
| num1 (n : nat)
|
87 |
+
| add1 (l r : ArithExp1).
|
88 |
+
|
89 |
+
Definition partial := (add (num 3)).
|
90 |
+
Definition a3 := partial (num 5).
|
91 |
+
|
92 |
+
Eval compute in a3.
|
93 |
+
|
94 |
+
Fixpoint eval (e : ArithExp) : nat :=
|
95 |
+
match e with
|
96 |
+
| num n => n
|
97 |
+
| add e1 e2 => Nat.add (eval e1) (eval e2)
|
98 |
+
end.
|
99 |
+
|
100 |
+
Eval compute in (eval a3).
|
101 |
+
|
102 |
+
Fixpoint const_fold (e : ArithExp) : ArithExp :=
|
103 |
+
match e with
|
104 |
+
| num n => num n
|
105 |
+
| add l r =>
|
106 |
+
match l, r with
|
107 |
+
| num n1, num n2 => num (Nat.add n1 n2)
|
108 |
+
| l', r' => add (const_fold l') (const_fold r')
|
109 |
+
end
|
110 |
+
end.
|
111 |
+
|
112 |
+
Inductive Color : Set :=
|
113 |
+
| red : Color
|
114 |
+
| green : Color
|
115 |
+
| blue : Color.
|
116 |
+
|
117 |
+
Inductive RGB : Set :=
|
118 |
+
| mk :nat -> nat -> nat -> RGB.
|
119 |
+
|
120 |
+
Definition colorToRGB (c : Color) : RGB :=
|
121 |
+
match c with
|
122 |
+
| red => mk 255 0 0
|
123 |
+
| green => mk 0 255 0
|
124 |
+
| blue => mk 0 0 255
|
125 |
+
end.
|
126 |
+
|
127 |
+
Definition RGBtoColor (r: RGB) : Color :=
|
128 |
+
match r with
|
129 |
+
| mk 255 0 0 => red
|
130 |
+
| mk 0 255 0 => green
|
131 |
+
| mk 0 0 255 => blue
|
132 |
+
| _ => red
|
133 |
+
end.
|
134 |
+
|
135 |
+
Theorem colorRGB_roundtrip : forall c,
|
136 |
+
RGBtoColor (colorToRGB c) = c.
|
137 |
+
Proof.
|
138 |
+
intros c.
|
139 |
+
destruct c; reflexivity.
|
140 |
+
Qed.
|
141 |
+
|
142 |
+
Fixpoint double (n : nat) : nat :=
|
143 |
+
match n with
|
144 |
+
| 0 => 0
|
145 |
+
| S n' => S (S (double n'))
|
146 |
+
end.
|
147 |
+
|
148 |
+
Eval compute in double 10.
|
149 |
+
|
150 |
+
Theorem double_succ : forall n,
|
151 |
+
double (S n) = S (S (double n)).
|
152 |
+
Proof.
|
153 |
+
intros n.
|
154 |
+
simpl.
|
155 |
+
reflexivity.
|
156 |
+
Qed.
|
157 |
+
|
158 |
+
Inductive ev : nat -> Prop :=
|
159 |
+
| ev_0 : ev 0
|
160 |
+
| ev_SS : forall n,
|
161 |
+
ev n -> ev (S (S n)).
|
162 |
+
|
163 |
+
Fixpoint ev_pred (n : nat) : Prop :=
|
164 |
+
match n with
|
165 |
+
| 0 => True
|
166 |
+
| S (S n) => ev_pred n'
|
167 |
+
| _ => False
|
168 |
+
end.
|
169 |
+
|
170 |
+
Theorem ev_4 : ev 4.
|
171 |
+
Proof.
|
172 |
+
apply ev_SS.
|
173 |
+
apply ev_SS.
|
174 |
+
apply ev_0.
|
175 |
+
Qed.
|
176 |
+
|