
// Make newform 60.6.d.a in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_60_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_60_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_60_6_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_60_6_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 := [186624, 0, 33732, 0, 373, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, -114516, 0, -805, 0, -1], [15445728, 3092220, 497016, 31979, 1944, 95], [-15312240, 264636, -497016, -27149, -1944, -89], [34892208, 4506012, -217728, 61543, -2592, 187], [2574288, -3347604, 82836, -45151, 324, -139]];
    Rf_basisdens := [1, 29664, 266976, 133488, 133488, 44496];
    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_60_d();"
function MakeCharacter_60_d()
    N := 60;
    order := 2;
    char_gens := [31, 41, 37];
    v := [2, 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_60_d_Hecke();"
function MakeCharacter_60_d_Hecke(Kf)
    N := 60;
    order := 2;
    char_gens := [31, 41, 37];
    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 := 6;
    raw_aps := [[0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [-6, -1, -1, 0, 0, 0], [0, -3, 1, 0, 0, -1], [48, 1, 1, 0, 2, 1], [3, -1, -3, -3, 0, -3], [7, -35, -9, -7, 0, -5], [-998, 0, -12, 2, 4, 0], [2, -36, 12, -2, 0, -16], [-2661, 3, 21, -3, 0, 3], [78, -18, -78, 10, -16, -18], [-21, -425, 61, 21, 0, -19], [2696, 10, 94, -14, -8, 10], [-72, 996, 80, 72, 0, 64], [-46, -1414, -54, 46, 0, 146], [15, 413, 15, -15, 0, -45], [15328, 31, 271, -40, -18, 31], [1098, 0, -336, 56, 112, 0], [-48, -4622, 206, 48, 0, -110], [-26852, 18, 186, -28, -20, 18], [150, 1594, 62, -150, 0, -362], [21582, -18, -414, 66, 96, -18], [92, 4564, -408, -92, 0, 224], [12686, 32, -280, 52, 168, 32], [84, -12376, -424, -84, 0, 256], [-18941, -13, -475, 77, 128, -13], [-324, 6927, 427, 324, 0, 221], [-276, -11928, 108, 276, 0, 444], [-38572, 198, 1818, -270, -144, 198], [-357, 5545, -69, 357, 0, 783], [-36, -12771, -263, 36, 0, 335], [-156044, -21, 3, -4, -50, -21], [-951, -1437, 2169, 951, 0, -267], [-86106, 198, 834, -106, 184, 198], [23427, 7, -1199, 201, 416, 7], [37866, 306, -258, 94, 800, 306], [1209, 8093, -2785, -1209, 0, 367], [1488, 8030, -1622, -1488, 0, -1354], [1962, 10480, -4416, -1962, 0, 492], [397, -31865, 1341, -397, 0, -2135], [250452, 655, -281, 156, 1622, 655], [250540, 666, 2838, -362, 608, 666], [-583256, 1038, 4734, -616, 844, 1038], [-2130, -40930, 1754, 2130, 0, 2506], [-679, 70063, 2805, 679, 0, -1447], [41926, -1458, -9678, 1370, -176, -1458], [255346, -2142, -11082, 1490, -1304, -2142], [-2784, 40795, 6191, 2784, 0, -623], [-452, 50844, -2208, 452, 0, 3112], [-130984, 270, -1182, 242, 1024, 270], [-1559, -50173, -2247, 1559, 0, 5365], [459304, 2510, 15998, -2248, 524, 2510], [365194, -1836, -2484, 108, -3456, -1836], [-903812, -1185, -4905, 620, -1130, -1185], [-111, 60947, -327, 111, 0, 549], [1778, 56796, -8340, -1778, 0, 4784], [-20187, -291, -16437, 2691, 4800, -291], [960218, -594, -11766, 1862, 2536, -594], [4107, 27899, 5929, -4107, 0, -14143], [-1537998, 876, -348, 204, 2160, 876], [-1488, 85078, 5458, 1488, 0, -2482], [5775, -145599, -3141, -5775, 0, -8409], [1272, -83656, -15372, -1272, 0, 12828], [-966472, 1902, 18942, -2840, -1876, 1902], [2406, -91234, -13174, -2406, 0, 8362], [7627, -11451, -11865, -7627, 0, -3389], [1687090, 2880, 24372, -3582, -1404, 2880], [-1530, -117822, -5930, 1530, 0, 8990], [-6984, -233480, 3828, 6984, 0, 10140], [483826, 3276, 21396, -3020, 512, 3276], [-10271, -89237, 18945, 10271, 0, 1597], [1341548, -7068, -41076, 5668, -2800, -7068], [-5652, -331779, 16633, 5652, 0, -5329], [8679, -127357, -20367, -8679, 0, 3009], [855450, 6462, 36498, -5006, 2912, 6462], [5626, 233086, -14850, -5626, 0, 3598], [1472919, 1931, 4253, -387, 3088, 1931], [9207, -111369, -17195, -9207, 0, -1219], [-1120864, 8510, 49130, -6770, 3480, 8510], [-596128, -2754, -12990, 1706, -2096, -2754], [-2606404, 4877, 25733, -3476, 2802, 4877], [1164968, 2970, -18138, 3518, 12976, 2970], [-639492, -4316, -55508, 8532, 8432, -4316], [-17250, -102370, 50234, 17250, 0, -15734], [793110, 2574, -19566, 3690, 12528, 2574], [16140, 282824, -28452, -16140, 0, -3828], [-1072544, -10314, -50646, 6722, -7184, -10314], [-7008, -109708, 37564, 7008, 0, -23548], [1820425, 1821, 40059, -6373, -9104, 1821], [8100, 242601, 17349, -8100, 0, -33549], [264, -69192, 41364, -264, 0, -41892], [317092, 13802, 53570, -6628, 14348, 13802], [-9276, 237815, -2733, 9276, 0, 21285], [1659760, 4995, 44979, -6664, -3338, 4995], [-1523242, 6660, 26688, -3338, 6644, 6660], [-31314, 149770, 49170, 31314, 0, 13458], [2559803, 14379, 124317, -18323, -7888, 14379], [5397856, -9838, -47218, 6230, -7216, -9838], [-2592, -125226, -6350, 2592, 0, 11534], [-2025156, -10926, -62754, 8638, -4576, -10926], [12528, 277284, -11360, -12528, 0, -13696], [-21363, 846703, 38613, 21363, 0, 4113], [1816, -165224, 21492, -1816, 0, -25124], [25764, 15518, 21674, -1026, 28984, 15518], [-241926, 18360, 126876, -18086, 548, 18360], [15360, 434848, -7424, -15360, 0, -23296], [-32532, 833744, 44196, 32532, 0, 20868], [32283, 9249, 5283, -32283, 0, -69849], [-1853036, 5916, 53748, -7972, -4112, 5916], [-7607796, -1854, -15618, 2294, 880, -1854], [29880, 341931, -23617, -29880, 0, -36143], [-291, -118187, -28225, 291, 0, 28807], [52927, -290635, -28977, -52927, 0, -76877], [2084190, 10170, 150726, -23426, -26512, 10170], [-5177590, 954, 13014, -2010, -2112, 954], [2708408, -2186, -50342, 8026, 11680, -2186], [-10128, -305390, -51954, 10128, 0, 72210], [-38538, 757750, 12414, 38538, 0, 64662], [-4519, -528137, 67965, 4519, 0, -58927], [-8524712, 4093, -39587, 7280, 22746, 4093], [-905250, 1332, 61404, -10012, -17360, 1332], [27858, 27146, 20094, -27858, 0, -75810], [-3533, 846645, -5529, 3533, 0, 12595], [-66040, 12540, 68664, 66040, 0, 63416], [-2479422, 30276, 199848, -28262, 4028, 30276], [-302563, -35267, -127397, 15355, -39824, -35267], [3101700, 5490, 77886, -12066, -13152, 5490], [-18388540, -4216, -14176, 1660, -5112, -4216], [-75492, 412023, 60099, 75492, 0, 90885], [-5787, 500133, -17273, 5787, 0, 28847], [915718, 12096, 129180, -19514, -14836, 12096], [12318, -52406, -55374, -12318, 0, 30738], [-6796650, -10278, -187122, 29474, 38392, -10278], [-16077, -912941, 54913, 16077, 0, -22759], [2365820, 33006, 77730, -7454, 51104, 33006], [-14151640, -17910, -45402, 4582, -26656, -17910], [-14343, 754887, -57699, 14343, 0, 86385], [56040, -388706, -71798, -56040, 0, -40282], [-47597, -596127, -27381, 47597, 0, 122575], [18581724, 28158, 33234, -846, 54624, 28158], [-6191430, -45054, -106602, 10258, -69592, -45054], [1228405, 6317, -40693, 7835, 28304, 6317], [-95352, -584695, 283341, 95352, 0, -92637], [63256, -633404, -128880, -63256, 0, 2368], [4720288, -26118, -96474, 11726, -28784, -26118], [-9056684, 11056, 256168, -40852, -59592, 11056], [-74727, 924009, 8539, 74727, 0, 140915], [9915, -3514143, -15885, -9915, 0, -3945], [9354778, 36918, 7146, 4962, 83760, 36918], [104670, -537320, -107088, -104670, 0, -102252], [-67527, 267573, 188327, 67527, 0, -53273], [-2518158, -23880, 125088, -24828, -97416, -23880], [98760, -604150, -160218, -98760, 0, -37302], [-48438, 69912, 187128, 48438, 0, -90252], [-71712, -516456, -114396, 71712, 0, 257820], [3167296, 67056, 299280, -38704, 56704, 67056], [-5879782, -74610, -390246, 52606, -44008, -74610], [18923384, -65034, -245094, 30010, -70048, -65034], [-99516, -1163516, 95180, 99516, 0, 103852], [-4061171, -5975, 6991, -2161, -16272, -5975], [113580, 197992, -158676, -113580, 0, -68484], [-38681, 85701, 175839, 38681, 0, -98477], [20568, 983945, -31987, -20568, 0, -9149], [-1836516, 19839, 137271, -19572, 534, 19839], [-79533, 486833, -24717, 79533, 0, 183783], [-23234, -1618354, -155850, 23234, 0, 202318], [-4150442, 10314, -47538, 9642, 39912, 10314], [51105, 2583569, -150525, -51105, 0, 48315]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_60_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_60_6_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_60_6_d_a(:prec:=6)
    chi := MakeCharacter_60_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_60_6_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_60_6_d_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_60_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;