
// Make newform 1815.4.a.s in Magma, downloaded from the LMFDB on 07 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1815_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_1815_4_a_s();".
// 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_1815_4_a_s();".
// 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 := [26, -20, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-14, 1, 1]];
    Rf_basisdens := [1, 1, 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_1815_a();"
function MakeCharacter_1815_a()
    N := 1815;
    order := 1;
    char_gens := [1211, 727, 1696];
    v := [1, 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_1815_a_Hecke( : Kf := Kf)
    return MakeCharacter_1815_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 := [[1, 1, 0], [-3, 0, 0], [-5, 0, 0], [2, -2, 2], [0, 0, 0], [4, -12, -2], [76, -10, -6], [-48, -2, -4], [-60, -20, -8], [-34, 34, -20], [-24, 4, -16], [-122, -24, -4], [66, -2, 20], [150, 74, -14], [-36, 48, 28], [-42, -32, 52], [-308, -120, -4], [-218, 12, 44], [-128, 148, -28], [-216, 104, -16], [-356, 168, -14], [524, 14, 52], [582, -164, -70], [-730, 68, 0], [286, -240, 64], [82, -174, -88], [-728, -224, 40], [326, -188, 162], [-214, 40, -144], [-458, 20, -240], [-562, 78, -218], [-96, -312, 76], [-762, 336, 72], [1900, 62, 64], [-270, 358, 136], [324, 238, 140], [-950, 336, 108], [-2188, 128, -128], [846, -460, -218], [496, -610, 186], [2252, -16, 84], [130, 40, 16], [368, -744, -116], [-3716, -44, 18], [-1376, 654, 298], [1384, 128, -300], [1960, 814, -124], [700, -356, -180], [1442, 84, 38], [3350, -180, -28], [296, -926, 478], [-1164, 964, -180], [-2046, 380, 28], [-4164, -168, -168], [1234, 164, 300], [498, 1548, -318], [-1578, 456, 184], [1084, -1438, -124], [1100, 36, -50], [-1998, 78, 500], [1430, 858, 98], [2100, 1250, -66], [-530, -306, 194], [2000, 1912, -524], [-758, -1232, 348], [410, -716, 568], [-3068, 24, 160], [-6396, -48, 498], [318, -92, 794], [-1114, 788, -308], [290, -968, 660], [-6132, -928, 500], [-4548, 100, -148], [-8176, -224, -150], [-3764, 2236, 612], [-10504, 52, -164], [830, -740, -416], [602, 544, 528], [222, 1952, 720], [-10314, 132, -336], [644, -2136, 556], [2010, 1224, 648], [2328, -1812, -1040], [-3314, 880, -1352], [328, 1402, 584], [4476, 668, 276], [4422, 1100, -312], [-6208, -2160, 486], [5114, 662, 56], [6764, 2260, -788], [-1896, -1140, -1144], [-4740, -2868, 372], [-124, 620, 1276], [3924, -860, 856], [-5708, 536, -220], [1302, 1732, 270], [2342, 2328, 56], [-4442, 80, -184], [8954, -3462, -986], [3402, -1496, 1112], [-4718, 170, -1994], [11520, 194, 330], [5538, -4224, 446], [-9106, 2834, -1192], [-5580, 2754, -336], [-3034, 576, -324], [2016, -4260, 1240], [-636, 4082, -1526], [2712, -48, 976], [14434, -1920, -1140], [1214, 78, 2374], [18288, -2512, 202], [-5586, -4324, 392], [-15692, 1008, -224], [-192, -5552, 1076], [30, 2788, -2104], [-17772, -1480, 616], [-10400, 4, 1204], [-738, -124, -1740], [6324, -3192, 1752], [1846, -3128, -408], [-14756, 196, 1586], [5108, -2730, -802], [2088, 3704, -1308], [-4756, -7068, 772], [12094, -3050, 28], [13010, 5244, -1388], [7560, 1944, -476], [-6328, 3272, 952], [-4424, 6500, -998], [-5828, -1454, -1048], [-1102, 4416, 1370], [21920, -688, -956], [3290, -6848, 2068], [-17490, 1202, 1360], [-17038, 2312, -2972], [-10186, 3348, -476], [-7514, -110, 890], [26234, -1828, 1536], [-2070, 1362, -660], [12364, -4138, 1144], [16374, -3630, -500], [-5216, 248, -1784], [-20514, 4044, -2062], [5610, -2900, 1436], [9304, -1248, 3004], [2904, 4576, -1702], [8316, -906, 818], [14900, 4520, -1032], [18576, -4052, -1884], [-2904, -5864, 3290], [234, 2052, 1184], [-13748, 1432, 3432], [-31778, -96, -418], [-17520, 908, 844], [23664, 1232, 268], [56, -1382, -736], [-15246, 5092, -2256], [-26976, -2580, 2382], [1506, -4390, 1944], [-7376, 5912, -4212], [-1768, -2114, -2370], [-19226, -954, -42], [25220, -152, 336], [-47210, 1560, -1016], [13224, 10172, -468], [8016, 2924, 2968], [-32960, -4512, -342], [4538, -1228, -132], [-31554, 888, -372], [-13108, 2808, -16], [-3670, -7692, -140], [436, 3184, -4772], [-2792, -8424, -1058], [-18008, -1664, -4024], [8466, -2780, -2048], [-1780, -3758, 2000], [-17890, 8392, 3648], [8670, 3334, 1886], [-7878, 8980, 1256], [10112, 5128, 264], [30772, 1792, -1464], [-5366, 7680, -2388], [9688, 8894, 1718], [22404, 13728, -1924], [-14574, 1772, -1712], [-42232, 5308, -2214], [-456, -12300, 3180], [16534, -236, 976], [-20640, -7732, -528], [-4674, -12072, 4740], [-49170, 5556, 1330], [3740, 1040, 2236], [-322, 1660, 2080], [20258, -7488, 694], [-27774, 3484, -3548], [32010, 64, -2260], [-25314, 6368, -5144], [19352, -10290, 3094], [-18318, 6872, -62], [-138, 5614, 1924], [-26176, 3662, 1336], [1550, -8136, -2856], [-15990, 3020, 1900], [-30012, 648, -3092], [27426, -10556, -2088], [-14224, 8316, 1396], [-11310, 6368, 2758], [11394, 14826, -1580], [10028, 5732, 4016], [8784, -4956, -1674], [-37358, 1084, 2368], [-2968, 88, 7768], [-16200, 10460, 4888], [-15612, -1320, 308], [-24206, -9340, -684], [-40790, 2674, 1826], [49486, 6982, -1088], [10632, -6288, -3576], [9590, -4820, -7980], [-12346, 9304, -6212], [41356, -11306, 2716], [-54262, -1980, 448], [-31192, 17120, 1192], [81366, -3944, 370], [46322, -28, -320], [-31362, -11576, 984], [-57008, 344, 1860], [-21570, -10790, 3950], [-37944, 6012, -292], [-14006, -9344, -448], [53964, 4126, -3856], [-27992, 1518, -4016], [38442, -1182, -5900], [-44576, -13196, 4620], [22370, -560, -326], [-37594, 3656, 4696], [15660, 8562, -7138], [-3572, 8248, -3168], [9760, 9800, -6640], [9948, -4508, 2828], [37544, -9006, -468], [28432, -9848, 5192], [-6830, -1960, 248], [-10784, 9914, -3370], [-35636, -3448, 2364], [-62308, -6468, -2788], [7308, 6240, 5328], [58436, -4198, 6040], [-31438, -3488, 298], [-21116, -16188, -1034], [-44050, 2454, 2576], [7056, 3048, 4904], [50802, 11332, 572], [-60416, 9458, 2778], [1220, -3020, -2216], [-17342, 9660, -9156], [-4094, -12250, -6754], [12242, 25316, -4608], [-30664, 15668, 1406], [-58462, 4442, -2422], [28218, 6360, 1926], [-55682, -1280, -5620], [-64540, -10440, 2006], [-61550, -7896, 2036], [-66308, 7704, 1436], [9610, 22700, -4176], [-18998, -24012, 7096], [23342, -6570, -1030], [-27756, 5790, 926], [-10306, -12324, 1908], [-81096, 12916, 1748], [12270, -21352, -4988], [-7712, 22978, -3280], [-48768, -12272, -3130], [-7564, -15844, 956], [-54248, -1880, -2556], [-53586, 15068, 3892], [-30902, -26584, 4924], [39936, 22288, -3884], [-9982, 7468, 6442], [-16864, -16372, 5680], [4050, 3104, -4934], [18586, 10636, -8896], [51202, 1506, 6270], [3248, -22160, -1800], [41654, -13664, -4816], [-71148, 10534, 4454], [58680, -4252, 9664], [14014, -11458, 8048], [-6034, -7028, 3960], [-42388, 9276, 9596], [-29776, -1982, -14210], [-15144, 17448, 7044], [-73516, -14136, 2262], [-44430, -4138, 560], [29616, -10224, 4092], [-65490, -5420, 6868], [60780, -8252, -2960], [-26954, -12162, 330], [21208, 1756, -66], [-55920, -21870, 2922], [44104, -15858, -6320], [-27552, -3284, 656], [33004, -9796, -8600], [56410, -29728, -10660], [-55808, 7048, 9756], [-57378, 3184, -136], [28080, 12496, -6144], [1832, -22696, -5366], [71086, 1884, -2674], [13174, -3028, 5576], [23310, -14906, 8544], [-4448, 18340, -6972], [-12354, 22788, -5266], [134602, 4268, -404], [40652, -29792, -8816], [-39908, 6400, -8244], [105470, -384, 4428], [21870, -4718, -13384], [39328, -5834, 4476], [-47074, 1680, 6260], [24510, 27462, 5172], [-1380, -7908, 5412], [-24504, -174, 4814], [-55370, 5712, 7800], [-43180, 11388, -18960], [53996, -24688, 3760], [162090, 4876, 1482], [-64304, 9830, 3338], [98462, -22896, -2748], [54498, 5752, -12712], [-8796, -3578, 3548], [14322, -14748, -3570], [-3784, -11046, -11668], [33596, 3116, 1020], [55214, -2756, -13036], [-11296, -17550, 13582], [-39074, 20576, -12072], [11378, -130, -15878], [-74094, 11432, -10088], [54474, 9352, 10348], [-6102, -6770, 1344], [40104, -10680, -7152], [-129282, 6612, 4972], [-3872, -12908, -13028], [-52050, 10416, -2304], [-13924, -3008, -8872], [45560, -8384, -14336], [58630, -4452, -8660], [7700, 29166, -3272], [25642, 648, 9888], [94410, 12636, -4296], [50558, 78, 10614], [76622, -8500, 10828], [45588, -20634, -2694], [14952, -33048, 3736], [16208, 204, 4340], [8160, 17318, -7242], [21128, 8384, -11344], [-18180, 3664, -1066], [38782, 19070, 8888], [-72332, 5964, -12040], [58136, 9836, 4692], [37276, -36576, -7080], [17942, -28920, 2364], [-73632, -6198, 9562], [14162, 32686, 5026], [147818, -4088, -7764], [-52332, 12656, 6884], [-106060, -20400, 10392], [58786, -32864, -16070], [-66126, -23854, 6120], [48608, -9686, -8688], [33186, -1560, -3300], [4788, -5040, -3452], [59636, -44244, -2404], [-71224, 2156, -14650], [-8002, 7594, -9408], [-102760, 13904, 16126], [-2090, 43452, -9280], [-7902, -1812, 9452], [142694, 5358, 3702], [-1956, -14466, -14462], [33648, -11390, -1684], [-39120, -27656, 13184], [144760, -9096, 8188], [-76782, -15528, -8640], [90186, -11470, -3866], [25512, 22640, 5232], [11006, 51196, -16500], [84198, -17328, 23068], [-49572, 29472, 8832], [-140520, -2820, 10668], [48528, -34584, -8516], [-112688, 18312, -10122], [43600, -19642, -15824], [101418, -34040, -16704], [-14836, 23548, 9828], [-122578, 26098, 2116], [87938, 44292, -11328], [-140634, 16404, -19760], [-78310, -38346, 9906], [22410, 45732, -1260], [116274, 4134, -4176], [-58628, 1710, -8580], [87802, -36792, -6992], [-66306, -10290, 2056], [-60080, 43692, -6540], [22492, 13048, 20968], [-113640, -7220, 3350], [67620, -29142, -1946], [147932, -10536, 6032], [-17860, 14850, 15424], [-16556, -7392, -10358], [8826, -6416, 14752], [169776, 14676, -8704], [34616, -22368, 7056], [-49494, -25008, -7572], [117286, -16724, 13966], [3586, 412, 17424], [54804, -26024, -2074], [-22088, 2496, 3256], [-55344, -9276, -12124], [215762, -11856, 5760], [4134, 34036, -5476], [23108, -8864, -15944], [54246, -3618, 15368], [97500, -8172, -14844], [33020, -10100, 30564]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1815_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1815_4_a_s();".
// 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_1815_4_a_s(:prec:=3)
    chi := MakeCharacter_1815_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_1815_4_a_s();".
// 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_1815_4_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1815_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![44, -15, -4, 1]>,<7,R![3744, -428, -4, 1]>],Snew);
    return Vf;
end function;