
// Make newform 1350.4.c.x in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1350_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1350_c_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_1350_4_c_x();".
// 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_1350_4_c_x();".
// 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 := [2704, 0, 105, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 53, 0, 1], [0, 209, 0, 1], [158, 0, 3, 0]];
    Rf_basisdens := [1, 52, 52, 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_1350_c();"
function MakeCharacter_1350_c()
    N := 1350;
    order := 2;
    char_gens := [1001, 1027];
    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_1350_c_Hecke();"
function MakeCharacter_1350_c_Hecke(Kf)
    N := 1350;
    order := 2;
    char_gens := [1001, 1027];
    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, 2, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -7, -1, 0], [-8, 0, 0, -2], [0, 4, 1, 0], [0, 2, -2, 0], [-22, 0, 0, 1], [0, -68, -4, 0], [16, 0, 0, -2], [73, 0, 0, 2], [0, 121, 12, 0], [-12, 0, 0, -6], [0, 7, -14, 0], [0, 154, -10, 0], [0, -430, -14, 0], [-8, 0, 0, -8], [320, 0, 0, -27], [0, 622, 15, 0], [60, 0, 0, 36], [0, 701, 12, 0], [259, 0, 0, 0], [0, -2, 62, 0], [-780, 0, 0, 24], [0, 525, -23, 0], [-1148, 0, 0, -14], [0, 755, 12, 0], [0, 932, 40, 0], [-309, 0, 0, -4], [0, 364, -16, 0], [0, 88, -36, 0], [-1012, 0, 0, -10], [0, 1014, -54, 0], [109, 0, 0, 48], [-1260, 0, 0, 18], [1394, 0, 0, 39], [0, 509, 20, 0], [0, 1542, -85, 0], [0, 3794, 10, 0], [0, -1732, -104, 0], [-3092, 0, 0, -8], [-2057, 0, 0, -115], [-3652, 0, 0, 38], [0, 1853, 105, 0], [0, 1366, -118, 0], [1005, 0, 0, 53], [-945, 0, 0, 115], [0, -3141, -58, 0], [0, 2496, 72, 0], [2099, 0, 0, -152], [0, -1902, 114, 0], [-2632, 0, 0, -94], [-2165, 0, 0, -43], [-1460, 0, 0, 70], [0, 6062, -38, 0], [0, -5026, -62, 0], [-1564, 0, 0, -160], [-3631, 0, 0, 192], [0, 1563, -128, 0], [-3524, 0, 0, 202], [0, -195, -178, 0], [0, 1908, 228, 0], [0, -1013, 294, 0], [7112, 0, 0, 110], [0, -5808, -25, 0], [0, 478, 350, 0], [-1165, 0, 0, -420], [0, 1212, 139, 0], [0, 2928, -168, 0], [4741, 0, 0, -360], [0, -6408, -204, 0], [4436, 0, 0, 158], [0, 4654, 249, 0], [0, -267, 125, 0], [-577, 0, 0, -521], [0, 4042, -334, 0], [4192, 0, 0, 58], [0, -3459, 16, 0], [12468, 0, 0, -72], [3845, 0, 0, 391], [-4952, 0, 0, 400], [1853, 0, 0, 456], [-2340, 0, 0, 18], [0, 6139, -224, 0], [8863, 0, 0, 402], [0, 2380, 560, 0], [6464, 0, 0, -154], [0, 1822, -132, 0], [-9540, 0, 0, 156], [0, 5243, -48, 0], [0, -7008, 72, 0], [1900, 0, 0, -668], [0, -3214, -751, 0], [17584, 0, 0, -98], [-2579, 0, 0, -258], [0, 898, -910, 0], [-6876, 0, 0, -348], [2580, 0, 0, 732], [0, 12941, 231, 0], [1848, 0, 0, -353], [0, 14065, 468, 0], [0, -6846, 594, 0], [0, 13532, 256, 0], [9524, 0, 0, -64], [3126, 0, 0, -533], [0, 691, 663, 0], [0, -19278, 174, 0], [0, 5972, 520, 0], [1836, 0, 0, -624], [-1761, 0, 0, 292], [0, 5965, -576, 0], [0, -3661, 324, 0], [0, 1752, 624, 0], [-10910, 0, 0, -159], [20773, 0, 0, -127], [-8652, 0, 0, 12], [0, 4532, -300, 0], [0, -15040, -596, 0], [0, 7468, -808, 0], [17140, 0, 0, 610], [-1561, 0, 0, 480], [0, 791, -996, 0], [0, -21862, -350, 0], [0, -6758, 134, 0], [80, 0, 0, -948], [10192, 0, 0, -1028], [-5824, 0, 0, 265], [-5352, 0, 0, -498], [0, 10105, -618, 0], [0, -11722, -300, 0], [3664, 0, 0, -744], [0, 17412, 456, 0], [4517, 0, 0, 96], [0, -13379, 405, 0], [6128, 0, 0, -1030], [5739, 0, 0, 269], [0, -4766, 242, 0], [0, 9271, 1173, 0], [0, 2572, -1768, 0], [-14220, 0, 0, -312], [16795, 0, 0, 254], [-5180, 0, 0, 226], [0, 9238, 1585, 0], [0, -1526, 878, 0], [30775, 0, 0, 60], [7644, 0, 0, -420], [0, 3512, -1341, 0], [0, 4468, 1448, 0], [-21095, 0, 0, -1248], [0, 2458, 722, 0], [0, 15323, 1067, 0], [-3912, 0, 0, -330], [0, -18273, -787, 0], [0, 10622, -338, 0], [0, -15881, 768, 0], [-20364, 0, 0, 1410], [-4919, 0, 0, -978], [-20000, 0, 0, -644], [0, -44485, 359, 0], [-11152, 0, 0, 146], [0, -3734, -538, 0], [0, -10202, -598, 0], [0, 22459, -960, 0], [-8992, 0, 0, 356], [0, 33492, 576, 0], [0, 11938, -202, 0], [41438, 0, 0, -75], [0, -40970, -324, 0], [15388, 0, 0, 1533], [0, 7462, 74, 0], [-20912, 0, 0, -416], [-29953, 0, 0, 396], [-25532, 0, 0, 244], [0, -11033, 1627, 0], [-25923, 0, 0, 1457], [-1544, 0, 0, -704], [10375, 0, 0, 242], [-39640, 0, 0, 914], [0, -14294, -191, 0], [-10719, 0, 0, -1684], [0, 3138, -941, 0], [-1480, 0, 0, -586], [0, -30931, 1356, 0], [0, 25304, -548, 0], [0, -27152, -328, 0], [-30908, 0, 0, -446], [0, -39908, -1485, 0], [0, 8382, -1273, 0], [-26884, 0, 0, 553], [14620, 0, 0, -1448], [0, 6927, 2075, 0], [0, -22970, 326, 0], [48426, 0, 0, -1259], [-28944, 0, 0, -2196], [0, 45600, -252, 0], [0, -22330, -446, 0], [-17101, 0, 0, -1128], [0, -9727, 792, 0], [0, 5924, -980, 0], [0, -21202, -914, 0], [-38720, 0, 0, 1828], [57809, 0, 0, 144], [0, 35719, 1224, 0], [-32813, 0, 0, -600], [-22320, 0, 0, -606], [0, 32378, 1174, 0], [9086, 0, 0, 1189], [0, -49138, -530, 0], [-7380, 0, 0, -2154], [3265, 0, 0, -247], [0, -36840, 949, 0], [9772, 0, 0, 3154], [0, -6046, -1647, 0], [0, 57714, -714, 0], [-7396, 0, 0, -850], [-29521, 0, 0, -2460], [0, 24257, 410, 0], [31328, 0, 0, 1202], [0, 31796, -248, 0], [0, -43152, 1488, 0], [11728, 0, 0, 311], [-66467, 0, 0, 1086], [-4120, 0, 0, -2242], [0, 83840, 348, 0], [0, -60204, -516, 0], [-15657, 0, 0, 2525], [0, 19908, 2016, 0], [34524, 0, 0, -882], [0, -17442, -2303, 0], [70988, 0, 0, 980], [0, -18077, 2371, 0], [-51104, 0, 0, 108], [34575, 0, 0, -1370], [-77500, 0, 0, 686], [0, -32605, 1692, 0], [0, -10456, 676, 0], [-2333, 0, 0, -2772], [0, 11520, -948, 0], [-8448, 0, 0, -3876], [3488, 0, 0, -1432], [0, 45230, -3050, 0], [44453, 0, 0, -1575], [0, 35945, -633, 0], [11731, 0, 0, -2415], [0, -20422, -1478, 0], [-18000, 0, 0, 4086], [0, 59139, 1069, 0], [-70220, 0, 0, 28], [-34633, 0, 0, 2950], [0, 30656, 2752, 0], [0, -64694, -1044, 0], [2920, 0, 0, -1544], [0, -43874, 590, 0], [25321, 0, 0, -921], [0, 31348, -2788, 0], [23452, 0, 0, -1502], [-85312, 0, 0, -1761], [0, 77668, 1260, 0], [0, -40684, 748, 0], [0, -59774, 2100, 0], [0, -76953, -1111, 0], [0, -35598, -2058, 0], [25459, 0, 0, -1440], [0, 54565, -1547, 0], [0, -103114, 982, 0], [40216, 0, 0, -1884], [22804, 0, 0, -1472], [55968, 0, 0, -30], [0, 48872, -1296, 0], [0, 3468, 1500, 0], [-80856, 0, 0, 841], [0, -98363, 180, 0], [0, -33082, 3600, 0], [5527, 0, 0, 939], [0, 52095, -1664, 0], [0, 22631, 1449, 0], [0, -54892, -1028, 0], [59453, 0, 0, 1492], [-32849, 0, 0, 1532], [63760, 0, 0, 850], [0, 6952, 740, 0], [-72124, 0, 0, -612], [0, 15274, 4766, 0], [-64939, 0, 0, 975], [0, 778, -5055, 0], [2816, 0, 0, -226], [0, 26992, 229, 0], [0, -95612, -1108, 0], [54397, 0, 0, -3444], [58520, 0, 0, -58], [106740, 0, 0, -2352], [0, -118912, -620, 0], [0, -72256, 184, 0], [-100, 0, 0, 2996], [0, -1333, 3600, 0], [140236, 0, 0, 112], [-15218, 0, 0, -1255], [0, -3990, -378, 0], [-24756, 0, 0, -3612], [0, -26441, -5700, 0], [0, -114229, -384, 0], [0, 27520, 3824, 0], [-33585, 0, 0, -2590]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1350_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1350_4_c_x();".
// 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_1350_4_c_x(:prec:=4)
    chi := MakeCharacter_1350_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_1350_4_c_x();".
// 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_1350_4_c_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![183184, 0, 1025, 0, 1]>,<11,R![-1800, 18, 1]>],Snew);
    return Vf;
end function;