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 Variable, t
from proveit.linear_algebra import Norm, ScalarMult, VecAdd
from proveit.logic import Equals, Forall
from proveit.numbers import Add, Exp, Interval, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _phase
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = Forall(instance_param_or_params = [sub_expr1], instance_expr = Equals(Norm(ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1)))), one), domain = Interval(Add(Neg(t), one), zero))
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_{{_{-}a} \in \{-t + 1~\ldotp \ldotp~0\}}~\left(\left \|\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-{_{-}a}} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\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: 61
body: 4
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operands: 8
6Operationoperator: 9
operands: 10
7Literal
8ExprTuple11, 48
9Literal
10ExprTuple61, 12
11Operationoperator: 13
operand: 17
12Operationoperator: 15
operands: 16
13Literal
14ExprTuple17
15Literal
16ExprTuple18, 38
17Operationoperator: 35
operands: 19
18Operationoperator: 20
operands: 21
19ExprTuple22, 23
20Literal
21ExprTuple24, 48
22Operationoperator: 41
operands: 25
23Operationoperator: 26
operands: 27
24Operationoperator: 59
operand: 32
25ExprTuple48, 29
26Literal
27ExprTuple30, 31
28ExprTuple32
29Operationoperator: 55
operands: 33
30Operationoperator: 44
operand: 38
31Operationoperator: 35
operands: 36
32Variable
33ExprTuple57, 37
34ExprTuple38
35Literal
36ExprTuple39, 40
37Operationoperator: 41
operands: 42
38Literal
39Operationoperator: 55
operands: 43
40Operationoperator: 44
operand: 48
41Literal
42ExprTuple48, 57
43ExprTuple46, 47
44Literal
45ExprTuple48
46Literal
47Operationoperator: 49
operands: 50
48Literal
49Literal
50ExprTuple57, 51, 52, 53, 54
51Literal
52Literal
53Operationoperator: 55
operands: 56
54Literal
55Literal
56ExprTuple57, 58
57Literal
58Operationoperator: 59
operand: 61
59Literal
60ExprTuple61
61Variable