logo

Expression of type Conditional

from the theory of proveit.physics.quantum.QPE

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, Variable, VertExprArray, t
from proveit.logic import Equals, InSet
from proveit.numbers import Add, Interval, NaturalPos, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE1, _U, _ket_u, _psi_t_ket, _s
from proveit.physics.quantum.circuits import Gate, Input, MultiQubitElem, Output, Qcircuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, one)
sub_expr3 = Add(t, _s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE1(_U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Conditional(Equals(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)], [ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _psi_t_ket, part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)]))), one), InSet(t, 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\{\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}_1\left(U, t\right)} & \multiqout{3}{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \qout{\lvert u \rangle}
} \end{array}\right) = 1 \textrm{ if } t \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: 3
operands: 4
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7, 75
5Literal
6ExprTuple76, 8
7Operationoperator: 9
operand: 11
8Literal
9Literal
10ExprTuple11
11Operationoperator: 12
operands: 13
12Literal
13ExprTuple14, 15, 16
14ExprTuple17, 18
15ExprTuple19, 20
16ExprTuple21, 22
17ExprRangelambda_map: 23
start_index: 75
end_index: 76
18ExprRangelambda_map: 24
start_index: 75
end_index: 77
19ExprRangelambda_map: 25
start_index: 75
end_index: 76
20ExprRangelambda_map: 25
start_index: 65
end_index: 66
21ExprRangelambda_map: 26
start_index: 75
end_index: 76
22ExprRangelambda_map: 27
start_index: 75
end_index: 77
23Lambdaparameter: 64
body: 28
24Lambdaparameter: 64
body: 29
25Lambdaparameter: 64
body: 30
26Lambdaparameter: 64
body: 31
27Lambdaparameter: 64
body: 33
28Operationoperator: 50
operands: 34
29Operationoperator: 38
operands: 35
30Operationoperator: 38
operands: 36
31Operationoperator: 38
operands: 37
32ExprTuple64
33Operationoperator: 38
operands: 39
34NamedExprsstate: 40
35NamedExprselement: 41
targets: 47
36NamedExprselement: 42
targets: 43
37NamedExprselement: 44
targets: 45
38Literal
39NamedExprselement: 46
targets: 47
40Operationoperator: 48
operand: 60
41Operationoperator: 50
operands: 57
42Operationoperator: 51
operands: 52
43Operationoperator: 58
operands: 53
44Operationoperator: 56
operands: 54
45Operationoperator: 58
operands: 55
46Operationoperator: 56
operands: 57
47Operationoperator: 58
operands: 59
48Literal
49ExprTuple60
50Literal
51Literal
52NamedExprsoperation: 61
part: 64
53ExprTuple75, 66
54NamedExprsstate: 62
part: 64
55ExprTuple75, 76
56Literal
57NamedExprsstate: 63
part: 64
58Literal
59ExprTuple65, 66
60Literal
61Operationoperator: 67
operands: 68
62Operationoperator: 69
operand: 76
63Literal
64Variable
65Operationoperator: 72
operands: 71
66Operationoperator: 72
operands: 73
67Literal
68ExprTuple74, 76
69Literal
70ExprTuple76
71ExprTuple76, 75
72Literal
73ExprTuple76, 77
74Literal
75Literal
76Variable
77Literal