
// Make newform 15.5.d.c in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_15_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_15_d_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_15_5_d_c();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_15_5_d_c();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [81, 0, 8, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 26, 0, 1], [0, 1, 0, -1], [12, 0, 3, 0]];
    Rf_basisdens := [1, 9, 9, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_15_d();"
function MakeCharacter_15_d()
    N := 15;
    order := 2;
    char_gens := [11, 7];
    v := [1, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_15_d_Hecke();"
function MakeCharacter_15_d_Hecke(Kf)
    N := 15;
    order := 2;
    char_gens := [11, 7];
    char_values := [[-1, 0, 0, 0], [-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..(prec+1)]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 5;
    raw_aps := [[0, 0, 1, 0], [0, 1, 1, 0], [0, 0, 2, -1], [0, -2, 1, 0], [0, 0, 0, -4], [0, 32, -16, 0], [0, 0, 88, 0], [308, 0, 0, 0], [0, 0, -131, 0], [0, 0, 0, 8], [32, 0, 0, 0], [0, 168, -84, 0], [0, 0, 0, -86], [0, -338, 169, 0], [0, 0, -773, 0], [0, 0, 448, 0], [0, 0, 0, -164], [-928, 0, 0, 0], [0, 338, -169, 0], [0, 0, 0, 192], [0, 552, -276, 0], [8, 0, 0, 0], [0, 0, -1403, 0], [0, 0, 0, 384], [0, 328, -164, 0], [0, 0, 0, 200], [0, -718, 359, 0], [0, 0, 925, 0], [-6352, 0, 0, 0], [0, 0, -2804, 0], [0, 498, -249, 0], [0, 0, 0, -332], [0, 0, 6724, 0], [-19372, 0, 0, 0], [0, 0, 0, 670], [33272, 0, 0, 0], [0, -3832, 1916, 0], [0, 1602, -801, 0], [0, 0, -797, 0], [0, 0, -15596, 0], [0, 0, 0, -1572], [20342, 0, 0, 0], [0, 0, 0, -2296], [0, 6632, -3316, 0], [0, 0, -9128, 0], [34328, 0, 0, 0], [-33268, 0, 0, 0], [0, -9938, 4969, 0], [0, 0, -5309, 0], [40298, 0, 0, 0], [0, 0, 27592, 0], [0, 0, 0, 3664], [72152, 0, 0, 0], [0, 0, 0, -660], [0, 0, 26860, 0], [0, 0, 901, 0], [0, 0, 0, 162], [-67048, 0, 0, 0], [0, -1352, 676, 0], [0, 0, 0, -922], [0, -15358, 7679, 0], [0, 0, -18140, 0], [0, -1362, 681, 0], [0, 0, 0, 4216], [0, 23872, -11936, 0], [0, 0, -10592, 0], [204092, 0, 0, 0], [0, -5872, 2936, 0], [0, 0, -42773, 0], [-228682, 0, 0, 0], [0, 0, -33812, 0], [0, 0, 0, 7296], [0, 23278, -11639, 0], [0, -10168, 5084, 0], [-12292, 0, 0, 0], [0, 0, 77827, 0], [0, 0, 0, -4126], [0, 18768, -9384, 0], [0, 0, 0, -10160], [34808, 0, 0, 0], [0, 0, 0, -9068], [168992, 0, 0, 0], [0, 0, 0, 6408], [0, -20088, 10044, 0], [65168, 0, 0, 0], [0, 0, -36845, 0], [0, 0, 0, 3270], [0, -50912, 25456, 0], [0, 0, 0, -9784], [0, 33182, -16591, 0], [0, 0, 115693, 0], [0, 0, 0, 10568], [0, -58302, 29151, 0], [0, 0, 0, 9484], [157748, 0, 0, 0], [0, 0, -157997, 0], [0, 0, 0, -6344], [0, 0, 0, 10032], [0, 17502, -8751, 0], [-195478, 0, 0, 0], [0, 18718, -9359, 0], [0, 0, 127060, 0], [0, 0, 39901, 0], [0, 0, 0, -14698], [-454108, 0, 0, 0], [0, 13488, -6744, 0], [0, 0, -150101, 0], [0, 0, -54740, 0], [0, 0, 0, 24280], [475352, 0, 0, 0], [0, -40702, 20351, 0], [0, -29328, 14664, 0], [0, 0, -63392, 0], [22508, 0, 0, 0], [-157408, 0, 0, 0], [0, 0, 0, 12314], [0, 17102, -8551, 0], [0, 0, -37163, 0], [0, 0, 202648, 0], [0, 0, 0, 5036], [5072, 0, 0, 0], [0, -23768, 11884, 0], [0, 0, -96344, 0], [0, 0, -198533, 0], [-17308, 0, 0, 0], [0, 0, 0, -990], [-381322, 0, 0, 0], [0, 0, 0, -38328], [0, 48898, -24449, 0], [0, -41608, 20804, 0], [409268, 0, 0, 0], [0, 0, -3605, 0], [347432, 0, 0, 0], [0, 115848, -57924, 0], [0, 0, 0, 10816], [-832882, 0, 0, 0], [0, 0, 12184, 0], [0, 81998, -40999, 0], [0, 0, -344768, 0], [0, 0, 0, 4176], [-400948, 0, 0, 0], [0, 0, 0, 32162], [0, 28562, -14281, 0], [0, 0, -145739, 0], [-60352, 0, 0, 0], [0, 0, 0, 6704], [0, -166928, 83464, 0], [0, 0, 98380, 0], [1146308, 0, 0, 0], [0, 0, 202651, 0], [0, 58568, -29284, 0], [0, 0, 0, 3018], [0, 104322, -52161, 0], [0, 0, -331691, 0], [0, -139262, 69631, 0], [0, 0, 0, 51896], [552368, 0, 0, 0], [0, 0, 0, 30938], [0, -22632, 11316, 0], [0, 0, 0, -72296], [0, 0, 310987, 0], [0, 0, 282868, 0], [0, -106162, 53081, 0], [0, 0, 0, -13788], [0, 0, 418936, 0], [0, 0, -257813, 0], [1576352, 0, 0, 0], [0, 16768, -8384, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_15_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_15_5_d_c();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_15_5_d_c(:prec:=4)
    chi := MakeCharacter_15_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 5));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_15_5_d_c();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_15_5_d_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_15_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([<2,R![-10, 0, 1]>],Snew);
    return Vf;
end function;