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, 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 = [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)))
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_{\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)
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: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameter: 104
body: 5
4ExprTuple104
5Conditionalvalue: 6
condition: 7
6Operationoperator: 9
operands: 8
7Operationoperator: 9
operands: 10
8ExprTuple11, 98
9Literal
10ExprTuple12, 13
11Operationoperator: 14
operand: 19
12Operationoperator: 16
operands: 17
13Operationoperator: 81
operands: 18
14Literal
15ExprTuple19
16Literal
17ExprTuple72, 76
18ExprTuple87, 76
19Operationoperator: 20
operands: 21
20Literal
21ExprTuple22, 23, 24
22ExprTuple25, 26
23ExprTuple27, 28
24ExprTuple29, 30
25Operationoperator: 62
operands: 31
26ExprRangelambda_map: 32
start_index: 98
end_index: 37
27Operationoperator: 53
operands: 33
28ExprRangelambda_map: 34
start_index: 98
end_index: 37
29Operationoperator: 68
operands: 35
30ExprRangelambda_map: 36
start_index: 98
end_index: 37
31NamedExprsstate: 38
32Lambdaparameter: 77
body: 39
33NamedExprselement: 40
targets: 41
34Lambdaparameter: 77
body: 42
35NamedExprsstate: 43
36Lambdaparameter: 77
body: 45
37Operationoperator: 83
operands: 46
38Operationoperator: 94
operand: 55
39Operationoperator: 53
operands: 48
40Literal
41Operationoperator: 49
operand: 101
42Operationoperator: 53
operands: 51
43Operationoperator: 81
operands: 52
44ExprTuple77
45Operationoperator: 53
operands: 54
46ExprTuple89, 98
47ExprTuple55
48NamedExprselement: 56
targets: 61
49Literal
50ExprTuple101
51NamedExprselement: 57
targets: 61
52ExprTuple58, 59
53Literal
54NamedExprselement: 60
targets: 61
55Literal
56Operationoperator: 62
operands: 69
57Operationoperator: 63
operands: 64
58Operationoperator: 90
operands: 65
59Operationoperator: 66
operands: 67
60Operationoperator: 68
operands: 69
61Operationoperator: 70
operands: 71
62Literal
63Literal
64NamedExprsoperation: 72
part: 77
65ExprTuple98, 73
66Literal
67ExprTuple74, 75
68Literal
69NamedExprsstate: 76
part: 77
70Literal
71ExprTuple101, 78
72Variable
73Operationoperator: 92
operands: 79
74Operationoperator: 94
operand: 86
75Operationoperator: 81
operands: 82
76Variable
77Variable
78Operationoperator: 83
operands: 84
79ExprTuple101, 85
80ExprTuple86
81Literal
82ExprTuple87, 88
83Literal
84ExprTuple89, 101
85Operationoperator: 90
operands: 91
86Literal
87Operationoperator: 92
operands: 93
88Operationoperator: 94
operand: 98
89Variable
90Literal
91ExprTuple98, 101
92Literal
93ExprTuple96, 97
94Literal
95ExprTuple98
96Literal
97Operationoperator: 99
operands: 100
98Literal
99Literal
100ExprTuple101, 102, 103, 104
101Literal
102Literal
103Literal
104Variable