deriv | R Documentation |
freealg
objectsDifferentiation of freealg
objects
## S3 method for class 'freealg'
deriv(expr, r, ...)
expr |
Object of class |
r |
Integer vector. Elements denote variables to differentiate
with respect to. If |
... |
Further arguments, currently ignored |
Experimental function deriv(S,v)
returns
\frac{\partial^r S}{\partial v_1\partial v_2\ldots\partial
v_r}
. The Leibniz product rule
\left(u\cdot v\right)'=uv'+u'v
operates even if (as here) u,v
do not commute. For example, if
we wish to differentiate aaba
with respect to a
, we would
write f(a) = aaba
and then
f(a+\delta a) = (a+\delta a)(a+\delta a)b(a+\delta a)
and working to first order we have
f(a+\delta a) -f(a)= (\delta a)aba + a(\delta a)ba + aab(\delta
a).
In the package:
> deriv(as.freealg("aaba"),"a") free algebra element algebraically equal to + 1*aab(da) + 1*a(da)ba + 1*(da)aba
A term of a freealg
object can include negative values which
correspond to negative powers of variables. Thus:
> deriv(as.freealg("AAAA"),"a") free algebra element algebraically equal to - 1*AAAA(da)A - 1*AAA(da)AA - 1*AA(da)AAA - 1*A(da)AAAA
(see also the examples). Vector r
may include negative
integers which mean to differentiate with respect to the inverse of
the variable:
> deriv(as.freealg("3abcbCC"),"C") free algebra element algebraically equal to + 3*abcbC(dC) + 3*abcb(dC)C - 3*abc(dC)cbCC
It is possible to perform repeated differentiation by passing a
suitable value of r
. For
\frac{\partial^2}{\partial a\partial c}
:
> deriv(as.freealg("aaabAcx"),"ac") free algebra element algebraically equal to - 1*aaabA(da)A(dc)x + 1*aa(da)bA(dc)x + 1*a(da)abA(dc)x + 1*(da)aabA(dc)x
The infinitesimal indeterminates (“da
” etc) are
represented by SHRT_MAX+r
, where r
is the integer for
the symbol, and SHRT_MAX
is the maximum short integer. This
includes negative r
. So the maximum number for any symbol is
SHRT_MAX
. Inverse elements such as A
, being represented
by negative integers, have differentials that are SHRT_MAX-r
.
Function deriv()
calls helper function lowlevel_diffn()
which is documented at Ops.freealg.Rd
.
A vignette illustrating this concept and furnishing numerical
verification of the code in the context of matrix algebra is given at
inst/freealg_matrix.Rmd
.
Robin K. S. Hankin
deriv(as.freealg("4*aaaabaacAc"),1)
x <- rfalg()
deriv(x,1:3)
y <- rfalg(7,7,17,TRUE)
deriv(y,1:5)-deriv(y,sample(1:5)) # should be zero
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.