Data and Math
vsymbolic
Expression trees you can differentiate and simplify, symbol by symbol.
Released v1.0.0 · 2026-09-28use "stdlib/symbolic.ven"
Symbolic algebra: building an expression as a tree of values and operations, differentiating it symbolically, and simplifying it algebraically, built on Venutian's own trigonometry, exponential and logarithm builtins together with maps and shapes. It manipulates an expression as data, rather than only evaluating it to a number.
x = sym_var("x")
print x.kind
Reference (20 functions)
API reference
expr_new(kind, value, name, left, right, arg, exponent)
sym_to_text(expr_new("const", 7.0, "", nothing, nothing, nothing, 0.0))sym_const(v)
sym_to_text(sym_const(5.0))sym_var(name)
sym_var("x").kindsym_coerce(value)
Coerces a plain Number into a constant Expr, passing an existing Expr through unchanged.
sym_to_text(sym_coerce(9.0))sym_add(a, b)
sym_to_text(sym_add(sym_var("x"), 3.0))sym_sub(a, b)
sym_to_text(sym_sub(sym_var("x"), 3.0))sym_mul(a, b)
sym_to_text(sym_mul(sym_var("x"), 2.0))sym_div(a, b)
sym_to_text(sym_div(sym_var("x"), 2.0))sym_pow(a, n)
sym_to_text(sym_pow(sym_var("x"), 3.0))sym_neg(a)
sym_to_text(sym_neg(sym_var("x")))sym_sin(a)
sym_to_text(sym_sin(sym_var("x")))sym_cos(a)
sym_to_text(sym_cos(sym_var("x")))sym_exp(a)
sym_to_text(sym_exp(sym_var("x")))sym_ln(a)
sym_to_text(sym_ln(sym_var("x")))bindings_of(var_name, v)
Builds a single-variable bindings Map for sym_evaluate.
map_get(bindings_of("x", 2.5), "x")sym_evaluate(expr, bindings)
sym_evaluate(sym_pow(sym_var("x"), 2.0), bindings_of("x", 4.0))sym_differentiate(expr, var_name)
Symbolically differentiates expr with respect to var_name, returning a new Expr.
sym_to_text(sym_simplify(sym_differentiate(sym_pow(sym_var("x"), 2.0), "x")))sym_simplify_once(expr)
Runs one bottom-up simplification pass over expr, returning a new, possibly-smaller Expr.
sym_to_text(sym_simplify_once(sym_add(sym_const(1.0), sym_const(2.0))))sym_simplify(expr)
sym_to_text(sym_simplify(sym_neg(sym_neg(sym_var("x")))))sym_to_text(expr)
Renders expr as a fully-parenthesized Text expression.
sym_to_text(sym_add(sym_var("x"), 3.0))