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.QPE import QPE1, QPE1_U_t_circuit
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 = MultiQubitElem(element = Gate(operation = QPE1(U, t), part = sub_expr1), targets = Interval(one, sub_expr2))
expr = Forall(instance_param_or_params = [U], instance_expr = QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr3, one, t), ExprRange(sub_expr1, sub_expr3, Add(t, one), sub_expr2)])), QPE1_U_t_circuit), 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}_1\left(U, t\right)} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qw \\
& \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qw \\
& \gate{U^{2^{t - 1}}} & \gate{U^{2^{t - 2}}} & \gate{\cdots} & \gate{U^{2^{0}}} & { /^{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: 84
body: 5
4ExprTuple84
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple12, 13
10Literal
11ExprTuple84, 14
12Operationoperator: 16
operand: 20
13Operationoperator: 16
operands: 17
14Operationoperator: 18
operand: 22
15ExprTuple20
16Literal
17ExprTuple21
18Literal
19ExprTuple22
20ExprTuple23, 24
21ExprRangelambda_map: 25
start_index: 26
end_index: 27
22Operationoperator: 88
operands: 28
23ExprRangelambda_map: 29
start_index: 95
end_index: 94
24ExprRangelambda_map: 29
start_index: 87
end_index: 72
25Lambdaparameter: 98
body: 30
26Operationoperator: 90
operands: 31
27Literal
28ExprTuple92, 86
29Lambdaparameter: 77
body: 32
30ExprTuple33, 34
31ExprTuple35, 95
32Operationoperator: 64
operands: 36
33ExprRangelambda_map: 37
start_index: 95
end_index: 94
34ExprRangelambda_map: 38
start_index: 95
end_index: 86
35Operationoperator: 96
operand: 94
36NamedExprselement: 40
targets: 41
37Lambdaparameter: 77
body: 42
38Lambdaparameter: 77
body: 44
39ExprTuple94
40Operationoperator: 67
operands: 45
41Operationoperator: 62
operands: 46
42Operationoperator: 47
operands: 48
43ExprTuple77
44Operationoperator: 64
operands: 49
45NamedExprsoperation: 50
part: 77
46ExprTuple95, 72
47Literal
48ExprTuple51, 52
49NamedExprselement: 53
targets: 54
50Operationoperator: 55
operands: 56
51Conditionalvalue: 57
condition: 58
52Conditionalvalue: 59
condition: 60
53Operationoperator: 67
operands: 61
54Operationoperator: 62
operands: 63
55Literal
56ExprTuple84, 94
57Operationoperator: 64
operands: 65
58Operationoperator: 66
operands: 70
59Operationoperator: 67
operands: 68
60Operationoperator: 69
operands: 70
61NamedExprsoperation: 71
part: 77
62Literal
63ExprTuple87, 72
64Literal
65NamedExprselement: 73
targets: 74
66Literal
67Literal
68NamedExprsoperation: 75
69Literal
70ExprTuple76, 77
71Operationoperator: 78
operands: 79
72Operationoperator: 90
operands: 80
73Literal
74Operationoperator: 81
operand: 87
75Literal
76Operationoperator: 90
operands: 83
77Variable
78Literal
79ExprTuple84, 85
80ExprTuple94, 86
81Literal
82ExprTuple87
83ExprTuple98, 94
84Variable
85Operationoperator: 88
operands: 89
86Variable
87Operationoperator: 90
operands: 91
88Literal
89ExprTuple92, 93
90Literal
91ExprTuple94, 95
92Literal
93Operationoperator: 96
operand: 98
94Variable
95Literal
96Literal
97ExprTuple98
98Variable