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, b
from proveit.logic import And, Equals, InSet, Set
from proveit.numbers import Abs, Exp, one, two, zero
from proveit.physics.quantum import Bra, Qmult, QubitSpace, normalized_var_ket_psi, var_ket_psi
from proveit.physics.quantum.circuits import qubit_meas
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = ExprTuple(Lambda([var_ket_psi, b], Conditional(Equals(Prob(qubit_meas), Exp(Abs(Qmult(Bra(b), var_ket_psi)), two)), And(InSet(var_ket_psi, QubitSpace), InSet(b, Set(zero, one)), 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(\lvert \psi \rangle, b\right) \mapsto \left\{\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi \rangle} & \meter & \qout{\lvert b \rangle}
} \end{array}\right) = \left|\langle b \rvert \thinspace \lvert \psi \rangle\right|^{2} \textrm{ if } \lvert \psi \rangle \in \mathbb{C}^{2} ,  b \in \left\{0, 1\right\} ,  \left \|\lvert \psi \rangle\right \| = 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
1Lambdaparameters: 2
body: 3
2ExprTuple58, 64
3Conditionalvalue: 4
condition: 5
4Operationoperator: 21
operands: 6
5Operationoperator: 7
operands: 8
6ExprTuple9, 10
7Literal
8ExprTuple11, 12, 13
9Operationoperator: 14
operand: 23
10Operationoperator: 16
operands: 17
11Operationoperator: 19
operands: 18
12Operationoperator: 19
operands: 20
13Operationoperator: 21
operands: 22
14Literal
15ExprTuple23
16Literal
17ExprTuple24, 43
18ExprTuple58, 25
19Literal
20ExprTuple64, 26
21Literal
22ExprTuple27, 45
23Operationoperator: 28
operands: 29
24Operationoperator: 30
operand: 41
25Operationoperator: 32
operands: 33
26Operationoperator: 34
operands: 35
27Operationoperator: 36
operand: 58
28Literal
29ExprTuple38, 39, 40
30Literal
31ExprTuple41
32Literal
33ExprTuple42, 43
34Literal
35ExprTuple44, 45
36Literal
37ExprTuple58
38ExprTuple46
39ExprTuple47
40ExprTuple48
41Operationoperator: 49
operands: 50
42Literal
43Literal
44Literal
45Literal
46Operationoperator: 51
operands: 52
47Operationoperator: 53
operands: 54
48Operationoperator: 55
operands: 56
49Literal
50ExprTuple57, 58
51Literal
52NamedExprsstate: 58
53Literal
54NamedExprsbasis: 59
55Literal
56NamedExprsstate: 60
57Operationoperator: 61
operand: 64
58Variable
59Literal
60Operationoperator: 62
operand: 64
61Literal
62Literal
63ExprTuple64
64Variable