
// Make newform 225.6.a.i in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_225_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_225_6_a_i();".
// 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_225_6_a_i();".
// 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 := [-22, -1, 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_225_a();"
function MakeCharacter_225_a()
    N := 225;
    order := 1;
    char_gens := [101, 127];
    v := [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_225_a_Hecke(Kf)
    return MakeCharacter_225_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 := [[-4, -1], [0, 0], [0, 0], [42, 24], [-30, -108], [690, -84], [-358, 140], [-632, -72], [-2996, 88], [1344, 864], [-5752, -144], [7542, -396], [-2418, 3024], [-4452, 1344], [-976, -1288], [12094, -2012], [-30342, 3348], [-13486, -3168], [-312, -4560], [-7092, -3240], [-2124, 792], [-24080, -9360], [-70412, 6832], [-70758, 4752], [50568, -15600], [-116760, 6912], [10698, -25176], [-67516, 28112], [26458, 37728], [-50642, -4988], [55098, 57960], [53166, -12852], [11606, -38476], [-128708, -23328], [183156, -26784], [-5368, -58320], [-76686, -44484], [-366336, -36720], [211148, 32456], [-416102, -7028], [-147510, -95580], [-399022, 6336], [54060, 103032], [382452, 36888], [-244690, -41692], [-220016, 89424], [252188, 19296], [-413790, -153384], [213548, 9296], [266662, -13248], [-756758, 36076], [-144588, 100872], [-1097770, -81792], [-1215522, -142020], [895094, -106828], [1202476, -205640], [-511488, -92448], [-595240, 173088], [617910, -40908], [-1003566, -225504], [-262560, 193776], [664606, 420100], [-588564, 379008], [-1549140, -26568], [1667604, 14520], [-2159446, 131372], [776912, 93960], [1448940, 262632], [-1897228, -72160], [338746, 752256], [-2476310, -368756], [-1297152, -50112], [731130, -253848], [3286338, -135876], [1362580, -255600], [733096, 569320], [1958988, -88992], [4189446, 207108], [-1002534, -674352], [1740502, -497088], [2830182, -366228], [784166, 167904], [3406752, -349056], [3480084, -154440], [-1387760, -212400], [1573420, -30896], [2129346, 802656], [-4456128, 62304], [789108, -51840], [-5313522, 524184], [-2285836, 590432], [2748180, -1266840], [1776438, 277560], [-3276834, 861948], [6536008, 552888], [4913440, -548456], [2626368, -45792], [6248682, 381024], [548928, 602064], [-801142, 2327616], [3255972, -2204256], [703622, 1112180], [2394028, 675232], [105402, -915408], [2168720, -704952], [-7932672, 131040], [9758084, -992368], [422062, -3045884], [-5409984, 2578176], [10321250, -703872], [-10103442, 1331400], [-4661298, -889452], [678266, -961396], [-1227308, -1844208], [-5716528, 3132720], [1988862, 1802304], [-5203272, -181776], [3228392, 2753960], [3505186, -2332100], [-3771330, 1866780], [4711922, -2501280], [-14374644, -1420728], [-8784310, -1057492], [-7109084, 2151040], [-1799680, -715752], [4042656, 749088], [2305678, -3644352], [-3025224, -223344], [3274134, 3215256], [19086918, 429684], [2622112, 2106792], [-21629888, 786616], [19227680, -2306592], [-444906, -2085804], [20538354, -5184], [4455874, -572256], [4307506, 4703260], [10958736, 1283088], [-2766646, 226892], [27166590, -1252800], [-3981148, 3175200], [22885224, -3348864], [11609502, -3435672], [8982812, -2063200], [19282930, -1749600], [-17094840, -2538000], [-7208106, 7352580], [13324514, -5015908], [6814900, -2774160], [-2060588, -1128344], [14201202, -3348996], [-13815486, 2135376], [5222808, 6670224], [-7575796, 2924552], [24148716, -2992512], [-3200592, 2151360], [-30023840, -3576960], [12521442, 4214592], [-28073880, 1169712], [-4142148, -4129056], [-21860284, -3502576], [13375510, 1701364], [-25051902, 1637400], [3452382, -7878276], [7660322, 6872060], [-9235976, -4623272], [-388168, -7038720], [2498154, 3685596], [10541590, -2884320], [-18609902, 347452], [-18596238, 9441252], [4015934, -5139648], [3215424, 2159136], [-103236, 1037640], [-44442584, -3593664], [-44374638, -129168], [-27601132, 7121376], [8687700, 8271072], [47342358, -710136], [-4268570, 5456160], [6949302, 7255464], [-11783370, 12643452], [-9604938, 6496548], [57537974, 2549012], [21288232, -129944], [43084380, -4851360], [52825698, 2274300], [-46978080, 2766576], [-31739534, -3062304], [-46034316, -684504], [-37172052, -7061976], [-45849452, -6555248], [-867436, -6450768], [-59025900, -757728], [4436372, 13222400], [38359918, -8827868], [14343470, 6795648], [12051282, -10027572], [32181494, -12198988], [-892424, -2615720], [-4795644, -6208704], [9104, -930528], [55483050, -555108], [36053518, -9116352], [67279266, -5457564], [-27188602, -10744204], [46665808, 8777808], [13117636, 13939360], [85333026, -2811024], [-108988624, -717336], [-56093796, -8309304], [3217908, -570240], [-12766614, -4087608], [-97659148, 2987360], [15584748, 7679448], [3957494, 8157312], [39357714, -10779864], [50708346, -10485072], [37344800, -9108472], [-10165418, -17225804], [-42846274, 17280864], [-47430584, 12377376], [30192270, -7467120], [-43162218, 10471608], [12217364, -6612928], [-36093650, -3350880], [50354086, -14347340], [-19415448, -18061488], [-14243394, -2581032], [51467874, 10018836], [76433226, -12277668], [-4509812, 1966608], [-56472400, -12321072], [104263986, -12517632], [-55488408, 19317648], [-166108, 14626520], [4111966, 18827136], [-87688154, 3401140], [-52908078, 11026692], [-27075924, -7427592], [99950908, -12143168], [81522056, -17076456], [-30946026, 8755080], [713914, 9808704], [10947826, 14913340], [-1925412, 10461528], [58511970, 17471592], [66624762, -2153196], [-79399808, -9876168], [68749756, 2960680], [46347582, 23987604], [-129644802, 3283200], [1696508, -510424], [55699942, -1914048], [-169973114, 5487220], [-99790866, 10097244], [113437802, 6033600], [-122798712, -9469200], [-9077650, -2619292], [54344340, -1195848], [107778738, -14098056], [44736908, 7674416], [-66572234, 20537856], [109098342, 11828628], [55753622, -406060], [-29675696, 33600744], [41632092, -844128], [23950446, 19625328], [-530544, -37608528], [-48736502, -22759508], [-72670834, 22610304], [-61691364, 32283648], [-40412796, 10934040], [-77893784, -5606784], [-102805044, -14567352], [-165462966, 17222760], [-24405940, -35638432], [50532970, -8737920], [38679590, -38408832], [117601422, -15332436], [36858484, 15436168], [-44622784, -4216896], [83491808, -10409464], [-40373050, 19945728], [59454516, 10249248], [195942852, 2583144], [-152154216, 29389680], [18679706, 18726284], [121394776, 26024256], [17891550, -49012560], [-104169540, -16879968], [-38019436, 33233792], [-54253214, -26339780], [3668394, -31762044], [50518974, -26144700], [-40574460, 62735040], [-178373488, 819360], [-97845710, 51685084], [-104976990, 1701540], [-28942356, 33072576], [109405572, -20356392], [-33619534, 40098524], [-133636664, -13088304], [-11058452, 18585232], [225059624, -27006408], [92603808, -5855040], [36992084, 35200592], [-110530682, -40151232], [158005932, -23039208], [46041858, -14539716], [-76370828, 12963016], [-63463968, -8987328], [-24002238, 2353104], [23166564, -75617760], [-206574856, -14716408], [-149733002, -17294112], [-103039926, 24784164], [-44575332, -32023080], [-4734924, 34375512], [-80819346, -18637776], [67823888, -36824904], [-269501388, -11380776], [-117759240, -15886368], [98433918, 14334264], [273941122, 15619996], [-167135290, 42285888], [79120060, 44797680], [-291964956, -9330720], [-258493144, 15898904], [-30525662, -17094308], [227105222, 11106720], [71017622, -46177900], [203053720, -24779520], [103704700, -56922416], [52032044, 21380112], [-155550364, 17898224], [-274221506, 40104864], [-8837702, -27811028], [60134714, 54292032], [-258894342, -15597720], [37536258, 17617404], [-194212462, 10715516], [-254429112, 11492928], [-51420928, 6491520], [-119532362, 21917332], [132205410, 53457300], [-413942146, 6787872], [195329940, 25435392], [-239951748, -34190856], [34777010, -43659652], [121948100, -8757072], [-233727120, 35236512], [-120453648, 89139744], [436020690, 15562776], [-278991422, 9989568], [-101998622, 26444092], [36785472, 12595392], [78900714, 24596676], [-103582450, 57435428], [85908748, -17471528], [120900858, -51418020], [-370905186, 16823376], [326653400, 46469048], [33907458, -62280252], [356669496, -6949872], [-194891424, -63194208], [40580582, 47457620], [-211733478, 78453288], [-332355670, 37063008], [561309954, -15700284], [-157041452, 5483088], [-216649736, 97174888], [119404992, -87019488], [-213130504, -34493616], [-35661258, 97574724], [288747762, 49122612], [-411877224, -12130992], [246884760, 55120176], [-226463454, -26097984], [34514376, 74840208], [88869588, -31246560], [16532542, -86908124], [76569570, -66200328], [500490122, -24034420], [54138196, -15064704], [244531492, -12562664], [-11512264, -23296176], [-271728834, -71723292], [109912428, -8333856], [218783564, 83897912], [24412882, -98985888], [436454878, 23445892], [470720754, 20567844], [-513598008, 16551024], [24367416, 54297648], [249909504, -87689280], [197594440, -21268080], [-276854442, 30379968], [-231841792, -89729784], [457398804, 4422816], [-502105346, 795744], [78693190, -56889356], [200743122, 34466664], [-34369642, 9877556], [-32525568, 27780192], [-128228272, 10514736], [-342323202, 98959380], [-505965270, -11248848], [-488129376, 14786160], [226595478, -68337972], [245522280, -39337584], [452747174, -51289228], [-396519716, 14451808], [306108320, -3718152], [667311636, -41500392], [-486063936, -27402624], [-108645768, 9439632], [401670906, -61936392], [-636920242, -25787164], [667866340, -53895656], [-395239164, -91191744], [-8240670, 53521452], [505575680, 3605048], [205076958, 11668428], [450281340, 38859336], [-182197306, 157961972], [-332336156, -21160592], [-216022410, 100582560], [39809720, -45989352], [996888, -61409232]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_225_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_225_6_a_i();".
// 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_225_6_a_i(:prec:=2)
    chi := MakeCharacter_225_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_225_6_a_i();".
// 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_225_6_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_225_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-2, 9, 1]>,<7,R![-9900, -108, 1]>],Snew);
    return Vf;
end function;