
// Make newform 38.4.c.c in Magma, downloaded from the LMFDB on 25 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_4_c_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_38_4_c_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 := [225, -945, 3984, 33, 64, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [-60480, 945, -3984, 4096, -64, 1], [-3641036, 19845, -83664, 1339, -1344, 21], [4800, 5334576, 64832, 85696, -1339, 1344], [-54410265, 229386768, 1517621, 3684928, -57577, 57792]];
    Rf_basisdens := [1, 1, 254031, 169354, 1270155, 2540310];
    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, 0, -1, 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 := 4;
    raw_aps := [[2, 0, 0, 0, -2, 0], [-2, -1, -1, 0, 2, 0], [-1, -1, -1, 0, 1, -1], [9, 0, 1, 0, 0, 0], [2, 0, -1, 3, 0, 0], [0, -4, 0, -1, 44, 1], [-18, 0, 0, 0, 18, -3], [-6, 13, 8, -2, 26, 3], [0, -5, 0, -1, 17, 1], [0, -25, 0, -5, -35, 5], [-11, 0, 23, -6, 0, 0], [-59, 0, 5, 6, 0, 0], [147, -30, -30, 0, -147, -4], [-8, 42, 42, 0, 8, 7], [0, 19, 0, 5, -85, -5], [0, 24, 0, -5, 0, 5], [-358, -1, -1, 0, 358, -8], [0, 29, 0, -1, -337, 1], [0, -67, 0, 16, 320, -16], [710, -22, -22, 0, -710, 17], [221, -14, -14, 0, -221, 10], [570, 68, 68, 0, -570, -29], [168, 0, -105, 21, 0, 0], [0, -88, 0, 5, 262, -5], [-247, 202, 202, 0, 247, 42], [0, -87, 0, 43, 75, -43], [616, 0, 14, 98, 0, 0], [-310, 0, 50, 60, 0, 0], [-626, -48, -48, 0, 626, -31], [913, 0, 16, -41, 0, 0], [0, -38, 0, -9, -462, 9], [276, -3, -3, 0, -276, -72], [0, 44, 0, -50, -1745, 50], [0, -115, 0, -62, -58, 62], [193, 163, 163, 0, -193, 113], [1901, 0, -261, -78, 0, 0], [-1254, -40, -40, 0, 1254, -79], [-352, 0, 51, -27, 0, 0], [0, 140, 0, -151, 46, 151], [-1436, 244, 244, 0, 1436, -1], [-148, 0, -31, -173, 0, 0], [0, 171, 0, -155, -425, 155], [1900, 0, 100, 120, 0, 0], [-230, -588, -588, 0, 230, -7], [-827, 0, 445, -26, 0, 0], [0, 126, 0, 171, -962, -171], [2162, -182, -182, 0, -2162, -35], [-3031, -131, -131, 0, 3031, -115], [-1002, 0, -507, 121, 0, 0], [-376, 0, 216, -186, 0, 0], [2769, -6, -6, 0, -2769, -150], [-1604, 0, -584, -40, 0, 0], [0, -432, 0, -116, 1057, 116], [0, 373, 0, 38, -1078, -38], [0, 242, 0, 198, 1957, -198], [-135, 495, 495, 0, 135, 27], [2842, 100, 100, 0, -2842, -31], [-577, 493, 493, 0, 577, 51], [2153, 0, 243, 356, 0, 0], [0, 186, 0, -226, -4851, 226], [-638, 111, 111, 0, 638, -316], [-3453, 0, -759, 192, 0, 0], [532, 723, 723, 0, -532, -10], [1627, 0, -47, 78, 0, 0], [0, 182, 0, -88, 2951, 88], [0, -260, 0, -17, 5564, 17], [-4332, 0, -347, 215, 0, 0], [-3629, -726, -726, 0, 3629, -20], [8076, 249, 249, 0, -8076, -40], [332, 0, 240, -118, 0, 0], [6087, 0, 1038, -273, 0, 0], [4179, -81, -81, 0, -4179, 117], [0, 57, 0, -497, -2249, 497], [1728, 0, -752, 170, 0, 0], [5500, 0, 386, 326, 0, 0], [-1645, 341, 341, 0, 1645, 339], [0, 980, 0, 245, 958, -245], [-389, 21, 21, 0, 389, -3], [-3581, 1132, 1132, 0, 3581, 202], [0, 88, 0, 128, -2271, -128], [2536, 0, -1268, -424, 0, 0], [749, -17, -17, 0, -749, -523], [0, 98, 0, -133, -9962, 133], [0, -94, 0, 29, 8048, -29], [6059, -749, -749, 0, -6059, -67], [0, -431, 0, 114, 5234, -114], [787, 0, 562, 687, 0, 0], [6759, 0, -1094, -1, 0, 0], [5056, 988, 988, 0, -5056, 567], [6636, 0, 406, -350, 0, 0], [1302, 0, -903, -203, 0, 0], [0, -272, 0, -147, -2914, 147], [-2865, 0, 253, -710, 0, 0], [-2084, -110, -110, 0, 2084, -489], [-9928, -149, -149, 0, 9928, -750], [0, 49, 0, 655, -1621, -655], [0, 1680, 0, -423, 10314, 423], [-8547, 0, 1554, 581, 0, 0], [0, -802, 0, -79, -4708, 79], [0, -516, 0, -603, -5462, 603], [0, 1358, 0, -483, 2276, 483], [0, -1448, 0, 381, -11470, -381], [-10478, 0, -1439, 257, 0, 0], [-8044, 0, 704, -82, 0, 0], [2800, 0, 749, -749, 0, 0], [-599, 0, 212, 547, 0, 0], [740, -1786, -1786, 0, -740, -245], [0, -2922, 0, 554, -5511, -554], [0, 2001, 0, -297, -4005, 297], [-9301, 0, -1548, -739, 0, 0], [14735, 0, 987, 252, 0, 0], [-16772, -192, -192, 0, 16772, 415], [0, -2498, 0, 1060, 1571, -1060], [-2438, 0, 638, 984, 0, 0], [0, 1011, 0, -579, 13531, 579], [-5045, -2174, -2174, 0, 5045, -16], [-13750, 1735, 1735, 0, 13750, 840], [7908, 0, 2262, 326, 0, 0], [1764, 0, -3360, 42, 0, 0], [0, -1248, 0, -503, 14226, 503], [0, 2915, 0, -309, 1073, 309], [614, 0, -222, -1266, 0, 0], [8698, 0, -212, -540, 0, 0], [-8544, 0, 540, 844, 0, 0], [20488, 0, -2236, -376, 0, 0], [-8485, 743, 743, 0, 8485, 599], [0, -4169, 0, 513, -2961, -513], [2126, 62, 62, 0, -2126, 441], [-7766, -648, -648, 0, 7766, 1003], [-1221, 0, 2455, -1086, 0, 0], [-4596, 125, 125, 0, 4596, -1292], [-11981, 1483, 1483, 0, 11981, 129], [0, 542, 0, 779, -11998, -779], [-560, 1704, 1704, 0, 560, -401], [-13655, 0, -2210, -1111, 0, 0], [0, -1306, 0, -387, -4036, 387], [0, 515, 0, -265, -1367, 265], [10896, 0, 3589, 307, 0, 0], [-26083, 0, -955, -26, 0, 0], [-10567, 0, -1936, 607, 0, 0], [0, 34, 0, -987, -10092, 987], [0, 4268, 0, 575, -1076, -575], [0, 4510, 0, -785, 1146, 785], [0, -505, 0, -150, -7388, 150], [-18104, 0, 1160, 194, 0, 0], [-14043, -309, -309, 0, 14043, 1147], [-25000, -1736, -1736, 0, 25000, -977], [-11313, -1944, -1944, 0, 11313, -618], [0, -2611, 0, 1866, 5834, -1866], [-24631, 0, 83, 346, 0, 0], [-13225, -689, -689, 0, 13225, 1395], [-17907, 0, -2082, -1755, 0, 0], [0, 5019, 0, -434, 9148, 434], [0, -2648, 0, 2013, -994, -2013], [-2150, -5271, -5271, 0, 2150, 294], [11057, 0, 4499, -890, 0, 0], [2884, 0, -190, 850, 0, 0], [10547, 2204, 2204, 0, -10547, -490], [0, 1426, 0, 502, -37395, -502], [0, -3620, 0, 399, 9872, -399], [8678, 2216, 2216, 0, -8678, 2431], [-8197, -3070, -3070, 0, 8197, -184], [10822, -3882, -3882, 0, -10822, -163], [-7338, -687, -687, 0, 7338, -182], [18537, 0, 5574, -1063, 0, 0], [-14562, 3912, 3912, 0, 14562, 315], [-4426, 1012, 1012, 0, 4426, 471], [0, 883, 0, 1967, 13137, -1967]];
    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_4_c_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_38_4_c_c(:prec:=6)
    chi := MakeCharacter_38_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_c_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_38_4_c_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_38_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![11449, 5885, 3560, -61, 80, 5, 1]>],Snew);
    return Vf;
end function;