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 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 = ExprTuple(Lambda([m, var_ket_psi], 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(m, \lvert \psi \rangle\right) \mapsto \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..\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
2ExprTuple86, 79
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operands: 7
5Operationoperator: 8
operands: 9
6Literal
7ExprTuple10, 11
8Literal
9ExprTuple12, 13, 14
10Operationoperator: 15
operand: 21
11Literal
12Operationoperator: 36
operands: 17
13Operationoperator: 36
operands: 18
14Operationoperator: 19
operands: 20
15Literal
16ExprTuple21
17ExprTuple86, 22
18ExprTuple79, 23
19Literal
20ExprTuple24, 82
21Lambdaparameter: 85
body: 26
22Literal
23Operationoperator: 27
operands: 28
24Operationoperator: 29
operand: 79
25ExprTuple85
26Conditionalvalue: 31
condition: 32
27Literal
28ExprTuple33, 62
29Literal
30ExprTuple79
31Operationoperator: 34
operands: 35
32Operationoperator: 36
operands: 37
33Literal
34Literal
35ExprTuple38, 39, 40
36Literal
37ExprTuple85, 41
38ExprTuple42
39ExprTuple43
40ExprTuple44
41Operationoperator: 76
operands: 45
42ExprRangelambda_map: 46
start_index: 82
end_index: 86
43ExprRangelambda_map: 47
start_index: 82
end_index: 86
44ExprRangelambda_map: 48
start_index: 82
end_index: 86
45ExprTuple49, 50
46Lambdaparameter: 81
body: 51
47Lambdaparameter: 81
body: 52
48Lambdaparameter: 81
body: 54
49Literal
50Operationoperator: 55
operands: 56
51Operationoperator: 60
operands: 57
52Operationoperator: 58
operands: 59
53ExprTuple81
54Operationoperator: 60
operands: 61
55Literal
56ExprTuple62, 63
57NamedExprselement: 64
targets: 67
58Literal
59NamedExprsbasis: 65
60Literal
61NamedExprselement: 66
targets: 67
62Operationoperator: 68
operands: 69
63Operationoperator: 70
operand: 82
64Operationoperator: 72
operands: 73
65Literal
66Operationoperator: 74
operands: 75
67Operationoperator: 76
operands: 77
68Literal
69ExprTuple78, 86
70Literal
71ExprTuple82
72Literal
73NamedExprsstate: 79
part: 81
74Literal
75NamedExprsstate: 80
part: 81
76Literal
77ExprTuple82, 86
78Literal
79Variable
80Operationoperator: 83
operands: 84
81Variable
82Literal
83Literal
84ExprTuple85, 86
85Variable
86Variable