-
Notifications
You must be signed in to change notification settings - Fork 7
/
yacas-rules.Rmd
executable file
·85 lines (67 loc) · 1.83 KB
/
yacas-rules.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
title: "User-defined yacas rules"
author: "Mikkel Meyer Andersen and Søren Højsgaard"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{User-defined yacas rules}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, message=FALSE}
library(Ryacas)
```
# Included rules
`yacas` comes with a number of rules all defined in the `yacas` directory of the installed package:
```{r}
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:
```{r}
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:
```{r}
yac_str("Sum(i, 1, m, 2^i)")
```
# Custom rules
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?
```{r}
yac_str("Sum(i, 0, m, 2*i-1)")
```
We can then add our own rule by:
```{r}
yac_silent("SumFunc(_k,0,_n,2*_k-1, n^2 - 1)")
```
And then try again:
```{r}
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](https://yacas.readthedocs.io/en/latest/programming_in_yacas/).