deriv: Differentiation of 'freealg' objects

derivR Documentation

Differentiation of freealg objects

Description

Differentiation of freealg objects

Usage

## S3 method for class 'freealg'
deriv(expr, r, ...)

Arguments

expr

Object of class freealg

r

Integer vector. Elements denote variables to differentiate with respect to. If r is a character vector, it is interpreted as a=1,b=2,...,z=26; if of length 1, “aab” is interpreted as c("a","a","b")

...

Further arguments, currently ignored

Details

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.

Author(s)

Robin K. S. Hankin

Examples


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



RobinHankin/freealg documentation built on Dec. 24, 2024, 3:16 a.m.