File: SLIP_LU_UserGuide.tex

package info (click to toggle)
suitesparse 1%3A5.12.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 176,720 kB
  • sloc: ansic: 1,193,914; cpp: 31,704; makefile: 6,638; fortran: 1,927; java: 1,826; csh: 765; ruby: 725; sh: 529; python: 333; perl: 225; sed: 164; awk: 35
file content (2130 lines) | stat: -rw-r--r-- 92,030 bytes parent folder | download | duplicates (2)
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
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
\documentclass[12pt]{article}
\usepackage{amsmath,amssymb,amsthm,latexsym,paralist,comment}
\usepackage{graphicx}
\usepackage{psfrag}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{cprotect}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}
\usepackage[hidelinks]{hyperref}
\usepackage{framed}
\usepackage{mdframed}
\hypersetup{
       colorlinks = true,
       citecolor = blue,
       linkcolor = blue,
       urlcolor = Maroon
}
\usepackage{geometry}
\theoremstyle{definition}

\newcommand{\N}{\mathbf{N}}
\newcommand{\R}{\mathbf{R}}
\newcommand{\Z}{\mathbf{Z}}
\newcommand{\import}{\textcolor{red}{\textbf{**IMPORTANT**}}}

\begin{document}

\begin{center}
\begin{large}
\textbf{User Guide for SLIP LU, A Sparse Left-Looking Integer
Preserving LU Factorization} \\
\vspace{5mm}
Version 1.0.2, July 14, 2020 % VERSION
\vspace{20mm}

Christopher Lourenco, Jinhao Chen, \\ Erick Moreno-Centeno, Timothy A. Davis \\

Texas A\&M University

\vspace{20mm}
Contact Information: Contact Chris Lourenco, \href{mailto:chrisjlourenco@gmail.com}{chrisjlourenco@gmail.com}, or Tim Davis,
\href{mailto:timdavis@aldenmath.com}{timdavis@aldenmath.com},
\href{mailto:davis@tamu.edu}{davis@tamu.edu},
\href{DrTimothyAldenDavis@gmail.com}{DrTimothyAldenDavis@gmail.com}

\end{large}
\end{center}

\newpage
\tableofcontents

\newpage

%-------------------------------------------------------------------------------
\section{Overview}
\label{s:intro}
%-------------------------------------------------------------------------------

SLIP LU is a software package designed to exactly solve unsymmetric sparse
linear systems, $ A x = b$, where $A \in \mathbb{Q}^{n \times
n}$, $b \in \mathbb{Q}^{n \times r}$, and $x \in \mathbb{Q}^{n \times
r}$. This package performs a left-looking, roundoff-error-free (REF) LU
factorization $P A Q = L D U$, where $L$ and $U$ are integer, $D$ is diagonal,
and $P$ and $Q$ are row and column permutations, respectively. 
Note that the matrix $D$ is never explicitly computed nor needed; thus this 
package uses only the matrices $L$ and $U$. The theory associated with this code 
is the Sparse Left-looking Integer-Preserving (SLIP) LU factorization
 \cite{lourenco2019exact}. Aside from
solving sparse linear systems exactly, one of the key goals of this package is
to provide a framework for other solvers to benchmark the reliability and
stability of their linear solvers, as our final solution vector $x$ is
guaranteed to be exact. In addition, SLIP LU provides a wrapper class for the
GNU Multiple Precision Arithmetic (GMP) \cite{granlund2015gnu} and GNU Multiple
Precision Floating Point Reliable (MPFR) \cite{fousse2007mpfr} libraries in
order to prevent memory leaks and improve the overall stability of these
external libraries. SLIP LU is written in ANSI C and is accompanied by a MATLAB
interface.

For all primary computational routines in Section \ref{s:primary}, the input
argument $A$ must be stored in a compressed sparse column (CSC) matrix with
entries in \verb|mpz_t| type (referred to as CSC \verb|mpz_t| matrix
henceforth), while $b$ must be stored as a dense \verb|mpz_t| matrix (i.e., a
dense matrix with entries in \verb|mpz_t| type).  However, the original data
type of entries in the input matrix $A$ and right hand side (RHS)
vectors $b$ can be any one of: \verb|double|, \verb|int64_t|, \verb|mpq_t|,
\verb|mpz_t|, or \verb|mpfr_t|, and their format(s) are allowed to be 
CSC, sparse triplet or dense. A discussion of how to use these
matrix formats and data types in the \verb|SLIP_matrix|, and to
perform conversions between matrix types and formats
in Section \ref{ss:populate_Ab}.

The matrices $L$ and $U$ are computed using integer-preserving
routines with the big integer (\verb|mpz_t|) data types from the GMP Library
\cite{granlund2015gnu}. The matrices $L$ and $U$ are computed one column at a
time, where each column is computed via the sparse REF triangular solve
detailed in \cite{lourenco2019exact}. All divisions performed in the algorithm
are guaranteed to be exact (i.e., integer); therefore, no greatest common
divisor algorithms are needed to reduce the size of entries.

The permutation matrices $P$ and $Q$ define the pivot ordering; $Q$ is the
fill-reducing column ordering, and $P$ is determined dynamically during the
factorization.  For the matrix $P$, the default option is to use a partial
pivoting scheme in which the diagonal entry in column $k$ is selected if it is
the same magnitude as the smallest entry of $k$-th column, otherwise the
smallest entry is selected as the $k$-th pivot. In addition to this approach,
the code allows diagonal pivoting, partial pivoting which selects the largest
pivot, or various tolerance based diagonal pivoting schemes. For the matrix
$Q$, the default ordering is the Column Approximate Minimum Degree (COLAMD)
algorithm \cite{davis2004algorithmcolamd,davis2004column}. Other approaches
include using the Approximate Minimum Degree (AMD) ordering
\cite{amestoy1996approximate,amestoy2004algorithmamd}, or no ordering ($Q=I$).
A discussion of how to select these permutations prior to factorization is
given in Section \ref{s:primary}.

Once the factorization $L D U = P A Q $ is computed, the solution vector 
$x$ is computed via sparse REF forward and backward substitution. 
The forward substitution is a variant of the sparse REF triangular solve 
discussed above. The backward substitution is a typical column oriented 
sparse backward substitution. Both of these routines require $b$ 
stored as a dense \verb|mpz_t| matrix. At the conclusion of the forward and 
backward substitution routines, the final solution vector(s) $x$ 
are guaranteed to be exact.  The solution $x$ is returned as a dense
\verb|mpq_t| matrix.

Using the SLIP matrix copy function, any matrix in any of the 15 combinations
of the set (CSC, triplet, dense) $\times$ (\verb|mpz_t|, \verb|mpq_t| ,
\verb|mpfr_t|, \verb|int64_t|, or \verb|double|), can be copied and converted
into any one of the 15 combinations.

One key advantage of utilizing SLIP LU with floating-point output is that the
solution is guaranteed to be exact until this final conversion; meaning that
roundoff errors are only introduced in the final conversion from rational
numbers. Thus, the solution $x$ output in \verb|double| precision are accurate
to machine roundoff (approximately $10^{-16}$) and SLIP LU utilizes higher
precision for the MPFR output; thus it is also accurate to user-specified
precision.

Most routines expect the input sparse matrix $A$ to be stored in CSC format.
This data structure stores the matrix $A$ as a sequence of three arrays:

\begin{itemize}
\item
\verb|A->p|: Column pointers; an array of size \verb|n+1|. The row indices of
column $j$ are located in positions \verb|A->p[j]| to \verb|A->p[j+1]-1| of the
array \verb|A->i|. Data type: \verb|int64_t|.

\item
\verb|A->i|: Row indices; an array of size equal to the number of entries in
the matrix. The entry \verb|A->i[k]| is the row index of the $k$th nonzero in
the matrix. Data type: \verb|int64_t|.

\item
\verb|A->x|: Numeric entries. The entry \verb|A->x[k]| is the numeric value of
the $k$th nonzero in the matrix.  The array \verb|A->x| has a union type, and
must be accessed via a suffix according to the type of \verb|A|.  For details,
see Section~\ref{ss:SLIP_matrix}.

\end{itemize}

An example matrix $A$ with \verb|mpz_t| type is stored as follows (notice that
via C convention, the indexing is zero based).
\[
A = \begin{bmatrix}
1 & 0 & 0 & 1 \\
2 & 0 & 4 & 12 \\
7 & 1 & 1 & 1 \\
0 & 2 & 3 & 0 \\
\end{bmatrix}
\]

\begin{verbatim}
A->p     = [0, 3, 5, 8, 11]
A->i     = [0, 1, 2, 2, 3, 1, 2, 3, 0,  1, 2]
A->x.mpz = [1, 2, 7, 1, 2, 4, 1, 3, 1, 12, 1]
\end{verbatim}

For example, the last column appears in positions 8 to 10 of \verb|A->i| and
\verb|A->x.mpz|, with row indices 0, 1, and 2, and values $a_{03}=1$,
$a_{13}=12$, and $a_{23}=1$.

%-------------------------------------------------------------------------------
\section{Availability}
%-------------------------------------------------------------------------------

\textbf{Copyright:} This software is copyright by Christopher Lourenco, Jinhao
Chen, Erick Moreno-Centeno, and Timothy Davis.

\noindent \textbf{Contact Info:} Contact Chris Lourenco,
\href{mailto:chrisjlourenco@gmail.com}{chrisjlourenco@gmail.com}, or Tim Davis,
\href{mailto:timdavis@aldenmath.com}{timdavis@aldenmath.com},
\href{mailto:davis@tamu.edu}{davis@tamu.edu}, or
\href{DrTimothyAldenDavis@gmail.com}{DrTimothyAldenDavis@gmail.com}

\noindent \textbf{License:} This software package is dual licensed under the
GNU General Public License version 2 or the GNU Lesser General Public License
version 3. Details of this license are in \verb|SLIP_LU/License/license.txt|.
For alternative licenses, please contact the authors.

