~ubuntu-branches/ubuntu/hardy/coq-doc/hardy

« back to all changes in this revision

Viewing changes to library/Coq.ZArith.Zpower.html

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2004-09-18 13:28:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040918132822-ees5mb8qmzd6a0fw
Tags: 8.0pl1.0-1
* Added the Coq faq, moved the tutorial to the root directory and added
  doc-base files for both, closes: #272204.
* Set dh_compat to level 4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html xmlns="http://www.w3.org/1999/xhtml">
 
2
<head>
 
3
<meta http-equiv="Content-Type" content="text/html; charset="><link rel="stylesheet" href="style.css" type="text/css"><title>Coq.ZArith.Zpower</title>
 
4
</head>
 
5
 
 
6
<body>
 
7
 
 
8
<h1>Library Coq.ZArith.Zpower</h1>
 
9
 
 
10
<code>
 
11
<code class="keyword">Require</code> <code class="keyword">Import</code> ZArith_base.<br/>
 
12
<code class="keyword">Require</code> <code class="keyword">Import</code> Omega.<br/>
 
13
<code class="keyword">Require</code> <code class="keyword">Import</code> Zcomplements.<br/>
 
14
Open <code class="keyword">Local</code> Scope Z_scope.<br/>
 
15
 
 
16
<br/>
 
17
<code class="keyword">Section</code> section1.<br/>
 
18
 
 
19
<br/>
 
20
</code>
 
21
 
 
22
<table width="100%"><tr class="doc"><td>
 
23
<code>Zpower_nat z n</code> is the n-th power of <code>z</code> when <code>n</code> is an unary
 
24
    integer (type <code>nat</code>) and <code>z</code> a signed integer (type <code>Z</code>) 
 
25
</td></tr></table>
 
26
<code>
 
27
 
 
28
<br/>
 
29
<code class="keyword">Definition</code> <a name="Zpower_nat"></a>Zpower_nat (z:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) (n:<a href="Coq.Init.Datatypes.html#nat">nat</a>) := <a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> n <a href="Coq.ZArith.BinInt.html#Z">Z</a> (fun x:<a href="Coq.ZArith.BinInt.html#Z">Z</a> =&gt; z * x) 1.<br/>
 
30
 
 
31
<br/>
 
32
</code>
 
33
 
 
34
<table width="100%"><tr class="doc"><td>
 
35
<code>Zpower_nat_is_exp</code> says <code>Zpower_nat</code> is a morphism for
 
36
    <code>plus : nat-&gt;nat</code> and <code>Zmult : Z-&gt;Z</code> 
 
37
</td></tr></table>
 
38
<code>
 
39
 
 
40
<br/>
 
41
<code class="keyword">Lemma</code> <a name="Zpower_nat_is_exp"></a>Zpower_nat_is_exp :<br/>
 
42
&nbsp;forall (n m:<a href="Coq.Init.Datatypes.html#nat">nat</a>) (z:<a href="Coq.ZArith.BinInt.html#Z">Z</a>),<br/>
 
43
&nbsp;&nbsp;&nbsp;<a href="Coq.ZArith.Zpower.html#Zpower_nat">Zpower_nat</a> z (n + m) = <a href="Coq.ZArith.Zpower.html#Zpower_nat">Zpower_nat</a> z n * <a href="Coq.ZArith.Zpower.html#Zpower_nat">Zpower_nat</a> z m.<br/>
 
44
 
 
45
<br/>
 
46
intros; elim n;<br/>
 
47
&nbsp;[ simpl in |- *; elim (Zpower_nat z m); auto with zarith
 
48
 | unfold Zpower_nat in |- *; intros; simpl in |- *; rewrite H;
 
49
    apply Zmult_assoc ].<br/>
 
50
<code class="keyword">Qed</code>.<br/>
 
51
 
 
52
<br/>
 
53
</code>
 
54
 
 
55
<table width="100%"><tr class="doc"><td>
 
56
<code>Zpower_pos z n</code> is the n-th power of <code>z</code> when <code>n</code> is an binary
 
57
    integer (type <code>positive</code>) and <code>z</code> a signed integer (type <code>Z</code>) 
 
58
</td></tr></table>
 
59
<code>
 
60
 
 
61
<br/>
 
62
<code class="keyword">Definition</code> <a name="Zpower_pos"></a>Zpower_pos (z:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) (n:<a href="Coq.NArith.BinPos.html#positive">positive</a>) := <a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> n <a href="Coq.ZArith.BinInt.html#Z">Z</a> (fun x:<a href="Coq.ZArith.BinInt.html#Z">Z</a> =&gt; z * x) 1.<br/>
 
63
 
 
64
<br/>
 
65
</code>
 
66
 
 
67
<table width="100%"><tr class="doc"><td>
 
68
This theorem shows that powers of unary and binary integers
 
69
   are the same thing, modulo the function convert : <code>positive -&gt; nat</code> 
 
70
</td></tr></table>
 
71
<code>
 
72
 
 
73
<br/>
 
74
<code class="keyword">Theorem</code> <a name="Zpower_pos_nat"></a>Zpower_pos_nat :<br/>
 
75
&nbsp;forall (z:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) (p:<a href="Coq.NArith.BinPos.html#positive">positive</a>), <a href="Coq.ZArith.Zpower.html#Zpower_pos">Zpower_pos</a> z p = <a href="Coq.ZArith.Zpower.html#Zpower_nat">Zpower_nat</a> z (<a href="Coq.NArith.BinPos.html#nat_of_P">nat_of_P</a> p).<br/>
 
76
 
 
77
<br/>
 
78
intros; unfold Zpower_pos in |- *; unfold Zpower_nat in |- *;<br/>
 
79
&nbsp;apply <a href="Coq.ZArith.Zmisc.html#iter_nat_of_P">iter_nat_of_P</a>.<br/>
 
80
<code class="keyword">Qed</code>.<br/>
 
