~ubuntu-branches/debian/squeeze/maxima/squeeze

« back to all changes in this revision

Viewing changes to doc/info/maxima_32.html

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2006-10-18 14:52:42 UTC
  • mto: (1.1.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061018145242-vzyrm5hmxr8kiosf
ImportĀ upstreamĀ versionĀ 5.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
 
2
<html>
 
3
<!-- Created on September, 20 2006 by texi2html 1.76 -->
 
4
<!--
 
5
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
 
6
            Karl Berry  <karl@freefriends.org>
 
7
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
 
8
            and many others.
 
9
Maintained by: Many creative people <dev@texi2html.cvshome.org>
 
10
Send bugs and suggestions to <users@texi2html.cvshome.org>
 
11
 
 
12
-->
 
13
<head>
 
14
<title>Maxima Manual: 32. Number Theory</title>
 
15
 
 
16
<meta name="description" content="Maxima Manual: 32. Number Theory">
 
17
<meta name="keywords" content="Maxima Manual: 32. Number Theory">
 
18
<meta name="resource-type" content="document">
 
19
<meta name="distribution" content="global">
 
20
<meta name="Generator" content="texi2html 1.76">
 
21
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
 
22
<style type="text/css">
 
23
<!--
 
24
a.summary-letter {text-decoration: none}
 
25
pre.display {font-family: serif}
 
26
pre.format {font-family: serif}
 
27
pre.menu-comment {font-family: serif}
 
28
pre.menu-preformatted {font-family: serif}
 
29
pre.smalldisplay {font-family: serif; font-size: smaller}
 
30
pre.smallexample {font-size: smaller}
 
31
pre.smallformat {font-family: serif; font-size: smaller}
 
32
pre.smalllisp {font-size: smaller}
 
33
span.sansserif {font-family:sans-serif; font-weight:normal;}
 
34
ul.toc {list-style: none}
 
35
body
 
36
{
 
37
    color: black;
 
38
    background: white; 
 
39
    margin-left: 8%;
 
40
    margin-right: 13%;
 
41
}
 
42
 
 
43
h1
 
44
{
 
45
    margin-left: +8%;
 
46
    font-size: 150%;
 
47
    font-family: sans-serif
 
48
}
 
49
 
 
50
h2
 
51
{
 
52
    font-size: 125%;
 
53
    font-family: sans-serif
 
54
}
 
55
 
 
56
h3
 
57
{
 
58
    font-size: 100%;
 
59
    font-family: sans-serif
 
60
}
 
61
 
 
62
h2,h3,h4,h5,h6 { margin-left: +4%; }
 
63
 
 
64
div.textbox
 
65
{
 
66
    border: solid;
 
67
    border-width: thin;
 
68
    /* width: 100%; */
 
69
    padding-top: 1em;
 
70
    padding-bottom: 1em;
 
71
    padding-left: 2em;
 
72
    padding-right: 2em
 
73
}
 
74
 
 
75
div.titlebox
 
76
{
 
77
    border: none;
 
78
    padding-top: 1em;
 
79
    padding-bottom: 1em;
 
80
    padding-left: 2em;
 
81
    padding-right: 2em;
 
82
    background: rgb(200,255,255);
 
83
    font-family: sans-serif
 
84
}
 
85
 
 
86
div.synopsisbox
 
87
{
 
88
    border: none;
 
89
    padding-top: 1em;
 
90
    padding-bottom: 1em;
 
91
    padding-left: 2em;
 
92
    padding-right: 2em;
 
93
     background: rgb(255,220,255);
 
94
    /*background: rgb(200,255,255); */
 
95
    /* font-family: fixed */
 
96
}
 
97
 
 
98
pre.example
 
99
{
 
100
    border: none;
 
101
    padding-top: 1em;
 
102
    padding-bottom: 1em;
 
103
    padding-left: 1em;
 
104
    padding-right: 1em;
 
105
    background: rgb(247,242,180); /* kind of sandy */
 
106
    /* background: rgb(200,255,255); */ /* sky blue */
 
107
    font-family: "Lucida Console", monospace
 
108
}
 
109
 
 
110
div.spacerbox
 
111
{
 
112
    border: none;
 
113
    padding-top: 2em;
 
114
    padding-bottom: 2em
 
115
}
 
116
 
 
117
div.image
 
118
{
 
119
    margin: 0;
 
120
    padding: 1em;
 
121
    text-align: center;
 
122
}
 
123
-->
 
124
</style>
 
125
 
 
126
<link rel="icon" href="http://maxima.sourceforge.net/favicon.ico"/>
 
127
</head>
 
128
 
 
129
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
 
130
 
 
131
<a name="Number-Theory"></a>
 
132
<a name="SEC128"></a>
 
133
<table cellpadding="1" cellspacing="1" border="0">
 
134
<tr><td valign="middle" align="left">[<a href="maxima_31.html#SEC127" title="Previous section in reading order"> &lt; </a>]</td>
 
135
<td valign="middle" align="left">[<a href="#SEC129" title="Next section in reading order"> &gt; </a>]</td>
 
136
<td valign="middle" align="left"> &nbsp; </td>
 
137
<td valign="middle" align="left">[<a href="maxima_31.html#SEC125" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
 
138
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Up section"> Up </a>]</td>
 
139
<td valign="middle" align="left">[<a href="maxima_33.html#SEC130" title="Next chapter"> &gt;&gt; </a>]</td>
 
140
<td valign="middle" align="left"> &nbsp; </td>
 
141
<td valign="middle" align="left"> &nbsp; </td>
 
142
<td valign="middle" align="left"> &nbsp; </td>
 
143
<td valign="middle" align="left"> &nbsp; </td>
 
144
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
 
145
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
 
146
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
 
147
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
 
148
</tr></table>
 
149
<h1 class="chapter"> 32. Number Theory </h1>
 
150
 
 
151
 
 
152
<table class="menu" border="0" cellspacing="0">
 
153
<tr><td align="left" valign="top"><a href="#SEC129">32.1 Definitions for Number Theory</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">  
 
154
</td></tr>
 
155
</table>
 
156
 
 
157
<hr size="6">
 
158
<a name="Definitions-for-Number-Theory"></a>
 
159
<a name="SEC129"></a>
 
160
<table cellpadding="1" cellspacing="1" border="0">
 
161
<tr><td valign="middle" align="left">[<a href="#SEC128" title="Previous section in reading order"> &lt; </a>]</td>
 
162
<td valign="middle" align="left">[<a href="maxima_33.html#SEC130" title="Next section in reading order"> &gt; </a>]</td>
 
163
<td valign="middle" align="left"> &nbsp; </td>
 
164
<td valign="middle" align="left">[<a href="#SEC128" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
 
165
<td valign="middle" align="left">[<a href="#SEC128" title="Up section"> Up </a>]</td>
 
166
<td valign="middle" align="left">[<a href="maxima_33.html#SEC130" title="Next chapter"> &gt;&gt; </a>]</td>
 
167
<td valign="middle" align="left"> &nbsp; </td>
 
168
<td valign="middle" align="left"> &nbsp; </td>
 
169
<td valign="middle" align="left"> &nbsp; </td>
 
170
<td valign="middle" align="left"> &nbsp; </td>
 
171
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
 
172
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
 
173
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
 
174
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
 
175
</tr></table>
 
176
<h2 class="section"> 32.1 Definitions for Number Theory </h2>
 
177
 
 
178
<dl>
 
179
<dt><u>Function:</u> <b>bern</b><i> (<var>n</var>)</i>
 
180
<a name="IDX1046"></a>
 
181
</dt>
 
182
<dd><p>Returns the <var>n</var>'th Bernoulli number for integer <var>n</var>.
 
183
Bernoulli numbers equal to zero are suppressed if <code>zerobern</code> is <code>false</code>.
 
184
</p>
 
185
<p>See also <code>burn</code>.
 
186
</p>
 
187
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) zerobern: true$
 
188
(%i2) map (bern, [0, 1, 2, 3, 4, 5, 6, 7, 8]);
 
189
                  1  1       1      1        1
 
190
(%o2)       [1, - -, -, 0, - --, 0, --, 0, - --]
 
191
                  2  6       30     42       30
 
192
(%i3) zerobern: false$
 
193
(%i4) map (bern, [0, 1, 2, 3, 4, 5, 6, 7, 8]);
 
194
            1  1    1   5     691   7    3617  43867
 
195
(%o4) [1, - -, -, - --, --, - ----, -, - ----, -----]
 
196
            2  6    30  66    2730  6    510    798
 
197
</pre></td></tr></table>
 
198
</dd></dl>
 
199
 
 
200
<dl>
 
201
<dt><u>Function:</u> <b>bernpoly</b><i> (<var>x</var>, <var>n</var>)</i>
 
202
<a name="IDX1047"></a>
 
203
</dt>
 
204
<dd><p>Returns the <var>n</var>'th Bernoulli polynomial in the
 
205
variable <var>x</var>.
 
206
</p>
 
207
</dd></dl>
 
208
 
 
209
<dl>
 
210
<dt><u>Function:</u> <b>bfzeta</b><i> (<var>s</var>, <var>n</var>)</i>
 
211
<a name="IDX1048"></a>
 
212
</dt>
 
213
<dd><p>Returns the Riemann zeta function for the argument <var>s</var>.
 
214
The return value is a big float (bfloat);
 
215
<var>n</var> is the number of digits in the return value.
 
216
</p>
 
217
<p><code>load (&quot;bffac&quot;)</code> loads this function.
 
218
</p>
 
219
</dd></dl>
 
220
 
 
221
<dl>
 
222
<dt><u>Function:</u> <b>bfhzeta</b><i> (<var>s</var>, <var>h</var>, <var>n</var>)</i>
 
223
<a name="IDX1049"></a>
 
224
</dt>
 
225
<dd><p>Returns the Hurwitz zeta function for the arguments <var>s</var> and <var>h</var>.
 
226
The return value is a big float (bfloat);
 
227
<var>n</var> is the number of digits in the return value.
 
228
</p>
 
229
<p>The Hurwitz zeta function is defined as
 
230
</p>
 
231
<table><tr><td>&nbsp;</td><td><pre class="example">sum ((k+h)^-s, k, 0, inf)
 
232
</pre></td></tr></table>
 
233
<p><code>load (&quot;bffac&quot;)</code> loads this function.
 
234
</p>
 
235
</dd></dl>
 
236
 
 
237
<dl>
 
238
<dt><u>Function:</u> <b>binomial</b><i> (<var>x</var>, <var>y</var>)</i>
 
239
<a name="IDX1050"></a>
 
240
</dt>
 
241
<dd><p>The binomial coefficient <code><var>x</var>!/(<var>y</var>! (<var>x</var> - <var>y</var>)!)</code>.
 
242
If <var>x</var> and <var>y</var> are integers, then the numerical value of the binomial
 
243
coefficient is computed.
 
244
If <var>y</var>, or <var>x - y</var>, is an integer,
 
245
the binomial coefficient is expressed as a polynomial.
 
246
</p>
 
247
<p>Examples:
 
248
</p>
 
249
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) binomial (11, 7);
 
250
(%o1)                          330
 
251
(%i2) 11! / 7! / (11 - 7)!;
 
252
(%o2)                          330
 
253
(%i3) binomial (x, 7);
 
254
        (x - 6) (x - 5) (x - 4) (x - 3) (x - 2) (x - 1) x
 
255
(%o3)   -------------------------------------------------
 
256
                              5040
 
257
(%i4) binomial (x + 7, x);
 
258
      (x + 1) (x + 2) (x + 3) (x + 4) (x + 5) (x + 6) (x + 7)
 
259
(%o4) -------------------------------------------------------
 
260
                               5040
 
261
(%i5) binomial (11, y);
 
262
(%o5)                    binomial(11, y)
 
263
</pre></td></tr></table>
 
264
</dd></dl>
 
265
 
 
266
<dl>
 
267
<dt><u>Function:</u> <b>burn</b><i> (<var>n</var>)</i>
 
268
<a name="IDX1051"></a>
 
269
</dt>
 
270
<dd><p>Returns the <var>n</var>'th Bernoulli number for integer <var>n</var>.
 
271
<code>burn</code> may be more efficient than <code>bern</code> for large, isolated <var>n</var>
 
272
(perhaps <var>n</var> greater than 105 or so), as <code>bern</code> computes all the Bernoulli numbers up to index <var>n</var> before returning.
 
273
</p>
 
274
 
 
275
<p><code>burn</code> exploits the observation that (rational) Bernoulli numbers can be
 
276
approximated by (transcendental) zetas with tolerable efficiency.
 
277
</p>
 
278
<p><code>load (&quot;bffac&quot;)</code> loads this function.
 
279
</p>
 
280
</dd></dl>
 
281
 
 
282
<dl>
 
283
<dt><u>Function:</u> <b>cf</b><i> (<var>expr</var>)</i>
 
284
<a name="IDX1052"></a>
 
285
</dt>
 
286
<dd><p>Converts <var>expr</var> into a continued fraction.
 
287
<var>expr</var> is an expression
 
288
comprising continued fractions and square roots of integers.
 
289
Operands in the expression may be combined with arithmetic operators.
 
290
Aside from continued fractions and square roots,
 
291
factors in the expression must be integer or rational numbers.
 
292
Maxima does not know about operations on continued fractions outside of <code>cf</code>.
 
293
</p>
 
294
<p><code>cf</code> evaluates its arguments after binding <code>listarith</code> to <code>false</code>.
 
295
<code>cf</code> returns a continued fraction, represented as a list.
 
296
</p>
 
297
<p>A continued fraction <code>a + 1/(b + 1/(c + ...))</code>
 
298
is represented by the list <code>[a, b, c, ...]</code>.
 
299
The list elements <code>a</code>, <code>b</code>, <code>c</code>, ... must evaluate to integers.
 
300
<var>expr</var> may also contain <code>sqrt (n)</code> where <code>n</code> is an integer.
 
301
In this case <code>cf</code> will give as many
 
302
terms of the continued fraction as the value of the variable
 
303
<code>cflength</code> times the period.
 
304
</p>
 
305
<p>A continued fraction can be evaluated to a number
 
306
by evaluating the arithmetic representation
 
307
returned by <code>cfdisrep</code>.
 
308
See also <code>cfexpand</code> for another way to evaluate a continued fraction.
 
309
</p>
 
310
<p>See also <code>cfdisrep</code>, <code>cfexpand</code>, and <code>cflength</code>.
 
311
</p>
 
312
<p>Examples:
 
313
</p>
 
314
<ul>
 
315
<li>
 
316
<var>expr</var> is an expression comprising continued fractions and square roots of integers.
 
317
 
 
318
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) cf ([5, 3, 1]*[11, 9, 7] + [3, 7]/[4, 3, 2]);
 
