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 Equals, Forall, InSet
from proveit.numbers import Abs, Exp, NaturalPos, two
from proveit.physics.quantum import NumBra, Qmult, 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 Prob
In [2]:
# build up the expression from sub-expressions
expr = Conditional(Forall(instance_param_or_params = [n], instance_expr = Forall(instance_param_or_params = [var_ket_psi], instance_expr = Equals(Prob(register_meas), Exp(Abs(Qmult(NumBra(n, m), var_ket_psi)), two)), domain = m_ket_domain, condition = normalized_var_ket_psi), domain = m_bit_interval), InSet(m, NaturalPos))
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\{\forall_{n \in \{0~\ldotp \ldotp~2^{m} - 1\}}~\left[\forall_{\lvert \psi \rangle \in \mathbb{C}^{2^{m}}~|~\left \|\lvert \psi \rangle\right \| = 1}~\left(\textrm{Pr}\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) = \left|{_{m}}\langle n \rvert \thinspace \lvert \psi \rangle\right|^{2}\right)\right] \textrm{ if } m \in \mathbb{N}^+\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: 11
operand: 5
2Operationoperator: 35
operands: 4
3ExprTuple5
4ExprTuple98, 6
5Lambdaparameter: 97
body: 8
6Literal
7ExprTuple97
8Conditionalvalue: 9
condition: 10
9Operationoperator: 11
operand: 14
10Operationoperator: 35
operands: 13
11Literal
12ExprTuple14
13ExprTuple97, 15
14Lambdaparameter: 91
body: 16
15Operationoperator: 89
operands: 17
16Conditionalvalue: 18
condition: 19
17ExprTuple20, 21
18Operationoperator: 37
operands: 22
19Operationoperator: 23
operands: 24
20Literal
21Operationoperator: 25
operands: 26
22ExprTuple27, 28
23Literal
24ExprTuple29, 30
25Literal
26ExprTuple58, 31
27Operationoperator: 32
operand: 41
28Operationoperator: 64
operands: 34
29Operationoperator: 35
operands: 36
30Operationoperator: 37
operands: 38
31Operationoperator: 39
operand: 94
32Literal
33ExprTuple41
34ExprTuple42, 70
35Literal
36ExprTuple91, 43
37Literal
38ExprTuple44, 94
39Literal
40ExprTuple94
41Operationoperator: 45
operands: 46
42Operationoperator: 47
operand: 56
43Operationoperator: 49
operands: 50
44Operationoperator: 51
operand: 91
45Literal
46ExprTuple53, 54, 55
47Literal
48ExprTuple56
49Literal
50ExprTuple57, 58
51Literal
52ExprTuple91
53ExprTuple59
54ExprTuple60
55ExprTuple61
56Operationoperator: 62
operands: 63
57Literal
58Operationoperator: 64
operands: 65
59ExprRangelambda_map: 66
start_index: 94
end_index: 98
60ExprRangelambda_map: 67
start_index: 94
end_index: 98
61ExprRangelambda_map: 68
start_index: 94
end_index: 98
62Literal
63ExprTuple69, 91
64Literal
65ExprTuple70, 98
66Lambdaparameter: 93
body: 71
67Lambdaparameter: 93
body: 72
68Lambdaparameter: 93
body: 74
69Operationoperator: 75
operands: 96
70Literal
71Operationoperator: 79
operands: 76
72Operationoperator: 77
operands: 78
73ExprTuple93
74Operationoperator: 79
operands: 80
75Literal
76NamedExprselement: 81
targets: 84
77Literal
78NamedExprsbasis: 82
79Literal
80NamedExprselement: 83
targets: 84
81Operationoperator: 85
operands: 86
82Literal
83Operationoperator: 87
operands: 88
84Operationoperator: 89
operands: 90
85Literal
86NamedExprsstate: 91
part: 93
87Literal
88NamedExprsstate: 92
part: 93
89Literal
90ExprTuple94, 98
91Variable
92Operationoperator: 95
operands: 96
93Variable
94Literal
95Literal
96ExprTuple97, 98
97Variable
98Variable