
// Make newform 525.4.d.m in Magma, downloaded from the LMFDB on 12 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_525_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_525_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_525_4_d_m();".
// 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_525_4_d_m();".
// 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 := [16, 0, 9, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 5, 0, 1], [5, 0, 1, 0]];
    Rf_basisdens := [1, 1, 4, 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_525_d();"
function MakeCharacter_525_d()
    N := 525;
    order := 2;
    char_gens := [176, 127, 451];
    v := [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_525_d_Hecke();"
function MakeCharacter_525_d_Hecke( : Kf := false)
    N := 525;
    order := 2;
    char_gens := [176, 127, 451];
    char_values := [[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 := ISA(Type(Kf), Fld), 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 := 4;
    raw_aps := [[0, 1, -1, 0], [0, 0, -3, 0], [0, 0, 0, 0], [0, 0, 7, 0], [-13, 0, 0, -5], [0, -17, 11, 0], [0, 27, 53, 0], [0, 0, 0, 56], [0, -24, 115, 0], [-11, 0, 0, 84], [-74, 0, 0, 13], [0, -19, -66, 0], [140, 0, 0, -45], [0, -58, 373, 0], [0, -88, -120, 0], [0, 89, 119, 0], [116, 0, 0, 209], [-248, 0, 0, 273], [0, -123, -640, 0], [427, 0, 0, -235], [0, -88, 90, 0], [265, 0, 0, -103], [0, 431, 821, 0], [28, 0, 0, -522], [0, 704, 266, 0], [-550, 0, 0, 666], [0, 21, -111, 0], [0, 310, -390, 0], [599, 0, 0, 597], [0, -601, 342, 0], [0, -109, -1918, 0], [-214, 0, 0, 246], [0, -394, -4, 0], [1266, 0, 0, -390], [-313, 0, 0, -874], [-43, 0, 0, 453], [0, -242, 834, 0], [0, -341, 427, 0], [0, 90, 2342, 0], [0, 44, 448, 0], [-2900, 0, 0, -370], [-2094, 0, 0, -364], [664, 0, 0, 237], [0, 429, -2566, 0], [0, -2224, -595, 0], [-3152, 0, 0, 1200], [-2520, 0, 0, 479], [0, -1757, 957, 0], [0, 1097, 2529, 0], [-3014, 0, 0, -152], [0, -2349, -236, 0], [-3512, 0, 0, -1232], [-4964, 0, 0, -406], [1146, 0, 0, -163], [0, 1403, -711, 0], [0, -1126, -4609, 0], [-5650, 0, 0, 1508], [260, 0, 0, 1424], [0, -1760, -1230, 0], [-681, 0, 0, -2267], [0, 1278, -2160, 0], [0, -868, 6360, 0], [0, -1232, 2114, 0], [-3406, 0, 0, 868], [0, 714, -5774, 0], [0, 2852, -759, 0], [1055, 0, 0, -3782], [0, 3121, 3263, 0], [0, 279, -9082, 0], [-5068, 0, 0, 4889], [0, 3740, -390, 0], [-4535, 0, 0, -94], [0, -4627, -2411, 0], [0, 3735, 6348, 0], [8065, 0, 0, -3808], [0, -924, 2956, 0], [-2219, 0, 0, -3883], [0, -3735, -1521, 0], [7643, 0, 0, -63], [2068, 0, 0, -4418], [8986, 0, 0, -2195], [-2417, 0, 0, -477], [14212, 0, 0, -1159], [0, -2594, 4238, 0], [-460, 0, 0, 4661], [0, -4428, -2576, 0], [175, 0, 0, 2097], [0, -1916, 1215, 0], [-9900, 0, 0, 328], [0, 6344, 4972, 0], [0, 157, -14521, 0], [8728, 0, 0, 2596], [0, -631, -18698, 0], [18727, 0, 0, 335], [-1808, 0, 0, 3395], [0, 7344, 3410, 0], [-4712, 0, 0, 1084], [-8150, 0, 0, 491], [0, 1420, -3292, 0], [-1025, 0, 0, 3781], [0, 1658, 12757, 0], [0, -4751, -8126, 0], [0, -8341, -5487, 0], [-8031, 0, 0, 2293], [16871, 0, 0, -336], [0, -2258, 5690, 0], [0, -3819, -21653, 0], [0, -1078, -8522, 0], [9279, 0, 0, -7952], [-17756, 0, 0, -3428], [0, 6864, 516, 0], [0, -3233, -5574, 0], [0, -10589, -3898, 0], [4444, 0, 0, 1374], [-5981, 0, 0, -3405], [10723, 0, 0, -2877], [0, 4598, 24682, 0], [0, -220, 8862, 0], [0, 336, -29034, 0], [17668, 0, 0, 3890], [-20900, 0, 0, -2402], [0, 3615, -7215, 0], [0, -4466, -6880, 0], [0, -107, -28170, 0], [-11092, 0, 0, 10942], [-8834, 0, 0, -8163], [-8142, 0, 0, -10198], [26960, 0, 0, -582], [0, -2403, 28047, 0], [0, -5415, -26415, 0], [-5497, 0, 0, -598], [0, -2847, 3077, 0], [-8800, 0, 0, 17936], [0, -115, 12222, 0], [9612, 0, 0, -1366], [-22312, 0, 0, 9084], [0, -730, -31728, 0], [0, 4484, 8318, 0], [0, 17692, 16002, 0], [-10397, 0, 0, 4009], [9342, 0, 0, 2688], [9730, 0, 0, 9572], [0, -8659, 20146, 0], [0, -15877, -8994, 0], [13626, 0, 0, 6503], [6658, 0, 0, -9162], [0, -3871, -8831, 0], [0, -4038, 2318, 0], [9750, 0, 0, -19166], [0, 13883, -6052, 0], [0, -12510, 5016, 0], [-6666, 0, 0, 12041], [0, -10858, 6615, 0], [0, 9234, -17642, 0], [0, -20719, 661, 0], [16005, 0, 0, -5310], [-10091, 0, 0, -3721], [24706, 0, 0, -4597], [0, -15338, 5234, 0], [24966, 0, 0, -13710], [0, -8776, -2132, 0], [0, 12093, -14036, 0], [0, -13936, 4608, 0], [40188, 0, 0, 3968], [0, -4785, 5962, 0], [0, -3150, -392, 0], [45003, 0, 0, -3575], [0, -8538, 31190, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_525_d_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_525_4_d_m();".
// 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_525_4_d_m(:prec:=4)
    chi := MakeCharacter_525_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_525_4_d_m();".
// 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_525_4_d_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![4, 0, 13, 0, 1]>,<11,R![134, 31, 1]>],Snew);
    return Vf;
end function;