| 1 |
(************************************************************************) |
| 2 |
(* * The Rocq Prover / The Rocq Development Team *) |
| 3 |
(* v * Copyright INRIA, CNRS and contributors *) |
| 4 |
(* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 |
(* \VV/ **************************************************************) |
| 6 |
(* // * This file is distributed under the terms of the *) |
| 7 |
(* * GNU Lesser General Public License Version 2.1 *) |
| 8 |
(* * (see LICENSE file for the text of the license) *) |
| 9 |
(************************************************************************) |
| 10 |
|
| 11 |
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) |
| 12 |
|
| 13 |
Require Import ssreflect. |
| 14 |
Require Import ssrbool ssrfun TestSuite.ssr_mini_mathcomp. |
| 15 |
Axiom daemon : False. Ltac myadmit := case: daemon. |
| 16 |
|
| 17 |
(* Ltac debugging feature: recursive elim + eq generation *) |
| 18 |
Lemma testL1 : forall A (s : seq A), s = s. |
| 19 |
Proof. |
| 20 |
move=> A s; elim branch: s => [|x xs _]. |
| 21 |
match goal with _ : _ = [::] |- [::] = [::] => move: branch => // | _ => fail end. |
| 22 |
match goal with _ : _ = _ :: _ |- _ :: _ = _ :: _ => move: branch => // | _ => fail end. |
| 23 |
Qed. |
| 24 |
|
| 25 |
(* The same but with explicit eliminator and a conflict in the intro pattern *) |
| 26 |
Lemma testL2 : forall A (s : seq A), s = s. |
| 27 |
Proof. |
| 28 |
move=> A s; elim/last_ind branch: s => [|x s _]. |
| 29 |
match goal with _ : _ = [::] |- [::] = [::] => move: branch => // | _ => fail end. |
| 30 |
match goal with _ : _ = rcons _ _ |- rcons _ _ = rcons _ _ => move: branch => // | _ => fail end. |
| 31 |
Qed. |
| 32 |
|
| 33 |
(* The same but without names for variables involved in the generated eq *) |
| 34 |
Lemma testL3 : forall A (s : seq A), s = s. |
| 35 |
Proof. |
| 36 |
move=> A s; elim branch: s. |
| 37 |
match goal with _ : _ = [::] |- [::] = [::] => move: branch => // | _ => fail end. |
| 38 |
move=> _; match goal with _ : _ = _ :: _ |- _ :: _ = _ :: _ => move: branch => // | _ => fail end. |
| 39 |
Qed. |
| 40 |
|
| 41 |
Inductive foo : Type := K1 : foo | K2 : foo -> foo -> foo | K3 : (nat -> foo) -> foo. |
| 42 |
|
| 43 |
(* The same but with more intros to be done *) |
| 44 |
Lemma testL4 : forall (o : foo), o = o. |
| 45 |
Proof. |
| 46 |
move=> o; elim branch: o. |
| 47 |
match goal with _ : _ = K1 |- K1 = K1 => move: branch => // | _ => fail end. |
| 48 |
move=> _; match goal with _ : _ = K2 _ _ |- K2 _ _ = K2 _ _ => move: branch => // | _ => fail end. |
| 49 |
move=> _; match goal with _ : _ = K3 _ |- K3 _ = K3 _ => move: branch => // | _ => fail end. |
| 50 |
Qed. |
| 51 |
|
| 52 |
(* Occurrence counting *) |
| 53 |
Lemma testO1: forall (b : bool), b = b. |
| 54 |
Proof. |
| 55 |
move=> b; case: (b) / idP. |
| 56 |
match goal with |- is_true b -> true = true => done | _ => fail end. |
| 57 |
match goal with |- ~ is_true b -> false = false => done | _ => fail end. |
| 58 |
Qed. |
| 59 |
|
| 60 |
(* The same but only the second occ *) |
| 61 |
Lemma testO2: forall (b : bool), b = b. |
| 62 |
Proof. |
| 63 |
move=> b; case: {2}(b) / idP. |
| 64 |
match goal with |- is_true b -> b = true => done | _ => fail end. |
| 65 |
match goal with |- ~ is_true b -> b = false => move/(introF idP) => // | _ => fail end. |
| 66 |
Qed. |
| 67 |
|
| 68 |
(* The same but with eq generation *) |
| 69 |
Lemma testO3: forall (b : bool), b = b. |
| 70 |
Proof. |
| 71 |
move=> b; case E: {2}(b) / idP. |
| 72 |
match goal with _ : is_true b, _ : b = true |- b = true => move: E => _; done | _ => fail end. |
| 73 |
match goal with H : ~ is_true b, _ : b = false |- b = false => move: E => _; move/(introF idP): H => // | _ => fail end. |
| 74 |
Qed. |
| 75 |
|
| 76 |
(* Views *) |
| 77 |
Lemma testV1 : forall A (s : seq A), s = s. |
| 78 |
Proof. |
| 79 |
move=> A s; case/lastP E: {1}s => [| x xs]. |
| 80 |
match goal with _ : s = [::] |- [::] = s => symmetry; exact E | _ => fail end. |
| 81 |
match goal with _ : s = rcons x xs |- rcons _ _ = s => symmetry; exact E | _ => fail end. |
| 82 |
Qed. |
| 83 |
|
| 84 |
Lemma testV2 : forall A (s : seq A), s = s. |
| 85 |
Proof. |
| 86 |
move=> A s; case/lastP E: s => [| x xs]. |
| 87 |
match goal with _ : s = [::] |- [::] = [::] => done | _ => fail end. |
| 88 |
match goal with _ : s = rcons x xs |- rcons _ _ = rcons _ _ => done | _ => fail end. |
| 89 |
Qed. |
| 90 |
|
| 91 |
Lemma testV3 : forall A (s : seq A), s = s. |
| 92 |
Proof. |
| 93 |
move=> A s; case/lastP: s => [| x xs]. |
| 94 |
match goal with |- [::] = [::] => done | _ => fail end. |
| 95 |
match goal with |- rcons _ _ = rcons _ _ => done | _ => fail end. |
| 96 |
Qed. |
| 97 |
|
| 98 |
(* Patterns *) |
| 99 |
Lemma testP1: forall (x y : nat), (y == x) && (y == x) -> y == x. |
| 100 |
move=> x y; elim: {2}(_ == _) / eqP. |
| 101 |
match goal with |- (y = x -> is_true ((y == x) && true) -> is_true (y == x)) => move=> -> // | _ => fail end. |
| 102 |
match goal with |- (y <> x -> is_true ((y == x) && false) -> is_true (y == x)) => move=> _; rewrite andbC // | _ => fail end. |
| 103 |
Qed. |
| 104 |
|
| 105 |
(* The same but with an implicit pattern *) |
| 106 |
Lemma testP2 : forall (x y : nat), (y == x) && (y == x) -> y == x. |
| 107 |
move=> x y; elim: {2}_ / eqP. |
| 108 |
match goal with |- (y = x -> is_true ((y == x) && true) -> is_true (y == x)) => move=> -> // | _ => fail end. |
| 109 |
match goal with |- (y <> x -> is_true ((y == x) && false) -> is_true (y == x)) => move=> _; rewrite andbC // | _ => fail end. |
| 110 |
Qed. |
| 111 |
|
| 112 |
(* The same but with an eq generation switch *) |
| 113 |
Lemma testP3 : forall (x y : nat), (y == x) && (y == x) -> y == x. |
| 114 |
move=> x y; elim E: {2}_ / eqP. |
| 115 |
match goal with _ : y = x |- (is_true ((y == x) && true) -> is_true (y == x)) => rewrite E; reflexivity | _ => fail end. |
| 116 |
match goal with _ : y <> x |- (is_true ((y == x) && false) -> is_true (y == x)) => rewrite E => /= H; exact H | _ => fail end. |
| 117 |
Qed. |
| 118 |
|
| 119 |
Inductive spec : nat -> nat -> nat -> Prop := |
| 120 |
| specK : forall a b c, a = 0 -> b = 2 -> c = 4 -> spec a b c. |
| 121 |
Lemma specP : spec 0 2 4. Proof. by constructor. Qed. |
| 122 |
|
| 123 |
Lemma testP4 : (1+1) * 4 = 2 + (1+1) + (2 + 2). |
| 124 |
Proof. |
| 125 |
case: specP => a b c defa defb defc. |
| 126 |
match goal with |- (a.+1 + a.+1) * c = b + (a.+1 + a.+1) + (b + b) => subst; done | _ => fail end. |
| 127 |
Qed. |
| 128 |
|
| 129 |
Lemma testP5 : (1+1) * 4 = 2 + (1+1) + (2 + 2). |
| 130 |
Proof. |
| 131 |
case: (1 + 1) _ / specP => a b c defa defb defc. |
| 132 |
match goal with |- b * c = a.+2 + b + (a.+2 + a.+2) => subst; done | _ => fail end. |
| 133 |
Qed. |
| 134 |
|
| 135 |
Lemma testP6 : (1+1) * 4 = 2 + (1+1) + (2 + 2). |
| 136 |
Proof. |
| 137 |
case: {2}(1 + 1) _ / specP => a b c defa defb defc. |
| 138 |
match goal with |- (a.+1 + a.+1) * c = a.+2 + b + (a.+2 + a.+2) => subst; done | _ => fail end. |
| 139 |
Qed. |
| 140 |
|
| 141 |
Lemma testP7 : (1+1) * 4 = 2 + (1+1) + (2 + 2). |
| 142 |
Proof. |
| 143 |
case: _ (1 + 1) (2 + _) / specP => a b c defa defb defc. |
| 144 |
match goal with |- b * a.+4 = c + c => subst; done | _ => fail end. |
| 145 |
Qed. |
| 146 |
|
| 147 |
Lemma testP8 : (1+1) * 4 = 2 + (1+1) + (2 + 2). |
| 148 |
Proof. |
| 149 |
case E: (1 + 1) (2 + _) / specP=> [a b c defa defb defc]. |
| 150 |
match goal with |- b * a.+4 = c + c => subst; done | _ => fail end. |
| 151 |
Qed. |
| 152 |
|
| 153 |
Parameters (T : Type) (tr : T -> T). |
| 154 |
|
| 155 |
Inductive exec (cf0 cf1 : T) : seq T -> Prop := |
| 156 |
| exec_step : tr cf0 = cf1 -> exec cf0 cf1 [::] |
| 157 |
| exec_star : forall cf2 t, tr cf0 = cf2 -> |
| 158 |
exec cf2 cf1 t -> exec cf0 cf1 (cf2 :: t). |
| 159 |
|
| 160 |
Inductive execr (cf0 cf1 : T) : seq T -> Prop := |
| 161 |
| execr_step : tr cf0 = cf1 -> execr cf0 cf1 [::] |
| 162 |
| execr_star : forall cf2 t, execr cf0 cf2 t -> |
| 163 |
tr cf2 = cf1 -> execr cf0 cf1 (t ++ [:: cf2]). |
| 164 |
|
| 165 |
Lemma execP : forall cf0 cf1 t, exec cf0 cf1 t <-> execr cf0 cf1 t. |
| 166 |
Proof. |
| 167 |
move=> cf0 cf1 t; split => [] Ecf. |
| 168 |
elim: Ecf. |
| 169 |
match goal with |- forall cf2 cf3 : T, tr cf2 = cf3 -> |
| 170 |
execr cf2 cf3 [::] => myadmit | _ => fail end. |
| 171 |
match goal with |- forall (cf2 cf3 cf4 : T) (t0 : seq T), |
| 172 |
tr cf2 = cf4 -> exec cf4 cf3 t0 -> execr cf4 cf3 t0 -> |
| 173 |
execr cf2 cf3 (cf4 :: t0) => myadmit | _ => fail end. |
| 174 |
elim: Ecf. |
| 175 |
match goal with |- forall cf2 : T, |
| 176 |
tr cf0 = cf2 -> exec cf0 cf2 [::] => myadmit | _ => fail end. |
| 177 |
match goal with |- forall (cf2 cf3 : T) (t0 : seq T), |
| 178 |
execr cf0 cf3 t0 -> exec cf0 cf3 t0 -> tr cf3 = cf2 -> |
| 179 |
exec cf0 cf2 (t0 ++ [:: cf3]) => myadmit | _ => fail end. |
| 180 |
Qed. |
| 181 |
|
| 182 |
Fixpoint plus (m n : nat) {struct n} : nat := |
| 183 |
match n with |
| 184 |
| 0 => m |
| 185 |
| S p => S (plus m p) |
| 186 |
end. |
| 187 |
|
| 188 |
Definition plus_equation : |
| 189 |
forall m n : nat, |
| 190 |
plus m n = |
| 191 |
match n with |
| 192 |
| 0 => m |
| 193 |
| p.+1 => (plus m p).+1 |
| 194 |
end |
| 195 |
:= |
| 196 |
fun m n : nat => |
| 197 |
match |
| 198 |
n as n0 |
| 199 |
return |
| 200 |
(forall m0 : nat, |
| 201 |
plus m0 n0 = |
| 202 |
match n0 with |
| 203 |
| 0 => m0 |
| 204 |
| p.+1 => (plus m0 p).+1 |
| 205 |
end) |
| 206 |
with |
| 207 |
| 0 => @erefl nat |
| 208 |
| n0.+1 => fun m0 : nat => erefl (plus m0 n0).+1 |
| 209 |
end m. |
| 210 |
|
| 211 |
Definition plus_rect : |
| 212 |
forall (m : nat) (P : nat -> nat -> Type), |
| 213 |
(forall n : nat, n = 0 -> P 0 m) -> |
| 214 |
(forall n p : nat, |
| 215 |
n = p.+1 -> P p (plus m p) -> P p.+1 (plus m p).+1) -> |
| 216 |
forall n : nat, P n (plus m n) |
| 217 |
:= |
| 218 |
fun (m : nat) (P : nat -> nat -> Type) |
| 219 |
(f0 : forall n : nat, n = 0 -> P 0 m) |
| 220 |
(f : forall n p : nat, |
| 221 |
n = p.+1 -> P p (plus m p) -> P p.+1 (plus m p).+1) => |
| 222 |
fix plus0 (n : nat) : P n (plus m n) := |
| 223 |
eq_rect_r [eta P n] |
| 224 |
(let f1 := f0 n in |
| 225 |
let f2 := f n in |
| 226 |
match |
| 227 |
n as n0 |
| 228 |
return |
| 229 |
(n = n0 -> |
| 230 |
(forall p : nat, |
| 231 |
n0 = p.+1 -> P p (plus m p) -> P p.+1 (plus m p).+1) -> |
| 232 |
(n0 = 0 -> P 0 m) -> |
| 233 |
P n0 match n0 with |
| 234 |
| 0 => m |
| 235 |
| p.+1 => (plus m p).+1 |
| 236 |
end) |
| 237 |
with |
| 238 |
| 0 => |
| 239 |
fun (_ : n = 0) |
| 240 |
(_ : forall p : nat, |
| 241 |
0 = p.+1 -> |
| 242 |
P p (plus m p) -> P p.+1 (plus m p).+1) |
| 243 |
(f4 : 0 = 0 -> P 0 m) => unkeyed (f4 (erefl 0)) |
| 244 |
| n0.+1 => |
| 245 |
fun (_ : n = n0.+1) |
| 246 |
(f3 : forall p : nat, |
| 247 |
n0.+1 = p.+1 -> |
| 248 |
P p (plus m p) -> P p.+1 (plus m p).+1) |
| 249 |
(_ : n0.+1 = 0 -> P 0 m) => |
| 250 |
let f5 := |
| 251 |
let p := n0 in |
| 252 |
let H := erefl n0.+1 : n0.+1 = p.+1 in f3 p H in |
| 253 |
unkeyed (let Hrec := plus0 n0 in f5 Hrec) |
| 254 |
end (erefl n) f2 f1) (plus_equation m n). |
| 255 |
|
| 256 |
Definition plus_ind := plus_rect. |
| 257 |
|
| 258 |
Lemma exF x y z: plus (plus x y) z = plus x (plus y z). |
| 259 |
elim/plus_ind: z / (plus _ z). |
| 260 |
match goal with |- forall n : nat, n = 0 -> plus x y = plus x (plus y 0) => idtac end. |
| 261 |
Undo 2. |
| 262 |
elim/plus_ind: (plus _ z). |
| 263 |
match goal with |- forall n : nat, n = 0 -> plus x y = plus x (plus y 0) => idtac end. |
| 264 |
Undo 2. |
| 265 |
elim/plus_ind: {z}(plus _ z). |
| 266 |
match goal with |- forall n : nat, n = 0 -> plus x y = plus x (plus y 0) => idtac end. |
| 267 |
Undo 2. |
| 268 |
elim/plus_ind: {z}_. |
| 269 |
match goal with |- forall n : nat, n = 0 -> plus x y = plus x (plus y 0) => idtac end. |
| 270 |
Undo 2. |
| 271 |
elim/plus_ind: z / _. |
| 272 |
match goal with |- forall n : nat, n = 0 -> plus x y = plus x (plus y 0) => idtac end. |
| 273 |
done. |
| 274 |
by move=> _ p _ ->. |
| 275 |
Qed. |
| 276 |
|
| 277 |
(* BUG elim-False *) |
| 278 |
Lemma testeF : False -> 1 = 0. |
| 279 |
Proof. by elim. Qed. |