
// Make newform 525.3.f.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_525_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_525_f_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_525_3_f_a();".
// 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_525_3_f_a();".
// 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 := [4, 24, 72, -40, 12, 4, 8, -4, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-804, -26, -68, 110, -83, 29, -7, 1], [3476, -436, -1210, 1380, 153, 254, -129, 40], [15968, -26590, 8582, 1848, 2592, -2563, 879, -104], [-4532, -29708, 17920, -4242, -1008, -3290, 1596, -379], [672, 4412, -2260, 778, 146, 422, -206, 51], [-16564, -23698, 16982, -4812, -3996, -3001, 1797, -494], [-744, -8142, 3818, -1282, -194, -931, 433, -105]];
    Rf_basisdens := [1, 302, 2718, 5436, 5436, 604, 5436, 604];
    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_525_f();"
function MakeCharacter_525_f()
    N := 525;
    order := 2;
    char_gens := [176, 127, 451];
    v := [1, 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_525_f_Hecke();"
function MakeCharacter_525_f_Hecke(Kf)
    N := 525;
    order := 2;
    char_gens := [176, 127, 451];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 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, 0, -1, 0, 0, 0, 0, 0], [0, 0, -1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, -1, -1, 0, -1, 0], [0, 0, 0, 0, 0, -2, 0, 0], [0, 0, 1, -1, 8, 0, -1, 0], [0, 0, 0, -2, 0, 0, 2, 0], [-3, -5, 0, 0, 0, 0, 0, 0], [0, 0, 6, -2, 0, 0, 2, 0], [2, 2, 0, 0, 0, -6, 0, 4], [34, -2, 0, 0, 0, 0, 0, 0], [0, 0, -14, 14, 18, 0, 14, 0], [8, 8, 0, 0, 0, 6, 0, 16], [0, 0, -6, 6, 46, 0, 6, 0], [0, 0, -12, -4, 0, 0, 4, 0], [0, 0, -6, -16, 0, 0, 16, 0], [1, 1, 0, 0, 0, -28, 0, 2], [-39, -7, 0, 0, 0, 0, 0, 0], [0, 0, 8, -8, -14, 0, -8, 0], [6, 6, 0, 0, 0, -30, 0, 12], [0, 0, 26, -26, -18, 0, -26, 0], [-32, -36, 0, 0, 0, 0, 0, 0], [0, 0, -27, -9, 0, 0, 9, 0], [16, 16, 0, 0, 0, 10, 0, 32], [0, 0, -8, 8, 6, 0, 8, 0], [7, 7, 0, 0, 0, -50, 0, 14], [0, 0, 12, -12, 76, 0, -12, 0], [0, 0, -8, 22, 0, 0, -22, 0], [-64, 38, 0, 0, 0, 0, 0, 0], [0, 0, 8, 22, 0, 0, -22, 0], [0, 0, 4, -4, -30, 0, -4, 0], [5, 5, 0, 0, 0, 44, 0, 10], [0, 0, 12, 4, 0, 0, -4, 0], [65, -49, 0, 0, 0, 0, 0, 0], [-40, -40, 0, 0, 0, 10, 0, -80], [134, -12, 0, 0, 0, 0, 0, 0], [0, 0, 77, -77, -176, 0, -77, 0], [0, 0, -14, 14, 122, 0, 14, 0], [0, 0, -50, 14, 0, 0, -14, 0], [0, 0, -29, 3, 0, 0, -3, 0], [-58, -58, 0, 0, 0, 50, 0, -116], [-9, -85, 0, 0, 0, 0, 0, 0], [-22, -22, 0, 0, 0, -46, 0, -44], [0, 0, -42, 42, 76, 0, 42, 0], [0, 0, -26, 20, 0, 0, -20, 0], [-76, -4, 0, 0, 0, 0, 0, 0], [30, -4, 0, 0, 0, 0, 0, 0], [0, 0, -14, 14, -124, 0, 14, 0], [0, 0, -81, -47, 0, 0, 47, 0], [-17, -9, 0, 0, 0, 0, 0, 0], [0, 0, -108, 4, 0, 0, -4, 0], [-6, -6, 0, 0, 0, 24, 0, -12], [230, 36, 0, 0, 0, 0, 0, 0], [-53, -53, 0, 0, 0, 12, 0, -106], [0, 0, -16, 42, 0, 0, -42, 0], [0, 0, -52, -30, 0, 0, 30, 0], [49, 49, 0, 0, 0, -82, 0, 98], [-270, -94, 0, 0, 0, 0, 0, 0], [0, 0, 20, -20, -194, 0, -20, 0], [56, 56, 0, 0, 0, 24, 0, 112], [0, 0, 145, -145, -130, 0, -145, 0], [0, 0, 49, 77, 0, 0, -77, 0], [0, 0, -91, 91, 418, 0, 91, 0], [2, 2, 0, 0, 0, 40, 0, 4], [0, 0, -90, 90, 10, 0, 90, 0], [0, 0, 78, -40, 0, 0, 40, 0], [-52, 78, 0, 0, 0, 0, 0, 0], [0, 0, 14, -14, 352, 0, -14, 0], [0, 0, -106, 44, 0, 0, -44, 0], [219, 55, 0, 0, 0, 0, 0, 0], [0, 0, 44, 30, 0, 0, -30, 0], [6, 6, 0, 0, 0, -116, 0, 12], [0, 0, -74, 74, 108, 0, 74, 0], [0, 0, 12, -12, -422, 0, -12, 0], [236, -70, 0, 0, 0, 0, 0, 0], [0, 0, -84, -80, 0, 0, 80, 0], [-14, -14, 0, 0, 0, 230, 0, -28], [0, 0, -95, 95, 252, 0, 95, 0], [-2, -2, 0, 0, 0, -190, 0, -4], [316, -126, 0, 0, 0, 0, 0, 0], [-9, -9, 0, 0, 0, -24, 0, -18], [170, 96, 0, 0, 0, 0, 0, 0], [-82, -82, 0, 0, 0, 232, 0, -164], [0, 0, -8, 8, -130, 0, 8, 0], [200, -124, 0, 0, 0, 0, 0, 0], [0, 0, 24, -50, 0, 0, 50, 0], [-84, -84, 0, 0, 0, 96, 0, -168], [0, 0, 74, -74, -392, 0, -74, 0], [-67, -67, 0, 0, 0, 282, 0, -134], [0, 0, 268, -268, -340, 0, -268, 0], [0, 0, -177, 65, 0, 0, -65, 0], [80, 80, 0, 0, 0, -244, 0, 160], [0, 0, 92, -92, 238, 0, -92, 0], [98, 98, 0, 0, 0, -210, 0, 196], [234, 232, 0, 0, 0, 0, 0, 0], [0, 0, -6, 78, 0, 0, -78, 0], [-135, -135, 0, 0, 0, 82, 0, -270], [152, 152, 0, 0, 0, -2, 0, 304], [0, 0, -269, 269, 182, 0, 269, 0], [-514, -84, 0, 0, 0, 0, 0, 0], [0, 0, -82, 82, 70, 0, 82, 0], [0, 0, 274, 24, 0, 0, -24, 0], [0, 0, 125, -9, 0, 0, 9, 0], [94, 94, 0, 0, 0, 10, 0, 188], [8, -42, 0, 0, 0, 0, 0, 0], [0, 0, -4, 4, -662, 0, 4, 0], [0, 0, -29, -115, 0, 0, 115, 0], [0, 0, 312, 70, 0, 0, -70, 0], [-14, -14, 0, 0, 0, 2, 0, -28], [-548, -146, 0, 0, 0, 0, 0, 0], [0, 0, -210, 210, 584, 0, 210, 0], [0, 0, 226, -226, 74, 0, -226, 0], [0, 0, 384, 78, 0, 0, -78, 0], [-783, -161, 0, 0, 0, 0, 0, 0], [44, 324, 0, 0, 0, 0, 0, 0], [122, 122, 0, 0, 0, -50, 0, 244], [0, 0, 21, -21, -110, 0, -21, 0], [0, 0, -130, 146, 0, 0, -146, 0], [0, 0, 132, 34, 0, 0, -34, 0], [108, 108, 0, 0, 0, -150, 0, 216], [-435, -199, 0, 0, 0, 0, 0, 0], [0, 0, 328, -328, -106, 0, -328, 0], [0, 0, 345, -19, 0, 0, 19, 0], [0, 0, -96, 2, 0, 0, -2, 0], [-109, -255, 0, 0, 0, 0, 0, 0], [-198, -198, 0, 0, 0, -54, 0, -396], [-928, 62, 0, 0, 0, 0, 0, 0], [164, 164, 0, 0, 0, -92, 0, 328], [0, 0, 72, -72, 416, 0, -72, 0], [0, 0, 161, -161, -192, 0, -161, 0], [20, -118, 0, 0, 0, 0, 0, 0], [0, 0, -90, 30, 0, 0, -30, 0], [-654, -16, 0, 0, 0, 0, 0, 0], [0, 0, 222, -222, 158, 0, -222, 0], [-44, -44, 0, 0, 0, 98, 0, -88], [58, -372, 0, 0, 0, 0, 0, 0], [0, 0, 79, -65, 0, 0, 65, 0], [0, 0, -85, 85, 154, 0, 85, 0], [0, 0, 127, -121, 0, 0, 121, 0], [-38, -38, 0, 0, 0, 2, 0, -76], [257, 303, 0, 0, 0, 0, 0, 0], [-216, -216, 0, 0, 0, 122, 0, -432], [0, 0, 200, -200, -936, 0, -200, 0], [0, 0, 36, -138, 0, 0, 138, 0], [-377, -105, 0, 0, 0, 0, 0, 0], [38, 38, 0, 0, 0, -48, 0, 76], [0, 0, -45, 45, 1048, 0, 45, 0], [0, 0, 58, -156, 0, 0, 156, 0], [1159, -195, 0, 0, 0, 0, 0, 0], [0, 0, 72, 202, 0, 0, -202, 0], [0, 0, 26, -26, -302, 0, -26, 0], [-150, -150, 0, 0, 0, -150, 0, -300], [0, 0, 96, -96, 742, 0, -96, 0], [0, 0, 62, 30, 0, 0, -30, 0], [0, 0, 396, -396, -850, 0, -396, 0], [-66, -66, 0, 0, 0, 432, 0, -132], [304, 144, 0, 0, 0, 0, 0, 0], [246, 246, 0, 0, 0, -350, 0, 492], [0, 0, -146, 146, -738, 0, 146, 0], [43, 43, 0, 0, 0, -26, 0, 86], [0, 0, 158, -144, 0, 0, 144, 0], [0, 0, -140, 32, 0, 0, -32, 0], [0, 0, -112, 112, 646, 0, 112, 0], [103, 103, 0, 0, 0, -556, 0, 206], [0, 0, -84, 88, 0, 0, -88, 0], [0, 0, 378, -94, 0, 0, 94, 0], [848, 252, 0, 0, 0, 0, 0, 0], [0, 0, 569, -569, -248, 0, -569, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_525_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_525_3_f_a();".
// 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_525_3_f_a(:prec:=8)
    chi := MakeCharacter_525_f();
    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_525_3_f_a();".
// 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_525_3_f_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<2,R![21, 0, -14, 0, 1]>],Snew);
    return Vf;
end function;