Version: dev

substitute_in_model

Stable function · Expressions

Tier: stable · Kind: function · Topic: Expressions

JuliaTypeScriptPythonRustGo
not exportedsubstituteInModelsubstitute_in_modelsubstitute_in_modelSubstituteInModel

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, and affect_neg[].rhs;
  • every discrete event’s condition-trigger.expression and affects[].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 into
  • bindings — Variable name to expression mappings
  • context — Optional context for resolving scoped references

Returns

New model with substitutions applied

Source

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 on
  • bindings (dict[str, Expr]) — Dictionary mapping variable names to replacement expressions

Returns

New model (same type as input) with substitutions applied

Source

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).

Source · Rust docs

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.

Source · Go docs