R interface to ‘Giac’
Giac is a general purpose symbolic algebra software. It powers the graphical interface Xcas. This package allows to execute Giac commands in R. You can find the documentation of Giac here.
remotes::install_github("rstudio/chromote")
remotes::install_github("stla/giacR")The ‘chromote’ package is used to create a Giac session. If the
find_chrome() function of ‘chromote’ returns
NULL, you can set the path to the Chrome executable (or
Chromium, Brave, etc) to the environment variable
CHROMOTE_CHROME. Or you can pass it to the the
Giac$new function. Since the Chrome executable is in my
system path, I can use Sys.which("chrome").
library(giacR)
giac <- Giac$new(Sys.which("chrome"))giac$execute("2 + 3/7")
## [1] "17/7=2.42857142857"giac$execute("gbasis([x^3 - 2*x*y, x^2*y - 2*y^2 + x], [x, y])")
## [1] "[x^2,x*y,2*y^2-x]"giac$execute("integrate(ln(x))")
## [1] "x*ln(x)-x"giac$execute("sum(1/(n^2), n, 1, +(infinity))")
## [1] "1/6*pi^2=1.64493406685"giac$execute("crationalroot(2*x^3 - 3*x^2 + 8*x - 12)")
## [1] "[2*i,3/2,-2*i]"giac$execute(
"apply(simplify, solve([x^2+y+z=1, x+y^2+z=1, x+y+z^2=1], [x, y, z]))"
)
## [1] "list[[0,1,0],[1,0,0],[0,0,1],[sqrt(2)-1,sqrt(2)-1,sqrt(2)-1],[-sqrt(2)-1,-sqrt(2)-1,-sqrt(2)-1]]"giac$execute("det([[1, 2, 3], [3/4, a, b], [c, 4, 5]])")
## [1] "(-6*a*c+10*a+4*b*c-8*b+3)/2"giac$execute("has(x*y + u^2*z, u)")
## [1] "3"giac$execute("has(x*y + u^2*z, w)")
## [1] "0"giac$close()
## [1] TRUE