* Implementation of GiNaC's symmetry definitions. */
/*
- * GiNaC Copyright (C) 1999-2009 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2011 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 "symmetry.h"
#include "lst.h"
+#include "add.h"
#include "numeric.h" // for factorial()
#include "operators.h"
#include "archive.h"
return 1;
if (this_size < that_size)
return -1;
- typedef std::set<unsigned>::iterator set_it;
+ typedef std::set<unsigned>::const_iterator set_it;
set_it end = indices.end();
for (set_it i=indices.begin(),j=othersymm.indices.begin(); i!=end; ++i,++j) {
if(*i < *j)
if (type == none) {
v = rotate_left(v);
- v ^= *(indices.begin());
+ if (!indices.empty())
+ v ^= *(indices.begin());
} else {
for (exvector::const_iterator i=children.begin(); i!=children.end(); ++i)
{
// non-virtual functions in this class
//////////
+bool symmetry::has_nonsymmetric() const
+{
+ if (type == antisymmetric || type == cyclic)
+ return true;
+
+ for (exvector::const_iterator i=children.begin(); i!=children.end(); ++i)
+ if (ex_to<symmetry>(*i).has_nonsymmetric())
+ return true;
+
+ return false;
+}
+
bool symmetry::has_cyclic() const
{
if (type == cyclic)
// Loop over all permutations (the first permutation, which is the
// identity, is unrolled)
- ex sum = e;
+ exvector sum_v;
+ sum_v.push_back(e);
while (std::next_permutation(iv, iv + num)) {
lst new_lst;
for (unsigned i=0; i<num; i++)
memcpy(iv2, iv, num * sizeof(unsigned));
term *= permutation_sign(iv2, iv2 + num);
}
- sum += term;
+ sum_v.push_back(term);
}
+ ex sum = (new add(sum_v))->setflag(status_flags::dynallocated);
delete[] iv;
delete[] iv2;