@@ -868,14 +868,16 @@ cdef class Basic(object):
868
868
def expand (Basic self not None , cppbool deep = True ):
869
869
return c2py(symengine.expand(self .thisptr, deep))
870
870
871
- def diff (Basic self not None , x = None ):
872
- if x is None :
871
+ def _diff (Basic self not None , Basic x ):
872
+ return c2py(symengine.diff(self .thisptr, x.thisptr))
873
+
874
+ def diff (self , *args ):
875
+ if len (args) == 0 :
873
876
f = self .free_symbols
874
877
if (len (f) != 1 ):
875
878
raise RuntimeError (" Variable w.r.t should be given" )
876
- return self .diff(f.pop())
877
- cdef Basic s = sympify(x)
878
- return c2py(symengine.diff(self .thisptr, s.thisptr))
879
+ return self ._diff(f.pop())
880
+ return diff(self , * args)
879
881
880
882
def subs_dict (Basic self not None , *args ):
881
883
warnings.warn(" subs_dict() is deprecated. Use subs() instead" , DeprecationWarning )
@@ -3430,13 +3432,15 @@ cdef class DenseMatrixBase(MatrixBase):
3430
3432
cdef _DictBasic D = get_dict(* args)
3431
3433
return self .applyfunc(lambda x : x.msubs(D))
3432
3434
3433
- def diff (self , x ):
3434
- cdef Basic x_ = sympify(x)
3435
+ def _diff (self , Basic x ):
3435
3436
cdef DenseMatrixBase R = self .__class__ (self .rows, self .cols)
3436
3437
symengine.diff(< const symengine.DenseMatrix & > deref(self .thisptr),
3437
- x_ .thisptr, < symengine.DenseMatrix & > deref(R.thisptr))
3438
+ x .thisptr, < symengine.DenseMatrix & > deref(R.thisptr))
3438
3439
return R
3439
3440
3441
+ def diff (self , *args ):
3442
+ return diff(self , * args)
3443
+
3440
3444
# TODO: implement this in C++
3441
3445
def subs (self , *args ):
3442
3446
cdef _DictBasic D = get_dict(* args)
@@ -3769,10 +3773,20 @@ def module_cleanup():
3769
3773
import atexit
3770
3774
atexit.register(module_cleanup)
3771
3775
3772
- def diff (ex , *x ):
3776
+ def diff (ex , *args ):
3773
3777
ex = sympify(ex)
3774
- for i in x:
3775
- ex = ex.diff(i)
3778
+ prev = 0
3779
+ cdef Basic b
3780
+ cdef size_t i
3781
+ for x in args:
3782
+ b = sympify(x)
3783
+ if isinstance (b, Integer):
3784
+ i = int (b) - 1
3785
+ for j in range (i):
3786
+ ex = ex._diff(prev)
3787
+ else :
3788
+ ex = ex._diff(b)
3789
+ prev = b
3776
3790
return ex
3777
3791
3778
3792
def expand (x , deep = True ):
0 commit comments