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 A, Conditional, ExprRange, ExprTuple, IndexedVar, Lambda, N, Variable, VertExprArray, m, n
from proveit.core_expr_types import A_1_to_m, n_1_to_m
from proveit.linear_algebra import TensorProd
from proveit.logic import And, CartExp, Forall, InSet
from proveit.numbers import Add, Complex, Exp, Interval, Natural, NaturalPos, one, subtract, two
from proveit.physics.quantum.circuits import MultiQubitElem, N_0_to_m, N_m, Output, 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}")
sub_expr4 = IndexedVar(n, sub_expr2)
expr = ExprTuple(Lambda([n_1_to_m], Conditional(Forall(instance_param_or_params = [A_1_to_m], instance_expr = Forall(instance_param_or_params = [N_0_to_m], instance_expr = QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, ExprRange(sub_expr2, MultiQubitElem(element = Output(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 = Output(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)]))), domain = Natural, condition = each_Nk_is_partial_sum).with_wrapping(), domains = [ExprRange(sub_expr2, CartExp(Complex, Exp(two, sub_expr4)), one, m)]).with_wrapping(), And(ExprRange(sub_expr2, InSet(sub_expr4, NaturalPos), 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(n_{1}, n_{2}, \ldots, n_{m}\right) \mapsto \left\{\begin{array}{l}\forall_{\left(A_{1} \in \mathbb{C}^{2^{n_{1}}}\right), \left(A_{2} \in \mathbb{C}^{2^{n_{2}}}\right), \ldots, \left(A_{m} \in \mathbb{C}^{2^{n_{m}}}\right)}~\\
\left[\begin{array}{l}\forall_{N_{0}, N_{1}, \ldots, N_{m} \in \mathbb{N}~|~\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)}~\\
\left(\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qout{A_{1}~\mbox{part}~1~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} \\
& \qout{A_{1}~\mbox{part}~2~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} \\
& \qout{\vdots} \\
& \qout{A_{1}~\mbox{part}~n_{1}~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} \\
& \qout{A_{2}~\mbox{part}~1~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} \\
& \qout{A_{2}~\mbox{part}~2~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} \\
& \qout{\vdots} \\
& \qout{A_{2}~\mbox{part}~n_{2}~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} \\
& \qout{\begin{array}{c}\vdots\\ \vdots\end{array}} \\
& \qout{A_{m}~\mbox{part}~1~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} \\
& \qout{A_{m}~\mbox{part}~2~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} \\
& \qout{\vdots} \\
& \qout{A_{m}~\mbox{part}~n_{m}~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}}
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qout{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{1 - 1} + 1~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} \\
& \qout{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{1 - 1} + 2~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} \\
& \qout{\vdots} \\
& \qout{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{1}~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} \\
& \qout{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{2 - 1} + 1~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} \\
& \qout{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{2 - 1} + 2~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} \\
& \qout{\vdots} \\
& \qout{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{2}~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} \\
& \qout{\begin{array}{c}\vdots\\ \vdots\end{array}} \\
& \qout{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{m - 1} + 1~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} \\
& \qout{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{m - 1} + 2~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} \\
& \qout{\vdots} \\
& \qout{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{m}~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}}
} \end{array}\right)\right)\end{array}\right]\end{array} \textrm{ if } \left(n_{1} \in \mathbb{N}^+\right) \land  \left(n_{2} \in \mathbb{N}^+\right) \land  \ldots \land  \left(n_{m} \in \mathbb{N}^+\right)\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameters: 2
body: 3
2ExprTuple4
3Conditionalvalue: 5
condition: 6
4ExprRangelambda_map: 7
start_index: 139
end_index: 127
5Operationoperator: 17
operand: 10
6Operationoperator: 45
operands: 9
7Lambdaparameter: 136
body: 93
8ExprTuple10
9ExprTuple11
10Lambdaparameters: 119
body: 12
11ExprRangelambda_map: 13
start_index: 139
end_index: 127
12Conditionalvalue: 14
condition: 15
13Lambdaparameter: 136
body: 16
14Operationoperator: 17
operand: 21
15Operationoperator: 45
operands: 19
16Operationoperator: 58
operands: 20
17Literal
18ExprTuple21
19ExprTuple22
20ExprTuple93, 23
21Lambdaparameters: 24
body: 25
22ExprRangelambda_map: 26
start_index: 139
end_index: 127
23Literal
24ExprTuple27
25Conditionalvalue: 28
condition: 29
26Lambdaparameter: 136
body: 30
27ExprRangelambda_map: 31
start_index: 80
end_index: 127
28Operationoperator: 32
operands: 33
29Operationoperator: 45
operands: 34
30Operationoperator: 58
operands: 35
31Lambdaparameter: 136
body: 81
32Literal
33ExprTuple36, 37
34ExprTuple38, 39
35ExprTuple129, 40
36Operationoperator: 42
operand: 49
37Operationoperator: 42
operand: 50
38ExprRangelambda_map: 44
start_index: 80
end_index: 127
39Operationoperator: 45
operands: 46
40Operationoperator: 47
operands: 48
41ExprTuple49
42Literal
43ExprTuple50
44Lambdaparameter: 136
body: 51
45Literal
46ExprTuple52, 53
47Literal
48ExprTuple54, 55
49ExprTuple56
50ExprTuple57
51Operationoperator: 58
operands: 59
52Operationoperator: 73
operands: 60
53ExprRangelambda_map: 61
start_index: 139
end_index: 127
54Literal
55Operationoperator: 62
operands: 63
56ExprRangelambda_map: 64
start_index: 139
end_index: 127
57ExprRangelambda_map: 65
start_index: 139
end_index: 127
58Literal
59ExprTuple81, 66
60ExprTuple67, 80
61Lambdaparameter: 136
body: 68
62Literal
63ExprTuple69, 93
64Lambdaparameter: 134
body: 70
65Lambdaparameter: 121
body: 71
66Literal
67IndexedVarvariable: 124
index: 80
68Operationoperator: 73
operands: 74
69Literal
70ExprRangelambda_map: 75
start_index: 139
end_index: 76
71ExprRangelambda_map: 77
start_index: 78
end_index: 79
72ExprTuple80
73Literal
74ExprTuple81, 82
75Lambdaparameter: 136
body: 83
76IndexedVarvariable: 100
index: 134
77Lambdaparameter: 134
body: 84
78Operationoperator: 130
operands: 85
79IndexedVarvariable: 124
index: 121
80Literal
81IndexedVarvariable: 124
index: 136
82Operationoperator: 130
operands: 87
83Operationoperator: 89
operands: 88
84Operationoperator: 89
operands: 90
85ExprTuple91, 139
86ExprTuple121
87ExprTuple92, 93
88NamedExprselement: 94
targets: 95
89Literal
90NamedExprselement: 96
targets: 97
91IndexedVarvariable: 124
index: 107
92IndexedVarvariable: 124
index: 108
93IndexedVarvariable: 100
index: 136
94Operationoperator: 103
operands: 101
95Operationoperator: 105
operands: 102
96Operationoperator: 103
operands: 104
97Operationoperator: 105
operands: 106
98ExprTuple107
99ExprTuple108
100Variable
101NamedExprsstate: 109
part: 136
102ExprTuple110, 111
103Literal
104NamedExprsstate: 112
part: 134
105Literal
106ExprTuple139, 113
107Operationoperator: 130
operands: 114
108Operationoperator: 130
operands: 115
109IndexedVarvariable: 132
index: 134
110Operationoperator: 130
operands: 116
111IndexedVarvariable: 124
index: 134
112Operationoperator: 118
operands: 119
113IndexedVarvariable: 124
index: 127
114ExprTuple121, 135
115ExprTuple136, 135
116ExprTuple122, 139
117ExprTuple134
118Literal
119ExprTuple123
120ExprTuple127
121Variable
122IndexedVarvariable: 124
index: 128
123ExprRangelambda_map: 126
start_index: 139
end_index: 127
124Variable
125ExprTuple128
126Lambdaparameter: 136
body: 129
127Variable
128Operationoperator: 130
operands: 131
129IndexedVarvariable: 132
index: 136
130Literal
131ExprTuple134, 135
132Variable
133ExprTuple136
134Variable
135Operationoperator: 137
operand: 139
136Variable
137Literal
138ExprTuple139
139Literal