
// Make newform 33.6.a.c in Magma, downloaded from the LMFDB on 05 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_33_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_33_6_a_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_33_6_a_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 := [-44, -1, 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_33_a();"
function MakeCharacter_33_a()
    N := 33;
    order := 1;
    char_gens := [23, 13];
    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;

function MakeCharacter_33_a_Hecke( : Kf := Kf)
    return MakeCharacter_33_a();
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 := 6;
    raw_aps := [[-2, -1], [-9, 0], [24, 10], [-138, -10], [-121, 0], [-64, -38], [-370, -60], [-744, 12], [-1502, -366], [3506, -412], [-3592, -344], [-15026, 136], [-3246, 712], [-9076, 1496], [2662, 2526], [8192, -2206], [7912, 1476], [-308, -2330], [17268, -3200], [-18454, 3098], [34090, -7536], [-3806, 9482], [-27852, -2592], [53722, -15056], [-7090, 21300], [-16022, -8556], [-24812, -11380], [508, 4648], [-35760, -310], [201386, 5336], [-140030, 31994], [109180, 31384], [-280298, -13620], [-27416, -47244], [-43786, 47728], [62378, 35754], [-13062, -2996], [-291668, 34368], [-179692, 65804], [-94302, -6300], [-161592, -61236], [427098, -41452], [108190, 32166], [201046, -74124], [626538, -15260], [-170028, -50532], [129380, 39224], [-362688, 88448], [-1201924, 25232], [-107166, 38652], [-644678, 87280], [-820692, -15780], [-390362, -127548], [375296, -182628], [-287022, 36592], [-700000, -138872], [1437912, -135422], [-845730, -187034], [-514420, 60142], [1391814, -103788], [1427804, 16936], [-1379906, 183112], [1131184, 42260], [572394, -111894], [-158918, -78976], [61844, 167646], [1309372, -122472], [220298, 501288], [93124, 393896], [-1401896, -382142], [-874006, 192104], [-1972004, -138652], [2323880, -288920], [-2498832, 170114], [3187380, -7408], [-1596846, 345722], [-1445480, -70934], [-986678, -100740], [2739350, 248452], [-164210, -77852], [5023032, -157156], [-3289938, -14920], [-5201968, 6992], [1432138, -652488], [-513742, 954178], [2546272, 45980], [76710, -646012], [-1441706, 590956], [-2976370, 135824], [1066372, -802620], [-2429756, 141256], [1490072, -711800], [-2050676, -492796], [2358628, -582784], [797412, -942728], [-1023884, 1062188], [3332392, -218942], [4804566, 690300], [4996148, 182400], [-8118440, -437022], [-430648, 68700], [1641750, 90328], [768132, -859544], [-1046842, -826060], [-1156728, -285116], [3377358, -115692], [-70240, -265284], [-8662818, 34772], [-8493270, -214838], [-9154118, -708400], [2451458, 1778538], [-3562812, -1639466], [5621002, -1040384], [13699420, 37520], [-13462640, -424536], [304246, 1563316], [4602044, -1458696], [-12254158, -63614], [2890012, -1524202], [9363460, 772664], [-10956206, -78900], [-10651386, -865100], [-2092718, -625748], [-12337496, 305508], [-17604748, 1044336], [1525710, 1067552], [5920706, -2082948], [8959746, -144486], [-1260052, 2667380], [-887168, 2665930], [-9222852, -644048], [-363076, -938076], [-8370072, 1078904], [15629238, 1621312], [7749638, -1841068], [24649238, 697908], [3686768, 2109698], [-207564, -2125768], [14483992, 919410], [9391914, 1422528], [13028164, -4704], [-37150, -4900692], [16904680, -427184], [14359444, 1222536], [3356254, -648384], [-11691530, 4407782], [-18268868, -1152226], [-21515990, 256272], [-14962252, -344656], [-18823490, 1789222], [-23352648, 2466066], [-8606662, 3672856], [6640076, 2848360], [29394276, -2290276], [-297484, 1417592], [-170950, 1060994], [-115314, 1636574], [9210406, 350212], [5120618, 567984], [-13206862, 2300852], [39252740, -581944], [-55110, -4570208], [-35502734, -557358], [33137848, -2620332], [-27838066, -2470996], [-11939206, -3001030], [31906616, 1465672], [5875416, 3919834]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_33_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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