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, 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 = [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), InSet(U, Unitary(Exp(two, m))))
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_{\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] \textrm{ if } U \in \textrm{U}\left(2^{m}\right)\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: 12
operand: 5
2Operationoperator: 21
operands: 4
3ExprTuple5
4ExprTuple99, 6
5Lambdaparameter: 103
body: 7
6Operationoperator: 8
operand: 39
7Conditionalvalue: 10
condition: 11
8Literal
9ExprTuple39
10Operationoperator: 12
operand: 16
11Operationoperator: 14
operands: 15
12Literal
13ExprTuple16
14Literal
15ExprTuple17, 18
16Lambdaparameter: 131
body: 20
17Operationoperator: 21
operands: 22
18Operationoperator: 29
operands: 23
19ExprTuple131
20Conditionalvalue: 24
condition: 25
21Literal
22ExprTuple103, 26
23ExprTuple27, 125
24Operationoperator: 29
operands: 28
25Operationoperator: 29
operands: 30
26Operationoperator: 31
operands: 32
27Operationoperator: 33
operand: 103
28ExprTuple35, 125
29Literal
30ExprTuple36, 37
31Literal
32ExprTuple38, 39
33Literal
34ExprTuple103
35Operationoperator: 40
operand: 46
36Operationoperator: 42
operands: 43
37Operationoperator: 108
operands: 44
38Literal
39Operationoperator: 119
operands: 45
40Literal
41ExprTuple46
42Literal
43ExprTuple99, 103
44ExprTuple114, 103
45ExprTuple128, 116
46Operationoperator: 47
operands: 48
47Literal
48ExprTuple49, 50, 51
49ExprTuple52, 53
50ExprTuple54, 55
51ExprTuple56, 57
52Operationoperator: 89
operands: 58
53ExprRangelambda_map: 59
start_index: 125
end_index: 64
54Operationoperator: 80
operands: 60
55ExprRangelambda_map: 61
start_index: 125
end_index: 64
56Operationoperator: 95
operands: 62
57ExprRangelambda_map: 63
start_index: 125
end_index: 64
58NamedExprsstate: 65
59Lambdaparameter: 104
body: 66
60NamedExprselement: 67
targets: 68
61Lambdaparameter: 104
body: 69
62NamedExprsstate: 70
63Lambdaparameter: 104
body: 72
64Operationoperator: 110
operands: 73
65Operationoperator: 121
operand: 82
66Operationoperator: 80
operands: 75
67Literal
68Operationoperator: 76
operand: 128
69Operationoperator: 80
operands: 78
70Operationoperator: 108
operands: 79
71ExprTuple104
72Operationoperator: 80
operands: 81
73ExprTuple116, 125
74ExprTuple82
75NamedExprselement: 83
targets: 88
76Literal
77ExprTuple128
78NamedExprselement: 84
targets: 88
79ExprTuple85, 86
80Literal
81NamedExprselement: 87
targets: 88
82Literal
83Operationoperator: 89
operands: 96
84Operationoperator: 90
operands: 91
85Operationoperator: 117
operands: 92
86Operationoperator: 93
operands: 94
87Operationoperator: 95
operands: 96
88Operationoperator: 97
operands: 98
89Literal
90Literal
91NamedExprsoperation: 99
part: 104
92ExprTuple125, 100
93Literal
94ExprTuple101, 102
95Literal
96NamedExprsstate: 103
part: 104
97Literal
98ExprTuple128, 105
99Variable
100Operationoperator: 119
operands: 106
101Operationoperator: 121
operand: 113
102Operationoperator: 108
operands: 109
103Variable
104Variable
105Operationoperator: 110
operands: 111
106ExprTuple128, 112
107ExprTuple113
108Literal
109ExprTuple114, 115
110Literal
111ExprTuple116, 128
112Operationoperator: 117
operands: 118
113Literal
114Operationoperator: 119
operands: 120
115Operationoperator: 121
operand: 125
116Variable
117Literal
118ExprTuple125, 128
119Literal
120ExprTuple123, 124
121Literal
122ExprTuple125
123Literal
124Operationoperator: 126
operands: 127
125Literal
126Literal
127ExprTuple128, 129, 130, 131
128Literal
129Literal
130Literal
131Variable