
// Make newform 1950.2.a.bb in Magma, downloaded from the LMFDB on 10 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1950_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_1950_2_a_bb();".
// 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_1950_2_a_bb();".
// 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_1950_a();"
function MakeCharacter_1950_a()
    N := 1950;
    order := 1;
    char_gens := [1301, 1327, 301];
    v := [1, 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_1950_a_Hecke(Kf)
    return MakeCharacter_1950_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]];
    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], [3], [-3], [1], [3], [0], [4], [5], [-3], [-12], [2], [4], [3], [9], [15], [-3], [-7], [-8], [-16], [0], [-1], [0], [-2], [-3], [-6], [-2], [10], [14], [-12], [-18], [-12], [10], [10], [17], [-7], [4], [-12], [-1], [10], [17], [-18], [-26], [-2], [-10], [12], [-16], [13], [-10], [-6], [-5], [22], [2], [-27], [-26], [5], [-3], [-2], [-18], [-6], [-26], [28], [2], [19], [28], [-28], [-27], [18], [-20], [14], [-15], [28], [29], [15], [-16], [-30], [-22], [12], [-10], [30], [-28], [12], [-26], [0], [4], [-20], [18], [-38], [9], [-32], [15], [43], [2], [5], [-6], [10], [22], [14], [32], [-22], [18], [4], [15], [-28], [-22], [33], [-6], [30], [-3], [18], [-26], [-42], [-20], [12], [17], [44], [48], [39], [40], [42], [-51], [-42], [-21], [17], [27], [-10], [30], [-42], [4], [5], [-21], [12], [43], [-28], [40], [34], [3], [33], [-10], [-43], [-28], [44], [3], [15], [0], [-16], [-22], [40], [39], [8], [7], [-16], [48], [8], [52], [50], [-10], [13], [52], [-57], [29], [-37], [42], [-52], [29], [-8], [-17], [20], [-21], [20], [52], [-18], [4], [-10], [45], [-3], [2], [34], [55], [8], [32], [34], [-52], [-1], [-10], [-37], [-1], [20], [27], [34], [19], [-48], [12], [-2], [-31], [52], [19], [18], [34], [-40], [-8], [-2], [25], [65], [38], [-5], [-66], [20], [-58], [43], [-58], [44], [-67], [45], [-28], [-2], [-3], [-7], [-56], [-58], [40], [-40], [-11], [8], [-65], [-6], [10], [-22], [-13], [-46], [-20], [57], [2], [-16], [48], [10], [24], [0], [12], [-36], [72], [74], [-20], [-36], [30], [28], [-8], [55], [34], [-32], [-48], [-12], [-5], [34], [-45], [-38], [13], [-27], [58], [-26], [-32], [-20], [-6], [-52], [-60], [-30], [12], [-71], [39], [42], [-77], [74], [30], [-57], [-41], [68], [-20], [-8], [-18], [-66], [-8], [-72], [2], [33], [72], [-51], [78], [35], [-45], [7], [18], [-6], [77], [49], [-45], [-48], [-26], [-60], [-27], [-61], [18], [70], [-36], [-58], [-52], [48], [50], [40], [59], [-56], [-60], [27], [-76], [13], [50], [65], [-8], [-56], [45], [42], [-42], [42], [39], [-16], [-13], [-65], [19], [38], [39], [-78], [-22], [10], [29], [27], [43], [30], [-36], [22], [-62], [-6], [-62], [30], [-8], [-36], [-60], [27], [-87], [67], [53], [-53], [-32], [-38], [4], [-30], [-11], [-95], [77], [33], [-51], [-72], [42], [-12], [0], [18], [54], [-22], [-61], [-53], [82], [-70], [24], [-25], [-38], [3], [55], [42], [-16], [45], [-62], [-78], [-36], [-27], [78], [20], [24], [37], [13], [44], [58], [20], [84], [-5], [-82], [-43], [-51], [-35], [65], [-78], [-78], [0], [99], [-67], [-42], [30], [102], [98], [-78], [-11], [20], [-1], [73], [34], [62], [-2], [87], [20], [-92], [78], [54], [45], [8], [-87], [0], [24], [-12], [4], [50], [7], [-10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1950_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1950_2_a_bb();".
// 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_1950_2_a_bb(:prec:=1)
    chi := MakeCharacter_1950_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_1950_2_a_bb();".
// 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_1950_2_a_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1950_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-3, 1]>,<11,R![3, 1]>,<17,R![-3, 1]>,<23,R![-4, 1]>,<31,R![3, 1]>],Snew);
    return Vf;
end function;