1 #include "monomial.h"
2 
3 #include "printer.h"
4 #include <sstream>
5 
Monomial(PolynomialRing const & r,const IntegerVector & v)6 Monomial::Monomial(PolynomialRing const &r,const IntegerVector &v):exponent(v),theRing(r)
7 {
8   if(v.size()!=r.getNumberOfVariables())
9     {
10       AsciiPrinter(Stderr).printPolynomialRing(r);
11       AsciiPrinter(Stderr).printVector(v);
12       assert(v.size()==r.getNumberOfVariables());
13     }
14 }
15 
16 
toString(bool alwaysWriteSign,bool writeIfOne,bool latex) const17 string Monomial::toString(bool alwaysWriteSign, bool writeIfOne, bool latex/*, bool mathMode*/)const
18 {
19   stringstream s;
20 
21   /*  if(latex & !mathMode)
22     s << "$";
23   */
24   const int sign=1;
25 
26   bool variablePrinted=false;
27   for(int i=0;i<exponent.size();i++)if(exponent[i]*sign>0)
28     {
29       s << getRing().getVariableName(i);
30       if(int(exponent[i]*sign)!=1)
31 	{
32 	  s << "^";
33 	  if(latex)
34 	    s << "{";
35 	  s << int(exponent[i]*sign);
36 	  if(latex)
37 	    s << "}";
38 	}
39       variablePrinted=true;
40     }
41   if(!variablePrinted && writeIfOne)
42     s<< "1";
43 
44   /*  if(latex & !mathMode)
45     s << "$";
46   */
47   return s.str();
48 }
49