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 import U_1_to_i, V_1_to_j
from proveit.logic import Equals, Forall, Implies
from proveit.numbers import 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 = [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()
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_{\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}
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: 7
operand: 2
1ExprTuple2
2Lambdaparameter: 73
body: 4
3ExprTuple73
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 11
6Operationoperator: 9
operands: 10
7Literal
8ExprTuple11
9Literal
10ExprTuple73, 12
11Lambdaparameters: 13
body: 14
12Operationoperator: 15
operands: 16
13ExprTuple44, 46
14Operationoperator: 17
operands: 18
15Literal
16ExprTuple19, 20
17Literal
18ExprTuple21, 22
19Literal
20Operationoperator: 23
operands: 24
21Operationoperator: 26
operands: 25
22Operationoperator: 26
operands: 27
23Literal
24ExprTuple28, 76
25ExprTuple29, 75
26Literal
27ExprTuple30, 31
28Literal
29Operationoperator: 34
operand: 36
30Operationoperator: 34
operand: 37
31Operationoperator: 34
operand: 38
32ExprTuple36
33ExprTuple37
34Literal
35ExprTuple38
36Operationoperator: 41
operands: 39
37Operationoperator: 41
operands: 40
38Operationoperator: 41
operands: 42
39ExprTuple44, 43
40ExprTuple44, 46
41Literal
42ExprTuple45, 46
43ExprTuple47
44ExprRangelambda_map: 48
start_index: 75
end_index: 49
45ExprTuple50
46ExprRangelambda_map: 51
start_index: 75
end_index: 52
47ExprRangelambda_map: 53
start_index: 75
end_index: 76
48Lambdaparameter: 74
body: 54
49Variable
50ExprRangelambda_map: 55
start_index: 75
end_index: 76
51Lambdaparameter: 74
body: 56
52Variable
53Lambdaparameter: 74
body: 57
54IndexedVarvariable: 58
index: 74
55Lambdaparameter: 74
body: 59
56IndexedVarvariable: 60
index: 74
57Operationoperator: 63
operands: 62
58Variable
59Operationoperator: 63
operands: 64
60Variable
61ExprTuple74
62NamedExprselement: 65
targets: 67
63Literal
64NamedExprselement: 66
targets: 67
65Operationoperator: 68
operands: 70
66Operationoperator: 69
operands: 70
67Operationoperator: 71
operands: 72
68Literal
69Literal
70NamedExprsstate: 73
part: 74
71Literal
72ExprTuple75, 76
73Variable
74Variable
75Literal
76Variable