
// Make newform 3600.3.j.h in Magma, downloaded from the LMFDB on 02 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3600_j();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_3600_j_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_j_h();".
// 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_j_h();".
// 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 := [1, 0, -1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 0, 0, 1], [-1, 0, 2, 0], [0, 2, 0, -1]];
    Rf_basisdens := [1, 1, 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_j();"
function MakeCharacter_3600_j()
    N := 3600;
    order := 2;
    char_gens := [3151, 901, 2801, 577];
    v := [1, 2, 2, 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_3600_j_Hecke();"
function MakeCharacter_3600_j_Hecke(Kf)
    N := 3600;
    order := 2;
    char_gens := [3151, 901, 2801, 577];
    char_values := [[-1, 0, 0, 0], [1, 0, 0, 0], [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]];
    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, 0, 0], [0, 0, 0, 0], [0, 0, 0, -1], [0, 0, 2, 0], [0, 11, 0, 0], [0, -6, 0, 0], [0, 0, -11, 0], [0, 0, 0, -10], [30, 0, 0, 0], [0, 0, -3, 0], [0, 14, 0, 0], [-36, 0, 0, 0], [0, 0, 0, -3], [0, 0, 0, 26], [0, -72, 0, 0], [0, 0, 22, 0], [35, 0, 0, 0], [0, 0, 0, -17], [0, 0, -52, 0], [0, 62, 0, 0], [0, 0, -44, 0], [0, 0, 0, 42], [144, 0, 0, 0], [0, 181, 0, 0], [48, 0, 0, 0], [0, 0, 0, -56], [0, 0, 0, 104], [-169, 0, 0, 0], [0, -12, 0, 0], [0, 0, 0, 60], [0, 0, -40, 0], [0, -54, 0, 0], [0, 0, -28, 0], [234, 0, 0, 0], [0, 0, 95, 0], [0, 35, 0, 0], [0, 0, 0, -101], [0, 0, 0, 80], [0, -198, 0, 0], [0, 0, -146, 0], [-23, 0, 0, 0], [0, 0, -138, 0], [0, -59, 0, 0], [0, 162, 0, 0], [0, 0, -127, 0], [0, 0, -233, 0], [0, 0, 0, 129], [0, 0, 0, 244], [59, 0, 0, 0], [0, -84, 0, 0], [0, 0, -112, 0], [73, 0, 0, 0], [0, 0, 20, 0], [0, 228, 0, 0], [0, 0, 0, -244], [-270, 0, 0, 0], [0, 0, 20, 0], [0, 49, 0, 0], [246, 0, 0, 0], [0, 0, 0, -81], [0, 78, 0, 0], [0, 0, 0, 117], [0, 0, -214, 0], [0, 25, 0, 0], [0, 600, 0, 0], [0, 0, -236, 0], [0, -203, 0, 0], [0, 0, 0, 354], [538, 0, 0, 0], [0, 498, 0, 0], [0, 0, -52, 0], [0, 0, 0, 329], [0, -491, 0, 0], [0, 0, 187, 0], [0, 0, 0, -212], [-132, 0, 0, 0], [0, 251, 0, 0], [720, 0, 0, 0], [515, 0, 0, 0], [0, 0, -456, 0], [-278, 0, 0, 0], [0, 0, -362, 0], [0, -287, 0, 0], [0, 0, -141, 0], [0, 0, 0, 128], [132, 0, 0, 0], [0, -434, 0, 0], [-312, 0, 0, 0], [0, 0, 0, 52], [0, 0, 0, -2], [0, 0, -426, 0], [0, 0, 0, 149], [0, 0, 192, 0], [0, 0, 177, 0], [0, 0, 0, -108], [-546, 0, 0, 0], [318, 0, 0, 0], [0, 0, 0, -517], [157, 0, 0, 0], [0, 0, 0, -40], [0, -114, 0, 0], [0, 0, 0, -74], [450, 0, 0, 0], [0, 0, -13, 0], [0, 311, 0, 0], [0, 0, 0, 96], [0, 636, 0, 0], [0, 0, 444, 0], [371, 0, 0, 0], [0, 0, 0, 308], [0, -374, 0, 0], [0, -240, 0, 0], [0, 0, -359, 0], [0, 0, 317, 0], [300, 0, 0, 0], [0, 0, 0, 228], [0, 0, 0, 404], [0, -534, 0, 0], [0, 0, 252, 0], [-34, 0, 0, 0], [0, 1234, 0, 0], [0, -534, 0, 0], [0, 0, 0, 304], [0, 0, -648, 0], [-306, 0, 0, 0], [-433, 0, 0, 0], [0, 0, 338, 0], [0, 0, 0, -537], [0, 590, 0, 0], [0, 0, 372, 0], [0, 0, 0, 428], [0, 0, 524, 0], [0, 841, 0, 0], [-924, 0, 0, 0], [-347, 0, 0, 0], [0, -1404, 0, 0], [0, 0, 0, 25], [0, -348, 0, 0], [384, 0, 0, 0], [0, 0, 399, 0], [-462, 0, 0, 0], [0, 0, 0, -355], [0, 0, 0, 112], [-1606, 0, 0, 0], [0, 0, 518, 0], [0, -575, 0, 0], [0, -1068, 0, 0], [0, 0, -712, 0], [0, 0, 0, -96], [0, 731, 0, 0], [-48, 0, 0, 0], [0, 0, 0, -599], [0, 0, 0, -794], [0, 0, 0, -884], [0, 0, 802, 0], [0, 0, 81, 0], [1002, 0, 0, 0], [0, -661, 0, 0], [-1110, 0, 0, 0], [0, 0, 0, -582], [0, 1680, 0, 0], [0, 0, 0, -356], [0, 0, -178, 0], [0, -1578, 0, 0], [0, 0, 0, 796], [0, 0, -47, 0], [0, -34, 0, 0], [383, 0, 0, 0], [0, -78, 0, 0], [0, 0, 438, 0], [-1045, 0, 0, 0], [0, 0, -14, 0], [0, 1583, 0, 0], [0, 0, 953, 0], [-168, 0, 0, 0], [0, 0, 267, 0], [-114, 0, 0, 0], [0, 0, 0, -907], [493, 0, 0, 0], [0, 0, 0, -281], [0, 0, 328, 0], [0, -337, 0, 0], [0, -2034, 0, 0], [0, 0, 0, -210], [-1362, 0, 0, 0], [0, -1583, 0, 0], [0, 0, 0, 1135], [-169, 0, 0, 0], [0, 0, 922, 0], [0, -1921, 0, 0], [0, 0, 0, 412], [0, 0, 697, 0], [-930, 0, 0, 0], [0, 0, 0, -1226], [0, 1566, 0, 0], [-178, 0, 0, 0], [0, -10, 0, 0], [0, 654, 0, 0], [0, 0, 0, 774], [-2052, 0, 0, 0], [0, 0, -808, 0], [0, -1082, 0, 0], [1502, 0, 0, 0], [0, 0, 1340, 0], [0, -606, 0, 0], [0, 0, 1309, 0], [0, 0, 0, -470], [-2100, 0, 0, 0], [0, 0, 329, 0], [0, -325, 0, 0], [-906, 0, 0, 0], [0, 0, 0, 1313], [0, 0, 0, -988], [0, 0, -206, 0], [1334, 0, 0, 0], [0, 0, 0, -621], [1074, 0, 0, 0], [0, 0, 0, -436], [0, -1854, 0, 0], [313, 0, 0, 0], [0, 0, -627, 0], [-78, 0, 0, 0], [0, 0, 0, -564], [0, 0, 0, -812], [2629, 0, 0, 0], [0, 1614, 0, 0], [0, 0, -1190, 0], [0, 0, 0, -919], [0, 0, -486, 0], [0, -2725, 0, 0], [0, 0, 1428, 0], [0, 0, -1233, 0], [2058, 0, 0, 0], [0, 0, 0, 796], [0, 0, 0, -512], [758, 0, 0, 0], [0, 216, 0, 0], [0, 0, 354, 0], [0, 0, 1216, 0], [0, 0, 0, -678], [0, 0, 1061, 0], [0, 0, 0, -1165], [157, 0, 0, 0], [0, 1974, 0, 0], [0, 0, 814, 0], [0, 0, 0, 973], [0, 0, -86, 0], [0, 0, 291, 0], [0, 0, 0, 178], [0, 1354, 0, 0], [-318, 0, 0, 0], [0, 0, 0, 692], [-289, 0, 0, 0], [0, 942, 0, 0], [0, 0, -916, 0], [-1151, 0, 0, 0], [0, 0, 0, -636], [0, 2952, 0, 0], [0, -10, 0, 0], [0, 0, 0, 1525], [0, 0, 0, -774], [-274, 0, 0, 0], [0, -3119, 0, 0], [0, -450, 0, 0], [0, 0, -1152, 0], [-1686, 0, 0, 0], [-1464, 0, 0, 0], [0, 0, 0, -1692], [0, -2622, 0, 0], [1703, 0, 0, 0], [0, 0, 0, 368], [0, 1550, 0, 0], [0, 0, 1255, 0], [0, 1273, 0, 0], [0, 0, 0, -1799], [0, 0, 0, 606], [-1175, 0, 0, 0], [-865, 0, 0, 0], [0, 0, -464, 0], [0, 0, 0, 1780], [0, 0, -1284, 0], [0, 0, 0, 854], [1475, 0, 0, 0], [0, 0, 0, 917], [0, 0, -794, 0], [0, 1103, 0, 0], [0, -2220, 0, 0], [0, 0, -1852, 0], [1764, 0, 0, 0], [-978, 0, 0, 0], [0, 0, 0, 948], [0, 2004, 0, 0], [0, 0, -1360, 0], [0, 3109, 0, 0], [780, 0, 0, 0], [0, 0, -1487, 0], [0, -3300, 0, 0], [0, 0, 1542, 0], [0, 0, 0, 1396], [0, -1550, 0, 0], [0, -3300, 0, 0], [0, 0, 1407, 0], [0, 0, 0, -890], [0, 0, 796, 0], [0, 2773, 0, 0], [0, 0, 0, 2020], [-733, 0, 0, 0], [0, 0, 1280, 0], [0, -2186, 0, 0], [0, 0, 0, -774], [2148, 0, 0, 0], [684, 0, 0, 0], [0, 0, 0, -851], [0, 0, 0, 2106], [-325, 0, 0, 0], [0, 0, -1386, 0], [0, 0, 476, 0], [0, 2435, 0, 0], [2682, 0, 0, 0], [0, 0, -1480, 0], [0, -2257, 0, 0], [-480, 0, 0, 0], [0, 0, 0, -1851], [0, 786, 0, 0], [3442, 0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3600_j_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3600_3_j_h();".
// 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_j_h(:prec:=4)
    chi := MakeCharacter_3600_j();
    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_j_h();".
// 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_j_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3600_j();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![-3, 0, 1]>,<11,R![12, 0, 1]>,<13,R![121, 0, 1]>],Snew);
    return Vf;
end function;