logo

Expression of type Forall

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 Equals, Forall
from proveit.numbers import Add, Exp, Interval, Mult, NaturalPos, e, frac, i, one, pi, subtract, two, zero
from proveit.physics.quantum import 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 = 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())
\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)
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: 95
body: 4
4Conditionalvalue: 5
condition: 6
5Operationoperator: 17
operands: 7
6Operationoperator: 8
operands: 9
7ExprTuple10, 11
8Literal
9ExprTuple12, 13
10Operationoperator: 26
operand: 62
11Operationoperator: 58
operands: 15
12Operationoperator: 60
operands: 16
13Operationoperator: 17
operands: 18
14ExprTuple62
15ExprTuple19, 20
16ExprTuple95, 21
17Literal
18ExprTuple22, 23
19Operationoperator: 56
operands: 24
20Operationoperator: 36
operand: 30
21Literal
22Operationoperator: 26
operand: 95
23Operationoperator: 58
operands: 28
24ExprTuple96, 29
25ExprTuple30
26Literal
27ExprTuple95
28ExprTuple31, 32
29Operationoperator: 90
operands: 33
30Lambdaparameter: 87
body: 34
31Operationoperator: 56
operands: 35
32Operationoperator: 36
operand: 42
33ExprTuple94, 38
34Conditionalvalue: 39
condition: 40
35ExprTuple96, 41
36Literal
37ExprTuple42
38Operationoperator: 56
operands: 43
39Operationoperator: 58
operands: 44
40Operationoperator: 60
operands: 45
41Operationoperator: 90
operands: 46
42Lambdaparameter: 87
body: 48
43ExprTuple62, 94
44ExprTuple64, 49
45ExprTuple87, 50
46ExprTuple94, 51
47ExprTuple87
48Conditionalvalue: 52
condition: 53
49Operationoperator: 70
operands: 54
50Operationoperator: 72
operands: 55
51Operationoperator: 56
operands: 57
52Operationoperator: 58
operands: 59
53Operationoperator: 60
operands: 61
54ExprTuple87, 62
55ExprTuple77, 63
56Literal
57ExprTuple95, 94
58Literal
59ExprTuple64, 65
60Literal
61ExprTuple87, 66
62Operationoperator: 82
operands: 67
63Operationoperator: 82
operands: 68
64Operationoperator: 90
operands: 69
65Operationoperator: 70
operands: 71
66Operationoperator: 72
operands: 73
67ExprTuple95, 96
68ExprTuple74, 89
69ExprTuple75, 76
70Literal
71ExprTuple87, 95
72Literal
73ExprTuple77, 78
74Operationoperator: 80
operands: 79
75Literal
76Operationoperator: 80
operands: 81
77Literal
78Operationoperator: 82
operands: 83
79ExprTuple94, 88
80Literal
81ExprTuple94, 84, 85, 86, 87
82Literal
83ExprTuple88, 89
84Literal
85Literal
86Literal
87Variable
88Operationoperator: 90
operands: 91
89Operationoperator: 92
operand: 96
90Literal
91ExprTuple94, 95
92Literal
93ExprTuple96
94Literal
95Variable
96Literal