* point of view it boils down to power series expansion. It also has quite
* an intriguing check for consistency, which is why we include it here.
*
- * This program is based on work by Isabella Bierenbaum and Dirk Kreimer.
- * For details, please see the diploma theses of Isabella Bierenbaum.
+ * This program is based on work by
+ * Isabella Bierenbaum <bierenbaum@thep.physik.uni-mainz.de> and
+ * Dirk Kreimer <dkreimer@bu.edu>.
+ * For details, please ask for the diploma theses of Isabella Bierenbaum.
+ * Also, this file is based on an early version of their program, they now
+ * have production-code that is somewhat more efficient than the stuff below.
*/
/*
#include "times.h"
#include <utility>
-#include <list>
+#include <vector>
+#include <stdexcept>
// whether to run this beast or not:
static const bool do_test = true;
/* Extract only the divergent part of a series and discard the rest. */
static ex div_part(const ex &exarg, const symbol &x, unsigned grad)
{
- unsigned order = grad;
- ex exser;
- // maybe we have to generate more terms on the series (obnoxious):
- do {
- exser = exarg.series(x==0, order);
- ++order;
- } while (exser.degree(x) < 0);
+ const ex exser = exarg.series(x==0, grad);
+ if (exser.degree(x)<0)
+ throw runtime_error("divergent part truncation disaster");
ex exser_trunc;
for (int i=exser.ldegree(x); i<0; ++i)
exser_trunc += exser.coeff(x,i)*pow(x,i);
public:
node(const vertex &v) { vert = v.copy(); }
node(const node &n) { vert = (n.vert)->copy(); children = n.children; }
+ const node & operator=(const node &);
~node() { delete vert; }
void add_child(const node &, bool = false);
ex evaluate(const symbol &x, unsigned grad) const;
unsigned total_edges(void) const;
private:
vertex *vert;
- list<child> children;
+ vector<child> children;
};
+const node & node::operator=(const node &n)
+{
+ delete vert;
+ vert = (n.vert)->copy();
+ children = n.children;
+ return *this;
+}
+
void node::add_child(const node &childnode, bool cut)
{
children.push_back(child(childnode, cut));
ex node::evaluate(const symbol &x, unsigned grad) const
{
ex product = 1;
- for (list<child>::const_iterator i=children.begin(); i!=children.end(); ++i) {
+ for (vector<child>::const_iterator i=children.begin(); i!=children.end(); ++i) {
if (!i->second)
product *= i->first.evaluate(x,grad);
else
unsigned node::total_edges(void) const
{
unsigned accu = 0;
- for (list<child>::const_iterator i=children.begin(); i!=children.end(); ++i) {
+ for (vector<child>::const_iterator i=children.begin(); i!=children.end(); ++i) {
accu += i->first.total_edges();
++accu;
}
* written using calls to node's method add_child() because it allows for
* editor-assisted indentation.
*/
-node operator+(const node &n, const child &c)
+const node operator+(const node &n, const child &c)
{
node nn(n);
nn.add_child(c.first, c.second);