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.core_expr_types.expr_arrays import A11_to_Akl
from proveit.logic import Equals, Forall
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__psi_m__u_Akl_v, circuit__u_Akl_v
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
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__psi_m__u_Akl_v)).with_wrapping_at(2)).with_wrapping(), domain = m_ket_domain), domain = l_ket_domain)
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_{\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{
\qin{\lvert \psi \rangle} & { /^{m} } \qw & { /^{m} } \qw & \gate{\cdots} & { /^{m} } \qw & \qout{\lvert \psi \rangle} \\
\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) \end{array} \end{array}\right)\end{array}\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: 20
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple116, 120
4Conditionalvalue: 5
condition: 6
5Operationoperator: 20
operand: 10
6Operationoperator: 8
operands: 9
7ExprTuple10
8Literal
9ExprTuple11, 12
10Lambdaparameter: 119
body: 14
11Operationoperator: 22
operands: 15
12Operationoperator: 22
operands: 16
13ExprTuple119
14Conditionalvalue: 17
condition: 18
15ExprTuple116, 19
16ExprTuple120, 19
17Operationoperator: 20
operand: 25
18Operationoperator: 22
operands: 23
19Operationoperator: 30
operands: 24
20Literal
21ExprTuple25
22Literal
23ExprTuple119, 26
24ExprTuple36, 27
25Lambdaparameters: 28
body: 29
26Operationoperator: 30
operands: 31
27Operationoperator: 41
operands: 32
28ExprTuple33
29Operationoperator: 34
operands: 35
30Literal
31ExprTuple36, 37
32ExprTuple46, 129
33ExprRangelambda_map: 38
start_index: 127
end_index: 64
34Literal
35ExprTuple39, 40
36Literal
37Operationoperator: 41
operands: 42
38Lambdaparameter: 118
body: 81
39Operationoperator: 44
operand: 47
40Operationoperator: 44
operand: 48
41Literal
42ExprTuple46, 128
43ExprTuple47
44Literal
45ExprTuple48
46Literal
47Operationoperator: 50
operands: 49
48Operationoperator: 50
operands: 51
49ExprTuple52, 53, 54
50Literal
51ExprTuple55, 56, 57
52ExprTuple58
53ExprRangelambda_map: 59
start_index: 127
end_index: 64
54ExprTuple60
55ExprTuple61, 62
56ExprRangelambda_map: 63
start_index: 127
end_index: 64
57ExprTuple65, 66
58ExprRangelambda_map: 67
start_index: 127
end_index: 129
59Lambdaparameter: 118
body: 68
60ExprRangelambda_map: 69
start_index: 127
end_index: 129
61ExprRangelambda_map: 70
start_index: 127
end_index: 128
62ExprRangelambda_map: 71
start_index: 127
end_index: 129
63Lambdaparameter: 118
body: 73
64Variable
65ExprRangelambda_map: 74
start_index: 127
end_index: 128
66ExprRangelambda_map: 75
start_index: 127
end_index: 129
67Lambdaparameter: 121
body: 76
68ExprTuple81
69Lambdaparameter: 121
body: 77
70Lambdaparameter: 121
body: 78
71Lambdaparameter: 121
body: 79
72ExprTuple118
73ExprTuple80, 81
74Lambdaparameter: 121
body: 82
75Lambdaparameter: 121
body: 83
76Operationoperator: 91
operands: 84
77Operationoperator: 91
operands: 85
78Operationoperator: 91
operands: 86
79Operationoperator: 91
operands: 87
80ExprRangelambda_map: 88
start_index: 127
end_index: 128
81ExprRangelambda_map: 89
start_index: 127
end_index: 129
82Operationoperator: 91
operands: 90
83Operationoperator: 91
operands: 92
84NamedExprselement: 95
targets: 93
85NamedExprselement: 101
targets: 93
86NamedExprselement: 94
targets: 100
87NamedExprselement: 95
targets: 102
88Lambdaparameter: 121
body: 96
89Lambdaparameter: 121
body: 98
90NamedExprselement: 99
targets: 100
91Literal
92NamedExprselement: 101
targets: 102
93Operationoperator: 114
operands: 103
94Operationoperator: 104
operands: 110
95Operationoperator: 104
operands: 105
96Operationoperator: 106
operands: 107
97ExprTuple121
98IndexedVarvariable: 108
indices: 109
99Operationoperator: 112
operands: 110
100Operationoperator: 114
operands: 111
101Operationoperator: 112
operands: 113
102Operationoperator: 114
operands: 115
103ExprTuple127, 129
104Literal
105NamedExprsstate: 116
part: 121
106Literal
107NamedExprsoperation: 117
108Variable
109ExprTuple118, 121
110NamedExprsstate: 119
part: 121
111ExprTuple127, 128
112Literal
113NamedExprsstate: 120
part: 121
114Literal
115ExprTuple122, 123
116Variable
117Literal
118Variable
119Variable
120Variable
121Variable
122Operationoperator: 125
operands: 124
123Operationoperator: 125
operands: 126
124ExprTuple128, 127
125Literal
126ExprTuple128, 129
127Literal
128Variable
129Variable