
// Make newform 3600.3.l.n in Magma, downloaded from the LMFDB on 16 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_n();".
// 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_n();".
// 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 := [9, 0, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -1, 0, 1], [0, 7, 0, -1], [-12, 0, 6, 0]];
    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_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, 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+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, 0, 0], [0, 0, 0, 0], [-4, 0, 1, 0], [0, -1, 0, 1], [-2, 0, -1, 0], [0, 4, 0, 0], [-8, 0, -2, 0], [0, 2, 0, -1], [0, 8, 0, -1], [-2, 0, -2, 0], [34, 0, 3, 0], [0, -3, 0, 4], [20, 0, -2, 0], [0, -14, 0, -2], [0, -10, 0, -4], [0, -17, 0, -3], [-10, 0, -6, 0], [-76, 0, 0, 0], [0, -12, 0, 2], [-38, 0, 6, 0], [-50, 0, -6, 0], [0, 2, 0, -4], [0, 21, 0, 2], [106, 0, -2, 0], [0, -2, 0, -9], [-28, 0, 15, 0], [0, -22, 0, 0], [26, 0, 10, 0], [0, -26, 0, 0], [20, 0, 9, 0], [0, -11, 0, -7], [0, 6, 0, 18], [-98, 0, 12, 0], [0, -6, 0, 5], [10, 0, -12, 0], [22, 0, -1, 0], [-196, 0, -10, 0], [0, 38, 0, 1], [0, -34, 0, 14], [0, -5, 0, -5], [38, 0, -10, 0], [0, -26, 0, 4], [-110, 0, 0, 0], [0, -4, 0, -17], [94, 0, 8, 0], [-38, 0, 32, 0], [-64, 0, -13, 0], [0, 36, 0, 20], [-178, 0, 8, 0], [0, -36, 0, 4], [0, 50, 0, -10], [-220, 0, -4, 0], [0, -49, 0, -5], [0, -50, 0, 6], [0, -86, 0, -7], [0, -68, 0, -1], [-362, 0, -12, 0], [10, 0, -35, 0], [0, -83, 0, 0], [-16, 0, -28, 0], [0, -12, 0, -1], [344, 0, -12, 0], [0, -2, 0, 0], [-302, 0, -32, 0], [0, -52, 0, 23], [220, 0, -18, 0], [-206, 0, 22, 0], [0, 24, 0, -2], [-94, 0, -6, 0], [0, -12, 0, -18], [0, 98, 0, 12], [272, 0, -3, 0], [-410, 0, 31, 0], [-182, 0, 16, 0], [0, -46, 0, -34], [0, 20, 0, 9], [-14, 0, -11, 0], [0, -15, 0, -8], [-298, 0, -4, 0], [0, -17, 0, -25], [-202, 0, -60, 0], [0, -30, 0, 42], [478, 0, 38, 0], [-50, 0, 0, 0], [0, -4, 0, 38], [0, 19, 0, 30], [490, 0, 6, 0], [0, -42, 0, 23], [224, 0, -21, 0], [0, -114, 0, -14], [0, -32, 0, -30], [428, 0, 19, 0], [0, -37, 0, 1], [-332, 0, -30, 0], [0, -82, 0, -2], [0, -6, 0, -11], [0, 63, 0, 14], [-580, 0, 30, 0], [470, 0, 46, 0], [-616, 0, -6, 0], [0, 66, 0, 44], [0, 64, 0, -22], [0, 19, 0, 16], [-116, 0, -82, 0], [94, 0, 18, 0], [0, -174, 0, -4], [0, -70, 0, 22], [0, -30, 0, 66], [20, 0, -32, 0], [-316, 0, 51, 0], [538, 0, -15, 0], [0, 132, 0, 22], [-422, 0, 12, 0], [-326, 0, -2, 0], [0, 123, 0, -54], [440, 0, 30, 0], [0, 2, 0, -10], [0, -44, 0, 55], [0, -53, 0, -43], [-586, 0, 6, 0], [-698, 0, 30, 0], [0, 88, 0, -1], [0, 62, 0, -18], [328, 0, 6, 0], [0, 94, 0, 3], [-430, 0, 32, 0], [0, 198, 0, -20], [212, 0, -111, 0], [46, 0, -57, 0], [-524, 0, -78, 0], [0, 42, 0, 58], [154, 0, 102, 0], [-302, 0, 81, 0], [0, -67, 0, -70], [-304, 0, -104, 0], [0, 52, 0, -41], [-880, 0, -66, 0], [0, -154, 0, 30], [0, -189, 0, -22], [-158, 0, 40, 0], [0, 88, 0, 47], [-16, 0, 37, 0], [0, -104, 0, -42], [506, 0, 18, 0], [0, 18, 0, -52], [-110, 0, 69, 0], [0, -136, 0, 70], [-206, 0, 24, 0], [0, 122, 0, -55], [-1070, 0, -7, 0], [0, -3, 0, 54], [-100, 0, -46, 0], [0, 266, 0, 25], [-112, 0, 102, 0], [0, 360, 0, 4], [1546, 0, -6, 0], [0, 35, 0, -66], [-146, 0, -148, 0], [0, 164, 0, -5], [0, -56, 0, -94], [0, 34, 0, 6], [-136, 0, 39, 0], [0, -131, 0, 93], [0, -264, 0, 54], [0, -70, 0, 22], [-734, 0, 24, 0], [-302, 0, 63, 0], [-904, 0, -12, 0], [0, 94, 0, -34], [0, 169, 0, 95], [1502, 0, -36, 0], [0, 320, 0, 38], [382, 0, -172, 0], [214, 0, -22, 0], [0, -139, 0, 38], [514, 0, -32, 0], [0, -70, 0, 7], [-1228, 0, -77, 0], [-862, 0, 100, 0], [680, 0, 47, 0], [0, -161, 0, 69], [154, 0, 111, 0], [0, -194, 0, 16], [0, 14, 0, -30], [0, -388, 0, 9], [-530, 0, -27, 0], [284, 0, 32, 0], [-472, 0, 32, 0], [0, 14, 0, -58], [406, 0, 136, 0], [0, 236, 0, -2], [-146, 0, -148, 0], [0, -162, 0, -71], [0, -162, 0, -76], [0, 26, 0, 56], [926, 0, -36, 0], [-230, 0, 57, 0], [0, -314, 0, 16], [0, -62, 0, 154], [0, 128, 0, 89], [742, 0, 42, 0], [-98, 0, -33, 0], [392, 0, -204, 0], [0, -9, 0, 95], [0, -152, 0, -15], [-134, 0, 58, 0], [0, 364, 0, 28], [0, 273, 0, -46], [-440, 0, -2, 0], [34, 0, 160, 0], [0, 466, 0, -9], [380, 0, 69, 0], [0, -384, 0, -28], [0, 188, 0, 72], [122, 0, 228, 0], [32, 0, -53, 0], [0, 5, 0, 52], [0, -214, 0, 82], [0, -6, 0, 12], [-778, 0, -172, 0], [-422, 0, -168, 0], [0, -239, 0, -28], [200, 0, 261, 0], [0, -306, 0, 54], [1790, 0, -20, 0], [0, -162, 0, -28], [0, -318, 0, -42], [104, 0, 179, 0], [0, 13, 0, 105], [586, 0, -7, 0], [682, 0, 60, 0], [-770, 0, 20, 0], [0, -289, 0, -8], [-796, 0, 54, 0], [0, -46, 0, 11], [674, 0, 84, 0], [0, -360, 0, -37], [0, -285, 0, -65], [0, 148, 0, 28], [0, 28, 0, 44], [1108, 0, 42, 0], [416, 0, -87, 0], [1826, 0, -114, 0], [0, 452, 0, -42], [0, 312, 0, 2], [1520, 0, 23, 0], [0, -409, 0, -11], [-2252, 0, 70, 0], [0, 346, 0, -33], [-62, 0, -153, 0], [0, 145, 0, 128], [0, 94, 0, -77], [-178, 0, -120, 0], [0, 298, 0, -84], [0, 55, 0, -27], [554, 0, 30, 0], [-580, 0, -168, 0], [0, 166, 0, 40], [1078, 0, 138, 0], [-1168, 0, -19, 0], [0, -432, 0, 76], [-766, 0, -108, 0], [358, 0, -79, 0], [0, 166, 0, -56], [-644, 0, 54, 0], [0, -280, 0, -103], [0, 387, 0, 94], [1088, 0, -210, 0], [0, -12, 0, 7], [386, 0, -68, 0], [-952, 0, -180, 0], [-14, 0, -204, 0], [-590, 0, 6, 0], [-722, 0, -32, 0], [1220, 0, -219, 0], [0, -196, 0, -134], [1502, 0, 14, 0], [-742, 0, -148, 0], [0, 401, 0, -39], [0, -322, 0, -9], [-746, 0, -120, 0], [0, 250, 0, 114], [434, 0, 24, 0], [-1984, 0, -90, 0], [0, -278, 0, -58], [-950, 0, 116, 0], [0, 200, 0, -87], [562, 0, -168, 0], [0, 283, 0, -86], [0, 516, 0, 99], [0, 2, 0, 44], [0, -544, 0, -62], [0, -527, 0, 69], [382, 0, 9, 0], [0, -154, 0, -167], [-1190, 0, 10, 0], [0, -6, 0, 34], [0, -393, 0, -89], [3236, 0, -6, 0], [-170, 0, -348, 0], [0, -16, 0, 61], [3178, 0, -4, 0], [0, -222, 0, 120], [2080, 0, -126, 0], [1810, 0, -16, 0], [0, -54, 0, 212], [398, 0, 0, 0], [0, -108, 0, 230], [-3134, 0, 45, 0], [0, -110, 0, 65], [0, -164, 0, -149], [0, -569, 0, 48], [-1840, 0, 2, 0], [0, 714, 0, -50], [188, 0, 316, 0], [0, -115, 0, 265], [0, 416, 0, 14], [3286, 0, 70, 0], [0, -95, 0, 106], [-1076, 0, 66, 0], [-614, 0, 152, 0], [0, 282, 0, 103], [788, 0, 323, 0], [0, 60, 0, -178], [-2320, 0, 24, 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_n();".
// 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_n(:prec:=4)
    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_n();".
// 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_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3600_l();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![-74, 8, 1]>,<11,R![26244, 0, 396, 0, 1]>,<13,R![-86, 4, 1]>],Snew);
    return Vf;
end function;