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 Equals
from proveit.numbers import Exp, Mult, e, i, one, pi, two
from proveit.physics.quantum import Qmult, 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(Equals(Prob(phase_kickback_circuit), one), Equals(Qmult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, varphi)), 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\{\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 \textrm{ if } \left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\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: 4
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 93
4Literal
5ExprTuple7, 8
6Operationoperator: 9
operand: 14
7Operationoperator: 11
operands: 12
8Operationoperator: 76
operands: 13
9Literal
10ExprTuple14
11Literal
12ExprTuple67, 71
13ExprTuple82, 71
14Operationoperator: 15
operands: 16
15Literal
16ExprTuple17, 18, 19
17ExprTuple20, 21
18ExprTuple22, 23
19ExprTuple24, 25
20Operationoperator: 57
operands: 26
21ExprRangelambda_map: 27
start_index: 93
end_index: 32
22Operationoperator: 48
operands: 28
23ExprRangelambda_map: 29
start_index: 93
end_index: 32
24Operationoperator: 63
operands: 30
25ExprRangelambda_map: 31
start_index: 93
end_index: 32
26NamedExprsstate: 33
27Lambdaparameter: 72
body: 34
28NamedExprselement: 35
targets: 36
29Lambdaparameter: 72
body: 37
30NamedExprsstate: 38
31Lambdaparameter: 72
body: 40
32Operationoperator: 78
operands: 41
33Operationoperator: 89
operand: 50
34Operationoperator: 48
operands: 43
35Literal
36Operationoperator: 44
operand: 96
37Operationoperator: 48
operands: 46
38Operationoperator: 76
operands: 47
39ExprTuple72
40Operationoperator: 48
operands: 49
41ExprTuple84, 93
42ExprTuple50
43NamedExprselement: 51
targets: 56
44Literal
45ExprTuple96
46NamedExprselement: 52
targets: 56
47ExprTuple53, 54
48Literal
49NamedExprselement: 55
targets: 56
50Literal
51Operationoperator: 57
operands: 64
52Operationoperator: 58
operands: 59
53Operationoperator: 85
operands: 60
54Operationoperator: 61
operands: 62
55Operationoperator: 63
operands: 64
56Operationoperator: 65
operands: 66
57Literal
58Literal
59NamedExprsoperation: 67
part: 72
60ExprTuple93, 68
61Literal
62ExprTuple69, 70
63Literal
64NamedExprsstate: 71
part: 72
65Literal
66ExprTuple96, 73
67Variable
68Operationoperator: 87
operands: 74
69Operationoperator: 89
operand: 81
70Operationoperator: 76
operands: 77
71Variable
72Variable
73Operationoperator: 78
operands: 79
74ExprTuple96, 80
75ExprTuple81
76Literal
77ExprTuple82, 83
78Literal
79ExprTuple84, 96
80Operationoperator: 85
operands: 86
81Literal
82Operationoperator: 87
operands: 88
83Operationoperator: 89
operand: 93
84Variable
85Literal
86ExprTuple93, 96
87Literal
88ExprTuple91, 92
89Literal
90ExprTuple93
91Literal
92Operationoperator: 94
operands: 95
93Literal
94Literal
95ExprTuple96, 97, 98, 99
96Literal
97Literal
98Literal
99Variable