knitr::opts_chunk$set(echo = TRUE)
library(Ryacas)
yacas comes with a number of rules all defined in the yacas directory of the installed package:
system.file(package = "Ryacas", "yacas")
For example in the sums.rep folder, a number of rules for sums are defined in the code.ys file.
As an example, the fact that
[
\sum_{k = 1}^n (2k-1) = n^2
]
is defined in yacas as
SumFunc(_k,1,_n,2*_k-1, n^2 );
and the geometric sum is defined as
SumFunc(_k,0,_n,(r_IsFreeOf(k))^(_k), (1-r^(n+1))/(1-r) );
These can be verified:
yac_str("Sum(i, 1, m, 2*i-1)") yac_str("Sum(i, 0, m, 2^i)")
There are also rules in yacas that are able to let the user change some limits of some sums, e.g. for the geometric sum:
yac_str("Sum(i, 1, m, 2^i)")
But what about changing the limit of the first sum? I.e. instead of
[
\sum_{k = 1}^n (2k-1) = n^2
]
then know that
[
\sum_{k = 0}^n (2k-1) = -1 + \sum_{k = 1}^n (2k-1) = n^2 - 1 .
]
But what does yacas say?
yac_str("Sum(i, 0, m, 2*i-1)")
We can then add our own rule by:
yac_silent("SumFunc(_k,0,_n,2*_k-1, n^2 - 1)")
And then try again:
yac_str("Sum(i, 0, m, 2*i-1)")
A good source of inspiration for writing custom rules is reading the included rules,
but there is a lot to programming in yacas and we refer to yacas's documentation,
specifically the chapter Programming in Yacas.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.