Title: | Multivariate Polynomials with Rational Coefficients |
---|---|
Description: | Symbolic calculation (addition or multiplication) and evaluation of multivariate polynomials with rational coefficients. |
Authors: | Stéphane Laurent |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL-3 |
Version: | 1.1.0 |
Built: | 2024-11-20 03:19:38 UTC |
Source: | https://github.com/stla/gmpoly |
Define a multivariate polynomial from a string or from its coefficients and powers.
gmpoly(string, coeffs = NULL, powers = NULL)
gmpoly(string, coeffs = NULL, powers = NULL)
string |
a string such as |
coeffs |
the coefficients of the polynomial, in case you don't define
it with the |
powers |
the powers of the polynomial, in case you don't define it
with the |
A gmpoly
object.
library(gmpoly) gmpoly("5/2 x^(2,3) + 3 x^(1,1)") gmpoly("5/2 x^(2,3) - 3 x^(1,1)") gmpoly("-x^(1,2,3) + 4/7 x^(3,1,1)") library(gmp) gmpoly( coeffs = as.bigq(c(5, 7), c(8, 9)), powers = rbind(c(1, 1, 1), c(2, 2, 2)) )
library(gmpoly) gmpoly("5/2 x^(2,3) + 3 x^(1,1)") gmpoly("5/2 x^(2,3) - 3 x^(1,1)") gmpoly("-x^(1,2,3) + 4/7 x^(3,1,1)") library(gmp) gmpoly( coeffs = as.bigq(c(5, 7), c(8, 9)), powers = rbind(c(1, 1, 1), c(2, 2, 2)) )
Convert a gmpoly
polynomial to a
mvp
polynomial.
gmpoly2mvp(pol)
gmpoly2mvp(pol)
pol |
a |
A mvp
object.
library(gmpoly) pol <- gmpoly("5/2 x^(2,2,3) + 3 x^(1,0,1)") gmpoly2mvp(pol)
library(gmpoly) pol <- gmpoly("5/2 x^(2,2,3) + 3 x^(1,0,1)") gmpoly2mvp(pol)
Constructs a constant multivariate polynomial.
gmpolyConstant(m, value)
gmpolyConstant(m, value)
m |
number of variables, a strictly positive integer |
value |
the constant value of the polynomial; the
|
A gmpoly
object.
library(gmpoly) gmpolyConstant(3, "2/3")
library(gmpoly) gmpolyConstant(3, "2/3")
Evaluates a gmpoly
multivariate polynomial for given
values of the variables.
gmpolyEval(pol, x)
gmpolyEval(pol, x)
pol |
a |
x |
either a |
A bigq
number or vector.
library(gmpoly) library(gmp) pol <- gmpoly("5/2 x^(2,3) + 3 x^(1,1)") gmpolyEval(pol, as.bigq(c(1, 1))) x <- rbind( t(as.bigq(c(1, 1))), t(as.bigq(c(3, 4), c(4, 3))) ) gmpolyEval(pol, x)
library(gmpoly) library(gmp) pol <- gmpoly("5/2 x^(2,3) + 3 x^(1,1)") gmpolyEval(pol, as.bigq(c(1, 1))) x <- rbind( t(as.bigq(c(1, 1))), t(as.bigq(c(3, 4), c(4, 3))) ) gmpolyEval(pol, x)
Grow a multivariate polynomial by including a new variable.
gmpolyGrow(pol)
gmpolyGrow(pol)
pol |
a |
The "same" multivariate polynomial as pol
, except that it
has an additional variable.
library(gmpoly) pol <- gmpoly("3 x^(1,2) - 1/7 x^(5,3)") gmpolyGrow(pol)
library(gmpoly) pol <- gmpoly("3 x^(1,2) - 1/7 x^(5,3)") gmpolyGrow(pol)
Arithmetic operators for multivariate polynomials
## S3 method for class 'gmpoly' Ops(e1, e2 = NULL)
## S3 method for class 'gmpoly' Ops(e1, e2 = NULL)
e1 , e2
|
for an unary operator, only |
A gmpoly
object.
library(gmpoly) pol <- gmpoly("4 x^(2, 1, 1) + 1/2 x^(0,1,0)") +pol -pol 2 * pol pol / 2 pol + 5 pol - 5 pol^2 pol1 <- gmpoly("2 x^(1,1) - 5/3 x^(0,1)") pol2 <- gmpoly("-2 x^(1,1) + 3 x^(2,1)") pol1 + pol2 pol1 * pol2 pol1 == pol2 pol1 != pol2
library(gmpoly) pol <- gmpoly("4 x^(2, 1, 1) + 1/2 x^(0,1,0)") +pol -pol 2 * pol pol / 2 pol + 5 pol - 5 pol^2 pol1 <- gmpoly("2 x^(1,1) - 5/3 x^(0,1)") pol2 <- gmpoly("-2 x^(1,1) + 3 x^(2,1)") pol1 + pol2 pol1 * pol2 pol1 == pol2 pol1 != pol2
Print a multivariate polynomial of class gmpoly
.
## S3 method for class 'gmpoly' print(x, ...)
## S3 method for class 'gmpoly' print(x, ...)
x |
a |
... |
ignored |
No value, just prints the polynomial.