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 e, l
from proveit.logic import Equals, Forall
from proveit.numbers import Abs, Add, Exp, Sum, two
from proveit.physics.quantum.QPE import Pfail, _e_domain, _neg_domain, _pos_domain, _rel_indexed_alpha
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [l]
sub_expr2 = Exp(Abs(_rel_indexed_alpha), two)
expr = Forall(instance_param_or_params = [e], instance_expr = Equals(Pfail(e), Add(Sum(index_or_indices = sub_expr1, summand = sub_expr2, domain = _neg_domain), Sum(index_or_indices = sub_expr1, summand = sub_expr2, domain = _pos_domain))), domain = _e_domain)
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_{e \in \{1~\ldotp \ldotp~2^{t - 1} - 2\}}~\left(\left[P_{\rm fail}\right]\left(e\right) = \left(\left(\sum_{l = -2^{t - 1} + 1}^{-\left(e + 1\right)} \left|\alpha_{b_{\textit{f}} \oplus l}\right|^{2}\right) + \left(\sum_{l = e + 1}^{2^{t - 1}} \left|\alpha_{b_{\textit{f}} \oplus l}\right|^{2}\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: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameter: 61
body: 4
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operands: 8
6Operationoperator: 36
operands: 9
7Literal
8ExprTuple10, 11
9ExprTuple61, 12
10Operationoperator: 13
operand: 61
11Operationoperator: 68
operands: 15
12Operationoperator: 44
operands: 16
13Literal
14ExprTuple61
15ExprTuple17, 18
16ExprTuple74, 19
17Operationoperator: 21
operand: 24
18Operationoperator: 21
operand: 25
19Operationoperator: 68
operands: 23
20ExprTuple24
21Literal
22ExprTuple25
23ExprTuple60, 26
24Lambdaparameter: 63
body: 27
25Lambdaparameter: 63
body: 29
26Operationoperator: 72
operand: 66
27Conditionalvalue: 32
condition: 31
28ExprTuple63
29Conditionalvalue: 32
condition: 33
30ExprTuple66
31Operationoperator: 36
operands: 34
32Operationoperator: 64
operands: 35
33Operationoperator: 36
operands: 37
34ExprTuple63, 38
35ExprTuple39, 66
36Literal
37ExprTuple63, 40
38Operationoperator: 44
operands: 41
39Operationoperator: 42
operand: 48
40Operationoperator: 44
operands: 45
41ExprTuple46, 47
42Literal
43ExprTuple48
44Literal
45ExprTuple54, 60
46Operationoperator: 68
operands: 49
47Operationoperator: 72
operand: 54
48Operationoperator: 51
operand: 55
49ExprTuple53, 74
50ExprTuple54
51Literal
52ExprTuple55
53Operationoperator: 72
operand: 60
54Operationoperator: 68
operands: 57
55Operationoperator: 58
operands: 59
56ExprTuple60
57ExprTuple61, 74
58Literal
59ExprTuple62, 63
60Operationoperator: 64
operands: 65
61Variable
62Literal
63Variable
64Literal
65ExprTuple66, 67
66Literal
67Operationoperator: 68
operands: 69
68Literal
69ExprTuple70, 71
70Literal
71Operationoperator: 72
operand: 74
72Literal
73ExprTuple74
74Literal