* Implementation of GiNaC's symbolic exponentiation (basis^exponent). */
/*
- * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2002 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
c.s << ')';
// <expr>^-1 is printed as "1.0/<expr>" or with the recip() function of CLN
- } else if (exponent.compare(_num_1) == 0) {
+ } else if (exponent.is_equal(_ex_1)) {
if (is_a<print_csrc_cl_N>(c))
c.s << "recip(";
else
c.s << ')';
}
+ } else if (is_a<print_python_repr>(c)) {
+
+ c.s << class_name() << '(';
+ basis.print(c);
+ c.s << ',';
+ exponent.print(c);
+ c.s << ')';
+
} else {
if (exponent.is_equal(_ex1_2)) {
c.s << "(";
}
basis.print(c, precedence());
- c.s << '^';
+ if (is_a<print_python>(c))
+ c.s << "**";
+ else
+ c.s << '^';
if (is_a<print_latex>(c))
c.s << '{';
exponent.print(c, precedence());
int power::degree(const ex & s) const
{
- if (is_ex_exactly_of_type(exponent, numeric) && ex_to<numeric>(exponent).is_integer()) {
+ if (is_equal(ex_to<basic>(s)))
+ return 1;
+ else if (is_ex_exactly_of_type(exponent, numeric) && ex_to<numeric>(exponent).is_integer()) {
if (basis.is_equal(s))
return ex_to<numeric>(exponent).to_int();
else
return basis.degree(s) * ex_to<numeric>(exponent).to_int();
- }
- return 0;
+ } else if (basis.has(s))
+ throw(std::runtime_error("power::degree(): undefined degree because of non-integer exponent"));
+ else
+ return 0;
}
int power::ldegree(const ex & s) const
{
- if (is_ex_exactly_of_type(exponent, numeric) && ex_to<numeric>(exponent).is_integer()) {
+ if (is_equal(ex_to<basic>(s)))
+ return 1;
+ else if (is_ex_exactly_of_type(exponent, numeric) && ex_to<numeric>(exponent).is_integer()) {
if (basis.is_equal(s))
return ex_to<numeric>(exponent).to_int();
else
return basis.ldegree(s) * ex_to<numeric>(exponent).to_int();
- }
- return 0;
+ } else if (basis.has(s))
+ throw(std::runtime_error("power::ldegree(): undefined degree because of non-integer exponent"));
+ else
+ return 0;
}
ex power::coeff(const ex & s, int n) const
{
- if (!basis.is_equal(s)) {
+ if (is_equal(ex_to<basic>(s)))
+ return n==1 ? _ex1 : _ex0;
+ else if (!basis.is_equal(s)) {
// basis not equal to s
if (n == 0)
return *this;