]> www.ginac.de Git - ginac.git/blobdiff - ginac/symmetry.cpp
index a0a2af1dbdba3d7ae9b2960819a1b85ea56cfd16..6cf5aaeac223a109f6280c8044bbd7cc68142748 100644 (file)
#include "lst.h"
#include "numeric.h" // for factorial()
#include "operators.h"
-#include "print.h"
#include "archive.h"
#include "utils.h"

namespace GiNaC {

-GINAC_IMPLEMENT_REGISTERED_CLASS(symmetry, basic)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(symmetry, basic,
+  print_func<print_context>(&symmetry::do_print).
+  print_func<print_tree>(&symmetry::do_print_tree))

/*
Some notes about the structure of a symmetry tree:
@@ -146,63 +147,60 @@ int symmetry::compare_same_type(const basic & other) const
return 0;
}

-void symmetry::print(const print_context & c, unsigned level) const
+void symmetry::do_print(const print_context & c, unsigned level) const
{
-       if (is_a<print_tree>(c)) {
-
-               c.s << std::string(level, ' ') << class_name()
-                   << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
-                   << ", type=";
-
+       if (children.empty()) {
+               if (indices.size() > 0)
+                       c.s << *(indices.begin());
+               else
+                       c.s << "none";
+       } else {
switch (type) {
-                       case none: c.s << "none"; break;
-                       case symmetric: c.s << "symm"; break;
-                       case antisymmetric: c.s << "anti"; break;
-                       case cyclic: c.s << "cycl"; break;
-                       default: c.s << "<unknown>"; break;
+                       case none: c.s << '!'; break;
+                       case symmetric: c.s << '+'; break;
+                       case antisymmetric: c.s << '-'; break;
+                       case cyclic: c.s << '@'; break;
+                       default: c.s << '?'; break;
}
-
-               c.s << ", indices=(";
-               if (!indices.empty()) {
-                       std::set<unsigned>::const_iterator i = indices.begin(), end = indices.end();
-                       --end;
-                       while (i != end)
-                               c.s << *i++ << ",";
-                       c.s << *i;
+               c.s << '(';
+               size_t num = children.size();
+               for (size_t i=0; i<num; i++) {
+                       children[i].print(c);
+                       if (i != num - 1)
+                               c.s << ",";
}
-               c.s << ")\n";
+               c.s << ')';
+       }
+}

-               unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
-               exvector::const_iterator i = children.begin(), end = children.end();
-               while (i != end) {
-                       i->print(c, level + delta_indent);
-                       ++i;
-               }
+void symmetry::do_print_tree(const print_tree & c, unsigned level) const
+{
+       c.s << std::string(level, ' ') << class_name() << " @" << this
+           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+           << ", type=";
+
+       switch (type) {
+               case none: c.s << "none"; break;
+               case symmetric: c.s << "symm"; break;
+               case antisymmetric: c.s << "anti"; break;
+               case cyclic: c.s << "cycl"; break;
+               default: c.s << "<unknown>"; break;
+       }

-       } else {
+       c.s << ", indices=(";
+       if (!indices.empty()) {
+               std::set<unsigned>::const_iterator i = indices.begin(), end = indices.end();
+               --end;
+               while (i != end)
+                       c.s << *i++ << ",";
+               c.s << *i;
+       }
+       c.s << ")\n";

-               if (children.empty()) {
-                       if (indices.size() > 0)
-                               c.s << *(indices.begin());
-                       else
-                               c.s << "none";
-               } else {
-                       switch (type) {
-                               case none: c.s << '!'; break;
-                               case symmetric: c.s << '+'; break;
-                               case antisymmetric: c.s << '-'; break;
-                               case cyclic: c.s << '@'; break;
-                               default: c.s << '?'; break;
-                       }
-                       c.s << '(';
-                       size_t num = children.size();
-                       for (size_t i=0; i<num; i++) {
-                               children[i].print(c);
-                               if (i != num - 1)
-                                       c.s << ",";
-                       }
-                       c.s << ')';
-               }
+       exvector::const_iterator i = children.begin(), end = children.end();
+       while (i != end) {
+               i->print(c, level + c.delta_indent);
+               ++i;
}
}

@@ -363,7 +361,7 @@ static ex symm(const ex & e, exvector::const_iterator first, exvector::const_ite
lst new_lst;
for (unsigned i=0; i<num; i++)
new_lst.append(orig_lst.op(iv[i]));
-               ex term = e.subs(orig_lst, new_lst);
+               ex term = e.subs(orig_lst, new_lst, subs_options::no_pattern);
if (asymmetric) {
memcpy(iv2, iv, num * sizeof(unsigned));
term *= permutation_sign(iv2, iv2 + num);
@@ -404,7 +402,7 @@ ex symmetrize_cyclic(const ex & e, exvector::const_iterator first, exvector::con
for (unsigned i=0; i<num-1; i++) {
ex perm = new_lst.op(0);
new_lst.remove_first().append(perm);
-               sum += e.subs(orig_lst, new_lst);
+               sum += e.subs(orig_lst, new_lst, subs_options::no_pattern);
}
return sum / num;
}