
// Make newform 720.6.a.h in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_720_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_720_6_a_h();".
// 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_720_6_a_h();".
// 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_720_a();"
function MakeCharacter_720_a()
    N := 720;
    order := 1;
    char_gens := [271, 181, 641, 577];
    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_720_a_Hecke(Kf)
    return MakeCharacter_720_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], [-25], [108], [-604], [-306], [-930], [1324], [-852], [-5902], [3320], [10774], [17958], [-9264], [-9796], [31434], [33228], [-40210], [-58864], [-55312], [27258], [-31456], [24552], [90854], [154706], [72714], [129396], [-206680], [-70146], [151854], [336596], [275308], [228502], [-224284], [183802], [-296032], [134766], [60248], [-62012], [591682], [-241404], [187622], [37560], [164434], [-360518], [654168], [693156], [-494756], [907088], [1089494], [-499706], [1620384], [1001218], [368980], [-279010], [811740], [-353214], [1716216], [-245882], [1676182], [1258816], [-719158], [-1860128], [278384], [-474182], [1837378], [-2997428], [1875314], [180312], [-87058], [-2659010], [-2149368], [3082580], [2287270], [1301540], [-2032764], [-94230], [-5555506], [784814], [-4594006], [1413012], [5945558], [-6481144], [4055970], [1214504], [-5531536], [-2201106], [3298346], [3942658], [-8820404], [-1287088], [6511792], [5795228], [990276], [-2914996], [2478716], [6758066], [6339030], [-231920], [-9444402], [-3101616], [1223298], [-14089592], [-1484682], [2864700], [4217282], [-2010472], [-7336914], [1148840], [11640938], [155540], [-11813690], [-6422522], [-3852524], [6751360], [7354926], [-15969448], [17266692], [1362514], [-8818076], [-1520346], [-315086], [1740922], [-19893488], [-20151916], [-8107662], [-13561258], [4283136], [-11208388], [4705486], [23109868], [5752940], [19242376], [4492102], [-7335002], [-5855262], [-13455750], [-10070608], [11884418], [-10605258], [1389436], [11266138], [27709332], [12366168], [12318190], [-11727656], [15705878], [-25239002], [-3662476], [-41793772], [10898974], [30433630], [-6090280], [27790788], [-37151032], [-7859592], [16269304], [36936462], [4897050], [6839426], [10379040], [-25958746], [39211980], [-10687596], [-27726562], [-9492724], [20324312], [47050758], [52843474], [47814186], [-1450340], [27458830], [17824896], [45657050], [8170896], [65960806], [39374588], [-496342], [47134276], [52606174], [6508228], [-14592532], [-38621018], [308166], [-53677244], [14042010], [7825006], [-24374216], [-44525062], [72833480], [-74192318], [-70328064], [69312756], [-18100174], [-34669248], [-2272858], [83716130], [-77310274], [70432894], [-18891540], [22774082], [-32544296], [-68415818], [23223138], [-90746916], [20724754], [-31947328], [100731240], [7102710], [75814892], [-84217982], [115062138], [116370484], [53184712], [-21200520], [-47642022], [-61113788], [-81130130], [-26973036], [-106477950], [16387766], [759800], [-87903970], [42266396], [95428208], [102795750], [-89299434], [-82057344], [-141714004], [-38189100], [-20751346], [-22103540], [124381000], [14778278], [-93439136], [-12761508], [77675810], [-3815030], [-57676900], [-3989888], [-54278008], [-29233684], [85233844], [141404894], [-104564402], [-80731176], [109889108], [20604348], [-130162300], [-111504076], [-158780418], [-125007810], [164099460], [-196613222], [119363458], [120977460], [57464870], [19339240], [-70266454], [183459034], [-149241076], [-175146768], [20312182], [125366862], [169750062], [156144668], [-90245310], [-70633050], [104219536], [-40507254], [-15476514], [9376112], [-118878998], [15645536], [245303602], [-118685276], [-63849912], [50002670], [57928666], [42864252], [142929300], [197719840], [-133566972], [32001014], [75994280], [155283832], [5243682], [-177520566], [-187806120], [116559310], [-226463294], [-174815312], [154387254], [131905284], [-12674242], [-52934382], [268716728], [-104241222], [344524764], [190620992], [153420586], [-132658974], [120966336], [21755160], [204245612], [-137165582], [191228888], [-151707874], [149612856], [-165001162], [-308450316], [311624954], [25669406], [-5119192], [-182448124], [-64154646], [41793684], [-388308568], [18867490], [-221453026], [47621076], [243057978], [-120336526], [-148605668], [-2008362], [-49806782], [-197537060], [256186640], [169403180], [314280186], [142969214], [449023698], [357628336], [89425176], [-82864804], [87861144], [325555310], [423647454], [315947130], [86951220], [25584518], [-51335770], [-312155958], [-290042160], [249611730], [433055972], [-374860042], [-36159336], [-270674952], [345265802], [-132173196], [-325016182], [270363650], [-228119108], [-327656186], [-33011402], [-61130736], [374480436], [362445694], [54094684], [-17143514], [64369878], [-379705236], [-304882772], [-542933024], [115525914], [-113735374], [-261546556], [445126410], [-545549012], [-288895340], [-311438764], [-145615334], [-529417408], [466234046], [-148895724], [-250032216], [522408098], [-238451202], [143560058], [34945970], [623336630], [-262343492], [-147219682], [668315932], [263010268], [455422072], [202152230], [83476144], [455475436], [-445210030], [129890186], [42323324], [-131578384], [149221760], [-156293318], [-485838928], [249704502], [72306396], [509742330], [277677646], [577251790], [204499508], [-683763066], [385408074], [-170625872], [508833358], [584712846], [-650518664], [558904916], [-560451470], [-258485638], [-66312256], [411361460], [63346266], [-53800670], [662898624], [-452394820], [-36761986], [-362385572], [-3357454], [72126342], [135964828], [-34420692], [427481194], [263284194], [653558104], [189028502], [161402332], [-545979112]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_720_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_720_6_a_h();".
// 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_720_6_a_h(:prec:=1)
    chi := MakeCharacter_720_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_720_6_a_h();".
// 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_720_6_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_720_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![-108, 1]>,<11,R![604, 1]>],Snew);
    return Vf;
end function;