1#############################################################################
2##
3#W  apery-extra-4ti2i-sing.gi         Ignacio Ojeda <mdelgado@fc.up.pt>
4#W                                    Carlos Jesús Moreno Ávila
5#W                                    Manuel Delgado <mdelgado@fc.up.pt>
6#W                                    Pedro Garcia-Sanchez <pedro@ugr.es>
7##
8#Y  Copyright 2015-- Universidad de Extremadura and Universidad de Granada, Spain
9#############################################################################
10
11InstallMethod(AperyList,
12    "method using 4ti2 for the calculaction of the Apery set",
13    [IsNumericalSemigroup],80,
14    function( S )
15    local v, tv, n, I, R, x, m, M, i, j, inM, ap, Ap;
16
17    Info(InfoNumSgps,2,"Using 4ti2Interface and Singular for the calculation of the Apery set");
18
19    v := MinimalGeneratingSystemOfNumericalSemigroup(S);
20    n := Length( v );
21    I := 4ti2Interface_groebner_matrix( TransposedMat([v]), v );
22    R := PolynomialRing(GF(2),n-1);
23    x := IndeterminatesOfPolynomialRing(R);
24    m := [1];
25    M := [0];
26  	for i in [1 .. Length(I)] do
27			for j in [1 .. n-1] do
28	   		m[j+1] := m[j]*x[j]^((I[i][j+1]+AbsoluteValue(I[i][j+1]))/2);
29			od;
30			M[i] := m[n];
31    od;
32    M := Ideal(R,M);;
33    inM := SingularInterface("kbase",[M],"ideal");
34    inM := GeneratorsOfIdeal(inM);
35    ap := [0];
36    Ap := [0];
37    for i in [1 .. Length(inM)] do
38			for j in [1 .. n-1] do
39	    	ap[j+1] := ap[j] + DegreeIndeterminate(inM[i],j)*v[j+1];
40			od;
41			Ap[i] := ap[n];
42    od;
43    return List([0..v[1]-1], i->First(Ap, y->(y-i) mod v[1]=0));
44end);
45