
// Make newform 448.6.a.q in Magma, downloaded from the LMFDB on 27 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_448_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_448_6_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_448_6_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 := [-44, -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_448_a();"
function MakeCharacter_448_a()
    N := 448;
    order := 1;
    char_gens := [127, 197, 129];
    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_448_a_Hecke(Kf)
    return MakeCharacter_448_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 := 6;
    raw_aps := [[0, 0], [-13, -1], [31, 5], [-49, 0], [486, -6], [-39, 71], [280, 6], [1321, 37], [-1136, 248], [3904, 14], [-2722, -130], [-288, -650], [-8444, 378], [-4198, -338], [2266, -1238], [-710, 1152], [17073, 325], [-9553, -3347], [28476, 1240], [3612, -700], [64414, -1260], [-26404, 1548], [-42243, 5209], [-65486, -2312], [97312, 350], [88311, -4995], [166626, -2294], [45648, -1372], [-77740, -814], [-40788, 4490], [171772, 1260], [-142279, -5403], [65414, -8292], [153471, 8227], [-44314, -12436], [-364564, 2548], [323409, 14031], [321274, -24138], [-118314, -30754], [453925, -8141], [18680, 24868], [107521, 27191], [-331132, -39100], [391656, -20202], [20886, -57556], [-343634, 1270], [-399244, 55296], [75036, -53284], [151673, -33755], [-1037435, 33259], [-446302, 44888], [281776, 40944], [-215864, 119030], [1401079, 25163], [-685782, -102296], [51900, 26596], [1148901, 24915], [-677048, 16504], [-274342, -88992], [-569814, -100112], [971465, 3037], [-756669, -41527], [-1422455, -31163], [-1598448, 13448], [470804, 165498], [1093326, -84740], [-450838, 150430], [-2783296, -53666], [519426, 205862], [-760163, 162779], [-329790, 203200], [-1440180, 167300], [3050212, -31820], [-1508090, -69652], [961182, -65950], [-946614, -60694], [-2987896, -57730], [248333, 56699], [3690024, 122022], [690240, -396634], [864719, 107771], [88466, -6232], [-293688, 335656], [1151836, 39722], [3687384, -117136], [93884, -417568], [992986, 13592], [1477696, 180742], [2400777, -95433], [2223328, -36176], [-1638099, 496553], [410270, -160834], [-1882768, 434856], [356004, -674728], [-4104260, -219000], [776948, 234444], [2574813, -309893], [6463980, 48610], [7815173, -183543], [-5263402, 196], [4583662, -23702], [7230086, -146524], [4366411, 346951], [11903448, -93682], [5787830, -700230], [952650, 126312], [963643, -861537], [5324670, -64276], [-10751680, 173528], [-2393102, -857736], [10060928, -272288], [2766200, -110226], [-1096056, -332370], [-10683207, 98877], [-8751212, 93836], [-1526768, 123230], [702043, -18681], [1878366, -720730], [4398004, 119410], [-9332650, -382942], [8163931, 742097], [-2337098, -1012780], [2344473, 784959], [-9580644, 406320], [6770417, -1133971], [6929516, -394790], [-4289464, -926018], [20474166, 210918], [131098, 1301970], [-5121433, 314245], [-786278, 915222], [-7404332, 536844], [-7800872, 503160], [-27851344, -215754], [13761432, -142658], [16921252, 291586], [1672571, -972319], [188725, 1984753], [-7963491, -342181], [-3500760, 1034254], [18732357, -415607], [-12757326, -1206888], [-24365312, -213800], [13157424, 1538868], [28203655, 366789], [4216122, -1708158], [-1634347, -1025749], [1195008, 293990], [-15444665, -589957], [-11266004, -976436], [10462360, 1328278], [-23689346, 1140268], [796048, -1085924], [-3802494, -486502], [11185208, 1478220], [12077180, -2023396], [28968896, 183224], [995200, -657826], [28642494, -265836], [5898735, 2621661], [13592782, 1321850], [3864898, -2164888], [9570696, 4384], [-13877783, -3293779], [42575790, -506788], [-48312630, -327646], [-19135608, 409864], [-3608077, -2313287], [23200536, 2528918], [-3956659, -3817725], [-26528204, 864664], [4867593, -344345], [-33342852, 1993636], [21174994, -461272], [-11922738, -2944834], [10478606, 751444], [-6101128, 810972], [40954248, 789182], [45063740, 1252516], [31953119, -494195], [-38998408, 2413992], [18897923, -1585745], [23109428, 130986], [-13420334, 1823176], [-43586292, 1485292], [10211409, -2311769], [13893562, 1848328], [-32325607, -3443771], [-25481754, 3493020], [-56316822, -943574], [-39160726, -866360], [-1089900, 1187464], [20684720, 4900060], [32402769, -473137], [50283784, 7652], [58905414, 713724], [25632448, -5177538], [-27317264, -772322], [14185918, -1725156], [26168000, -1521816], [11839714, -1944736], [-21037590, -1688198], [8428963, -201895], [9080398, -3721972], [37778589, 1921985], [62998959, 2350445], [-19190390, 3073098], [-8230470, -4238026], [8319524, -3043254], [-79231565, -531529], [16944912, -4274802], [61128207, 4155589], [-2833684, 366068], [33450441, 354717], [29103424, 1792776], [19793736, 1435390], [-55197360, -4282944], [-33092500, -266758], [82493472, -2977352], [9487316, -613150], [-24107604, -7495774], [-60003040, 3889912], [14309354, -6511704], [14015808, -3517216], [87401929, 838213], [-3475124, -1897166], [45364458, -5129296], [-29220968, -3594744], [-38381380, -4187644], [-12958530, -3322254], [45881972, 3062930], [-30233401, -3818013], [-71446888, 3751832], [-33273950, 3201016], [18471133, -4510719], [-12497184, 8530960], [-17367112, -5079642], [17538990, 7720052], [-8522660, -6254880], [36125124, 963436], [40530038, 1463554], [1385261, -6623743], [19514716, -9300540], [5903858, -3433872], [-50489154, 2287884], [-21253354, -9532370], [-59344888, -8577816], [59218721, 5244077], [-10662342, -11918994], [-27701576, 8079560], [35067766, 3274692], [40496762, 8890712], [-6481636, -3509916], [74157546, -381120], [-9263233, 3219469], [-101161872, -4722244], [-72939452, -7273110], [-142485133, 4952839], [107590335, 981957], [-85675752, 6512606], [59327632, 2828768], [-127570494, -1963650], [-150395601, 1418069], [16153031, 1340517], [70244784, 3204270], [-126249529, -1249389], [148971734, 3102228], [-4908350, 2711272], [23094000, 14059252], [-76871844, -7973230], [-27397051, 5513075], [119910694, 10151506], [-84990346, -3470980], [-37732284, 5365396], [-166425678, 1974080], [-15081212, -9859396], [-19271638, 7054478], [-156863770, -2743724], [-62189596, -14932854], [-111855195, -6627711], [34340124, 2470172], [162464968, 7037136], [-147222294, -5633470], [-74793525, 14632945], [12674717, 11879809], [103280268, -6461332], [31435914, 14140728], [17265758, 4444164], [-197839734, -1455614], [128926722, 7954752], [-62322294, 4333032], [-147856475, 2305953], [69516536, -4196466], [41378629, -208215], [76198522, 10978264], [55023269, -4114589], [62347896, 6563064], [-15985391, -12886137], [-185908641, 7278131], [-194718949, -4259673], [63643208, -9972930], [46017036, -12920598], [-95763432, -2360536], [-75638070, 19064886], [4228482, -6708346], [-120818554, -3608860], [98296962, -1211242], [-70863325, -5396783], [213036344, 2131616], [80887642, -4490544], [98722924, 8173340], [96055960, 19451678], [120393358, -7818580], [-253072358, -8086154], [-110077292, -5570884], [150007546, 7512560], [120321019, -15126473], [72928256, -12518976], [-98147138, -478884], [330467658, 6348216], [46052015, 9906539], [17062958, -11986636], [258241023, -6056867], [26288828, 12884220], [95908544, -12612186], [23900924, -12638262], [150858622, 17052122], [-55358843, 5609561], [123656724, -6364668], [-295213812, 9444610], [-191571762, 8481068], [297618156, 8424794], [36529466, 11454362], [-30617081, -12160973], [171760952, -10993876], [-277007179, -7995863], [319342316, -6008486], [293933794, 2133984], [-6292390, 668016], [-360912574, -7787534], [-94250514, 7531060], [170468304, -6847162], [-86770167, 18768975], [-154355468, -6568580], [-152962652, -17022734], [2639310, -15834582], [-246381463, 1383247], [129809110, -4349142], [118495892, -6313500], [-163999013, 450289], [282879323, -6402265], [82375090, -12946232], [-322226478, 1285264], [92876010, 3046714], [217346190, -922508], [-275174250, -16327588], [-54385746, -892210], [313168865, 15280389], [-38545518, -32957792], [-145482792, 23359456], [210805174, 3939052], [-49843602, 7624804], [-367153596, -16050684], [-398090328, -7365652], [536763825, -730083], [214024352, 22485062], [13506597, -23365197], [291989616, -4059512], [-220649504, -7626154], [-264855136, -19600388], [-64517977, -34781397], [-106095336, -6512472], [130265822, -34768380], [-208640152, -2174112], [-310133802, 17451364], [-128364191, -22853219], [-196728960, -12777872], [-5870914, -1365764], [-167404168, 11247526], [268325728, -18716314], [-57253507, 24598427], [-84050152, 26362718], [-213260848, -8520184], [-70188102, -12400488], [-230328661, 4313079], [147655320, -34391200], [-21085028, -46975316], [-306814457, -16191779], [233705084, -35858016], [-140586454, -21264022], [-109363840, 22310510], [22151687, -5538131], [449077464, 5206668], [-489693969, 2740203], [241095812, 19303948], [-560883466, -13739204], [249458486, 16224726], [149229748, -16274614], [284351368, -22252260], [-406636848, -373034], [155718303, -17984611], [471520586, -18458104], [232162800, -2883200], [-520377024, -5677402], [104259349, 22891707], [-171741038, -42672006], [-27318758, -39504360], [-552518264, 843462], [-81336513, -16323813], [-257216493, 30771967], [105156390, -43290700], [-4551516, 25435786], [122363174, 45529866], [395452780, 4386696], [-188151990, 8876864], [-434783127, -15341513], [276193124, 4287556], [-43445038, 50779962], [-367476168, 34998278], [-185880940, -30724660], [-305524092, -15254350], [-154072517, 8586369], [-585416904, -4175800], [493757835, -9570081], [-168277260, 20330634], [463155555, 7370801], [204364918, -8266590], [263722242, 8761032], [-76134517, 42871935], [485221286, 8503550]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_448_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_448_6_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_448_6_a_q(:prec:=2)
    chi := MakeCharacter_448_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_448_6_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_448_6_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_448_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-8, 26, 1]>,<5,R![-3464, -62, 1]>],Snew);
    return Vf;
end function;