Debian Codegraph @

test-suite/ssr/rewpatterns.v

raw
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
14 Require Import ssreflect.
15 Require Import ssrbool ssrfun TestSuite.ssr_mini_mathcomp.
16
17 Lemma test1 : forall x y (f : nat -> nat), f (x + y).+1 = f (y + x.+1).
18 by move=> x y f; rewrite [_.+1](addnC x.+1).
19 Qed.
20
21 Lemma test2 : forall x y f, x + y + f (y + x) + f (y + x) = x + y + f (y + x) + f (x + y).
22 by move=> x y f; rewrite {2}[in f _]addnC.
23 Qed.
24
25 Lemma test2' : forall x y f, true && f (x * (y + x)) = true && f(x * (x + y)).
26 by move=> x y f; rewrite [in f _](addnC y).
27 Qed.
28
29 Lemma test2'' : forall x y f, f (y + x) + f(y + x) + f(y + x) = f(x + y) + f(y + x) + f(x + y).
30 by move=> x y f; rewrite {1 3}[in f _](addnC y).
31 Qed.
32
33 (* patterns catching bound vars not supported *)
34 Lemma test2_1 : forall x y f, true && (let z := x in f (z * (y + x))) = true && f(x * (x + y)).
35 by move=> x y f; rewrite [in f _](addnC x). (* put y when bound var will be OK *)
36 Qed.
37
38 Lemma test3 : forall x y f, x + f (x + y) (f (y + x) x) = x + f (x + y) (f (x + y) x).
39 by move=> x y f; rewrite [in X in (f _ X)](addnC y).
40 Qed.
41
42 Lemma test3' : forall x y f, x = y -> x + f (x + x) x + f (x + x) x =
43 x + f (x + y) x + f (y + x) x.
44 by move=> x y f E; rewrite {2 3}[in X in (f X _)]E.
45 Qed.
46
47 Lemma test3'' : forall x y f, x = y -> x + f (x + y) x + f (x + y) x =
48 x + f (x + y) x + f (y + y) x.
49 by move=> x y f E; rewrite {2}[in X in (f X _)]E.
50 Qed.
51
52 Lemma test4 : forall x y f, x = y -> x + f (fun _ : nat => x + x) x + f (fun _ => x + x) x =
53 x + f (fun _ => x + y) x + f (fun _ => y + x) x.
54 by move=> x y f E; rewrite {2 3}[in X in (f X _)]E.
55 Qed.
56
57 Lemma test4' : forall x y f, x = y -> x + f (fun _ _ _ : nat => x + x) x =
58 x + f (fun _ _ _ => x + y) x.
59 by move=> x y f E; rewrite {2}[in X in (f X _)]E.
60 Qed.
61
62 Lemma test5 : forall x y f, x = y -> x + f (y + x) x + f (y + x) x =
63 x + f (x + y) x + f (y + x) x.
64 by move=> x y f E; rewrite {1}[X in (f X _)]addnC.
65 Qed.
66
67 Lemma test3''' : forall x y f, x = y -> x + f (x + y) x + f (x + y) (x + y) =
68 x + f (x + y) x + f (y + y) (x + y).
69 by move=> x y f E; rewrite {1}[in X in (f X X)]E.
70 Qed.
71
72 Lemma test3'''' : forall x y f, x = y -> x + f (x + y) x + f (x + y) (x + y) =
73 x + f (x + y) x + f (y + y) (y + y).
74 by move=> x y f E; rewrite [in X in (f X X)]E.
75 Qed.
76
77 Lemma test3x : forall x y f, y+y = x+y -> x + f (x + y) x + f (x + y) (x + y) =
78 x + f (x + y) x + f (y + y) (y + y).
79 by move=> x y f E; rewrite -[X in (f X X)]E.
80 Qed.
81
82 Lemma test6 : forall x y (f : nat -> nat), f (x + y).+1 = f (y.+1 + x).
83 by move=> x y f; rewrite [(x + y) in X in (f X)]addnC.
84 Qed.
85
86 Lemma test7 : forall x y (f : nat -> nat), f (x + y).+1 = f (y + x.+1).
87 by move=> x y f; rewrite [(x.+1 + y) as X in (f X)]addnC.
88 Qed.
89
90 Lemma manual x y z (f : nat -> nat -> nat) : (x + y).+1 + f (x.+1 + y) (z + (x + y).+1) = 0.
91 Proof.
92 rewrite [in f _]addSn.
93 match goal with |- (x + y).+1 + f (x + y).+1 (z + (x + y).+1) = 0 => idtac end.
94 rewrite -[X in _ = X]addn0.
95 match goal with |- (x + y).+1 + f (x + y).+1 (z + (x + y).+1) = 0 + 0 => idtac end.
96 rewrite -{2}[in X in _ = X](addn0 0).
97 match goal with |- (x + y).+1 + f (x + y).+1 (z + (x + y).+1) = 0 + (0 + 0) => idtac end.
98 rewrite [_.+1 in X in f _ X](addnC x.+1).
99 match goal with |- (x + y).+1 + f (x + y).+1 (z + (y + x.+1)) = 0 + (0 + 0) => idtac end.
100 rewrite [x.+1 + y as X in f X _]addnC.
101 match goal with |- (x + y).+1 + f (y + x.+1) (z + (y + x.+1)) = 0 + (0 + 0) => idtac end.
102 Admitted.
103
104 Goal (exists x : 'I_3, x > 0).
105 apply: (ex_intro _ (@Ordinal _ 2 _)).
106 Admitted.
107
108 Goal (forall y, 1 < y < 2 -> exists x : 'I_3, x > 0).
109 move=> y; case/andP=> y_gt1 y_lt2; apply: (ex_intro _ (@Ordinal _ y _)).
110 by apply: leq_trans y_lt2 _.
111 by move=> y_lt3; apply: leq_trans _ y_gt1.
112 Qed.
113
114 Goal (forall x y : nat, forall P : nat -> Prop, x = y -> True).
115 move=> x y P E.
116 have: P x -> P y by suff: x = y by move=> ?; congr (P _).
117 Admitted.
118
119 Goal forall a : bool, a -> true && a || false && a.
120 by move=> a ?; rewrite [true && _]/= [_ && a]/= orbC [_ || _]//=.
121 Qed.
122
123 Goal forall a : bool, a -> true && a || false && a.
124 by move=> a ?; rewrite [X in X || _]/= [X in _ || X]/= orbC [false && a as X in X || _]//=.
125 Qed.
126
127 Parameter a : bool.
128 Definition f x := x || a.
129 Definition g x := f x.
130
131 Goal a -> g false.
132 by move=> Ha; rewrite [g _]/f orbC Ha.
133 Qed.
134
135 Goal a -> g false || g false.
136 move=> Ha; rewrite {2}[g _]/f orbC Ha.
137 match goal with |- (is_true (false || true || g false)) => done end.
138 Qed.
139
140 Goal a -> (a && a || true && a) && true.
141 by move=> Ha; rewrite -[_ || _]/(g _) andbC /= Ha [g _]/f.
142 Qed.
143
144 Goal a -> (a || a) && true.
145 by move=> Ha; rewrite -[in _ || _]/(f _) Ha andbC /f.
146 Qed.