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
from proveit.linear_algebra import 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 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 = [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))), 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\{\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) \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: 7
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7
5Literal
6ExprTuple8, 9
7Lambdaparameter: 122
body: 11
8Operationoperator: 12
operands: 13
9Operationoperator: 20
operands: 14
10ExprTuple122
11Conditionalvalue: 15
condition: 16
12Literal
13ExprTuple94, 17
14ExprTuple18, 116
15Operationoperator: 20
operands: 19
16Operationoperator: 20
operands: 21
17Operationoperator: 22
operands: 23
18Operationoperator: 24
operand: 94
19ExprTuple26, 116
20Literal
21ExprTuple27, 28
22Literal
23ExprTuple29, 30
24Literal
25ExprTuple94
26Operationoperator: 31
operand: 37
27Operationoperator: 33
operands: 34
28Operationoperator: 99
operands: 35
29Literal
30Operationoperator: 110
operands: 36
31Literal
32ExprTuple37
33Literal
34ExprTuple90, 94
35ExprTuple105, 94
36ExprTuple119, 107
37Operationoperator: 38
operands: 39
38Literal
39ExprTuple40, 41, 42
40ExprTuple43, 44
41ExprTuple45, 46
42ExprTuple47, 48
43Operationoperator: 80
operands: 49
44ExprRangelambda_map: 50
start_index: 116
end_index: 55
45Operationoperator: 71
operands: 51
46ExprRangelambda_map: 52
start_index: 116
end_index: 55
47Operationoperator: 86
operands: 53
48ExprRangelambda_map: 54
start_index: 116
end_index: 55
49NamedExprsstate: 56
50Lambdaparameter: 95
body: 57
51NamedExprselement: 58
targets: 59
52Lambdaparameter: 95
body: 60
53NamedExprsstate: 61
54Lambdaparameter: 95
body: 63
55Operationoperator: 101
operands: 64
56Operationoperator: 112
operand: 73
57Operationoperator: 71
operands: 66
58Literal
59Operationoperator: 67
operand: 119
60Operationoperator: 71
operands: 69
61Operationoperator: 99
operands: 70
62ExprTuple95
63Operationoperator: 71
operands: 72
64ExprTuple107, 116
65ExprTuple73
66NamedExprselement: 74
targets: 79
67Literal
68ExprTuple119
69NamedExprselement: 75
targets: 79
70ExprTuple76, 77
71Literal
72NamedExprselement: 78
targets: 79
73Literal
74Operationoperator: 80
operands: 87
75Operationoperator: 81
operands: 82
76Operationoperator: 108
operands: 83
77Operationoperator: 84
operands: 85
78Operationoperator: 86
operands: 87
79Operationoperator: 88
operands: 89
80Literal
81Literal
82NamedExprsoperation: 90
part: 95
83ExprTuple116, 91
84Literal
85ExprTuple92, 93
86Literal
87NamedExprsstate: 94
part: 95
88Literal
89ExprTuple119, 96
90Variable
91Operationoperator: 110
operands: 97
92Operationoperator: 112
operand: 104
93Operationoperator: 99
operands: 100
94Variable
95Variable
96Operationoperator: 101
operands: 102
97ExprTuple119, 103
98ExprTuple104
99Literal
100ExprTuple105, 106
101Literal
102ExprTuple107, 119
103Operationoperator: 108
operands: 109
104Literal
105Operationoperator: 110
operands: 111
106Operationoperator: 112
operand: 116
107Variable
108Literal
109ExprTuple116, 119
110Literal
111ExprTuple114, 115
112Literal
113ExprTuple116
114Literal
115Operationoperator: 117
operands: 118
116Literal
117Literal
118ExprTuple119, 120, 121, 122
119Literal
120Literal
121Literal
122Variable