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, ExprRange, ExprTuple, IndexedVar, Lambda, U, Variable, t
from proveit.linear_algebra import MatrixMult, ScalarMult
from proveit.logic import And, Equals
from proveit.numbers import Exp, Mult, e, i, one, pi, two
from proveit.physics.quantum import var_ket_u, varphi
from proveit.physics.quantum.circuits import phase_kickback_on_register_circuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = IndexedVar(varphi, sub_expr1)
expr = ExprTuple(Lambda([ExprRange(sub_expr1, sub_expr2, one, t)], Conditional(Equals(Prob(phase_kickback_on_register_circuit), one), And(ExprRange(sub_expr1, Equals(MatrixMult(IndexedVar(U, sub_expr1), var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, sub_expr2)), var_ket_u)), one, t)))))
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(\varphi_{1}, \varphi_{2}, \ldots, \varphi_{t}\right) \mapsto \left\{\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qout{\vdots} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{t}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U_{1}} & \gate{U_{2}} & \gate{\cdots} & \gate{U_{t}} & \qout{\lvert u \rangle}
} \end{array}\right) = 1 \textrm{ if } \left(\left(U_{1} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert u \rangle\right)\right) \land  \left(\left(U_{2} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert u \rangle\right)\right) \land  \ldots \land  \left(\left(U_{t} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{t}} \cdot \lvert u \rangle\right)\right)\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
2ExprTuple4
3Conditionalvalue: 5
condition: 6
4ExprRangelambda_map: 7
start_index: 126
end_index: 125
5Operationoperator: 86
operands: 8
6Operationoperator: 9
operands: 10
7Lambdaparameter: 135
body: 132
8ExprTuple11, 126
9Literal
10ExprTuple12
11Operationoperator: 13
operand: 16
12ExprRangelambda_map: 15
start_index: 126
end_index: 125
13Literal
14ExprTuple16
15Lambdaparameter: 135
body: 17
16Operationoperator: 18
operands: 19
17Operationoperator: 86
operands: 20
18Literal
19ExprTuple21, 22, 23
20ExprTuple24, 25
21ExprTuple26, 27
22ExprRangelambda_map: 28
start_index: 126
end_index: 125
23ExprTuple29, 30
24Operationoperator: 31
operands: 32
25Operationoperator: 104
operands: 33
26ExprRangelambda_map: 34
start_index: 126
end_index: 125
27ExprRangelambda_map: 35
start_index: 126
end_index: 109
28Lambdaparameter: 108
body: 36
29ExprRangelambda_map: 37
start_index: 126
end_index: 125
30ExprRangelambda_map: 38
start_index: 126
end_index: 109
31Literal
32ExprTuple39, 73
33ExprTuple112, 73
34Lambdaparameter: 135
body: 40
35Lambdaparameter: 135
body: 41
36ExprTuple42, 43
37Lambdaparameter: 135
body: 44
38Lambdaparameter: 135
body: 45
39IndexedVarvariable: 99
index: 135
40Operationoperator: 59
operands: 46
41Operationoperator: 84
operands: 47
42ExprRangelambda_map: 48
start_index: 126
end_index: 125
43ExprRangelambda_map: 49
start_index: 126
end_index: 109
44Operationoperator: 64
operands: 50
45Operationoperator: 84
operands: 51
46NamedExprsstate: 52
47NamedExprselement: 53
targets: 70
48Lambdaparameter: 135
body: 54
49Lambdaparameter: 135
body: 55
50NamedExprsstate: 56
51NamedExprselement: 57
targets: 70
52Operationoperator: 119
operand: 66
53Operationoperator: 59
operands: 65
54Operationoperator: 60
operands: 61
55Operationoperator: 84
operands: 62
56Operationoperator: 104
operands: 63
57Operationoperator: 64
operands: 65
58ExprTuple66
59Literal
60Literal
61ExprTuple67, 68
62NamedExprselement: 69
targets: 70
63ExprTuple71, 72
64Literal
65NamedExprsstate: 73
part: 135
66Literal
67Conditionalvalue: 74
condition: 75
68Conditionalvalue: 76
condition: 77
69Operationoperator: 87
operands: 78
70Operationoperator: 79
operands: 80
71Operationoperator: 115
operands: 81
72Operationoperator: 82
operands: 83
73Variable
74Operationoperator: 84
operands: 85
75Operationoperator: 86
operands: 90
76Operationoperator: 87
operands: 88
77Operationoperator: 89
operands: 90
78NamedExprsoperation: 91
part: 135
79Literal
80ExprTuple114, 92
81ExprTuple126, 93
82Literal
83ExprTuple94, 95
84Literal
85NamedExprselement: 96
targets: 97
86Literal
87Literal
88NamedExprsoperation: 98
89Literal
90ExprTuple108, 135
91IndexedVarvariable: 99
index: 108
92Operationoperator: 121
operands: 101
93Operationoperator: 117
operands: 102
94Operationoperator: 119
operand: 111
95Operationoperator: 104
operands: 105
96Literal
97Operationoperator: 106
operand: 114
98Literal
99Variable
100ExprTuple108
101ExprTuple125, 109
102ExprTuple129, 110
103ExprTuple111
104Literal
105ExprTuple112, 113
106Literal
107ExprTuple114
108Variable
109Variable
110Operationoperator: 115
operands: 116
111Literal
112Operationoperator: 117
operands: 118
113Operationoperator: 119
operand: 126
114Operationoperator: 121
operands: 122
115Literal
116ExprTuple126, 129
117Literal
118ExprTuple123, 124
119Literal
120ExprTuple126
121Literal
122ExprTuple125, 126
123Literal
124Operationoperator: 127
operands: 128
125Variable
126Literal
127Literal
128ExprTuple129, 130, 131, 132
129Literal
130Literal
131Literal
132IndexedVarvariable: 133
index: 135
133Variable
134ExprTuple135
135Variable