-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommon.v
84 lines (69 loc) · 3.54 KB
/
Common.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(**************************************************************************)
(* This is part of ATBR, it is distributed under the terms of the *)
(* GNU Lesser General Public License version 3 *)
(* (see file LICENSE for more details) *)
(* *)
(* Copyright 2009-2011: Thomas Braibant, Damien Pous. *)
(**************************************************************************)
(** This small module is imported in all our files, it exports useful
modules and defines some basic utilities and tactics *)
Require Export Arith.
Require Export Omega.
Require Export Coq.Program.Equality.
Require Export Setoid Morphisms.
Set Implicit Arguments.
Bind Scope nat_scope with nat.
(** Functional composition *)
Definition comp A B C (f: A -> B) (g: B -> C) := fun x => g (f x).
Notation "f >> g" := (comp f g) (at level 50).
(** This lemma is useful when applied in hypotyheses ([apply apply in H] makes it possible to specialize
an hypothesis [H] by generating the corresponding subgoals) *)
Definition apply X x Y (f: X -> Y) := f x.
(** Tactics to resolve a goal by using a contradiction in the hypotheses, using either [omega] or [tauto] *)
Ltac omega_false := exfalso; omega.
Ltac tauto_false := exfalso; tauto.
(** This destructor sometimes works better that the standard [destruct] *)
Ltac idestruct H :=
let H' := fresh in generalize H; intro H'; destruct H'.
(** For debugging *)
Ltac print_goal := match goal with |- ?x => idtac x end.
(** This tactic allows one to infere maximally implicit arguments that failed to be inferred and were
replaced by sub-goals *)
Ltac ti_auto := eauto with typeclass_instances.
(** The following databases are used all along the library:
- <compat> contains most "compatibility with equality" and "monotonicity" lemmas: Morphisms with respects to
[Classes.equal] and [Classes.leq] ; it is useful to solve simple goals like [x <== y |- x*f x <== y*f y],
and to obtain new morphisms. These morphism are always called [f_compat] and [f_incr], where [f] is the
name of the compatible or monotone function.
- <algebra> contains simple algebraic lemmas like [0 <== x], [1 <== x#],
and [x <== z -> y <== z -> x+y <== z],
that seem to be appropriate for [(e)auto] proof search.
- <simpl> is a rewriting database, to be used with the [rsimpl] tactic. It contains lemmas like [1*x == x]
[0# == 1] and provides a simple way to normalise the goal "in depth", using the setoid infrastructure.
This is not really efficient, however.
- <omega> contains hints to use [omega] when proof search failed ; this basically allows us to avoid
using [omega] in trivial cases.
*)
Create HintDb compat discriminated.
Create HintDb algebra discriminated.
Ltac rsimpl := simpl; autorewrite with simpl using ti_auto.
Hint Extern 9 (@eq nat ?x ?y) => instantiate; abstract omega: omega.
Hint Extern 9 (Peano.le ?x ?y) => instantiate; abstract omega: omega.
Hint Extern 9 (Peano.lt ?x ?y) => instantiate; abstract omega: omega.
(** Tactic to use when apply does not smartly unify *)
Ltac rapply H := first
[ refine H
| refine (H _)
| refine (H _ _)
| refine (H _ _ _)
| refine (H _ _ _ _)
| refine (H _ _ _ _ _)
| refine (H _ _ _ _ _ _)
| refine (H _ _ _ _ _ _ _)
| refine (H _ _ _ _ _ _ _ _)
| refine (H _ _ _ _ _ _ _ _ _)
| refine (H _ _ _ _ _ _ _ _ _ _)
| refine (H _ _ _ _ _ _ _ _ _ _ _)
| refine (H _ _ _ _ _ _ _ _ _ _ _ _)
| fail 1 "extend rapply"
].