319
(%o1)               [59, 17, 2, 1, 1, 1, 27]
 
320
(%i2) cf ((3/17)*[1, -2, 5]/sqrt(11) + (8/13));
 
321
(%o2)        [0, 1, 1, 1, 3, 2, 1, 4, 1, 9, 1, 9, 2]
 
322
</pre></td></tr></table>
 
323
</li><li>
 
324
<code>cflength</code> controls how many periods of the continued fraction
 
325
are computed for algebraic, irrational numbers.
 
326
 
 
327
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) cflength: 1$
 
328
(%i2) cf ((1 + sqrt(5))/2);
 
329
(%o2)                    [1, 1, 1, 1, 2]
 
330
(%i3) cflength: 2$
 
331
(%i4) cf ((1 + sqrt(5))/2);
 
332
(%o4)               [1, 1, 1, 1, 1, 1, 1, 2]
 
333
(%i5) cflength: 3$
 
334
(%i6) cf ((1 + sqrt(5))/2);
 
335
(%o6)           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
 
336
</pre></td></tr></table>
 
337
</li><li>
 
338
A continued fraction can be evaluated by evaluating the arithmetic representation
 
339
returned by <code>cfdisrep</code>.
 
340
 
 
341
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) cflength: 3$
 
342
(%i2) cfdisrep (cf (sqrt (3)))$
 
