logo

Expression of type Conditional

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 Conditional, k, t
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.logic import And, Equals, InSet
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 = Conditional(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))))), And(InSet(t, NaturalPos), 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_{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) \textrm{ if } 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)\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 13
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 7
4Literal
5ExprTuple8, 9
6Operationoperator: 22
operand: 58
7Operationoperator: 54
operands: 11
8Operationoperator: 56
operands: 12
9Operationoperator: 13
operands: 14
10ExprTuple58
11ExprTuple15, 16
12ExprTuple91, 17
13Literal
14ExprTuple18, 19
15Operationoperator: 52
operands: 20
16Operationoperator: 32
operand: 26
17Literal
18Operationoperator: 22
operand: 91
19Operationoperator: 54
operands: 24
20ExprTuple92, 25
21ExprTuple26
22Literal
23ExprTuple91
24ExprTuple27, 28
25Operationoperator: 86
operands: 29
26Lambdaparameter: 83
body: 30
27Operationoperator: 52
operands: 31
28Operationoperator: 32
operand: 38
29ExprTuple90, 34
30Conditionalvalue: 35
condition: 36
31ExprTuple92, 37
32Literal
33ExprTuple38
34Operationoperator: 52
operands: 39
35Operationoperator: 54
operands: 40
36Operationoperator: 56
operands: 41
37Operationoperator: 86
operands: 42
38Lambdaparameter: 83
body: 44
39ExprTuple58, 90
40ExprTuple60, 45
41ExprTuple83, 46
42ExprTuple90, 47
43ExprTuple83
44Conditionalvalue: 48
condition: 49
45Operationoperator: 66
operands: 50
46Operationoperator: 68
operands: 51
47Operationoperator: 52
operands: 53
48Operationoperator: 54
operands: 55
49Operationoperator: 56
operands: 57
50ExprTuple83, 58
51ExprTuple73, 59
52Literal
53ExprTuple91, 90
54Literal
55ExprTuple60, 61
56Literal
57ExprTuple83, 62
58Operationoperator: 78
operands: 63
59Operationoperator: 78
operands: 64
60Operationoperator: 86
operands: 65
61Operationoperator: 66
operands: 67
62Operationoperator: 68
operands: 69
63ExprTuple91, 92
64ExprTuple70, 85
65ExprTuple71, 72
66Literal
67ExprTuple83, 91
68Literal
69ExprTuple73, 74
70Operationoperator: 76
operands: 75
71Literal
72Operationoperator: 76
operands: 77
73Literal
74Operationoperator: 78
operands: 79
75ExprTuple90, 84
76Literal
77ExprTuple90, 80, 81, 82, 83
78Literal
79ExprTuple84, 85
80Literal
81Literal
82Literal
83Variable
84Operationoperator: 86
operands: 87
85Operationoperator: 88
operand: 92
86Literal
87ExprTuple90, 91
88Literal
89ExprTuple92
90Literal
91Variable
92Literal