
// Make newform 6.10.a.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6_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_6_10_a_a();".
// 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_6_10_a_a();".
// 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_6_a();"
function MakeCharacter_6_a()
    N := 6;
    order := 1;
    char_gens := [5];
    v := [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_6_a_Hecke(Kf)
    return MakeCharacter_6_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 := 10;
    raw_aps := [[-16], [81], [2694], [-3544], [29580], [-44818], [-101934], [-895084], [-1113000], [-2357346], [175808], [-2919418], [26218794], [-18762964], [-20966160], [57251574], [33587580], [82260830], [-188455804], [80924040], [-236140918], [526909808], [18346452], [690643098], [-438251038], [980602278], [1719087176], [425004588], [874700750], [-44297358], [-3148450720], [-4163281980], [-7365005814], [4511432396], [-1105326186], [10300517048], [-703726018], [11018069156], [1803570600], [-8932502802], [-4286517516], [870114134], [31944486336], [4898414018], [21783554694], [-37416484312], [5740957460], [22157134400], [74612697828], [-64430455930], [-17563505238], [7797589104], [4743425522], [-47237889924], [74701630722], [30798806280], [-149383915506], [132111123824], [-91921881418], [-62124488742], [-146305025188], [96520695654], [-274874263180], [-181294891080], [159020223482], [195485479998], [397197704972], [-259812630574], [-326152200228], [154935582590], [348971728866], [121868134056], [-508451258608], [-256076486314], [-55324968964], [-81477156480], [601212354054], [13106570798], [-598150653486], [-197716061734], [337678091940], [-107358454330], [-692353397520], [-1038846031054], [911780668568], [-788302867908], [-728686696446], [-155747049334], [584721243150], [198254313776], [1909835802324], [-1496028260064], [357916134152], [723262368684], [-616112911564], [-2177492436936], [-265266747906], [-1520018129142], [754029473420], [-2055795289090], [2090224309412], [2242440366318], [-94897588812], [80228190138], [-2640089381380], [-2163060642238], [567860987148], [2170494983250], [2654166008856], [-4551446750182], [-3345527921344], [1755081841862], [3304089932970], [1580346111404], [3141016181912], [377816548290], [978207718916], [-3415480218936], [1274093410638], [-6729312523692], [-6585916816906], [2280848536226], [-166591094106], [6389330011308], [7323497214644], [8915962206654], [10228405976678], [-8588122723440], [6408062928632], [7384248097598], [-1131690306652], [4624444321896], [-3040088919280], [12172698188822], [-14875723662342], [-43467459838], [-6976401059898], [-12856408061164], [18413195895390], [-5678751152214], [-5495225745364], [1568310828918], [-14631506918440], [-306630984708], [-14118421341922], [-6594198569976], [7393734312374], [21656288591322], [1809612284636], [-5097754701216], [23021945449742], [-27808820239374], [25323448926836], [27052988578680], [-31037049699316], [30682660046352], [-14034905897416], [-5444395261086], [-21113875967254], [-17605542902802], [-28182097976844], [-48052738550214], [-41135998185304], [10233055511244], [30136933850898], [-17123480278824], [32609856848384], [-35207129963194]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6_10_a_a();".
// 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_6_10_a_a(:prec:=1)
    chi := MakeCharacter_6_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_6_10_a_a();".
// 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_6_10_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;