logo

Expression of type Conditional

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, IndexedVar, U, Variable, t
from proveit.linear_algebra import MatrixMult, ScalarMult
from proveit.logic import And, Equals, Forall, InSet
from proveit.numbers import Exp, Mult, e, i, one, pi, two
from proveit.physics.quantum import m_ket_domain, normalized_var_ket_u, 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 = Conditional(Forall(instance_param_or_params = [ExprRange(sub_expr1, sub_expr2, one, t)], instance_expr = Equals(Prob(phase_kickback_on_register_circuit), one), condition = 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)).with_wrapping(), And(InSet(var_ket_u, m_ket_domain), normalized_var_ket_u))
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\{\begin{array}{l}\forall_{\varphi_{1}, \varphi_{2}, \ldots, \varphi_{t}~|~\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), \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), \ldots, \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)}~\\
\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\right)\end{array} \textrm{ if } \lvert u \rangle \in \mathbb{C}^{2^{m}} ,  \left \|\lvert u \rangle\right \| = 1\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operand: 6
2Operationoperator: 21
operands: 5
3Literal
4ExprTuple6
5ExprTuple7, 8
6Lambdaparameters: 9
body: 10
7Operationoperator: 11
operands: 12
8Operationoperator: 105
operands: 13
9ExprTuple14
10Conditionalvalue: 15
condition: 16
11Literal
12ExprTuple92, 17
13ExprTuple18, 145
14ExprRangelambda_map: 19
start_index: 145
end_index: 144
15Operationoperator: 105
operands: 20
16Operationoperator: 21
operands: 22
17Operationoperator: 23
operands: 24
18Operationoperator: 25
operand: 92
19Lambdaparameter: 154
body: 151
20ExprTuple27, 145
21Literal
22ExprTuple28
23Literal
24ExprTuple29, 30
25Literal
26ExprTuple92
27Operationoperator: 31
operand: 35
28ExprRangelambda_map: 33
start_index: 145
end_index: 144
29Literal
30Operationoperator: 136
operands: 34
31Literal
32ExprTuple35
33Lambdaparameter: 154
body: 36
34ExprTuple148, 128
35Operationoperator: 37
operands: 38
36Operationoperator: 105
operands: 39
37Literal
38ExprTuple40, 41, 42
39ExprTuple43, 44
40ExprTuple45, 46
41ExprRangelambda_map: 47
start_index: 145
end_index: 144
42ExprTuple48, 49
43Operationoperator: 50
operands: 51
44Operationoperator: 123
operands: 52
45ExprRangelambda_map: 53
start_index: 145
end_index: 144
46ExprRangelambda_map: 54
start_index: 145
end_index: 128
47Lambdaparameter: 127
body: 55
48ExprRangelambda_map: 56
start_index: 145
end_index: 144
49ExprRangelambda_map: 57
start_index: 145
end_index: 128
50Literal
51ExprTuple58, 92
52ExprTuple131, 92
53Lambdaparameter: 154
body: 59
54Lambdaparameter: 154
body: 60
55ExprTuple61, 62
56Lambdaparameter: 154
body: 63
57Lambdaparameter: 154
body: 64
58IndexedVarvariable: 118
index: 154
59Operationoperator: 78
operands: 65
60Operationoperator: 103
operands: 66
61ExprRangelambda_map: 67
start_index: 145
end_index: 144
62ExprRangelambda_map: 68
start_index: 145
end_index: 128
63Operationoperator: 83
operands: 69
64Operationoperator: 103
operands: 70
65NamedExprsstate: 71
66NamedExprselement: 72
targets: 89
67Lambdaparameter: 154
body: 73
68Lambdaparameter: 154
body: 74
69NamedExprsstate: 75
70NamedExprselement: 76
targets: 89
71Operationoperator: 138
operand: 85
72Operationoperator: 78
operands: 84
73Operationoperator: 79
operands: 80
74Operationoperator: 103
operands: 81
75Operationoperator: 123
operands: 82
76Operationoperator: 83
operands: 84
77ExprTuple85
78Literal
79Literal
80ExprTuple86, 87
81NamedExprselement: 88
targets: 89
82ExprTuple90, 91
83Literal
84NamedExprsstate: 92
part: 154
85Literal
86Conditionalvalue: 93
condition: 94
87Conditionalvalue: 95
condition: 96
88Operationoperator: 106
operands: 97
89Operationoperator: 98
operands: 99
90Operationoperator: 134
operands: 100
91Operationoperator: 101
operands: 102
92Variable
93Operationoperator: 103
operands: 104
94Operationoperator: 105
operands: 109
95Operationoperator: 106
operands: 107
96Operationoperator: 108
operands: 109
97NamedExprsoperation: 110
part: 154
98Literal
99ExprTuple133, 111
100ExprTuple145, 112
101Literal
102ExprTuple113, 114
103Literal
104NamedExprselement: 115
targets: 116
105Literal
106Literal
107NamedExprsoperation: 117
108Literal
109ExprTuple127, 154
110IndexedVarvariable: 118
index: 127
111Operationoperator: 140
operands: 120
112Operationoperator: 136
operands: 121
113Operationoperator: 138
operand: 130
114Operationoperator: 123
operands: 124
115Literal
116Operationoperator: 125
operand: 133
117Literal
118Variable
119ExprTuple127
120ExprTuple144, 128
121ExprTuple148, 129
122ExprTuple130
123Literal
124ExprTuple131, 132
125Literal
126ExprTuple133
127Variable
128Variable
129Operationoperator: 134
operands: 135
130Literal
131Operationoperator: 136
operands: 137
132Operationoperator: 138
operand: 145
133Operationoperator: 140
operands: 141
134Literal
135ExprTuple145, 148
136Literal
137ExprTuple142, 143
138Literal
139ExprTuple145
140Literal
141ExprTuple144, 145
142Literal
143Operationoperator: 146
operands: 147
144Variable
145Literal
146Literal
147ExprTuple148, 149, 150, 151
148Literal
149Literal
150Literal
151IndexedVarvariable: 152
index: 154
152Variable
153ExprTuple154
154Variable