\noindent \textbf{Location:} \url{https://github.com/clouren/SLIP_LU} and
\url{www.suitesparse.com}

\noindent \textbf{Required Packages:} SLIP LU requires the installation of AMD
\cite{amestoy1996approximate,amestoy2004algorithmamd}, COLAMD
\cite{davis2004column,davis2004algorithmcolamd}, \verb|SuiteSparse_config|
\cite{davis2020suitesparse}, the GNU GMP \cite{granlund2015gnu} and GNU MPFR
\cite{fousse2007mpfr} libraries.  AMD and COLAMD are available under a BSD
3-clause license, and no license restrictions apply to
\verb|SuiteSparse_config|.  Notice that AMD, COLAMD, and
\verb|SuiteSparse_config| are included in this distribution for
convenience. The GNU GMP and GNU MPFR library can be acquired and installed
from \url{https://gmplib.org/} and \url{http://www.mpfr.org/} respectively.

With a Debian/Ubuntu based Linux system, a compatible version of GMP and MPFR
can be installed with the following terminal commands:

{\small
\begin{verbatim}
    sudo apt-get install libgmp3-dev
    sudo apt-get install libmpfr-dev libmpfr-doc libmpfr4 libmpfr4-dbg
\end{verbatim} }

%-------------------------------------------------------------------------------
\section{Installation} \label{s:install}
%-------------------------------------------------------------------------------

Installation of SLIP LU requires the \verb|make| utility in Linux/MacOS, or
\verb|Cygwin make| in Windows. With the proper compiler, typing \verb|make|
under the main directory will compile AMD, COLAMD and SLIP LU to the respective
\verb|SLIP_LU/Lib| folder. To further install the libraries onto your computer,
simply type \verb|make install|.  Thereafter, to use the code inside of your
program, precede your code with \verb|#include "SLIP_LU.h"|.

To run the statement coverage tests, go to the \verb|Tcov| folder and
type \verb|make|.  The last line of output should read:

\begin{verbatim}
    statments not yet tested: 0
\end{verbatim}

If you want to use SLIP LU within MATLAB, from your installation of MATLAB,
\verb|cd| to the folder \verb|SLIP_LU/SLIP_LU/MATLAB| then type
\verb|SLIP_install|. This should compile the necessary code so that you can use
the \verb|SLIP_backslash| function from within MATLAB. Note that
\verb|SLIP_install| does not add the correct directory to your path; therefore,
if you want to use \verb|SLIP_backslash| in future sessions, type
\verb|pathtool| and save your path for future MATLAB sessions. If you cannot
save your path because of file permissions, edit your \verb|startup.m| by
adding \verb|addpath| commands (type \verb|doc startup| and \verb|doc addpath|
for more information).

%-------------------------------------------------------------------------------
\section{Managing the SLIP LU environment} \label{s:user:setup}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_LU_VERSION|: the software package version}
%-------------------------------------------------------------------------------

SLIP LU defines the following strings with \verb|#define|. Refer to
the \verb|SLIP_LU.h| file for details.

%----------------------------------------
\begin{center}
\begin{tabular}{ll}
\hline
Macro & purpose \\
\hline
\verb|SLIP_LU_VERSION|       & current version of the code (as a string)\\
\verb|SLIP_LU_VERSION_MAJOR| & major version of the code\\
\verb|SLIP_LU_VERSION_MINOR| & minor version of the code   \\
\verb|SLIP_LU_VERSION_SUB|   & sub version of the code\\
\hline
\end{tabular}
\end{center}

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_info|: status code returned by SLIP LU}
\label{ss:SLIP_info}
%-------------------------------------------------------------------------------

Most SLIP LU functions return their status to the caller as their return value,
an enumerated type called \verb|SLIP_info|. All current possible values for
\verb|SLIP_info| are listed as follows:

\begin{center}
\begin{tabular}{rll}
\hline
    0& \verb|SLIP_OK|& The function was successfully executed.\\
\hline
    -1& \verb|SLIP_OUT_OF_MEMORY|& out of memory\\
\hline
    -2& \verb|SLIP_SINGULAR|& The input matrix $A$ is exactly singular.\\
\hline
    -3& \verb|SLIP_INCORRECT_INPUT|& One or more input arguments are incorrect.\\
\hline
    -4& \verb|SLIP_INCORRECT|& The solution is incorrect.\\
\hline
    -5& \verb|SLIP_PANIC| & SLIP LU environment error \\
\hline
\end{tabular}
\end{center}

Either \verb|SLIP_initialize| or \verb|SLIP_initialize_expert| (but not both)
must be called prior to using any other SLIP LU function.  \verb|SLIP_finalize|
must be called as the last SLIP LU function.

Subsequent SLIP LU sessions can be restarted after a call to
\verb|SLIP_finalize|, by calling either \verb|SLIP_initialize| or
\verb|SLIP_initialize_expert| (but not both), followed by a final call to
\verb|SLIP_finalize| when finished.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_initialize|: initialize the working environment}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_initialize
    (
        void
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_initialize| initializes the working environment for SLIP LU
functions.  SLIP LU utilizes a specialized memory management scheme in order to
prevent potential memory failures caused by GMP and MPFR libraries.  Either
this function or \verb|SLIP_initialize_expert| must be called prior to using
any other function in the library.  Returns \verb|SLIP_PANIC| if SLIP LU has
already been initialized, or \verb|SLIP_OK| if successful.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_initialize_expert|: initialize environment
(expert version)}\label{ss:SLIP_initialize_expert}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_initialize_expert
    (
        void* (*MyMalloc) (size_t),             // user-defined malloc
        void* (*MyCalloc) (size_t, size_t),     // user-defined calloc
        void* (*MyRealloc) (void *, size_t),    // user-defined realloc
        void  (*MyFree) (void *)                // user-defined free
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_initialize_expert| is the same as \verb|SLIP_initialize| except that
it allows for a redefinition of custom memory functions that are used for SLIP
LU and GMP/MPFR.  The four inputs to this function are pointers to four
functions with the same signatures as the ANSI C \verb'malloc', \verb'calloc',
\verb'realloc', and \verb'free' functions.  That is:

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    #include <stdlib.h>
    void *malloc (size_t size) ;
    void *calloc (size_t nmemb, size_t size) ;
    void *realloc (void *ptr, size_t size) ;
    void free (void *ptr) ;
\end{verbatim}
} \end{mdframed}

Returns \verb|SLIP_PANIC| if SLIP LU has already been initialized,
or \verb|SLIP_OK| if successful.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_finalize|: free the working environment}
\label{ss:SLIP_finalize}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_finalize
    (
        void
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_finalize| finalizes the working environment for SLIP LU
library, and frees any internal workspace created by SLIP LU.  It must be
called as the last \verb|SLIP_*| function called, except that a subsequent
call to \verb|SLIP_initialize*| may be used to start another SLIP LU session.
Returns \verb|SLIP_PANIC| if SLIP LU has not been initialized,
or \verb|SLIP_OK| if successful.

%-------------------------------------------------------------------------------
\section{Memory Management} \label{s:user:memmanag}
%-------------------------------------------------------------------------------

The routines in this section are used to allocate and free memory for the data
structures used in SLIP LU.  By default, SLIP LU relies on the SuiteSparse
memory management functions, \verb|SuiteSparse_malloc|,
\verb|SuiteSparse_calloc|, \verb|SuiteSparse_realloc|, and
\verb|SuiteSparse_free|.  By default, those functions rely on the ANSI C
\verb|malloc|, \verb|calloc|, \verb|realloc|, and \verb|free|, but this may be
changed by initializing the SLIP LU environment with
\verb|SLIP_initialize_expert|.

%-------------------------------------------------------------------------------
\newpage
\cprotect\subsection{\verb|SLIP_calloc|: allocate initialized memory}
\label{ss:SLIP_calloc}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    void *SLIP_calloc 
    ( 
        size_t nitems,      // number of items to allocate 
        size_t size         // size of each item 
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_calloc| allocates a block of memory for an array of \verb|nitems|
elements, each of them \verb|size| bytes long, and initializes all its bits to
zero. If any input is less than 1, it is treated as if equal to 1. If the
function failed to allocate the requested block of memory, then a \verb|NULL|
pointer is returned.
Returns \verb|NULL| if SLIP LU has not been initialized.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_malloc|: allocate uninitialized memory}
\label{ss:SLIP_malloc}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    void *SLIP_malloc
    (
        size_t size        // size of memory space to allocate
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_malloc| allocates a block of \verb|size| bytes of memory, returning
a pointer to the beginning of the block. The content of the newly allocated
block of memory is not initialized, remaining with indeterminate values.
If \verb|size| is less than 1, it is treated as if equal to 1. If the function
fails to allocate the requested block of memory, then a \verb|NULL| pointer is
returned.
Returns \verb|NULL| if SLIP LU has not been initialized.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_realloc|: resize allocated memory}
\label{ss:SLIP_realloc}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    void *SLIP_realloc      // pointer to reallocated block, or original block
                            // if the realloc failed
    (
        int64_t nitems_new,     // new number of items in the object
        int64_t nitems_old,     // old number of items in the object
        size_t size_of_item,    // sizeof each item
        void *p,                // old object to reallocate
        bool *ok                // true if success, false on failure
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_realloc| is a wrapper for realloc.  If \verb|p| is non-\verb|NULL| on
input, it points to a previously allocated object of size \verb|nitems_old|
$\times$ \verb|size_of_item|.  The object is reallocated to be of size
\verb|nitems_new| $\times$ \verb|size_of_item|.  If \verb|p| is \verb|NULL| on input,
then a new object of that size is allocated.  On success, a pointer to the new
object is returned.  Returns \verb|ok| as \verb|false| if SLIP LU has not been
initialized.

If the reallocation fails, \verb|p| is not modified, and \verb|ok| is returned
as \verb|false| to indicate that the reallocation failed.  If the size
decreases or remains the same, then the method always succeeds (\verb|ok| is
returned as \verb|true|), unless SLIP LU has not been initialized.

Typical usage:  the following code fragment allocates an array of 10
\verb|int|'s, and then increases the size of the array to 20 \verb|int|'s.  If
the \verb|SLIP_malloc| succeeds but the \verb|SLIP_realloc| fails, then the
array remains unmodified, of size 10.

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
     int *p ;
     p = SLIP_malloc (10 * sizeof (int)) ;
     if (p == NULL) { error here ... }
     printf ("p points to an array of size 10 * sizeof (int)\n") ;
     bool ok ;
     p = SLIP_realloc (20, 10, sizeof (int), p, &ok) ;
     if (ok) printf ("p has size 20 * sizeof (int)\n") ;
     else printf ("realloc failed; p still has size 10 * sizeof (int)\n") ;
     SLIP_free (p) ;
\end{verbatim}
} \end{mdframed}

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_free|: free allocated memory}
\label{ss:SLIP_free}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    void SLIP_free
    (
        void *p         // Pointer to memory space to free
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_free| deallocates the memory previously allocated by a call to
\verb|SLIP_calloc|, \verb|SLIP_malloc|, or \verb|SLIP_realloc|.  If \verb|p| is
\verb|NULL| on input, then no action is taken (this is not an error condition).
To guard against freeing the same memory space twice, the following macro
\verb|SLIP_FREE| is provided, which calls \verb|SLIP_free| and then sets the
freed pointer to \verb|NULL|.

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    #define SLIP_FREE(p)                        \
    {                                           \
        SLIP_free (p) ;                         \
        (p) = NULL ;                            \
    }
\end{verbatim}
} \end{mdframed}

No action is taken if SLIP LU has not been initialized.

%-------------------------------------------------------------------------------
\cprotect\section{The \verb|SLIP_options| object:
parameter settings for SLIP LU} \label{ss:SLIP_options}
%-------------------------------------------------------------------------------

The \verb|SLIP_options| object contains numerous parameters that may be
modified to change the behavior of the SLIP LU functions.  Default values of
these parameters will lead to good performance in most cases.  Modifying this
struct provides control of column orderings, pivoting schemes, and other
components of the factorization.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_pivot|: enum for pivoting schemes}
\label{ss:SLIP_pivot}
%-------------------------------------------------------------------------------

There are six available pivoting schemes provided in SLIP LU that can be
selected with the \verb|SLIP_options| structure.  If the matrix is non-singular
(in an exact sense), then the pivot is always nonzero, and is chosen as the
{\em smallest} nonzero entry, with the smallest magnitude.  This may seem
counter-intuitive, but selecting a small nonzero pivot leads to smaller growth
in the number of digits in the entries of \verb|L| and \verb|U|.  This choice
does not lead to any kind of numerical inaccuracy, since SLIP LU is guaranteed
to find an exact roundoff-error free factorization of a non-singular matrix
(unless it runs out of memory), for any nonzero pivot choice.