81
 
 
82
<br/>
 
83
</code>
 
84
 
 
85
<table width="100%"><tr class="doc"><td>
 
86
Using the theorem <code>Zpower_pos_nat</code> and the lemma <code>Zpower_nat_is_exp</code> we
 
87
   deduce that the function <code>[n:positive](Zpower_pos z n)</code> is a morphism
 
88
   for <code>add : positive-&gt;positive</code> and <code>Zmult : Z-&gt;Z</code> 
 
89
</td></tr></table>
 
90
<code>
 
91
 
 
92
<br/>
 
93
<code class="keyword">Theorem</code> <a name="Zpower_pos_is_exp"></a>Zpower_pos_is_exp :<br/>
 
94
&nbsp;forall (n m:<a href="Coq.NArith.BinPos.html#positive">positive</a>) (z:<a href="Coq.ZArith.BinInt.html#Z">Z</a>),<br/>
 
95
&nbsp;&nbsp;&nbsp;<a href="Coq.ZArith.Zpower.html#Zpower_pos">Zpower_pos</a> z (n + m) = <a href="Coq.ZArith.Zpower.html#Zpower_pos">Zpower_pos</a> z n * <a href="Coq.ZArith.Zpower.html#Zpower_pos">Zpower_pos</a> z m.<br/>
 
96
 
 
97
<br/>
 
98
intros.<br/>
 
99
rewrite (<a href="Coq.ZArith.Zpower.html#Zpower_pos_nat">Zpower_pos_nat</a> z n).<br/>
 
100
rewrite (<a href="Coq.ZArith.Zpower.html#Zpower_pos_nat">Zpower_pos_nat</a> z m).<br/>
 
101
rewrite (<a href="Coq.ZArith.Zpower.html#Zpower_pos_nat">Zpower_pos_nat</a> z (n + m)).<br/>
 
102
rewrite (<a href="Coq.NArith.Pnat.html#nat_of_P_plus_morphism">nat_of_P_plus_morphism</a> n m).<br/>
 
103
apply <a href="Coq.ZArith.Zpower.html#Zpower_nat_is_exp">Zpower_nat_is_exp</a>.<br/>
 
104
<code class="keyword">Qed</code>.<br/>
 
105
 
 
106
<br/>
 
107
<code class="keyword">Definition</code> <a name="Zpower"></a>Zpower (x y:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) :=<br/>
 
108
&nbsp;&nbsp;match y with<br/>
 
109
&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> p =&gt; <a href="Coq.ZArith.Zpower.html#Zpower_pos">Zpower_pos</a> x p<br/>
 
110
&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Z0">Z0</a> =&gt; 1<br/>
 
111
&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> p =&gt; 0<br/>
 
112
&nbsp;&nbsp;end.<br/>
 
113
 
 
114
<br/>
 
115
<code class="keyword">Infix</code> "^" := <a href="Coq.ZArith.Zpower.html#Zpower">Zpower</a> : Z_scope.<br/>
 
116
 
 
117
<br/>
 
118
<code class="keyword">Hint</code> <code class="keyword">Immediate</code> <a href="Coq.ZArith.Zpower.html#Zpower_nat_is_exp">Zpower_nat_is_exp</a>: zarith.<br/>
 
119
<code class="keyword">Hint</code> <code class="keyword">Immediate</code> <a href="Coq.ZArith.Zpower.html#Zpower_pos_is_exp">Zpower_pos_is_exp</a>: zarith.<br/>
 
120
<code class="keyword">Hint</code> Unfold Zpower_pos: zarith.<br/>
 
121
<code class="keyword">Hint</code> Unfold Zpower_nat: zarith.<br/>
 
122
 
 
123
<br/>
 
124
<code class="keyword">Lemma</code> <a name="Zpower_exp"></a>Zpower_exp :<br/>
 
125
&nbsp;forall x n m:<a href="Coq.ZArith.BinInt.html#Z">Z</a>, n &gt;= 0 -&gt; m &gt;= 0 -&gt; x ^ (n + m) = x ^ n * x ^ m.<br/>
 
126
destruct n; destruct m; auto with zarith.<br/>
 
127
simpl in |- *; intros; apply <a href="Coq.ZArith.auxiliary.html#Zred_factor0">Zred_factor0</a>.<br/>
 
128
simpl in |- *; auto with zarith.<br/>
 
129
intros; compute in H0; absurd (Datatypes.Lt = Datatypes.Lt); auto with zarith.<br/>
 
130
intros; compute in H0; absurd (Datatypes.Lt = Datatypes.Lt); auto with zarith.<br/>
 
131
<code class="keyword">Qed</code>.<br/>
 
132
 
 
133
<br/>
 
134
<code class="keyword">End</code> section1.<br/>
 
135
 
 
136
<br/>
 
137
<code class="keyword">Infix</code> "^" := <a href="Coq.ZArith.Zpower.html#Zpower">Zpower</a> : Z_scope.<br/>
 
138
 
 
139
<br/>
 
140
<code class="keyword">Hint</code> <code class="keyword">Immediate</code> <a href="Coq.ZArith.Zpower.html#Zpower_nat_is_exp">Zpower_nat_is_exp</a>: zarith.<br/>
 
141
<code class="keyword">Hint</code> <code class="keyword">Immediate</code> <a href="Coq.ZArith.Zpower.html#Zpower_pos_is_exp">Zpower_pos_is_exp</a>: zarith.<br/>
 
142
<code class="keyword">Hint</code> Unfold Zpower_pos: zarith.<br/>
 
143
<code class="keyword">Hint</code> Unfold Zpower_nat: zarith.<br/>
 
144
 
 
145
<br/>
 
146
<code class="keyword">Section</code> Powers_of_2.<br/>
 
147
 
 
148
<br/>
 
149
</code>
 
150
 
 
151
<table width="100%"><tr class="doc"><td>
 
152
For the powers of two, that will be widely used, a more direct
 
