1 /** @file printtree.cpp
3 * print in tree- (indented-) form, so developers can have a look at the
4 * underlying structure. */
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
31 #include "expairseq.h"
38 #include "relational.h"
45 void ex::printtree(ostream & os, unsigned indent) const
47 debugmsg("ex printtree",LOGLEVEL_PRINT);
49 // os << "refcount=" << bp->refcount << " ";
50 bp->printtree(os,indent);
53 void ex::dbgprinttree(void) const
55 debugmsg("ex dbgprinttree",LOGLEVEL_PRINT);
60 void basic::printtree(ostream & os, unsigned indent) const
62 debugmsg("basic printtree",LOGLEVEL_PRINT);
63 os << string(indent,' ') << "type=" << typeid(*this).name()
64 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
65 << ", flags=" << flags
66 << ", nops=" << nops() << endl;
67 for (int i=0; i<nops(); ++i) {
68 op(i).printtree(os,indent+delta_indent);
72 void basic::dbgprinttree(void) const
77 void numeric::printtree(ostream & os, unsigned indent) const
79 debugmsg("numeric printtree", LOGLEVEL_PRINT);
80 // We are cheating here, because we don't want to include the underlying
81 // bignum package's headers again, so we use ostream::operator<<(numeric):
82 os << string(indent,' ');
85 << "hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
86 << ", flags=" << flags << endl;
89 void symbol::printtree(ostream & os, unsigned indent) const
91 debugmsg("symbol printtree",LOGLEVEL_PRINT);
92 os << string(indent,' ') << name << " (symbol): "
93 << "serial=" << serial
94 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
95 << ", flags=" << flags << endl;
98 void power::printtree(ostream & os, unsigned indent) const
100 debugmsg("power printtree",LOGLEVEL_PRINT);
102 os << string(indent,' ') << "power: "
103 << "hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
104 << ", flags=" << flags << endl;
105 basis.printtree(os,indent+delta_indent);
106 exponent.printtree(os,indent+delta_indent);
109 void expairseq::printtree(ostream & os, unsigned indent) const
111 debugmsg("expairseq printtree",LOGLEVEL_PRINT);
113 os << string(indent,' ') << "type=" << typeid(*this).name()
114 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
115 << ", flags=" << flags
116 << ", nops=" << nops() << endl;
117 for (unsigned i=0; i<seq.size(); ++i) {
118 seq[i].rest.printtree(os,indent+delta_indent);
119 seq[i].coeff.printtree(os,indent+delta_indent);
120 if (i!=seq.size()-1) {
121 os << string(indent+delta_indent,' ') << "-----" << endl;
124 if (!overall_coeff.is_equal(default_overall_coeff())) {
125 os << string(indent+delta_indent,' ') << "-----" << endl;
126 os << string(indent+delta_indent,' ') << "overall_coeff" << endl;
127 overall_coeff.printtree(os,indent+delta_indent);
129 os << string(indent+delta_indent,' ') << "=====" << endl;
130 #ifdef EXPAIRSEQ_USE_HASHTAB
131 os << string(indent+delta_indent,' ')
132 << "hashtab size " << hashtabsize << endl;
133 if (hashtabsize==0) return;
135 unsigned count[MAXCOUNT+1];
136 for (int i=0; i<MAXCOUNT+1; ++i) count[i]=0;
137 unsigned this_bin_fill;
138 unsigned cum_fill_sq=0;
140 for (unsigned i=0; i<hashtabsize; ++i) {
142 if (hashtab[i].size()>0) {
143 os << string(indent+delta_indent,' ')
144 << "bin " << i << " with entries ";
145 for (epplist::const_iterator it=hashtab[i].begin();
146 it!=hashtab[i].end(); ++it) {
147 os << *it-seq.begin() << " ";
151 cum_fill += this_bin_fill;
152 cum_fill_sq += this_bin_fill*this_bin_fill;
154 if (this_bin_fill<MAXCOUNT) {
155 ++count[this_bin_fill];
162 double lambda=(1.0*seq.size())/hashtabsize;
163 for (int k=0; k<MAXCOUNT; ++k) {
165 double prob=pow(lambda,k)/fact*exp(-lambda);
167 os << string(indent+delta_indent,' ') << "bins with " << k << " entries: "
168 << int(1000.0*count[k]/hashtabsize)/10.0 << "% (expected: "
169 << int(prob*1000)/10.0 << ")" << endl;
171 os << string(indent+delta_indent,' ') << "bins with more entries: "
172 << int(1000.0*count[MAXCOUNT]/hashtabsize)/10.0 << "% (expected: "
173 << int((1-cum_prob)*1000)/10.0 << ")" << endl;
175 os << string(indent+delta_indent,' ') << "variance: "
176 << 1.0/hashtabsize*cum_fill_sq-(1.0/hashtabsize*cum_fill)*(1.0/hashtabsize*cum_fill)
178 os << string(indent+delta_indent,' ') << "average fill: "
179 << (1.0*cum_fill)/hashtabsize
180 << " (should be equal to " << (1.0*seq.size())/hashtabsize << ")" << endl;
181 #endif // def EXPAIRSEQ_USE_HASHTAB