logo

Expression of type Forall

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, ExprRange, IndexedVar, 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
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 = 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()
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())
\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}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 18
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple5
4Conditionalvalue: 6
condition: 7
5ExprRangelambda_map: 8
start_index: 140
end_index: 128
6Operationoperator: 18
operand: 11
7Operationoperator: 46
operands: 10
8Lambdaparameter: 137
body: 94
9ExprTuple11
10ExprTuple12
11Lambdaparameters: 120
body: 13
12ExprRangelambda_map: 14
start_index: 140
end_index: 128
13Conditionalvalue: 15
condition: 16
14Lambdaparameter: 137
body: 17
15Operationoperator: 18
operand: 22
16Operationoperator: 46
operands: 20
17Operationoperator: 59
operands: 21
18Literal
19ExprTuple22
20ExprTuple23
21ExprTuple94, 24
22Lambdaparameters: 25
body: 26
23ExprRangelambda_map: 27
start_index: 140
end_index: 128
24Literal
25ExprTuple28
26Conditionalvalue: 29
condition: 30
27Lambdaparameter: 137
body: 31
28ExprRangelambda_map: 32
start_index: 81
end_index: 128
29Operationoperator: 33
operands: 34
30Operationoperator: 46
operands: 35
31Operationoperator: 59
operands: 36
32Lambdaparameter: 137
body: 82
33Literal
34ExprTuple37, 38
35ExprTuple39, 40
36ExprTuple130, 41
37Operationoperator: 43
operand: 50
38Operationoperator: 43
operand: 51
39ExprRangelambda_map: 45
start_index: 81
end_index: 128
40Operationoperator: 46
operands: 47
41Operationoperator: 48
operands: 49
42ExprTuple50
43Literal
44ExprTuple51
45Lambdaparameter: 137
body: 52
46Literal
47ExprTuple53, 54
48Literal
49ExprTuple55, 56
50ExprTuple57
51ExprTuple58
52Operationoperator: 59
operands: 60
53Operationoperator: 74
operands: 61
54ExprRangelambda_map: 62
start_index: 140
end_index: 128
55Literal
56Operationoperator: 63
operands: 64
57ExprRangelambda_map: 65
start_index: 140
end_index: 128
58ExprRangelambda_map: 66
start_index: 140
end_index: 128
59Literal
60ExprTuple82, 67
61ExprTuple68, 81
62Lambdaparameter: 137
body: 69
63Literal
64ExprTuple70, 94
65Lambdaparameter: 135
body: 71
66Lambdaparameter: 122
body: 72
67Literal
68IndexedVarvariable: 125
index: 81
69Operationoperator: 74
operands: 75
70Literal
71ExprRangelambda_map: 76
start_index: 140
end_index: 77
72ExprRangelambda_map: 78
start_index: 79
end_index: 80
73ExprTuple81
74Literal
75ExprTuple82, 83
76Lambdaparameter: 137
body: 84
77IndexedVarvariable: 101
index: 135
78Lambdaparameter: 135
body: 85
79Operationoperator: 131
operands: 86
80IndexedVarvariable: 125
index: 122
81Literal
82IndexedVarvariable: 125
index: 137
83Operationoperator: 131
operands: 88
84Operationoperator: 90
operands: 89
85Operationoperator: 90
operands: 91
86ExprTuple92, 140
87ExprTuple122
88ExprTuple93, 94
89NamedExprselement: 95
targets: 96
90Literal
91NamedExprselement: 97
targets: 98
92IndexedVarvariable: 125
index: 108
93IndexedVarvariable: 125
index: 109
94IndexedVarvariable: 101
index: 137
95Operationoperator: 104
operands: 102
96Operationoperator: 106
operands: 103
97Operationoperator: 104
operands: 105
98Operationoperator: 106
operands: 107
99ExprTuple108
100ExprTuple109
101Variable
102NamedExprsstate: 110
part: 137
103ExprTuple111, 112
104Literal
105NamedExprsstate: 113
part: 135
106Literal
107ExprTuple140, 114
108Operationoperator: 131
operands: 115
109Operationoperator: 131
operands: 116
110IndexedVarvariable: 133
index: 135
111Operationoperator: 131
operands: 117
112IndexedVarvariable: 125
index: 135
113Operationoperator: 119
operands: 120
114IndexedVarvariable: 125
index: 128
115ExprTuple122, 136
116ExprTuple137, 136
117ExprTuple123, 140
118ExprTuple135
119Literal
120ExprTuple124
121ExprTuple128
122Variable
123IndexedVarvariable: 125
index: 129
124ExprRangelambda_map: 127
start_index: 140
end_index: 128
125Variable
126ExprTuple129
127Lambdaparameter: 137
body: 130
128Variable
129Operationoperator: 131
operands: 132
130IndexedVarvariable: 133
index: 137
131Literal
132ExprTuple135, 136
133Variable
134ExprTuple137
135Variable
136Operationoperator: 138
operand: 140
137Variable
138Literal
139ExprTuple140
140Literal