
// Make newform 176.11.h.a in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_176_h();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_176_h_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_176_11_h_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_176_11_h_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_176_h();"
function MakeCharacter_176_h()
    N := 176;
    order := 2;
    char_gens := [111, 133, 145];
    v := [2, 2, 1];
    // 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_176_h_Hecke();"
function MakeCharacter_176_h_Hecke(Kf)
    N := 176;
    order := 2;
    char_gens := [111, 133, 145];
    char_values := [[1], [1], [-1]];
    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 := 11;
    raw_aps := [[0], [-475], [-3001], [0], [161051], [0], [0], [0], [11910325], [0], [-3192323], [-137082625], [0], [0], [-151795250], [375066650], [813567973], [0], [-2616638675], [-783651827], [0], [0], [0], [-2870912977], [9454010975], [0], [-9302418050], [0], [0], [161745575], [0], [0], [-27205510825], [0], [0], [0], [-112312451425], [203183981350], [0], [0], [-338385561923], [-310198474177], [434228898277], [0], [0], [-15680808002], [0], [1041674558725], [0], [111772766327], [0], [0], [0], [-1423057370627], [-2126806325950], [0], [-1469456782198], [0], [0], [0], [0], [0], [0], [-5504794917602], [-4908279730825], [4373522609975], [7403333165677], [0], [0], [0], [8220030059375], [0], [11591179443325], [0], [12072710165173], [-10898295219275], [12922088563727], [-17289078824950], [11922227318498], [0], [25823840291302], [20568233410298], [0], [-4379377827625], [0], [16674688229725], [-23285893427377], [0], [0], [-7996059095675], [34128982322125], [0], [35424606608125], [0], [5930086964998], [0], [50658194727527], [75145013507423], [0], [0], [0], [0], [0], [0], [0], [-63044959336225], [-27359343384650], [0], [-61402233278498], [0], [0], [0], [142489272045650], [178095228308677], [34423583527573], [10953197047223], [-219818399614475], [175104678471325], [189126022871975], [0], [210313493026727], [0], [0], [17286638672950], [-311487769772027], [0], [313308494533223], [384302693057677], [114172254329725], [0], [0], [0], [-178058099195627], [-113953706405350], [0], [0], [-410387282974150], [0], [-554412662714425], [0], [0], [0], [-519688437057275], [0], [-419458818291577], [-717675837774227], [0], [0], [708943491150277], [911192956111150], [0], [-1010740479945073], [1033888483846150], [0], [290238066133750], [-568037159398898], [0], [-580691505028798], [0], [0], [1138876155968725], [0], [0], [-366222315687923], [434197517786375], [-1830706999046675], [-1903692692118098], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_176_h_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_176_11_h_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_176_11_h_a(:prec:=1)
    chi := MakeCharacter_176_h();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 11));
    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_176_11_h_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_176_11_h_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_176_h();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,11,sign)));
    Vf := Kernel([<3,R![475, 1]>],Snew);
    return Vf;
end function;