Title: | Fractions of Multivariate Polynomials with Rational Coefficients |
---|---|
Description: | Based on the 'qspray' package, this package introduces the new type 'ratioOfQsprays'. An object of type 'qspray' represents a multivariate polynomial with rational coefficients while an object of type 'ratioOfQsprays', defined by two 'qspray' objects, represents a fraction of two multivariate polynomials with rational coefficients. Arithmetic operations for these objects are available, and they always return irreducible fractions. Other features include: differentiation, evaluation, conversion to a function, and fine control of the way to print a 'ratioOfQsprays' object. The 'C++' library 'CGAL' is used to make the fractions irreducible. |
Authors: | Stéphane Laurent [aut, cre] |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL-3 |
Version: | 1.1.0 |
Built: | 2024-11-26 06:46:15 UTC |
Source: | CRAN |
Coerces a ratioOfQsprays
polynomial to a function.
## S3 method for class 'ratioOfQsprays' as.function(x, N = FALSE, ...)
## S3 method for class 'ratioOfQsprays' as.function(x, N = FALSE, ...)
x |
object of class |
N |
Boolean, whether the function must numerically approximate the result |
... |
ignored |
A function having the same variables as the polynomial. If
N=FALSE
, it returns a string. If N=TRUE
, it returns a number
if the result does not contain any variable, otherwise it returns a
R expression.
library(ratioOfQsprays) x <- qlone(1); y <- qlone(2) roq <- (x^2/2 + y^2 + x*y - 1) / (x + 1) f <- as.function(roq) g <- as.function(roq, N = TRUE) f(2, "3/7") g(2, "3/7") f("x", "y") g("x", "y") # the evaluation is performed by (R)yacas and complex numbers are # allowed; the imaginary unit is denoted by \code{I}: f("2 + 2*I", "Sqrt(2)") g("2 + 2*I", "Sqrt(2)")
library(ratioOfQsprays) x <- qlone(1); y <- qlone(2) roq <- (x^2/2 + y^2 + x*y - 1) / (x + 1) f <- as.function(roq) g <- as.function(roq, N = TRUE) f(2, "3/7") g(2, "3/7") f("x", "y") g("x", "y") # the evaluation is performed by (R)yacas and complex numbers are # allowed; the imaginary unit is denoted by \code{I}: f("2 + 2*I", "Sqrt(2)") g("2 + 2*I", "Sqrt(2)")
Coercion to a 'ratioOfQsprays' object
## S4 method for signature 'character' as.ratioOfQsprays(x) ## S4 method for signature 'ratioOfQsprays' as.ratioOfQsprays(x) ## S4 method for signature 'qspray' as.ratioOfQsprays(x) ## S4 method for signature 'numeric' as.ratioOfQsprays(x) ## S4 method for signature 'bigz' as.ratioOfQsprays(x) ## S4 method for signature 'bigq' as.ratioOfQsprays(x)
## S4 method for signature 'character' as.ratioOfQsprays(x) ## S4 method for signature 'ratioOfQsprays' as.ratioOfQsprays(x) ## S4 method for signature 'qspray' as.ratioOfQsprays(x) ## S4 method for signature 'numeric' as.ratioOfQsprays(x) ## S4 method for signature 'bigz' as.ratioOfQsprays(x) ## S4 method for signature 'bigq' as.ratioOfQsprays(x)
x |
a |
This returns x
if x
already is a ratioOfQsprays
object, otherwise this returns the ratioOfQsprays
object whose
numerator is the coercion of x
to a qspray
object and whose
denominator is the unit qspray
object.
library(qspray) as.ratioOfQsprays(2) as.ratioOfQsprays("1/3") ( qspray <- 5*qlone(1) + qlone(2)^2 ) as.ratioOfQsprays(qspray) # show options are inherited: showQsprayOption(qspray, "x") <- "A" as.ratioOfQsprays(qspray)
library(qspray) as.ratioOfQsprays(2) as.ratioOfQsprays("1/3") ( qspray <- 5*qlone(1) + qlone(2)^2 ) as.ratioOfQsprays(qspray) # show options are inherited: showQsprayOption(qspray, "x") <- "A" as.ratioOfQsprays(qspray)
Replaces the variables of a ratioOfQsprays
fraction of
polynomials with some qspray
polynomials. E.g. you have a fraction
of polynomials and you want the fraction of polynomials
.
## S4 method for signature 'ratioOfQsprays,list' changeVariables(x, listOfQsprays)
## S4 method for signature 'ratioOfQsprays,list' changeVariables(x, listOfQsprays)
x |
a |
listOfQsprays |
a list containing at least |
The ratioOfQsprays
fraction of polynomials obtained by
replacing the variables of the fraction of polynomials given in the
x
argument with the qspray
polynomials given in the
listOfQsprays
argument.
library(ratioOfQsprays) f <- function(x, y) { (x^2 + 5*y - 1) / (x + 1) } x <- qlone(1) y <- qlone(2) R <- f(x, y) X <- x^2 Y <- x + y + 1 S <- changeVariables(R, list(X, Y)) S == f(X, Y) # should be TRUE
library(ratioOfQsprays) f <- function(x, y) { (x^2 + 5*y - 1) / (x + 1) } x <- qlone(1) y <- qlone(2) R <- f(x, y) X <- x^2 Y <- x + y + 1 S <- changeVariables(R, list(X, Y)) S == f(X, Y) # should be TRUE
Partial derivative of a ratioOfQsprays
.
derivRatioOfQsprays(roq, i, derivative = 1)
derivRatioOfQsprays(roq, i, derivative = 1)
roq |
object of class |
i |
integer, the dimension to differentiate with respect to, e.g.
|
derivative |
integer, how many times to differentiate |
A ratioOfQsprays
object.
library(ratioOfQsprays) x <- qlone(1) y <- qlone(2) roq <- (2*x + 3*x*y) / (x^2 + y^2) derivRatioOfQsprays(roq, 2) # derivative w.r.t. y
library(ratioOfQsprays) x <- qlone(1) y <- qlone(2) roq <- (2*x + 3*x*y) / (x^2 + y^2) derivRatioOfQsprays(roq, 2) # derivative w.r.t. y
Partial differentiation of a ratioOfQsprays
polynomial.
dRatioOfQsprays(roq, orders)
dRatioOfQsprays(roq, orders)
roq |
object of class |
orders |
integer vector, the orders of the differentiation; e.g.
|
A ratioOfQsprays
object.
library(ratioOfQsprays) x <- qlone(1) y <- qlone(2) roq <- (x + 2*y + 3*x*y) / (x + 1) dRatioOfQsprays(roq, c(1, 1)) derivRatioOfQsprays(derivRatioOfQsprays(roq, 1), 2)
library(ratioOfQsprays) x <- qlone(1) y <- qlone(2) roq <- (x + 2*y + 3*x*y) / (x + 1) dRatioOfQsprays(roq, c(1, 1)) derivRatioOfQsprays(derivRatioOfQsprays(roq, 1), 2)
Evaluation of the fraction of multivariate polynomials
represented by a ratioOfQsprays
object.
evalRatioOfQsprays(roq, values_re, values_im = NULL)
evalRatioOfQsprays(roq, values_re, values_im = NULL)
roq |
a |
values_re |
vector of the real parts of the values; each element of
|
values_im |
vector of the imaginary parts of the values; each element of
|
A bigq
number if values_im=NULL
, a pair of bigq
numbers otherwise: the real part and the imaginary part of the result.
x <- qlone(1); y <- qlone(2) roq <- 2*x / (x^2 + 3*y^2) evalRatioOfQsprays(roq, c("2", "5/2", "99999")) # "99999" will be ignored
x <- qlone(1); y <- qlone(2) roq <- 2*x / (x^2 + 3*y^2) evalRatioOfQsprays(roq, c("2", "5/2", "99999")) # "99999" will be ignored
Get the denominator of a ratioOfQsprays
object,
preserving the show options.
getDenominator(roq)
getDenominator(roq)
roq |
a |
A qspray
object.
Get the numerator of a ratioOfQsprays
object,
preserving the show options.
getNumerator(roq)
getNumerator(roq)
roq |
a |
A qspray
object.
Variables involved in a ratioOfQsprays
object.
## S4 method for signature 'ratioOfQsprays' involvedVariables(x)
## S4 method for signature 'ratioOfQsprays' involvedVariables(x)
x |
a |
A vector of integers. Each integer represents the index of a
variable involved in x
.
x <- qlone(1); z <- qlone(3) rOQ <- 2*x/z + x/(x+z) + z^2/x involvedVariables(rOQ) # should be c(1L, 3L)
x <- qlone(1); z <- qlone(3) rOQ <- 2*x/z + x/(x+z) + z^2/x involvedVariables(rOQ) # should be c(1L, 3L)
Checks whether a ratioOfQsprays
object defines a constant
fraction of polynomials.
## S4 method for signature 'ratioOfQsprays' isConstant(x)
## S4 method for signature 'ratioOfQsprays' isConstant(x)
x |
a |
A Boolean value.
Checks whether a ratioOfQsprays
actually is polynomial,
that is, whether its denominator is a constant qspray
polynomial
(and then it should be equal to one).
isPolynomial(roq)
isPolynomial(roq)
roq |
a |
A Boolean value.
x <- qlone(1) y <- qlone(2) roq <- (x^2 - y^2) / (x - y) isPolynomial(roq) roq == x + y
x <- qlone(1) y <- qlone(2) roq <- (x^2 - y^2) / (x - y) isPolynomial(roq) roq == x + y
Checks whether a ratioOfQsprays
object defines a
univariate fraction of polynomials.
## S4 method for signature 'ratioOfQsprays' isUnivariate(x)
## S4 method for signature 'ratioOfQsprays' isUnivariate(x)
x |
a |
A Boolean value.
The ratioOfQsprays
object y / (1 + y)
where
y=qlone(2)
is not univariate, although it involves only one
variable. The function returns TRUE
when only qlone(1)
is involved or when no variable is involved.
Number of variables involved in a ratioOfQsprays
object.
## S4 method for signature 'ratioOfQsprays' numberOfVariables(x)
## S4 method for signature 'ratioOfQsprays' numberOfVariables(x)
x |
a |
An integer.
The number of variables in the ratioOfQsprays
object
y / (1 + y)
where y=qlone(2)
is 2
, not 1
,
although only one variable occurs. Rigorously speaking, the function
returns the maximal integer d
such that qlone(d)
occurs in
the 'ratioOfQsprays'.
Permute the variables of a ratioOfQsprays
fraction
of polynomials.
## S4 method for signature 'ratioOfQsprays,numeric' permuteVariables(x, permutation)
## S4 method for signature 'ratioOfQsprays,numeric' permuteVariables(x, permutation)
x |
a |
permutation |
a permutation |
A ratioOfQsprays
object.
library(ratioOfQsprays) f <- function(x, y, z) { (x^2 + 5*y + z - 1) / (x + 1) } x <- qlone(1) y <- qlone(2) z <- qlone(3) R <- f(x, y, z) permutation <- c(3, 1, 2) S <- permuteVariables(R, permutation) S == f(z, x, y) # should be TRUE
library(ratioOfQsprays) f <- function(x, y, z) { (x^2 + 5*y + z - 1) / (x + 1) } x <- qlone(1) y <- qlone(2) z <- qlone(3) R <- f(x, y, z) permutation <- c(3, 1, 2) S <- permuteVariables(R, permutation) S == f(z, x, y) # should be TRUE
This function is for internal usage. It is exported because it is also used for internal usage in other packages.
ratioOfQsprays_from_list(x)
ratioOfQsprays_from_list(x)
x |
list returned by the Rcpp function
|
A ratioOfQsprays
object.
Unary operators for ratioOfQsprays
objects.
## S4 method for signature 'ratioOfQsprays,missing' e1 + e2 ## S4 method for signature 'ratioOfQsprays,missing' e1 - e2
## S4 method for signature 'ratioOfQsprays,missing' e1 + e2 ## S4 method for signature 'ratioOfQsprays,missing' e1 - e2
e1 |
object of class |
e2 |
nothing |
A ratioOfQsprays
object.
Generates a random ratioOfQsprays
object.
rRatioOfQsprays(allow.zero = TRUE)
rRatioOfQsprays(allow.zero = TRUE)
allow.zero |
Boolean, whether to allow to get a null
|
A ratioOfQsprays
object.
Prints a ratioOfQsprays
object given a function to print
a qspray
object
showRatioOfQsprays( showQspray, quotientBar = " %//% ", lbracket = "[ ", rbracket = " ]" )
showRatioOfQsprays( showQspray, quotientBar = " %//% ", lbracket = "[ ", rbracket = " ]" )
showQspray |
a function which prints a |
quotientBar |
a string representing the quotient bar between the
numerator and the denominator, including surrounding spaces,
e.g |
lbracket , rbracket
|
used to enclose the numerator and the denominator |
A function which takes as argument a ratioOfQsprays
object
and which prints it.
The function returned by this function can be used as the option
"showRatioOfQsprays"
of the setter function
showRatioOfQspraysOption<-
. That said, one would more often
uses showRatioOfQspraysX1X2X3
or
showRatioOfQspraysXYZ
for this option, which are both built
with showRatioOfQsprays
.
showRatioOfQspraysX1X2X3
,
showRatioOfQspraysXYZ
,
showRatioOfQspraysOption<-
,
showQspray
.
set.seed(666) ( roq <- rRatioOfQsprays() ) f <- showRatioOfQsprays(showQsprayX1X2X3("a"), " / ", "[[ ", " ]]") f(roq) # this is equivalent to f <- showRatioOfQspraysX1X2X3("a", " / ", lbracket = "[[ ", rbracket = " ]]") f(roq)
set.seed(666) ( roq <- rRatioOfQsprays() ) f <- showRatioOfQsprays(showQsprayX1X2X3("a"), " / ", "[[ ", " ]]") f(roq) # this is equivalent to f <- showRatioOfQspraysX1X2X3("a", " / ", lbracket = "[[ ", rbracket = " ]]") f(roq)
Set a show option to a ratioOfQsprays
object.
showRatioOfQspraysOption(x, which) <- value
showRatioOfQspraysOption(x, which) <- value
x |
a |
which |
which option to set; this can be |
value |
the value of the option to be set |
This returns the updated ratioOfQsprays
.
set.seed(666) ( roq <- rRatioOfQsprays() ) showRatioOfQspraysOption(roq, "quotientBar") <- " / " roq showRatioOfQspraysOption(roq, "x") <- "a" roq showRatioOfQspraysOption(roq, "showQspray") <- showQsprayXYZ() roq
set.seed(666) ( roq <- rRatioOfQsprays() ) showRatioOfQspraysOption(roq, "quotientBar") <- " / " roq showRatioOfQspraysOption(roq, "x") <- "a" roq showRatioOfQspraysOption(roq, "showQspray") <- showQsprayXYZ() roq
Print a ratioOfQsprays
object given a string to denote
the non-indexed variables.
showRatioOfQspraysX1X2X3(var, quotientBar = " %//% ", ...)
showRatioOfQspraysX1X2X3(var, quotientBar = " %//% ", ...)
var |
a string, usually a letter, to denote the non-indexed variables |
quotientBar |
a string representing the quotient bar between the
numerator and the denominator, including surrounding spaces,
e.g |
... |
arguments other than |
A function which takes as argument a ratioOfQsprays
object
and which prints it.
The function returned by this function can be used as the option
"showRatioOfQsprays"
of the setter function
showRatioOfQspraysOption<-
. If you do not use the
ellipsis arguments, this is equivalent to set the "x"
option and the "quotientBar"
option (see example).
showRatioOfQspraysXYZ
,
showRatioOfQspraysOption<-
.
set.seed(666) ( roq <- rRatioOfQsprays() ) showRatioOfQspraysX1X2X3("X", " / ")(roq) # setting a show option: showRatioOfQspraysOption(roq, "showRatioOfQsprays") <- showRatioOfQspraysX1X2X3("X", " / ") roq # this is equivalent to set the "x" and "quotientBar" options: showRatioOfQspraysOption(roq, "x") <- "X" showRatioOfQspraysOption(roq, "quotientBar") <- " / "
set.seed(666) ( roq <- rRatioOfQsprays() ) showRatioOfQspraysX1X2X3("X", " / ")(roq) # setting a show option: showRatioOfQspraysOption(roq, "showRatioOfQsprays") <- showRatioOfQspraysX1X2X3("X", " / ") roq # this is equivalent to set the "x" and "quotientBar" options: showRatioOfQspraysOption(roq, "x") <- "X" showRatioOfQspraysOption(roq, "quotientBar") <- " / "
Print a ratioOfQsprays
object given some letters to
denote the variables, by printing monomials in the style of
"x^2.yz"
.
showRatioOfQspraysXYZ( letters = c("x", "y", "z"), quotientBar = " %//% ", ... )
showRatioOfQspraysXYZ( letters = c("x", "y", "z"), quotientBar = " %//% ", ... )
letters |
a vector of strings, usually some letters such as |
quotientBar |
a string representing the quotient bar between the
numerator and the denominator, including surrounding spaces,
e.g |
... |
arguments other than |
A function which takes as argument a ratioOfQsprays
object
and which prints it.
The function returned by this function can be used as the option
"showRatioOfQsprays"
of the setter function
showRatioOfQspraysOption<-
.
As another note, let us describe the behavior of this function in a
case when the number of variables of the ratioOfQsprays
object to
be printed is bigger than the number of provided letters. In such a case,
the output will be the same as an application of the function
showRatioOfQspraysX1X2X3(x)
with x
being the first letter
provided. See the example.
showRatioOfQspraysX1X2X3
,
showRatioOfQspraysOption<-
.
set.seed(666) ( roq <- rRatioOfQsprays() ) showRatioOfQspraysXYZ(c("X", "Y", "Z"), " / ")(roq) # now take a ratioOfQsprays with four variables: roq <- roq * qlone(4) # then the symbols X1, X2, X3, X4 denote the variables now: showRatioOfQspraysXYZ(c("X", "Y", "Z"), " / ")(roq) # this is the method used by default to print the ratioOfQsprays objects, # with the initial letters x, y, z which then become x1, x2, x3, x4: roq
set.seed(666) ( roq <- rRatioOfQsprays() ) showRatioOfQspraysXYZ(c("X", "Y", "Z"), " / ")(roq) # now take a ratioOfQsprays with four variables: roq <- roq * qlone(4) # then the symbols X1, X2, X3, X4 denote the variables now: showRatioOfQspraysXYZ(c("X", "Y", "Z"), " / ")(roq) # this is the method used by default to print the ratioOfQsprays objects, # with the initial letters x, y, z which then become x1, x2, x3, x4: roq
Substitute some values to a subset of the variables of a
ratioOfQsprays
fraction of polynomials.
substituteRatioOfQsprays(roq, values)
substituteRatioOfQsprays(roq, values)
roq |
a |
values |
the values to be substituted; this must be a vector whose
length equals the number of variables of |
A ratioOfQsprays
object.
library(ratioOfQsprays) x <- qlone(1) y <- qlone(2) z <- qlone(3) roq <- (x^2 + y^2 + x*y*z - 1) / (x + 1) substituteRatioOfQsprays(roq, c("2", NA, "3/2"))
library(ratioOfQsprays) x <- qlone(1) y <- qlone(2) z <- qlone(3) roq <- (x^2 + y^2 + x*y*z - 1) / (x + 1) substituteRatioOfQsprays(roq, c("2", NA, "3/2"))
Swap two variables of a ratioOfQsprays
.
## S4 method for signature 'ratioOfQsprays,numeric,numeric' swapVariables(x, i, j)
## S4 method for signature 'ratioOfQsprays,numeric,numeric' swapVariables(x, i, j)
x |
a |
i , j
|
indices of the variables to be swapped |
A ratioOfQsprays
object.
library(ratioOfQsprays) f <- function(x, y, z) { (x^2 + 5*y + z - 1) / (x + 1) } x <- qlone(1) y <- qlone(2) z <- qlone(3) R <- f(x, y, z) S <- swapVariables(R, 2, 3) S == f(x, z, y) # should be TRUE
library(ratioOfQsprays) f <- function(x, y, z) { (x^2 + 5*y + z - 1) / (x + 1) } x <- qlone(1) y <- qlone(2) z <- qlone(3) R <- f(x, y, z) S <- swapVariables(R, 2, 3) S == f(x, z, y) # should be TRUE