153
   calculus is possible. We will also prove some properties such
 
154
   as <code>(x:positive) x &lt; 2^x</code> that are true for all integers bigger
 
155
   than 2 but more difficult to prove and useless. 
 
156
</td></tr></table>
 
157
<code>
 
158
 
 
159
<br/>
 
160
</code>
 
161
 
 
162
<table width="100%"><tr class="doc"><td>
 
163
<code>shift n m</code> computes <code>2^n * m</code>, or <code>m</code> shifted by <code>n</code> positions 
 
164
</td></tr></table>
 
165
<code>
 
166
 
 
167
<br/>
 
168
<code class="keyword">Definition</code> <a name="shift_nat"></a>shift_nat (n:<a href="Coq.Init.Datatypes.html#nat">nat</a>) (z:<a href="Coq.NArith.BinPos.html#positive">positive</a>) := <a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> n <a href="Coq.NArith.BinPos.html#positive">positive</a> <a href="Coq.NArith.BinPos.html#xO">xO</a> z. <br/>
 
169
<code class="keyword">Definition</code> <a name="shift_pos"></a>shift_pos (n z:<a href="Coq.NArith.BinPos.html#positive">positive</a>) := <a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> n <a href="Coq.NArith.BinPos.html#positive">positive</a> <a href="Coq.NArith.BinPos.html#xO">xO</a> z. <br/>
 
170
<code class="keyword">Definition</code> <a name="shift"></a>shift (n:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) (z:<a href="Coq.NArith.BinPos.html#positive">positive</a>) :=<br/>
 
171
&nbsp;&nbsp;match n with<br/>
 
172
&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Z0">Z0</a> =&gt; z<br/>
 
173
&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> p =&gt; <a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> p <a href="Coq.NArith.BinPos.html#positive">positive</a> <a href="Coq.NArith.BinPos.html#xO">xO</a> z<br/>
 
174
&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> p =&gt; z<br/>
 
175
&nbsp;&nbsp;end.<br/>
 
176
 
 
177
<br/>
 
178
<code class="keyword">Definition</code> <a name="two_power_nat"></a>two_power_nat (n:<a href="Coq.Init.Datatypes.html#nat">nat</a>) := <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> (<a href="Coq.ZArith.Zpower.html#shift_nat">shift_nat</a> n 1).<br/>
 
179
<code class="keyword">Definition</code> <a name="two_power_pos"></a>two_power_pos (x:<a href="Coq.NArith.BinPos.html#positive">positive</a>) := <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> (<a href="Coq.ZArith.Zpower.html#shift_pos">shift_pos</a> x 1).<br/>
 
180
 
 
181
<br/>
 
182
<code class="keyword">Lemma</code> <a name="two_power_nat_S"></a>two_power_nat_S :<br/>
 
183
&nbsp;forall n:<a href="Coq.Init.Datatypes.html#nat">nat</a>, <a href="Coq.ZArith.Zpower.html#two_power_nat">two_power_nat</a> (<a href="Coq.Init.Datatypes.html#S">S</a> n) = 2 * <a href="Coq.ZArith.Zpower.html#two_power_nat">two_power_nat</a> n.<br/>
 
184
intro; simpl in |- *; apply <a href="Coq.Init.Logic.html#refl_equal">refl_equal</a>.<br/>
 
185
<code class="keyword">Qed</code>.<br/>
 
186
 
 
187
<br/>
 
188
<code class="keyword">Lemma</code> <a name="shift_nat_plus"></a>shift_nat_plus :<br/>
 
189
&nbsp;forall (n m:<a href="Coq.Init.Datatypes.html#nat">nat</a>) (x:<a href="Coq.NArith.BinPos.html#positive">positive</a>),<br/>
 
190
&nbsp;&nbsp;&nbsp;<a href="Coq.ZArith.Zpower.html#shift_nat">shift_nat</a> (n + m) x = <a href="Coq.ZArith.Zpower.html#shift_nat">shift_nat</a> n (<a href="Coq.ZArith.Zpower.html#shift_nat">shift_nat</a> m x).<br/>
 
191
 
 
192
<br/>
 
193
intros; unfold shift_nat in |- *; apply <a href="Coq.ZArith.Zmisc.html#iter_nat_plus">iter_nat_plus</a>.<br/>
 
194
<code class="keyword">Qed</code>.<br/>
 
195
 
 
196
<br/>
 
197
<code class="keyword">Theorem</code> <a name="shift_nat_correct"></a>shift_nat_correct :<br/>
 
198
&nbsp;forall (n:<a href="Coq.Init.Datatypes.html#nat">nat</a>) (x:<a href="Coq.NArith.BinPos.html#positive">positive</a>), <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> (<a href="Coq.ZArith.Zpower.html#shift_nat">shift_nat</a> n x) = <a href="Coq.ZArith.Zpower.html#Zpower_nat">Zpower_nat</a> 2 n * <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> x.<br/>
 
199
 
 
200
<br/>
 
201
unfold shift_nat in |- *; simple induction n;<br/>
 
202
&nbsp;[ simpl in |- *; trivial with zarith<br/>
 
203
&nbsp;| intros; replace (<a href="Coq.ZArith.Zpower.html#Zpower_nat">Zpower_nat</a> 2 (<a href="Coq.Init.Datatypes.html#S">S</a> n0)) with (2 * <a href="Coq.ZArith.Zpower.html#Zpower_nat">Zpower_nat</a> 2 n0);<br/>
 
204
&nbsp;&nbsp;&nbsp;&nbsp;[ rewrite &lt;- Zmult_assoc; rewrite &lt;- (H x); simpl in |- *; reflexivity
 
205
    | auto with zarith ] ].<br/>
 
206
<code class="keyword">Qed</code>.<br/>
 
207
 
 
208
<br/>
 
209
<code class="keyword">Theorem</code> <a name="two_power_nat_correct"></a>two_power_nat_correct :<br/>
 
