
// Make newform 25.7.c.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_25_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_25_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_25_7_c_a();".
// 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_7_c_a();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_c();"
function MakeCharacter_25_c()
    N := 25;
    order := 4;
    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_c_Hecke();"
function MakeCharacter_25_c_Hecke(Kf)
    N := 25;
    order := 4;
    char_gens := [2];
    char_values := [[0, 1]];
    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 := [[-3, -3], [33, -33], [0, 0], [207, 207], [-1188, 0], [1548, -1548], [3252, 3252], [0, 5060], [5313, -5313], [0, -8910], [25432, 0], [20592, 20592], [-19008, 0], [80343, -80343], [16137, 16137], [-155892, 155892], [0, 360180], [178112, 0], [-240273, -240273], [-617328, 0], [-306612, 306612], [0, -232760], [-134097, 134097], [0, 270270], [810612, 810612], [-1762398, 0], [-938817, 938817], [1521657, 1521657], [0, -117920], [965448, -965448], [716247, 716247], [-963468, 0], [66792, 66792], [0, -426580], [0, -3088800], [3914152, 0], [-3943368, -3943368], [661023, -661023], [1716927, 1716927], [-3908712, 3908712], [0, -7478460], [-8800418, 0], [5683392, 0], [-1255932, 1255932], [-3973188, -3973188], [0, 7741600], [-5058988, 0], [4711113, -4711113], [497697, 497697], [0, 8236190], [12989628, -12989628], [0, -3932280], [11654192, 0], [3690252, 0], [7784832, 7784832], [1467423, -1467423], [0, -19621440], [-9203128, 0], [-20615328, -20615328], [-36395568, 0], [1630953, -1630953], [13114968, -13114968], [-6044193, -6044193], [-29784888, 0], [-400752, 400752], [-40661148, -40661148], [9620732, 0], [-21431808, -21431808], [51344487, 51344487], [0, -21130450], [-26988192, 26988192], [0, -9016920], [41057577, 41057577], [9560088, -9560088], [0, -66764860], [66199353, -66199353], [0, 34477920], [40351212, 40351212], [-74854098, 0], [0, 130148480], [0, -104965740], [-32529728, 0], [-19704168, 0], [-70213572, 70213572], [0, 109253320], [-2070057, 2070057], [0, -84704400], [-45366768, -45366768], [86381262, 0], [-93606777, 93606777], [26542527, 26542527], [0, -67264560], [83227617, 83227617], [169894692, 0], [0, 112385500], [84972783, -84972783], [0, -43567470], [106987122, 0], [-92247687, 92247687], [-244414258, 0], [32317137, 32317137], [-5417568, -5417568], [37143873, -37143873], [0, -217499040], [155107172, 0], [-222400728, -222400728], [172769817, 172769817], [65058168, -65058168], [0, -8197200], [171402352, 0], [124641657, 124641657], [-3566052, 3566052], [192655452, 192655452], [0, 166124860], [-232976968, 0], [-198771408, 0], [310830993, -310830993], [-185001663, -185001663], [53858508, -53858508], [0, 124840980], [246399712, 0], [-332338212, 332338212], [-392435028, -392435028], [-80018697, 80018697], [124098892, 0], [-665394048, 0], [0, -410059870], [0, 316685160], [-432149553, -432149553], [-176122872, 176122872], [0, -686278780], [185043393, -185043393], [185168752, 0], [139487832, 139487832], [-39279438, 0], [0, 431053810], [55309188, -55309188], [233171217, 233171217], [-573296988, -573296988], [0, 303738930], [-753778388, 0], [161976672, 0], [-326681487, 326681487], [404806647, 404806647], [0, -857649760], [0, -320361480], [388384308, -388384308], [562507032, 562507032], [0, 847272580], [-779331927, 779331927], [-741247128, -741247128], [383908032, 0], [50524353, -50524353], [131857167, 131857167], [73982007, 73982007], [522926712, 0], [0, -871858240], [0, 345641040], [465551892, 465551892], [1136288142, 0], [-538433313, -538433313], [136529208, -136529208], [-328178223, -328178223], [1357906572, 0], [-29083428, -29083428], [598045503, -598045503], [-1008441808, 0], [1063010412, 1063010412]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_25_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_25_7_c_a();".
// 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_7_c_a(:prec:=2)
    chi := MakeCharacter_25_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_25_7_c_a();".
// 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_7_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_25_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<2,R![18, 6, 1]>],Snew);
    return Vf;
end function;