The pivot tolerance for two of the pivoting schemes is specified by the
\verb|tol| component in \verb|SLIP_options|.  The pivoting schemes are as
follows:

%----------------------------------------
{\small
\begin{center}
\begin{tabular}{llp{4in}}
\hline
0 & \verb|SLIP_SMALLEST|        & The $k$-th pivot is selected as the smallest
                                  entry in the $k$-th column.\\
\hline
1 & \verb|SLIP_DIAGONAL|        & The $k$-th pivot is selected as the diagonal
                                  entry. If the diagonal entry is zero,
                                  this method instead selects the smallest
                                  pivot in the column.\\
\hline
2 & \verb|SLIP_FIRST_NONZERO|   & The $k$-th pivot is selected as the first
                                  eligible nonzero in the column. \\
\hline
3 & \verb|SLIP_TOL_SMALLEST|    & The $k$-th pivot is selected as the diagonal
                                  entry if the diagonal is within a
                                  specified tolerance of the smallest entry in
                                  the column. Otherwise, the smallest
                                  entry in the $k$-th column is selected.
                                  This is the default pivot selection
                                  strategy. \\
\hline
4 & \verb|SLIP_TOL_LARGEST|     & The $k$-th pivot is selected as the diagonal
                                  entry if the diagonal is within a
                                  specified tolerance of the largest entry in
                                  the column.  Otherwise, the largest
                                  entry in the $k$-th column is selected. \\
\hline
5 & \verb|SLIP_LARGEST|         & The $k$-th pivot is selected as the largest
                                  entry in the $k$-th column. \\
\hline
\end{tabular}
\end{center}
}

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_col_order|: enum for column ordering schemes}
\label{ss:SLIP_col_order}
%-------------------------------------------------------------------------------

The SLIP LU library provides three column ordering schemes: no pre-ordering,
COLAMD, and AMD, selected via the \verb|order|
component in the \verb|SLIP_options| structure described in Section
\ref{ss:SLIP_options_struct}.

{\small
\begin{center}
\begin{tabular}{llp{4in}}
\hline
0 & \verb|SLIP_NO_ORDERING| & No pre-ordering is performed on the matrix $A$,
                              that is $Q = I$. \\
\hline
1 & \verb|SLIP_COLAMD|      & The columns of $A$ are permuted prior to
                              factorization using the COLAMD
                              \cite{davis2004algorithmcolamd} ordering.
                              This is the default ordering. \\
\hline
2 & \verb|SLIP_AMD|         & The nonzero pattern of $A + A^T$ is analyzed and
                              the columns of $A$ are permuted prior to
                              factorization based on the AMD
                              \cite{amestoy2004algorithmamd} ordering of
                              $A+A^T$. This works well if $A$ has a mostly
                              symmetric pattern, but tends to be worse
                              than COLAMD on matrices with unsymmetric pattern.
                              \cite{davis2004column}.\\
\hline
\end{tabular}
\label{tab:SLIP_pivot}
\end{center}
}

%-------------------------------------------------------------------------------
\cprotect\subsection{ \verb|SLIP_options| structure}
\label{ss:SLIP_options_struct}
%-------------------------------------------------------------------------------

The \verb|SLIP_options| struct stores key command parameters for various
functions used in the SLIP LU package. The \verb|SLIP_options* option| struct
contains the following components:

\begin{itemize}
\item
\verb|option->pivot|: An enum \verb|SLIP_pivot| type (discussed in Section
\ref{ss:SLIP_pivot}) which controls the type of pivoting used. Default value:
\verb|SLIP_TOL_SMALLEST| (3).

\item
\verb|option->order|: An enum \verb|SLIP_col_order| type (discussed in Section
\ref{ss:SLIP_col_order}) which controls what column ordering is used. Default
value: \verb|SLIP_COLAMD| (1).

\item
\verb|option->tol|: A \verb|double| tolerance for
the tolerance-based pivoting scheme, i.e., \verb|SLIP_TOL_SMALLEST| or
\verb|SLIP_TOL_LARGEST|. \verb|option->tol| must be in the range of $(0,1]$.
Default value: 1 meaning that the diagonal entry will be selected if it has the
same magnitude as the smallest entry in the $k$ the column.

\item
\verb|option->print_level|: An \verb|int| which controls the amount of
output:
0: print nothing, 1: just errors, 2: terse, with basic stats from
COLAMD/AMD and SLIP, 3: all, with matrices and results. Default value: 0.

\item
\verb|option->prec|: An \verb|int32_t| which specifies the precision used
for multiple precision floating point numbers, (i.e., MPFR). This
can be any integer larger than \verb|MPFR_PREC_MIN| (value of 1 in MPFR 4.0.2
and 2 in some legacy versions) and smaller than \verb|MPFR_PREC_MAX| (usually
the largest possible integer available in your system). Default value: 128
(quad precision).

\item
\verb|option->round|: A \verb|mpfr_rnd_t| which determines the type
of MPFR rounding to be used by SLIP LU. This is a parameter of the MPFR
library. The options for this parameter are:

    \begin{itemize}
        \item \verb|MPFR_RNDN|: round to nearest
            (roundTiesToEven in IEEE 754-2008)
        \item \verb|MPFR_RNDZ|: round toward zero
            (roundTowardZero in IEEE 754-2008)
        \item \verb|MPFR_RNDU|: round toward plus infinity
            (roundTowardPositive in IEEE 754-2008)
        \item \verb|MPFR_RNDD|: round toward minus infinity
            (roundTowardNegative in IEEE 754-2008)
        \item \verb|MPFR_RNDA|: round away from zero
        \item \verb|MPFR_RNDF|: faithful rounding. This is not stable.
    \end{itemize}

\noindent Refer to the MPFR User Guide available at
\url{https://www.mpfr.org/mpfr-current/mpfr.pdf} for details on the MPFR
rounding style and any other utilized MPFR convention. Default value:
\verb|MPFR_RNDN|.

\item
\verb|option->check|: A \verb|bool| which indicates whether the solution to the
system should be checked. Intended for debugging only; the SLIP LU library is
guaranteed to return the exact solution. Default value: \verb|false|.

\end{itemize}

All SLIP LU routines except basic memory management routines in Sections
\ref{ss:SLIP_finalize}-\ref{ss:SLIP_calloc} and \verb|SLIP_options| allocation
routine in \ref{ss:create_default_options} require \verb|option| as an input
argument.  The construction of the \verb|option| struct can be avoided by
passing \verb|NULL| for the default settings.  Otherwise, the following
functions create and destroy a \verb|SLIP_options| object:

%----------------------------------------
\begin{center}
\begin{tabular}{lp{2.5in}l}
\hline
function/macro name & description & section \\
\hline
\verb|SLIP_create_default_options|
    & create and return \verb|SLIP_options| pointer
      with default parameters upon successful allocation
    & \ref{ss:create_default_options} \\
\hline
\verb|SLIP_FREE|
    & destroy \verb|SLIP_options| object
    & \ref{ss:SLIP_free} \\
\hline
\end{tabular}
\end{center}

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_create_default_options|: create default \verb|SLIP_options| object}
\label{ss:create_default_options}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_options* SLIP_create_default_options
    (
        void
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_create_default_options| creates and returns a pointer to a
\verb|SLIP_options| struct with default parameters upon successful allocation,
which are discussed in Section \ref{ss:SLIP_options_struct}.  To safely free
the \verb|SLIP_options* option| structure, simply use \newline \verb|SLIP_FREE(option)|.
All functions that require \verb|SLIP_options *option| as an input argument can
have a \verb'NULL' pointer passed instead. In this case, the default value of
the corresponding command option is used. For example, if a \verb'NULL' pointer
is passed to the symbolic analysis routines, COLAMD is used. As a result,
defaults are desired, the \verb|SLIP_options| struct need not be allocated.
Returns \verb|NULL| if SLIP LU has not been initialized.

%-------------------------------------------------------------------------------
\cprotect\section{The \verb|SLIP_matrix| object} \label{ss:SLIP_matrix}
%-------------------------------------------------------------------------------

All matrices for SLIP LU are stored as a \verb|SLIP_matrix| object (a pointer
to a \verb'struct').  The matrix can be held in three formats: CSC, triplet or
dense matrix (as discussed in Section \ref{ss:SLIP_kind}) with entries stored
as 5 different types: \verb|mpz_t|, \verb|mpq_t|, \verb|mpfr_t|, \verb|int64_t|
and \verb|double| (as discussed in Section \ref{ss:SLIP_type}).  This gives a
total of 15 different combinations of matrix format and entry type. Note that
not all functions accept all 15 matrix types. Indeed, most functions expect the
input matrix $A$ to be a CSC \verb|mpz_t| matrix while vectors (such as $x$ and
$b$) are in dense format.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_kind|: enum for matrix formats}
\label{ss:SLIP_kind}
%-------------------------------------------------------------------------------

The SLIP LU library provides three available matrix formats: sparse CSC
(compressed sparse column), sparse triplet and dense.

{\small
\begin{center}
\begin{tabular}{llp{4in}}
\hline
0 & \verb|SLIP_CSC| & Matrix is in compressed sparse column format. \\
\hline
1 & \verb|SLIP_TRIPLET|      & Matrix is in sparse triplet format. \\
\hline
2 & \verb|SLIP_DENSE|        & Matrix is in dense format.\\
\hline
\end{tabular}
\label{tab:SLIP_kind}
\end{center}
}

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_type|: enum for data types of matrix entry}
\label{ss:SLIP_type}
%-------------------------------------------------------------------------------

The SLIP LU library provides five data types for matrix entries: \verb|mpz_t|,
\verb|mpq_t|, \verb|mpfr_t|, \verb|int64_t| and \verb|double|.

{\small
\begin{center}
\begin{tabular}{llp{4in}}
\hline
0 & \verb|SLIP_MPZ|     & Matrix entries are in \verb|mpz_t| type: an integer
                          of arbitrary size. \\
\hline
1 & \verb|SLIP_MPQ|     & Matrix entries are in \verb|mpq_t| type: a rational
                          number with arbitrary-sized integer numerator and
                          denominator. \\
\hline
2 & \verb|SLIP_MPFR|    & Matrix entries are in \verb|mpfr_t| type: a
                          floating-point number of arbitrary precision. \\
\hline
3 & \verb|SLIP_INT64|   & Matrix entries are in \verb|int64_t| type. \\
\hline
4 & \verb|SLIP_FP64|    & Matrix entries are in \verb|double| type. \\
\hline
\end{tabular}
\label{tab:SLIP_type}
\end{center}
}

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_matrix| structure}
%-------------------------------------------------------------------------------

A matrix \verb|SLIP_matrix *A| has the following components:

\begin{itemize}
\item \verb|A->m|: Number of rows in the matrix. Data Type: \verb|int64_t|.

\item \verb|A->n|: Number of columns in the matrix. Data Type: \verb|int64_t|.

\item \verb|A->nz|: The number of nonzeros in the matrix $A$, if $A$ is
a triplet matrix (ignored for matrices in CSC or dense formats). Data Type:
\verb|int64_t|.

\item \verb|A->nzmax|: The allocated size of the vectors \verb|A->i|,
\verb|A->j| and \verb|A->x|. Note that \verb|A->nzmax| $\geq$ \verb|nnz(A)|,
where \verb|nnz(A)| is the return value of \verb|SLIP_matrix_nnz(A,option)|.
Data Type: \verb|int64_t|.

