
// Make newform 450.6.a.s in Magma, downloaded from the LMFDB on 22 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_450_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_450_6_a_s();".
// 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_450_6_a_s();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_450_a();"
function MakeCharacter_450_a()
    N := 450;
    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_450_a_Hecke(Kf)
    return MakeCharacter_450_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], [0], [0], [4], [500], [288], [1516], [-1344], [-4100], [2646], [-5612], [7288], [18986], [2404], [8900], [39804], [28300], [18290], [-65956], [28800], [30808], [60228], [-2468], [-22678], [36968], [-167918], [154364], [136788], [-53810], [82692], [211780], [-169500], [252036], [192016], [-235694], [-371492], [-264952], [403124], [-261900], [326228], [109516], [-53146], [-232056], [1030672], [-522796], [-215292], [-1030080], [-456020], [-434252], [-722710], [-565348], [-324904], [915262], [-1367076], [892932], [-1866500], [1372266], [458644], [985408], [-165798], [1664708], [2551044], [-736020], [-1716600], [-2838512], [-1276052], [443992], [-2713256], [-1310508], [-298910], [737996], [2340744], [-127292], [-4038696], [1012136], [-2376100], [-1424974], [-1693448], [2845006], [-1890694], [-4609300], [-6041510], [3800], [-250736], [-3588732], [-1414788], [829806], [-4681976], [141930], [-727476], [-4476396], [1327184], [4116468], [6123156], [-7904904], [3976284], [-781914], [-5826938], [9789380], [4760590], [1165948], [-1612932], [3406028], [14400902], [4747720], [10909408], [8532228], [-4631820], [-6275976], [7719878], [6061604], [3664888], [-9325220], [-7401616], [160052], [16956530], [-11012796], [3338484], [-4761812], [-798188], [-15404806], [976704], [19388524], [-5255732], [-5450336], [4439606], [4559178], [20663000], [-5481612], [8555792], [-5291192], [-2364324], [-8796940], [-29580752], [12629622], [-23218578], [-17320068], [-556676], [3005620], [-2231526], [22486216], [16592062], [-14754420], [-3394748], [-509442], [-40060904], [-9675064], [32753532], [-21742024], [20874444], [-39680392], [-26074206], [-41048556], [13755300], [5869356], [-46398192], [22785924], [-27035154], [28614944], [36789242], [7968276], [-48220204], [-48350956], [40551516], [-43492932], [-3348964], [-55572596], [12734184], [-32234338], [-9083724], [54714972], [-12922626], [-49893664], [33602600], [39741076], [62521482], [-7086352], [16514418], [27122668], [2345054], [32763412], [19735612], [14134400], [-64896204], [-1801300], [42283086], [21666928], [7727492], [39504266], [3347224], [13439352], [23066572], [-40587248], [-40115370], [-58641516], [-19684044], [65055150], [-41430624], [32865780], [-81786004], [67467462], [90269388], [45670032], [64324654], [-97333900], [13972020], [-23804340], [59816668], [-28355270], [62624032], [-84550048], [-83848242], [99841196], [108745860], [-57912272], [-42499034], [69189380], [59016526], [-94796236], [94990636], [-2584710], [-16586540], [89439330], [-1984708], [-126696348], [-52841178], [18435316], [-87824600], [-66559420], [-31911748], [-137450032], [-147057080], [-4192156], [-23535798], [-20086892], [55955956], [40495650], [105368996], [83260452], [9111408], [-36194244], [12705320], [-99799268], [148359538], [-53759204], [8473488], [-97821948], [104092716], [91428152], [-73458164], [-103452048], [46951934], [80483252], [104338906], [-57174004], [95117028], [-178476794], [-50684212], [-46381348], [176498048], [96589980], [6872068], [-211393238], [-136436776], [-115834188], [199429544], [79782630], [-52946122], [-45794204], [-23064516], [86732846], [8479580], [-94041064], [-123435740], [208037704], [127952972], [-234165916], [89073698], [81990278], [-110175900], [115146012], [-28030540], [84310148], [195006790], [-26317156], [-266578984], [84390216], [121105532], [-281673172], [-151202386], [38931830], [265623060], [106802604], [226277100], [96367864], [35207082], [-100172244], [-77026668], [89063300], [98193468], [42264800], [241987452], [45254780], [-155560308], [-212486272], [84399256], [120773348], [-12618526], [-181327808], [210813816], [199618332], [77076174], [41604894], [127140708], [-253257932], [-236575354], [147699772], [88417696], [199714120], [233973630], [-187692616], [-81121312], [-77098026], [-401124596], [117230844], [24961742], [321331320], [-306962604], [127502548], [259559764], [-88899758], [-1781204], [92780252], [56464460], [-18892752], [254513796], [-16626674], [-241778532], [-412840586], [-237022220], [-320563224], [-292124452], [-318324382], [280359860], [-93862052], [308784996], [461645178], [314369564], [71600272], [212050692], [387348920], [-26260680], [-215439162], [146546508], [-516257206], [-262987716], [-79617552], [-270531492], [-81701276], [-298134308], [324020920], [60276198], [314948100], [105319700], [324460188], [13785712], [-435181380], [-219386868], [-390901434], [134789764], [347763224], [147094252], [240513378], [-498302340], [488789472], [-11377084], [-368821088], [276903696], [-535904802], [-523094536], [-127016838], [-238803484], [-274144972], [273843308], [-449421192], [615206412], [-242742972], [289752224], [-658874412], [311607556], [-644608558], [18320844], [346998348], [-520593748], [-281579504], [3527032], [23018852], [89867578], [-511672480], [-776785026], [415376014], [-211134620], [-361952092], [404750484], [-193831470], [457086404], [-338979984], [133285806], [-399117436], [591885228], [358912928], [-177413724], [-11401860], [-175579856], [415432648], [-45386374], [-788684464], [786696948], [733596148], [33748236], [54389418], [-419510536], [-258423308], [278122812], [-501365632], [694491972], [-831619204], [120945766], [885270720], [380615624]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_450_6_a_s();".
// 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_450_6_a_s(:prec:=1)
    chi := MakeCharacter_450_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_450_6_a_s();".
// 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_450_6_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![-4, 1]>,<11,R![-500, 1]>,<17,R![-1516, 1]>],Snew);
    return Vf;
end function;