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

« back to all changes in this revision

Viewing changes to share/contrib/sarag/lowLevel.mac

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ------------------------------------------------------------------- */
 
2
/* SARAG - Low Level Routines                                          */
 
3
/* by Fabrizio Caruso                                                  */
 
4
 
 
5
 
 
6
/* It expands a polynomial if ASSUME_EXPANDED is false */
 
7
expandIf(pol)::=
 
8
  buildq([pol],
 
9
  if ASSUME_EXPANDED then
 
10
    pol
 
11
  else
 
12
    ratexpand(pol));
 
13
 
 
14
 
 
15
/* Degree of a polynomial (MACRO) */
 
16
 
 
17
degree(poly,indet) ::=
 
18
  buildq([poly,indet],if poly = 0 then -1 else hipow(poly,indet));
 
19
 
 
20
 
 
21
/* Leading coefficient of a polynomial */
 
22
leadCoeff(poly,indet)::=
 
23
   buildq([poly,indet],
 
24
          ratcoeff(poly,indet,degree(poly,indet)));
 
25
 
 
26
 
 
27
/* Leading term of a polynomial */
 
28
leadTerm(poly,indet)::=
 
29
   buildq([poly,indet],
 
30
          indet^degree(poly,indet));
 
31
 
 
32
/* Leading monomial of a polynomial */
 
33
leadMono(poly,indet)::=
 
34
   buildq([poly,indet],
 
35
          leadCoeff(poly,indet)*leadTerm(poly,indet));
 
36
 
 
37
/* Tail of a polynomial */
 
38
Tail(poly,indet) ::=
 
39
   buildq([poly,indet],
 
40
          poly-leadMono(poly,indet));
 
41
 
 
42
 
 
43
/* Sign function */
 
44
 
 
45
sgn(val) ::=
 
46
  buildq([val], if val = 0 then 0 else if val < 0 then -1 else 1); 
 
47
 
 
48
 
 
49
/* Array-related routines */
 
50
 
 
51
/* Number of dimensions */
 
52
numOfDim(ar) :=
 
53
  second(arrayinfo(ar));
 
54
 
 
55
/* Array degree */
 
56
arrayDegree(ar) :=
 
57
  first(third(arrayinfo(ar)));
 
58
 
 
59
/* Array length */
 
60
arrayLength(ar) :=
 
61
  first(third(arrayinfo(ar)))+1;
 
62
 
 
63
/* Number of rows */
 
64
numOfRows(ar) :=
 
65
  first(third(arrayinfo(ar)))+1;
 
66
 
 
67
/* Number of columns */
 
68
numOfCols(ar) :=
 
69
  second(third(arrayinfo(ar)))+1;
 
70
 
 
71
/* It makes a polynomial out of a list */
 
72
list2poly(lst,var) :=
 
73
  sum(lst[i]*var^(i-1),i,1,length(lst));
 
74
 
 
75
poly2list(pol,var) :=
 
76
    makelist(coeff(pol,var,i),i,0,degree(pol,var));
 
77
 
 
78
matrix2list(mtx) :=
 
79
    makelist(mtx[i],i,1,length(mtx));
 
80
    
 
81
 
 
82
/* list of lists -> bidimensional array */
 
83
list2array(lst) :=
 
84
  block([nRows,nCols,i,j,res],
 
85
   nRows : length(lst),
 
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],
 
91
   return(res)
 
92
   ); 
 
93
 
 
94
 
 
95
 
 
96
/* bidimensional array -> list of lists */
 
97
array2list(arr) :=
 
98
  block([nRows,nCols,i,j,newRow,res],
 
99
   nRows : first(third(arrayinfo(arr)))+1,
 
100
   nCols : second(third(arrayinfo(arr)))+1,
 
101
   res : [],
 
102
 
 
103
   for i : 1 thru nRows do
 
104
     (
 
105
     newRow : [],
 
106
     for j : 1 thru nCols do
 
107
       newRow : endcons(arr[i-1,j-1],newRow),
 
108
 
 
109
     res : endcons(newRow,res)
 
110
     ),
 
111
   return(res)
 
112
   );
 
113
 
 
114
 
 
115
array2singleList(arr) :=
 
116
  makelist(arr[j],j,0,first(third(arrayinfo(arr))));
 
117
 
 
118
 
 
119
singleList2array(lst) := 
 
120
  block([res,i],
 
121
  res:make_array('any,length(lst)),
 
122
  for i : 1 thru length(lst) do
 
123
     res[i-1] : lst[i],
 
124
  return(res)
 
125
  );
 
126
 
 
127
 
 
128
poly2array(pol,var) :=
 
129
  singleList2array(poly2list(pol,var));
 
130
 
 
131
array2poly(arr,var) :=
 
132
  list2poly(array2singleList(arr),var);