
// Make newform 15.12.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_15_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_15_12_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_15_12_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_15_a();"
function MakeCharacter_15_a()
    N := 15;
    order := 1;
    char_gens := [11, 7];
    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_15_a_Hecke(Kf)
    return MakeCharacter_15_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 := 12;
    raw_aps := [[-56], [-243], [3125], [27984], [-112028], [-1096922], [-249566], [-13712420], [41395728], [-4533850], [-265339008], [-212136946], [-1266969958], [14129548], [-2657273336], [2402699278], [7498737220], [-4064828858], [6871514244], [-13283734648], [-28875844262], [27100302240], [-34365255132], [-63500412630], [19634495234], [-121293427458], [132352900928], [19375849404], [232687643510], [319484645218], [-561435481736], [457850197452], [-42073719606], [813652678340], [-156118511890], [550139058472], [-1874889829546], [-2177306962252], [-1180135617936], [499181044278], [3212027565580], [-2932450524178], [2286424007312], [5866168055618], [541588187454], [-6120340986680], [1920540125612], [8972141608328], [10822290696164], [-8418977378850], [-16929734493942], [6998345975440], [-9061645939118], [25929062159892], [8775821425554], [8381568574208], [-32250024017450], [-2891990976848], [9739682305854], [-9369304152918], [47090172181788], [-11185125192642], [48576724547764], [51804972303192], [24567309993098], [-17494183406746], [-68445293034348], [-76993860289646], [129518792018764], [36476284371910], [103350644950098], [-152981747691720], [149106017114184], [-56118546889442], [75741683256340], [20207144566728], [196148007831870], [312645303386854], [-129291609660558], [170213011057610], [74740580490140], [-185677464850178], [-342728390297568], [477828926865298], [-550254703091240], [26077178942748], [-154203049709630], [77654252983834], [659985887284662], [-296907964521672], [-837122616677836], [121855424718720], [94530848390384], [-209823733037308], [-264935570798180], [-364546280054032], [236671059379270], [257733695944922], [-1480294352845172], [-1215286563714138], [-493439890809116], [515727567018294], [286863235997988], [-524421019633110], [-1333232644141468], [1218021327823874], [751064687970684], [-1954009573420222], [2088989061159080], [-2782050055621558], [2483340089569144], [-3545102456845202], [121585237099914], [-1338492091622140], [-2231409210668888], [2539174381647522], [-1402148124930732], [1450239470260624], [674966781552758], [3553340613113740], [4089976062621262], [-231713826360222], [-4214419150696386], [-930313763999892], [-3133092044095508], [-6217871172397018], [-1380760631347970], [-1222192420866960], [-7752128781579616], [8294259617487638], [-408381135077300], [1876022532001888], [9975253684852912], [10929287389303774], [-3390907971722838], [-6405072107567230], [6928651372310718], [-2818687198372556], [3100849164019814], [13295608197638810], [6981271242122772], [6460071570149262], [-4549179373861552], [-3588197149342196], [13598990543251110], [-14962224305650120], [-9312900173632962], [-20108075840233766], [-17863628196615980], [25119414023248808], [10524869428313094], [-21004971736711118], [-15518070027775612], [7611826628871744], [-23910345161110596], [24492253385468032], [-32157517777822760], [-12773908327583710], [1115540237962074], [-39799126405060138], [-32697926982537996], [-2744523613683302], [7813351374887024], [47962273387156452], [42890100994565794], [-19098413403748272], [-7644353011880608], [47289073638574734]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_15_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_15_12_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_15_12_a_a(:prec:=1)
    chi := MakeCharacter_15_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_15_12_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_15_12_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_15_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<2,R![56, 1]>],Snew);
    return Vf;
end function;