EvaluatorInstructions

Symbolica documentation for getting started, symbolic expressions, numerical evaluation, pattern matching, and APIs in Python and Rust.

EvaluatorInstructions

EvaluatorInstructions()

A portable instruction stream for evaluating an expression.

Attributes

Name Description
constants Exact constants referenced by ('const', index) slots.
input_count The number of input parameter values expected by this instruction stream.
instructions Return a portable instruction representation for efficiently evaluating the expression
output_count The number of output values produced by this instruction stream.
sub_evaluators Non-inlined function bodies referenced by fun instructions in this stream.
temporary_count The number of temporary storage slots required by instructions.

constants

EvaluatorInstructions.constants: list[Expression]

Exact constants referenced by ('const', index) slots.

input_count

EvaluatorInstructions.input_count: int

The number of input parameter values expected by this instruction stream.

instructions

EvaluatorInstructions.instructions: list[tuple]

Return a portable instruction representation for efficiently evaluating the expression. This can be used to generate code for the expression evaluation in any programming language.

There are four lists that are used in the evaluation instructions:

  • param: the list of input parameters.
  • temp: the list of temporary slots. Its size is available as temporary_count.
  • const: the list of constants.
  • out: the list of outputs.

The instructions are of the form:

  • ('add', ('out', 0), [('const', 1), ('param', 0)], 0) which means out[0] = const[1] + param[0] where the first 0 arguments are real.
  • ('mul', ('out', 0), [('temp', 0), ('param', 0)], 1) which means out[0] = temp[0] * param[0], where the first 1 arguments are real.
  • ('pow', ('out', 0), ('param', 0), -1, true) which means out[0] = param[0]^-1 and the output is real (true).
  • ('powf', ('out', 0), ('param', 0), ('param', 1), false) which means out[0] = param[0]^param[1].
  • ('fun', ('temp', 1), f, ["0"], [('param', 0)], true) which means temp[1] = f(0, param[0]) and the output is real (true).
  • ('if_else', ('temp', 0), 5) which means if temp[0] == 0 goto label 5 (false branch).
  • ('goto', 10) which means goto label 10.
  • ('label', 3) which means label 3.
  • ('join', ('out', 0), ('temp', 0), 3, 7) which means out[0] = (temp[0] != 0) ? label 3 : label 7.

output_count

EvaluatorInstructions.output_count: int

The number of output values produced by this instruction stream.

sub_evaluators

EvaluatorInstructions.sub_evaluators: list[EvaluatorFunction]

Non-inlined function bodies referenced by fun instructions in this stream.

temporary_count

EvaluatorInstructions.temporary_count: int

The number of temporary storage slots required by instructions.

Methods

Name Description
__repr__

__repr__

EvaluatorInstructions.__repr__() -> str