/// the Poisson bracket of two polynomials in this algebra
Polynomial ClassicalLieAlgebra::poissonBracket(const Polynomial& polA,
                                               const Polynomial& polB) const {
  if (!(hasElt(polA) && hasElt(polB)))
    throw LieAlgebraSizeMismatchError();
  assert(polA.hasSameNumVars(polB));
  Polynomial pb(zero());
  Polynomial pbA(zero());
  Polynomial pbB(zero());
  for (Index d = 0; d < dof_; ++d) {
    pbA = (polA.diff(iQ(d)) * polB.diff(iP(d)));
    pbB = (polA.diff(iP(d)) * polB.diff(iQ(d)));
    pb += (pbA - pbB);
  }
  return pb;
}
Exemplo n.º 2
0
Polynomial operator*(const Polynomial& a, const Polynomial& b) {
  if (!a.hasSameNumVars(b))
    throw PolynomialSizeMismatchError();
  Polynomial res(a.numVars_);
  PowersToCoeffMap::const_iterator apc;
  PowersToCoeffMap::const_iterator bpc;
  for (apc = a.terms_.begin(); apc != a.terms_.end(); ++apc) {
    assert(isValidCoeff(apc->second));
    for (bpc = b.terms_.begin(); bpc != b.terms_.end(); ++bpc) {
      assert(isValidCoeff(bpc->second));
      res.addMonomial((apc->first) * (bpc->first),
                      (apc->second) * (bpc->second));
    }
  }
  return res;
}