
// Make newform 1350.3.d.n in Magma, downloaded from the LMFDB on 25 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1350_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1350_d_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_1350_3_d_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_1350_3_d_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, 0, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 0, 3, 0], [0, 1, 0, 1], [0, 3, 0, -3]];
    Rf_basisdens := [1, 1, 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_1350_d();"
function MakeCharacter_1350_d()
    N := 1350;
    order := 2;
    char_gens := [1001, 1027];
    v := [1, 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_1350_d_Hecke();"
function MakeCharacter_1350_d_Hecke(Kf)
    N := 1350;
    order := 2;
    char_gens := [1001, 1027];
    char_values := [[-1, 0, 0, 0], [1, 0, 0, 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, -1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [4, 0, 0, -1], [0, -1, 0, 0], [-5, 0, 0, 2], [0, -4, 3, 0], [8, 0, 0, -4], [0, 5, -6, 0], [0, -8, 12, 0], [8, 0, 0, 5], [-11, 0, 0, -6], [0, -12, -15, 0], [28, 0, 0, -4], [0, -5, 6, 0], [0, -8, 36, 0], [0, -17, -24, 0], [-19, 0, 0, 18], [-8, 0, 0, -21], [0, -27, 6, 0], [-56, 0, 0, -12], [-40, 0, 0, -9], [0, 14, -48, 0], [0, -12, 3, 0], [25, 0, 0, -32], [0, -16, 87, 0], [28, 0, 0, -21], [0, 17, -60, 0], [104, 0, 0, -20], [0, -16, 15, 0], [16, 0, 0, -45], [0, 1, -108, 0], [0, 36, 60, 0], [-28, 0, 0, -21], [0, 0, -99, 0], [80, 0, 0, 12], [16, 0, 0, -40], [-212, 0, 0, 7], [0, 53, -90, 0], [0, -92, -39, 0], [0, -65, 36, 0], [-157, 0, 0, 26], [0, -8, 228, 0], [16, 0, 0, 12], [0, 52, -24, 0], [116, 0, 0, -5], [-4, 0, 0, 40], [184, 0, 0, 4], [0, 9, 228, 0], [-181, 0, 0, 2], [0, -48, -3, 0], [0, -67, 42, 0], [-1, 0, 0, 20], [0, 23, -192, 0], [0, 56, -147, 0], [0, -5, -198, 0], [0, -4, -120, 0], [-160, 0, 0, -24], [238, 0, 0, 16], [0, 56, 276, 0], [-8, 0, 0, 4], [0, -60, 231, 0], [280, 0, 0, 15], [0, -83, -186, 0], [-152, 0, 0, 52], [0, 76, 204, 0], [104, 0, 0, -87], [-344, 0, 0, 64], [0, -120, -120, 0], [32, 0, 0, 72], [0, 12, -372, 0], [0, -19, -222, 0], [292, 0, 0, 24], [-158, 0, 0, 16], [-76, 0, 0, 95], [0, 125, 66, 0], [0, -92, 252, 0], [-11, 0, 0, 118], [0, 72, -339, 0], [-169, 0, 0, 80], [0, -50, -144, 0], [-229, 0, 0, -102], [0, -261, 18, 0], [463, 0, 0, -40], [200, 0, 0, 57], [0, 89, -156, 0], [0, -16, -15, 0], [-167, 0, 0, 84], [0, 24, 384, 0], [-188, 0, 0, 12], [0, -135, 48, 0], [0, -8, -144, 0], [136, 0, 0, 119], [0, -226, 48, 0], [-364, 0, 0, 96], [0, 56, 96, 0], [0, 12, 3, 0], [0, 96, -141, 0], [508, 0, 0, 48], [155, 0, 0, 10], [148, 0, 0, 72], [0, 0, 111, 0], [0, 103, 276, 0], [0, 212, 111, 0], [152, 0, 0, -113], [895, 0, 0, -12], [0, -192, 192, 0], [0, 112, 48, 0], [0, 114, -336, 0], [-433, 0, 0, 40], [-728, 0, 0, 27], [331, 0, 0, 90], [0, 60, 9, 0], [116, 0, 0, -183], [-112, 0, 0, -4], [0, 276, -213, 0], [-800, 0, 0, 57], [0, -67, -558, 0], [0, -160, -249, 0], [0, -152, 492, 0], [773, 0, 0, 66], [-671, 0, 0, -12], [0, 212, -69, 0], [0, 191, -168, 0], [-220, 0, 0, 105], [0, 320, -177, 0], [299, 0, 0, 86], [0, 69, 138, 0], [-236, 0, 0, -96], [19, 0, 0, -42], [128, 0, 0, -3], [0, 51, -174, 0], [8, 0, 0, 24], [229, 0, 0, -126], [0, 256, 393, 0], [-688, 0, 0, -164], [0, -268, -180, 0], [-380, 0, 0, -168], [0, -32, 396, 0], [0, 300, 300, 0], [-232, 0, 0, 179], [0, 320, -171, 0], [-644, 0, 0, -52], [0, 55, 276, 0], [-475, 0, 0, 30], [0, 219, -90, 0], [-77, 0, 0, -198], [0, 40, -288, 0], [-172, 0, 0, 60], [0, 320, 180, 0], [-989, 0, 0, -118], [0, 276, 432, 0], [-332, 0, 0, -83], [0, -157, -378, 0], [328, 0, 0, -60], [0, 21, -1146, 0], [332, 0, 0, -228], [0, 448, -207, 0], [151, 0, 0, -220], [0, 52, 657, 0], [0, -368, -180, 0], [0, -388, 264, 0], [-44, 0, 0, -240], [0, -161, 204, 0], [0, 216, 48, 0], [0, 461, 210, 0], [248, 0, 0, 96], [-635, 0, 0, -126], [887, 0, 0, -84], [0, 164, -504, 0], [0, -98, -768, 0], [968, 0, 0, -180], [0, -163, 654, 0], [-617, 0, 0, 164], [-940, 0, 0, -119], [0, 412, 564, 0], [1364, 0, 0, 80], [0, -116, 219, 0], [-152, 0, 0, -100], [-37, 0, 0, -278], [1432, 0, 0, -140], [0, -167, -864, 0], [283, 0, 0, -6], [0, -376, 396, 0], [0, 104, -84, 0], [0, -452, 396, 0], [466, 0, 0, 144], [856, 0, 0, 184], [-607, 0, 0, 224], [0, -277, 162, 0], [-1151, 0, 0, 232], [0, 305, 228, 0], [-1384, 0, 0, -221], [0, -108, -1260, 0], [0, -351, 240, 0], [0, 4, 120, 0], [143, 0, 0, 276], [-653, 0, 0, -126], [0, -148, -255, 0], [0, 208, -864, 0], [0, -260, -3, 0], [1436, 0, 0, -180], [541, 0, 0, 126], [977, 0, 0, -48], [0, -57, -48, 0], [0, 512, 660, 0], [1304, 0, 0, 176], [0, 271, -384, 0], [0, -48, -1164, 0], [-700, 0, 0, 269], [184, 0, 0, -56], [0, 320, 288, 0], [1408, 0, 0, 45], [0, -231, -1212, 0], [0, -229, 918, 0], [248, 0, 0, -408], [-20, 0, 0, 404], [0, 304, -732, 0], [0, 107, -30, 0], [0, -708, 291, 0], [77, 0, 0, -478], [284, 0, 0, 183], [0, 368, 201, 0], [-1352, 0, 0, -276], [0, 489, -708, 0], [443, 0, 0, 238], [0, 0, 1404, 0], [0, -405, -90, 0], [1684, 0, 0, 64], [0, -320, -540, 0], [307, 0, 0, 314], [884, 0, 0, 171], [200, 0, 0, -329], [0, 160, 648, 0], [-140, 0, 0, 81], [0, -229, -210, 0], [-847, 0, 0, 108], [0, -48, -1176, 0], [0, -240, -1008, 0], [0, 259, 198, 0], [0, -392, 972, 0], [-268, 0, 0, -324], [-560, 0, 0, 93], [227, 0, 0, 354], [0, 52, -1764, 0], [0, -99, -918, 0], [-1232, 0, 0, 145], [0, -73, 408, 0], [-424, 0, 0, 536], [0, -59, -714, 0], [2251, 0, 0, -18], [0, 548, -264, 0], [0, 67, 1290, 0], [329, 0, 0, 264], [0, -388, -765, 0], [0, -119, 1248, 0], [896, 0, 0, -384], [1660, 0, 0, 36], [0, 452, 180, 0], [583, 0, 0, 336], [1744, 0, 0, 283], [0, 672, 72, 0], [350, 0, 0, -432], [277, 0, 0, -166], [0, 332, -807, 0], [-688, 0, 0, -132], [0, -656, -585, 0], [0, 156, -396, 0], [-548, 0, 0, -36], [0, -156, -396, 0], [2411, 0, 0, -98], [-992, 0, 0, 279], [-2111, 0, 0, 108], [1520, 0, 0, 393], [415, 0, 0, 160], [-752, 0, 0, 468], [0, -160, -396, 0], [2318, 0, 0, -160], [-655, 0, 0, 512], [0, 569, -804, 0], [0, -781, -606, 0], [-2656, 0, 0, -117], [0, -155, -150, 0], [-1741, 0, 0, 174], [-512, 0, 0, 381], [0, -101, -258, 0], [433, 0, 0, 308], [0, 1036, 108, 0], [-1336, 0, 0, 276], [0, 260, 1863, 0], [0, -492, 867, 0], [0, 272, -36, 0], [0, 400, 843, 0], [0, 289, -744, 0], [-1208, 0, 0, -108], [0, -1148, -63, 0], [416, 0, 0, 635], [0, 0, -267, 0], [0, 240, -1500, 0], [-32, 0, 0, -300], [1009, 0, 0, 96], [0, -380, -600, 0], [-1372, 0, 0, -431]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1350_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1350_3_d_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_1350_3_d_n(:prec:=4)
    chi := MakeCharacter_1350_d();
    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_1350_3_d_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_1350_3_d_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![-2, -8, 1]>,<11,R![9, 0, 1]>],Snew);
    return Vf;
end function;