File: maxima_31.html

package info (click to toggle)
maxima 5.21.1-2squeeze
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 94,928 kB
  • ctags: 43,849
  • sloc: lisp: 298,974; fortran: 14,666; perl: 14,325; tcl: 10,494; sh: 4,052; makefile: 2,975; ansic: 471; awk: 24; sed: 7
file content (1139 lines) | stat: -rw-r--r-- 35,787 bytes parent folder | download
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on April, 24 2010 by texi2html 1.76 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people <dev@texi2html.cvshome.org>
Send bugs and suggestions to <users@texi2html.cvshome.org>

-->
<head>
<title>Maxima 5.21.1 Manual: 31. Number Theory</title>

<meta name="description" content="Maxima 5.21.1 Manual: 31. Number Theory">
<meta name="keywords" content="Maxima 5.21.1 Manual: 31. Number Theory">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.76">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
body
{
    color: black;
    background: white; 
    margin-left: 8%;
    margin-right: 13%;
}

h1
{
    margin-left: +8%;
    font-size: 150%;
    font-family: sans-serif
}

h2
{
    font-size: 125%;
    font-family: sans-serif
}

h3
{
    font-size: 100%;
    font-family: sans-serif
}

h2,h3,h4,h5,h6 { margin-left: +4%; }

div.textbox
{
    border: solid;
    border-width: thin;
    /* width: 100%; */
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 2em;
    padding-right: 2em
}

div.titlebox
{
    border: none;
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 2em;
    padding-right: 2em;
    background: rgb(200,255,255);
    font-family: sans-serif
}

div.synopsisbox
{
    border: none;
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 2em;
    padding-right: 2em;
     background: rgb(255,220,255);
    /*background: rgb(200,255,255); */
    /* font-family: fixed */
}

pre.example
{
    border: 1px solid gray;
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 1em;
    padding-right: 1em;
    /* background: rgb(247,242,180); */ /* kind of sandy */
    /* background: rgb(200,255,255); */ /* sky blue */
    background-color: #F1F5F9; /* light blue-gray */
    /* font-family: "Lucida Console", monospace */
}

div.spacerbox
{
    border: none;
    padding-top: 2em;
    padding-bottom: 2em
}

div.image
{
    margin: 0;
    padding: 1em;
    text-align: center;
}

div.categorybox
{
    border: 1px solid gray;
    padding-top: 0px;
    padding-bottom: 0px;
    padding-left: 1em;
    padding-right: 1em;
    background: rgb(247,242,220);
}


-->
</style>

<link rel="icon" href="http://maxima.sourceforge.net/favicon.ico"/>
</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="Number-Theory"></a>
<a name="SEC138"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="maxima_30.html#SEC137" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC139" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima_30.html#SEC134" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_32.html#SEC140" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_79.html#SEC331" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h1 class="chapter"> 31. Number Theory </h1>


<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#SEC139">31.1 Functions and Variables for Number Theory</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">  
</td></tr>
</table>

<p><a name="Item_003a-Functions-and-Variables-for-Number-Theory"></a>
</p><hr size="6">
<a name="Functions-and-Variables-for-Number-Theory"></a>
<a name="SEC139"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC138" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="maxima_32.html#SEC140" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC138" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC138" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_32.html#SEC140" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_79.html#SEC331" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 31.1 Functions and Variables for Number Theory </h2>

<p><a name="Item_003a-bern"></a>
</p><dl>
<dt><u>Function:</u> <b>bern</b><i> (<var>n</var>)</i>
<a name="IDX1148"></a>
</dt>
<dd><p>Returns the <var>n</var>'th Bernoulli number for integer <var>n</var>.
Bernoulli numbers equal to zero are suppressed if <code>zerobern</code> is <code>false</code>.
</p>
<p>See also <code>burn</code>.
</p>
<pre class="example">(%i1) zerobern: true$
(%i2) map (bern, [0, 1, 2, 3, 4, 5, 6, 7, 8]);
                  1  1       1      1        1
(%o2)       [1, - -, -, 0, - --, 0, --, 0, - --]
                  2  6       30     42       30
(%i3) zerobern: false$
(%i4) map (bern, [0, 1, 2, 3, 4, 5, 6, 7, 8]);
            1  1    1   5     691   7    3617  43867
