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, Variable, VertExprArray, t
from proveit.logic import Equals, Forall
from proveit.numbers import Add, Interval, NaturalPos, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE1, _U, _ket_u, _psi_t_ket, _s
from proveit.physics.quantum.circuits import Gate, Input, MultiQubitElem, Output, Qcircuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, one)
sub_expr3 = Add(t, _s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE1(_U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Forall(instance_param_or_params = [t], instance_expr = Equals(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)], [ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _psi_t_ket, part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)]))), one), 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_{t \in \mathbb{N}^+}~\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}_1\left(U, t\right)} & \multiqout{3}{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \qout{\lvert u \rangle}
} \end{array}\right) = 1\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: 80
body: 4
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operands: 8
6Operationoperator: 9
operands: 10
7Literal
8ExprTuple11, 79
9Literal
10ExprTuple80, 12
11Operationoperator: 13
operand: 15
12Literal
13Literal
14ExprTuple15
15Operationoperator: 16
operands: 17
16Literal
17ExprTuple18, 19, 20
18ExprTuple21, 22
19ExprTuple23, 24
20ExprTuple25, 26
21ExprRangelambda_map: 27
start_index: 79
end_index: 80
22ExprRangelambda_map: 28
start_index: 79
end_index: 81
23ExprRangelambda_map: 29
start_index: 79
end_index: 80
24ExprRangelambda_map: 29
start_index: 69
end_index: 70
25ExprRangelambda_map: 30
start_index: 79
end_index: 80
26ExprRangelambda_map: 31
start_index: 79
end_index: 81
27Lambdaparameter: 68
body: 32
28Lambdaparameter: 68
body: 33
29Lambdaparameter: 68
body: 34
30Lambdaparameter: 68
body: 35
31Lambdaparameter: 68
body: 37
32Operationoperator: 54
operands: 38
33Operationoperator: 42
operands: 39
34Operationoperator: 42
operands: 40
35Operationoperator: 42
operands: 41
36ExprTuple68
37Operationoperator: 42
operands: 43
38NamedExprsstate: 44
39NamedExprselement: 45
targets: 51
40NamedExprselement: 46
targets: 47
41NamedExprselement: 48
targets: 49
42Literal
43NamedExprselement: 50
targets: 51
44Operationoperator: 52
operand: 64
45Operationoperator: 54
operands: 61
46Operationoperator: 55
operands: 56
47Operationoperator: 62
operands: 57
48Operationoperator: 60
operands: 58
49Operationoperator: 62
operands: 59
50Operationoperator: 60
operands: 61
51Operationoperator: 62
operands: 63
52Literal
53ExprTuple64
54Literal
55Literal
56NamedExprsoperation: 65
part: 68
57ExprTuple79, 70
58NamedExprsstate: 66
part: 68
59ExprTuple79, 80
60Literal
61NamedExprsstate: 67
part: 68
62Literal
63ExprTuple69, 70
64Literal
65Operationoperator: 71
operands: 72
66Operationoperator: 73
operand: 80
67Literal
68Variable
69Operationoperator: 76
operands: 75
70Operationoperator: 76
operands: 77
71Literal
72ExprTuple78, 80
73Literal
74ExprTuple80
75ExprTuple80, 79
76Literal
77ExprTuple80, 81
78Literal
79Literal
80Variable
81Literal