
// Make newform 343.4.a.a in Magma, downloaded from the LMFDB on 10 March 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_343_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_343_4_a_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_343_4_a_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 := [1, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 1]];
    Rf_basisdens := [1, 1, 1];
    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_343_a();"
function MakeCharacter_343_a()
    N := 343;
    order := 1;
    char_gens := [3];
    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;

function MakeCharacter_343_a_Hecke(Kf)
    return MakeCharacter_343_a();
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 := [[-1, 3, 1], [0, 0, 0], [0, 0, 0], [0, 0, 0], [39, -19, 29], [0, 0, 0], [0, 0, 0], [0, 0, 0], [164, -82, 103], [-200, 100, -233], [0, 0, 0], [-227, 219, -223], [0, 0, 0], [202, -11, -202], [0, 0, 0], [188, -389, -188], [0, 0, 0], [0, 0, 0], [612, -306, 89], [370, -529, -370], [0, 0, 0], [90, 647, -90], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [1172, -586, 89], [860, -403, -860], [-101, -1643, 771], [613, -2161, 1387], [0, 0, 0], [-592, 296, 1111], [0, 0, 0], [263, 2417, -1077], [1901, -201, 1051], [0, 0, 0], [-1422, -179, 1422], [0, 0, 0], [0, 0, 0], [1630, 227, -1630], [0, 0, 0], [2671, -131, 1401], [2096, -1048, -723], [3832, -1916, 1769], [0, 0, 0], [1340, -670, 3939], [0, 0, 0], [0, 0, 0], [0, 0, 0], [2008, 1361, -2008], [-340, 170, -3943], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-2999, 6043, -4521], [0, 0, 0], [0, 0, 0], [-2593, 6841, -4717], [-591, 6911, -3751], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [5163, 1549, 1807], [3860, -1930, 8349], [3917, 5091, -587], [-4100, 0, 0], [0, 0, 0], [0, 0, 0], [-8104, 0, 0], [0, 0, 0], [-2664, 1332, -8983], [11916, 0, 0], [0, 0, 0], [4220, 3153, -4220], [0, 0, 0], [6040, -3819, -6040], [0, 0, 0], [0, 0, 0], [-3060, -6101, 3060], [-5930, 7269, 5930], [0, 0, 0], [0, 0, 0], [18580, 0, 0], [-7120, 4903, 7120], [-13472, 6736, -6099], [0, 0, 0], [809, -14453, 7631], [0, 0, 0], [0, 0, 0], [21240, 0, 0], [2890, -11631, -2890], [-367, -15573, 7603], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-14760, 7380, -3131], [-10657, -6011, -2323], [6236, -13353, -6236], [0, 0, 0], [-2720, 1360, -15493], [-9990, 8389, 9990], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-24736, 0, 0], [0, 0, 0], [0, 0, 0], [-12491, -7453, -2519], [944, -15747, -944], [0, 0, 0], [-13500, 6750, -23221], [23600, -11800, 22139], [0, 0, 0], [0, 0, 0], [-9831, 24607, -17219], [-25540, 12770, -20057], [0, 0, 0], [3632, 14969, -3632], [0, 0, 0], [19051, -10967, 15009], [0, 0, 0], [9069, 18811, -4871], [13460, -13003, -13460], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-23580, 11790, -30347], [25160, 0, 0], [-6541, -24519, 8989], [17272, -8636, -4461], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-13597, 33917, -23757], [0, 0, 0], [6740, 18399, -6740], [3618, 21311, -3618], [-23980, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-17578, 18889, 17578], [-38952, 19476, -32489], [0, 0, 0], [-23159, -9357, -6901], [0, 0, 0], [-23677, 34449, -29063], [12611, -41431, 27021], [21744, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-12034, -18393, 12034], [-5001, 43577, -24289], [22788, -11394, 43111], [0, 0, 0], [27857, 8591, 9633], [0, 0, 0], [-18260, 9130, 15069], [0, 0, 0], [48240, -24120, 33157], [0, 0, 0], [18356, 0, 0], [0, 0, 0], [12260, -6130, 41291], [22392, -26191, -22392], [0, 0, 0], [0, 0, 0], [31860, -15930, -2879], [-15320, 7660, 21551], [0, 0, 0], [0, 0, 0], [-18054, -17693, 18054], [0, 0, 0], [-27252, 11161, 27252], [0, 0, 0], [-3476, 1738, -39167], [0, 0, 0], [12956, 26687, -12956], [0, 0, 0], [39673, -8713, 24193], [0, 0, 0], [0, 0, 0], [6922, 35129, -6922], [2750, 38531, -2750], [0, 0, 0], [22313, 38579, -8133], [0, 0, 0], [50480, -25240, 13011], [-63144, 31572, -53713], [0, 0, 0], [0, 0, 0], [-35480, 17740, -62743], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [45916, -22958, 68927], [33200, -2013, -33200], [0, 0, 0], [-44803, 51571, -48187], [0, 0, 0], [7762, -49781, -7762], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-31097, 70149, -50623], [0, 0, 0], [-320, 0, 0], [-8230, 0, 0], [24642, 0, 0], [0, 0, 0], [77920, -38960, 70313], [19382, -56851, -19382], [0, 0, 0], [-51887, -7593, -22147], [0, 0, 0], [58083, -36503, 47293], [0, 0, 0], [17300, -8650, -41099], [-72630, 0, 0], [0, 0, 0], [-74260, 37130, -27939], [63920, -31960, 86161], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-87890, 0, 0], [-8636, 0, 0], [0, 0, 0], [51964, -25982, 87463], [0, 0, 0], [0, 0, 0], [-46973, 83253, -65113], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-14003, -79777, 32887], [-442, -62759, 442], [-116730, 0, 0], [0, 0, 0], [67953, -48781, 58367], [0, 0, 0], [0, 0, 0], [14137, -97277, 55707], [-45811, -46709, 449], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-56844, 28422, -99073], [-6994, 70927, 6994], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [40120, -20060, -35387], [0, 0, 0], [104436, -52218, 96857], [142690, 0, 0], [0, 0, 0], [81532, -40766, 11919], [0, 0, 0], [-28340, 14170, 50097], [0, 0, 0], [0, 0, 0], [-31540, 0, 0], [-102680, 51340, -43647], [-44341, -68619, 12139], [0, 0, 0], [0, 0, 0], [59399, -107819, 83609], [0, 0, 0], [0, 0, 0], [0, 0, 0], [48950, 24069, -48950], [-49568, 72439, 49568], [44152, -22076, 109009], [0, 0, 0], [0, 0, 0], [-165002, 0, 0], [0, 0, 0], [34941, -126397, 80669], [0, 0, 0], [-57492, 66671, 57492], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-174550, 0, 0], [-68940, 34470, 25163], [-18259, 133583, -75921], [24119, 111421, -43651], [-71488, 35744, -130881], [136748, -68374, 90431], [0, 0, 0], [67150, -9363, -67150], [99439, -51063, 75251], [0, 0, 0], [-136280, 68140, -129257], [-101279, 42079, -71679], [59749, -138633, 99191], [79167, 45341, 16913], [0, 0, 0], [0, 0, 0], [-56330, -33919, 56330], [0, 0, 0], [73520, -22943, -73520], [0, 0, 0], [47704, 52153, -47704], [0, 0, 0], [78271, 55533, 11369], [-22688, -83941, 22688], [0, 0, 0], [-37710, -69787, 37710], [0, 0, 0], [-98228, 49114, -154471], [-189950, 0, 0], [-77260, 61211, 77260], [26396, 86677, -26396], [0, 0, 0], [0, 0, 0], [-98479, 125659, -112069], [0, 0, 0], [-33967, -129113, 47573], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-157896, 78948, -84527], [81584, -62507, -81584], [0, 0, 0], [13810, 102679, -13810], [195610, 0, 0], [-59410, -51657, 59410], [0, 0, 0], [35734, 85543, -35734], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-74376, 98423, 74376], [-60609, -113111, 26251], [0, 0, 0], [-68580, 107803, 68580], [0, 0, 0], [0, 0, 0], [0, 0, 0], [120103, -114791, 117447], [-99389, 155353, -127371], [-117953, -8839, -54557], [0, 0, 0], [173932, -86966, 168089], [100004, 0, 0], [0, 0, 0], [180064, -90032, 104403], [0, 0, 0], [94338, -57509, -94338], [25280, -12640, 144429], [95570, -32631, -95570], [0, 0, 0], [77361, 111043, -16841], [-37677, -156203, 59263], [0, 0, 0], [-50436, -85537, 50436], [0, 0, 0], [177460, -88730, 72959], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [46784, -23392, -96427], [-122400, 0, 0], [90087, 107641, -8777], [0, 0, 0], [0, 0, 0], [79610, -129049, -79610], [0, 0, 0], [32939, 175177, -71119], [0, 0, 0], [-193680, 96840, -90197], [0, 0, 0], [-340, 170, 139963], [0, 0, 0], [32420, -16210, -115201], [123056, -61528, 207807], [0, 0, 0], [0, 0, 0], [56790, -149741, -56790], [-203278, 0, 0], [0, 0, 0], [-119409, 189233, -154321], [-48294, 154927, 48294], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-49032, 24516, -181099], [111880, -47541, -111880], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-127627, 194819, -161223], [147100, 0, 0], [160171, -41991, 101081], [-217872, 108936, -213929], [0, 0, 0], [73623, -232363, 152993], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-237080, 118540, -182933], [0, 0, 0], [100852, -50426, 219259], [0, 0, 0], [0, 0, 0], [0, 0, 0], [121022, -40961, -121022], [91720, -152863, -91720], [0, 0, 0], [0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_343_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_343_4_a_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_343_4_a_a(:prec:=3)
    chi := MakeCharacter_343_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_343_4_a_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_343_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_343_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-43, -30, 1, 1]>,<3,R![0, 1]>],Snew);
    return Vf;
end function;