210
&nbsp;forall n:<a href="Coq.Init.Datatypes.html#nat">nat</a>, <a href="Coq.ZArith.Zpower.html#two_power_nat">two_power_nat</a> n = <a href="Coq.ZArith.Zpower.html#Zpower_nat">Zpower_nat</a> 2 n.<br/>
 
211
 
 
212
<br/>
 
213
intro n.<br/>
 
214
unfold two_power_nat in |- *.<br/>
 
215
rewrite (<a href="Coq.ZArith.Zpower.html#shift_nat_correct">shift_nat_correct</a> n).<br/>
 
216
omega.<br/>
 
217
<code class="keyword">Qed</code>.<br/>
 
218
&nbsp;&nbsp;<br/>
 
219
</code>
 
220
 
 
221
<table width="100%"><tr class="doc"><td>
 
222
Second we show that <code>two_power_pos</code> and <code>two_power_nat</code> are the same 
 
223
</td></tr></table>
 
224
<code>
 
225
<code class="keyword">Lemma</code> <a name="shift_pos_nat"></a>shift_pos_nat :<br/>
 
226
&nbsp;forall p x:<a href="Coq.NArith.BinPos.html#positive">positive</a>, <a href="Coq.ZArith.Zpower.html#shift_pos">shift_pos</a> p x = <a href="Coq.ZArith.Zpower.html#shift_nat">shift_nat</a> (<a href="Coq.NArith.BinPos.html#nat_of_P">nat_of_P</a> p) x.<br/>
 
227
 
 
228
<br/>
 
229
unfold shift_pos in |- *.<br/>
 
230
unfold shift_nat in |- *.<br/>
 
231
intros; apply <a href="Coq.ZArith.Zmisc.html#iter_nat_of_P">iter_nat_of_P</a>.<br/>
 
232
<code class="keyword">Qed</code>.<br/>
 
233
 
 
234
<br/>
 
235
<code class="keyword">Lemma</code> <a name="two_power_pos_nat"></a>two_power_pos_nat :<br/>
 
236
&nbsp;forall p:<a href="Coq.NArith.BinPos.html#positive">positive</a>, <a href="Coq.ZArith.Zpower.html#two_power_pos">two_power_pos</a> p = <a href="Coq.ZArith.Zpower.html#two_power_nat">two_power_nat</a> (<a href="Coq.NArith.BinPos.html#nat_of_P">nat_of_P</a> p).<br/>
 
237
 
 
238
<br/>
 
239
intro; unfold two_power_pos in |- *; unfold two_power_nat in |- *.<br/>
 
240
apply <a href="Coq.Init.Logic.html#f_equal">f_equal</a> with (f:= <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a>).<br/>
 
241
apply <a href="Coq.ZArith.Zpower.html#shift_pos_nat">shift_pos_nat</a>.<br/>
 
242
<code class="keyword">Qed</code>.<br/>
 
243
 
 
244
<br/>
 
245
</code>
 
246
 
 
247
<table width="100%"><tr class="doc"><td>
 
248
Then we deduce that <code>two_power_pos</code> is also correct 
 
249
</td></tr></table>
 
250
<code>
 
251
 
 
252
<br/>
 
253
<code class="keyword">Theorem</code> <a name="shift_pos_correct"></a>shift_pos_correct :<br/>
 
254
&nbsp;forall p x:<a href="Coq.NArith.BinPos.html#positive">positive</a>, <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> (<a href="Coq.ZArith.Zpower.html#shift_pos">shift_pos</a> p x) = <a href="Coq.ZArith.Zpower.html#Zpower_pos">Zpower_pos</a> 2 p * <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> x.<br/>
 
255
 
 
256
<br/>
 
257
intros.<br/>
 
258
rewrite (<a href="Coq.ZArith.Zpower.html#shift_pos_nat">shift_pos_nat</a> p x).<br/>
 
259
rewrite (<a href="Coq.ZArith.Zpower.html#Zpower_pos_nat">Zpower_pos_nat</a> 2 p).<br/>
 
260
apply <a href="Coq.ZArith.Zpower.html#shift_nat_correct">shift_nat_correct</a>.<br/>
 
261
<code class="keyword">Qed</code>.<br/>
 
262
 
 
263
<br/>
 
264
<code class="keyword">Theorem</code> <a name="two_power_pos_correct"></a>two_power_pos_correct :<br/>
 
265
&nbsp;forall x:<a href="Coq.NArith.BinPos.html#positive">positive</a>, <a href="Coq.ZArith.Zpower.html#two_power_pos">two_power_pos</a> x = <a href="Coq.ZArith.Zpower.html#Zpower_pos">Zpower_pos</a> 2 x.<br/>
 
266
 
 
267
<br/>
 
268
intro.<br/>
 
269
rewrite <a href="Coq.ZArith.Zpower.html#two_power_pos_nat">two_power_pos_nat</a>.<br/>
 
270
rewrite <a href="Coq.ZArith.Zpower.html#Zpower_pos_nat">Zpower_pos_nat</a>.<br/>
 
271
apply <a href="Coq.ZArith.Zpower.html#two_power_nat_correct">two_power_nat_correct</a>.<br/>
 
272
<code class="keyword">Qed</code>.<br/>
 
273
 
 
274
<br/>
 
275
</code>
 
276
 
 
277
<table width="100%"><tr class="doc"><td>
 
278
Some consequences 
 
279
</td></tr></table>
 
280
<code>
 
281
 
 
282
<br/>
 
283
<code class="keyword">Theorem</code> <a name="two_power_pos_is_exp"></a>two_power_pos_is_exp :<br/>
 
284
&nbsp;forall x y:<a href="Coq.NArith.BinPos.html#positive">positive</a>,<br/>
 
285
&nbsp;&nbsp;&nbsp;<a href="Coq.ZArith.Zpower.html#two_power_pos">two_power_pos</a> (x + y) = <a href="Coq.ZArith.Zpower.html#two_power_pos">two_power_pos</a> x * <a href="Coq.ZArith.Zpower.html#two_power_pos">two_power_pos</a> y.<br/>
 
