
// Make newform 525.4.d.g in Magma, downloaded from the LMFDB on 25 April 2024.
// 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_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_525_4_d_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 := [196, 0, 29, 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, 15, 0, 1], [15, 0, 1, 0]];
    Rf_basisdens := [1, 1, 14, 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)
    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 := 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 := 4;
    raw_aps := [[0, 1, -1, 0], [0, 0, -3, 0], [0, 0, 0, 0], [0, 0, 7, 0], [2, 0, 0, -10], [0, -12, -14, 0], [0, 2, -2, 0], [-20, 0, 0, -24], [0, -34, -20, 0], [114, 0, 0, 24], [56, 0, 0, -72], [0, 36, -106, 0], [-240, 0, 0, 30], [0, -48, -212, 0], [0, -68, -40, 0], [0, 4, 554, 0], [-344, 0, 0, -116], [-178, 0, 0, -72], [0, -108, 20, 0], [462, 0, 0, 30], [0, 12, -530, 0], [340, 0, 0, -108], [0, 96, -924, 0], [-112, 0, 0, -142], [0, -276, 266, 0], [560, 0, 0, 26], [0, -144, 1384, 0], [0, -170, 440, 0], [394, 0, 0, -288], [0, 264, 222, 0], [0, 156, -1048, 0], [916, 0, 0, 136], [0, -124, -974, 0], [-884, 0, 0, 240], [422, 0, 0, 356], [-808, 0, 0, -432], [0, -192, 2294, 0], [0, 324, -1028, 0], [0, 300, 672, 0], [0, 494, -1682, 0], [-110, 0, 0, -890], [866, 0, 0, -684], [334, 0, 0, 22], [0, 324, -2666, 0], [0, 876, 870, 0], [1888, 0, 0, -360], [1460, 0, 0, 264], [0, -72, 3472, 0], [0, -988, -2396, 0], [-1154, 0, 0, -612], [0, -4, 6574, 0], [438, 0, 0, 78], [1406, 0, 0, -36], [3576, 0, 0, 372], [0, -2, 2774, 0], [0, 814, 1436, 0], [1060, 0, 0, 1378], [-1600, 0, 0, -1296], [0, -180, 1910, 0], [-666, 0, 0, 108], [0, -72, -740, 0], [0, -378, 630, 0], [0, 1488, 3164, 0], [404, 0, 0, 1148], [0, -96, 1846, 0], [0, 1372, -274, 0], [7580, 0, 0, 168], [0, -1944, 2018, 0], [0, -1366, -3872, 0], [6802, 0, 0, 744], [0, -1970, -2350, 0], [-5230, 0, 0, 1346], [0, -912, -3376, 0], [0, 1920, 4978, 0], [-3260, 0, 0, 1032], [0, -1864, 6256, 0], [-3734, 0, 0, -248], [0, -720, -2266, 0], [-242, 0, 0, -788], [-2342, 0, 0, -1548], [-4464, 0, 0, 2700], [-1222, 0, 0, 2988], [-5458, 0, 0, 326], [0, -3864, -4802, 0], [6280, 0, 0, -2544], [0, -1978, 6784, 0], [-10050, 0, 0, 192], [0, -2016, -4390, 0], [3720, 0, 0, 858], [0, -756, -7688, 0], [0, -1508, -10876, 0], [-932, 0, 0, 556], [0, 24, -568, 0], [-6378, 0, 0, 570], [-4628, 0, 0, 1080], [0, 144, -7560, 0], [-7132, 0, 0, -2446], [1580, 0, 0, -3094], [0, -2160, -1892, 0], [-9070, 0, 0, 2076], [0, -492, 212, 0], [0, 644, -2066, 0], [0, 2884, 9788, 0], [11474, 0, 0, -3892], [-11104, 0, 0, 204], [0, 792, 13970, 0], [0, 3276, 5292, 0], [0, -1138, 10498, 0], [-19526, 0, 0, 1978], [1154, 0, 0, -5928], [0, -3936, 2816, 0], [0, 2592, 2626, 0], [0, 5916, 1122, 0], [8404, 0, 0, 1944], [10964, 0, 0, -420], [-7642, 0, 0, 788], [0, -552, -1148, 0], [0, 3380, 11632, 0], [0, 2576, -9974, 0], [-4002, 0, 0, -1950], [-3490, 0, 0, 1248], [0, -1620, -18650, 0], [0, -4766, 11930, 0], [0, 3838, -16960, 0], [3908, 0, 0, 1512], [-6354, 0, 0, 1512], [-4142, 0, 0, -5328], [-12640, 0, 0, -592], [0, -4128, -19768, 0], [0, -5580, -2270, 0], [-9272, 0, 0, -5868], [0, -702, -5868, 0], [1280, 0, 0, 3696], [0, -240, -15538, 0], [-32768, 0, 0, 94], [-362, 0, 0, 1944], [0, -5570, 422, 0], [0, 2664, -5812, 0], [0, -3918, -20958, 0], [12838, 0, 0, -3296], [2252, 0, 0, -7992], [35650, 0, 0, -1148], [0, 3996, 736, 0], [0, -5082, -25464, 0], [42406, 0, 0, -852], [-16332, 0, 0, -132], [0, -1656, -41006, 0], [0, 7502, -3362, 0], [-2180, 0, 0, -2736], [0, -5962, 5188, 0], [0, -8640, 3926, 0], [-36156, 0, 0, 2346], [0, 7992, -10460, 0], [0, 7564, -11632, 0], [0, 1296, -8044, 0], [-31650, 0, 0, -4650], [24064, 0, 0, -1656], [416, 0, 0, 1178], [0, 4872, 26474, 0], [-39604, 0, 0, 1550], [0, 3334, -34672, 0], [0, 10608, -6666, 0], [0, 4764, -26752, 0], [-2012, 0, 0, 1888], [0, 140, 5242, 0], [0, 5800, -19192, 0], [9848, 0, 0, 2520], [0, -288, 20270, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_525_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_525_4_d_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_525_4_d_g(: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_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_525_4_d_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![144, 0, 33, 0, 1]>,<11,R![-1416, 6, 1]>],Snew);
    return Vf;
end function;