logo

Expression of type ExprTuple

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, ExprTuple, Lambda, k, t
from proveit.linear_algebra import ScalarMult, TensorProd
from proveit.logic import Equals, Forall, 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 = Interval(zero, subtract(two_pow_t, one))
sub_expr3 = InSet(k, sub_expr2)
sub_expr4 = ScalarMult(Exp(e, Mult(two, pi, i, _phase, sub_expr1)), NumKet(sub_expr1, Add(t, one)))
sub_expr5 = 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)))
expr = ExprTuple(Forall(instance_param_or_params = [k], instance_expr = Equals(sub_expr4, sub_expr5), domain = sub_expr2), Equals(Lambda(k, Conditional(sub_expr4, sub_expr3)), Lambda(k, Conditional(sub_expr5, sub_expr3))).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())
\left(\forall_{k \in \{0~\ldotp \ldotp~2^{t} - 1\}}~\left(\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}\right) = \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)\right)\right), \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}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2
1Operationoperator: 3
operand: 6
2Operationoperator: 15
operands: 5
3Literal
4ExprTuple6
5ExprTuple7, 8
6Lambdaparameter: 65
body: 9
7Lambdaparameter: 65
body: 10
8Lambdaparameter: 65
body: 12
9Conditionalvalue: 13
condition: 14
10Conditionalvalue: 19
condition: 14
11ExprTuple65
12Conditionalvalue: 20
condition: 14
13Operationoperator: 15
operands: 16
14Operationoperator: 17
operands: 18
15Literal
16ExprTuple19, 20
17Literal
18ExprTuple65, 21
19Operationoperator: 23
operands: 22
20Operationoperator: 23
operands: 24
21Operationoperator: 25
operands: 26
22ExprTuple27, 28
23Literal
24ExprTuple29, 30
25Literal
26ExprTuple31, 32
27Operationoperator: 70
operands: 33
28Operationoperator: 51
operands: 34
29Operationoperator: 63
operands: 35
30Operationoperator: 36
operands: 37
31Literal
32Operationoperator: 60
operands: 38
33ExprTuple57, 39
34ExprTuple55, 40
35ExprTuple41, 42
36Literal
37ExprTuple43, 44
38ExprTuple69, 45
39Operationoperator: 63
operands: 46
40Operationoperator: 60
operands: 47
41Operationoperator: 70
operands: 48
42Operationoperator: 70
operands: 49
43Operationoperator: 50
operand: 59
44Operationoperator: 51
operands: 52
45Operationoperator: 53
operand: 59
46ExprTuple72, 66, 67, 68, 55
47ExprTuple73, 59
48ExprTuple57, 56
49ExprTuple57, 58
50Literal
51Literal
52ExprTuple65, 73
53Literal
54ExprTuple59
55Operationoperator: 60
operands: 61
56Operationoperator: 63
operands: 62
57Literal
58Operationoperator: 63
operands: 64
59Literal
60Literal
61ExprTuple65, 69
62ExprTuple72, 66, 67, 68, 65
63Literal
64ExprTuple72, 66, 67, 68, 69
65Variable
66Literal
67Literal
68Literal
69Operationoperator: 70
operands: 71
70Literal
71ExprTuple72, 73
72Literal
73Variable