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
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 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([N_0_to_m], Conditional(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)]))), 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(N_{0}, N_{1}, \ldots, N_{m}\right) \mapsto \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) \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()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 1
body: 2
1ExprTuple3
2Conditionalvalue: 4
condition: 5
3ExprRangelambda_map: 6
start_index: 46
end_index: 93
4Operationoperator: 7
operands: 8
5Operationoperator: 18
operands: 9
6Lambdaparameter: 102
body: 47
7Literal
8ExprTuple10, 11
9ExprTuple12, 13
10Operationoperator: 15
operand: 20
11Operationoperator: 15
operand: 21
12ExprRangelambda_map: 17
start_index: 46
end_index: 93
13Operationoperator: 18
operands: 19
14ExprTuple20
15Literal
16ExprTuple21
17Lambdaparameter: 102
body: 22
18Literal
19ExprTuple23, 24
20ExprTuple25
21ExprTuple26
22Operationoperator: 27
operands: 28
23Operationoperator: 39
operands: 29
24ExprRangelambda_map: 30
start_index: 105
end_index: 93
25ExprRangelambda_map: 31
start_index: 105
end_index: 93
26ExprRangelambda_map: 32
start_index: 105
end_index: 93
27Literal
28ExprTuple47, 33
29ExprTuple34, 46
30Lambdaparameter: 102
body: 35
31Lambdaparameter: 100
body: 36
32Lambdaparameter: 87
body: 37
33Literal
34IndexedVarvariable: 90
index: 46
35Operationoperator: 39
operands: 40
36ExprRangelambda_map: 41
start_index: 105
end_index: 42
37ExprRangelambda_map: 43
start_index: 44
end_index: 45
38ExprTuple46
39Literal
40ExprTuple47, 48
41Lambdaparameter: 102
body: 49
42IndexedVarvariable: 66
index: 100
43Lambdaparameter: 100
body: 50
44Operationoperator: 96
operands: 51
45IndexedVarvariable: 90
index: 87
46Literal
47IndexedVarvariable: 90
index: 102
48Operationoperator: 96
operands: 53
49Operationoperator: 55
operands: 54
50Operationoperator: 55
operands: 56
51ExprTuple57, 105
52ExprTuple87
53ExprTuple58, 59
54NamedExprselement: 60
targets: 61
55Literal
56NamedExprselement: 62
targets: 63
57IndexedVarvariable: 90
index: 73
58IndexedVarvariable: 90
index: 74
59IndexedVarvariable: 66
index: 102
60Operationoperator: 69
operands: 67
61Operationoperator: 71
operands: 68
62Operationoperator: 69
operands: 70
63Operationoperator: 71
operands: 72
64ExprTuple73
65ExprTuple74
66Variable
67NamedExprsstate: 75
part: 102
68ExprTuple76, 77
69Literal
70NamedExprsstate: 78
part: 100
71Literal
72ExprTuple105, 79
73Operationoperator: 96
operands: 80
74Operationoperator: 96
operands: 81
75IndexedVarvariable: 98
index: 100
76Operationoperator: 96
operands: 82
77IndexedVarvariable: 90
index: 100
78Operationoperator: 84
operands: 85
79IndexedVarvariable: 90
index: 93
80ExprTuple87, 101
81ExprTuple102, 101
82ExprTuple88, 105
83ExprTuple100
84Literal
85ExprTuple89
86ExprTuple93
87Variable
88IndexedVarvariable: 90
index: 94
89ExprRangelambda_map: 92
start_index: 105
end_index: 93
90Variable
91ExprTuple94
92Lambdaparameter: 102
body: 95
93Variable
94Operationoperator: 96
operands: 97
95IndexedVarvariable: 98
index: 102
96Literal
97ExprTuple100, 101
98Variable
99ExprTuple102
100Variable
101Operationoperator: 103
operand: 105
102Variable
103Literal
104ExprTuple105
105Literal