logo

Expression of type ExprTuple

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, ExprTuple, Lambda, 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 = ExprTuple(Lambda(t, 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(t \mapsto \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..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameter: 78
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9, 77
7Literal
8ExprTuple78, 10
9Operationoperator: 11
operand: 13
10Literal
11Literal
12ExprTuple13
13Operationoperator: 14
operands: 15
14Literal
15ExprTuple16, 17, 18
16ExprTuple19, 20
17ExprTuple21, 22
18ExprTuple23, 24
19ExprRangelambda_map: 25
start_index: 77
end_index: 78
20ExprRangelambda_map: 26
start_index: 77
end_index: 79
21ExprRangelambda_map: 27
start_index: 77
end_index: 78
22ExprRangelambda_map: 27
start_index: 67
end_index: 68
23ExprRangelambda_map: 28
start_index: 77
end_index: 78
24ExprRangelambda_map: 29
start_index: 77
end_index: 79
25Lambdaparameter: 66
body: 30
26Lambdaparameter: 66
body: 31
27Lambdaparameter: 66
body: 32
28Lambdaparameter: 66
body: 33
29Lambdaparameter: 66
body: 35
30Operationoperator: 52
operands: 36
31Operationoperator: 40
operands: 37
32Operationoperator: 40
operands: 38
33Operationoperator: 40
operands: 39
34ExprTuple66
35Operationoperator: 40
operands: 41
36NamedExprsstate: 42
37NamedExprselement: 43
targets: 49
38NamedExprselement: 44
targets: 45
39NamedExprselement: 46
targets: 47
40Literal
41NamedExprselement: 48
targets: 49
42Operationoperator: 50
operand: 62
43Operationoperator: 52
operands: 59
44Operationoperator: 53
operands: 54
45Operationoperator: 60
operands: 55
46Operationoperator: 58
operands: 56
47Operationoperator: 60
operands: 57
48Operationoperator: 58
operands: 59
49Operationoperator: 60
operands: 61
50Literal
51ExprTuple62
52Literal
53Literal
54NamedExprsoperation: 63
part: 66
55ExprTuple77, 68
56NamedExprsstate: 64
part: 66
57ExprTuple77, 78
58Literal
59NamedExprsstate: 65
part: 66
60Literal
61ExprTuple67, 68
62Literal
63Operationoperator: 69
operands: 70
64Operationoperator: 71
operand: 78
65Literal
66Variable
67Operationoperator: 74
operands: 73
68Operationoperator: 74
operands: 75
69Literal
70ExprTuple76, 78
71Literal
72ExprTuple78
73ExprTuple78, 77
74Literal
75ExprTuple78, 79
76Literal
77Literal
78Variable
79Literal