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 And, CartExp, Forall, InSet
from proveit.numbers import Add, Complex, Exp, Interval, Natural, NaturalPos, 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}")
sub_expr4 = IndexedVar(n, sub_expr2)
expr = 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 = 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(), 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(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{
\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}\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..
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: 138
end_index: 126
4Operationoperator: 16
operand: 9
5Operationoperator: 44
operands: 8
6Lambdaparameter: 135
body: 92
7ExprTuple9
8ExprTuple10
9Lambdaparameters: 118
body: 11
10ExprRangelambda_map: 12
start_index: 138
end_index: 126
11Conditionalvalue: 13
condition: 14
12Lambdaparameter: 135
body: 15
13Operationoperator: 16
operand: 20
14Operationoperator: 44
operands: 18
15Operationoperator: 57
operands: 19
16Literal
17ExprTuple20
18ExprTuple21
19ExprTuple92, 22
20Lambdaparameters: 23
body: 24
21ExprRangelambda_map: 25
start_index: 138
end_index: 126
22Literal
23ExprTuple26
24Conditionalvalue: 27
condition: 28
25Lambdaparameter: 135
body: 29
26ExprRangelambda_map: 30
start_index: 79
end_index: 126
27Operationoperator: 31
operands: 32
28Operationoperator: 44
operands: 33
29Operationoperator: 57
operands: 34
30Lambdaparameter: 135
body: 80
31Literal
32ExprTuple35, 36
33ExprTuple37, 38
34ExprTuple128, 39
35Operationoperator: 41
operand: 48
36Operationoperator: 41
operand: 49
37ExprRangelambda_map: 43
start_index: 79
end_index: 126
38Operationoperator: 44
operands: 45
39Operationoperator: 46
operands: 47
40ExprTuple48
41Literal
42ExprTuple49
43Lambdaparameter: 135
body: 50
44Literal
45ExprTuple51, 52
46Literal
47ExprTuple53, 54
48ExprTuple55
49ExprTuple56
50Operationoperator: 57
operands: 58
51Operationoperator: 72
operands: 59
52ExprRangelambda_map: 60
start_index: 138
end_index: 126
53Literal
54Operationoperator: 61
operands: 62
55ExprRangelambda_map: 63
start_index: 138
end_index: 126
56ExprRangelambda_map: 64
start_index: 138
end_index: 126
57Literal
58ExprTuple80, 65
59ExprTuple66, 79
60Lambdaparameter: 135
body: 67
61Literal
62ExprTuple68, 92
63Lambdaparameter: 133
body: 69
64Lambdaparameter: 120
body: 70
65Literal
66IndexedVarvariable: 123
index: 79
67Operationoperator: 72
operands: 73
68Literal
69ExprRangelambda_map: 74
start_index: 138
end_index: 75
70ExprRangelambda_map: 76
start_index: 77
end_index: 78
71ExprTuple79
72Literal
73ExprTuple80, 81
74Lambdaparameter: 135
body: 82
75IndexedVarvariable: 99
index: 133
76Lambdaparameter: 133
body: 83
77Operationoperator: 129
operands: 84
78IndexedVarvariable: 123
index: 120
79Literal
80IndexedVarvariable: 123
index: 135
81Operationoperator: 129
operands: 86
82Operationoperator: 88
operands: 87
83Operationoperator: 88
operands: 89
84ExprTuple90, 138
85ExprTuple120
86ExprTuple91, 92
87NamedExprselement: 93
targets: 94
88Literal
89NamedExprselement: 95
targets: 96
90IndexedVarvariable: 123
index: 106
91IndexedVarvariable: 123
index: 107
92IndexedVarvariable: 99
index: 135
93Operationoperator: 102
operands: 100
94Operationoperator: 104
operands: 101
95Operationoperator: 102
operands: 103
96Operationoperator: 104
operands: 105
97ExprTuple106
98ExprTuple107
99Variable
100NamedExprsstate: 108
part: 135
101ExprTuple109, 110
102Literal
103NamedExprsstate: 111
part: 133
104Literal
105ExprTuple138, 112
106Operationoperator: 129
operands: 113
107Operationoperator: 129
operands: 114
108IndexedVarvariable: 131
index: 133
109Operationoperator: 129
operands: 115
110IndexedVarvariable: 123
index: 133
111Operationoperator: 117
operands: 118
112IndexedVarvariable: 123
index: 126
113ExprTuple120, 134
114ExprTuple135, 134
115ExprTuple121, 138
116ExprTuple133
117Literal
118ExprTuple122
119ExprTuple126
120Variable
121IndexedVarvariable: 123
index: 127
122ExprRangelambda_map: 125
start_index: 138
end_index: 126
123Variable
124ExprTuple127
125Lambdaparameter: 135
body: 128
126Variable
127Operationoperator: 129
operands: 130
128IndexedVarvariable: 131
index: 135
129Literal
130ExprTuple133, 134
131Variable
132ExprTuple135
133Variable
134Operationoperator: 136
operand: 138
135Variable
136Literal
137ExprTuple138
138Literal