
// Make newform 4.11.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_4_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_4_11_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_4_11_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 := [336, -58, 59, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [161, 78, 4, 2], [154, 492, 8, 4], [3920, -1472, 160, -32]];
    Rf_basisdens := [1, 7, 7, 7];
    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_4_b();"
function MakeCharacter_4_b()
    N := 4;
    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_4_b_Hecke();"
function MakeCharacter_4_b_Hecke(Kf)
    N := 4;
    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 := 11;
    raw_aps := [[-3, 1, 0, 0], [0, -2, 1, 0], [-390, 64, 0, 4], [0, -460, -26, 32], [0, 418, 303, -64], [53066, -7872, 0, -492], [-42846, -2432, 0, -152], [0, -38874, 8685, 1344], [0, -53956, -21918, 6112], [7511658, -311744, 0, -19484], [0, 388624, 49400, -30464], [33602234, 525120, 0, 32820], [-85045038, 1336576, 0, 83536], [0, 2132210, 63367, -141184], [0, 1903192, -388908, -70336], [359392986, 4582720, 0, 286420], [0, -18650662, 2601747, 840448], [853020842, -10302144, 0, -643884], [0, 38524318, -2655439, -2075840], [0, 2756436, 8102742, -1185120], [-747127534, -55984512, 0, -3499032], [0, 15125864, -2386100, -647104], [0, -54031418, -17655267, 5583872], [1318680498, 32133760, 0, 2008360], [3585799874, -47068032, 0, -2941752], [-6582727878, -172852928, 0, -10803308], [0, -32936732, -22323058, 4848928], [0, -176750190, 32730423, 6955584], [-10551782902, 395732544, 0, 24733284], [8753682786, 97592320, 0, 6099520], [0, -457765824, 49702368, 22397568], [0, 1074684734, 81582177, -77365568], [13367469714, 604563712, 0, 37785232], [0, -1041206558, -98747761, 77418880], [-8468121702, 901836352, 0, 56364772], [0, 1036362620, -277614782, -30070816], [89239698794, 688643904, 0, 43040244], [0, 713350926, 530330745, -110875776], [0, -776285692, -680754690, 133612192], [152918888586, 1079990080, 0, 67499380], [0, -4652889546, -109242651, 304460928], [6923246042, -4542238656, 0, -283889916], [0, 2392024672, -68570928, -140930176], [-185328648574, -2842670976, 0, -177666936], [-224672440326, 2482930240, 0, 155183140], [0, 3688094100, -410488266, -179194848], [0, 9320495878, 395054717, -631912832], [0, -1723946896, -3141282872, 500407040], [0, -11514134354, 71294889, 710721536], [-738570667462, 337143360, 0, 21071460], [899659460946, 1783634560, 0, 111477160], [0, 13031730872, 57725604, -821698880], [-203889098398, -2821441920, 0, -176340120], [0, 16357680570, -906488541, -909043968], [-198137988606, -18728474624, 0, -1170529664], [0, -16458673484, -3342319194, 1446456992], [568119003978, 11600710720, 0, 725044420], [0, -9154820664, 6094915356, -189688128], [-258338977126, 24066519360, 0, 1504157460], [691316123442, -12948164480, 0, -809260280], [0, -7083821558, -1858714885, 675078208], [-225655165254, -41710745024, 0, -2606921564], [0, 16547946870, 10170899781, -2305609152], [0, -68940942772, 7965513690, 3313119712], [-659075753614, -57842854656, 0, -3615178416], [572148312234, 55767206464, 0, 3485450404], [0, -9423421246, -22773088865, 3435599936], [54683246114, -174080054784, 0, -10880003424], [0, 55156211882, -4754914389, -2852898944], [520735407338, -117747014592, 0, -7359188412], [3771812269506, 91231607296, 0, 5701975456], [0, -77764210332, -19973251506, 7356919584], [0, -7193878792, -7546816892, 1392969536], [348689736026, 102796839744, 0, 6424802484], [0, 83178781434, 24685399683, -8284348800], [0, 277604910272, -14147523168, -15581866496], [-6791179660422, 85170942784, 0, 5323183924], [-3760457072566, -270447439296, 0, -16902964956], [13103174434722, -93439475072, 0, -5839967192], [-6927113286862, 150691272960, 0, 9418204560], [0, 216431736206, 1960323897, -13772024000], [6999803784122, 140292393024, 0, 8768274564], [0, -209439110376, 57064760436, 5956849344], [-689781770014, 199638764160, 0, 12477422760], [0, -38185525108, 8923390138, 1271171552], [0, -105766266470, -17189087949, 8759027648], [13869985446018, -203359006592, 0, -12709937912], [-24962063321326, 109933236480, 0, 6870827280], [-14961636121398, 53213147200, 0, 3325821700], [0, 132143003176, -15477247252, -6324281792], [0, 47052454278, 104218639677, -15968108352], [0, -530406526736, -63400378488, 41075455232], [0, -201998593116, -127907348178, 28613330592], [0, 553127046482, -36399707817, -30020476928], [0, -233267255210, 140392614869, -2969873408], [0, -28941309012, -192351715542, 25852796256], [-20322777114582, -697314234560, 0, -43582139660], [22509714109842, -248123882240, 0, -15507742640], [0, 754691999394, -89000164689, -36043229376], [8777654434922, -648624711360, 0, -40539044460], [0, -755132534578, 124331842969, 31654303040], [-65010395383926, 871869338944, 0, 54491833684], [0, 806071136246, 203001316869, -75754610624], [58543088419698, 1126414064896, 0, 70400879056], [0, 800550829786, -167067297133, -29151014720], [-2454315531646, -900232748544, 0, -56264546784], [0, -1645085449406, 155271995487, 83408841152], [32295767954466, 1612018226176, 0, 100751139136], [0, 2825877005660, -85422230958, -165939533984], [-2026930877518, 711860216448, 0, 44491263528], [0, -1567403080400, -94490588824, 109774016128], [-63283825655494, 1140571068480, 0, 71285691780], [72758931418194, -1440741080960, 0, -90046317560], [0, -1105800092014, 151913047735, 50123374784], [0, -2846868215316, -129456898038, 194111375712], [-45192678471678, -435826785152, 0, -27239174072], [0, 617069785150, -45765542431, -32846168768], [0, 900180050292, 320537205318, -96328403808], [27642890962506, -3129892749248, 0, -195618296828], [0, -1638242376602, -287037368883, 138269819648], [118364063719322, -630886368192, 0, -39430398012], [-120418707454654, 1778819018880, 0, 111176188680], [-155110642712646, 1861898395456, 0, 116368649716], [0, 688347158322, -335376059289, -1099689984], [0, -4745038780618, 28753909861, 292970685056], [97220619242922, 4644150008128, 0, 290259375508], [-125839898308102, -4212870565056, 0, -263304410316], [0, -3210389125464, 314117702316, 161384607552], [0, 7246056754076, -442104766670, -397615451296], [57600569791466, -1862424513984, 0, -116401532124], [0, 4969318526382, -79607359191, -300631488000], [0, 2342904018980, -469612433682, -87729946976], [0, -454905663560, 833583274532, -75766305344], [100384110769754, -1271205042624, 0, -79450315164], [72323700559602, 5735019955456, 0, 358438747216], [45654736225538, 5607251568768, 0, 350453223048], [-409219830811014, 33524807488, 0, 2095300468], [0, 4736358482854, -40671215059, -290938503296], [135955512171114, -8727948612800, 0, -545496788300], [25022692044498, -6703702434560, 0, -418981402160], [0, 322269487218, 1463631167943, -203095738944], [469522583302362, 871627100992, 0, 54476693812], [0, 540489001804, 1025542818650, -161973414944], [0, -2093326489254, -181866565293, 153566226240], [-51157343104342, 12483531927360, 0, 780220745460], [0, 453133921492, -1862957936490, 204548871968], [412272336679706, 4642457651520, 0, 290153603220], [-453386614196046, 6465650709760, 0, 404103169360], [0, -2224944892502, 640400130347, 59009039488], [0, 9821210103216, -249997641432, -582575926272], [-282737508402166, 9919576368192, 0, 619973523012], [-300094965806238, -8761878291968, 0, -547617393248], [0, 7936667655702, 1742526311157, -713857517376], [0, -471507433876, 3169603972554, -366731281952], [0, -5193441904030, -4053588938033, 831288736256], [0, 12642790526728, -581207291268, -717523496512], [0, -7414441260804, 3074072278146, 79143544032], [-138656639516862, -13523742902144, 0, -845233931384], [-334824652220206, 2043725251200, 0, 127732828200], [188596306366602, -6097999486400, 0, -381124967900], [0, -2111193107018, 1117232667429, -7704514240], [-213024782949774, -651433518848, 0, -40714594928], [0, 6319839442708, -2457314747530, -87825621728], [0, 28556943288066, 619861210239, -1862291606784], [-356781293386206, 21845670086272, 0, 1365354380392], [0, -13618205362148, -2995315453710, 1225552266848], [0, 22604917785072, 842929869576, -1518173595264], [-880551818883526, -4774990209216, 0, -298436888076]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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