
// Make newform 1872.4.a.ba in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1872_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_1872_4_a_ba();".
// 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_1872_4_a_ba();".
// 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 := [-7, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [1, 1];
    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_1872_a();"
function MakeCharacter_1872_a()
    N := 1872;
    order := 1;
    char_gens := [703, 469, 209, 145];
    v := [1, 1, 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_1872_a_Hecke(Kf)
    return MakeCharacter_1872_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, 0], [0, 0], [0, 2], [22, 0], [0, -1], [13, 0], [0, -22], [126, 0], [0, 6], [0, -10], [182, 0], [-86, 0], [0, 84], [-96, 0], [0, 69], [0, 36], [0, -111], [574, 0], [530, 0], [0, 153], [-154, 0], [460, 0], [0, -61], [0, -272], [70, 0], [0, 276], [1428, 0], [0, -306], [-338, 0], [0, 318], [376, 0], [0, -130], [0, -264], [-2100, 0], [0, 378], [-3526, 0], [3066, 0], [3442, 0], [0, 509], [0, -660], [0, 32], [3374, 0], [0, -224], [-1542, 0], [0, -402], [952, 0], [1640, 0], [4886, 0], [0, 353], [5558, 0], [0, 676], [0, -555], [-602, 0], [0, -666], [0, -556], [0, 162], [0, -62], [2814, 0], [-3190, 0], [0, -1156], [4788, 0], [0, 1266], [406, 0], [0, 1566], [-5586, 0], [0, 1586], [4426, 0], [8370, 0], [0, 1152], [4354, 0], [0, -644], [0, -1467], [7784, 0], [-8510, 0], [-1650, 0], [0, -1637], [0, -458], [-1414, 0], [0, 988], [5782, 0], [0, -2170], [-14194, 0], [0, 987], [-686, 0], [1372, 0], [0, 442], [0, -3260], [-17866, 0], [0, -398], [13718, 0], [0, 774], [0, 1647], [-4506, 0], [0, -4086], [786, 0], [0, 398], [0, -1586], [0, -738], [17668, 0], [-1650, 0], [-3796, 0], [0, 390], [0, 4920], [0, 688], [19612, 0], [15722, 0], [0, 515], [0, -3404], [0, 2302], [5950, 0], [-14168, 0], [-6326, 0], [0, -1664], [24486, 0], [-22430, 0], [0, -5194], [-16478, 0], [0, -5020], [0, 3834], [0, -124], [-14238, 0], [-4874, 0], [0, 4120], [0, -1653], [-294, 0], [0, 2978], [-6722, 0], [0, 6], [-12824, 0], [-29610, 0], [15622, 0], [0, -1623], [-29468, 0], [-35030, 0], [0, 4220], [-27342, 0], [0, -2246], [-22666, 0], [0, -110], [0, -150], [9478, 0], [0, -610], [-40476, 0], [0, 1355], [27482, 0], [0, 3615], [31962, 0], [0, 932], [-11704, 0], [0, 431], [-1006, 0], [0, -7688], [-124, 0], [0, -3132], [42996, 0], [0, 10048], [-8244, 0], [0, -3060], [-18214, 0], [0, -2630], [0, -7635], [0, 4020], [-9578, 0], [0, -8496], [0, -6192], [0, -8965], [6848, 0], [-5810, 0], [-46338, 0], [0, -1440], [0, -3675], [48202, 0], [0, 838], [23382, 0], [-9828, 0], [0, -1404], [-28338, 0], [0, 5382], [-64204, 0], [-16758, 0], [-3194, 0], [0, -1560], [-8566, 0], [0, -4896], [0, -4487], [0, 11442], [29734, 0], [3262, 0], [-54514, 0], [0, -7767], [61138, 0], [0, 3575], [18356, 0], [0, -1066], [0, 1308], [0, 12144], [24106, 0], [4006, 0], [0, -7048], [0, -1080], [0, -1026], [-64568, 0], [-30674, 0], [19250, 0], [0, -2835], [0, -6076], [12950, 0], [0, 3650], [0, -15148], [-12460, 0], [-19486, 0], [0, -11532], [-9812, 0], [0, -1909], [0, 8183], [77546, 0], [-74996, 0], [0, 13892], [0, 9141], [0, -5622], [22370, 0], [-26026, 0], [0, -2144], [28478, 0], [0, -10170], [-29402, 0], [0, -468], [0, 6826], [26600, 0], [0, 12721], [13494, 0], [33964, 0], [30634, 0], [0, -11202], [41636, 0], [0, 15885], [-55930, 0], [0, -7754], [0, 5812], [0, -1648], [0, -6625], [-95620, 0], [27412, 0], [67842, 0], [0, 1512], [0, -14130], [80318, 0], [0, 12729], [-57962, 0], [0, -4674], [-51130, 0], [0, 17960], [0, 2835], [-83846, 0], [0, 5850], [0, 18119], [21758, 0], [66598, 0], [0, 14130], [77770, 0], [54360, 0], [0, -24988], [11942, 0], [-16394, 0], [0, 1872], [99680, 0], [0, -19078], [0, 11028], [-5546, 0], [0, -19496], [-44842, 0], [125106, 0], [-60242, 0], [-29972, 0], [-17094, 0], [5642, 0], [0, -18415], [126586, 0], [-77534, 0], [0, 5238], [0, 1488], [-14786, 0], [0, 18968], [12026, 0], [39382, 0], [0, 10160], [-102482, 0], [0, -7002], [25690, 0], [0, 4244], [0, -14964], [0, 26112], [0, 5028], [0, 8661], [-43958, 0], [0, 8986], [-79968, 0], [0, 9430], [0, 29332], [-70322, 0], [148778, 0], [0, 11950], [-110980, 0], [0, 15808], [-103196, 0], [-12714, 0], [0, -29192], [-4550, 0], [0, -23157], [-138462, 0], [0, -29246], [0, -7806], [0, -21218], [-96976, 0], [0, -5387], [-99358, 0], [0, -23427], [0, -26137], [98350, 0], [0, -16842], [-33320, 0], [-86438, 0], [0, 23484], [-104718, 0], [0, 18924], [-62706, 0], [59050, 0], [18578, 0], [0, -24112], [0, -3054], [80246, 0], [0, 15318], [-66220, 0], [0, 17599], [-97162, 0], [0, -10153], [-75710, 0], [0, 7196], [-103978, 0], [165116, 0], [25650, 0], [0, -27350], [0, -13414], [175156, 0], [0, 35690], [0, -19560], [-177170, 0], [-58798, 0], [0, 7669], [0, 24958], [-162918, 0], [124014, 0], [0, 24054], [-141512, 0], [-59554, 0], [0, -27010], [0, 2761], [0, -22167], [0, 16560], [0, 6107], [63114, 0], [0, 40074], [0, -9726], [0, -27231], [81872, 0], [-21002, 0], [0, 16266], [-3502, 0], [204510, 0], [0, -12522], [-214704, 0], [0, 32933], [0, -28416], [-20076, 0], [-214086, 0], [0, -16101], [0, 16812], [-254702, 0], [0, 22624], [-167118, 0], [0, 20382], [0, -2532], [-151226, 0], [0, -23268], [-240646, 0], [0, -4825], [76050, 0], [-86142, 0], [34774, 0], [0, -19550], [-238138, 0], [0, -16690], [0, -32981], [25816, 0], [0, -39623], [98950, 0], [-111062, 0], [0, 7398], [-10768, 0], [0, -49422], [-113806, 0], [0, 17598], [22790, 0], [0, -50052], [0, -19798], [-159068, 0], [8710, 0], [0, 368], [-65394, 0], [0, 12819], [151970, 0], [0, 40040], [0, 44208], [137384, 0], [-246762, 0], [0, -17424], [0, -10415], [200788, 0], [0, 2700], [0, -14870], [0, 46132], [-37926, 0], [0, -15803], [0, -33038], [-104734, 0], [0, 36874], [0, 37842], [0, -8388], [84322, 0], [0, 9924]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1872_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1872_4_a_ba();".
// 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_1872_4_a_ba(:prec:=2)
    chi := MakeCharacter_1872_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(2999) - 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_1872_4_a_ba();".
// 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_1872_4_a_ba( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1872_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-112, 0, 1]>,<7,R![-22, 1]>],Snew);
    return Vf;
end function;