
// Make newform 38.6.c.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_38_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_38_c_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_38_6_c_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_38_6_c_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 := [900, -3990, 17689, -60, 133, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0], [-60, 0, 0, 2, 0, 0], [0, 17689, -30, 133, 0, 1], [11837, -30, 133, 0, 1, 0], [355110, -1574321, 6660, -11837, 0, -89]];
    Rf_basisdens := [1, 1, 133, 3990, 133, 3990];
    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_38_c();"
function MakeCharacter_38_c()
    N := 38;
    order := 3;
    char_gens := [21];
    v := [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_38_c_Hecke();"
function MakeCharacter_38_c_Hecke(Kf)
    N := 38;
    order := 3;
    char_gens := [21];
    char_values := [[0, 0, 0, -1, 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 := 6;
    raw_aps := [[4, 0, 0, -4, 0, 0], [-5, 1, 1, 5, 0, 0], [5, -1, -1, -5, 0, -1], [-104, 0, 4, 0, 0, 0], [-156, 0, 1, 0, -1, 0], [0, -15, 0, -247, 5, -5], [-335, 45, 45, 335, 0, 5], [893, 19, 0, 114, 0, -19], [0, -14, 0, -711, -35, 35], [0, -61, 0, 505, -29, 29], [48, 0, 356, 0, 54, 0], [3326, 0, -94, 0, 52, 0], [-6463, -212, -212, 6463, 0, -162], [-1701, 202, 202, 1701, 0, 45], [0, 166, 0, 2409, 199, -199], [0, 319, 0, -1199, 441, -441], [-125, -303, -303, 125, 0, 50], [0, -243, 0, 6481, 231, -231], [0, -1781, 0, 20665, -158, 158], [1951, -2818, -2818, -1951, 0, -93], [6137, -1132, -1132, -6137, 0, 336], [26487, -3960, -3960, -26487, 0, 697], [-55748, 0, 3447, 0, -457, 0], [0, 1455, 0, -55439, 89, -89], [-29047, 3472, 3472, 29047, 0, 526], [0, 2191, 0, 1993, 1203, -1203], [4040, 0, -1238, 0, 362, 0], [23228, 0, 4288, 0, 372, 0], [-126459, -5311, -5311, 126459, 0, -805], [-68046, 0, -1451, 0, -2059, 0], [0, 4402, 0, 104009, -1551, 1551], [187515, 6873, 6873, -187515, 0, 576], [0, -1624, 0, 36409, 1366, -1366], [0, 3799, 0, 213849, -880, 880], [-36787, -9837, -9837, 36787, 0, -1451], [-178248, 0, 2322, 0, 578, 0], [87213, -13349, -13349, -87213, 0, 3987], [274748, 0, 11427, 0, 1833, 0], [0, -3330, 0, -140679, 3651, -3651], [170445, 25485, 25485, -170445, 0, 3621], [-539332, 0, 5403, 0, 829, 0], [0, 17135, 0, 132657, -3711, 3711], [-576896, 0, 10316, 0, -4308, 0], [114921, -7141, -7141, -114921, 0, -8995], [-105666, 0, -15374, 0, 6416, 0], [0, -12804, 0, 315385, 4389, -4389], [739235, 6848, 6848, -739235, 0, -6987], [437159, -11964, -11964, -437159, 0, 3611], [-300660, 0, -24931, 0, 4855, 0], [-159282, 0, 24240, 0, 4082, 0], [-118959, 28566, 28566, 118959, 0, 9996], [411312, 0, 32370, 0, 12756, 0], [0, -29416, 0, -576695, -598, 598], [0, 7945, 0, 693593, 10526, -10526], [0, -13592, 0, 305921, 4652, -4652], [-268689, -5898, -5898, 268689, 0, -18963], [-997051, -45495, -45495, 997051, 0, -809], [-27337, 72154, 72154, 27337, 0, -12983], [1476542, 0, -37888, 0, 8254, 0], [0, 22880, 0, -1299247, 9468, -9468], [-644557, 38501, 38501, 644557, 0, -6516], [-44690, 0, 14532, 0, 28526, 0], [104587, -51469, -51469, -104587, 0, 32560], [-236120, 0, 11564, 0, -27114, 0], [0, 42444, 0, 212345, -17038, 17038], [0, -102555, 0, 178569, -3183, 3183], [428548, 0, -24789, 0, -31367, 0], [711497, 19642, 19642, -711497, 0, -10772], [31571, 81685, 81685, -31571, 0, 12234], [710726, 0, 43652, 0, 26374, 0], [659778, 0, -65991, 0, -27231, 0], [1338831, -20448, -20448, -1338831, 0, 5391], [0, -29980, 0, 1321913, -12251, 12251], [-1857274, 0, 8010, 0, 37230, 0], [-1796148, 0, -61628, 0, 11464, 0], [583815, -129428, -129428, -583815, 0, -6667], [0, 98085, 0, -1390399, 6787, -6787], [753581, -47403, -47403, -753581, 0, 35345], [-403847, 90904, 90904, 403847, 0, -28670], [0, 122714, 0, 76929, 51138, -51138], [1082004, 0, -47268, 0, -45624, 0], [-1509003, -140979, -140979, 1509003, 0, -55391], [0, 42414, 0, -1497607, -2375, 2375], [0, -128031, 0, 3184073, 13805, -13805], [-3310785, -50406, -50406, 3310785, 0, 39763], [0, -237151, 0, -1974167, -10526, 10526], [-368494, 0, -253633, 0, 5255, 0], [4096850, 0, -50091, 0, -20733, 0], [-3323179, -10477, -10477, 3323179, 0, 92261], [-779040, 0, -112720, 0, 24438, 0], [-1689684, 0, 251699, 0, 44857, 0], [0, 332966, 0, 1438921, 3823, -3823], [600184, 0, -179710, 0, -23098, 0], [504347, 189692, 189692, -504347, 0, -55711], [-2176069, 71905, 71905, 2176069, 0, -24158], [0, -18282, 0, -7931687, -15655, 15655], [0, -288933, 0, 2414393, -5753, 5753], [557538, 0, -21287, 0, 105935, 0], [0, -224424, 0, 39489, 68527, -68527], [0, 129375, 0, -2710439, -71469, 71469], [0, 114038, 0, 7160753, -46289, 46289], [0, 257261, 0, 5240465, -43809, 43809], [-2664660, 0, 249153, 0, -74817, 0], [7058738, 0, 273506, 0, 39848, 0], [-2332, 0, -50229, 0, 123981, 0], [542274, 0, 529845, 0, 35057, 0], [669499, -102744, -102744, -669499, 0, 5741], [0, -383338, 0, 4623929, 41316, -41316], [0, -357042, 0, -6260791, -42755, 42755], [544986, 0, -282751, 0, -74175, 0], [-5207104, 0, -367368, 0, -64392, 0], [4089341, -164969, -164969, -4089341, 0, -14519], [0, 58266, 0, -9152055, -49620, 49620], [-7088116, 0, -93160, 0, -45776, 0], [0, 119154, 0, -1236791, 148227, -148227], [5380849, -667314, -667314, -5380849, 0, 81374], [7631947, -150317, -150317, -7631947, 0, -123244], [-8216792, 0, -393110, 0, -80054, 0], [8636502, 0, 259800, 0, -30858, 0], [0, -25796, 0, -2570031, 178759, -178759], [0, 275975, 0, -2073911, 147083, -147083], [-7256326, 0, -5334, 0, -114612, 0], [1016510, 0, -245314, 0, 4328, 0], [-5698660, 0, -389494, 0, 101504, 0], [2243476, 0, 268096, 0, 35376, 0], [-10027947, -68251, -68251, 10027947, 0, 64159], [0, -52481, 0, -6466287, -22819, 22819], [-6080425, 730408, 730408, 6080425, 0, 112527], [13889087, 427366, 427366, -13889087, 0, 66781], [-3633866, 0, 730006, 0, -19056, 0], [4527963, -383799, -383799, -4527963, 0, -35378], [20009087, 161528, 161528, -20009087, 0, -31933], [0, 27846, 0, 7135881, -164939, 164939], [3728837, 248521, 248521, -3728837, 0, -24923], [-854198, 0, -102561, 0, 168095, 0], [0, 508793, 0, 14887593, -88203, 88203], [0, -320367, 0, 578721, 264171, -264171], [722012, 0, -308533, 0, -102371, 0], [-139946, 0, 831114, 0, -139660, 0], [-866118, 0, -39765, 0, 377619, 0], [0, -150728, 0, 13249553, -60957, 60957], [0, 449925, 0, 1909593, -134307, 134307], [0, -1088064, 0, -2861271, -80723, 80723], [0, -218759, 0, -7644823, 505898, -505898], [-6818274, 0, -540422, 0, -53882, 0], [-513169, 414638, 414638, 513169, 0, -273763], [8462149, 421529, 421529, -8462149, 0, -254327], [2593401, 1058610, 1058610, -2593401, 0, 10218], [0, 142055, 0, 5231737, 257438, -257438], [-2416016, 0, -293088, 0, 215702, 0], [933413, 1197109, 1197109, -933413, 0, 429211], [-10812558, 0, -624039, 0, 208557, 0], [0, -115627, 0, 22876425, -208626, 208626], [0, -742294, 0, -17077559, -128093, 128093], [-22201341, -642117, -642117, 22201341, 0, -21536], [17532432, 0, -515478, 0, -94518, 0], [-10955832, 0, -767454, 0, 52718, 0], [17618513, -443254, -443254, -17618513, 0, 239786], [0, -336624, 0, 39273265, -3228, 3228], [0, 1189883, 0, -12861055, -230223, 230223], [16505683, 169638, 169638, -16505683, 0, -290707], [-27658951, -155350, -155350, 27658951, 0, 51638], [12266863, 110798, 110798, -12266863, 0, 273175], [20396195, 239807, 239807, -20396195, 0, -423940], [12831106, 0, 175975, 0, -159017, 0], [-10559793, -935808, -935808, 10559793, 0, -400227], [8724343, -221312, -221312, -8724343, 0, -297379], [0, -390715, 0, 10876385, 237727, -237727]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_38_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_38_6_c_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_38_6_c_a(:prec:=6)
    chi := MakeCharacter_38_c();
    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_38_6_c_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_38_6_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_38_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![7700625, 1268175, 250474, -1305, 682, 15, 1]>],Snew);
    return Vf;
end function;