
// Make newform 525.3.o.l in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_525_o();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_525_o_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_o_l();".
// 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_o_l();".
// 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 := [100, 100, 190, -50, 91, -2, 13, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [-8440, 13280, -9240, 1477, -1614, 411, -144, 7], [12250, 300, 480, -161, 132, 87, -38, 9], [13700, 2900, 4640, 10117, 1276, 841, -24, 87], [-10830, 21390, -16967, 11191, -1115, 1805, -361, 137], [3590, -21870, 4766, -7761, 636, -1079, 154, -69], [40300, 82420, -67845, 45838, -6851, 8184, -1781, 598]];
    Rf_basisdens := [1, 1, 3090, 3090, 21630, 21630, 3090, 21630];
    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_o();"
function MakeCharacter_525_o()
    N := 525;
    order := 6;
    char_gens := [176, 127, 451];
    v := [6, 6, 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_525_o_Hecke();"
function MakeCharacter_525_o_Hecke(Kf)
    N := 525;
    order := 6;
    char_gens := [176, 127, 451];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, -1, 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, 0, 0], [1, 0, 0, 0, 0, -1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [4, -1, -1, 0, 1, 3, 0, 0], [5, 1, 1, -1, 1, 6, 2, 0], [-2, 4, 0, -1, 2, 0, 4, -2], [4, -4, 1, 1, 4, -3, 0, -1], [-2, -2, -4, 0, -4, -3, -4, 0], [4, -3, 4, 2, 0, 16, -4, -2], [-15, 0, -10, 9, 0, -5, -5, 5], [-12, -1, -4, 6, 1, 8, 0, -1], [-4, -8, -4, -7, 0, -26, 4, 7], [4, -6, 0, -2, -3, 5, -3, 7], [-39, 0, 10, -2, 5, 5, 5, -5], [13, 1, -1, 2, 2, 6, -1, 2], [18, 3, 5, -5, 3, 23, 10, 7], [2, -14, -1, -9, 14, -3, 0, 5], [-70, -4, -10, 2, -8, -40, -10, 2], [-48, -5, -1, 1, -5, -49, -2, 10], [9, 0, 10, -1, -28, 5, 5, -5], [-38, 11, -7, -13, -11, 31, 0, 10], [-6, -5, -6, -9, 0, 46, 6, 9], [-9, -24, 0, 9, -12, -13, 5, -23], [57, 10, 11, 0, 20, 34, 11, 0], [-6, 28, 0, 12, 14, -22, -10, -14], [-24, 2, 21, 21, -2, 45, 0, -21], [7, 11, 1, 11, 22, 4, 1, 11], [17, -30, 17, 14, 0, 18, -17, -14], [-22, -15, -2, 2, -15, -24, -4, -9], [4, 0, -8, -10, 20, -4, -4, 4], [22, 0, 4, 11, -68, 2, 2, -2], [30, -13, 28, -21, -26, 29, 28, -21], [90, 42, 17, -17, 42, 107, 34, 13], [28, 58, 0, -7, 29, 58, 2, 12], [-4, -20, -4, -14, 0, 70, 4, 14], [50, -58, 0, 0, -58, 50, 0, 30], [-6, -23, 3, -45, 23, 9, 0, 21], [0, -48, 0, 2, 0, 100, 0, -2], [74, 50, 0, 22, 25, 118, -30, -14], [39, 17, 33, -30, 34, 36, 33, -30], [-61, -39, 6, -6, -39, -55, 12, -25], [32, -50, 0, 13, -25, 50, -14, -12], [20, -6, 20, 12, 0, 50, -20, -12], [-26, -45, 11, -11, -45, -15, 22, -40], [-34, 0, 40, 4, -71, 20, 20, -20], [6, 42, 14, 46, -42, 8, 0, -30], [49, 0, 32, -27, 51, 16, 16, -16], [-20, -28, 0, -32, -14, 24, 64, 0], [48, 14, 25, -43, -14, -23, 0, 9], [156, -19, 12, 7, -38, 84, 12, 7], [-10, 78, -10, -40, 0, 174, 10, 40], [-204, 0, 20, -38, 6, 10, 10, -10], [43, -17, -28, 14, 17, -71, 0, 7], [-42, 2, 0, -10, 1, -41, 43, -23], [101, 32, -5, 2, 64, 48, -5, 2], [-220, -76, -6, 6, -76, -226, -12, 2], [2, -26, -44, 44, 26, -46, 0, 0], [8, 20, -36, 32, 40, -14, -36, 32], [-170, -123, -13, 13, -123, -183, -26, -6], [-139, 0, -48, 69, -49, -24, -24, 24], [68, -17, 67, -63, 17, -1, 0, -2], [-33, -86, 0, 5, -43, -117, -51, 41], [-1, 158, 0, 16, 79, -11, -9, -23], [-36, 36, 57, 17, -36, 93, 0, -37], [133, -25, -25, 41, -50, 54, -25, 41], [-55, 0, -55, 8, 0, -24, 55, -8], [-6, 0, -6, 82, 0, 191, 6, -82], [-23, 0, -78, -4, -21, -39, -39, 39], [70, 116, -16, 16, 116, 54, -32, -10], [-104, -96, 0, -28, -48, -160, 48, 8], [50, 56, -21, -13, -56, -71, 0, 17], [29, 16, 29, -36, 0, -278, -29, 36], [-108, -4, -82, -56, 4, 26, 0, 69], [15, -19, 15, 23, 0, 302, -15, -23], [63, 0, -88, 10, -56, -44, -44, 44], [303, -11, -19, -16, -22, 142, -19, -16], [-334, -18, -27, 27, -18, -361, -54, 9], [-61, -31, -83, 85, -62, -72, -83, 85], [-20, -173, -20, -69, 0, -127, 20, 69], [-142, 73, -30, -16, -73, 112, 0, 23], [-125, 118, 0, -65, 59, -132, 118, 12], [390, 0, 24, 65, 119, 12, 12, -12], [130, -54, 8, -8, -54, 138, 16, -32], [139, 58, 0, 98, 29, 175, -103, -93], [-66, 2, 74, -18, 4, 4, 74, -18], [-24, 42, -24, -126, 0, -178, 24, 126], [7, 0, -68, -47, 13, -34, -34, 34], [23, 29, 23, 41, 0, 126, -23, -41], [-93, -124, 0, -75, -62, -83, 103, 47], [-182, 0, -84, -65, -54, -42, -42, 42], [704, -24, -36, 32, -48, 334, -36, 32], [116, 2, 62, -42, -2, -54, 0, -10], [362, 29, 53, -53, 29, 415, 106, -72], [304, 0, -108, 8, 78, -54, -54, 54], [52, 63, 52, 153, 0, 148, -52, -153], [-166, -40, 0, 56, -20, -334, -2, -110], [358, 118, 42, -10, 236, 200, 42, -10], [-29, 23, -78, 72, -23, -49, 0, 3], [71, 127, 45, -15, 254, 58, 45, -15], [72, 71, 72, -25, 0, 108, -72, 25], [434, 0, 56, -68, 28, 28, 28, -28], [-230, 13, -11, 11, 13, -241, -22, 141], [156, -36, 20, -24, 36, -136, 0, 2], [21, 25, 21, -43, 0, 27, -21, 43], [-196, -87, -56, 56, -87, -252, -112, 133], [-86, -51, 15, 121, 51, 101, 0, -68], [-189, -120, 0, 11, -60, -359, 19, -41], [-273, 104, -103, 118, 208, -188, -103, 118], [548, 194, -46, 46, 194, 502, -92, 22], [-20, 282, 0, 25, 141, -66, -26, -24], [-14, -28, 86, -117, -56, 36, 86, -117], [4, 37, -21, 21, 37, -17, -42, 55], [-582, 0, -8, -72, 96, -4, -4, 4], [-157, 140, 62, -62, -140, 219, 0, 0], [-30, 0, 16, -8, 36, 8, 8, -8], [-57, 11, -45, 45, 11, -102, -90, 58], [-101, 202, 0, -10, 101, -185, 17, 3], [232, 67, 78, 118, -67, -154, 0, -98], [12, -183, 12, 138, 0, -310, -12, -138], [-538, 0, -80, -26, 126, -40, -40, 40], [-238, 115, -148, -18, -115, 90, 0, 83], [77, 0, 166, -108, 195, 83, 83, -83], [22, -73, 94, 0, -146, 58, 94, 0], [288, 98, -11, 11, 98, 277, -22, 27], [246, -21, -178, 39, -42, 34, -178, 39], [121, 0, 18, -255, -30, 9, 9, -9], [-100, -234, -100, -30, 0, -18, 100, 30], [304, 82, 24, 86, 164, 164, 24, 86], [90, -32, 0, 45, -16, 82, -98, 8], [492, 100, -64, 19, 200, 214, -64, 19], [653, 224, -54, 54, 224, 599, -108, -4], [188, 0, 48, 48, 219, 24, 24, -24], [-8, 99, -8, 211, 0, 154, 8, -211], [452, 0, 64, -18, 294, 32, 32, -32], [135, -37, -141, 59, -74, -3, -141, 59], [-51, -8, 0, -98, -4, 172, 274, -78], [-378, 47, -4, -184, -47, 374, 0, 94], [16, -116, 98, 50, 116, 82, 0, -74], [-241, -196, 0, -53, -98, -471, 11, 95], [-223, -143, -50, 50, -143, -273, -100, 69], [-373, -118, 0, 31, -59, -720, 26, -88], [73, -90, 73, 130, 0, 738, -73, -130], [880, -24, -16, 16, -24, 864, -32, 8], [460, 0, -48, 94, -320, -24, -24, 24], [-96, -125, 94, 108, 125, 190, 0, -101], [-41, 32, 0, 149, 16, -227, -145, -153], [-256, -244, 0, -135, -122, -370, 142, 128], [-60, 24, -333, -61, -24, -273, 0, 197], [142, 146, -54, -98, 292, 44, -54, -98], [49, -113, 49, 68, 0, 132, -49, -68], [-113, -219, -113, 92, 0, 240, 113, -92], [-331, 78, 0, -65, 39, -590, 72, 58], [-15, 0, -6, 190, 181, -3, -3, 3], [859, 136, -119, -20, 272, 370, -119, -20], [124, 63, 23, -23, 63, 147, 46, -34], [271, 0, 234, -49, 204, 117, 117, -117], [38, -25, 38, 241, 0, -368, -38, -241], [-621, -51, 95, -63, -102, -263, 95, -63], [-67, 134, 0, -208, 67, -25, 109, 307], [-148, 86, 185, 37, -86, 333, 0, -111], [209, -78, 209, 100, 0, 210, -209, -100], [924, 0, -56, 4, -114, -28, -28, 28], [331, 0, -174, 214, 51, -87, -87, 87], [420, 125, -34, 61, 250, 193, -34, 61], [216, -24, 41, -41, -24, 257, 82, -131], [-4, 143, -52, 168, -143, -48, 0, -58], [366, -65, 102, -102, -65, 468, 204, -237], [-52, 17, -97, -307, -17, -45, 0, 202]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_525_o_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_525_3_o_l();".
// 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_o_l(:prec:=8)
    chi := MakeCharacter_525_o();
    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_o_l();".
// 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_o_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_o();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<2,R![100, -100, 190, 50, 91, 2, 13, 2, 1]>,<11,R![196, -4340, 96982, 18970, 10183, -1880, 337, -20, 1]>,<13,R![1230957225, 0, 47028060, 0, 420414, 0, 1164, 0, 1]>],Snew);
    return Vf;
end function;