Example #1
0
 def test_zero_is_multiplicative_nil(self):
     o = FermionOperator.zero()
     u = FermionOperator.identity()
     f = FermionOperator(((0, 1), (5, 0), (6, 1)), 0.6j)
     g = FermionOperator(((0, 0), (5, 0), (6, 1)), 0.3j)
     self.assertTrue(o.isclose(o * u))
     self.assertTrue(o.isclose(o * f))
     self.assertTrue(o.isclose(o * g))
     self.assertTrue(o.isclose(o * (f + g)))
Example #2
0
    def test_zero_is_additive_identity(self):
        o = FermionOperator.zero()
        f = FermionOperator(((0, 1), (5, 0), (6, 1)), 0.6j)
        g = FermionOperator(((0, 0), (5, 0), (6, 1)), 0.3j)
        h = f + g
        self.assertTrue(f.isclose(o + f))
        self.assertTrue(f.isclose(f + o))
        self.assertTrue(g.isclose(o + g))
        self.assertTrue(g.isclose(g + o))
        self.assertTrue(h.isclose(o + h))
        self.assertTrue(h.isclose(h + o))

        o += h
        self.assertTrue(h.isclose(o))
        self.assertFalse(f.isclose(o))

        # Method always returns new instances.
        self.assertFalse(FermionOperator.zero().isclose(o))