def d2q2element(p: int, q: int, r: int, s: int, factor: Union[float, int])\ -> DualBasisElement: """ Build the dual basis element for symmetric form of 2-marginal :param p: tensor index :param q: tensor index :param r: tensor index :param s: tensor index :param factor: scaling coeff for a symmetric constraint :return: the dual basis of the mapping """ dbe = DualBasisElement() dbe.add_element('cckk', (p, q, r, s), -1.0 * factor) dbe.add_element('kkcc', (r, s, p, q), +1.0 * factor) if q == s: dbe.add_element('ck', (p, r), factor) if p == r: dbe.add_element('ck', (q, s), factor) if q == r: dbe.add_element('ck', (p, s), -1. * factor) if p == s: dbe.add_element('ck', (q, r), -1. * factor) dbe.dual_scalar = ( kronecker_delta(q, s) * kronecker_delta(p, r) - kronecker_delta(q, r) * kronecker_delta(p, s)) * factor return dbe
def test_kronecker_delta_nonunit_args(self): assert kronecker_delta(3, 3) == 1
def test_kronecker_delta_11(self): assert kronecker_delta(1, 1) == 1
def test_kronecker_delta_10(self): assert kronecker_delta(1, 0) == 0
def test_kronecker_delta_01(self): assert kronecker_delta(0, 1) == 0
def test_kronecker_delta_00(self): assert kronecker_delta(0, 0) == 1