343
(%i3) ev (%, numer);
 
344
(%o3)                   1.731707317073171
 
345
</pre></td></tr></table>
 
346
</li><li>
 
347
Maxima does not know about operations on continued fractions outside of <code>cf</code>.
 
348
 
 
349
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) cf ([1,1,1,1,1,2] * 3);
 
350
(%o1)                     [4, 1, 5, 2]
 
351
(%i2) cf ([1,1,1,1,1,2]) * 3;
 
352
(%o2)                  [3, 3, 3, 3, 3, 6]
 
353
</pre></td></tr></table>
 
354
</li></ul>
 
355
</dd></dl>
 
356
 
 
357
<dl>
 
358
<dt><u>Function:</u> <b>cfdisrep</b><i> (<var>list</var>)</i>
 
359
<a name="IDX1053"></a>
 
360
</dt>
 
361
<dd><p>Constructs and returns an ordinary arithmetic expression
 
362
of the form <code>a + 1/(b + 1/(c + ...))</code>
 
363
from the list representation of a continued fraction <code>[a, b, c, ...]</code>.
 
364
</p>
 
365
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) cf ([1, 2, -3] + [1, -2, 1]);
 
366
(%o1)                     [1, 1, 1, 2]
 
367
(%i2) cfdisrep (%);
 
