logo

Expression of type Lambda

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 Conditional, Lambda, i, j, m
from proveit.core_expr_types import U_1_to_i, V_1_to_j
from proveit.logic import And, Equals, Forall, Implies, InSet
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 = Lambda([i, j, m], Conditional(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(), And(InSet(i, NaturalPos), InSet(j, NaturalPos), InSet(m, 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())
\left(i, j, m\right) \mapsto \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} \textrm{ if } i \in \mathbb{N}^+ ,  j \in \mathbb{N}^+ ,  m \in \mathbb{N}^+\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 1
body: 2
1ExprTuple62, 65, 89
2Conditionalvalue: 3
condition: 4
3Operationoperator: 20
operand: 8
4Operationoperator: 6
operands: 7
5ExprTuple8
6Literal
7ExprTuple9, 10, 11
8Lambdaparameter: 86
body: 13
9Operationoperator: 22
operands: 14
10Operationoperator: 22
operands: 15
11Operationoperator: 22
operands: 16
12ExprTuple86
13Conditionalvalue: 17
condition: 18
14ExprTuple62, 19
15ExprTuple65, 19
16ExprTuple89, 19
17Operationoperator: 20
operand: 24
18Operationoperator: 22
operands: 23
19Literal
20Literal
21ExprTuple24
22Literal
23ExprTuple86, 25
24Lambdaparameters: 26
body: 27
25Operationoperator: 28
operands: 29
26ExprTuple57, 59
27Operationoperator: 30
operands: 31
28Literal
29ExprTuple32, 33
30Literal
31ExprTuple34, 35
32Literal
33Operationoperator: 36
operands: 37
34Operationoperator: 39
operands: 38
35Operationoperator: 39
operands: 40
36Literal
37ExprTuple41, 89
38ExprTuple42, 88
39Literal
40ExprTuple43, 44
41Literal
42Operationoperator: 47
operand: 49
43Operationoperator: 47
operand: 50
44Operationoperator: 47
operand: 51
45ExprTuple49
46ExprTuple50
47Literal
48ExprTuple51
49Operationoperator: 54
operands: 52
50Operationoperator: 54
operands: 53
51Operationoperator: 54
operands: 55
52ExprTuple57, 56
53ExprTuple57, 59
54Literal
55ExprTuple58, 59
56ExprTuple60
57ExprRangelambda_map: 61
start_index: 88
end_index: 62
58ExprTuple63
59ExprRangelambda_map: 64
start_index: 88
end_index: 65
60ExprRangelambda_map: 66
start_index: 88
end_index: 89
61Lambdaparameter: 87
body: 67
62Variable
63ExprRangelambda_map: 68
start_index: 88
end_index: 89
64Lambdaparameter: 87
body: 69
65Variable
66Lambdaparameter: 87
body: 70
67IndexedVarvariable: 71
index: 87
68Lambdaparameter: 87
body: 72
69IndexedVarvariable: 73
index: 87
70Operationoperator: 76
operands: 75
71Variable
72Operationoperator: 76
operands: 77
73Variable
74ExprTuple87
75NamedExprselement: 78
targets: 80
76Literal
77NamedExprselement: 79
targets: 80
78Operationoperator: 81
operands: 83
79Operationoperator: 82
operands: 83
80Operationoperator: 84
operands: 85
81Literal
82Literal
83NamedExprsstate: 86
part: 87
84Literal
85ExprTuple88, 89
86Variable
87Variable
88Literal
89Variable