
// Make newform 10.7.c.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_10_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_10_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_10_7_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_10_7_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 := [1024, 0, 65, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 33, 0, 1], [5216, 259, 160, 3], [-2608, 113, -80, 1]];
    Rf_basisdens := [1, 32, 32, 16];
    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_10_c();"
function MakeCharacter_10_c()
    N := 10;
    order := 4;
    char_gens := [7];
    v := [3];
    // 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_10_c_Hecke();"
function MakeCharacter_10_c_Hecke(Kf)
    N := 10;
    order := 4;
    char_gens := [7];
    char_values := [[0, 1, 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 := [[4, 4, 0, 0], [-5, 4, 0, -1], [83, 28, 1, 2], [-45, -45, -11, 0], [-570, 13, -13, 13], [197, -199, 0, -2], [3069, 3069, 46, 0], [0, -2750, 34, 34], [8795, -8876, 0, -81], [0, -14320, -232, -232], [-5082, -349, 349, -349], [-17631, -17631, 1356, 0], [28846, 1289, -1289, 1289], [-73301, 73468, 0, 167], [49755, 49755, -1791, 0], [-32903, 28091, 0, -4812], [0, -82390, 2586, 2586], [-56266, 4577, -4577, 4577], [-196189, -196189, 5577, 0], [-261706, -173, 173, -173], [228897, -232289, 0, -3392], [0, -179280, 2704, 2704], [-312797, 306232, 0, -6565], [0, 89680, 1920, 1920], [-479903, -479903, -8960, 0], [319346, 7654, -7654, 7654], [213003, -220148, 0, -7145], [156211, 156211, 13097, 0], [0, 1747775, 4347, 4347], [-80995, 98949, 0, 17954], [-1434189, -1434189, -3443, 0], [1098726, -28271, 28271, -28271], [2112625, 2112625, -33536, 0], [0, 1516970, -58694, -58694], [0, -1428975, -55435, -55435], [-2097418, 77755, -77755, 77755], [1350525, 1350525, 43074, 0], [256603, -240588, 0, 16015], [-484789, -484789, -71423, 0], [3137913, -3184693, 0, -46780], [0, -407810, 172142, 172142], [823098, -112244, 112244, -112244], [4168294, -75693, 75693, -75693], [149213, -389323, 0, -240110], [-1998719, -1998719, 245452, 0], [0, 1322220, 20908, 20908], [3084982, 26645, -26645, 26645], [6052211, -5961280, 0, 90931], [1757739, 1757739, -10339, 0], [0, 14804400, -2424, -2424], [5343709, -5695307, 0, -351598], [0, 12308940, 43644, 43644], [-20183138, 6345, -6345, 6345], [2617622, 545, -545, 545], [-1757891, -1757891, -247314, 0], [8198611, -8344240, 0, -145629], [0, -10705255, -174963, -174963], [-10739754, 247359, -247359, 247359], [-6829075, -6829075, 689234, 0], [7334542, -8615, 8615, -8615], [-6616589, 6506880, 0, -109709], [16938213, -16433223, 0, 504990], [-11279133, -11279133, -704295, 0], [-18595642, -357689, 357689, -357689], [-18417091, 18933173, 0, 516082], [10470781, 10470781, -217838, 0], [22459110, 633173, -633173, 633173], [30855137, 30855137, -308320, 0], [15374923, 15374923, 751733, 0], [0, -36232160, -375384, -375384], [-19709183, 20827711, 0, 1118528], [0, 22217440, 304848, 304848], [-31391021, -31391021, -1130899, 0], [-9539687, 8782907, 0, -756780], [0, -70342370, -580482, -580482], [11312819, -12467872, 0, -1155053], [0, 18942495, 782091, 782091], [23729393, 23729393, 1171468, 0], [-67983262, -484624, 484624, -484624], [0, 9031965, -2110007, -2110007], [0, 85154130, 650386, 650386], [31381062, 1272265, -1272265, 1272265], [51426422, 1567815, -1567815, 1567815], [-88947071, 89216463, 0, 269392], [0, -65580400, 1014688, 1014688], [38355827, -40017664, 0, -1661837], [0, 11546435, -1688121, -1688121], [-30083763, -30083763, 584190, 0], [87213602, -96810, 96810, -96810], [-2467573, 943756, 0, -1523817], [-9662149, -9662149, -1653003, 0], [0, -753340, 364020, 364020], [-10917021, -10917021, -1179939, 0], [1941318, 2252141, -2252141, 2252141], [0, -31034230, 1553738, 1553738], [29027019, -27783252, 0, 1243767], [0, 95401280, 1158024, 1158024], [1538602, -1639070, 1639070, -1639070], [-125893181, 125567368, 0, -325813], [-26221246, -1912058, 1912058, -1912058], [124056779, 124056779, 1248941, 0], [-110471407, -110471407, -2721652, 0], [-90047061, 88203228, 0, -1843833], [0, 36605155, -3329449, -3329449], [-103208058, 1527445, -1527445, 1527445], [-104550851, -104550851, -170034, 0], [148756491, 148756491, -542523, 0], [37568737, -31678929, 0, 5889808], [0, 55272380, 763292, 763292], [-6589810, -140967, 140967, -140967], [-197943621, -197943621, 566721, 0], [74399045, -68858311, 0, 5540734], [26779277, 26779277, 5482190, 0], [0, 305222490, -1314390, -1314390], [216146438, -4289129, 4289129, -4289129], [73044862, -1472055, 1472055, -1472055], [200979539, -196745392, 0, 4234147], [-111603165, -111603165, -8686051, 0], [-98528263, 95909531, 0, -2618732], [0, -320867150, 2790162, 2790162], [-313943482, 4153521, -4153521, 4153521], [164508833, -167840673, 0, -3331840], [174287361, 174287361, -3037268, 0], [-114953749, 123529820, 0, 8576071], [8174102, -9434515, 9434515, -9434515], [163649430, 7099273, -7099273, 7099273], [0, 319083280, -5200536, -5200536], [0, -547125460, -780900, -780900], [-60656365, -60656365, 6117989, 0], [227635545, -223199141, 0, 4436404], [0, 323643710, -119218, -119218], [-248148957, 249567832, 0, 1418875], [-424904634, -680301, 680301, -680301], [90110349, 90110349, 4513506, 0], [198830130, -965912, 965912, -965912], [0, -25255000, 9174984, 9174984], [-158426747, 148356697, 0, -10070050], [109878675, 109878675, 2484689, 0], [-129907651, -129907651, 4051826, 0], [0, 206936080, 1131104, 1131104], [140862070, 12705953, -12705953, 12705953], [-379845242, -6139999, 6139999, -6139999], [285518651, -275432540, 0, 10086111], [-44094997, -44094997, 15103013, 0], [0, -220582375, -6968339, -6968339], [0, 425836540, 2886204, 2886204], [-338513755, 345306729, 0, 6792974], [-387053039, -387053039, 12045472, 0], [0, -25118710, -13915462, -13915462], [-61321541, 41774148, 0, -19547393], [-266499683, -266499683, -5492510, 0], [855498462, 7848505, -7848505, 7848505], [13105643, -26541828, 0, -13436185], [201098147, 201098147, -6780115, 0], [559559731, 559559731, -6349143, 0], [-548756858, 6214755, -6214755, 6214755], [0, -568151740, 13599108, 13599108], [0, -942776515, -6832135, -6832135], [-96372883, -96372883, -100130, 0], [655150858, 11990956, -11990956, 11990956], [-105785213, -105785213, 3281385, 0], [645853469, -660215227, 0, -14361758], [245621947, 245621947, 3358425, 0], [427635542, 2103145, -2103145, 2103145], [-590100895, -590100895, -14564176, 0], [563658659, -556844232, 0, 6814427], [-148578698, 10677135, -10677135, 10677135], [416815373, 416815373, -3785342, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_10_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_10_7_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_10_7_c_b(:prec:=4)
    chi := MakeCharacter_10_c();
    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_10_7_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_10_7_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_10_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<3,R![2471184, -28296, 162, 18, 1]>],Snew);
    return Vf;
end function;