.. _SectRSRoot:

.. _roots-coroots-weights:

Roots and Coroots
=================

The roots are stored as an indexed set

.. math:: \{@\; \alpha_1,\dots,\alpha_N,\alpha_{N+1},\dots,\alpha_{2N} \; @\},

where :math:`\alpha_1,\dots,\alpha_N` are the positive roots (in an order
compatible with height), and :math:`\alpha_{N+1},\dots,\alpha_{2N}` are the
corresponding negative roots (i.e. :math:`\alpha_{i+N}=-\alpha_i`). The simple
roots are :math:`\alpha_1,\dots,\alpha_n` where :math:`n` is the rank.

Many of these functions have an optional argument ``Basis`` which may take one
of the following values

1. ``"Standard"``: the standard basis for the (co)root space (this is the
default); or

2. ``"Root"``: the basis of simple (co)roots.

.. _SubsectRSRootAccess:

.. _access:

Accessing Roots and Coroots
---------------------------

.. magma:function:: RootSpace(R)
   :input_types: RootSys
   :output_types: ModTupFld
   :label: RootSpace_RootSys

.. magma:function:: CorootSpace(R)
   :input_types: RootSys
   :output_types: ModTupFld
   :label: CorootSpace_RootSys

   The vector space containing the (co)roots of the root system :math:`R`,
   i.e. :math:`X` (respectively, :math:`Y`).

.. magma:function:: SimpleRoots(R)
   :input_types: RootSys
   :output_types: Mtrx
   :label: SimpleRoots_RootSys

.. magma:function:: SimpleCoroots(R)
   :input_types: RootSys
   :output_types: Mtrx
   :label: SimpleCoroots_RootSys

   The simple (co)roots of the root system :math:`R` as the rows of a matrix,
   i.e. :math:`A` (respectively, :math:`B`).

.. magma:example:: Example: Root Space
   :label: RootSpace

   .. code-block:: magma

      > R := RootSystem("G2");
      > RootSpace(R);
      Full Vector space of degree 2 over Rational Field                    
      > CorootSpace(R);
      Full Vector space of degree 2 over Rational Field                    
      > SimpleRoots(R);
      [1 0]
      [0 1]
      > SimpleCoroots(R);
      [ 2 -3]
      [-1  2]
      > CartanMatrix(R);
      [ 2 -1]
      [-3  2]

.. magma:function:: NumberOfPositiveRoots(R)
   :input_types: RootSys
   :output_types: RngIntElt
   :label: NumberOfPositiveRoots_RootSys

.. magma:function:: NumPosRoots(R)
   :input_types: RootSys
   :output_types: RngIntElt
   :label: NumPosRoots_RootSys

   The number of positive roots of the root system :math:`R`. This is also the
   number of positive coroots. The total number of (co)roots is twice the number of
   positive (co)roots.

.. magma:function:: Roots(R)
   :input_types: RootSys
   :output_types: $\{@@\}$
   :label: Roots_RootSys

.. magma:function:: Coroots(R)
   :input_types: RootSys
   :output_types: $\{@@\}$
   :label: Coroots_RootSys
   :parameters: Basis : MonStgElt : ``Standard"

   The indexed set of (co)roots of the root system :math:`R`,
   i.e. :math:`\{@\,\alpha_1,\dots\alpha_{2N}\,@\}` (respectively,
   :math:`\{@\,\alpha_1^\star,\dots\alpha_{2N}^\star\,@\}`).

.. magma:function:: PositiveRoots(R)
   :input_types: RootSys
   :output_types: $\{@@\}$
   :label: PositiveRoots_RootSys

.. magma:function:: PositiveCoroots(R)
   :input_types: RootSys
   :output_types: $\{@@\}$
   :label: PositiveCoroots_RootSys
   :parameters: Basis : MonStgElt : ``Standard"

   The indexed set of positive (co)roots of the root system :math:`R`,
   i.e. :math:`\{@\,\alpha_1,\dots\alpha_N\,@\}` (respectively,
   :math:`\{@\,\alpha_1^\star,\dots\alpha_N^\star\,@\}`).

