Ejemplo n.º 1
0
    def test_mul_inverse(self):
        ga = GeometricAlgebra(metric=dual_metric)

        # a = 2
        a = ga.from_tensor_with_kind(tf.fill([1], 2.0), kind="scalar")

        # b = 3 + 3e0
        b = ga.from_tensor_with_kind(tf.fill([2], 3.0), kind="mv")

        # a * b = 2 * (3 + 3e0) = 6 + 6e0
        c = ga.geom_prod(a, b)
        self.assertTensorsEqual(c, ga.from_scalar(6.0) + 6.0 * ga.e("0"))

        # a^-1 = 1 / 2
        a_inv = ga.inverse(a)
        self.assertTensorsEqual(ga.select_blades_with_name(a_inv, ""), 0.5)

        # c = a * b
        # => a_inv * c = b
        self.assertTensorsEqual(ga.geom_prod(a_inv, c), b)

        # Since a is scalar, should commute too.
        # => c * a_inv = b
        self.assertTensorsEqual(ga.geom_prod(c, a_inv), b)

        # b is not simply invertible (because it does not square to a scalar)
        # and will throw an exception
        self.assertRaises(Exception, ga.simple_inverse, b)

        # b is invertible with the shirokov inverse
        b_inv = ga.inverse(b)
        self.assertTensorsEqual(ga.geom_prod(b, b_inv), 1 * ga.e(""))
Ejemplo n.º 2
0
    def test_inverse(self):
        pga = GeometricAlgebra(pga_signature)

        # a = 3e12 + 5e23
        a = 3 * pga.e12 + 5 * pga.e23

        # a_inv: -0.09*e_12 + -0.15*e_23
        a_inv = pga.inverse(a)

        # a a_inv should be 1
        self.assertTensorsApproxEqual(pga.geom_prod(a, a_inv), 1 * pga.e(""))