
// Make newform 25.12.b.b in Magma, downloaded from the LMFDB on 18 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_25_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_25_b_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_25_12_b_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_25_12_b_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 := [1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 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_25_b();"
function MakeCharacter_25_b()
    N := 25;
    order := 2;
    char_gens := [2];
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_25_b_Hecke();"
function MakeCharacter_25_b_Hecke(Kf)
    N := 25;
    order := 2;
    char_gens := [2];
    char_values := [[-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]];
    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 := 12;
    raw_aps := [[0, 12], [0, 126], [0, 0], [0, 8372], [534612, 0], [0, -288869], [0, 3452967], [-10661420, 0], [0, 9321636], [-128406630, 0], [-52843168, 0], [0, 91106657], [308120442, 0], [0, -8562854], [0, -1343674248], [0, -798027849], [5189203740, 0], [6956478662, 0], [0, 7740913442], [9791485272, 0], [0, 731895661], [-38116845680, 0], [0, -14667549834], [24992917110, 0], [0, -37506784273], [81742959102, 0], [0, -112877564324], [0, -45120629178], [-73482676310, 0], [0, -42573431319], [0, 131358600512], [631528759932, 0], [0, 148599373107], [-596793577940, 0], [1115433620850, 0], [-824447297848, 0], [0, -657558377203], [0, -178916379794], [0, -1377416946108], [0, -475193724789], [-1681384224780, 0], [-996774496018, 0], [2762403350592, 0], [0, 2721193842721], [0, 1438045752177], [-728391402200, 0], [-6793168439188, 0], [0, 3667431510736], [0, 679919782962], [11824411223170, 0], [0, -8781676724259], [7139577462960, 0], [-231306909358, 0], [12983053545252, 0], [0, -11980596282753], [0, -12136864232244], [-25837706543670, 0], [-3767932360528, 0], [0, 8209466002937], [21035722907082, 0], [0, 8356588163266], [0, -11963429493729], [0, -7655546414278], [49875160575912, 0], [0, -49740416378219], [0, -41684624179683], [-63584021925868, 0], [0, -60500714167993], [0, 77830780539102], [25643022194650, 0], [0, 12454907622801], [-157584150853560, 0], [0, 88950610064792], [0, -27580867011689], [-146463116322980, 0], [0, 115724785866816], [149871571611810, 0], [0, -104055340136923], [-133407937691598, 0], [206167580638390, 0], [-73403515193820, 0], [171111932338622, 0], [-71775829446768, 0], [0, 49940624112841], [29031220908760, 0], [0, 164184924359346], [612368143631550, 0], [0, -151741516455853], [-729307946668938, 0], [0, 61094082036856], [0, 308690341831242], [-1050837984850080, 0], [0, 109954985880932], [-483863128068108, 0], [108877719272500, 0], [0, 253294177893876], [-85753393288710, 0], [927574652509722, 0], [0, -10909325670614], [-1695266465052058, 0], [0, -376072375661998], [0, -93744516467403], [0, 122485642958406], [-1352425875836970, 0], [1432228477996772, 0], [0, 438829662096287], [0, 1217125250891382], [0, -151659106139079], [1701984261329400, 0], [2339216023326602, 0], [0, 1248036243449072], [0, 1236504506258431], [0, -12168388578333], [-4225450805148020, 0], [-4263261111420568, 0], [1008295928583042, 0], [0, 151991208080446], [0, -1717914212065548], [0, -592693578384549], [2265102374509140, 0], [-5330121520762738, 0], [0, 2370599317710961], [0, 706535819320737], [0, -1515578813538534], [-2747313442193908, 0], [5727465442629702, 0], [-698326457818910, 0], [-9709787093595120, 0], [0, -1232343443342788], [0, 3956426199377491], [8406936179151460, 0], [0, 681434897235996], [6817220120892752, 0], [0, 333524487507497], [-7744079729695638, 0], [-2524111226919170, 0], [0, -5572634056233489], [0, -6613552127949718], [0, -1151238879123123], [-5604717670694010, 0], [-5085164185024588, 0], [279110773799022, 0], [0, -6763258930801964], [0, -136271964676338], [-18045917610367430, 0], [7961834707368360, 0], [0, -7491322000695449], [0, 11128065087925947], [-5442366024533060, 0], [0, 5405493713191056], [0, 14051218879735637], [4222089494633682, 0], [0, 258045997718566], [0, -2859530233289268], [0, 42188892150422], [-11009058285505488, 0], [4863513801242680, 0], [-3575343976258530, 0], [0, -19318665862103293], [-34899727878407658, 0], [0, 14256145559207802], [0, 20016717117910101], [0, -9247652154198508], [-21487665696030828, 0], [0, 4369399858782087], [0, 5946213078754116], [23440857788319392, 0], [0, 10700207993699777]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_25_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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