
// Make newform 3600.3.l.g in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3600_l();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_3600_l_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_3600_3_l_g();".
// 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_3600_3_l_g();".
// 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 := [2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 3]];
    Rf_basisdens := [1, 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_3600_l();"
function MakeCharacter_3600_l()
    N := 3600;
    order := 2;
    char_gens := [3151, 901, 2801, 577];
    v := [2, 2, 1, 2];
    // 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_3600_l_Hecke();"
function MakeCharacter_3600_l_Hecke(Kf)
    N := 3600;
    order := 2;
    char_gens := [3151, 901, 2801, 577];
    char_values := [[1, 0], [1, 0], [-1, 0], [1, 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 := 3;
    raw_aps := [[0, 0], [0, 0], [0, 0], [1, 0], [0, -1], [-7, 0], [0, -1], [7, 0], [0, 7], [0, -7], [-17, 0], [-16, 0], [0, 12], [55, 0], [0, 11], [0, -20], [0, 13], [65, 0], [49, 0], [0, -12], [-88, 0], [40, 0], [0, 37], [0, -24], [41, 0], [0, 28], [82, 0], [0, 28], [-49, 0], [0, -16], [160, 0], [0, 4], [0, 21], [-8, 0], [0, -21], [25, 0], [137, 0], [79, 0], [0, 28], [0, 31], [0, -35], [-97, 0], [0, 49], [185, 0], [0, 61], [-311, 0], [97, 0], [-239, 0], [0, 36], [17, 0], [0, 84], [0, -100], [95, 0], [0, 56], [0, 80], [0, -76], [0, 7], [448, 0], [455, 0], [0, -23], [-71, 0], [0, 93], [559, 0], [0, 133], [383, 0], [0, 88], [40, 0], [449, 0], [0, 69], [-184, 0], [0, 63], [0, -52], [-263, 0], [305, 0], [-497, 0], [0, -56], [0, 20], [-439, 0], [0, 60], [-343, 0], [0, 28], [608, 0], [0, 105], [-337, 0], [-65, 0], [0, 136], [0, -56], [590, 0], [0, -12], [64, 0], [0, 81], [0, -77], [823, 0], [0, -112], [553, 0], [0, 28], [0, -171], [0, 153], [775, 0], [-175, 0], [-266, 0], [0, -69], [0, 239], [0, -161], [-1001, 0], [-1081, 0], [0, 156], [0, -140], [0, 0], [665, 0], [-296, 0], [-952, 0], [0, 12], [1033, 0], [799, 0], [0, 48], [1000, 0], [0, -8], [0, -109], [0, 292], [-136, 0], [-328, 0], [0, -7], [0, 232], [-842, 0], [0, 79], [-985, 0], [0, 63], [-623, 0], [296, 0], [-704, 0], [0, -168], [-656, 0], [-937, 0], [0, -112], [281, 0], [0, -28], [-95, 0], [0, -224], [0, -84], [1177, 0], [0, 133], [-641, 0], [0, -124], [1046, 0], [0, -327], [335, 0], [0, -56], [1414, 0], [0, -368], [425, 0], [0, -408], [385, 0], [0, -269], [-752, 0], [0, 315], [-719, 0], [0, 305], [-1471, 0], [0, -211], [0, -241], [0, 224], [-1016, 0], [0, -371], [0, -189], [0, -440], [1081, 0], [248, 0], [71, 0], [0, 179], [0, 169], [-463, 0], [0, 245], [287, 0], [-911, 0], [0, 296], [-1121, 0], [0, -385], [-1553, 0], [233, 0], [-1895, 0], [0, -56], [1679, 0], [0, 101], [0, -371], [0, -133], [-1585, 0], [-311, 0], [863, 0], [0, 119], [-889, 0], [0, -44], [-1031, 0], [0, -417], [0, 63], [0, 91], [-1144, 0], [-760, 0], [0, -469], [0, -367], [0, 428], [1282, 0], [602, 0], [392, 0], [0, 336], [0, -337], [-929, 0], [0, 119], [0, 168], [-1655, 0], [-511, 0], [0, 91], [-1415, 0], [0, -24], [0, 203], [1832, 0], [367, 0], [0, -385], [0, -284], [0, -231], [-793, 0], [103, 0], [0, -539], [-560, 0], [0, 324], [-1135, 0], [0, -297], [0, -363], [-1031, 0], [0, -647], [-799, 0], [952, 0], [-1415, 0], [0, -259], [2344, 0], [0, -56], [1304, 0], [0, -60], [0, 555], [0, 628], [0, 503], [-1097, 0], [2191, 0], [-1279, 0], [0, -413], [0, 357], [295, 0], [0, -679], [-17, 0], [0, -19], [8, 0], [0, 385], [0, 224], [-1393, 0], [0, -217], [0, 640], [2159, 0], [1480, 0], [0, -364], [1568, 0], [-833, 0], [0, 33], [-136, 0], [-2857, 0], [0, -469], [1066, 0], [0, -595], [0, 432], [2368, 0], [0, -147], [-889, 0], [-182, 0], [-1264, 0], [2065, 0], [-2017, 0], [-2735, 0], [0, -101], [2327, 0], [3143, 0], [0, 416], [0, -92], [424, 0], [0, 665], [-511, 0], [751, 0], [0, -413], [-1345, 0], [0, 700], [-2768, 0], [0, 868], [0, 21], [0, 232], [0, 256], [0, 688], [497, 0], [0, 476], [985, 0], [0, 324], [0, -273], [2416, 0], [2240, 0], [0, 304], [-1607, 0], [0, -147], [1360, 0], [2345, 0], [0, 456], [3353, 0], [0, -588], [3386, 0], [0, -385], [0, -224], [0, -584], [1495, 0], [0, -231], [-1327, 0], [0, -385], [0, 896], [-679, 0], [0, 145], [2614, 0], [2711, 0], [0, -828], [-3017, 0], [0, 525], [-520, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3600_l_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3600_3_l_g();".
// 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_3600_3_l_g(:prec:=2)
    chi := MakeCharacter_3600_l();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2161) - 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_3600_3_l_g();".
// 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_3600_3_l_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3600_l();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![-1, 1]>,<11,R![18, 0, 1]>,<13,R![7, 1]>],Snew);
    return Vf;
end function;