#include "utils.h"
#include "debugmsg.h"
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
namespace GiNaC {
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
GINAC_IMPLEMENT_REGISTERED_CLASS(basic, void)
return *this;
}
+/** Default interface of nth derivative ex::diff(s, n). It should be called
+ * instead of ::derivative(s) for first derivatives and for nth derivatives it
+ * just recurses down.
+ *
+ * @param s symbol to differentiate in
+ * @param nth order of differentiation
+ * @see ex::diff */
+ex basic::diff(const symbol & s, unsigned nth) const
+{
+ // trivial: zeroth derivative
+ if (!nth)
+ return ex(*this);
+
+ // evaluate unevalueted *this before differentiating
+ if (!(flags & status_flags::evaluated))
+ return ex(*this).diff(s, nth);
+
+ ex ndiff = derivative(s);
+ while (!ndiff.is_zero() && // stop differentiating zeros
+ nth>1) {
+ ndiff = ndiff.diff(s);
+ --nth;
+ }
+ return ndiff;
+}
+
exvector basic::get_indices(void) const
{
return exvector(); // return an empty exvector
// protected
+/** Default implementation of ex::diff(). It simply throws an error message.
+ *
+ * @exception logic_error (differentiation not supported by this type)
+ * @see ex::diff */
+ex basic::derivative(const symbol & s) const
+{
+ throw(std::logic_error("differentiation not supported by this type"));
+}
+
int basic::compare_same_type(const basic & other) const
{
return compare_pointers(this, &other);
return this->setflag(status_flags::expanded);
}
+
//////////
// non-virtual functions in this class
//////////
int max_recursion_level=1024;
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
} // namespace GiNaC
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC