logo

Expression of type Equals

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, t
from proveit.linear_algebra import TensorProd
from proveit.logic import Equals
from proveit.numbers import Add, Interval, Neg, one, two, zero
from proveit.physics.quantum.QPE import _ket_u, _psi_t_ket, _s
from proveit.physics.quantum.circuits import MultiQubitElem, Output
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, _s)
sub_expr3 = Neg(t)
sub_expr4 = TensorProd(_psi_t_ket, _ket_u)
sub_expr5 = Interval(one, sub_expr2)
sub_expr6 = MultiQubitElem(element = Output(state = sub_expr4, part = Add(sub_expr1, t)), targets = sub_expr5)
sub_expr7 = ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr4, part = sub_expr1), targets = sub_expr5), Add(t, one), sub_expr2).with_wrapping_at(2,6)
expr = Equals([MultiQubitElem(element = Output(state = sub_expr4, part = one), targets = sub_expr5), ExprRange(sub_expr1, sub_expr6, Add(sub_expr3, two), zero), sub_expr7], [ExprRange(sub_expr1, sub_expr6, Add(sub_expr3, one), zero), sub_expr7]).with_wrapping_at(2)
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}{c} \begin{array}{l} \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~\left(-t + 2\right) + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~\left(-t + 3\right) + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~0 + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + 2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + s~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}\right) =  \\ \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~\left(-t + 1\right) + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~\left(-t + 2\right) + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~0 + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + 2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + s~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}\right) \end{array} \end{array}
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.()(2)('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',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3ExprTuple5, 6, 8
4ExprTuple7, 8
5Operationoperator: 27
operands: 9
6ExprRangelambda_map: 11
start_index: 10
end_index: 13
7ExprRangelambda_map: 11
start_index: 12
end_index: 13
8ExprRangelambda_map: 14
start_index: 15
end_index: 41
9NamedExprselement: 16
targets: 32
10Operationoperator: 45
operands: 17
11Lambdaparameter: 47
body: 18
12Operationoperator: 45
operands: 19
13Literal
14Lambdaparameter: 47
body: 21
15Operationoperator: 45
operands: 22
16Operationoperator: 34
operands: 23
17ExprTuple26, 24
18Operationoperator: 27
operands: 25
19ExprTuple26, 40
20ExprTuple47
21Operationoperator: 27
operands: 28
22ExprTuple53, 40
23NamedExprsstate: 39
part: 40
24Literal
25NamedExprselement: 29
targets: 32
26Operationoperator: 30
operand: 53
27Literal
28NamedExprselement: 31
targets: 32
29Operationoperator: 34
operands: 33
30Literal
31Operationoperator: 34
operands: 35
32Operationoperator: 36
operands: 37
33NamedExprsstate: 39
part: 38
34Literal
35NamedExprsstate: 39
part: 47
36Literal
37ExprTuple40, 41
38Operationoperator: 45
operands: 42
39Operationoperator: 43
operands: 44
40Literal
41Operationoperator: 45
operands: 46
42ExprTuple47, 53
43Literal
44ExprTuple48, 49
45Literal
46ExprTuple53, 50
47Variable
48Operationoperator: 51
operand: 53
49Literal
50Literal
51Literal
52ExprTuple53
53Variable