logo

Expression of type Conditional

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 A, Conditional, ExprRange, IndexedVar, N, Variable, VertExprArray, m, n
from proveit.core_expr_types import A_1_to_m
from proveit.linear_algebra import TensorProd
from proveit.logic import And, InSet
from proveit.numbers import Add, Interval, Natural, one, subtract, zero
from proveit.physics.quantum.circuits import Input, MultiQubitElem, N_m, Qcircuit, QcircuitEquiv, each_Nk_is_partial_sum
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr2 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr3 = Variable("_c", latex_format = r"{_{-}c}")
expr = Conditional(QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, ExprRange(sub_expr2, MultiQubitElem(element = Input(state = IndexedVar(A, sub_expr1), part = sub_expr2), targets = Interval(Add(IndexedVar(N, subtract(sub_expr1, one)), one), IndexedVar(N, sub_expr1))), one, IndexedVar(n, sub_expr1)).with_wrapping_at(2,6), one, m)])), Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr3, ExprRange(sub_expr1, MultiQubitElem(element = Input(state = TensorProd(A_1_to_m), part = sub_expr1), targets = Interval(one, N_m)), Add(IndexedVar(N, subtract(sub_expr3, one)), one), IndexedVar(N, sub_expr3)).with_wrapping_at(2,6), one, m)]))), And(ExprRange(sub_expr2, InSet(IndexedVar(N, sub_expr2), Natural), zero, m), each_Nk_is_partial_sum))
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{
\qin{A_{1}~\mbox{part}~1~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} & \qw \\
\qin{A_{1}~\mbox{part}~2~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} & \qw \\
\qin{\vdots} & \qw \\
\qin{A_{1}~\mbox{part}~n_{1}~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} & \qw \\
\qin{A_{2}~\mbox{part}~1~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} & \qw \\
\qin{A_{2}~\mbox{part}~2~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} & \qw \\
\qin{\vdots} & \qw \\
\qin{A_{2}~\mbox{part}~n_{2}~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} & \qw \\
\qin{\begin{array}{c}\vdots\\ \vdots\end{array}} & \qw \\
\qin{A_{m}~\mbox{part}~1~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{A_{m}~\mbox{part}~2~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{\vdots} & \qw \\
\qin{A_{m}~\mbox{part}~n_{m}~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} & \qw
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{1 - 1} + 1~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{1 - 1} + 2~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{\vdots} & \qw \\
\qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{1}~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{2 - 1} + 1~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{2 - 1} + 2~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{\vdots} & \qw \\
\qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{2}~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{\begin{array}{c}\vdots\\ \vdots\end{array}} & \qw \\
\qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{m - 1} + 1~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{m - 1} + 2~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{\vdots} & \qw \\
\qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{m}~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw
} \end{array}\right) \textrm{ if } \left(N_{0} \in \mathbb{N}\right) ,  \left(N_{1} \in \mathbb{N}\right) ,  \ldots ,  \left(N_{m} \in \mathbb{N}\right) ,  \left(N_{0} = 0\right)\land \left(N_{1} = \left(N_{1 - 1} + n_{1}\right)\right) \land  \left(N_{2} = \left(N_{2 - 1} + n_{2}\right)\right) \land  \ldots \land  \left(N_{m} = \left(N_{m - 1} + n_{m}\right)\right)\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operands: 4
2Operationoperator: 14
operands: 5
3Literal
4ExprTuple6, 7
5ExprTuple8, 9
6Operationoperator: 11
operand: 16
7Operationoperator: 11
operand: 17
8ExprRangelambda_map: 13
start_index: 42
end_index: 89
9Operationoperator: 14
operands: 15
10ExprTuple16
11Literal
12ExprTuple17
13Lambdaparameter: 98
body: 18
14Literal
15ExprTuple19, 20
16ExprTuple21
17ExprTuple22
18Operationoperator: 23
operands: 24
19Operationoperator: 35
operands: 25
20ExprRangelambda_map: 26
start_index: 101
end_index: 89
21ExprRangelambda_map: 27
start_index: 101
end_index: 89
22ExprRangelambda_map: 28
start_index: 101
end_index: 89
23Literal
24ExprTuple43, 29
25ExprTuple30, 42
26Lambdaparameter: 98
body: 31
27Lambdaparameter: 96
body: 32
28Lambdaparameter: 83
body: 33
29Literal
30IndexedVarvariable: 86
index: 42
31Operationoperator: 35
operands: 36
32ExprRangelambda_map: 37
start_index: 101
end_index: 38
33ExprRangelambda_map: 39
start_index: 40
end_index: 41
34ExprTuple42
35Literal
36ExprTuple43, 44
37Lambdaparameter: 98
body: 45
38IndexedVarvariable: 62
index: 96
39Lambdaparameter: 96
body: 46
40Operationoperator: 92
operands: 47
41IndexedVarvariable: 86
index: 83
42Literal
43IndexedVarvariable: 86
index: 98
44Operationoperator: 92
operands: 49
45Operationoperator: 51
operands: 50
46Operationoperator: 51
operands: 52
47ExprTuple53, 101
48ExprTuple83
49ExprTuple54, 55
50NamedExprselement: 56
targets: 57
51Literal
52NamedExprselement: 58
targets: 59
53IndexedVarvariable: 86
index: 69
54IndexedVarvariable: 86
index: 70
55IndexedVarvariable: 62
index: 98
56Operationoperator: 65
operands: 63
57Operationoperator: 67
operands: 64
58Operationoperator: 65
operands: 66
59Operationoperator: 67
operands: 68
60ExprTuple69
61ExprTuple70
62Variable
63NamedExprsstate: 71
part: 98
64ExprTuple72, 73
65Literal
66NamedExprsstate: 74
part: 96
67Literal
68ExprTuple101, 75
69Operationoperator: 92
operands: 76
70Operationoperator: 92
operands: 77
71IndexedVarvariable: 94
index: 96
72Operationoperator: 92
operands: 78
73IndexedVarvariable: 86
index: 96
74Operationoperator: 80
operands: 81
75IndexedVarvariable: 86
index: 89
76ExprTuple83, 97
77ExprTuple98, 97
78ExprTuple84, 101
79ExprTuple96
80Literal
81ExprTuple85
82ExprTuple89
83Variable
84IndexedVarvariable: 86
index: 90
85ExprRangelambda_map: 88
start_index: 101
end_index: 89
86Variable
87ExprTuple90
88Lambdaparameter: 98
body: 91
89Variable
90Operationoperator: 92
operands: 93
91IndexedVarvariable: 94
index: 98
92Literal
93ExprTuple96, 97
94Variable
95ExprTuple98
96Variable
97Operationoperator: 99
operand: 101
98Variable
99Literal
100ExprTuple101
101Literal