mvp v1.0-8


Monthly downloads



Fast Symbolic Multivariate Polynomials

Fast manipulation of symbolic multivariate polynomials using the 'Map' class of the Standard Template Library. The package uses print and coercion methods from the 'mpoly' package (Kahle 2013, "Multivariate polynomials in R". The R Journal, 5(1):162), but offers speed improvements. It is comparable in speed to the 'spray' package for sparse arrays, but retains the symbolic benefits of 'mpoly'.


Fast symbolic multivariate polynomials in R

Status CRAN\_Status\_Badge Rdoc


Multivariate polynomials are intereresting and useful objects. Here I present the mvp package which hopefully improves upon previous R functionality provided by the packages multipol, mpoly, and spray. The mvp package follows mpoly in using a symbolic, rather than numeric, representation of a multivariate polynomial; but it offers speed advantages over mpoly. mvp uses the excellent print and coercion methods of the mpoly package. mvp includes some pleasing substitution idiom not found elsewhere; it is theoretically comparable in speed to the spray package and I present some timings in the package vignette.

The mvp package uses C++’s STL map class for efficiency, which has the downside that the order of the terms, and the order of the symbols within each term, is undefined. This does not matter as the mathematical value of a multivariate polynomial is unaffected by reordering; and the print method (taken from mpoly) does a good job in producing human-readable output.


You can install the released version of mvp from CRAN with:

# install.packages("mvp")  # uncomment this to install the package

The mvp package in use

Creating a multivariate polynomial is straightforward:

X <- as.mvp("1 + a^2 + a*b*c^3")
#> mvp object algebraically equal to
#> 1  +  a b c^3  +  a^2

and arithmetic operations work as expected:

Y <- as.mvp("12*a^2  + b - c^2 + 4*d")
#> mvp object algebraically equal to
#> 1  +  a b c^3  +  13 a^2  +  b  -  c^2  +  4 d
#> mvp object algebraically equal to
#> 1  +  a b c^3  -  35 a^2  -  3 b  +  3 c^2  -  12 d
#> mvp object algebraically equal to
#> 1  +  2 a b c^3  +  2 a^2  +  a^2 b^2 c^6  +  2 a^3 b c^3  +  a^4

Substitution uses the subs() function:

#> mvp object algebraically equal to
#> 1  +  a b c^3  +  a^2
#> mvp object algebraically equal to
#> 2  +  b c^3
#> mvp object algebraically equal to
#> 2  +  2 c^3
#> [1] 56
#> mvp object algebraically equal to
#> 14  +  4 d  +  x  +  26 x^2  +  13 x^4  +  y

Further information

For more detail, see the package vignette


Functions in mvp

Name Description
deriv Differentiation of mvp objects
ooom One over one minus a multivariate polynomial
mvp Multivariate polynomials, mvp objects
summary Summary methods for mvp objects
lose Drop empty variables
zero The zero polynomial
lowlevel Low level functions
spray Spray functionality
rmvp Random multivariate polynomials
subs Substitution
print Print methods for mvp objects
series Decomposition of multivariate polynomials by powers
special Various functions to create simple multivariate polynomials
mpoly Conversion to and from mpoly form
mvp-package mvp
horner Horner's method
as.function.mvp Functional form for multivariate polynomials
constant The constant term
kahle A sparse multivariate polynomial
allvars All variables in a multivariate polynomial
invert Replace symbols with their reciprocals
Ops.mvp Arithmetic Ops Group Methods for mvp objects
knight Chess knight
accessor Accessor methods for mvp objects
No Results!

Vignettes of mvp

No Results!

Last month downloads


Type Package
VignetteBuilder knitr
License GPL (>= 2)
LinkingTo Rcpp
SystemRequirements C++11
NeedsCompilation yes
Packaged 2019-09-04 21:41:02 UTC; rhankin
Repository CRAN
Date/Publication 2019-09-05 04:40:09 UTC

Include our badge in your README