
// Make newform 175.6.b.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_175_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_175_b_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_175_6_b_b();".
// 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_6_b_b();".
// 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 := [1, 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_b();"
function MakeCharacter_175_b()
    N := 175;
    order := 2;
    char_gens := [127, 101];
    v := [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_175_b_Hecke();"
function MakeCharacter_175_b_Hecke(Kf)
    N := 175;
    order := 2;
    char_gens := [127, 101];
    char_values := [[-1, 0], [1, 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+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 := 6;
    raw_aps := [[0, 8], [0, 1], [0, 0], [0, -49], [-453, 0], [0, -969], [0, -1637], [1550, 0], [0, -1654], [4985, 0], [1192, 0], [0, 11018], [-1728, 0], [0, -10814], [0, -26237], [0, 25936], [4580, 0], [-12488, 0], [0, 15848], [51792, 0], [0, 4846], [-62765, 0], [0, -23644], [147300, 0], [0, 8343], [-11878, 0], [0, -132439], [0, -136842], [-109485, 0], [0, -200934], [0, -330692], [43982, 0], [0, 99748], [-258930, 0], [498430, 0], [-245803, 0], [0, 85478], [0, 193026], [0, 157783], [0, -265659], [-183660, 0], [-635048, 0], [-226613, 0], [0, 46476], [0, -204972], [953020, 0], [-223523, 0], [0, 1014801], [0, -999797], [851120, 0], [0, 1092696], [-765905, 0], [-1210938, 0], [278262, 0], [0, 352998], [0, -1558094], [1219630, 0], [405792, 0], [0, -652442], [118827, 0], [0, 1488011], [0, 1895801], [0, 821853], [-2095998, 0], [0, 394571], [0, -321422], [-2232588, 0], [0, 3656558], [0, 1889618], [2693290, 0], [0, -1574679], [-4055760, 0], [0, 4906283], [0, -3453364], [4234660, 0], [0, -1864604], [4815015, 0], [0, -1213757], [5904417, 0], [-4842890, 0], [-270360, 0], [3136477, 0], [-1877033, 0], [0, 3203566], [6272090, 0], [0, 724986], [875985, 0], [0, 832668], [5921152, 0], [0, 682776], [0, 5416673], [-1985990, 0], [0, 1069738], [4592457, 0], [-1960655, 0], [0, 3514831], [1452110, 0], [-4242398, 0], [0, -7560124], [1240647, 0], [0, 1850568], [0, -7775552], [0, 8377156], [6155910, 0], [7215132, 0], [0, -13669927], [0, 10068648], [0, 9806151], [-8262575, 0], [-3594918, 0], [0, 13296913], [0, 2503266], [0, -1882542], [-8214870, 0], [16115487, 0], [-8505438, 0], [0, -13219079], [0, -1891152], [0, 4905866], [-13636695, 0], [-2223448, 0], [0, 4884836], [0, 19878473], [0, 4278696], [9489252, 0], [-5863853, 0], [2666705, 0], [4466290, 0], [0, 7477568], [0, -4397509], [-28403555, 0], [0, -19601184], [-2603443, 0], [0, 29886928], [12146982, 0], [-4538450, 0], [0, 19332951], [0, -16639237], [0, -18040917], [-23389065, 0], [-22903698, 0], [-18074463, 0], [0, 11798936], [0, -2576502], [38433960, 0], [12422190, 0], [0, 7920666], [0, -14898342], [13874020, 0], [0, 12549996], [0, 28600198], [40960752, 0], [0, 13050436], [0, -25359472], [0, -19859482], [-19934448, 0], [11069535, 0], [32568200, 0], [0, -31568977], [-36799728, 0], [0, -18845252], [0, -12511964], [0, 34234418], [-26202748, 0], [0, 8011138], [0, -46012609], [-37582848, 0], [0, -22206617]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_175_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_175_6_b_b();".
// 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_6_b_b(:prec:=2)
    chi := MakeCharacter_175_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_6_b_b();".
// 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_6_b_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_175_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![64, 0, 1]>],Snew);
    return Vf;
end function;