286
intros.<br/>
 
287
rewrite (<a href="Coq.ZArith.Zpower.html#two_power_pos_correct">two_power_pos_correct</a> (x + y)).<br/>
 
288
rewrite (<a href="Coq.ZArith.Zpower.html#two_power_pos_correct">two_power_pos_correct</a> x).<br/>
 
289
rewrite (<a href="Coq.ZArith.Zpower.html#two_power_pos_correct">two_power_pos_correct</a> y).<br/>
 
290
apply <a href="Coq.ZArith.Zpower.html#Zpower_pos_is_exp">Zpower_pos_is_exp</a>.<br/>
 
291
<code class="keyword">Qed</code>.<br/>
 
292
 
 
293
<br/>
 
294
</code>
 
295
 
 
296
<table width="100%"><tr class="doc"><td>
 
297
The exponentiation <code>z -&gt; 2^z</code> for <code>z</code> a signed integer. 
 
298
    For convenience, we assume that <code>2^z = 0</code> for all <code>z &lt; 0</code>
 
299
    We could also define a inductive type <code>Log_result</code> with
 
300
    3 contructors <code> Zero | Pos positive -&gt; | minus_infty</code>
 
301
    but it's more complexe and not so useful. 
 
302
</td></tr></table>
 
303
<code>
 
304
&nbsp;<br/>
 
305
<code class="keyword">Definition</code> <a name="two_p"></a>two_p (x:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) :=<br/>
 
306
&nbsp;&nbsp;match x with<br/>
 
307
&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Z0">Z0</a> =&gt; 1<br/>
 
308
&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> y =&gt; <a href="Coq.ZArith.Zpower.html#two_power_pos">two_power_pos</a> y<br/>
 
309
&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> y =&gt; 0<br/>
 
310
&nbsp;&nbsp;end.<br/>
 
311
 
 
312
<br/>
 
313
<code class="keyword">Theorem</code> <a name="two_p_is_exp"></a>two_p_is_exp :<br/>
 
314
&nbsp;forall x y:<a href="Coq.ZArith.BinInt.html#Z">Z</a>, 0 &lt;= x -&gt; 0 &lt;= y -&gt; <a href="Coq.ZArith.Zpower.html#two_p">two_p</a> (x + y) = <a href="Coq.ZArith.Zpower.html#two_p">two_p</a> x * <a href="Coq.ZArith.Zpower.html#two_p">two_p</a> y.<br/>
 
315
simple induction x;<br/>
 
316
&nbsp;[ simple induction y; simpl in |- *; auto with zarith<br/>
 
317
&nbsp;| simple induction y;<br/>
 
318
&nbsp;&nbsp;&nbsp;&nbsp;[ unfold two_p in |- *; rewrite (Zmult_comm (two_power_pos p) 1);
 
319
       rewrite (Zmult_1_l (two_power_pos p)); auto with zarith
 
320
    | unfold Zplus in |- *; unfold two_p in |- *; intros;
 
321
       apply two_power_pos_is_exp
 
322
    | intros; unfold Zle in H0; unfold Zcompare in H0;
 
323
       absurd (Datatypes.Gt = Datatypes.Gt); trivial with zarith ]<br/>
 
324
&nbsp;| simple induction y;<br/>
 
325
&nbsp;&nbsp;&nbsp;&nbsp;[ simpl in |- *; auto with zarith
 
326
    | intros; unfold Zle in H; unfold Zcompare in H;
 
327
       absurd (Datatypes.Gt = Datatypes.Gt); trivial with zarith
 
328
    | intros; unfold Zle in H; unfold Zcompare in H;
 
329
       absurd (Datatypes.Gt = Datatypes.Gt); trivial with zarith ] ].<br/>
 
330
<code class="keyword">Qed</code>.<br/>
 
331
 
 
332
<br/>
 
333
<code class="keyword">Lemma</code> <a name="two_p_gt_ZERO"></a>two_p_gt_ZERO : forall x:<a href="Coq.ZArith.BinInt.html#Z">Z</a>, 0 &lt;= x -&gt; <a href="Coq.ZArith.Zpower.html#two_p">two_p</a> x &gt; 0.<br/>
 
334
simple induction x; intros;<br/>
 
335
&nbsp;[ simpl in |- *; omega<br/>
 
336
&nbsp;| simpl in |- *; unfold two_power_pos in |- *; apply Zorder.Zgt_pos_0<br/>
 
337
&nbsp;| absurd (0 &lt;= <a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> p);<br/>
 
338
&nbsp;&nbsp;&nbsp;&nbsp;[ simpl in |- *; unfold Zle in |- *; unfold Zcompare in |- *;
 
339
       do 2 unfold not in |- *; auto with zarith
 
340
    | assumption ] ].<br/>
 
341
<code class="keyword">Qed</code>.<br/>
 
342
 
 
343
<br/>
 
344
<code class="keyword">Lemma</code> <a name="two_p_S"></a>two_p_S : forall x:<a href="Coq.ZArith.BinInt.html#Z">Z</a>, 0 &lt;= x -&gt; <a href="Coq.ZArith.Zpower.html#two_p">two_p</a> (<a href="Coq.ZArith.BinInt.html#Zsucc">Zsucc</a> x) = 2 * <a href="Coq.ZArith.Zpower.html#two_p">two_p</a> x.<br/>
 
345
intros; unfold Zsucc in |- *. <br/>
 
346
rewrite (<a href="Coq.ZArith.Zpower.html#two_p_is_exp">two_p_is_exp</a> x 1 H (Zorder.Zle_0_pos 1)).<br/>
 
347
apply <a href="Coq.ZArith.BinInt.html#Zmult_comm">Zmult_comm</a>.<br/>
 
348
<code class="keyword">Qed</code>.<br/>
 
