* Implementation of GiNaC's non-commutative products of expressions. */
/*
- * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "add.h"
#include "mul.h"
#include "matrix.h"
-#include "print.h"
#include "archive.h"
#include "utils.h"
namespace GiNaC {
-GINAC_IMPLEMENT_REGISTERED_CLASS(ncmul, exprseq)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(ncmul, exprseq,
+ print_func<print_context>(&ncmul::do_print).
+ print_func<print_tree>(&basic::do_print_tree).
+ print_func<print_csrc>(&ncmul::do_print_csrc).
+ print_func<print_python_repr>(&ncmul::do_print_csrc))
+
//////////
// default constructor
tinfo_key = TINFO_ncmul;
}
-ncmul::ncmul(exvector * vp) : inherited(vp)
+ncmul::ncmul(std::auto_ptr<exvector> vp) : inherited(vp)
{
tinfo_key = TINFO_ncmul;
}
// public
-void ncmul::print(const print_context & c, unsigned level) const
+void ncmul::do_print(const print_context & c, unsigned level) const
{
- if (is_a<print_tree>(c)) {
-
- inherited::print(c, level);
-
- } else if (is_a<print_csrc>(c) || is_a<print_python_repr>(c)) {
-
- c.s << class_name() << "(";
- exvector::const_iterator it = seq.begin(), itend = seq.end()-1;
- while (it != itend) {
- it->print(c, precedence());
- c.s << ",";
- it++;
- }
- it->print(c, precedence());
- c.s << ")";
+ printseq(c, '(', '*', ')', precedence(), level);
+}
- } else
- printseq(c, '(', '*', ')', precedence(), level);
+void ncmul::do_print_csrc(const print_context & c, unsigned level) const
+{
+ c.s << class_name();
+ printseq(c, '(', ',', ')', precedence(), precedence());
}
bool ncmul::info(unsigned inf) const
ex ncmul::evalm() const
{
// Evaluate children first
- exvector *s = new exvector;
+ std::auto_ptr<exvector> s(new exvector);
s->reserve(seq.size());
exvector::const_iterator it = seq.begin(), itend = seq.end();
while (it != itend) {
prod = prod.mul(ex_to<matrix>(*it));
it++;
}
- delete s;
return prod;
}
return (new ncmul(v))->setflag(status_flags::dynallocated);
}
-ex ncmul::thiscontainer(exvector * vp) const
+ex ncmul::thiscontainer(std::auto_ptr<exvector> vp) const
{
return (new ncmul(vp))->setflag(status_flags::dynallocated);
}
+ex ncmul::conjugate() const
+{
+ if (return_type() != return_types::noncommutative) {
+ return exprseq::conjugate();
+ }
+
+ if (return_type_tinfo() & 0xffffff00U != TINFO_clifford) {
+ return exprseq::conjugate();
+ }
+
+ exvector ev;
+ ev.reserve(nops());
+ for (const_iterator i=end(); i!=begin();) {
+ --i;
+ ev.push_back(i->conjugate());
+ }
+ return (new ncmul(ev, true))->setflag(status_flags::dynallocated).eval();
+}
+
// protected
/** Implementation of ex::diff() for a non-commutative product. It applies