Ian Jauslin
summaryrefslogtreecommitdiff
blob: 2daf429c470e567e912a7db3ee90275ca73aba82 (plain)
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
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
<html>
  <head>
    <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>
    <!--<script type="text/javascript" src="/usr/share/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>-->

    <style>
      body {
	margin-top:40pt;
	margin-bottom:40pt;
	margin-left:40pt;
	margin-right:40pt;

	text-align:justify;
      }

      p {
	text-indent:20pt;
      }

      .codeblock {
	display:block;
	margin-left:40pt;
	margin-top:10pt;
	margin-bottom:15pt;
	text-indent:0pt;
      }

      li {
	margin-top:10pt;
      }

      .toc {
	font-weight:bold;
      }
      .toc ul {
	list-style-type:none;
      }
      .toc li {
	margin-top:0pt;
      }
      .toc_sec {
	counter-increment: tocsec;
	counter-reset: tocsub 0;
      }
      .toc_sec:before {
	content: counter(tocsec) ". ";
      }
      .toc_sub {
	counter-increment: tocsub;
      }
      .toc_sub:before {
	content: counter(tocsec) "." counter(tocsub) ". ";
      }

      body {
	counter-reset: section 0;
      }
      .section:before {
	counter-increment: section;
	content: counter(section) ". ";
      }
      .section {
	margin-top:50pt;
	counter-reset: subsection 0;
      }
      .subsection:before {
	counter-increment: subsection;
	content: counter(section) "." counter(subsection) ". ";
      }
      .subsection {
	margin-top:30pt;
      }

    </style>

  </head>

  <body>
    <h1 style="margin-bottom:50pt;">libinum <span style="margin-left:10pt;font-size:18pt">v1.0</span></h1>

    <p>
      This is the official documentation for <b>libinum</b>, version 1.0.
    </p>

    <h2 style="margin-top:50pt;">Table of contents</h2>
    <div class="toc">
      <ul>
	<li class="toc_sec"><a href="#sec_description">Description</a></li>
	<li class="toc_sec"><a href="#sec_datatypes">Data types</a></li>
	<li class="toc_sec"><a href="#sec_algorithms">Algorithms</a></li>
	  <ul>
	    <li class="toc_sub"><a href="#subsec_root_finding">Root finding</a></li>
	      <ul>
		<li><a href="#func_root_newton"><code>root_newton</code></a></li>
		<li><a href="#func_root_newton_inplace"><code>root_newton_inplace</code></a></li>
	      </ul>
	    <li class="toc_sub"><a href="#subsec_integrals">Integrals</a></li>
	      <ul>
		<li><a href="#func_integrate_gauss"><code>integrate_gauss</code></a></li>
		<li><a href="#func_integrate_gauss_multithread"><code>integrate_gauss_multithread</code></a></li>
		<li><a href="#func_integrate_gauss_smarttmp"><code>integrate_gauss_smarttmp</code></a></li>
		<li><a href="#func_integrate_gauss_smarttmp_multithread"><code>integrate_gauss_smarttmp_multithread</code></a></li>
		<li><a href="#func_gauss_legendre_weights"><code>gauss_legendre_weights</code></a></li>
	      </ul>
	  </ul>
	<li class="toc_sec"><a href="#sec_types">Types</a></li>
	  <ul>
	    <li class="toc_sub"><a href="#subsec_array"><code>array</code></a></li>
	    <li class="toc_sub"><a href="#subsec_polynomial"><code>polynomial</code></a></li>
	    <li class="toc_sub"><a href="#subsec_polynomialMV"><code>polynomialMV</code></a></li>
	    <li class="toc_sub"><a href="#subsec_functions">Functions</a></li>
	  </ul>
	<li class="toc_sec"><a href="#sec_utilities">Utilities</a></li>
	<li class="toc_sec"><a href="#sec_examples">Examples</a></li>
	<li class="toc_sec"><a href="#sec_authors">Authors</a></li>
      </ul>
    </div>

    <h2 class="section" id="sec_description">Description</h2>
    <p>
      <b>libinum</b> is a C library that implements several algorithms, intended for applications in numerical and symbolic computations.
    </p>
    <p>
      <b>libinum</b> defines functions to perform the following tasks:
      <ul>
	<li>Compute roots of smooth real functions numerically using the Newton-Raphson algorithm.</li>
	<li>Compute definite integrals of smooth real functions numerically using Gauss-Legendre quadratures.</li>
      </ul>
      In addition, <b>libinum</b> defines the following structures:
      <ul>
	<li>Variable-length arrays.</li>
	<li>Single variable and multivariate polynomials.</li>
      </ul>
    </p>

    <p>
      As a general rule, the functions and structures can be used with several different data types. For instance, the root finding and integration functions can manipulate double precision, extended precision, or multi-precision floating point numbers. See <a href="#sec_datatypes">Data types</a> for details.
    </p>

    <h2 class="section" id="sec_datatypes">Data types</h2>
    <p>
      One of the guiding principles of <b>libinum</b> is that it should should not push a specific data type on users. If, hypothetically, the computation being carried out requires the precision of the floating point numbers to be large, then multi-precision floating point numbers might be preferable to double precision numbers. If, instead, computation time is more important than precision, then extended precision floats may be preferred. The structures and functions defined in <b>libinum</b>, therefore, support various data types.
    </p>

    <p>
      We will now briefly discuss the data types that may be used to represent numbers.
    </p>


    <h3 class="subsection" id="subsec_int">Integers</h3>
    <h4>Fixed-precision integers</h4>
    <p>
      The standard integer types of the C language are <code>char</code>, <code>short int</code>, <code>int</code>, <code>long int</code> and <code>long long int</code>, as well as their <code>unsigned</code> counterparts. The number of bits, and, in consequence, the available range of integers, of each of these types, is platform-dependent. In cases where this could be problematic, fixed-precision integers can be used: with 8 bits: <code>int8_t</code>, 16: <code>int16_t</code>, 32: <code>int32_t</code> and 64: <code>int64_t</code>.
    </p>
    <p>
      <b>libinum</b> provides a function, <code>print_datatype_info()</code>, that prints the equivalence table between <code>char</code>, <code>short int</code>, <code>int</code>, <code>long int</code> and <code>long long int</code> and <code>int8_t</code>, <code>int16_t</code>, <code>int32_t</code> and <code>int64_t</code> for the implementation of the C library used to compile <b>libinum</b>.
    </p>

    <h4>Multi-precision integers</h4>
    <p>
      In cases where the required number of bits of integers exceeds 64, one can use <i>multi-precision integers</i>, which can be as large as will fit in memory. However, computation times can greatly increase when using multi-precision integers. The implementation used in <b>libinum</b> is provided by the <a href="http://gmplib.org">GNU GMP</a> library.
    </p>



    <h3 class="subsection" id="subsec_float">Floating point numbers</h3>
    <p>
      Let us first start with a description of floating point numbers. A real number \(x\) is approximated, with a <i>precision</i> of \(m\) bits, as a collection of three numbers: the <i>sign</i> \(s\in\{-1,1\}\); <i>mantissa</i>, whose binary expansion is denoted by \(a_1\cdots a_m\); and <i>exponent</i> \(e\in\mathbb Z\). The approximate value of the number \(x\) is obtained from its sign, mantissa and exponent by
      $$
      x=s\times a_1.a_2\cdots a_m\times2^e.
      $$
      The <i>precision</i> of a floating point number is the number of bits allocated to its sign and mantissa (since \(a_1\) is necessarily equal to \(1\), it is not stored, so the precision of \(x\) is \(m\) instead of \(m+1\)).
    </p>
    <p> In <b>libinum</b>, floating point number may either be double, extended or multi-precision numbers.

    <h4>Double precision floating point numbers</h4>
    <p>
      Double precision floats are represented using the <code>double</code> type.
    </p>
    <p>
      The precision and maximal and minimal values of the exponent of <code>double</code> floats depends on the compiler. Their values can be printed using the <b>libinum</b> function <code>print_datatype_info()</code>.
    </p>
    <p>
      For example, using version 5.3.0 of the <a href="https://gcc.gnu.org/">GNU GCC</a> compiler on the x86-64 architecture, the precision is of 53 bits (i.e. 15 decimal digits), and the maximal and minimal values of the exponent are 1024 and -1021.
    </p>

    <h4>Extended precision floating point numbers</h4>
    <p>
      Extended precision floats are represented using the <code>long double</code> type. They require more memory than double precision floats, and, as a consequence, slightly more computation time.
    </p>
    <p>
      The precision and maximal and minimal values of the exponent of <code>long double</code> floats depends on the compiler. Their values can be printed using the <b>libinum</b> function <code>print_datatype_info()</code>.
    </p>
    <p>
      For example, using version 5.3.0 of the <a href="https://gcc.gnu.org/">GNU GCC</a> compiler on the x86-64 architecture, the precision is of 64 bits (i.e. 18 decimal digits), and the maximal and minimal values of the exponent are 16384 and -16381.
    </p>

    <h4>Multi-precision floating point numbers</h4>
    <p>
      A multi-precision floating point number is a floating point number whose precision can be set to an arbitrary value (until the number fills up the entire memory of the computer). In <b>libinum</b>, multi-precision floats are implemented using the <a href="http://mpfr.org">GNU MPFR</a> library, and will be called <i> MPFR floats</i>.
    </p>
    <p>
      The precision of MPFR floats can be set using the function <code>mpfr_set_default_prec</code> (see the MPFR library <a href="http://www.mpfr.org/mpfr-current/mpfr.html#index-mpfr_005fset_005fdefault_005fprec">documentation</a> for details). The default value of the precision is 53 bits (as of version 3.1.4 of the MPFR library).
    </p>
    <p>
      In addition, the maximal value (in absolute value) of the exponent can be controlled by setting <i>emax</i> using the function <code>mpfr_set_emax</code> (see the MPFR library <a href="http://www.mpfr.org/mpfr-current/mpfr.html#index-mpfr_005fset_005femax">documentation</a> for details).
    </p>
    <p>
      Depending on the MPFR implementation, the precision and emax can either be an <code>int</code> or a <code>long int</code>, so its maximal and minimal values are platform dependent. The <b>libinum</b> function <code>print_datatype_info()</code> prints which it is.
    </p>


    <h2 class="section" id="sec_algorithms">Algorithms</h2>
    <p>
      What follows is a detailed description of the functions that implement the algorithms supported by <b>libinum</b>.
    </p>

    <h3 class="subsection" id="subsec_root_finding">Root finding</h3>
    <p>
      <b>libinum</b> can compute the root of smooth real functions using the Newton-Raphson algorithm. The algorithm converges quickly, provided an adequate approximation of the root in provided, and that the root is not located at a minimum of the function.
    </p>

    <h4>Description</h4>
    <p>
      Given a function \(f\) and a real number \(x_0\), the algorithm produces a sequence \((x_n)\) which, provided the algorithm converges, tends to a root of \(f\). The sequence is defined as
      $$
      x_{n+1}=x_n-\frac{f(x_{n})}{f'(x_{n})}
      $$
      where \(f'\) denotes the derivative of \(f\). The following estimate holds:
      $$
      |x_{n+1}-x_n|\leqslant \frac12|x_n-x_{n-1}|^2\sup_{\xi\in[x_{n+1},x_n]}\frac{f''(\xi)}{f'(\xi)}
      $$
      so that, provided \(f\) is smooth and its derivative does not vanish in the intervals \([x_{n+1},x_n]\), the algorithm converges <i>quadratically</i>.
    </p>

    <h4>Implementation</h4>
    <p>
      This algorithm has been implemented using double, extended and multi-precision floats.
      <?php
	$typenames=["double", "ldouble", "mpfr"];
	$floattypes=["double", "long double", "mpfr_t"];
      ?>
    </p>

    <ul>
      <li id="func_root_newton">
	<div style="vertical-align: top;">
	  <?php
	    for ($i=0; $i<count($typenames); $i++){
	      $TYPENAME=$typenames[$i];
	      $FLOATTYPE=$floattypes[$i];
	      print("
	  <code>
	    <div style=\"margin-bottom:20pt\">
	      <div id=\"func_root_newton_${TYPENAME}\" style=\"display: inline-block; vertical-align: top;\">
		int root_newton_${TYPENAME}(
	      </div>
	      <div id=\"func_root_newton_${TYPENAME}\" style=\"display: inline-block; vertical-align: top;\">
		${FLOATTYPE}* out,<br>
		int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
		int (*deriv_func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
		${FLOATTYPE} init,<br>
		${FLOATTYPE} tolerance,<br>
		int maxiter,<br>
		void* extra_args)
	      </div>
	    </div>
	  </code>
	      ");
	    }
	  ?>
	</div>

	<br>
	<b>Description</b>: Compute a numerical approximation for the root.<br>
	<br>
	
	<b>Arguments</b>:
	<ul>
	  <li>
	    <code>out</code>: pointer to the number to which the result will be written. If the number requires initialization (e.g. if it is an <code>mpfr_t</code>), then it must be initialized.
	  </li>
	  <li>
	    <code>func</code>: pointer to the function that computes \(f(x)\). It must be in the format specified in <a href="#subsec_functions">functions</a>.
	  </li>
	  <li>
	    <code>deriv_func</code>: pointer to the function that computes the derivative of \(f\). It must be in the format specified in <a href="#subsec_functions">functions</a>.
	  </li>
	  <li>
	    <code>init</code>: the value of \(x_0\).
	  </li>
	  <li>
	    <code>tolerance</code>: the algorithm halts when \(|x_{n+1}-x_n|\leqslant\)<code>tolerance</code>. <code>tolerance</code> thus provides control over the error of the algorithm.
	  </li>
	  <li>
	    <code>maxiter</code>: maximum number of iterations. The algorithm gives up if this number is reached and throws a <code>LIBINUM_ERROR_MAXITER</code> exception.
	  </li>
	  <li>
	    <code>extra_args</code>: pointer to the extra arguments to be passed to the functions <code>*func</code> and <code>*deriv_func</code> when they are evaluated.
	  </li>
	</ul>
	<br>
	<b>Return value</b>: returns <code>0</code> on success, and
	<ul>
	  <li><code>LIBINUM_ERROR_MAXITER</code> if the maximal number of iterations was reached.</li>
	  <li><code>LIBINUM_ERROR_NAN</code> if any of the evaluations of <code>*func</code> or <code>*deriv_func</code> returned <code>nan</code> or <code>infinity</code>, or if any of the evaluations of <code>*deriv_func</code> returned <code>0</code>.</li>
	</ul>
      </li>
      <br><br>

      <li id="func_root_newton_inplace">
	<div style="vertical-align: top;">
	  <?php
	    for ($i=0; $i<count($typenames); $i++){
	      $TYPENAME=$typenames[$i];
	      $FLOATTYPE=$floattypes[$i];
	      print("
	  <code>
	    <div style=\"margin-bottom:20pt\">
	      <div id=\"func_root_newton_inplace_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
		int root_newton_inplace_${TYPENAME}(
	      </div>
	      <div style=\"display: inline-block; vertical-align: top\">
		${FLOATTYPE}* out,<br>
		int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
		int (*deriv_func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
		${FLOATTYPE} tolerance,<br>
		int maxiter,<br>
		void* extra_args)<br>
	      </div>
	    </div>
	  </code>
	      ");
	    }
	  ?>
	</div>

	<br>
	<b>Description</b>: Similar to <a href="#func_root_newton"><code>root_newton_*</code></a> except that the value of \(x_0\) is passed to the function in the argument <code>out</code>.
      </li>
    </ul>

    <h3 class="subsection" id="subsec_integrals">Integrals</h3>
    <p>
      <b>libinum</b> can compute definite integrals of smooth real functions using Gauss-Legendre quadratures.
    </p>

    <h4>Description</h4>
    <p>
      The main idea of Gauss-Legendre quadratures is to find a set of <i>abcissa</i> \(\{t_1,\cdots,t_N\}\in[-1,1]^N\) and <i>weights</i> \(\{w_1,\cdots,w_N\}\in\mathbb R^N\) such that, if \(f\) were a polynomial of degree \(\leqslant2N-1\), then the integral would be equal to a discrete sum:
      $$
      \int_{a}^bdx\ f(x)=\sum_{i=1}^Nw_if\left(\frac{a+b}2+t_i\frac{b-a}2\right).
      $$
      In the general case, if \(f\) is \(\mathcal C^{2N}\), then
      $$
      \left|\int_{a}^bdx\ f(x)-\sum_{i=1}^Nw_if\left(\frac{a+b}2+t_i\frac{b-a}2\right)\right|
      \leqslant \frac{N!^4}{(2N+1)(2N)!^3}\sup_{x\in[a,b]}\frac{d^{2N}f(x)}{dx^{2N}}.
      $$
      The number \(N\) is called the <i>order</i> of the integration.
    </p>

    <p>
      As it turns out, the abcissa are the roots of the \(N\)-th Legendre polynomial \(L_N\), defined by the recursive equation
      $$
      (N+1)L_{N+1}(x)=(2N+1)xL_N(x)-NL_{N-1}(x),\quad
      L_0(x)=1,\quad L_1(x)=x
      $$
      and the weights are
      $$
      w_i=\frac2{(1-x_i^2)L_N'(t_i)}.
      $$
    </p>

    <h4>Implementation</h4>
    <p>
      This algorithm has been implemented using double, extended and multi-precision floats
      <?php
	$typenames=["double", "ldouble", "mpfr"];
	$floattypes=["double", "long double", "mpfr_t"];
	$typenames_init=["mpfr"];
	$floattypes_init=["mpfr_t"];
      ?>
    <ul>

      <li id="func_integrate_gauss">
	<div style="vertical-align: top;">
	  <?php
	    for ($i=0; $i<count($typenames); $i++){
	      $TYPENAME=$typenames[$i];
	      $FLOATTYPE=$floattypes[$i];
	      print("
	  <code>
	    <div style=\"margin-bottom:20pt\">
	      <div id=\"func_integrate_gauss_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
		int integrate_gauss_${TYPENAME}(
	      </div>
	      <div style=\"display: inline-block; vertical-align: top\">
	      ${FLOATTYPE}* out,<br>
	      int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
	      ${FLOATTYPE} lower,<br>
	      ${FLOATTYPE} upper,<br>
	      array_${TYPENAME} abcissa,<br>
	      array_${TYPENAME} weights,<br>
	      void* extra_args)
	      </div>
	    </div>
	  </code>
	      ");
	    }
	  ?>
	</div>

	<br>
	<b>Description</b>: Compute a numerical approximation for the integral of a real function using Gauss quadratures.<br>
	<br>
	
	<b>Arguments</b>:
	<ul>
	  <li>
	    <code>out</code>: pointer to the number to which the result will be written.  If the number requires initialization (e.g. if it is an <code>mpfr_t</code>), then it must be initialized.
	  </li>
	  <li>
	    <code>func</code>: pointer to the function that computes the integrand \(f(x)\). It must be in the format specified in <a href="#subsec_functions">functions</a>.
	  </li>
	  <li>
	    <code>lower</code>: lower bound of the integration.
	  </li>
	  <li>
	    <code>upper</code>: upper bound of the integration.
	  </li>
	  <li>
	    <code>abcissa</code>: the abcissa used to compute the integral using Gauss quadratures. For Gauss-Legendre integration, they can be computed by the function <a href="#func_gauss_legendre_weights"><code>gauss_legendre_weights</code></a>.
	  </li>
	  <li>
	    <code>weights</code>: the weights used to compute the integral using Gauss quadratures. For Gauss-Legendre integration, they can be computed by the function <a href="#func_gauss_legendre_weights"><code>gauss_legendre_weights</code></a>.
	  </li>
	  <li>
	    <code>extra_args</code>: pointer to the extra arguments to be passed to the function <code>*func</code> when it is evaluated (see <a href="#subsec_functions">functions</a>).
	  </li>
	</ul>
	<br>
	<b>Return value</b>: returns <code>0</code> on success, and
	<ul>
	  <li><code>LIBINUM_ERROR_NAN</code> if any of the evaluations of <code>*func</code> returned <code>nan</code> or <code>infinity</code>.</li>
	  <li><code>LIBINUM_ERROR_SIZE_MISMATCH</code> if the lengths of the vectors <code>abcissa</code> and <code>weights</code> are different.</li>
	</ul>
      </li>
      <br><br>

      <li id="func_integrate_gauss_multithread">
	<div style="vertical-align: top;">
	  <?php
	    for ($i=0; $i<count($typenames); $i++){
	      $TYPENAME=$typenames[$i];
	      $FLOATTYPE=$floattypes[$i];
	      print("
	  <code>
	    <div style=\"margin-bottom:20pt\">
	      <div id=\"func_integrate_gauss_multithread_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
	      int integrate_gauss_multithread_${TYPENAME}(
	      </div>
	      <div style=\"display: inline-block; vertical-align: top;\">
	      ${FLOATTYPE}* out,<br>
	      int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
	      ${FLOATTYPE} lower,<br>
	      ${FLOATTYPE} upper,<br>
	      array_${TYPENAME} abcissa,<br>
	      array_${TYPENAME} weights,<br>
	      void* extra_args,<br>
	      unsigned int threads,<br>
	      array_pthread_t* thread_ids)
	      </div>
	    </div>
	  </code>
	      ");
	    }
	  ?>
	</div>

	<b>Description</b>: Multithreaded version of <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>, in which function calls are performed in parallel.<br>
	<br>
	
	<b>Arguments</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>, except for
	<ul>
	  <li>
	    <code>threads</code>: number of threads to use for the computation.
	  </li>
	  <li>
	    <code>thread_ids</code>: pointer to an array in which the id of each thread is written to. The array must not be initialized. This array can then be used by each thread to identify themselves.
	  </li>
	</ul>
	<br>
	<b>Return value</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>.
      </li>
      <br><br>

      <li id="func_integrate_gauss_smarttmp">
	<div style="vertical-align: top;">
	  <?php
	    for ($i=0; $i<count($typenames_init); $i++){
	      $TYPENAME=$typenames_init[$i];
	      $FLOATTYPE=$floattypes_init[$i];
	      print("
	  <code>
	    <div style=\"margin-bottom:20pt\">
	      <div id=\"func_integrate_gauss_smarttmp_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
	      int integrate_gauss_smarttmp_${TYPENAME}(
	      </div>
	      <div style=\"display: inline-block; vertical-align: top;\">
	      ${FLOATTYPE}* out,<br>
	      int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
	      ${FLOATTYPE} lower,<br>
	      ${FLOATTYPE} upper,<br>
	      array_${TYPENAME} abcissa,<br>
	      array_${TYPENAME} weights,<br>
	      array_${TYPENAME}* tmps,<br>
	      void* extra_args)
	      </div>
	    </div>
	  </code>
	      ");
	    }
	  ?>
	</div>

	<b>Description</b>: Similar to <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>, except that, if temporary floats are needed during the computation, they are saved to an array so that they can be re-used later on. This is useful to perform repeated integrations, in which it would be costly to re-allocate memory for temporary floats. When using this function, temporary floats are allocated as needed, but they are not discarded.<br>
	<br>
	
	<b>Arguments</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>, except for
	<ul>
	  <li>
	    <code>tmps</code>: pointer to an array that is used to store temporary floats. The array must be initialized beforehand. When temporary floats are needed, the array is checked for available floats. If enough of them are already present in the array, then the routine uses them, if not, it enlarges the array and allocates as many extra floats as is needed. The floats in the array can then be re-used for other purposes.
	  </li>
	</ul>
	<br>
	<b>Return value</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>.
      </li>
      <br><br>

      <li id="func_integrate_gauss_smarttmp_multithread">
	<div style="vertical-align: top;">
	  <?php
	    for ($i=0; $i<count($typenames_init); $i++){
	      $TYPENAME=$typenames_init[$i];
	      $FLOATTYPE=$floattypes_init[$i];
	      print("
	  <code>
	    <div style=\"margin-bottom:20pt\">
	      <div id=\"func_integrate_gauss_smarttmp_multithread_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
	      int integrate_gauss_smarttmp_multithread_${TYPENAME}(
	      </div>
	      <div style=\"display: inline-block; vertical-align: top;\">
	      ${FLOATTYPE}* out,<br>
	      int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
	      ${FLOATTYPE} lower,<br>
	      ${FLOATTYPE} upper,<br>
	      array_${TYPENAME} abcissa,<br>
	      array_${TYPENAME} weights,<br>
	      void* extra_args,<br>
	      unsigned int threads,<br>
	      array_pthread_t* thread_ids)
	      </div>
	    </div>
	  </code>
	      ");
	    }
	  ?>
	</div>

	<b>Description</b>: Multithreaded version of <a href="#func_integrate_gauss_smarttmp"><code>integrate_gauss_smarttmp_*</code></a>, in which function calls are performed in parallel.<br>
	<br>
	
	<b>Arguments</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_smarttmp_*</code></a>, except for
	<ul>
	  <li>
	    <code>threads</code>: number of threads to use for the computation.
	  </li>
	  <li>
	    <code>thread_ids</code>: pointer to an array in which the id of each thread is written to. The array must not be initialized. This array can then be used by each thread to identify themselves.
	  </li>
	</ul>
	<br>
	<b>Return value</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>.
      </li>
      <br><br>


      <li id="func_gauss_legendre_weights">
	<div style="vertical-align: top;">
	  <?php
	    for ($i=0; $i<count($typenames); $i++){
	      $TYPENAME=$typenames[$i];
	      $FLOATTYPE=$floattypes[$i];
	      print("
	  <code>
	    <div style=\"margin-bottom:20pt\">
	      <div id=\"func_gauss_legendre_weights_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
	      gauss_legendre_weights_${TYPENAME}(
	      </div>
	      <div style=\"display: inline-block; vertical-align: top\">
	      unsigned int order,<br>
	      ${FLOATTYPE} tolerance,<br>
	      unsigned int maxiter,<br>
	      array_${TYPENAME}* abcissa,<br>
	      array_${TYPENAME}* weights)
	      </div>
	    </div>
	  </code>
	      ");
	    }
	  ?>
	</div>

	<b>Description</b>: Compute the Gauss-Legendre abcissa and weights.<br>
	<br>
	
	<b>Arguments</b>:
	<ul>
	  <li>
	    <code>order</code>: the order \(N\) of the integration.
	  </li>
	  <li>
	    <code>tolerance</code>: tolerance for the Newton algorithm used to compute the roots of the Legendre polynomial (see <a href="#func_root_newton"><code>root_newton</code></a>).
	  </li>
	  <li>
	    <code>maxiter</code>: the maximal number of steps to compute before giving up.
	  </li>
	  <li>
	    <code>abcissa</code>: pointer to the <a href="#subsec_array">array</a> in which to write the abcissa. It must not be initialized.
	  </li>
	  <li>
	    <code>weights</code>: pointer to the <a href="#subsec_array">array</a> in which to write the weights. It must not be initialized.
	  </li>
	</ul>
	<br>
	<b>Return value</b>: returns <code>0</code> on success, and
	<ul>
	  <li><code>LIBINUM_ERROR_MAXITER</code> if, when computing the roots of the Legendre polynomial using a Newton iteration, the maximal number of iterations was reached.</li>
	</ul>
      </li>
    </ul>

    <h2 class="section" id="sec_types">Types</h2>
    <p>
      What follows is a detailed description of the C types defined in <b>libinum</b>.
    </p>

    <h3 class="subsection" id="subsec_array"><code>array</code></h3>
    <p>Array that can be dynamically resized.</p>

    <?php
      $typenames=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr", "pthread_t"];
      $types=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr", "pthread_t"];

      $typenames_init=["mpfr", "2_mpfr", "str", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr"];
      $types_init=["mpfr_t", "array_mpfr", "array_char", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr"];

      $typenames_print=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr"];
      $types_print=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr"];

      $typenames_ifeq=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "pthread_t"];
      $types_ifeq=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "pthread_t"];
      $typenames_iflt=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "pthread_t"];
      $types_iflt=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "pthread_t"];
      $typenames_ifgt=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "pthread_t"];
      $types_ifgt=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "pthread_t"];
      $typenames_ifltgt=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "pthread_t"];
      $types_ifltgt=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "pthread_t"];
    ?>

    <h4>Structure</h4>
    Arrays of several types of objects are defined. They are structures, with the following keys:

    <ul>
      <?php
	for ($i=0; $i<count($typenames); $i++){
	  $TYPENAME=$typenames[$i];
	  $TYPE=$types[$i];
	  print("
      <li id=\"struct_array_${TYPENAME}\">
	<code>array_${TYPENAME}</code>:
	<code>{ ${TYPE}* values, unsigned int length, unsigned int memory }</code>
      </li>
	  ");
	}
      ?>
    </ul>
    where the keys correspond to
    <ul>
      <li><code>values</code>: the array in which the objects are stored</li>
      <li><code>length</code>: the number of elements in the array</li>
      <li><code>memory</code>: the number of elements allocated to the array</li>
    </ul>
    <code>array_*</code>'s must be initialized before they are used, and freed when they are no longer needed. khen the array is freed, the objects it contains are freed as well.

    <h4>Functions</h4>
    <ul>
      <li id="func_array_init">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $TYPE=$types[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_init_${TYPENAME}\">int array_${TYPENAME}_init(array_${TYPENAME}* array, unsigned int memory)</code>
	</div>
	    ");
	  }
	?>
	<br>
	initialize the array pointed to by <code>array</code>, and allocate <code>memory</code> elements.
      </li>
      <br>
      <li id="func_array_free">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $TYPE=$types[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_free_${TYPENAME}\">int array_${TYPENAME}_free(array_${TYPENAME} array)</code><br>
	</div>
	    ");
	  }
	?>
	<br>
	free the array <code>array</code>.
      </li>
      <br>
      <li id="func_array_free_vects">
	<?php
	  for ($i=0; $i<count($typenames_init); $i++){
	    $TYPENAME=$typenames_init[$i];
	    $TYPE=$types_init[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_free_vects_${TYPENAME}\">int array_${TYPENAME}_free_vects(array_${TYPENAME} array)</code><br>
	</div>
	    ");
	  }
	?>
	<br>
	free the memory pointed to by <code>array.values</code>, but do not free the elements of the array.
      </li>
      <br>
      <li id="func_array_resize">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $TYPE=$types[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_resize_${TYPENAME}\">int array_${TYPENAME}_resize(array_${TYPENAME}* array, unsigned int newsize)</code>
	</div>
	    ");
	  }
	?>
	<br>
	copy the array pointed to by <code>array</code> to another with memory <code>newsize</code>.
      </li>
      <br>
      <li id="func_array_append">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $TYPE=$types[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_append_${TYPENAME}\">int array_${TYPENAME}_append(${TYPE} value, array_${TYPENAME}* array)</code>
	</div>
	    ");
	  }
	?>
	<br>
	append <code>value</code> to the end of the array pointed to by <code>array</code>. Resize the array if needed.
      </li>
      <br>
      <li id="func_array_append_noinit">
	<?php
	  for ($i=0; $i<count($typenames_init); $i++){
	    $TYPENAME=$typenames_init[$i];
	    $TYPE=$types[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_append_noinit_${TYPENAME}\">int array_${TYPENAME}_append_noinit(${TYPE} value, array_${TYPENAME}* array)</code>
	</div>
	    ");
	  }
	?>
	<br>
	append <code>value</code> to the end of the array pointed to by <code>array</code>. Do not initialize the new value, instead, copy <code>value</code> to the end of <code>*array</code>. <code>value</code> must not be freed, since it will be freed when <code>*array</code> is. Resize the array if needed.
      </li>
      <br>
      <li id="func_array_concat">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $TYPE=$types[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_concat_${TYPENAME}\">int array_${TYPENAME}_concat(array_${TYPENAME} input, array_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	append the values in <code>input</code> to the end of the array pointed to by <code>output</code>. Resize the array if needed.
      </li>
      <br>
      <li id="func_array_cpy">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $TYPE=$types[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_cpy_${TYPENAME}\">int array_${TYPENAME}_cpy(array_${TYPENAME} input, array_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	copy <code>input</code> to the array pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <br>
      <li id="func_array_cpy_noinit">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $TYPE=$types[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_cpy_noinit_${TYPENAME}\">int array_${TYPENAME}_cpy_noinit(array_${TYPENAME} input, array_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	copy <code>input</code> to the array pointed to by <code>output</code>. Does not initialize <code>*output</code>, so <code>*output</code> must be initialized ahead of time, and its memory must be larger or equal to the length of <code>input</code>. Returns <code>LIBINUM_ERROR_SIZE_MISMATCH</code> if the memory of <code>*output</code> is smaller than the length of <code>input</code>.
      </li>
      <br>
      <li id="func_array_subarray">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $TYPE=$types[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_subarray_${TYPENAME}\">int array_${TYPENAME}_subarray(array_${TYPENAME} array, unsigned int begin, unsigned int end, array_${TYPENAME}* subarray)</code>
	</div>
	    ");
	  }
	?>
	<br>
	extract the sub-array of <code>array</code> whose indices are larger or equal to <code>begin</code> and smaller or equal to <code>end</code>. Returns <code>LIBINUM_ERROR_ILLEGAL_MEMORY_ACCESS</code> if the subarray does not exist.
      </li>
      <br>
      <li id="func_array_print">
	<?php
	  for ($i=0; $i<count($typenames_print); $i++){
	    $TYPENAME=$typenames_print[$i];
	    $TYPE=$types_print[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_print_${TYPENAME}\">int array_${TYPENAME}_print(array_${TYPENAME} array)</code>
	</div>
	    ");
	  }
	?>
	<br>
	print the elements of <code>array</code>.
      </li>
    </ul>

    <h4>Extra functions for arrays of ordered objects</h4>
    In addition, we define the following ordering for the possible objects in an array:
    <ul>
      <li>the obvious ordering for <code>int, unsigned int, double, long double, mpfr, char</code></li>
      <li>lexicographical ordering for <code>array_char</code></li>
      <li>no ordering for <code>polynomial_*</code>.</li>
    </ul>
    If the ordering is defined, then the following functions are defined:

    <ul>
      <li id="func_array_append_unique">
	<?php
	  for ($i=0; $i<count($typenames_ifeq); $i++){
	    $TYPENAME=$typenames_ifeq[$i];
	    $TYPE=$types_ifeq[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_append_unique_${TYPENAME}\">int array_${TYPENAME}_append_unique(${TYPE} value, array_${TYPENAME}* array)</code>
	</div>
	    ");
	  }
	?>
	<br>
	if <code>value</code> is not already present in the array pointed to by <code>array</code>, then append it. Resize the array if needed.
      </li>
      <br>
      <li id="func_array_concat_unique">
	<?php
	  for ($i=0; $i<count($typenames_ifeq); $i++){
	    $TYPENAME=$typenames_ifeq[$i];
	    $TYPE=$types_ifeq[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_concat_unique_${TYPENAME}\">int array_${TYPENAME}_concat_unique(array_${TYPENAME} input, array_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	append the values in <code>input</code> that are not already present in the array pointed to by <code>output</code>. Resize the array if needed.
      </li>
      <br>
      <li id="func_array_find">
	<?php
	  for ($i=0; $i<count($typenames_ifeq); $i++){
	    $TYPENAME=$typenames_ifeq[$i];
	    $TYPE=$types_ifeq[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_find_${TYPENAME}\">int array_${TYPENAME}_find(${TYPE} val, array_${TYPENAME} array)</code>
	</div>
	    ");
	  }
	?>
	<br>
	search for <code>val</code> in <code>array</code>. Returns the index of <code>val</code> in <code>array</code> if it is present, and <code>-1</code> if it is not.
      </li>
      <br>
      <li id="func_array_sort">
	<?php
	  for ($i=0; $i<count($typenames_iflt); $i++){
	    $TYPENAME=$typenames_iflt[$i];
	    $TYPE=$types_iflt[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_sort_${TYPENAME}\">int array_${TYPENAME}_sort(array_${TYPENAME} array)</code>
	</div>
	    ");
	  }
	?>
	<br>
	sort the elements of <code>array</code> from smallest to largest (for numerical values, the ordering relation is the usual one, for characters and strings, the lexicographical ordering is used). The sorting is performed in place. The <i>quicksort</i> algorithm is used.
      </li>
      <br>
      <li id="func_array_sort_sub">
	<?php
	  for ($i=0; $i<count($typenames_iflt); $i++){
	    $TYPENAME=$typenames_iflt[$i];
	    $TYPE=$types_iflt[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_sort_sub_${TYPENAME}\">int array_${TYPENAME}_sort_sub(array_${TYPENAME} array, unsigned int begin, unsigned int end)</code>
	</div>
	    ");
	  }
	?>
	<br>
	sort the elements of the sub-array of <code>array</code> consisting of the elements whose index is larger or equal than <code>begin</code> and smaller or equal than <code>end</code>. The sorting is performed in place. The <i>quicksort</i> algorithm is used.
      </li>
      <br>
      <li id="func_array_cmp">
	<?php
	  for ($i=0; $i<count($typenames_ifltgt); $i++){
	    $TYPENAME=$typenames_ifltgt[$i];
	    $TYPE=$types_ifltgt[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_array_cmp_${TYPENAME}\">int array_${TYPENAME}_cmp(array_${TYPENAME} array1, array_${TYPENAME} array2)</code>
	</div>
	    ");
	  }
	?>
	<br>
	compare <code>array1</code> and <code>array2</code>. Returns <code>0</code> if both arrays are equal (that is, if their elements are the same, and in the same order), <code>-1</code> if <code>array1</code> is smaller than <code>array2</code> in lexicographical order, and <code>1</code> if <code>array1</code> is smaller than <code>array2</code> in lexicographical order.
      </li>
    </ul>

    <h4>Extra functions for <code>array_char</code></h4>
    In addition, the following functions are defined for <code>array_char</code>.
    <ul>
      <li id="func_array_char_append_str">
	<code>int array_char_append_str(char* str, array_char* output)</code><br>
	append the characters in <code>str</code> to the end of the array pointed to by <code>output</code>. Resize the array if needed.
      </li>
      <li id="func_array_char_to_str">
	<code>int array_char_to_str(array_char input, char** output)</code><br>
	copy the string in <code>input</code> to the string pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <li id="func_array_char_to_str_noinit">
	<code>char* array_char_to_str(array_char* input)</code><br>
	convert the array pointed to by <code>input</code> to a string, and return it. Appends <code>'\0'</code> at the end of <code>*input</code>. The string thus generated should not be freed, since it is actually a pointer to <code>input->str</code>, which is freed when <code>*input</code> is.
      </li>
      <li id="func_str_to_array_char">
	<code>int str_to_array_char(char* str, array_char* output)</code><br>
	copy the string <code>input</code> to the array pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <li id="func_array_char_cmp_str">
	<code>int array_char_cmp_str(array_char array_char, char* str)</code><br>
	compare the string in <code>array_char</code> and the string <code>str</code>. Returns <code>1</code> if the strings are identical, and <code>0</code> if not.
      </li>
      <li id="func_array_char_snprintf">
	<code>int array_char_snprintf(array_char* output, char* fmt)</code><br>
	reads the format <code>fmt</code> and appends the output to the array pointed to by <code>output</code>. The format should follow the specifications of the standard C function <code>printf</code>.
      </li>
    </ul>


    <h3 class="subsection" id="subsec_polynomial"><code>polynomial</code></h3>
    <p>A polynomial with real coefficients. A <code>polynomial</code> is represented as an array of coefficients and an array of exponents. For example \(1+x+2x^2\) is represented as <code>({1.,1.,2.},{0,1,2})</code>.</p>

    <h4>Structure</h4>
    The coefficients of polynomials can be double, extended, or multi-precision floats, and their exponents are unsigned integers. Polynomials are represented as structures, with the following keys:

    <?php
      $typenames=["double", "ldouble", "mpfr"];
      $coeftypes=["double", "long double", "mpfr_t"];
      $coeftypenames=["double", "ldouble", "mpfr"];
      $exptypes=["unsigned int", "unsigned int", "unsigned int"];
      $exptypenames=["uint", "uint", "uint"];
    ?>

    <ul>
      <?php
	for ($i=0; $i<count($typenames); $i++){
	  $TYPENAME=$typenames[$i];
	  $COEFTYPE=$coeftypes[$i];
	  $COEFTYPENAME=$coeftypenames[$i];
	  $EXPTYPE=$exptypes[$i];
	  $EXPTYPENAME=$exptypenames[$i];
	  print("
      <li id=\"struct_polynomial_${TYPENAME}\">
	<code>polynomial_${TYPENAME}</code>:
	<code>{ array_${COEFTYPENAME} coefficients, array_${EXPTYPENAME} orders }</code>
      </li>
	  ");
	}
      ?>
    </ul>
    where the keys correspond to
    <ul>
      <li><code>coefficients</code>: array of coefficients</li>
      <li><code>orders</code>: array of exponents.</li>
    </ul>
    <code>polynomial_*</code>'s must be initialized before they are used, and freed when they are no longer needed.

    <h4>Functions</h4>
    <ul>
      <li id="func_polynomial_init">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_init_${TYPENAME}\">polynomial_${TYPENAME}_init(polynomial_${TYPENAME}* poly, unsigned int memory)</code>
	</div>
	    ");
	  }
	?>
	<br>
	initialize the polynomial pointed to by <code>poly</code>, and allocate <code>memory</code> terms.
      </li>
      <br>
      <li id="func_polynomial_free">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_free_${TYPENAME}\">polynomial_${TYPENAME}_free(polynomial_${TYPENAME} poly)</code>
	</div>
	    ");
	  }
	?>
	<br>
	free the polynomial <code>poly</code>.
      </li>
      <br>
      <li id="func_polynomial_resize">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_resize_${TYPENAME}\">polynomial_${TYPENAME}_resize(polynomial_${TYPENAME}* poly, unsigned int newsize)</code>
	</div>
	    ");
	  }
	?>
	<br>
	copy the array polynomial to by <code>poly</code> to another with memory <code>newsize</code>.
      </li>
      <br>
      <li id="func_polynomial_append">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_append_${TYPENAME}\">polynomial_${TYPENAME}_add_monomial(${COEFTYPE} val, ${EXPTYPE} order, polynomial_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	add a term with coefficient <code>val</code> and exponent <code>order</code> to the polynomial pointed to by <code>output</code>. Resize the polynomial if needed.
      </li>
      <br>
      <li id="func_polynomial_append_d">
	<?php
	  for ($i=1; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_append_d_${TYPENAME}\">polynomial_${TYPENAME}_add_monomial_dui(double val, unsigned int order, polynomial_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	add a term with coefficient <code>val</code> (converted from a <code>double</code>) and exponent <code>order</code> (converted from an <code>unsigned int</code>) to the polynomial pointed to by <code>output</code>. Resize the polynomial if needed.
      </li>
      <br>
      <li id="func_polynomial_cpy">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_cpy_${TYPENAME}\">polynomial_${TYPENAME}_cpy(polynomial_${TYPENAME} input, polynomial_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	copy <code>input</code> to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <br>
      <li id="func_polynomial_cpy_noinit">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_cpy_noinit_${TYPENAME}\">polynomial_${TYPENAME}_cpy_noinit(polynomial_${TYPENAME} input, polynomial_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	copy <code>input</code> to the polynomial pointed to by <code>output</code>. Does not initialize <code>*output</code>, so <code>*output</code> must be initialized ahead of time, and its memory must be larger or equal to the length of <code>input</code>. Returns <code>LIBINUM_ERROR_SIZE_MISMATCH</code> if the memory of <code>*output</code> is smaller than the length of <code>input</code>.
      </li>
      <br>
      <li id="func_polynomial_add">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_add_${TYPENAME}\">polynomial_${TYPENAME}_add(polynomial poly1, polynomial_${TYPENAME} poly2, polynomial_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	add <code>poly1</code> and <code>poly2</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <br>
      <li id="func_polynomial_add_inplace">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_add_inplace_${TYPENAME}\">polynomial_${TYPENAME}_add_inplace(polynomial_${TYPENAME} poly1, polynomial_${TYPENAME}* poly2)</code>
	</div>
	    ");
	  }
	?>
	<br>
	add <code>poly1</code> and <code>*poly2</code> and write the result to the polynomial pointed to by <code>poly2</code>.
      </li>
      <br>
      <li id="func_polynomial_mul_scalar">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_mul_scalar_${TYPENAME}\">polynomial_${TYPENAME}_mul_scalar(${COEFTYPE} x, polynomial_${TYPENAME} poly, polynomial_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	multiply <code>x</code> and <code>poly</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <br>
      <li id="func_polynomial_mul_scalar_inplace">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_mul_scalar_inplace_${TYPENAME}\">polynomial_${TYPENAME}_mul_scalar_inplace(${COEFTYPE} x, polynomial_${TYPENAME}* poly)</code>
	</div>
	    ");
	  }
	?>
	<br>
	multiply <code>x</code> and <code>*poly</code> and write the result to the polynomial pointed to by <code>poly</code>.
      </li>
      <br>
      <li id="func_polynomial_mul_monomial">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_mul_monomial_${TYPENAME}\">polynomial_${TYPENAME}_mul_monomial(${COEFTYPE} x, ${EXPTYPE} order, polynomial_${TYPENAME} poly, polynomial_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	multiply <code>poly</code> and the monomial whose coefficient and exponent are <code>x</code> and <code>order</code>, and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <br>
      <li id="func_polynomial_mul_monomial_inplace">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_mul_monomial_inplace_${TYPENAME}\">polynomial_${TYPENAME}_mul_monomial_inplace(${COEFTYPE} x, ${EXPTYPE} order, polynomial_${TYPENAME}* poly)</code>
	</div>
	    ");
	  }
	?>
	<br>
	multiply <code>*poly</code> and the monomial whose coefficient and exponent are <code>x</code> and <code>order</code>, and write the result to the polynomial pointed to by <code>poly</code>.
      </li>
      <br>
      <li id="func_polynomial_mul">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_mul_${TYPENAME}\">polynomial_${TYPENAME}_mul(polynomial_${TYPENAME} poly1, polynomial_${TYPENAME} poly2, polynomial_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	multiply <code>poly1</code> and <code>poly2</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <br>
      <li id="func_polynomial_mul_inplace">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_mul_inplace_${TYPENAME}\">polynomial_${TYPENAME}_mul_inplace(polynomial_${TYPENAME} poly1, polynomial_${TYPENAME}* poly2)</code>
	</div>
	    ");
	  }
	?>
	<br>
	multiply <code>poly1</code> and <code>*poly2</code> and write the result to the polynomial pointed to by <code>poly2</code>.
      </li>
      <br>
      <li id="func_polynomial_derive">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_derive_${TYPENAME}\">polynomial_${TYPENAME}_derive(polynomial_${TYPENAME} poly, polynomial_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	derive <code>poly</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <br>
      <li id="func_polynomial_derive_inplace">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_derive_inplace_${TYPENAME}\">polynomial_${TYPENAME}_derive_inplace(polynomial_${TYPENAME}* poly)</code>
	</div>
	    ");
	  }
	?>
	<br>
	derive <code>*poly</code> and write the result to the polynomial pointed to by <code>poly</code>.
      </li>
      <br>
      <li id="func_polynomial_evaluate">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_evaluate_${TYPENAME}\">polynomial_${TYPENAME}_evaluate(${COEFTYPE}* out, ${COEFTYPE} x, polynomial_${TYPENAME} poly)</code>
	</div>
	    ");
	  }
	?>
	<br>
	evaluate <code>poly</code> at <code>x</code>, and write the result to  <code>out</code>. <code>out</code> must be initialized if its type requires it.
      </li>
      <br>
      <li id="func_polynomial_print">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_print_${TYPENAME}\">polynomial_${TYPENAME}_print(polynomial_${TYPENAME} poly)</code>
	</div>
	    ");
	  }
	?>
	<br>
	print <code>poly</code>.
      </li>
      <br>
      <li id="func_polynomial_legendre">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $COEFTYPENAME=$coeftypenames[$i];
	    $EXPTYPE=$exptypes[$i];
	    $EXPTYPENAME=$exptypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomial_legendre_${TYPENAME}\">polynomial_${TYPENAME}_legendre(unsigned int n, polynomial_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	compute the <code>n</code>-th Legendre polynomial, and write the output to the polynomial pointed to by <code>poly</code>. Initializes <code>*poly</code>.
      </li>
    </ul>

    <h3 class="subsection" id="subsec_polynomialMV"><code>polynomialMV</code></h3>
    <p>Multi-variable polynomials. A <code>polynomial</code> is represented as an array of coefficients and an array of arrays of indices, each of which represents a variable. For example, \(3x_1^2+x_1x_2\) is represented as <code>({3,1},{{1,1},{1,2}})</code>.</p>

    <?php
      $typenames=["int", "mpz"];
      $coeftypes=["int", "mpz_t"];
      $indextypes=["int", "int"];
      $indextypenames=["int", "int"];
    ?>

    <h4>Structure</h4>
    The coefficients of multi-variable polynomials can be integers or multiprecision integers, and the indices are integers. Multi-variable polynomials are represented as structures, with the following keys:
    <ul>
      <?php
	for ($i=0; $i<count($typenames); $i++){
	  $TYPENAME=$typenames[$i];
	  $COEFTYPE=$coeftypes[$i];
	  $INDEXTYPE=$indextypes[$i];
	  $INDEXTYPENAME=$indextypenames[$i];
	  print("
      <li id=\"struct_polynomialMV_${TYPENAME}\">
	<code>polynomialMV_${TYPENAME}</code>:
	<code>{ ${COEFTYPE}* coefficients, array_${INDEXTYPENAME} factors, unsigned int length, unsigned int memory }</code>
      </li>
	  ");
	}
      ?>
    </ul>
    where the keys correspond to
    <ul>
      <li><code>coefficients</code>: array of coefficients</li>
      <li><code>factors</code>: array of <i>factors</i>, i.e. arrays of indices of variables</li>
      <li><code>length</code>: the number of terms in the polynomial</li>
      <li><code>memory</code>: the number of terms allocated to the polynomial</li>
    </ul>
    <code>polynomialMV_*</code>'s must be initialized before they are used, and freed when they are no longer needed. When the polynomial is freed, its coefficients and factors are freed as well.

    <h4>Functions</h4>
    <ul>
      <li id="func_polynomialMV_init">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_init_${TYPENAME}\">polynomialMV_${TYPENAME}_init(polynomialMV_${TYPENAME}* poly, unsigned int memory)</code>
	</div>
	    ");
	  }
	?>
	<br>
	initialize the polynomial pointed to by <code>poly</code>, and allocate <code>memory</code> terms.
      </li>
      <br>
      <li id="func_polynomialMV_free">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_free_${TYPENAME}\">polynomialMV_${TYPENAME}_free(polynomialMV_${TYPENAME} poly)</code>
	</div>
	    ");
	  }
	?>
	<br>
	free the polynomial <code>poly</code>.
      </li>
      <br>
      <li id="func_polynomialMV_resize">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_resize_${TYPENAME}\">polynomialMV_${TYPENAME}_resize(polynomialMV_${TYPENAME}* poly, unsigned int newsize)</code>
	</div>
	    ");
	  }
	?>
	<br>
	copy the array polynomial to by <code>poly</code> to another with memory <code>newsize</code>.
      </li>
      <br>
      <li id="func_polynomialMV_cpy">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_cpy_${TYPENAME}\">polynomialMV_${TYPENAME}_cpy(polynomialMV_${TYPENAME} input, polynomialMV_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	copy <code>input</code> to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <br>
      <li id="func_polynomialMV_cpy_noinit">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_cpy_noinit_${TYPENAME}\">polynomialMV_${TYPENAME}_cpy_noinit(polynomialMV_${TYPENAME} input, polynomialMV_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	copy <code>input</code> to the polynomial pointed to by <code>output</code>. Does not initialize <code>*output</code>, so <code>*output</code> must be initialized ahead of time, and its memory must be larger or equal to the length of <code>input</code>. Returns <code>LIBINUM_ERROR_SIZE_MISMATCH</code> if the memory of <code>*output</code> is smaller than the length of <code>input</code>.
      </li>
      <br>
      <li id="func_polynomialMV_append">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_append_${TYPENAME}\">polynomialMV_${TYPENAME}_append(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	add a term with coefficient <code>coef</code> and factor <code>factor</code> to the polynomial pointed to by <code>output</code>. Resize the polynomial if needed.
      </li>
      <br>
      <li id="func_polynomialMV_append_inplace">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_append_inplace_${TYPENAME}\">polynomialMV_${TYPENAME}_append_inplace(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	same as <a href="#func_polynomialMV_append"><code>polynomialMV_*_append</code></a> except that if the factor is already present in the polynomial pointed to by <code>output</code>, then add <code>coef</code> to the coefficient of that factor, instead of appending it to the end of the polynomial. Resize the polynomial if needed.
      </li>
      <br>
      <li id="func_polynomialMV_append_noinit">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_append_noinit_${TYPENAME}\">polynomialMV_${TYPENAME}_append_noinit(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	same as <a href="#func_polynomialMV_append"><code>polynomialMV_*_append</code></a> except that the new factor and coefficient to be appended to the polynomial pointed to by <code>output</code> are not allocated. Instead, pointers to <code>factor</code> and <code>coef</code> are appended. <code>factor</code> and <code>coef</code> must therefore not be freed (since they will be freed when <code>output</code> is). Resize the polynomial if needed.
      </li>
      <br>
      <li id="func_polynomialMV_append_noinitfactor">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_append_noinitfactor_${TYPENAME}\">polynomialMV_${TYPENAME}_append_noinitfactor(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	same as <a href="#func_polynomialMV_append"><code>polynomialMV_*_append</code></a> except that the new factor to be appended to the polynomial pointed to by <code>output</code> is not allocated. Instead, a pointer to <code>factor</code> is appended. <code>factor</code> must therefore not be freed (since it will be freed when <code>output</code> is). <code>coef</code> is, however, copied and must be freed. Resize the polynomial if needed.
      </li>
      <br>
      <li id="func_polynomialMV_append_noinit_inplace">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_append_noinit_inplace_${TYPENAME}\">polynomialMV_${TYPENAME}_append_noinit_inplace(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomial* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	same as <a href="#func_polynomialMV_append_noinit"><code>polynomialMV_*_append_noinit</code></a> except that if the factor is already present in the polynomial pointed to by <code>output</code>, then add <code>coef</code> to the coefficient of that factor, instead of appending it to the end of the polynomial. Resize the polynomial if needed.
      </li>
      <br>
      <li id="func_polynomialMV_append_noinitfactor_inplace">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_append_noinitfactor_inplace_${TYPENAME}\">polynomialMV_${TYPENAME}_append_noinit_inplace(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomial* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	same as <a href="#func_polynomialMV_append_noinitfactor"><code>polynomialMV_*_append_noinitfactor</code></a> except that if the factor is already present in the polynomial pointed to by <code>output</code>, then add <code>coef</code> to the coefficient of that factor, instead of appending it to the end of the polynomial. Resize the polynomial if needed.
      </li>
      <br>
      <li id="func_polynomialMV_add">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_add_${TYPENAME}\">polynomialMV_${TYPENAME}_add(polynomialMV_${TYPENAME} poly1, polynomialMV_${TYPENAME} poly2, polynomialMV_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	add <code>poly1</code> and <code>poly2</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <br>
      <li id="func_polynomialMV_add_inplace">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_add_inplace_${TYPENAME}\">polynomialMV_${TYPENAME}_add_inplace(polynomialMV_${TYPENAME} poly1, polynomialMV_${TYPENAME}* poly2)</code>
	</div>
	    ");
	  }
	?>
	<br>
	add <code>poly1</code> and <code>*poly2</code> and write the result to the polynomial pointed to by <code>poly2</code>.
      </li>
      <br>
      <li id="func_polynomialMV_multiply_scalar">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_multiply_scalar_${TYPENAME}\">polynomialMV_${TYPENAME}_multiply_scalar(polynomial poly, ${COEFTYPE} num)</code>
	</div>
	    ");
	  }
	?>
	<br>
	multiply <code>num</code> and <code>poly</code> and write the result to <code>poly</code>.
      </li>
      <br>
      <li id="func_polynomialMV_prod">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_prod_${TYPENAME}\">polynomialMV_${TYPENAME}_prod(polynomialMV_${TYPENAME} poly1, polynomialMV_${TYPENAME} poly2, polynomialMV_${TYPENAME}* output)</code>
	</div>
	    ");
	  }
	?>
	<br>
	multiply <code>poly1</code> and <code>poly2</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
      </li>
      <br>
      <li id="func_polynomialMV_order">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_order_${TYPENAME}\">polynomialMV_${TYPENAME}_order(polynomialMV_${TYPENAME} poly)</code>
	</div>
	    ");
	  }
	?>
	<br>
	order the factors in <code>poly</code>, using <a href="#func_array_sort">array_*_sort</a>.
      </li>
      <br>
      <li id="func_polynomialMV_print">
	<?php
	  for ($i=0; $i<count($typenames); $i++){
	    $TYPENAME=$typenames[$i];
	    $COEFTYPE=$coeftypes[$i];
	    $INDEXTYPE=$indextypes[$i];
	    $INDEXTYPENAME=$indextypenames[$i];
	    print("
	<div style=\"margin-bottom:5pt\">
	  <code id=\"func_polynomialMV_print_${TYPENAME}\">polynomialMV_${TYPENAME}_print(polynomialMV_${TYPENAME} poly)</code>
	</div>
	    ");
	  }
	?>
	<br>
	print <code>poly</code>.
      </li>
    </ul>


    <h3 class="subsection" id="subsec_functions">Functions</h3>
    <p>
      Functions are not, strictly speaking, a C type. Instead, in this section, we describe how functions whose pointers are to be passed to the various algorithms of <b>libinum</b>, should be formatted.
    </p>

    <p>
      Functions must take 3 arguments, and return an integer (a return code):
      <code class="codeblock">int f(TYPE* out, TYPE in, void* extra_args)</code>
      where <code>TYPE</code> is the appropriate data type, e.g. <code>double</code> or <code>mpfr_t</code>. <code>in</code> is the argument of the function, <code>out</code> is made to point to \(f(\)<code>in</code>\()\), and <code>extra_args</code> is a pointer to void, which may contain extra arguments to be passed to the function, for example a parameter that the function depends on. For example, to implement the function \(f_\alpha(x)=x^\alpha\) using MPFR floats,
      <code class=codeblock>
<pre>
int f(mpfr_t out, mpfr_t in, void* extra_args){
  int alpha=*((*int)extra_args);
  mpfr_pow_ui(out, in, alpha, MPFR_RNDN);
  return(0);
}
</pre>
      </code>
    </p>

    <h2 class="section" id="sec_utilities">Utilities</h2>
    <p>
      In addition, the following functions are defined
    </p>
    <ul>
      <li id="func_fprint_double">
	<code>fprint_double(FILE* file, double x)</code><br>
	print <code>x</code> to <code>file</code>, with as many digits as possible.
      </li>
      <li id="func_fprint_ldouble">
	<code>fprint_ldouble(FILE* file, long double x)</code><br>
	print <code>x</code> to <code>file</code>, with as many digits as possible.
      </li>
      <li id="func_fprint_mpfr">
	<code>fprint_mpfr(FILE* file, mpfr_t x)</code><br>
	print <code>x</code> to <code>file</code>, with as many digits as allowed by the MPFR precision.
      </li>
      <li id="func_print_datatype_info">
	<code>print_datatype_info()</code><br>
	print miscellaneous information about integers and floats. Namely, the number of bits used in <code>char</code>, <code>short int</code>, <code>int</code>, <code>long int</code> and <code>long long int</code>; the precision and maximal and minimal exponents of <code>double</code> and <code>long double</code>; the type used to store the precision and emax of MPFR floats.
      </li>
    </ul>


    <h2 class="section" id="sec_examples">Examples</h2>
    <p>
      Examples of programs using <b>libinum</b> are provided with the source code, in the <code>doc/libinum-examples</code> directory. If <b>libinum</b> is installed on the filesystem, then the examples can also be found at <code>/usr/share/doc/libinum/libinum-examples</code>.
    </p>


    <h2 class="section" id="sec_authors">Authors</h2>
    <p>
      <b>libinum</b> was written by Ian Jauslin.
    </p>
  </body>
</html>