logo

Expression of type And

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
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 = Add(t, one)
sub_expr3 = Exp(e, Mult(two, pi, i, _phase, k))
expr = And(Equals(SubIndexed(_psi, [one]), ScalarMult(frac(one, sqrt(two)), VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr3, Ket(k)), domain = Interval(zero, one)))), Forall(instance_param_or_params = [t], instance_expr = Equals(SubIndexed(_psi, [sub_expr2]), ScalarMult(frac(one, Exp(two, frac(sub_expr2, two))), VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr3, NumKet(k, sub_expr2)), domain = Interval(zero, subtract(Mult(two, two_pow_t), one))))), domain = NaturalPos, condition = Equals(_psi_t_ket, ScalarMult(frac(one, Exp(two, frac(t, two))), VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr3, NumKet(k, t)), domain = Interval(zero, subtract(two_pow_t, one)))))))
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(\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]
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',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 19
operands: 1
1ExprTuple2, 3
2Operationoperator: 32
operands: 4
3Operationoperator: 5
operand: 9
4ExprTuple7, 8
5Literal
6ExprTuple9
7Operationoperator: 47
operand: 121
8Operationoperator: 83
operands: 10
9Lambdaparameter: 120
body: 11
10ExprTuple12, 13
11Conditionalvalue: 14
condition: 15
12Operationoperator: 81
operands: 16
13Operationoperator: 61
operand: 22
14Operationoperator: 32
operands: 18
15Operationoperator: 19
operands: 20
16ExprTuple121, 21
17ExprTuple22
18ExprTuple23, 24
19Literal
20ExprTuple25, 26
21Operationoperator: 115
operands: 27
22Lambdaparameter: 112
body: 28
23Operationoperator: 47
operand: 87
24Operationoperator: 83
operands: 30
25Operationoperator: 85
operands: 31
26Operationoperator: 32
operands: 33
27ExprTuple119, 34
28Conditionalvalue: 35
condition: 36
29ExprTuple87
30ExprTuple37, 38
31ExprTuple120, 39
32Literal
33ExprTuple40, 41
34Operationoperator: 81
operands: 42
35Operationoperator: 83
operands: 43
36Operationoperator: 85
operands: 44
37Operationoperator: 81
operands: 45
38Operationoperator: 61
operand: 53
39Literal
40Operationoperator: 47
operand: 120
41Operationoperator: 83
operands: 49
42ExprTuple121, 119
43ExprTuple89, 50
44ExprTuple112, 51
45ExprTuple121, 52
46ExprTuple53
47Literal
48ExprTuple120
49ExprTuple54, 55
50Operationoperator: 56
operand: 112
51Operationoperator: 97
operands: 57
52Operationoperator: 115
operands: 58
53Lambdaparameter: 112
body: 59
54Operationoperator: 81
operands: 60
55Operationoperator: 61
operand: 67
56Literal
57ExprTuple102, 121
58ExprTuple119, 63
59Conditionalvalue: 64
condition: 65
60ExprTuple121, 66
61Literal
62ExprTuple67
63Operationoperator: 81
operands: 68
64Operationoperator: 83
operands: 69
65Operationoperator: 85
operands: 70
66Operationoperator: 115
operands: 71
67Lambdaparameter: 112
body: 73
68ExprTuple87, 119
69ExprTuple89, 74
70ExprTuple112, 75
71ExprTuple119, 76
72ExprTuple112
73Conditionalvalue: 77
condition: 78
74Operationoperator: 95
operands: 79
75Operationoperator: 97
operands: 80
76Operationoperator: 81
operands: 82
77Operationoperator: 83
operands: 84
78Operationoperator: 85
operands: 86
79ExprTuple112, 87
80ExprTuple102, 88
81Literal
82ExprTuple120, 119
83Literal
84ExprTuple89, 90
85Literal
86ExprTuple112, 91
87Operationoperator: 107
operands: 92
88Operationoperator: 107
operands: 93
89Operationoperator: 115
operands: 94
90Operationoperator: 95
operands: 96
91Operationoperator: 97
operands: 98
92ExprTuple120, 121
93ExprTuple99, 114
94ExprTuple100, 101
95Literal
96ExprTuple112, 120
97Literal
98ExprTuple102, 103
99Operationoperator: 105
operands: 104
100Literal
101Operationoperator: 105
operands: 106
102Literal
103Operationoperator: 107
operands: 108
104ExprTuple119, 113
105Literal
106ExprTuple119, 109, 110, 111, 112
107Literal
108ExprTuple113, 114
109Literal
110Literal
111Literal
112Variable
113Operationoperator: 115
operands: 116
114Operationoperator: 117
operand: 121
115Literal
116ExprTuple119, 120
117Literal
118ExprTuple121
119Literal
120Variable
121Literal