1 /** @file printtree.cpp
3 * print in tree- (indented-) form, so developers can have a look at the
4 * underlying structure.
6 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "expairseq.h"
37 #include "relational.h"
41 void ex::printtree(ostream & os, unsigned indent) const
43 debugmsg("ex printtree",LOGLEVEL_PRINT);
45 // os << "refcount=" << bp->refcount << " ";
46 bp->printtree(os,indent);
49 void ex::dbgprinttree(void) const
51 debugmsg("ex dbgprinttree",LOGLEVEL_PRINT);
56 void basic::printtree(ostream & os, unsigned indent) const
58 debugmsg("basic printtree",LOGLEVEL_PRINT);
59 os << string(indent,' ') << "type=" << typeid(*this).name()
60 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
61 << ", flags=" << flags
62 << ", nops=" << nops() << endl;
63 for (int i=0; i<nops(); ++i) {
64 op(i).printtree(os,indent+delta_indent);
68 void basic::dbgprinttree(void) const
73 void numeric::printtree(ostream & os, unsigned indent) const
75 debugmsg("numeric printtree", LOGLEVEL_PRINT);
76 // We are cheating here, because we don't want to include the underlying
77 // bignum package's headers again, so we use ostream::operator<<(numeric):
78 os << string(indent,' ');
81 << "hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
82 << ", flags=" << flags << endl;
85 void symbol::printtree(ostream & os, unsigned indent) const
87 debugmsg("symbol printtree",LOGLEVEL_PRINT);
88 os << string(indent,' ') << name << " (symbol): "
89 << "serial=" << serial
90 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
91 << ", flags=" << flags << endl;
94 void power::printtree(ostream & os, unsigned indent) const
96 debugmsg("power printtree",LOGLEVEL_PRINT);
98 os << string(indent,' ') << "power: "
99 << "hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
100 << ", flags=" << flags << endl;
101 basis.printtree(os,indent+delta_indent);
102 exponent.printtree(os,indent+delta_indent);
105 void expairseq::printtree(ostream & os, unsigned indent) const
107 debugmsg("expairseq printtree",LOGLEVEL_PRINT);
109 os << string(indent,' ') << "type=" << typeid(*this).name()
110 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
111 << ", flags=" << flags
112 << ", nops=" << nops() << endl;
113 for (unsigned i=0; i<seq.size(); ++i) {
114 seq[i].rest.printtree(os,indent+delta_indent);
115 seq[i].coeff.printtree(os,indent+delta_indent);
116 if (i!=seq.size()-1) {
117 os << string(indent+delta_indent,' ') << "-----" << endl;
120 if (!overall_coeff.is_equal(default_overall_coeff())) {
121 os << string(indent+delta_indent,' ') << "-----" << endl;
122 os << string(indent+delta_indent,' ') << "overall_coeff" << endl;
123 overall_coeff.printtree(os,indent+delta_indent);
125 os << string(indent+delta_indent,' ') << "=====" << endl;
126 #ifdef EXPAIRSEQ_USE_HASHTAB
127 os << string(indent+delta_indent,' ')
128 << "hashtab size " << hashtabsize << endl;
129 if (hashtabsize==0) return;
131 unsigned count[MAXCOUNT+1];
132 for (int i=0; i<MAXCOUNT+1; ++i) count[i]=0;
133 unsigned this_bin_fill;
134 unsigned cum_fill_sq=0;
136 for (unsigned i=0; i<hashtabsize; ++i) {
138 if (hashtab[i].size()>0) {
139 os << string(indent+delta_indent,' ')
140 << "bin " << i << " with entries ";
141 for (epplist::const_iterator it=hashtab[i].begin();
142 it!=hashtab[i].end(); ++it) {
143 os << *it-seq.begin() << " ";
147 cum_fill += this_bin_fill;
148 cum_fill_sq += this_bin_fill*this_bin_fill;
150 if (this_bin_fill<MAXCOUNT) {
151 ++count[this_bin_fill];
158 double lambda=(1.0*seq.size())/hashtabsize;
159 for (int k=0; k<MAXCOUNT; ++k) {
161 double prob=pow(lambda,k)/fact*exp(-lambda);
163 os << string(indent+delta_indent,' ') << "bins with " << k << " entries: "
164 << int(1000.0*count[k]/hashtabsize)/10.0 << "% (expected: "
165 << int(prob*1000)/10.0 << ")" << endl;
167 os << string(indent+delta_indent,' ') << "bins with more entries: "
168 << int(1000.0*count[MAXCOUNT]/hashtabsize)/10.0 << "% (expected: "
169 << int((1-cum_prob)*1000)/10.0 << ")" << endl;
171 os << string(indent+delta_indent,' ') << "variance: "
172 << 1.0/hashtabsize*cum_fill_sq-(1.0/hashtabsize*cum_fill)*(1.0/hashtabsize*cum_fill)
174 os << string(indent+delta_indent,' ') << "average fill: "
175 << (1.0*cum_fill)/hashtabsize
176 << " (should be equal to " << (1.0*seq.size())/hashtabsize << ")" << endl;
177 #endif // def EXPAIRSEQ_USE_HASHTAB