# This file was *autogenerated* from the file local_braid.sage
from sage.all_cmdline import *   # import sage library
_sage_const_2 = Integer(2); _sage_const_1 = Integer(1); _sage_const_0 = Integer(0)
"""
Local Braid Groups

This module contains several extensions to the sage braid group class.
It fills in additional methods and extend the existing method burau_matrix

##############################################################################
#       Copyright (C) 2016 Sebastian Oehms <[email protected]>
#
#  Distributed under the terms of the GNU General Public License (GPL)
#
#  The full text of the GPL is available at:
#
#                  http://www.gnu.org/licenses/
##############################################################################

This module contains extensions of the following classes from sage.groups.braid

    sage class                                     |  extended class
-------------------------------------------------------------------------------
    Braid                                          |  local_Braid
    BraidGroup_class                               |  local_BraidGroup_class


For further information see the documentation of the corresponding classes and methods

    sage: print local_Braid.__doc__
    sage: print local_Braid.burau_matrix_unitary.__doc__
    sage: print local_Braid.__burau_matrix_wikipedia__.__doc__
    sage: print local_Braid.__burau_matrix_unitary__.__doc__

    sage: print local_BraidGroup_class.__doc__
    sage: print local_BraidGroup_class.__doc__.__unitary_form__

EXAMPLES:
    
    see the documentation of the corresponding classes and methods

TESTS:     

    see the documentation of the corresponding classes and methods

AUTHOR

  - Sebastian Oehms, Oct. 2016

"""



####################################################################################################
# Extension to Braid Element Class defining the _burau_matrix_unitary_
####################################################################################################
from sage.groups.braid import *

