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 i, j, m
from proveit.core_expr_types import U_1_to_i, V_1_to_j
from proveit.logic import Equals, Forall, Implies
from proveit.numbers import NaturalPos, one
from proveit.physics.quantum import m_ket_domain, var_ket_psi
from proveit.physics.quantum.circuits import circuit_Ui_Vj, circuit_Ui_psi_m, circuit_psi_m_Vj
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = Forall(instance_param_or_params = [i, j, m], instance_expr = Forall(instance_param_or_params = [var_ket_psi], instance_expr = Forall(instance_param_or_params = [U_1_to_i, V_1_to_j], instance_expr = Implies(Equals(Prob(circuit_Ui_psi_m), one), Equals(Prob(circuit_Ui_Vj), Prob(circuit_psi_m_Vj)).with_wrapping_at(2)).with_wrapping_at(2)).with_wrapping(), domain = m_ket_domain).with_wrapping(), domain = NaturalPos).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_{i, j, m \in \mathbb{N}^+}~\\
\left[\begin{array}{l}\forall_{\lvert \psi \rangle \in \mathbb{C}^{2^{m}}}~\\
\left[\begin{array}{l}\forall_{U_{1}, U_{2}, \ldots, U_{i}, V_{1}, V_{2}, \ldots, V_{j}}~\\
\left(\begin{array}{c} \begin{array}{l} \left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \gate{\begin{array}{c} \uparrow \\U_{1} \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\\cdots \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\U_{i} \\ \downarrow\end{array}} & \qout{\lvert \psi \rangle}
} \end{array}\right) = 1\right) \Rightarrow  \\ \left(\begin{array}{c} \begin{array}{l} \textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \gate{\begin{array}{c} \uparrow \\U_{1} \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\U_{2} \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\\cdots \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\U_{i} \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\V_{1} \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\V_{2} \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\\cdots \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\V_{j} \\ \downarrow\end{array}} & \qw
} \end{array}\right) =  \\ \textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi \rangle} & \gate{\begin{array}{c} \uparrow \\V_{1} \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\\cdots \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\V_{j} \\ \downarrow\end{array}} & { /^{m} } \qw
} \end{array}\right) \end{array} \end{array}\right) \end{array} \end{array}\right)\end{array}\right]\end{array}\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: 22
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple64, 67, 91
4Conditionalvalue: 5
condition: 6
5Operationoperator: 22
operand: 10
6Operationoperator: 8
operands: 9
7ExprTuple10
8Literal
9ExprTuple11, 12, 13
10Lambdaparameter: 88
body: 15
11Operationoperator: 24
operands: 16
12Operationoperator: 24
operands: 17
13Operationoperator: 24
operands: 18
14ExprTuple88
15Conditionalvalue: 19
condition: 20
16ExprTuple64, 21
17ExprTuple67, 21
18ExprTuple91, 21
19Operationoperator: 22
operand: 26
20Operationoperator: 24
operands: 25
21Literal
22Literal
23ExprTuple26
24Literal
25ExprTuple88, 27
26Lambdaparameters: 28
body: 29
27Operationoperator: 30
operands: 31
28ExprTuple59, 61
29Operationoperator: 32
operands: 33
30Literal
31ExprTuple34, 35
32Literal
33ExprTuple36, 37
34Literal
35Operationoperator: 38
operands: 39
36Operationoperator: 41
operands: 40
37Operationoperator: 41
operands: 42
38Literal
39ExprTuple43, 91
40ExprTuple44, 90
41Literal
42ExprTuple45, 46
43Literal
44Operationoperator: 49
operand: 51
45Operationoperator: 49
operand: 52
46Operationoperator: 49
operand: 53
47ExprTuple51
48ExprTuple52
49Literal
50ExprTuple53
51Operationoperator: 56
operands: 54
52Operationoperator: 56
operands: 55
53Operationoperator: 56
operands: 57
54ExprTuple59, 58
55ExprTuple59, 61
56Literal
57ExprTuple60, 61
58ExprTuple62
59ExprRangelambda_map: 63
start_index: 90
end_index: 64
60ExprTuple65
61ExprRangelambda_map: 66
start_index: 90
end_index: 67
62ExprRangelambda_map: 68
start_index: 90
end_index: 91
63Lambdaparameter: 89
body: 69
64Variable
65ExprRangelambda_map: 70
start_index: 90
end_index: 91
66Lambdaparameter: 89
body: 71
67Variable
68Lambdaparameter: 89
body: 72
69IndexedVarvariable: 73
index: 89
70Lambdaparameter: 89
body: 74
71IndexedVarvariable: 75
index: 89
72Operationoperator: 78
operands: 77
73Variable
74Operationoperator: 78
operands: 79
75Variable
76ExprTuple89
77NamedExprselement: 80
targets: 82
78Literal
79NamedExprselement: 81
targets: 82
80Operationoperator: 83
operands: 85
81Operationoperator: 84
operands: 85
82Operationoperator: 86
operands: 87
83Literal
84Literal
85NamedExprsstate: 88
part: 89
86Literal
87ExprTuple90, 91
88Variable
89Variable
90Literal
91Variable