
// Make newform 180.3.c.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_180_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_180_c_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_180_3_c_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_180_3_c_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 := [16, -8, -8, 2, 3, 1, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [8, 24, -8, -17, 7, 4, 3, -1], [8, 8, -8, 1, 1, 4, -3, 1], [-24, -8, 16, -5, -5, -4, -1, 3], [-8, -8, 2, 3, 1, -2, -1, 1], [56, 24, -24, -5, 3, 4, -1, -5], [-88, -8, 32, 15, -9, -12, 3, 7], [168, 40, -48, -23, 25, 20, -11, -15]];
    Rf_basisdens := [1, 16, 8, 16, 4, 16, 8, 16];
    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_180_c();"
function MakeCharacter_180_c()
    N := 180;
    order := 2;
    char_gens := [91, 101, 37];
    v := [1, 2, 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_180_c_Hecke();"
function MakeCharacter_180_c_Hecke(Kf)
    N := 180;
    order := 2;
    char_gens := [91, 101, 37];
    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, 0, 0, 0, -1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [-1, 1, -1, 0, 0, 1, -1, 0], [-1, -1, 1, 0, 1, 2, 0, 1], [3, 1, 1, 2, -4, -3, 1, 2], [-2, 0, 0, 6, -1, 5, 1, -1], [-3, -1, 3, 0, 0, 3, -5, -2], [-5, 5, 1, 0, 4, 9, -7, -2], [-10, 2, 2, 2, -10, 4, 4, 2], [5, 11, -1, 0, 10, 5, 5, 0], [-19, -1, -1, 14, 2, 13, 1, -4], [4, 2, 2, 0, -8, -6, 2, 4], [-7, -15, 1, 0, -7, 0, 0, 7], [-7, -9, -1, 0, -12, -5, -9, -2], [-46, -2, -2, -2, 8, 6, -2, -4], [-1, -1, 1, 0, 5, 6, 4, 5], [-16, -2, -2, -4, 12, -14, -6, 0], [-3, -3, 1, 0, -11, -8, -12, -9], [-2, -18, 2, 0, -10, -8, 4, 6], [-20, 2, 2, -12, -4, -26, -2, 8], [21, 7, -13, 0, -4, -25, 23, 2], [15, 23, -5, 0, 23, 8, 20, 5], [-12, -2, -2, -44, 8, 6, -2, -4], [64, -2, -2, -24, 14, -24, -8, 2], [36, 0, 0, -6, 4, -20, -4, 4], [-9, 9, 7, 0, 20, 29, -5, 4], [25, -3, 1, 0, -9, -34, 18, -7], [34, 4, 4, 20, -24, 28, 12, 0], [54, 4, 4, -22, -9, -47, -3, 15], [9, 11, 1, 0, 22, 13, 19, 10], [1, 29, -13, 0, 13, 12, -2, -3], [58, -4, -4, -22, 21, -13, -9, -3], [37, 3, 19, 0, 6, -31, 21, -16], [82, 2, 2, 6, -10, 4, 4, 2], [-1, -35, 13, 0, -20, -19, 1, 2], [7, 1, 1, 42, 2, -33, -5, 8], [-35, 21, -15, 0, 13, 48, -28, 7], [-7, 35, -17, 0, 26, 33, 1, 8], [34, 2, 2, 14, 2, -56, -8, 14], [33, -11, -17, 0, -11, -44, 50, 17], [-82, 8, 8, 60, -36, -4, 12, 12], [0, 8, 20, 0, 16, 16, -12, -12], [-166, 0, 0, -44, 6, -30, -6, 6], [-148, 0, 0, -2, -6, 30, 6, -6], [-35, -29, -5, 0, -42, -7, -43, -8], [-33, -43, -19, 0, -36, -3, -7, 26], [47, 53, -5, 0, 22, -25, 21, -26], [-17, 7, 23, 0, 35, 52, -12, 5], [-16, -6, -6, 72, 8, 98, 10, -28], [-94, 0, 0, 14, -11, 55, 11, -11], [22, 50, -2, 0, 16, -6, -10, -32], [70, 4, 4, -104, 0, -92, -12, 24], [-49, 27, -7, 0, 7, 56, -62, -13], [-58, 12, 12, -30, -49, -31, 13, 23], [7, 21, -47, 0, 26, 19, 59, 52], [134, -6, -6, 74, 22, 28, -4, -14], [-5, 17, 25, 0, 44, 49, -3, 2], [-41, 5, 5, -42, -14, -45, -1, 16], [94, 8, 8, -44, -26, -54, 2, 22], [-33, -9, -13, 0, 27, 60, 16, 49], [56, 4, 4, 62, -22, 18, 10, 2], [-49, -5, 43, 0, 33, 82, -54, -5], [36, 0, -36, 0, -2, -38, 70, 34], [178, -16, -16, -60, 74, -2, -26, -22], [-132, 16, 16, -10, -66, -38, 18, 30], [77, 107, -25, 0, 90, 13, 85, 8], [84, 2, 2, 12, -12, 14, 6, 0], [-21, -41, 23, 0, -7, 14, -10, 11], [164, -6, -6, 44, 44, -82, -26, 8], [26, -16, -16, -26, 77, -17, -29, -19], [110, 70, 70, 0, 102, -8, 72, -38], [31, 21, 11, 0, 2, -29, 1, -30], [35, 21, 21, -110, -82, -73, 19, 44], [35, 109, -11, 0, 70, 35, 7, -28], [15, 13, -43, 0, -38, -53, 7, -8], [72, -24, -24, -10, 96, 72, -24, -48], [-285, -3, -3, 102, 4, 49, 5, -14], [64, -10, -10, -44, 26, 100, 4, -34], [-42, 4, 4, -112, 4, -112, -16, 28], [-27, -55, -41, 0, -23, 4, 46, 73], [-36, -10, -10, -152, 44, 10, -14, -16], [-56, -112, 8, 0, -56, 0, -8, 48], [108, 10, 10, 28, -60, 70, 30, 0], [-59, -141, 3, 0, -62, -3, 17, 76], [121, 97, 33, 0, 77, -44, 68, -53], [174, 20, 20, -100, -48, -220, -12, 72], [116, -22, -22, -208, 114, -64, -48, -18], [-14, -6, -6, -58, 18, 48, 0, -18], [89, 3, 77, 0, 70, -19, 79, -10], [37, -15, -35, 0, -49, -86, 38, 1], [-48, -48, 12, 0, -40, 8, -52, -4], [53, 51, -67, 0, -8, -61, 61, 8], [35, -109, 41, 0, -123, -158, -20, -55], [-33, 45, 113, 0, 84, 117, -107, -74], [-113, -35, 13, 0, -30, 83, -121, -8], [-52, 16, 16, -70, -40, -168, -8, 56], [90, 8, 8, 36, -20, -84, -4, 28], [95, -5, -49, 0, -3, -98, 146, 51], [74, 20, 20, 76, -104, 60, 44, 16], [-17, -17, 39, 0, 11, 28, -28, -11], [62, 6, 6, 206, -54, 132, 36, -18], [45, 65, -23, 0, 79, 34, 82, 37], [-724, 18, 18, 12, -78, -24, 24, 30], [25, -65, 27, 0, -142, -167, -79, -104], [564, 26, 26, 168, -90, -148, 12, 66], [-47, 93, 17, 0, 43, 90, -114, -67], [-210, 28, 28, 114, -157, 141, 73, 11], [-6, -30, 106, 0, 90, 96, 8, 14], [-18, 52, 52, -24, -236, -16, 80, 76], [103, 29, 95, 0, 74, -29, 53, -50], [-81, -23, -23, -146, 68, 189, 1, -70], [510, -12, -12, 86, 57, -9, -21, -15], [-115, 75, -45, 0, 70, 185, -75, 40], [55, 129, -11, 0, 82, 27, 19, -36], [-150, -8, -8, 216, 14, 114, 10, -34], [-171, 117, -31, 0, 73, 244, -184, -13], [77, 31, 55, 0, -46, -123, -55, -132], [-96, 8, 8, 102, -68, 156, 44, -20], [-75, 21, -5, 0, 103, 178, 12, 87], [416, 6, 6, -68, -32, 22, 14, 4], [164, -30, -30, 356, 112, 130, -22, -68], [-704, -24, -24, -74, 76, 172, -4, -68], [43, -97, 59, 0, -39, -82, 42, -1], [-115, -173, 63, 0, -18, 97, -23, 92], [-192, -36, -36, 58, 200, -172, -92, -16], [-160, 42, 42, -176, -180, -66, 54, 72], [-118, 62, 6, 0, 40, 158, -146, -28], [-31, -105, -7, 0, -32, -1, 49, 80], [-309, 1, 1, -242, -10, 27, 7, -4], [79, -187, 41, 0, -80, -159, 145, 66], [-17, -79, -151, 0, -164, -147, 49, 66], [57, -209, -45, 0, -162, -219, 149, 92], [19, -23, -23, -394, 122, -81, -53, -16], [-114, 4, 4, -148, -64, 228, 52, -40], [-342, 8, 8, 304, -24, -64, 0, 24], [720, 4, 4, -186, 10, -142, -22, 34], [69, -15, -59, 0, -101, -170, 42, -27], [-666, -2, -2, 46, 42, -164, -36, 30], [-778, -44, -44, -312, 162, 202, -30, -102], [187, -31, 81, 0, 72, -115, 209, 22], [206, -22, -22, -182, 74, 136, -8, -58], [67, 13, 7, 0, 116, 49, 163, 96], [223, 119, 15, 0, 43, -180, 132, -91], [174, -32, -32, 52, 116, 156, -20, -76], [170, 74, 50, 0, 6, -164, 52, -118], [187, -3, -3, 46, -52, 329, 61, -70], [766, 0, 0, -2, 35, -175, -35, 35], [-61, -251, 61, 0, -182, -121, -53, 8], [195, 37, -31, 0, 24, -171, 213, 18], [-357, -19, -19, -30, 86, 7, -29, -28], [-88, 26, 26, -76, -8, -558, -70, 148], [105, -39, -3, 0, -59, -164, 88, -17], [-143, -45, 167, 0, 150, 293, -115, 28], [-27, 185, -79, 0, 159, 186, 26, 53], [154, 150, 54, 0, 120, -34, 70, -84], [119, -75, 65, 0, -88, -207, 41, -78], [158, -4, -4, 460, 36, -88, -24, 12], [514, 24, 24, -8, -64, -232, -8, 80], [1208, 16, 16, -10, -84, 52, 36, 12], [-169, -109, -133, 0, -83, 86, -10, 159], [-194, -72, -72, -254, 313, 91, -97, -119], [-83, -125, 1, 0, -132, -49, -91, -8], [-265, -373, -55, 0, -229, 36, -66, 199], [686, 24, 24, -194, -1, -547, -71, 143], [-1, 161, 81, 0, 132, 133, -111, -110], [-123, -105, -73, 0, -184, -61, -129, -6], [-491, 55, 55, -294, -200, -265, 35, 130]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_180_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_180_3_c_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_180_3_c_b(:prec:=8)
    chi := MakeCharacter_180_c();
    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_180_3_c_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_180_3_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_180_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![65536, 0, 188416, 0, 12032, 0, 224, 0, 1]>],Snew);
    return Vf;
end function;