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
from proveit.linear_algebra import TensorProd
from proveit.logic import CartExp, Forall
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 = 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, IndexedVar(n, sub_expr2))), one, m)]).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_{\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}
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: 6
operand: 2
1ExprTuple2
2Lambdaparameters: 106
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operand: 9
5Operationoperator: 32
operands: 8
6Literal
7ExprTuple9
8ExprTuple10
9Lambdaparameters: 11
body: 12
10ExprRangelambda_map: 13
start_index: 126
end_index: 114
11ExprTuple14
12Conditionalvalue: 15
condition: 16
13Lambdaparameter: 123
body: 17
14ExprRangelambda_map: 18
start_index: 67
end_index: 114
15Operationoperator: 19
operands: 20
16Operationoperator: 32
operands: 21
17Operationoperator: 45
operands: 22
18Lambdaparameter: 123
body: 68
19Literal
20ExprTuple23, 24
21ExprTuple25, 26
22ExprTuple116, 27
23Operationoperator: 29
operand: 36
24Operationoperator: 29
operand: 37
25ExprRangelambda_map: 31
start_index: 67
end_index: 114
26Operationoperator: 32
operands: 33
27Operationoperator: 34
operands: 35
28ExprTuple36
29Literal
30ExprTuple37
31Lambdaparameter: 123
body: 38
32Literal
33ExprTuple39, 40
34Literal
35ExprTuple41, 42
36ExprTuple43
37ExprTuple44
38Operationoperator: 45
operands: 46
39Operationoperator: 60
operands: 47
40ExprRangelambda_map: 48
start_index: 126
end_index: 114
41Literal
42Operationoperator: 49
operands: 50
43ExprRangelambda_map: 51
start_index: 126
end_index: 114
44ExprRangelambda_map: 52
start_index: 126
end_index: 114
45Literal
46ExprTuple68, 53
47ExprTuple54, 67
48Lambdaparameter: 123
body: 55
49Literal
50ExprTuple56, 80
51Lambdaparameter: 121
body: 57
52Lambdaparameter: 108
body: 58
53Literal
54IndexedVarvariable: 111
index: 67
55Operationoperator: 60
operands: 61
56Literal
57ExprRangelambda_map: 62
start_index: 126
end_index: 63
58ExprRangelambda_map: 64
start_index: 65
end_index: 66
59ExprTuple67
60Literal
61ExprTuple68, 69
62Lambdaparameter: 123
body: 70
63IndexedVarvariable: 87
index: 121
64Lambdaparameter: 121
body: 71
65Operationoperator: 117
operands: 72
66IndexedVarvariable: 111
index: 108
67Literal
68IndexedVarvariable: 111
index: 123
69Operationoperator: 117
operands: 74
70Operationoperator: 76
operands: 75
71Operationoperator: 76
operands: 77
72ExprTuple78, 126
73ExprTuple108
74ExprTuple79, 80
75NamedExprselement: 81
targets: 82
76Literal
77NamedExprselement: 83
targets: 84
78IndexedVarvariable: 111
index: 94
79IndexedVarvariable: 111
index: 95
80IndexedVarvariable: 87
index: 123
81Operationoperator: 90
operands: 88
82Operationoperator: 92
operands: 89
83Operationoperator: 90
operands: 91
84Operationoperator: 92
operands: 93
85ExprTuple94
86ExprTuple95
87Variable
88NamedExprsstate: 96
part: 123
89ExprTuple97, 98
90Literal
91NamedExprsstate: 99
part: 121
92Literal
93ExprTuple126, 100
94Operationoperator: 117
operands: 101
95Operationoperator: 117
operands: 102
96IndexedVarvariable: 119
index: 121
97Operationoperator: 117
operands: 103
98IndexedVarvariable: 111
index: 121
99Operationoperator: 105
operands: 106
100IndexedVarvariable: 111
index: 114
101ExprTuple108, 122
102ExprTuple123, 122
103ExprTuple109, 126
104ExprTuple121
105Literal
106ExprTuple110
107ExprTuple114
108Variable
109IndexedVarvariable: 111
index: 115
110ExprRangelambda_map: 113
start_index: 126
end_index: 114
111Variable
112ExprTuple115
113Lambdaparameter: 123
body: 116
114Variable
115Operationoperator: 117
operands: 118
116IndexedVarvariable: 119
index: 123
117Literal
118ExprTuple121, 122
119Variable
120ExprTuple123
121Variable
122Operationoperator: 124
operand: 126
123Variable
124Literal
125ExprTuple126
126Literal