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
from proveit.linear_algebra import TensorProd
from proveit.logic import And, CartExp, Forall, InSet
from proveit.numbers import Add, Complex, Exp, Interval, Natural, 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}")
expr = ExprTuple(Lambda([A_1_to_m], Conditional(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(), And(ExprRange(sub_expr2, InSet(IndexedVar(A, sub_expr2), CartExp(Complex, Exp(two, IndexedVar(n, sub_expr2)))), 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(A_{1}, A_{2}, \ldots, A_{m}\right) \mapsto \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} \textrm{ if } \left(A_{1} \in \mathbb{C}^{2^{n_{1}}}\right) \land  \left(A_{2} \in \mathbb{C}^{2^{n_{2}}}\right) \land  \ldots \land  \left(A_{m} \in \mathbb{C}^{2^{n_{m}}}\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: 105
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 8
4Operationoperator: 31
operands: 7
5Literal
6ExprTuple8
7ExprTuple9
8Lambdaparameters: 10
body: 11
9ExprRangelambda_map: 12
start_index: 125
end_index: 113
10ExprTuple13
11Conditionalvalue: 14
condition: 15
12Lambdaparameter: 122
body: 16
13ExprRangelambda_map: 17
start_index: 66
end_index: 113
14Operationoperator: 18
operands: 19
15Operationoperator: 31
operands: 20
16Operationoperator: 44
operands: 21
17Lambdaparameter: 122
body: 67
18Literal
19ExprTuple22, 23
20ExprTuple24, 25
21ExprTuple115, 26
22Operationoperator: 28
operand: 35
23Operationoperator: 28
operand: 36
24ExprRangelambda_map: 30
start_index: 66
end_index: 113
25Operationoperator: 31
operands: 32
26Operationoperator: 33
operands: 34
27ExprTuple35
28Literal
29ExprTuple36
30Lambdaparameter: 122
body: 37
31Literal
32ExprTuple38, 39
33Literal
34ExprTuple40, 41
35ExprTuple42
36ExprTuple43
37Operationoperator: 44
operands: 45
38Operationoperator: 59
operands: 46
39ExprRangelambda_map: 47
start_index: 125
end_index: 113
40Literal
41Operationoperator: 48
operands: 49
42ExprRangelambda_map: 50
start_index: 125
end_index: 113
43ExprRangelambda_map: 51
start_index: 125
end_index: 113
44Literal
45ExprTuple67, 52
46ExprTuple53, 66
47Lambdaparameter: 122
body: 54
48Literal
49ExprTuple55, 79
50Lambdaparameter: 120
body: 56
51Lambdaparameter: 107
body: 57
52Literal
53IndexedVarvariable: 110
index: 66
54Operationoperator: 59
operands: 60
55Literal
56ExprRangelambda_map: 61
start_index: 125
end_index: 62
57ExprRangelambda_map: 63
start_index: 64
end_index: 65
58ExprTuple66
59Literal
60ExprTuple67, 68
61Lambdaparameter: 122
body: 69
62IndexedVarvariable: 86
index: 120
63Lambdaparameter: 120
body: 70
64Operationoperator: 116
operands: 71
65IndexedVarvariable: 110
index: 107
66Literal
67IndexedVarvariable: 110
index: 122
68Operationoperator: 116
operands: 73
69Operationoperator: 75
operands: 74
70Operationoperator: 75
operands: 76
71ExprTuple77, 125
72ExprTuple107
73ExprTuple78, 79
74NamedExprselement: 80
targets: 81
75Literal
76NamedExprselement: 82
targets: 83
77IndexedVarvariable: 110
index: 93
78IndexedVarvariable: 110
index: 94
79IndexedVarvariable: 86
index: 122
80Operationoperator: 89
operands: 87
81Operationoperator: 91
operands: 88
82Operationoperator: 89
operands: 90
83Operationoperator: 91
operands: 92
84ExprTuple93
85ExprTuple94
86Variable
87NamedExprsstate: 95
part: 122
88ExprTuple96, 97
89Literal
90NamedExprsstate: 98
part: 120
91Literal
92ExprTuple125, 99
93Operationoperator: 116
operands: 100
94Operationoperator: 116
operands: 101
95IndexedVarvariable: 118
index: 120
96Operationoperator: 116
operands: 102
97IndexedVarvariable: 110
index: 120
98Operationoperator: 104
operands: 105
99IndexedVarvariable: 110
index: 113
100ExprTuple107, 121
101ExprTuple122, 121
102ExprTuple108, 125
103ExprTuple120
104Literal
105ExprTuple109
106ExprTuple113
107Variable
108IndexedVarvariable: 110
index: 114
109ExprRangelambda_map: 112
start_index: 125
end_index: 113
110Variable
111ExprTuple114
112Lambdaparameter: 122
body: 115
113Variable
114Operationoperator: 116
operands: 117
115IndexedVarvariable: 118
index: 122
116Literal
117ExprTuple120, 121
118Variable
119ExprTuple122
120Variable
121Operationoperator: 123
operand: 125
122Variable
123Literal
124ExprTuple125
125Literal