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
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}")
expr = 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, IndexedVar(varphi, sub_expr1))), 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\{\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..
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: 81
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 121
4Literal
5ExprTuple7
6Operationoperator: 8
operand: 11
7ExprRangelambda_map: 10
start_index: 121
end_index: 120
8Literal
9ExprTuple11
10Lambdaparameter: 130
body: 12
11Operationoperator: 13
operands: 14
12Operationoperator: 81
operands: 15
13Literal
14ExprTuple16, 17, 18
15ExprTuple19, 20
16ExprTuple21, 22
17ExprRangelambda_map: 23
start_index: 121
end_index: 120
18ExprTuple24, 25
19Operationoperator: 26
operands: 27
20Operationoperator: 99
operands: 28
21ExprRangelambda_map: 29
start_index: 121
end_index: 120
22ExprRangelambda_map: 30
start_index: 121
end_index: 104
23Lambdaparameter: 103
body: 31
24ExprRangelambda_map: 32
start_index: 121
end_index: 120
25ExprRangelambda_map: 33
start_index: 121
end_index: 104
26Literal
27ExprTuple34, 68
28ExprTuple107, 68
29Lambdaparameter: 130
body: 35
30Lambdaparameter: 130
body: 36
31ExprTuple37, 38
32Lambdaparameter: 130
body: 39
33Lambdaparameter: 130
body: 40
34IndexedVarvariable: 94
index: 130
35Operationoperator: 54
operands: 41
36Operationoperator: 79
operands: 42
37ExprRangelambda_map: 43
start_index: 121
end_index: 120
38ExprRangelambda_map: 44
start_index: 121
end_index: 104
39Operationoperator: 59
operands: 45
40Operationoperator: 79
operands: 46
41NamedExprsstate: 47
42NamedExprselement: 48
targets: 65
43Lambdaparameter: 130
body: 49
44Lambdaparameter: 130
body: 50
45NamedExprsstate: 51
46NamedExprselement: 52
targets: 65
47Operationoperator: 114
operand: 61
48Operationoperator: 54
operands: 60
49Operationoperator: 55
operands: 56
50Operationoperator: 79
operands: 57
51Operationoperator: 99
operands: 58
52Operationoperator: 59
operands: 60
53ExprTuple61
54Literal
55Literal
56ExprTuple62, 63
57NamedExprselement: 64
targets: 65
58ExprTuple66, 67
59Literal
60NamedExprsstate: 68
part: 130
61Literal
62Conditionalvalue: 69
condition: 70
63Conditionalvalue: 71
condition: 72
64Operationoperator: 82
operands: 73
65Operationoperator: 74
operands: 75
66Operationoperator: 110
operands: 76
67Operationoperator: 77
operands: 78
68Variable
69Operationoperator: 79
operands: 80
70Operationoperator: 81
operands: 85
71Operationoperator: 82
operands: 83
72Operationoperator: 84
operands: 85
73NamedExprsoperation: 86
part: 130
74Literal
75ExprTuple109, 87
76ExprTuple121, 88
77Literal
78ExprTuple89, 90
79Literal
80NamedExprselement: 91
targets: 92
81Literal
82Literal
83NamedExprsoperation: 93
84Literal
85ExprTuple103, 130
86IndexedVarvariable: 94
index: 103
87Operationoperator: 116
operands: 96
88Operationoperator: 112
operands: 97
89Operationoperator: 114
operand: 106
90Operationoperator: 99
operands: 100
91Literal
92Operationoperator: 101
operand: 109
93Literal
94Variable
95ExprTuple103
96ExprTuple120, 104
97ExprTuple124, 105
98ExprTuple106
99Literal
100ExprTuple107, 108
101Literal
102ExprTuple109
103Variable
104Variable
105Operationoperator: 110
operands: 111
106Literal
107Operationoperator: 112
operands: 113
108Operationoperator: 114
operand: 121
109Operationoperator: 116
operands: 117
110Literal
111ExprTuple121, 124
112Literal
113ExprTuple118, 119
114Literal
115ExprTuple121
116Literal
117ExprTuple120, 121
118Literal
119Operationoperator: 122
operands: 123
120Variable
121Literal
122Literal
123ExprTuple124, 125, 126, 127
124Literal
125Literal
126Literal
127IndexedVarvariable: 128
index: 130
128Variable
129ExprTuple130
130Variable