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, U, m
from proveit.linear_algebra import ScalarMult, Unitary
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Exp, Mult, NaturalPos, e, i, one, pi, two
from proveit.physics.quantum import Qmult, m_ket_domain, normalized_var_ket_u, var_ket_u, varphi
from proveit.physics.quantum.circuits import phase_kickback_circuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = Conditional(Forall(instance_param_or_params = [U], instance_expr = Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [varphi], instance_expr = Equals(Prob(phase_kickback_circuit), one), condition = Equals(Qmult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, varphi)), var_ket_u))), domain = m_ket_domain, condition = normalized_var_ket_u), domain = Unitary(Exp(two, m))), InSet(m, NaturalPos))
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\{\forall_{U \in \textrm{U}\left(2^{m}\right)}~\left[\forall_{\lvert u \rangle \in \mathbb{C}^{2^{m}}~|~\left \|\lvert u \rangle\right \| = 1}~\left[\forall_{\varphi~|~\left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)}~\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \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} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U} & \qout{\lvert u \rangle}
} \end{array}\right) = 1\right)\right]\right] \textrm{ if } m \in \mathbb{N}^+\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: 20
operand: 5
2Operationoperator: 29
operands: 4
3ExprTuple5
4ExprTuple124, 6
5Lambdaparameter: 107
body: 8
6Literal
7ExprTuple107
8Conditionalvalue: 9
condition: 10
9Operationoperator: 20
operand: 13
10Operationoperator: 29
operands: 12
11ExprTuple13
12ExprTuple107, 14
13Lambdaparameter: 111
body: 15
14Operationoperator: 16
operand: 47
15Conditionalvalue: 18
condition: 19
16Literal
17ExprTuple47
18Operationoperator: 20
operand: 24
19Operationoperator: 22
operands: 23
20Literal
21ExprTuple24
22Literal
23ExprTuple25, 26
24Lambdaparameter: 139
body: 28
25Operationoperator: 29
operands: 30
26Operationoperator: 37
operands: 31
27ExprTuple139
28Conditionalvalue: 32
condition: 33
29Literal
30ExprTuple111, 34
31ExprTuple35, 133
32Operationoperator: 37
operands: 36
33Operationoperator: 37
operands: 38
34Operationoperator: 39
operands: 40
35Operationoperator: 41
operand: 111
36ExprTuple43, 133
37Literal
38ExprTuple44, 45
39Literal
40ExprTuple46, 47
41Literal
42ExprTuple111
43Operationoperator: 48
operand: 54
44Operationoperator: 50
operands: 51
45Operationoperator: 116
operands: 52
46Literal
47Operationoperator: 127
operands: 53
48Literal
49ExprTuple54
50Literal
51ExprTuple107, 111
52ExprTuple122, 111
53ExprTuple136, 124
54Operationoperator: 55
operands: 56
55Literal
56ExprTuple57, 58, 59
57ExprTuple60, 61
58ExprTuple62, 63
59ExprTuple64, 65
60Operationoperator: 97
operands: 66
61ExprRangelambda_map: 67
start_index: 133
end_index: 72
62Operationoperator: 88
operands: 68
63ExprRangelambda_map: 69
start_index: 133
end_index: 72
64Operationoperator: 103
operands: 70
65ExprRangelambda_map: 71
start_index: 133
end_index: 72
66NamedExprsstate: 73
67Lambdaparameter: 112
body: 74
68NamedExprselement: 75
targets: 76
69Lambdaparameter: 112
body: 77
70NamedExprsstate: 78
71Lambdaparameter: 112
body: 80
72Operationoperator: 118
operands: 81
73Operationoperator: 129
operand: 90
74Operationoperator: 88
operands: 83
75Literal
76Operationoperator: 84
operand: 136
77Operationoperator: 88
operands: 86
78Operationoperator: 116
operands: 87
79ExprTuple112
80Operationoperator: 88
operands: 89
81ExprTuple124, 133
82ExprTuple90
83NamedExprselement: 91
targets: 96
84Literal
85ExprTuple136
86NamedExprselement: 92
targets: 96
87ExprTuple93, 94
88Literal
89NamedExprselement: 95
targets: 96
90Literal
91Operationoperator: 97
operands: 104
92Operationoperator: 98
operands: 99
93Operationoperator: 125
operands: 100
94Operationoperator: 101
operands: 102
95Operationoperator: 103
operands: 104
96Operationoperator: 105
operands: 106
97Literal
98Literal
99NamedExprsoperation: 107
part: 112
100ExprTuple133, 108
101Literal
102ExprTuple109, 110
103Literal
104NamedExprsstate: 111
part: 112
105Literal
106ExprTuple136, 113
107Variable
108Operationoperator: 127
operands: 114
109Operationoperator: 129
operand: 121
110Operationoperator: 116
operands: 117
111Variable
112Variable
113Operationoperator: 118
operands: 119
114ExprTuple136, 120
115ExprTuple121
116Literal
117ExprTuple122, 123
118Literal
119ExprTuple124, 136
120Operationoperator: 125
operands: 126
121Literal
122Operationoperator: 127
operands: 128
123Operationoperator: 129
operand: 133
124Variable
125Literal
126ExprTuple133, 136
127Literal
128ExprTuple131, 132
129Literal
130ExprTuple133
131Literal
132Operationoperator: 134
operands: 135
133Literal
134Literal
135ExprTuple136, 137, 138, 139
136Literal
137Literal
138Literal
139Variable