
// Make newform 105.4.d.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_105_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_105_d_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_d_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_105_4_d_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 := [18, -36, 36, 6, 2, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-9, 42, -130, 53, 3, -7], [57, -48, 24, 64, -19, 8], [-261, 564, 154, 11, -22, 15], [-186, -2838, -434, -31, 62, -72], [2796, -2802, -452, -79, 158, -78]];
    Rf_basisdens := [1, 327, 327, 327, 327, 327];
    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_d();"
function MakeCharacter_105_d()
    N := 105;
    order := 2;
    char_gens := [71, 22, 31];
    v := [2, 1, 2];
    // 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_d_Hecke();"
function MakeCharacter_105_d_Hecke(Kf)
    N := 105;
    order := 2;
    char_gens := [71, 22, 31];
    char_values := [[1, 0, 0, 0, 0, 0], [-1, 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, 0, 0], [0, 0, 0, -3, 0, 0], [-3, 2, -1, -1, -2, 1], [0, 0, 0, 7, 0, 0], [-26, 0, 4, 0, -4, 4], [0, 4, 0, 36, 1, 1], [0, -8, 0, -50, 5, 5], [44, 0, 8, 0, 1, -1], [0, 22, 0, -52, 1, 1], [-66, 0, 40, 0, 6, -6], [-104, 0, -40, 0, 7, -7], [0, 64, 0, -84, -32, -32], [-34, 0, -18, 0, 43, -43], [0, 120, 0, -4, -12, -12], [0, 32, 0, 52, 50, 50], [0, 132, 0, 144, -27, -27], [332, 0, -108, 0, 4, -4], [-306, 0, 164, 0, 58, -58], [0, -24, 0, -20, -66, -66], [-374, 0, 168, 0, 32, -32], [0, -68, 0, 452, -65, -65], [464, 0, 168, 0, -30, 30], [0, -308, 0, -356, 56, 56], [650, 0, 74, 0, 43, -43], [0, 156, 0, -556, 27, 27], [6, 0, 102, 0, -33, 33], [0, -336, 0, 476, 258, 258], [0, 302, 0, 924, -33, -33], [458, 0, 148, 0, 80, -80], [0, 120, 0, -1032, -129, -129], [0, -312, 0, 472, 342, 342], [-1232, 0, 204, 0, -100, 100], [0, 768, 0, 516, -183, -183], [-528, 0, 692, 0, 133, -133], [426, 0, -212, 0, 36, -36], [-516, 0, 664, 0, -142, 142], [0, 36, 0, -432, 183, 183], [0, -396, 0, 1516, 150, 150], [0, 268, 0, -1732, -302, -302], [0, -132, 0, 510, 429, 429], [-2006, 0, -652, 0, -388, 388], [-230, 0, -32, 0, 116, -116], [1046, 0, -1336, 0, -116, 116], [0, 164, 0, 368, -10, -10], [0, 372, 0, 568, -19, -19], [140, 0, -1076, 0, -439, 439], [-776, 0, -112, 0, -632, 632], [0, 1200, 0, -216, -288, -288], [0, -1104, 0, 1324, 74, 74], [1378, 0, -336, 0, 48, -48], [0, -80, 0, -1932, 369, 369], [2078, 0, -40, 0, -68, 68], [2542, 0, 732, 0, -186, 186], [876, 0, -1500, 0, -432, 432], [0, -352, 0, 3102, -405, -405], [0, -678, 0, -4404, 423, 423], [3834, 0, 1078, 0, 1119, -1119], [1712, 0, 784, 0, 317, -317], [0, 536, 0, 332, -244, -244], [-1322, 0, 828, 0, 854, -854], [0, -936, 0, 3680, 426, 426], [0, 116, 0, -710, -721, -721], [0, -280, 0, 696, -238, -238], [972, 0, -1344, 0, -234, 234], [0, 1988, 0, 328, -1081, -1081], [0, -164, 0, 1736, 1099, 1099], [-1560, 0, 1200, 0, 612, -612], [0, 208, 0, -4312, -308, -308], [0, 14, 0, 7852, -445, -445], [3314, 0, -1956, 0, -18, 18], [0, -408, 0, -1186, 517, 517], [322, 0, 1784, 0, 140, -140], [0, -1040, 0, -6184, 412, 412], [0, -2516, 0, -4564, 304, 304], [3416, 0, -488, 0, -1174, 1174], [0, -480, 0, -4220, -1036, -1036], [7994, 0, 256, 0, -98, 98], [0, 524, 0, -648, -511, -511], [1650, 0, -3036, 0, -186, 186], [-2490, 0, -2716, 0, -746, 746], [3364, 0, -1484, 0, -1126, 1126], [2110, 0, 484, 0, -472, 472], [-2918, 0, 2040, 0, 644, -644], [0, 3356, 0, -1296, -1285, -1285], [-2572, 0, 716, 0, 1153, -1153], [0, 1530, 0, 3692, 613, 613], [-1538, 0, -3256, 0, -16, 16], [0, 1032, 0, 6920, 138, 138], [-15090, 0, -810, 0, -3, 3], [0, -2640, 0, 4728, 2166, 2166], [0, -1576, 0, 8020, 242, 242], [660, 0, 1584, 0, 1530, -1530], [0, 2252, 0, 12952, -532, -532], [-8946, 0, -916, 0, 276, -276], [8944, 0, -736, 0, 226, -226], [0, 4608, 0, 612, -756, -756], [8702, 0, 3218, 0, 553, -553], [6106, 0, 2702, 0, 287, -287], [0, 1144, 0, 76, 904, 904], [4634, 0, 1628, 0, -464, 464], [0, -6112, 0, -6100, 1250, 1250], [0, -2140, 0, 8240, -1649, -1649], [0, 620, 0, 5764, -1054, -1054], [-10386, 0, 3300, 0, -138, 138], [-9028, 0, -1408, 0, -296, 296], [0, -2468, 0, -13968, -575, -575], [0, 2204, 0, -6356, 758, 758], [0, -56, 0, 6634, 2447, 2447], [-5230, 0, -1488, 0, -1580, 1580], [6262, 0, -4104, 0, -2148, 2148], [0, 3200, 0, 7672, 296, 296], [0, 4796, 0, -8404, -1906, -1906], [0, -2744, 0, -4172, 2015, 2015], [7352, 0, -3324, 0, -1635, 1635], [2688, 0, 3488, 0, 502, -502], [17910, 0, -1276, 0, -822, 822], [0, 568, 0, 8400, 1150, 1150], [0, 52, 0, -11804, -1318, -1318], [0, 4100, 0, -5220, -471, -471], [-2434, 0, -2404, 0, -536, 536], [13550, 0, -3220, 0, -1178, 1178], [0, -3236, 0, 6848, -2696, -2696], [0, -2836, 0, -1366, 1975, 1975], [0, -6782, 0, 4788, -1275, -1275], [8528, 0, -3620, 0, -127, 127], [8986, 0, 3560, 0, -622, 622], [-19946, 0, 2232, 0, -624, 624], [-2160, 0, 1560, 0, 2022, -2022], [0, -5560, 0, -8500, 758, 758], [0, -11716, 0, -13372, 1529, 1529], [7868, 0, 4440, 0, 3288, -3288], [0, 5694, 0, 6532, -1939, -1939], [-6092, 0, 6136, 0, 1268, -1268], [0, 5436, 0, -716, 36, 36], [82, 0, -4510, 0, 731, -731], [1074, 0, -1968, 0, -1296, 1296], [0, -884, 0, 6674, -1469, -1469], [0, 7616, 0, 2756, 152, 152], [0, 5332, 0, 21474, 315, 315], [-29598, 0, -3552, 0, 408, -408], [-9128, 0, 4500, 0, -453, 453], [33474, 0, 2948, 0, -60, 60], [0, 3984, 0, 2528, 798, 798], [0, -3530, 0, -3292, 847, 847], [-17138, 0, 5872, 0, 920, -920], [6324, 0, 72, 0, 4740, -4740], [0, 6212, 0, 304, 2423, 2423], [0, -8864, 0, 7598, 2899, 2899], [-36, 0, 7648, 0, -1297, 1297], [0, 4294, 0, -2692, 181, 181], [0, -444, 0, 13708, 666, 666], [2774, 0, 4890, 0, -401, 401], [0, -5684, 0, -22540, 4, 4], [0, 3168, 0, 5500, -2566, -2566], [0, -2700, 0, -21460, 2844, 2844], [-27106, 0, 2168, 0, 652, -652], [19812, 0, -704, 0, 1880, -1880], [15134, 0, -2994, 0, -3239, 3239], [0, 524, 0, 2360, 1007, 1007], [40630, 0, 1978, 0, 467, -467], [0, -3166, 0, -1988, -2755, -2755], [0, 4704, 0, -27936, -3969, -3969], [0, 8812, 0, 16888, 1558, 1558], [-39856, 0, -1148, 0, 1330, -1330], [0, -1944, 0, 18204, 3111, 3111], [0, -780, 0, -4452, -2460, -2460], [-5140, 0, 14704, 0, 4916, -4916], [0, -4332, 0, -10616, 3441, 3441]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_105_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_105_4_d_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_105_4_d_a(:prec:=6)
    chi := MakeCharacter_105_d();
    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_d_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_105_4_d_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_105_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![1, 0, 171, 0, 27, 0, 1]>],Snew);
    return Vf;
end function;