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 U, m
from proveit.linear_algebra import ScalarMult, Unitary
from proveit.logic import Equals, Forall
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 = Forall(instance_param_or_params = [U], instance_expr = 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), domain = 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())
\forall_{U \in \textrm{U}\left(2^{m}\right)}~\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]\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: 16
operand: 2
1ExprTuple2
2Lambdaparameter: 103
body: 4
3ExprTuple103
4Conditionalvalue: 5
condition: 6
5Operationoperator: 16
operand: 9
6Operationoperator: 25
operands: 8
7ExprTuple9
8ExprTuple103, 10
9Lambdaparameter: 107
body: 11
10Operationoperator: 12
operand: 43
11Conditionalvalue: 14
condition: 15
12Literal
13ExprTuple43
14Operationoperator: 16
operand: 20
15Operationoperator: 18
operands: 19
16Literal
17ExprTuple20
18Literal
19ExprTuple21, 22
20Lambdaparameter: 135
body: 24
21Operationoperator: 25
operands: 26
22Operationoperator: 33
operands: 27
23ExprTuple135
24Conditionalvalue: 28
condition: 29
25Literal
26ExprTuple107, 30
27ExprTuple31, 129
28Operationoperator: 33
operands: 32
29Operationoperator: 33
operands: 34
30Operationoperator: 35
operands: 36
31Operationoperator: 37
operand: 107
32ExprTuple39, 129
33Literal
34ExprTuple40, 41
35Literal
36ExprTuple42, 43
37Literal
38ExprTuple107
39Operationoperator: 44
operand: 50
40Operationoperator: 46
operands: 47
41Operationoperator: 112
operands: 48
42Literal
43Operationoperator: 123
operands: 49
44Literal
45ExprTuple50
46Literal
47ExprTuple103, 107
48ExprTuple118, 107
49ExprTuple132, 120
50Operationoperator: 51
operands: 52
51Literal
52ExprTuple53, 54, 55
53ExprTuple56, 57
54ExprTuple58, 59
55ExprTuple60, 61
56Operationoperator: 93
operands: 62
57ExprRangelambda_map: 63
start_index: 129
end_index: 68
58Operationoperator: 84
operands: 64
59ExprRangelambda_map: 65
start_index: 129
end_index: 68
60Operationoperator: 99
operands: 66
61ExprRangelambda_map: 67
start_index: 129
end_index: 68
62NamedExprsstate: 69
63Lambdaparameter: 108
body: 70
64NamedExprselement: 71
targets: 72
65Lambdaparameter: 108
body: 73
66NamedExprsstate: 74
67Lambdaparameter: 108
body: 76
68Operationoperator: 114
operands: 77
69Operationoperator: 125
operand: 86
70Operationoperator: 84
operands: 79
71Literal
72Operationoperator: 80
operand: 132
73Operationoperator: 84
operands: 82
74Operationoperator: 112
operands: 83
75ExprTuple108
76Operationoperator: 84
operands: 85
77ExprTuple120, 129
78ExprTuple86
79NamedExprselement: 87
targets: 92
80Literal
81ExprTuple132
82NamedExprselement: 88
targets: 92
83ExprTuple89, 90
84Literal
85NamedExprselement: 91
targets: 92
86Literal
87Operationoperator: 93
operands: 100
88Operationoperator: 94
operands: 95
89Operationoperator: 121
operands: 96
90Operationoperator: 97
operands: 98
91Operationoperator: 99
operands: 100
92Operationoperator: 101
operands: 102
93Literal
94Literal
95NamedExprsoperation: 103
part: 108
96ExprTuple129, 104
97Literal
98ExprTuple105, 106
99Literal
100NamedExprsstate: 107
part: 108
101Literal
102ExprTuple132, 109
103Variable
104Operationoperator: 123
operands: 110
105Operationoperator: 125
operand: 117
106Operationoperator: 112
operands: 113
107Variable
108Variable
109Operationoperator: 114
operands: 115
110ExprTuple132, 116
111ExprTuple117
112Literal
113ExprTuple118, 119
114Literal
115ExprTuple120, 132
116Operationoperator: 121
operands: 122
117Literal
118Operationoperator: 123
operands: 124
119Operationoperator: 125
operand: 129
120Variable
121Literal
122ExprTuple129, 132
123Literal
124ExprTuple127, 128
125Literal
126ExprTuple129
127Literal
128Operationoperator: 130
operands: 131
129Literal
130Literal
131ExprTuple132, 133, 134, 135
132Literal
133Literal
134Literal
135Variable