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

« back to all changes in this revision

Viewing changes to theories/ZArith/Zmisc.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: Zmisc.v 11072 2008-06-08 16:13:37Z herbelin $ i*)
 
10
 
 
11
Require Import Wf_nat.
 
12
Require Import BinInt.
 
13
Require Import Zcompare.
 
14
Require Import Zorder.
 
15
Require Import Bool.
 
16
Open Local Scope Z_scope.
 
17
 
 
18
(**********************************************************************)
 
19
(** Iterators *)
 
20
 
 
21
(** [n]th iteration of the function [f] *)
 
22
 
 
23
Fixpoint iter_pos (n:positive) (A:Type) (f:A -> A) (x:A) {struct n} : A :=
 
24
  match n with
 
25
    | xH => f x
 
26
    | xO n' => iter_pos n' A f (iter_pos n' A f x)
 
27
    | xI n' => f (iter_pos n' A f (iter_pos n' A f x))
 
28
  end.
 
29
 
 
30
Definition iter (n:Z) (A:Type) (f:A -> A) (x:A) :=
 
31
  match n with
 
32
    | Z0 => x
 
33
    | Zpos p => iter_pos p A f x
 
34
    | Zneg p => x
 
35
  end.
 
36
 
 
37
Theorem iter_nat_of_P :
 
38
  forall (p:positive) (A:Type) (f:A -> A) (x:A),
 
39
    iter_pos p A f x = iter_nat (nat_of_P p) A f x.
 
40
Proof.    
 
41
  intro n; induction n as [p H| p H| ];
 
42
    [ intros; simpl in |- *; rewrite (H A f x);
 
43
      rewrite (H A f (iter_nat (nat_of_P p) A f x)); 
 
44
        rewrite (ZL6 p); symmetry  in |- *; apply f_equal with (f := f);
 
45
          apply iter_nat_plus
 
46
      | intros; unfold nat_of_P in |- *; simpl in |- *; rewrite (H A f x);
 
47
        rewrite (H A f (iter_nat (nat_of_P p) A f x)); 
 
48
          rewrite (ZL6 p); symmetry  in |- *; apply iter_nat_plus
 
49
      | simpl in |- *; auto with arith ].
 
50
Qed.
 
51
 
 
52
Theorem iter_pos_plus :
 
53
  forall (p q:positive) (A:Type) (f:A -> A) (x:A),
 
54
    iter_pos (p + q) A f x = iter_pos p A f (iter_pos q A f x).
 
55
Proof.    
 
56
  intros n m; intros.
 
57
  rewrite (iter_nat_of_P m A f x).
 
58
  rewrite (iter_nat_of_P n A f (iter_nat (nat_of_P m) A f x)).
 
59
  rewrite (iter_nat_of_P (n + m) A f x).
 
60
  rewrite (nat_of_P_plus_morphism n m).
 
61
  apply iter_nat_plus.
 
62
Qed.
 
63
 
 
64
(** Preservation of invariants : if [f : A->A] preserves the invariant [Inv], 
 
65
    then the iterates of [f] also preserve it. *)
 
66
 
 
67
Theorem iter_nat_invariant :
 
68
  forall (n:nat) (A:Type) (f:A -> A) (Inv:A -> Prop),
 
69
    (forall x:A, Inv x -> Inv (f x)) ->
 
70
    forall x:A, Inv x -> Inv (iter_nat n A f x).
 
71
Proof.    
 
72
  simple induction n; intros;
 
73
    [ trivial with arith
 
74
      | simpl in |- *; apply H0 with (x := iter_nat n0 A f x); apply H;
 
75
        trivial with arith ].
 
76
Qed.
 
77
 
 
78
Theorem iter_pos_invariant :
 
79
  forall (p:positive) (A:Type) (f:A -> A) (Inv:A -> Prop),
 
80
    (forall x:A, Inv x -> Inv (f x)) ->
 
81
    forall x:A, Inv x -> Inv (iter_pos p A f x).
 
82
Proof.    
 
83
  intros; rewrite iter_nat_of_P; apply iter_nat_invariant; trivial with arith.
 
84
Qed.