
// Make newform 15.6.a.c in Magma, downloaded from the LMFDB on 23 May 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_6_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_6_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 := [-102, -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 := 6;
    raw_aps := [[0, -1], [-9, 0], [25, 0], [-64, 16], [108, 32], [446, -16], [978, 80], [836, -208], [-1632, 48], [942, 64], [1424, -176], [3926, 816], [-4086, 544], [-8188, -64], [-10296, 1232], [-6042, -2272], [1164, -3232], [9326, 1568], [-5812, -1280], [-18888, -3200], [29258, 608], [51920, 3760], [-63060, 4032], [48186, 7392], [-6142, -12480], [34518, -5568], [-36208, -9264], [-106956, 3552], [-40354, -2688], [-8430, 2192], [-13672, -22000], [-96924, 4608], [202890, 4464], [176444, -14832], [-295002, 10816], [175592, 35600], [-393490, -14256], [534044, -12480], [545856, -12624], [14430, -38208], [55140, -58240], [-330586, 29184], [-300432, -15488], [205730, -48288], [-499338, 35808], [54728, 16016], [328724, -65136], [303656, 41904], [325356, 84736], [-622186, -56672], [193482, 33456], [-950064, 8672], [884018, 40832], [-1078308, 16320], [1142754, -79728], [-462576, 15760], [-955074, 114752], [-233632, -42928], [-1538938, 36688], [2301690, 10656], [860276, 5824], [-393546, 4320], [988604, 63392], [-741432, 101472], [653594, 220320], [-598386, -71648], [-3413908, -4400], [-2125678, -3232], [1238628, -227680], [-154258, -26656], [-126654, 60144], [-1505016, 104448], [-675928, 353008], [-1910938, -99184], [195020, -13840], [2046984, -122160], [-373866, -287232], [-1185346, 203312], [1416786, 406848], [1783034, 173568], [3530196, 132352], [-772810, -43744], [294624, -222336], [1871954, -364960], [2873720, -414640], [2240436, 292224], [-4843902, -74944], [25706, -151744], [3540702, -307200], [-1723048, 13456], [-1068036, 59872], [6096000, -168960], [1126208, -309840], [-2415924, -204512], [795236, 292112], [410016, -243056], [-246066, 439808], [-3577686, 65344], [696932, 413216], [3293294, 817024], [1411436, -1020544], [-1915362, -397440], [10567500, 182112], [-6189414, 248832], [790748, 500112], [1241858, -155520], [-1821516, -306528], [567282, -628784], [2458008, -137984], [6483578, -747648], [-6157192, 460400], [9743030, -541648], [6889290, -161616], [-6268036, 127248], [-13262968, -366160], [2032194, 1572384], [5718332, -126464], [-10787232, 942320], [-379746, 526720], [4102020, -947680], [-4050778, 1478240], [609218, -141152], [-2935338, 1319808], [-1160316, -522720], [10087508, 163472], [5752686, -1858112], [9759926, -60448], [4087728, 37536], [-4558000, 190704], [-8686738, 179856], [10822004, -1748272], [-5436528, 244976], [15132128, -1050928], [2199590, 1414544], [-2040870, -732864], [1761218, 649536], [420534, -2339040], [13589564, 702752], [13018734, 1225792], [10663050, 2112160], [19557932, 875920], [-5866170, 2270976], [-12099520, 2164752], [-28257852, -374080], [27278510, 94720], [7473480, -1864640], [9499814, -536720], [4463514, -3116848], [18118220, 997040], [19323912, 544816], [-3900994, -2675504], [-6680910, 1309856], [10407692, 479616], [-22095696, -1703568], [8342324, 2358112], [42912, 2711840], [-3285640, 1232720], [-15646494, -2964608], [-15950038, 1554688], [-6959106, 1858624], [-9367620, 1888224], [-23339334, 2822384], [-28398592, -337680], [-4024116, 276864], [29196498, 453200], [32914848, -507792], [25128272, 3408240], [-10267210, -352496]];
    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_6_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_6_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, 6));
    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_6_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_6_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_15_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-102, 1, 1]>],Snew);
    return Vf;
end function;