mp is a smart function which attempts to create a formal mpoly object from a character string containing the usual representation of a multivariate polynomial.

make_indeterminate_list(vars)

mp(string, varorder, stars_only = FALSE)

Arguments

vars

a character vector of indeterminates

string

a character string containing a polynomial, see examples

varorder

(optional) order of variables in string

stars_only

if you format your multiplications using asterisks, setting this to TRUE will reduce preprocessing time

Value

An object of class mpoly.

See also

Examples

( m <- mp("x + y + x y") )
#> x + y + x y
#> [1] TRUE
#> [[1]] #> x coef #> 1 1 #> #> [[2]] #> y coef #> 1 1 #> #> [[3]] #> x y coef #> 1 1 1 #>
mp("x + 2 y + x^2 y + x y z")
#> x + 2 y + x^2 y + x y z
mp("x + 2 y + x^2 y + x y z", varorder = c("y", "z", "x"))
#> x + 2 y + y x^2 + y z x
( ms <- mp(c("x + y", "2 x")) )
#> x + y #> 2 x
#> [1] TRUE
gradient( mp("x + 2 y + x^2 y + x y z") )
#> 2 x y + y z + 1 #> x^2 + x z + 2 #> x y
gradient( mp("(x + y)^10") )
#> 10 x^9 + 90 x^8 y + 360 x^7 y^2 + 840 x^6 y^3 + 1260 x^5 y^4 + 1260 x^4 y^5 + 840 x^3 y^6 + 360 x^2 y^7 + 90 x y^8 + 10 y^9 #> 10 x^9 + 90 x^8 y + 360 x^7 y^2 + 840 x^6 y^3 + 1260 x^5 y^4 + 1260 x^4 y^5 + 840 x^3 y^6 + 360 x^2 y^7 + 90 x y^8 + 10 y^9
# mp and the print methods are kinds of inverses of each other ( polys <- mp(c("x + y", "x - y")) )
#> x + y #> x - y
strings <- print(polys, silent = TRUE) strings
#> [1] "x + y" "x - y"
mp(strings)
#> x + y #> x - y