\item \verb|A->kind|: Indicating the kind of matrix A: CSC, triplet or dense.
Data Type: \verb|SLIP_kind|.

\item \verb|A->type|: Indicating the type of entries in matrix A: \verb|mpz_t|,
\verb|mpq_t|, \verb|mpfr_t|, \verb|int64_t| or \verb|double|.
Data Type: \verb|SLIP_type|.

\item \verb|A->p|: An array of size \verb|A->n|$+1$ which contains column pointers
of $A$, if $A$ is a CSC matrix (\verb|NULL| for matrices in triplet or dense
formats). Data Type: \verb|int64_t*|.

\item \verb|A->p_shallow|: A boolean indicating whether \verb|A->p| is shallow.
Data Type: \verb|bool|.

\item \verb|A->i|: An array of size \verb|A->nzmax| which contains the row
indices of the nonzeros in $A$, if $A$ is a CSC or triplet matrix (\verb|NULL|
for dense matrices). The matrix is zero-based, so row indices are
in the range of $[0,$ \verb|A->m|$-1]$. Data Type: \verb|int64_t*|.

\item \verb|A->i_shallow|: A boolean indicating whether \verb|A->i| is shallow.
Data Type: \verb|bool|.

\item \verb|A->j|: An array of size \verb|A->nzmax| which contains the column
indices of the nonzeros in $A$, if $A$ is a triplet matrix (\verb|NULL| for
matrices in CSC or dense formats).
The matrix is zero-based, so column indices are
in the range of $[0,$ \verb|A->n|$-1]$. Data Type: \verb|int64_t*|.

\item \verb|A->j_shallow|: A boolean indicating whether \verb|A->j| is shallow.
Data Type: \verb|bool|.

\item \verb|A->x|: An array of size \verb|A->nzmax| which contains the
numeric values of the matrix.  This array is a union, and must be accessed via
one of: \verb|A->x.mpz|, \verb|A->x.mpq|, \verb|A->x.mpfr|, \verb|A->x.int64|,
or \verb|A->x.fp64|, depending on the \verb|A->type| parameter.
Data Type: \verb|union|.

\item \verb|A->x_shallow|: A boolean indicating whether \verb|A->x| is
shallow. Data Type: \verb|bool|.

\item \verb|A->scale|: A scaling parameter for matrix of \verb|mpz_t| type. For
all matrices whose entries are stored in data type other than \verb|mpz_t|,
\verb|A->scale = 1|. This is used to ensure that entry can be represented as an
integer in an \verb|mpz_t| matrix if these entries are converted from non-integer type
data (such as double, variable precision floating point, or rational). Data
Type: \verb|mpq_t|.

\end{itemize}

Specifically, for different kinds of \verb|A| of size \verb|A->m| $\times$ \verb|A->n|
with \verb|nz| nonzero entries, its components are defined as:

\begin{itemize}
\item
 (0) \verb|SLIP_CSC|:  A sparse matrix in CSC (compressed sparse column) format.
      \verb|A->p| is an \verb|int64_t| array of size \verb|A->n|+1, \verb|A->i|
      is an \verb|int64_t| array of size \verb|A->nzmax| (with $nz$ $\le$
      \verb|A->nzmax|), and \verb|A->x.TYPE| is an array of size
      \verb|A->nzmax| of matrix entries (\verb'TYPE' is one of \verb|mpz|,
      \verb|mpq|, \verb|mpfr|, \verb|int64|, or \verb|fp64|).  The row indices
      of column $j$ appear in \verb|A->i [A->p [j] ... A->p [j+1]-1]|, and the
      values appear in the same locations in \verb|A->x.TYPE|.  The \verb|A->j|
      array is \verb|NULL|.  \verb|A->nz| is ignored; the number of entries in
      \verb|A| is given by \verb|A->p [A->n]|.
      Row indices need not be sorted in each column, but duplicates cannot
      appear.

\item
 (1) \verb|SLIP_TRIPLET|:  A sparse matrix in triplet format.  \verb|A->i| and
     \verb|A->j| are both \verb|int64_t| arrays of size \verb|A->nzmax|, and
     \verb|A->x.TYPE| is an array of values of the same size.  The $k$th tuple
     has row index \verb|A->i [k]|, column index \verb|A->j [k]| , and value
     \verb|A->x.TYPE [k]|, with 0 $\le$ $k <$ \verb|A->nz|.
     The \verb|A->p| array is \verb|NULL|.
     Triplets can be unsorted, but duplicates cannot appear.

\item
 (2) \verb|SLIP_DENSE|:  A dense matrix.  The integer arrays \verb|A->p|,
     \verb|A->i|, and \verb|A->j| are all \verb|NULL|.  \verb|A->x.TYPE| is a
     pointer to an array of size \verb|A->m|*\verb|A->n|, stored in
     column-oriented format.  The value of $A(i,j)$ is \verb|A->x.TYPE [p]|
     with \verb|p| = $i + j*$\verb|A->m|.  \verb|A->nz| is ignored; the number
     of entries in \verb|A| is \verb|A->m| $\times$ \verb|A->n|.

\end{itemize}

\verb|A| may contain shallow components, \verb|A->p|, \verb|A->i|, \verb|A->j|,
and \verb|A->x|.  For example, if \verb|A->p_shallow| is true, then a
non-\verb|NULL| \verb|A->p| is a pointer to a read-only array, and the
\verb|A->p| array is not freed by \verb|SLIP_matrix_free|.  If \verb|A->p| is
\verb|NULL| (for a triplet or dense matrix), then \verb|A->p_shallow| has no
effect.

To simplify the access the entries in \verb|A|, SLIP LU package provides the
following macros (Note that the \verb|TYPE| parameter in the macros is one of:
\verb|mpz|, \verb|mpq|, \verb|mpfr|, \verb|int64| or \verb|fp64|):

\begin{itemize}

\item
\verb|SLIP_1D(A,k,TYPE)|: used to access the $k$th entry in
                         \verb|SLIP_matrix *A| using 1D linear addressing for
                         any matrix kind (CSC, triplet or dense), in any type
                         with \verb|TYPE| specified corresponding

\item
\verb|SLIP_2D(A,i,j,TYPE)|: used to access the $(i,j)$th entry in a dense
                            \verb|SLIP_matrix *A|.

\end{itemize}

The SLIP LU package has a set of functions to allocate, copy(convert), query and
destroy a SLIP LU matrix, \verb|SLIP_matrix|, as shown in the following table.

%----------------------------------------
{\small
\begin{center}
\begin{tabular}{lp{2.5in}l}
\hline
function name & description & section \\
\hline
\verb|SLIP_matrix_allocate|
    & allocate a $m$-by-$n$ \verb|SLIP_matrix|
    & \ref{s:user:matrix_allocate} \\
\hline
\verb|SLIP_matrix_free|
    & destroy a \verb|SLIP_matrix| and free its allocated memory
    & \ref{s:user:matrix_free} \\
\hline
\verb|SLIP_matrix_copy|
    & make a copy of a matrix, into another kind and/or type
    & \ref{s:user:matrix_copy} \\
\hline
\verb|SLIP_matrix_nnz|
    & get the number of entries in a matrix
    & \ref{s:user:matrix_nnz} \\
\hline
\end{tabular}
\end{center}
}