368
                                  1
 
369
(%o2)                     1 + ---------
 
370
                                    1
 
371
                              1 + -----
 
372
                                      1
 
373
                                  1 + -
 
374
                                      2
 
375
</pre></td></tr></table>
 
376
</dd></dl>
 
377
 
 
378
<dl>
 
379
<dt><u>Function:</u> <b>cfexpand</b><i> (<var>x</var>)</i>
 
380
<a name="IDX1054"></a>
 
381
</dt>
 
382
<dd><p>Returns a matrix of the numerators and denominators of the
 
383
last (column 1) and next-to-last (column 2) convergents of the continued fraction <var>x</var>.
 
384
</p>
 
385
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) cf (rat (ev (%pi, numer)));
 
386
 
 
387
`rat' replaced 3.141592653589793 by 103993//33102 = 3.141592653011902
 
388
(%o1)                  [3, 7, 15, 1, 292]
 
389
(%i2) cfexpand (%); 
 
390
                         [ 103993  355 ]
 
391
(%o2)                    [             ]
 
392
                         [ 33102   113 ]
 
393
(%i3) %[1,1]/%[2,1], numer;
 
394
(%o3)                   3.141592653011902
 
395
</pre></td></tr></table>
 
396
</dd></dl>
 
397
 
 
398
<dl>
 
399
<dt><u>Option variable:</u> <b>cflength</b>
 
400
<a name="IDX1055"></a>
 
401
</dt>
 
402
<dd><p>Default value: 1
 
403
</p>
 
404
<p><code>cflength</code> controls the number of terms of the continued
 
405
fraction the function <code>cf</code> will give, as the value <code>cflength</code> times the
 
406
period.  Thus the default is to give one period.
 
407
</p>
 
408
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) cflength: 1$
 
409
(%i2) cf ((1 + sqrt(5))/2);
 
410
(%o2)                    [1, 1, 1, 1, 2]
 
411
(%i3) cflength: 2$
 
412
(%i4) cf ((1 + sqrt(5))/2);
 
413
(%o4)               [1, 1, 1, 1, 1, 1, 1, 2]
 
414
(%i5) cflength: 3$
 
415
(%i6) cf ((1 + sqrt(5))/2);
 
416
(%o6)           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
 
417
</pre></td></tr></table>
 
418
</dd></dl>
 
419
 
 
420
<dl>
 
421
<dt><u>Function:</u> <b>divsum</b><i> (<var>n</var>, <var>k</var>)</i>
 
422
<a name="IDX1056"></a>
 
423
</dt>
 
424
<dt><u>Function:</u> <b>divsum</b><i> (<var>n</var>)</i>
 
425
<a name="IDX1057"></a>
 
426
</dt>
 
427
<dd><p><code>divsum (<var>n</var>, <var>k</var>)</code> returns the sum of the divisors of <var>n</var>
 
428
raised to the <var>k</var>'th power.
 
429
</p>
 
430
<p><code>divsum (<var>n</var>)</code> returns the sum of the divisors of <var>n</var>.
 
431
</p>
 
432
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) divsum (12);
 
433
(%o1)                          28
 
434
(%i2) 1 + 2 + 3 + 4 + 6 + 12;
 
435
(%o2)                          28
 
436
(%i3) divsum (12, 2);
 
437
(%o3)                          210
 
438
(%i4) 1^2 + 2^2 + 3^2 + 4^2 + 6^2 + 12^2;
 
439
(%o4)                          210
 
440
</pre></td></tr></table>
 
441
</dd></dl>
 
442
 
 
443
<dl>
 
444
<dt><u>Function:</u> <b>euler</b><i> (<var>n</var>)</i>
 
445
<a name="IDX1058"></a>
 
446
</dt>
 
447
<dd><p>Returns the <var>n</var>'th Euler number for nonnegative integer <var>n</var>.
 
448
</p>
 
449
<p>For the Euler-Mascheroni constant, see <code>%gamma</code>.
 
450
</p>
 
451
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) map (euler, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
 
452
(%o1)    [1, 0, - 1, 0, 5, 0, - 61, 0, 1385, 0, - 50521]
 
453
</pre></td></tr></table>
 
454
</dd></dl>
 
455
 
 
456
<dl>
 
457
<dt><u>Constant:</u> <b>%gamma</b>
 
458
<a name="IDX1059"></a>
 
459
</dt>
 
460
<dd><p>The Euler-Mascheroni constant, 0.5772156649015329 ....
 
461
</p>
 
462
</dd></dl>
 
463
 
 
464
<dl>
 
465
<dt><u>Function:</u> <b>factorial</b><i> (<var>x</var>)</i>
 
466
<a name="IDX1060"></a>
 
467
</dt>
 
468
<dd><p>Represents the factorial function. Maxima treats <code>factorial (<var>x</var>)</code> the same as <code><var>x</var>!</code>.
 
469
See <code>!</code>.
 
470
</p>
 
471
</dd></dl>
 
472
 
 
473
<dl>
 
474
<dt><u>Function:</u> <b>fib</b><i> (<var>n</var>)</i>
 
475
<a name="IDX1061"></a>
 
476
</dt>
 
477
<dd><p>Returns the <var>n</var>'th Fibonacci number.
 
478
<code>fib(0)</code> equal to 0 and <code>fib(1)</code> equal to 1,
 
479
and
 
480
<code>fib (-<var>n</var>)</code> equal to <code>(-1)^(<var>n</var> + 1) * fib(<var>n</var>)</code>.
 
481
</p>
 
482
<p>After calling <code>fib</code>,
 
483
<code>prevfib</code> is equal to <code>fib (<var>x</var> - 1)</code>,
 
484
the Fibonacci number preceding the last one computed.
 
485
</p>
 
486
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) map (fib, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
 
487
(%o1)         [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
 
488
</pre></td></tr></table>
 
489
</dd></dl>
 
490
 
 
491
<dl>
 
492
<dt><u>Function:</u> <b>fibtophi</b><i> (<var>expr</var>)</i>
 
493
<a name="IDX1062"></a>
 
494
</dt>
 
495
<dd><p>Expresses Fibonacci numbers in terms of the constant <code>%phi</code>,
 
496
which is <code>(1 + sqrt(5))/2</code>, approximately 1.61803399.
 
497
</p>
 
498
<p>By default, Maxima does not know about <code>%phi</code>.
 
499
After executing <code>tellrat (%phi^2 - %phi - 1)</code> and <code>algebraic: true</code>,
 
500
<code>ratsimp</code> can simplify some expressions containing <code>%phi</code>.
 
501
</p>
 
502
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) fibtophi (fib (n));
 
503
                           n             n
 
504
                       %phi  - (1 - %phi)
 
505
(%o1)                  -------------------
 
506
                           2 %phi - 1
 
507
(%i2) fib (n-1) + fib (n) - fib (n+1);
 
508
(%o2)          - fib(n + 1) + fib(n) + fib(n - 1)
 
509
(%i3) ratsimp (fibtophi (%));
 
510
(%o3)                           0
 
511
</pre></td></tr></table>
 
512
</dd></dl>
 
513
 
 
514
<dl>
 
515
<dt><u>Function:</u> <b>ifactors</b><i> (<var>n</var>)</i>
 
516
<a name="IDX1063"></a>
 
517
</dt>
 
518
<dd><p>For a positive integer <var>n</var> returns the factorization of <var>n</var>. If
 
519
<code>n=p1^e1..pk^nk</code> is the decomposition of <var>n</var> into prime
 
520
factors, ifactors returns <code>[[p1, e1], ... , [pk, ek]]</code>.
 
521
</p>
 
522
<p>Factorization methods used are trial divisions by primes up to 9973,
 
523
Pollard's rho method and elliptic curve method.
 
524
</p>
 
525
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) ifactors(51575319651600);
 
526
(%o1)     [[2, 4], [3, 2], [5, 2], [1583, 1], [9050207, 1]]
 
527
(%i2) apply(&quot;*&quot;, map(lambda([u], u[1]^u[2]), %));
 
528
(%o2)                        51575319651600
 
529
</pre></td></tr></table>
 
530
</dd></dl>
 
531
 
 
532
<dl>
 
533
<dt><u>Function:</u> <b>inrt</b><i> (<var>x</var>, <var>n</var>)</i>
 
534
<a name="IDX1064"></a>
 
535
</dt>
 
536
<dd><p>Returns the integer <var>n</var>'th root of the absolute value of <var>x</var>.
 
537
</p>
 
538
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) l: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]$
 
539
(%i2) map (lambda ([a], inrt (10^a, 3)), l);
 
540
(%o2) [2, 4, 10, 21, 46, 100, 215, 464, 1000, 2154, 4641, 10000]
 
541
</pre></td></tr></table>
 
542
</dd></dl>
 
543
 
 
544
<dl>
 
545
<dt><u>Function:</u> <b>inv_mod</b><i> (<var>n</var>, <var>m</var>)</i>
 
546
<a name="IDX1065"></a>
 
547
</dt>
 
548
<dd><p>Computes the inverse of <var>n</var> modulo <var>m</var>. 
 
549
<code>inv_mod (n,m)</code> returns <code>false</code>, 
 
550
if <var>n</var> is a zero divisor modulo <var>m</var>.
 
551
</p>
 
552
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) inv_mod(3, 41);
 
553
(%o1)                           14
 
554
(%i2) ratsimp(3^-1), modulus=41;
 
555
(%o2)                           14
 
556
(%i3) inv_mod(3, 42);
 
557
(%o3)                          false
 
558
</pre></td></tr></table>
 
559
</dd></dl>
 
560
 
 
561
<dl>
 
562
<dt><u>Function:</u> <b>jacobi</b><i> (<var>p</var>, <var>q</var>)</i>
 
563
<a name="IDX1066"></a>
 
564
</dt>
 
565
<dd><p>Returns the Jacobi symbol of <var>p</var> and <var>q</var>.
 
566
</p>
 
567
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) l: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]$
 
568
(%i2) map (lambda ([a], jacobi (a, 9)), l);
 
569
(%o2)         [1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0]
 
570
</pre></td></tr></table>
 
571
</dd></dl>
 
572
 
 
573
<dl>
 
574
<dt><u>Function:</u> <b>lcm</b><i> (<var>expr_1</var>, ..., <var>expr_n</var>)</i>
 
575
<a name="IDX1067"></a>
 
576
</dt>
 
577
<dd><p>Returns the least common multiple of its arguments.
 
578
The arguments may be general expressions as well as integers.
 
579
</p>
 
580
<p><code>load (&quot;functs&quot;)</code> loads this function.
 
581
</p>
 
582
</dd></dl>
 
583
 
 
584
<dl>
 
585
<dt><u>Function:</u> <b>minfactorial</b><i> (<var>expr</var>)</i>
 
586
<a name="IDX1068"></a>
 
587
</dt>
 
588
<dd><p>Examines <var>expr</var> for occurrences of two factorials
 
589
which differ by an integer.
 
590
<code>minfactorial</code> then turns one into a polynomial times the other.
 
591
</p>
 
592
 
 
593
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) n!/(n+2)!;
 
594
                               n!
 
595
(%o1)                       --------
 
596
                            (n + 2)!
 
597
(%i2) minfactorial (%);
 
598
                                1
 
599
(%o2)                    ---------------
 
600
                         (n + 1) (n + 2)
 
601
</pre></td></tr></table>
 
602
</dd></dl>
 
603
 
 
604
<dl>
 
605
<dt><u>Function:</u> <b>power_mod</b><i> (<var>a</var>, <var>n</var>, <var>m</var>)</i>
 
606
<a name="IDX1069"></a>
 
607
</dt>
 
608
<dd><p>Uses a modular algorithm to compute <code>a^n mod m</code> 
 
609
where <var>a</var> and <var>n</var> are integers and <var>m</var> is a positive integer. 
 
610
If <var>n</var> is negative, <code>inv_mod</code> is used to find the modular inverse.
 
611
</p>
 
612
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) power_mod(3, 15, 5);
 
613
(%o1)                          2
 
614
(%i2) mod(3^15,5);
 
615
(%o2)                          2
 
616
(%i3) power_mod(2, -1, 5);
 
617
(%o3)                          3
 
618
(%i4) inv_mod(2,5);
 
619
(%o4)                          3
 
620
</pre></td></tr></table>
 
621
</dd></dl>
 
622
 
 
623
<dl>
 
624
<dt><u>Function:</u> <b>next_prime</b><i> (<var>n</var>)</i>
 
625
<a name="IDX1070"></a>
 
626
</dt>
 
627
<dd><p>Returns the smallest prime bigger than <var>n</var>.
 
628
</p>
 
629
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) next_prime(27);
 
630
(%o1)                       29
 
631
</pre></td></tr></table>
 
632
</dd></dl>
 
633
 
 
634
<dl>
 
635
<dt><u>Function:</u> <b>partfrac</b><i> (<var>expr</var>, <var>var</var>)</i>
 
636
<a name="IDX1071"></a>
 
637
</dt>
 
638
<dd><p>Expands the expression <var>expr</var> in partial fractions
 
639
with respect to the main variable <var>var</var>.  <code>partfrac</code> does a complete
 
640
partial fraction decomposition.  The algorithm employed is based on
 
641
the fact that the denominators of the partial fraction expansion (the
 
642
factors of the original denominator) are relatively prime.  The
 
643
numerators can be written as linear combinations of denominators, and
 
644
the expansion falls out.
 
645
</p>
 
646
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) 1/(1+x)^2 - 2/(1+x) + 2/(2+x);
 
647
                      2       2        1
 
648
(%o1)               ----- - ----- + --------
 
649
                    x + 2   x + 1          2
 
650
                                    (x + 1)
 
651
(%i2) ratsimp (%);
 
652
                                 x
 
653
(%o2)                 - -------------------
 
654
                         3      2
 
655
                        x  + 4 x  + 5 x + 2
 
656
(%i3) partfrac (%, x);
 
657
                      2       2        1
 
658
(%o3)               ----- - ----- + --------
 
659
                    x + 2   x + 1          2
 
660
                                    (x + 1)
 
661
</pre></td></tr></table></dd></dl>
 
662
 
 
663
<dl>
 
664
<dt><u>Function:</u> <b>primep</b><i> (<var>n</var>)</i>
 
665
<a name="IDX1072"></a>
 
666
</dt>
 
667
<dd><p>Primality test. If <code>primep (n)</code> returns <code>false</code>, <var>n</var> is a
 
668
composite number and if it returns <code>true</code>, <var>n</var> is a prime number
 
669
with very high probability.
 
670
</p>
 
671
<p>For <var>n</var> less than 341550071728321 a deterministic version of Miller-Rabin's
 
672
test is used. If <code>primep (n)</code> returns <code>true</code>, then <var>n</var> is a
 
673
prime number.
 
674
</p>
 
675
<p>For <var>n</var> bigger than 34155071728321 <code>primep</code> uses
 
676
<code>primep_number_of_tests</code> Miller-Rabin's pseudo-primality tests
 
677
and one Lucas pseudo-primality test. The probability that <var>n</var> will
 
678
pass one Miller-Rabin test is less than 1/4. Using the default value 25 for
 
679
<code>primep_number_of_tests</code>, the probability of <var>n</var> beeing
 
680
composite is much smaller that 10^-15.
 
681
</p>
 
682
</dd></dl>
 
683
 
 
684
<dl>
 
685
<dt><u>Option variable:</u> <b>primep_number_of_tests</b>
 
686
<a name="IDX1073"></a>
 
687
</dt>
 
688
<dd><p>Default value: 25
 
689
</p>
 
690
<p>Number of Miller-Rabin's tests used in <code>primep</code>.
 
691
</p></dd></dl>
 
692
 
 
693
<dl>
 
694
<dt><u>Function:</u> <b>prev_prime</b><i> (<var>n</var>)</i>
 
695
<a name="IDX1074"></a>
 
696
</dt>
 
697
<dd><p>Returns the greatest prime smaller than <var>n</var>.
 
698
</p>
 
699
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) prev_prime(27);
 
700
(%o1)                       23
 
701
</pre></td></tr></table></dd></dl>
 
702
 
 
703
<dl>
 
704
<dt><u>Function:</u> <b>qunit</b><i> (<var>n</var>)</i>
 
705
<a name="IDX1075"></a>
 
706
</dt>
 
707
<dd><p>Returns the principal unit of the real quadratic number field
 
708
<code>sqrt (<var>n</var>)</code> where <var>n</var> is an integer,
 
709
i.e., the element whose norm is unity.
 
710
This amounts to solving Pell's equation <code>a^2 - <var>n</var> b^2 = 1</code>.
 
711
</p>
 
712
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) qunit (17);
 
713
(%o1)                     sqrt(17) + 4
 
714
(%i2) expand (% * (sqrt(17) - 4));
 
715
(%o2)                           1
 
716
</pre></td></tr></table>
 
717
</dd></dl>
 
718
 
 
719
<dl>
 
720
<dt><u>Function:</u> <b>totient</b><i> (<var>n</var>)</i>
 
721
<a name="IDX1076"></a>
 
722
</dt>
 
723
<dd><p>Returns the number of integers less than or equal to <var>n</var> which
 
724
are relatively prime to <var>n</var>.
 
725
</p>
 
726
</dd></dl>
 
727
 
 
728
<dl>
 
729
<dt><u>Option variable:</u> <b>zerobern</b>
 
730
<a name="IDX1077"></a>
 
731
</dt>
 
732
<dd><p>Default value: <code>true</code>
 
733
</p>
 
734
<p>When <code>zerobern</code> is <code>false</code>,
 
735
<code>bern</code> excludes the Bernoulli numbers which are equal to zero. 
 
736
See <code>bern</code>.
 
737
</p>
 
738
</dd></dl>
 
739
 
 
740
<dl>
 
741
<dt><u>Function:</u> <b>zeta</b><i> (<var>n</var>)</i>
 
742
<a name="IDX1078"></a>
 
743
</dt>
 
744
<dd><p>Returns the Riemann zeta function if <var>x</var> is a negative integer, 0, 1,
 
745
or a positive even number,
 
746
and returns a noun form <code>zeta (<var>n</var>)</code> for all other arguments,
 
747
including rational noninteger, floating point, and complex arguments.
 
748
</p>
 
749
<p>See also <code>bfzeta</code> and <code>zeta%pi</code>.
 
750
</p>
 
751
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) map (zeta, [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]);
 
752
                                     2              4
 
753
           1        1     1       %pi            %pi
 
754
(%o1) [0, ---, 0, - --, - -, inf, ----, zeta(3), ----, zeta(5)]
 
755
          120       12    2        6              90
 
756
</pre></td></tr></table>
 
757
</dd></dl>
 
758
 
 
759
<dl>
 
760
<dt><u>Option variable:</u> <b>zeta%pi</b>
 
761
<a name="IDX1079"></a>
 
762
</dt>
 
763
<dd><p>Default value: <code>true</code>
 
764
</p>
 
765
<p>When <code>zeta%pi</code> is <code>true</code>, <code>zeta</code> returns an expression
 
766
proportional to <code>%pi^n</code> for even integer <code>n</code>.
 
767
Otherwise, <code>zeta</code> returns a noun form <code>zeta (n)</code>
 
768
for even integer <code>n</code>.
 
769
</p>
 
770
<table><tr><td>&nbsp;</td><td><pre class="example">(%i1) zeta%pi: true$
 
771
(%i2) zeta (4);
 
772
                                 4
 
773
                              %pi
 
774
(%o2)                         ----
 
775
                               90
 
776
(%i3) zeta%pi: false$
 
777
(%i4) zeta (4);
 
778
(%o4)                        zeta(4)
 
779
</pre></td></tr></table>
 
780
</dd></dl>
 
781
 
 
782
<hr size="6">
 
783
<table cellpadding="1" cellspacing="1" border="0">
 
784
<tr><td valign="middle" align="left">[<a href="#SEC128" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
 
785
<td valign="middle" align="left">[<a href="maxima_33.html#SEC130" title="Next chapter"> &gt;&gt; </a>]</td>
 
786
<td valign="middle" align="left"> &nbsp; </td>
 
787
<td valign="middle" align="left"> &nbsp; </td>
 
788
<td valign="middle" align="left"> &nbsp; </td>
 
789
<td valign="middle" align="left"> &nbsp; </td>
 
790
<td valign="middle" align="left"> &nbsp; </td>
 
791
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
 
792
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
 
793
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
 
794
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
 
795
</tr></table>
 
796
<p>
 
797
 <font size="-1">
 
798
  This document was generated by <em>Robert Dodier</em> on <em>September, 20 2006</em> using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.
 
799
 </font>
 
800
 <br>
 
801
 
 
802
</p>
 
803
</body>
 
804
</html>