(%o4) [1, - -, -, - --, --, - ----, -, - ----, -----]
            2  6    30  66    2730  6    510    798
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-bernpoly"></a>
</p><dl>
<dt><u>Function:</u> <b>bernpoly</b><i> (<var>x</var>, <var>n</var>)</i>
<a name="IDX1149"></a>
</dt>
<dd><p>Returns the <var>n</var>'th Bernoulli polynomial in the
variable <var>x</var>.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-bfzeta"></a>
</p><dl>
<dt><u>Function:</u> <b>bfzeta</b><i> (<var>s</var>, <var>n</var>)</i>
<a name="IDX1150"></a>
</dt>
<dd><p>Returns the Riemann zeta function for the argument <var>s</var>.
The return value is a big float (bfloat);
<var>n</var> is the number of digits in the return value.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
 &middot;
<a href="maxima_95.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-bfhzeta"></a>
</p><dl>
<dt><u>Function:</u> <b>bfhzeta</b><i> (<var>s</var>, <var>h</var>, <var>n</var>)</i>
<a name="IDX1151"></a>
</dt>
<dd><p>Returns the Hurwitz zeta function for the arguments <var>s</var> and <var>h</var>.
The return value is a big float (bfloat);
<var>n</var> is the number of digits in the return value.
</p>
<p>The Hurwitz zeta function is defined as
</p>
<pre class="example">                        inf
                        ====
                        \        1
         zeta (s,h)  =   &gt;    --------
                        /            s
                        ====  (k + h)
                        k = 0
</pre>
<p><code>load (&quot;bffac&quot;)</code> loads this function.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
 &middot;
<a href="maxima_95.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-binomial"></a>
</p><dl>
<dt><u>Function:</u> <b>binomial</b><i> (<var>x</var>, <var>y</var>)</i>
<a name="IDX1152"></a>
</dt>
<dd><p>The binomial coefficient <code><var>x</var>!/(<var>y</var>! (<var>x</var> - <var>y</var>)!)</code>.
If <var>x</var> and <var>y</var> are integers, then the numerical value of the binomial
coefficient is computed.
If <var>y</var>, or <var>x - y</var>, is an integer,
the binomial coefficient is expressed as a polynomial.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) binomial (11, 7);
(%o1)                          330
(%i2) 11! / 7! / (11 - 7)!;
(%o2)                          330
(%i3) binomial (x, 7);
        (x - 6) (x - 5) (x - 4) (x - 3) (x - 2) (x - 1) x
(%o3)   -------------------------------------------------
                              5040
(%i4) binomial (x + 7, x);
      (x + 1) (x + 2) (x + 3) (x + 4) (x + 5) (x + 6) (x + 7)
(%o4) -------------------------------------------------------
                               5040
