subs: Substitution In mvp: Fast Symbolic Multivariate Polynomials

Description

Substitute symbols in an mvp object for numbers or other multivariate polynomials

Usage

 1 2 3 4 5 6 7 subs(S, ..., lose = TRUE) subsy(S, ..., lose = TRUE) subvec(S, ...) subsmvp(S,v,X) varchange(S,...) varchange_formal(S,old,new) namechanger(x,old,new)

Arguments

 S,X Multivariate polynomials ... named arguments corresponding to variables to substitute lose Boolean with default TRUE meaning to return a scalar (the constant) in place of a constant mvp object v A string corresponding to the variable to substitute old,new,x The old and new variable names respectively; x is a character vector

Details

Function subs() substitutes variables for mvp objects, using a natural R idiom. Observe that this type of substitution is sensitive to order:

 1 2 3 4 5 6 7 > p <- as.mvp("a b^2") > subs(p,a="b",b="x") mvp object algebraically equal to x^3 > subs(p,b="x",a="b") # same arguments, different order mvp object algebraically equal to b x^2

Functions subsy() and subsmvp() are lower-level functions, not really intended for the end-user. Function subsy() substitutes variables for numeric values (order matters if a variable is substituted more than once). Function subsmpv() takes a mvp object and substitutes another mvp object for a specific symbol.

Function subvec() substitutes the symbols of S with numerical values. It is vectorised in its ellipsis arguments with recycling rules and names behaviour inherited from cbind(). However, if the first element of ... is a matrix, then this is interpreted by rows, with symbol names given by the matrix column names; further arguments are ignored. Unlike subs(), this function is generally only useful if all symbols are given a value; unassigned symbols take a value of zero.

Function varchange() makes a formal variable substitution. It is useful because it can take non-standard variable names such as “(a-b)” or “?”, and is used in taylor(). Function varchange_formal() does the same task, but takes two character vectors, old and new, which might be more convenient than passing named arguments. Remember that non-standard names might need to be quoted; also you might need to escape some characters, see the examples. Function namechanger() is a low-level helper function that uses regular expression idiom to substitute variable names.

Value

Functions subs(), subsy() and subsmvp() return a multivariate polynomial unless lose is TRUE in which case a length one numeric vector is returned. Function subvec() returns a numeric vector (sic! the output inherits its order from the arguments).

Author(s)

Robin K. S. Hankin