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 (pGetCoeff(p)!=NULL)
33  n_Normalize(pGetCoeff(p),C);
34 
35  if (((p_GetComp(p,r) == (short)ko)
36  &&(p_LmIsConstantComp(p, r)))
37  || ((!n_IsOne(pGetCoeff(p),C))
38  && (!n_IsMOne(pGetCoeff(p),C))
39  )
40  )
41  {
42  if( bNotShortOut )
43  n_WriteLong(pGetCoeff(p),C);
44  else
45  n_WriteShort(pGetCoeff(p),C);
46 
47  wroteCoef=(bNotShortOut)
48  || (rParameter(r)!=NULL)
49  || rField_is_R(r) || (rField_is_long_R(r)) || (rField_is_long_C(r));
50  writeGen=TRUE;
51  }
52  else if (n_IsMOne(pGetCoeff(p),C))
53  {
54  if (n_GreaterZero(pGetCoeff(p),C))
55  {
56  if( bNotShortOut )
57  n_WriteLong(pGetCoeff(p),C);
58  else
59  n_WriteShort(pGetCoeff(p),C);
60 
61  wroteCoef=(bNotShortOut)
62  || (rParameter(r)!=NULL)
63  || rField_is_R(r) || (rField_is_long_R(r)) || (rField_is_long_C(r));
64  writeGen=TRUE;
65  }
66  else
67  StringAppendS("-");
68  }
69 
70  int i;
71  for (i=0; i<rVar(r); i++)
72  {
73  {
74  long ee = p_GetExp(p,i+1,r);
75  if (ee!=0L)
76  {
77  if (wroteCoef)
78  StringAppendS("*");
79  //else
80  wroteCoef=(bNotShortOut);
81  writeGen=TRUE;
82  StringAppendS(rRingVar(i, r));
83  if (ee != 1L)
84  {
85  if (bNotShortOut) StringAppendS("^");
86  StringAppend("%ld", ee);
87  }
88  }
89  }
90  }
91  //StringAppend("{%d}",p->Order);
92  if (p_GetComp(p, r) != (long)ko)
93  {
94  if (writeGen) StringAppendS("*");
95  StringAppend("gen(%d)", p_GetComp(p, r));
96  }
97 }
98 
99 /// if possible print p in a short way...
100 void p_String0Short(const poly p, ring lmRing, ring tailRing)
101 {
102  // NOTE: the following (non-thread-safe!) UGLYNESS
103  // (changing naRing->ShortOut for a while) is due to Hans!
104  // Just think of other ring using the VERY SAME naRing and possible
105  // side-effects...
106  const BOOLEAN bLMShortOut = rShortOut(lmRing);
107  const BOOLEAN bTAILShortOut = rShortOut(tailRing);
108 
109  lmRing->ShortOut = rCanShortOut(lmRing);
110  tailRing->ShortOut = rCanShortOut(tailRing);
111 
112  p_String0(p, lmRing, tailRing);
113 
114  lmRing->ShortOut = bLMShortOut;
115  tailRing->ShortOut = bTAILShortOut;
116 }
117 
118 /// print p in a long way...
119 void p_String0Long(const poly p, ring lmRing, ring tailRing)
120 {
121  // NOTE: the following (non-thread-safe!) UGLYNESS
122  // (changing naRing->ShortOut for a while) is due to Hans!
123  // Just think of other ring using the VERY SAME naRing and possible
124  // side-effects...
125  const BOOLEAN bLMShortOut = rShortOut(lmRing);
126  const BOOLEAN bTAILShortOut = rShortOut(tailRing);
127 
128  lmRing->ShortOut = FALSE;
129  tailRing->ShortOut = FALSE;
130 
131  p_String0(p, lmRing, tailRing);
132 
133  lmRing->ShortOut = bLMShortOut;
134  tailRing->ShortOut = bTAILShortOut;
135 }
136 
137 
138 void p_String0(poly p, ring lmRing, ring tailRing)
139 {
140  if (p == NULL)
141  {
142  StringAppendS("0");
143  return;
144  }
145  if ((p_GetComp(p, lmRing) == 0) || (!lmRing->VectorOut))
146  {
147  writemon(p,0, lmRing);
148  p = pNext(p);
149  while (p!=NULL)
150  {
151  assume((p->coef==NULL)||(!n_IsZero(p->coef,tailRing->cf)));
152  if ((p->coef==NULL)||n_GreaterZero(p->coef,tailRing->cf))
153  StringAppendS("+");
154  writemon(p,0, tailRing);
155  p = pNext(p);
156  }
157  return;
158  }
159 
160  long k = 1;
161  StringAppendS("[");
162  loop
163  {
164  while (k < p_GetComp(p,lmRing))
165  {
166  StringAppendS("0,");
167  k++;
168  }
169  writemon(p,k,lmRing);
170  pIter(p);
171  while ((p!=NULL) && (k == p_GetComp(p, tailRing)))
172  {
173  if (n_GreaterZero(p->coef,tailRing->cf)) StringAppendS("+");
174  writemon(p,k,tailRing);
175  pIter(p);
176  }
177  if (p == NULL) break;
178  StringAppendS(",");
179  k++;
180  }
181  StringAppendS("]");
182 }
183 
184 char* p_String(poly p, ring lmRing, ring tailRing)
185 {
186  StringSetS("");
187  p_String0(p, lmRing, tailRing);
188  return StringEndS();
189 }
190 
191 /*2
192 * writes a polynomial p to stdout
193 */
194 void p_Write0(poly p, ring lmRing, ring tailRing)
195 {
196  char *s=p_String(p, lmRing, tailRing);
197  PrintS(s);
198  omFree(s);
199 }
200 
201 /*2
202 * writes a polynomial p to stdout followed by \n
203 */
204 void p_Write(poly p, ring lmRing, ring tailRing)
205 {
206  p_Write0(p, lmRing, tailRing);
207  PrintLn();
208 }
209 
210 #if !defined(__OPTIMIZE__) || defined(KDEBUG)
211 /*2
212 *the standard debugging output:
213 *print the first two monomials of the poly (wrp) or only the lead term (wrp0),
214 *possibly followed by the string "+..."
215 */
216 void p_wrp0(poly p, ring ri)
217 {
218  poly r;
219 
220  if (p==NULL) PrintS("NULL");
221  else if (pNext(p)==NULL) p_Write0(p, ri);
222  else
223  {
224  r = pNext(p);
225  pNext(p) = NULL;
226  p_Write0(p, ri);
227  if (r!=NULL)
228  {
229  PrintS("+...");
230  pNext(p) = r;
231  }
232  }
233 }
234 #endif
235 void p_wrp(poly p, ring lmRing, ring tailRing)
236 {
237  poly r;
238 
239  if (p==NULL) PrintS("NULL");
240  else if (pNext(p)==NULL) p_Write0(p, lmRing);
241  else
242  {
243  r = pNext(pNext(p));
244  pNext(pNext(p)) = NULL;
245  p_Write0(p, lmRing, tailRing);
246  if (r!=NULL)
247  {
248  PrintS("+...");
249  pNext(pNext(p)) = r;
250  }
251  }
252 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
char * p_String(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:184
static BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
Definition: p_polys.h:937
void PrintLn()
Definition: reporter.cc:322
BEGIN_NAMESPACE_SINGULARXX const ring lmRing
Definition: DebugPrint.h:30
loop
Definition: myNF.cc:98
#define FALSE
Definition: auxiliary.h:140
return P p
Definition: myNF.cc:203
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:468
static BOOLEAN rField_is_R(const ring r)
Definition: ring.h:458
#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:520
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:531
void p_String0Short(const poly p, ring lmRing, ring tailRing)
if possible print p in a short way...
Definition: polys0.cc:100
#define TRUE
Definition: auxiliary.h:144
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:577
int k
Definition: cfEzgcd.cc:93
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:564
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:525
#define pIter(p)
Definition: monomials.h:44
void p_Write(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:204
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:235
const ring r
Definition: syzextra.cc:208
void p_Write0(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:194
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:465
#define omFree(addr)
Definition: omAllocDecl.h:261
polyrec * poly
Definition: hilb.h:10
#define assume(x)
Definition: mod2.h:405
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:119
#define StringAppend
Definition: emacs.cc:82
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:294
static char * rRingVar(short i, const ring r)
Definition: ring.h:516
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:464
void p_wrp0(poly p, ring ri)
Definition: polys0.cc:216
static BOOLEAN rField_is_long_C(const ring r)
Definition: ring.h:485
#define NULL
Definition: omList.c:10
static BOOLEAN rField_is_long_R(const ring r)
Definition: ring.h:482
#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:138
static FORCE_INLINE BOOLEAN n_IsMOne(number n, const coeffs r)
TRUE iff 'n' represents the additive inverse of the one element, i.e. -1.
Definition: coeffs.h:472
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff 'n' 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)/: 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:494
int BOOLEAN
Definition: auxiliary.h:131
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:587
static FORCE_INLINE void n_WriteLong(number &n, const coeffs r)
write to the output buffer of the currently used reporter
Definition: coeffs.h:582
static void writemon(poly p, int ko, const ring r)
Definition: polys0.cc:23