(%i5) binomial (11, y);
(%o5)                    binomial(11, y)
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-burn"></a>
</p><dl>
<dt><u>Function:</u> <b>burn</b><i> (<var>n</var>)</i>
<a name="IDX1153"></a>
</dt>
<dd><p>Returns the <var>n</var>'th Bernoulli number for integer <var>n</var>.
<code>burn</code> may be more efficient than <code>bern</code> for large, isolated <var>n</var>
(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.
</p>

<p><code>burn</code> exploits the observation that (rational) Bernoulli numbers can be
approximated by (transcendental) zetas with tolerable efficiency.
</p>
<p><code>load (&quot;bffac&quot;)</code> loads this function.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-cf"></a>
</p><dl>
<dt><u>Function:</u> <b>cf</b><i> (<var>expr</var>)</i>
<a name="IDX1154"></a>
</dt>
<dd><p>Converts <var>expr</var> into a continued fraction.
<var>expr</var> is an expression
comprising continued fractions and square roots of integers.
Operands in the expression may be combined with arithmetic operators.
Aside from continued fractions and square roots,
factors in the expression must be integer or rational numbers.
Maxima does not know about operations on continued fractions outside of <code>cf</code>.
</p>
<p><code>cf</code> evaluates its arguments after binding <code>listarith</code> to <code>false</code>.
<code>cf</code> returns a continued fraction, represented as a list.
</p>
<p>A continued fraction <code>a + 1/(b + 1/(c + ...))</code>
is represented by the list <code>[a, b, c, ...]</code>.
The list elements <code>a</code>, <code>b</code>, <code>c</code>, ... must evaluate to integers.
<var>expr</var> may also contain <code>sqrt (n)</code> where <code>n</code> is an integer.
In this case <code>cf</code> will give as many
terms of the continued fraction as the value of the variable
<code>cflength</code> times the period.
</p>
<p>A continued fraction can be evaluated to a number
by evaluating the arithmetic representation
returned by <code>cfdisrep</code>.
See also <code>cfexpand</code> for another way to evaluate a continued fraction.
</p>
<p>See also <code>cfdisrep</code>, <code>cfexpand</code>, and <code>cflength</code>.
</p>
<p>Examples:
</p>
<ul>
<li>
<var>expr</var> is an expression comprising continued fractions and square roots of integers.

<pre class="example">(%i1) cf ([5, 3, 1]*[11, 9, 7] + [3, 7]/[4, 3, 2]);
(%o1)               [59, 17, 2, 1, 1, 1, 27]
(%i2) cf ((3/17)*[1, -2, 5]/sqrt(11) + (8/13));
(%o2)        [0, 1, 1, 1, 3, 2, 1, 4, 1, 9, 1, 9, 2]
</pre>
</li><li>
<code>cflength</code> controls how many periods of the continued fraction
are computed for algebraic, irrational numbers.

<pre class="example">(%i1) cflength: 1$
(%i2) cf ((1 + sqrt(5))/2);
(%o2)                    [1, 1, 1, 1, 2]
(%i3) cflength: 2$
(%i4) cf ((1 + sqrt(5))/2);
(%o4)               [1, 1, 1, 1, 1, 1, 1, 2]
(%i5) cflength: 3$
(%i6) cf ((1 + sqrt(5))/2);
(%o6)           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
</pre>
</li><li>
A continued fraction can be evaluated by evaluating the arithmetic representation
returned by <code>cfdisrep</code>.

<pre class="example">(%i1) cflength: 3$
(%i2) cfdisrep (cf (sqrt (3)))$
(%i3) ev (%, numer);
(%o3)                   1.731707317073171
</pre>
</li><li>
Maxima does not know about operations on continued fractions outside of <code>cf</code>.

<pre class="example">(%i1) cf ([1,1,1,1,1,2] * 3);
(%o1)                     [4, 1, 5, 2]
(%i2) cf ([1,1,1,1,1,2]) * 3;
(%o2)                  [3, 3, 3, 3, 3, 6]
</pre>
</li></ul>

<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Continued-fractions">Continued fractions</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-cfdisrep"></a>
</p><dl>
<dt><u>Function:</u> <b>cfdisrep</b><i> (<var>list</var>)</i>
<a name="IDX1155"></a>
</dt>
<dd><p>Constructs and returns an ordinary arithmetic expression
of the form <code>a + 1/(b + 1/(c + ...))</code>
from the list representation of a continued fraction <code>[a, b, c, ...]</code>.
</p>
<pre class="example">(%i1) cf ([1, 2, -3] + [1, -2, 1]);
(%o1)                     [1, 1, 1, 2]
(%i2) cfdisrep (%);
                                  1
(%o2)                     1 + ---------
                                    1
                              1 + -----
                                      1
                                  1 + -
                                      2
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Continued-fractions">Continued fractions</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-cfexpand"></a>
</p><dl>
<dt><u>Function:</u> <b>cfexpand</b><i> (<var>x</var>)</i>
<a name="IDX1156"></a>
</dt>
<dd><p>Returns a matrix of the numerators and denominators of the
last (column 1) and next-to-last (column 2) convergents of the continued fraction <var>x</var>.
</p>
<pre class="example">(%i1) cf (rat (ev (%pi, numer)));

`rat' replaced 3.141592653589793 by 103993/33102 =3.141592653011902
(%o1)                  [3, 7, 15, 1, 292]
(%i2) cfexpand (%); 
                         [ 103993  355 ]
(%o2)                    [             ]
                         [ 33102   113 ]
(%i3) %[1,1]/%[2,1], numer;
(%o3)                   3.141592653011902
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Continued-fractions">Continued fractions</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-cflength"></a>
</p><dl>
<dt><u>Option variable:</u> <b>cflength</b>
<a name="IDX1157"></a>
</dt>
<dd><p>Default value: 1
</p>
<p><code>cflength</code> controls the number of terms of the continued
fraction the function <code>cf</code> will give, as the value <code>cflength</code> times the
period.  Thus the default is to give one period.
</p>
<pre class="example">(%i1) cflength: 1$
(%i2) cf ((1 + sqrt(5))/2);
(%o2)                    [1, 1, 1, 1, 2]
(%i3) cflength: 2$
(%i4) cf ((1 + sqrt(5))/2);
(%o4)               [1, 1, 1, 1, 1, 1, 1, 2]
(%i5) cflength: 3$
(%i6) cf ((1 + sqrt(5))/2);
(%o6)           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Continued-fractions">Continued fractions</a>
</p>
</div>


</dd></dl>

<p><a name="Item_003a-divsum"></a>
</p><dl>
<dt><u>Function:</u> <b>divsum</b><i> (<var>n</var>, <var>k</var>)</i>
<a name="IDX1158"></a>
</dt>
<dt><u>Function:</u> <b>divsum</b><i> (<var>n</var>)</i>
<a name="IDX1159"></a>
</dt>
<dd><p><code>divsum (<var>n</var>, <var>k</var>)</code> returns the sum of the divisors of <var>n</var>
raised to the <var>k</var>'th power.
</p>
<p><code>divsum (<var>n</var>)</code> returns the sum of the divisors of <var>n</var>.
</p>
<pre class="example">(%i1) divsum (12);
(%o1)                          28
(%i2) 1 + 2 + 3 + 4 + 6 + 12;
(%o2)                          28
(%i3) divsum (12, 2);
(%o3)                          210
(%i4) 1^2 + 2^2 + 3^2 + 4^2 + 6^2 + 12^2;
(%o4)                          210
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-euler"></a>
</p><dl>
<dt><u>Function:</u> <b>euler</b><i> (<var>n</var>)</i>
<a name="IDX1160"></a>
</dt>
<dd><p>Returns the <var>n</var>'th Euler number for nonnegative integer <var>n</var>.
</p>
<p>For the Euler-Mascheroni constant, see <code>%gamma</code>.
</p>
<pre class="example">(%i1) map (euler, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
(%o1)    [1, 0, - 1, 0, 5, 0, - 61, 0, 1385, 0, - 50521]
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-_0025gamma"></a>
</p><dl>
<dt><u>Constant:</u> <b>%gamma</b>
<a name="IDX1161"></a>
</dt>
<dd><p>The Euler-Mascheroni constant, 0.5772156649015329 ....
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Constants">Constants</a>
</p>
</div>


</dd></dl>

<p><a name="Item_003a-factorial"></a>
</p><dl>
<dt><u>Function:</u> <b>factorial</b><i> (<var>x</var>)</i>
<a name="IDX1162"></a>
</dt>
<dd><p>Represents the factorial function. Maxima treats <code>factorial (<var>x</var>)</code> the same as <code><var>x</var>!</code>.
See <code>!</code>.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Gamma-and-factorial-functions">Gamma and factorial functions</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-factorial_005fexpand"></a>
</p><dl>
<dt><u>Option variable:</u> <b>factorial_expand</b>
<a name="IDX1163"></a>
</dt>
<dd><p>Default value: false
</p>
<p>The option variable <code>factorial_expand</code> controls the simplification of 
expressions like <code>(n+1)!</code>, where <code>n</code> is an integer. 
See <code>!</code> for an example.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Gamma-and-factorial-functions">Gamma and factorial functions</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-fib"></a>
</p><dl>
<dt><u>Function:</u> <b>fib</b><i> (<var>n</var>)</i>
<a name="IDX1164"></a>
</dt>
<dd><p>Returns the <var>n</var>'th Fibonacci number.
<code>fib(0)</code> equal to 0 and <code>fib(1)</code> equal to 1,
and
<code>fib (-<var>n</var>)</code> equal to <code>(-1)^(<var>n</var> + 1) * fib(<var>n</var>)</code>.
</p>
<p>After calling <code>fib</code>,
<code>prevfib</code> is equal to <code>fib (<var>x</var> - 1)</code>,
the Fibonacci number preceding the last one computed.
</p>
<pre class="example">(%i1) map (fib, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
(%o1)         [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-fibtophi"></a>
</p><dl>
<dt><u>Function:</u> <b>fibtophi</b><i> (<var>expr</var>)</i>
<a name="IDX1165"></a>
</dt>
<dd><p>Expresses Fibonacci numbers in <var>expr</var> in terms of the constant <code>%phi</code>,
which is <code>(1 + sqrt(5))/2</code>, approximately 1.61803399.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) fibtophi (fib (n));
                           n             n
                       %phi  - (1 - %phi)
(%o1)                  -------------------
                           2 %phi - 1
(%i2) fib (n-1) + fib (n) - fib (n+1);
(%o2)          - fib(n + 1) + fib(n) + fib(n - 1)
(%i3) fibtophi (%);
            n + 1             n + 1       n             n
        %phi      - (1 - %phi)        %phi  - (1 - %phi)
(%o3) - --------------------------- + -------------------
                2 %phi - 1                2 %phi - 1
                                          n - 1             n - 1
                                      %phi      - (1 - %phi)
                                    + ---------------------------
                                              2 %phi - 1
(%i4) ratsimp (%);
(%o4)                           0
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-ifactors"></a>
</p><dl>
<dt><u>Function:</u> <b>ifactors</b><i> (<var>n</var>)</i>
<a name="IDX1166"></a>
</dt>
<dd><p>For a positive integer <var>n</var> returns the factorization of <var>n</var>. If
<code>n=p1^e1..pk^nk</code> is the decomposition of <var>n</var> into prime
factors, ifactors returns <code>[[p1, e1], ... , [pk, ek]]</code>.
</p>
<p>Factorization methods used are trial divisions by primes up to 9973,
Pollard's rho method and elliptic curve method.
</p>
<pre class="example">(%i1) ifactors(51575319651600);
(%o1)     [[2, 4], [3, 2], [5, 2], [1583, 1], [9050207, 1]]
(%i2) apply(&quot;*&quot;, map(lambda([u], u[1]^u[2]), %));
(%o2)                        51575319651600
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-inrt"></a>
</p><dl>
<dt><u>Function:</u> <b>inrt</b><i> (<var>x</var>, <var>n</var>)</i>
<a name="IDX1167"></a>
</dt>
<dd><p>Returns the integer <var>n</var>'th root of the absolute value of <var>x</var>.
</p>
<pre class="example">(%i1) l: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]$
(%i2) map (lambda ([a], inrt (10^a, 3)), l);
(%o2) [2, 4, 10, 21, 46, 100, 215, 464, 1000, 2154, 4641, 10000]
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-inv_005fmod"></a>
</p><dl>
<dt><u>Function:</u> <b>inv_mod</b><i> (<var>n</var>, <var>m</var>)</i>
<a name="IDX1168"></a>
</dt>
<dd><p>Computes the inverse of <var>n</var> modulo <var>m</var>. 
<code>inv_mod (n,m)</code> returns <code>false</code>, 
if <var>n</var> is a zero divisor modulo <var>m</var>.
</p>
<pre class="example">(%i1) inv_mod(3, 41);
(%o1)                           14
(%i2) ratsimp(3^-1), modulus=41;
(%o2)                           14
(%i3) inv_mod(3, 42);
(%o3)                          false
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-jacobi"></a>
</p><dl>
<dt><u>Function:</u> <b>jacobi</b><i> (<var>p</var>, <var>q</var>)</i>
<a name="IDX1169"></a>
</dt>
<dd><p>Returns the Jacobi symbol of <var>p</var> and <var>q</var>.
</p>
<pre class="example">(%i1) l: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]$
(%i2) map (lambda ([a], jacobi (a, 9)), l);
(%o2)         [1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0]
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-lcm"></a>
</p><dl>
<dt><u>Function:</u> <b>lcm</b><i> (<var>expr_1</var>, ..., <var>expr_n</var>)</i>
<a name="IDX1170"></a>
</dt>
<dd><p>Returns the least common multiple of its arguments.
The arguments may be general expressions as well as integers.
</p>
<p><code>load (&quot;functs&quot;)</code> loads this function.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-minfactorial"></a>
</p><dl>
<dt><u>Function:</u> <b>minfactorial</b><i> (<var>expr</var>)</i>
<a name="IDX1171"></a>
</dt>
<dd><p>Examines <var>expr</var> for occurrences of two factorials
which differ by an integer.
<code>minfactorial</code> then turns one into a polynomial times the other.
</p>

<pre class="example">(%i1) n!/(n+2)!;
                               n!
(%o1)                       --------
                            (n + 2)!
(%i2) minfactorial (%);
                                1
(%o2)                    ---------------
                         (n + 1) (n + 2)
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-next_005fprime"></a>
</p><dl>
<dt><u>Function:</u> <b>next_prime</b><i> (<var>n</var>)</i>
<a name="IDX1172"></a>
</dt>
<dd><p>Returns the smallest prime bigger than <var>n</var>.
</p>
<pre class="example">(%i1) next_prime(27);
(%o1)                       29
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-partfrac"></a>
</p><dl>
<dt><u>Function:</u> <b>partfrac</b><i> (<var>expr</var>, <var>var</var>)</i>
<a name="IDX1173"></a>
</dt>
<dd><p>Expands the expression <var>expr</var> in partial fractions
with respect to the main variable <var>var</var>.  <code>partfrac</code> does a complete
partial fraction decomposition.  The algorithm employed is based on
the fact that the denominators of the partial fraction expansion (the
factors of the original denominator) are relatively prime.  The
numerators can be written as linear combinations of denominators, and
the expansion falls out.
</p>
<pre class="example">(%i1) 1/(1+x)^2 - 2/(1+x) + 2/(2+x);
                      2       2        1
(%o1)               ----- - ----- + --------
                    x + 2   x + 1          2
                                    (x + 1)
(%i2) ratsimp (%);
                                 x
(%o2)                 - -------------------
                         3      2
                        x  + 4 x  + 5 x + 2
(%i3) partfrac (%, x);
                      2       2        1
(%o3)               ----- - ----- + --------
                    x + 2   x + 1          2
                                    (x + 1)
</pre></dd></dl>

<p><a name="Item_003a-power_005fmod"></a>
</p><dl>
<dt><u>Function:</u> <b>power_mod</b><i> (<var>a</var>, <var>n</var>, <var>m</var>)</i>
<a name="IDX1174"></a>
</dt>
<dd><p>Uses a modular algorithm to compute <code>a^n mod m</code> 
where <var>a</var> and <var>n</var> are integers and <var>m</var> is a positive integer. 
If <var>n</var> is negative, <code>inv_mod</code> is used to find the modular inverse.
</p>
<pre class="example">(%i1) power_mod(3, 15, 5);
(%o1)                          2
(%i2) mod(3^15,5);
(%o2)                          2
(%i3) power_mod(2, -1, 5);
(%o3)                          3
(%i4) inv_mod(2,5);
(%o4)                          3
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-primep"></a>
</p><dl>
<dt><u>Function:</u> <b>primep</b><i> (<var>n</var>)</i>
<a name="IDX1175"></a>
</dt>
<dd><p>Primality test. If <code>primep (<var>n</var>)</code> returns <code>false</code>, <var>n</var> is a
composite number and if it returns <code>true</code>, <var>n</var> is a prime number
with very high probability.
</p>
<p>For <var>n</var> less than 341550071728321 a deterministic version of
Miller-Rabin's test is used. If <code>primep (<var>n</var>)</code> returns
<code>true</code>, then <var>n</var> is a prime number.
</p>
<p>For <var>n</var> bigger than 341550071728321 <code>primep</code> uses
<code>primep_number_of_tests</code> Miller-Rabin's pseudo-primality tests and
one Lucas pseudo-primality test. The probability that <var>n</var> will pass
one Miller-Rabin test is less than 1/4. Using the default value 25 for
<code>primep_number_of_tests</code>, the probability of <var>n</var> beeing
composite is much smaller that 10^-15.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Predicate-functions">Predicate functions</a>
 &middot;
<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-primep_005fnumber_005fof_005ftests"></a>
</p><dl>
<dt><u>Option variable:</u> <b>primep_number_of_tests</b>
<a name="IDX1176"></a>
</dt>
<dd><p>Default value: 25
</p>
<p>Number of Miller-Rabin's tests used in <code>primep</code>.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Predicate-functions">Predicate functions</a>
 &middot;
<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>


</dd></dl>

<p><a name="Item_003a-prev_005fprime"></a>
</p><dl>
<dt><u>Function:</u> <b>prev_prime</b><i> (<var>n</var>)</i>
<a name="IDX1177"></a>
</dt>
<dd><p>Returns the greatest prime smaller than <var>n</var>.
</p>
<pre class="example">(%i1) prev_prime(27);
(%o1)                       23
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-qunit"></a>
</p><dl>
<dt><u>Function:</u> <b>qunit</b><i> (<var>n</var>)</i>
<a name="IDX1178"></a>
</dt>
<dd><p>Returns the principal unit of the real quadratic number field
<code>sqrt (<var>n</var>)</code> where <var>n</var> is an integer,
i.e., the element whose norm is unity.
This amounts to solving Pell's equation <code>a^2 - <var>n</var> b^2 = 1</code>.
</p>
<pre class="example">(%i1) qunit (17);
(%o1)                     sqrt(17) + 4
(%i2) expand (% * (sqrt(17) - 4));
(%o2)                           1
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-totient"></a>
</p><dl>
<dt><u>Function:</u> <b>totient</b><i> (<var>n</var>)</i>
<a name="IDX1179"></a>
</dt>
<dd><p>Returns the number of integers less than or equal to <var>n</var> which
are relatively prime to <var>n</var>.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-zerobern"></a>
</p><dl>
<dt><u>Option variable:</u> <b>zerobern</b>
<a name="IDX1180"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>When <code>zerobern</code> is <code>false</code>, <code>bern</code> excludes the Bernoulli numbers
and <code>euler</code> excludes the Euler numbers which are equal to zero. 
See <code>bern</code> and <code>euler</code>.
</p>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-zeta"></a>
</p><dl>
<dt><u>Function:</u> <b>zeta</b><i> (<var>n</var>)</i>
<a name="IDX1181"></a>
</dt>
<dd><p>Returns the Riemann zeta function. If <var>n</var> is a negative integer, 0, or a 
positive even integer, the Riemann zeta function simplifies to an exact value.
For a positive even integer the option variable <code>zeta%pi</code> has to be
<code>true</code> in addition (See <code>zeta%pi</code>). For a floating point or bigfloat 
number the Riemann zeta function is evaluated numerically. Maxima returns a noun
form <code>zeta (<var>n</var>)</code> for all other arguments, including rational 
noninteger, and complex arguments, or for even integers, if <code>zeta%pi</code> has 
the value <code>false</code>.
</p>
<p><code>zeta(1)</code> is undefined, but Maxima knows the limit 
<code>limit(zeta(x), x, 1)</code> from above and below.
</p>
<p>The Riemann zeta function distributes over lists, matrices, and equations.
</p>
<p>See also <code>bfzeta</code> and <code>zeta%pi</code>.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) zeta([-2,-1,0,0.5,2,3,1+%i]);
                                              2
             1     1                       %pi
(%o1)  [0, - --, - -, - 1.460354508809587, ----, zeta(3), zeta(%i + 1)]
             12    2                        6 

(%i2) limit(zeta(x),x,1,plus);
(%o2)                                 inf
(%i3) limit(zeta(x),x,1,minus);
(%o3)                                minf
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>

<p><a name="Item_003a-zeta_0025pi"></a>
</p><dl>
<dt><u>Option variable:</u> <b>zeta%pi</b>
<a name="IDX1182"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>When <code>zeta%pi</code> is <code>true</code>, <code>zeta</code> returns an expression 
proportional to <code>%pi^n</code> for even integer <code>n</code>. Otherwise, <code>zeta</code> 
returns a noun form <code>zeta (n)</code> for even integer <code>n</code>.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) zeta%pi: true$
(%i2) zeta (4);
                                 4
                              %pi
(%o2)                         ----
                               90
(%i3) zeta%pi: false$
(%i4) zeta (4);
(%o4)                        zeta(4)
</pre>
<div class=categorybox>


<p>Categories:&nbsp;&nbsp;<a href="maxima_95.html#Category_003a-Number-theory">Number theory</a>
</p>
</div>

</dd></dl>


<p><a name="Item_003a-Symmetries"></a>
</p><hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC138" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="maxima_32.html#SEC140" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_79.html#SEC331" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated by <em>Robert Dodier</em> on <em>April, 24 2010</em> using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.
 </font>
 <br>

</p>
</body>
</html>