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

« back to all changes in this revision

Viewing changes to theories/Arith/Minus.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
(************************************************************************)
 
2
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
 
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
 
4
(*   \VV/  **************************************************************)
 
5
(*    //   *      This file is distributed under the terms of the       *)
 
6
(*         *       GNU Lesser General Public License Version 2.1        *)
 
7
(************************************************************************)
 
8
 
 
9
(*i $Id: Minus.v 11072 2008-06-08 16:13:37Z herbelin $ i*)
 
10
 
 
11
(** [minus] (difference between two natural numbers) is defined in [Init/Peano.v] as:
 
12
<<
 
13
Fixpoint minus (n m:nat) {struct n} : nat :=
 
14
  match n, m with
 
15
  | O, _ => n
 
16
  | S k, O => S k
 
17
  | S k, S l => k - l
 
18
  end
 
19
where "n - m" := (minus n m) : nat_scope.
 
20
>>
 
21
*)
 
22
 
 
23
Require Import Lt.
 
24
Require Import Le.
 
25
 
 
26
Open Local Scope nat_scope.
 
27
 
 
28
Implicit Types m n p : nat.
 
29
 
 
30
(** * 0 is right neutral *)
 
31
 
 
32
Lemma minus_n_O : forall n, n = n - 0.
 
33
Proof.
 
34
  induction n; simpl in |- *; auto with arith.
 
35
Qed.
 
36
Hint Resolve minus_n_O: arith v62.
 
37
 
 
38
(** * Permutation with successor *)
 
39
 
 
40
Lemma minus_Sn_m : forall n m, m <= n -> S (n - m) = S n - m.
 
41
Proof.
 
42
  intros n m Le; pattern m, n in |- *; apply le_elim_rel; simpl in |- *;
 
43
    auto with arith.
 
44
Qed.
 
45
Hint Resolve minus_Sn_m: arith v62.
 
46
 
 
47
Theorem pred_of_minus : forall n, pred n = n - 1.
 
48
Proof.
 
49
  intro x; induction x; simpl in |- *; auto with arith.
 
50
Qed.
 
51
 
 
52
(** * Diagonal *)
 
53
 
 
54
Lemma minus_diag : forall n, n - n = 0.
 
55
Proof.
 
56
  induction n; simpl in |- *; auto with arith.
 
57
Qed.
 
58
 
 
59
Lemma minus_diag_reverse : forall n, 0 = n - n.
 
60
Proof.
 
61
  auto using minus_diag.
 
62
Qed.
 
63
Hint Resolve minus_diag_reverse: arith v62.
 
64
 
 
65
Notation minus_n_n := minus_diag_reverse.
 
66
 
 
67
(** * Simplification *)
 
68
 
 
69
Lemma minus_plus_simpl_l_reverse : forall n m p, n - m = p + n - (p + m).
 
70
Proof.
 
71
  induction p; simpl in |- *; auto with arith.
 
72
Qed.
 
73
Hint Resolve minus_plus_simpl_l_reverse: arith v62.
 
74
 
 
75
(** * Relation with plus *)
 
76
 
 
77
Lemma plus_minus : forall n m p, n = m + p -> p = n - m.
 
78
Proof.
 
79
  intros n m p; pattern m, n in |- *; apply nat_double_ind; simpl in |- *;
 
80
    intros.
 
81
  replace (n0 - 0) with n0; auto with arith.
 
82
  absurd (0 = S (n0 + p)); auto with arith.
 
83
  auto with arith.
 
84
Qed.
 
85
Hint Immediate plus_minus: arith v62.
 
86
 
 
87
Lemma minus_plus : forall n m, n + m - n = m.
 
88
  symmetry  in |- *; auto with arith.
 
89
Qed.
 
90
Hint Resolve minus_plus: arith v62.
 
91
 
 
92
Lemma le_plus_minus : forall n m, n <= m -> m = n + (m - n).
 
93
Proof.
 
94
  intros n m Le; pattern n, m in |- *; apply le_elim_rel; simpl in |- *;
 
95
    auto with arith.
 
96
Qed.
 
97
Hint Resolve le_plus_minus: arith v62.
 
98
 
 
99
Lemma le_plus_minus_r : forall n m, n <= m -> n + (m - n) = m.
 
100
Proof.
 
101
  symmetry  in |- *; auto with arith.
 
102
Qed.
 
103
Hint Resolve le_plus_minus_r: arith v62.
 
104
 
 
105
(** * Relation with order *)
 
106
 
 
107
Theorem minus_le_compat_r : forall n m p : nat, n <= m -> n - p <= m - p.
 
108
Proof.
 
109
  intros n m p; generalize n m; clear n m; induction p as [|p HI].
 
110
    intros n m; rewrite <- (minus_n_O n); rewrite <- (minus_n_O m); trivial.
 
111
 
 
112
    intros n m Hnm; apply le_elim_rel with (n:=n) (m:=m); auto with arith.
 
113
    intros q r H _. simpl. auto using HI.
 
114
Qed.
 
115
 
 
116
Theorem minus_le_compat_l : forall n m p : nat, n <= m -> p - m <= p - n.
 
117
Proof.
 
118
  intros n m p; generalize n m; clear n m; induction p as [|p HI].
 
119
    trivial.
 
120
 
 
121
    intros n m Hnm; apply le_elim_rel with (n:=n) (m:=m); trivial.
 
122
      intros q; destruct q; auto with arith.
 
123
        simpl. 
 
124
        apply le_trans with (m := p - 0); [apply HI | rewrite <- minus_n_O];
 
125
          auto with arith.
 
126
        
 
127
      intros q r Hqr _. simpl. auto using HI.
 
128
Qed.
 
129
 
 
130
Corollary le_minus : forall n m, n - m <= n.
 
131
Proof.
 
132
  intros n m; rewrite minus_n_O; auto using minus_le_compat_l with arith.
 
133
Qed.
 
134
 
 
135
Lemma lt_minus : forall n m, m <= n -> 0 < m -> n - m < n.
 
136
Proof.
 
137
  intros n m Le; pattern m, n in |- *; apply le_elim_rel; simpl in |- *;
 
138
    auto using le_minus with arith.
 
139
    intros; absurd (0 < 0); auto with arith.
 
140
Qed.
 
141
Hint Resolve lt_minus: arith v62.
 
142
 
 
143
Lemma lt_O_minus_lt : forall n m, 0 < n - m -> m < n.
 
144
Proof.
 
145
  intros n m; pattern n, m in |- *; apply nat_double_ind; simpl in |- *;
 
146
    auto with arith.
 
147
  intros; absurd (0 < 0); trivial with arith.
 
148
Qed.
 
149
Hint Immediate lt_O_minus_lt: arith v62.
 
150
 
 
151
Theorem not_le_minus_0 : forall n m, ~ m <= n -> n - m = 0.
 
152
Proof.
 
153
  intros y x; pattern y, x in |- *; apply nat_double_ind;
 
154
    [ simpl in |- *; trivial with arith
 
155
      | intros n H; absurd (0 <= S n); [ assumption | apply le_O_n ]
 
156
      | simpl in |- *; intros n m H1 H2; apply H1; unfold not in |- *; intros H3;
 
157
        apply H2; apply le_n_S; assumption ].
 
158
Qed.