
// Make newform 15.12.a.c in Magma, downloaded from the LMFDB on 20 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_c();".
// 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_c();".
// 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 := [-450, -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_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 := [[-6, -1], [-243, 0], [-3125, 0], [5684, -3584], [163272, -30976], [292778, 71936], [4250934, 78080], [8879780, -131584], [-14134872, -1571328], [-103051950, 4221952], [-32308408, -6440192], [346513754, 12830976], [-154634358, -18386432], [1598048348, -3544576], [1022573064, 7918592], [-1208121822, 111944192], [-619281480, -240207616], [-4074042658, -116806144], [11999581244, 213015040], [-10521135648, 823383040], [13394501138, -909419008], [10842173240, 640648960], [23726037468, 562434048], [38776245570, 1657191936], [-18582564766, 89902080], [-105698413158, 2425227264], [-25627143772, 1226179584], [-75213083196, -4144946688], [18401871710, 2396491776], [81004512318, 5822605568], [71001048764, 2155258880], [112171300152, 16028142336], [-566926701306, -621947136], [23191473140, 30924670464], [-397296581790, 13101242368], [827480296472, -26784628480], [-690967420246, 4956466944], [1058484628748, 73646254080], [650733906264, -107344779264], [-246721469622, -85793943552], [-936589849920, 47143865600], [395471424422, 101532423168], [501481853112, -128322192896], [2940584298218, 8090208768], [3775180927554, -4336922112], [-1596762233080, -27914874112], [-4254192680788, -304592174592], [9948448750028, -2481398784], [-814714038636, 287489399296], [6277945251950, -188971245056], [-6221377734642, -625791580416], [-8527909584360, 440279998976], [-401565484318, 645039970304], [4336208149392, -1249525006080], [6515559407454, -17716547328], [-32771993712792, 10755374080], [2691752015250, 1565685518336], [-12880315192048, 1455694648064], [-7286979747046, -1059777274112], [45505463632482, 177018419712], [9326701189988, -680411400704], [19975544229858, 1317052147200], [-60130094633836, -309192506368], [63174403876992, 436015593984], [28457819502098, 1580910328320], [-34940277933846, -325666247168], [15614448256652, 5558222248960], [2208521060954, 4475388174848], [6290673496764, 3377556861440], [24877603765310, -2219313822208], [-1229222684202, -3258759508224], [39826116541080, -1360852179456], [162818006490284, -2748812989952], [-22033814628142, 7007920327424], [-111350291143660, 2240830561280], [80012321872728, 1210809008640], [-155456531032830, 3739702401024], [-96893648743246, -2378494720768], [-198024170108358, 4877124811776], [-146749785089590, 5267099787264], [34554496764840, -9038565734144], [-5781587121778, -5003910005248], [106355189398032, -244194104832], [-115568796157702, 10930786956800], [201399958198760, 3883048313600], [170406214551948, 14369483521536], [252567908246970, 20001097161728], [-283538248786966, 3167440756736], [-387375165248838, 3004195768320], [64574103448628, 1084233301504], [148316294649564, 10977895724032], [-779628958160280, 8817399828480], [418070137545884, -1884583772160], [207115312411392, -11245990340864], [458373573510020, -8577168845824], [636633192999168, 30959343379456], [399270031311570, 46966294744064], [11727678519522, -24276006413312], [1178754598516628, -1095727277056], [-1499538828789538, 18897344263168], [527482230194084, 18827160766976], [-777081640033206, 19747160878080], [-892324071536412, 81555387452928], [-35758718618910, -5039034537984], [-1736125041005668, -12110522305536], [-94742622664126, 817549962240], [960898401090084, -3445157242368], [714161037324078, 10049444349184], [472375579222680, 31797456905728], [-1611448901390758, -46934026070016], [1649829411696644, -68756564569600], [-49772175016102, -72783313629952], [3023354078225214, 24275856178944], [1022574717758660, -83912906374656], [-136328539591888, 21854117262080], [2175842664925122, 27895474856448], [1601330139309068, -137222083337216], [-2642494267127376, -86309140096000], [-3748954404734742, -42698649082880], [1252351977369240, -170325712764160], [-775074508291738, -10753353879040], [-161351461558822, 152053052396032], [2557072543095714, -199561500828672], [-6003758207582892, 58127012951040], [5181415170148292, -126127817575936], [5345182161533682, -66012198800384], [-5773511265236770, -80667996527104], [167069797748640, 168214378449408], [-1781498701209316, -247319090820096], [-1569319427306062, 221068686852864], [-5564717809859500, -67942535981056], [-1646573417691312, 157201009908224], [-4429485503713288, -116978526167296], [-3949767043757926, -328196142413056], [4939541591186562, -179548466439168], [-6309712388701630, 57317122556928], [-3486986121088782, -268624629404160], [-3997863177397156, 571656644298752], [4118927022714714, 420076875830272], [-2213190043181190, -23411320286720], [6438745405732772, 290268833136640], [-8596426359668838, 533579156462592], [6748502516199548, 296962870499328], [-11158964565212196, 141829792870400], [-8543149806383890, -32399158077440], [2789756320739880, -160789391352320], [3562079677630538, 35317897150720], [11637649111657134, 585008277677312], [13506317984220020, 53945306240000], [1498696934818608, 1165326813558784], [1945727956950794, 523282751362816], [-18604589713733718, -16053743676928], [2968120764426188, -279426258564096], [-6236487483194856, -712293746654208], [7282288134731804, -664737188069888], [26294848697032032, -200447765862400], [-4093577263371760, 18503266430720], [27430851202874490, 53085624395776], [15444408123201674, 174644576386048], [-9339371859574038, -786685216704512], [-26740995198155196, 343118990905344], [30245472725983398, -712419144358144], [-10567422521570476, 206016466176000], [19622063011623552, 394835450750208], [-22563417768659706, 187279581221120], [7791513837202128, -1379118935152128], [29897243128617392, -1014015752405760], [-24929750013373966, 863906066124544]];
    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_c();".
// 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_c(:prec:=2)
    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_c();".
// 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_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_15_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<2,R![-408, 13, 1]>],Snew);
    return Vf;
end function;