#% -*- GAP -*-
#% This file is marked for TeX processing
#[caption]"A few common objects"
#================================================================
#: The group $"S"=\BG3$, $"Gamma"=\MG$, and free group $"G"=\FG3$.
#: The generators "x" and "y" are commonly used below to specify%
#:    paths in skeletons
#----------------------------------------------------------------
G := FreeGroup(3);    #"G"
S := FreeGroup(2);    #"S" #: We do not need the relations
Gamma := FreeGroup(["x", "y"]);  #"Gamma"#%
x := Gamma.1;  y := Gamma.2;
rho := G.1*G.2*G.3;   #: Usually there is a relation "rho^n"
#================================================================
#: The homomorphism $\BG3\to\MG$ and the inverse expressions
#----------------------------------------------------------------
#% !!!!! To double check these expressions !!!!!
XX := function(s1, s2) return s1*s2; end;              #"XX"
YY := function(s1, s2) return s1^-1*s2^-1*s1^-1; end;  #"YY"
sigma1 := function(x, y) return x^-1*y^-1; end;        #"sigma1"
sigma2 := function(x, y) return y^-1*x^-1; end;        #"sigma2"
#================================================================
#: "WordPath(path)" converts "path" in the form "[0, -1, 1, 0, ...]",%
#:    with $0$ (or $\pm2$) for $\Y$ and $\pm1$ for $\X^{\pm1}$%
#:    (for easy input) to a word in "x", "y" (an element of \kwd{Gamma})
#: "Path(p)" returns path "p" as a braid (an element of \kwd{S})
#----------------------------------------------------------------
WordPath := function(path)  #"WordPath"
 if not(path in Gamma) then
  path := AssocWordByLetterRep(FamilyObj(x), List(path,
              function(i) if i = 0 then return 2; else return i; fi; end));
 fi;
 return path;
end;
Path := p -> MappedWord(WordPath(p), [x, y], [XX(S.1, S.2), YY(S.1, S.2)]);#"Path"
#================================================================
#: The Burau representation
#: "BurauPath(path, t[: normalized, transposed])" returns the image of%
#:    "Path(path)" in the Burau representation.%
#:    If "normalized" is set, the result is normalized to clear the denominators;%
#:    if "transposed" is set, the result is transposed.
#----------------------------------------------------------------
t := Indeterminate(Integers, "t");       #: Use this to enter polynomials
if not IsBound(out) then out := 0; fi;   #: Just bind the variable
OpenOut := function(name)                #"OpenOut" #: Create a stream for output
 out := OutputTextFile(name, false); #%
 SetPrintFormattingStatus(out, false);
end;
#% To double check
Burau := [t -> [[-t, 0*t], [t^0, t^0]],  #: Burau matrices
          t -> [[t^0, t], [0*t, -t]]];
BurauPath := function(path, t)
 local res, d;
 res := MappedWord(Path(path), [S.1, S.2], [Burau[1](t), Burau[2](t)]);
 if ValueOption("transposed") = true then res := TransposedMat(res); fi;
 if ValueOption("normalized") = true then
  d := Minimum(List(Flat(res), p -> CoefficientsOfLaurentPolynomial(p)[2]));
  res := t^(-3*QuoInt(d - 2, 3))*res;
 fi;
 return res;
end;
#================================================================
#[endinput]
