~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to test-suite/success/ltac.v

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* The tactic language *)
 
2
 
 
3
(* Submitted by Pierre Cr�gut *)
 
4
(* Checks substitution of x *)
 
5
Ltac f x := unfold x in |- *; idtac.
 
6
 
 
7
Lemma lem1 : 0 + 0 = 0.
 
8
f plus.
 
9
reflexivity.
 
10
Qed.
 
11
 
 
12
(* Submitted by Pierre Cr�gut *)
 
13
(* Check syntactic correctness *)
 
14
Ltac F x := idtac; G x
 
15
 with G y := idtac; F y.
 
16
 
 
17
(* Check that Match Context keeps a closure *)
 
18
Ltac U := let a := constr:I in
 
19
          match goal with
 
20
          |  |- _ => apply a
 
21
          end.
 
22
 
 
23
Lemma lem2 : True.
 
24
U.
 
25
Qed.
 
26
 
 
27
(* Check that Match giving non-tactic arguments are evaluated at Let-time *)
 
28
 
 
29
Ltac B := let y := (match goal with
 
30
                    | z:_ |- _ => z
 
31
                    end) in
 
32
          (intro H1; exact y).
 
33
 
 
34
Lemma lem3 : True -> False -> True -> False.
 
35
intros H H0.
 
36
B.  (* y is H0 if at let-time, H1 otherwise *)
 
37
Qed.
 
38
 
 
39
(* Checks the matching order of hypotheses *)
 
40
Ltac Y := match goal with
 
41
          | x:_,y:_ |- _ => apply x
 
42
          end.
 
43
Ltac Z := match goal with
 
44
          | y:_,x:_ |- _ => apply x
 
45
          end.
 
46
 
 
47
Lemma lem4 : (True -> False) -> (False -> False) -> False.
 
48
intros H H0.
 
49
Z. (* Apply H0 *)
 
50
Y. (* Apply H *)
 
51
exact I.
 
52
Qed.
 
53
 
 
54
(* Check backtracking *)
 
55
Lemma back1 : 0 = 1 -> 0 = 0 -> 1 = 1 -> 0 = 0.
 
56
intros;
 
57
 match goal with
 
58
 | _:(0 = ?X1),_:(1 = 1) |- _ => exact (refl_equal X1)
 
59
 end.
 
60
Qed.
 
61
 
 
62
Lemma back2 : 0 = 0 -> 0 = 1 -> 1 = 1 -> 0 = 0.
 
63
intros;
 
64
 match goal with
 
65
 | _:(0 = ?X1),_:(1 = 1) |- _ => exact (refl_equal X1)
 
66
 end.
 
67
Qed.
 
68
 
 
69
Lemma back3 : 0 = 0 -> 1 = 1 -> 0 = 1 -> 0 = 0.
 
70
intros;
 
71
 match goal with
 
72
 | _:(0 = ?X1),_:(1 = 1) |- _ => exact (refl_equal X1)
 
73
 end.
 
74
Qed.
 
75
 
 
76
(* Check context binding *)
 
77
Ltac sym t :=
 
78
  match constr:t with
 
79
  | context C[(?X1 = ?X2)] => context C [X1 = X2]
 
80
  end.
 
81
 
 
82
Lemma sym : 0 <> 1 -> 1 <> 0.
 
83
intro H.
 
84
let t := sym type of H in
 
85
assert t.
 
86
exact H.
 
87
intro H1.
 
88
apply H.
 
89
symmetry  in |- *.
 
90
assumption.
 
91
Qed.
 
92
 
 
93
(* Check context binding in match goal *)
 
94
(* This wasn't working in V8.0pl1, as the list of matched hyps wasn't empty *)
 
95
Ltac sym' :=
 
96
  match goal with
 
97
  | _:True |- context C[(?X1 = ?X2)] =>
 
98
      let t := context C [X2 = X1] in
 
99
      assert t
 
100
  end.
 
101
 
 
102
Lemma sym' : True -> 0 <> 1 -> 1 <> 0.
 
103
intros Ht H.
 
104
sym'.
 
105
exact H.
 
106
intro H1.
 
