source: git/kernel/polys0.cc @ 5fdd0f

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