%-------------------------------------------------------------------------------
\newpage
\cprotect\subsection{\verb|SLIP_matrix_allocate|: allocate a $m$-by-$n$
\verb|SLIP_matrix|}
\label{s:user:matrix_allocate}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_matrix_allocate
    (
        SLIP_matrix **A_handle, // matrix to allocate
        SLIP_kind kind,         // CSC, triplet, or dense
        SLIP_type type,         // mpz, mpq, mpfr, int64, or double (fp64)
        int64_t m,              // # of rows
        int64_t n,              // # of columns
        int64_t nzmax,          // max # of entries
        bool shallow,           // if true, matrix is shallow.  A->p, A->i,
                                // A->j, A->x are all returned as NULL and must
                                // be set by the caller.  All A->*_shallow are
                                // returned as true.
        bool init,              // If true, and the data types are mpz, mpq, or
                                // mpfr, the entries are initialized (using the
                                // appropriate SLIP_mp*_init function). If
                                // false, the mpz, mpq, and mpfr arrays are
                                // allocated but not initialized.
        const SLIP_options *option
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_matrix_allocate| allocates memory space for a $m$-by-$n$
\verb|SLIP_matrix| whose kind (CSC, triplet or dense) and data type
(\verb|mpz|, \verb|mpq|, \verb|mpfr|, \verb|int64| or \verb|fp64|) is
specified. If \verb|shallow| is true, all components (\verb|A->p|, \verb|A->i|,
\verb|A->j|, \verb|A->x|) are returned as \verb|NULL|, and their shallow flags
are all true.  The pointers \verb|A->p|, \verb|A->i|, \verb|A->j|,
and/or \verb|A->x| can then be assigned from arrays in the calling application.

If \verb|shallow| is false, the appropriate individual arrays are allocated
(via \verb|SLIP_calloc|). The second boolean parameter is used if the entries
are \verb|mpz_t|, \verb|mpq_t|, or \verb|mpfr_t|. Specifically, if \verb|init|
is true, the individual entries within \verb|A->x.TYPE| are initialized using
the appropriate \verb|SLIP_mp*_init|) function. Otherwise, if \verb|init| is
false, the \verb|A->x.TYPE| array is allocated (via \verb|SLIP_calloc|) and
left that way.  They are not otherwise initialized, and attempting to access
the values of these uninitialized entries will lead to undefined behavior.
Returns \verb|SLIP_PANIC| if SLIP LU has not been initialized.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_matrix_free|: free a \verb|SLIP_matrix|}
\label{s:user:matrix_free}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_matrix_free
    (
        SLIP_matrix **A_handle, // matrix to free
        const SLIP_options *option
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_matrix_free| frees the \verb|SLIP_matrix *A|.  Note that the input
of the function is the pointer to the pointer of a \verb|SLIP_matrix|
structure. This is because this function internally sets the pointer of a
\verb|SLIP_matrix| to be \verb|NULL| to prevent potential segmentation fault
that could be caused by double \verb|free|.  If default settings are desired,
\verb|option| can be input as \verb|NULL|.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_matrix_copy|: make a copy of a \verb|SLIP_matrix|}
\label{s:user:matrix_copy}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_matrix_copy
    (
        SLIP_matrix **C,        // matrix to create (never shallow)
        // inputs, not modified:
        SLIP_kind kind,         // CSC, triplet, or dense
        SLIP_type type,         // mpz_t, mpq_t, mpfr_t, int64_t, or fp64
        SLIP_matrix *A,         // matrix to make a copy of (may be shallow)
        const SLIP_options *option
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_matrix_copy| creates a \verb|SLIP_matrix *C| which is a modified
copy of a \verb|SLIP_matrix *A|. This function can convert between any pair of
the 15 kinds of matrices, so the new matrix \verb|C| can be of any type or kind
different than \verb|A|.  On input \verb|C| must be non-\verb|NULL|, and the
value of \verb|*C| is ignored; it is overwritten, output with the matrix
\verb|C|, which is a copy of \verb|A| of kind \verb|kind| and type \verb|type|.

The input matrix is assumed to be valid. It can be checked first with
\verb|SLIP_matrix_check| (Section \ref{s:user:matrix_check}), if desired.
Results are undefined for an invalid input matrix \verb|A|.  Returns
\verb|SLIP_PANIC| if SLIP LU has not been initialized.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_matrix_nnz|: get the number of entries in a
\verb|SLIP_matrix|}
\label{s:user:matrix_nnz}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    int64_t SLIP_matrix_nnz     // return # of entries in A, or -1 on error
    (
        const SLIP_matrix *A,         // matrix to query
        const SLIP_options *option
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_matrix_nnz| returns the number of entries in a \verb|SLIP_matrix *A|.
For details regarding how the number of entries is obtained for different kinds
of matrices, refer to Section \ref{ss:SLIP_matrix}.
For any matrix with invalid dimension(s), this function returns -1.
If default settings are desired, \verb|option| can be input as \verb|NULL|.
Returns -1 if SLIP LU has not been initialized.

%-------------------------------------------------------------------------------
\newpage
\cprotect\subsection{\verb|SLIP_matrix_check|: check and print a \verb|SLIP_matrix|}
\label{s:user:matrix_check}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_matrix_check     // returns a SLIP_LU status code
    (
        const SLIP_matrix *A,       // matrix to check
        const SLIP_options* option  // defines the print level
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_matrix_check| checks the validity of a \verb|SLIP_matrix *A| in any
of the 15 different matrix types (CSC, triplet, dense) $\times$ (\verb|mpz|,
\verb|mpq|, \verb|mpfr|, \verb|int64|, \verb|fp64|). The print level can be
changed via \verb|option->print_level| (refer to Section \ref{ss:SLIP_options}
for more details).  If default settings are desired, \verb|option| can be input
as \verb|NULL|.  Returns \verb|SLIP_PANIC| if SLIP LU has not been initialized.

%-------------------------------------------------------------------------------
\section{Primary Computational Routines}
\label{s:primary}
%-------------------------------------------------------------------------------

These routines perform symbolic analysis, compute the LU factorization of the
matrix $A$, and solve $Ax=b$ using the factorization of $A$.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_LU_analysis| structure}
\label{ss:SLIP_LU_analysis}
%-------------------------------------------------------------------------------

The \verb|SLIP_LU_analysis| data structure is used for storing the column
permutation for LU and the estimate of the number of nonzeros that may appear
in $L$ and $U$.  This need not be modified or accessed in the user application;
it simply needs to be passed in directly to the other functions that take it as
in input parameter. A \verb|SLIP_LU_analysis| structure has the following
components:

\begin{itemize}
\item \verb|S->q|: The column permutation stored as a dense \verb|int64_t|
vector of size $n+1$, where $n$ is the number of columns of the analyzed matrix.
Currently this vector is obtained via COLAMD, AMD, or is set to no ordering
(i.e., $[0, 1, \hdots, n-1]$).

\item \verb|S->lnz|: An \verb|int64_t| which is an estimate of the number of
nonzeros in $L$. \verb|S->lnz| must be in the range of $[n, n^2]$. If
\verb|S->lnz| is too small, the program may waste time performing extra memory
reallocations. This is set during the symbolic analysis.

\item \verb|S->unz|: An \verb|int64_t| which is an estimate of the number of
nonzeros in $U$. \verb|S->unz| must be in the range of $[n, n^2]$. If
\verb|S->unz| is too small, the program may waste time performing extra memory
reallocations. This is set during the symbolic analysis.
\end{itemize}

The SLIP LU package provides the following functions to create and destroy a
\verb|SLIP_LU_analysis| object:

%----------------------------------------
{\small
\begin{center}
\begin{tabular}{lll}
\hline
function/macro name & description & section \\
\hline
\verb|SLIP_LU_analyze|
    & create \verb|SLIP_LU_analysis| object
    & \ref{s:SLIP_LU_analyze} \\
\hline
\verb|SLIP_LU_analysis_free|
    & destroy \verb|SLIP_LU_analysis| object
    & \ref{ss:LU_analysis_free} \\
\hline
\end{tabular}
\end{center}
}

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_LU_analyze|: perform symbolic analysis}
\label{s:SLIP_LU_analyze}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_LU_analyze
    (
        SLIP_LU_analysis **S, // symbolic analysis (column permutation
                              // and nnz L,U)
        const SLIP_matrix *A, // Input matrix
        const SLIP_options *option  // Control parameters
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_LU_analyze| performs the symbolic ordering for SLIP LU. Currently,
there are three options: no ordering, COLAMD, or AMD, which are passed in by
\verb|SLIP_options| \verb|*option|. For more details, refer to
Section \ref{ss:SLIP_options}.

The \verb|SLIP_LU_analysis *S| is created by calling
\verb|SLIP_LU_analyze(&S, A, option)| with \verb|SLIP_matrix *A| properly
initialized as CSC matrix and \verb|option| be \verb|NULL| if default ordering
(COLAMD) is desired. The value of \verb|S| is ignored on input.  On output,
\verb|S| is a pointer to the newly created symbolic analysis object and
\verb|SLIP_OK| is returned upon successful completion, or \verb|S = NULL| with
error status returned if a failure occurred.  Returns \verb|SLIP_PANIC| if SLIP
LU has not been initialized.

The analysis \verb|S| is freed by \verb|SLIP_LU_analysis_free|.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_LU_analysis_free|: free \verb|SLIP_LU_analysis| structure}
\label{ss:LU_analysis_free}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_LU_analysis_free
    (
        SLIP_LU_analysis **S, // Structure to be deleted
        const SLIP_options *option
    ) ;
\end{verbatim}
} \end{mdframed}


\verb|SLIP_LU_analysis_free| frees a \verb|SLIP_LU_analysis| structure.
Note that the input of the function is the pointer to the pointer of a
\verb|SLIP_LU_analysis| structure. This is because this function internally
sets the pointer of a \verb|SLIP_LU_analysis| to be \verb|NULL| to prevent
potential segmentation fault that could be caused by double \verb|free|.
If default settings are desired, \verb|option| can be input as \verb|NULL|.
Returns \verb|SLIP_PANIC| if SLIP LU has not been initialized.

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_LU_factorize|: perform LU factorization}
\label{ss:SLIP_LU_factorize}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_LU_factorize
    (
        // output:
        SLIP_matrix **L_handle,     // lower triangular matrix
        SLIP_matrix **U_handle,     // upper triangular matrix
        SLIP_matrix **rhos_handle,  // sequence of pivots
        int64_t **pinv_handle,      // inverse row permutation
        // input:
        const SLIP_matrix *A,        // matrix to be factored
        const SLIP_LU_analysis *S,   // column permutation and estimates
                                     // of nnz in L and U 
        const SLIP_options* option
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_LU_factorize| performs the SLIP LU factorization. This factorization
is done via $n$ (number of rows or columns of the square matrix $A$) iterations
of the sparse REF triangular solve function. The overall factorization is $PAQ
= LDU$.  This routine allows the factorization and solve to be split into
separate phases.  For example codes, refer to either
\verb|SLIP_LU/Demos/SLIPLU.c| or Section \ref{s:Using:expert}.

On input, \verb|L|, \verb|U|, \verb|rhos|, and \verb|pinv| are undefined and
ignored.  \verb|A| must be a CSC \verb|mpz| matrix. Default settings are used
if \verb|option| is input as \verb|NULL|.

Upon successful completion, the function returns \verb|SLIP_OK|, and \verb|L|
and \verb|U| are lower and upper triangular matrices, respectively, which are
CSC matrices of type \verb|mpz|.  \verb|rhos| contains the sequence of pivots
as an \verb|n|-by-1 dense vector of type \verb|mpz|.

After factorizing the matrix, the determinant of $A$ can be obtained from
\verb|rhos[n-1]| and \verb|A->scale| as follows:

\begin{verbatim}
    mpq_t determinant ;
    SLIP_mpq_init (determinant) ;
    SLIP_mpq_set_z (determinant, rhos->x.mpz[rhos->n-1]) ;
    SLIP_mpq_div (determinant, determinant, A->scale) ;
\end{verbatim}

The output array \verb|pinv| contains the inverse row permutation (that is, the
row index in the permuted matrix $PA$. For the $i$th row in $A$, \verb|pinv[i]|
gives the row index in $PA$). 

Returns \verb|SLIP_PANIC| if SLIP LU has not been initialized.  Otherwise, if
another error occurs, \verb|L|, \verb|U|, \verb|rhos|, and \verb|pinv| are all
returned as \verb|NULL|, and an error code will be returned correspondingly.

%-------------------------------------------------------------------------------
\newpage
\cprotect\subsection{\verb|SLIP_LU_solve|: solve the linear system $Ax=b$}
\label{ss:SLIP_LU_solve}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_LU_solve         // solves the linear system LD^(-1)U x = b
    (
        // Output
        SLIP_matrix **X_handle,     // rational solution to the system
        // input:
        const SLIP_matrix *b,       // right hand side vector
        const SLIP_matrix *A,       // Input matrix
        const SLIP_matrix *L,       // lower triangular matrix
        const SLIP_matrix *U,       // upper triangular matrix
        const SLIP_matrix *rhos,    // sequence of pivots
        const SLIP_LU_analysis *S,  // symbolic analysis struct
        const int64_t *pinv,        // inverse row permutation
        const SLIP_options* option
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_LU_solve| obtains the solution of \verb|mpq_t| type to the linear
system $Ax=b$ upon a successful factorization.  This function may be called
after a successful return from \verb|SLIP_LU_factorize|, which computes
\verb|L|, \verb|U|, \verb|rhos|, and \verb|pinv|. 

On input, \verb|SLIP_matrix *x| is undefined. \verb|A|, \verb|L| and \verb|U|
must be CSC \verb|mpz_t| matrices while \verb|b| and \verb|rhos| must be dense
\verb|mpz_t|  matrices. All matrices must have matched dimensions: the matrices
\verb|L| and \verb|U| must be square lower and upper triangular matrices the
same size as \verb|A|, and \verb|rhos| must be a dense \verb|n|-by-1 vector.
The input matrix \verb|b| must have same number of rows as \verb|A|.  Default
settings are used if \verb|option| is input as \verb|NULL|.

Upon successful completion, the function returns \verb|SLIP_OK|, and \verb|x|
contains the solution of \verb|mpq_t| type with dense format to the linear
system $Ax=b$. If desired, \verb|option->check| can be set to \verb|true| to
enable a post-check of the solution of this function.  However, this is
intended for debugging only; the SLIP LU library is guaranteed to return the
exact solution. Otherwise (in case of error occurred), the function returns
corresponding error code.

This function is primarily for applications that require intermediate results.
For additional information, refer to either \verb|SLIP_LU/Demos/SLIPLU.c| or
Section \ref{s:Using:expert}.  Returns \verb|SLIP_PANIC| if SLIP LU has not
been initialized.

%-------------------------------------------------------------------------------
\newpage
\cprotect\subsection{\verb|SLIP_backslash|: solve $Ax=b$}
\label{ss:SLIP_backslash}
%-------------------------------------------------------------------------------

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_info SLIP_backslash
    (
        // Output
        SLIP_matrix **X_handle,       // Final solution vector
        // Input
        SLIP_type type,               // Type of output desired:
                                      // Must be SLIP_MPQ, SLIP_MPFR,
                                      // or SLIP_FP64
        const SLIP_matrix *A,         // Input matrix
        const SLIP_matrix *b,         // Right hand side vector(s)
        const SLIP_options* option
    ) ;
\end{verbatim}
} \end{mdframed}

\verb|SLIP_backslash| solves the linear system $Ax=b$ and returns the solution
as a dense matrix of \verb|mpq_t|, \verb|mpfr_t| or \verb|double| numbers. This
function performs symbolic analysis, factorization, and solving all in one line. 
It can be thought of as an exact version of MATLAB sparse backslash.

On input, \verb|SLIP_matrix *x| is undefined. \verb|type| must be one of:
\verb|SLIP_MPQ|, \verb|SLIP_MPFR| or \verb|SLIP_FP64| to specify the data type
of the solution entries. \verb|A| should be a square CSC \verb|mpz_t| matrix
while \verb|b| should be a dense \verb|mpz_t| matrix. In addition, \verb|A->m|
should be equal to \verb|b->m|.  Default settings are used if
\verb|option| is input as \verb|NULL|.

Upon successful completion, the function returns \verb|SLIP_OK|, and
\verb|x| contains the solution of data type specified by
\verb|type| to the linear system $Ax=b$. If desired, \verb|option->check| can
be set to \verb|true| to enable solution checking process in this function.
However, this is intended for debugging only; SLIP LU library is guaranteed to
return the exact solution. Otherwise (in case of error occurred), the function
returns corresponding error code.

Returns \verb|SLIP_PANIC| if SLIP LU has not been initialized.

For a complete example, refer to \verb|SLIP_LU/Demos/example.c|,  \\
\verb|SLIP_LU/Demos/example2.c|, or Section \ref{s:Using:simple}.

%-------------------------------------------------------------------------------
\section{SLIP LU wrapper functions for GMP and MPFR}
%-------------------------------------------------------------------------------

SLIP LU provides a wrapper class for all GMP and MPFR functions used by SLIP
LU.  The wrapper class provides error-handling for out-of-memory conditions
that are not handled by the GMP and MPFR libraries.  These wrapper functions
are used inside all SLIP LU functions, wherever any GMP or MPFR functions are
used.  These functions may also be called by the end-user application.

Each wrapped function has the same name as its corresponding GMP/MPFR function
with the added prefix \verb|SLIP_|. For example, the default GMP function
\verb|mpz_mul| is changed to \verb|SLIP_mpz_mul|. Each SLIP GMP/MPFR function
returns \verb|SLIP_OK| if successful or the correct error code if not. The
following table gives a brief list of each currently covered SLIP GMP/MPFR
function. For a detailed description of each function, refer to
\verb|SLIP_LU/Source/SLIP_gmp.c|.

If additional GMP and MPFR functions are needed in the end-user application,
this wrapper mechanism can be extended to those functions.  Below are
instructions on how to do this.

Given a GMP function \verb|void gmpfunc(TYPEa a, TYPEb b, ...)|, where
\verb|TYPEa| and \verb|TYPEb| can be GMP type data (\verb|mpz_t|,
\verb|mpq_t| and \verb|mpfr_t|, for example) or non-GMP type data (\verb|int|,
\verb|double|, for example), and they need not to be the same.
A wrapper for a new GMP or MPFR function can be created by following
this outline:

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
SLIP_info SLIP_gmpfunc
(
    TYPEa a,
    TYPEb b,
    ...
)
{
    // Start the GMP Wrappter
    // uncomment one of the following:
    // If this function is not modifying any GMP/MPFR type variable, then use
    //SLIP_GMP_WRAPPER_START;
    // If this function is modifying mpz_t type (say TYPEa = mpz_t), then use
    //SLIP_GMPZ_WRAPPER_START(a) ;
    // If this function is modifying mpq_t type (say TYPEa = mpq_t), then use
    //SLIP_GMPQ_WRAPPER_START(a) ;
    // If this function is modifying mpfr_t type (say TYPEa = mpfr_t), then use
    //SLIP_GMPFR_WRAPPER_START(a) ;

    // Call the GMP function
    gmpfunc(a,b,...) ;

    //Finish the wrapper and return ok if successful.
    SLIP_GMP_WRAPPER_FINISH;
    return SLIP_OK;
}
\end{verbatim}
} \end{mdframed}

