
// Make newform 363.4.a.l in Magma, downloaded from the LMFDB on 01 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_363_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_363_4_a_l();".
// 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_363_4_a_l();".
// 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 := [-3, 0, 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_363_a();"
function MakeCharacter_363_a()
    N := 363;
    order := 1;
    char_gens := [122, 244];
    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_363_a_Hecke( : Kf := Kf)
    return MakeCharacter_363_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]];
    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, 3], [-3, 0], [9, 0], [0, 14], [0, 0], [0, -41], [0, -51], [0, 84], [90, 0], [0, 51], [-188, 0], [133, 0], [0, -21], [0, 42], [72, 0], [-45, 0], [378, 0], [0, -360], [-386, 0], [-198, 0], [0, -44], [0, 88], [0, -720], [45, 0], [89, 0], [0, -744], [1358, 0], [0, -750], [0, -695], [711, 0], [0, -376], [0, -1506], [2394, 0], [0, -106], [0, 2085], [0, -784], [1306, 0], [2546, 0], [0, 390], [0, 1836], [-2556, 0], [-775, 0], [2628, 0], [0, -1611], [0, 2073], [1618, 0], [0, -1074], [-964, 0], [0, 1650], [-5519, 0], [0, 2085], [0, -1884], [0, -1996], [6714, 0], [1341, 0], [0, -552], [3087, 0], [0, -2330], [0, 2189], [0, 1572], [0, 1870], [0, -2505], [0, 3338], [5220, 0], [-3977, 0], [9918, 0], [8756, 0], [0, -5727], [0, 768], [0, -1641], [-1431, 0], [0, 3114], [3554, 0], [0, 3220], [-13186, 0], [-3330, 0], [3537, 0], [-4501, 0], [3303, 0], [0, 5529], [-6750, 0], [-13481, 0], [0, 798], [-1531, 0], [0, -1108], [14598, 0], [-12591, 0], [0, 9687], [0, 8163], [6902, 0], [15894, 0], [0, -5610], [-7622, 0], [0, 8604], [13006, 0], [0, -8190], [18234, 0], [20502, 0], [0, -6120], [0, 3512], [0, 11188], [0, -8208], [0, -1230], [0, 9960], [0, 5242], [-7427, 0], [-9972, 0], [0, -12657], [576, 0], [0, -4469], [0, -8372], [0, 3059], [6939, 0], [1286, 0], [-15110, 0], [13293, 0], [20528, 0], [-11124, 0], [5562, 0], [0, 9456], [-28385, 0], [0, -4012], [0, -2265], [2034, 0], [4598, 0], [0, -3435], [24814, 0], [26442, 0], [-28370, 0], [0, -11739], [0, 5224], [0, 5634], [-34010, 0], [-5345, 0], [0, -13065], [0, -20185], [29610, 0], [0, -3340], [-4626, 0], [0, 18036], [0, 25600], [0, -22224], [8678, 0], [0, -15726], [-19789, 0], [-1800, 0], [0, 19349], [0, 15408], [46694, 0], [-36018, 0], [0, -5307], [-40005, 0], [4492, 0], [0, 25146], [7634, 0], [-43830, 0], [0, -18782], [15651, 0], [0, -3659], [0, 5685], [-738, 0], [0, -8973], [0, -21762], [-12402, 0], [31203, 0], [-36540, 0], [-56888, 0], [0, 9071], [0, 3727], [35442, 0], [0, -12414], [54170, 0], [0, 16068], [0, 16567], [-37216, 0], [62919, 0], [0, -5620], [-10485, 0], [0, 24530], [0, 7025], [50956, 0], [0, -12192], [59902, 0], [0, -16851], [4644, 0], [-13014, 0], [0, 25533], [-22876, 0], [0, 16187], [0, 30192], [-13166, 0], [0, -12324], [-13448, 0], [-30735, 0], [0, -13830], [-79047, 0], [0, 725], [2438, 0], [0, 19071], [0, -28644], [0, 8568], [0, 4182], [57629, 0], [0, -7975], [-52524, 0], [52794, 0], [-71656, 0], [0, 10566], [0, 49149], [-16676, 0], [0, -42891], [-441, 0], [-8552, 0], [-29646, 0], [0, -29220], [-46025, 0], [0, -5324], [0, -30852], [-19242, 0], [-79533, 0], [0, -20185], [0, 8334], [-58005, 0], [57842, 0], [0, 37248], [0, -61069], [57411, 0], [12168, 0], [0, -3616], [0, -34512], [82727, 0], [0, 10760], [0, 25060], [0, -33609], [-28322, 0], [0, 37686], [35170, 0], [0, 31899], [-28314, 0], [-8856, 0], [-48330, 0], [0, -13456], [-15860, 0], [26755, 0], [0, 17364], [0, -60426], [109720, 0], [6048, 0], [0, -49956], [0, -21102], [0, 38620], [0, -49143], [-77238, 0], [-65789, 0], [0, -33471], [0, 10758], [38555, 0], [0, 20964], [-8955, 0], [0, -27956], [0, 4640], [0, -6426], [0, -24011], [0, 39300], [-90999, 0], [-94742, 0], [-9306, 0], [-7362, 0], [0, -43940], [0, -69888], [12635, 0], [-121768, 0], [50545, 0], [0, 42688], [0, -22244], [-35234, 0], [-59904, 0], [0, -57243], [0, -23260], [0, -24042], [0, -1530], [-32930, 0], [0, 32268], [0, 77813], [0, 47618], [-47592, 0], [45038, 0], [0, -60], [38674, 0], [0, 17019], [-22671, 0], [86112, 0], [0, 57159], [0, 80532], [0, -53064], [0, -28788], [19162, 0], [-72765, 0], [0, 25740], [0, -47932], [0, 54552], [0, 59913], [0, -1426], [154098, 0], [13852, 0], [-169658, 0], [149490, 0], [-96293, 0], [-27738, 0], [0, 22485], [0, -11856], [-71055, 0], [0, -44157], [-34712, 0], [0, -32496], [0, 5429], [62154, 0], [0, -63036], [99730, 0], [0, 53517], [0, -48808], [111565, 0], [0, 579], [-59138, 0], [0, 46701], [-164638, 0], [-121826, 0], [-28718, 0], [0, -51894], [0, 92061], [0, 21223], [-171270, 0], [0, 93982], [0, -101280], [0, -28350], [-52884, 0], [90179, 0], [0, 19116], [69551, 0], [0, -112346], [122363, 0], [-29934, 0], [0, 97731], [181358, 0], [126666, 0], [0, -88260], [79973, 0], [-88444, 0], [0, 42612], [222075, 0], [0, 89530], [-172042, 0], [20979, 0], [0, -70416], [0, 21707], [0, 104667], [194292, 0], [0, 90252], [0, 73143], [70632, 0], [0, -108816], [0, 32460], [93024, 0], [0, -123006], [74734, 0], [-90863, 0], [0, 30321], [0, -116222], [0, -69405], [-112932, 0], [89318, 0], [0, -43044], [0, -94833], [0, 81824], [60031, 0], [15696, 0], [0, -37122], [0, 32465], [0, -37161], [0, 1296], [103878, 0], [165717, 0], [0, 74938], [0, -141696], [0, 117006], [32562, 0], [-7634, 0], [-211465, 0], [0, 3892], [57438, 0], [152846, 0], [122814, 0], [-156870, 0], [86326, 0], [134982, 0], [0, 117028], [0, 56334], [-136107, 0], [59102, 0], [0, 1557], [0, -148341], [10719, 0], [0, -105078], [-77526, 0], [0, -120864], [0, -23736], [51239, 0], [0, 39909], [-88838, 0], [-7830, 0], [0, 59811], [0, -138789], [-2106, 0], [0, 45962], [0, 47927], [-20907, 0], [0, -108246], [9794, 0], [-110610, 0], [0, 23142], [-301833, 0], [0, 71408], [183600, 0], [0, 10674], [-293293, 0], [-50049, 0], [118242, 0], [0, 32304], [-72388, 0], [0, -62226]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_363_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_363_4_a_l();".
// 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_363_4_a_l(:prec:=2)
    chi := MakeCharacter_363_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_363_4_a_l();".
// 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_363_4_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_363_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-27, 0, 1]>,<5,R![-9, 1]>,<7,R![-588, 0, 1]>],Snew);
    return Vf;
end function;