List of symbols in the abstract syntax tree of the expression
Source:R/zzz_CLOSED_FORM.R
CLOSED_FORM-cash-sym.Rd
A list, will be initialized after an instance is built.
Examples
# Constant variable
a <- 1
# Random uniform variable
b <- rand_uniform()
# Define a closed form expression
cf <- closed_form(~3 * (exp(a) + b))
cf
#>
#> ── <CLOSED_FORM object>
#> EXPR = 3 * (exp(a) + b)
#> - b: <RAND_UNIFORM object>
#> [a: 0, b: 1]
# Get the list of symbols
cf$sym
#> $`*`
#> function (e1, e2) .Primitive("*")
#>
#> $`(`
#> .Primitive("(")
#>
#> $`+`
#> function (e1, e2) .Primitive("+")
#>
#> $exp
#> function (x) .Primitive("exp")
#>
#> $a
#> [1] 1
#>
#> $b
#>
#> ── <RAND_UNIFORM object>
#> [a: 0, b: 1]
#>
# Get the list of symbol names
cf$sym_name
#> [[1]]
#> [1] "*"
#>
#> [[2]]
#> [1] "("
#>
#> [[3]]
#> [1] "+"
#>
#> [[4]]
#> [1] "exp"
#>
#> [[5]]
#> [1] "a"
#>
#> [[6]]
#> [1] "b"
#>
# Get the list of symbol types
cf$sym_type
#> $`*`
#> [1] "other"
#>
#> $`(`
#> [1] "other"
#>
#> $`+`
#> [1] "other"
#>
#> $exp
#> [1] "other"
#>
#> $a
#> [1] "other"
#>
#> $b
#> [1] "rand_var or closed_form"
#>
d <- rand_normal()
# Define a closed form expression with another closed form expression
cf2 <- closed_form(~cf + 3 * d)
cf2
#>
#> ── <CLOSED_FORM object>
#> EXPR = cf + 3 * d
#> - cf: <CLOSED_FORM object>
#> EXPR = 3 * (exp(a) + b)
#> - b: <RAND_UNIFORM object>
#> [a: 0, b: 1]
#> - d: <RAND_NORMAL object>
#> [mu: 0, sigma: 1]
# Get the list of symbols, constants are not counted as symbols
cf2$sym
#> $`+`
#> function (e1, e2) .Primitive("+")
#>
#> $cf
#>
#> ── <CLOSED_FORM object>
#> EXPR = 3 * (exp(a) + b)
#> - b: <RAND_UNIFORM object>
#> [a: 0, b: 1]
#>
#> $`*`
#> function (e1, e2) .Primitive("*")
#>
#> $d
#>
#> ── <RAND_NORMAL object>
#> [mu: 0, sigma: 1]
#>
# Get the list of symbol names
cf2$sym_name
#> [[1]]
#> [1] "+"
#>
#> [[2]]
#> [1] "cf"
#>
#> [[3]]
#> [1] "*"
#>
#> [[4]]
#> [1] "d"
#>
# Get the list of symbol types
cf$sym_type
#> $`*`
#> [1] "other"
#>
#> $`(`
#> [1] "other"
#>
#> $`+`
#> [1] "other"
#>
#> $exp
#> [1] "other"
#>
#> $a
#> [1] "other"
#>
#> $b
#> [1] "rand_var or closed_form"
#>