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 ScalarMult, VecAdd
from proveit.logic import InSet
from proveit.numbers import Add, Exp, Interval, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import QubitSpace, ket0, ket1
from proveit.physics.quantum.QPE import _phase
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = Conditional(InSet(ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1))), QubitSpace), 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(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-{_{-}a}} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right) \in \mathbb{C}^{2} \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: 4
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 7
4Literal
5ExprTuple57, 8
6Operationoperator: 29
operands: 9
7Operationoperator: 10
operands: 11
8Operationoperator: 12
operands: 13
9ExprTuple14, 15
10Literal
11ExprTuple16, 53
12Literal
13ExprTuple17, 33
14Operationoperator: 37
operands: 18
15Operationoperator: 19
operands: 20
16Literal
17Operationoperator: 21
operands: 22
18ExprTuple44, 23
19Literal
20ExprTuple24, 25
21Literal
22ExprTuple26, 44
23Operationoperator: 51
operands: 27
24Operationoperator: 40
operand: 33
25Operationoperator: 29
operands: 30
26Operationoperator: 55
operand: 36
27ExprTuple53, 32
28ExprTuple33
29Literal
30ExprTuple34, 35
31ExprTuple36
32Operationoperator: 37
operands: 38
33Literal
34Operationoperator: 51
operands: 39
35Operationoperator: 40
operand: 44
36Variable
37Literal
38ExprTuple44, 53
39ExprTuple42, 43
40Literal
41ExprTuple44
42Literal
43Operationoperator: 45
operands: 46
44Literal
45Literal
46ExprTuple53, 47, 48, 49, 50
47Literal
48Literal
49Operationoperator: 51
operands: 52
50Literal
51Literal
52ExprTuple53, 54
53Literal
54Operationoperator: 55
operand: 57
55Literal
56ExprTuple57
57Variable