1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: pInline.cc |
---|
6 | * Purpose: implementation of poly Level 0 functions |
---|
7 | * Author: obachman (Olaf Bachmann) |
---|
8 | * Created: 8/00 |
---|
9 | * Version: $Id$ |
---|
10 | *******************************************************************/ |
---|
11 | #ifndef PINLINE0_H |
---|
12 | #define PINLINE0_H |
---|
13 | |
---|
14 | #if defined(DO_PINLINE0) |
---|
15 | #define PINLINE0 static inline |
---|
16 | #else |
---|
17 | #define PINLINE0 |
---|
18 | #endif |
---|
19 | |
---|
20 | #include <kernel/p_polys.h> |
---|
21 | #include <kernel/ring.h> |
---|
22 | |
---|
23 | PINLINE0 void p_SetCompP(poly p, int i, ring r) |
---|
24 | { |
---|
25 | if (p != NULL) |
---|
26 | { |
---|
27 | #ifdef PDEBUG |
---|
28 | poly q = p; |
---|
29 | int l = 0; |
---|
30 | #endif |
---|
31 | |
---|
32 | if (rOrd_SetCompRequiresSetm(r)) |
---|
33 | { |
---|
34 | do |
---|
35 | { |
---|
36 | p_SetComp(p, i, r); |
---|
37 | p_SetmComp(p, r); |
---|
38 | #ifdef PDEBUG |
---|
39 | l++; |
---|
40 | #endif |
---|
41 | pIter(p); |
---|
42 | } |
---|
43 | while (p != NULL); |
---|
44 | } |
---|
45 | else |
---|
46 | { |
---|
47 | do |
---|
48 | { |
---|
49 | p_SetComp(p, i, r); |
---|
50 | #ifdef PDEBUG |
---|
51 | l++; |
---|
52 | #endif |
---|
53 | pIter(p); |
---|
54 | } |
---|
55 | while(p != NULL); |
---|
56 | } |
---|
57 | #ifdef PDEBUG |
---|
58 | p_Test(q, r); |
---|
59 | assume(l == pLength(q)); |
---|
60 | #endif |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | PINLINE0 void p_SetCompP(poly p, int i, ring lmRing, ring tailRing) |
---|
65 | { |
---|
66 | if (p != NULL) |
---|
67 | { |
---|
68 | p_SetComp(p, i, lmRing); |
---|
69 | p_SetmComp(p, lmRing); |
---|
70 | p_SetCompP(pNext(p), i, tailRing); |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | // returns minimal column number in the modul element a (or 0) |
---|
75 | PINLINE0 long p_MinComp(poly p, ring lmRing, ring tailRing) |
---|
76 | { |
---|
77 | long result,i; |
---|
78 | |
---|
79 | if(p==NULL) return 0; |
---|
80 | result = p_GetComp(p,lmRing); |
---|
81 | if (result != 0) |
---|
82 | { |
---|
83 | loop |
---|
84 | { |
---|
85 | pIter(p); |
---|
86 | if(p==NULL) break; |
---|
87 | i = p_GetComp(p,tailRing); |
---|
88 | if (i<result) result = i; |
---|
89 | } |
---|
90 | } |
---|
91 | return result; |
---|
92 | } |
---|
93 | |
---|
94 | // returns maximal column number in the modul element a (or 0) |
---|
95 | PINLINE0 long p_MaxComp(poly p, ring lmRing, ring tailRing) |
---|
96 | { |
---|
97 | long result,i; |
---|
98 | |
---|
99 | if(p==NULL) return 0; |
---|
100 | result = p_GetComp(p, lmRing); |
---|
101 | if (result != 0) |
---|
102 | { |
---|
103 | loop |
---|
104 | { |
---|
105 | pIter(p); |
---|
106 | if(p==NULL) break; |
---|
107 | i = p_GetComp(p, tailRing); |
---|
108 | if (i>result) result = i; |
---|
109 | } |
---|
110 | } |
---|
111 | return result; |
---|
112 | } |
---|
113 | |
---|
114 | BOOLEAN p_IsConstantPoly(const poly p, const ring r) |
---|
115 | { |
---|
116 | poly pp=p; |
---|
117 | while(pp!=NULL) |
---|
118 | { |
---|
119 | if (! p_LmIsConstantComp(pp, r)) |
---|
120 | return FALSE; |
---|
121 | pIter(pp); |
---|
122 | } |
---|
123 | return TRUE; |
---|
124 | } |
---|
125 | |
---|
126 | /*************************************************************** |
---|
127 | * |
---|
128 | * poly things which are independent of ring |
---|
129 | * |
---|
130 | ***************************************************************/ |
---|
131 | PINLINE0 poly pReverse(poly p) |
---|
132 | { |
---|
133 | if (p == NULL || pNext(p) == NULL) return p; |
---|
134 | |
---|
135 | poly q = pNext(p), // == pNext(p) |
---|
136 | qn; |
---|
137 | pNext(p) = NULL; |
---|
138 | do |
---|
139 | { |
---|
140 | qn = pNext(q); |
---|
141 | pNext(q) = p; |
---|
142 | p = q; |
---|
143 | q = qn; |
---|
144 | } |
---|
145 | while (qn != NULL); |
---|
146 | return p; |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | /*2 |
---|
151 | * returns the length of a (numbers of monomials) |
---|
152 | */ |
---|
153 | PINLINE0 int pLength(poly a) |
---|
154 | { |
---|
155 | int l = 0; |
---|
156 | |
---|
157 | while (a!=NULL) |
---|
158 | { |
---|
159 | pIter(a); |
---|
160 | l++; |
---|
161 | } |
---|
162 | return l; |
---|
163 | } |
---|
164 | |
---|
165 | /*2 |
---|
166 | * returns the length of a (numbers of monomials) |
---|
167 | * respect syzComp |
---|
168 | */ |
---|
169 | poly pLast(poly a, int &l); |
---|
170 | |
---|
171 | #endif // PINLINE_CC |
---|
172 | |
---|