
// Make newform 672.4.a.m in Magma, downloaded from the LMFDB on 12 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_672_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_672_4_a_m();".
// 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_672_4_a_m();".
// 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 := [-34, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_672_a();"
function MakeCharacter_672_a()
    N := 672;
    order := 1;
    char_gens := [127, 421, 449, 577];
    v := [1, 1, 1, 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_672_a_Hecke( : Kf := Kf)
    return MakeCharacter_672_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 := [[0, 0], [3, 0], [5, -1], [7, 0], [11, -1], [12, 2], [15, 1], [16, -4], [41, -3], [18, 20], [56, -8], [24, -14], [-35, -1], [20, 20], [210, 34], [88, 18], [202, -2], [-78, 40], [-2, 30], [407, -5], [-108, -46], [790, 22], [232, 4], [-579, 87], [-880, 62], [763, -51], [932, -76], [867, -49], [-146, -88], [-838, 56], [1398, -2], [1036, 24], [-324, -166], [-148, 112], [1608, -142], [168, -88], [102, 116], [1138, -6], [-2434, 30], [1543, 57], [-107, 89], [872, -74], [-701, 263], [-3100, 74], [2476, -10], [-2020, 204], [-936, 240], [-2276, -92], [1686, -230], [-1984, 302], [1552, -82], [1025, -523], [-2416, -178], [-3218, 138], [-3163, -153], [-2423, -107], [3125, -97], [-468, 180], [-7132, -58], [1684, 114], [-4024, -284], [2187, 173], [-2684, -416], [-3710, 90], [-5950, -416], [-2064, 322], [-1704, 152], [-4050, 220], [-2747, 241], [4178, -32], [1471, 521], [-6721, 139], [-1184, 840], [-8610, -440], [-7800, 456], [-7048, 384], [-9414, 356], [2030, -1156], [16, -26], [5632, 678], [1162, 934], [556, 126], [667, -1017], [2630, -468], [6496, -504], [5909, 425], [3566, -868], [-414, 1304], [10467, -747], [7482, 890], [3618, 1222], [4246, -234], [4388, 276], [5845, -1127], [-2576, -1384], [-2884, 28], [3693, -153], [15131, -75], [11668, -96], [-236, -626], [-6882, -186], [-10212, -1154], [10670, 346], [5888, -946], [-1270, 1234], [14574, -1044], [21282, -354], [-15321, -447], [939, 1567], [13734, 940], [-224, 440], [-26378, -168], [14976, 590], [-7048, 1316], [17358, -562], [-15316, -414], [12800, 468], [4090, -566], [-8302, -732], [-4857, -245], [254, 524], [-1056, 1334], [-23281, -823], [14073, 1133], [10320, 1276], [5182, 960], [3294, -1408], [-21692, 380], [7892, -956], [-10084, 2074], [-13670, -1518], [-1921, -613], [-9960, -840], [13910, -232], [-2323, 2287], [15646, 1508], [-10073, -1799], [-22216, -60], [22847, 1505], [-13202, 420], [25032, -812], [-11644, -130], [4018, 482], [-27525, -377], [26640, 286], [-23734, -182], [14506, -2064], [8381, -113], [8244, -1144], [2037, -2159], [25302, -624], [-4453, 1269], [-24784, -904], [-18874, -1738], [-23468, -1652], [-6493, 3327], [-18012, -340], [-25007, 2027], [18198, 460], [28013, -49], [7563, -2145], [-8734, -440], [23070, 1430], [-292, 1816], [-26612, -990], [-1676, 1756], [-19452, 1500], [22606, 3244], [-18344, 1790], [-6253, -355], [-40361, -1709], [28390, 212], [-3877, -705], [-7160, -1034], [-16476, -2988], [-89, -4503], [7830, -2746], [-6202, -2384], [-5904, 1640], [-466, 1092], [-34206, 1818], [24744, -3860], [-4476, 814], [6147, -2747], [24757, -631], [-4433, -1607], [19490, 2644], [-5812, -3864], [-7816, 3718], [40568, -1328], [4024, 334], [-24829, 319], [19812, -3636], [7179, -3443], [26375, 3091], [19759, 1121], [-26640, 1254], [4868, 134], [-3087, -1821], [10374, -5826], [54348, 2046], [-14428, 2212], [14324, -2630], [-18056, 1502], [-11128, -1596], [17199, 489], [724, 4884], [67691, -1233], [-20814, -904], [27468, -80], [-47846, 2232], [33673, -893], [80932, -156], [-3996, -4768], [-4310, 2626], [12846, 2012], [-17492, -3692], [-22141, -3963], [22817, 1229], [25850, -3460], [38766, -1936], [-32108, -3044], [48578, 2144], [5936, -4336], [13644, 2104], [-32096, 1642], [27013, 287], [37921, 2597], [44964, 1276], [28425, -139], [4934, -1776], [-59788, -1032], [83404, -1692], [37142, -1060], [62916, 848], [66160, 2160], [-1608, -7962], [9336, 5794], [-99207, 605], [-13548, -6492], [44161, -2467], [97688, 228], [-11716, 6644], [-33948, 3358], [29553, 1299], [-53338, -3930], [16832, -6120], [13470, -4478], [-57310, -1558], [78573, 1257], [-37662, -4268], [54183, 433], [50227, -937], [-31764, -2262], [-99089, 441], [38983, -3037], [-18340, 4966], [-13956, -3936], [-50177, -5407], [-20010, 6244], [-10338, -6650], [-62455, 1605], [-32488, -1490], [-80054, 2496], [99779, 1765], [48920, -2948], [-37640, 2746], [-80461, -2539], [30102, -6442], [101142, 416], [-34078, 7200], [-70756, 2156], [-60908, -2862], [-142548, 44], [-29044, -4014], [69860, 300], [-53713, -4349], [12796, -9738], [-7748, 1034], [6942, 2514], [84300, -340], [-50490, 3926], [-42068, 7476], [-61914, -1276], [68348, 856], [11331, 4607], [90778, -1352], [89176, -2734], [-58268, -7564], [42741, 711], [69460, -4378], [-28988, -5568], [111168, 222], [-7634, -9582], [-103442, 2528], [-25649, -4879], [-4772, -6732], [-51359, 1875], [-157370, 130], [45212, -2208], [17146, 7560], [-55574, -6516], [-98582, 4154], [-18569, -1893], [25338, -3246], [7062, 9380], [-43887, -563], [-84480, 6286], [-76785, -2469], [11324, 2430], [-12948, 124], [121330, -2212], [-4004, 5506], [37824, -5632], [-1855, -12931], [-73436, -7486], [-24120, 9340], [43273, -4587], [122476, -5406], [-40956, 3082], [20744, -11188], [9376, -15394], [-19981, -4035], [70924, 9204], [31946, -3696], [-45700, 5482], [-64322, -7130], [152008, 548], [21319, -7629], [22822, -3392], [-76918, 9532], [69402, 8252], [-49172, 10348], [40082, 7502], [-44818, -9314], [1258, 10590], [-70690, 408], [152165, 823], [-98176, -7458], [50828, 2876], [9134, 4680], [-188388, -1062], [75881, 2059], [-7364, 13460], [-99910, 748], [-16625, -15117], [40668, -1462], [-69980, 7524], [96628, -2476], [13595, 5997], [140436, -1240], [94128, -6034], [28020, 12566], [20388, -6524], [23174, 6784], [-78801, -7535], [-59436, -9588], [83036, 2056], [354, 6352], [11563, 711], [89646, 8264], [-101143, -4285], [31307, 14167], [-51785, 2835], [-115816, 8644], [95328, 7934], [-54167, 611], [102398, 2982], [-20116, -17318], [94945, 3669], [-61740, 8856], [126735, 5475], [65800, -6846], [6228, 1852], [52700, 9814], [-19964, 3024], [37881, -179], [45502, 6060], [-60065, 2561], [-28220, 11258], [-135925, 10237], [-242, 9764], [170252, 724], [-39034, 9300], [26708, -16472], [-9376, -18800], [-120760, 3392], [130468, 250], [38022, -15882], [72926, 1422], [25264, -6890], [-6947, -11305], [-46669, -12961], [106540, -10192], [103863, 803], [17502, 7188], [-23628, 8452], [-147953, -11335], [73958, 10694], [108846, 4936], [100570, 8592], [139810, -2688], [-43138, -1746], [10133, -9785], [-19435, 6199], [200560, 3472], [96140, 4710], [-187806, -5760], [-38460, 6968], [-79342, 13390], [-41510, 3368], [-96638, 4284], [146841, 133], [-77820, 15116], [93960, -170], [57345, -4309], [-71227, 6897], [-4632, -3512], [-139733, -9411], [-74566, 11938], [-85334, -3556], [167310, -2932], [-1805, -10537], [-102332, 2616], [77794, -14320], [-42137, -17567], [96665, -3691], [-194428, 6210], [-12620, 19976], [-185010, -6786]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_672_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_672_4_a_m();".
// 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_672_4_a_m(:prec:=2)
    chi := MakeCharacter_672_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_672_4_a_m();".
// 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_672_4_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_672_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-112, -10, 1]>,<11,R![-16, -22, 1]>],Snew);
    return Vf;
end function;