
// Make newform 1575.4.a.z in Magma, downloaded from the LMFDB on 25 April 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_z();".
// 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_z();".
// 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 := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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 := [[4, 1], [0, 0], [0, 0], [7, 0], [7, 32], [-25, -4], [-25, 44], [18, 44], [122, -68], [13, -24], [-60, -180], [-282, 60], [164, -124], [130, -68], [-175, -132], [-28, 128], [616, 0], [168, -108], [76, 64], [952, 0], [-338, 344], [507, 248], [-188, 600], [108, -44], [-1371, -220], [338, 68], [667, -716], [862, -456], [241, 1056], [-242, -1140], [-1304, -64], [110, -1324], [644, -1108], [166, -256], [-226, -392], [-645, -1184], [-774, -176], [174, 832], [-795, -308], [403, -2044], [-2300, 480], [2028, 400], [1099, 512], [404, 804], [-696, 988], [3080, 152], [4863, -552], [2811, -2516], [325, 948], [-1260, -3796], [88, -368], [-263, -3760], [-3146, -2228], [118, -304], [-4818, -2152], [2014, 2272], [-2266, 696], [1904, 1980], [-4286, -3304], [1853, -1048], [205, 3972], [3863, 2532], [-579, 948], [-4466, -2300], [-3561, -3532], [-642, -5048], [-7308, 1680], [3546, 2528], [846, 6148], [-4494, 4084], [4299, 1060], [448, -1920], [2095, 3732], [-1916, -3204], [-2460, -1264], [-2756, -2776], [3747, 1856], [-1131, -2204], [6503, 1648], [-6010, 4024], [5028, 5488], [3401, -7176], [5807, -440], [-1890, 4336], [-5502, 48], [-8490, -2124], [12041, 3400], [-6224, -6452], [-10056, -2816], [13792, -3628], [119, 4876], [-10266, -5564], [-11062, -3872], [-379, 112], [3269, 1888], [-3589, -5668], [-7930, 6928], [-7390, 900], [12228, 3152], [15475, -4360], [-9192, -1204], [8712, -11728], [18716, 2160], [11182, 848], [-8676, 2056], [-2069, -1884], [-12096, 2584], [9261, 6844], [-1329, -15080], [-15970, 16], [5917, 14196], [1982, -1872], [-2382, 14696], [610, -8316], [9681, -3040], [17758, 1200], [9599, 3604], [8360, -14888], [314, -8980], [-10701, 9032], [-4096, 3656], [-564, -18124], [-13319, 6428], [9384, 12828], [-12428, -14776], [8633, 17416], [16803, -2192], [9574, -1060], [-13992, 12488], [-989, 11292], [-2543, 6416], [20940, 3544], [5739, -14024], [-1824, 3096], [13490, -11108], [-314, -15664], [-7935, 12452], [29083, -5756], [-8429, 22596], [10079, 5744], [-18406, 11240], [-2117, -11160], [3740, -12572], [25174, -7104], [26676, -3316], [15282, -9196], [-11374, -1392], [-4638, 16496], [12300, 4256], [16688, 15164], [24974, -3724], [-15392, 20848], [-4004, 628], [20248, 13072], [-21466, 1572], [-10368, -17144], [20079, 4064], [-18060, -984], [-32427, -1444], [-6480, -5428], [-18152, -14100], [6808, -1252], [21982, -23672], [-22200, -108], [14374, -20], [21139, 9420], [-5344, -21104], [50713, 12], [-4355, 28952], [6050, -13320], [41240, 5728], [12650, -20968], [-10069, 15992], [2070, 19032], [-9534, 14596], [-38804, 144], [-18331, -14936], [-33781, -16800], [-28076, -5592], [22712, -17236], [29532, -25188], [500, -4708], [-670, -6212], [19462, -6944], [-39332, -2804], [30102, -15564], [5864, 4488], [3143, 21508], [21249, 14832], [-25152, -14652], [-61970, 10032], [-35418, 24220], [45531, -8840], [66472, 4676], [17268, 6008], [40221, 3276], [16599, 8376], [7324, 15076], [2919, -21540], [25445, -28628], [-15062, -4144], [-23590, 23600], [-34522, 15848], [77402, -1580], [17418, -1756], [29287, -25332], [12170, -15552], [35108, 9724], [-42630, 23856], [-54896, -8484], [41916, -2644], [-1442, 22656], [-11516, -33476], [-14435, 48484], [17758, 21400], [-41244, 700], [44222, -10220], [31628, 47516], [11922, -9140], [18910, -29056], [-15870, -53800], [44138, -3888], [-9973, 42920], [-2506, 18264], [23181, 8020], [26910, -4568], [-18037, 22788], [70911, -1288], [-19469, -26220], [31852, 13784], [-48388, -10580], [-8986, 15736], [-14032, 4888], [10799, -19336], [75771, -15972], [-17435, 19972], [-5032, 23692], [-17312, 8408], [17509, -39096], [-34562, -31300], [46104, -10576], [43624, 24024], [17127, 12620], [-14226, 31568], [41773, -7556], [15770, 33732], [-11944, -4568], [-4850, -79032], [32639, 56336], [8790, -22452], [32062, 1196], [81886, -17528], [-4140, -22664], [-80680, -11208], [16318, 8408], [-8549, -70944], [66654, -13576], [34980, 21744], [64977, -7356], [84475, 17932], [-88910, -24292], [-81230, -31656], [47844, -43224], [32387, 63668], [61298, 1976], [98298, 14412], [-38365, -15072], [48414, -46688], [58684, -16816], [-77550, -4660], [49072, 65644], [1372, 7564], [105541, 4252], [16596, -45696], [58298, -53752], [73383, 17420], [72524, -31344], [874, -61472], [-83607, -19200], [-72594, -10328], [-127731, 12716], [-72013, -7736], [-7888, 80976], [81942, -31576], [-41501, 76108], [-40169, 16776], [26970, 49876], [-44342, -5636], [59900, -45120], [-42052, 14192], [32363, -21736], [51927, 1644], [38688, -68548], [-95628, 11180], [-84122, 28732], [66216, 63468], [-5102, 43240], [39409, -38572], [-36108, 30136], [87415, 43396], [1201, 49628], [26534, 68352], [-78531, -7320], [-77392, -1360], [1883, -20224], [79062, 30588], [-19250, -40004], [-16192, 43728], [18408, -64744], [25544, 26552], [-82136, 9000], [-53111, 26768], [-45038, 94400], [-75902, 47600], [-61938, 57044], [-34876, 76372], [66190, -27520], [105879, 3488], [12529, -72924], [-95741, 34112], [-126402, -27864], [-8600, -72820], [-20026, -19896], [-6076, 73316], [41230, 17888], [-16948, -59128], [50251, 17064], [42044, 112584], [30192, 15492], [64148, 79116], [-49826, 9392], [-21732, 21460], [44230, 53352], [-22325, -6276], [-71388, 58440], [-101615, 10844], [-15183, -19464], [106786, -64512], [-76698, -5220], [-104553, 26892], [-69474, -97440], [-43416, -3824], [-73514, -32844], [65853, 32552], [19046, -67340], [-83252, 35280], [92486, 25592], [-45564, -42092], [-9482, 124908], [-126109, 13932], [46648, 114480], [9264, -133108], [19195, -256], [-5601, -85988], [-18619, 121096], [-36418, 23784], [109642, -49656], [58578, 76836], [177594, -3916], [-10694, 6624], [-74688, 90036], [142008, 65392], [-31448, -18844], [13859, 75696], [-51092, -18496], [160062, -12628], [8763, -107220], [124126, 12716], [-96419, 93488], [-7197, -127040], [6928, 14492], [-9928, -48944], [-101591, -46976], [806, -48352], [-4306, 38912], [43432, 71368], [-112725, -11232], [-39893, 131308], [-59750, -48432], [60583, -56516], [7810, -57592], [-2858, -26312], [-53844, -44176], [81414, -91304], [-44320, -24404], [133125, -75420], [61769, 68656], [-117897, -64252], [28828, 110040], [-25297, -54428], [-63511, -129040], [-25977, 19036], [-162631, 30280], [-157412, -84112], [136783, 59664], [-66952, -10072], [104532, 53964], [-38240, -83516], [52705, 114448], [57302, 14480], [157948, -66572], [-20204, 187680], [-204306, -28972], [180531, 31916], [-52188, 92144], [-106518, -99776], [-106162, -72368], [154033, 29456], [107444, -22224], [-158796, 43248], [-41323, -29716], [-36578, 145064], [-82386, -123996], [-16204, -125984], [73826, -25644], [102456, 56416], [51679, -2544], [-36500, 63752], [34522, 76104], [-144963, 50252], [-77841, -76472], [4706, 174656], [-26694, 9264], [79884, -30664], [-154745, -59028], [115491, -45436], [170704, 69688], [91446, 135912], [-47480, -80388], [-110672, 108796]];
    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_z();".
// 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_z(: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_z();".
// 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_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1575_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![14, -8, 1]>,<11,R![-1999, -14, 1]>,<13,R![593, 50, 1]>],Snew);
    return Vf;
end function;