Qx.Export.OpenQASM.Expr (Qx - Quantum Computing Simulator v0.6.0)

View Source

Evaluator for OpenQASM parameter expressions.

Handles numeric literals, the pi constant, the four arithmetic operators, unary minus, and the function set sin, cos, tan, exp, ln, sqrt.

Identifier references are resolved against an env map, used when evaluating bodies of gate definitions whose parameter names are bound to caller-supplied values. For top-level gate_call parameters the env is empty — any identifier reference there raises Qx.QasmParseError.

Function names are matched against a literal whitelist; unknown names raise Qx.QasmUnsupportedError. Per Iron Law 1, no String.to_atom/1 on caller-supplied identifiers.

Summary

Functions

Evaluates an expression AST node to a float.

Types

env()

@type env() :: %{optional(String.t()) => float()}

expr()

@type expr() :: tuple()

Functions

eval(expr, env \\ %{})

@spec eval(expr(), env()) :: float()

Evaluates an expression AST node to a float.