
// Make newform 35.5.c.c in Magma, downloaded from the LMFDB on 20 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_5_c_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_35_5_c_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 := [6, 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_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, 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 := 5;
    raw_aps := [[0, 1], [-5, 0], [-5, 10], [-35, 14], [89, 0], [5, 0], [485, 0], [0, 90], [0, -286], [191, 0], [0, -430], [0, 666], [0, 1190], [0, 154], [2195, 0], [0, -648], [0, -1480], [0, 790], [0, 836], [4454, 0], [-8650, 0], [5561, 0], [-1990, 0], [0, -330], [-9235, 0], [0, -1970], [4715, 0], [0, -5172], [12311, 0], [0, 1274], [0, -9744], [0, 2750], [0, 9418], [0, -12040], [28346, 0], [-17551, 0], [25790, 0], [0, -15168], [20795, 0], [-115, 0], [5318, 0], [0, -5040], [-14263, 0], [0, -13066], [0, 1386], [0, -7920], [52817, 0], [-13645, 0], [-74485, 0], [0, 27950], [0, 24564], [-75367, 0], [0, -31790], [0, 20580], [-3370, 0], [0, 24244], [0, -31440], [0, 58470], [0, -41612], [-47521, 0], [43115, 0], [162125, 0], [-33805, 0], [0, -20590], [-68155, 0], [0, -17324], [-114706, 0], [0, 47768], [0, -28774], [0, -37310], [11405, 0], [230366, 0], [-74485, 0], [0, -41866], [-172954, 0], [144050, 0], [-148969, 0], [256925, 0], [-35641, 0], [0, 61940], [0, -61600], [-4681, 0], [-87103, 0], [-231730, 0], [0, 100540], [0, 142822], [254711, 0], [0, 107626], [0, 52360], [0, -33418], [-204445, 0], [0, 32470], [0, -67344], [-74191, 0], [-278527, 0], [60275, 0], [0, -142360], [0, -34590], [235610, 0], [259199, 0], [0, -173054], [0, 54456], [369770, 0], [-326134, 0], [306374, 0], [-387595, 0], [-467350, 0], [-214315, 0], [-283999, 0], [0, 37240], [193715, 0], [0, -120936], [0, -173404], [0, 153430], [-471511, 0], [558794, 0], [454235, 0], [129530, 0], [0, -140398], [526913, 0], [0, 78320], [0, 175462], [79685, 0], [0, -293766], [0, 162700], [-658873, 0], [-593737, 0], [0, 30750], [-342190, 0], [-958555, 0], [-229399, 0], [0, -39928], [246977, 0], [0, 431256], [0, -166090], [0, -241780], [401165, 0], [-357565, 0], [1181885, 0], [-272449, 0], [0, -498540], [-621793, 0], [0, -47926], [0, -81564], [0, -80790], [0, -337610], [-385450, 0], [356750, 0], [0, 236060], [0, 61734], [0, -226162], [0, 217140], [0, 247674], [-1357030, 0], [0, -184622], [-948106, 0], [394481, 0], [0, -56960], [434285, 0], [0, -220090], [0, 68398], [0, -536046], [0, -138292], [0, 656130], [0, -571834], [-1737685, 0], [-423586, 0], [-548035, 0]];
    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_5_c_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_35_5_c_c(:prec:=2)
    chi := MakeCharacter_35_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 5));
    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_5_c_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_35_5_c_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_35_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([<2,R![6, 0, 1]>,<3,R![5, 1]>],Snew);
    return Vf;
end function;