logo

Expression of type Implies

from the theory of proveit.physics.quantum.QPE

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 k, t
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.logic import And, Equals, Forall, Implies
from proveit.numbers import Add, Exp, Interval, Mult, NaturalPos, e, frac, i, one, pi, sqrt, subtract, two, zero
from proveit.physics.quantum import Ket, NumKet
from proveit.physics.quantum.QPE import SubIndexed, _phase, _psi, _psi_t_ket, two_pow_t
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [k]
sub_expr2 = [t]
sub_expr3 = Add(t, one)
sub_expr4 = Exp(e, Mult(two, pi, i, _phase, k))
sub_expr5 = Equals(_psi_t_ket, ScalarMult(frac(one, Exp(two, frac(t, two))), VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr4, NumKet(k, t)), domain = Interval(zero, subtract(two_pow_t, one)))))
expr = Implies(And(Equals(SubIndexed(_psi, [one]), ScalarMult(frac(one, sqrt(two)), VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr4, Ket(k)), domain = Interval(zero, one)))), Forall(instance_param_or_params = sub_expr2, instance_expr = Equals(SubIndexed(_psi, [sub_expr3]), ScalarMult(frac(one, Exp(two, frac(sub_expr3, two))), VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr4, NumKet(k, sub_expr3)), domain = Interval(zero, subtract(Mult(two, two_pow_t), one))))), domain = NaturalPos, condition = sub_expr5)), Forall(instance_param_or_params = sub_expr2, instance_expr = sub_expr5, domain = 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(\left(\lvert \psi_{1} \rangle = \left(\frac{1}{\sqrt{2}} \cdot \left(\sum_{k=0}^{1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle\right)\right)\right)\right) \land \left[\forall_{t \in \mathbb{N}^+~|~\lvert \psi_{t} \rangle = \left(\frac{1}{2^{\frac{t}{2}}} \cdot \left(\sum_{k=0}^{2^{t} - 1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle_{t}\right)\right)\right)}~\left(\lvert \psi_{t + 1} \rangle = \left(\frac{1}{2^{\frac{t + 1}{2}}} \cdot \left(\sum_{k=0}^{\left(2 \cdot 2^{t}\right) - 1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle_{t + 1}\right)\right)\right)\right)\right]\right) \Rightarrow \left[\forall_{t \in \mathbb{N}^+}~\left(\lvert \psi_{t} \rangle = \left(\frac{1}{2^{\frac{t}{2}}} \cdot \left(\sum_{k=0}^{2^{t} - 1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle_{t}\right)\right)\right)\right)\right]
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()()('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 26
operands: 5
4Operationoperator: 11
operand: 9
5ExprTuple7, 8
6ExprTuple9
7Operationoperator: 39
operands: 10
8Operationoperator: 11
operand: 16
9Lambdaparameter: 127
body: 13
10ExprTuple14, 15
11Literal
12ExprTuple16
13Conditionalvalue: 33
condition: 32
14Operationoperator: 54
operand: 128
15Operationoperator: 90
operands: 17
16Lambdaparameter: 127
body: 18
17ExprTuple19, 20
18Conditionalvalue: 21
condition: 22
19Operationoperator: 88
operands: 23
20Operationoperator: 68
operand: 29
21Operationoperator: 39
operands: 25
22Operationoperator: 26
operands: 27
23ExprTuple128, 28
24ExprTuple29
25ExprTuple30, 31
26Literal
27ExprTuple32, 33
28Operationoperator: 122
operands: 34
29Lambdaparameter: 119
body: 35
30Operationoperator: 54
operand: 94
31Operationoperator: 90
operands: 37
32Operationoperator: 92
operands: 38
33Operationoperator: 39
operands: 40
34ExprTuple126, 41
35Conditionalvalue: 42
condition: 43
36ExprTuple94
37ExprTuple44, 45
38ExprTuple127, 46
39Literal
40ExprTuple47, 48
41Operationoperator: 88
operands: 49
42Operationoperator: 90
operands: 50
43Operationoperator: 92
operands: 51
44Operationoperator: 88
operands: 52
45Operationoperator: 68
operand: 60
46Literal
47Operationoperator: 54
operand: 127
48Operationoperator: 90
operands: 56
49ExprTuple128, 126
50ExprTuple96, 57
51ExprTuple119, 58
52ExprTuple128, 59
53ExprTuple60
54Literal
55ExprTuple127
56ExprTuple61, 62
57Operationoperator: 63
operand: 119
58Operationoperator: 104
operands: 64
59Operationoperator: 122
operands: 65
60Lambdaparameter: 119
body: 66
61Operationoperator: 88
operands: 67
62Operationoperator: 68
operand: 74
63Literal
64ExprTuple109, 128
65ExprTuple126, 70
66Conditionalvalue: 71
condition: 72
67ExprTuple128, 73
68Literal
69ExprTuple74
70Operationoperator: 88
operands: 75
71Operationoperator: 90
operands: 76
72Operationoperator: 92
operands: 77
73Operationoperator: 122
operands: 78
74Lambdaparameter: 119
body: 80
75ExprTuple94, 126
76ExprTuple96, 81
77ExprTuple119, 82
78ExprTuple126, 83
79ExprTuple119
80Conditionalvalue: 84
condition: 85
81Operationoperator: 102
operands: 86
82Operationoperator: 104
operands: 87
83Operationoperator: 88
operands: 89
84Operationoperator: 90
operands: 91
85Operationoperator: 92
operands: 93
86ExprTuple119, 94
87ExprTuple109, 95
88Literal
89ExprTuple127, 126
90Literal
91ExprTuple96, 97
92Literal
93ExprTuple119, 98
94Operationoperator: 114
operands: 99
95Operationoperator: 114
operands: 100
96Operationoperator: 122
operands: 101
97Operationoperator: 102
operands: 103
98Operationoperator: 104
operands: 105
99ExprTuple127, 128
100ExprTuple106, 121
101ExprTuple107, 108
102Literal
103ExprTuple119, 127
104Literal
105ExprTuple109, 110
106Operationoperator: 112
operands: 111
107Literal
108Operationoperator: 112
operands: 113
109Literal
110Operationoperator: 114
operands: 115
111ExprTuple126, 120
112Literal
113ExprTuple126, 116, 117, 118, 119
114Literal
115ExprTuple120, 121
116Literal
117Literal
118Literal
119Variable
120Operationoperator: 122
operands: 123
121Operationoperator: 124
operand: 128
122Literal
123ExprTuple126, 127
124Literal
125ExprTuple128
126Literal
127Variable
128Literal