
// Make newform 1575.4.a.n in Magma, downloaded from the LMFDB on 12 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1575_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_1575_4_a_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_1575_4_a_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 := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_1575_a();"
function MakeCharacter_1575_a()
    N := 1575;
    order := 1;
    char_gens := [1226, 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_1575_a_Hecke(Kf)
    return MakeCharacter_1575_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 := [[-2, -1], [0, 0], [0, 0], [7, 0], [46, -2], [-4, -38], [-22, -44], [-54, -26], [-160, 20], [118, 12], [-30, -102], [-102, 24], [-22, -80], [-68, 128], [200, 168], [8, -86], [232, -36], [-342, -84], [-368, 164], [370, -138], [-212, -122], [-204, 484], [304, 84], [666, -112], [1224, -86], [-34, -632], [736, -256], [568, -312], [1318, -336], [-572, 618], [1180, 628], [956, 208], [968, -386], [-1982, 478], [-2014, 104], [48, 608], [-96, 758], [348, -64], [-996, -76], [190, -1220], [-674, 126], [-1386, -712], [1558, -206], [-2266, -552], [684, 398], [-2614, -350], [2184, 516], [-2748, 1172], [1456, 1068], [2850, -140], [2212, 794], [2674, 310], [2182, -1396], [2200, -356], [-498, -656], [-2612, 992], [3326, -648], [-274, -186], [-1334, -2216], [-1918, 1732], [-2780, -1008], [4142, 996], [6432, 84], [9784, 56], [-888, 586], [-936, -1774], [-264, -2244], [-6642, 976], [924, 1940], [-2358, 1484], [-1350, -3388], [3982, -414], [2860, -468], [3310, 540], [-5772, 376], [-740, -332], [-1134, 2944], [3636, 4490], [-1570, -5608], [-7198, -3040], [12828, -1336], [-5362, -3264], [1274, 1478], [7032, -1678], [-3366, 1314], [15468, -12], [-4570, -2152], [-950, -5644], [-6690, 2432], [-6548, -620], [9632, -916], [12144, -2824], [5636, 6380], [-490, 7742], [3116, 1304], [-388, -7508], [5150, -4408], [722, 3504], [-4680, -6068], [-3194, -1136], [3432, 2044], [-9264, 4714], [10652, 168], [190, 1936], [-444, 1808], [2272, 522], [5436, 7088], [-8718, -2452], [4158, 2114], [854, -1300], [-4028, -2796], [-14662, -3912], [-12612, 2674], [7930, 1254], [-13860, -1436], [-2318, 9708], [5240, 9020], [4220, -4588], [-14884, -7058], [16482, -6134], [3962, 10420], [-4542, 2500], [-33866, -308], [1644, 5844], [-22130, -1070], [-15610, -1924], [18534, -5512], [-23108, 4492], [14820, -860], [-1436, -4590], [25564, -4736], [8340, 4544], [708, -12100], [20790, 3252], [-13558, 7664], [4438, -44], [20622, -4748], [-28712, 4868], [10078, 11916], [3242, -3980], [18914, -5090], [10702, -1884], [11588, -8716], [-11144, -11928], [-7074, 14824], [18372, -1244], [8420, 4050], [-4818, -392], [2766, 10978], [-26872, 7972], [11138, -4040], [5506, 7640], [18904, -7372], [-14264, 12272], [9728, -8460], [1854, 6794], [-29868, -428], [-654, 2880], [16476, -1250], [31782, 6112], [-5132, -1188], [9508, -1502], [-10880, -5824], [2568, 2436], [6940, -18694], [-19568, 11712], [-20596, 13844], [7372, 14730], [6754, 14032], [-3322, -9636], [43478, -10], [20270, 15328], [-32230, 12094], [-16914, -6168], [-3162, -9226], [-6758, -1848], [-23152, -484], [1226, -19464], [26212, 10740], [54614, -5672], [-48024, -7632], [-27880, -10580], [10886, -14188], [3058, 6740], [-17348, 1352], [35046, 10944], [-40726, 7536], [39488, 1532], [-9870, -16824], [-18948, 22044], [24472, 12042], [31320, -18040], [28572, 21560], [23734, -3032], [21396, -8516], [-6846, 31092], [67650, -5712], [4030, -15532], [-14922, -2520], [19652, 16796], [-16274, -20228], [36602, 19882], [-46312, -7922], [-18466, -7996], [-15696, -14468], [-8426, -26220], [-40162, 6270], [15392, -6136], [18282, 12228], [6838, 16458], [79434, 1420], [-48602, -12264], [54448, -8440], [-63344, -4996], [-6140, 8372], [-1890, 26996], [-46252, -5596], [47978, -11696], [-11124, -26080], [45460, 7942], [43638, 5320], [-37462, -342], [4442, 6412], [2864, 28608], [-1980, 5288], [81630, -3952], [46478, -10488], [53718, 24058], [11224, 14040], [-39818, -13634], [-65098, 8252], [-10414, -31282], [-54616, -15088], [-43990, 628], [-8592, -44484], [65656, -11920], [-53158, 2528], [12844, 37630], [-16394, 11982], [652, 2260], [-8520, 25672], [-29606, 26262], [-45144, -26720], [-51186, 11560], [91918, 9200], [49700, 3492], [26804, -27844], [31540, 19248], [-15160, 100], [-37968, 16236], [-38942, -30776], [-42182, 25040], [40488, 24212], [-4678, 8808], [-93794, 5356], [21454, 13734], [-15330, -4016], [19716, 6144], [-31746, 36228], [43168, 6530], [20644, 22684], [-94364, -348], [16410, -11988], [35672, 25678], [26066, 19996], [-98802, 17970], [-45106, 6204], [-43038, 11552], [-68864, 4444], [5460, -50738], [57910, -11320], [-4196, -15112], [71200, 1370], [-23724, 39708], [26984, 37018], [-47988, -12500], [-30496, 16704], [8830, -35272], [63450, 13968], [50232, 12212], [-4512, -48104], [68756, -20740], [-19000, -54024], [-59370, 33808], [-80048, -11788], [-28346, -50478], [-104406, -10708], [-30608, -58174], [74474, -24534], [-12766, -176], [32462, 16636], [62424, 924], [67428, 10], [-14700, 47752], [45430, 31148], [19134, -67008], [55390, 16958], [-85118, -10160], [-133032, 4796], [62344, -652], [61612, 30718], [-29236, 13278], [11040, 29664], [55100, 17188], [-48340, -28376], [15438, 47136], [35176, 13376], [-19510, 35076], [-25710, 20902], [-16402, -53780], [128296, 8448], [71110, -5180], [-6938, 27520], [-35144, -23996], [-24072, 13420], [-92146, -38932], [-25412, -15488], [-94506, 2458], [125032, 9018], [-83114, -24512], [27342, 16458], [94666, 5812], [-4186, -32664], [-16312, 36952], [-107264, 1198], [-10906, -10628], [37996, 39504], [8228, -8304], [-60528, 5076], [22208, 44058], [-62810, 38128], [-102300, 7622], [95998, 46326], [77764, 7248], [-40440, -35916], [-72500, 40480], [66534, 25680], [-29378, 20832], [10710, -34044], [-75972, 8628], [-22098, 57084], [114396, 37394], [50230, 58344], [39672, 63112], [75668, -32698], [28018, -3318], [-78454, 1180], [-2496, 14276], [-35468, -13212], [-418, -18300], [-159158, 15510], [45378, -44996], [-65858, 66940], [-38808, -44200], [-62362, -35128], [-81814, 23820], [-44180, 45468], [-117012, 1704], [97428, 15274], [31516, -41544], [60078, -54708], [62442, -32080], [105892, -43928], [-31246, -51822], [-6104, -19964], [62178, -26180], [-83166, -8760], [-52760, 63544], [58330, -6944], [3078, 7190], [-20594, 48034], [-126964, 21488], [-58190, 78680], [19766, -22058], [100154, 63424], [112012, -28432], [-53850, 41514], [-88376, -65038], [3370, 67824], [82828, 43190], [86422, 17848], [-61292, 35954], [18900, 14332], [73824, 66518], [103970, 29702], [46884, -63324], [-108148, -25900], [143700, 44650], [-137768, -9660], [-182536, -21976], [-115894, 26104], [-148878, 31856], [-78214, 75626], [-104, -33860], [-150710, -43602], [99686, -63392], [-55266, -23922], [6778, 55160], [195172, -10240], [178862, 16876], [-20306, -47344], [-16292, -65790], [-149280, 10408], [-49506, 26056], [25470, 2128], [81942, 878], [-192694, -17536], [-120170, -29624], [-172372, -22584], [-34056, -54252], [144500, -37922], [-7808, -43430], [-49644, -62148], [126872, 10292], [99878, 57216], [119694, -62632], [-45854, 39270], [-131444, -46004], [138010, 55572], [-28224, 37528], [-71286, 22832], [81260, 63514], [249636, -5064], [77640, -5852], [-96152, -69750], [60486, -40172], [-35096, 40664], [-42714, -85656], [-68186, -20622], [101236, -73756]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1575_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1575_4_a_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_1575_4_a_n(:prec:=2)
    chi := MakeCharacter_1575_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_1575_4_a_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_1575_4_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1575_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-1, 4, 1]>,<11,R![2096, -92, 1]>,<13,R![-7204, 8, 1]>],Snew);
    return Vf;
end function;