
// Make newform 1120.3.c.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1120_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1120_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_1120_3_c_a();".
// 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_1120_3_c_a();".
// 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_1120_c();"
function MakeCharacter_1120_c()
    N := 1120;
    order := 2;
    char_gens := [351, 421, 897, 801];
    v := [2, 1, 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_1120_c_Hecke();"
function MakeCharacter_1120_c_Hecke(Kf)
    N := 1120;
    order := 2;
    char_gens := [351, 421, 897, 801];
    char_values := [[1], [-1], [-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 := 3;
    raw_aps := [[0], [0], [-5], [-7], [0], [0], [-6], [-18], [0], [0], [0], [-66], [0], [54], [66], [-34], [62], [102], [6], [138], [106], [122], [0], [0], [-166], [22], [-46], [-74], [0], [0], [0], [-242], [0], [222], [0], [-22], [0], [-186], [306], [0], [0], [-138], [-102], [0], [254], [0], [0], [194], [0], [438], [0], [-198], [0], [-2], [-486], [0], [358], [0], [414], [-558], [0], [0], [0], [0], [-374], [-626], [0], [0], [566], [198], [666], [-438], [706], [606], [0], [-606], [0], [0], [-318], [0], [782], [0], [-582], [506], [0], [374], [-222], [0], [-698], [0], [0], [0], [0], [0], [0], [-366], [998], [0], [0], [0], [-954], [-146], [0], [18], [0], [1114], [0], [186], [-918], [0], [-1054], [1086], [0], [1182], [1258], [162], [0], [1266], [46], [0], [-1098], [0], [0], [-1226], [-1362], [0], [0], [0], [-814], [0], [0], [0], [1018], [1374], [0], [0], [0], [0], [0], [498], [-1122], [0], [0], [-394], [-762], [0], [0], [1674], [1662], [0], [-1746], [0], [1734], [-1614], [1686], [-1542], [682], [0], [1514], [1702], [1606], [0], [0], [1438], [0], [594], [538], [0], [898], [0], [0], [1542], [-1782], [0], [0], [0], [0], [0], [1874], [-1242], [0], [-562], [2046], [1194], [0], [-202], [-1266], [0], [-2222], [0], [-934], [1174], [0], [-2138], [-2234], [2346], [-2078], [-1074], [-2406], [-2286], [0], [0], [0], [0], [-2018], [0], [0], [-1306], [-1902], [-162], [0], [982], [0], [0], [0], [0], [0], [0], [0], [1486], [0], [0], [-1662], [0], [0], [0], [1866], [-2598], [2866], [0], [-594], [2862], [-422], [-1518], [0], [-414], [0], [2846], [0], [0], [454], [318], [-1646], [0], [-1734], [0], [866], [2638], [0], [0], [-306], [0], [0], [0], [0], [0], [0], [0], [0], [74], [0], [-2074], [-2442], [0], [-3366], [-3378], [0], [0], [3414], [-3394], [102], [3366], [-3254], [3482], [-1286], [2194], [3286], [0], [2482], [878], [-1086], [3338], [306], [-3498], [0], [3258], [0], [-3106], [0], [0], [0], [0], [0], [3358], [366], [-1882], [0], [0], [-578], [0], [746], [2734], [-1478]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1120_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1120_3_c_a();".
// 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_1120_3_c_a(:prec:=1)
    chi := MakeCharacter_1120_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_1120_3_c_a();".
// 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_1120_3_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1120_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<3,R![0, 1]>,<17,R![6, 1]>,<19,R![18, 1]>],Snew);
    return Vf;
end function;