349
 
 
350
<br/>
 
351
<code class="keyword">Lemma</code> <a name="two_p_pred"></a>two_p_pred : forall x:<a href="Coq.ZArith.BinInt.html#Z">Z</a>, 0 &lt;= x -&gt; <a href="Coq.ZArith.Zpower.html#two_p">two_p</a> (<a href="Coq.ZArith.BinInt.html#Zpred">Zpred</a> x) &lt; <a href="Coq.ZArith.Zpower.html#two_p">two_p</a> x.<br/>
 
352
intros; apply <a href="Coq.ZArith.Wf_Z.html#natlike_ind">natlike_ind</a> with (P:= fun x:<a href="Coq.ZArith.BinInt.html#Z">Z</a> =&gt; <a href="Coq.ZArith.Zpower.html#two_p">two_p</a> (<a href="Coq.ZArith.BinInt.html#Zpred">Zpred</a> x) &lt; <a href="Coq.ZArith.Zpower.html#two_p">two_p</a> x);<br/>
 
353
&nbsp;[ simpl in |- *; unfold Zlt in |- *; auto with zarith<br/>
 
354
&nbsp;| intros; elim (<a href="Coq.ZArith.Zorder.html#Zle_lt_or_eq">Zle_lt_or_eq</a> 0 x0 H0);<br/>
 
355
&nbsp;&nbsp;&nbsp;&nbsp;[ intros;<br/>
 
356
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;replace (<a href="Coq.ZArith.Zpower.html#two_p">two_p</a> (<a href="Coq.ZArith.BinInt.html#Zpred">Zpred</a> (<a href="Coq.ZArith.BinInt.html#Zsucc">Zsucc</a> x0))) with (<a href="Coq.ZArith.Zpower.html#two_p">two_p</a> (<a href="Coq.ZArith.BinInt.html#Zsucc">Zsucc</a> (<a href="Coq.ZArith.BinInt.html#Zpred">Zpred</a> x0)));<br/>
 
357
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ rewrite (<a href="Coq.ZArith.Zpower.html#two_p_S">two_p_S</a> (<a href="Coq.ZArith.BinInt.html#Zpred">Zpred</a> x0));<br/>
 
358
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ rewrite (<a href="Coq.ZArith.Zpower.html#two_p_S">two_p_S</a> x0); [ omega | assumption ]<br/>
 
359
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| apply Zorder.Zlt_0_le_0_pred; assumption ]<br/>
 
360
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| rewrite &lt;- (<a href="Coq.ZArith.BinInt.html#Zsucc_pred">Zsucc_pred</a> x0); rewrite &lt;- (<a href="Coq.ZArith.BinInt.html#Zpred_succ">Zpred_succ</a> x0);<br/>
 
361
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trivial with zarith ]<br/>
 
362
&nbsp;&nbsp;&nbsp;&nbsp;| intro Hx0; rewrite &lt;- Hx0; simpl in |- *; unfold Zlt in |- *;<br/>
 
363
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;auto with zarith ]<br/>
 
364
&nbsp;| assumption ].<br/>
 
365
<code class="keyword">Qed</code>. <br/>
 
366
 
 
367
<br/>
 
368
<code class="keyword">Lemma</code> <a name="Zlt_lt_double"></a>Zlt_lt_double : forall x y:<a href="Coq.ZArith.BinInt.html#Z">Z</a>, 0 &lt;= x &lt; y -&gt; x &lt; 2 * y.<br/>
 
369
intros; omega. <code class="keyword">Qed</code>. <br/>
 
370
 
 
371
<br/>
 
372
<code class="keyword">End</code> Powers_of_2.<br/>
 
373
 
 
374
<br/>
 
375
<code class="keyword">Hint</code> Resolve <a href="Coq.ZArith.Zpower.html#two_p_gt_ZERO">two_p_gt_ZERO</a>: zarith.<br/>
 
376
<code class="keyword">Hint</code> <code class="keyword">Immediate</code> <a href="Coq.ZArith.Zpower.html#two_p_pred">two_p_pred</a> <a href="Coq.ZArith.Zpower.html#two_p_S">two_p_S</a>: zarith.<br/>
 
377
 
 
378
<br/>
 
379
<code class="keyword">Section</code> power_div_with_rest.<br/>
 
380
 
 
381
<br/>
 
382
</code>
 
383
 
 
384
<table width="100%"><tr class="doc"><td>
 
385
Division by a power of two.
 
386
    To <code>n:Z</code> and <code>p:positive</code>, <code>q</code>,<code>r</code> are associated such that
 
387
    <code>n = 2^p.q + r</code> and <code>0 &lt;= r &lt; 2^p</code> 
 
388
</td></tr></table>
 
389
<code>
 
390
 
 
391
<br/>
 
392
</code>
 
393
 
 
394
<table width="100%"><tr class="doc"><td>
 
395
Invariant: <code>d*q + r = d'*q + r /\ d' = 2*d /\ 0&lt;= r &lt; d /\ 0 &lt;= r' &lt; d'</code> 
 
396
</td></tr></table>
 
397
<code>
 
398
<code class="keyword">Definition</code> <a name="Zdiv_rest_aux"></a>Zdiv_rest_aux (qrd:<a href="Coq.ZArith.BinInt.html#Z">Z</a> * <a href="Coq.ZArith.BinInt.html#Z">Z</a> * <a href="Coq.ZArith.BinInt.html#Z">Z</a>) :=<br/>
 
399
&nbsp;&nbsp;let (qr, d) := qrd in<br/>
 
400
&nbsp;&nbsp;let (q, r) := qr in<br/>
 
