
// Make newform 2304.3.g.n in Magma, downloaded from the LMFDB on 02 May 2026.
// 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_n();".
// 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_n();".
// 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 := [1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-4, 8]];
    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 := false)
    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 := ISA(Type(Kf), Fld), 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 := [[0, 0], [0, 0], [4, 0], [0, -1], [0, -1], [0, 0], [18, 0], [0, 3], [0, 6], [-4, 0], [0, 7], [72, 0], [18, 0], [0, 9], [0, -6], [44, 0], [0, -9], [-72, 0], [0, 3], [0, -6], [82, 0], [0, -9], [0, -19], [126, 0], [110, 0], [92, 0], [0, 9], [0, -13], [-144, 0], [126, 0], [0, -23], [0, 29], [18, 0], [0, 9], [-140, 0], [0, 19], [-216, 0], [0, -33], [0, -12], [52, 0], [0, -23], [-144, 0], [0, 12], [94, 0], [188, 0], [0, -23], [0, -9], [0, 45], [0, 45], [0, 0], [126, 0], [0, -24], [158, 0], [0, 27], [126, 0], [0, 72], [-52, 0], [0, 5], [-144, 0], [414, 0], [0, -51], [-532, 0], [0, 75], [0, -12], [-2, 0], [524, 0], [0, -3], [82, 0], [0, 43], [216, 0], [414, 0], [0, -78], [0, -17], [-360, 0], [0, 57], [0, -60], [52, 0], [216, 0], [18, 0], [14, 0], [0, -63], [-720, 0], [0, 78], [334, 0], [0, 37], [0, -81], [306, 0], [-466, 0], [196, 0], [0, 29], [0, -31], [0, 18], [0, 27], [0, 7], [0, 87], [0, 42], [284, 0], [-846, 0], [0, 21], [-432, 0], [0, 147], [-764, 0], [0, -119], [306, 0], [0, 21], [722, 0], [0, -109], [-1026, 0], [0, 42], [146, 0], [0, 81], [-648, 0], [-1026, 0], [0, 45], [0, 59], [-558, 0], [0, 3], [0, 102], [436, 0], [0, 73], [648, 0], [-722, 0], [4, 0], [0, 99], [0, -57], [-1252, 0], [1152, 0], [0, -162], [0, 71], [-288, 0], [0, 63], [0, 96], [0, -173], [576, 0], [18, 0], [670, 0], [1100, 0], [0, -129], [724, 0], [-558, 0], [0, -195], [-292, 0], [0, -209], [0, -117], [-720, 0], [0, -138], [72, 0], [306, 0], [0, -159], [0, 156], [-360, 0], [414, 0], [0, -45], [0, -72], [0, -111], [0, 168], [0, 247], [-270, 0], [674, 0], [1444, 0], [0, -107], [18, 0], [0, 245], [0, 131], [-1710, 0], [0, 216], [0, -13], [-648, 0], [1358, 0], [-1052, 0], [0, -53], [936, 0], [0, -240], [-1310, 0], [0, -137], [990, 0], [0, -111], [244, 0], [0, 77], [-504, 0], [0, -89], [0, 53], [-1440, 0], [-450, 0], [0, -108], [-1532, 0], [0, 0], [0, 183], [1022, 0], [0, 96], [-254, 0], [0, 55], [0, -213], [772, 0], [0, -279], [-1026, 0], [626, 0], [576, 0], [1566, 0], [0, 348], [1588, 0], [0, -71], [-1296, 0], [178, 0], [0, -257], [-1204, 0], [0, 153], [0, 101], [126, 0], [0, -123], [766, 0], [-1340, 0], [0, -91], [0, -125], [0, 198], [-2450, 0], [0, 27], [306, 0], [0, -180], [1396, 0], [144, 0], [0, -63], [1170, 0], [0, -63], [0, -223], [360, 0], [2430, 0], [0, -342], [0, -135], [0, 63], [2736, 0], [0, 291], [0, -99], [2430, 0], [0, 321], [0, -102], [-370, 0], [340, 0], [0, 79], [0, -90], [0, 117], [0, -75], [0, -97], [-1368, 0], [-2178, 0], [0, -210], [0, -401], [0, -43], [0, 33], [0, 324], [-1872, 0], [-738, 0], [0, 102], [-542, 0], [-340, 0], [0, 41], [-1296, 0], [0, 129], [-532, 0], [910, 0], [0, -163], [0, 73], [1296, 0], [2664, 0], [594, 0], [0, 3], [-524, 0], [-1314, 0], [0, -63], [-1772, 0], [-72, 0], [0, -69], [-2558, 0], [0, -169], [-158, 0], [0, -95], [0, -25], [-2376, 0], [1970, 0], [0, 405], [0, -342], [0, 277], [0, -54], [-3240, 0], [0, -63], [0, 108], [2654, 0], [-140, 0], [0, -225], [-162, 0], [-2732, 0], [0, -139], [-2178, 0], [0, 187], [-1944, 0], [-3068, 0], [0, 397], [-1924, 0], [0, 455], [0, 99], [1630, 0], [2116, 0], [0, 167]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2304_g_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2304_3_g_n();".
// 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_n(: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_n();".
// 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_n( : 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![48, 0, 1]>,<11,R![48, 0, 1]>,<13,R![0, 1]>],Snew);
    return Vf;
end function;