-
Notifications
You must be signed in to change notification settings - Fork 4
/
prime.html
265 lines (265 loc) · 9.31 KB
/
prime.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html>
<head>
<title>numbers.js documentation</title>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/bootstrap.min.js"></script>
<link type="text/css" rel="stylesheet" href="./css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="./css/doc.css">
</head>
<body>
<nav role="navigation" class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" class="navbar-toggle collapsed"><span class="sr-only">Toggle navigation</span></button><a href="#" class="navbar-brand">numbers.js</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div id="bs-example-navbar-collapse-1" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="./index.html">Home <span class="glyphicon glyphicon-home"></span></a></li>
<li><a href="./examples.html">Examples</a></li>
<li class="active dropdown"><a href="#" data-toggle="dropdown" class="dropdown-toggle">Documentation<span class="caret"></span></a>
<ul role="menu" class="dropdown-menu">
<li><a href="./basic.html">basic</a></li>
<li><a href="./calculus.html">calculus</a></li>
<li><a href="./complex.html">complex</a></li>
<li><a href="./dsp.html">dsp</a></li>
<li><a href="./generate.html">generate</a></li>
<li><a href="./matrix.html">matrix</a></li>
<li><a href="./prime.html">prime</a></li>
<li><a href="./random.html">random</a></li>
<li><a href="./statistic.html">statistic</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="https://github.com/sjkaliski/numbers.js">numbers.js on GitHub</a></li>
<li><a href="https://github.com/stdako/numbersdoc">documentation on GitHub</a></li>
</ul>
</div>
<!--.navbar-collapse -->
</div>
<!--.container-fluid -->
</nav><span id="sidebar">
<ul>
<li><a href="#coprime">prime.coprime</a></li>
<li><a href="#factorization">prime.factorization</a></li>
<li><a href="#getPerfectPower">prime.getPerfectPower</a></li>
<li><a href="#getPrimePower">prime.getPrimePower</a></li>
<li><a href="#millerRabin">prime.millerRabin</a></li>
<li><a href="#sieve">prime.sieve</a></li>
<li><a href="#simple">prime.simple</a></li>
</ul></span><span id="api-cont">
<h3><strong>numbers.prime</strong></h3>
<div id="coprime" class="api-func">
<h4>numbers.prime.<b>coprime</b>(a, b)</h4>
<p>Determine if two integers are coprime.</p>
<table>
<tr>
<th>Parameters</th>
<td>
<p><b>a</b> : <i>Int</i><br/>
<div class="desc">First integer.</div>
</p>
<p><b>b</b> : <i>Int</i><br/>
<div class="desc">Second integer</div>
</p>
</td>
</tr>
<tr>
<th>Returns</th>
<td>
<p><b>bool</b> : <i>Boolean</i>
<div class="desc">true if <i>a</i>, <i>b</i> are coprime, false otherwise.</div>
</p>
</td>
</tr>
<tr>
<th>Errors</th>
<td>
<p>This function does not raise any errors.</p>
</td>
</tr>
</table>
<hr/>
</div>
<div id="factorization" class="api-func">
<h4>numbers.prime.<b>factorization</b>(n)</h4>
<p>Factors an integer, <i>n</i>, into its prime factors and puts them into an array.</p>
<table>
<tr>
<th>Parameters</th>
<td>
<p><b>n</b> : <i>Int</i><br/>
<div class="desc">The number to factor.</div>
</p>
</td>
</tr>
<tr>
<th>Returns</th>
<td>
<p><b>arr</b> : <i>Array</i>
<div class="desc">The prime factors of <i>n</i>.</div>
</p>
</td>
</tr>
<tr>
<th>Errors</th>
<td>
<p>This function does not raise any errors.</p>
</td>
</tr>
</table>
<hr/>
</div>
<div id="getPerfectPower" class="api-func">
<h4>numbers.prime.<b>getPerfectPower</b>(n)</h4>
<p>Determines if an integer, <i>n</i>, is a perfect power. It should be noted that this does not find the minimum value of k where m^k = n for some m.</p>
<table>
<tr>
<th>Parameters</th>
<td>
<p><b>n</b> : <i>Int</i><br/>
<div class="desc">The number to test.</div>
</p>
</td>
</tr>
<tr>
<th>Returns</th>
<td>
<p><b>arr/bool</b> : <i>Array/Boolean</i>
<div class="desc">Returns <span class="lit">[m,k]</span> if <i>n</i> is a perfect power, returns false otherwise.</div>
</p>
</td>
</tr>
<tr>
<th>Errors</th>
<td>
<p>This function does not raise any errors.</p>
</td>
</tr>
</table>
<hr/>
</div>
<div id="getPrimePower" class="api-func">
<h4>numbers.prime.<b>getPrimePower</b>(n)</h4>
<p>Determines if an integer, <i>n</i>, is a prime power (n = p^m). The prime and the power are returned if so.</p>
<table>
<tr>
<th>Parameters</th>
<td>
<p><b>n</b> : <i>Int</i><br/>
<div class="desc">The number to test.</div>
</p>
</td>
</tr>
<tr>
<th>Returns</th>
<td>
<p><b>arr/bool</b> : <i>Array/Boolean</i>
<div class="desc">Returns <span class="lit">[p,m]</span> if <i>n</i> is a perfect power, returns false otherwise.</div>
</p>
</td>
</tr>
<tr>
<th>Errors</th>
<td>
<p>This function does not raise any errors.</p>
</td>
</tr>
</table>
<hr/>
</div>
<div id="millerRabin" class="api-func">
<h4>numbers.prime.<b>millerRabin</b>(n, k)</h4>
<p>Determines if an integer, <i>n</i>, is prime in polynomial time using the Miller-Rabin primality test, with an accuracy rate (number of trials) <i>k</i>.</p>
<table>
<tr>
<th>Parameters</th>
<td>
<p><b>n</b> : <i>Int</i><br/>
<div class="desc">The number to test for primality.</div>
</p>
<p><b>k</b> : <i>Int</i><br/>
<div class="desc">The accuracy rate.</div>
</p>
</td>
</tr>
<tr>
<th>Returns</th>
<td>
<p><b>bool</b> : <i>Boolean</i>
<div class="desc">true if <i>n</i> is prime, false otherwise.</div>
</p>
</td>
</tr>
<tr>
<th>Errors</th>
<td>
<p>This function does not raise any errors.</p>
</td>
</tr>
</table>
<hr/>
</div>
<div id="sieve" class="api-func">
<h4>numbers.prime.<b>sieve</b>(n)</h4>
<p>Creates an array of prime numbers from 2 to <i>n</i>, inclusive.</p>
<table>
<tr>
<th>Parameters</th>
<td>
<p><b>n</b> : <i>Int</i><br/>
<div class="desc">The largest prime number to be returned.</div>
</p>
</td>
</tr>
<tr>
<th>Returns</th>
<td>
<p><b>arr</b> : <i>Array</i>
<div class="desc">An array of primes from 2 to <i>n</i>.</div>
</p>
</td>
</tr>
<tr>
<th>Errors</th>
<td>
<p>This function does not raise any errors.</p>
</td>
</tr>
</table>
<hr/>
</div>
<div id="simple" class="api-func">
<h4>numbers.prime.<b>simple</b>(n)</h4>
<p>Determines if an integer, <i>n</i>, is prime using brute force.</p>
<table>
<tr>
<th>Parameters</th>
<td>
<p><b>n</b> : <i>Int</i><br/>
<div class="desc">The number to test for primality.</div>
</p>
</td>
</tr>
<tr>
<th>Returns</th>
<td>
<p><b>bool</b> : <i>Boolean</i>
<div class="desc">true if <i>n</i> is prime, false otherwise.</div>
</p>
</td>
</tr>
<tr>
<th>Errors</th>
<td>
<p>This function does not raise any errors.</p>
</td>
</tr>
</table>
<hr/>
</div></span>
</body>
</html>