401
&nbsp;&nbsp;(match q with<br/>
 
402
&nbsp;&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Z0">Z0</a> =&gt; (0, r)<br/>
 
403
&nbsp;&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> <a href="Coq.NArith.BinPos.html#xH">xH</a> =&gt; (0, d + r)<br/>
 
404
&nbsp;&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> (<a href="Coq.NArith.BinPos.html#xI">xI</a> n) =&gt; (<a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> n, d + r)<br/>
 
405
&nbsp;&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> (<a href="Coq.NArith.BinPos.html#xO">xO</a> n) =&gt; (<a href="Coq.ZArith.BinInt.html#Zpos">Zpos</a> n, r)<br/>
 
406
&nbsp;&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> <a href="Coq.NArith.BinPos.html#xH">xH</a> =&gt; (-1, d + r)<br/>
 
407
&nbsp;&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> (<a href="Coq.NArith.BinPos.html#xI">xI</a> n) =&gt; (<a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> n - 1, d + r)<br/>
 
408
&nbsp;&nbsp;&nbsp;| <a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> (<a href="Coq.NArith.BinPos.html#xO">xO</a> n) =&gt; (<a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> n, r)<br/>
 
409
&nbsp;&nbsp;&nbsp;end, 2 * d).<br/>
 
410
 
 
411
<br/>
 
412
<code class="keyword">Definition</code> <a name="Zdiv_rest"></a>Zdiv_rest (x:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) (p:<a href="Coq.NArith.BinPos.html#positive">positive</a>) :=<br/>
 
413
&nbsp;&nbsp;let (qr, d) := <a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> p _ <a href="Coq.ZArith.Zpower.html#Zdiv_rest_aux">Zdiv_rest_aux</a> (x, 0, 1) in qr.<br/>
 
414
 
 
415
<br/>
 
416
<code class="keyword">Lemma</code> <a name="Zdiv_rest_correct1"></a>Zdiv_rest_correct1 :<br/>
 
417
&nbsp;forall (x:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) (p:<a href="Coq.NArith.BinPos.html#positive">positive</a>),<br/>
 
418
&nbsp;&nbsp;&nbsp;let (qr, d) := <a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> p _ <a href="Coq.ZArith.Zpower.html#Zdiv_rest_aux">Zdiv_rest_aux</a> (x, 0, 1) in d = <a href="Coq.ZArith.Zpower.html#two_power_pos">two_power_pos</a> p.<br/>
 
419
 
 
420
<br/>
 
421
intros x p; rewrite (<a href="Coq.ZArith.Zmisc.html#iter_nat_of_P">iter_nat_of_P</a> p _ <a href="Coq.ZArith.Zpower.html#Zdiv_rest_aux">Zdiv_rest_aux</a> (x, 0, 1));<br/>
 
422
&nbsp;rewrite (<a href="Coq.ZArith.Zpower.html#two_power_pos_nat">two_power_pos_nat</a> p); elim (<a href="Coq.NArith.BinPos.html#nat_of_P">nat_of_P</a> p); <br/>
 
423
&nbsp;simpl in |- *;<br/>
 
424
&nbsp;[ trivial with zarith<br/>
 
425
&nbsp;| intro n; rewrite (<a href="Coq.ZArith.Zpower.html#two_power_nat_S">two_power_nat_S</a> n); unfold Zdiv_rest_aux at 2 in |- *;<br/>
 
426
&nbsp;&nbsp;&nbsp;&nbsp;elim (<a href="Coq.ZArith.Zmisc.html#iter_nat">iter_nat</a> n (<a href="Coq.ZArith.BinInt.html#Z">Z</a> * <a href="Coq.ZArith.BinInt.html#Z">Z</a> * <a href="Coq.ZArith.BinInt.html#Z">Z</a>) <a href="Coq.ZArith.Zpower.html#Zdiv_rest_aux">Zdiv_rest_aux</a> (x, 0, 1)); <br/>
 
427
&nbsp;&nbsp;&nbsp;&nbsp;destruct a; intros; apply <a href="Coq.Init.Logic.html#f_equal">f_equal</a> with (f:= fun z:<a href="Coq.ZArith.BinInt.html#Z">Z</a> =&gt; 2 * z);<br/>
 
428
&nbsp;&nbsp;&nbsp;&nbsp;assumption ]. <br/>
 
429
<code class="keyword">Qed</code>.<br/>
 
430
 
 
431
<br/>
 
432
<code class="keyword">Lemma</code> <a name="Zdiv_rest_correct2"></a>Zdiv_rest_correct2 :<br/>
 
433
&nbsp;forall (x:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) (p:<a href="Coq.NArith.BinPos.html#positive">positive</a>),<br/>
 
434
&nbsp;&nbsp;&nbsp;let (qr, d) := <a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> p _ <a href="Coq.ZArith.Zpower.html#Zdiv_rest_aux">Zdiv_rest_aux</a> (x, 0, 1) in<br/>
 
435
&nbsp;&nbsp;&nbsp;let (q, r) := qr in x = q * d + r /\ 0 &lt;= r &lt; d.<br/>
 
436
 
 
437
<br/>
 
438
intros;<br/>
 
439
&nbsp;apply <a href="Coq.ZArith.Zmisc.html#iter_pos_invariant">iter_pos_invariant</a> with<br/>
 
440
&nbsp;&nbsp;(f:= <a href="Coq.ZArith.Zpower.html#Zdiv_rest_aux">Zdiv_rest_aux</a>)<br/>
 
441
&nbsp;&nbsp;(Inv:= fun qrd:<a href="Coq.ZArith.BinInt.html#Z">Z</a> * <a href="Coq.ZArith.BinInt.html#Z">Z</a> * <a href="Coq.ZArith.BinInt.html#Z">Z</a> =&gt;<br/>
 
442
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let (qr, d) := qrd in<br/>
 
443
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let (q, r) := qr in x = q * d + r /\ 0 &lt;= r &lt; d);<br/>
 