107
apply H.
 
108
symmetry  in |- *.
 
109
assumption.
 
110
Qed.
 
111
 
 
112
(* Check that fails abort the current match context *)
 
113
Lemma decide : True \/ False.
 
114
match goal with
 
115
| _ => fail 1
 
116
| _ => right
 
117
end || left.
 
118
exact I.
 
119
Qed.
 
120
 
 
121
(* Check that "match c with" backtracks on subterms *)
 
122
Lemma refl : 1 = 1.
 
123
let t :=
 
124
 (match constr:(1 = 2) with
 
125
  | context [(S ?X1)] => constr:(refl_equal X1:1 = 1)
 
126
  end) in
 
127
assert (H := t).
 
128
assumption.
 
129
Qed.
 
130
 
 
131
(* Note that backtracking in "match c with" is only on type-checking not on
 
132
evaluation of tactics. E.g., this does not work
 
133
 
 
134
Lemma refl : (1)=(1).
 
135
Match (1)=(2) With
 
136
  [[(S ?1)]] -> Apply (refl_equal nat ?1).
 
137
Qed.
 
138
*)
 
139
 
 
140
 
 
141
(* Check the precedences of rel context, ltac context and vars context *)
 
142
(* (was wrong in V8.0) *)
 
143
 
 
144
Ltac check_binding y := cut ((fun y => y) = S).
 
145
Goal True.
 
146
check_binding true.
 
147
Abort.
 
148
 
 
149
(* Check that variables explicitly parsed as ltac variables are not
 
150
   seen as intro pattern or constr (bug #984) *)
 
151
 
 
152
Ltac afi tac := intros; tac.
 
153
Goal 1 = 2.
 
154
afi ltac:auto.
 
155
 
 
156
(* Tactic Notation avec listes *)
 
157
 
 
158
Tactic Notation "pat" hyp(id) "occs" integer_list(l) := pattern id at l.
 
159
 
 
160
Goal forall x, x=0 -> x=x.
 
161
intro x.
 
162
pat x occs 1 3.
 
163
Abort.
 
164
 
 
165
Tactic Notation "revert" ne_hyp_list(l) := generalize l; clear l.
 
166
 
 
167
Goal forall a b c, a=0 -> b=c+a.
 
168
intros.
 
169
revert a b c H.
 
170
Abort.
 
171
 
 
172
(* Used to fail until revision 9280 because of a parasitic App node with
 
173
   empty args *)
 
174
 
 
175
Goal True.
 
176
match constr:@None with @None => exact I end.
 
177
Abort.
 
178
 
 
179
(* Check second-order pattern unification *)
 
180
 
 
181
Ltac to_exist :=
 
182
  match goal with 
 
183
  |- forall x y, @?P x y => 
 
184
    let Q := eval lazy beta in (exists x, forall y, P x y) in
 
185
    assert (Q->Q)
 
186
  end.
 
187
 
 
188
Goal forall x y : nat, x = y.
 
189
to_exist. exact (fun H => H).
 
190
Abort.
 
191
 
 
192
(* Used to fail in V8.1 *)
 
193
 
 
194
Tactic Notation "test" constr(t) integer(n) :=
 
195
   set (k := t) in |- * at n.
 
196
 
 
197
Goal forall x : nat, x = 1 -> x + x + x = 3.
 
198
intros x H.
 
199
test x 2.
 
200
Abort.
 
201
 
 
202
(* Utilisation de let rec sans arguments *)
 
203
 
 
204
Ltac is := 
 
205
  let rec i := match goal with |- ?A -> ?B => intro; i | _ => idtac end in
 
206
  i.
 
207
 
 
208
Goal True -> True -> True.
 
209
is.
 
210
exact I.
 
211
Abort.
 
212
 
 
213
(* Interf�rence entre espaces des noms *)
 
214
 
 
215
Ltac O := intro.
 
216
Ltac Z1 t := set (x:=t).
 
217
Ltac Z2 t := t.
 
218
Goal True -> True.
 
219
Z1 O.
 
220
Z2 ltac:O.
 
221
exact I.
 
222
Qed.