Debian Codegraph @

test-suite/success/simpl_tuning.v

raw
1 (* as it is dynamically inferred by simpl *)
2 Arguments minus !n / m.
3
4 Lemma foo x y : S (S x) - S y = 0.
5 simpl.
6 match goal with |- (match y with O => S x | S _ => _ end = 0) => idtac end.
7 Abort.
8
9 (* we avoid exposing a match *)
10 Arguments minus n m : simpl nomatch.
11
12 Lemma foo x : minus 0 x = 0.
13 simpl.
14 match goal with |- (0 = 0) => idtac end.
15 Abort.
16
17 Lemma foo x y : S (S x) - S y = 0.
18 simpl.
19 match goal with |- (S x - y = 0) => idtac end.
20 Abort.
21
22 Lemma foo x y : S (S x) - (S (match y with O => O | S z => S z end)) = 0.
23 simpl.
24 match goal with |-(S x - (match y with O => _ | S _ => _ end) = 0) => idtac end.
25 Abort.
26
27 (* we unfold as soon as we have 1 args, but we avoid exposing a match *)
28 Arguments minus n / m : simpl nomatch.
29
30 Lemma foo : minus 0 = fun x => 0.
31 simpl.
32 match goal with |- minus 0 = _ => idtac end.
33 Abort.
34 (* This does not work as one may expect. The point is that simpl is implemented
35 as "strong (whd_simpl_state)" and after unfolding minus you have
36 (fun m => match 0 => 0 | S n => ...) that is already in whd and exposes
37 a match, that of course "strong" would reduce away but at that stage
38 we don't know, and reducing by hand under the lambda is against whd *)
39
40 (* extra tuning for the usual heuristic *)
41 Arguments minus !n / m : simpl nomatch.
42
43 Lemma foo x y : S (S x) - S y = 0.
44 simpl.
45 match goal with |- (S x - y = 0) => idtac end.
46 Abort.
47
48 Lemma foo x y : S (S x) - (S (match y with O => O | S z => S z end)) = 0.
49 simpl.
50 match goal with |-(S x - (match y with O => _ | S _ => _ end) = 0) => idtac end.
51 Abort.
52
53 (* full control *)
54 Arguments minus !n !m /.
55
56 Lemma foo x y : S (S x) - S y = 0.
57 simpl.
58 match goal with |- (S x - y = 0) => idtac end.
59 Abort.
60
61 Lemma foo x y : S (S x) - (S (match y with O => O | S z => S z end)) = 0.
62 simpl.
63 match goal with |-(S x - (match y with O => _ | S _ => _ end) = 0) => idtac end.
64 Abort.
65
66 (* omitting /, that being immediately after the last ! is irrelevant *)
67 Arguments minus !n !m.
68
69 Lemma foo x y : S (S x) - S y = 0.
70 simpl.
71 match goal with |- (S x - y = 0) => idtac end.
72 Abort.
73
74 Lemma foo x y : S (S x) - (S (match y with O => O | S z => S z end)) = 0.
75 simpl.
76 match goal with |-(S x - (match y with O => _ | S _ => _ end) = 0) => idtac end.
77 Abort.
78
79 Definition pf (D1 C1 : Type) (f : D1 -> C1) (D2 C2 : Type) (g : D2 -> C2) :=
80 fun x => (f (fst x), g (snd x)).
81
82 Delimit Scope foo_scope with F.
83 Notation "@@" := nat (only parsing) : foo_scope.
84 Notation "@@" := (fun x => x) (only parsing).
85
86 Arguments pf {D1%_F C1%_type} f [D2 C2] g x : simpl never.
87
88 Lemma foo x : @pf @@ nat @@ nat nat @@ x = pf @@ @@ x.
89 Abort.
90
91 Definition fcomp A B C f (g : A -> B) (x : A) : C := f (g x).
92
93 (* fcomp is unfolded if applied to 6 args *)
94 Arguments fcomp {A B C}%_type f g x /.
95
96 Notation "f \o g" := (fcomp f g) (at level 50).
97
98 Lemma foo (f g h : nat -> nat) x : pf (f \o g) h x = pf f h (g (fst x), snd x).
99 simpl.
100 match goal with |- (pf (f \o g) h x = _) => idtac end.
101 case x; intros x1 x2.
102 simpl.
103 match goal with |- (pf (f \o g) h _ = pf f h _) => idtac end.
104 unfold pf; simpl.
105 match goal with |- (f (g x1), h x2) = (f (g x1), h x2) => idtac end.
106 Abort.
107
108 Definition volatile := fun x : nat => x.
109 Arguments volatile / _.
110
111 Lemma foo : volatile = volatile.
112 simpl.
113 match goal with |- (fun _ => _) = _ => idtac end.
114 Abort.
115
116 Set Implicit Arguments.
117
118 Section S1.
119
120 Variable T1 : Type.
121
122 Section S2.
123
124 Variable T2 : Type.
125
126 Fixpoint f (x : T1) (y : T2) n (v : unit) m {struct n} : nat :=
127 match n, m with
128 | 0,_ => 0
129 | S _, 0 => n
130 | S n', S m' => f x y n' v m' end.
131
132 Global Arguments f x y !n !v !m.
133
134 Lemma foo x y n m : f x y (S n) tt m = f x y (S n) tt (S m).
135 simpl.
136 match goal with |- (f _ _ _ _ _ = f _ _ _ _ _) => idtac end.
137 Abort.
138
139 End S2.
140
141 Lemma foo T x y n m : @f T x y (S n) tt m = @f T x y (S n) tt (S m).
142 simpl.
143 match goal with |- (f _ _ _ _ _ = f _ _ _ _ _) => idtac end.
144 Abort.
145
146 End S1.
147
148 Arguments f : clear implicits and scopes.
149
150 Module TestClearSimpl.
151
152 Fail Arguments id _ x / : clear simpl.
153 Fail Arguments id _ ! x : clear simpl.
154 Fail Arguments id _ : simpl never, clear simpl.
155 Fail Arguments id _ : simpl nomatch, clear simpl.
156
157 Arguments id _ x /.
158 Lemma foo : id 0 = 0.
159 simpl.
160 match goal with |- 0 = 0 => idtac end.
161 Abort.
162
163 Arguments id _ x : clear simpl.
164 Lemma foo : id 0 = 0.
165 simpl.
166 match goal with |- id 0 = 0 => idtac end.
167 Abort.
168
169 End TestClearSimpl.