polys0.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 
5 /*
6 * ABSTRACT - all basic methods to convert polynomials to strings
7 */
8 
9 /* includes */
10 
11 #include <misc/auxiliary.h>
12 
13 // #include <polys/structs.h>
14 #include <coeffs/numbers.h>
15 #include <polys/monomials/ring.h>
17 // #include <???/febase.h>
18 
19 /*2
20 * writes a monomial (p),
21 * uses form x*gen(.) if ko != coloumn number of p
22 */
23 static void writemon(poly p, int ko, const ring r)
24 {
25  assume(r != NULL);
26  const coeffs C = r->cf;
27  assume(C != NULL);
28 
29  BOOLEAN wroteCoef=FALSE,writeGen=FALSE;
30  const BOOLEAN bNotShortOut = (rShortOut(r) == FALSE);
31 
32  if (((p_GetComp(p,r) == ko)
33  &&(p_LmIsConstantComp(p, r)))
34  || ((!n_IsOne(pGetCoeff(p),C))
35  && (!n_IsMOne(pGetCoeff(p),C))
36  )
37  )
38  {
39  if( bNotShortOut )
40  n_WriteLong(pGetCoeff(p),C);
41  else
42  n_WriteShort(pGetCoeff(p),C);
43 
44  wroteCoef=(bNotShortOut)
45  || (rParameter(r)!=NULL)
46  || rField_is_R(r) || (rField_is_long_R(r)) || (rField_is_long_C(r));
47  writeGen=TRUE;
48  }
49  else if (n_IsMOne(pGetCoeff(p),C))
50  {
51  if (n_GreaterZero(pGetCoeff(p),C))
52  {
53  if( bNotShortOut )
54  n_WriteLong(pGetCoeff(p),C);
55  else
56  n_WriteShort(pGetCoeff(p),C);
57 
58  wroteCoef=(bNotShortOut)
59  || (rParameter(r)!=NULL)
60  || rField_is_R(r) || (rField_is_long_R(r)) || (rField_is_long_C(r));
61  writeGen=TRUE;
62  }
63  else
64  StringAppendS("-");
65  }
66 
67  int i;
68  for (i=0; i<rVar(r); i++)
69  {
70  {
71  long ee = p_GetExp(p,i+1,r);
72  if (ee!=0L)
73  {
74  if (wroteCoef)
75  StringAppendS("*");
76  //else
77  wroteCoef=(bNotShortOut);
78  writeGen=TRUE;
79  StringAppendS(rRingVar(i, r));
80  if (ee != 1L)
81  {
82  if (bNotShortOut) StringAppendS("^");
83  StringAppend("%ld", ee);
84  }
85  }
86  }
87  }
88  //StringAppend("{%d}",p->Order);
89  if (p_GetComp(p, r) != (long)ko)
90  {
91  if (writeGen) StringAppendS("*");
92  StringAppend("gen(%d)", p_GetComp(p, r));
93  }
94 }
95 
96 /// if possible print p in a short way...
97 void p_String0Short(const poly p, ring lmRing, ring tailRing)
98 {
99  // NOTE: the following (non-thread-safe!) UGLYNESS
100  // (changing naRing->ShortOut for a while) is due to Hans!
101  // Just think of other ring using the VERY SAME naRing and possible
102  // side-effects...
103  const BOOLEAN bLMShortOut = rShortOut(lmRing);
104  const BOOLEAN bTAILShortOut = rShortOut(tailRing);
105 
106  lmRing->ShortOut = rCanShortOut(lmRing);
107  tailRing->ShortOut = rCanShortOut(tailRing);
108 
109  p_String0(p, lmRing, tailRing);
110 
111  lmRing->ShortOut = bLMShortOut;
112  tailRing->ShortOut = bTAILShortOut;
113 }
114 
115 /// print p in a long way...
116 void p_String0Long(const poly p, ring lmRing, ring tailRing)
117 {
118  // NOTE: the following (non-thread-safe!) UGLYNESS
119  // (changing naRing->ShortOut for a while) is due to Hans!
120  // Just think of other ring using the VERY SAME naRing and possible
121  // side-effects...
122  // but this is not a problem: i/o is not thread-safe anyway.
123  const BOOLEAN bLMShortOut = rShortOut(lmRing);
124  const BOOLEAN bTAILShortOut = rShortOut(tailRing);
125 
126  lmRing->ShortOut = FALSE;
127  tailRing->ShortOut = FALSE;
128 
129  p_String0(p, lmRing, tailRing);
130 
131  lmRing->ShortOut = bLMShortOut;
132  tailRing->ShortOut = bTAILShortOut;
133 }
134 
135 
136 void p_String0(poly p, ring lmRing, ring tailRing)
137 {
138  if (p == NULL)
139  {
140  StringAppendS("0");
141  return;
142  }
143  p_Normalize(p,lmRing);
144  if ((n_GetChar(lmRing->cf) == 0)
145  && (nCoeff_is_transExt(lmRing->cf)))
146  p_Normalize(p,lmRing); /* Manual/absfact.tst */
147  if ((p_GetComp(p, lmRing) == 0) || (!lmRing->VectorOut))
148  {
149  writemon(p,0, lmRing);
150  p = pNext(p);
151  while (p!=NULL)
152  {
153  assume((p->coef==NULL)||(!n_IsZero(p->coef,tailRing->cf)));
154  if ((p->coef==NULL)||n_GreaterZero(p->coef,tailRing->cf))
155  StringAppendS("+");
156  writemon(p,0, tailRing);
157  p = pNext(p);
158  }
159  return;
160  }
161 
162  long k = 1;
163  StringAppendS("[");
164  loop
165  {
166  while (k < p_GetComp(p,lmRing))
167  {
168  StringAppendS("0,");
169  k++;
170  }
171  writemon(p,k,lmRing);
172  pIter(p);
173  while ((p!=NULL) && (k == p_GetComp(p, tailRing)))
174  {
175  if (n_GreaterZero(p->coef,tailRing->cf)) StringAppendS("+");
176  writemon(p,k,tailRing);
177  pIter(p);
178  }
179  if (p == NULL) break;
180  StringAppendS(",");
181  k++;
182  }
183  StringAppendS("]");
184 }
185 
186 char* p_String(poly p, ring lmRing, ring tailRing)
187 {
188  StringSetS("");
189  p_String0(p, lmRing, tailRing);
190  return StringEndS();
191 }
192 
193 /*2
194 * writes a polynomial p to stdout
195 */
196 void p_Write0(poly p, ring lmRing, ring tailRing)
197 {
198  char *s=p_String(p, lmRing, tailRing);
199  PrintS(s);
200  omFree(s);
201 }
202 
203 /*2
204 * writes a polynomial p to stdout followed by \n
205 */
206 void p_Write(poly p, ring lmRing, ring tailRing)
207 {
208  p_Write0(p, lmRing, tailRing);
209  PrintLn();
210 }
211 
212 #if !defined(__OPTIMIZE__) || defined(KDEBUG)
213 /*2
214 *the standard debugging output:
215 *print the first two monomials of the poly (wrp) or only the lead term (wrp0),
216 *possibly followed by the string "+..."
217 */
218 void p_wrp0(poly p, ring ri)
219 {
220  poly r;
221 
222  if (p==NULL) PrintS("NULL");
223  else if (pNext(p)==NULL) p_Write0(p, ri);
224  else
225  {
226  r = pNext(p);
227  pNext(p) = NULL;
228  p_Write0(p, ri);
229  if (r!=NULL)
230  {
231  PrintS("+...");
232  pNext(p) = r;
233  }
234  }
235 }
236 #endif
237 void p_wrp(poly p, ring lmRing, ring tailRing)
238 {
239  poly r;
240 
241  if (p==NULL) PrintS("NULL");
242  else if (pNext(p)==NULL) p_Write0(p, lmRing);
243  else
244  {
245  r = pNext(pNext(p));
246  pNext(pNext(p)) = NULL;
247  p_Write0(p, tailRing);
248  if (r!=NULL)
249  {
250  PrintS("+...");
251  pNext(pNext(p)) = r;
252  }
253  }
254 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
char * p_String(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:186
static BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
Definition: p_polys.h:932
void PrintLn()
Definition: reporter.cc:310
BEGIN_NAMESPACE_SINGULARXX const ring lmRing
Definition: DebugPrint.h:30
loop
Definition: myNF.cc:98
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the one element.
Definition: coeffs.h:472
static BOOLEAN rField_is_R(const ring r)
Definition: ring.h:510
#define p_GetComp(p, r)
Definition: monomials.h:72
BEGIN_NAMESPACE_SINGULARXX const ring const ring tailRing
Definition: DebugPrint.h:30
static BOOLEAN rShortOut(const ring r)
Definition: ring.h:572
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:583
void p_String0Short(const poly p, ring lmRing, ring tailRing)
if possible print p in a short way...
Definition: polys0.cc:97
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:448
#define TRUE
Definition: auxiliary.h:98
int k
Definition: cfEzgcd.cc:93
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:616
char * StringEndS()
Definition: reporter.cc:151
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
static BOOLEAN rCanShortOut(const ring r)
Definition: ring.h:577
static FORCE_INLINE void n_WriteLong(number n, const coeffs r)
write to the output buffer of the currently used reporter
Definition: coeffs.h:587
#define pIter(p)
Definition: monomials.h:44
void p_Write(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:206
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:237
const ring r
Definition: syzextra.cc:208
void p_Write0(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:196
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:464
#define omFree(addr)
Definition: omAllocDecl.h:261
#define assume(x)
Definition: mod2.h:394
The main handler for Singular numbers which are suitable for Singular polynomials.
void StringSetS(const char *st)
Definition: reporter.cc:128
void StringAppendS(const char *st)
Definition: reporter.cc:107
All the auxiliary stuff.
void p_String0Long(const poly p, ring lmRing, ring tailRing)
print p in a long way...
Definition: polys0.cc:116
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition: coeffs.h:935
#define StringAppend
Definition: emacs.cc:82
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:284
static char * rRingVar(short i, const ring r)
Definition: ring.h:568
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the zero element.
Definition: coeffs.h:468
void p_wrp0(poly p, ring ri)
Definition: polys0.cc:218
static BOOLEAN rField_is_long_C(const ring r)
Definition: ring.h:537
void p_Normalize(poly p, const ring r)
Definition: p_polys.cc:3633
#define NULL
Definition: omList.c:10
static BOOLEAN rField_is_long_R(const ring r)
Definition: ring.h:534
#define pNext(p)
Definition: monomials.h:43
void p_String0(poly p, ring lmRing, ring tailRing)
print p according to ShortOut in lmRing & tailRing
Definition: polys0.cc:136
static FORCE_INLINE BOOLEAN n_IsMOne(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the additive inverse of the one element, i.e. -1.
Definition: coeffs.h:476
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff &#39;n&#39; is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2), where m is the long representing n in C: TRUE iff (Im(n) != 0 and Im(n) >= 0) or (Im(n) == 0 and Re(n) >= 0) in K(a)/<p(a)>: TRUE iff (n != 0 and (LC(n) > 0 or deg(n) > 0)) in K(t_1, ..., t_n): TRUE iff (LC(numerator(n) is a constant and > 0) or (LC(numerator(n) is not a constant) in Z/2^kZ: TRUE iff 0 < n <= 2^(k-1) in Z/mZ: TRUE iff the internal mpz is greater than zero in Z: TRUE iff n > 0
Definition: coeffs.h:498
polyrec * poly
Definition: hilb.h:10
static FORCE_INLINE void n_WriteShort(number n, const coeffs r)
write to the output buffer of the currently used reporter in a shortest possible way, e.g. in K(a): a2 instead of a^2
Definition: coeffs.h:592
int BOOLEAN
Definition: auxiliary.h:85
static void writemon(poly p, int ko, const ring r)
Definition: polys0.cc:23