1
<html xmlns="http://www.w3.org/1999/xhtml">
3
<meta http-equiv="Content-Type" content="text/html; charset="><link rel="stylesheet" href="style.css" type="text/css"><title>Coq.ZArith.Zmisc</title>
8
<h1>Library Coq.ZArith.Zmisc</h1>
11
<code class="keyword">Require</code> <code class="keyword">Import</code> BinInt.<br/>
12
<code class="keyword">Require</code> <code class="keyword">Import</code> Zcompare.<br/>
13
<code class="keyword">Require</code> <code class="keyword">Import</code> Zorder.<br/>
14
<code class="keyword">Require</code> <code class="keyword">Import</code> Bool.<br/>
15
Open <code class="keyword">Local</code> Scope Z_scope.<br/>
20
<table width="100%"><tr class="doc"><td>
28
<table width="100%"><tr class="doc"><td>
29
<code>n</code>th iteration of the function <code>f</code>
32
<code class="keyword">Fixpoint</code> <a name="iter_nat"></a>iter_nat (n:<a href="Coq.Init.Datatypes.html#nat">nat</a>) (A:Set) (f:A -> A) (x:A) {struct n} : A :=<br/>
33
match n with<br/>
34
| <a href="Coq.Init.Datatypes.html#O">O</a> => x<br/>
35
| <a href="Coq.Init.Datatypes.html#S">S</a> n' => f (iter_nat n' A f x)<br/>
39
<code class="keyword">Fixpoint</code> <a name="iter_pos"></a>iter_pos (n:<a href="Coq.NArith.BinPos.html#positive">positive</a>) (A:Set) (f:A -> A) (x:A) {struct n} : A :=<br/>
40
match n with<br/>
41
| <a href="Coq.NArith.BinPos.html#xH">xH</a> => f x<br/>
42
| <a href="Coq.NArith.BinPos.html#xO">xO</a> n' => iter_pos n' A f (iter_pos n' A f x)<br/>
43
| <a href="Coq.NArith.BinPos.html#xI">xI</a> n' => f (iter_pos n' A f (iter_pos n' A f x))<br/>
47
<code class="keyword">Definition</code> <a name="iter"></a>iter (n:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) (A:Set) (f:A -> A) (x:A) :=<br/>
48
match n with<br/>
49
| <a href="Coq.ZArith.BinInt.html#Z0">Z0</a> => x<br/>
50
| <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> p => <a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> p A f x<br/>
51
| <a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> p => x<br/>
55
<code class="keyword">Theorem</code> <a name="iter_nat_plus"></a>iter_nat_plus :<br/>
56
forall (n m:<a href="Coq.Init.Datatypes.html#nat">nat</a>) (A:Set) (f:A -> A) (x:A),<br/>
57
<a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> (n + m) A f x = <a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> n A f (<a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> m A f x).<br/>
58
<code class="keyword">Proof</code>. <br/>
59
simple induction n;<br/>
60
[ simpl in |- *; auto with arith<br/>
61
| intros; simpl in |- *; apply <a href="Coq.Init.Logic.html#f_equal">f_equal</a> with (f:= f); apply H ]. <br/>
62
<code class="keyword">Qed</code>.<br/>
65
<code class="keyword">Theorem</code> <a name="iter_nat_of_P"></a>iter_nat_of_P :<br/>
66
forall (p:<a href="Coq.NArith.BinPos.html#positive">positive</a>) (A:Set) (f:A -> A) (x:A),<br/>
67
<a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> p A f x = <a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> (<a href="Coq.NArith.BinPos.html#nat_of_P">nat_of_P</a> p) A f x.<br/>
68
<code class="keyword">Proof</code>. <br/>
69
intro n; induction n as [p H| p H| ];<br/>
70
[ intros; simpl in |- *; rewrite (H A f x);<br/>
71
rewrite (H A f (<a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> (<a href="Coq.NArith.BinPos.html#nat_of_P">nat_of_P</a> p) A f x)); <br/>
72
rewrite (<a href="Coq.NArith.Pnat.html#ZL6">ZL6</a> p); symmetry in |- *; apply <a href="Coq.Init.Logic.html#f_equal">f_equal</a> with (f:= f);<br/>
73
apply <a href="Coq.ZArith.Zmisc.html#iter_nat_plus">iter_nat_plus</a><br/>
74
| intros; unfold nat_of_P in |- *; simpl in |- *; rewrite (H A f x);<br/>
75
rewrite (H A f (<a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> (<a href="Coq.NArith.BinPos.html#nat_of_P">nat_of_P</a> p) A f x)); <br/>
76
rewrite (<a href="Coq.NArith.Pnat.html#ZL6">ZL6</a> p); symmetry in |- *; apply <a href="Coq.ZArith.Zmisc.html#iter_nat_plus">iter_nat_plus</a><br/>
77
| simpl in |- *; auto with arith ].<br/>
78
<code class="keyword">Qed</code>.<br/>
81
<code class="keyword">Theorem</code> <a name="iter_pos_plus"></a>iter_pos_plus :<br/>
82
forall (p q:<a href="Coq.NArith.BinPos.html#positive">positive</a>) (A:Set) (f:A -> A) (x:A),<br/>
83
<a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> (p + q) A f x = <a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> p A f (<a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> q A f x).<br/>
84
<code class="keyword">Proof</code>. <br/>
85
intros n m; intros.<br/>
86
rewrite (<a href="Coq.ZArith.Zmisc.html#iter_nat_of_P">iter_nat_of_P</a> m A f x).<br/>
87
rewrite (<a href="Coq.ZArith.Zmisc.html#iter_nat_of_P">iter_nat_of_P</a> n A f (<a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> (<a href="Coq.NArith.BinPos.html#nat_of_P">nat_of_P</a> m) A f x)).<br/>
88
rewrite (<a href="Coq.ZArith.Zmisc.html#iter_nat_of_P">iter_nat_of_P</a> (n + m) A f x).<br/>
89
rewrite (<a href="Coq.NArith.Pnat.html#nat_of_P_plus_morphism">nat_of_P_plus_morphism</a> n m).<br/>
90
apply <a href="Coq.ZArith.Zmisc.html#iter_nat_plus">iter_nat_plus</a>.<br/>
91
<code class="keyword">Qed</code>.<br/>
96
<table width="100%"><tr class="doc"><td>
97
Preservation of invariants : if <code>f : A->A</code> preserves the invariant <code>Inv</code>,
98
then the iterates of <code>f</code> also preserve it.
103
<code class="keyword">Theorem</code> <a name="iter_nat_invariant"></a>iter_nat_invariant :<br/>
104
forall (n:<a href="Coq.Init.Datatypes.html#nat">nat</a>) (A:Set) (f:A -> A) (Inv:A -> Prop),<br/>
105
(forall x:A, Inv x -> Inv (f x)) -><br/>
106
forall x:A, Inv x -> Inv (<a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> n A f x).<br/>
107
<code class="keyword">Proof</code>. <br/>
108
simple induction n; intros;<br/>
109
[ trivial with arith<br/>
110
| simpl in |- *; apply H0 with (x:= <a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> n0 A f x); apply H;<br/>
111
trivial with arith ].<br/>
112
<code class="keyword">Qed</code>.<br/>
115
<code class="keyword">Theorem</code> <a name="iter_pos_invariant"></a>iter_pos_invariant :<br/>
116
forall (p:<a href="Coq.NArith.BinPos.html#positive">positive</a>) (A:Set) (f:A -> A) (Inv:A -> Prop),<br/>
117
(forall x:A, Inv x -> Inv (f x)) -><br/>
118
forall x:A, Inv x -> Inv (<a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> p A f x).<br/>
119
<code class="keyword">Proof</code>. <br/>
120
intros; rewrite <a href="Coq.ZArith.Zmisc.html#iter_nat_of_P">iter_nat_of_P</a>; apply <a href="Coq.ZArith.Zmisc.html#iter_nat_invariant">iter_nat_invariant</a>; trivial with arith.<br/>
121
<code class="keyword">Qed</code>.<br/>
123
<hr/><a href="index.html">Index</a><hr/><font size="-1">This page has been generated by <a href="http://www.lri.fr/~filliatr/coqdoc/">coqdoc</a></font>
b'\\ No newline at end of file'