source: git/Singular/polys0.cc @ 799ce1

spielwiese
Last change on this file since 799ce1 was 954622, checked in by Hans Schönemann <hannes@…>, 26 years ago
* hannes: fixes for "TEST_MAC_ORDER" and some optimizations for binomials (binom.cc binom.h claptmpl.cc ipid.h kstd1.cc kstd2.cc kutil.cc polys-impl.h polys.cc polys.h polys0.cc polys1.cc ring.h spolys.cc spolys0.h) git-svn-id: file:///usr/local/Singular/svn/trunk@1005 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.2 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: polys0.cc,v 1.8 1998-01-05 16:39:27 Singular 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  nNormalize(pGetCoeff(p));
30
31  if (((pGetComp(p) == (short)ko)
32    &&(pIsConstantComp(p)))
33  || ((!nIsOne(pGetCoeff(p)))
34    && (!nIsMOne(pGetCoeff(p)))
35  )
36#ifdef DRING
37  || (pDRING && pdIsConstantComp(p))
38#endif
39  )
40  {
41    nWrite(p->coef);
42    wroteCoef=((pShortOut==0)||(currRing->parameter!=NULL));
43    writeGen=TRUE;
44  }
45  else if (nIsMOne(pGetCoeff(p)))
46  {
47    StringAppendS("-");
48  }
49
50  int i;
51  for (i=0; i<pVariables; i++)
52  {
53#ifdef DRING
54    if ((!pDRING)||(i!=2*pdN))
55#endif
56    {
57      Exponent_t ee = pGetExp(p,i+1);
58      if (ee!=0)
59      {
60        if (wroteCoef)
61          StringAppendS("*");
62        //else
63          wroteCoef=(pShortOut==0);
64        writeGen=TRUE;
65#ifdef DRING
66        if((pDRING)&&(pdN<=i)&&(i<2*pdN)&&(pdDFlag(p)==0))
67        {
68          StringAppendS(RingVar(i-pdN));
69          ee=-ee;
70        }
71        else
72          StringAppendS(RingVar(i));
73#else
74        StringAppendS(RingVar(i));
75#endif
76        if (ee != 1)
77        {
78          if (pShortOut==0) StringAppendS("^");
79          StringAppend("%d", ee);
80        }
81      }
82    }
83  }
84  //StringAppend("{%d}",p->Order);
85  if (pGetComp(p) != (Exponent_t)ko)
86  {
87    if (writeGen) StringAppendS("*");
88    StringAppend("gen(%d)", pGetComp(p));
89  }
90}
91
92char* pString0(poly p)
93{
94  if (p == NULL)
95  {
96    return StringAppendS("0");
97  }
98  if ((pGetComp(p) == 0) || (!pVectorOut))
99  {
100    writemon(p,0);
101    p = pNext(p);
102    while (p!=NULL)
103    {
104      if ((p->coef==NULL)||nGreaterZero(p->coef))
105        StringAppendS("+");
106      writemon(p,0);
107      p = pNext(p);
108    }
109    return StringAppendS("");
110  }
111
112  Exponent_t k = 1;
113  StringAppendS("[");
114  loop
115  {
116    while (k < pGetComp(p))
117    {
118      StringAppendS("0,");
119      k++;
120    }
121    writemon(p,k);
122    pIter(p);
123    while ((p!=NULL) && (k == pGetComp(p)))
124    {
125      if (nGreaterZero(p->coef)) StringAppendS("+");
126      writemon(p,k);
127      pIter(p);
128    }
129    if (p == NULL) break;
130    StringAppendS(",");
131    k++;
132  }
133  return StringAppendS("]");
134}
135
136char* pString(poly p)
137{
138  StringSetS("");
139  return pString0(p);
140}
141
142/*2
143* writes a polynomial p to stdout
144*/
145void pWrite0(poly p)
146{
147  PrintS(pString(p));
148}
149
150/*2
151* writes a polynomial p to stdout followed by \n
152*/
153void pWrite(poly p)
154{
155  pWrite0(p);
156  PrintLn();
157}
158
159/*2
160*the standard debugging output:
161*print the first two monomials of the poly,
162*possibly followed by the string "+..."
163*/
164void wrp(poly p)
165{
166  poly r;
167
168  if (p==NULL) PrintS("NULL");
169  else if (pNext(p)==NULL) pWrite0(p);
170  else
171  {
172    r = pNext(pNext(p));
173    pNext(pNext(p)) = NULL;
174    pWrite0(p);
175    if (r!=NULL)
176    {
177      PrintS("+...");
178      pNext(pNext(p)) = r;
179    }
180  }
181}
Note: See TracBrowser for help on using the repository browser.