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, ConditionalSet, ExprRange, ExprTuple, U, Variable, s, t
from proveit.linear_algebra import MatrixExp
from proveit.logic import Equals, NotEquals, Set
from proveit.numbers import Add, Exp, Interval, Neg, one, two
from proveit.physics.quantum import CONTROL, I
from proveit.physics.quantum.circuits import Gate, MultiQubitElem
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr3 = Add(t, one)
sub_expr4 = Add(sub_expr2, t)
expr = ExprTuple(ExprRange(sub_expr1, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr4, sub_expr1)), Conditional(Gate(operation = I).with_implicit_representation(), NotEquals(sub_expr4, sub_expr1))), one, t).with_case_simplification(), ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = MatrixExp(U, Exp(two, Neg(sub_expr2))), part = sub_expr1), targets = Interval(sub_expr3, 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}{ccc}\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \qw 
} \end{array} \textrm{ if } \left({_{-}b} + t\right) = 1 \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } \left({_{-}b} + t\right) \neq 1\end{array}\right.., \left\{\begin{array}{ccc}\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \qw 
} \end{array} \textrm{ if } \left({_{-}b} + t\right) = 2 \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } \left({_{-}b} + t\right) \neq 2\end{array}\right.., \ldots, \left\{\begin{array}{ccc}\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \qw 
} \end{array} \textrm{ if } \left({_{-}b} + t\right) = t \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } \left({_{-}b} + t\right) \neq t\end{array}\right..,\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{-{_{-}b}}}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{-{_{-}b}}}~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{-{_{-}b}}}~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2
1ExprRangelambda_map: 3
start_index: 53
end_index: 52
2ExprRangelambda_map: 4
start_index: 53
end_index: 44
3Lambdaparameter: 35
body: 5
4Lambdaparameter: 35
body: 7
5Operationoperator: 8
operands: 9
6ExprTuple35
7Operationoperator: 22
operands: 10
8Literal
9ExprTuple11, 12
10NamedExprselement: 13
targets: 14
11Conditionalvalue: 15
condition: 16
12Conditionalvalue: 17
condition: 18
13Operationoperator: 25
operands: 19
14Operationoperator: 20
operands: 21
15Operationoperator: 22
operands: 23
16Operationoperator: 24
operands: 28
17Operationoperator: 25
operands: 26
18Operationoperator: 27
operands: 28
19NamedExprsoperation: 29
part: 35
20Literal
21ExprTuple45, 30
22Literal
23NamedExprselement: 31
targets: 32
24Literal
25Literal
26NamedExprsoperation: 33
27Literal
28ExprTuple34, 35
29Operationoperator: 36
operands: 37
30Operationoperator: 48
operands: 38
31Literal
32Operationoperator: 39
operand: 45
33Literal
34Operationoperator: 48
operands: 41
35Variable
36Literal
37ExprTuple42, 43
38ExprTuple52, 44
39Literal
40ExprTuple45
41ExprTuple56, 52
42Variable
43Operationoperator: 46
operands: 47
44Variable
45Operationoperator: 48
operands: 49
46Literal
47ExprTuple50, 51
48Literal
49ExprTuple52, 53
50Literal
51Operationoperator: 54
operand: 56
52Variable
53Literal
54Literal
55ExprTuple56
56Variable