
// Make newform 207.4.a.f in Magma, downloaded from the LMFDB on 16 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_207_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_207_4_a_f();".
// 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_207_4_a_f();".
// 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 := [25, 25, -20, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [15, -15, -1, 1], [-20, 25, 1, -1], [-15, -35, 3, 2]];
    Rf_basisdens := [1, 5, 5, 5];
    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_207_a();"
function MakeCharacter_207_a()
    N := 207;
    order := 1;
    char_gens := [47, 28];
    v := [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_207_a_Hecke(Kf)
    return MakeCharacter_207_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+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], [-1, -3, -2, -1], [10, 4, 1, -1], [-13, 5, -5, -6], [6, -4, 2, -4], [14, 14, 7, 3], [9, -3, 2, -9], [23, 0, 0, 0], [4, -2, 32, 10], [122, 22, 0, -2], [45, 9, -31, -40], [134, 4, -44, 24], [311, 7, -18, 25], [6, 30, -30, 10], [-97, -15, 22, -5], [-190, 66, 46, 46], [67, -13, 7, -8], [9, 81, -64, -59], [-232, 52, 40, 48], [-324, -38, 2, 80], [490, 64, -23, 15], [-239, 111, 77, -58], [268, 100, -19, -45], [-400, -138, -48, 78], [424, -290, 86, 68], [-124, 86, -177, -57], [-51, 291, 69, 150], [667, -129, -35, 6], [1600, 32, -91, -81], [608, -148, 102, 86], [190, 70, 14, -80], [42, 118, 213, 189], [648, -284, 32, 76], [-741, 81, -204, -155], [470, -66, 42, 88], [1197, 433, 5, 220], [210, -258, 212, -146], [-272, -476, -52, 204], [2616, -302, -48, -90], [-2208, -276, -204, 30], [751, -149, 241, -70], [606, 54, 492, -82], [680, 542, 0, 60], [366, 372, 78, -226], [394, 464, 55, 125], [1070, 474, -204, 306], [-1150, -406, 150, 68], [-709, 321, -479, -184], [975, -589, 185, -226], [1650, -412, -108, 84], [-3340, 28, 40, -268], [656, 334, 744, -62], [549, -201, 279, 780], [-666, 948, 132, 104], [-1848, 900, -42, -94], [-1290, -4, 726, -354], [276, 112, -190, 142], [-640, -1170, 186, 308], [-392, 600, -85, 305], [-4905, -1237, -406, 437], [67, 133, 764, 905], [470, -78, 24, 682], [5054, -486, -122, 238], [296, -318, -810, 376], [1296, -102, -1128, -54], [-3026, -94, 832, -230], [-1934, 1732, 634, 538], [-1972, 864, 268, -526], [-784, 210, -960, -684], [1790, -1332, 586, 2], [-2638, -1862, -272, 150], [-3890, -164, 13, -649], [-1079, -1235, -923, -848], [261, 769, 1172, 1181], [7172, 880, -158, -586], [-775, 791, 574, -1223], [-4702, -100, 660, 344], [-9278, -1214, -217, 159], [2388, 874, 404, 1112], [-3731, -1613, -1051, 610], [3261, 909, -73, 414], [2318, -582, 82, -164], [8240, 1338, 138, -800], [-740, -1140, -896, 468], [-2112, -1068, -168, -732], [4154, 2888, 1240, -84], [552, -2290, -364, -970], [-2882, 796, -958, -1602], [-116, 652, 364, 52], [1605, 1087, -681, 1140], [-2880, 872, -540, -312], [-11740, 1196, 1452, 1004], [-8452, -16, 1276, 1158], [2550, -14, 1640, 814], [-466, 2354, -710, -2172], [-7180, -1738, -44, -350], [4902, -1350, 1479, 327], [409, -2559, 1276, 537], [5596, -978, -140, 312], [-9246, -1410, -292, -474], [2389, 1939, -298, -1547], [-4341, 249, 1749, 796], [-4562, -498, -1855, -1519], [4501, 597, -746, 135], [13230, -356, 998, 888], [5238, 654, 582, -1248], [5330, -1720, 1720, 1788], [-9456, -40, 156, 1476], [16782, 2116, 830, -576], [-3110, 178, -3434, -240], [9679, -697, 1183, 224], [-12048, 1392, 2805, 919], [5731, -2553, -896, -1833], [-16120, -1158, -1899, -287], [-4634, -2146, -697, 355], [15463, 1855, 910, 785], [-4910, -2738, 62, -554], [2600, -5778, -218, -760], [-1655, 539, -2521, -1536], [-1245, 3243, -1045, -1600], [-554, 1500, 2482, 672], [3831, -1995, 1728, 1581], [5190, 2374, 2298, -1900], [9622, 3706, 1312, 2478], [10397, 2063, -1556, -2181], [6313, 2609, 655, 934], [8538, 870, 2670, 878], [-2238, -3052, 455, 1085], [-5335, 1841, 2583, 3682], [25720, -820, 1060, -120], [-8152, -3076, -974, 2954], [-10232, -2146, -2381, -1425], [15679, -3509, 2113, -150], [12546, 6408, 2754, -1082], [6804, -2242, -3142, -928], [409, 1955, 3626, -1791], [-7633, 903, -1122, -2559], [16729, 535, -112, -601], [6902, 6116, -782, 982], [4058, 4374, 1296, -326], [13988, -358, 1618, 2244], [-2266, -446, 912, -314], [9157, -1745, -1141, 2184], [-15748, -1082, 1164, 352], [-756, -4248, 726, -66], [5426, 4204, 4416, -824], [17290, 796, -1588, -748], [560, 12, -4248, -2568], [5174, -6334, -1910, -2974], [-14980, -2086, -1386, -960], [1212, 2052, 2151, -431], [11734, 5986, -1136, -2342], [5862, 2190, -4650, -4654], [6079, -5733, 4102, 3057], [-10714, -310, 1354, 2076], [-790, 2632, -4245, 1153], [-6654, 1008, 2100, 4388], [-9870, 1792, -2848, -5472], [-18613, -79, 2074, -1409], [9076, 2744, 320, -3474], [358, -5610, -3763, 445], [23354, 3886, -1344, 646], [5771, 1985, -4463, -3888], [-2518, 1862, -2537, -1085], [-18122, -4310, -1126, -1116], [2998, -4014, -2600, -1170], [-15732, 3238, 1940, 2956]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_207_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_207_4_a_f();".
// 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_207_4_a_f(:prec:=4)
    chi := MakeCharacter_207_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(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_207_4_a_f();".
// 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_207_4_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_207_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![48, 40, -27, -2, 1]>],Snew);
    return Vf;
end function;