
// Make newform 35.17.c.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_35_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_35_c_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_35_17_c_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_35_17_c_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_35_c();"
function MakeCharacter_35_c()
    N := 35;
    order := 2;
    char_gens := [22, 31];
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_35_c_Hecke();"
function MakeCharacter_35_c_Hecke(Kf)
    N := 35;
    order := 2;
    char_gens := [22, 31];
    char_values := [[-1], [-1]];
    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 := 17;
    raw_aps := [[0], [3007], [390625], [5764801], [145028447], [1571306207], [-4372390753], [0], [0], [-993241792513], [0], [0], [0], [0], [-42819958052353], [0], [0], [0], [0], [1283316773477762], [-491238137911678], [1884802582005407], [-1568384056666558], [0], [11753087741306207], [0], [-12604132212364993], [0], [-34028385770513473], [0], [0], [0], [0], [0], [-327391043169456958], [508805188739383967], [-684082704566880958], [0], [336634266965941247], [1184568405075835487], [1057219294162236482], [0], [-3373877003651991073], [0], [0], [0], [-3628671005853960673], [-10831745950223628673], [-6102175503150893953], [0], [0], [283446859706937887], [0], [0], [-23582938898942499838], [0], [0], [0], [0], [-74196847739811244033], [25204215704889628607], [104999933199440961887], [-157529649888591914113], [0], [-178278538163451067873], [0], [-264844912310114237758], [0], [0], [0], [-7055312397283626913], [198712679156802403202], [-142424952414488304193], [0], [750255694174955828162], [853447991797125949442], [-779426293759807087873], [-713405244879000930913], [997144085034597438527], [0], [0], [1268178543609759108287], [957463910897056023647], [-1392399156887335860478], [0], [0], [-3172866024857888003713], [0], [0], [0], [-4445999913205167994753], [0], [0], [4338661789425496433567], [7443070590723999417887], [-7303127976048596718913], [0], [0], [-9201650645887939425598], [14673078460530294979007], [0], [0], [13687993755309050495042], [-9495204937931040620158], [15284251689466760402882], [24076780701431187331487], [-27780421261861095885118], [-9607448143859898782113], [-19074552813130622165473], [0], [33216309490633393109567], [0], [0], [0], [43963665875070211148447], [50863727239730578913282], [-30635509657211182780033], [52860260791391733175682], [0], [-19452678016714525125793], [0], [0], [-67976232480837612857953], [0], [0], [-26632564211183476520833], [121981469588672499796607], [0], [-271850191561206652798], [163658226114255880164767], [-176665918153405630954273], [0], [-156086381697947066135713], [0], [0], [0], [203953105364629621705247], [-199204281442286880244033], [-206229459305464611392353], [325509502808867691404927], [0], [-34609603087268323022593], [0], [0], [0], [0], [515553160644481496429762], [-563159439470218503411838], [0], [0], [0], [0], [0], [-485896799668277581941118], [0], [-947077286424359674563838], [-127571800670288197102753], [0], [-219657790752153048346273], [0], [0], [0], [0], [0], [0], [245972269126431381368447], [-1837067452180320723724798], [97504518595688520218207]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_35_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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