.. magma:function:: Root(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: $\{@@\}$
   :label: Root_RootSys_RngIntElt

.. magma:function:: Coroot(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: $\{@@\}$
   :label: Coroot_RootSys_RngIntElt
   :parameters: Basis : MonStgElt : ``Standard"

   The :math:`r`\ th (co)root :math:`\alpha_r` (respectively,
   :math:`\alpha_r^\star`) of the root system :math:`R`.

.. magma:function:: RootPosition(R, v)
   :input_types: RootSys, .
   :output_types: $\{@@\}$
   :label: RootPosition_RootSys

.. magma:function:: CorootPosition(R, v)
   :input_types: RootSys, .
   :output_types: $\{@@\}$
   :label: CorootPosition_RootSys
   :parameters: Basis : MonStgElt : ``Standard"

   If :math:`v` is a (co)root in the root system :math:`R`, return its index;
   otherwise return 0. These functions will try to coerce :math:`v`, which can be a
   vector or a sequence representing a vector, into the appropriate vector space;
   :math:`v` should be written with respect to the basis specified by the parameter
   ``Basis``.

.. magma:example:: Example: Roots Coroots
   :label: RootsCoroots

   .. code-block:: magma

      > A := Matrix(2,3, [1,-1,0, -1,1,-1]);
      > B := Matrix(2,3, [1,-1,1, 0,1,-1]);
      > R := RootSystem(A, B);
      > Roots(R);
      {@
          (1 -1  0),
          (-1  1 -1),
          (0  0 -1),
          (1 -1 -1),
          (2 -2 -1),
          (1 -1 -2),
          (-1  1  0),
          (1 -1  1),
          (0 0 1),
          (-1  1  1),
          (-2  2  1),
          (-1  1  2)
      @}
      > PositiveCoroots(R);
      {@
          (1 -1  1),
          (0  1 -1),
          (1  2 -2),
          (2  1 -1),
          (1 0 0),
          (1  1 -1)
      @}
      > #Roots(R) eq 2*NumPosRoots(R);
      true
      %%a> assert $1;
      > Root(R, 4);
      (1 -1 -1)
      > Root(R, 4 : Basis := "Root");
      (2 1)
      > RootPosition(R, [1,-1,-1]);
      4
      %%a> assert $1 eq 4;
      > RootPosition(R, [2,1] : Basis := "Root");
      4
      %%a> assert $1 eq 4;

.. magma:function:: HighestRoot(R)
   :input_types: RootSys
   :output_types: .
   :label: HighestRoot_RootSys

.. magma:function:: HighestCoroot(R)
   :input_types: RootSys
   :output_types: .
   :label: HighestCoroot_RootSys
   :parameters: Basis : MonStgElt : ``Standard"

   The unique (co)root of greatest height in the irreducible root system :math:`R`.

.. magma:function:: HighestLongRoot(R)
   :input_types: RootSys
   :output_types: .
   :label: HighestLongRoot_RootSys

.. magma:function:: HighestLongCoroot(R)
   :input_types: RootSys
   :output_types: .
   :label: HighestLongCoroot_RootSys
   :parameters: Basis : MonStgElt : ``Standard"

   The unique long (co)root of greatest height in the irreducible root system
   :math:`R`.

.. magma:function:: HighestShortRoot(R)
   :input_types: RootSys
   :output_types: .
   :label: HighestShortRoot_RootSys

.. magma:function:: HighestShortCoroot(R)
   :input_types: RootSys
   :output_types: .
   :label: HighestShortCoroot_RootSys
   :parameters: Basis : MonStgElt : ``Standard"

   The unique short (co)root of greatest height in the irreducible root system
   :math:`R`.

.. magma:example:: Example: Heighest Roots
   :label: HeighestRoots

   .. code-block:: magma

      > R := RootSystem("G2");
      > HighestRoot(R);
      (3 2)
      > HighestLongRoot(R);
      (3 2)
      > HighestShortRoot(R);
      (2 1)

.. magma:function:: CoxeterForm(R)
   :input_types: RootSys
   :output_types: AlgMatElt
   :label: CoxeterForm_RootSys

.. magma:function:: DualCoxeterForm(R)
   :input_types: RootSys
   :output_types: AlgMatElt
   :label: DualCoxeterForm_RootSys
   :parameters: Basis : MonStgElt : ``Standard"

   The matrix of an inner product on the (co)root space of the root system
   :math:`R` which is invariant under the action of the (co)roots. This inner
   product is uniquely determined up to a constant on each irreducible component of
   :math:`R`. The inner product is normalised so that the short roots in each
   crystallographic component have length one.

.. _SubsectRSRootAction:

.. _rootrefl:

Reflections
-----------

The root :math:`\alpha` acts on the root space via the reflection
:math:`s_\alpha`; the coroot :math:`\alpha^\star` acts on the coroot space via
the coreflection :math:`s_\alpha^\star`.

.. magma:function:: SimpleReflectionMatrices(R)
   :input_types: RootSys
   :output_types: []
   :label: SimpleReflectionMatrices_RootSys

.. magma:function:: SimpleCoreflectionMatrices(R)
   :input_types: RootSys
   :output_types: []
   :label: SimpleCoreflectionMatrices_RootSys
   :parameters: Basis : MonStgElt : ``Standard"

   The sequence of matrices giving the action of the simple (co)roots of the root
   system :math:`R` on the (co)root space, i.e. the matrices of
   :math:`s_{\alpha_1},\dots,s_{\alpha_n}` (respectively,
   :math:`s_{\alpha_1}^\star,\dots,s_{\alpha_n}^\star`).

.. magma:function:: ReflectionMatrices(R)
   :input_types: RootSys
   :output_types: []
   :label: ReflectionMatrices_RootSys

.. magma:function:: CoreflectionMatrices(R)
   :input_types: RootSys
   :output_types: []
   :label: CoreflectionMatrices_RootSys
   :parameters: Basis : MonStgElt : ``Standard"

   The sequence of matrices giving the action of the (co)roots of the root system
   :math:`R` on the (co)root space, i.e. the matrices of
   :math:`s_{\alpha_1},\dots,s_{\alpha_{2N}}` (respectively,
   :math:`s_{\alpha_1}^\star,\dots,s_{\alpha_{2N}}^\star`).

.. magma:function:: ReflectionMatrix(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: []
   :label: ReflectionMatrix_RootSys_RngIntElt

.. magma:function:: CoreflectionMatrix(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: []
   :label: CoreflectionMatrix_RootSys_RngIntElt
   :parameters: Basis : MonStgElt : ``Standard"

   The matrix giving the action of the :math:`r`\ th (co)root of the root system
   :math:`R` on the (co)root space, i.e. the matrix of :math:`s_{\alpha_r}`
   (respectively, :math:`s_{\alpha_r}^\star`).

.. magma:function:: SimpleReflectionPermutations(R)
   :input_types: RootSys
   :output_types: []
   :label: SimpleReflectionPermutations_RootSys

   The sequence of permutations giving the action of the simple (co)roots of the
   root system :math:`R` on the (co)roots. This action is the same for roots and
   coroots.

.. magma:function:: ReflectionPermutations(R)
   :input_types: RootSys
   :output_types: []
   :label: ReflectionPermutations_RootSys

   The sequence of permutations giving the action of the (co)roots of the root
   system :math:`R` on the (co)roots. This action is the same for roots and
   coroots.

.. magma:function:: ReflectionPermutation(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: []
   :label: ReflectionPermutation_RootSys_RngIntElt

   The permutation giving the action of the :math:`r`\ th (co)root of the root
   system :math:`R` on the (co)roots. This action is the same for roots and
   coroots.

.. magma:function:: ReflectionWords(R)
   :input_types: RootSys
   :output_types: []
   :label: ReflectionWords_RootSys

   The sequence of words in the simple reflections for all the reflections of the
   root system :math:`R`. These words are given as sequences of integers. In other
   words, if :math:`[a_1,\dots,a_l] = \hbox{\tt ReflectionWords(R)[r]}`, then
   :math:`s_{\alpha_r} = s_{\alpha_{a_1}} \cdots s_{\alpha_{a_l}}`.

.. magma:function:: ReflectionWord(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: []
   :label: ReflectionWord_RootSys_RngIntElt

   The word in the simple reflections for the :math:`r`\ th reflection of the root
   system :math:`R`. The word is given as a sequence of integers. In other words,
   if :math:`[a_1,\dots,a_l] = \hbox{\tt ReflectionWord(R,r)}`, then
   :math:`s_{\alpha_r} = s_{\alpha_{a_1}} \cdots s_{\alpha_{a_l}}`.

.. magma:example:: Example: Action
   :label: Action

   .. code-block:: magma

      > R := RootSystem("B3");
      > mx := ReflectionMatrix(R, 4);
      > perm := ReflectionPermutation(R, 4);
      > wd := ReflectionWord(R, 4);
      > RootPosition(R, Root(R,2) * mx) eq 2^perm;
      true
      %%a> assert $1;
      > perm eq &*[ ReflectionPermutation(R, r) : r in wd ];
      true
      %%a> assert $1;
      > 
      > mx := CoreflectionMatrix(R, 4);
      > CorootPosition(R, Coroot(R,2) * mx) eq 2^perm;
      true
      %%a> assert $1;

.. _SubsectRSRootOp:

.. _ops-root-coroot:

Operations and Properties for  Roots and Coroot Indices
-------------------------------------------------------

.. magma:function:: Sum(R, r, s)
   :input_types: RootSys, RngIntElt, RngIntElt
   :output_types: RngIntElt
   :label: Sum_RootSys_RngIntElt_RngIntElt

   The index of the sum of the :math:`r`\ th and :math:`s`\ th roots in the
   crystallographic root system :math:`R`, or 0 if the sum is not a root. In other
   words, if :math:`t=\hbox{\tt Sum(R,$r$,$s$)}\ne0` then
   :math:`\alpha_t=\alpha_r+\alpha_s`. We require :math:`\alpha_r\ne\pm\alpha_s`.

.. magma:function:: IsPositive(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: BoolElt
   :label: IsPositive_RootSys_RngIntElt

   Returns ``true`` if, and only if, the :math:`r`\ th (co)root of the root system
   :math:`R` is a positive root.

.. magma:function:: IsNegative(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: BoolElt
   :label: IsNegative_RootSys_RngIntElt

   Returns ``true`` if, and only if, the :math:`r`\ th (co)root of the root system
   :math:`R` is a negative root.

.. magma:function:: Negative(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: RngIntElt
   :label: Negative_RootSys_RngIntElt

   The index of the negative of the :math:`r`\ th (co)root of the root system
   :math:`R`. In other words, if :math:`s = \hbox{\tt Negative(R,$r$)}` then
   :math:`\alpha_s=-\alpha_r`.

.. magma:example:: Example: Root Arithmetic
   :label: RootArithmetic

   .. code-block:: magma

      > R := RootSystem("G2");
      > Sum(R, 1, Negative(R,5));
      10
      %%a> assert $1 eq 10;
      > IsPositive(R, 10);
      false
      %%a> assert not $1;
      > Negative(R, 10);
      4
      %%a> assert $1 eq 4;
      > P := PositiveRoots(R);
      > P[1] - P[5] eq -P[4];
      true
      %%a> assert $1;

.. magma:function:: RootHeight(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: RngIntElt
   :label: RootHeight_RootSys_RngIntElt

.. magma:function:: CorootHeight(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: RngIntElt
   :label: CorootHeight_RootSys_RngIntElt

   The height of the :math:`r`\ th (co)root of the root system :math:`R`, i.e. the
   sum of the coefficients of :math:`\alpha_r` (respectively,
   :math:`\alpha_r^\star`) with respect to the simple (co)roots.

.. magma:function:: RootNorms(R)
   :input_types: RootSys
   :output_types: [RngIntElt]
   :label: RootNorms_RootSys

.. magma:function:: CorootNorms(R)
   :input_types: RootSys
   :output_types: [RngIntElt]
   :label: CorootNorms_RootSys

   The sequence of squares of the lengths of the (co)roots of the root system
   :math:`R`.

.. magma:function:: RootNorm(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: RngIntElt
   :label: RootNorm_RootSys_RngIntElt

.. magma:function:: CorootNorm(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: RngIntElt
   :label: CorootNorm_RootSys_RngIntElt

   The square of the length of the :math:`r`\ th (co)root of the root system
   :math:`R`.

.. magma:function:: IsLongRoot(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: BoolElt
   :label: IsLongRoot_RootSys_RngIntElt

   Returns ``true`` if, and only if, the :math:`r`\ th root of the root system
   :math:`R` is long. This only makes sense for irreducible crystallographic root
   systems. Note that for non-reduced root systems, the roots which are not
   indivisible are actually longer than the long ones.

.. magma:function:: IsShortRoot(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: BoolElt
   :label: IsShortRoot_RootSys_RngIntElt

   Returns ``true`` if, and only if, the :math:`r`\ th root of the root system
   :math:`R` is short. This only makes sense for irreducible crystallographic root
   systems.

.. magma:function:: IsIndivisibleRoot(R, r)
   :input_types: RootSys, RngIntElt
   :output_types: BoolElt
   :label: IsIndivisibleRoot_RootSys_RngIntElt

   Returns ``true`` if, and only if, the :math:`r`\ th root of the root system
   :math:`R` is indivisible, ie, :math:`\alpha_r/2` is not a root.

.. magma:function:: LeftString(R, r, s)
   :input_types: RootSys, RngIntElt, RngIntElt
   :output_types: RngIntElt
   :label: LeftString_RootSys_RngIntElt_RngIntElt

   Indices in the crystallographic root system :math:`R` of the left string through
   :math:`\alpha_s` in the direction of :math:`\alpha_r`, i.e. the indices of
   :math:`\alpha_s-\alpha_r,\alpha_s-2\alpha_r,\dots,\alpha_s-p\alpha_r`. In other
   words, this returns the sequence :math:`[r_1,\dots,r_p]` where
   :math:`\alpha_{r_i}=\alpha_s-i\alpha_r` and :math:`\alpha_s-(p+1)\alpha_r` is
   not a root. We require that :math:`\alpha_r\ne\pm\alpha_s`.

.. magma:function:: RightString(R, r, s)
   :input_types: RootSys, RngIntElt, RngIntElt
   :output_types: RngIntElt
   :label: RightString_RootSys_RngIntElt_RngIntElt

   Indices in the crystallographic root system :math:`R` of the left string through
   :math:`\alpha_s` in the direction of :math:`\alpha_r`, i.e. the indices of
   :math:`\alpha_s+\alpha_r,\alpha_s+2\alpha_r,\dots,\alpha_s+q\alpha_r`. In other
   words, this returns the sequence :math:`[r_1,\dots,r_q]` where
   :math:`\alpha_{r_i}=\alpha_s+i\alpha_r` and :math:`\alpha_s+(q+1)\alpha_r` is
   not a root. We require that :math:`\alpha_r\ne\pm\alpha_s`.

.. magma:function:: LeftStringLength(R, r, s)
   :input_types: RootSys, RngIntElt, RngIntElt
   :output_types: RngIntElt
   :label: LeftStringLength_RootSys_RngIntElt_RngIntElt

   The largest :math:`p` such that :math:`\alpha_s-p\alpha_r` is a root. We require
   that the root system :math:`R` be crystallographic and
   :math:`\alpha_s\ne\pm\alpha_r`.

.. magma:function:: RightStringLength(R, r, s)
   :input_types: RootSys, RngIntElt, RngIntElt
   :output_types: RngIntElt
   :label: RightStringLength_RootSys_RngIntElt_RngIntElt

   The largest :math:`q` such that :math:`\alpha_s+q\alpha_r` is a root. We require
   that the root system :math:`R` be crystallographic and
   :math:`\alpha_s\ne\pm\alpha_r`.

.. magma:example:: Example: Root Operations
   :label: RootOperations

   .. code-block:: magma

      > R := RootSystem("G2");
      > RootHeight(R, 5);
      4
      %%a> assert $1 eq 4;
      > F := CoxeterForm(R);
      > v := Root(R, 5);
      > (v*F, v) eq RootNorm(R, 5);
      true
      %%a> assert $1;
      > IsLongRoot(R, 5);
      true
      %%a> assert $1;
      > LeftString(R, 1, 5);
      [ 4, 3, 2 ]
      > roots := Roots(R);
      > for i in [1..3] do
      >   RootPosition(R, roots[5]-i*roots[1]);
      > end for;
      4
      3
      2
      > R := RootSystem("BC2");
      > Root(R,2), IsIndivisibleRoot(R,2);
      (0 1) true
      > Root(R,4), IsIndivisibleRoot(R,4);
      (0 2) false

.. magma:function:: AdditiveOrder(R)
   :input_types: RootSys
   :output_types: SeqEnum
   :label: AdditiveOrder_RootSys

   An additive order on the positive roots of the root system :math:`R`, i.e. a
   sequence containing the numbers :math:`1,\dots,N` in some order so that
   :math:`\alpha_r+\alpha_s=\alpha_t` implies :math:`t` is between :math:`r` and
   :math:`s`. This is computed using the techniques of :cite:`Papi`.

.. magma:function:: IsAdditiveOrder(R, Q)
   :input_types: RootSys, [RngIntElt]
   :output_types: BoolElt
   :label: IsAdditiveOrder_RootSys_RngIntElt

   Returns ``true`` if, and only if, the sequence :math:`Q` gives an additive order
   on a set of positive roots of the root system :math:`R`. :math:`Q` must be a
   sequence of integers in the range :math:`[1..N]`, where :math:`N` is the number
   of positive roots of :math:`R`, with no gaps or repeats.

.. magma:example:: Example: Additive Order
   :label: AdditiveOrder

   .. code-block:: magma

      > R := RootSystem("A5");
      > a := AdditiveOrder(R);
      > Position(a, 2);
      6
      %%a> assert $1 eq 6;
      > Position(a, 3);
      10
      %%a> assert $1 eq 10;
      > Position(a, Sum(R, 2, 3));
      7
      %%a> assert $1 eq 7;
