# 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.
# import Expression classes needed to build the expression
from proveit import Lambda, m
from proveit.logic import And, InSet, Injections, Surjections
from proveit.physics.quantum.QPE import _Omega, _m_domain, _phase_est_circuit

In [2]:
# build up the expression from sub-expressions
sub_expr1 = Lambda(m, _phase_est_circuit)
expr = And(InSet(sub_expr1, Injections(_m_domain, _Omega)), InSet(sub_expr1, Surjections(_m_domain, _Omega)))

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[m \mapsto \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right)\right] \in \left[\{0~\ldotp \ldotp~2^{t} - 1\} \xrightarrow[]{\text{1-to-1}} \Omega\right]\right) \land \left(\left[m \mapsto \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right)\right] \in \left[\{0~\ldotp \ldotp~2^{t} - 1\} \xrightarrow[\text{onto}]{} \Omega\right]\right)

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.()()('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
2ExprTuple3, 4
3Operationoperator: 6
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple9, 8
6Literal
7ExprTuple9, 10
8Operationoperator: 11
operands: 15
9Lambdaparameter: 104
body: 13
10Operationoperator: 14
operands: 15
11Literal
12ExprTuple104
13Operationoperator: 16
operands: 17
14Literal
15ExprTuple18, 19
16Literal
17ExprTuple20, 21, 22, 23
18Operationoperator: 87
operands: 24
19Literal
20ExprTuple25, 26
21ExprTuple27, 28
22ExprTuple29, 30
23ExprTuple31, 32
24ExprTuple33, 34
25ExprRangelambda_map: 35
start_index: 105
end_index: 106
26ExprRangelambda_map: 36
start_index: 105
end_index: 107
27ExprRangelambda_map: 37
start_index: 105
end_index: 106
28ExprRangelambda_map: 37
start_index: 94
end_index: 95
29ExprRangelambda_map: 38
start_index: 105
end_index: 106
30ExprRangelambda_map: 39
start_index: 105
end_index: 107
31ExprRangelambda_map: 40
start_index: 105
end_index: 106
32ExprRangelambda_map: 41
start_index: 105
end_index: 107
33Literal
34Operationoperator: 101
operands: 42
35Lambdaparameter: 93
body: 43
36Lambdaparameter: 93
body: 44
37Lambdaparameter: 93
body: 45
38Lambdaparameter: 93
body: 46
39Lambdaparameter: 93
body: 47
40Lambdaparameter: 93
body: 48
41Lambdaparameter: 93
body: 50
42ExprTuple51, 52
43Operationoperator: 79
operands: 53
44Operationoperator: 60
operands: 54
45Operationoperator: 60
operands: 55
46Operationoperator: 56
operands: 57
47Operationoperator: 80
operands: 58
48Operationoperator: 60
operands: 59
49ExprTuple93
50Operationoperator: 60
operands: 61
51Operationoperator: 62
operands: 63
52Operationoperator: 64
operand: 105
54NamedExprselement: 67
targets: 75
55NamedExprselement: 68
targets: 69
56Literal
57NamedExprsbasis: 70
58NamedExprsoperation: 71
59NamedExprselement: 72
targets: 73
60Literal
61NamedExprselement: 74
targets: 75
62Literal
63ExprTuple76, 106
64Literal
65ExprTuple105
66Operationoperator: 77
operand: 89
67Operationoperator: 79
operands: 86
68Operationoperator: 80
operands: 81
69Operationoperator: 87
operands: 82
70Literal
71Literal
72Operationoperator: 85
operands: 83
73Operationoperator: 87
operands: 84
74Operationoperator: 85
operands: 86
75Operationoperator: 87
operands: 88
76Literal
77Literal
78ExprTuple89
79Literal
80Literal
81NamedExprsoperation: 90
part: 93
82ExprTuple105, 95
part: 93
84ExprTuple105, 106
85Literal
part: 93
87Literal
88ExprTuple94, 95
89Literal
90Operationoperator: 96
operands: 97
91Operationoperator: 98
operands: 99
92Literal
93Variable
94Operationoperator: 101
operands: 100
95Operationoperator: 101
operands: 102
96Literal
97ExprTuple103, 106
98Literal
99ExprTuple104, 106
100ExprTuple106, 105
101Literal
102ExprTuple106, 107
103Literal
104Variable
105Literal
106Literal
107Literal