logo

Expression of type Equals

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, Lambda, k, t
from proveit.linear_algebra import ScalarMult, TensorProd
from proveit.logic import Equals, InSet
from proveit.numbers import Add, Exp, Interval, Mult, e, i, one, pi, subtract, two, zero
from proveit.physics.quantum import NumKet, ket1
from proveit.physics.quantum.QPE import _phase, two_pow_t
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Add(k, two_pow_t)
sub_expr2 = InSet(k, Interval(zero, subtract(two_pow_t, one)))
expr = Equals(Lambda(k, Conditional(ScalarMult(Exp(e, Mult(two, pi, i, _phase, sub_expr1)), NumKet(sub_expr1, Add(t, one))), sub_expr2)), Lambda(k, Conditional(ScalarMult(Mult(Exp(e, Mult(two, pi, i, _phase, k)), Exp(e, Mult(two, pi, i, _phase, two_pow_t))), TensorProd(ket1, NumKet(k, t))), sub_expr2))).with_wrapping_at(2)
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())
\begin{array}{c} \begin{array}{l} \left[k \mapsto \left\{\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot \left(k + 2^{t}\right)} \cdot \lvert k + 2^{t} \rangle_{t + 1} \textrm{ if } k \in \{0~\ldotp \ldotp~2^{t} - 1\}\right..\right] =  \\ \left[k \mapsto \left\{\left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot 2^{t}}\right) \cdot \left(\lvert 1 \rangle {\otimes} \lvert k \rangle_{t}\right) \textrm{ if } k \in \{0~\ldotp \ldotp~2^{t} - 1\}\right..\right] \end{array} \end{array}
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.()(2)('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
3Lambdaparameter: 56
body: 5
4Lambdaparameter: 56
body: 7
5Conditionalvalue: 8
condition: 10
6ExprTuple56
7Conditionalvalue: 9
condition: 10
8Operationoperator: 12
operands: 11
9Operationoperator: 12
operands: 13
10Operationoperator: 14
operands: 15
11ExprTuple16, 17
12Literal
13ExprTuple18, 19
14Literal
15ExprTuple56, 20
16Operationoperator: 62
operands: 21
17Operationoperator: 41
operands: 22
18Operationoperator: 52
operands: 23
19Operationoperator: 24
operands: 25
20Operationoperator: 26
operands: 27
21ExprTuple46, 28
22ExprTuple44, 29
23ExprTuple30, 31
24Literal
25ExprTuple32, 33
26Literal
27ExprTuple34, 35
28Operationoperator: 52
operands: 36
29Operationoperator: 49
operands: 37
30Operationoperator: 62
operands: 38
31Operationoperator: 62
operands: 39
32Operationoperator: 40
operand: 61
33Operationoperator: 41
operands: 42
34Literal
35Operationoperator: 49
operands: 43
36ExprTuple64, 57, 58, 59, 44
37ExprTuple65, 61
38ExprTuple46, 45
39ExprTuple46, 47
40Literal
41Literal
42ExprTuple56, 65
43ExprTuple60, 48
44Operationoperator: 49
operands: 50
45Operationoperator: 52
operands: 51
46Literal
47Operationoperator: 52
operands: 53
48Operationoperator: 54
operand: 61
49Literal
50ExprTuple56, 60
51ExprTuple64, 57, 58, 59, 56
52Literal
53ExprTuple64, 57, 58, 59, 60
54Literal
55ExprTuple61
56Variable
57Literal
58Literal
59Literal
60Operationoperator: 62
operands: 63
61Literal
62Literal
63ExprTuple64, 65
64Literal
65Variable