
// Make newform 105.4.i.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_105_i();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_105_i_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_105_4_i_d();".
// 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_105_4_i_d();".
// 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 := [7056, -12852, 25257, -1674, 4906, -132, 791, 16, 34, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1484766936324, -154004812416, 299152475424, -454016335892, 48270423888, -4661698144, 4214332012, -373768160, 75909616, 12943327], [-35777128730004, 1959124199760, -3805574935140, 1228852276606, -614057145930, 59302339340, -23328533825, 4754775100, -965660510, 75909616], [-4926976726560, -140436264460887, -2849362756538, -27554247931158, 647207513852, -4542517142681, -104736425072, -198200228510, 12146277730, -5891932287], [2042580337554330, -976894778144850, 799993208735817, -38711293243072, 97601661662829, -12389162294075, 3399331150877, -655311132625, 119035582802, -16488755029], [1698046934032386, 256072942328586, 600194442164529, 59709531979981, 128328781787148, -9429985831651, 4524205545394, -1094116349765, 236260514137, -30058669202], [235019674123164, -461633838622203, 14724535319181, -89018972495962, 2617408475988, -13692815202059, -255208627048, -599833439770, 37501567814, -17494590283], [-1081834742065392, -5106750093747669, -1067899558666308, -1142781356570312, -273866567873244, -217927468728697, -19453355724956, -8344840988516, 132041218924, -279383812109], [-3236223734104032, 12416920116994941, -352867789435002, 2665043905267252, 104683569051882, 401473369686179, 13099894135486, 16408777816366, -729818535632, 477073435099]];
    Rf_basisdens := [1, 1, 2726355561837, 2726355561837, 76337955731436, 114506933597154, 114506933597154, 19084488932859, 229013867194308, 229013867194308];
    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_105_i();"
