
// Make newform 441.7.d.c in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_441_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_441_d_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_441_7_d_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_441_7_d_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 := [21068100, -601290, 985651, 36821, 39800, 473, 212, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [6787296640242135, 423382833624317, 529666993003657, 20860832470090, 2673339327091, 65484675874, 12595814413, 405518177], [-5583985297290, 15909261436572, 15479370553, 336428371378, 3085757533, 1621914529, -13389005, 8497603], [-5583985297290, 824259839130, 15479370553, 336428371378, 3085757533, 1621914529, -13389005, 8497603], [208034068231995, -707660422560, -13289665936, -323422537422, -2649247696, -1392479248, -50933099, -7295536], [-277910537962726260, 162140643786549358, -15721266306367057, 3069708627551885, -98352920361781, 19199653600241, -648926656693, 65881610383], [-478310744905115040, -253385183003352218, -43067900538846163, -6373179964075405, -280397778215839, -30723933002041, -904004937787, -135000035243], [-1324669278373776, 135053950277610, 2536275627841, 47373358739629, 505597536901, 265748679913, -2568340439, 1392321691]];
    Rf_basisdens := [1, 5770013111021565, 7542500798721, 7542500798721, 2514166932907, 7693350814695420, 7693350814695420, 30170003194884];
    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_441_d();"
