logo

Expression of type Conditional

from the theory of proveit.physics.quantum.circuits

In [1]:
import proveit
# Automation is not needed when building an expression:
proveit.defaults.automation = False # This will speed things up.
proveit.defaults.inline_pngs = False # Makes files smaller.
%load_expr # Load the stored expression as 'stored_expr'
# import Expression classes needed to build the expression
from proveit import Conditional, n
from proveit.logic import InSet
from proveit.physics.quantum import m_bit_interval
from proveit.physics.quantum.circuits import register_meas
In [2]:
# build up the expression from sub-expressions
expr = Conditional(register_meas, InSet(n, m_bit_interval))
expr:
In [3]:
# check that the built expression is the same as the stored expression
assert expr == stored_expr
assert expr._style_id == stored_expr._style_id
print("Passed sanity check: expr matches stored_expr")
Passed sanity check: expr matches stored_expr
In [4]:
# Show the LaTeX representation of the expression for convenience if you need it.
print(stored_expr.latex())
\left\{\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\multiqin{3}{\lvert \psi \rangle} & \meter & \multiqout{3}{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \meter & \ghostqout{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \measure{\begin{array}{c}:\\ \left(m - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \meter & \ghostqout{\lvert n \rangle_{m}}
} \end{array} \textrm{ if } n \in \{0~\ldotp \ldotp~2^{m} - 1\}\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operands: 4
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7, 8, 9
5Literal
6ExprTuple54, 10
7ExprTuple11
8ExprTuple12
9ExprTuple13
10Operationoperator: 45
operands: 14
11ExprRangelambda_map: 15
start_index: 51
end_index: 55
12ExprRangelambda_map: 16
start_index: 51
end_index: 55
13ExprRangelambda_map: 17
start_index: 51
end_index: 55
14ExprTuple18, 19
15Lambdaparameter: 50
body: 20
16Lambdaparameter: 50
body: 21
17Lambdaparameter: 50
body: 23
18Literal
19Operationoperator: 24
operands: 25
20Operationoperator: 29
operands: 26
21Operationoperator: 27
operands: 28
22ExprTuple50
23Operationoperator: 29
operands: 30
24Literal
25ExprTuple31, 32
26NamedExprselement: 33
targets: 36
27Literal
28NamedExprsbasis: 34
29Literal
30NamedExprselement: 35
targets: 36
31Operationoperator: 37
operands: 38
32Operationoperator: 39
operand: 51
33Operationoperator: 41
operands: 42
34Literal
35Operationoperator: 43
operands: 44
36Operationoperator: 45
operands: 46
37Literal
38ExprTuple47, 55
39Literal
40ExprTuple51
41Literal
42NamedExprsstate: 48
part: 50
43Literal
44NamedExprsstate: 49
part: 50
45Literal
46ExprTuple51, 55
47Literal
48Variable
49Operationoperator: 52
operands: 53
50Variable
51Literal
52Literal
53ExprTuple54, 55
54Variable
55Variable