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, Variable, t
from proveit.linear_algebra import MatrixExp, MatrixMult, ScalarMult
from proveit.logic import Equals, InSet
from proveit.numbers import Add, Exp, Interval, Mult, Neg, e, i, one, pi, two, zero
from proveit.physics.quantum.QPE import _U, _ket_u, _phase
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Exp(two, Neg(sub_expr1))
expr = Conditional(Equals(MatrixMult(MatrixExp(_U, sub_expr2), _ket_u), ScalarMult(Exp(e, Mult(two, pi, i, Mult(sub_expr2, _phase))), _ket_u)), InSet(sub_expr1, Interval(Add(Neg(t), one), zero)))
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\{\left(U^{2^{-{_{-}a}}} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \left(2^{-{_{-}a}} \cdot \varphi\right)} \cdot \lvert u \rangle\right) \textrm{ if } {_{-}a} \in \{-t + 1~\ldotp \ldotp~0\}\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: 3
operands: 4
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7, 8
5Literal
6ExprTuple47, 9
7Operationoperator: 10
operands: 11
8Operationoperator: 12
operands: 13
9Operationoperator: 14
operands: 15
10Literal
11ExprTuple16, 18
12Literal
13ExprTuple17, 18
14Literal
15ExprTuple19, 20
16Operationoperator: 21
operands: 22
17Operationoperator: 41
operands: 23
18Literal
19Operationoperator: 24
operands: 25
20Literal
21Literal
22ExprTuple26, 39
23ExprTuple27, 28
24Literal
25ExprTuple29, 30
26Literal
27Literal
28Operationoperator: 37
operands: 31
29Operationoperator: 45
operand: 36
30Literal
31ExprTuple43, 33, 34, 35
32ExprTuple36
33Literal
34Literal
35Operationoperator: 37
operands: 38
36Variable
37Literal
38ExprTuple39, 40
39Operationoperator: 41
operands: 42
40Literal
41Literal
42ExprTuple43, 44
43Literal
44Operationoperator: 45
operand: 47
45Literal
46ExprTuple47
47Variable