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 Conditional, k
from proveit.linear_algebra import ScalarMult
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Add, Exp, Interval, Mult, e, i, one, pi, two, zero
from proveit.physics.quantum import Ket
from proveit.physics.quantum.QPE import _phase
In [2]:
# build up the expression from sub-expressions
sub_expr1 = ScalarMult(Exp(e, Mult(two, pi, i, _phase, k)), Ket(k))
expr = Forall(instance_param_or_params = [k], instance_expr = Equals(Conditional(sub_expr1, InSet(k, Interval(Add(zero, one), one))), Conditional(sub_expr1, InSet(k, Interval(one, one)))))
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_{k}~\left(\left\{\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle \textrm{ if } k \in \{0 + 1~\ldotp \ldotp~1\}\right.. = \left\{\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle \textrm{ if } k \in \{1~\ldotp \ldotp~1\}\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: 41
body: 4
4Operationoperator: 5
operands: 6
5Literal
6ExprTuple7, 8
7Conditionalvalue: 10
condition: 9
8Conditionalvalue: 10
condition: 11
9Operationoperator: 15
operands: 12
10Operationoperator: 13
operands: 14
11Operationoperator: 15
operands: 16
12ExprTuple41, 17
13Literal
14ExprTuple18, 19
15Literal
16ExprTuple41, 20
17Operationoperator: 26
operands: 21
18Operationoperator: 22
operands: 23
19Operationoperator: 24
operand: 41
20Operationoperator: 26
operands: 27
21ExprTuple28, 36
22Literal
23ExprTuple29, 30
24Literal
25ExprTuple41
26Literal
27ExprTuple36, 36
28Operationoperator: 31
operands: 32
29Literal
30Operationoperator: 33
operands: 34
31Literal
32ExprTuple35, 36
33Literal
34ExprTuple37, 38, 39, 40, 41
35Literal
36Literal
37Literal
38Literal
39Literal
40Literal
41Variable