User:KHiddemann/GeSHi

From ApCoCoAWiki
< User:KHiddemann
Revision as of 20:18, 9 August 2007 by KHiddemann (talk | contribs) (An example taken from the CoCoA School 2007 to demonstrate syntax highlighting of CoCoAL code in the Wiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

An example taken from the CoCoA School 2007 to demonstrate syntax highlighting of CoCoAL code in the Wiki:

Define Reduce(Generators)
-- Generators: List of polynomials
-- returns a set of generators with pairwise different LTs
-- (hence K-linear independent)
  
Generators := NonZero(Generators); -- remove zero polynomials
LinIndGens := [];
 
While Len(Generators) > 0 Do
 
   -- find polynomial with largest LT 
   MaxPoly := Generators[1];
   MaxTerm := LT(MaxPoly);
   MaxPos  := 1;
   For Pos := 2 To Len(Generators) Do
      If LT(Generators[Pos]) > MaxTerm Then
         MaxPoly := Generators[Pos];
         MaxTerm := LT(MaxPoly);
         MaxPos  := Pos
      EndIf
   EndFor;

   MaxPoly := MaxPoly / LC(MaxPoly);
   Append( LinIndGens, MaxPoly);
   Remove( Generators, MaxPos);
 
   -- reduce other polynomials
   For Pos := 1 To Len(Generators) Do
      If LT(Generators[Pos]) = MaxTerm Then       
         Generators[Pos] := Generators[Pos] - LC(Generators[Pos]) * MaxPoly
      EndIf
   EndFor; 
  
   -- remove zero polynomials
   Generators := NonZero(Generators)
EndWhile;
 
Return LinIndGens
EndDefine;