1
/* ------------------------------------------------------------------- */
2
/* SARAG - Low Level Routines */
3
/* by Fabrizio Caruso */
6
/* It expands a polynomial if ASSUME_EXPANDED is false */
9
if ASSUME_EXPANDED then
15
/* Degree of a polynomial (MACRO) */
17
degree(poly,indet) ::=
18
buildq([poly,indet],if poly = 0 then -1 else hipow(poly,indet));
21
/* Leading coefficient of a polynomial */
22
leadCoeff(poly,indet)::=
24
ratcoeff(poly,indet,degree(poly,indet)));
27
/* Leading term of a polynomial */
28
leadTerm(poly,indet)::=
30
indet^degree(poly,indet));
32
/* Leading monomial of a polynomial */
33
leadMono(poly,indet)::=
35
leadCoeff(poly,indet)*leadTerm(poly,indet));
37
/* Tail of a polynomial */
40
poly-leadMono(poly,indet));
46
buildq([val], if val = 0 then 0 else if val < 0 then -1 else 1);
49
/* Array-related routines */
51
/* Number of dimensions */
53
second(arrayinfo(ar));
57
first(third(arrayinfo(ar)));
61
first(third(arrayinfo(ar)))+1;
65
first(third(arrayinfo(ar)))+1;
67
/* Number of columns */
69
second(third(arrayinfo(ar)))+1;
71
/* It makes a polynomial out of a list */
73
sum(lst[i]*var^(i-1),i,1,length(lst));
76
makelist(coeff(pol,var,i),i,0,degree(pol,var));
79
makelist(mtx[i],i,1,length(mtx));
82
/* list of lists -> bidimensional array */
84
block([nRows,nCols,i,j,res],
86
nCols : length(lst[1]),
87
res : make_array( 'any,nRows,nCols ),
88
for i : 1 thru nRows do
89
for j : 1 thru nCols do
90
res[i-1,j-1] : lst[i][j],
96
/* bidimensional array -> list of lists */
98
block([nRows,nCols,i,j,newRow,res],
99
nRows : first(third(arrayinfo(arr)))+1,
100
nCols : second(third(arrayinfo(arr)))+1,
103
for i : 1 thru nRows do
106
for j : 1 thru nCols do
107
newRow : endcons(arr[i-1,j-1],newRow),
109
res : endcons(newRow,res)
115
array2singleList(arr) :=
116
makelist(arr[j],j,0,first(third(arrayinfo(arr))));
119
singleList2array(lst) :=
121
res:make_array('any,length(lst)),
122
for i : 1 thru length(lst) do
128
poly2array(pol,var) :=
129
singleList2array(poly2list(pol,var));
131
array2poly(arr,var) :=
132
list2poly(array2singleList(arr),var);