3 * The methods .print() are responsible for the nice default-output of
4 * objects. All related helper-functions go in here as well. */
10 void ex::print(ostream & os, unsigned upper_precedence) const
12 debugmsg("ex print",LOGLEVEL_PRINT);
14 bp->print(os,upper_precedence);
17 void ex::dbgprint(void) const
19 debugmsg("ex dbgprint",LOGLEVEL_PRINT);
24 void basic::print(ostream & os, unsigned upper_precedence) const
26 debugmsg("basic print",LOGLEVEL_PRINT);
27 os << "[basic object]";
30 void basic::dbgprint(void) const
36 void symbol::print(ostream & os, unsigned upper_precedence) const
38 debugmsg("symbol print",LOGLEVEL_PRINT);
42 void constant::print(ostream & os, unsigned upper_precedence) const
44 debugmsg("constant print",LOGLEVEL_PRINT);
48 void power::print(ostream & os, unsigned upper_precedence) const
50 debugmsg("power print",LOGLEVEL_PRINT);
52 if (precedence<=upper_precedence) os << "(";
53 basis.print(os,precedence);
55 exponent.print(os,precedence);
56 if (precedence<=upper_precedence) os << ")";
58 os << "pow(" << basis << "," << exponent << ")";
62 void fail::print(ostream & os, unsigned upper_precedence) const
64 debugmsg("fail print",LOGLEVEL_PRINT);
68 void expairseq::printpair(ostream & os, expair const & p, unsigned upper_precedence) const
71 p.rest.bp->print(os,precedence);
73 p.coeff.bp->print(os,precedence);
78 void expairseq::printseq(ostream & os, char delim, unsigned this_precedence,
79 unsigned upper_precedence) const
81 if (this_precedence<=upper_precedence) os << "(";
82 epvector::const_iterator itt,it,it_last,it_start;
89 for (it=seq.begin(); it!=it_last; ++it) {
91 expair const & k = *itt;
92 printpair(os,*it, this_precedence);
93 if (((is_ex_of_type(k.rest, numeric)) && (k.coeff*k.rest > 0) ) || ((!is_ex_of_type(k.rest, numeric)) && (k.coeff >0))){
97 printpair(os,*it,this_precedence);
101 for (it = it_last ; it!=it_start; --it) {
102 if ((*it).rest.is_equal(exMINUSONE()) &&
103 (*it).coeff.is_equal(exONE())) {
106 printpair(os, *it,this_precedence);
110 printpair(os,*it,this_precedence);
113 clog << "Nobody expects the Spanish Inquisition: "
114 << "deliminator unknown!" << endl;
116 if (this_precedence<=upper_precedence) os << ")";
120 void expairseq::printseq(ostream & os, char delim, unsigned this_precedence,
121 unsigned upper_precedence) const
123 if (this_precedence<=upper_precedence) os << "(";
124 epvector::const_iterator it,it_last;
127 for (it=seq.begin(); it!=it_last; ++it) {
128 printpair(os,*it,this_precedence);
131 printpair(os,*it,this_precedence);
132 if (!overall_coeff.is_equal(default_overall_coeff())) {
133 os << delim << overall_coeff;
135 if (this_precedence<=upper_precedence) os << ")";
138 void expairseq::print(ostream & os, unsigned upper_precedence) const
140 debugmsg("expairseq print",LOGLEVEL_PRINT);
142 printseq(os,',',precedence,upper_precedence);
146 void add::printpair(ostream & os, expair const & p, unsigned upper_precedence) const
161 void add::print(ostream & os, unsigned upper_precedence) const
163 debugmsg("add print",LOGLEVEL_PRINT);
164 if (precedence<=upper_precedence) os << "(";
166 for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
168 if (cit->coeff > 0) os << '+';
172 if (cit->coeff == -1) {
175 if (cit->coeff != 1) {
182 if (!overall_coeff.is_equal(exZERO())) {
183 if (overall_coeff > 0) os << '+';
186 if (precedence<=upper_precedence) os << ")";
189 void mul::printpair(ostream & os, expair const & p, unsigned upper_precedence) const
192 if (p.coeff.compare(exONE())==0) {
193 p.rest.print(os,upper_precedence);
195 // outer parens around ex needed for broken gcc-2.95 parser:
196 (ex(power(p.rest,p.coeff))).print(os,upper_precedence);
201 void mul::print(ostream & os, unsigned upper_precedence) const
203 debugmsg("mul print",LOGLEVEL_PRINT);
204 if (precedence<=upper_precedence) os << "(";
206 if (!overall_coeff.is_equal(exONE())) {
207 overall_coeff.print(os,precedence);
210 for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
216 recombine_pair_to_ex(*cit).print(os,precedence);
218 if (precedence<=upper_precedence) os << ")";
221 void ncmul::print(ostream & os, unsigned upper_precedence) const
223 debugmsg("ncmul print",LOGLEVEL_PRINT);
224 printseq(os,'(','%',')',precedence,upper_precedence);
227 /*void function::print(ostream & os, unsigned upper_precedence) const
229 * debugmsg("function print",LOGLEVEL_PRINT);
231 * printseq(os,'(',',',')',exprseq::precedence,function::precedence);
234 void series::print(ostream &os, unsigned upper_precedence) const
236 debugmsg("symbol print", LOGLEVEL_PRINT);
237 convert_to_poly().print(os, upper_precedence);
240 void relational::print(ostream & os, unsigned upper_precedence) const
242 debugmsg("relational print",LOGLEVEL_PRINT);
243 if (precedence<=upper_precedence) os << "(";
244 lh.print(os,precedence);
261 case greater_or_equal:
265 os << "(INVALID RELATIONAL OPERATOR)";
267 rh.print(os,precedence);
268 if (precedence<=upper_precedence) os << ")";
271 void matrix::print(ostream & os, unsigned upper_precedence) const
273 debugmsg("matrix print",LOGLEVEL_PRINT);
275 for (int r=0; r<row-1; ++r) {
277 for (int c=0; c<col-1; ++c) {
278 os << m[r*col+c] << ",";
280 os << m[col*(r+1)-1] << "]], ";
283 for (int c=0; c<col-1; ++c) {
284 os << m[(row-1)*col+c] << ",";
286 os << m[row*col-1] << "]] ]]";