
// Make newform 2304.3.g.m in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2304_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_2304_g_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_2304_3_g_m();".
// 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_2304_3_g_m();".
// 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 := [2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_2304_g();"
function MakeCharacter_2304_g()
    N := 2304;
    order := 2;
    char_gens := [1279, 2053, 1793];
    v := [1, 2, 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_2304_g_Hecke();"
function MakeCharacter_2304_g_Hecke(Kf)
    N := 2304;
    order := 2;
    char_gens := [1279, 2053, 1793];
    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+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], [0, 0], [4, 0], [0, -4], [0, -5], [-20, 0], [10, 0], [0, -5], [0, -4], [20, 0], [0, 0], [-20, 0], [-30, 0], [0, 1], [0, 24], [-60, 0], [0, 15], [28, 0], [0, -29], [0, 20], [10, 0], [0, 40], [0, 9], [22, 0], [150, 0], [-140, 0], [0, -36], [0, 51], [-68, 0], [190, 0], [0, -16], [0, 5], [130, 0], [0, -15], [52, 0], [0, -60], [-100, 0], [0, 39], [0, -44], [20, 0], [0, -15], [-180, 0], [0, -80], [-170, 0], [-220, 0], [0, 60], [0, -145], [0, 64], [0, -79], [-260, 0], [-10, 0], [0, -120], [-10, 0], [0, -65], [350, 0], [0, 84], [-188, 0], [0, -40], [540, 0], [-490, 0], [0, -171], [-380, 0], [0, 171], [0, 60], [-130, 0], [-460, 0], [0, -115], [450, 0], [0, -41], [140, 0], [-130, 0], [0, -220], [0, -216], [-420, 0], [0, 105], [0, -64], [372, 0], [-100, 0], [-502, 0], [190, 0], [0, 285], [-292, 0], [0, -120], [-10, 0], [0, -60], [0, -189], [-150, 0], [-290, 0], [-60, 0], [0, -24], [0, -99], [0, 320], [0, -84], [0, -265], [0, 55], [0, -84], [900, 0], [642, 0], [0, -211], [-580, 0], [0, -141], [-460, 0], [0, -219], [-670, 0], [0, 45], [610, 0], [0, -181], [670, 0], [0, 300], [-470, 0], [0, 16], [540, 0], [950, 0], [0, 165], [0, -300], [-470, 0], [0, -189], [0, -236], [900, 0], [0, 185], [172, 0], [-170, 0], [-300, 0], [0, 39], [0, -65], [548, 0], [460, 0], [0, 440], [0, -364], [-660, 0], [0, -225], [0, 84], [0, 280], [-660, 0], [-1022, 0], [-362, 0], [820, 0], [0, 271], [-860, 0], [482, 0], [0, -315], [1508, 0], [0, 324], [0, 299], [-1092, 0], [0, 100], [1500, 0], [290, 0], [0, 345], [0, 224], [-100, 0], [510, 0], [0, -141], [0, 124], [0, 489], [0, 200], [0, -220], [490, 0], [10, 0], [-700, 0], [0, -251], [-670, 0], [0, -356], [0, 215], [330, 0], [0, 204], [0, -80], [620, 0], [1718, 0], [1140, 0], [0, -45], [1580, 0], [0, 180], [1610, 0], [0, 440], [-1002, 0], [0, -655], [-1420, 0], [0, 204], [812, 0], [0, -96], [0, -95], [-260, 0], [630, 0], [0, -696], [-1420, 0], [220, 0], [0, 391], [-1250, 0], [0, 640], [-830, 0], [0, -609], [0, 35], [-812, 0], [0, -311], [-10, 0], [2210, 0], [1020, 0], [-770, 0], [0, -44], [-1900, 0], [0, -760], [-260, 0], [98, 0], [0, 275], [1620, 0], [0, 320], [0, 489], [-522, 0], [0, -395], [-330, 0], [-748, 0], [0, -524], [0, -61], [0, 180], [-450, 0], [0, -136], [2378, 0], [0, 876], [1940, 0], [-1988, 0], [0, 500], [-982, 0], [0, -696], [0, 789], [892, 0], [1110, 0], [0, -80], [0, 444], [0, 15], [-1060, 0], [0, -445], [0, 160], [-10, 0], [0, -999], [0, -744], [-1930, 0], [20, 0], [0, 555], [0, 820], [0, 89], [0, 965], [0, -564], [-1140, 0], [-2370, 0], [0, -20], [0, -896], [0, -235], [0, -375], [0, 264], [-980, 0], [-2498, 0], [0, -396], [-950, 0], [-220, 0], [0, -575], [-1460, 0], [0, -479], [-940, 0], [-1410, 0], [0, -384], [0, -879], [1580, 0], [1420, 0], [-2710, 0], [0, -525], [-1660, 0], [-1642, 0], [0, -831], [-2860, 0], [-340, 0], [0, 179], [-2070, 0], [0, 720], [1250, 0], [0, -204], [0, -549], [380, 0], [-950, 0], [0, -75], [0, -1056], [0, 540], [0, 396], [2620, 0], [0, 81], [0, -1080], [-2570, 0], [1380, 0], [0, -700], [350, 0], [-348, 0], [0, 469], [2390, 0], [0, -165], [1660, 0], [452, 0], [0, 960], [1300, 0], [0, -245], [0, 699], [1150, 0], [340, 0], [0, 760]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2304_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2304_3_g_m();".
// 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_2304_3_g_m(:prec:=2)
    chi := MakeCharacter_2304_g();
    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_2304_3_g_m();".
// 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_2304_3_g_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2304_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![-4, 1]>,<7,R![128, 0, 1]>,<11,R![200, 0, 1]>,<13,R![20, 1]>],Snew);
    return Vf;
end function;