substitute_in_model
Stable function · Expressions
Tier: stable · Kind: function · Topic: Expressions
| Julia | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
| not exported | substituteInModel | substitute_in_model | substitute_in_model | SubstituteInModel |
Julia
Julia does not export this function.
TypeScript
function substituteInModel(model: Model, bindings: Record<string, Expr>, context?: SubstitutionContext): Model
Apply substitution across an ENTIRE model, not just its equations.
The rewritten expression sites are, exhaustively (this is the single write
definition of “a model’s expression sites”; edit.ts’s read-side
forEachModelExpressionSite MUST cover the same set):
- every equation
lhs/rhs; - every observed variable’s
expression; - every continuous event’s
conditions[],affects[].rhs, andaffect_neg[].rhs; - every discrete event’s condition-
trigger.expressionandaffects[].rhs; - recursively, every inline-model subsystem (data loaders and unresolved
{ref}subsystems pass through unchanged).
Event affect lhs values are write-TARGET names (string), not expression
read-sites, and are intentionally left untouched — substitution replaces
references, not assignment targets.
Returns a new model with substitutions applied (immutable).
Parameters
model— Model to substitute intobindings— Variable name to expression mappingscontext— Optional context for resolving scoped references
Returns
New model with substitutions applied
Python
substitute_in_model(model, bindings: dict[str, Expr])
Apply substitutions to all expressions in a model.
Parameters
model— Model object or dict to perform substitutions onbindings(dict[str, Expr]) — Dictionary mapping variable names to replacement expressions
Returns
New model (same type as input) with substitutions applied
Rust
pub fn substitute_in_model(model: &Model, substitutions: &HashMap<String, Expr>) -> Model
Substitute variables in all expressions within a model (equations plus discrete/continuous events; other model fields are cloned unchanged).
Go
func SubstituteInModel(model Model, bindings map[string]Expression) (Model, error)
SubstituteInModel performs substitution across an entire model. It is the scope-free case of SubstituteInModelWithContext (file=nil disables dotted-name resolution), so it delegates rather than duplicating the traversal.