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, U, m
from proveit.linear_algebra import ScalarMult, Unitary
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Exp, Mult, e, i, one, pi, two
from proveit.physics.quantum import Qmult, m_ket_domain, normalized_var_ket_u, var_ket_u, varphi
from proveit.physics.quantum.circuits import phase_kickback_circuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = Lambda(U, Conditional(Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [varphi], instance_expr = Equals(Prob(phase_kickback_circuit), one), condition = Equals(Qmult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, varphi)), var_ket_u))), domain = m_ket_domain, condition = normalized_var_ket_u), InSet(U, Unitary(Exp(two, m)))))
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())
U \mapsto \left\{\forall_{\lvert u \rangle \in \mathbb{C}^{2^{m}}~|~\left \|\lvert u \rangle\right \| = 1}~\left[\forall_{\varphi~|~\left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)}~\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \control{} \qw \qwx[1] & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U} & \qout{\lvert u \rangle}
} \end{array}\right) = 1\right)\right] \textrm{ if } U \in \textrm{U}\left(2^{m}\right)\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 101
body: 2
1ExprTuple101
2Conditionalvalue: 3
condition: 4
3Operationoperator: 14
operand: 7
4Operationoperator: 23
operands: 6
5ExprTuple7
6ExprTuple101, 8
7Lambdaparameter: 105
body: 9
8Operationoperator: 10
operand: 41
9Conditionalvalue: 12
condition: 13
10Literal
11ExprTuple41
12Operationoperator: 14
operand: 18
13Operationoperator: 16
operands: 17
14Literal
15ExprTuple18
16Literal
17ExprTuple19, 20
18Lambdaparameter: 133
body: 22
19Operationoperator: 23
operands: 24
20Operationoperator: 31
operands: 25
21ExprTuple133
22Conditionalvalue: 26
condition: 27
23Literal
24ExprTuple105, 28
25ExprTuple29, 127
26Operationoperator: 31
operands: 30
27Operationoperator: 31
operands: 32
28Operationoperator: 33
operands: 34
29Operationoperator: 35
operand: 105
30ExprTuple37, 127
31Literal
32ExprTuple38, 39
33Literal
34ExprTuple40, 41
35Literal
36ExprTuple105
37Operationoperator: 42
operand: 48
38Operationoperator: 44
operands: 45
39Operationoperator: 110
operands: 46
40Literal
41Operationoperator: 121
operands: 47
42Literal
43ExprTuple48
44Literal
45ExprTuple101, 105
46ExprTuple116, 105
47ExprTuple130, 118
48Operationoperator: 49
operands: 50
49Literal
50ExprTuple51, 52, 53
51ExprTuple54, 55
52ExprTuple56, 57
53ExprTuple58, 59
54Operationoperator: 91
operands: 60
55ExprRangelambda_map: 61
start_index: 127
end_index: 66
56Operationoperator: 82
operands: 62
57ExprRangelambda_map: 63
start_index: 127
end_index: 66
58Operationoperator: 97
operands: 64
59ExprRangelambda_map: 65
start_index: 127
end_index: 66
60NamedExprsstate: 67
61Lambdaparameter: 106
body: 68
62NamedExprselement: 69
targets: 70
63Lambdaparameter: 106
body: 71
64NamedExprsstate: 72
65Lambdaparameter: 106
body: 74
66Operationoperator: 112
operands: 75
67Operationoperator: 123
operand: 84
68Operationoperator: 82
operands: 77
69Literal
70Operationoperator: 78
operand: 130
71Operationoperator: 82
operands: 80
72Operationoperator: 110
operands: 81
73ExprTuple106
74Operationoperator: 82
operands: 83
75ExprTuple118, 127
76ExprTuple84
77NamedExprselement: 85
targets: 90
78Literal
79ExprTuple130
80NamedExprselement: 86
targets: 90
81ExprTuple87, 88
82Literal
83NamedExprselement: 89
targets: 90
84Literal
85Operationoperator: 91
operands: 98
86Operationoperator: 92
operands: 93
87Operationoperator: 119
operands: 94
88Operationoperator: 95
operands: 96
89Operationoperator: 97
operands: 98
90Operationoperator: 99
operands: 100
91Literal
92Literal
93NamedExprsoperation: 101
part: 106
94ExprTuple127, 102
95Literal
96ExprTuple103, 104
97Literal
98NamedExprsstate: 105
part: 106
99Literal
100ExprTuple130, 107
101Variable
102Operationoperator: 121
operands: 108
103Operationoperator: 123
operand: 115
104Operationoperator: 110
operands: 111
105Variable
106Variable
107Operationoperator: 112
operands: 113
108ExprTuple130, 114
109ExprTuple115
110Literal
111ExprTuple116, 117
112Literal
113ExprTuple118, 130
114Operationoperator: 119
operands: 120
115Literal
116Operationoperator: 121
operands: 122
117Operationoperator: 123
operand: 127
118Variable
119Literal
120ExprTuple127, 130
121Literal
122ExprTuple125, 126
123Literal
124ExprTuple127
125Literal
126Operationoperator: 128
operands: 129
127Literal
128Literal
129ExprTuple130, 131, 132, 133
130Literal
131Literal
132Literal
133Variable