Skip to content

Commit

Permalink
showSymbolicQsprayABCXYZ
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Apr 22, 2024
1 parent 1cbd3ce commit 16a5311
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 8 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(hasPolynomialCoefficients)
export(numberOfParameters)
export(rSymbolicQspray)
export(showSymbolicQspray)
export(showSymbolicQsprayABCXYZ)
export(showSymbolicQsprayX1X2X3)
export(showSymbolicQsprayXYZ)
export(substituteParameters)
Expand Down
54 changes: 47 additions & 7 deletions R/show.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,23 @@ showSymbolicQspray <- function(
function(powers) {
vapply(powers, showMonomial, character(1L))
}
f <- function(qspray) {
if(isQzero(qspray)) {
showMultipleRatiosOfQsprays <-
attr(showRatioOfQsprays, "showMultipleRatiosOfQsprays") %||%
function(rOQs) {
vapply(rOQs, showRatioOfQsprays, character(1L))
}
f <- function(Qspray) {
if(isQzero(Qspray)) {
return("0")
}
qspray <- orderedQspray(qspray)
monomials <- showMonomials(qspray@powers)
qspray <- orderedQspray(Qspray)
monomials <- showMonomials(Qspray@powers)
coeffs <- paste0(
lbrace,
vapply(qspray@coeffs, showRatioOfQsprays, character(1L)),
showMultipleRatiosOfQsprays(Qspray@coeffs),
rbrace
)
nterms <- numberOfTerms(qspray)
nterms <- numberOfTerms(Qspray)
if(monomials[nterms] == "") {
toPaste <- c(
sprintf("%s%s%s", coeffs[-nterms], multiplication, monomials[-nterms]),
Expand Down Expand Up @@ -151,7 +156,42 @@ showSymbolicQsprayXYZ <- function(
)
}

#' @title Set show option to a 'qspray' object
#' @title Print a 'symbolicQspray' object
#' @description Prints a \code{symbolicQspray} object.
#'
#' @param params vector of strings, usually some letters, to denote the
#' parameters of the polynomial
#' @param vars a vector of strings, usually some letters, to denote the
#' variables of the polynomial
#' @param quotientBar a string for the quotient bar between the numerator and
#' the denominator of a \code{ratioOfQsprays} object, including surrounding
#' spaces, e.g. \code{" / "}
#' @param ... arguments other than \code{showRatioOfQsprays} and
#' \code{showMonomial} passed to \code{\link{showSymbolicQspray}}
#'
#' @return A function which prints \code{symbolicQspray} objects.
#' @export
#' @importFrom ratioOfQsprays showRatioOfQspraysXYZ
#' @importFrom qspray showMonomialXYZ
#'
#' @note This function is built by applying \code{\link{showSymbolicQspray}} to
#' \code{\link[ratioOfQsprays]{showRatioOfQspraysXYZ}(params)} and
#' \code{\link[qspray]{showMonomialXYZ}(vars)}.
#'
#' @examples
#' set.seed(421)
#' ( Qspray <- rSymbolicQspray() )
#' showSymbolicQsprayABCXYZ(c("a", "b", "c"), c("U", "V"))(Qspray)
showSymbolicQsprayABCXYZ <- function(
params, vars = c("X", "Y", "Z"), quotientBar = " %//% ", ...
) {
showSymbolicQspray(
showRatioOfQspraysXYZ(letters = params, quotientBar = quotientBar),
showMonomialXYZ(vars), ...
)
}

#' @title Set a show option to a 'symbolicQspray' object
#' @description Set show option to a \code{symbolicQspray} object
#'
#' @param x a \code{symbolicQspray} object
Expand Down
43 changes: 43 additions & 0 deletions man/showSymbolicQsprayABCXYZ.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/showSymbolicQsprayOption-set.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/testthat/test-show.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,23 @@ test_that("show - univariate", {
"{ [ a1 ] } * X^2 "
)
})

test_that("showRatioOfQspraysXYZ is OK", {
a <- qlone(1)
b <- qlone(2)
X <- Qlone(1)
Q <- a*X + (a+b)*X^2
showSymbolicQsprayOption(Q, "showRatioOfQsprays") <-
showRatioOfQspraysXYZ("a")
expect_identical(
Print(Q),
"{ [ a1 + a2 ] } * X^2 + { [ a1 ] } * X "
)
showSymbolicQsprayOption(Q, "showSymbolicQspray") <-
showSymbolicQsprayABCXYZ("b", "Z")
expect_identical(
Print(Q),
"{ [ b1 + b2 ] } * Z^2 + { [ b1 ] } * Z "
)

})

0 comments on commit 16a5311

Please sign in to comment.