class local_Braid(Braid):
    """
    This Class contains extensions to the Braid Element class.

    If you don't see this well formatted type 

    sage: print local_Braid.__doc__
     
    This class has two new methods and one overwriting the corresponding methods of the class Braid.

    New methods:
        - __burau_matrix_wikipedia__
        - __burau_matrix_unitary__

    Modified:
        . burau_matrix (using __burau_matrix_wikipedia__, __burau_matrix_unitary__ )


    For more information type

        sage: print local_Braid.__burau_matrix_wikipedia__.__doc__
        sage: print local_Braid.__burau_matrix_unitary__.__doc__
        sage: print local_Braid.burau_matrix.__doc__

    AUTHOR

     - Sebastian Oehms, Oct. 2016

    """

    def __burau_matrix_wikipedia__( self, var='t'):
        """
        The explicit reduced Burau representation given on Wikipedia since 11.03.2014 is different from the version 
        implemented in the braid-basis class. The version according to the recent Wikipedia-Page is implemented here.

        If you don't see this well formatted type 

        sage: print local_Braid.__burau_matrix_wikipedia__.__doc__


        Moreover it is the version used by Squier and Coxeter and will be used here to implement the unitary Burau 
        reoresentation 

        INPUT:

          - "var":  string (default: 't'); the name of the variable in the entries of the matrix. See also: 
                    print sage.groups.braid.Braid.burau_matrix.__doc__

        OUTPUT:

            The Burau matrix of the braid. It is a matrix whose entries are Laurent polynomials in the variable "var".

        EXAMPLES:

            sage: sage.groups.braid.BraidGroup_class = local_BraidGroup_class
            sage: B4 = BraidGroup(4)
            sage: b1, b2, b3 = B4.gens()
            sage: b = b1*b2/b3/b2
            sage: type(b)
            <class 'lib.local_braid.local_BraidGroup_class_with_category.element_class'>
            sage: b.__burau_matrix_wikipedia__()
            [    1 - t -t^-1 + 1        -1]
            [        1 -t^-1 + 1        -1]
            [        1     -t^-1         0]
            sage: b.__burau_matrix_wikipedia__(var='x')
            [    1 - x -x^-1 + 1        -1]
            [        1 -x^-1 + 1        -1]
            [        1     -x^-1         0]

          compare with the original method

            sage: b.burau_matrix()
            [       1 - t            0      t - t^2          t^2]
            [           1            0            0            0]
            [           0            0            1            0]
            [           0         t^-2 -t^-2 + t^-1    -t^-1 + 1]
            sage: b.burau_matrix(reduced=True)
            [                     0               -t + t^2                   -t^2]
            [                     0            1 - t + t^2                   -t^2]
            [                  t^-2 -t^-2 + t^-1 - t + t^2        -t^-1 + 1 - t^2]
            sage: 
       

        REFERENCES:

         - wikipedia:'Burau_representation'

        AUTHOR

         - Sebastian Oehms, Oct. 2016

        """
        R = LaurentPolynomialRing(IntegerRing(), var)
        t = R.gen()
        n = self.strands()
        M = identity_matrix(R, n-_sage_const_1 )
        for i in self.Tietze():
            A = identity_matrix(R, n-_sage_const_1 )
            if i > _sage_const_0 :
                A[i-_sage_const_1 , i-_sage_const_1 ] = -t
                if i > _sage_const_1 :
                    A[i-_sage_const_1 , i-_sage_const_2 ] = t
                if i < n-_sage_const_1 :
                    A[i-_sage_const_1 , i] = _sage_const_1 
            if i < _sage_const_0 :
                A[-i-_sage_const_1 , -i-_sage_const_1 ] = -t**(-_sage_const_1 )
                if -i > _sage_const_1 :
                    A[-i-_sage_const_1 , -i-_sage_const_2 ] = _sage_const_1 
                if -i < n-_sage_const_1 :
                    A[-i-_sage_const_1 , -i] = t**(-_sage_const_1 )
            M = M * A
        return M



    

    def __burau_matrix_unitary__(self, var='s'):
        """
        Return the unitary form of the Burau matrix of the braid according to
 
        CRAIG C. SQUIE: THE BURAU REPRESENTATION IS UNITARY, PROCEEDINGS OF THE AMERICAN MATHEMATICAL SOCIETY,
                        Volume 90. Number 2, February 1984

        If you don't see this well formatted type 

        sage: print local_Braid.__burau_matrix_unitary__.__doc__

        INPUT:

          - "var":  string (default: 's'); the name of the variable in the entries of the matrix. The connection with the 
                    variable t of the original burau_matrix is t=s**2. See also: 
                    print sage.groups.braid.Braid.burau_matrix.__doc__

        OUTPUT:

          The Burau matrix of the braid in the unitary form. It is obtained from the original burau_matrix by a base change
          in order to preserve a hermitian form. It is a matrix whose entries are Laurent polynomials in the variable "var".
          The original Burau matrix can be obtained by the method local_Braid.__burau_matrix_wikipedia__ 

        EXAMPLES:

            sage: sage.groups.braid.BraidGroup_class = local_BraidGroup_class
            sage: B4 = BraidGroup(4)
            sage: b1, b2, b3 = B4.gens()
            sage: b = b1*b2/b3/b2
            sage: type(b)
            <class 'lib.local_braid.local_BraidGroup_class_with_category.element_class'>
            sage: b.__burau_matrix_unitary__()
            [  1 - s^2 -s^-1 + s      -s^2]
            [     s^-1 -s^-2 + 1        -s]
            [     s^-2     -s^-3         0]
            sage: b.__burau_matrix_unitary__(var='x')
            [  1 - x^2 -x^-1 + x      -x^2]
            [     x^-1 -x^-2 + 1        -x]
            [     x^-2     -x^-3         0]
            sage: 

          compare with the version given on wikipedia:

            sage: b.__burau_matrix_wikipedia__()
            [    1 - t -t^-1 + 1        -1]
            [        1 -t^-1 + 1        -1]
            [        1     -t^-1         0]

          compare with the original method:

            sage: b.burau_matrix()
            [       1 - t            0      t - t^2          t^2]
            [           1            0            0            0]
            [           0            0            1            0]
            [           0         t^-2 -t^-2 + t^-1    -t^-1 + 1]
            sage: b.burau_matrix(reduced=True)
            [                     0               -t + t^2                   -t^2]
            [                     0            1 - t + t^2                   -t^2]
            [                  t^-2 -t^-2 + t^-1 - t + t^2        -t^-1 + 1 - t^2]
            sage: 

        REFERENCES:

        - Coxeter, H.S.M: "Factor groups of the braid groups, Proceedings of the Fourth Candian Mathematical Congress
          (Vancover      1957), pp. 95-122". 

        - C. C. Squier:`THE BURAU REPRESENTATION IS UNITARY`, PROCEEDINGS OF THE
                                                              AMERICAN MATHEMATICAL SOCIETY
                                                              Volume 90. Number 2, February 1984
        - Tyakay Venkataramana: Image of the Burau Representation at $d$-th Roots of unity. ANNALS OF MATHEMATICS MAY 2014

        AUTHOR

         - Sebastian Oehms, Oct. 2016

        """

        BurauOri = self.__burau_matrix_wikipedia__( )
        d = BurauOri.dimensions()[_sage_const_0 ]
        oriDomain = LaurentPolynomialRing(IntegerRing(), names=('t',)); (t,) = oriDomain._first_ngens(1)
        newDomain = LaurentPolynomialRing(IntegerRing(), var)
        s = newDomain.gen()
        subsVar = oriDomain.hom( [s**_sage_const_2 ], codomain = newDomain )
         
        BurauMat = matrix(d,d, lambda i,j:  subsVar(BurauOri[i,j] ) )
        transformP = matrix( newDomain, d,d , lambda i, j: _sage_const_0 )
        transformPI = matrix( newDomain, d,d , lambda i, j: _sage_const_0  )
        for i in range(d):
            transformP[i,i]=s**(i+_sage_const_1 )
            transformPI[i,i]=s**(-i-_sage_const_1 )
        res = transformPI * BurauMat * transformP
        return res 


    def burau_matrix(self, var='t', reduced=False, version='default'):
        """
        This method is a modification of the original burau_matrix-method. It contains an additional keyword-parameter 
        "version". If this keyword is not set or is set to the value 'default' it behaves like the original one.

        If you don't see this well formatted type:

        sage: print local_Braid.burau_matrix.__doc__

        To read the original docstring type:

        sage: print Braid.burau_matrix.__doc__

        INPUT:

          - "var":  string (default: 't'); the name of the variable in the entries of the matrix. See also: 
                    print sage.groups.braid.Braid.burau_matrix.__doc__
          - "reduced": boolean (default: 'False'); whether to return the reduced or unreduced Burau representation.
                    Note: if version is set to a value different from 'default' this keyword is ignored and treated
                    as set to 'True' (this means: no unreduced form for other versions)
          - "version": string (default = 'default' ). The following values are possible

            - "default" the method behaves like the original one. For more information on this see
               sage: print Braid.burau_matrix.__doc__

            - "unitary" gives the unitary form according to Squier. For more information on this see
               sage: print local_Braid.__burau_matrix_unitary__.__doc__
                       
            - any value else gives the reduced form given on wikipedia. For more information on this see
               sage: print local_Braid.__burau_matrix_wikipedia__.__doc__

        OUTPUT:

            The Burau matrix of the braid. It is a matrix whose entries are Laurent polynomials in the variable "var".
                      
        EXAMPLES:

            sage: sage.groups.braid.BraidGroup_class = local_BraidGroup_class
            sage: B4 = BraidGroup(4)
            sage: b1, b2, b3 = B4.gens()
            sage: b = b1*b2/b3/b2
            sage: type(b)
            <class 'lib.local_braid.local_BraidGroup_class_with_category.element_class'>
            sage: b.burau_matrix()
            [       1 - t            0      t - t^2          t^2]
            [           1            0            0            0]
            [           0            0            1            0]
            [           0         t^-2 -t^-2 + t^-1    -t^-1 + 1]
            sage: b.burau_matrix(version='unitary')
            [  1 - t^2 -t^-1 + t      -t^2]
            [     t^-1 -t^-2 + 1        -t]
            [     t^-2     -t^-3         0]
            sage: b.burau_matrix(version='wiki')
            [    1 - t -t^-1 + 1        -1]
            [        1 -t^-1 + 1        -1]
            [        1     -t^-1         0]
            sage: b.burau_matrix(version='wiki', reduced=True)
            [    1 - t -t^-1 + 1        -1]
            [        1 -t^-1 + 1        -1]
            [        1     -t^-1         0]
            sage: b.burau_matrix(version='wiki', reduced=False)
            [    1 - t -t^-1 + 1        -1]
            [        1 -t^-1 + 1        -1]
            [        1     -t^-1         0]
            sage: b.burau_matrix(reduced=True)
            [                     0               -t + t^2                   -t^2]
            [                     0            1 - t + t^2                   -t^2]
            [                  t^-2 -t^-2 + t^-1 - t + t^2        -t^-1 + 1 - t^2]
            sage: b.burau_matrix(var='s', version='unitary')
            [  1 - s^2 -s^-1 + s      -s^2]
            [     s^-1 -s^-2 + 1        -s]
            [     s^-2     -s^-3         0]
            sage: 


        AUTHOR

         - Sebastian Oehms, Oct. 2016

        """

        if version == 'default':
            return sage.groups.braid.Braid.burau_matrix(self, var=var, reduced=reduced )
        elif version == 'unitary':
            return self.__burau_matrix_unitary__(var=var)
        else:
            return self.__burau_matrix_wikipedia__(var=var)




