logo

Expression of type VertExprArray

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 ExprRange, Literal, Variable, VertExprArray
from proveit.numbers import Add, Exp, Interval, Mult, one, two
from proveit.physics.quantum import I, NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import QPE
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(Literal("t", theory = "proveit.physics.quantum.QPE"), one)
sub_expr3 = Add(Literal("t", theory = "proveit.physics.quantum.QPE"), Literal("s", theory = "proveit.physics.quantum.QPE"))
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(Literal("U", theory = "proveit.physics.quantum.QPE"), Literal("t", theory = "proveit.physics.quantum.QPE")), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = Literal("|u>", latex_format = r"\lvert u \rangle", theory = "proveit.physics.quantum.QPE"), part = sub_expr1), targets = sub_expr4), one, Literal("s", theory = "proveit.physics.quantum.QPE"))], [ExprRange(sub_expr1, sub_expr5, one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, Literal("s", theory = "proveit.physics.quantum.QPE"))], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(Mult(Exp(two, Literal("t", theory = "proveit.physics.quantum.QPE")), Literal("phase", latex_format = r"\varphi", theory = "proveit.physics.quantum.QPE")), Literal("t", theory = "proveit.physics.quantum.QPE")), part = sub_expr1), targets = Interval(one, Literal("t", theory = "proveit.physics.quantum.QPE"))), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = Literal("|u>", latex_format = r"\lvert u \rangle", theory = "proveit.physics.quantum.QPE"), part = sub_expr1), targets = sub_expr4), one, Literal("s", theory = "proveit.physics.quantum.QPE"))])
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())
\begin{array}{cccc} 
 \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert 2^{t} \cdot \varphi \rangle_{t}~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert 2^{t} \cdot \varphi \rangle_{t}~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array} \\
\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array} & \vdots & \begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array} & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert 2^{t} \cdot \varphi \rangle_{t}~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + 2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array} \\
\vdots & \vdots & \begin{array}{c}:\\ \left(s - 3\right) \times \\:\end{array} & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + s~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array} \\
\end{array}

In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenterwith_justification
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2, 3, 4
1ExprTuple5, 6
2ExprTuple7, 8
3ExprTuple9, 10
4ExprTuple11, 12
5ExprRangelambda_map: 13
start_index: 75
end_index: 84
6ExprRangelambda_map: 14
start_index: 75
end_index: 76
7ExprRangelambda_map: 15
start_index: 75
end_index: 84
8ExprRangelambda_map: 15
start_index: 64
end_index: 65
9ExprRangelambda_map: 16
start_index: 75
end_index: 84
10ExprRangelambda_map: 17
start_index: 75
end_index: 76
11ExprRangelambda_map: 18
start_index: 75
end_index: 84
12ExprRangelambda_map: 19
start_index: 75
end_index: 76
13Lambdaparameter: 63
body: 20
14Lambdaparameter: 63
body: 21
15Lambdaparameter: 63
body: 22
16Lambdaparameter: 63
body: 23
17Lambdaparameter: 63
body: 24
18Lambdaparameter: 63
body: 25
19Lambdaparameter: 63
body: 27
20Operationoperator: 49
operands: 28
21Operationoperator: 35
operands: 29
22Operationoperator: 35
operands: 30
23Operationoperator: 31
operands: 32
24Operationoperator: 50
operands: 33
25Operationoperator: 35
operands: 34
26ExprTuple63
27Operationoperator: 35
operands: 36
28NamedExprsstate: 37
29NamedExprselement: 38
targets: 46
30NamedExprselement: 39
targets: 40
31Literal
32NamedExprsbasis: 41
33NamedExprsoperation: 42
34NamedExprselement: 43
targets: 44
35Literal
36NamedExprselement: 45
targets: 46
37Operationoperator: 47
operand: 59
38Operationoperator: 49
operands: 56
39Operationoperator: 50
operands: 51
40Operationoperator: 57
operands: 52
41Literal
42Literal
43Operationoperator: 55
operands: 53
44Operationoperator: 57
operands: 54
45Operationoperator: 55
operands: 56
46Operationoperator: 57
operands: 58
47Literal
48ExprTuple59
49Literal
50Literal
51NamedExprsoperation: 60
part: 63
52ExprTuple75, 65
53NamedExprsstate: 61
part: 63
54ExprTuple75, 84
55Literal
56NamedExprsstate: 62
part: 63
57Literal
58ExprTuple64, 65
59Literal
60Operationoperator: 66
operands: 67
61Operationoperator: 68
operands: 69
62Literal
63Variable
64Operationoperator: 71
operands: 70
65Operationoperator: 71
operands: 72
66Literal
67ExprTuple73, 84
68Literal
69ExprTuple74, 84
70ExprTuple84, 75
71Literal
72ExprTuple84, 76
73Literal
74Operationoperator: 77
operands: 78
75Literal
76Literal
77Literal
78ExprTuple79, 80
79Operationoperator: 81
operands: 82
80Literal
81Literal
82ExprTuple83, 84
83Literal
84Literal