logo

Expression of type ExprTuple

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, ExprTuple, Lambda, m, n
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Abs, Exp, 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 = ExprTuple(Lambda(n, Conditional(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), 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(n \mapsto \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) \textrm{ if } n \in \{0~\ldotp \ldotp~2^{m} - 1\}\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameter: 92
body: 3
2ExprTuple92
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operand: 9
5Operationoperator: 30
operands: 8
6Literal
7ExprTuple9
8ExprTuple92, 10
9Lambdaparameter: 86
body: 11
10Operationoperator: 84
operands: 12
11Conditionalvalue: 13
condition: 14
12ExprTuple15, 16
13Operationoperator: 32
operands: 17
14Operationoperator: 18
operands: 19
15Literal
16Operationoperator: 20
operands: 21
17ExprTuple22, 23
18Literal
19ExprTuple24, 25
20Literal
21ExprTuple53, 26
22Operationoperator: 27
operand: 36
23Operationoperator: 59
operands: 29
24Operationoperator: 30
operands: 31
25Operationoperator: 32
operands: 33
26Operationoperator: 34
operand: 89
27Literal
28ExprTuple36
29ExprTuple37, 65
30Literal
31ExprTuple86, 38
32Literal
33ExprTuple39, 89
34Literal
35ExprTuple89
36Operationoperator: 40
operands: 41
37Operationoperator: 42
operand: 51
38Operationoperator: 44
operands: 45
39Operationoperator: 46
operand: 86
40Literal
41ExprTuple48, 49, 50
42Literal
43ExprTuple51
44Literal
45ExprTuple52, 53
46Literal
47ExprTuple86
48ExprTuple54
49ExprTuple55
50ExprTuple56
51Operationoperator: 57
operands: 58
52Literal
53Operationoperator: 59
operands: 60
54ExprRangelambda_map: 61
start_index: 89
end_index: 93
55ExprRangelambda_map: 62
start_index: 89
end_index: 93
56ExprRangelambda_map: 63
start_index: 89
end_index: 93
57Literal
58ExprTuple64, 86
59Literal
60ExprTuple65, 93
61Lambdaparameter: 88
body: 66
62Lambdaparameter: 88
body: 67
63Lambdaparameter: 88
body: 69
64Operationoperator: 70
operands: 91
65Literal
66Operationoperator: 74
operands: 71
67Operationoperator: 72
operands: 73
68ExprTuple88
69Operationoperator: 74
operands: 75
70Literal
71NamedExprselement: 76
targets: 79
72Literal
73NamedExprsbasis: 77
74Literal
75NamedExprselement: 78
targets: 79
76Operationoperator: 80
operands: 81
77Literal
78Operationoperator: 82
operands: 83
79Operationoperator: 84
operands: 85
80Literal
81NamedExprsstate: 86
part: 88
82Literal
83NamedExprsstate: 87
part: 88
84Literal
85ExprTuple89, 93
86Variable
87Operationoperator: 90
operands: 91
88Variable
89Literal
90Literal
91ExprTuple92, 93
92Variable
93Variable