]> www.ginac.de Git - ginac.git/blobdiff - ginac/ncmul.cpp
- The default implementations of evalf(), diff(), normal() and expand() use
[ginac.git] / ginac / ncmul.cpp
index e4a9186aa87b2d7620a1b0781f0b124fcb62f3b7..dbd5732840ccde39e9704e09893f4dc44a236b1f 100644 (file)
@@ -475,11 +475,21 @@ ex ncmul::thisexprseq(exvector * vp) const
 
 // protected
 
-/** Implementation of ex::diff() for a non-commutative product. It always returns 0.
+/** Implementation of ex::diff() for a non-commutative product. It applies
+ *  the product rule.
  *  @see ex::diff */
 ex ncmul::derivative(const symbol & s) const
 {
-       return _ex0();
+       exvector addseq;
+       addseq.reserve(seq.size());
+       
+       // D(a*b*c) = D(a)*b*c + a*D(b)*c + a*b*D(c)
+       for (unsigned i=0; i!=seq.size(); ++i) {
+               exvector ncmulseq = seq;
+               ncmulseq[i] = seq[i].diff(s);
+               addseq.push_back((new ncmul(ncmulseq))->setflag(status_flags::dynallocated));
+       }
+       return (new add(addseq))->setflag(status_flags::dynallocated);
 }
 
 int ncmul::compare_same_type(const basic & other) const