We can think of a variable as a piece of memory in a computer. A variable typically also has a name (also called a symbol). That name/symbol is used to refer to the variable; that is, the name / symbol is a handle on the variable. It is like the difference between you and your name.
There are different ways of creating a variable in
caracas. One is as
which creates a SymPy variable a but provides no handle
on it (no R-symbol). We can get an R-handle on a SymPy variable with
where we do something very confusing: Assign the R-name
a to the SymPy variable b and vice versa. We
can compute on variable b in SymPy by manipulating the
symbol a in R, e.g.
A text representation of a symbol can be found as:
Usually, the best practice is to assign R symbols to SymPy variables of the same name. To avoid confusion, symbol names and Python variable names will always coincide.
In addition to symbol() illustrated above, multiple
R-symbols / Python-variables can be defined using def_sym
and def_sym_vec
With this, R-symbols u, v, w,
x exist and each are connected to Python variables with the
same name
A third way for creating a symbol with as_sym. First
notice:
More interestingly
Above, r is a \(4 \times
1\) matrix, while e.g. u is an atom:
We can coerce between different “classes” (we quote the word because it is not a class system as e.g. those known from R) A text representation of the variables are:
While not often needed that are also lists and vectors in Python. In
caracas they are created by coercion:
The corresponding text representations are:
u |> to_list() |> as.character()
u |> to_vector() |> as.character()
m |> to_list() |> as.character()
m |> to_vector() |> as.character()Likewise:
\[tex(eq)\]