
// Make newform 650.4.b.h in Magma, downloaded from the LMFDB on 05 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_650_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_650_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_650_4_b_h();".
// 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_650_4_b_h();".
// 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 := [51529, 0, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 0, 1, 0], [0, 227, 0, 1], [0, 227, 0, -1]];
    Rf_basisdens := [1, 227, 227, 227];
    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_650_b();"
function MakeCharacter_650_b()
    N := 650;
    order := 2;
    char_gens := [27, 301];
    v := [1, 2];
    // 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_650_b_Hecke();"
function MakeCharacter_650_b_Hecke( : Kf := false)
    N := 650;
    order := 2;
    char_gens := [27, 301];
    char_values := [[-1, 0, 0, 0], [1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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 := 4;
    raw_aps := [[0, 2, 0, 0], [0, 4, 0, 0], [0, 0, 0, 0], [0, 5, 1, 0], [11, 0, 0, 1], [0, 13, 0, 0], [0, 53, -2, 0], [-26, 0, 0, -4], [0, 70, 6, 0], [-17, 0, 0, 12], [-37, 0, 0, 13], [0, 366, 0, 0], [-168, 0, 0, -16], [0, -222, -14, 0], [0, 165, 3, 0], [0, -309, -6, 0], [-387, 0, 0, 21], [-343, 0, 0, 10], [0, 157, -3, 0], [362, 0, 0, -16], [0, -350, -20, 0], [-314, 0, 0, -10], [0, -425, -5, 0], [-520, 0, 0, -32], [0, 222, -52, 0], [-65, 0, 0, 2], [0, -968, -4, 0], [0, 738, 62, 0], [272, 0, 0, 36], [0, -222, 8, 0], [0, -26, -46, 0], [-284, 0, 0, -16], [0, 608, -92, 0], [-282, 0, 0, 62], [-1926, 0, 0, -16], [-607, 0, 0, 69], [0, 525, 100, 0], [0, 1946, 68, 0], [0, 1122, -36, 0], [0, -147, 146, 0], [4164, 0, 0, -4], [-2269, 0, 0, 72], [710, 0, 0, 190], [0, 1772, -52, 0], [0, -1092, -100, 0], [2342, 0, 0, -46], [-1118, 0, 0, -22], [0, 1782, -112, 0], [0, -2927, 7, 0], [-318, 0, 0, 124], [0, -314, -64, 0], [-103, 0, 0, 171], [492, 0, 0, -212], [192, 0, 0, -196], [0, -1879, 172, 0], [0, 2024, -100, 0], [-1181, 0, 0, -24], [601, 0, 0, -79], [0, 6042, -64, 0], [6826, 0, 0, -16], [0, 5422, 38, 0], [0, 4118, -112, 0], [0, 2326, 316, 0], [3398, 0, 0, -150], [0, -1547, -30, 0], [0, -2118, -184, 0], [4910, 0, 0, -192], [0, 7805, 178, 0], [0, 638, -38, 0], [-6282, 0, 0, 32], [0, -3332, 340, 0], [-2133, 0, 0, -519], [0, 500, -420, 0], [0, -105, 56, 0], [13279, 0, 0, 11], [0, 230, 72, 0], [-1822, 0, 0, 496], [0, -5770, 308, 0], [1446, 0, 0, -36], [656, 0, 0, 164], [7856, 0, 0, -80], [-6496, 0, 0, -192], [1058, 0, 0, -200], [0, 7086, -416, 0], [11306, 0, 0, 106], [0, -12590, 186, 0], [-2648, 0, 0, 256], [0, 13384, -232, 0], [-4450, 0, 0, 32], [0, 11027, 205, 0], [0, -2132, -464, 0], [-897, 0, 0, 147], [0, 875, 489, 0], [-622, 0, 0, -54], [-11637, 0, 0, -35], [0, -12648, 0, 0], [1992, 0, 0, 356], [2510, 0, 0, 272], [0, -12882, -190, 0], [7918, 0, 0, -668], [0, -10816, 260, 0], [0, 9904, -364, 0], [0, -6682, 182, 0], [4511, 0, 0, -260], [7454, 0, 0, 582], [0, 5922, -68, 0], [0, -1419, 519, 0], [0, 11398, 584, 0], [-10392, 0, 0, -120], [11103, 0, 0, -354], [0, -7638, -750, 0], [0, -1194, -212, 0], [0, -4286, -316, 0], [8274, 0, 0, 740], [19778, 0, 0, 196], [25249, 0, 0, 202], [0, -14298, -172, 0], [0, -18996, 120, 0], [0, -3857, 140, 0], [634, 0, 0, -38], [4660, 0, 0, 140], [0, 3419, 670, 0], [0, -25994, 296, 0], [0, -9351, 699, 0], [-5039, 0, 0, -257], [15215, 0, 0, -536], [-7644, 0, 0, -404], [-15876, 0, 0, 612], [0, 14764, 44, 0], [0, 25328, 488, 0], [1909, 0, 0, 69], [0, -23163, 117, 0], [3170, 0, 0, 1042], [0, 1245, -202, 0], [-8554, 0, 0, -420], [32084, 0, 0, -132], [0, 11638, 72, 0], [0, -9521, -1285, 0], [0, 5031, -1140, 0], [12098, 0, 0, -256], [-5107, 0, 0, 147], [-32474, 0, 0, 412], [0, -4480, 744, 0], [0, -4813, 709, 0], [31313, 0, 0, -338], [2970, 0, 0, -432], [0, 40008, -340, 0], [0, -2682, 1072, 0], [31754, 0, 0, -222], [0, 5517, -387, 0], [0, 18972, -380, 0], [-175, 0, 0, 1328], [0, 12168, 704, 0], [0, -23106, -30, 0], [0, -3344, 408, 0], [1238, 0, 0, -526], [38242, 0, 0, -54], [-5354, 0, 0, -696], [0, -7689, -1660, 0], [-182, 0, 0, 996], [0, 13951, -31, 0], [0, 13963, -1256, 0], [0, 5631, -2015, 0], [-906, 0, 0, 318], [0, 9200, -460, 0], [0, 18607, -737, 0], [13582, 0, 0, -126], [0, -13455, 2030, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_650_b_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_650_4_b_h();".
// 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_650_4_b_h(:prec:=4)
    chi := MakeCharacter_650_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_650_4_b_h();".
// 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_650_4_b_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_650_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![16, 0, 1]>,<7,R![184041, 0, 958, 0, 1]>],Snew);
    return Vf;
end function;