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, CartExp, Forall, InSet
from proveit.numbers import Add, Complex, Exp, Interval, Natural, one, subtract, two
from proveit.physics.quantum.circuits import Input, MultiQubitElem, N_0_to_m, 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 = 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 = 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)]))), 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(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{
\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)\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..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 104
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 7
3Operationoperator: 30
operands: 6
4Literal
5ExprTuple7
6ExprTuple8
7Lambdaparameters: 9
body: 10
8ExprRangelambda_map: 11
start_index: 124
end_index: 112
9ExprTuple12
10Conditionalvalue: 13
condition: 14
11Lambdaparameter: 121
body: 15
12ExprRangelambda_map: 16
start_index: 65
end_index: 112
13Operationoperator: 17
operands: 18
14Operationoperator: 30
operands: 19
15Operationoperator: 43
operands: 20
16Lambdaparameter: 121
body: 66
17Literal
18ExprTuple21, 22
19ExprTuple23, 24
20ExprTuple114, 25
21Operationoperator: 27
operand: 34
22Operationoperator: 27
operand: 35
23ExprRangelambda_map: 29
start_index: 65
end_index: 112
24Operationoperator: 30
operands: 31
25Operationoperator: 32
operands: 33
26ExprTuple34
27Literal
28ExprTuple35
29Lambdaparameter: 121
body: 36
30Literal
31ExprTuple37, 38
32Literal
33ExprTuple39, 40
34ExprTuple41
35ExprTuple42
36Operationoperator: 43
operands: 44
37Operationoperator: 58
operands: 45
38ExprRangelambda_map: 46
start_index: 124
end_index: 112
39Literal
40Operationoperator: 47
operands: 48
41ExprRangelambda_map: 49
start_index: 124
end_index: 112
42ExprRangelambda_map: 50
start_index: 124
end_index: 112
43Literal
44ExprTuple66, 51
45ExprTuple52, 65
46Lambdaparameter: 121
body: 53
47Literal
48ExprTuple54, 78
49Lambdaparameter: 119
body: 55
50Lambdaparameter: 106
body: 56
51Literal
52IndexedVarvariable: 109
index: 65
53Operationoperator: 58
operands: 59
54Literal
55ExprRangelambda_map: 60
start_index: 124
end_index: 61
56ExprRangelambda_map: 62
start_index: 63
end_index: 64
57ExprTuple65
58Literal
59ExprTuple66, 67
60Lambdaparameter: 121
body: 68
61IndexedVarvariable: 85
index: 119
62Lambdaparameter: 119
body: 69
63Operationoperator: 115
operands: 70
64IndexedVarvariable: 109
index: 106
65Literal
66IndexedVarvariable: 109
index: 121
67Operationoperator: 115
operands: 72
68Operationoperator: 74
operands: 73
69Operationoperator: 74
operands: 75
70ExprTuple76, 124
71ExprTuple106
72ExprTuple77, 78
73NamedExprselement: 79
targets: 80
74Literal
75NamedExprselement: 81
targets: 82
76IndexedVarvariable: 109
index: 92
77IndexedVarvariable: 109
index: 93
78IndexedVarvariable: 85
index: 121
79Operationoperator: 88
operands: 86
80Operationoperator: 90
operands: 87
81Operationoperator: 88
operands: 89
82Operationoperator: 90
operands: 91
83ExprTuple92
84ExprTuple93
85Variable
86NamedExprsstate: 94
part: 121
87ExprTuple95, 96
88Literal
89NamedExprsstate: 97
part: 119
90Literal
91ExprTuple124, 98
92Operationoperator: 115
operands: 99
93Operationoperator: 115
operands: 100
94IndexedVarvariable: 117
index: 119
95Operationoperator: 115
operands: 101
96IndexedVarvariable: 109
index: 119
97Operationoperator: 103
operands: 104
98IndexedVarvariable: 109
index: 112
99ExprTuple106, 120
100ExprTuple121, 120
101ExprTuple107, 124
102ExprTuple119
103Literal
104ExprTuple108
105ExprTuple112
106Variable
107IndexedVarvariable: 109
index: 113
108ExprRangelambda_map: 111
start_index: 124
end_index: 112
109Variable
110ExprTuple113
111Lambdaparameter: 121
body: 114
112Variable
113Operationoperator: 115
operands: 116
114IndexedVarvariable: 117
index: 121
115Literal
116ExprTuple119, 120
117Variable
118ExprTuple121
119Variable
120Operationoperator: 122
operand: 124
121Variable
122Literal
123ExprTuple124
124Literal