
// Make newform 15.7.d.c in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_15_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_15_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_15_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_15_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 := [5736025, 0, 206220, 0, 7774, 0, 60, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [164874195, 1771445, 11638263, 198313, 64665, 1615, 1437, -13], [3437, 0, 30, 0, 1, 0, 0, 0], [0, -1771445, 0, -198313, 0, -1615, 0, 13], [-64110, 0, -4724, 0, -45, 0, -1, 0], [0, -606845, 0, 411827, 0, 1985, 0, 73], [0, 666060, 0, 10169, 0, 60, 0, 1], [16635670, 20279345, 143700, 433499, 4790, 6055, 0, 61]];
    Rf_basisdens := [1, 10346400, 36, 5173200, 225, 5173200, 43110, 344880];
    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_15_d();"
function MakeCharacter_15_d()
    N := 15;
    order := 2;
    char_gens := [11, 7];
    v := [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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_15_d_Hecke();"
function MakeCharacter_15_d_Hecke(Kf)
    N := 15;
    order := 2;
    char_gens := [11, 7];
    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 := [[0, 0, 0, 0, 0, -1, 0, 0], [0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 0, 2, 0, -7, 1, 0], [0, -6, 0, -3, 1, 0, 0, 0], [-3, 0, -3, 1, 0, -1, -8, 6], [0, -60, 0, -30, -1, 0, 0, 0], [0, 0, 0, 69, 0, -187, 0, 0], [-3565, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 609, 0, -160, 0, 0], [-51, 0, -51, -65, 0, 65, 28, 102], [737, 0, -185, 0, 0, 0, 0, 0], [0, 708, 0, 354, -27, 0, 0, 0], [-87, 0, -87, -196, 0, 196, 218, 174], [0, -1266, 0, -633, 16, 0, 0, 0], [0, 0, 0, 617, 0, 13026, 0, 0], [0, 0, 0, -1539, 0, -12763, 0, 0], [393, 0, 393, 1925, 0, -1925, -3064, -786], [186677, 0, 1795, 0, 0, 0, 0, 0], [0, -10878, 0, -5439, -280, 0, 0, 0], [-666, 0, -666, 402, 0, -402, -2136, 1332], [0, 14448, 0, 7224, 738, 0, 0, 0], [-160795, 0, 8731, 0, 0, 0, 0, 0], [0, 0, 0, -5487, 0, -31216, 0, 0], [-618, 0, -618, -3030, 0, 3030, 4824, 1236], [0, -34104, 0, -17052, 1732, 0, 0, 0], [975, 0, 975, -2795, 0, 2795, 7540, -1950], [0, -11658, 0, -5829, -1645, 0, 0, 0], [0, 0, 0, -9127, 0, -288, 0, 0], [-911755, 0, 11011, 0, 0, 0, 0, 0], [0, 0, 0, 43205, 0, -49479, 0, 0], [0, -27090, 0, -13545, -3471, 0, 0, 0], [-429, 0, -429, 17303, 0, -17303, -35464, 858], [0, 0, 0, 9861, 0, 234065, 0, 0], [-202885, 0, -38919, 0, 0, 0, 0, 0], [-10740, 0, -10740, -2365, 0, 2365, -16750, 21480], [-2574763, 0, -24645, 0, 0, 0, 0, 0], [0, -131076, 0, -65538, 4751, 0, 0, 0], [0, 170850, 0, 85425, 6144, 0, 0, 0], [0, 0, 0, 159849, 0, 391418, 0, 0], [0, 0, 0, -228411, 0, -354655, 0, 0], [4059, 0, 4059, -23205, 0, 23205, 54528, -8118], [-1536508, 0, -19670, 0, 0, 0, 0, 0], [-19332, 0, -19332, -37856, 0, 37856, 37048, 38664], [0, -109656, 0, -54828, 6836, 0, 0, 0], [0, 0, 0, -260043, 0, 722741, 0, 0], [5079485, 0, 46611, 0, 0, 0, 0, 0], [-2315593, 0, 126085, 0, 0, 0, 0, 0], [0, -283662, 0, -141831, 10903, 0, 0, 0], [0, 0, 0, 122505, 0, -1102246, 0, 0], [9238310, 0, -203204, 0, 0, 0, 0, 0], [0, 0, 0, 317573, 0, 1743669, 0, 0], [-5628, 0, -5628, 65300, 0, -65300, -141856, 11256], [-4702663, 0, 104335, 0, 0, 0, 0, 0], [-25095, 0, -25095, 37245, 0, -37245, -124680, 50190], [0, 0, 0, -550107, 0, -1055143, 0, 0], [0, 0, 0, 299345, 0, -1976064, 0, 0], [47496, 0, 47496, 23985, 0, -23985, 47022, -94992], [-14662243, 0, -310445, 0, 0, 0, 0, 0], [0, 546180, 0, 273090, 9889, 0, 0, 0], [-32409, 0, -32409, -89972, 0, 89972, 115126, 64818], [0, 1227066, 0, 613533, -2578, 0, 0, 0], [0, 0, 0, -636243, 0, 760793, 0, 0], [0, 530454, 0, 265227, -48174, 0, 0, 0], [123462, 0, 123462, 97526, 0, -97526, 51872, -246924], [0, -920040, 0, -460020, 47914, 0, 0, 0], [0, 0, 0, 142509, 0, 1694453, 0, 0], [-9703033, 0, 488805, 0, 0, 0, 0, 0], [0, 400128, 0, 200064, 78188, 0, 0, 0], [0, 0, 0, 195017, 0, 3494226, 0, 0], [20422340, 0, 435226, 0, 0, 0, 0, 0], [0, 0, 0, 1876181, 0, -2149143, 0, 0], [-80202, 0, -80202, 57810, 0, -57810, -276024, 160404], [0, -1298718, 0, -649359, 2395, 0, 0, 0], [0, -2336652, 0, -1168326, -25327, 0, 0, 0], [-11259145, 0, -472619, 0, 0, 0, 0, 0], [0, 0, 0, -2332647, 0, 2934674, 0, 0], [168702, 0, 168702, 219115, 0, -219115, -100826, -337404], [0, 216756, 0, 108378, -155193, 0, 0, 0], [-105420, 0, -105420, -638860, 0, 638860, 1066880, 210840], [18218465, 0, 1442071, 0, 0, 0, 0, 0], [257331, 0, 257331, 22295, 0, -22295, 470072, -514662], [-79900723, 0, -380885, 0, 0, 0, 0, 0], [-74424, 0, -74424, -312012, 0, 312012, 475176, 148848], [0, -910824, 0, -455412, 195792, 0, 0, 0], [11500145, 0, -726329, 0, 0, 0, 0, 0], [0, 0, 0, -1495983, 0, -10754422, 0, 0], [-69015, 0, -69015, -294150, 0, 294150, 450270, 138030], [0, 2576424, 0, 1288212, -105314, 0, 0, 0], [-99063, 0, -99063, 406771, 0, -406771, -1011668, 198126], [0, 5186850, 0, 2593425, -77221, 0, 0, 0], [0, 0, 0, 3808329, 0, -3978952, 0, 0], [-317196, 0, -317196, -273560, 0, 273560, -87272, 634392], [0, -1298442, 0, -649221, 11163, 0, 0, 0], [-215547, 0, -215547, -489151, 0, 489151, 547208, 431094], [54775475, 0, 1764481, 0, 0, 0, 0, 0], [0, 0, 0, -1770999, 0, 6897002, 0, 0], [-134547, 0, -134547, 420575, 0, -420575, -1110244, 269094], [292914, 0, 292914, 114582, 0, -114582, 356664, -585828], [0, 6490158, 0, 3245079, 42768, 0, 0, 0], [73463222, 0, 245340, 0, 0, 0, 0, 0], [0, -7200474, 0, -3600237, 22942, 0, 0, 0], [0, 0, 0, -7562107, 0, 7053057, 0, 0], [0, 0, 0, 2241545, 0, -221064, 0, 0], [-47409, 0, -47409, 910780, 0, -910780, -1916378, 94818], [17257427, 0, -3602735, 0, 0, 0, 0, 0], [0, 5796240, 0, 2898120, -81936, 0, 0, 0], [0, 0, 0, 103761, 0, -1716310, 0, 0], [0, 0, 0, 5667957, 0, 1863593, 0, 0], [-142410, 0, -142410, -925210, 0, 925210, 1565600, 284820], [-167730823, 0, 1675375, 0, 0, 0, 0, 0], [0, 10320174, 0, 5160087, 385841, 0, 0, 0], [0, -13758900, 0, -6879450, -349191, 0, 0, 0], [0, 0, 0, 2565909, 0, 1557053, 0, 0], [141750335, 0, 2263101, 0, 0, 0, 0, 0], [175419017, 0, 479455, 0, 0, 0, 0, 0], [641463, 0, 641463, 1850134, 0, -1850134, -2417342, -1282926], [0, 6259494, 0, 3129747, 226526, 0, 0, 0], [0, 0, 0, -1416063, 0, 28756496, 0, 0], [0, 0, 0, 10232661, 0, -9121963, 0, 0], [284043, 0, 284043, 45955, 0, -45955, 476176, -568086], [225301277, 0, -858405, 0, 0, 0, 0, 0], [0, 424488, 0, 212244, 933268, 0, 0, 0], [0, 0, 0, 7618685, 0, -38708691, 0, 0], [0, 0, 0, -15584727, 0, -6794206, 0, 0], [-356587093, 0, -1114055, 0, 0, 0, 0, 0], [-270180, 0, -270180, -2159235, 0, 2159235, 3778110, 540360], [-110474620, 0, 1014666, 0, 0, 0, 0, 0], [-549024, 0, -549024, -1861860, 0, 1861860, 2625672, 1098048], [0, 698790, 0, 349395, -505481, 0, 0, 0], [0, 18240876, 0, 9120438, -307273, 0, 0, 0], [-254521405, 0, 3756721, 0, 0, 0, 0, 0], [0, 0, 0, -19928263, 0, 47947098, 0, 0], [711517517, 0, 1313395, 0, 0, 0, 0, 0], [0, 901044, 0, 450522, 1365201, 0, 0, 0], [132462, 0, 132462, -1211014, 0, 1211014, 2686952, -264924], [13500080, 0, -3951314, 0, 0, 0, 0, 0], [0, 0, 0, -5203371, 0, -66346315, 0, 0], [0, 11605398, 0, 5802699, -847342, 0, 0, 0], [0, 0, 0, 16746477, 0, -3561739, 0, 0], [-279462, 0, -279462, 700830, 0, -700830, -1960584, 558924], [739375967, 0, -1388835, 0, 0, 0, 0, 0], [-2538126, 0, -2538126, -1291913, 0, 1291913, -2492426, 5076252], [0, -16015482, 0, -8007741, 193943, 0, 0, 0], [0, 0, 0, 10239345, 0, 30195944, 0, 0], [120785285, 0, 6625971, 0, 0, 0, 0, 0], [-178458, 0, -178458, 3206410, 0, -3206410, -6769736, 356916], [0, 8872572, 0, 4436286, -1352675, 0, 0, 0], [0, 0, 0, -3192267, 0, 23809097, 0, 0], [-273431485, 0, 378721, 0, 0, 0, 0, 0], [0, 0, 0, 22537545, 0, -32603614, 0, 0], [0, -30470580, 0, -15235290, 1214219, 0, 0, 0], [-917229, 0, -917229, 2211378, 0, -2211378, -6257214, 1834458], [0, 9161106, 0, 4580553, 1325652, 0, 0, 0], [0, 0, 0, -11161119, 0, -52167040, 0, 0], [0, 29306634, 0, 14653317, 1072066, 0, 0, 0], [781272, 0, 781272, -3638804, 0, 3638804, 8840152, -1562544], [220017305, 0, 5190111, 0, 0, 0, 0, 0], [580239, 0, 580239, 1764190, 0, -1764190, -2367902, -1160478], [0, -14083872, 0, -7041936, -1191942, 0, 0, 0], [3302793, 0, 3302793, 3103619, 0, -3103619, 398348, -6605586], [0, 0, 0, 43760937, 0, -97384054, 0, 0], [0, 0, 0, -39787579, 0, -12853503, 0, 0], [0, -17818758, 0, -8909379, -2042695, 0, 0, 0], [177249, 0, 177249, 8707257, 0, -8707257, -17060016, -354498], [0, 0, 0, -44552155, 0, -25852731, 0, 0], [0, 0, 0, -15464967, 0, 118883354, 0, 0], [-244538263, 0, -3007265, 0, 0, 0, 0, 0], [0, -71833764, 0, -35916882, -931103, 0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_15_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_15_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_15_7_d_c(:prec:=8)
    chi := MakeCharacter_15_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_15_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_15_7_d_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_15_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<2,R![640, 0, -146, 0, 1]>],Snew);
    return Vf;
end function;