logo

Expression of type Conditional

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, 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, 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}")
expr = Conditional(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 = 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(), domain = NaturalPos).with_wrapping(), InSet(m, NaturalPos))
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\{\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{
\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}\right]\end{array} \textrm{ if } m \in \mathbb{N}^+\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 21
operand: 5
2Operationoperator: 62
operands: 4
3ExprTuple5
4ExprTuple131, 27
5Lambdaparameters: 6
body: 7
6ExprTuple8
7Conditionalvalue: 9
condition: 10
8ExprRangelambda_map: 11
start_index: 143
end_index: 131
9Operationoperator: 21
operand: 14
10Operationoperator: 49
operands: 13
11Lambdaparameter: 140
body: 97
12ExprTuple14
13ExprTuple15
14Lambdaparameters: 123
body: 16
15ExprRangelambda_map: 17
start_index: 143
end_index: 131
16Conditionalvalue: 18
condition: 19
17Lambdaparameter: 140
body: 20
18Operationoperator: 21
operand: 25
19Operationoperator: 49
operands: 23
20Operationoperator: 62
operands: 24
21Literal
22ExprTuple25
23ExprTuple26
24ExprTuple97, 27
25Lambdaparameters: 28
body: 29
26ExprRangelambda_map: 30
start_index: 143
end_index: 131
27Literal
28ExprTuple31
29Conditionalvalue: 32
condition: 33
30Lambdaparameter: 140
body: 34
31ExprRangelambda_map: 35
start_index: 84
end_index: 131
32Operationoperator: 36
operands: 37
33Operationoperator: 49
operands: 38
34Operationoperator: 62
operands: 39
35Lambdaparameter: 140
body: 85
36Literal
37ExprTuple40, 41
38ExprTuple42, 43
39ExprTuple133, 44
40Operationoperator: 46
operand: 53
41Operationoperator: 46
operand: 54
42ExprRangelambda_map: 48
start_index: 84
end_index: 131
43Operationoperator: 49
operands: 50
44Operationoperator: 51
operands: 52
45ExprTuple53
46Literal
47ExprTuple54
48Lambdaparameter: 140
body: 55
49Literal
50ExprTuple56, 57
51Literal
52ExprTuple58, 59
53ExprTuple60
54ExprTuple61
55Operationoperator: 62
operands: 63
56Operationoperator: 77
operands: 64
57ExprRangelambda_map: 65
start_index: 143
end_index: 131
58Literal
59Operationoperator: 66
operands: 67
60ExprRangelambda_map: 68
start_index: 143
end_index: 131
61ExprRangelambda_map: 69
start_index: 143
end_index: 131
62Literal
63ExprTuple85, 70
64ExprTuple71, 84
65Lambdaparameter: 140
body: 72
66Literal
67ExprTuple73, 97
68Lambdaparameter: 138
body: 74
69Lambdaparameter: 125
body: 75
70Literal
71IndexedVarvariable: 128
index: 84
72Operationoperator: 77
operands: 78
73Literal
74ExprRangelambda_map: 79
start_index: 143
end_index: 80
75ExprRangelambda_map: 81
start_index: 82
end_index: 83
76ExprTuple84
77Literal
78ExprTuple85, 86
79Lambdaparameter: 140
body: 87
80IndexedVarvariable: 104
index: 138
81Lambdaparameter: 138
body: 88
82Operationoperator: 134
operands: 89
83IndexedVarvariable: 128
index: 125
84Literal
85IndexedVarvariable: 128
index: 140
86Operationoperator: 134
operands: 91
87Operationoperator: 93
operands: 92
88Operationoperator: 93
operands: 94
89ExprTuple95, 143
90ExprTuple125
91ExprTuple96, 97
92NamedExprselement: 98
targets: 99
93Literal
94NamedExprselement: 100
targets: 101
95IndexedVarvariable: 128
index: 111
96IndexedVarvariable: 128
index: 112
97IndexedVarvariable: 104
index: 140
98Operationoperator: 107
operands: 105
99Operationoperator: 109
operands: 106
100Operationoperator: 107
operands: 108
101Operationoperator: 109
operands: 110
102ExprTuple111
103ExprTuple112
104Variable
105NamedExprsstate: 113
part: 140
106ExprTuple114, 115
107Literal
108NamedExprsstate: 116
part: 138
109Literal
110ExprTuple143, 117
111Operationoperator: 134
operands: 118
112Operationoperator: 134
operands: 119
113IndexedVarvariable: 136
index: 138
114Operationoperator: 134
operands: 120
115IndexedVarvariable: 128
index: 138
116Operationoperator: 122
operands: 123
117IndexedVarvariable: 128
index: 131
118ExprTuple125, 139
119ExprTuple140, 139
120ExprTuple126, 143
121ExprTuple138
122Literal
123ExprTuple127
124ExprTuple131
125Variable
126IndexedVarvariable: 128
index: 132
127ExprRangelambda_map: 130
start_index: 143
end_index: 131
128Variable
129ExprTuple132
130Lambdaparameter: 140
body: 133
131Variable
132Operationoperator: 134
operands: 135
133IndexedVarvariable: 136
index: 140
134Literal
135ExprTuple138, 139
136Variable
137ExprTuple140
138Variable
139Operationoperator: 141
operand: 143
140Variable
141Literal
142ExprTuple143
143Literal