
// Make newform 414.3.c.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_414_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_414_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_414_3_c_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_414_3_c_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 := [9558, -7044, 2713, -1010, 301, -88, 19, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [1216458, -436638, 94493, -51735, 11918, -4990, -477, -373], [8262, -4962, 11, 951, -142, 14, -27, 5], [-379080, 134574, -57976, 18591, -88, 2282, 180, 77], [-8586, 2406, -1421, 411, -110, 22, -3, 1], [-59562, 156990, -23045, 1383, -3950, -1154, -363, -59], [6858, -2238, 2269, -423, 238, -62, 3, -5], [-6900714, 3362766, -1151821, 460815, -105598, 40286, -1251, 1901]];
    Rf_basisdens := [1, 565056, 5184, 70632, 864, 47088, 1728, 565056];
    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_414_c();"
function MakeCharacter_414_c()
    N := 414;
    order := 2;
    char_gens := [47, 235];
    v := [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_414_c_Hecke();"
function MakeCharacter_414_c_Hecke(Kf)
    N := 414;
    order := 2;
    char_gens := [47, 235];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, -1], [2, 0, -1, 0, 0, 0, -1, 0], [0, -2, 0, -1, 0, 1, 0, 0], [-1, 0, 0, 0, -1, 0, -2, 0], [0, 2, 0, 0, 0, 0, 0, 3], [-6, 0, 3, 0, 0, 0, -1, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, -3, 0, 4, 0, 0, 0, -4], [-4, 0, 2, 0, 0, 0, -2, 0], [4, 0, 0, 0, -2, 0, -4, 0], [0, 11, 0, 4, 0, -4, 0, 4], [4, 0, -1, 0, 6, 0, -1, 0], [0, -10, 0, 0, 0, 4, 0, -4], [0, -6, 0, 6, 0, 2, 0, 3], [0, 2, 0, -2, 0, -2, 0, -12], [6, 0, -4, 0, 4, 0, 4, 0], [-2, 0, 9, 0, 0, 0, 5, 0], [0, 16, 0, -6, 0, 6, 0, 8], [-54, 0, 0, 0, 10, 0, 0, 0], [-52, 0, 13, 0, -6, 0, 9, 0], [0, -2, 0, 1, 0, -1, 0, -12], [0, -32, 0, 6, 0, -6, 0, -1], [-1, 0, -4, 0, -5, 0, 4, 0], [0, 31, 0, -4, 0, 4, 0, -12], [-36, 0, -1, 0, -10, 0, -5, 0], [0, 34, 0, -15, 0, -1, 0, -4], [55, 0, 4, 0, 3, 0, -4, 0], [0, 28, 0, -10, 0, 2, 0, 11], [48, 0, -18, 0, 12, 0, -22, 0], [0, -8, 0, -16, 0, 0, 0, -20], [0, -40, 0, -16, 0, 8, 0, -19], [-40, 0, 4, 0, 12, 0, -8, 0], [0, 28, 0, -10, 0, 2, 0, -23], [60, 0, -12, 0, -8, 0, -4, 0], [-76, 0, 4, 0, 6, 0, 24, 0], [64, 0, -10, 0, 12, 0, -10, 0], [0, -24, 0, -28, 0, -4, 0, 12], [0, 43, 0, 8, 0, 4, 0, 44], [0, 50, 0, -16, 0, 4, 0, 20], [1, 0, 8, 0, -11, 0, 12, 0], [0, -58, 0, -3, 0, -5, 0, -12], [-33, 0, -8, 0, -15, 0, 2, 0], [0, -17, 0, 32, 0, -4, 0, -24], [-34, 0, -5, 0, 4, 0, -29, 0], [-196, 0, 10, 0, 4, 0, 14, 0], [272, 0, 8, 0, -16, 0, -4, 0], [0, -144, 0, -12, 0, -4, 0, 20], [33, 0, 8, 0, -19, 0, 24, 0], [0, -57, 0, 44, 0, 16, 0, 6], [0, 124, 0, 14, 0, 18, 0, 4], [-73, 0, -28, 0, 27, 0, 0, 0], [0, 108, 0, 16, 0, 8, 0, 28], [0, 41, 0, 40, 0, 8, 0, 0], [0, -82, 0, 41, 0, -1, 0, -12], [0, -33, 0, 40, 0, 4, 0, -32], [-276, 0, 30, 0, 8, 0, 10, 0], [-102, 0, -24, 0, 10, 0, 8, 0], [0, -136, 0, 28, 0, -20, 0, 3], [-230, 0, -11, 0, 12, 0, 1, 0], [0, -78, 0, 60, 0, 20, 0, 7], [-16, 0, 30, 0, 24, 0, -6, 0], [0, 178, 0, -20, 0, -24, 0, -20], [100, 0, 32, 0, 18, 0, 44, 0], [0, 45, 0, -12, 0, 44, 0, -18], [-236, 0, 30, 0, -32, 0, 14, 0], [153, 0, -20, 0, -19, 0, 12, 0], [0, 146, 0, -18, 0, -26, 0, -12], [-299, 0, 32, 0, -5, 0, 22, 0], [0, -11, 0, -28, 0, -36, 0, 2], [0, -170, 0, -31, 0, -33, 0, 28], [-200, 0, 39, 0, -30, 0, 43, 0], [-152, 0, -16, 0, -18, 0, 4, 0], [-256, 0, 29, 0, 14, 0, -3, 0], [0, -50, 0, 67, 0, 29, 0, -4], [0, 130, 0, -40, 0, -8, 0, -1], [-64, 0, 8, 0, -18, 0, 20, 0], [0, -122, 0, -52, 0, -4, 0, 15], [-201, 0, -40, 0, 15, 0, -38, 0], [0, -298, 0, 13, 0, 3, 0, -28], [-209, 0, -20, 0, 35, 0, 40, 0], [0, -44, 0, -80, 0, 0, 0, -48], [-358, 0, -52, 0, -28, 0, -84, 0], [92, 0, 4, 0, 36, 0, -8, 0], [0, -48, 0, -50, 0, 18, 0, 8], [0, 117, 0, 16, 0, 4, 0, -18], [-57, 0, 20, 0, -21, 0, 48, 0], [0, 179, 0, -100, 0, -12, 0, -6], [88, 0, -8, 0, -44, 0, -32, 0], [0, -100, 0, 0, 0, -40, 0, -4], [0, 20, 0, -84, 0, 44, 0, -4], [-68, 0, -48, 0, 8, 0, -24, 0], [0, -194, 0, -2, 0, 38, 0, -76], [324, 0, 30, 0, 0, 0, 62, 0], [0, -196, 0, 20, 0, -4, 0, -88], [0, 143, 0, 8, 0, -72, 0, 78], [0, 100, 0, -94, 0, -34, 0, -11], [334, 0, 41, 0, -40, 0, -11, 0], [225, 0, -8, 0, -55, 0, 46, 0], [-180, 0, -34, 0, -68, 0, 26, 0], [0, -334, 0, -12, 0, 12, 0, 15], [0, 128, 0, 40, 0, -16, 0, 96], [0, -174, 0, -82, 0, -6, 0, -57], [-600, 0, -41, 0, 10, 0, -49, 0], [201, 0, 72, 0, -73, 0, 30, 0], [0, 44, 0, -12, 0, 4, 0, -84], [0, 399, 0, 28, 0, -16, 0, 30], [0, 332, 0, -54, 0, 14, 0, 44], [31, 0, 40, 0, -63, 0, -14, 0], [-396, 0, -40, 0, -8, 0, -24, 0], [416, 0, 16, 0, 22, 0, 4, 0], [0, 264, 0, 26, 0, 6, 0, -49], [344, 0, 41, 0, -58, 0, -15, 0], [266, 0, 5, 0, -4, 0, -19, 0], [0, -386, 0, -116, 0, 4, 0, -25], [-140, 0, -27, 0, -6, 0, -75, 0], [0, -322, 0, -2, 0, -2, 0, -68], [0, 265, 0, 104, 0, 28, 0, -58], [0, 52, 0, 0, 0, 16, 0, -108], [696, 0, -12, 0, -38, 0, -24, 0], [-245, 0, 64, 0, 57, 0, -38, 0], [0, -416, 0, 62, 0, -38, 0, -37], [0, -104, 0, 90, 0, -26, 0, 60], [-644, 0, -30, 0, -36, 0, -82, 0], [0, -32, 0, -20, 0, 60, 0, 129], [-693, 0, 28, 0, -57, 0, 68, 0], [0, -50, 0, 90, 0, -30, 0, -4], [564, 0, -3, 0, 58, 0, -63, 0], [-203, 0, 16, 0, -23, 0, -44, 0], [104, 0, 0, 0, 104, 0, 40, 0], [0, 190, 0, 175, 0, -39, 0, 72], [442, 0, 35, 0, 8, 0, 27, 0], [195, 0, 80, 0, 15, 0, 116, 0], [0, -75, 0, 32, 0, 96, 0, -70], [628, 0, 20, 0, 10, 0, -40, 0], [0, -384, 0, 34, 0, 6, 0, 29], [-116, 0, 53, 0, -30, 0, 45, 0], [0, -34, 0, 10, 0, 38, 0, 173], [0, 195, 0, -8, 0, -76, 0, -24], [-240, 0, -42, 0, -112, 0, 34, 0], [0, -109, 0, -144, 0, -64, 0, 48], [-332, 0, 74, 0, -68, 0, 66, 0], [0, 460, 0, 144, 0, 24, 0, -112], [-413, 0, -112, 0, 11, 0, -6, 0], [0, -58, 0, 45, 0, -37, 0, -24], [292, 0, -48, 0, 30, 0, -84, 0], [0, 253, 0, -176, 0, 36, 0, -18], [144, 0, -44, 0, 4, 0, -48, 0], [0, -218, 0, 38, 0, 30, 0, -84], [378, 0, -112, 0, -16, 0, 80, 0], [0, -32, 0, -100, 0, 76, 0, 5], [-980, 0, -34, 0, 48, 0, 30, 0], [0, 262, 0, 62, 0, 6, 0, -92], [218, 0, 55, 0, -72, 0, 107, 0], [0, -460, 0, 52, 0, 60, 0, -12], [18, 0, -119, 0, -4, 0, 41, 0], [0, 13, 0, -24, 0, -40, 0, -140], [138, 0, 8, 0, 92, 0, 64, 0], [0, -400, 0, 20, 0, -52, 0, -127], [0, 54, 0, -52, 0, 64, 0, 180], [0, -306, 0, 194, 0, -42, 0, 19], [-380, 0, -2, 0, -128, 0, 42, 0], [0, -48, 0, -132, 0, -4, 0, -56], [0, -472, 0, -134, 0, 38, 0, 31], [0, -572, 0, 28, 0, 36, 0, -36], [548, 0, -102, 0, -44, 0, 58, 0], [721, 0, -88, 0, 103, 0, -58, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_414_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_414_3_c_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_414_3_c_b(:prec:=8)
    chi := MakeCharacter_414_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_414_3_c_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_414_3_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_414_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![153664, 0, 40672, 0, 3284, 0, 100, 0, 1]>],Snew);
    return Vf;
end function;