quil.expression
Errors that may occur while evaluation an Expression
.
Errors that may occur while parsing an Expression
.
The type of Quil expressions.
Quil expressions take advantage of structural sharing; if a Quil expression contains the same
subexpression twice, such as x + y
in (x + y) * (x + y)
, the two children of the *
node
will be the same pointer. This is implemented through interning, also known as
hash-consing; the recursive references to child nodes are done via [ArcIntern<Expression>
]s.
Creating an [ArcIntern
] from an Expression
will always return the same pointer for the same
expression.
The structural sharing means that equality, cloning, and hashing on Quil expressions are all
very cheap, as they do not need to be recursive: equality of [ArcIntern
]s is a single-pointer
comparison, cloning of [ArcIntern
]s is a pointer copy and an atomic increment, and hashing of
[ArcIntern
]s hashes a single pointer. It is also very cheap to key [HashMap
]s by an
[ArcIntern<Expression>
], which can allow for cheap memoization of operations on Expression
s.
The structural sharing also means that Quil expressions are fundamentally immutable; it is
impossible to get an owned or &mut
reference to the child Expression
s of any Expression
,
as the use of interning means there may be multiple references to that Expression
at any time.
Note that when comparing Quil expressions, any embedded NaNs are treated as equal to other NaNs, not unequal, in contravention of the IEEE 754 spec.
If this is a number with imaginary part "equal to" zero (of _small_ absolute value), return that number. Otherwise, error with an evaluation error of a descriptive type.
Return an expression derived from this one, simplified as much as possible.
Evaluate an expression, expecting that it may be fully reduced to a single complex number.
If it cannot be reduced to a complex number, this raises an error.
Substitute an expression in the place of each matching variable.
Parse an Expression
from a string.
Raises a ParseExpressionError
error if the string isn't a valid Quil expression.
Inherited Members
Inherited Members
Inherited Members
Inherited Members
Inherited Members
Inherited Members
Inherited Members
A function defined within Quil syntax.
The type of function call Quil expressions, e.g. sin(e)
.
Quil expressions take advantage of structural sharing, which is why the expression
here is
wrapped in an [ArcIntern
]; for more details, see the documentation for [Expression
].
Note that when comparing Quil expressions, any embedded NaNs are treated as equal to other NaNs, not unequal, in contravention of the IEEE 754 spec.
The type of infix Quil expressions, e.g. e1 + e2
.
Quil expressions take advantage of structural sharing, which is why the left
and right
expressions here are wrapped in [ArcIntern
]s; for more details, see the documentation for
[Expression
].
Note that when comparing Quil expressions, any embedded NaNs are treated as equal to other NaNs, not unequal, in contravention of the IEEE 754 spec.
The type of prefix Quil expressions, e.g. -e
.
Quil expressions take advantage of structural sharing, which is why the expression
here is
wrapped in an [ArcIntern
]; for more details, see the documentation for [Expression
].
Note that when comparing Quil expressions, any embedded NaNs are treated as equal to other NaNs, not unequal, in contravention of the IEEE 754 spec.