# This is a routine for pretty printing of abelian groups. It # takes a list of integers [n_1,n_2,...,n_k] and prints out # the product of cyclic groups Z/n_1Z + Z/n_2Z + ... + Z/n_kZ # in the form # Z^(a_0) + (Z/m_1Z)^(a_1) + ... + (Z/m_r)^(a_r) # with 1 < m_1 < m_2 < ... < m_r. displayAbelianGroup := function( vector ) local entry, length, isoType, numFactors; length := Size( vector ); if length = 0 then Print("0\n"); return; fi; for entry in [1..length] do vector[ entry ] := AbsInt( vector[ entry ] ); od; Sort( vector ); numFactors := 0; for entry in [1..length] do if numFactors = 0 then isoType := vector[entry]; numFactors := 1; fi; if (entry = length) or not (vector[entry + 1] = isoType) then if isoType < 0 then isoType := -isoType; fi; if isoType = 0 then if numFactors = 1 then Print("Z"); else Print("Z^",numFactors); fi; fi; if isoType > 1 then if numFactors = 1 then Print("Z/",isoType); else Print("(Z/",isoType,")^",numFactors); fi; fi; if entry < length and not isoType = 1 then Print(" + "); fi; numFactors := 0; else numFactors := numFactors + 1; fi; od; Print("\n"); end;