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, m, n
from proveit.logic import And, InClass, InSet, SetOfAll
from proveit.numbers import NaturalPos
from proveit.physics.quantum import m_bit_interval, m_ket_domain, normalized_var_ket_psi, var_ket_psi
from proveit.physics.quantum.circuits import register_meas
from proveit.statistics import SampleSpaces
In [2]:
# build up the expression from sub-expressions
expr = Conditional(InClass(SetOfAll(instance_param_or_params = [n], instance_element = register_meas, domain = m_bit_interval), SampleSpaces), And(InSet(m, NaturalPos), InSet(var_ket_psi, m_ket_domain), normalized_var_ket_psi))
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\{\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}\right\}_{n \in \{0~\ldotp \ldotp~2^{m} - 1\}} \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces} \textrm{ if } m \in \mathbb{N}^+ ,  \lvert \psi \rangle \in \mathbb{C}^{2^{m}} ,  \left \|\lvert \psi \rangle\right \| = 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
5Literal
6ExprTuple9, 10, 11
7Operationoperator: 12
operand: 18
8Literal
9Operationoperator: 33
operands: 14
10Operationoperator: 33
operands: 15
11Operationoperator: 16
operands: 17
12Literal
13ExprTuple18
14ExprTuple83, 19
15ExprTuple76, 20
16Literal
17ExprTuple21, 79
18Lambdaparameter: 82
body: 23
19Literal
20Operationoperator: 24
operands: 25
21Operationoperator: 26
operand: 76
22ExprTuple82
23Conditionalvalue: 28
condition: 29
24Literal
25ExprTuple30, 59
26Literal
27ExprTuple76
28Operationoperator: 31
operands: 32
29Operationoperator: 33
operands: 34
30Literal
31Literal
32ExprTuple35, 36, 37
33Literal
34ExprTuple82, 38
35ExprTuple39
36ExprTuple40
37ExprTuple41
38Operationoperator: 73
operands: 42
39ExprRangelambda_map: 43
start_index: 79
end_index: 83
40ExprRangelambda_map: 44
start_index: 79
end_index: 83
41ExprRangelambda_map: 45
start_index: 79
end_index: 83
42ExprTuple46, 47
43Lambdaparameter: 78
body: 48
44Lambdaparameter: 78
body: 49
45Lambdaparameter: 78
body: 51
46Literal
47Operationoperator: 52
operands: 53
48Operationoperator: 57
operands: 54
49Operationoperator: 55
operands: 56
50ExprTuple78
51Operationoperator: 57
operands: 58
52Literal
53ExprTuple59, 60
54NamedExprselement: 61
targets: 64
55Literal
56NamedExprsbasis: 62
57Literal
58NamedExprselement: 63
targets: 64
59Operationoperator: 65
operands: 66
60Operationoperator: 67
operand: 79
61Operationoperator: 69
operands: 70
62Literal
63Operationoperator: 71
operands: 72
64Operationoperator: 73
operands: 74
65Literal
66ExprTuple75, 83
67Literal
68ExprTuple79
69Literal
70NamedExprsstate: 76
part: 78
71Literal
72NamedExprsstate: 77
part: 78
73Literal
74ExprTuple79, 83
75Literal
76Variable
77Operationoperator: 80
operands: 81
78Variable
79Literal
80Literal
81ExprTuple82, 83
82Variable
83Variable