
// Make newform 2496.4.a.bc in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2496_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_2496_4_a_bc();".
// 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_2496_4_a_bc();".
// 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 := [-14, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 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_2496_a();"
function MakeCharacter_2496_a()
    N := 2496;
    order := 1;
    char_gens := [703, 1093, 833, 769];
    v := [1, 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_2496_a_Hecke(Kf)
    return MakeCharacter_2496_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, 0], [3, 0], [-12, 1], [0, -1], [22, 6], [13, 0], [82, 2], [-24, -1], [4, 24], [-202, 12], [20, -13], [50, -14], [100, 47], [308, -26], [-162, 16], [82, 60], [-70, -20], [-314, -68], [236, 85], [214, -42], [-450, 38], [-216, -44], [694, -32], [480, -95], [-266, -110], [182, -14], [-280, 218], [-984, -20], [30, -140], [702, 116], [24, -170], [736, 72], [164, 95], [-460, 20], [1080, -145], [-420, 57], [322, 264], [1976, -119], [310, -56], [2862, -130], [-1572, -248], [-1286, 144], [1736, -104], [954, -196], [4252, -51], [2680, -50], [3852, -24], [4436, 87], [306, 310], [686, -316], [3118, -330], [1942, 438], [2766, 446], [-5256, -156], [910, -286], [2628, -420], [3606, 204], [856, -689], [1274, 72], [-2988, -145], [-4236, -282], [5016, 451], [-316, -493], [2484, 448], [-1290, 408], [4692, 189], [-6540, -127], [5182, 572], [-5324, -820], [-382, 542], [5252, -249], [-2490, -960], [264, -1200], [-178, -600], [-4240, -885], [7450, 348], [-7990, 210], [9730, 306], [-2544, 821], [1254, -174], [1312, -272], [8350, 868], [-6470, 1012], [5990, 388], [-4032, -918], [-7264, 1476], [6984, -919], [-5114, 518], [-2692, -815], [-5680, 243], [640, 1116], [-2630, 910], [-12300, -821], [-5968, -284], [11892, -127], [-340, -1192], [5020, 665], [11398, 4], [5020, -28], [2078, -600], [9036, -620], [6480, 1471], [-5780, 1692], [590, 1890], [-9652, 690], [5522, -2148], [1278, 48], [16920, -387], [-2388, 368], [1126, -1504], [-10696, 1740], [12762, -1790], [10316, -1777], [-19252, 547], [10404, -647], [-6974, -2294], [3628, -251], [-5904, 988], [886, -1544], [11748, 292], [-30, 318], [-12246, -2696], [1850, -104], [-4858, 690], [-13084, 1457], [9466, 762], [22518, -1808], [2252, 828], [-14536, 790], [-8794, -2984], [916, 2239], [-11498, -1314], [17056, -714], [-3594, 2700], [-7836, -2877], [-6150, -3000], [-23512, 1339], [-21020, -649], [8850, -4114], [-9114, 1964], [-20072, 955], [26624, -2201], [14912, -1554], [31294, -1818], [-15522, -3028], [19754, 3226], [14642, 710], [10510, 2074], [7692, 5068], [1162, -424], [1042, 4774], [8566, 3586], [13260, -178], [-1240, -4236], [3932, -726], [26104, -852], [10144, 1316], [-3772, 247], [-21418, 1492], [-9928, -149], [-22766, -1248], [-11434, 262], [20140, -3401], [-12268, -1604], [-24496, -3355], [-5222, 7030], [-32864, 3196], [-1854, 2240], [8974, -2574], [-30770, -718], [-28670, 390], [-7758, 6506], [-16428, 2020], [-35274, 2962], [-42376, -274], [2, -2152], [39404, 99], [-36232, -3245], [10952, 2586], [-26298, -3952], [-22984, -2117], [13948, 3680], [-42810, -1628], [2552, 1737], [-58042, -1760], [-13910, 1930], [-41454, 1720], [256, -6549], [24622, 2698], [-25114, 1376], [27538, -1240], [-21474, 396], [22028, -4280], [-28408, 2671], [-23852, -4032], [7894, -9466], [27890, 2572], [26262, 2200], [44640, 49], [33008, -5560], [4492, -887], [3376, -6804], [-1066, -9408], [-6222, -3648], [-28102, -3808], [19290, 5096], [-26196, 6351], [-47160, 552], [38952, 4033], [-23972, 4390], [6726, -10412], [33474, -4336], [1432, 2016], [8630, -534], [17426, 5824], [52306, 4296], [-13656, -760], [27610, -1308], [30398, -1874], [-16952, -3621], [-51886, -2896], [-43432, 5607], [40616, -571], [84548, -245], [11584, 2832], [4834, 4356], [-40990, -672], [-57332, -2988], [60840, 1874], [47786, -188], [-55278, 3640], [3476, -936], [-60712, -1931], [26874, -3942], [-1836, 1888], [11446, -12722], [39902, -982], [50792, 3175], [-94868, -432], [-464, 11956], [-13138, -12480], [26932, -814], [-20032, -12260], [-24726, 1346], [-18912, -7555], [-80620, -4880], [-41064, 3243], [6898, 2060], [-19920, -8265], [53932, 6636], [-2370, 2456], [2980, 6567], [-31158, 2582], [-36234, 4244], [91758, -3736], [10790, -710], [-22898, -4184], [-54960, -209], [-76918, 6794], [4914, 10000], [39288, -10910], [-24060, -6004], [115286, -236], [15610, -9128], [5784, -3975], [108660, 560], [74628, -3123], [-4140, -2273], [54764, 983], [36966, -2814], [-93426, -3176], [47356, -4615], [5030, 13918], [-45328, 2418], [15790, 7544], [-5624, 16817], [-29678, 2114], [86730, 8170], [35666, -1924], [-10864, -668], [-21896, -5656], [-129936, -717], [122320, 3744], [27082, 11566], [33492, 3499], [64, -2172], [-14426, -17236], [-42888, 7679], [69604, -7159], [77870, -4610], [-20830, 3968], [-52356, 4092], [-4608, 3941], [-70366, -8436], [-526, -6072], [11258, -3938], [-66384, 7296], [60522, 4410], [69724, 1476], [13316, 8155], [114122, -5144], [-49324, 3825], [-48112, -5858], [55292, 10160], [21236, 1672], [-34122, 3366], [-7948, 20324], [1322, -6872], [57850, -2050], [68966, -9884], [-57188, 14196], [1772, -13107], [-16922, -10956], [23772, 12220], [-12162, -924], [-5722, 352], [75770, -14130], [-55470, 4492], [-82786, -2786], [-62742, 14562], [-75788, -2514], [-56038, 9292], [-19486, -9676], [13972, -3999], [-63256, 16609], [57094, 12228], [-45160, -11255], [-108124, 11701], [67664, -10580], [151110, 2712], [167878, -1440], [36366, 21720], [-9392, -10688], [-40874, 3826], [-176816, 1619], [133854, 1292], [27882, -16542], [183388, -2385], [177686, -2634], [8400, -13686], [87458, -3426], [-50490, -11096], [41736, -14901], [-65856, 2518], [-66188, -8415], [88380, -16820], [-27298, -15744], [93152, -11611], [67454, -19832], [-76502, -442], [21868, 21525], [105758, -9754], [57504, 6139], [-73944, -15398], [-43722, -9608], [-26834, -8708], [-168218, 2008], [198610, 2898], [92726, 3038], [154034, 804], [-59014, -7530], [-15454, -26954], [19756, 23408], [-4222, 402], [-159524, -5210], [78034, -9096], [-3708, 14589], [16076, 4237], [-45982, 3024], [132720, -6652], [-9324, -13106], [47158, -3420], [-79510, -23300], [-180592, 4964], [-17622, -6352], [-38786, 14116], [-25416, 1468], [-178238, -9604], [33962, 30788], [-108110, -11716], [26976, 3727], [-31332, 17235], [-17744, 23403], [-45176, 24465], [-67624, 769], [129090, 17118], [35680, 20157], [59878, 3108], [-68920, 3627], [173084, -9680], [34942, -16422], [-25160, -13593], [-69330, -2930], [89316, 3780], [9902, -27880], [-103010, 7948], [-8192, -34323], [-28910, 6870], [-142420, 14868], [161140, 2093], [-49142, -15698], [-90054, -11998], [-140080, -6841], [68624, -3395], [-193932, -5363], [47560, -28628], [-80794, -6280], [95824, 24013], [-70948, -5125], [-93234, -10766], [-111182, 6920], [48154, -19688], [-47500, 612], [53388, -31030], [-54718, -29468], [94578, 6880], [-116050, 6750], [114648, -20804], [37016, -16707], [49420, -24292], [34118, 11242], [88330, -15994], [-24690, 22194], [-69600, 10440], [64450, 12308], [81200, -27429], [85944, -13012], [160560, 3925], [284384, -2971], [60712, -2892]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2496_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2496_4_a_bc();".
// 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_2496_4_a_bc(:prec:=2)
    chi := MakeCharacter_2496_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_2496_4_a_bc();".
// 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_2496_4_a_bc( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2496_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![88, 24, 1]>,<7,R![-56, 0, 1]>,<11,R![-1532, -44, 1]>],Snew);
    return Vf;
end function;