function MakeCharacter_105_i()
    N := 105;
    order := 3;
    char_gens := [71, 22, 31];
    v := [3, 3, 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_105_i_Hecke();"
function MakeCharacter_105_i_Hecke(Kf)
    N := 105;
    order := 3;
    char_gens := [71, 22, 31];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 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, 1, 0, 0, 1, 0, 0, 0, 0, 0], [-3, 0, 0, 0, -3, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0], [-4, 0, -1, 0, -2, -1, 0, 0, 0, 0], [-7, 4, -4, 0, -7, 1, -1, 1, -1, -1], [22, 0, 5, 4, 0, -2, -1, -1, -1, -1], [-25, -1, 1, 0, -25, 1, 0, 1, 0, -1], [0, 12, 0, 0, 13, 0, 0, -2, 2, -2], [0, -2, 0, 8, 15, 0, 0, 7, 1, -1], [71, 0, 5, 0, 0, 0, 5, -5, -5, -5], [-63, 3, -3, 0, -63, 0, -7, -4, -7, 0], [0, -43, 0, 2, 26, -5, 5, 4, -7, 2], [65, 0, 16, 10, 0, 7, 9, -2, -2, -2], [34, 0, -70, -10, 0, -3, 1, -4, -4, -4], [0, 63, 0, -14, 28, -9, 9, -13, -10, 1], [116, 119, -119, 0, 116, 8, 17, 18, 17, -8], [-163, -75, 75, 0, -163, 7, 4, -35, 4, -7], [0, -2, 0, 42, -38, -10, 10, 36, -4, -6], [360, 24, -24, 0, 360, -17, -7, -39, -7, 17], [-25, 0, 71, 24, 0, 24, -1, 25, 25, 25], [-466, -180, 180, 0, -466, 17, 19, -33, 19, -17], [0, -31, 0, 34, 33, -3, 3, 19, 12, -15], [-93, 0, 65, -70, 0, -6, 3, -9, -9, -9], [0, 91, 0, 12, 225, 13, -13, -6, 31, -18], [-154, 0, 102, -74, 0, -10, 20, -30, -30, -30], [51, 279, -279, 0, 51, -13, 14, -3, 14, 13], [0, -172, 0, 42, 572, 6, -6, 29, 19, -13], [0, 91, 0, 118, 141, 41, -41, 140, 19, 22], [589, 71, -71, 0, 589, 38, 31, -66, 31, -38], [166, 0, 136, 60, 0, -68, 0, -68, -68, -68], [-266, 0, -273, -10, 0, 34, 17, 17, 17, 17], [0, -189, 0, -62, -198, -5, 5, -19, -48, 43], [-621, -243, 243, 0, -621, 17, -30, -19, -30, -17], [-271, 0, 135, 14, 0, 65, 18, 47, 47, 47], [0, 160, 0, 128, 848, 92, -92, 168, 52, 40], [104, 118, -118, 0, 104, 0, -6, 162, -6, 0], [-890, 17, -17, 0, -890, 24, 67, -2, 67, -24], [0, 304, 0, 8, -880, 56, -56, 32, 32, 24], [465, 0, 382, 48, 0, -55, -39, -16, -16, -16], [0, -403, 0, 82, 1272, 33, -33, 119, -4, 37], [-112, 441, -441, 0, -112, -74, 1, -8, 1, 74], [-799, 0, 207, 112, 0, -41, 12, -53, -53, -53], [0, 108, 0, -48, -274, -56, 56, 24, -128, 72], [1318, 572, -572, 0, 1318, 47, -59, 165, -59, -47], [333, 0, -8, -108, 0, -99, -13, -86, -86, -86], [-1060, 32, -32, 0, -1060, -40, -120, -138, -120, 40], [302, 0, 199, 244, 0, -43, -50, 7, 7, 7], [-958, 0, -262, 64, 0, -136, -54, -82, -82, -82], [637, 537, -537, 0, 637, 9, 106, 253, 106, -9], [0, -955, 0, -74, 51, 69, -69, -23, 18, 51], [0, -582, 0, -104, -1644, -66, 66, -228, 58, -124], [1810, 0, 268, -124, 0, 8, -152, 160, 160, 160], [554, 437, -437, 0, 554, 76, 11, -48, 11, -76], [219, 0, 26, -14, 0, 209, 81, 128, 128, 128], [0, 499, 0, 42, 2187, -59, 59, -156, 139, -198], [2170, 142, -142, 0, 2170, -50, 40, -354, 40, 50], [-148, -728, 728, 0, -148, -74, -50, -214, -50, 74], [0, -436, 0, -2, 1252, 164, -164, 94, 68, 96], [1020, -482, 482, 0, 1020, -45, 31, 37, 31, 45], [2106, 0, -1023, -106, 0, 167, 198, -31, -31, -31], [1260, -886, 886, 0, 1260, -35, -59, 105, -59, 35], [-786, 0, 559, -386, 0, 5, 10, -5, -5, -5], [82, 0, 530, 156, 0, 139, -17, 156, 156, 156], [1869, 189, -189, 0, 1869, -51, 74, 571, 74, 51], [0, -66, 0, -4, 5954, -144, 144, -105, -43, -101], [0, 1075, 0, -194, -2107, -43, 43, -156, -81, 38], [0, -390, 0, -170, -6159, -14, 14, -188, 4, -18], [-1244, 0, -668, -6, 0, 311, -23, 334, 334, 334], [-2704, -942, 942, 0, -2704, 60, -42, 424, -42, -60], [-1670, 0, -374, 468, 0, -10, 172, -182, -182, -182], [2043, -1013, 1013, 0, 2043, 103, 114, 311, 114, -103], [0, -409, 0, -4, 5091, -19, 19, 0, -23, 4], [-246, -1531, 1531, 0, -246, -63, -10, -395, -10, 63], [0, -70, 0, -290, -8684, 132, -132, -189, 31, 101], [3943, 0, 522, -258, 0, -60, 166, -226, -226, -226], [0, 1127, 0, 490, -1896, 271, -271, 349, 412, -141], [-1479, -77, 77, 0, -1479, 101, 164, 427, 164, -101], [0, 1242, 0, 36, 5344, -40, 40, 137, -141, 101], [0, 473, 0, 742, -5916, -7, 7, 555, 180, -187], [-5471, 791, -791, 0, -5471, 270, 215, 84, 215, -270], [-1162, 0, 165, 278, 0, -103, -176, 73, 73, 73], [-1925, 0, 2323, -280, 0, 201, 134, 67, 67, 67], [444, -1880, 1880, 0, 444, -14, -98, -2, -98, 14], [-122, 0, 1194, 354, 0, 61, 201, -140, -140, -140], [0, 1066, 0, 366, -1886, -26, 26, 262, 78, -104], [0, 54, 0, -792, 4794, -94, 94, -728, -158, 64], [7708, 0, -1593, -786, 0, -207, 14, -221, -221, -221], [0, -1034, 0, -518, -5432, -108, 108, -499, -127, 19], [1785, 0, 923, -168, 0, 140, 107, 33, 33, 33], [-7596, 0, 733, 118, 0, -232, -87, -145, -145, -145], [0, 726, 0, -60, -1450, 106, -106, 270, -224, 330], [-11148, 182, -182, 0, -11148, 16, -158, -232, -158, -16], [5122, -138, 138, 0, 5122, -47, 177, -125, 177, 47], [4238, 0, -1294, -32, 0, 88, -10, 98, 98, 98], [0, 267, 0, 160, 4471, -121, 121, 215, -176, 55], [80, 0, 2404, -552, 0, -238, 10, -248, -248, -248], [0, 222, 0, -60, 1144, 182, -182, -72, 194, -12], [-6356, -129, 129, 0, -6356, 132, 121, -566, 121, -132], [0, 194, 0, 300, -2408, 516, -516, 639, 177, 339], [0, 1381, 0, -558, -357, 109, -109, -55, -394, 503], [310, 0, 982, 252, 0, -212, -238, 26, 26, 26], [-4872, -511, 511, 0, -4872, 10, -83, -64, -83, -10], [-1386, -728, 728, 0, -1386, 196, -40, -384, -40, -196], [0, 1744, 0, 410, 9579, 30, -30, 313, 127, -97], [3985, -3411, 3411, 0, 3985, -328, -321, -382, -321, 328], [-10088, -1302, 1302, 0, -10088, -359, -391, 389, -391, 359], [7095, 0, 19, -162, 0, 242, 477, -235, -235, -235], [0, -413, 0, -230, 10331, -55, 55, -12, -273, 218], [3358, -3864, 3864, 0, 3358, 110, -482, -66, -482, -110], [3833, 0, -319, -420, 0, 283, -198, 481, 481, 481], [0, -595, 0, 154, 6934, 31, -31, -346, 531, -500], [-4000, 2601, -2601, 0, -4000, -414, -179, 694, -179, 414], [-7764, 0, 356, -708, 0, -138, -242, 104, 104, 104], [-9389, -2596, 2596, 0, -9389, -224, -52, -398, -52, 224], [-6632, 0, -858, 300, 0, -962, -168, -794, -794, -794], [-2517, -4688, 4688, 0, -2517, 169, 35, 681, 35, -169], [804, 0, -406, -36, 0, 159, -525, 684, 684, 684], [3125, 886, -886, 0, 3125, 653, 181, -93, 181, -653], [0, -1900, 0, 240, -5887, -346, 346, 37, -143, -203], [7708, 0, -2148, 64, 0, 528, -72, 600, 600, 600], [5189, 833, -833, 0, 5189, -732, -145, 200, -145, 732], [-6612, 0, 2960, 1802, 0, 569, -429, 998, 998, 998], [0, 284, 0, 280, 4101, 34, -34, 451, -137, 171], [-3387, -651, 651, 0, -3387, -329, 404, 803, 404, 329], [0, -2773, 0, -340, 9187, -5, 5, -163, -182, 177], [3413, 0, -2563, -68, 0, -318, -285, -33, -33, -33], [0, -1030, 0, 906, -7178, 34, -34, 1508, -568, 602], [0, 1366, 0, -1048, 7116, 270, -270, -992, 214, 56], [10976, 0, -2499, -968, 0, -380, 225, -605, -605, -605], [0, 3795, 0, -948, 9620, -131, 131, -736, -343, 212], [-919, -686, 686, 0, -919, 508, -566, 540, -566, -508], [-8945, 0, -2136, -80, 0, 121, 383, -262, -262, -262], [0, 4559, 0, -852, 13753, -537, 537, -1587, 198, -735], [-15014, 0, -1924, 432, 0, 188, 96, 92, 92, 92], [0, 5666, 0, 718, 13929, -264, 264, 83, 371, -635], [4673, 0, -918, 266, 0, 560, 306, 254, 254, 254], [-4323, -1528, 1528, 0, -4323, -211, 723, 271, 723, 211], [1226, -748, 748, 0, 1226, 834, 410, -418, 410, -834], [1529, 0, -3543, -818, 0, -102, -37, -65, -65, -65], [5092, -3263, 3263, 0, 5092, -910, -495, -1144, -495, 910], [7524, 0, -1971, 52, 0, -263, 368, -631, -631, -631], [0, 1625, 0, -1624, 8631, -249, 249, -1852, -21, -228], [4918, -1494, 1494, 0, 4918, 226, -264, -1244, -264, -226], [9928, 0, 4354, -408, 0, 20, 902, -882, -882, -882], [17187, -3341, 3341, 0, 17187, 636, 165, -592, 165, -636], [-18949, 0, -511, -532, 0, -820, -271, -549, -549, -549], [4986, 0, 4207, -1266, 0, -186, 781, -967, -967, -967], [-3781, 1777, -1777, 0, -3781, -451, -406, 2213, -406, 451], [0, -150, 0, -1950, -4178, -258, 258, -2090, -118, -140], [0, -4171, 0, -138, 6614, -403, 403, -125, -416, 13], [0, -495, 0, 774, 4500, 209, -209, 765, 218, -9], [-4802, 0, -3415, 374, 0, -825, -514, -311, -311, -311], [362, 0, -2684, -1254, 0, 193, 319, -126, -126, -126], [0, -5739, 0, -890, -19287, -381, 381, -1044, -227, -154], [11058, 4888, -4888, 0, 11058, 329, 987, -1127, 987, -329], [9517, 0, 2809, 1516, 0, -574, -357, -217, -217, -217], [0, -621, 0, 792, 2875, 619, -619, -159, 1570, -951], [0, 2342, 0, 1006, -7519, 1028, -1028, 1225, 809, 219], [22656, 0, 2684, 92, 0, -303, -253, -50, -50, -50], [3505, 3947, -3947, 0, 3505, 243, -130, 185, -130, -243], [0, -3587, 0, -2162, -7197, -1737, 1737, -3134, -765, -972], [-902, 0, 126, -2796, 0, -332, 118, -450, -450, -450], [-15010, 0, -2258, -750, 0, 71, -93, 164, 164, 164], [0, -297, 0, 162, -4398, -801, 801, -189, -450, -351], [-3127, 851, -851, 0, -3127, -1427, -724, 1673, -724, 1427], [-3609, 1922, -1922, 0, -3609, 569, 481, -45, 481, -569], [-19067, -3445, 3445, 0, -19067, -52, -555, -794, -555, 52], [13572, -622, 622, 0, 13572, -351, -523, 595, -523, 351]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_105_i_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_105_4_i_d();".
// 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_105_4_i_d(:prec:=10)
    chi := MakeCharacter_105_i();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_105_4_i_d();".
// 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_105_4_i_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_105_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![3600, 6240, 15016, -3920, 7632, 1396, 890, 56, 37, 3, 1]>],Snew);
    return Vf;
end function;