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