logo

Expression of type Forall

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, U, Variable, VertExprArray, s, t
from proveit.linear_algebra import Unitary
from proveit.logic import Forall
from proveit.numbers import Add, Exp, Interval, one, two
from proveit.physics.quantum import I
from proveit.physics.quantum.QFT import InverseFourierTransform
from proveit.physics.quantum.QPE import QPE, QPE1
from proveit.physics.quantum.circuits import Gate, MultiQubitElem, Qcircuit, QcircuitEquiv
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, s)
sub_expr3 = Add(t, one)
sub_expr4 = Interval(one, sub_expr2)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = sub_expr4)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE1(U, t), part = sub_expr1), targets = sub_expr4)
expr = Forall(instance_param_or_params = [U], instance_expr = QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr3, sub_expr2)])), Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr6, one, t), ExprRange(sub_expr1, sub_expr6, sub_expr3, sub_expr2)], [ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)]))), domain = Unitary(Exp(two, s)))
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())
\forall_{U \in \textrm{U}\left(2^{s}\right)}~\left(\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multigate{1}{\textrm{QPE}\left(U, t\right)} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multigate{1}{\textrm{QPE}_1\left(U, t\right)} & \gate{{\mathrm {FT}}^{\dag}_{t}} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw & { /^{s} } \qw
} \end{array}\right)\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameter: 75
body: 5
4ExprTuple75
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple12, 13
10Literal
11ExprTuple75, 14
12Operationoperator: 16
operand: 20
13Operationoperator: 16
operands: 17
14Operationoperator: 18
operand: 23
15ExprTuple20
16Literal
17ExprTuple21, 22
18Literal
19ExprTuple23
20ExprTuple24, 25
21ExprTuple26, 27
22ExprTuple28, 29
23Operationoperator: 30
operands: 31
24ExprRangelambda_map: 32
start_index: 67
end_index: 77
25ExprRangelambda_map: 32
start_index: 34
end_index: 64
26ExprRangelambda_map: 33
start_index: 67
end_index: 77
27ExprRangelambda_map: 33
start_index: 34
end_index: 64
28ExprRangelambda_map: 35
start_index: 67
end_index: 77
29ExprRangelambda_map: 36
start_index: 67
end_index: 76
30Literal
31ExprTuple37, 76
32Lambdaparameter: 66
body: 38
33Lambdaparameter: 66
body: 39
34Operationoperator: 71
operands: 40
35Lambdaparameter: 66
body: 41
36Lambdaparameter: 66
body: 43
37Literal
38Operationoperator: 46
operands: 44
39Operationoperator: 46
operands: 45
40ExprTuple77, 67
41Operationoperator: 46
operands: 47
42ExprTuple66
43Operationoperator: 58
operands: 48
44NamedExprselement: 49
targets: 51
45NamedExprselement: 50
targets: 51
46Literal
47NamedExprselement: 52
targets: 53
48NamedExprsoperation: 54
49Operationoperator: 58
operands: 55
50Operationoperator: 58
operands: 56
51Operationoperator: 60
operands: 57
52Operationoperator: 58
operands: 59
53Operationoperator: 60
operands: 61
54Literal
55NamedExprsoperation: 62
part: 66
56NamedExprsoperation: 63
part: 66
57ExprTuple67, 64
58Literal
59NamedExprsoperation: 65
part: 66
60Literal
61ExprTuple67, 77
62Operationoperator: 68
operands: 70
63Operationoperator: 69
operands: 70
64Operationoperator: 71
operands: 72
65Operationoperator: 73
operand: 77
66Variable
67Literal
68Literal
69Literal
70ExprTuple75, 77
71Literal
72ExprTuple77, 76
73Literal
74ExprTuple77
75Variable
76Variable
77Variable