
// Make newform 100.3.b.f in Magma, downloaded from the LMFDB on 12 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_100_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_100_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_100_3_b_f();".
// 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_100_3_b_f();".
// 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, -1, 1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 2, 2], [1, -2, 2, -2]];
    Rf_basisdens := [1, 1, 1, 1];
    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_100_b();"
function MakeCharacter_100_b()
    N := 100;
    order := 2;
    char_gens := [51, 77];
    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_100_b_Hecke();"
function MakeCharacter_100_b_Hecke(Kf)
    N := 100;
    order := 2;
    char_gens := [51, 77];
    char_values := [[-1, 0, 0, 0], [1, 0, 0, 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 := 3;
    raw_aps := [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0], [2, -2, -1, 2], [4, -4, 2, 4], [4, -2, 0, -2], [6, 8, 0, 8], [-4, 4, 0, -4], [2, -2, -3, 2], [-2, 4, 0, 4], [4, -4, -10, 4], [-4, -10, 0, -10], [-28, -6, 0, -6], [-4, 4, -3, -4], [-6, 6, -13, -6], [44, -10, 0, -10], [12, -12, -12, 12], [32, -26, 0, -26], [-20, 20, 11, -20], [-20, 20, -2, -20], [-66, -32, 0, -32], [-16, 16, 20, -16], [12, -12, 13, 12], [-22, 40, 0, 40], [66, -12, 0, -12], [82, 8, 0, 8], [-22, 22, -23, -22], [24, -24, -17, 24], [-32, -74, 0, -74], [-126, 20, 0, 20], [38, -38, 23, 38], [28, -28, -42, 28], [26, 12, 0, 12], [-60, 60, -4, -60], [48, 38, 0, 38], [36, -36, 62, 36], [-84, 54, 0, 54], [-56, 56, 45, -56], [-18, 18, 15, -18], [204, -10, 0, -10], [12, -12, 76, 12], [122, 16, 0, 16], [-44, 44, 58, -44], [-146, -16, 0, -16], [16, -70, 0, -70], [-32, 32, -64, -32], [-28, 28, -42, -28], [-70, 70, 13, -70], [16, -16, -1, 16], [118, -20, 0, -20], [-6, 140, 0, 140], [40, -40, 36, 40], [-68, -30, 0, -30], [-52, 52, 26, -52], [266, -4, 0, -4], [-58, 58, -79, -58], [-192, 70, 0, 70], [-12, 12, -86, -12], [256, 90, 0, 90], [-28, 10, 0, 10], [48, -48, -15, 48], [-76, 46, 0, 46], [68, -68, 11, 68], [68, -68, 10, 68], [174, -176, 0, -176], [-264, -46, 0, -46], [44, -44, 70, 44], [126, -64, 0, -64], [76, -76, 91, 76], [-242, -108, 0, -108], [14, -144, 0, -144], [16, -16, 16, 16], [-34, 34, -157, -34], [-256, 154, 0, 154], [60, -60, 32, 60], [114, -114, -43, 114], [48, -154, 0, -154], [-124, 94, 0, 94], [282, 72, 0, 72], [-272, 150, 0, 150], [-140, 140, 28, -140], [-328, -114, 0, -114], [-44, 44, -126, -44], [234, 60, 0, 60], [128, -128, -48, 128], [88, -88, -19, 88], [528, 102, 0, 102], [-554, 120, 0, 120], [-278, 80, 0, 80], [-2, 2, -167, -2], [-232, 232, -13, -232], [-32, 32, -172, -32], [-158, 158, 67, -158], [-52, 52, -38, -52], [228, -228, -24, 228], [-214, 214, 73, -214], [-602, 140, 0, 140], [202, -360, 0, -360], [104, -104, 161, 104], [-438, -80, 0, -80], [40, -40, -1, 40], [-704, -86, 0, -86], [-184, 184, 89, -184], [-112, 54, 0, 54], [20, -20, -122, 20], [186, 236, 0, 236], [-68, 68, -153, -68], [94, 96, 0, 96], [-216, 216, -12, -216], [172, 82, 0, 82], [138, -138, 251, 138], [-656, -70, 0, -70], [-54, 220, 0, 220], [-4, 4, 200, -4], [-52, 52, 198, -52], [212, 282, 0, 282], [52, -52, -271, 52], [-38, 38, -117, -38], [464, 42, 0, 42], [-28, 28, -92, -28], [-48, 342, 0, 342], [114, 260, 0, 260], [136, 306, 0, 306], [-44, 44, 61, -44], [4, -4, -86, 4], [-568, 62, 0, 62], [518, 316, 0, 316], [88, -88, -76, 88], [154, -154, 55, 154], [-236, 446, 0, 446], [-20, 20, 36, -20], [134, -134, 213, 134], [-116, 116, -282, -116], [576, -134, 0, -134], [122, 344, 0, 344], [-102, -328, 0, -328], [104, -142, 0, -142], [-116, 116, -169, -116], [-744, 210, 0, 210], [218, 200, 0, 200], [44, -44, 122, 44], [232, -402, 0, -402], [-134, 134, -115, -134], [-220, 220, 267, -220], [-352, 70, 0, 70], [-208, 208, 220, -208], [264, -590, 0, -590], [426, -260, 0, -260], [12, -12, -52, 12], [158, -158, -147, 158], [-284, 142, 0, 142], [-348, -262, 0, -262], [64, -64, -103, 64], [18, -18, 199, 18], [-104, 104, 27, -104], [-108, 108, -442, -108], [88, -88, 204, 88], [968, 254, 0, 254], [-294, -20, 0, -20], [1082, 160, 0, 160], [140, -140, 259, 140], [-866, 192, 0, 192], [182, -182, -125, 182], [-396, 396, 246, -396], [1226, -68, 0, -68], [-122, 122, 65, -122], [244, -244, 14, 244], [316, -346, 0, -346]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_100_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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