
// Make newform 175.4.a.c in Magma, downloaded from the LMFDB on 19 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_c();".
// 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_c();".
// 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 := [-2, 0, 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 := [[-4, 1], [-1, -4], [0, 0], [7, 0], [-7, 32], [-25, 4], [25, 44], [18, -44], [-122, -68], [-13, -24], [-60, 180], [-282, -60], [-164, -124], [130, 68], [175, -132], [28, 128], [-616, 0], [168, 108], [76, -64], [-952, 0], [-338, -344], [507, -248], [188, 600], [-108, -44], [-1371, 220], [-338, 68], [667, 716], [-862, -456], [241, -1056], [242, -1140], [-1304, 64], [-110, -1324], [-644, -1108], [166, 256], [226, -392], [-645, 1184], [-774, 176], [174, -832], [795, -308], [-403, -2044], [2300, 480], [2028, -400], [-1099, 512], [404, -804], [696, 988], [3080, -152], [4863, 552], [2811, 2516], [-325, 948], [-1260, 3796], [-88, -368], [263, -3760], [-3146, 2228], [-118, -304], [4818, -2152], [-2014, 2272], [2266, 696], [1904, -1980], [-4286, 3304], [-1853, -1048], [205, -3972], [-3863, 2532], [-579, -948], [4466, -2300], [-3561, 3532], [642, -5048], [-7308, -1680], [3546, -2528], [-846, 6148], [-4494, -4084], [-4299, 1060], [-448, -1920], [2095, -3732], [-1916, 3204], [-2460, 1264], [2756, -2776], [-3747, 1856], [-1131, 2204], [-6503, 1648], [-6010, -4024], [-5028, 5488], [3401, 7176], [-5807, -440], [-1890, -4336], [-5502, -48], [8490, -2124], [-12041, 3400], [-6224, 6452], [10056, -2816], [13792, 3628], [-119, 4876], [10266, -5564], [-11062, 3872], [379, 112], [3269, -1888], [3589, -5668], [7930, 6928], [7390, 900], [12228, -3152], [15475, 4360], [-9192, 1204], [-8712, -11728], [-18716, 2160], [-11182, 848], [-8676, -2056], [-2069, 1884], [12096, 2584], [-9261, 6844], [1329, -15080], [-15970, -16], [5917, -14196], [1982, 1872], [2382, 14696], [610, 8316], [9681, 3040], [-17758, 1200], [9599, -3604], [-8360, -14888], [-314, -8980], [10701, 9032], [-4096, -3656], [-564, 18124], [13319, 6428], [-9384, 12828], [-12428, 14776], [-8633, 17416], [16803, 2192], [-9574, -1060], [-13992, -12488], [-989, -11292], [-2543, -6416], [-20940, 3544], [5739, 14024], [-1824, -3096], [-13490, -11108], [-314, 15664], [7935, 12452], [29083, 5756], [8429, 22596], [-10079, 5744], [-18406, -11240], [2117, -11160], [3740, 12572], [-25174, -7104], [26676, 3316], [-15282, -9196], [-11374, 1392], [4638, 16496], [12300, -4256], [-16688, 15164], [24974, 3724], [15392, 20848], [-4004, -628], [-20248, 13072], [-21466, -1572], [10368, -17144], [20079, -4064], [18060, -984], [-32427, 1444], [6480, -5428], [18152, -14100], [-6808, -1252], [21982, 23672], [22200, -108], [-14374, -20], [-21139, 9420], [-5344, 21104], [50713, -12]];
    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_c();".
// 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_c(: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_c();".
// 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_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_175_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![14, 8, 1]>],Snew);
    return Vf;
end function;