from sympy.core import Set, Dict, Tuple
from .cartan_type import Standard_Cartan
from sympy.matrices import eye


class TypeE(Standard_Cartan):

    def __init__(self, n):
        assert n >= 6
        assert n <= 8
        Standard_Cartan.__init__(self, "E", n)

    def dimension(self):
        """
        Returns the dimension of the vector space
        V underlying the Lie algebra
        Example
        ========
        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType("E6")
        >>> c.dimension()
        8
        """

        return 8

    def basic_root(self, i, j):
        """
        This is a method just to generate roots
        with a -1 in the ith position and a 1
        in the jth postion.

        """

        root = [0]*8
        root[i] = -1
        root[j] = 1
        return root

    def simple_root(self, i):
        """
        Returns the ith simple root for E_n.

        Examples
        ========
        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType("E6")
        >>> c.simple_root(2)
        [1, 1, 0, 0, 0, 0, 0, 0]
        """
        n = self.n
        if i == 1:
            root = [-0.5]*8
            root[0] = 0.5
            root[7] = 0.5
            return root
        elif i == 2:
            root = [0]*8
            root[1] = 1
            root[0] = 1
            return root
        else:
            if i == 7 or i == 8 and n == 6:
                raise ValueError("E6 only has six simple roots!")
            if i == 8 and n == 7:
                raise ValueError("E7 has only 7 simple roots!")

            return self.basic_root(i-3, i-2)

    def roots(self):
        """
        Returns the total number of roots of E_n
        """

        n = self.n
        if n == 6:
            return 72
        if n == 7:
            return 126
        if n == 8:
            return 240


    def cartan_matrix(self):
        """
        Returns the Cartan matrix for G_2
        The Cartan matrix matrix for a Lie algebra is
        generated by assigning an ordering to the simple
        roots, (alpha[1], ...., alpha[l]).  Then the ijth
        entry of the Cartan matrix is (<alpha[i],alpha[j]>).

        Example
        =======
        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType('A4')
        >>> c.cartan_matrix()
        Matrix([
        [ 2, -1,  0,  0],
        [-1,  2, -1,  0],
        [ 0, -1,  2, -1],
        [ 0,  0, -1,  2]])


        """

        n = self.n
        m = 2*eye(n)
        i = 3
        while i < n-1:
            m[i, i+1] = -1
            m[i, i-1] = -1
            i += 1
        m[0, 2] = m[2, 0] = -1
        m[1, 3] = m[3, 1] = -1
        m[2, 3] = -1
        m[n-1, n-2] = -1
        return m


    def basis(self):
        """
        Returns the number of independent generators of E_n
        """

        n = self.n
        if n == 6:
            return 78
        if n == 7:
            return 133
        if n == 8:
            return 248

from sympy.core import Set, Dict, Tuple
from .cartan_type import Standard_Cartan
from sympy.matrices import eye


class TypeE(Standard_Cartan):

    def __init__(self, n):
        assert n >= 6
        assert n <= 8
        Standard_Cartan.__init__(self, "E", n)

    def dimension(self):
        """
        Returns the dimension of the vector space
        V underlying the Lie algebra
        Example
        ========
        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType("E6")
        >>> c.dimension()
        8
        """

        return 8

    def basic_root(self, i, j):
        """
        This is a method just to generate roots
        with a -1 in the ith position and a 1
        in the jth postion.

        """

        root = [0]*8
        root[i] = -1
        root[j] = 1
        return root

    def simple_root(self, i):
        """
        Returns the ith simple root for E_n.

        Examples
        ========
        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType("E6")
        >>> c.simple_root(2)
        [1, 1, 0, 0, 0, 0, 0, 0]
        """
        n = self.n
        if i == 1:
            root = [-0.5]*8
            root[0] = 0.5
            root[7] = 0.5
            return root
        elif i == 2:
            root = [0]*8
            root[1] = 1
            root[0] = 1
            return root
        else:
            if i == 7 or i == 8 and n == 6:
                raise ValueError("E6 only has six simple roots!")
            if i == 8 and n == 7:
                raise ValueError("E7 has only 7 simple roots!")

            return self.basic_root(i-3, i-2)

    def roots(self):
        """
        Returns the total number of roots of E_n
        """

        n = self.n
        if n == 6:
            return 72
        if n == 7:
            return 126
        if n == 8:
            return 240


    def cartan_matrix(self):
        """
        Returns the Cartan matrix for G_2
        The Cartan matrix matrix for a Lie algebra is
        generated by assigning an ordering to the simple
        roots, (alpha[1], ...., alpha[l]).  Then the ijth
        entry of the Cartan matrix is (<alpha[i],alpha[j]>).

        Example
        =======
        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType('A4')
        >>> c.cartan_matrix()
        Matrix([
        [ 2, -1,  0,  0],
        [-1,  2, -1,  0],
        [ 0, -1,  2, -1],
        [ 0,  0, -1,  2]])


        """

        n = self.n
        m = 2*eye(n)
        i = 3
        while i < n-1:
            m[i, i+1] = -1
            m[i, i-1] = -1
            i += 1
        m[0, 2] = m[2, 0] = -1
        m[1, 3] = m[3, 1] = -1
        m[2, 3] = -1
        m[n-1, n-2] = -1
        return m


    def basis(self):
        """
        Returns the number of independent generators of E_n
        """

        n = self.n
        if n == 6:
            return 78
        if n == 7:
            return 133
        if n == 8:
            return 248

Returns the dimension of the vector space         V underlying the Lie algebra         Example         ========         >>> from sympy.liealgebras.cartan_type import CartanType         >>> c = CartanType("E6")         >>> c.dimension()         8 This is a method just to generate roots         with a -1 in the ith position and a 1         in the jth postion. Returns the ith simple root for E_n.          Examples         ========         >>> from sympy.liealgebras.cartan_type import CartanType         >>> c = CartanType("E6")         >>> c.simple_root(2)         [1, 1, 0, 0, 0, 0, 0, 0] Returns the total number of roots of E_n Returns the Cartan matrix for G_2         The Cartan matrix matrix for a Lie algebra is         generated by assigning an ordering to the simple         roots, (alpha[1], ...., alpha[l]).  Then the ijth         entry of the Cartan matrix is (<alpha[i],alpha[j]>).          Example         =======         >>> from sympy.liealgebras.cartan_type import CartanType         >>> c = CartanType('A4')         >>> c.cartan_matrix()         Matrix([         [ 2, -1,  0,  0],         [-1,  2, -1,  0],         [ 0, -1,  2, -1],         [ 0,  0, -1,  2]]) Returns the number of independent generators of E_n