
// Make newform 1950.2.y.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1950_y();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1950_y_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_1950_2_y_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_1950_2_y_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, 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_1950_y();"
function MakeCharacter_1950_y()
    N := 1950;
    order := 6;
    char_gens := [1301, 1327, 301];
    v := [6, 3, 5];
    // 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_1950_y_Hecke();"
function MakeCharacter_1950_y_Hecke(Kf)
    N := 1950;
    order := 6;
    char_gens := [1301, 1327, 301];
    char_values := [[1, 0, 0, 0], [-1, 0, 0, 0], [0, 0, 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+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, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 1, -1, 1], [-1, -3, -1, 0], [-1, 0, -3, 0], [-2, 4, 1, -4], [-2, 3, 1, -3], [3, 1, 3, 0], [-1, 2, 1, -4], [-2, 0, 4, 2], [7, 2, -7, -4], [6, 1, 6, 0], [10, -1, -5, 1], [3, 6, 0, -3], [2, 0, -4, 3], [0, -8, 0, 8], [0, -3, 4, -3], [-1, 7, 1, -14], [2, -3, -1, 3], [-8, -2, 0, 1], [6, 4, 0, -2], [-5, -6, 0, 3], [2, -6, 2, 0], [0, 0, 6, 0], [-5, -4, 5, 8], [1, 0, -2, -17], [3, -5, 3, 0], [2, 0, -4, -2], [10, 10, -5, -10], [8, 4, 8, 0], [10, 4, 0, -2], [0, -4, 5, -4], [0, -8, 4, -8], [-6, 8, 3, -8], [1, 0, -2, 5], [9, 0, -18, -8], [0, -2, 10, -2], [-6, 2, 6, -4], [-12, -6, 6, 6], [-3, -11, 3, 22], [-14, 6, 0, -3], [0, -4, 0, -4], [10, -1, -10, 2], [4, -8, -4, 16], [0, -3, 9, -3], [-6, 6, 6, -12], [-20, 4, 20, -8], [0, -3, 7, -3], [8, 0, -16, -2], [-8, 0, 16, 6], [5, 0, -10, -1], [-18, -2, 9, 2], [0, -2, 10, -2], [5, 18, 5, 0], [11, 9, 11, 0], [0, -2, 2, -2], [-8, 8, -8, 0], [-2, 4, 1, -4], [10, 0, -20, -5], [5, -17, 5, 0], [0, 13, -8, 13], [7, -18, 0, 9], [-7, -10, 0, 5], [2, 0, -4, -10], [12, -10, 0, 5], [0, -20, 0, 20], [8, 0, -16, 7], [-14, 21, 7, -21], [-10, -2, -10, 0], [-1, 12, 1, -24], [7, 0, -14, -11], [1, 13, 1, 0], [-2, 12, 1, -12], [-2, 2, -2, 0], [0, 2, 2, 2], [-9, -24, 0, 12], [0, -6, 10, -6], [-4, -15, -4, 0], [-2, 16, 1, -16], [-14, 2, 14, -4], [16, 0, -32, -5], [-7, 1, -7, 0], [-16, -1, 8, 1], [9, 5, -9, -10], [6, 0, -12, -26], [20, 6, -10, -6], [-10, -5, 10, 10], [-2, -24, 1, 24], [-9, -22, 0, 11], [-9, 0, 18, -3], [-2, 30, -2, 0], [0, -7, -9, -7], [7, -1, -7, 2], [0, 0, 0, 32], [30, -15, -15, 15], [1, -12, 1, 0], [12, -34, 0, 17], [17, 7, 17, 0], [-10, 0, 20, 23], [-3, 0, 6, 1], [6, -21, -6, 42], [-8, 28, 4, -28], [4, 20, -4, -40], [5, 22, 0, -11], [2, -2, 0, 1], [-16, 0, 16, 0], [-23, -16, 0, 8], [6, 4, 0, -2], [-1, 4, 1, -8], [24, -20, -12, 20], [1, 6, -1, -12], [0, -14, -11, -14], [-2, 0, 4, -14], [32, 20, -16, -20], [0, 15, 0, 15], [0, 8, 0, 8], [14, 2, 14, 0], [2, -14, 2, 0], [0, 14, 14, 14], [6, -1, 6, 0], [4, -21, 4, 0], [-2, 0, 4, -42], [0, 8, 24, 8], [-5, 35, -5, 0], [-14, -20, 0, 10], [-16, -27, 8, 27], [0, -2, 26, -2], [15, 0, -30, 5], [-19, 0, 0, 0], [-4, -4, -4, 0], [-38, 6, 38, -12], [-17, 19, 17, -38], [4, -14, 4, 0], [-20, -6, 10, 6], [-8, 30, -8, 0], [0, 4, -42, 4], [0, 10, 22, 10], [0, 34, 0, -34], [-38, 9, 38, -18], [-18, 0, 36, 14], [4, 6, 4, 0], [-48, 0, 24, 0], [-30, -4, 0, 2], [0, -7, 0, 14], [16, -28, -8, 28], [-23, 36, 0, -18], [-17, 0, 34, -10], [35, -14, 0, 7], [5, -14, 0, 7], [0, 4, -17, 4], [12, 23, -12, -46], [4, 0, -8, 36], [8, -24, 8, 0], [-6, 26, -6, 0], [-6, -4, 0, 2], [0, -30, -6, -30], [28, -15, -14, 15], [-14, 0, 28, 19], [-20, 0, 40, 22], [28, 4, -28, -8], [-48, 0, 24, 0], [-31, 14, 0, -7], [0, 14, -6, 14], [-39, 4, 39, -8], [0, -24, 0, 12], [-7, 9, 7, -18], [10, 30, -5, -30], [-16, 0, 32, -10], [4, 0, -8, -55], [-7, 0, 14, 21], [40, -3, -20, 3], [0, 2, 26, 2], [0, 1, -28, 1], [-36, 8, 0, -4], [0, 5, -48, 5], [19, -1, 19, 0], [-19, 0, 38, 20], [-4, 12, -4, 0], [2, -20, -2, 40], [-5, 2, 0, -1], [2, -12, 0, 6], [-3, 0, 6, 36], [-26, -16, 0, 8], [15, 23, -15, -46], [0, -10, 33, -10], [8, 0, -16, 46], [26, -36, 0, 18], [1, 42, 1, 0], [38, 19, -19, -19], [-12, 5, 6, -5], [0, -9, 49, -9], [23, -22, 0, 11], [-8, -44, -8, 0], [34, -15, -17, 15], [-4, -14, -4, 0], [15, 0, -30, 38], [30, 0, -15, 0], [-5, 28, 0, -14], [16, 0, -32, 12], [-26, 18, 13, -18], [0, -12, 20, -12], [33, -4, -33, 8], [-23, -4, 0, 2], [19, -3, 19, 0], [10, -29, 10, 0], [-13, 0, 26, -33], [64, -12, -32, 12], [2, -21, 2, 0], [0, 24, -16, 24], [-8, 31, -8, 0], [18, -44, 0, 22], [13, 17, 13, 0], [0, 9, 31, 9], [-36, -26, 18, 26], [11, 0, -22, 4], [12, 0, -24, -20], [0, -23, -24, -23], [0, 4, 0, -8], [-22, 56, 0, -28], [-30, 13, 30, -26], [-12, 0, 24, 0], [20, 0, -40, -9], [0, 18, -38, 18], [-23, -3, -23, 0], [10, 18, 0, -9], [15, -14, 15, 0], [0, 14, 14, 14], [-8, -8, 4, 8], [-20, 0, 40, 24], [19, 26, 19, 0], [4, 0, -4, 0], [18, 10, 18, 0], [-12, -6, 0, 3], [14, 0, -28, 46], [18, -20, 0, 10], [-32, 6, 16, -6], [18, 1, -18, -2], [0, 18, 2, 18], [-33, 9, 33, -18], [13, -17, -13, 34], [13, 7, -13, -14], [-38, 5, 19, -5], [20, -1, 20, 0], [0, 20, 9, 20], [10, -60, 0, 30], [0, -12, -40, -12], [-26, 14, -26, 0], [14, 35, -7, -35], [13, -37, 13, 0], [30, -2, -30, 4], [-16, 30, -16, 0], [20, 8, 0, -4], [-49, -16, 49, 32], [8, 0, -16, 18], [54, 9, -27, -9], [0, -24, -2, -24], [-23, -31, 23, 62], [26, 0, -52, 26], [0, 9, 16, 9], [20, 0, -40, 24], [-12, 0, -12, 0], [4, 0, -8, -49], [15, -40, 15, 0], [0, -2, 39, -2], [0, -19, -1, -19], [32, -20, -16, 20], [-6, 0, 12, -47], [0, -5, 11, -5], [20, -59, -10, 59], [8, 30, 0, -15], [8, 40, 0, -20], [-2, 9, 2, -18], [0, -16, -4, -16], [-4, -50, 2, 50], [-29, 5, 29, -10], [0, -12, -16, -12], [14, 0, -28, -13], [-38, 10, 19, -10], [0, 37, -3, 37], [27, -31, 27, 0], [-6, -10, -6, 0], [-4, 0, 8, -8], [-22, -7, -22, 0], [17, 26, 0, -13], [-19, -42, 0, 21], [-16, 0, 32, -3], [-14, 42, 0, -21], [78, 5, -39, -5], [0, 3, 20, 3], [30, 2, -30, -4], [18, -71, -9, 71], [-63, -10, 63, 20], [-20, -6, 10, 6], [-16, -42, 8, 42], [-17, -28, 0, 14], [-12, -72, 0, 36], [-10, 27, -10, 0], [-64, -4, 64, 8], [-39, -3, 39, 6], [-40, 3, 20, -3], [-6, -18, 0, 9], [11, -1, -11, 2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1950_y_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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