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
from proveit.linear_algebra import ScalarMult
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 = [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)
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_{\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]
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: 6
operand: 2
1ExprTuple2
2Lambdaparameter: 97
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operand: 10
5Operationoperator: 8
operands: 9
6Literal
7ExprTuple10
8Literal
9ExprTuple11, 12
10Lambdaparameter: 125
body: 14
11Operationoperator: 15
operands: 16
12Operationoperator: 23
operands: 17
13ExprTuple125
14Conditionalvalue: 18
condition: 19
15Literal
16ExprTuple97, 20
17ExprTuple21, 119
18Operationoperator: 23
operands: 22
19Operationoperator: 23
operands: 24
20Operationoperator: 25
operands: 26
21Operationoperator: 27
operand: 97
22ExprTuple29, 119
23Literal
24ExprTuple30, 31
25Literal
26ExprTuple32, 33
27Literal
28ExprTuple97
29Operationoperator: 34
operand: 40
30Operationoperator: 36
operands: 37
31Operationoperator: 102
operands: 38
32Literal
33Operationoperator: 113
operands: 39
34Literal
35ExprTuple40
36Literal
37ExprTuple93, 97
38ExprTuple108, 97
39ExprTuple122, 110
40Operationoperator: 41
operands: 42
41Literal
42ExprTuple43, 44, 45
43ExprTuple46, 47
44ExprTuple48, 49
45ExprTuple50, 51
46Operationoperator: 83
operands: 52
47ExprRangelambda_map: 53
start_index: 119
end_index: 58
48Operationoperator: 74
operands: 54
49ExprRangelambda_map: 55
start_index: 119
end_index: 58
50Operationoperator: 89
operands: 56
51ExprRangelambda_map: 57
start_index: 119
end_index: 58
52NamedExprsstate: 59
53Lambdaparameter: 98
body: 60
54NamedExprselement: 61
targets: 62
55Lambdaparameter: 98
body: 63
56NamedExprsstate: 64
57Lambdaparameter: 98
body: 66
58Operationoperator: 104
operands: 67
59Operationoperator: 115
operand: 76
60Operationoperator: 74
operands: 69
61Literal
62Operationoperator: 70
operand: 122
63Operationoperator: 74
operands: 72
64Operationoperator: 102
operands: 73
65ExprTuple98
66Operationoperator: 74
operands: 75
67ExprTuple110, 119
68ExprTuple76
69NamedExprselement: 77
targets: 82
70Literal
71ExprTuple122
72NamedExprselement: 78
targets: 82
73ExprTuple79, 80
74Literal
75NamedExprselement: 81
targets: 82
76Literal
77Operationoperator: 83
operands: 90
78Operationoperator: 84
operands: 85
79Operationoperator: 111
operands: 86
80Operationoperator: 87
operands: 88
81Operationoperator: 89
operands: 90
82Operationoperator: 91
operands: 92
83Literal
84Literal
85NamedExprsoperation: 93
part: 98
86ExprTuple119, 94
87Literal
88ExprTuple95, 96
89Literal
90NamedExprsstate: 97
part: 98
91Literal
92ExprTuple122, 99
93Variable
94Operationoperator: 113
operands: 100
95Operationoperator: 115
operand: 107
96Operationoperator: 102
operands: 103
97Variable
98Variable
99Operationoperator: 104
operands: 105
100ExprTuple122, 106
101ExprTuple107
102Literal
103ExprTuple108, 109
104Literal
105ExprTuple110, 122
106Operationoperator: 111
operands: 112
107Literal
108Operationoperator: 113
operands: 114
109Operationoperator: 115
operand: 119
110Variable
111Literal
112ExprTuple119, 122
113Literal
114ExprTuple117, 118
115Literal
116ExprTuple119
117Literal
118Operationoperator: 120
operands: 121
119Literal
120Literal
121ExprTuple122, 123, 124, 125
122Literal
123Literal
124Literal
125Variable