
// Make newform 525.4.a.q in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_525_a();"
// 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_a_q();".
// 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_a_q();".
// 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, -13, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-9, -1, 1]];
    Rf_basisdens := [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_525_a();"
function MakeCharacter_525_a()
    N := 525;
    order := 1;
    char_gens := [176, 127, 451];
    v := [1, 1, 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;

function MakeCharacter_525_a_Hecke(Kf)
    return MakeCharacter_525_a();
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], [3, 0, 0], [0, 0, 0], [7, 0, 0], [-26, 8, -4], [-36, 5, -1], [-50, 3, 5], [-44, -7, -1], [52, 23, -1], [66, -34, -6], [-104, -47, 7], [-84, -32, -32], [-34, -61, 43], [4, 108, 12], [52, -82, 50], [-144, 105, 27], [-332, 112, -4], [-306, 106, 58], [-20, 90, -66], [-374, 136, 32], [-452, -133, 65], [-464, -198, 30], [356, -252, -56], [-650, -31, -43], [-556, -183, 27], [6, 135, -33], [-476, -78, -258], [924, -269, -33], [-458, -68, -80], [1032, -9, 129], [472, -30, 342], [-1232, 304, -100], [516, -585, -183], [528, -559, -133], [-426, 248, -36], [-516, 806, -142], [-432, -219, 183], [-1516, -246, -150], [-1732, 34, -302], [-510, 297, -429], [2006, 264, 388], [-230, -148, 116], [1046, -1220, -116], [-368, 154, 10], [568, -353, -19], [-140, 637, 439], [-776, 520, -632], [216, 912, 288], [1324, 1030, 74], [-1378, 384, -48], [1932, 289, -369], [-2078, -28, 68], [2542, 918, -186], [876, -1068, -432], [3102, 757, -405], [4404, -255, -423], [-3834, 41, -1119], [1712, 467, 317], [332, -292, -244], [-1322, -26, 854], [-3680, -510, -426], [710, -605, 721], [696, 518, -238], [972, -1110, -234], [-328, 907, 1081], [1736, -935, 1099], [-1560, 588, 612], [-4312, 100, -308], [7852, 431, -445], [-3314, 1938, 18], [1186, 109, -517], [-322, -1644, -140], [-6184, 628, 412], [4564, -2212, -304], [-3416, -686, 1174], [4220, -1516, 1036], [-7994, -354, 98], [-648, -13, -511], [1650, -2850, -186], [2490, 1970, 746], [-3364, 358, 1126], [2110, 956, -472], [-2918, 1396, 644], [1296, 2071, 1285], [2572, 437, -1153], [-3692, 2143, -613], [1538, 3240, 16], [6920, -1170, 138], [-15090, -807, -3], [-4728, -474, -2166], [8020, 1334, 242], [-660, -54, -1530], [12952, -1720, -532], [-8946, -1192, 276], [-8944, 962, -226], [-612, 3852, 756], [-8702, -2665, -553], [6106, 2415, 287], [-76, 2048, -904], [4634, 2092, -464], [-6100, 4862, 1250], [8240, 3789, -1649], [-5764, -434, 1054], [10386, -3438, 138], [-9028, -1112, -296], [-13968, 3043, -575], [-6356, -2962, 758], [-6634, 2391, -2447], [5230, -92, 1580], [6262, -1956, -2148], [7672, -3496, 296], [8404, 2890, 1906], [-4172, 729, 2015], [-7352, 1689, 1635], [2688, 2986, 502], [17910, -454, -822], [-8400, 1718, -1150], [-11804, 1266, -1318], [5220, 3629, 471], [2434, 1868, 536], [13550, -2042, -1178], [-6848, -5932, 2696], [-1366, 861, 1975], [-4788, -8057, 1275], [8528, -3493, -127], [8986, 4182, -622], [19946, -2856, 624], [2160, 462, -2022], [-8500, 4802, 758], [13372, -10187, -1529], [-7868, -1152, -3288], [-6532, 3755, 1939], [-6092, 4868, 1268], [-716, -5472, 36], [82, -5241, 731], [-1074, 672, 1296], [-6674, -2353, 1469], [2756, -7768, 152], [21474, -5647, 315], [29598, 3960, -408], [-9128, 4953, -453], [33474, 3008, -60], [-2528, 4782, -798], [-3292, 2683, 847], [17138, -4952, -920], [-6324, 4668, -4740], [-304, 8635, -2423], [7598, 5965, 2899], [36, -8945, 1297], [2692, 4475, -181], [13708, -222, 666], [2774, 5291, -401], [22540, -5680, -4], [5500, -602, -2566], [-21460, -144, 2844], [-27106, 1516, 652], [-19812, 2584, -1880], [-15134, -245, 3239], [2360, -1531, 1007], [40630, 1511, 467], [-1988, 5921, -2755], [27936, 735, 3969], [16888, -10370, 1558], [-39856, -2478, 1330], [18204, -1167, 3111], [4452, -3240, 2460], [-5140, 9788, 4916], [-10616, 891, 3441], [3426, 14296, -536], [8390, -6257, 1117], [-12962, -5404, -424], [15418, 4766, -2842], [-18638, -7872, 3848], [-12848, 5670, -66], [10708, 8715, -2031], [15142, -13507, -5731], [-7924, 5226, 2238], [-7682, 4634, -3034], [13260, 8006, -2206], [13578, 3298, -1622], [-32728, -5862, 2994], [-18688, 7090, 154], [-21300, 3410, 4766], [-6926, 1721, -4969], [-12804, 8645, -5811], [13226, 2797, 1093], [-14916, 290, -2494], [-1340, -11220, -1044], [-38226, -908, -1868], [10896, 1538, 1326], [-27668, 225, 1755], [-9140, -6717, -5497], [-4688, -12482, -3638], [-43342, -57, 3667], [-2828, -8935, 1349], [-6986, -3469, -9067], [386, -6224, 4432], [9940, 754, 2686], [41342, -4415, 2287], [-7244, -2026, 4238], [12722, -9800, 388], [-40116, 517, -4817], [-9276, -73, 2525], [-10, 3518, -3442], [-5280, -9250, 3894], [50314, -6679, 539], [-11636, 207, -1347], [33692, -1601, 3427], [14478, 5056, 1008], [-29044, -3961, -7207], [7176, -8194, -1582], [-6254, -7685, 5603], [18888, -8108, -5636], [16204, -2872, 4172], [21428, 10400, 5536], [36734, -444, -4260], [-13024, 1012, 3592], [28274, 5333, 6841], [10724, 15725, -4019], [55804, 1293, -1897], [5690, -15936, 5496], [-4208, -8547, -4245], [44678, -12100, -116], [-2936, -3844, 3860], [31444, 1724, 3620], [-33734, -12444, 1932], [-8490, 5813, -261], [-39618, 5164, -3444], [-57988, -10358, 3694], [21694, -4396, -3928], [-1956, 12144, 2508], [-19004, 4313, -1249], [31564, -17430, 1182], [27670, 8744, -6784], [-46328, 1630, -8054], [10780, 376, -6124], [-42230, 834, -9366], [89592, -7629, 273], [5894, -6404, -9920], [-2240, -7002, 2978], [-48308, -5023, 1157], [-14000, -3975, -429], [1840, 12284, 7580], [28062, -16648, -8704], [32102, 20725, 691], [44212, -1516, 4940], [48892, 238, 2602], [-17308, -12998, -8390], [-55148, -6282, -2478], [-64972, 6711, -689], [67060, -7758, 5610], [-4262, 9881, 8981], [-32964, 23849, 8865], [44642, -21646, -1558], [5838, 23931, -6351], [-76442, 5352, 5156], [50994, 2488, 3160], [-50304, 11594, -7522], [27158, 10843, -4175], [-17616, -4197, -399], [-14536, -6890, 6754], [42940, -9221, 8279], [-10706, -13860, 10212], [61912, 2841, -2517], [21342, -693, 4005], [7024, 16059, -7191], [13674, 18372, 336], [6306, 17007, -3801], [45356, 18058, -98], [7316, -8335, 7075], [62714, 1930, 5506], [-68876, -3144, -1128], [-39292, -18631, -685], [27852, 1364, 4724], [-7660, -7811, -12521], [-31092, 2594, 4574], [18900, -21177, -4605], [11614, 1132, 1192], [-66118, -6648, 3396], [-81588, 5340, 2376], [-101732, 11004, -1216], [-87600, -8974, 494], [2116, -19216, 908], [-6190, -17350, 10706], [-26060, 7932, -13764], [15846, 9240, -13344], [5016, -8066, 13330], [50896, -8223, -7597], [-68824, -11799, 9999], [10402, 991, 8075], [-34014, -5412, -1824], [-80340, 1176, -13980], [-31684, -13015, -10145], [-70420, -8662, 6154], [14732, -108, 6840], [13590, -24995, -1239], [3492, -12205, 3713], [17126, -12687, -5069], [-26932, 6036, 3280], [35788, -12216, -3576], [15392, -30115, 6023], [-61684, 15757, 1111], [-27040, 4756, 2788], [-11604, 2257, 10749], [18692, 8960, 9680], [-7872, 29524, -11588], [9052, -5719, 20237], [-37738, 8788, -9020], [13090, -28324, -15340], [64316, 5586, -12930], [-47564, -17428, 1592], [-11134, 11878, 17650], [-48494, 41198, 6614], [20100, -6800, 1036], [-52108, 10267, 4171], [71806, -14606, 11794], [-130048, 6236, -6800], [49518, -920, -12840], [-6532, -27231, 1875], [-58414, -3590, 5026], [-70444, -10353, 3177], [-73296, -20796, 5544], [-35830, -8601, -11429], [-29408, 30012, -10404], [-126560, -511, -6769], [-75746, 11686, -9266], [-45908, -15656, 11200], [-76624, 42102, 2298], [70580, -2687, 16825], [19436, -20193, 9157], [-5294, 35364, 8184], [-4044, -25527, -6861], [40352, 42919, -4895], [-10068, 4042, 7218], [80844, -19526, 15622], [-20452, 41350, 6478], [-74834, 19908, -12444], [-77566, 52523, 13525], [51198, -22526, -9278], [45388, 10158, -8934], [-46908, -29048, -11444], [-76036, -3131, 7195], [-16610, 17381, 5741], [16668, 37926, 3738], [61276, 12449, -2485], [36162, -29360, 2532], [39462, 1232, 9296], [61228, -22600, 836], [64976, 8994, 14206], [-24626, -21529, 989], [71036, 10433, 15551], [33584, 14084, 608], [-12294, 18180, 6072], [-19928, -12388, 5660], [30186, 12380, -3424], [60170, 4197, 18787], [87032, -6858, 13834], [-33880, -25164, 3688], [-99864, 23087, -5439], [-68332, 12775, -21353], [-7692, 21872, 19844], [-34550, -6471, 2825], [12708, -39089, -11049], [-6446, 10724, -20752], [25020, -25576, -17392], [33400, 36768, -2196], [-124966, -20165, -7055], [74216, -37090, -13210], [90394, -33680, -4916], [-94754, 22268, 9464], [-22308, 21227, -26419], [-38116, -1205, 14707], [20222, -1648, 9028], [113576, -18681, -2007], [115932, 6508, -476], [-123096, -24356, 4272], [129134, 21060, -10100], [-113680, -13597, 1337], [-28966, 21019, -18413], [-160268, 14139, 3561], [107926, -41393, -9265], [16928, -12437, -12611], [55928, 11540, 6080], [-12712, 34877, -7589], [71400, -31819, 1079], [-149644, -7968, 5008], [43644, 2468, -18340], [-29132, -25691, 6799], [42724, -42358, 10766], [-55268, -5302, -10162], [3238, -56652, -7068], [-17786, -26055, -19909], [-10606, -41312, -13676], [-7952, 8526, 20370], [55202, -10424, 280], [-95472, -376, -3520], [70324, 22111, -1907], [7702, 20831, 14315], [78564, 5572, 32812], [-33254, -23602, -13654], [-63174, -14454, 3930], [39784, -59025, -12223], [87752, 35854, 46], [-102326, 31967, 14897], [103646, 17431, -9437], [198948, -27229, -6607], [30620, -30232, -1168], [-146030, 8264, -1816], [5324, -13716, 11532], [-47332, 38564, -22832], [-81968, 16205, -745], [78772, 58739, -17287], [36668, -54261, -11489], [-19920, 14528, -6472], [8496, 22390, -21722], [13494, -41299, 30981], [39058, 28188, 21644], [-164636, -9286, -13330], [-54190, -23807, 13255], [6132, -35006, -12738], [-73442, 27434, -4042], [121760, 10523, 30401], [-133356, -31893, 12723], [-2024, 49718, -14602], [-46512, -24381, 16161], [-49874, 49847, -20083], [-12860, 35237, -2959], [6090, -48642, 21990], [-19600, -19097, 19261], [58740, -5220, 21924]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_525_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_525_4_a_q();".
// 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_a_q(:prec:=3)
    chi := MakeCharacter_525_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_a_q();".
// 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_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-1, -13, 1, 1]>,<11,R![-6120, -276, 66, 1]>],Snew);
    return Vf;
end function;