
// Make newform 14.10.a.c in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_14_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_14_10_a_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_14_10_a_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 := [-576, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 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_14_a();"
function MakeCharacter_14_a()
    N := 14;
    order := 1;
    char_gens := [3];
    v := [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_14_a_Hecke(Kf)
    return MakeCharacter_14_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+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 := 10;
    raw_aps := [[-16, 0], [-7, -5], [-1365, -21], [2401, 0], [22470, -1050], [50141, 225], [-435204, 1590], [254387, -13455], [39900, -7140], [1003164, 119490], [1094366, 39330], [-10361788, 143010], [9508296, 517890], [2096858, -345870], [-37271262, 200430], [-1619874, -464520], [-66821181, -1119735], [113900843, -866205], [166465136, -1654380], [-83992860, 6323940], [-22342138, 6043140], [134821388, -2213820], [-91552881, -6075435], [395828874, 6785040], [-2084740, -13989690], [-431689125, 8773275], [197920226, 24992550], [-33054228, -9401280], [136383752, -6929370], [-38538564, -11295690], [2024056424, 11806200], [3450295443, -20710335], [1475534958, 95981340], [2080374149, 3585015], [1541892162, -97417740], [-3226468192, -62130600], [3848138021, 197659305], [4143893834, 66492090], [-11410340802, 103900170], [10528747593, 180291285], [13708148868, 33941040], [-12045985315, -110424375], [26537698284, 9917460], [-10602989656, 277133850], [14407677882, 197811180], [-12771295810, 220997610], [12846821816, -192380580], [-51755175052, -407098260], [15001338723, 1177552785], [-24454653559, -232186995], [21133781874, -1231830600], [-11963394636, -1556937060], [-8326745980, 2969550], [48778240077, 1015790175], [-10848046902, 133671480], [-72880788540, -994354620], [77806476153, -39656955], [20035122464, 1064447280], [126626784230, -842995440], [-85379809206, -308244720], [-35761615477, -207930015], [-26171668761, 333473295], [99816370787, -2847550815], [133045436496, 1156257000], [185109082760, -1110817710], [6858494466, -3281457060], [45316947818, -238057470], [129346407344, 1436462370], [51100938786, -4641966630], [-216291521383, 585350325], [194036549658, 82458120], [454466042136, -412354320], [-206756516932, 5560525620], [-634800362686, -1056445740], [533299138454, -578556090], [56801936226, 3025428990], [64241117628, 10158475530], [-118128065335, 5101893045], [41894126112, 11353006770], [-85020800956, -120919050], [-586806008019, -5162690265], [-325131099730, 6436001880], [-34161716556, -9326587620], [-105113100904, 16109569530], [473445314048, -19855366920], [-909820248312, 5336804340], [129666642858, -6630359400], [925759316000, 8046067050], [370498534917, 16568205945], [411492250712, -9377633160], [391306544559, -5710359435], [-544940799186, -29210333550], [38837560124, -41629924980], [245711700768, -11232986100], [725985460136, 20577041100], [1253744065980, 7500564540], [324786741321, 17623044645], [1577367201816, 27827742930], [2401109946767, 2848500045], [2429663341538, -27319656420], [578657970038, 29487793230], [587483809146, -22007134380], [240385551105, 31343043555], [-2360053291584, -36936845190], [1781818891022, 49172682510], [586178058242, 76756752000], [1855926813993, 72211274835], [1806712108614, -43240087860], [2940404729376, 12032145720], [-1929185494054, -964416960], [680703548672, -39289883040], [-3321712237948, 58730718690], [405119296056, 99424271730], [57313169291, -99081531855], [792267490964, -131826589020], [-497882060328, -49097278230], [-6822399941791, -13740549165], [-3736521372402, -2128621350], [-21193458432, -1834348530], [1935921449886, -84129799530], [-3990962989825, 46458995175], [1864760876606, 138701821860], [-1232028158907, -34428848175], [3995442884448, 131495412300], [5146097300939, 56410539705], [1480350630168, 4487420070], [2751197768444, -103273955190], [-4959941412258, 72718545810], [-4858088769646, 90825667110], [-2864313815965, -49157155125], [-5456015451286, 128961820890], [-1907212578576, 16380842520], [3291091757300, -102330419940], [6344459915852, -164463516630], [2168782238532, 294050862870], [-12107564888776, -24660670230], [4901789848599, -260104412865], [6003272543303, -56100888675], [1390870883073, -96965020275], [8414932536216, -103045366830], [5273579972927, 104517176445], [-5283931768194, 239967244440], [11576316716840, 272703024720], [-19605053452356, 106276080960], [4386080800451, -315644378805], [-20469191697318, -65479370610], [-8972848440871, -161995558995], [-16486004939628, 101390502630], [13258009528589, 54650417535], [6091468024356, 156333733500], [-6087402347812, 197668927890], [12412674580446, -64671161580], [-9731119426540, 411297253920], [-9763881073926, -334929670050], [28538794004204, 201334442400], [-7101555397392, 353180304960], [21995066252936, 85155552720], [-23930309206524, -252630881730], [-890316765898, 592082922420], [19092923103891, -556014545685], [-21238247221626, -47669929650], [9129249372546, -111823374600], [27227446929092, 182050196580], [16405351263819, -591751795695], [10098364564614, -306139850100], [5362426010634, -177060077970], [3612818005544, 213720305400], [-37503682296577, 436537727415]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_14_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_14_10_a_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_14_10_a_c(:prec:=2)
    chi := MakeCharacter_14_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_14_10_a_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_14_10_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_14_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![-57576, 14, 1]>],Snew);
    return Vf;
end function;