A short summary of often-used yacas commands are found in the section “yacas reference” in the “Getting started” vignette. A short summary of Ryacas’s high-level functions are found in the section “Ryacas high-level reference” at the end of this document.
Start with a base symbol what can either be:
yacas command, e.g. x, 2*a or something similarR matrix or vector.Here, we keep it simple. Consider an R matrix and vector:
## [,1] [,2] [,3] [,4]
## [1,] 1 -2 -3 -4
## [2,] 0 2 -2 -3
## [3,] 1 0 3 -2
## [4,] 2 1 0 4
## [1] 1 2 3 4
They are now considered yacas-enabled:
## {{ 1, -2, -3, -4},
## { 0, 2, -2, -3},
## { 1, 0, 3, -2},
## { 2, 1, 0, 4}}
## [1] {1,2,3,4}
Notice how they are printed using yacas’s syntax.
We can apply yacas functions using y_fn():
## {{ 1, 0, 1, 2},
## {-2, 2, 0, 1},
## {-3, -2, 3, 0},
## {-4, -3, -2, 4}}
## {{ 37/202, 3/101, 41/202, 31/101},
## {(-17)/101, 30/101, 3/101, 7/101},
## {(-19)/202, (-7)/101, 39/202, (-5)/101},
## { (-5)/101, (-9)/101, (-11)/101, 8/101}}
## [1] 10
Standard R commands are available (see the section “Ryacas high-level reference” at the end of this document):
## [,1]
## [1,] -28
## [2,] -14
## [3,] 2
## [4,] 20
## [1] {-28,-14,2,20}
## [,1] [,2] [,3] [,4]
## [1,] 1 0 1 2
## [2,] -2 2 0 1
## [3,] -3 -2 3 0
## [4,] -4 -3 -2 4
## {{ 1, 0, 1, 2},
## {-2, 2, 0, 1},
## {-3, -2, 3, 0},
## {-4, -3, -2, 4}}
## {{ Exp(1), Exp(-2), Exp(-3), Exp(-4)},
## { 1, Exp(2), Exp(-2), Exp(-3)},
## { Exp(1), 1, Exp(3), Exp(-2)},
## { Exp(2), Exp(1), 1, Exp(4)}}
## [,1] [,2] [,3] [,4]
## [1,] 2.718282 0.1353353 0.04978707 0.01831564
## [2,] 1.000000 7.3890561 0.13533528 0.04978707
## [3,] 2.718282 1.0000000 20.08553692 0.13533528
## [4,] 7.389056 2.7182818 1.00000000 54.59815003
## [,1] [,2]
## [1,] -2 -3
## [2,] 2 -2
## [3,] 0 3
## [4,] 1 0
## {{-2, -3},
## { 2, -2},
## { 0, 3},
## { 1, 0}}
## [,1] [,2] [,3] [,4]
## [1,] 1 1 1 1
## [2,] 0 2 1 1
## [3,] 1 0 3 1
## [4,] 2 1 0 4
## {{1, 1, 1, 1},
## {0, 2, 1, 1},
## {1, 0, 3, 1},
## {2, 1, 0, 4}}
## [,1] [,2] [,3] [,4]
## [1,] 1 1 1 1
## [2,] 0 2 1 1
## [3,] 1 0 3 1
## [4,] 2 1 0 4
## {{1, 1, 1, 1},
## {0, 2, 1, 1},
## {1, 0, 3, 1},
## {2, 1, 0, 4}}
## [,1] [,2] [,3] [,4]
## [1,] 1.000000e+00 -1.110223e-16 5.551115e-17 5.551115e-17
## [2,] -1.110223e-16 1.000000e+00 5.551115e-17 5.551115e-17
## [3,] 2.220446e-16 -1.110223e-16 1.000000e+00 0.000000e+00
## [4,] 0.000000e+00 -2.220446e-16 0.000000e+00 1.000000e+00
## {{1, 0, 0, 0},
## {0, 1, 0, 0},
## {0, 0, 1, 0},
## {0, 0, 0, 1}}
## [,1] [,2] [,3] [,4]
## [1,] 3.7040816 -1.2551020 -0.8877551 -0.6224490
## [2,] -1.2551020 0.6938776 0.2346939 0.1530612
## [3,] -0.8877551 0.2346939 0.3367347 0.1326531
## [4,] -0.6224490 0.1530612 0.1326531 0.1734694
## {{ 363/98, (-123)/98, (-87)/98, (-61)/98},
## {(-123)/98, 34/49, 23/98, 15/98},
## { (-87)/98, 23/98, 33/98, 13/98},
## { (-61)/98, 15/98, 13/98, 17/98}}
We can also assign a yacas variable, but remember that this may be difficult to distinguish:
## [1] "W"
## [1] "{j,rformBitwiseOps,I}"
## {{1, 1, 1, 1},
## {0, 2, 1, 1},
## {1, 0, 3, 1},
## {2, 1, 0, 4}}
yac_assign(B, "W") # assign B in R to W in yacas
yac_str("W") # Get variable W if exists, or else just a symbol## [1] "{{1,1,1,1},{0,2,1,1},{1,0,3,1},{2,1,0,4}}"
## [1] "{j,rformBitwiseOps,I,W}"
## [1] "{j,rformBitwiseOps,I}"
## [1] "W"
There are additional functions available:
simplify()tex()To demonstrate these and some additional benefit, we exploit yacas’s symbolic availabilities.
## {{1, 0, 0, 0},
## {0, 1, 0, 0},
## {0, 0, 1, 0},
## {0, 0, 0, 1}}
## {{1/2, 0, 0, 0},
## { 0, 1/2, 0, 0},
## { 0, 0, 1/2, 0},
## { 0, 0, 0, 1/2}}
## {{ 1/2, 0, 0, 0},
## { d, 1/2, 0, 0},
## { d, 0, 1/2, 2*d+2},
## { 0, 0, 0, 1/2}}
## {{ 2, 0, 0, 0},
## { (-4)*d, 2, 0, 0},
## { (-4)*d, 0, 2, (-4)*(2*d+2)},
## { 0, 0, 0, 2}}
## {{ 2, 0, 0, 0},
## { (-4)*d, 2, 0, 0},
## { (-4)*d, 0, 2, (-8)*(d+1)},
## { 0, 0, 0, 2}}
## [1] "\\left( \\begin{array}{cccc} 2 & 0 & 0 & 0 \\\\ -4 d & 2 & 0 & 0 \\\\ -4 d & 0 & 2 & -8 \\left( d + 1\\right) \\\\ 0 & 0 & 0 & 2 \\end{array} \\right) "
\[ \left( \begin{array}{cccc} 2 & 0 & 0 & 0 \\ -4 d & 2 & 0 & 0 \\ -4 d & 0 & 2 & -8 \left( d + 1\right) \\ 0 & 0 & 0 & 2 \end{array} \right) \]
yacas has a Simplify() function. This is made available via a simplify() function that also includes a time-out that prevents yacas in making the R session hang, but it requires that the unix package is available. The default timeout value used when unix is available is 2 seconds.
Ryacas high-level referencePrinciple:
yac_symbol(x) converts x to a yac_symbol that automatically runs yacas when needed. x can both be a text string with yacas commands or an R vector/matrix.as_r(x): Is used to convert the yac_symbol back to an R representation.y_fn(x, fn, ...): Apply a yacas function fn to the yac_symbol x, i.e. fn(x, ...)Reference:
The following functions work with yac_symbols.
yac_*() functions (see the “Getting started” vignette)
yac_str(): Return yacas stringyac_expr(): Return R expressionyac_silent(): Do something silentlyyac_assign(): Assign a variablesimplify(x, timeout = 2): Try yacas’s Simplify() function. When the unix package is available, the timeout (in seconds), stops trying after that amount of time to avoid making the R process hang.tex(): ConvertR that has been implemented for yac_symbols:
print()dim()[ getter[<- setter%*% matrix/vector multiplicationdiag() getterdiag<-() setterupper.tri() getterlower.tri() gettert()solve() (only matrix inverse)+, -, *, /, ^sin(), cos(), tan(), asin(), acos(), atan(), asinh(), acosh(), atanh(), exp(), log(), sqrt()