source: git/Singular/polys0.cc @ 675526a

fieker-DuValspielwiese
Last change on this file since 675526a was a29995, checked in by Olaf Bachmann <obachman@…>, 23 years ago
* towards tailRings for local case git-svn-id: file:///usr/local/Singular/svn/trunk@4777 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[0e1846]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[a29995]4/* $Id: polys0.cc,v 1.18 2000-11-28 11:50:56 obachman Exp $ */
[32df82]5
[0e1846]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 "numbers.h"
15#include "ring.h"
[c5f4b9]16#include "p_polys.h"
17#include "febase.h"
[0e1846]18
19/*2
20* writes a monomial (p),
21* uses form x*gen(.) if ko != coloumn number of p
22*/
[c5f4b9]23static void writemon(poly p, int ko, ring r)
[0e1846]24{
25  BOOLEAN wroteCoef=FALSE,writeGen=FALSE;
26
[8a150b]27  if (pGetCoeff(p)!=NULL)
28    nNormalize(pGetCoeff(p));
[116a98]29
[c5f4b9]30  if (((p_GetComp(p,r) == (short)ko)
31    &&(p_LmIsConstantComp(p, r)))
[da97958]32  || ((!nIsOne(pGetCoeff(p)))
[116a98]33    && (!nIsMOne(pGetCoeff(p)))
34  )
[0e1846]35  )
36  {
[da97958]37    nWrite(p->coef);
[c5f4b9]38    wroteCoef=(rShortOut(r) == FALSE ||(r->parameter!=NULL));
[da97958]39    writeGen=TRUE;
40  }
41  else if (nIsMOne(pGetCoeff(p)))
42  {
[be0519]43    if (nGreaterZero(pGetCoeff(p)))
44    {
45      nWrite(p->coef);
[c5f4b9]46      wroteCoef=(rShortOut(r) == FALSE ||(r->parameter!=NULL));
[be0519]47      writeGen=TRUE;
48    }
[a9a7be]49    else
[be0519]50      StringAppendS("-");
[0e1846]51  }
[da97958]52
53  int i;
[c5f4b9]54  for (i=0; i<r->N; i++)
[0e1846]55  {
56    {
[c5f4b9]57      Exponent_t ee = p_GetExp(p,i+1,r);
[0e1846]58      if (ee!=0)
59      {
60        if (wroteCoef)
61          StringAppendS("*");
62        //else
[c5f4b9]63          wroteCoef=(rShortOut(r) == FALSE);
[0e1846]64        writeGen=TRUE;
[c5f4b9]65        StringAppendS(rRingVar(i, r));
[0e1846]66        if (ee != 1)
67        {
[c5f4b9]68          if (rShortOut(r)==0) StringAppendS("^");
[0e1846]69          StringAppend("%d", ee);
70        }
71      }
72    }
73  }
[954622]74  //StringAppend("{%d}",p->Order);
[c5f4b9]75  if (p_GetComp(p, r) != (Exponent_t)ko)
[0e1846]76  {
77    if (writeGen) StringAppendS("*");
[c5f4b9]78    StringAppend("gen(%d)", p_GetComp(p, r));
[0e1846]79  }
80}
81
[beb237]82char* p_String0(poly p, ring lmRing, ring tailRing)
[0e1846]83{
84  if (p == NULL)
85  {
86    return StringAppendS("0");
87  }
[47bc1c]88  if ((p_GetComp(p, lmRing) == 0) || (!lmRing->VectorOut))
[0e1846]89  {
[47bc1c]90    writemon(p,0, lmRing);
[0e1846]91    p = pNext(p);
92    while (p!=NULL)
93    {
94      if ((p->coef==NULL)||nGreaterZero(p->coef))
95        StringAppendS("+");
[47bc1c]96      writemon(p,0, tailRing);
[0e1846]97      p = pNext(p);
98    }
99    return StringAppendS("");
100  }
101
[51c163]102  Exponent_t k = 1;
[0e1846]103  StringAppendS("[");
104  loop
105  {
[47bc1c]106    while (k < p_GetComp(p,lmRing))
[0e1846]107    {
108      StringAppendS("0,");
109      k++;
110    }
[47bc1c]111    writemon(p,k,lmRing);
[da97958]112    pIter(p);
[47bc1c]113    while ((p!=NULL) && (k == p_GetComp(p, tailRing)))
[0e1846]114    {
115      if (nGreaterZero(p->coef)) StringAppendS("+");
[47bc1c]116      writemon(p,k,tailRing);
[da97958]117      pIter(p);
[0e1846]118    }
119    if (p == NULL) break;
120    StringAppendS(",");
121    k++;
122  }
123  return StringAppendS("]");
124}
125
[beb237]126char* p_String(poly p, ring lmRing, ring tailRing)
[0e1846]127{
128  StringSetS("");
[beb237]129  return p_String0(p, lmRing, tailRing);
[0e1846]130}
131
132/*2
133* writes a polynomial p to stdout
134*/
[beb237]135void p_Write0(poly p, ring lmRing, ring tailRing)
[0e1846]136{
[beb237]137  PrintS(p_String(p, lmRing, tailRing));
[0e1846]138}
139
140/*2
141* writes a polynomial p to stdout followed by \n
142*/
[beb237]143void p_Write(poly p, ring lmRing, ring tailRing)
[0e1846]144{
[beb237]145  p_Write0(p, lmRing, tailRing);
[0e1846]146  PrintLn();
147}
148
149/*2
150*the standard debugging output:
[47bc1c]151*print the first two monomials of the poly (wrp) or only the lead term (wrp0),
[0e1846]152*possibly followed by the string "+..."
153*/
[beb237]154void p_wrp0(poly p, ring ri)
[37fd1b]155{
156  poly r;
157
158  if (p==NULL) PrintS("NULL");
[beb237]159  else if (pNext(p)==NULL) p_Write0(p, ri);
[37fd1b]160  else
161  {
162    r = pNext(p);
163    pNext(p) = NULL;
[beb237]164    p_Write0(p, ri);
[37fd1b]165    if (r!=NULL)
166    {
167      PrintS("+...");
168      pNext(p) = r;
169    }
170  }
171}
[a29995]172#if 1
[beb237]173void p_wrp(poly p, ring lmRing, ring tailRing)
[0e1846]174{
175  poly r;
176
177  if (p==NULL) PrintS("NULL");
[beb237]178  else if (pNext(p)==NULL) p_Write0(p, lmRing);
[0e1846]179  else
180  {
181    r = pNext(pNext(p));
182    pNext(pNext(p)) = NULL;
[beb237]183    p_Write0(p, lmRing, tailRing);
[0e1846]184    if (r!=NULL)
185    {
186      PrintS("+...");
187      pNext(pNext(p)) = r;
188    }
189  }
190}
[a29995]191#else
192// this is for use with buckets
193void p_wrp(poly p, ring lmRing, ring tailRing)
194{
195  poly r;
196
197  if (p==NULL) PrintS("NULL");
198  else if (pNext(p)==NULL) p_Write0(p, lmRing);
199  else
200  {
201    r = pNext(p);
202    pNext(p) = NULL;
203    p_Write0(p, lmRing, tailRing);
204    pNext(p) = r;
205  }
206}
207#endif
Note: See TracBrowser for help on using the repository browser.