source: git/Singular/polys0.cc @ 6a6dccc

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