#% -*- GAP -*-
#% This file is marked for TeX processing
#[caption]"Braid manipulation in \GAP"
#================================================================
#: "Braid(b, G, x)" evaluates a braid "b" on element(s) "x" of group "G"%
#:    (which is assumed to be a "FreeGroup")
#----------------------------------------------------------------
Braid := function(b, G, x)  #"Braid" #: There must be a way to recover "G" from "x"?
 local i, res, g;
 if IsList(x) then return List(x, i -> Braid(b, G, i)); fi;
 g := GeneratorsOfGroup(G); res := x;
 for i in LetterRepAssocWord(b) do
  if i > 0 then  #: this is $\Gs_i$
   res := MappedWord(res, [g[i],g[1+i]],[g[i]*g[1+i]*g[i]^-1,g[i]]);
  else           #: this is $\Gs_{-i}\1$
   res := MappedWord(res, [g[-i],g[1-i]],[g[1-i],g[1-i]^-1*g[-i]*g[1-i]]);
  fi;
 od;
 return res;
end;
#================================================================
#: "BraidRelations(b, G[, list])" returns the list of $b(x)x^{-1}$%
#:    for all "x" in "list" (which must all be elements of group "G").%
#:    By default, "list = GeneratorsOfGroup(G)"
#----------------------------------------------------------------
BraidRelations := function(arg)    #"BraidRelations"
 if Length(arg) = 2 then arg[3] := GeneratorsOfGroup(arg[2]); fi;
 return List(arg[3], x -> Braid(arg[1], arg[2], x)*x^-1);
end;
#================================================================
#: "IsBraidID(b, G)" decides if a braid "b" acts trivially on a group "G"
#----------------------------------------------------------------
IsBraidID := function(b, G)        #"IsBraidID"
 local x;
 for x in GeneratorsOfGroup(G) do
  if x <> Braid(b, G, x) then return false; fi;
 od;
 return true;
end;
#================================================================
#[endinput]
#================================================================
#: The relator $\{a,b\}_n$
#----------------------------------------------------------------
Brace := function(a, b, n)
if (n mod 2) = 0 then
 return (a*b)^(n/2)/(b*a)^(n/2);
else
 return (a*b)^((n-1)/2)*a/((b*a)^((n-1)/2)*b);
fi;
end;
#================================================================
#[endinput]
