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 Forall
from proveit.numbers import Add, Interval, Natural, one, subtract
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 = [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()
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_{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}
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: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameters: 4
body: 5
4ExprTuple6
5Conditionalvalue: 7
condition: 8
6ExprRangelambda_map: 9
start_index: 49
end_index: 96
7Operationoperator: 10
operands: 11
8Operationoperator: 21
operands: 12
9Lambdaparameter: 105
body: 50
10Literal
11ExprTuple13, 14
12ExprTuple15, 16
13Operationoperator: 18
operand: 23
14Operationoperator: 18
operand: 24
15ExprRangelambda_map: 20
start_index: 49
end_index: 96
16Operationoperator: 21
operands: 22
17ExprTuple23
18Literal
19ExprTuple24
20Lambdaparameter: 105
body: 25
21Literal
22ExprTuple26, 27
23ExprTuple28
24ExprTuple29
25Operationoperator: 30
operands: 31
26Operationoperator: 42
operands: 32
27ExprRangelambda_map: 33
start_index: 108
end_index: 96
28ExprRangelambda_map: 34
start_index: 108
end_index: 96
29ExprRangelambda_map: 35
start_index: 108
end_index: 96
30Literal
31ExprTuple50, 36
32ExprTuple37, 49
33Lambdaparameter: 105
body: 38
34Lambdaparameter: 103
body: 39
35Lambdaparameter: 90
body: 40
36Literal
37IndexedVarvariable: 93
index: 49
38Operationoperator: 42
operands: 43
39ExprRangelambda_map: 44
start_index: 108
end_index: 45
40ExprRangelambda_map: 46
start_index: 47
end_index: 48
41ExprTuple49
42Literal
43ExprTuple50, 51
44Lambdaparameter: 105
body: 52
45IndexedVarvariable: 69
index: 103
46Lambdaparameter: 103
body: 53
47Operationoperator: 99
operands: 54
48IndexedVarvariable: 93
index: 90
49Literal
50IndexedVarvariable: 93
index: 105
51Operationoperator: 99
operands: 56
52Operationoperator: 58
operands: 57
53Operationoperator: 58
operands: 59
54ExprTuple60, 108
55ExprTuple90
56ExprTuple61, 62
57NamedExprselement: 63
targets: 64
58Literal
59NamedExprselement: 65
targets: 66
60IndexedVarvariable: 93
index: 76
61IndexedVarvariable: 93
index: 77
62IndexedVarvariable: 69
index: 105
63Operationoperator: 72
operands: 70
64Operationoperator: 74
operands: 71
65Operationoperator: 72
operands: 73
66Operationoperator: 74
operands: 75
67ExprTuple76
68ExprTuple77
69Variable
70NamedExprsstate: 78
part: 105
71ExprTuple79, 80
72Literal
73NamedExprsstate: 81
part: 103
74Literal
75ExprTuple108, 82
76Operationoperator: 99
operands: 83
77Operationoperator: 99
operands: 84
78IndexedVarvariable: 101
index: 103
79Operationoperator: 99
operands: 85
80IndexedVarvariable: 93
index: 103
81Operationoperator: 87
operands: 88
82IndexedVarvariable: 93
index: 96
83ExprTuple90, 104
84ExprTuple105, 104
85ExprTuple91, 108
86ExprTuple103
87Literal
88ExprTuple92
89ExprTuple96
90Variable
91IndexedVarvariable: 93
index: 97
92ExprRangelambda_map: 95
start_index: 108
end_index: 96
93Variable
94ExprTuple97
95Lambdaparameter: 105
body: 98
96Variable
97Operationoperator: 99
operands: 100
98IndexedVarvariable: 101
index: 105
99Literal
100ExprTuple103, 104
101Variable
102ExprTuple105
103Variable
104Operationoperator: 106
operand: 108
105Variable
106Literal
107ExprTuple108
108Literal