Note that, other than \verb|SLIP_mpfr_fprintf|, \verb|SLIP_gmp_fprintf|,
\verb|SLIP_gmp_printf| and \verb|SLIP_gmp_fscanf|, all of the wrapped GMP/MPFR
functions always return \verb|SLIP_info| to the caller. Therefore, for some
GMP/MPFR functions that have their own return value.  For example, for
\verb|int mpq_cmp(const mpq_t a, const mpq_t b)|, the return value becomes a
parameter of the wrapped function. In general, a GMP/MPFR function in the form
of \verb|TYPEr gmpfunc(TYPEa a, TYPEb b, ...)|, the wrapped
function can be constructed as follows:

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
SLIP_info SLIP_gmpfunc
(
    TYPEr *r,        // return value of the GMP/MPFR function
    TYPEa a,
    TYPEb b,
    ...
)
{
    // Start the GMP Wrappter
    //SLIP_GMP_WRAPPER_START;

    // Call the GMP function
    *r = gmpfunc(a,b,...) ;

    //Finish the wrapper and return ok if successful.
    SLIP_GMP_WRAPPER_FINISH;
    return SLIP_OK;
}
\end{verbatim}
} \end{mdframed}

% \newpage
\thispagestyle{empty}
{\scriptsize
\begin{center}
\begin{tabular}{|l|l|l|}
\hline
%----------------------------------------
{\bf MPFR Function} & \verb|SLIP_MPFR| {\bf Function} & {\bf Description} \\
%----------------------------------------
\hline\hline
\verb|n = mpfr_asprintf(&buff, fmt, ...)|
    & \verb|n = SLIP_mpfr_asprintf(&buff, fmt, ...)|
    & Print format to allocated string \\ \hline
\verb|mpfr_free_str(buff)|
    & \verb|SLIP_mpfr_free_str(buff)|
    & Free string allocated by MPFR \\ \hline
\verb|mpfr_init2(x, size)|
    & \verb|SLIP_mpfr_init2(x, size)|
    & Initialize x with size bits \\ \hline
\verb|mpfr_set(x, y, rnd)|
    & \verb|SLIP_mpfr_set(x, y, rnd)|
    & $x = y$ \\ \hline
\verb|mpfr_set_d(x, y, rnd)|
    & \verb|SLIP_mpfr_set_d(x, y, rnd)|
    & $x = y$ (double) \\ \hline
\verb|mpfr_set_q(x, y, rnd)|
    & \verb|SLIP_mpfr_set_q(x, y, rnd)|
    & $x = y$ (\verb|mpq_t|) \\ \hline
\verb|mpfr_set_z(x, y, rnd)|
    & \verb|SLIP_mpfr_set_z(x, y, rnd)|
    & $x = y$ (\verb|mpz_t|) \\ \hline
\verb|mpfr_get_z(x, y, rnd)|
    & \verb|SLIP_mpfr_get_z(x, y, rnd)|
    & (\verb|mpz_t|) $x = y$\\ \hline
\verb|x = mpfr_get_d(y, rnd)|
    & \verb|SLIP_mpfr_get_d(x, y, rnd)|
    & (double) $x = y$\\ \hline
\verb|mpfr_mul(x, y, z, rnd)|
    & \verb|SLIP_mpfr_mul(x, y, z, rnd)|
    & $x = y*z$ \\ \hline
\verb|mpfr_mul_d(x, y, z, rnd)|
    & \verb|SLIP_mpfr_mul_d(x, y, z, rnd)|
    & $x = y*z$ \\ \hline
\verb|mpfr_div_d(x, y, z, rnd)|
    & \verb|SLIP_mpfr_div_d(x, y, z, rnd)|
    & $x = y/z$ \\ \hline
\verb|mpfr_ui_pow_ui(x, y, z, rnd)|
    & \verb|SLIP_mpfr_ui_pow_ui(x, y, z, rnd)|
    & $x = y^z$ \\ \hline
\verb|mpfr_log2(x, y, rnd)|
    & \verb|SLIP_mpfr_log2(x, y, rnd )|
    & $x = \log_2 (y)$ \\ \hline
\verb|mpfr_free_cache()|
    & \verb|SLIP_mpfr_free_cache()|
    & Free cache after log2 \\ \hline
\hline
%----------------------------------------
{\bf GMP Function} & \verb|SLIP_GMP| {\bf Function} & {\bf Description} \\
%----------------------------------------
\hline\hline
\verb|n = gmp_fscanf(fp, fmt, ...)|
    & \verb|n = SLIP_gmp_fscanf(fp, fmt, ...)|
    & Read from file fp \\ \hline
\verb|mpz_init(x)|
    & \verb|SLIP_mpz_init(x)|
    & Initialize x \\ \hline
\verb|mpz_init2(x, size)|
    & \verb|SLIP_mpz_init2(x, size)|
    & Initialize x to size bits \\ \hline
\verb|mpz_set(x, y)|
    & \verb|SLIP_mpz_set(x, y)| 
    & $x = y$ (\verb|mpz_t|) \\ \hline
\verb|mpz_set_ui(x, y)|
    & \verb|SLIP_mpz_set_ui(x, y)|
    & $x = y$ (signed int) \\ \hline
\verb|mpz_set_si(x, y)|
    & \verb|SLIP_mpz_set_si(x, y)|
    & $x = y$ (unsigned int) \\ \hline
\verb|mpz_set_d(x, y)|
    & \verb|SLIP_mpz_set_d(x, y)|
    & $x = y$ (double)\\ \hline
\verb|x = mpz_get_d(y)|
    & \verb|SLIP_mpz_get_d(x, y)|
    & $x = y$ (double out) \\ \hline
\verb|mpz_set_q(x, y)|
    & \verb|SLIP_mpz_set_q(x, y)|
    & $x = y$ (\verb|mpz_t|) \\ \hline
\verb|mpz_mul(x, y, z)|
    & \verb|SLIP_mpz_mul(x, y, z)|
    & $x = y*z$ \\ \hline
\verb|mpz_add(x, y, z)|
    & \verb|SLIP_mpz_add(x, y, z)|
    & $x = y+z$ \\ \hline
\verb|mpz_addmul(x, y, z)|
    & \verb|SLIP_mpz_addmul(x, y, z)|
    & $x = x+y*z$ \\ \hline
\verb|mpz_submul(x, y, z)|
    & \verb|SLIP_mpz_submul(x, y, z)|
    & $x = x-y*z$ \\ \hline
\verb|mpz_divexact(x, y, z)|
    & \verb|SLIP_mpz_divexact(x, y, z)|
    & $x = y/z$ \\ \hline
\verb|gcd = mpz_gcd(x, y)|
    & \verb|SLIP_mpz_gcd(gcd, x, y)|
    & $gcd = gcd(x,y)$\\ \hline
\verb|lcm = mpz_lcm(x, y)|
    & \verb|SLIP_mpz_lcm(lcm, x, y)|
    & $lcm = lcm(x,y)$ \\ \hline
\verb|mpz_abs(x, y)|
    & \verb|SLIP_mpz_abs(x, y)|
    & $x = |y|$ \\ \hline
\verb|r = mpz_cmp(x, y)|
    & \verb|SLIP_mpz_cmp(r, x, y)|
    & $r = 0$ if $x=y$, $r\neq 0$  if $x\neq y$ \\ \hline
\verb|r = mpz_cmpabs(x, y)|
    & \verb|SLIP_mpz_cmpabs(r, x, y)|
    & $r = 0$ if $|x|=|y|$,  $r\neq 0$  if $|x|\neq |y|$\\ \hline
\verb|r = mpz_cmp_ui(x, y)|
    & \verb|SLIP_mpz_cmp_ui(r, x, y)|
    & $r = 0$ if $x=y$,  $r\neq 0$  if $x\neq y$ \\ \hline
\verb|sgn = mpz_sgn(x)|
    & \verb|SLIP_mpz_sgn(sgn, x)|
    & $sgn = 0$ if $x = 0$ \\ \hline
\verb|size = mpz_sizeinbase(x, base)|
    & \verb|SLIP_mpz_sizeinbase(size, x, base)|
    & size of x in base \\ \hline
\verb|mpq_init(x)|
    & \verb|SLIP_mpq_init(x)|
    & Initialize x \\ \hline
\verb|mpq_set(x, y)|
    & \verb|SLIP_mpq_set(x, y)|
    & $x = y$ \\ \hline
\verb|mpq_set_z(x, y)|
    & \verb|SLIP_mpq_set_z(x, y)|
    & $x = y$ (\verb|mpz|) \\ \hline
\verb|mpq_set_d(x, y)|
    & \verb|SLIP_mpq_set_d(x, y)|
    & $x=y$ (double) \\ \hline
\verb|mpq_set_ui(x, y, z)|
    & \verb|SLIP_mpq_set_ui(x, y, z)|
    & $x = y/z$ (unsigned int) \\ \hline
\verb|mpq_set_num(x, y)|
    & \verb|SLIP_mpq_set_num(x, y)|
    & $num(x) = y$ \\ \hline
\verb|mpq_set_den(x, y)|
    & \verb|SLIP_mpq_set_den(x, y)|
    & $den(x) = y$ \\ \hline
\verb|mpq_get_den(x, y)|
    & \verb|SLIP_mpq_get_den(x, y)|
    & $x = den(y)$ \\ \hline
\verb|x = mpq_get_d(y)|
    & \verb|SLIP_mpq_get_d(x, y)|
    & (double) $x = y$ \\ \hline
\verb|mpq_abs(x, y)|
    & \verb|SLIP_mpq_abs(x, y)|
    & $x = |y|$ \\ \hline
\verb|mpq_add(x, y, z)|
    & \verb|SLIP_mpq_add(x, y, z)|
    & $x = y+z$ \\ \hline
\verb|mpq_mul(x, y, z)|
    & \verb|SLIP_mpq_mul(x, y, z)|
    & $x = y*z$ \\ \hline
\verb|mpq_div(x, y, z)|
    & \verb|SLIP_mpq_div(x, y, z)|
    & $x = y/z$ \\ \hline
\verb|r = mpq_cmp(x, y)|
    & \verb|SLIP_mpq_cmp(r, x, y)|
    & $r = 0$ if $x=y$,  $r\neq 0$ if $x\neq y$ \\ \hline
\verb|r = mpq_cmp_ui(x, n, d)|
    & \verb|SLIP_mpq_cmp_ui(r, x, n, d)|
    & $r = 0$ if $x=n/d$, $r\neq 0$ if $x\neq n/d$ \\ \hline
\verb|r = mpq_equal(x, y)|
    & \verb|SLIP_mpq_equal(r, x, y)|
    & $r = 0$ if $x=y$,  $r\neq 0$ if $x\neq y$ \\ \hline
\end{tabular}
\end{center}
}

