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, InClass, InSet, Set, SetOfAll
from proveit.numbers import one, zero
from proveit.physics.quantum import QubitSpace, normalized_var_ket_psi, var_ket_psi
from proveit.physics.quantum.circuits import qubit_meas
from proveit.statistics import SampleSpaces
In [2]:
# build up the expression from sub-expressions
expr = ExprTuple(Lambda(var_ket_psi, Conditional(InClass(SetOfAll(instance_param_or_params = [b], instance_element = qubit_meas, domain = Set(zero, one)), SampleSpaces), And(InSet(var_ket_psi, QubitSpace), 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(\lvert \psi \rangle \mapsto \left\{\left\{\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi \rangle} & \meter & \qout{\lvert b \rangle}
} \end{array}\right\}_{b \in \left\{0, 1\right\}} \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces} \textrm{ if } \lvert \psi \rangle \in \mathbb{C}^{2} ,  \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
1Lambdaparameter: 51
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9, 10
7Literal
8ExprTuple11, 12
9Operationoperator: 13
operand: 18
10Literal
11Operationoperator: 32
operands: 15
12Operationoperator: 16
operands: 17
13Literal
14ExprTuple18
15ExprTuple51, 19
16Literal
17ExprTuple20, 50
18Lambdaparameter: 56
body: 21
19Operationoperator: 22
operands: 23
20Operationoperator: 24
operand: 51
21Conditionalvalue: 26
condition: 27
22Literal
23ExprTuple28, 29
24Literal
25ExprTuple51
26Operationoperator: 30
operands: 31
27Operationoperator: 32
operands: 33
28Literal
29Literal
30Literal
31ExprTuple34, 35, 36
32Literal
33ExprTuple56, 37
34ExprTuple38
35ExprTuple39
36ExprTuple40
37Operationoperator: 41
operands: 42
38Operationoperator: 43
operands: 44
39Operationoperator: 45
operands: 46
40Operationoperator: 47
operands: 48
41Literal
42ExprTuple49, 50
43Literal
44NamedExprsstate: 51
45Literal
46NamedExprsbasis: 52
47Literal
48NamedExprsstate: 53
49Literal
50Literal
51Variable
52Literal
53Operationoperator: 54
operand: 56
54Literal
55ExprTuple56
56Variable