logo

Expression of type Len

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, Variable, m
from proveit.core_expr_types import Len
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import NumKet, Z
from proveit.physics.quantum.QPE import _ket_u, _s, _s_wire, _t
from proveit.physics.quantum.circuits import Measure, MultiQubitElem, Output
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = Len(operands = [[ExprRange(sub_expr1, Measure(basis = Z), one, _t), _s_wire], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, _t), part = sub_expr1), targets = Interval(one, _t)), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = Interval(Add(_t, one), Add(_t, _s))), one, _s)]])
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(\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array}, ..\left(t - 3\right) \times.., \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, ..\left(s - 3\right) \times.., \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}\right), \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert m \rangle_{t}~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert m \rangle_{t}~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert m \rangle_{t}~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \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{
& & \qout{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array}, \ldots, \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}\right)\right)|
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()()('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3ExprTuple5, 6
4ExprTuple7, 8
5ExprRangelambda_map: 9
start_index: 48
end_index: 49
6ExprRangelambda_map: 10
start_index: 48
end_index: 50
7ExprRangelambda_map: 11
start_index: 48
end_index: 49
8ExprRangelambda_map: 12
start_index: 48
end_index: 50
9Lambdaparameter: 39
body: 13
10Lambdaparameter: 39
body: 14
11Lambdaparameter: 39
body: 15
12Lambdaparameter: 39
body: 17
13Operationoperator: 18
operands: 19
14Operationoperator: 20
operands: 21
15Operationoperator: 23
operands: 22
16ExprTuple39
17Operationoperator: 23
operands: 24
18Literal
19NamedExprsbasis: 25
20Literal
21NamedExprsoperation: 26
22NamedExprselement: 27
targets: 28
23Literal
24NamedExprselement: 29
targets: 30
25Literal
26Literal
27Operationoperator: 33
operands: 31
28Operationoperator: 35
operands: 32
29Operationoperator: 33
operands: 34
30Operationoperator: 35
operands: 36
31NamedExprsstate: 37
part: 39
32ExprTuple48, 49
33Literal
34NamedExprsstate: 38
part: 39
35Literal
36ExprTuple40, 41
37Operationoperator: 42
operands: 43
38Literal
39Variable
40Operationoperator: 45
operands: 44
41Operationoperator: 45
operands: 46
42Literal
43ExprTuple47, 49
44ExprTuple49, 48
45Literal
46ExprTuple49, 50
47Variable
48Literal
49Literal
50Literal