
// Make newform 175.4.a.d in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_175_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_175_4_a_d();".
// 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_175_4_a_d();".
// 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 := [-10, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_175_a();"
function MakeCharacter_175_a()
    N := 175;
    order := 1;
    char_gens := [127, 101];
    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_175_a_Hecke(Kf)
    return MakeCharacter_175_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], [2, 1], [0, 0], [-7, 0], [-23, -10], [-30, 8], [54, -5], [-32, 7], [13, 5], [-193, -27], [-114, 66], [-9, -57], [-222, -61], [75, -77], [-58, -108], [174, -86], [-10, 210], [468, 54], [-537, 166], [215, -303], [34, 269], [-539, -41], [724, 69], [-848, -17], [-1018, 272], [-864, 416], [870, 178], [-2, -189], [-53, -147], [667, -204], [1057, 287], [-516, 68], [-1116, 175], [1886, -251], [-2119, 469], [-781, 563], [1012, 592], [-1106, -71], [-3214, 38], [122, 616], [-802, -93], [-2260, 482], [2404, -382], [-1193, -54], [3365, 59], [276, 94], [2322, -15], [-68, -554], [-4634, 498], [1234, -1904], [2043, -1075], [-1364, -376], [1020, -1363], [1618, 1499], [670, -356], [4647, 401], [46, -276], [6494, -492], [-110, -616], [-4317, 269], [-76, -2211], [-4702, 1440], [2118, -579], [-12, -2546], [-538, 896], [341, 713], [4587, -540], [3092, -2263], [6761, 1358], [674, 2186], [-8830, 68], [-1189, 1329], [116, 108], [-9223, -459], [3775, -3290], [-1426, 1204], [563, 227], [6370, -1736], [-9475, 1552], [-7184, 1409], [-4928, -2237], [-4543, -795], [5456, 1396], [4654, -3221], [7674, -2274], [-8226, -711], [-1561, -2594], [-6381, -1910], [1906, -2984], [9184, 1064], [-9530, -646], [-2210, 820], [-4741, 3085], [5315, -2273], [2236, -1216], [10854, -236], [-7414, 664], [-5252, 2349], [2030, 2453], [-3319, 1891], [-13621, -280], [13873, -1979], [-4918, 4566], [4477, 3968], [9581, 1361], [-11836, -165], [14978, -2029], [-22858, -1039], [9025, -575], [4990, 3557], [-2434, 1218], [6019, -4911], [-2129, 1753], [-22406, -1794], [-20531, 1573], [-22705, -363], [2732, -5924], [11818, -5134], [-9102, 2350], [7850, 3425], [2142, -1760], [10634, 2504], [-4510, -1406], [7617, -2034], [-5698, 2545], [1226, 3226], [5930, -5530], [7780, 5060], [-19276, 2030], [5348, 300], [323, 9007], [-6124, 7052], [968, -8866], [32967, 1737], [4130, -3053], [-6994, 9199], [-21158, -5114], [-11160, 9364], [6100, -1206], [2025, -9685], [-14778, 3010], [12878, -2826], [-11203, -1229], [9097, -3768], [21952, 3028], [19712, -1282], [20620, -4002], [1570, 2059], [13804, 331], [15963, -8945], [-15990, -4726], [-15330, 1252], [23835, 2188], [-1212, 3206], [8668, -7944], [-16919, 7741], [-6491, -4169], [-41556, 1326], [-2554, 7433], [13970, 842], [49060, 1344], [12275, -9902], [-6276, -7130], [1692, 6195], [-23103, 1292], [-19922, 5970], [-40739, 5201], [-21526, 660]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_175_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_175_4_a_d();".
// 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_175_4_a_d(:prec:=2)
    chi := MakeCharacter_175_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_175_4_a_d();".
// 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_175_4_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_175_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-10, 1, 1]>],Snew);
    return Vf;
end function;