
// Make newform 1400.4.g.c in Magma, downloaded from the LMFDB on 15 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1400_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1400_g_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_1400_4_g_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_1400_4_g_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 := [1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_1400_g();"
function MakeCharacter_1400_g()
    N := 1400;
    order := 2;
    char_gens := [351, 701, 1177, 801];
    v := [2, 2, 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_1400_g_Hecke();"
function MakeCharacter_1400_g_Hecke( : Kf := false)
    N := 1400;
    order := 2;
    char_gens := [351, 701, 1177, 801];
    char_values := [[1, 0], [1, 0], [-1, 0], [1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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]];
    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 := [[0, 0], [0, 5], [0, 0], [0, 7], [-39, 0], [0, -19], [0, 37], [18, 0], [0, -90], [-99, 0], [-32, 0], [0, -46], [-248, 0], [0, 178], [0, -429], [0, -652], [-40, 0], [-36, 0], [0, 348], [72, 0], [0, -1190], [-699, 0], [0, -116], [704, 0], [0, -223], [522, 0], [0, 1697], [0, -246], [-345, 0], [0, 186], [0, -2344], [958, 0], [0, -768], [122, 0], [166, 0], [-1725, 0], [0, -3686], [0, 2594], [0, -1457], [0, -3241], [4596, 0], [-1140, 0], [-4131, 0], [0, -2792], [0, -2692], [2640, 0], [327, 0], [0, 4665], [0, 1071], [3920, 0], [0, -2616], [6913, 0], [2690, 0], [3034, 0], [0, 2266], [0, -7058], [-3474, 0], [-20, 0], [0, 4186], [-7221, 0], [0, 23], [0, 139], [0, -6759], [1038, 0], [0, -9507], [0, 1290], [-5404, 0], [0, -3094], [0, 1486], [-6630, 0], [0, -5417], [9200, 0], [0, -4157], [0, 8592], [-2084, 0], [0, -9292], [1723, 0], [0, -3767], [-14967, 0], [-11374, 0], [-14076, 0], [3769, 0], [-7423, 0], [0, -670], [-6466, 0], [0, 14618], [-7551, 0], [0, 14076], [-18360, 0], [0, 2812], [0, -2619], [7546, 0], [0, -9398], [-5397, 0], [-11669, 0], [0, 4055], [-12026, 0], [-17622, 0], [0, 14684], [-5741, 0], [0, 9268], [0, 23112], [0, -13284], [10446, 0], [-2252, 0], [0, -4457], [0, 25048], [0, 177], [-9009, 0], [-25794, 0], [0, -4319], [0, -15134], [0, -8394], [1658, 0], [-8071, 0], [28130, 0], [0, 2693], [0, -1376], [0, 30342], [15163, 0], [-5688, 0], [0, 21488], [0, -16453], [0, -3372], [14172, 0], [30663, 0], [14485, 0], [8818, 0], [0, 11408], [0, 15233], [-32113, 0], [0, 4596], [-15893, 0], [0, -15336], [33010, 0], [-30982, 0], [0, -5915], [0, 24615], [0, -6055], [-27809, 0], [-18654, 0], [27285, 0], [0, 18592], [0, 37146], [-11024, 0], [-42858, 0], [0, -31522], [0, -37026], [-34380, 0], [0, -29172], [0, 18178], [2608, 0], [0, 26880], [0, -31208], [0, -21494], [3704, 0], [16185, 0], [-8500, 0], [0, -33415], [-25884, 0], [0, -26404], [0, -21068], [0, -298], [-8972, 0], [0, -7874], [0, -47585], [-42016, 0], [0, -1867], [32027, 0], [0, -30758], [-59480, 0], [-45374, 0], [13509, 0], [0, 20674], [20410, 0], [-31428, 0], [-16451, 0], [38381, 0], [0, -54012], [61468, 0], [0, 27912], [9552, 0], [0, 4002], [0, -28918], [0, -48520], [9946, 0], [0, 56896], [0, -6099], [24847, 0], [-51620, 0], [0, 10050], [0, -44718], [36035, 0], [21508, 0], [0, -73868], [0, 73297], [-44833, 0], [0, 47968], [0, -23499], [0, 61553], [70858, 0], [13098, 0], [0, -11122], [76130, 0], [-258, 0], [0, 4909], [28294, 0], [0, -12624], [60794, 0], [-17876, 0], [0, -91160], [58098, 0], [0, 75328], [0, -67641], [-71754, 0], [-54016, 0], [0, 32674], [-6936, 0], [0, -42942], [0, 34046], [87722, 0], [-46138, 0], [11683, 0], [0, -29374], [0, -30633], [22602, 0], [0, 86807], [-1089, 0], [0, 57751], [11628, 0], [0, 78344], [33970, 0], [93896, 0], [-94935, 0], [0, -99407], [0, 13063], [31436, 0], [0, -776], [55245, 0], [33558, 0], [0, 19976], [-116576, 0], [0, 72493], [72866, 0], [0, -100431], [-8578, 0], [0, 60256], [-36326, 0], [-45119, 0], [0, 30690], [0, -54230], [100298, 0], [0, 121380], [-111152, 0], [0, -39082], [-42421, 0], [-18170, 0], [0, 27140], [0, -97509], [0, 15199], [0, -92334], [0, 42118], [-100636, 0], [0, 109065], [0, -50346], [105914, 0], [99371, 0], [3890, 0], [0, 36868], [0, -108898], [120076, 0], [0, -109080], [0, 28567], [40812, 0], [0, 52194], [0, 45533], [0, -34972], [-47482, 0], [-114647, 0], [-76998, 0], [0, 825], [-40445, 0], [0, -61152], [121614, 0], [0, 104999], [15465, 0], [0, 3842], [0, 157466], [-139436, 0], [-70308, 0], [-21915, 0], [0, 9093], [0, -59780], [-5712, 0], [0, 9758], [-12636, 0], [-91574, 0], [0, -10107], [25580, 0], [0, 22563], [0, -14117], [0, 83258], [-86861, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1400_g_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1400_4_g_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_1400_4_g_c(:prec:=2)
    chi := MakeCharacter_1400_g();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_1400_4_g_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_1400_4_g_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1400_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![25, 0, 1]>,<11,R![39, 1]>],Snew);
    return Vf;
end function;