
// Make newform 525.4.d.n 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_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_525_4_d_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 := [2116, 0, 2217, 0, 668, 0, 48, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [12, 0, 1, 0, 0, 0, 0, 0], [0, 1113, 0, 622, 0, 48, 0, 1], [46, 0, 24, 0, 1, 0, 0, 0], [0, 2493, 0, 691, 0, 48, 0, 1], [0, 5620, 0, 3180, 0, 265, 0, 6], [926, 0, 526, 0, 44, 0, 1, 0]];
    Rf_basisdens := [1, 1, 1, 138, 3, 69, 69, 3];
    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, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0], [0, 0, 0, -3, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 7, 0, 0, 0, 0], [5, 0, 3, 0, 5, 0, 0, -1], [0, -3, 0, -2, 0, -3, 1, 0], [0, -7, 0, 24, 0, -3, -3, 0], [-18, 0, 4, 0, -6, 0, 0, 0], [0, -10, 0, -25, 0, 2, 6, 0], [59, 0, 0, 0, -30, 0, 0, -4], [90, 0, -3, 0, -9, 0, 0, 9], [0, -69, 0, 99, 0, -3, 9, 0], [96, 0, 15, 0, -7, 0, 0, 3], [0, 6, 0, -115, 0, 0, -28, 0], [0, -30, 0, 14, 0, -4, 36, 0], [0, -17, 0, -222, 0, -15, -3, 0], [218, 0, -27, 0, -3, 0, 0, 17], [168, 0, -3, 0, 87, 0, 0, -15], [0, -105, 0, -119, 0, 27, -17, 0], [-167, 0, 21, 0, -45, 0, 0, 13], [0, -162, 0, -304, 0, 12, -68, 0], [-87, 0, 37, 0, 153, 0, 0, -3], [0, 51, 0, -370, 0, 29, 33, 0], [46, 0, 78, 0, 140, 0, 0, -14], [0, -168, 0, -102, 0, -36, -28, 0], [-108, 0, 78, 0, -268, 0, 0, -30], [0, -21, 0, -874, 0, 3, 35, 0], [0, -66, 0, 892, 0, 46, -6, 0], [-37, 0, 15, 0, 357, 0, 0, 15], [0, 111, 0, 47, 0, 23, -93, 0], [0, -111, 0, 1021, 0, -51, -103, 0], [-504, 0, -126, 0, -232, 0, 0, -6], [0, 398, 0, 6, 0, -78, 30, 0], [-676, 0, 46, 0, -24, 0, 0, -6], [-703, 0, 138, 0, -244, 0, 0, -46], [-867, 0, 37, 0, -63, 0, 0, 105], [0, -138, 0, -108, 0, 90, 82, 0], [0, 441, 0, -936, 0, 39, -61, 0], [0, -224, 0, -130, 0, 74, 66, 0], [0, -758, 0, 886, 0, 52, 48, 0], [1436, 0, 66, 0, 150, 0, 0, 38], [1164, 0, 52, 0, -42, 0, 0, -12], [-2368, 0, -177, 0, -475, 0, 0, 47], [0, -777, 0, -221, 0, -27, 93, 0], [0, -518, 0, 1793, 0, 56, 120, 0], [-1112, 0, -176, 0, 288, 0, 0, 0], [-1428, 0, 69, 0, -141, 0, 0, -123], [0, -447, 0, 1596, 0, -27, 101, 0], [0, 99, 0, 2026, 0, -65, -309, 0], [-2874, 0, 124, 0, -72, 0, 0, 12], [0, 899, 0, 1209, 0, 27, 243, 0], [1828, 0, -60, 0, -920, 0, 0, -128], [250, 0, -26, 0, 720, 0, 0, 78], [-916, 0, 249, 0, -223, 0, 0, -163], [0, -793, 0, 2578, 0, 73, -147, 0], [0, 140, 0, -1407, 0, -96, 96, 0], [-2246, 0, 300, 0, 552, 0, 0, 4], [-2926, 0, -24, 0, 1014, 0, 0, -132], [0, 264, 0, -506, 0, 12, -544, 0], [-879, 0, -321, 0, -841, 0, 0, 63], [0, -1434, 0, 638, 0, 30, 174, 0], [0, 1518, 0, 3238, 0, 88, 84, 0], [0, -258, 0, 4644, 0, -24, -156, 0], [-3348, 0, 540, 0, 754, 0, 0, 156], [0, -900, 0, 1866, 0, -162, -266, 0], [0, -554, 0, 3221, 0, -76, -120, 0], [-465, 0, -300, 0, -930, 0, 0, 12], [0, 2475, 0, 1866, 0, 81, 329, 0], [0, -41, 0, -3133, 0, 185, 525, 0], [-2178, 0, -511, 0, -1107, 0, 0, 21], [0, 512, 0, 514, 0, 112, 480, 0], [3419, 0, -24, 0, 324, 0, 0, 56], [0, 2037, 0, 2644, 0, 111, 459, 0], [0, 1125, 0, 2075, 0, 51, -93, 0], [81, 0, 670, 0, -192, 0, 0, 186], [0, 1006, 0, -8846, 0, -44, -228, 0], [3539, 0, -225, 0, 919, 0, 0, -13], [0, 633, 0, 678, 0, 267, -257, 0], [-5063, 0, 531, 0, -401, 0, 0, -425], [-6590, 0, 110, 0, 96, 0, 0, 174], [2962, 0, -411, 0, 131, 0, 0, 313], [6683, 0, 489, 0, -117, 0, 0, -63], [-7472, 0, -897, 0, 769, 0, 0, -53], [0, -2022, 0, 372, 0, -126, -526, 0], [4638, 0, -1035, 0, 609, 0, 0, 93], [0, 1092, 0, -4200, 0, 252, -576, 0], [-1135, 0, 579, 0, -1717, 0, 0, -217], [0, 636, 0, 2521, 0, 156, -392, 0], [470, 0, 360, 0, 730, 0, 0, 92], [0, -264, 0, -6088, 0, 228, 652, 0], [0, -251, 0, -3410, 0, 127, -1125, 0], [-5666, 0, 972, 0, -1078, 0, 0, -68], [0, 1503, 0, -1369, 0, 255, -593, 0], [8545, 0, 183, 0, 25, 0, 0, 79], [2428, 0, 917, 0, 2547, 0, 0, 153], [0, 1144, 0, -9834, 0, -84, -228, 0], [1610, 0, 504, 0, -2326, 0, 0, 92], [-298, 0, 243, 0, -243, 0, 0, 95], [0, -1260, 0, -4800, 0, 396, -68, 0], [-1721, 0, 275, 0, 2637, 0, 0, -669], [0, 2010, 0, 6633, 0, 204, -16, 0], [0, 1685, 0, -6935, 0, -359, -435, 0], [0, 2367, 0, -1658, 0, -95, 189, 0], [-2297, 0, -453, 0, -2369, 0, 0, 19], [-3765, 0, -386, 0, 3600, 0, 0, -402], [0, -2280, 0, -3926, 0, -594, 846, 0], [0, 739, 0, 1604, 0, 803, 135, 0], [0, -514, 0, -5528, 0, -314, -1266, 0], [-5843, 0, -894, 0, -2734, 0, 0, -194], [4376, 0, 1072, 0, 4980, 0, 0, 24], [0, -1218, 0, -7910, 0, -300, 984, 0], [0, -51, 0, -1907, 0, 795, -669, 0], [0, 1859, 0, -5405, 0, 451, -129, 0], [446, 0, -858, 0, 60, 0, 0, -318], [5523, 0, -745, 0, -1533, 0, 0, 627], [-12107, 0, -1311, 0, -3987, 0, 0, 37], [0, -1662, 0, 2740, 0, -210, 1670, 0], [0, 1336, 0, -6158, 0, -80, -72, 0], [0, 196, 0, 10854, 0, -24, 792, 0], [2732, 0, -1242, 0, -1382, 0, 0, -538], [5930, 0, -310, 0, -1980, 0, 0, 162], [0, -903, 0, 21930, 0, -105, -329, 0], [0, -4174, 0, -10798, 0, 74, -6, 0], [0, -3099, 0, -13155, 0, 111, -129, 0], [4984, 0, -322, 0, -1866, 0, 0, 726], [-2906, 0, 1179, 0, 217, 0, 0, 187], [786, 0, -154, 0, 7986, 0, 0, 402], [2548, 0, 54, 0, 862, 0, 0, 526], [0, -6453, 0, 6108, 0, 27, 779, 0], [0, 2157, 0, 11300, 0, 255, 651, 0], [7307, 0, -428, 0, -1134, 0, 0, 1140], [0, -1057, 0, -4652, 0, 709, -987, 0], [-2820, 0, -464, 0, 2892, 0, 0, -336], [0, 4791, 0, 1239, 0, 21, -1575, 0], [-9464, 0, 642, 0, -734, 0, 0, -1382], [-2692, 0, 1012, 0, 744, 0, 0, 756], [0, -2366, 0, 19166, 0, -178, 606, 0], [0, 1374, 0, 3748, 0, 888, -1004, 0], [0, -2658, 0, -7676, 0, -200, 180, 0], [-7635, 0, -441, 0, 2959, 0, 0, 747], [-1510, 0, -916, 0, 2052, 0, 0, 636], [-22310, 0, 108, 0, 3756, 0, 0, 388], [0, -1269, 0, -13529, 0, -1113, 539, 0], [0, 2859, 0, -3641, 0, -935, -1167, 0], [-228, 0, 1075, 0, -3237, 0, 0, -825], [12992, 0, 1254, 0, 7420, 0, 0, -346], [0, -2127, 0, 20248, 0, -225, 1467, 0], [0, 1358, 0, -28064, 0, 598, 54, 0], [-5970, 0, 538, 0, 1026, 0, 0, -1134], [0, -8141, 0, 3993, 0, -219, 705, 0], [0, -2070, 0, -166, 0, 714, 1118, 0], [-12162, 0, 177, 0, 931, 0, 0, 1341], [0, -2922, 0, -817, 0, 588, 44, 0], [0, -4166, 0, -17616, 0, -54, 1122, 0], [0, -4437, 0, 9332, 0, -195, 321, 0], [11243, 0, 972, 0, -7532, 0, 0, -496], [30921, 0, 427, 0, 4935, 0, 0, 207], [11580, 0, 1323, 0, 2283, 0, 0, -1101], [0, -186, 0, -24720, 0, -1218, 470, 0], [-4322, 0, -1146, 0, -5446, 0, 0, 1606], [0, -5556, 0, -3188, 0, -20, 2580, 0], [0, -5975, 0, -18197, 0, -767, 717, 0], [0, 9984, 0, 6496, 0, 252, 2344, 0], [27534, 0, 1140, 0, 5838, 0, 0, 420], [0, -7589, 0, -15621, 0, 711, -2385, 0], [0, -2130, 0, -5662, 0, 350, 390, 0], [31835, 0, 25, 0, -2319, 0, 0, -819], [0, -2220, 0, 1522, 0, -810, -1386, 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_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_525_4_d_n(:prec:=8)
    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_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_525_4_d_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![2116, 0, 2217, 0, 668, 0, 48, 0, 1]>,<11,R![-304010, 61617, -2643, -21, 1]>],Snew);
    return Vf;
end function;