
// Make newform 1350.3.b.a in Magma, downloaded from the LMFDB on 11 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1350_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1350_b_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_b_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_1350_3_b_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
        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, 1, 0], [0, 1, 0, 1], [0, 1, 0, -1]];
    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_b();"
function MakeCharacter_1350_b()
    N := 1350;
    order := 2;
    char_gens := [1001, 1027];
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1350_b_Hecke();"
function MakeCharacter_1350_b_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, 0, -1], [0, 0, 0, 0], [0, 0, 0, 0], [0, 4, -3, 0], [0, 3, 0, 0], [0, 5, -6, 0], [-12, 0, 0, 3], [-8, 0, 0, 12], [-15, 0, 0, 6], [0, -24, 12, 0], [8, 0, 0, 15], [0, -11, -18, 0], [0, 36, 15, 0], [0, -28, 12, 0], [-15, 0, 0, 6], [24, 0, 0, -36], [0, -51, -24, 0], [-19, 0, 0, 54], [0, -8, -63, 0], [0, 81, -6, 0], [0, 56, 36, 0], [40, 0, 0, 27], [-42, 0, 0, 48], [0, -36, 3, 0], [0, 25, -96, 0], [0, 48, -87, 0], [0, -28, 63, 0], [51, 0, 0, -60], [-104, 0, 0, 60], [48, 0, 0, -15], [0, 16, -135, 0], [0, -3, 108, 0], [108, 0, 0, 60], [28, 0, 0, 63], [0, 0, -99, 0], [80, 0, 0, 36], [0, 16, -120, 0], [0, 212, -21, 0], [159, 0, 0, -90], [276, 0, 0, 39], [0, -195, 36, 0], [-157, 0, 0, 78], [0, 24, -228, 0], [0, -16, -36, 0], [156, 0, 0, -24], [-116, 0, 0, 15], [-4, 0, 0, 120], [0, -184, -12, 0], [27, 0, 0, 228], [181, 0, 0, -6], [144, 0, 0, 3], [0, -201, 42, 0], [-1, 0, 0, 60], [0, -69, 192, 0], [168, 0, 0, -147], [15, 0, 0, 198], [0, -12, -120, 0], [-160, 0, 0, -72], [0, 238, 48, 0], [0, -168, -276, 0], [0, 8, -12, 0], [180, 0, 0, -231], [0, 280, 45, 0], [0, 249, 186, 0], [0, 152, -156, 0], [228, 0, 0, 204], [104, 0, 0, -261], [0, -344, 192, 0], [-360, 0, 0, -120], [-32, 0, 0, -216], [-36, 0, 0, 372], [0, -57, -222, 0], [0, 292, 72, 0], [0, 158, -48, 0], [76, 0, 0, -285], [-375, 0, 0, -66], [0, -276, 252, 0], [0, -11, 354, 0], [0, -216, 339, 0], [169, 0, 0, -240], [0, -150, -144, 0], [-229, 0, 0, -306], [0, 783, -18, 0], [0, -463, 120, 0], [-200, 0, 0, -171], [-267, 0, 0, 156], [0, -48, -15, 0], [0, -167, 252, 0], [0, -72, -384, 0], [0, 188, -36, 0], [-405, 0, 0, 48], [0, -24, -144, 0], [0, 136, 357, 0], [0, 678, -48, 0], [364, 0, 0, -288], [-168, 0, 0, -96], [0, 36, 3, 0], [0, -288, 141, 0], [0, -508, -144, 0], [155, 0, 0, 30], [0, 148, 216, 0], [0, 0, 0, 111], [-309, 0, 0, -276], [0, 636, 111, 0], [152, 0, 0, -339], [0, 895, -36, 0], [-576, 0, 0, 192], [-336, 0, 0, -48], [0, 342, -336, 0], [-433, 0, 0, 120], [0, -728, 81, 0], [0, -331, -270, 0], [180, 0, 0, 9], [-116, 0, 0, 549], [-112, 0, 0, -12], [0, -828, 213, 0], [0, 800, -171, 0], [-201, 0, 0, -558], [480, 0, 0, 249], [0, -456, 492, 0], [773, 0, 0, 198], [0, 671, 36, 0], [636, 0, 0, -69], [-573, 0, 0, 168], [-220, 0, 0, 315], [0, -960, 177, 0], [-299, 0, 0, -258], [0, 207, 138, 0], [0, -236, -288, 0], [0, -19, 126, 0], [-128, 0, 0, 9], [-153, 0, 0, 174], [8, 0, 0, 72], [0, 229, -378, 0], [0, -768, -393, 0], [688, 0, 0, 492], [804, 0, 0, 180], [0, -380, -504, 0], [-96, 0, 0, 396], [0, 900, 300, 0], [-232, 0, 0, 537], [0, -960, 171, 0], [0, 644, 156, 0], [165, 0, 0, 276], [475, 0, 0, -90], [0, 657, -90, 0], [0, 77, 594, 0], [120, 0, 0, -288], [172, 0, 0, -180], [-960, 0, 0, -180], [0, -989, -354, 0], [0, -828, -432, 0], [0, 332, 249, 0], [-471, 0, 0, -378], [0, 328, -180, 0], [0, -63, 1146, 0], [-332, 0, 0, 684], [0, 1344, -207, 0], [0, 151, -660, 0], [0, -156, -657, 0], [-1104, 0, 0, -180], [1164, 0, 0, -264], [0, -44, -720, 0], [0, 483, -204, 0], [648, 0, 0, 48], [-1383, 0, 0, -210], [248, 0, 0, 288], [0, -635, -378, 0], [-887, 0, 0, 252], [-492, 0, 0, 504], [0, -294, -768, 0], [968, 0, 0, -540], [0, 489, -654, 0], [0, 617, -492, 0], [940, 0, 0, 357], [0, 1236, 564, 0], [1364, 0, 0, 240], [0, 348, -219, 0], [0, 152, 300, 0], [37, 0, 0, 834], [0, 1432, -420, 0], [0, 501, 864, 0], [0, -283, 18, 0], [-1128, 0, 0, 396], [-312, 0, 0, 84], [0, -1356, 396, 0], [0, 466, 432, 0], [0, -856, -552, 0], [607, 0, 0, -672], [0, 831, -162, 0], [0, 1151, -696, 0], [-915, 0, 0, -228], [-1384, 0, 0, -663], [0, 324, 1260, 0], [-1053, 0, 0, 240], [-12, 0, 0, -120], [143, 0, 0, 828], [0, 653, 378, 0], [-444, 0, 0, -255], [-624, 0, 0, 864], [0, -780, -3, 0], [1436, 0, 0, -540], [0, 541, 378, 0], [-977, 0, 0, 144], [0, -171, -48, 0], [1536, 0, 0, 660], [-1304, 0, 0, -528], [-813, 0, 0, 384], [0, -144, -1164, 0], [-700, 0, 0, 807], [0, 184, -168, 0], [0, -960, -288, 0], [0, -1408, -135, 0], [-693, 0, 0, -1212], [0, -687, 918, 0], [248, 0, 0, -1224], [0, -20, 1212, 0], [0, -912, 732, 0], [321, 0, 0, -30], [2124, 0, 0, -291], [77, 0, 0, -1434], [-284, 0, 0, -549], [0, 1104, 201, 0], [0, 1352, 828, 0], [1467, 0, 0, -708], [-443, 0, 0, -714], [0, 0, 0, -1404], [0, -1215, -90, 0], [0, 1684, 192, 0], [0, 960, 540, 0], [0, -307, -942, 0], [-884, 0, 0, -513], [200, 0, 0, -987], [0, -480, -648, 0], [0, 140, -243, 0], [-687, 0, 0, -210], [847, 0, 0, -324], [144, 0, 0, 1176], [0, -720, -1008, 0], [0, -777, -198, 0], [1176, 0, 0, -972], [-268, 0, 0, -972], [0, 560, -279, 0], [-227, 0, 0, -1062], [-156, 0, 0, 1764], [0, -297, -918, 0], [0, -1232, 435, 0], [0, 219, -408, 0], [424, 0, 0, -1608], [177, 0, 0, 714], [0, 2251, -54, 0], [0, -1644, 264, 0], [201, 0, 0, 1290], [-329, 0, 0, -792], [1164, 0, 0, 765], [0, -357, 1248, 0], [896, 0, 0, -1152], [0, 1660, 108, 0], [1356, 0, 0, 180], [0, 583, 1008, 0], [0, -1744, -849, 0], [2016, 0, 0, 72], [-350, 0, 0, 1296], [0, -277, 498, 0], [996, 0, 0, -807], [688, 0, 0, 396], [0, -1968, -585, 0], [0, -468, 396, 0], [0, 548, 108, 0], [468, 0, 0, 396], [2411, 0, 0, -294], [0, -992, 837, 0], [0, 2111, -324, 0], [-1520, 0, 0, -1179], [0, 415, 480, 0], [0, 752, -1404, 0], [-480, 0, 0, -396], [-2318, 0, 0, 480], [-655, 0, 0, 1536], [0, -1707, 804, 0], [2343, 0, 0, 606], [-2656, 0, 0, -351], [-465, 0, 0, -150], [-1741, 0, 0, 522], [0, -512, 1143, 0], [0, 303, 258, 0], [0, -433, -924, 0], [3108, 0, 0, 108], [1336, 0, 0, -828], [0, 780, 1863, 0], [0, 1476, -867, 0], [816, 0, 0, -36], [-1200, 0, 0, -843], [0, -867, 744, 0], [0, 1208, 324, 0], [0, -3444, -63, 0], [416, 0, 0, 1905], [0, 0, 0, 267], [0, 720, -1500, 0], [0, -32, -900, 0], [0, -1009, -288, 0], [-1140, 0, 0, -600], [1372, 0, 0, 1293]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1350_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1350_3_b_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_1350_3_b_a(:prec:=4)
    chi := MakeCharacter_1350_b();
    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_b_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_1350_3_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![4, 0, 68, 0, 1]>,<11,R![9, 0, 1]>,<17,R![126, 24, 1]>],Snew);
    return Vf;
end function;