ArticlePDF Available

Abstract

Ryacas is an R (R Core Team, 2018) package that enables a computer algebra system (CAS) within R via the open source CAS yacas (A. Z. Pinkus & Winitzki, 2002; A. Pinkus, Winnitzky, & Mazur, 2016), which is short for “yet another computer algebra system”. Ryacas includes both a high-level (symbol) interface using R objects like matrices and vectors as well as direct access to the underlying yacas such that the user can use the full yacas system, including for example defining new summation rules.
Ryacas: A computer algebra system in R
Mikkel Meyer Andersen1and Søren Højsgaard1
1Department of Mathematical Sciences, Aalborg University, Denmark
DOI: 10.21105/joss.01763
Software
Review
Repository
Archive
Submitted: 29 July 2019
Published: 09 October 2019
License
Authors of papers retain
copyright and release the work
under a Creative Commons
Attribution 4.0 International
License (CC-BY).
Summary
Ryacas is an R(R Core Team, 2018) package that enables a computer algebra system (CAS)
within Rvia the open source CAS yacas (A. Z. Pinkus & Winitzki, 2002; A. Pinkus, Winnitzky,
& Mazur, 2016), which is short for “yet another computer algebra system”.
Ryacas includes both a high-level (symbol) interface using Robjects like matrices and vectors
as well as direct access to the underlying yacas such that the user can use the full yacas
system, including for example dening new summation rules.
From a statistician’s perspective, Ryacas does provide convenient tools directly in Rlike
• sums,
• limits,
• dierentiation,
• integration,
symbolic matrices and vectors,
simplication, and
outputting in TeX format,
which are helpful in both research and teaching. With Ryacas, these tools are conveniently
available from within Rthrough Ryacas. However, it must be stressed that yacas is nowhere
as powerful as the larger commercial CASs.
yacas is easy to use and extensible so that the user can dene new rules, for example for
simplication or summations. More information about yacas is available at http://www.
yacas.org/.
Ryacas contains a number of vignettes that describe both how to use the high-level interface
directly with Robjects and how to use the underlying yacas system.
Ryacas contains a version of yacas which is bundled into Ryacas using Rcpp (Eddelbuettel
& Balamuta, 2017). This means that Ryacas can be installed like any other R package with
no special installation steps being required.
References
Eddelbuettel, D., & Balamuta, J. J. (2017). Extending Rwith C++: A Brief Introduction to
Rcpp.PeerJ Preprints,5, e3188v1. doi:10.7287/peerj.preprints.3188v1
Pinkus, A. Z., & Winitzki, S. (2002). YACAS: A Do-It-Yourself Symbolic Algebra Environ-
ment. In Proceedings of the joint international conferences on articial intelligence, automated
reasoning, and symbolic computation, AISC ’02/calculemus ’02 (pp. 332–336). London, UK,
UK: Springer-Verlag. doi:10.1007/3-540-45470-5_29
Andersen et al., (2019). Ryacas: A computer algebra system in R. Journal of Open Source Software, 4(42), 1763. https://doi.org/10.21105/
joss.01763
1
Pinkus, A., Winnitzky, S., & Mazur, G. (2016). Yacas - yet another computer algebra system.
Retrieved from https://yacas.readthedocs.io/en/latest/
R Core Team. (2018). R: A language and environment for statistical computing. Vienna,
Austria: R Foundation for Statistical Computing. Retrieved from https://www.R-project.org/
Andersen et al., (2019). Ryacas: A computer algebra system in R. Journal of Open Source Software, 4(42), 1763. https://doi.org/10.21105/
joss.01763
2
... The data used to estimate this model was collected by a European manufacturer of durable consumer goods via a questionnaire circulated by mail, which consisted of the 23 items mentioned above. 1 In total, 411 customer responses were collected. For more details about the setting and the items used, we refer readers to Bliemel et al. [5] and Henseler [22]. ...
... Additionally, the variance of the disturbance term of SQ is fixed to zero to ensure that SQ is fully composed of its dimensions. To ensure the identification of the parameters in the original H-O specification, we 1 The dataset is publicly available and can be downloaded from the following URL: http://www.compositebasedsem.com/chapter12/SQ. xlsx. ...
... To obtain the weights in the H-O specifications, the composite loading matrix can be inverted. For this purpose, software capable of performing symbolic calculations can be employed, such as the open-source R packages Ryacas [1] and calculus [20] or the commercial software Mathematica [51]. Consequently, the weight of TANG to form SQ is the element of the first row and first column of the inverted composite loading matrix. ...
... fstats function allows exploring in details the properties of an admixture graph specified by a graph.params object by deriving a symbolic representation of all the F 2 , F 3 , F 4 and the model equations (see above) using functionalities of the Ryacas package for symbolic computation (Andersen & Højsgaard, 2019). ...
... using functionalities of the Ryacas package(Andersen & Højsgaard, 2019) Note: a,b Objects existing or significantly improved since the first poolfstat version, respectively. ...
Article
Full-text available
By capturing various patterns of the structuring of genetic variation across populations, f ‐statistics have proved highly effective for the inference of demographic history. Such statistics are defined as covariance of SNP allele frequency differences among sets of populations without requiring haplotype information and are hence particularly relevant for the analysis of pooled sequencing (Pool‐Seq) data. We here propose a reinterpretation of the F (and D) parameters in terms of probability of gene identity and derive from this unified definition unbiased estimators for both Pool‐Seq data and standard allele count data obtained from individual genotypes. We implemented these estimators in a new version of the R package poolfstat, which now includes a wide range of inference methods: (i) three‐population test of admixture; (ii) four‐population test of treeness; (iii) F4‐ratio estimation of admixture rates; and (iv) fitting, visualization and (semi‐automatic) construction of admixture graphs. A comprehensive evaluation of the methods implemented in poolfstat on both simulated Pool‐Seq (with various sequencing coverages and error rates) and allele count data confirmed the accuracy of these approaches, even for the most cost‐effective Pool‐Seq design involving relatively low sequencing coverages. We further analyzed a real Pool‐Seq data made of 14 populations of the invasive species Drosophila suzukii which allowed refining both the demographic history of native populations and the invasion routes followed by this emblematic pest. Our new package poolfstat provides the community with a user‐friendly and efficient all‐in‐one tool to unravel complex population genetic histories from large‐size Pool‐Seq or allele count SNP data.
... The goal is to allow readers to "do" and "understand" SEM more deeply. While there are existing packages that can perform symbolic math in R (Andersen & Højsgaard, 2019, 2021 or that integrate SymPy with R for SEM (Cheung, 2020), this demonstration is intended to be more instructional regarding the analytic steps of SEM. Specifically, this presentation outlines the various steps in fitting SEMs along with the accompanying Python and Sympy code so that readers can test and replicate what is presented. ...
... The caracas package [Andersen and Højsgaard, 2021] and the Ryacas package [Andersen and Højsgaard, 2019] enhance the capability of R [R Core Team, 2023] to handle symbolic mathematics. In this paper we will illustrate the use of the caracas package in connection with teaching mathematics and statistics. ...
Preprint
Full-text available
The capability of R to do symbolic mathematics is enhanced by the caracas package. This package uses the Python computer algebra library SymPy as a back-end but caracas is tightly integrated in the R environment, thereby enabling the R user with symbolic mathematics within R. We demonstrate how mathematics and statistics can benefit from bridging computer algebra and data via R. This is done thought a number of examples and we propose some topics for small student projects. The caracas package integrates well with e.g. Rmarkdown, and as such creation of scientific reports and teaching is supported.
... The capability of R [R Core Team, 2021] to handle symbolic mathematics is greatly enhanced by two packages: The caracas package, which is the main topic of this paper, and the Ryacas package described in Andersen and Højsgaard [2019]. The caracas package is based on interfacing the Python library SymPy [Meurer et al., 2017], using the reticulate package, [Ushey et al., 2020]. ...
Preprint
Full-text available
The capability of R to do symbolic mathematics is enhanced by the caracas package. This package uses the Python computer algebra library SymPy as a back-end but caracas is tightly integrated in the R environment, thereby enabling the R user with symbolic mathematics within R. Key components of the caracas package are illustrated in this paper. Examples are taken from statistics and mathematics. The caracas package integrates well with e.g. Rmarkdown, and as such creation of scientific reports and teaching is supported.
Article
Background: Accurately estimating baseline kidney function is essential for diagnosing acute kidney injury (AKI) in patients with chronic kidney disease (CKD). We developed and evaluated novel equations to estimate baseline creatinine in patients with AKI on CKD. Methods: We retrospectively analysed 5649 adults with AKI out of 11 254 CKD patients, dividing them evenly into derivation and validation groups. Using quantiles regression, we created equations to estimate baseline creatinine, considering historical creatinine values, months since measurement, age, and sex from the derivation dataset. We assessed performance against back-estimation equations and unadjusted historical creatinine values using the validation dataset. Results: The optimal equation adjusted the most recent creatinine value for time since measurement and sex. Estimates closely matched the actual baseline at AKI onset, with median (95% confidence interval) differences of just 0.9% (-0.8% to 2.1%) and 0.6% (-1.6% to 3.9%) when the most recent value was within 6 months to 30 days and 2 years to 6 months before AKI onset, respectively. The equation improved AKI event reclassification by an additional 2.5% (2.0% to 3.0%) compared to the unadjusted most recent creatinine value and 7.3% (6.2% to 8.4%) compared to the CKD-EPI 2021 back-estimation equation. Conclusion: Creatinine levels drift in patients with CKD, causing false positives in AKI detection without adjustment. Our novel equation adjusts the most recent creatinine value for drift over time. It provides more accurate baseline creatinine estimation in patients with suspected AKI on CKD, which reduces false-positive AKI detection, improving patient care and management.
Article
Full-text available
The R package calculus implements C++-optimized functions for numerical and symbolic calculus, such as the Einstein summing convention, fast computation of the Levi-Civita symbol and generalized Kronecker delta, Taylor series expansion, multivariate Hermite polynomials, high-order derivatives, ordinary differential equations, differential operators and numerical integration in arbitrary orthogonal coordinate systems. The library applies numerical methods when working with functions, or symbolic programming when working with characters or expressions. The package handles multivariate numerical calculus in arbitrary dimensions and coordinates. It implements the symbolic counterpart of the numerical methods whenever possible, without depending on external computer algebra systems. Except for Rcpp, the package has no strict dependencies in order to provide a stable self-contained toolbox that invites re-use.
Preprint
Full-text available
The R package calculus implements C++ optimized functions for numerical and symbolic calculus, such as the Einstein summing convention, fast computation of the Levi-Civita symbol and generalized Kronecker delta, Taylor series expansion, multivariate Hermite polynomials, high-order derivatives, ordinary differential equations, differential operators and numerical integration in arbitrary orthogonal coordinate systems. The library applies numerical methods when working with R functions or symbolic programming when working with characters or expressions. The package handles multivariate numerical calculus in arbitrary dimensions and coordinates and implements the symbolic counterpart of the numerical methods whenever possible, without depending on external computer algebra systems. Except for Rcpp, the package has no strict dependencies in order to provide a stable self-contained toolbox that invites re-use.
Preprint
Full-text available
R has always provided an application programming interface (API) for extensions. Based on the C language, it uses a number of macros and other low-level constructs to exchange data structures between the R process and any dynamically-loaded component modules authors added to it. With the introduction of the Rcpp package, and its later refinements, this process has become considerably easier yet also more robust. By now, Rcpp has become the most popular extension mechanism for R . This article introduces Rcpp , and illustrates with several examples how the Rcpp Attributes mechanism in particular eases the transition of objects between R and C++ code.
Conference Paper
We describe the design and implementation of YACAS, a free computer algebra system under development. The system consists of a core interpreter and a library of scripts that implement symbolic algebra functionality. The interpreter provides a high-level weakly typed functional language designed for quick prototyping of computer algebra algorithms, but the language is suitable for all kinds of symbolic manipulation. It supports conditional term rewriting of symbolic expression trees, closures (pure functions) and delayed evaluation, dynamic creation of transformation rules, arbitrary-precision numerical calculations, and flexible user-defined syntax using infix notation. The library of scripts currently provides basic numerical and symbolic functionality. The main advantages of YACAS are: free (GPL) software; a flexible and easy-to-use programming language with a comfortable and adjustable syntax; cross-platform portability and small resource requirements; and extensibility
Yacas - Yet another computer algebra system
  • Ayal Pinkus
  • Serge Winnitzky
  • Grzegorz Mazur
R: A language and environment for statistical computing
  • A Pinkus
  • S Winnitzky
  • G Mazur
Pinkus, A., Winnitzky, S., & Mazur, G. (2016). Yacas -yet another computer algebra system. Retrieved from https://yacas.readthedocs.io/en/latest/ R Core Team. (2018). R: A language and environment for statistical computing. Vienna, Austria: R Foundation for Statistical Computing. Retrieved from https://www.R-project.org/