
// Make newform 15.4.b.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_15_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_15_b_Hecke();"
// 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_4_b_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_4_b_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
        poly := [100, 0, 21, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 1], [0, 33, 0, 3], [32, 0, 3, 0]];
    Rf_basisdens := [1, 10, 10, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_b();"
function MakeCharacter_15_b()
    N := 15;
    order := 2;
    char_gens := [11, 7];
    v := [2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_15_b_Hecke();"
function MakeCharacter_15_b_Hecke(Kf)
    N := 15;
    order := 2;
    char_gens := [11, 7];
    char_values := [[1, 0, 0, 0], [-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 4;
    raw_aps := [[0, -1, 0, 0], [0, 0, 1, 0], [2, 1, -2, -1], [0, 6, -4, 0], [-22, 0, 0, 2], [0, -6, 16, 0], [0, -10, -12, 0], [-24, 0, 0, -8], [0, 8, -12, 0], [152, 0, 0, 14], [24, 0, 0, 4], [0, -54, -24, 0], [-206, 0, 0, 4], [0, 96, -28, 0], [0, 92, -76, 0], [0, -82, 108, 0], [94, 0, 0, -2], [186, 0, 0, -32], [0, -60, -92, 0], [12, 0, 0, -60], [0, 108, 168, 0], [-240, 0, 0, 100], [0, -208, -60, 0], [-534, 0, 0, -48], [0, 240, 8, 0], [-592, 0, 0, 62], [0, 66, -548, 0], [0, -88, 404, 0], [366, 0, 0, -68], [0, 542, -220, 0], [0, -90, 348, 0], [-1514, 0, 0, 118], [0, 314, 60, 0], [44, 0, 0, -12], [28, 0, 0, 166], [152, 0, 0, 60], [0, -546, 280, 0], [0, -180, -396, 0], [0, -64, 36, 0], [0, -838, 900, 0], [2910, 0, 0, 30], [3354, 0, 0, 4], [-1972, 0, 0, -148], [0, -348, 400, 0], [0, -262, -708, 0], [-3472, 0, 0, 36], [-876, 0, 0, -356], [0, -246, -724, 0], [0, -64, 276, 0], [-126, 0, 0, 268], [0, 506, 1052, 0], [556, 0, 0, 172], [-1962, 0, 0, 232], [-138, 0, 0, -210], [0, -118, -36, 0], [0, 200, -76, 0], [-1944, 0, 0, -558], [2568, 0, 0, 532], [0, 258, -2128, 0], [2750, 0, 0, 56], [0, -996, 1636, 0], [0, -730, 1524, 0], [0, -2088, 1524, 0], [748, 0, 0, 652], [0, 420, -496, 0], [0, 2222, -2076, 0], [-208, 0, 0, -840], [0, -132, 2392, 0], [0, 920, -2092, 0], [3102, 0, 0, 184], [0, 794, -3604, 0], [384, 0, 0, -552], [0, -1722, 1052, 0], [0, 3666, -1448, 0], [-540, 0, 0, -1100], [0, -1900, 1044, 0], [-10156, 0, 0, 398], [0, 1962, -2136, 0], [5686, 0, 0, -692], [3594, 0, 0, 28], [6706, 0, 0, 922], [-5250, 0, 0, -284], [3744, 0, 0, -936], [0, -3420, 144, 0], [-6480, 0, 0, 1060], [0, 584, 2436, 0], [498, 0, 0, 876], [0, -1704, 2216, 0], [5732, 0, 0, 50], [0, -114, 2092, 0], [0, 152, -2316, 0], [15500, 0, 0, -460], [0, 2610, -2772, 0], [-10634, 0, 0, 358], [-12504, 0, 0, 112], [0, 2924, -204, 0], [-6536, 0, 0, -962], [6774, 0, 0, 1284], [0, 3996, -348, 0], [-3166, 0, 0, 1044], [0, -1344, 356, 0], [0, -790, -7372, 0], [0, -808, 1940, 0], [-10054, 0, 0, -148], [-5712, 0, 0, 712], [0, 0, 5088, 0], [0, 1592, 324, 0], [0, 1646, -2988, 0], [12928, 0, 0, -344], [3618, 0, 0, -668], [0, -150, -7652, 0], [0, -5778, 6360, 0], [0, 854, 2340, 0], [6884, 0, 0, -1092], [-3888, 0, 0, -20], [-11086, 0, 0, 1484], [0, -8124, 5572, 0], [0, -6220, 708, 0], [0, 890, 4764, 0], [-1030, 0, 0, -2230], [11402, 0, 0, -1560], [0, 2508, -1312, 0], [0, 5438, -6268, 0], [0, 2960, 564, 0], [9408, 0, 0, 352], [-16344, 0, 0, 18], [20186, 0, 0, -588], [16968, 0, 0, 1056], [0, 2994, 2540, 0], [0, 1326, -2048, 0], [1824, 0, 0, 1768], [0, 5996, -4108, 0], [30528, 0, 0, 412], [0, -3726, -4320, 0], [1390, 0, 0, -3044], [-17682, 0, 0, -1484], [0, 1610, -8436, 0], [0, -2868, 5764, 0], [0, -7498, 3804, 0], [-6210, 0, 0, -900], [-17908, 0, 0, -900], [1760, 0, 0, 2306], [0, 1902, -7220, 0], [0, -2080, 5508, 0], [4790, 0, 0, 900], [17720, 0, 0, -400], [0, -6330, 6344, 0], [0, 10142, -1596, 0], [-34620, 0, 0, 100], [0, -4384, 8772, 0], [0, -5874, -7544, 0], [-17250, 0, 0, 1056], [0, 10836, -10668, 0], [0, 4112, 2004, 0], [0, 6072, -11116, 0], [-18448, 0, 0, 800], [1280, 0, 0, -1260], [4946, 0, 0, 2252], [0, 2808, 3552, 0], [-8516, 0, 0, -2006], [0, 7784, 4980, 0], [0, -5866, 7316, 0], [0, 5070, 6508, 0], [10134, 0, 0, -306], [0, -4210, 10148, 0], [0, -3772, -10572, 0], [-14808, 0, 0, -2660], [0, 3894, -6280, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_15_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_15_4_b_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_4_b_a(:prec:=4)
    chi := MakeCharacter_15_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_b_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_4_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_15_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;