import proveit
from proveit import defaults
from proveit import alpha, beta, gamma, delta, j, m, n, b, c, A, B, C, D
from proveit.core_expr_types import b_1_to_j, f__b_1_to_j, Q__b_1_to_j
from proveit.logic import Forall, InSet, CartExp, InClass
from proveit.numbers import Complex, NaturalPos
from proveit.linear_algebra import VecAdd, MatrixSpace
from proveit.linear_algebra.addition import vec_summation_b1toj_fQ
from proveit.physics.quantum import Qmult, Bra, Ket
from proveit.physics.quantum import (
psi, bra_psi, ket_psi, varphi, bra_varphi, ket_varphi)
from proveit.physics.quantum.algebra import QmultCodomain
%begin demonstrations
all_instances_in_C_nxm = Forall(
b_1_to_j, InSet(f__b_1_to_j, MatrixSpace(Complex, n, m)),
condition=Q__b_1_to_j)
defaults.assumptions = [
InSet(alpha, Complex), InSet(beta, Complex),
InSet(gamma, Complex), InSet(delta, Complex),
InSet(j, NaturalPos),
InSet(m, NaturalPos), InSet(n, NaturalPos),
InSet(ket_psi, CartExp(Complex, m)),
InSet(A, MatrixSpace(Complex, n, m)),
InSet(B, MatrixSpace(Complex, n, m)),
InSet(C, MatrixSpace(Complex, n, m)),
InSet(D, MatrixSpace(Complex, m, n)),
InSet(ket_varphi, CartExp(Complex, n)),
all_instances_in_C_nxm,
Q__b_1_to_j.basic_replaced({b:c})
]
all_instances_in_C_nxm.instantiate({b:c})
Well-formed:
qmult1 = Qmult(alpha, A, beta, ket_psi, gamma)
qmult2 = Qmult(bra_varphi, alpha, A, beta,
ket_psi, gamma, bra_varphi, delta)
qmult3 = Qmult(bra_varphi, alpha, VecAdd(A, B, C), beta,
ket_psi, gamma, bra_varphi, delta)
qmult4 = Qmult(bra_varphi, alpha, vec_summation_b1toj_fQ, beta,
ket_psi, gamma, bra_varphi, delta).basic_replaced(
{b:c}, allow_relabeling=True)
qmult5 = Qmult(alpha, A, beta, VecAdd(ket_psi, Qmult(D, ket_varphi)))
qmult6 = Qmult(alpha, D, beta, VecAdd(Qmult(B, ket_psi), ket_varphi))
Not well-formed (matrix-vector incompatible):
qmult_bad = Qmult(alpha, D, beta, ket_psi,
gamma, Bra(varphi), delta)
print(Qmult.simplification_directive_keys())
Qmult.change_simplification_directives(
ungroup=False, factor_scalars=False, use_scalar_mult=False)
InClass(alpha, QmultCodomain).prove()
InClass(ket_psi, QmultCodomain).prove()
InClass(Bra(varphi), QmultCodomain).prove()
InClass(Qmult(alpha), QmultCodomain).prove()
InClass(Qmult(ket_psi), QmultCodomain).prove()
InClass(Qmult(A), QmultCodomain).prove()
InClass(Qmult(bra_varphi), QmultCodomain).prove()
InClass(Qmult(ket_varphi, bra_psi), QmultCodomain).prove()
InClass(Qmult(D, ket_varphi), QmultCodomain).prove()
InClass(Qmult(bra_psi, ket_psi), QmultCodomain).prove()
InClass(Qmult(alpha, A), QmultCodomain).prove()
InClass(Qmult(bra_varphi, ket_varphi, gamma), QmultCodomain).prove()
qmult1
InClass(qmult1, QmultCodomain).prove()
qmult5
InClass(qmult5, QmultCodomain).prove()
help(Qmult.association)
help(Qmult.disassociation)
qmult1
qmult1_association = qmult1.association(1, 2)
qmult1_associated = qmult1_association.rhs
qmult1_associated.disassociation(1)
qmult2
qmult2.association(5, 3)
If the Qmult is not well-formed, we expect an error:
qmult_bad
from proveit import UnsatisfiedPrerequisites try: qmult_bad.association(2, 3) assert False # expecting an error except UnsatisfiedPrerequisites as e: print("Expected error: %s"%e)
Scalars are pulled to the front automatically with the default simplification directives. This directive is currently disabled, however. Here, we demonstrate doing this manually.
help(Qmult.factorization_of_scalars)
qmult1.factorization_of_scalars()
qmult2
qmult2.factorization_of_scalars()
help(Qmult.distribution)
qmult3
QmultCodomain.membership_object(qmult3).expr
InClass(qmult3, QmultCodomain).prove()
qmult3.distribution(2)
qmult4
qmult4.distribution(2)
qmult5
qmult5.distribution(3)
qmult6
qmult6.distribution(3)
help(Qmult.simplification)
help(Qmult.shallow_simplification)
Qmult.change_simplification_directives(ungroup=True,
factor_scalars=True,
use_scalar_mult=True)
qmult1.simplification()
qmult1_associated
qmult1_associated.simplification()
qmult4
qmult4.simplification()
%end demonstrations