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__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 = [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)
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{
\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]
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
3ExprTuple106, 109
4Conditionalvalue: 5
condition: 6
5Operationoperator: 20
operand: 10
6Operationoperator: 8
operands: 9
7ExprTuple10
8Literal
9ExprTuple11, 12
10Lambdaparameter: 110
body: 14
11Operationoperator: 22
operands: 15
12Operationoperator: 22
operands: 16
13ExprTuple110
14Conditionalvalue: 17
condition: 18
15ExprTuple106, 19
16ExprTuple109, 19
17Operationoperator: 20
operand: 25
18Operationoperator: 22
operands: 23
19Operationoperator: 30
operands: 24
20Literal
21ExprTuple25
22Literal
23ExprTuple110, 26
24ExprTuple36, 27
25Lambdaparameters: 28
body: 29
26Operationoperator: 30
operands: 31
27Operationoperator: 41
operands: 32
28ExprTuple33
29Operationoperator: 34
operands: 35
30Literal
31ExprTuple36, 37
32ExprTuple46, 118
33ExprRangelambda_map: 38
start_index: 117
end_index: 62
34Literal
35ExprTuple39, 40
36Literal
37Operationoperator: 41
operands: 42
38Lambdaparameter: 107
body: 74
39Operationoperator: 44
operand: 47
40Operationoperator: 44
operand: 48
41Literal
42ExprTuple46, 119
43ExprTuple47
44Literal
45ExprTuple48
46Literal
47Operationoperator: 50
operands: 49
48Operationoperator: 50
operands: 51
49ExprTuple52, 53, 54
50Literal
51ExprTuple55, 56, 57
52ExprTuple59
53ExprRangelambda_map: 58
start_index: 117
end_index: 62
54ExprTuple63
55ExprTuple59, 60
56ExprRangelambda_map: 61
start_index: 117
end_index: 62
57ExprTuple63, 64
58Lambdaparameter: 107
body: 65
59ExprRangelambda_map: 66
start_index: 117
end_index: 118
60ExprRangelambda_map: 67
start_index: 117
end_index: 119
61Lambdaparameter: 107
body: 69
62Variable
63ExprRangelambda_map: 70
start_index: 117
end_index: 118
64ExprRangelambda_map: 71
start_index: 117
end_index: 119
65ExprTuple74
66Lambdaparameter: 111
body: 72
67Lambdaparameter: 111
body: 73
68ExprTuple107
69ExprTuple74, 75
70Lambdaparameter: 111
body: 76
71Lambdaparameter: 111
body: 77
72Operationoperator: 83
operands: 78
73Operationoperator: 83
operands: 79
74ExprRangelambda_map: 80
start_index: 117
end_index: 118
75ExprRangelambda_map: 81
start_index: 117
end_index: 119
76Operationoperator: 83
operands: 82
77Operationoperator: 83
operands: 84
78NamedExprselement: 85
targets: 91
79NamedExprselement: 86
targets: 93
80Lambdaparameter: 111
body: 87
81Lambdaparameter: 111
body: 89
82NamedExprselement: 90
targets: 91
83Literal
84NamedExprselement: 92
targets: 93
85Operationoperator: 95
operands: 94
86Operationoperator: 95
operands: 103
87IndexedVarvariable: 96
indices: 97
88ExprTuple111
89Operationoperator: 98
operands: 99
90Operationoperator: 102
operands: 100
91Operationoperator: 104
operands: 101
92Operationoperator: 102
operands: 103
93Operationoperator: 104
operands: 105
94NamedExprsstate: 106
part: 111
95Literal
96Variable
97ExprTuple107, 111
98Literal
99NamedExprsoperation: 108
100NamedExprsstate: 109
part: 111
101ExprTuple117, 118
102Literal
103NamedExprsstate: 110
part: 111
104Literal
105ExprTuple112, 113
106Variable
107Variable
108Literal
109Variable
110Variable
111Variable
112Operationoperator: 115
operands: 114
113Operationoperator: 115
operands: 116
114ExprTuple118, 117
115Literal
116ExprTuple118, 119
117Literal
118Variable
119Variable