User:KHiddemann/GeSHi
From ApCoCoAWiki
GeSHi example
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
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;
Line numbering
Line numbering in action:
Define S_ij(G_i, G_j) Return LCM(LT(G_i), LT(G_j))/LT(G_i) * G_i/LC(G_i) - LCM(LT(G_i), LT(G_j))/LT(G_j) * G_j/LC(G_j); EndDefine; Define CheckGB(F) B := [I | I In (1..Len(F))><(1..Len(F)) And I[1] < I[2]]; S := [NR(S_ij(F[I[1]], F[I[2]]), F) | I In B]; Return EqSet(S, [0]); EndDefine; R_1 ::= Q[x,y], Lex; R_2 ::= Q[x,y], DegRevLex; R_3 ::= Q[x,y,z], Lex; R_4 ::= Q[x,y,z], DegLex; R_5 ::= Q[x[1..4]], DegRevLex; Using R_1 Do CheckGB([x^2, xy+y^2, y^3]); EndUsing; Using R_2 Do CheckGB([x^2-1, xy^2-x]); EndUsing; Using R_3 Do CheckGB([xy^2-xz+y, xy-z^2, x-yz^4]); EndUsing; Using R_4 Do CheckGB([x^4y^2-z^5, x^3y^3-1, x^2y^4-2z]); EndUsing; Using R_5 Do CheckGB([x[1]x[3]-x[2]^2, x[1]x[4]-x[2]x[3], x[2]x[4]-x[3]^2]); EndUsing;
Custom starting number:
Define CheckGB(F) B := [I | I In (1..Len(F))><(1..Len(F)) And I[1] < I[2]]; S := [NR(S_ij(F[I[1]], F[I[2]]), F) | I In B]; Return EqSet(S, [0]); EndDefine;