// ********************** HELPFUNCTIONS *****************************
// These are some helpfunctions which didn't fit nicely in the
// "modular"-file.

// zeroseq(n) return a sequence of n zeros.

zeroseq := function(n);
  return [0:i in [1..n]];
end function;

// removezeros(fd) removes the (rudimentary) zeros at the end of a partition.

removezeros := function(fd);
  if fd[#fd] eq 0 then
    fdnotok := true; 
    while fdnotok and #fd ge 1 do
      if fd[#fd] eq 0 then Prune(~fd);
      else fdnotok := false;
      end if;
    end while;
  end if;
  return fd;
end function;

// fdsum(fd) returns the number of irreducible factors in fd.

fdsum := function(fd);
  fds := 0;
  for i in fd do fds +:= i; end for;
  return fds;
end function;    

// Let fd = [i_1, i_2, ..., i_n]. Then minusbofk(fd,b,k) returns fd
// with i_k := i_k - 1 and i_(k-b) := i_(k-b) + 1, if b ne k.

minusbofk := function(fd,b,k);
  fd[k] -:= 1;
  if b ne k then fd[k-b] +:= 1; end if;
  fd := removezeros(fd);
  return fd;
end function;

// Let fd = [i_1, i_2, ..., i_n]. Then plusab(fd,a,b) return fd
// with i_a := i_a - 1, i_b := i_b - 1 and i_(a+b) := i_(a+b) + 1.
  
plusab := function(fd,a,b);
  fd[a] -:= 1;
  fd[b] -:= 1;
  if IsDefined(fd,a+b) then 
    fd[a+b] +:= 1;
  else 
    fd[a+b] := 1;
    for i:=1 to #fd do 
      if not IsDefined(fd,i) then fd[i]:=0; end if; 
    end for;
  end if;
  return fd;
end function;
