3 * The methods .print() are responsible for the nice default-output of
4 * objects. All related helper-functions go in here as well. */
7 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "expairseq.h"
39 #include "relational.h"
44 #ifndef NO_GINAC_NAMESPACE
46 #endif // ndef NO_GINAC_NAMESPACE
48 void ex::print(ostream & os, unsigned upper_precedence) const
50 debugmsg("ex print",LOGLEVEL_PRINT);
52 bp->print(os,upper_precedence);
55 void ex::dbgprint(void) const
57 debugmsg("ex dbgprint",LOGLEVEL_PRINT);
62 void basic::print(ostream & os, unsigned upper_precedence) const
64 debugmsg("basic print",LOGLEVEL_PRINT);
65 os << "[basic object]";
68 void basic::dbgprint(void) const
74 void symbol::print(ostream & os, unsigned upper_precedence) const
76 debugmsg("symbol print",LOGLEVEL_PRINT);
80 void constant::print(ostream & os, unsigned upper_precedence) const
82 debugmsg("constant print",LOGLEVEL_PRINT);
86 void power::print(ostream & os, unsigned upper_precedence) const
88 debugmsg("power print",LOGLEVEL_PRINT);
89 if (precedence<=upper_precedence) os << "(";
90 basis.print(os,precedence);
92 exponent.print(os,precedence);
93 if (precedence<=upper_precedence) os << ")";
96 void fail::print(ostream & os, unsigned upper_precedence) const
98 debugmsg("fail print",LOGLEVEL_PRINT);
102 void expairseq::printpair(ostream & os, expair const & p, unsigned upper_precedence) const
105 p.rest.bp->print(os,precedence);
107 p.coeff.bp->print(os,precedence);
111 void expairseq::printseq(ostream & os, char delim, unsigned this_precedence,
112 unsigned upper_precedence) const
114 if (this_precedence<=upper_precedence) os << "(";
115 epvector::const_iterator it,it_last;
118 for (it=seq.begin(); it!=it_last; ++it) {
119 printpair(os,*it,this_precedence);
122 printpair(os,*it,this_precedence);
123 if (!overall_coeff.is_equal(default_overall_coeff())) {
124 os << delim << overall_coeff;
126 if (this_precedence<=upper_precedence) os << ")";
129 void expairseq::print(ostream & os, unsigned upper_precedence) const
131 debugmsg("expairseq print",LOGLEVEL_PRINT);
133 printseq(os,',',precedence,upper_precedence);
137 void add::print(ostream & os, unsigned upper_precedence) const
139 debugmsg("add print",LOGLEVEL_PRINT);
140 if (precedence<=upper_precedence) os << "(";
143 for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
144 coeff = ex_to_numeric(cit->coeff);
146 if (coeff.csgn()==-1) os << '-'; else os << '+';
148 if (coeff.csgn()==-1) os << '-';
151 if (!coeff.is_equal(numONE()) &&
152 !coeff.is_equal(numMINUSONE())) {
153 if (coeff.csgn()==-1)
154 (numMINUSONE()*coeff).print(os, precedence);
156 coeff.print(os, precedence);
161 // print the overall numeric coefficient, if present:
162 if (!overall_coeff.is_zero()) {
163 if (overall_coeff > 0) os << '+';
166 if (precedence<=upper_precedence) os << ")";
169 void mul::print(ostream & os, unsigned upper_precedence) const
171 debugmsg("mul print",LOGLEVEL_PRINT);
172 if (precedence<=upper_precedence) os << "(";
174 // first print the overall numeric coefficient:
175 if (ex_to_numeric(overall_coeff).csgn()==-1) os << '-';
176 if (!overall_coeff.is_equal(exONE()) &&
177 !overall_coeff.is_equal(exMINUSONE())) {
178 if (ex_to_numeric(overall_coeff).csgn()==-1)
179 (numMINUSONE()*overall_coeff).print(os, precedence);
181 overall_coeff.print(os, precedence);
184 // then proceed with the remaining factors:
185 for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
191 recombine_pair_to_ex(*cit).print(os,precedence);
193 if (precedence<=upper_precedence) os << ")";
196 void ncmul::print(ostream & os, unsigned upper_precedence) const
198 debugmsg("ncmul print",LOGLEVEL_PRINT);
199 printseq(os,'(','%',')',precedence,upper_precedence);
202 /*void function::print(ostream & os, unsigned upper_precedence) const
204 * debugmsg("function print",LOGLEVEL_PRINT);
206 * printseq(os,'(',',',')',exprseq::precedence,function::precedence);
209 void series::print(ostream &os, unsigned upper_precedence) const
211 debugmsg("symbol print", LOGLEVEL_PRINT);
212 convert_to_poly().print(os, upper_precedence);
215 void relational::print(ostream & os, unsigned upper_precedence) const
217 debugmsg("relational print",LOGLEVEL_PRINT);
218 if (precedence<=upper_precedence) os << "(";
219 lh.print(os,precedence);
236 case greater_or_equal:
240 os << "(INVALID RELATIONAL OPERATOR)";
242 rh.print(os,precedence);
243 if (precedence<=upper_precedence) os << ")";
246 void matrix::print(ostream & os, unsigned upper_precedence) const
248 debugmsg("matrix print",LOGLEVEL_PRINT);
250 for (int r=0; r<row-1; ++r) {
252 for (int c=0; c<col-1; ++c) {
253 os << m[r*col+c] << ",";
255 os << m[col*(r+1)-1] << "]], ";
258 for (int c=0; c<col-1; ++c) {
259 os << m[(row-1)*col+c] << ",";
261 os << m[row*col-1] << "]] ]]";
264 #ifndef NO_GINAC_NAMESPACE
266 #endif // ndef NO_GINAC_NAMESPACE