444
&nbsp;[ intro x0; elim x0; intro y0; elim y0; intros q r d;<br/>
 
445
&nbsp;&nbsp;&nbsp;&nbsp;unfold Zdiv_rest_aux in |- *; elim q;<br/>
 
446
&nbsp;&nbsp;&nbsp;&nbsp;[ omega<br/>
 
447
&nbsp;&nbsp;&nbsp;&nbsp;| destruct p0;<br/>
 
448
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ rewrite BinInt.Zpos_xI; intro; elim H; intros; split;<br/>
 
449
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ rewrite H0; rewrite Zplus_assoc; rewrite Zmult_plus_distr_l;
 
450
             rewrite Zmult_1_l; rewrite Zmult_assoc;
 
451
             rewrite (Zmult_comm (Zpos p0) 2); apply refl_equal
 
452
          | omega ]<br/>
 
453
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| rewrite BinInt.Zpos_xO; intro; elim H; intros; split;<br/>
 
454
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ rewrite H0; rewrite Zmult_assoc; rewrite (Zmult_comm (Zpos p0) 2);
 
455
             apply refl_equal
 
456
          | omega ]<br/>
 
457
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| omega ]<br/>
 
458
&nbsp;&nbsp;&nbsp;&nbsp;| destruct p0;<br/>
 
459
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ rewrite BinInt.Zneg_xI; unfold Zminus in |- *; intro; elim H; intros;<br/>
 
460
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;split;<br/>
 
461
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ rewrite H0; rewrite <a href="Coq.ZArith.BinInt.html#Zplus_assoc">Zplus_assoc</a>;<br/>
 
462
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apply <a href="Coq.Init.Logic.html#f_equal">f_equal</a> with (f:= fun z:<a href="Coq.ZArith.BinInt.html#Z">Z</a> =&gt; z + r);<br/>
 
463
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do 2 rewrite <a href="Coq.ZArith.BinInt.html#Zmult_plus_distr_l">Zmult_plus_distr_l</a>; rewrite <a href="Coq.ZArith.BinInt.html#Zmult_assoc">Zmult_assoc</a>;<br/>
 
464
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rewrite (<a href="Coq.ZArith.BinInt.html#Zmult_comm">Zmult_comm</a> (<a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> p0) 2); rewrite &lt;- <a href="Coq.ZArith.BinInt.html#Zplus_assoc">Zplus_assoc</a>;<br/>
 
465
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apply <a href="Coq.Init.Logic.html#f_equal">f_equal</a> with (f:= fun z:<a href="Coq.ZArith.BinInt.html#Z">Z</a> =&gt; 2 * <a href="Coq.ZArith.BinInt.html#Zneg">Zneg</a> p0 * d + z); <br/>
 
466
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;omega<br/>
 
467
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| omega ]<br/>
 
468
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| rewrite BinInt.Zneg_xO; unfold Zminus in |- *; intro; elim H; intros;<br/>
 
469
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;split;<br/>
 
470
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ rewrite H0; rewrite Zmult_assoc; rewrite (Zmult_comm (Zneg p0) 2);
 
471
             apply refl_equal
 
472
          | omega ]<br/>
 
473
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| omega ] ]<br/>
 
474
&nbsp;| omega ].<br/>
 
475
<code class="keyword">Qed</code>.<br/>
 
476
 
 
477
<br/>
 
478
<code class="keyword">Inductive</code> <a name="Zdiv_rest_proofs"></a>Zdiv_rest_proofs (x:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) (p:<a href="Coq.NArith.BinPos.html#positive">positive</a>) : Set :=<br/>
 
479
&nbsp;&nbsp;&nbsp;&nbsp;<a name="Zdiv_rest_proof"></a>Zdiv_rest_proof :<br/>
 
480
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;forall q r:<a href="Coq.ZArith.BinInt.html#Z">Z</a>,<br/>
 
481
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x = q * <a href="Coq.ZArith.Zpower.html#two_power_pos">two_power_pos</a> p + r -&gt;<br/>
 
482
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 &lt;= r -&gt; r &lt; <a href="Coq.ZArith.Zpower.html#two_power_pos">two_power_pos</a> p -&gt; Zdiv_rest_proofs x p.<br/>
 
483
 
 
484
<br/>
 
485
<code class="keyword">Lemma</code> <a name="Zdiv_rest_correct"></a>Zdiv_rest_correct : forall (x:<a href="Coq.ZArith.BinInt.html#Z">Z</a>) (p:<a href="Coq.NArith.BinPos.html#positive">positive</a>), <a href="Coq.ZArith.Zpower.html#Zdiv_rest_proofs">Zdiv_rest_proofs</a> x p.<br/>
 
486
intros x p.<br/>
 
487
generalize (<a href="Coq.ZArith.Zpower.html#Zdiv_rest_correct1">Zdiv_rest_correct1</a> x p); generalize (<a href="Coq.ZArith.Zpower.html#Zdiv_rest_correct2">Zdiv_rest_correct2</a> x p).<br/>
 
488
elim (<a href="Coq.ZArith.Zmisc.html#iter_pos">iter_pos</a> p (<a href="Coq.ZArith.BinInt.html#Z">Z</a> * <a href="Coq.ZArith.BinInt.html#Z">Z</a> * <a href="Coq.ZArith.BinInt.html#Z">Z</a>) <a href="Coq.ZArith.Zpower.html#Zdiv_rest_aux">Zdiv_rest_aux</a> (x, 0, 1)).<br/>
 
489
simple induction a.<br/>
 
490
intros.<br/>
 
491
elim H; intros H1 H2; clear H.<br/>
 
492
rewrite H0 in H1; rewrite H0 in H2; elim H2; intros;<br/>
 
493
&nbsp;apply <a href="Coq.ZArith.Zpower.html#Zdiv_rest_proof">Zdiv_rest_proof</a> with (q:= a0) (r:= b); assumption.<br/>
 
494
<code class="keyword">Qed</code>.<br/>
 
495
 
 
496
<br/>
 
497
<code class="keyword">End</code> power_div_with_rest.</code>
 
498
<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>
 
499
</body>
 
500
</html>
 
 
b'\\ No newline at end of file'