# Getting started

#### Mikkel Meyer Andersen and Søren Højsgaard

#### 2019-02-08

    library(Ryacas)

# Introduction

`Ryacas` makes the `yacas` computer algebra system available from within `R`. The name `yacas` is short for “Yet Another Computer Algebra System”. The `yacas` program is developed by Ayal Pinkhuis (who is also the maintainer) and others, and is available at http://www.yacas.org/ for various platforms. There is a comprehensive documentation (300+ pages) of `yacas` (also available at http://www.yacas.org/) and the documentation contains many examples.

# Example 1: using character vectors

    eq <- "x^2 + 4 + 2*x + 2*x"
    yacas(eq)

    ## expression(x^2 + 2 * x + 2 * x + 4)

    yacas(paste0("Simplify(", eq, ")"))

    ## expression(x^2 + 4 * x + 4)

    yacas(paste0("Factor(", eq, ")"))

    ## expression((x + 2)^2)

Or by using the corresponding `R` functions directly:

    Simplify(yacas(eq))

    ## expression(x^2 + 4 * x + 4)

    Factor(yacas(eq))

    ## expression((x + 2)^2)

Or course the result can be saved before calling the helper `R` functions:

    yeq <- yacas(eq)
    Simplify(yeq)

    ## expression(x^2 + 4 * x + 4)

    Factor(yeq)

    ## expression((x + 2)^2)

And getting results out:

    res <- Factor(yeq)
    as.character(res)

    ## [1] "(x + 2)^2"

    TeXForm(res)

    ## [1] "\\left( x + 2\\right)  ^{2}"

To include inline, e.g. \(x ^{2} + 2 x + 2 x + 4 = \left( x + 2\right) ^{2}\).

# Example 2: using `Sym()`

    xs <- Sym("x")
    eqs <- xs^2 + 4 + 2*xs + 2*xs
    Simplify(eqs)

    ## expression(x^2 + 4 * x + 4)

    Factor(eqs)

    ## expression((x + 2)^2)

    res <- Factor(eqs)
    as.character(res)

    ## [1] "(x + 2)^2"

    TeXForm(res)

    ## [1] "\\left( x + 2\\right)  ^{2}"