
// Make newform 15.10.a.d in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_15_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_15_10_a_d();".
// 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_10_a_d();".
// 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 := [-60, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 3]];
    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_15_a();"
function MakeCharacter_15_a()
    N := 15;
    order := 1;
    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;

function MakeCharacter_15_a_Hecke(Kf)
    return MakeCharacter_15_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 := [[15, -1], [-81, 0], [625, 0], [6944, -224], [-9572, 2368], [14814, 5344], [-82238, -7520], [-45084, 5728], [-380768, -26272], [-1254818, 168576], [5467584, 152736], [11083414, 198496], [13276234, 492096], [-3244412, 702336], [-16775384, -1970528], [1654422, 177728], [-15573156, 4348352], [170273566, -950208], [-144611188, -1026560], [107415672, 4545280], [-116915638, -1168192], [-21902080, -19049120], [-189671220, -7260288], [-218344134, -9049152], [892554882, 13450880], [-31369562, -76339072], [725554768, -18530144], [-942457804, 32784832], [2202285486, 4944128], [-216546110, 67408672], [-205274408, 148987680], [-3720446124, -73759488], [-171588230, 8056544], [2696557724, -78164448], [6860733238, -81457536], [1504738552, 74641440], [4525020910, -218923616], [-2734064964, -441527680], [-13602680096, -217991584], [2682470350, 97645952], [-10818725580, -91033600], [16580596054, 440736256], [-28426831152, 50322688], [-5157600510, -197347648], [12222732838, -4988992], [4780779448, 622888224], [-21986291916, 573460256], [-39328591576, -217101216], [-9727045396, -1943163904], [21919902054, -707329728], [14527621498, 1740473696], [47028993136, 1410808768], [-40499632782, -921274112], [35830918572, -302770560], [62201360466, 2641365792], [-1510369744, -2676122080], [38313741166, 3901468288], [-39828564912, 2424273568], [23028378918, -5051951712], [-7910378950, -3070613696], [-66002099596, 4180081024], [-88535669594, -6094350400], [-22000400484, -1678970048], [226418250088, -3932283712], [-39901545894, 11648962880], [-216341820194, 3860016192], [-81793861268, 4094383520], [-190440274702, -3914243392], [-123813516508, 9414546240], [-257577440098, -6198789184], [-399369068846, -2493738016], [-37959466456, 9968108032], [-120067883832, 3874085088], [69644422278, -22646649824], [407613344140, -2376291360], [416630740936, -4461324640], [-273054451546, -6480877568], [152088444766, 18037391712], [65817100306, 9219585152], [-107976483366, 1866094592], [-431341744604, 20115925248], [264189521350, -30452016576], [-383035491136, -24649266944], [4484168306, 9052740800], [496233153640, 11974154400], [380039739764, -45199767296], [-338159137662, -4989801856], [46597973834, -29185669504], [-4115968178, -11951695360], [286723059768, 14186013216], [1011781915036, -31971974208], [-1092091543040, -13139368960], [-727692503488, 25724281440], [-715821512644, 10952873792], [-483918022684, -75862493152], [-396174700416, 32289155104], [117777702974, -30038673408], [1417398505674, -42763842944], [-600495544572, 20003822656], [-1687593850946, 60443684096], [1638827087084, 2027062016], [661172868302, -130537329920], [-778091618740, 65027768512], [1806128347706, 62047779328], [1256229807068, -108283921632], [-442011439358, 51464515840], [3306421766836, 54720855872], [2251058826978, 32900418976], [714715619128, -208452550656], [2140496646618, -4076876032], [1998398920792, 50887058400], [-3610415134410, 31483876192], [2080848788090, 173577434464], [-1016066784996, 222595998752], [-312390785928, -220860628640], [2139543556834, 117520033856], [-17063976292, -24946663424], [599320024192, 173337176800], [-3811587197554, -141835928320], [3645082149300, 69801369920], [-1582685534218, -184650191680], [-1049018462238, 43437826368], [-819836188122, 236616323328], [-6927667319004, -122231317440], [-2982564299532, 229077560608], [3197635523806, -141338813568], [-7488785833914, -91615771712], [2202459315408, -336446406336], [-278948208880, 301820692704], [-4863102957202, 243749661216], [5023419819444, 113158847392], [-4959462408432, 119784448736], [2904488261968, -54743940192], [-14134316039930, 56714993184], [13049459844410, 137613457024], [4350305156098, 41881066624], [-9402354909914, -141157819840], [8314102131356, 174431446592], [8665831420126, -536761304448], [-1680691003830, -63000724160], [-7643635709588, 234398792480], [-8869515159850, 113327739904], [6499744257280, -120212104928], [-2099710173148, 860390563200], [4753791493950, -315079902720], [2781427565800, -79514213760], [-8842472111194, -541877887520], [-7251772645014, 684658876832], [6538836794380, -648857853600], [-7899671750232, 537881271136], [-4626314305666, 149545530016], [13961335515090, -437788739776], [5506774559468, 723661330176], [21001407691536, -307880897568], [-1465726713804, -287092584768], [-4084712329888, -1616765630400], [-10430961274520, 814449574560], [-32587300257374, -515939296512], [-4843244769142, -1353662945792], [-1529199040466, 1718769707136], [-639634079140, -415241439296], [13081531881194, 81863860704], [9723649623872, 639442456800], [-15637708238116, 216554845696], [3210433760962, -812519523680], [5914514882592, 1176613260768], [-10220424948128, 1789201504480], [4408792187350, 1947530825504]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_15_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_15_10_a_d();".
// 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_10_a_d(:prec:=2)
    chi := MakeCharacter_15_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_15_10_a_d();".
// 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_10_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_15_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![-302, -31, 1]>],Snew);
    return Vf;
end function;