
// Make newform 1350.3.i.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1350_i();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1350_i_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_i_b();".
// 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_i_b();".
// 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 := [4, 0, -2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 2, 2];
    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_i();"
function MakeCharacter_1350_i()
    N := 1350;
    order := 6;
    char_gens := [1001, 1027];
    v := [1, 6];
    // 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_i_Hecke();"
function MakeCharacter_1350_i_Hecke(Kf)
    N := 1350;
    order := 6;
    char_gens := [1001, 1027];
    char_values := [[1, 0, -1, 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, -1, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0], [0, 3, -1, 3], [-6, -3, 3, 3], [5, 6, -5, -12], [-6, 0, 12, -6], [-10, 12, 0, -6], [3, 3, 3, 0], [-6, 6, 3, -6], [19, 9, -19, -18], [-32, 12, 0, -6], [21, 18, 21, 0], [0, -9, 23, -9], [18, -21, -9, 21], [-30, 0, 60, -30], [-21, -39, -21, 0], [0, 18, 31, 18], [53, -9, -53, 18], [-30, 0, 60, 24], [52, 36, 0, -18], [0, -15, 7, -15], [-126, 15, 63, -15], [-30, 0, 60, -66], [0, 42, -7, 42], [6, 108, -3, -108], [-37, 27, 37, -54], [60, 0, -120, -48], [-16, 108, 0, -54], [9, 132, 9, 0], [34, -36, 0, 18], [-69, 81, -69, 0], [222, 30, -111, -30], [-11, -39, 11, 78], [-3, 78, -3, 0], [0, 45, 175, 45], [-109, -36, 109, 72], [58, 156, 0, -78], [-99, 87, -99, 0], [18, 60, -9, -60], [-96, 0, 192, 84], [140, -84, 0, 42], [6, 9, -3, -9], [125, -90, -125, 180], [-24, 0, 48, 84], [80, -60, 0, 30], [103, 21, -103, -42], [0, -45, 203, -45], [54, 87, -27, -87], [-143, -108, 143, 216], [-48, 0, 96, -48], [9, -51, 9, 0], [0, 24, -143, 24], [48, 0, -96, -96], [-27, 24, -27, 0], [462, -45, -231, 45], [30, 0, -60, -6], [-34, 252, 0, -126], [0, 0, -49, 0], [210, 114, -105, -114], [-145, -81, 145, 162], [-87, -96, -87, 0], [-110, -36, 0, 18], [93, -63, 93, 0], [0, 12, -397, 12], [-330, 126, 165, -126], [0, 93, -245, 93], [335, 12, -335, -24], [207, 159, 207, 0], [0, -84, -107, -84], [-210, 102, 105, -102], [36, 0, -72, 252], [0, -45, 77, -45], [113, -138, -113, 276], [-328, 132, 0, -66], [-183, -297, -183, 0], [78, 72, -39, -72], [124, 108, 0, -54], [-195, 54, -195, 0], [385, 24, -385, -48], [153, -195, 153, 0], [0, 6, -269, 6], [276, 0, -552, -156], [-344, 108, 0, -54], [0, -171, 139, -171], [162, -489, -81, 489], [-54, 0, 108, -450], [0, -126, 401, -126], [138, 78, -69, -78], [-283, -93, 283, 186], [60, 0, -120, -516], [-558, -123, 279, 123], [190, 132, 0, -66], [-345, 249, -345, 0], [-35, -243, 35, 486], [-342, 0, 684, -216], [-195, -378, -195, 0], [168, 0, -336, 60], [-488, -324, 0, 162], [-274, -192, 0, 96], [0, 207, 41, 207], [318, 0, -636, 102], [-333, -21, -333, 0], [6, 180, -3, -180], [7, 33, -7, -66], [88, 36, 0, -18], [-582, -45, 291, 45], [-78, 0, 156, -150], [483, 33, 483, 0], [0, 18, 751, 18], [-745, 183, 745, -366], [-56, 468, 0, -234], [-21, -162, -21, 0], [0, 9, 175, 9], [-58, -84, 0, 42], [318, 24, -159, -24], [593, -81, -593, 162], [-36, 0, 72, 252], [-375, 84, -375, 0], [42, -279, -21, 279], [-395, 252, 395, -504], [0, -174, 137, -174], [66, 288, -33, -288], [-180, 0, 360, 576], [0, -135, -707, -135], [-366, 0, 732, 102], [0, 336, 349, 336], [180, 0, -360, -144], [0, -81, -643, -81], [-55, 270, 55, -540], [272, -540, 0, 270], [297, 375, 297, 0], [241, 429, -241, -858], [-866, -144, 0, 72], [369, -222, 369, 0], [157, -204, -157, 408], [-234, 0, 468, 90], [359, -189, -359, 378], [63, -858, 63, 0], [6, 0, -12, -174], [74, 540, 0, -270], [-174, -774, 87, 774], [-1579, 15, 1579, -30], [444, 0, -888, -132], [980, 84, 0, -42], [54, -771, -27, 771], [0, 162, 77, 162], [990, 42, -495, -42], [-245, -291, 245, 582], [-528, 0, 1056, -276], [317, 282, -317, -564], [-510, 0, 1020, 462], [838, -444, 0, 222], [87, -513, 87, 0], [0, -345, 335, -345], [-198, 777, 99, -777], [38, -1044, 0, 522], [-558, 102, 279, -102], [-896, -348, 0, 174], [-165, 456, -165, 0], [-450, -273, 225, 273], [-342, 0, 684, -90], [629, 243, -629, -486], [-90, 0, 180, -576], [-15, 1092, -15, 0], [30, 567, -15, -567], [650, -180, 0, 90], [0, -396, 275, -396], [-1204, 324, 0, -162], [-489, -270, -489, 0], [1038, 213, -519, -213], [307, 270, -307, -540], [129, 369, 129, 0], [0, 498, 89, 498], [769, 489, -769, -978], [-273, -12, -273, 0], [0, 81, 1453, 81], [-18, 0, 36, -810], [-818, -84, 0, 42], [0, 432, -599, 432], [0, -357, 467, -357], [-282, -171, 141, 171], [215, 540, -215, -1080], [-450, 0, 900, 486], [429, -405, 429, 0], [-894, 918, 447, -918], [574, 288, 0, -144], [0, -249, 251, -249], [-635, 552, 635, -1104], [204, 0, -408, 1176], [1144, 204, 0, -102], [486, 555, -243, -555], [230, -300, 0, 150], [438, -396, -219, 396], [-168, 0, 336, -636], [-735, -204, -735, 0], [-1157, -6, 1157, 12], [0, 60, -61, 60], [-438, 360, 219, -360], [-60, 0, 120, 336], [-621, -204, -621, 0], [0, -519, -875, -519], [-553, 240, 553, -480], [0, 72, 517, 72], [-276, 0, 552, -420], [-78, 0, 156, -834], [1430, -276, 0, 138], [-471, -405, -471, 0], [942, 0, -471, 0], [97, -327, -97, 654], [148, -708, 0, 354], [-471, 366, -471, 0], [0, 63, -193, 63], [1110, -225, -555, 225], [-189, -1095, -189, 0], [0, -432, -923, -432], [161, 279, -161, -558], [1818, -762, -909, 762], [-12, 0, 24, 996], [723, -618, 723, 0], [715, -150, -715, 300], [-395, 297, 395, -594], [-1455, -54, -1455, 0], [214, -1980, 0, 990], [441, 15, 441, 0], [0, 444, -731, 444], [1314, -264, -657, 264], [84, 0, -168, 1164], [0, -429, 161, -429], [-1662, -3, 831, 3], [1343, -96, -1343, 192], [-214, -1116, 0, 558], [1351, -495, -1351, 990], [507, -396, 507, 0], [0, 543, -379, 543], [-102, 903, 51, -903], [-5, 390, 5, -780], [450, 0, -900, -738], [963, -447, 963, 0], [-168, 0, 336, -888], [1722, -765, -861, 765], [-286, -612, 0, 306], [251, -873, -251, 1746], [236, -396, 0, 198], [435, 786, 435, 0], [-762, -399, 381, 399], [730, 1788, 0, -894], [1173, 441, 1173, 0], [-1925, 153, 1925, -306], [1008, 0, -2016, 972], [233, 90, -233, -180], [-90, 0, 180, 1242], [975, -357, 975, 0], [0, 756, 301, 756], [-1710, 852, 855, -852], [726, 0, -1452, -624], [-1528, -324, 0, 162], [0, 891, 689, 891], [-792, 0, 1584, 324], [2248, -108, 0, 54], [0, -129, -2599, -129], [-54, 1527, 27, -1527], [1621, -396, -1621, 792], [724, -1500, 0, 750], [15, 522, 15, 0], [0, 801, 319, 801], [-822, 0, 1644, 510], [990, 804, -495, -804], [-199, 423, 199, -846], [783, -66, 783, 0], [-1037, 870, 1037, -1740], [-1058, -1356, 0, 678], [0, 468, 203, 468], [-791, -819, 791, 1638], [-1675, -450, 1675, 900], [358, -1044, 0, 522], [-1119, 387, -1119, 0], [0, -954, 427, -954], [560, 900, 0, -450], [258, 1161, -129, -1161], [-1551, -585, -1551, 0], [2161, -351, -2161, 702], [-1578, -969, 789, 969], [0, -360, -707, -360], [1583, 207, -1583, -414], [450, 0, -900, 144], [-332, -1740, 0, 870], [-1527, 408, -1527, 0], [0, -315, 2569, -315], [576, 0, -1152, -288], [-2502, -618, 1251, 618], [42, 0, -84, 1104], [93, 156, 93, 0], [693, -879, 693, 0], [0, 108, -1417, 108], [-597, -588, -597, 0], [0, 273, 2887, 273], [462, 810, -231, -810], [-108, 0, 216, 504], [0, 87, 1055, 87], [-373, -480, 373, 960], [522, 0, -1044, -738], [-2770, 180, 0, -90]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1350_i_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1350_3_i_b();".
// 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_i_b(:prec:=4)
    chi := MakeCharacter_1350_i();
    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_i_b();".
// 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_i_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![2809, -106, 57, 2, 1]>],Snew);
    return Vf;
end function;