class local_BraidGroup_class(BraidGroup_class):
    """
    This Class contains extensions to the sage BraidGroup class. 

    If you don't see this well formatted type:

    sage: print local_BraidGroup_class.__doc__

    New methods:

        - __unitary_form__

    Modified:

        . Element Class is local_Braid instead of Braid. This contains extension of the burau_matrix -method
          For more information type:

          sage: print local_Braid.__doc__

    AUTHOR

     - Sebastian Oehms, Oct. 2016

    """
    Element = local_Braid

    def __unitary_form__( self, var='s' ):
        """
        Returns the hermitian form with respect to the __unitary_burau_matrix__ of the Element Class

        If you don't see this well formatted type:

        sage: print local_BraidGroup_class.__unitary_form__.__doc__

        The hermitian form returned by this method is kept invariant by the unitary Burau matrices returned by the 
        local_Braid -method burau_matrix() setting the version keyword to 'unitary'

        For more information on the unitary Burau matrices type         

           sage: print local_Braid.__burau_matrix_unitary__.__doc__
           sage: print local_Braid.burau_matrix.__doc__

        INPUT:

          - "var":  string (default: 's'); the name of the variable in the entries of the matrix of the unitary form. 

        OUTPUT:

          The hermitian form as a quadratic matrix whose entries are Laurent polynomials in the variable "var".

        EXAMPLES:

            sage: sage.groups.braid.BraidGroup_class = local_BraidGroup_class
            sage: B4 = BraidGroup(4)
            sage: B4.__unitary_form__()
            [s^-1 + s       -1        0]
            [      -1 s^-1 + s       -1]
            [       0       -1 s^-1 + s]
            sage: 
            sage: 
            sage: B4.__unitary_form__(var='x')
            [x^-1 + x       -1        0]
            [      -1 x^-1 + x       -1]
            [       0       -1 x^-1 + x]
            sage: 

        REFERENCES:

        - Coxeter, H.S.M: "Factor groups of the braid groups, Proceedings of the Fourth Candian Mathematical Congress
          (Vancover      1957), pp. 95-122". 

        - C. C. Squier:`THE BURAU REPRESENTATION IS UNITARY`, PROCEEDINGS OF THE
                                                              AMERICAN MATHEMATICAL SOCIETY
                                                              Volume 90. Number 2, February 1984

        AUTHOR

         - Sebastian Oehms, Oct. 2016

        """
        R = LaurentPolynomialRing(IntegerRing(), var)
        t = R.gen()
        n = self.strands()
        M = (t+t**(-_sage_const_1 ))*identity_matrix(R, n-_sage_const_1 )
        for i in range(n-_sage_const_2 ):
            M[i,i+_sage_const_1 ] =-_sage_const_1 
            M[i+_sage_const_1 ,i] =-_sage_const_1 
        return M