* Implementation of symbolic differentiation in all of GiNaC's classes. */
/*
- * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2000 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 "numeric.h"
#include "power.h"
#include "relational.h"
-#include "series.h"
+#include "pseries.h"
#include "symbol.h"
+#include "utils.h"
#ifndef NO_GINAC_NAMESPACE
namespace GiNaC {
/** Default implementation of ex::diff(). It prints and error message and returns a fail object.
* @see ex::diff */
-ex basic::diff(symbol const & s) const
+ex basic::diff(const symbol & s) const
{
throw(std::logic_error("differentiation not supported by this type"));
}
/** Implementation of ex::diff() for a numeric. It always returns 0.
*
* @see ex::diff */
-ex numeric::diff(symbol const & s) const
+ex numeric::diff(const symbol & s) const
{
- return exZERO();
+ return _ex0();
}
* It returns 1 or 0.
*
* @see ex::diff */
-ex symbol::diff(symbol const & s) const
+ex symbol::diff(const symbol & s) const
{
if (compare_same_type(s)) {
- return exZERO();
+ return _ex0();
} else {
- return exONE();
+ return _ex1();
}
}
/** Implementation of ex::diff() for a constant. It always returns 0.
*
* @see ex::diff */
-ex constant::diff(symbol const & s) const
+ex constant::diff(const symbol & s) const
{
- return exZERO();
+ return _ex0();
}
/** Implementation of ex::diff() for multiple differentiation of a symbol.
*
* @param nth order of differentiation
* @see ex::diff */
-ex symbol::diff(symbol const & s, unsigned nth) const
+ex symbol::diff(const symbol & s, unsigned nth) const
{
if (compare_same_type(s)) {
switch (nth) {
return s;
break;
case 1:
- return exONE();
+ return _ex1();
break;
default:
- return exZERO();
+ return _ex0();
}
} else {
- return exONE();
+ return _ex1();
}
}
/** Implementation of ex::diff() for an indexed object. It always returns 0.
* @see ex::diff */
-ex indexed::diff(symbol const & s) const
+ex indexed::diff(const symbol & s) const
{
- return exZERO();
+ return _ex0();
}
/** Implementation of ex::diff() for an expairseq. It differentiates all elements of the sequence.
* @see ex::diff */
-ex expairseq::diff(symbol const & s) const
+ex expairseq::diff(const symbol & s) const
{
return thisexpairseq(diffchildren(s),overall_coeff);
}
/** Implementation of ex::diff() for a sum. It differentiates each term.
* @see ex::diff */
-ex add::diff(symbol const & s) const
+ex add::diff(const symbol & s) const
{
// D(a+b+c)=D(a)+D(b)+D(c)
return (new add(diffchildren(s)))->setflag(status_flags::dynallocated);
/** Implementation of ex::diff() for a product. It applies the product rule.
* @see ex::diff */
-ex mul::diff(symbol const & s) const
+ex mul::diff(const symbol & s) const
{
exvector new_seq;
new_seq.reserve(seq.size());
/** Implementation of ex::diff() for a non-commutative product. It always returns 0.
* @see ex::diff */
-ex ncmul::diff(symbol const & s) const
+ex ncmul::diff(const symbol & s) const
{
- return exZERO();
+ return _ex0();
}
/** Implementation of ex::diff() for a power.
* @see ex::diff */
-ex power::diff(symbol const & s) const
+ex power::diff(const symbol & s) const
{
if (exponent.info(info_flags::real)) {
// D(b^r) = r * b^(r-1) * D(b) (faster than the formula below)
- return mul(mul(exponent, power(basis, exponent - exONE())), basis.diff(s));
+ return mul(mul(exponent, power(basis, exponent - _ex1())), basis.diff(s));
} else {
// D(b^e) = b^e * (D(e)*ln(b) + e*D(b)/b)
return mul(power(basis, exponent),
/** Implementation of ex::diff() for functions. It applies the chain rule,
* except for the Order term function.
* @see ex::diff */
-ex function::diff(symbol const & s) const
+ex function::diff(const symbol & s) const
{
exvector new_seq;
}
-/** Implementation of ex::diff() for a power-series. It treats the series as a polynomial.
+/** Implementation of ex::diff() for a power series. It treats the series as a polynomial.
* @see ex::diff */
-ex series::diff(symbol const & s) const
+ex pseries::diff(const symbol & s) const
{
if (s == var) {
epvector new_seq;
}
it++;
}
- return series(var, point, new_seq);
+ return pseries(var, point, new_seq);
} else {
return *this;
}
* @param nth order of derivative (default 1)
* @return partial derivative as a new expression */
-ex ex::diff(symbol const & s, unsigned nth) const
+ex ex::diff(const symbol & s, unsigned nth) const
{
GINAC_ASSERT(bp!=0);