%-------------------------------------------------------------------------------
\cprotect\section{Using SLIP LU in C} \label{s:Using}
%-------------------------------------------------------------------------------

Using SLIP LU in C has three steps:

\begin{enumerate}
\item initialize and populate data structures,
\item perform symbolic analysis,
factorize the matrix $A$ and solve the linear
system for each $b$ vector, and
\item free all used memory and finalize.
\end{enumerate}

Step 1 is discussed in Section \ref{s:Using:init}.  For Step 2, performing
symbolic analysis and factorizing $A$ and solving the linear $A x =b$ can be
done in one of two ways. If only the solution vector $x$ is required, SLIP LU
provides a simple interface for this purpose which is discussed in Section
\ref{s:Using:simple}.  Alternatively, if the $L$ and $U$ factors are required,
refer to Section \ref{s:Using:expert}.  Finally, step 3 is discussed in Section
\ref{s:Using:free}. For the remainder of this section, \verb|n| will indicate
the dimension of $A$ (that is, $A \in \mathbb{Z}^{n \times n}$) and
\verb|numRHS| will indicate the number of right hand side vectors being solved
(that is, if \verb|numRHS|$= r$, then $b \in \mathbb{Z}^{n \times r}$).

%-------------------------------------------------------------------------------
\cprotect\subsection{SLIP LU initialization and population of data structures}
\label{s:Using:init}
%-------------------------------------------------------------------------------

This section discusses how to initialize and populate the global data
structures required for SLIP LU.

%-------------------------------------------------------------------------------
\subsubsection{Initializing the environment}
%-------------------------------------------------------------------------------

SLIP LU is built upon the GNU Multiple Precision Arithmetic (GMP)
\cite{granlund2015gnu} and GNU Multiple Precision Floating Point Reliable
(MPFR) \cite{fousse2007mpfr} libraries and provides wrappers to all GMP/MPFR
functions it uses.  This allows SLIP LU to properly handle memory management
failures, which GMP/MPFR does not handle.  To enable this mechanism, SLIP LU
requires initialization.  The following must be done before using any other
SLIP LU function:

\begin{mdframed}[userdefinedwidth=6in]
{\footnotesize
\begin{verbatim}
    SLIP_initialize ( ) ;
    // or SLIP_initialize_expert (...); if custom memory functions are desired
\end{verbatim}
} \end{mdframed}

%-------------------------------------------------------------------------------
\subsubsection{Initializing data structures}
\label{ss:init}
%-------------------------------------------------------------------------------

SLIP LU assumes three specific input options for all functions. These are:

\begin{itemize}
\item \verb|SLIP_matrix* A| and \verb|SLIP_matrix *b|: \verb|A| contains the
input coefficient matrix, while \verb|b| contains the right hand side vector(s)
of the linear system $Ax=b$.

\item \verb|SLIP_LU_analysis* S|: \verb|S| contains the column permutation used
for $A$ as well as estimates of the number of nonzeros in $L$ and $U$.

\item \verb|SLIP_options* option|: \verb|option| contains various control
options for the factorization including column ordering used, pivot selection
scheme, and others. For a full list of the contents of the \verb|SLIP_options|
structure, refer to Section \ref{ss:SLIP_options}.
If default settings are desired, \verb|option| can be set to \verb|NULL|.

\end{itemize}

%-------------------------------------------------------------------------------
\subsubsection{Populating data structures}
\label{ss:populate_Ab}
%-------------------------------------------------------------------------------

Of the three data structures discussed in Section~\ref{ss:init}, \verb|S| is
constructed during symbolic analysis (Section \ref{s:SLIP_LU_analyze}), and
\verb|option| is an optional parameter for selecting non-default parameters.
Refer to Section \ref{ss:SLIP_options} for the contents of \verb|option|.

SLIP LU allows the input numerical data for \verb|A| and \verb|b| to come in
one of 5 types: \verb|int64_t|, \verb|double|, \verb|mpfr_t|, \verb|mpq_t|,
and \verb|mpz_t|. Moreover, both \verb|A| and \verb|b| can be stored in
CSC form, sparse triplet form or dense form. CSC form is discussed in Section
\ref{s:intro}. The triplet form stores the contents of the matrix $A$
in three arrays \verb|i|, \verb|j|, and \verb|x| where the $k$th nonzero entry
is stored as $A ( i[k], j[k]) = x[k]$. SLIP LU stores its dense matrices in
in column-oriented format, that is, the $(i,j)$th entry in \verb|A|
is \verb|A->x.TYPE[p]| with $p = i+j$*\verb|A->m|.

If the data for matrices are in file format to be read, refer to
\verb|SLIP_LU/Demo| \verb|/example2.c| on how to read in data and construct
\verb|A| and \verb|b|. If the data for matrices are already stored in vectors
corresponding to CSC form, sparse triplet form or dense form, allocate a
shallow \verb|SLIP_matrix| and assign vectors accordingly, then use
\verb|SLIP_matrix_copy| to get a \verb|SLIP_matrix| in the desired kind and
type. For more details, refer to \verb|SLIP_LU/Demo/example.c|. In a case when
\verb|A| is available in format other than CSC \verb|mpz|, and/or \verb|b| is
available in format other than dense \verb|mpz|, the following code snippet
shows how to get \verb|A| and \verb|b| in a required format.

{\small
\begin{verbatim}

    /* Get the matrix A. Assume that A1 is stored in CSC form
       with mpfr_t entries, while b1 is stored in triplet form
       with mpq_t entries. (for A1 and b1 in any other form,
       the exact same code will work) */

    SLIP_matrix *A, *b;
    // A is a copy of the A1. A is a CSC matrix with mpz_t entries
    SLIP_matrix_copy(&A, SLIP_CSC,   SLIP_MPZ, A1, option);
    // b is a copy of the b1. b is a dense matrix with mpz_t entries. 
    SLIP_matrix_copy(&b, SLIP_DENSE, SLIP_MPZ, b1, option);
    \end{verbatim} }

%-------------------------------------------------------------------------------
\cprotect\subsection{Simple SLIP LU routines for solving linear systems}
\label{s:Using:simple}
%-------------------------------------------------------------------------------

After initializing the necessary data structures, SLIP LU obtains the solution
to $Ax=b$ using the simple interface of SLIP LU, \verb|SLIP_backslash|.  The
\verb|SLIP_backslash| function can return \verb|x| as \verb|double|,
\verb|mpq_t|, or \verb|mpfr_t| with an associated precision.  See Section
\ref{ss:SLIP_backslash} for more details.  The following code snippet shows how
to get solution as a dense \verb|mpq_t| matrix.

{\small
\begin{verbatim}
    SLIP_matrix *x;
    SLIP_type my_type = SLIP_MPQ; // SLIP_MPQ, SLIP_MPFR, SLIP_FP64
    SLIP_backslash(&x, my_type, A, b, option) ; \end{verbatim} }

On successful return, this function returns \verb|SLIP_OK| (see Section
\ref{ss:SLIP_info}).

%-------------------------------------------------------------------------------
\cprotect\subsection{Expert SLIP LU routines}
\label{s:Using:expert}
%-------------------------------------------------------------------------------

If the $L$ and $U$ factors from the SLIP LU factorization of the matrix $A$
are required, the steps performed by \verb|SLIP_backslash| can be done with
a sequence of calls to SLIP LU functions:

\begin{enumerate}
\item declare \verb|L|, \verb|U|, the solution matrix \verb|x|, and others,
\item perform symbolic analysis,
\item compute the factorization $PAQ = L D U$, 
\item solve the linear system $Ax =b$, and
\item convert the final solution into the final desired form.
\end{enumerate}

These steps are discussed below, along with examples.

%-------------------------------------------------------------------------------
\subsubsection{Declare workspace}
%-------------------------------------------------------------------------------

Using SLIP LU in this form requires the intermediate variables be declared,
such as \verb|L|, \verb|U|, etc. The following code snippet shows the
detailed list.

