
// Make newform 435.3.h.b in Magma, downloaded from the LMFDB on 15 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_435_h();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_435_h_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_435_3_h_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_435_3_h_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 := [5, 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_435_h();"
function MakeCharacter_435_h()
    N := 435;
    order := 2;
    char_gens := [146, 262, 31];
    v := [1, 2, 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_435_h_Hecke();"
function MakeCharacter_435_h_Hecke(Kf)
    N := 435;
    order := 2;
    char_gens := [146, 262, 31];
    char_values := [[-1, 0], [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]];
    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 := 3;
    raw_aps := [[2, 0], [2, -1], [0, 1], [8, 0], [11, 0], [2, 0], [32, 0], [0, -6], [0, -15], [-29, 0], [0, 12], [0, 15], [-37, 0], [0, 21], [2, 0], [0, 9], [0, 30], [0, -6], [38, 0], [0, -42], [0, 33], [0, -6], [0, 21], [-166, 0], [0, 63], [11, 0], [26, 0], [0, -78], [101, 0], [-142, 0], [0, 63], [86, 0], [-94, 0], [-19, 0], [0, 90], [-193, 0], [0, 54], [0, -111], [0, 126], [0, -99], [0, -96], [-61, 0], [23, 0], [0, 54], [0, -105], [101, 0], [0, 126], [2, 0], [0, -33], [0, -90], [0, -183], [0, 84], [59, 0], [26, 0], [0, -57], [284, 0], [74, 0], [0, -6], [248, 0], [0, -42], [-424, 0], [278, 0], [0, -105], [431, 0], [-268, 0], [-208, 0], [0, -48], [0, -126], [0, -201], [653, 0], [0, -138], [317, 0], [0, -9], [656, 0], [0, 210], [0, 321], [-31, 0], [-646, 0], [0, 300], [0, -282], [0, -126], [0, 294], [0, 114], [0, 189], [26, 0], [338, 0], [509, 0], [68, 0], [383, 0], [-208, 0], [-124, 0], [-598, 0], [-466, 0], [278, 0], [-814, 0], [698, 0], [0, -162], [0, 156], [152, 0], [0, 414], [128, 0], [0, -33], [-892, 0], [-166, 0], [-613, 0], [0, 222], [0, 210], [0, -330], [914, 0], [0, -252], [0, 162], [332, 0], [-604, 0], [0, -240], [-1006, 0], [-409, 0], [-208, 0], [0, -369], [-922, 0], [-1171, 0], [1319, 0], [212, 0], [1262, 0], [0, 9], [614, 0], [0, -588], [-247, 0], [0, -414], [0, 42], [0, -426], [0, -72], [278, 0], [0, 246], [0, -273], [0, 90], [0, -252], [74, 0], [-46, 0], [26, 0], [1229, 0], [779, 0], [0, -372], [0, 222], [-1024, 0], [0, 180], [194, 0], [0, -651], [0, -705], [0, -636], [0, 510], [-856, 0], [-1129, 0], [-124, 0], [632, 0], [0, -177], [971, 0], [-814, 0], [0, -288], [-1342, 0], [0, 576], [-1678, 0], [0, 294], [0, 483], [443, 0], [0, 51], [-346, 0], [1319, 0], [0, 327]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_435_h_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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