Expand description
Serializable expression tree for interchange (JSON, etc.). Serializable expression tree for interchange.
ExprTree is a standalone, self-contained representation of a
symbolic expression that can be serialized to JSON (or any serde
format) and deserialized back. It is the primary machine-readable
output format for symplex.
§Round-trip
use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
let expr = &x.powi(2) + &x + 1;
// Serialize to tree
let tree = expr.to_tree();
// Serialize to JSON
let json = serde_json::to_string(&tree).unwrap();
// Deserialize back
let tree2: symplex::tree::ExprTree = serde_json::from_str(&json).unwrap();
// Convert back to Ex in the same context
let expr2 = ctx.from_tree(&tree2);
assert_eq!(format!("{expr}"), format!("{expr2}"));Enums§
- Expr
Tree - A serializable expression tree.