
// Make newform 315.4.a.k in Magma, downloaded from the LMFDB on 07 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_315_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_315_4_a_k();".
// 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_315_4_a_k();".
// 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 := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 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_315_a();"
function MakeCharacter_315_a()
    N := 315;
    order := 1;
    char_gens := [281, 127, 136];
    v := [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_315_a_Hecke( : Kf := Kf)
    return MakeCharacter_315_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, 1], [0, 0], [-5, 0], [-7, 0], [8, -20], [-38, -2], [62, 2], [-48, -16], [8, 34], [-94, 54], [-60, 18], [-66, -66], [-50, -80], [-268, 62], [464, 42], [-442, -64], [-52, 204], [-234, -42], [-844, 38], [68, 150], [254, 322], [-216, -232], [292, 84], [702, -112], [-594, 46], [82, 124], [-664, 416], [-860, -390], [70, 168], [130, 36], [-184, 904], [316, -536], [-1582, -424], [904, -760], [-1790, 626], [456, -992], [-510, -1198], [300, 434], [-48, 370], [514, -424], [1520, -900], [54, 1006], [-220, -302], [322, 204], [-3618, 196], [-2788, 650], [372, 684], [-2232, -352], [-1772, 852], [30, 182], [1834, 1384], [-2068, 1678], [-3062, 304], [5468, 88], [-5850, 398], [-1184, -1694], [-2246, -792], [5372, -546], [-2770, -230], [-2498, -968], [-5764, -432], [-2614, -1692], [-420, 1092], [-1528, -1648], [1734, -1646], [-5730, -1448], [-2436, -2412], [-990, -956], [-1044, -986], [7686, 226], [10830, -650], [6428, 2286], [-4120, -1188], [-1402, -750], [7044, 2288], [-1928, 914], [8322, 502], [4266, 50], [6286, 1868], [3626, -2372], [1116, 1520], [-1378, 1968], [2620, 2294], [-11490, -1894], [2172, 2214], [-4068, 2958], [-5714, -1708], [1442, 3716], [2346, 5252], [1160, -4076], [13508, 1192], [2016, -3304], [-4640, -4444], [-9752, -580], [17948, 400], [15632, -754], [-4790, 3224], [-5378, -4956], [21828, -500], [3238, -2884], [3732, 4102], [-4578, 4664], [-6436, 3096], [12518, -3812], [17268, 2344], [3566, 1578], [11364, -1184], [-2802, -3542], [18108, -982], [-5470, 1972], [-8824, 216], [-8210, 3342], [11994, 416], [24424, -1644], [-8256, -2140], [-17002, 1932], [3628, 5648], [1232, -8090], [-2458, 1904], [-8232, 4600], [-26866, -1642], [-6390, -920], [-4022, -5416], [-276, 1602], [-6056, -4048], [418, 998], [-834, 7348], [14744, -1232], [3984, -5732], [-20950, -2010], [3916, -3532], [-288, 1522], [-16152, -2744], [14838, 5730], [-6194, -2764], [-11750, 5336], [21018, 20], [28364, -2464], [-6254, -5088], [26110, -3596], [-5704, 10088], [14474, -3102], [5248, -13324], [6772, 2118], [-32130, 482], [-2688, 4408], [10642, 4794], [5262, -9298], [-3792, -844], [-20224, -10618], [-8186, -350], [14678, 4064], [22004, -1198], [21736, -3146], [-27428, 234], [15540, -7270], [-2496, 4256], [4470, 7428], [-1698, -11282], [22794, -1280], [-4604, 1974], [-2630, -148], [-3256, -3964], [-33012, 7092], [-12398, -12320], [-10088, 4110], [-17032, 7360], [-32734, 2418], [30034, 8096], [-23686, -6552], [-24488, -9052], [3470, 12338], [45268, -2126], [-3606, -1692], [32412, -7238], [-25618, 8616], [5948, 17548], [9490, -11754], [38192, -7236], [3038, -10834], [-40368, -3504], [-25916, 12208], [-5546, -18358], [23974, 1762], [19240, 922], [10818, 7188], [-15290, 10542], [8044, -8548], [-33366, -96], [20136, 1920], [-32002, 10710], [-20220, 12226], [-12324, -6992], [-16342, 8812], [30756, 9782], [-9354, -6702], [11922, -6840], [-46402, -10474], [-65226, 2286], [-19120, 2590], [-15790, 1246], [-53500, 2282], [-23462, 16702], [-15430, -16724], [13596, -19772], [-10958, 21396], [-28420, 7242], [36140, 2662], [-2850, 3312], [34480, 6420], [24762, 19792], [29906, -624], [-48040, 6320], [40348, 868], [16016, 632], [18, -23816], [-67016, 8636], [-45482, 8020], [-40080, 10858], [-13946, 10736], [-42498, -6316], [51164, 6942], [66598, 5548], [-9488, -19284], [6300, -22484], [-20418, 15340], [25646, 5214], [12756, 8086], [4136, -21180], [-19912, -932], [-19058, 11030], [48944, -3320], [-10384, -23084], [-35042, 1096], [-40908, -6468], [8320, 7522], [-33070, 11908], [14254, -26692], [22712, 5436], [-2320, -31436], [61932, 16574], [856, -1932], [48744, -19856], [13446, -33964], [76678, -5702], [-60848, 12324], [34024, 21332], [-36100, -2628], [46316, 10088], [49248, 20262], [82262, -1238], [55382, -21652], [13272, 23506], [40730, 4992], [24946, 16076], [-88432, 11064], [-12834, 392], [-24660, -2640], [-27750, -7188], [-33322, -35470], [-98248, 9628], [15220, -4602], [-95874, 7746], [17026, -16238], [-75250, 18518], [27384, -13992], [-62318, -4266], [-49218, 8060], [-81940, 5842], [6846, 13280], [78670, 16978], [-30340, 11090], [-39994, 17294], [-10728, -852], [97870, -4298], [79152, 14272], [-38188, -27558], [68854, 5284], [-10854, 8016], [-89868, -17548], [-61152, -18082], [-81952, -14144], [-9880, 13650], [-234, -48562], [73076, -4396], [-74812, 4182], [-29142, -21076], [-28778, -15488], [31244, 12306], [-48986, 13396], [33106, -2210], [71124, -25176], [28986, -4840], [-62796, 6676], [33230, 1862], [-63846, -19068], [-54260, 20554], [32194, -30220], [-4452, 10256], [-27988, 12152], [-16690, 4846], [-87610, -18384], [672, -43752], [7028, -20410], [-76828, -4960], [27474, 20688], [-20972, 42790], [1574, 37122], [-39804, -37874], [-8090, -8294], [-38624, 24294], [117962, 8158], [118958, -9404], [-90796, -17678], [-264, -6634], [-45214, -7292], [8444, -16604], [-42588, 4210], [4766, 9894], [-82882, -3488], [-29784, 40764], [64946, -2408], [-9542, -14964], [10624, -24176], [45442, -4636], [157802, -10144], [29548, 43656], [71068, 27468], [-80448, -11958], [-57034, -14196], [-23594, 41408], [50982, -15656], [-2372, 14346], [69148, 15132], [-17988, -27468], [12676, 42404], [-98826, -16500], [19846, 2802], [19506, 53652], [72984, -31800], [-19866, -10926], [34410, 42496], [50450, 29328], [-111720, 3908], [21542, -33944], [62216, 19044], [-32914, -3274], [54156, -54538], [4952, -19764], [-4198, -5484], [178864, 3540], [-70878, -22340], [-12238, 59314], [108480, 28592], [25502, -48452], [167030, 19254], [-94744, -1560], [-89292, -15348], [22530, 25316], [-116480, -28914], [74550, -50910], [104574, -15316], [41848, -38098], [-13568, -43320], [29756, 18640], [-50286, 37636], [-32406, 1980], [129944, -31520], [63178, 32552], [67728, -3664], [-168224, 4916], [-22504, -22874], [-9118, 27278], [19220, 1670], [-52778, -17294], [-56212, 24968], [-24684, 17370], [69566, 15722], [29318, -62892], [-103714, -37534], [-1894, -19988], [47434, -47876], [-18528, -83180], [85962, -7484], [-62272, 61696], [173712, 19242], [34376, -28868], [-221118, -16418], [-99748, 18534], [-27328, 39646], [93842, 29648], [38130, 4888], [-24800, 3896], [2588, 41236], [-2476, -10434], [186106, -23336], [-5124, -77922], [-111106, 26576], [-61676, 71764], [45466, 64330], [-52130, -5186], [-133694, 46956], [82176, -6944], [-26226, 20954], [-188238, 22192], [-59820, -1202], [-54074, 36962], [30110, -68708], [-6572, -7092], [119508, 11940], [-30602, 17350], [-8954, 42260], [6780, 13374], [-22300, -58184], [-50534, -7644], [-79014, 17288], [35276, 12966], [-30160, 19144], [-180098, 2982], [-204120, -2458], [-102822, 22910], [-56318, 11050], [59880, -40158], [-25236, -26876], [-22570, -46134], [-60174, 19484], [-19316, 88306], [91158, 4848], [43168, 7500], [26096, -75712]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_315_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_315_4_a_k();".
// 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_315_4_a_k(:prec:=2)
    chi := MakeCharacter_315_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_315_4_a_k();".
// 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_315_4_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_315_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-7, -2, 1]>],Snew);
    return Vf;
end function;