
// Make newform 16.15.c.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_16_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_16_c_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_16_15_c_b();".
// 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_16_15_c_b();".
// 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 := [849, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-48, 96]];
    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_16_c();"
function MakeCharacter_16_c()
    N := 16;
    order := 2;
    char_gens := [15, 5];
    v := [1, 2];
    // 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_16_c_Hecke();"
function MakeCharacter_16_c_Hecke(Kf)
    N := 16;
    order := 2;
    char_gens := [15, 5];
    char_values := [[-1, 0], [1, 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 := 15;
    raw_aps := [[0, 0], [0, -1], [107850, 0], [0, 522], [0, 7425], [59275450, 0], [-44896350, 0], [0, 306675], [0, 490158], [30520168602, 0], [0, -12396600], [-125971660150, 0], [-41444675982, 0], [0, -35870679], [0, -1583604], [473374435050, 0], [0, -1130436675], [-58526672422, 0], [0, 1493137935], [0, 5611095450], [14644904168050, 0], [0, -2995497900], [0, 8806141827], [3585960554322, 0], [65197469070850, 0], [-4730550416118, 0], [0, -28336683870], [0, -100697615559], [-139743614178182, 0], [185435865679650, 0], [0, -91058573664], [0, -8610005025], [-1063473884393550, 0], [0, -312508108575], [-599280080701782, 0], [0, -732120620850], [3217640420922650, 0], [0, 737696115783], [0, 507091281714], [-132564384726150, 0], [0, -1111185425925], [-3836083230871958, 0], [0, 461688433200], [-1234742283855550, 0], [-2949655972682550, 0], [0, -5607134814150], [0, 8903703802275], [0, -2695602982536], [0, -12397559772393], [17105008272020362, 0], [-70335415126841550, 0], [0, -28175453756100], [72378666423282658, 0], [0, 11717522369325], [-57303711262909950, 0], [0, -2929965115446], [42875242901169978, 0], [0, -13793346373500], [70353324509060650, 0], [11903995437132498, 0], [0, 82293108777045], [-226382381483695350, 0], [0, 112345748542683], [0, -52859935485450], [-12844655539480750, 0], [-517156269582531750, 0], [0, -51486307448175], [-356376615354446750, 0], [0, -173001974549787], [972710159507840282, 0], [-643469246997090750, 0], [0, 350613253159650], [0, -367646867122212], [-902084501509657750, 0], [0, -264581474461875], [0, -532123830838944], [-1452048712749335862, 0], [-1916610453783319750, 0], [2284146690928965282, 0], [1552017116615847058, 0], [0, 526967595167175], [-2360934150803066102, 0], [0, -1453936376250900], [4354752233250942050, 0], [0, 874022114352150], [0, 1380670725519837], [5136396551294399298, 0], [3371453342004435250, 0], [-650855933907051078, 0], [0, -2483454416285772], [0, 2278046458142883], [0, -3072631863817800], [0, 1719586532459394], [0, -2990270698878375], [0, -1165296790631925], [0, 3557933595482022], [12871480922575817562, 0], [9550602957105473202, 0], [0, -101374614830079], [2914087891996134682, 0], [0, -2934688659381657], [-26866910852210454150, 0], [0, 7131887132018715], [-27431565007007559342, 0], [0, -1763887732812675], [-12646024861713466750, 0], [0, -5179561216920495], [-4622714441460117150, 0], [0, -15524539972848450], [16216237937483850578, 0], [0, 7558054288055640], [32759870858299987850, 0], [-10986365730967673550, 0], [0, 14469970943079225], [0, 8895144657745350], [68468248913696353218, 0], [0, -25478426566640673], [0, 20245259475890730], [-3546811848465361350, 0], [0, 34157593519873875], [34557149625653991338, 0], [-27220791107081012350, 0], [269677013228858250, 0], [0, 23567768240852169], [0, -35809661763137925], [53793884415965524698, 0], [150459969457798957642, 0], [0, -59916888605061900], [0, -55370150222719266], [-37581451645887851750, 0], [0, 39623320505748375], [0, 52416022555722690], [0, 30017189885082300], [-177335160213419254550, 0], [-259567508061131205678, 0], [-107657354259956631358, 0], [41996835542004693450, 0], [0, 102361033304862579], [169043364524584513050, 0], [-11255531215953257358, 0], [0, -56042213957637975], [214513573660884021738, 0], [0, 49960901470718070], [0, 80845834197142845], [-294368352620841771302, 0], [0, -170250103004365350], [572547741859259969450, 0], [-362001281787902784750, 0], [0, 10096618294426725], [0, 100689871225695768], [-222662823133916988550, 0], [-526201703607262414302, 0], [0, 191214131437823787], [0, -38088046203404922], [0, -47426214134846943], [0, 210137604688145700], [0, 112996259184631950], [-1103867667579234740862, 0], [484375994381825289650, 0], [105841371636975226362, 0], [0, 255775500842365179], [512145896272343533650, 0], [0, -452338505121792006], [0, 355838787922928625], [-803795147799384361950, 0], [0, -243907316036843490], [0, -80550808071510600], [-155465996500768789750, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_16_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_16_15_c_b();".
// 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_16_15_c_b(:prec:=2)
    chi := MakeCharacter_16_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 15));
    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_16_15_c_b();".
// 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_16_15_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_16_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,15,sign)));
    Vf := Kernel([<3,R![7822080, 0, 1]>],Snew);
    return Vf;
end function;