logo

Expression of type ExprTuple

from the theory of proveit.physics.quantum.circuits

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, IndexedVar, U, Variable, m, t
from proveit.logic import Equals, NotEquals, Set
from proveit.numbers import Add, Interval, one
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)
expr = ExprTuple(ExprRange(sub_expr1, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr2, sub_expr1)), Conditional(Gate(operation = I).with_implicit_representation(), NotEquals(sub_expr2, sub_expr1))), one, t).with_case_simplification(), ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = IndexedVar(U, sub_expr2), part = sub_expr1), targets = Interval(sub_expr3, Add(t, m))), one, m))
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 } {_{-}b} = 1 \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } {_{-}b} \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 } {_{-}b} = 2 \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } {_{-}b} \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 } {_{-}b} = t \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } {_{-}b} \neq t\end{array}\right..,\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{{_{-}b}}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{{_{-}b}}~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{{_{-}b}}~\mbox{part}~m~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \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: 46
end_index: 45
2ExprRangelambda_map: 4
start_index: 46
end_index: 41
3Lambdaparameter: 34
body: 5
4Lambdaparameter: 34
body: 7
5Operationoperator: 8
operands: 9
6ExprTuple34
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: 34
20Literal
21ExprTuple42, 30
22Literal
23NamedExprselement: 31
targets: 32
24Literal
25Literal
26NamedExprsoperation: 33
27Literal
28ExprTuple40, 34
29IndexedVarvariable: 35
index: 40
30Operationoperator: 43
operands: 37
31Literal
32Operationoperator: 38
operand: 42
33Literal
34Variable
35Variable
36ExprTuple40
37ExprTuple45, 41
38Literal
39ExprTuple42
40Variable
41Variable
42Operationoperator: 43
operands: 44
43Literal
44ExprTuple45, 46
45Variable
46Literal