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 k, l, m
from proveit.core_expr_types.expr_arrays import A11_to_Akl
from proveit.logic import Equals, Forall
from proveit.numbers import NaturalPos
from proveit.physics.quantum import l_ket_domain, m_ket_domain, var_ket_psi, var_ket_u, var_ket_v
from proveit.physics.quantum.circuits import circuit__u_Akl_v, circuit__u_Akl_v__psi_m
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = Forall(instance_param_or_params = [k, l, m], instance_expr = Forall(instance_param_or_params = [var_ket_u, var_ket_v], instance_expr = Forall(instance_param_or_params = [var_ket_psi], instance_expr = Forall(instance_param_or_params = [A11_to_Akl], instance_expr = Equals(Prob(circuit__u_Akl_v), Prob(circuit__u_Akl_v__psi_m)).with_wrapping_at(2)).with_wrapping(), domain = m_ket_domain), domain = l_ket_domain), domain = 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())
\forall_{k, l, m \in \mathbb{N}^+}~\left[\forall_{\lvert u \rangle, \lvert v \rangle \in \mathbb{C}^{2^{l}}}~\left[\forall_{\lvert \psi \rangle \in \mathbb{C}^{2^{m}}}~\left[\begin{array}{l}\forall_{A_{1, 1}, A_{1, 2}, \ldots, A_{1, l}, A_{2, 1}, A_{2, 2}, \ldots, A_{2, l}, \ldots\ldots, A_{k, 1}, A_{k, 2}, \ldots, A_{k, l}}~\\
\left(\begin{array}{c} \begin{array}{l} \textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\multiqin{3}{\lvert u \rangle} & \gate{A_{1, 1}} \qwx[1] & \gate{A_{2, 1}} \qwx[1] & \gate{\cdots} \qwx[1] & \gate{A_{k, 1}} \qwx[1] & \multiqout{3}{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{A_{1, 2}} \qwx[1] & \gate{A_{2, 2}} \qwx[1] & \gate{\cdots} \qwx[1] & \gate{A_{k, 2}} \qwx[1] & \ghostqout{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} \qwx[1] & \ghostqout{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{A_{1, l}} & \gate{A_{2, l}} & \gate{\cdots} & \gate{A_{k, l}} & \ghostqout{\lvert v \rangle}
} \end{array}\right) =  \\ \textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\multiqin{3}{\lvert u \rangle} & \gate{A_{1, 1}} \qwx[1] & \gate{A_{2, 1}} \qwx[1] & \gate{\cdots} \qwx[1] & \gate{A_{k, 1}} \qwx[1] & \multiqout{3}{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{A_{1, 2}} \qwx[1] & \gate{A_{2, 2}} \qwx[1] & \gate{\cdots} \qwx[1] & \gate{A_{k, 2}} \qwx[1] & \ghostqout{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} \qwx[1] & \ghostqout{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{A_{1, l}} & \gate{A_{2, l}} & \gate{\cdots} & \gate{A_{k, l}} & \ghostqout{\lvert v \rangle} \\
\qin{\lvert \psi \rangle} & { /^{m} } \qw & { /^{m} } \qw & \gate{\cdots} & { /^{m} } \qw & \qout{\lvert \psi \rangle}
} \end{array}\right) \end{array} \end{array}\right)\end{array}\right]\right]\right]
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('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: 34
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple76, 132, 133
4Conditionalvalue: 5
condition: 6
5Operationoperator: 34
operand: 9
6Operationoperator: 22
operands: 8
7ExprTuple9
8ExprTuple10, 11, 12
9Lambdaparameters: 13
body: 14
10Operationoperator: 36
operands: 15
11Operationoperator: 36
operands: 16
12Operationoperator: 36
operands: 17
13ExprTuple120, 123
14Conditionalvalue: 18
condition: 19
15ExprTuple76, 20
16ExprTuple132, 20
17ExprTuple133, 20
18Operationoperator: 34
operand: 24
19Operationoperator: 22
operands: 23
20Literal
21ExprTuple24
22Literal
23ExprTuple25, 26
24Lambdaparameter: 124
body: 28
25Operationoperator: 36
operands: 29
26Operationoperator: 36
operands: 30
27ExprTuple124
28Conditionalvalue: 31
condition: 32
29ExprTuple120, 33
30ExprTuple123, 33
31Operationoperator: 34
operand: 39
32Operationoperator: 36
operands: 37
33Operationoperator: 44
operands: 38
34Literal
35ExprTuple39
36Literal
37ExprTuple124, 40
38ExprTuple50, 41
39Lambdaparameters: 42
body: 43
40Operationoperator: 44
operands: 45
41Operationoperator: 55
operands: 46
42ExprTuple47
43Operationoperator: 48
operands: 49
44Literal
45ExprTuple50, 51
46ExprTuple60, 132
47ExprRangelambda_map: 52
start_index: 131
end_index: 76
48Literal
49ExprTuple53, 54
50Literal
51Operationoperator: 55
operands: 56
52Lambdaparameter: 121
body: 88
53Operationoperator: 58
operand: 61
54Operationoperator: 58
operand: 62
55Literal
56ExprTuple60, 133
57ExprTuple61
58Literal
59ExprTuple62
60Literal
61Operationoperator: 64
operands: 63
62Operationoperator: 64
operands: 65
63ExprTuple66, 67, 68
64Literal
65ExprTuple69, 70, 71
66ExprTuple73
67ExprRangelambda_map: 72
start_index: 131
end_index: 76
68ExprTuple77
69ExprTuple73, 74
70ExprRangelambda_map: 75
start_index: 131
end_index: 76
71ExprTuple77, 78
72Lambdaparameter: 121
body: 79
73ExprRangelambda_map: 80
start_index: 131
end_index: 132
74ExprRangelambda_map: 81
start_index: 131
end_index: 133
75Lambdaparameter: 121
body: 83
76Variable
77ExprRangelambda_map: 84
start_index: 131
end_index: 132
78ExprRangelambda_map: 85
start_index: 131
end_index: 133
79ExprTuple88
80Lambdaparameter: 125
body: 86
81Lambdaparameter: 125
body: 87
82ExprTuple121
83ExprTuple88, 89
84Lambdaparameter: 125
body: 90
85Lambdaparameter: 125
body: 91
86Operationoperator: 97
operands: 92
87Operationoperator: 97
operands: 93
88ExprRangelambda_map: 94
start_index: 131
end_index: 132
89ExprRangelambda_map: 95
start_index: 131
end_index: 133
90Operationoperator: 97
operands: 96
91Operationoperator: 97
operands: 98
92NamedExprselement: 99
targets: 105
93NamedExprselement: 100
targets: 107
94Lambdaparameter: 125
body: 101
95Lambdaparameter: 125
body: 103
96NamedExprselement: 104
targets: 105
97Literal
98NamedExprselement: 106
targets: 107
99Operationoperator: 109
operands: 108
100Operationoperator: 109
operands: 117
101IndexedVarvariable: 110
indices: 111
102ExprTuple125
103Operationoperator: 112
operands: 113
104Operationoperator: 116
operands: 114
105Operationoperator: 118
operands: 115
106Operationoperator: 116
operands: 117
107Operationoperator: 118
operands: 119
108NamedExprsstate: 120
part: 125
109Literal
110Variable
111ExprTuple121, 125
112Literal
113NamedExprsoperation: 122
114NamedExprsstate: 123
part: 125
115ExprTuple131, 132
116Literal
117NamedExprsstate: 124
part: 125
118Literal
119ExprTuple126, 127
120Variable
121Variable
122Literal
123Variable
124Variable
125Variable
126Operationoperator: 129
operands: 128
127Operationoperator: 129
operands: 130
128ExprTuple132, 131
129Literal
130ExprTuple132, 133
131Literal
132Variable
133Variable