function MakeCharacter_441_d()
    N := 441;
    order := 2;
    char_gens := [344, 199];
    v := [2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_441_d_Hecke();"
function MakeCharacter_441_d_Hecke(Kf)
    N := 441;
    order := 2;
    char_gens := [344, 199];
    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 := 7;
    raw_aps := [[-1, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 25, -3, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [-55, 0, 0, 103, -11, 0, 0, 1], [0, 264, 3, 0, 0, 19, 20, 0], [0, -442, -82, 0, 0, 6, 24, 0], [0, -1550, 85, 0, 0, 37, -44, 0], [1088, 0, 0, 280, 16, 0, 0, 64], [605, 0, 0, -1247, -193, 0, 0, -145], [0, 7331, 530, 0, 0, -18, -44, 0], [-16510, 0, 0, -1255, 147, 0, 0, -113], [0, 7782, 1052, 0, 0, 652, 432, 0], [6182, 0, 0, 1901, 399, 0, 0, -221], [0, -39992, -82, 0, 0, -1042, 96, 0], [-137125, 0, 0, -6857, 353, 0, 0, -511], [0, -15871, 571, 0, 0, 2323, 756, 0], [0, 38980, -15208, 0, 0, -1304, 720, 0], [291068, 0, 0, 6357, 1103, 0, 0, -1045], [-186172, 0, 0, -22382, -2650, 0, 0, 758], [0, 35228, -14317, 0, 0, -373, -1924, 0], [-152983, 0, 0, -7998, 2018, 0, 0, 2750], [0, 95781, 15973, 0, 0, 197, 1092, 0], [0, 81874, 3154, 0, 0, -918, -192, 0], [0, -114285, -33555, 0, 0, -4027, 4, 0], [0, 140996, 6714, 0, 0, -13822, -6576, 0], [0, 415264, 6537, 0, 0, -1607, 1316, 0], [-1014805, 0, 0, 4891, -6439, 0, 0, 3269], [-238648, 0, 0, -77413, -2607, 0, 0, -5123], [726158, 0, 0, -171668, 9668, 0, 0, -1444], [-410209, 0, 0, 111696, -20940, 0, 0, -10032], [0, 674845, -19707, 0, 0, -22931, 1044, 0], [292904, 0, 0, 193012, 9748, 0, 0, -19412], [0, -230034, -56545, 0, 0, -33, -1076, 0], [-2666854, 0, 0, -255170, -28070, 0, 0, -2366], [218219, 0, 0, 265277, -30557, 0, 0, -7357], [0, 1411580, -5208, 0, 0, 34744, -13072, 0], [1293848, 0, 0, 294282, -27642, 0, 0, 32214], [0, -486336, 180722, 0, 0, 25210, 20856, 0], [0, -366044, -130300, 0, 0, 17420, -43200, 0], [-1493794, 0, 0, -60392, -22072, 0, 0, 27968], [0, 1978218, 93639, 0, 0, 67191, 19476, 0], [-5201632, 0, 0, -75050, -28590, 0, 0, 6114], [2846399, 0, 0, 72530, 26078, 0, 0, 29310], [-977794, 0, 0, 434842, -23170, 0, 0, -13810], [0, 2124548, 144, 0, 0, -84840, 27336, 0], [733976, 0, 0, 559118, -90486, 0, 0, 20242], [0, 13941, 796259, 0, 0, -33713, -24552, 0], [0, 2021717, 156741, 0, 0, -13387, 89244, 0], [0, 3390382, -93509, 0, 0, -50965, -57180, 0], [-3271150, 0, 0, 811960, -79168, 0, 0, -49072], [535052, 0, 0, 276658, -186610, 0, 0, -12322], [0, 6178991, 366549, 0, 0, -32203, -65780, 0], [0, -2030157, -527919, 0, 0, 32097, -74844, 0], [0, -6601970, -617184, 0, 0, -69080, 13632, 0], [-12975634, 0, 0, 436558, -96350, 0, 0, -76862], [0, -5872375, 185321, 0, 0, 34581, -162816, 0], [0, 2905681, -125353, 0, 0, 33419, 32960, 0], [-7508188, 0, 0, 989061, 245383, 0, 0, 100819], [-9210220, 0, 0, 991720, 259904, 0, 0, 58736], [0, -7637158, 538729, 0, 0, 170465, 10716, 0], [0, 2128641, 523631, 0, 0, -234149, -28344, 0], [0, 8118156, 595649, 0, 0, 100337, 17156, 0], [0, 486338, -19508, 0, 0, -226124, 27672, 0], [0, 13838173, -686088, 0, 0, 93488, 160360, 0], [4982759, 0, 0, -52457, 70713, 0, 0, -116871], [5472104, 0, 0, 2336639, 302837, 0, 0, 18225], [-21938365, 0, 0, -2807470, 14478, 0, 0, -24002], [-6247306, 0, 0, 3955114, 117342, 0, 0, -38322], [0, 7305816, -832556, 0, 0, 240348, 275384, 0], [0, 7366268, 968670, 0, 0, 391742, 146832, 0], [-7800292, 0, 0, 4706416, 93560, 0, 0, 94496], [0, -14068807, 2547808, 0, 0, -226452, 22172, 0], [-4978918, 0, 0, 2062395, 78385, 0, 0, -99347], [-18827038, 0, 0, 345521, 134667, 0, 0, 255631], [0, 9130858, 71418, 0, 0, -242054, 375120, 0], [38859830, 0, 0, -24452, -434540, 0, 0, 88588], [0, -12886556, -937669, 0, 0, 30035, 158012, 0], [33152228, 0, 0, 2125300, 111244, 0, 0, -69644], [0, 10473137, 1474420, 0, 0, 62948, -133920, 0], [0, 14315820, 2723114, 0, 0, 170266, -301992, 0], [13257272, 0, 0, 6872121, 88563, 0, 0, 18735], [7025678, 0, 0, 6117028, -48892, 0, 0, -793516], [0, 22942788, 1180795, 0, 0, -574253, 236620, 0], [0, -4027619, -2248605, 0, 0, 735527, -295232, 0], [92857337, 0, 0, -4916831, 137955, 0, 0, 188223], [-9951316, 0, 0, -1640618, -1086934, 0, 0, 63794], [-20221051, 0, 0, 1282688, 429680, 0, 0, 28512], [0, -5314920, 2002048, 0, 0, 555416, -120600, 0], [22449566, 0, 0, 5337279, -101931, 0, 0, -435999], [0, 41244364, 4327618, 0, 0, 1519554, 36432, 0], [0, -33179722, 410130, 0, 0, -226726, 127032, 0], [-23882089, 0, 0, 12349154, -259470, 0, 0, 155038], [-20625307, 0, 0, -3028163, 229967, 0, 0, -419749], [-57245638, 0, 0, 11254385, -751181, 0, 0, 285215], [0, 76990842, 4066284, 0, 0, -429396, -299952, 0], [0, 42160291, -3322365, 0, 0, 908647, 167304, 0], [0, -23303674, 3448106, 0, 0, 45594, 82920, 0], [0, 22546324, 2568975, 0, 0, 1304847, 1091724, 0], [-55189846, 0, 0, -2422617, 93045, 0, 0, -519663], [-70622638, 0, 0, -10060572, 884676, 0, 0, 18684], [3912713, 0, 0, -1862513, 1535753, 0, 0, 961553], [0, 85957205, -1860371, 0, 0, -28259, -196428, 0], [-92220886, 0, 0, -9656588, -114972, 0, 0, -66756], [-47663416, 0, 0, -9122979, -502129, 0, 0, -1248685], [0, 17438813, -490920, 0, 0, 2374656, 416088, 0], [0, 54089985, -10774577, 0, 0, -557353, 1053948, 0], [0, 70361920, 6770566, 0, 0, -737250, -1099488, 0], [32274836, 0, 0, 4544776, 286896, 0, 0, 5448], [0, 48273465, 4572448, 0, 0, -480408, 334712, 0], [0, -11866547, -7411000, 0, 0, 287052, -680444, 0], [-123032836, 0, 0, -10664298, -1896822, 0, 0, 574746], [-109872808, 0, 0, 21562942, -1106662, 0, 0, -735454], [0, -93079912, 3347091, 0, 0, -851941, -371804, 0], [-202834753, 0, 0, -4728243, -939093, 0, 0, -753069], [73663352, 0, 0, 291076, -800804, 0, 0, -1208972], [0, 18033972, -572977, 0, 0, 1248399, 2081212, 0], [0, 11374820, -2202586, 0, 0, -822282, -1940856, 0], [-301217383, 0, 0, -9909389, 1094437, 0, 0, -1103795], [-3376330, 0, 0, 867970, 967238, 0, 0, -1403002], [0, -11864302, -5232813, 0, 0, -141485, -1094908, 0], [116265581, 0, 0, -7990336, -694608, 0, 0, -2536976], [0, 129697429, 3395291, 0, 0, -1017001, -1616040, 0], [-77096647, 0, 0, -15627947, -1208449, 0, 0, 738923], [0, 110350966, -7346987, 0, 0, -1156947, -64564, 0], [-379139137, 0, 0, -6182693, -1824811, 0, 0, 94445], [252090770, 0, 0, 721664, -644896, 0, 0, 672000], [0, 39235690, 7408888, 0, 0, 622008, -1127760, 0], [0, -193197711, -4131666, 0, 0, -1414222, 237964, 0], [0, 40896742, 17621349, 0, 0, -3101003, 1826588, 0], [278615114, 0, 0, -13881537, -2568483, 0, 0, -1439679], [-268366012, 0, 0, -32190506, -951670, 0, 0, 1435994], [-234146587, 0, 0, 20051684, -2146352, 0, 0, -2829748], [182812112, 0, 0, -29512078, 1407990, 0, 0, -1500866], [0, 176695540, -18248736, 0, 0, -1785752, 2132400, 0], [0, 265914585, -8492114, 0, 0, -1142842, 101184, 0], [0, -166063420, -5340574, 0, 0, 4047066, -1407936, 0], [0, 49481864, -13030712, 0, 0, 3845288, -2798832, 0], [0, -174738027, 6536183, 0, 0, 164659, -1169568, 0], [44168048, 0, 0, 22836046, -2011222, 0, 0, 1143194], [0, 29569140, 8806116, 0, 0, -1398420, -3097608, 0], [-501241105, 0, 0, -6171923, 2707923, 0, 0, 2532507], [-69557266, 0, 0, -37529664, 2759216, 0, 0, -332944], [298308107, 0, 0, 38086873, -604717, 0, 0, 1049159], [0, 82024634, -39988813, 0, 0, -2949109, 752492, 0], [0, 161295546, 34435222, 0, 0, -6101578, -1856232, 0], [0, 76751856, -31593475, 0, 0, 2131741, -424884, 0], [0, -238969348, -4515612, 0, 0, -7998412, 190992, 0], [0, 159260890, -5719122, 0, 0, 225934, 1238456, 0], [222993926, 0, 0, 20835748, 10303628, 0, 0, -150628], [639629360, 0, 0, 13804386, 764038, 0, 0, -2948450], [0, -70158276, -31631676, 0, 0, 5614716, -1493040, 0], [-517210030, 0, 0, 41506613, -161673, 0, 0, -2118869], [0, -97500800, 18613230, 0, 0, -4000922, -5048064, 0], [270522428, 0, 0, 8641235, -2914775, 0, 0, 4327325], [470052596, 0, 0, 998320, -6053968, 0, 0, 303320], [58190954, 0, 0, 37537025, 10562523, 0, 0, 1080511], [0, -238040078, 44147900, 0, 0, 4047500, 2403480, 0], [0, 169604151, -7960802, 0, 0, 1955470, -4532072, 0], [0, -40117693, -25114211, 0, 0, -3620423, 1250040, 0], [33579134, 0, 0, -3943796, -1422252, 0, 0, -2698764], [-114481150, 0, 0, 30265006, 1266362, 0, 0, -5923990], [-756889171, 0, 0, 4975602, 2379978, 0, 0, 4441086], [0, -388001627, 27450667, 0, 0, 546747, -5071908, 0], [-79252750, 0, 0, 48849304, 5936808, 0, 0, -878808], [0, 15263030, 10109010, 0, 0, 4109306, -2956968, 0], [30393131, 0, 0, -60549322, -8562570, 0, 0, 126202], [0, -237570076, 49989851, 0, 0, 6737755, 3151332, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_441_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_441_7_d_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_441_7_d_c(:prec:=8)
    chi := MakeCharacter_441_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 7));
    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_441_7_d_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_441_7_d_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<2,R![4512, -284, -202, 5, 1]>],Snew);
    return Vf;
end function;