
// Make newform 720.3.bh.f in Magma, downloaded from the LMFDB on 12 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_720_bh();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_720_bh_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_720_3_bh_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_720_3_bh_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 := [9, 0, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 3, 3];
    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_720_bh();"
function MakeCharacter_720_bh()
    N := 720;
    order := 4;
    char_gens := [271, 181, 641, 577];
    v := [4, 4, 4, 3];
    // 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_720_bh_Hecke();"
function MakeCharacter_720_bh_Hecke( : Kf := false)
    N := 720;
    order := 4;
    char_gens := [271, 181, 641, 577];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [0, 0, -1, 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 := 3;
    raw_aps := [[0, 0, 0, 0], [0, 0, 0, 0], [-3, 1, -1, 2], [-5, 0, 5, 2], [-4, -5, 0, 5], [0, 10, 0, 0], [10, 0, -10, 2], [0, -10, 10, -10], [-10, 6, -10, 0], [0, -5, -22, -5], [-4, 10, 0, -10], [0, 0, 0, -6], [-50, 10, 0, -10], [-30, 4, -30, 0], [0, 0, 0, -18], [50, -12, 50, 0], [0, 15, 52, 15], [-78, -10, 0, 10], [10, 0, -10, -12], [-20, 40, 0, -40], [-5, -32, -5, 0], [0, -10, -24, -10], [-60, -34, -60, 0], [0, 60, 10, 60], [75, 0, -75, 16], [-58, 5, 0, -5], [-55, 26, -55, 0], [-40, 0, 40, -46], [0, -30, -86, -30], [-40, 22, -40, 0], [-5, 0, 5, 2], [32, -5, 0, 5], [60, 0, -60, -34], [0, -40, 122, -40], [0, -35, -114, -35], [110, 20, 0, -20], [-30, 0, 30, 6], [40, -40, 40, 0], [130, 0, -130, 34], [-80, -74, -80, 0], [0, 5, -88, 5], [-10, -110, 0, 110], [4, -30, 0, 30], [15, -56, 15, 0], [-30, 0, 30, 188], [0, 20, -114, 20], [-110, 40, 0, -40], [105, 110, 105, 0], [100, 0, -100, 80], [0, 60, 138, 60], [-90, -50, -90, 0], [0, 60, -96, 60], [-32, 0, 0, 0], [-312, -25, 0, 25], [140, 0, -140, -54], [130, 66, 130, 0], [0, -15, 242, -15], [66, 0, 0, 0], [180, 0, -180, 26], [-6, -130, 0, 130], [-50, -208, -50, 0], [-90, 192, -90, 0], [-150, 0, 150, -24], [-116, 40, 0, -40], [-255, -56, -255, 0], [-60, 0, 60, 2], [-202, -170, 0, 170], [-75, 0, 75, -16], [320, 0, -320, -76], [0, 90, 38, 90], [-90, 142, -90, 0], [0, -30, 212, -30], [-5, 0, 5, -338], [70, -174, 70, 0], [0, 0, -194, 0], [-240, 238, -240, 0], [0, -105, 222, -105], [10, 0, -10, -326], [114, -200, 0, 200], [0, -80, -12, -80], [0, -125, -504, -125], [-310, -80, 0, 80], [128, -90, 0, 90], [65, 4, 65, 0], [0, 140, -214, 140], [-120, -176, -120, 0], [0, -150, -154, -150], [255, 0, -255, -240], [-326, 75, 0, -75], [-515, -18, -515, 0], [140, 0, -140, 414], [0, -60, 52, -60], [-105, 0, 105, 114], [4, 65, 0, -65], [0, -110, 278, -110], [-240, 234, -240, 0], [0, -45, -226, -45], [-522, 110, 0, -110], [-30, 52, -30, 0], [-482, -50, 0, 50], [-390, 0, 390, 184], [150, 0, -150, -236], [-420, 300, -420, 0], [0, -140, -338, -140], [-230, -10, 0, 10], [205, 0, -205, 396], [-180, 0, 180, -402], [40, 314, 40, 0], [0, -70, 568, -70], [-202, 180, 0, -180], [135, 0, -135, 186], [-210, 418, -210, 0], [150, 0, -150, -182], [0, -120, -522, -120], [-232, -130, 0, 130], [-634, -120, 0, 120], [-480, 236, -480, 0], [-620, 0, 620, 14], [240, 134, 240, 0], [0, -105, -196, -105], [938, -90, 0, 90], [295, -340, 295, 0], [160, 0, -160, -418], [540, 214, 540, 0], [1122, 10, 0, -10], [514, 65, 0, -65], [0, 120, 662, 120], [0, 60, -236, 60], [-585, 0, 585, -206], [100, 106, 100, 0], [0, 430, -130, 430], [-260, -266, -260, 0], [-252, -450, 0, 450], [-420, 0, 420, 462], [-182, -10, 0, 10], [0, 60, 706, 60], [420, 58, 420, 0], [890, 0, -890, -56], [240, 0, -240, 334], [0, 160, -518, 160], [310, -140, 0, 140], [-86, -365, 0, 365], [85, 342, 85, 0], [780, 0, -780, -244], [0, -290, 586, -290], [0, 30, 1052, 30], [670, 302, 670, 0], [-750, 0, 750, -106], [0, 220, 410, 220], [-430, -518, -430, 0], [-450, 0, 450, -98], [550, -280, 0, 280], [380, -272, 380, 0], [150, 0, -150, 158], [140, 0, -140, 636], [568, -90, 0, 90], [0, -330, 836, -330], [0, 10, 1046, 10], [-155, 0, 155, -176], [-630, 365, 0, -365], [-380, 0, 380, -216], [420, -34, 420, 0], [-205, 0, 205, -210], [-872, -275, 0, 275], [150, 0, -150, -566], [460, 638, 460, 0], [662, -360, 0, 360], [700, 0, -700, 82]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_720_bh_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_720_3_bh_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_720_3_bh_f(:prec:=4)
    chi := MakeCharacter_720_bh();
    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_720_3_bh_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_720_3_bh_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_720_bh();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![1444, 760, 200, 20, 1]>,<11,R![-134, 8, 1]>],Snew);
    return Vf;
end function;