
// Make newform 1400.4.g.l in Magma, downloaded from the LMFDB on 13 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1400_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1400_g_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_1400_4_g_l();".
// 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_1400_4_g_l();".
// 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 := [1600, 0, 1041, 0, 63, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 239, 0, -23, 0, -1], [43, 0, -58, 0, -2, 0], [0, 321, 0, 43, 0, 1], [106, 0, 35, 0, 1, 0], [0, 5053, 0, 539, 0, 13]];
    Rf_basisdens := [1, 360, 9, 60, 9, 360];
    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_1400_g();"
function MakeCharacter_1400_g()
    N := 1400;
    order := 2;
    char_gens := [351, 701, 1177, 801];
    v := [2, 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_1400_g_Hecke();"
function MakeCharacter_1400_g_Hecke(Kf)
    N := 1400;
    order := 2;
    char_gens := [351, 701, 1177, 801];
    char_values := [[1, 0, 0, 0, 0, 0], [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]];
    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, 0, 0, 0, 0, 0], [0, 2, 0, -1, 0, 0], [0, 0, 0, 0, 0, 0], [0, 7, 0, 0, 0, 0], [-1, 0, -3, 0, -1, 0], [0, -2, 0, 7, 0, -2], [0, -16, 0, -5, 0, -4], [53, 0, -7, 0, -12, 0], [0, 17, 0, 20, 0, -3], [153, 0, 9, 0, -13, 0], [-91, 0, 5, 0, 10, 0], [0, 83, 0, -22, 0, 13], [-29, 0, 13, 0, 12, 0], [0, 227, 0, 24, 0, 11], [0, -256, 0, 25, 0, -6], [0, -16, 0, -22, 0, -14], [364, 0, -4, 0, -40, 0], [69, 0, -33, 0, -68, 0], [0, 64, 0, 64, 0, 20], [-360, 0, 24, 0, -96, 0], [0, 60, 0, -92, 0, 14], [-137, 0, 49, 0, 67, 0], [0, 558, 0, 40, 0, 22], [-27, 0, -77, 0, 12, 0], [0, 552, 0, 207, 0, -36], [-339, 0, 51, 0, 78, 0], [0, -484, 0, 147, 0, 2], [0, 868, 0, 82, 0, 36], [-371, 0, -7, 0, -135, 0], [0, -553, 0, -30, 0, 65], [0, -212, 0, 208, 0, -108], [295, 0, -61, 0, 252, 0], [0, 1355, 0, 372, 0, -51], [798, 0, -22, 0, -202, 0], [2144, 0, 38, 0, -104, 0], [839, 0, 93, 0, -103, 0], [0, 54, 0, -12, 0, 76], [0, 150, 0, 478, 0, -66], [0, 728, 0, -19, 0, 114], [0, 1120, 0, -131, 0, 132], [-344, 0, 164, 0, 224, 0], [-972, 0, -90, 0, -430, 0], [-299, 0, 79, 0, 271, 0], [0, -1247, 0, -652, 0, -9], [0, -917, 0, 188, 0, 81], [946, 0, -46, 0, 364, 0], [-2313, 0, 145, 0, -139, 0], [0, 1354, 0, -57, 0, 192], [0, -544, 0, -319, 0, 2], [2813, 0, 27, 0, 84, 0], [0, 1612, 0, -142, 0, 18], [2809, 0, -157, 0, -277, 0], [-331, 0, 51, 0, -66, 0], [-590, 0, 62, 0, -466, 0], [0, 356, 0, -392, 0, -142], [0, -102, 0, -178, 0, 38], [7416, 0, -22, 0, 108, 0], [-527, 0, -79, 0, -306, 0], [0, 4496, 0, -28, 0, -134], [-1751, 0, -339, 0, 601, 0], [0, 5004, 0, -23, 0, -170], [0, 3096, 0, 1001, 0, -124], [0, 540, 0, -641, 0, -38], [-1161, 0, -45, 0, -1076, 0], [0, -3898, 0, 83, 0, -154], [0, -868, 0, 204, 0, 174], [984, 0, -148, 0, -280, 0], [0, 7466, 0, -556, 0, -160], [0, 2017, 0, 632, 0, -23], [3385, 0, -101, 0, 1370, 0], [0, -5346, 0, 237, 0, 370], [-1580, 0, 44, 0, -1576, 0], [0, -1260, 0, -1055, 0, 38], [0, -4773, 0, 868, 0, 493], [-2844, 0, 544, 0, 912, 0], [0, 3674, 0, -1032, 0, -262], [3305, 0, -331, 0, 69, 0], [0, 1058, 0, 111, 0, 574], [5441, 0, 225, 0, -917, 0], [-368, 0, 58, 0, -1624, 0], [476, 0, -76, 0, 484, 0], [4957, 0, 209, 0, 739, 0], [1855, 0, -839, 0, -769, 0], [0, -10866, 0, 880, 0, 272], [-2846, 0, 166, 0, -1494, 0], [0, 2991, 0, 1648, 0, 191], [-7693, 0, -497, 0, -509, 0], [0, -3003, 0, 1020, 0, 111], [-7560, 0, -438, 0, 542, 0], [0, 2315, 0, 1274, 0, -597], [0, -2656, 0, -21, 0, -602], [-515, 0, 65, 0, -1012, 0], [0, -9734, 0, 722, 0, 646], [-1367, 0, 259, 0, -1379, 0], [-6407, 0, -573, 0, 629, 0], [0, 2290, 0, -663, 0, 20], [358, 0, 488, 0, -256, 0], [6325, 0, 731, 0, -1050, 0], [0, -9372, 0, 1164, 0, 36], [-9381, 0, -29, 0, 757, 0], [0, -19089, 0, 118, 0, 307], [0, -6628, 0, -1206, 0, -118], [0, 3556, 0, 1484, 0, -300], [4342, 0, 1264, 0, -664, 0], [-6202, 0, 250, 0, -1148, 0], [0, -10786, 0, 577, 0, 198], [0, -4794, 0, 2220, 0, 262], [0, 15838, 0, -697, 0, -634], [14525, 0, -173, 0, -1143, 0], [7430, 0, 500, 0, 1340, 0], [0, -3970, 0, -1329, 0, -156], [0, -9466, 0, -1212, 0, 636], [0, 6712, 0, -2076, 0, 574], [4975, 0, 779, 0, 176, 0], [-21583, 0, -405, 0, 555, 0], [-5838, 0, -368, 0, 1424, 0], [0, -13574, 0, -1337, 0, 136], [0, 2402, 0, 916, 0, 34], [0, 6255, 0, -1278, 0, -1315], [-8669, 0, -379, 0, -1031, 0], [506, 0, -1476, 0, -2078, 0], [0, -7459, 0, -1740, 0, 467], [0, -5160, 0, -1563, 0, 768], [0, -181, 0, -2346, 0, -1081], [-2710, 0, 90, 0, -1832, 0], [10855, 0, -801, 0, -2871, 0], [-11077, 0, -781, 0, 383, 0], [-16409, 0, -181, 0, 664, 0], [0, -6394, 0, 332, 0, -906], [0, 5030, 0, 779, 0, 1446], [14793, 0, 1443, 0, 409, 0], [0, 3774, 0, -192, 0, 870], [705, 0, 911, 0, 1085, 0], [0, 6930, 0, 3334, 0, 544], [-5725, 0, -407, 0, 754, 0], [12226, 0, -1548, 0, -3572, 0], [0, -5422, 0, -5097, 0, 98], [0, -4858, 0, -787, 0, 904], [0, 13676, 0, -1773, 0, -280], [16027, 0, 915, 0, 573, 0], [11572, 0, -1368, 0, -1262, 0], [-15735, 0, 997, 0, 1239, 0], [0, 679, 0, 1374, 0, -1225], [0, 11670, 0, -2498, 0, -202], [197, 0, 1459, 0, -1660, 0], [-1043, 0, -415, 0, 3088, 0], [0, -32930, 0, -1244, 0, -256], [0, 5362, 0, 1288, 0, 1288], [-1772, 0, 20, 0, -2124, 0], [0, 1387, 0, 1522, 0, 779], [0, 3137, 0, 2022, 0, -1117], [6548, 0, -298, 0, -2674, 0], [0, 5347, 0, 498, 0, -2273], [0, -15796, 0, 2944, 0, 908], [0, -4817, 0, 5648, 0, 311], [25922, 0, 146, 0, 3476, 0], [20401, 0, -805, 0, -2957, 0], [-1318, 0, -2136, 0, 2066, 0], [0, 11854, 0, -1893, 0, -1102], [4061, 0, 1015, 0, 2404, 0], [0, -5435, 0, 1730, 0, 825], [0, 12241, 0, 4880, 0, 247], [0, -8876, 0, 2482, 0, -2024], [581, 0, 37, 0, -122, 0], [0, -16731, 0, 438, 0, 2107], [0, -938, 0, -119, 0, 1488], [-29712, 0, -1880, 0, 528, 0], [0, 12372, 0, -1585, 0, -344], [-12835, 0, 2037, 0, 2077, 0], [0, 12512, 0, 9076, 0, -1014], [-5884, 0, -2528, 0, 4980, 0], [11296, 0, -130, 0, -3668, 0], [107, 0, 1613, 0, -4421, 0], [0, -424, 0, 1748, 0, 82], [7163, 0, -1857, 0, 4928, 0], [39104, 0, 478, 0, -1626, 0], [-42443, 0, 275, 0, -3769, 0], [-13613, 0, -1673, 0, -3613, 0], [0, -48710, 0, 2328, 0, 426], [-26619, 0, 475, 0, -2240, 0], [0, -5957, 0, -714, 0, 363], [19047, 0, 2767, 0, -2978, 0], [0, 21493, 0, 690, 0, -413], [0, 19794, 0, -4996, 0, -1656], [0, 20767, 0, -2050, 0, -1217], [-30481, 0, -1351, 0, -2362, 0], [0, 4490, 0, -5018, 0, -824], [0, 17614, 0, 5919, 0, 196], [-15001, 0, 223, 0, 965, 0], [35505, 0, 409, 0, -762, 0], [0, 1642, 0, 2560, 0, -812], [0, -28479, 0, 1756, 0, -303], [-11133, 0, -1227, 0, -7615, 0], [9827, 0, 853, 0, 1344, 0], [0, 37390, 0, 3308, 0, 1138], [0, 1826, 0, 1311, 0, 3538], [-4875, 0, 265, 0, 6677, 0], [0, -9207, 0, -152, 0, 811], [0, 9180, 0, -5525, 0, 3248], [0, 15720, 0, -4501, 0, -3434], [-19918, 0, -2072, 0, -768, 0], [-27310, 0, -738, 0, 3502, 0], [0, 39432, 0, 1180, 0, 2326], [33505, 0, -1197, 0, -2726, 0], [66749, 0, 225, 0, 2856, 0], [0, 53750, 0, 3987, 0, -382], [-30162, 0, -1358, 0, 3402, 0], [0, 22919, 0, 6562, 0, 1083], [-18406, 0, -1220, 0, -636, 0], [18429, 0, -1771, 0, 7790, 0], [0, -5663, 0, 5192, 0, 4443], [10350, 0, -596, 0, 2128, 0], [0, -4991, 0, -1974, 0, 665], [0, -8980, 0, 3553, 0, -2378], [7540, 0, 1336, 0, 5246, 0], [3615, 0, -199, 0, 11188, 0], [0, 2131, 0, 4460, 0, 55], [2509, 0, 2943, 0, 4376, 0], [0, 3935, 0, 1812, 0, -677], [0, 5434, 0, 1928, 0, -3152], [-26484, 0, 382, 0, -5240, 0], [37582, 0, -110, 0, 8834, 0], [-41739, 0, -451, 0, -4555, 0], [0, 32560, 0, -6746, 0, 2772], [0, -29260, 0, -10431, 0, 502], [39660, 0, 1138, 0, 1508, 0], [0, 39142, 0, 10373, 0, 66], [-11883, 0, -2437, 0, 8337, 0], [0, -15788, 0, 1773, 0, -1370], [26766, 0, 2002, 0, 2364, 0], [0, -43993, 0, -956, 0, -1927], [7320, 0, 1820, 0, 530, 0], [-23110, 0, -2270, 0, 572, 0], [25707, 0, 2035, 0, 7167, 0], [0, -20752, 0, -9697, 0, -1610], [0, 29806, 0, -2887, 0, -3912], [-39275, 0, 139, 0, 5448, 0], [0, 27842, 0, -9510, 0, -5364], [-37183, 0, 2199, 0, 2031, 0], [1545, 0, -3531, 0, 7168, 0], [0, -21644, 0, -11020, 0, 2688], [-29662, 0, 2290, 0, -1612, 0], [0, -69202, 0, -4693, 0, 1604], [-2954, 0, 3612, 0, -7648, 0], [0, 30582, 0, -6017, 0, -3266], [47453, 0, -223, 0, 7552, 0], [0, 122, 0, -4524, 0, 5466], [33460, 0, -976, 0, -5622, 0], [-70945, 0, 1477, 0, -769, 0], [0, -60939, 0, 5544, 0, 1113], [0, -64749, 0, -7414, 0, 653], [11780, 0, 4162, 0, 5412, 0], [0, -19358, 0, 3168, 0, 3506], [22538, 0, -2528, 0, 278, 0], [0, 17460, 0, 4600, 0, 4566], [-46087, 0, -3549, 0, -1571, 0], [-61880, 0, 674, 0, -6172, 0], [0, -2700, 0, -20, 0, 4188], [0, 19714, 0, -207, 0, 1090], [0, -10176, 0, 8053, 0, 3784], [0, -5205, 0, 5564, 0, 951], [0, -61900, 0, 446, 0, -1044], [50286, 0, -2908, 0, -10342, 0], [0, 14452, 0, -3401, 0, 3620], [0, -64376, 0, 1524, 0, -1098], [-9775, 0, 2541, 0, -9868, 0], [-60219, 0, -2239, 0, 7229, 0], [29534, 0, -3980, 0, -1288, 0], [0, -43052, 0, 4464, 0, 4456], [0, -46153, 0, 2194, 0, -4067], [-20961, 0, -5215, 0, 10512, 0], [0, 31343, 0, 11274, 0, -453], [0, -24006, 0, 173, 0, -250], [-72252, 0, 732, 0, -676, 0], [0, 40516, 0, -15648, 0, -3854], [0, -67446, 0, 5467, 0, 3136], [0, -61192, 0, 6016, 0, 3212], [57138, 0, -1680, 0, 7668, 0], [14317, 0, 2773, 0, 3811, 0], [-22020, 0, -4456, 0, -3750, 0], [0, -3280, 0, 1411, 0, -3658], [10101, 0, -445, 0, 1109, 0], [0, -70292, 0, -12280, 0, -900], [-21548, 0, 4554, 0, -320, 0], [0, 80180, 0, -5831, 0, -1698], [-6925, 0, 189, 0, -7433, 0], [0, -99909, 0, -6502, 0, 1541], [0, 47757, 0, -13338, 0, -929], [-17280, 0, 1496, 0, -6628, 0], [48956, 0, 1282, 0, 7390, 0], [2249, 0, -5331, 0, -4009, 0], [0, -18896, 0, -7853, 0, 1286], [0, 38153, 0, 5976, 0, 1423], [-64049, 0, -3321, 0, -2282, 0], [0, 31129, 0, 4262, 0, 4271], [5903, 0, 3021, 0, -3476, 0], [-89024, 0, 1908, 0, 1162, 0], [0, -14586, 0, -21257, 0, 574], [-22082, 0, -6914, 0, -768, 0], [0, -54934, 0, -8927, 0, 604], [0, -58286, 0, -14567, 0, 2574], [0, 14638, 0, 5408, 0, 6248], [-31387, 0, -2437, 0, -5003, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1400_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1400_4_g_l();".
// 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_1400_4_g_l(:prec:=6)
    chi := MakeCharacter_1400_g();
    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_1400_4_g_l();".
// 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_1400_4_g_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1400_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![64, 0, 1129, 0, 106, 0, 1]>,<11,R![-24620, -2855, 6, 1]>],Snew);
    return Vf;
end function;