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