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.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 = [s, t], instance_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))), 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}_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)\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
3ExprTuple99, 107
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 11
6Operationoperator: 9
operands: 10
7Literal
8ExprTuple11
9Literal
10ExprTuple12, 13
11Lambdaparameter: 97
body: 15
12Operationoperator: 23
operands: 16
13Operationoperator: 23
operands: 17
14ExprTuple97
15Conditionalvalue: 18
condition: 19
16ExprTuple99, 20
17ExprTuple107, 20
18Operationoperator: 21
operands: 22
19Operationoperator: 23
operands: 24
20Literal
21Literal
22ExprTuple25, 26
23Literal
24ExprTuple97, 27
25Operationoperator: 29
operand: 33
26Operationoperator: 29
operands: 30
27Operationoperator: 31
operand: 35
28ExprTuple33
29Literal
30ExprTuple34
31Literal
32ExprTuple35
33ExprTuple36, 37
34ExprRangelambda_map: 38
start_index: 39
end_index: 40
35Operationoperator: 101
operands: 41
36ExprRangelambda_map: 42
start_index: 108
end_index: 107
37ExprRangelambda_map: 42
start_index: 100
end_index: 85
38Lambdaparameter: 111
body: 43
39Operationoperator: 103
operands: 44
40Literal
41ExprTuple105, 99
42Lambdaparameter: 90
body: 45
43ExprTuple46, 47
44ExprTuple48, 108
45Operationoperator: 77
operands: 49
46ExprRangelambda_map: 50
start_index: 108
end_index: 107
47ExprRangelambda_map: 51
start_index: 108
end_index: 99
48Operationoperator: 109
operand: 107
49NamedExprselement: 53
targets: 54
50Lambdaparameter: 90
body: 55
51Lambdaparameter: 90
body: 57
52ExprTuple107
53Operationoperator: 80
operands: 58
54Operationoperator: 75
operands: 59
55Operationoperator: 60
operands: 61
56ExprTuple90
57Operationoperator: 77
operands: 62
58NamedExprsoperation: 63
part: 90
59ExprTuple108, 85
60Literal
61ExprTuple64, 65
62NamedExprselement: 66
targets: 67
63Operationoperator: 68
operands: 69
64Conditionalvalue: 70
condition: 71
65Conditionalvalue: 72
condition: 73
66Operationoperator: 80
operands: 74
67Operationoperator: 75
operands: 76
68Literal
69ExprTuple97, 107
70Operationoperator: 77
operands: 78
71Operationoperator: 79
operands: 83
72Operationoperator: 80
operands: 81
73Operationoperator: 82
operands: 83
74NamedExprsoperation: 84
part: 90
75Literal
76ExprTuple100, 85
77Literal
78NamedExprselement: 86
targets: 87
79Literal
80Literal
81NamedExprsoperation: 88
82Literal
83ExprTuple89, 90
84Operationoperator: 91
operands: 92
85Operationoperator: 103
operands: 93
86Literal
87Operationoperator: 94
operand: 100
88Literal
89Operationoperator: 103
operands: 96
90Variable
91Literal
92ExprTuple97, 98
93ExprTuple107, 99
94Literal
95ExprTuple100
96ExprTuple111, 107
97Variable
98Operationoperator: 101
operands: 102
99Variable
100Operationoperator: 103
operands: 104
101Literal
102ExprTuple105, 106
103Literal
104ExprTuple107, 108
105Literal
106Operationoperator: 109
operand: 111
107Variable
108Literal
109Literal
110ExprTuple111
111Variable