freealg
objectsderiv.Rd
Differentiation of freealg
objects
# S3 method for class 'freealg'
deriv(expr, r, ...)
Experimental function deriv(S,v)
returns
∂rS∂v1∂v2…∂vr. The Leibniz product rule
(u⋅v)′=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+δa)=(a+δa)(a+δa)b(a+δa)
and working to first order we have
f(a+δa)−f(a)=(δa)aba+a(δa)ba+aab(δ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
∂2∂a∂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
.
deriv(as.freealg("4*aaaabaacAc"),1)
#> free algebra element algebraically equal to
#> - 4aaaabaacA(da)Ac + 4aaaaba(da)cAc + 4aaaab(da)acAc + 4aaa(da)baacAc +
#> 4aa(da)abaacAc + 4a(da)aabaacAc + 4(da)aaabaacAc
x <- rfalg()
deriv(x,1:3)
#> free algebra element algebraically equal to
#> 0
y <- rfalg(7,7,17,TRUE)
deriv(y,1:5)-deriv(y,sample(1:5)) # should be zero
#> free algebra element algebraically equal to
#> 0