
// Make newform 1225.2.a.b in Magma, downloaded from the LMFDB on 09 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1225_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_1225_2_a_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_1225_2_a_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1225_a();"
function MakeCharacter_1225_a()
    N := 1225;
    order := 1;
    char_gens := [1177, 101];
    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_1225_a_Hecke(Kf)
    return MakeCharacter_1225_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 := 2;
    raw_aps := [[-1], [-1], [0], [0], [0], [2], [2], [-6], [3], [7], [-2], [8], [-5], [-7], [0], [-6], [-10], [-7], [5], [-2], [-6], [-2], [-11], [-9], [-16], [-9], [7], [-11], [5], [6], [-16], [-4], [0], [-8], [1], [14], [12], [4], [-3], [-12], [-2], [3], [12], [4], [8], [4], [-10], [0], [-20], [22], [-14], [-18], [14], [-30], [20], [9], [11], [2], [-10], [-14], [16], [24], [23], [-30], [24], [6], [6], [-18], [-15], [17], [-26], [10], [27], [24], [-10], [5], [14], [-16], [3], [25], [-24], [15], [-32], [-2], [-24], [-31], [31], [-32], [-18], [-3], [3], [-42], [12], [-26], [16], [-15], [-27], [-14], [4], [-3], [17], [44], [33], [-18], [-18], [-32], [-36], [22], [-44], [-10], [-33], [34], [4], [-28], [40], [-11], [-4], [47], [26], [6], [9], [36], [-14], [-35], [20], [-1], [-49], [-36], [-47], [-16], [16], [49], [-12], [-22], [-14], [30], [18], [-17], [40], [9], [2], [22], [-25], [39], [30], [-48], [-6], [-12], [32], [9], [2], [43], [-36], [43], [19], [24], [34], [29], [-8], [18], [57], [-60], [13], [32], [-60], [3], [-50], [-2], [-11], [-18], [-12], [51], [50], [-10], [14], [51], [-58], [-6], [29], [23], [19], [18], [40], [-48], [32], [21], [4], [-44], [43], [-40], [-56], [16], [44], [41], [36], [-12], [45], [-44], [-30], [36], [-33], [26], [-10], [35], [2], [18], [14], [12], [5], [20], [-38], [-7], [5], [9], [-32], [10], [63], [13], [-20], [-56], [35], [68], [-19], [-24], [9], [13], [16], [20], [-27], [-42], [-54], [-18], [-8], [-75], [-49], [-41], [5], [-42], [54], [-32], [-12], [56], [0], [-13], [12], [-72], [35], [66], [-68], [20], [44], [-15], [-31], [-55], [-42], [-10], [13], [-31], [48], [30], [-39], [-43], [-34], [-14], [48], [-4], [66], [54], [9], [40], [-9], [-4], [22], [-4], [0], [32], [-60], [59], [17], [-6], [17], [-40], [-24], [-49], [13], [-60], [50], [-8], [-50], [-34], [-33], [63], [-2], [-8], [-26], [31], [-74], [82], [-16], [76], [-62], [-6], [-36], [61], [82], [-34], [-24], [69], [-66], [-38], [-81], [-6], [-69], [65], [27], [-29], [28], [62], [56], [-21], [10], [30], [41], [-61], [-78], [-65], [14], [29], [48], [26], [-38], [72], [-54], [-13], [76], [-57], [-50], [-64], [-25], [16], [80], [-12], [-21], [18], [-36], [-46], [-11], [-27], [-58], [72], [92], [62], [51], [51], [23], [4], [-34], [56], [-46], [-9], [-38], [58], [-17], [-48], [29], [2], [-18], [-16], [-31], [30], [34], [21], [-34], [-32], [-10], [94], [76], [-38], [-6], [82], [35], [30], [71], [-32], [70], [31], [44], [44], [-15], [21], [-26], [44], [42], [-92], [-96], [-38], [34], [-45], [-80], [51], [99], [4], [81], [-36], [-33], [-38], [32], [27], [95], [22], [6], [-12], [32], [-28], [32], [2], [44], [96], [60], [-13], [21], [76], [93], [54], [48], [-84], [24], [27], [0], [-12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1225_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1225_2_a_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_1225_2_a_b(:prec:=1)
    chi := MakeCharacter_1225_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_1225_2_a_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_1225_2_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1225_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, 1]>,<3,R![1, 1]>],Snew);
    return Vf;
end function;