User:KHiddemann/GeSHi
From ApCoCoAWiki
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;
Another example:
// Exercise: Make one-liners out of these functions... Define IsVarPower(I,T) L := Log(T); Return (Len(NonZero(L))=0) Or (Len(NonZero(L))=1 And L[I]<>0); EndDefine; Define IsZeroDim(I) VP := [[ IsVarPower(N,G) | G In Gens(LT(I)) ] | N In 1..NumIndets() ]; Return Not FALSE IsIn [ TRUE IsIn L | L In VP]; EndDefine; // Exercise: Why DO you have to check if your poly is constant? Define SqFree(F) If (F=0 Or Deg(F)=0) Then Return 1; Elsif (UnivariateIndetIndex(F)=0) Then Error("Non-univariate poly "+Sprint(F)); Else Return F/GCD(F, Der(F, Indet(UnivariateIndetIndex(F)))); EndIf; EndDefine; Define ZeroDimRadical(I) E := [ Head(Gens(Elim(Diff(Indets(), [X]), I))) | X In Indets() ]; If 0 IsIn E Then Error("Infinite set "+Sprint(I)); Else Return I+Ideal([SqFree(G) | G In E]); EndIf; EndDefine;