

intrinsic Dim(j::RngIntElt, n::RngIntElt, 
            alpha::RngIntElt, slopes::SeqEnum) -> RngIntElt
{}
   two_n   := 2^n;
   weights := [k : k in [2..#slopes] | 
                 k gt 14 and    IsEven(k) and (k + j) mod two_n eq 0];
   if #weights eq 0 then
      error "Slope table is too small.";
   end if;
   k := weights[1];
   d := #[i : i in [1..#slopes[k]] | slopes[k][i] eq alpha];

   for k in weights do
      i := Index(slopes[k], alpha);
      if i eq 0 then
         return -k;
      end if;
      for j in [i..i+d-1] do
         if slopes[k][j] ne alpha then
            return -k;
         end if;
      end for;
      if i+d-1 lt #slopes[k] and slopes[k][i+d] eq alpha then
         return -k;
      end if;
   end for;
   return d;         

/*   if exists(k) { k : k in weights | 
           d ne #[i : i in [1..#slopes[k]] | slopes[k][i] eq alpha]} then

      return -k;
   end if;
*/

end intrinsic;

intrinsic Conj(j::RngIntElt, n::RngIntElt, 
               alpha::RngIntElt, d::RngIntElt,
               slopes::SeqEnum) -> BoolElt, RngIntElt
{}
   twopow  := 2^(n+Ceiling(Log(j+2)/Log(2)));
   weights := [k : k in [2..#slopes] | 
                     k ge 20 and IsEven(k) and (k - (j+2)) mod twopow eq 0];
   if exists(k) { k : k in weights  | 
              d ne #[i : i in [1..#slopes[k]] | slopes[k][i] eq alpha+j+1] } then
      return false, k;
   end if;
   return true, 0;
 
end intrinsic;

intrinsic TryConj(j::RngIntElt, n::RngIntElt, 
              alpha::RngIntElt, slopes::SeqEnum) -> BoolElt, RngIntElt
{}
   d := Dim(j,n,alpha, slopes);
   if d eq 0 then
      return true, 0;   // vacuous   
   end if;
   return Conj(j,n,alpha,d,slopes), d;

end intrinsic;


