source: git/Singular/polys0.cc @ a9a7be

spielwiese
Last change on this file since a9a7be was a9a7be, checked in by Olaf Bachmann <obachman@…>, 25 years ago
* walk stuff git-svn-id: file:///usr/local/Singular/svn/trunk@3682 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: polys0.cc,v 1.11 1999-09-27 15:05:31 obachman Exp $ */
5
6/*
7* ABSTRACT - all basic methods to convert polynomials to strings
8*/
9
10/* includes */
11#include "mod2.h"
12#include "tok.h"
13#include "structs.h"
14#include "febase.h"
15#include "numbers.h"
16#include "ring.h"
17//#include "ipid.h"
18#include "polys.h"
19
20BOOLEAN pVectorOut=TRUE;
21/*2
22* writes a monomial (p),
23* uses form x*gen(.) if ko != coloumn number of p
24*/
25static void writemon(poly p, int ko)
26{
27  BOOLEAN wroteCoef=FALSE,writeGen=FALSE;
28
29  if (pGetCoeff(p)!=NULL)
30    nNormalize(pGetCoeff(p));
31
32  if (((pGetComp(p) == (short)ko)
33    &&(pIsConstantComp(p)))
34  || ((!nIsOne(pGetCoeff(p)))
35    && (!nIsMOne(pGetCoeff(p)))
36  )
37#ifdef DRING
38  || (pDRING && pdIsConstantComp(p))
39#endif
40  )
41  {
42    nWrite(p->coef);
43    wroteCoef=((pShortOut==0)||(currRing->parameter!=NULL));
44    writeGen=TRUE;
45  }
46  else if (nIsMOne(pGetCoeff(p)))
47  {
48    if (nGreaterZero(pGetCoeff(p)))
49    {
50      nWrite(p->coef);
51      wroteCoef=((pShortOut==0)||(currRing->parameter!=NULL));
52      writeGen=TRUE;
53    }
54    else
55      StringAppendS("-");
56  }
57
58  int i;
59  for (i=0; i<pVariables; i++)
60  {
61#ifdef DRING
62    if ((!pDRING)||(i!=2*pdN))
63#endif
64    {
65      Exponent_t ee = pGetExp(p,i+1);
66      if (ee!=0)
67      {
68        if (wroteCoef)
69          StringAppendS("*");
70        //else
71          wroteCoef=(pShortOut==0);
72        writeGen=TRUE;
73#ifdef DRING
74        if((pDRING)&&(pdN<=i)&&(i<2*pdN)&&(pdDFlag(p)==0))
75        {
76          StringAppendS(RingVar(i-pdN));
77          ee=-ee;
78        }
79        else
80          StringAppendS(RingVar(i));
81#else
82        StringAppendS(RingVar(i));
83#endif
84        if (ee != 1)
85        {
86          if (pShortOut==0) StringAppendS("^");
87          StringAppend("%d", ee);
88        }
89      }
90    }
91  }
92  //StringAppend("{%d}",p->Order);
93  if (pGetComp(p) != (Exponent_t)ko)
94  {
95    if (writeGen) StringAppendS("*");
96    StringAppend("gen(%d)", pGetComp(p));
97  }
98}
99
100char* pString0(poly p)
101{
102  if (p == NULL)
103  {
104    return StringAppendS("0");
105  }
106  if ((pGetComp(p) == 0) || (!pVectorOut))
107  {
108    writemon(p,0);
109    p = pNext(p);
110    while (p!=NULL)
111    {
112      if ((p->coef==NULL)||nGreaterZero(p->coef))
113        StringAppendS("+");
114      writemon(p,0);
115      p = pNext(p);
116    }
117    return StringAppendS("");
118  }
119
120  Exponent_t k = 1;
121  StringAppendS("[");
122  loop
123  {
124    while (k < pGetComp(p))
125    {
126      StringAppendS("0,");
127      k++;
128    }
129    writemon(p,k);
130    pIter(p);
131    while ((p!=NULL) && (k == pGetComp(p)))
132    {
133      if (nGreaterZero(p->coef)) StringAppendS("+");
134      writemon(p,k);
135      pIter(p);
136    }
137    if (p == NULL) break;
138    StringAppendS(",");
139    k++;
140  }
141  return StringAppendS("]");
142}
143
144char* pString(poly p)
145{
146  StringSetS("");
147  return pString0(p);
148}
149
150/*2
151* writes a polynomial p to stdout
152*/
153void pWrite0(poly p)
154{
155  PrintS(pString(p));
156}
157
158/*2
159* writes a polynomial p to stdout followed by \n
160*/
161void pWrite(poly p)
162{
163  pWrite0(p);
164  PrintLn();
165}
166
167/*2
168*the standard debugging output:
169*print the first two monomials of the poly,
170*possibly followed by the string "+..."
171*/
172void wrp(poly p)
173{
174  poly r;
175
176  if (p==NULL) PrintS("NULL");
177  else if (pNext(p)==NULL) pWrite0(p);
178  else
179  {
180    r = pNext(pNext(p));
181    pNext(pNext(p)) = NULL;
182    pWrite0(p);
183    if (r!=NULL)
184    {
185      PrintS("+...");
186      pNext(pNext(p)) = r;
187    }
188  }
189}
Note: See TracBrowser for help on using the repository browser.