
// Make newform 14.7.b.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_14_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_14_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_14_7_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_14_7_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 := [207, 0, 30, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 18, 0, 2], [0, 34, 0, 2], [60, 0, 4, 0]];
    Rf_basisdens := [1, 3, 1, 3];
    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_14_b();"
function MakeCharacter_14_b()
    N := 14;
    order := 2;
    char_gens := [3];
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_14_b_Hecke();"
function MakeCharacter_14_b_Hecke(Kf)
    N := 14;
    order := 2;
    char_gens := [3];
    char_values := [[-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 := 7;
    raw_aps := [[0, 0, 0, -1], [0, -1, 0, 0], [0, 0, -5, 0], [77, 14, -7, -21], [-1110, 0, 0, -12], [0, 94, 43, 0], [0, 150, -134, 0], [0, -283, 50, 0], [10146, 0, 0, -264], [-4566, 0, 0, 6564], [0, 54, 1038, 0], [-5798, 0, 0, 7668], [0, 1980, -2098, 0], [-11174, 0, 0, 18240], [0, -4014, -986, 0], [62154, 0, 0, -10968], [0, -13485, 6710, 0], [0, 9368, 2945, 0], [-108694, 0, 0, -408], [-112902, 0, 0, -58146], [0, 3494, -11008, 0], [523226, 0, 0, 12690], [0, 16983, -14380, 0], [0, 8430, 8076, 0], [0, -6254, 3562, 0], [0, -39102, 23637, 0], [0, -32698, -32476, 0], [158586, 0, 0, -49608], [1455034, 0, 0, -61680], [734346, 0, 0, -82662], [-24430, 0, 0, 241968], [0, 26475, 91980, 0], [-2011278, 0, 0, -233136], [0, 33131, -25942, 0], [482922, 0, 0, 201264], [-2151326, 0, 0, -388728], [0, -135690, 100599, 0], [-1836358, 0, 0, -606276], [0, -68430, 42304, 0], [0, -175038, 31767, 0], [-4731846, 0, 0, -329052], [0, 174796, 80131, 0], [-1506534, 0, 0, 618618], [7175626, 0, 0, 923778], [3234426, 0, 0, -1479252], [0, -32162, 12004, 0], [4194154, 0, 0, -288384], [0, 72192, 197832, 0], [0, 411525, 238638, 0], [0, -464262, 275181, 0], [-1688718, 0, 0, 543360], [10134354, 0, 0, -1018008], [0, 123062, -200878, 0], [0, 722613, -581720, 0], [0, -956892, 94500, 0], [-19709862, 0, 0, 1156374], [0, -1404906, 314723, 0], [0, 368560, -644564, 0], [16586042, 0, 0, -3860844], [-34542510, 0, 0, 587424], [0, -161571, 427944, 0], [0, 1035114, 239597, 0], [0, -826425, -631572, 0], [0, 1032600, -870974, 0], [0, 134968, 258958, 0], [8507466, 0, 0, 3770604], [32119882, 0, 0, -5361588], [-28358966, 0, 0, 4783194], [-18381702, 0, 0, -1472976], [0, 2637404, -337939, 0], [0, -251088, 1929544, 0], [26555970, 0, 0, 3283704], [0, -1566344, 1335772, 0], [-51116902, 0, 0, -7434180], [33568234, 0, 0, -1006020], [0, -1379166, -64990, 0], [-532038, 0, 0, 5619900], [0, 4312320, -410355, 0], [22912266, 0, 0, -4769478], [0, 913556, -839806, 0], [0, 101331, 1802572, 0], [-31056022, 0, 0, 6540216], [18236850, 0, 0, 13725696], [0, -3876102, 2648070, 0], [0, 2808276, -1303458, 0], [-110244150, 0, 0, 7843860], [-9557790, 0, 0, -16378008], [-9547958, 0, 0, -8253738], [0, -266268, 577217, 0], [129149786, 0, 0, 11103138], [0, -855867, -3765918, 0], [0, 1964910, 1333142, 0], [38093698, 0, 0, -14441784], [-73514502, 0, 0, 26753832], [-2686118, 0, 0, -10728228], [0, 5981052, -4049290, 0], [0, 3882972, 1792565, 0], [0, 4052100, 749006, 0], [0, 274243, -5636126, 0], [80149754, 0, 0, -16235352], [-73802374, 0, 0, -6734772], [-106503942, 0, 0, -5539008], [0, -7155651, 239970, 0], [90207210, 0, 0, 9130518], [156428570, 0, 0, 16157448], [0, 5866148, -2956300, 0], [0, 5250567, 4296726, 0], [0, -6233904, -2259196, 0], [12995322, 0, 0, 9101574], [0, 7163994, 6014712, 0], [0, -3527936, 8357608, 0], [1947050, 0, 0, 2313672], [55335690, 0, 0, -1909242], [0, 6240541, -288764, 0], [-278044774, 0, 0, -26929890], [-163817526, 0, 0, 62035650], [0, -4916247, -6637302, 0], [0, 7170990, -4112700, 0], [241586394, 0, 0, -23065416], [-137209398, 0, 0, -15499032], [0, -10041842, 11755453, 0], [-93788702, 0, 0, -48536664], [0, -7282404, -1151457, 0], [-417349926, 0, 0, 15747792], [0, -1755657, 4630140, 0], [388788858, 0, 0, 5463672], [180895210, 0, 0, 82277496], [0, -16000926, 6433934, 0], [0, 31235178, -9490548, 0], [0, -31349412, 15442701, 0], [103380122, 0, 0, -46302732], [152135682, 0, 0, 77243112], [-254733614, 0, 0, -19952664], [567887434, 0, 0, 15312024], [0, -13347300, -2835934, 0], [0, 1264886, -18350794, 0], [0, 3059712, 6218683, 0], [0, -28868459, 8723938, 0], [0, 2963634, 2721939, 0], [-394420662, 0, 0, -34081914], [0, 13919649, -20330664, 0], [-86545926, 0, 0, -82116204], [526756538, 0, 0, 1275894], [-240931638, 0, 0, -51735228], [0, 19223008, -25445303, 0], [0, -28985658, 2747308, 0], [0, -26378210, -9747203, 0], [0, -21365136, -21221618, 0], [0, -16099811, 17201368, 0], [-412248102, 0, 0, -133334694], [277772042, 0, 0, 84617748], [0, 37183176, -5531964, 0], [-25207094, 0, 0, -99385992], [0, -4463958, 107428, 0], [-1174463318, 0, 0, 5889636], [-219055854, 0, 0, -19590360], [-498870950, 0, 0, 68701614], [0, 5109270, -10721474, 0], [0, 16742042, 25950284, 0], [0, 47691366, -21962821, 0], [845897898, 0, 0, -8548176], [-955778094, 0, 0, -34539120], [160817282, 0, 0, -143351400], [0, 33896991, 13292942, 0], [145553826, 0, 0, -245637984], [0, -4835982, -40763500, 0], [290018266, 0, 0, 277066314], [0, 26397900, 36816735, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_14_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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