| Type: | Package |
| Title: | Multivariate Polynomials with Rational Coefficients |
| Version: | 3.1.0 |
| Maintainer: | Stéphane Laurent <laurent_step@outlook.fr> |
| Description: | Symbolic calculation and evaluation of multivariate polynomials with rational coefficients. This package is strongly inspired by the 'spray' package. It provides a function to compute Gröbner bases (reference <doi:10.1007/978-3-319-16721-3>). It also includes some features for symmetric polynomials, such as the Hall inner product. The header file of the C++ code can be used by other packages. It provides the templated class 'Qspray' that can be used to represent and to deal with multivariate polynomials with another type of coefficients. |
| License: | GPL-3 |
| URL: | https://github.com/stla/qspray |
| BugReports: | https://github.com/stla/qspray/issues |
| Imports: | DescTools, gmp, methods, partitions, purrr, RationalMatrix,Rcpp (≥ 1.0.9), Ryacas, utils |
| LinkingTo: | BH, Rcpp |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.1 |
| SystemRequirements: | C++17, gmp |
| Collate: | 'RcppExports.R' 'characteristicPolynomial.R' 'creation.R''evaluation.R' 'groebner.R' 'integrateOnSimplex.R' 'internal.R''qspray.R' 'qsprayDivision.R' 'queries.R' 'show.R''symmetricPolynomials.R' 'transformation.R' 'yacas.R' |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | yes |
| Packaged: | 2024-07-27 17:02:15 UTC; User |
| Author: | Stéphane Laurent [aut, cre], Robin Hankin [ctb, cph] (author of the 'spray' package, which strongly inspired this package) |
| Repository: | CRAN |
| Date/Publication: | 2024-07-27 22:20:09 UTC |
Complete homogeneous symmetric function
Description
Returns a complete homogeneous symmetric function as aqspray polynomial.
Usage
CSHFpoly(m, lambda)Arguments
m | integer, the number of variables |
lambda | an integer partition, given as a vector of decreasingpositive integers |
Value
Aqspray object.
Examples
library(qspray)CSHFpoly(3, c(3, 1))Elementary symmetric polynomial
Description
Returns an elementary symmetric function as a polynomial.
Usage
ESFpoly(m, lambda)Arguments
m | integer, the number of variables |
lambda | an integer partition, given as a vector of decreasingpositive integers |
Value
Aqspray object.
Examples
library(qspray)ESFpoly(3, c(3, 1))Hall inner product
Description
Hall inner product of two symmetric polynomials. It has a parameteralpha and the standard Hall inner product is the case whenalpha=1. It is possible to get the Hall inner product with a symbolicalpha parameter.
Usage
HallInnerProduct(qspray1, qspray2, alpha = 1)Arguments
qspray1,qspray2 | two symmetric |
alpha | parameter equal to |
Value
Abigq number ifalpha is notNULL, otherwise a univariateqspray polynomial.
Monomial symmetric function
Description
Returns a monomial symmetric function as a polynomial.
Usage
MSFpoly(m, lambda)Arguments
m | integer, the number of variables |
lambda | an integer partition, given as a vector of decreasingpositive integers |
Value
Aqspray object.
Examples
library(qspray)MSFpoly(3, c(3, 1))Symmetric polynomial in terms of the monomial symmetric polynomials
Description
Expression of a symmetric polynomial as a linear combination of the monomial symmetric polynomials.
Usage
MSPcombination(qspray, check = TRUE)Arguments
qspray | a |
check | Boolean, whether to check the symmetry |
Value
A list defining the combination. Each element of this list is a list with two elements:coeff, abigq number, andlambda, an integer partition; then this list corresponds to the termcoeff * MSFpoly(n, lambda), wheren is the number of variables in the symmetric polynomial.
Examples
qspray <- PSFpoly(4, c(3, 1)) + ESFpoly(4, c(2, 2)) + 4LMSPcombination(qspray)Power sum polynomial
Description
Returns a power sum function as a polynomial.
Usage
PSFpoly(m, lambda)Arguments
m | integer, the number of variables |
lambda | an integer partition, given as a vector of decreasingpositive integers |
Value
Aqspray object.
Examples
library(qspray)PSFpoly(3, c(3, 1))Symmetric polynomial as a linear combination of some power sum polynomials
Description
Expression of a symmetricqspray polynomial as a linear combination of some power sum polynomials.
Usage
PSPcombination(qspray)Arguments
qspray | a symmetric |
Value
A list of pairs. Each pair is made of abigq number, the coefficient of the term of the linear combination, and an integer partition, corresponding to a power sum polynomial.
See Also
Examples
# take a symmetric polynomial( qspray <- ESFpoly(4, c(2, 1)) + ESFpoly(4, c(2, 2)) )# compute the power sum combination( pspCombo <- PSPcombination(qspray) )# then the polynomial can be reconstructed as follows:Reduce(`+`, lapply(pspCombo, function(term) { term[["coeff"]] * PSFpoly(4, term[["lambda"]])}))Symmetric polynomial in terms of the power sum polynomials
Description
Expression of a symmetricqspray polynomial as a polynomial in the power sum polynomials.
Usage
PSPexpression(qspray)Arguments
qspray | a symmetric |
Value
Aqspray polynomial, sayP, such thatP(p_1, ..., p_n) equals the input symmetric polynomial, wherep_i is the i-th power sum polynomial (PSFpoly(n, i)).
See Also
Examples
# take a symmetric polynomial( qspray <- ESFpoly(4, c(2, 1)) + ESFpoly(4, c(2, 2)) )# compute the power sum expression( pspExpr <- PSPexpression(qspray) )# take the involved power sum polynomialspsPolys <- lapply(1:numberOfVariables(pspExpr), function(i) PSFpoly(4, i))# then this should be TRUE:qspray == changeVariables(pspExpr, psPolys)Multivariate polynomial as function
Description
Coerces aqspray polynomial into a function.
Usage
## S3 method for class 'qspray'as.function(x, N = FALSE, ...)Arguments
x | object of class |
N | Boolean, whether the function must numerically approximate the result |
... | ignored |
Value
A function having the same variables as the polynomial. IfN=FALSE, it returns a string. IfN=TRUE, it returns a number if the result does not contain any variable, otherwise it returns a R expression.
Examples
library(qspray)P <- (qlone(1) + "1/2"*qlone(2))^2 + 5f <- as.function(P)g <- as.function(P, 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 `I`f("2 + 2*I", "Sqrt(2)")g("2 + 2*I", "Sqrt(2)")Coercion to a 'qspray' object
Description
Coercion to a 'qspray' object
Usage
## S4 method for signature 'character'as.qspray(x)## S4 method for signature 'qspray'as.qspray(x)## S4 method for signature 'numeric'as.qspray(x)## S4 method for signature 'bigz'as.qspray(x)## S4 method for signature 'bigq'as.qspray(x)Arguments
x | a |
Value
Aqspray object.
Examples
as.qspray(2)as.qspray("1/3")Change of variables in a 'qspray' polynomial
Description
Replaces the variables of aqspray polynomial with someqspray polynomials. E.g. you have a polynomialP(x, y) and you want the polynomialP(x^2, x+y+1). This is an alias ofcomposeQspray.
Usage
## S4 method for signature 'qspray,list'changeVariables(x, listOfQsprays)Arguments
x | a |
listOfQsprays | a list containing at least |
Value
Theqspray polynomial obtained by replacing the variables of the polynomial given in thex argument with the polynomials given in thelistOfQsprays argument.
Examples
library(qspray)f <- function(x, y) x*y/2 + 4*yx <- qlone(1)y <- qlone(2)P <- f(x, y)X <- x^2Y <- x + y + 1changeVariables(P, list(X, Y)) == f(X, Y) # should be TRUECharacteristic polynomial
Description
Characteristic polynomial of a matrix.
Usage
characteristicPolynomial(A)Arguments
A | a square matrix with numeric, character, or |
Value
A univariateqspray polynomial.
Examples
set.seed(666)A <- matrix(rpois(9L, 10), nrow = 3, ncol = 3)( P <- characteristicPolynomial(A) )# check the roots are the eigen values:f <- as.function(P, N = TRUE)sapply(eigen(A)$values, f) # approx c(0, 0, 0)Whether two 'qspray' polynomials are collinear
Description
Checks whether the polynomials represented by twoqsprayobjects are collinear, that is, whether they are equal up to a scalar factor.
Usage
collinearQsprays(qspray1, qspray2)Arguments
qspray1,qspray2 | two |
Value
A Boolean value.
Examples
library(qspray)qspray1 <- qsprayMaker(string = "1/2 x^(1, 1) + 4 x^(0, 2) + 5")qspray2 <- "4/7" * qspray1collinearQsprays(qspray1, qspray2)Compact symmetric qspray
Description
Prints a symmetric qspray polynomial as a linear combination of the monomial symmetric polynomials.
Usage
## S4 method for signature 'qspray,logical'compactSymmetricQspray(qspray, check)## S4 method for signature 'qspray,ANY'compactSymmetricQspray(qspray)Arguments
qspray | a |
check | Boolean, whether to check the symmetry (default |
Value
A character string.
See Also
Examples
library(qspray)( qspray <- PSFpoly(4, c(3, 1)) - ESFpoly(4, c(2, 2)) + 4L )compactSymmetricQspray(qspray, check = TRUE)Compose 'qspray' polynomials
Description
Substitutes the variables of aqspray polynomial with someqspray polynomials. E.g. you have a polynomialP(x, y) and you want the polynomialP(x^2, x+y+1) (see example).
Usage
composeQspray(qspray, listOfQsprays)Arguments
qspray | a |
listOfQsprays | a list containing at least |
Value
Theqspray polynomial obtained by composing the polynomial given in theqspray argument with the polynomials given in thelistOfQsprays argument.
Examples
library(qspray)x <- qlone(1)y <- qlone(2)P <- x*y/2 + 4*yX <- x^2Y <- x + y + 1composeQspray(P, list(X, Y)) # this is P(x^2, x+y+1)Partial differentiation
Description
Partial differentiation of aqspray polynomial.
Usage
dQspray(qspray, orders)Arguments
qspray | object of class |
orders | integer vector, the orders of the differentiation; e.g. |
Value
Aqspray object.
Examples
library(qspray)x <- qlone(1)y <- qlone(2)qspray <- x + 2*y + 3*x*ydQspray(qspray, c(1, 1))derivQspray(derivQspray(qspray, 1), 2)Partial derivative
Description
Partial derivative of aqspray polynomial.
Usage
derivQspray(qspray, i, derivative = 1)Arguments
qspray | object of class |
i | integer, the dimension to differentiate with respect to, e.g. |
derivative | integer, how many times to differentiate |
Value
Aqspray object.
Examples
library(qspray)x <- qlone(1)y <- qlone(2)qspray <- 2*x + 3*x*yderivQspray(qspray, 2) # derivative w.r.t. yEvaluate a 'qspray' object
Description
Evaluation of the multivariate polynomial represented by aqspray object.
Usage
evalQspray(qspray, values_re, values_im = NULL)Arguments
qspray | 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 |
Value
Abigq number ifvalues_im=NULL, a pair ofbigq numbers otherwise: the real part and the imaginary part of the result.
Examples
x <- qlone(1); y <- qlone(2)P <- 2*x + "1/2"*yevalQspray(P, c("2", "5/2", "99999")) # "99999" will be ignoredGet a coefficient in a 'qspray' polynomial
Description
Get the coefficient of the term with the given monomial.
Usage
## S4 method for signature 'qspray,numeric'getCoefficient(qspray, exponents)Arguments
qspray | a |
exponents | a vector of exponents, thereby defining a monomial;trailing zeros are ignored |
Value
The coefficient as abigq number.
Examples
library(qspray)x <- qlone(1)y <- qlone(2)p <- 4*x^2 + 3*y - 5getCoefficient(p, 2) # coefficient of x^2getCoefficient(p, c(2, 0)) # same as getCoefficient(p, 2)getCoefficient(p, c(0, 1)) # coefficient of y because y=x^0*y^1getCoefficient(p, 0) # the constant termgetCoefficient(p, integer(0)) # the constant term getCoefficient(p, 3) # there's no x^3Get the constant term of a 'qspray' polynomial
Description
Get the constant term of aqspray polynomial.
Usage
## S4 method for signature 'qspray'getConstantTerm(qspray)Arguments
qspray | a |
Value
Abigq number.
Gröbner basis
Description
Returns a Gröbner basis following Buchberger's algorithm using the lexicographical order.
Usage
groebner(G, minimal = TRUE, reduced = TRUE)Arguments
G | a list of |
minimal | Boolean, whether to return a minimal basis |
reduced | Boolean, whether to return the reduced basis |
Value
A Gröbner basis of the ideal generated byG, given as a list ofqspray polynomials.
References
Cox, Little & O'Shea.Ideals, Varieties, and Algorithms. An Introduction to Computational Algebraic Geometry and Commutative Algebra.Fourth edition, Springer 2015.
Examples
library(qspray)f <- qsprayMaker(string = "x^(3) - 2 x^(1,1)")g <- qsprayMaker(string = "x^(2,1) - 2 x^(0,2) + x^(1)")groebner(list(f, g), FALSE, FALSE)# other examplex <- qlone(1); y <- qlone(2); z <- qlone(3)f1 <- x^2 + y + z^2 - 1f2 <- x^2 + y + z - 1f3 <- x + y^2 + z - 1groebner(list(f1, f2, f3))Implicitization with Gröbner bases
Description
Implicitization of a system of parametric equations (see example).
Usage
implicitization(nvariables, parameters, equations, relations)Arguments
nvariables | number of variables |
parameters | character vector of the names of the parameters, or |
equations | named list of |
relations | list of |
Value
A list ofqspray polynomials.
Examples
library(qspray)# ellipse example ##### variables cost <- qlone(1)sint <- qlone(2)nvariables <- 2# parametersa <- qlone(3)b <- qlone(4)parameters <- c("a", "b")#equations <- list( "x" = a * cost, "y" = b * sint)relations <- list( cost^2 + sint^2 - 1)# implicitization(nvariables, parameters, equations, relations)Integral of a multivariate polynomial over a simplex
Description
Returns the exact value of the integral of a multivariate polynomial with rational coefficients over a simplex whose vertices have rational coordinates.
Usage
integratePolynomialOnSimplex(P, S)Arguments
P | a |
S | the simplex, a |
Value
Abigq number, the exact value of the integral.
Examples
library(qspray)x <- qlone(1); y <- qlone(2)P <- x/2 + x*yS <- rbind(c("0", "0"), c("1", "0"), c("1", "1")) # a triangleintegratePolynomialOnSimplex(P, S)Variables involved in a 'qspray' polynomial
Description
Variables involved in aqspray object.
Usage
## S4 method for signature 'qspray'involvedVariables(x)Arguments
x | a |
Value
A vector of integers. Each integer represents the index of a variable involved inx.
Examples
x <- qlone(1); z <- qlone(3)involvedVariables(x^2 + x*z + 1) # should be c(1L, 3L)Whether a 'qspray' polynomial is constant
Description
Checks whether aqspray object defines a constant polynomial.
Usage
## S4 method for signature 'qspray'isConstant(x)Arguments
x | a |
Value
A Boolean value.
Whether a 'qspray' polynomial is homogeneous
Description
Checks whether the polynomial defined by aqspray object is homogeneous, and also returns the degree if this is true.
Usage
isHomogeneousQspray(qspray)Arguments
qspray | a |
Value
A Boolean value indicating whether the polynomial defined byqspray is homogeneous. Moreover, if it is homogeneous, the degree is given in the attribute"degree" of the output.
Examples
lambda <- c(3, 2, 1)p <- PSFpoly(4, lambda)( homogeneous <- isHomogeneousQspray(p) ) # should be TRUEattr(homogeneous, "degree") == sum(lambda) # should be TRUEWhether a 'qspray' is a polynomial of some given 'qsprays'
Description
Checks whether aqspray polynomial can be written as a polynomial of some givenqspray polynomials. IfTRUE, this polynomial is returned.
Usage
isPolynomialOf(qspray, qsprays)Arguments
qspray | a |
qsprays | a list of |
Value
A Boolean value indicating whether the polynomial defined byqspray can be written as a polynomial of the polynomials defined by theqspray objects given in theqsprays list. If this isTRUE, this polynomial is returned as an attribute named"polynomial".
Examples
library(qspray)x <- qlone(1); y <- qlone(2); z <- qlone(3)q1 <- x + yq2 <- x*z^2 + 4qspray <- q1^2*q2 + 2*q1 + 3( check <- isPolynomialOf(qspray, list(q1, q2)) )POLYNOMIAL <- attr(check, "polynomial")changeVariables(POLYNOMIAL, list(q1, q2)) == qspray # should be TRUEWhether a 'qspray' polynomial is the unit polynomial
Description
Checks whether aqspray object defines the unit polynomial.
Usage
## S4 method for signature 'qspray'isQone(qspray)Arguments
qspray | a |
Value
A Boolean value.
Whether a 'qspray' polynomial is null
Description
Checks whether aqspray object defines the zero polynomial.
Usage
## S4 method for signature 'qspray'isQzero(qspray)Arguments
qspray | a |
Value
A Boolean value.
Check symmetry of a polynomial
Description
Check whether aqspray polynomial is symmetric.
Usage
isSymmetricQspray(qspray)Arguments
qspray | a |
Value
A Boolean value indicating whether the polynomial defined byqspray is symmetric.
See Also
MSPcombination,compactSymmetricQspray
Examples
e1 <- ESFpoly(3, 1)e2 <- ESFpoly(3, 2)e3 <- ESFpoly(3, 3)q <- e1 + 2*e2 + 3*e3 + 4*e1*e3isSymmetricQspray(q)Whether a 'qspray' is univariate
Description
Checks whether aqspray object defines aunivariate polynomial.
Usage
## S4 method for signature 'qspray'isUnivariate(x)Arguments
x | a |
Value
A Boolean value.
Note
It is considered that a constantqspray is univariate, and that theqspray objecty^2+1 wherey=qlone(2) is not univariate, although only one variable is present (see the note in the documentation ofnumberOfVariables).
Leading coefficient of a 'qspray' polynomial
Description
Returns the leading coefficient of aqspray polynomial.
Usage
leadingCoefficient(qspray)Arguments
qspray | a |
Value
The coefficient of the leading term ofqspray,abigq rational number.
Leading term of a 'qspray' polynomial
Description
Returns the leading term of aqspray polynomial.
Usage
leadingTerm(qspray)Arguments
qspray | a |
Value
A list providing the exponents of the leading term in the fieldpowers, an integer vector, and the coefficient of the leading term in the fieldcoeff, abigq rational number.
Number of terms in a 'qspray' polynomial
Description
Number of terms of the polynomial defined by aqspray object.
Usage
## S4 method for signature 'qspray'numberOfTerms(qspray)Arguments
qspray | a |
Value
An integer.
Number of variables in a 'qspray' polynomial
Description
Number of variables involved in aqspray object (see the note for the precise meaning).
Usage
## S4 method for signature 'qspray'numberOfVariables(x)Arguments
x | a |
Value
An integer.
Note
The number of variables in theqspray objecty^2+1 wherey=qlone(2) is2, not1, although only one variable is present. Strictly speaking, the function returns the maximal integerd such that the variableqlone(d) occurs in the polynomial.
See Also
Ordered 'qspray'
Description
Reorders the terms of aqspray object according to the lexicographic order of the powers. This function is rather used internally only but it is exported for internal usage in other packages.
Usage
orderedQspray(qspray)Arguments
qspray | a |
Value
Aqspray object. It defines the same polynomial as the inputqspray object but it is ordered.
Examples
qspray <- rQspray()qspray == orderedQspray(qspray) # should be TRUEPermute variables
Description
Permute the variables of aqspray polynomial.
Usage
## S4 method for signature 'qspray,numeric'permuteVariables(x, permutation)Arguments
x | a |
permutation | a permutation |
Value
Aqspray object.
Examples
library(qspray)f <- function(x, y, z) { x^2 + 5*y + z - 1}x <- qlone(1)y <- qlone(2)z <- qlone(3)P <- f(x, y, z)permutation <- c(3, 1, 2)Q <- permuteVariables(P, permutation)Q == f(z, x, y) # should be TRUEPretty polynomial
Description
Pretty form of aqspray polynomial.
Usage
prettyQspray(qspray, vars = NULL)Arguments
qspray | a |
vars | variable names; |
Value
A character string.
Examples
library(qspray)P <- (qlone(1) + "1/2"*qlone(2))^2 + 5prettyP <- prettyQspray(P, vars = c("x", "y"))prettyPcat(Ryacas::yac_str(sprintf("PrettyForm(%s)", prettyP)))Ryacas::yac_str(sprintf("TeXForm(%s)", prettyP))Division of a qspray polynomial
Description
Division of a qspray polynomial by a list of qspray polynomials. See the reference for the definition.
Usage
qdivision(qspray, divisors)Arguments
qspray | the dividend, a |
divisors | the divisors, a list of |
Value
The remainder of the division, aqspray object.
References
Michael Weiss, 2010.Computing Gröbner Bases in Python with Buchberger’s Algorithm.
Examples
# a univariate examplelibrary(qspray)x <- qlone(1)f <- x^4 - 4*x^3 + 4*x^2 - x # 0 and 1 are trivial rootsg <- x * (x - 1)qdivision(f, list(g)) # should be zeroPolynomial variable
Description
Creates a polynomial variable. Using this function is the main way to buildqspray objects.
Usage
qlone(n)Arguments
n | positive integer, the index of the variable |
Value
Aqspray object.
Examples
x <- qlone(1)y <- qlone(2)(x + y) * (x - y)The unit 'qspray' polynomial
Description
Returns theqspray polynomial identically equal to 1.
Usage
qone()Value
Aqspray object.
Unary operators for qspray objects
Description
Unary operators for qspray objects.
Usage
## S4 method for signature 'qspray,missing'e1 + e2## S4 method for signature 'qspray,missing'e1 - e2Arguments
e1 | object of class |
e2 | nothing |
Value
Aqspray object.
Division of two polynomials
Description
Division of two polynomials
Usage
qsprayDivision(qsprayA, qsprayB)Arguments
qsprayA | a |
qsprayB | a |
Value
A list with twoqspray objects, the quotient and the remainder.
Examples
library(qspray)x <- qlone(1)y <- qlone(2)z <- qlone(3)B <- x*y^2 + z*x^2 + 1A <- B * (x^2*y^2*z^2 - 3) + x*ydivis <- qsprayDivision(A, B)B * divis[["Q"]] + divis[["R"]] == A # should be TRUEMake a 'qspray' object
Description
Make aqspray object from a list of exponents and a vector of coefficients.
Usage
qsprayMaker(powers, coeffs, string = NULL)Arguments
powers | list of positive integer vectors |
coeffs | a vector such that each element of |
string | if not |
Value
Aqspray object.
Examples
powers <- list(c(1, 1), c(0, 2))coeffs <- c("1/2", "4")qsprayMaker(powers, coeffs)qsprayMaker(string = "1/2 x^(1, 1) + 4 x^(0, 2)")(internal) Make a 'qspray' object from a list
Description
This function is for internal usage. It is exported because it is also used for internal usage in others packages.
Usage
qspray_from_list(qspray_as_list)Arguments
qspray_as_list | list returned by the Rcpp function |
Value
Aqspray object.
The null 'qspray' polynomial
Description
Returns theqspray polynomial identically equal to 0.
Usage
qzero()Value
Aqspray object.
Random 'qspray'
Description
Generates a randomqspray object.
Usage
rQspray()Value
Aqspray object with at most 4 terms and at most 3 variables.
Print a monomial
Description
Prints a monomial like"x^(1, 0, 2)". This way of showing a monomial was used by default in previous versions of this package.
Usage
showMonomialOld(x = "x")Arguments
x | a string, usually a letter such as |
Value
A function which takes as argument a sequence of exponents and which prints the corresponding monomial.
See Also
showMonomialX1X2X3,showMonomialXYZ,showQspray,showQsprayOption<-.
Examples
showMonomialOld("X")(c(1, 0, 2))showMonomialOld("X")(NULL)Print a monomial
Description
Prints a monomial in the style of"x1.x3^2".
Usage
showMonomialX1X2X3(x = "x", collapse = ".")Arguments
x | a string, usually a letter such as |
collapse | a string to denote the symbol representing the multiplication, e.g. |
Value
A function which takes as argument a sequence of exponents and which prints the corresponding monomial.
Note
The function returned by this function can be used as the option"showMonomial" in theshowQsprayOption<- function.But if you are happy with the defaultcollapse argument, then you can equivalently set the"x" option instead, thereby typing less code. See the example.
See Also
showQsprayX1X2X3,showMonomialXYZ,showQsprayOption<-.
Examples
showMonomialX1X2X3("X")(c(1, 0, 2))showMonomialX1X2X3("X", collapse = "*")(c(1, 0, 2))showMonomialX1X2X3("X")(c(1, 0, 2)) == showMonomialXYZ(c("X1", "X2", "X3"))(c(1, 0, 2))showMonomialX1X2X3()(NULL)# setting a show option:set.seed(3141)( qspray <- rQspray() )showQsprayOption(qspray, "showMonomial") <- showMonomialX1X2X3("X")qspray# this is equivalent to:showQsprayOption(qspray, "showQspray") <- showQsprayX1X2X3("X")# and also equivalent to:showQsprayOption(qspray, "x") <- "X"Print a monomial
Description
Prints a monomial like"x.z^2" if possible (see details).
Usage
showMonomialXYZ(letters = c("x", "y", "z"), collapse = ".")Arguments
letters | a vector of strings, usually some letters such as |
collapse | a string to denote the symbol representing the multiplication, e.g. |
Details
If the function returned by this function is applied to a vector of exponents whose length is higher than the length of theletters vector, thenshowMonomialX1X2X3(x=letters[1]) is applied (see the last example).
Value
A function which takes as argument a sequence of exponents and which prints the corresponding monomial.
Note
The function returned by this function can be used as the option"showMonomial" in theshowQsprayOption<- function.
See Also
showQsprayXYZ,showMonomialX1X2X3,showQsprayOption<-.
Examples
showMonomialXYZ()(c(1, 0, 2))showMonomialXYZ(collapse = "*")(c(1, 0, 2))showMonomialXYZ()(NULL)# what happens if there are more exponents than letters:showMonomialXYZ(c("a", "b"), collapse = "*")(c(1, 2, 3))# same as:showMonomialX1X2X3("a", collapse = "*")(c(1, 2, 3))# setting a show option:set.seed(3141)( qspray <- rQspray() )showQsprayOption(qspray, "showMonomial") <- showMonomialXYZ(c("A", "B", "C"))qspray# this is equivalent to:showQsprayOption(qspray, "showQspray") <- showQsprayXYZ(c("A", "B", "C"))Print a 'qspray' object
Description
Prints aqspray object given a function which prints the monomials.
Usage
showQspray(showMonomial, compact = FALSE, multiplication = "*")Arguments
showMonomial | a function which takes as argument a sequence of exponents and which returns a string representing the corresponding monomial |
compact | a Boolean value; if |
multiplication | used to separate the coefficient and the monomial within a term |
Value
A function which prints aqspray object.
Note
The function returned by this function can be used as the option"showQspray" in theshowQsprayOption<- function.But one generally prefers to useshowQsprayX1X2X3 orshowQsprayXYZ instead, which are both built withshowQspray.
See Also
showQsprayX1X2X3,showQsprayXYZ,showQsprayOption<-.
Examples
set.seed(3141)( qspray <- rQspray() )f <- showQspray(showMonomialX1X2X3("X"), compact = TRUE)f(qspray)# this is equivalent to:f <- showQsprayX1X2X3("X", compact = TRUE)f(qspray)# if you want to adopt this way to show a qspray, use # the setter function \code{\link{showQsprayOption<-}}: showQsprayOption(qspray, "showQspray") <- showQsprayX1X2X3("X", compact = TRUE)qspray# then this show option will be preserved by some operations on the qspray:qspray^2Set a show option to a 'qspray' object
Description
Set a show option to aqspray object
Usage
showQsprayOption(x, which) <- valueArguments
x | a |
which | which option to set; this can be |
value | the value of the option |
Value
This returns the updatedqspray.
Note
The interest of setting some show options to a 'qspray' is that these options are preserved by some operations. See the examples and the README.
Examples
set.seed(3141)( qspray <- rQspray() )showQsprayOption(qspray, "x") <- "a"qspray# this is identical to:showQsprayOption(qspray, "showMonomial") <- showMonomialX1X2X3("a")# and also identical to:showQsprayOption(qspray, "showQspray") <- showQsprayX1X2X3("a")# old show method:showQsprayOption(qspray, "showMonomial") <- showMonomialOld()qspray# show options are preserved by some operations:qspray^23*qsprayderivQspray(qspray, 1)swapVariables(qspray, 1, 2)substituteQspray(qspray, c(NA, NA, "3/2"))# for the binary arithmetic operations, the show options of the first # operand are transferred to the result when possible:( qspray2 <- rQspray() )qspray + qspray2Print a 'qspray' object
Description
Prints aqspray object given a string for the variable.
Usage
showQsprayX1X2X3(x = "x", collapse = ".", ...)Arguments
x,collapse | |
... | arguments passed to |
Value
A function which prints aqspray object.
Note
The wayqspray objects are displayed can be controlled with the help of the functionshowQsprayOption<-, andshowQsprayX1X2X3() is a possible option to pass inshowQsprayOption<-.
See Also
showMonomialX1X2X3,showQspray,showQsprayOption<-.
Examples
set.seed(3141)( qspray <- rQspray() )showQsprayX1X2X3("X")(qspray)# setting a show option:showQsprayOption(qspray, "showQspray") <- showQsprayX1X2X3("A")qspray# this is equivalent to:showQsprayOption(qspray, "showMonomial") <- showMonomialX1X2X3("A")# and also equivalent to:showQsprayOption(qspray, "x") <- "A"Print a polynomial
Description
Prints a polynomial by printing monomials like"x^2.yz".
Usage
showQsprayXYZ(letters = c("x", "y", "z"), collapse = ".", ...)Arguments
letters,collapse | |
... | arguments passed to |
Value
A function which prints aqspray object. It is constructed withshowQspray andshowMonomialXYZ.
Note
The function returned by this function can be used as the option"showQspray" in theshowQsprayOption<- function.
See Also
showMonomialXYZ,showQspray,showQsprayOption<-.
Examples
set.seed(3141)( qspray <- rQspray() )showQsprayXYZ(c("X", "Y", "Z"))(qspray)showQsprayXYZ(c("X", "Y", "Z"))(qlone(1) + qlone(2) + qlone(3) + qlone(4))# setting a show option:showQsprayOption(qspray, "showQspray") <- showQsprayXYZ(c("A", "B", "C"))qspray# this is equivalent to:showQsprayOption(qspray, "showMonomial") <- showMonomialXYZ(c("A", "B", "C"))Substitutions in a 'qspray' polynomial
Description
Substitute some variables in aqspray polynomial.
Usage
substituteQspray(qspray, values)Arguments
qspray | a |
values | the values to be substituted; this must be a vector whose length equals the number of variables of |
Value
Aqspray object.
Examples
library(qspray)x <- qlone(1)y <- qlone(2)z <- qlone(3)p <- x^2 + y^2 + x*y*z - 1substituteQspray(p, c("2", NA, "3/2"))Swap variables
Description
Swap two variables in aqspray polynomial.
Usage
## S4 method for signature 'qspray,numeric,numeric'swapVariables(x, i, j)Arguments
x | a |
i,j | indices of the variables to be swapped |
Value
Aqspray object.
Examples
library(qspray)f <- function(x, y, z) { x^2 + 5*y + z - 1}x <- qlone(1)y <- qlone(2)z <- qlone(3)P <- f(x, y, z)Q <- swapVariables(P, 2, 3)Q == f(x, z, y) # should be TRUE