logo

Expression of type Lambda

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, 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 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}")
expr = Lambda(m, Conditional(Forall(instance_param_or_params = [n_1_to_m], instance_expr = 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, IndexedVar(n, sub_expr2))), one, m)]).with_wrapping(), domain = NaturalPos).with_wrapping(), InSet(m, NaturalPos)))
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())
m \mapsto \left\{\begin{array}{l}\forall_{n_{1}, n_{2}, \ldots, n_{m} \in \mathbb{N}^+}~\\
\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}\right]\end{array} \textrm{ if } m \in \mathbb{N}^+\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 132
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 22
operand: 6
3Operationoperator: 63
operands: 5
4ExprTuple6
5ExprTuple132, 28
6Lambdaparameters: 7
body: 8
7ExprTuple9
8Conditionalvalue: 10
condition: 11
9ExprRangelambda_map: 12
start_index: 144
end_index: 132
10Operationoperator: 22
operand: 15
11Operationoperator: 50
operands: 14
12Lambdaparameter: 141
body: 98
13ExprTuple15
14ExprTuple16
15Lambdaparameters: 124
body: 17
16ExprRangelambda_map: 18
start_index: 144
end_index: 132
17Conditionalvalue: 19
condition: 20
18Lambdaparameter: 141
body: 21
19Operationoperator: 22
operand: 26
20Operationoperator: 50
operands: 24
21Operationoperator: 63
operands: 25
22Literal
23ExprTuple26
24ExprTuple27
25ExprTuple98, 28
26Lambdaparameters: 29
body: 30
27ExprRangelambda_map: 31
start_index: 144
end_index: 132
28Literal
29ExprTuple32
30Conditionalvalue: 33
condition: 34
31Lambdaparameter: 141
body: 35
32ExprRangelambda_map: 36
start_index: 85
end_index: 132
33Operationoperator: 37
operands: 38
34Operationoperator: 50
operands: 39
35Operationoperator: 63
operands: 40
36Lambdaparameter: 141
body: 86
37Literal
38ExprTuple41, 42
39ExprTuple43, 44
40ExprTuple134, 45
41Operationoperator: 47
operand: 54
42Operationoperator: 47
operand: 55
43ExprRangelambda_map: 49
start_index: 85
end_index: 132
44Operationoperator: 50
operands: 51
45Operationoperator: 52
operands: 53
46ExprTuple54
47Literal
48ExprTuple55
49Lambdaparameter: 141
body: 56
50Literal
51ExprTuple57, 58
52Literal
53ExprTuple59, 60
54ExprTuple61
55ExprTuple62
56Operationoperator: 63
operands: 64
57Operationoperator: 78
operands: 65
58ExprRangelambda_map: 66
start_index: 144
end_index: 132
59Literal
60Operationoperator: 67
operands: 68
61ExprRangelambda_map: 69
start_index: 144
end_index: 132
62ExprRangelambda_map: 70
start_index: 144
end_index: 132
63Literal
64ExprTuple86, 71
65ExprTuple72, 85
66Lambdaparameter: 141
body: 73
67Literal
68ExprTuple74, 98
69Lambdaparameter: 139
body: 75
70Lambdaparameter: 126
body: 76
71Literal
72IndexedVarvariable: 129
index: 85
73Operationoperator: 78
operands: 79
74Literal
75ExprRangelambda_map: 80
start_index: 144
end_index: 81
76ExprRangelambda_map: 82
start_index: 83
end_index: 84
77ExprTuple85
78Literal
79ExprTuple86, 87
80Lambdaparameter: 141
body: 88
81IndexedVarvariable: 105
index: 139
82Lambdaparameter: 139
body: 89
83Operationoperator: 135
operands: 90
84IndexedVarvariable: 129
index: 126
85Literal
86IndexedVarvariable: 129
index: 141
87Operationoperator: 135
operands: 92
88Operationoperator: 94
operands: 93
89Operationoperator: 94
operands: 95
90ExprTuple96, 144
91ExprTuple126
92ExprTuple97, 98
93NamedExprselement: 99
targets: 100
94Literal
95NamedExprselement: 101
targets: 102
96IndexedVarvariable: 129
index: 112
97IndexedVarvariable: 129
index: 113
98IndexedVarvariable: 105
index: 141
99Operationoperator: 108
operands: 106
100Operationoperator: 110
operands: 107
101Operationoperator: 108
operands: 109
102Operationoperator: 110
operands: 111
103ExprTuple112
104ExprTuple113
105Variable
106NamedExprsstate: 114
part: 141
107ExprTuple115, 116
108Literal
109NamedExprsstate: 117
part: 139
110Literal
111ExprTuple144, 118
112Operationoperator: 135
operands: 119
113Operationoperator: 135
operands: 120
114IndexedVarvariable: 137
index: 139
115Operationoperator: 135
operands: 121
116IndexedVarvariable: 129
index: 139
117Operationoperator: 123
operands: 124
118IndexedVarvariable: 129
index: 132
119ExprTuple126, 140
120ExprTuple141, 140
121ExprTuple127, 144
122ExprTuple139
123Literal
124ExprTuple128
125ExprTuple132
126Variable
127IndexedVarvariable: 129
index: 133
128ExprRangelambda_map: 131
start_index: 144
end_index: 132
129Variable
130ExprTuple133
131Lambdaparameter: 141
body: 134
132Variable
133Operationoperator: 135
operands: 136
134IndexedVarvariable: 137
index: 141
135Literal
136ExprTuple139, 140
137Variable
138ExprTuple141
139Variable
140Operationoperator: 142
operand: 144
141Variable
142Literal
143ExprTuple144
144Literal