{\small
\begin{verbatim}
    // A and b are in required type and ready to use
    SLIP_matrix *L = NULL;
    SLIP_matrix *U = NULL;
    SLIP_matrix *x = NULL;
    SLIP_matrix *rhos = NULL;
    int64_t* pinv = NULL;
    SLIP_LU_analysis* S = NULL;

    // option needs no declaration if default setting is desired
    // only declare option for further modification on default setting
    SLIP_options *option = SLIP_create_default_options();
     \end{verbatim} }

%-------------------------------------------------------------------------------
\subsubsection{SLIP LU symbolic analysis}
%-------------------------------------------------------------------------------

The symbolic analysis phase of SLIP LU computes the column permutation and
estimates of the number of nonzeros in $L$ and $U$. This function is called as:

{\small
    \begin{verbatim}
    SLIP_LU_analyze (&S, A, option) ; \end{verbatim} }


%-------------------------------------------------------------------------------
\subsubsection{Computing the factorization}
%-------------------------------------------------------------------------------

The matrices \verb|L| and \verb|U|, the pivot sequence \verb|rhos|, and the row
permutation \verb|pinv| are computed via the \verb|SLIP_LU_factorize| function
(Section \ref{ss:SLIP_LU_factorize}).  Upon successful completion, this
function returns \verb|SLIP_OK|.

%-------------------------------------------------------------------------------
\subsubsection{Solving the linear system}
%-------------------------------------------------------------------------------

After factorization, the next step is to solve the linear system and store the
solution as a dense matrix \verb|x| with entries of rational number
\verb|mpq_t|. This solution is done via the \verb|SLIP_LU_solve|
function (Section \ref{ss:SLIP_LU_solve}). 
Upon successful completion, this function returns \verb|SLIP_OK|.

In this step, \verb|option->check| can be set to \verb|true| to enable the
solution check process as discussed in Section \ref{ss:SLIP_LU_solve}.  The
process can verify that the solution vector x satisfies $Ax=b$ in perfect
precision intended for debugging.  This step is not needed, since the solution
returned is guaranteed to be exact.   It appears here simply as debugging tool,
and as a verification that SLIP LU is computing its expected result.  This test
can fail only if it runs out of memory, or if there is a bug in the code (in
which case, please notify the authors).  Also, note that this process can be
quite time consuming; thus it is not recommended to be used in general.

%-------------------------------------------------------------------------------
\subsubsection{Converting the solution vector to the final desired form}
%-------------------------------------------------------------------------------

Upon completion of the above routines, the solution to the linear system is in
a dense \verb|mpq_t| matrix. SLIP LU allows this to be converted into any form
of matrix in the set of (CSC, sparse triplet, dense) $\times$ (\verb|mpfr_t|,
\verb|mpq_t|, \verb|double|) using \verb|SLIP_matrix_copy|. The following code
snippet shows how to get solution as a dense \verb|double| matrix; since this
involves a floating-point representation, the solution \verb|my_x| will no
longer be exact, even though \verb|x| is the exact solution.

{\small
\begin{verbatim}
    SLIP_kind my_kind = SLIP_DENSE;  // SLIP_CSC, SLIP_TRIPLET or SLIP_DENSE
    SLIP_type my_type = SLIP_FP64;   // SLIP_MPQ, SLIP_MPFR, or SLIP_FP64
    SLIP_matrix* my_x = NULL;        // New output
    // Create copy which is stored as my_kind and my_type:
    SLIP_matrix_copy( &my_x, my_kind, my_type, x, option);\end{verbatim} }

%-------------------------------------------------------------------------------
\cprotect\subsection{Freeing memory}
\label{s:Using:free}
%-------------------------------------------------------------------------------

As described in Section \ref{s:user:memmanag}, SLIP LU provides a number
of functions/macros to free SLIP LU objects:

\begin{itemize}
\item \verb|SLIP_matrix*|: A \verb|SLIP_matrix* A| data structure can be freed
with a call to \verb|SLIP_matrix_free(&A, NULL) ;|

\item \verb|SLIP_LU_analysis*|: A \verb|SLIP_LU_analysis* S| data structure can
be freed with a call to \verb|SLIP_LU_analysis_free(&S, NULL) ;|

\item All others including \verb|SLIP_options*|: These data structures can be
freed with a call to the macro \verb|SLIP_FREE()|, for example,
\verb|SLIP_FREE(option)| for \newline
\verb|SLIP_options* option|.

\end{itemize}

After all usage of the SLIP LU routines is finished, \verb|SLIP_finalize()|
must be called (Section \ref{ss:SLIP_finalize}) to finalize usage of the
library.

%-------------------------------------------------------------------------------
\cprotect\subsection{Examples of using SLIP LU in a C program}
\label{s:Using:Examples}
%-------------------------------------------------------------------------------

The \verb|SLIP_LU/Demo| folder contains three sample C codes which utilize SLIP
LU. These files demonstrate the usage of SLIP LU as follows:

\begin{itemize}
\item \verb|example.c|: This example generates a random dense $50 \times 50$
matrix and a random dense $50 \times 1$ right hand side vector $b$ and
solves the linear system. In this function, the \verb|SLIP_backslash|
function is used; and the output is given as a double matrix.

\item \verb|example2.c|: This example reads in a matrix stored in triplet
format from the \verb|ExampleMats| folder. Additionally, it reads in a
right hand side vector from this folder and solves the associated linear system
via the \verb|SLIP_backslash| function, and, the solution is given as a matrix
of rational numbers.

\item \verb|SLIPLU.c|: This example reads in a matrix and right hand side
vector from a file and solves the linear system $A x = b$
using the techniques discussed in Section \ref{s:Using:expert}. This file also
allows command line arguments (discussed in \verb|README.md|) and can be used
to replicate the results from \cite{lourenco2019exact}.

\end{itemize}

%-------------------------------------------------------------------------------
\newpage
\cprotect\section{Using SLIP LU in MATLAB}
\label{s:Use:MATLAB}
%-------------------------------------------------------------------------------

After following the installation steps discussed in Section \ref{s:install},
using the SLIP LU factorization within MATLAB can be done via the
\verb|SLIP_backslash.m| function. First, this section describes the
\verb|option| struct in Section \ref{s:Use:MATLAB:setup}.
The use of the factorization is discussed in Section \ref{s:Use:MATLAB:factor}.
The \verb|SLIP_LU/MATLAB| folder must be in your MATLAB path.

%-------------------------------------------------------------------------------
\cprotect\subsection{Optional parameter settings}
\label{s:Use:MATLAB:setup}
%-------------------------------------------------------------------------------

The SLIP LU MATLAB interface includes an \verb|option| struct as in optional
input parameter that modifies behavior.  If this parameter is not provided,
default parameter settings are used.  The elements of the \verb'option' struct
are listed below.  Any fields not present in the struct are treated as their
default values.

\begin{itemize}

\item \verb|option.pivot|: This parameter is a string that controls the
pivoting scheme used.  When selecting a pivot entry in a given column, the
factorization method uses one of the following pivoting strategies:

    \begin{itemize}
    \item \verb|'smallest'|: smallest pivot,
    \item \verb|'diagonal'|: diagonal pivot if possible, otherwise smallest pivot,
    \item \verb|'first'|: first nonzero pivot in each column,
    \item \verb|'tol smallest'|: (default) diagonal pivot with a tolerance (\verb|option.tol|)
        for the smallest pivot,
    \item \verb|'tol largest'|: diagonal pivot with a tolerance (\verb|option.tol|)
        for the largest pivot,
    \item \verb|'largest'|: largest pivot.
    \end{itemize}
    
\item \verb|option.order|: This parameter is a string controls the
fill-reducing column preordering used.

    \begin{itemize}
    \item \verb|'none'|: no column ordering; factorize \verb'A' as-is.
    \item \verb|'colamd'|: COLAMD ordering (default)
    \item \verb|'amd'|: AMD ordering
    \end{itemize}

The \verb|'colamd'| is recommended for most cases.  The \verb|'AMD'| ordering
is suitable if the nonzero pattern of \verb'A' is mostly symmetric.  In this
case, \verb|option.pivot = 'diagonal'| is a useful option.

\item \verb|option.tol|: This parameter determines the tolerance used if one of
the threshold pivoting schemes is chosen. The default value is 1 and this
parameter can take any value in the range $(0,1]$.

\item \verb|option.solution|:
    a string determining how \verb|x| is to be returned:

    \begin{itemize}
        \item \verb|'double'|:  \verb|x| is converted to a 64-bit
            floating-point approximate solution.  This is the default.
        \item \verb|'vpa'|:  \verb|x| is returned as a \verb|vpa| array with
            \verb|option.digits| digits (default is given by the MATLAB
            \verb|digits| function).  The result may be inexact, if an entry in
            \verb|x| cannot be represented in the specified number of digits.
            To convert this \verb|x| to double, use \verb|x=double(x)|.
        \item \verb|'char'|:  \verb|x| is returned as a cell array of strings,
            where \verb|x {i} =| \newline \verb|'numerator/denominator'| and both
            \verb|numerator| and \verb|denominator| are arbitrary-length
            strings of decimal digits.  The result is always exact, although
            \verb|x| cannot be directly used in MATLAB for numerical
            calculations.  It can be inspected or analyzed using MATLAB string
            manipulation.  To convert \verb|x| to \verb|vpa|, use
            \verb|x=vpa(x)|.  To convert \verb|x| to double, use
            \verb|x=double(vpa(x))|.
    \end{itemize}

\item \verb|option.digits|: the number of decimal digits to use for \verb|x|, if
        \verb|option.solution| is \verb|'vpa'|.  Must be in range 2 to $2^{29}$.

\item \verb|option.print|: display the inputs and outputs
        (0: nothing (default), 1: just errors, 2: terse, 3: all).

\end{itemize}

%-------------------------------------------------------------------------------
\cprotect\subsection{\verb|SLIP_backslash.m|}
\label{s:Use:MATLAB:factor}
%-------------------------------------------------------------------------------

The \verb|SLIP_backslash.m| function solves the linear system $A x = b$ where
$A \in \mathtt{R}^{n \times n}$, $x \in \mathtt{R}^{n \times m}$ and $b \in
\mathtt{R}^{n \times m}$. The final solution vector(s) obtained via this
function are exact prior to their conversion to double precision.

The SLIP LU function expects as input a sparse matrix $A$ and dense set of
right hand side vectors $b$. Optionally, \verb|option| struct can be passed in.
Currently, there are 2 ways to use this function outlined below:

\begin{itemize}

\item \verb|x = SLIP_backslash(A,b)| returns the solution to $A x =
b$ using default settings. The solution vectors are more accurate than
the solution obtained via \verb|x = A \ b|.  The solution \verb|x| is
returned as a MATLAB double matrix.

\item \verb|x = SLIP_backslash(A,b,option)| returns the solution to $A x =
b$ using non-default settings from the \verb|option| struct.

\end{itemize}

If the result \verb|x| is held as a MATLAB double matrix, in conventional
floating-point representation (\verb|double|), it is guaranteed to be exact
only if the exact solution can be held in \verb|double| without modification.

The solution \verb|x| may also be returned as a MATLAB \verb|vpa| array, or as
a cell array of strings; See Section \ref{s:Use:MATLAB:setup} for details.

%-------------------------------------------------------------------------------
% References
%-------------------------------------------------------------------------------

\newpage
\bibliographystyle{siam}
\bibliography{SLIP_LU_UserGuide.bib}
\end{document}