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, NaturalPos, 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 = [s, t], instance_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))), domain = NaturalPos)
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_{s, t \in \mathbb{N}^+}~\left[\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)\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: 7
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple89, 90
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 11
6Operationoperator: 9
operands: 10
7Literal
8ExprTuple11
9Literal
10ExprTuple12, 13
11Lambdaparameter: 88
body: 15
12Operationoperator: 23
operands: 16
13Operationoperator: 23
operands: 17
14ExprTuple88
15Conditionalvalue: 18
condition: 19
16ExprTuple89, 20
17ExprTuple90, 20
18Operationoperator: 21
operands: 22
19Operationoperator: 23
operands: 24
20Literal
21Literal
22ExprTuple25, 26
23Literal
24ExprTuple88, 27
25Operationoperator: 29
operand: 33
26Operationoperator: 29
operands: 30
27Operationoperator: 31
operand: 36
28ExprTuple33
29Literal
30ExprTuple34, 35
31Literal
32ExprTuple36
33ExprTuple37, 38
34ExprTuple39, 40
35ExprTuple41, 42
36Operationoperator: 43
operands: 44
37ExprRangelambda_map: 45
start_index: 80
end_index: 90
38ExprRangelambda_map: 45
start_index: 47
end_index: 77
39ExprRangelambda_map: 46
start_index: 80
end_index: 90
40ExprRangelambda_map: 46
start_index: 47
end_index: 77
41ExprRangelambda_map: 48
start_index: 80
end_index: 90
42ExprRangelambda_map: 49
start_index: 80
end_index: 89
43Literal
44ExprTuple50, 89
45Lambdaparameter: 79
body: 51
46Lambdaparameter: 79
body: 52
47Operationoperator: 84
operands: 53
48Lambdaparameter: 79
body: 54
49Lambdaparameter: 79
body: 56
50Literal
51Operationoperator: 59
operands: 57
52Operationoperator: 59
operands: 58
53ExprTuple90, 80
54Operationoperator: 59
operands: 60
55ExprTuple79
56Operationoperator: 71
operands: 61
57NamedExprselement: 62
targets: 64
58NamedExprselement: 63
targets: 64
59Literal
60NamedExprselement: 65
targets: 66
61NamedExprsoperation: 67
62Operationoperator: 71
operands: 68
63Operationoperator: 71
operands: 69
64Operationoperator: 73
operands: 70
65Operationoperator: 71
operands: 72
66Operationoperator: 73
operands: 74
67Literal
68NamedExprsoperation: 75
part: 79
69NamedExprsoperation: 76
part: 79
70ExprTuple80, 77
71Literal
72NamedExprsoperation: 78
part: 79
73Literal
74ExprTuple80, 90
75Operationoperator: 81
operands: 83
76Operationoperator: 82
operands: 83
77Operationoperator: 84
operands: 85
78Operationoperator: 86
operand: 90
79Variable
80Literal
81Literal
82Literal
83ExprTuple88, 90
84Literal
85ExprTuple90, 89
86Literal
87ExprTuple90
88Variable
89Variable
90Variable