---------------------------------------------------------------------------------------------------
-- |
-- Module      : Helpers
-- Description : Useful functions
-- Copyright   : (c) Felix Springer, 2019
-- License     : BSD3
-- Maintainer  : felixspringer149@gmail.com
-- Stability   : experimental
-- Portability : POSIX
--
-- This module wraps around the other modules and defines functions to help interacting with the
-- data types.
--
---------------------------------------------------------------------------------------------------

module Lie.Helpers ( toDynkin
                   , rank
                   , simple
                   ) where

import Lie.Classification
import Lie.Dynkin

rank     :: Simple -> Int
rank (A n) = n
rank (B n) = n
rank (C n) = n
rank (D n) = n
rank  E6   = 6
rank  E7   = 7
rank  E8   = 8
rank  F4   = 4
rank  G2   = 2

simple :: SemiSimple -> Bool
simple (DirectSum ls)
  | length ls == 1 = True
  | length ls > 1  = False

toDynkin :: Simple -> Dynkin
toDynkin x = Dynkin $ toDynkinNode x

toDynkinNode :: Simple -> DynkinNode
toDynkinNode (A 1) = DynkinNode []
toDynkinNode (A n) = DynkinNode [ DynkinVertex 1 (toDynkinNode (A (n - 1))) ]
toDynkinNode (B 2) = DynkinNode [ DynkinVertexToShort 2 (DynkinNode [])        ]
toDynkinNode (B n) = DynkinNode [ DynkinVertex        1 (toDynkinNode (B (n - 1))) ]
toDynkinNode (C 2) = DynkinNode [ DynkinVertexToLong 2 (DynkinNode [])        ]
toDynkinNode (C n) = DynkinNode [ DynkinVertex       1 (toDynkinNode (C (n - 1))) ]
toDynkinNode (D 3) = DynkinNode [ DynkinVertex 1 (DynkinNode [])
                            , DynkinVertex 1 (DynkinNode [])
                            ]
toDynkinNode (D n) = DynkinNode [ DynkinVertex 1 (toDynkinNode (D (n - 1))) ]
toDynkinNode  E6   = DynkinNode [ DynkinVertex 1 (DynkinNode
                              [ DynkinVertex 1 (DynkinNode
                                [ DynkinVertex 1 (DynkinNode
                                  [ DynkinVertex 1 (DynkinNode [])])
                                , DynkinVertex 1 (DynkinNode []) ]) ]) ]
toDynkinNode  E7   = DynkinNode [ DynkinVertex 1 (toDynkinNode E6) ]
toDynkinNode  E8   = DynkinNode [ DynkinVertex 1 (toDynkinNode E7) ]
toDynkinNode  F4   = DynkinNode [ DynkinVertex 1 (DynkinNode
                              [ DynkinVertexToShort 2 (DynkinNode
                                [ DynkinVertex 1 (DynkinNode []) ]) ]) ]
toDynkinNode  G2   = DynkinNode [ DynkinVertexToShort 3 (DynkinNode []) ]