logo

Expression of type Bijections

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 ExprRange, Variable, VertExprArray, m
from proveit.logic import Bijections, SetOfAll
from proveit.numbers import Interval, one
from proveit.physics.quantum import NumKet, Z
from proveit.physics.quantum.QPE import _Psi_ket, _m_domain, _t
from proveit.physics.quantum.circuits import Input, Measure, MultiQubitElem, Output, Qcircuit
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Interval(one, _t)
expr = Bijections(_m_domain, SetOfAll(instance_param_or_params = [m], instance_element = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _Psi_ket, part = sub_expr1), targets = sub_expr2), one, _t)], [ExprRange(sub_expr1, Measure(basis = Z), one, _t)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, _t), part = sub_expr1), targets = sub_expr2), one, _t)])), domain = _m_domain))
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[\{0~\ldotp \ldotp~2^{t} - 1\} \xrightarrow[\text{onto}]{\text{1-to-1}} \left\{\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\multiqin{3}{\lvert \Psi \rangle} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\ghostqin{\lvert \Psi \rangle} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\ghostqin{\lvert \Psi \rangle} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert m \rangle_{t}} \\
\ghostqin{\lvert \Psi \rangle} & \meter & \ghostqout{\lvert m \rangle_{t}}
} \end{array}\right\}_{m \in \{0~\ldotp \ldotp~2^{t} - 1\}}\right]
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()()('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',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple18, 3
3Operationoperator: 4
operand: 6
4Literal
5ExprTuple6
6Lambdaparameter: 62
body: 8
7ExprTuple62
8Conditionalvalue: 9
condition: 10
9Operationoperator: 11
operands: 12
10Operationoperator: 13
operands: 14
11Literal
12ExprTuple15, 16, 17
13Literal
14ExprTuple62, 18
15ExprTuple19
16ExprTuple20
17ExprTuple21
18Operationoperator: 53
operands: 22
19ExprRangelambda_map: 23
start_index: 59
end_index: 63
20ExprRangelambda_map: 24
start_index: 59
end_index: 63
21ExprRangelambda_map: 25
start_index: 59
end_index: 63
22ExprTuple26, 27
23Lambdaparameter: 58
body: 28
24Lambdaparameter: 58
body: 29
25Lambdaparameter: 58
body: 31
26Literal
27Operationoperator: 32
operands: 33
28Operationoperator: 37
operands: 34
29Operationoperator: 35
operands: 36
30ExprTuple58
31Operationoperator: 37
operands: 38
32Literal
33ExprTuple39, 40
34NamedExprselement: 41
targets: 44
35Literal
36NamedExprsbasis: 42
37Literal
38NamedExprselement: 43
targets: 44
39Operationoperator: 45
operands: 46
40Operationoperator: 47
operand: 59
41Operationoperator: 49
operands: 50
42Literal
43Operationoperator: 51
operands: 52
44Operationoperator: 53
operands: 54
45Literal
46ExprTuple55, 63
47Literal
48ExprTuple59
49Literal
50NamedExprsstate: 56
part: 58
51Literal
52NamedExprsstate: 57
part: 58
53Literal
54ExprTuple59, 63
55Literal
56Literal
57Operationoperator: 60
operands: 61
58Variable
59Literal
60Literal
61ExprTuple62, 63
62Variable
63Literal