logo

Expression of type Exists

from the theory of proveit.physics.quantum.algebra

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, IndexedVar, Variable, i, lambda_, m, n
from proveit.core_expr_types import a_i, b_i, lambda_i
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.logic import Equals, Exists
from proveit.numbers import Interval, Min, RealNonNeg, one
from proveit.physics.quantum import Ket, Qmult, var_ket_psi
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Min(m, n)
expr = Exists(instance_param_or_params = [ExprRange(sub_expr1, IndexedVar(lambda_, sub_expr1), one, sub_expr2)], instance_expr = Equals(var_ket_psi, VecSum(index_or_indices = [i], summand = ScalarMult(lambda_i, Qmult(Ket(a_i), Ket(b_i))), domain = Interval(one, sub_expr2))), domain = RealNonNeg).with_wrapping()
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())
\begin{array}{l}\exists_{\lambda_{1}, \lambda_{2}, \ldots, \lambda_{{\rm Min}\left(m, n\right)} \in \mathbb{R}^{\ge 0}}~\\
\left(\lvert \psi \rangle = \left(\sum_{i=1}^{{\rm Min}\left(m, n\right)} \left(\lambda_{i} \cdot \left(\lvert a_{i} \rangle \thinspace \lvert b_{i} \rangle\right)\right)\right)\right)\end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('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
3Lambdaparameters: 4
body: 5
4ExprTuple6
5Conditionalvalue: 7
condition: 8
6ExprRangelambda_map: 9
start_index: 44
end_index: 45
7Operationoperator: 10
operands: 11
8Operationoperator: 12
operands: 13
9Lambdaparameter: 36
body: 26
10Literal
11ExprTuple14, 15
12Literal
13ExprTuple16
14Variable
15Operationoperator: 17
operand: 20
16ExprRangelambda_map: 19
start_index: 44
end_index: 45
17Literal
18ExprTuple20
19Lambdaparameter: 36
body: 21
20Lambdaparameter: 58
body: 22
21Operationoperator: 30
operands: 23
22Conditionalvalue: 24
condition: 25
23ExprTuple26, 27
24Operationoperator: 28
operands: 29
25Operationoperator: 30
operands: 31
26IndexedVarvariable: 37
index: 36
27Literal
28Literal
29ExprTuple33, 34
30Literal
31ExprTuple58, 35
32ExprTuple36
33IndexedVarvariable: 37
index: 58
34Operationoperator: 38
operands: 39
35Operationoperator: 40
operands: 41
36Variable
37Variable
38Literal
39ExprTuple42, 43
40Literal
41ExprTuple44, 45
42Operationoperator: 47
operand: 51
43Operationoperator: 47
operand: 52
44Literal
45Operationoperator: 49
operands: 50
46ExprTuple51
47Literal
48ExprTuple52
49Literal
50ExprTuple53, 54
51IndexedVarvariable: 55
index: 58
52IndexedVarvariable: 56
index: 58
53Variable
54Variable
55Variable
56Variable
57ExprTuple58
58Variable