
// Make newform 14.13.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_14_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_14_b_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_14_13_b_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_14_13_b_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 := [1264170035276291934, 0, 174724076278260, 0, 8245426887, 0, 154710, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [824985433394766, 0, -86616988470, 0, -8963839, 0, -125, 0], [1313309281764933518688, 0, 134728750743817140, 0, 4172748382238, 0, 38659002, 0], [0, 42330085042660184769534, 0, 4996545933179551482, 0, 176258268664353, 0, 1774768547], [0, 294315438819634193998926, 0, 24481269884717511642, 0, 538494861420537, 0, 3573248699], [32181593594130820913735970, 127633302987889994511660, 4454151732706627888542, 9831189176412236460, 144898251813388725, 240235006799442, 1294978085403, 1886431118], [0, -72072591043975261349238, 0, -4947828940310478066, 0, -140815055259077, 0, -1324158591], [0, -1977787602909975649095918, 0, -175256809018488285066, 0, -4284780743595945, 0, -31567664251]];
    Rf_basisdens := [1, 7033679917677, 218044077447987, 518486139587258495352, 259243069793629247676, 129621534896814623838, 86414356597876415892, 518486139587258495352];
    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_14_b();"
function MakeCharacter_14_b()
    N := 14;
    order := 2;
    char_gens := [3];
    v := [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_14_b_Hecke();"
function MakeCharacter_14_b_Hecke(Kf)
    N := 14;
    order := 2;
    char_gens := [3];
    char_values := [[-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 := 13;
    raw_aps := [[0, -1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, -11, -1, 0, 0, 0], [24395, 514, 0, 2, -3, 1, -3, -1], [-26730, 13508, -11, 0, 0, 0, 0, 0], [0, 0, 0, -2207, -290, 0, 71, 46], [0, 0, 0, 14806, -1585, 0, 933, -102], [0, 0, 0, 12263, -1531, 0, 91, 1562], [19591470, -589796, -535, 0, -486, 972, 486, 0], [38606706, 5750456, 718, 0, -4050, 8100, 4050, 0], [0, 0, 0, -432366, 58173, 0, 22383, -4926], [-405450110, -27493992, 7290, 0, -7938, 15876, 7938, 0], [0, 0, 0, 1311530, -405416, 0, 71370, -82908], [2625787750, 25211860, -10125, 0, 154, -308, -154, 0], [0, 0, 0, -3900530, -2395, 0, 303327, 329922], [22555704690, 91069248, 19620, 0, -19764, 39528, 19764, 0], [0, 0, 0, 24324785, 1122235, 0, -312915, -1044570], [0, 0, 0, -25175257, 979649, 0, -1826804, -605848], [46151407430, 84200692, 98415, 0, 257686, -515372, -257686, 0], [71757268038, -695314076, -127648, 0, -444285, 888570, 444285, 0], [0, 0, 0, 35307944, -6670675, 0, 1056109, -772006], [-75978326266, -2404164060, -609930, 0, 517905, -1035810, -517905, 0], [0, 0, 0, 203353577, 6658870, 0, 639090, 7113420], [0, 0, 0, -445643820, -125727, 0, 16869525, -574806], [0, 0, 0, -180748082, 47714725, 0, 10303211, -10704794], [0, 0, 0, 370568463, 33922278, 0, 27673941, 1174314], [0, 0, 0, -278226166, 116560490, 0, -32376602, 23406788], [27094823190, 2011556132, -3430565, 0, 10005606, -20011212, -10005606, 0], [-1681276897454, 26898410320, 7788960, 0, 8091640, -16183280, -8091640, 0], [537847631010, -53454895548, -6905745, 0, -5187321, 10374642, 5187321, 0], [-1408191485890, -123467468212, -3325455, 0, 7899350, -15798700, -7899350, 0], [0, 0, 0, -980543235, -305181570, 0, -98147550, -120666180], [-525675130830, 93196539824, 7322980, 0, 5847552, -11695104, -5847552, 0], [0, 0, 0, -6429656551, 413236001, 0, -248686097, -16350382], [-5455118033982, 4919048016, -36200772, 0, -45269280, 90538560, 45269280, 0], [3088855815694, 61112733852, 64032201, 0, -6418590, 12837180, 6418590, 0], [0, 0, 0, -10789897251, 861153570, 0, 432533247, 19302462], [-12681368884330, -27052148604, 33309225, 0, -13208052, 26416104, 13208052, 0], [0, 0, 0, 29024772574, -491206180, 0, -297708708, 112180632], [0, 0, 0, 4778455941, -509403000, 0, 174773109, 904723194], [-7636864588794, -215147992268, -29548999, 0, 251540640, -503081280, -251540640, 0], [0, 0, 0, -7092296699, 1554661285, 0, 108563342, -994094900], [-15201864610794, 66372430468, 742094, 0, -145080315, 290160630, 145080315, 0], [-26372018701550, -560871543708, 194148495, 0, -90552501, 181105002, 90552501, 0], [12714295958370, 814706743208, 117704710, 0, 89578386, -179156772, -89578386, 0], [0, 0, 0, 28655807722, 2243023558, 0, -2298741886, 721998604], [11447487492454, 2347501637876, 17162523, 0, 243854570, -487709140, -243854570, 0], [0, 0, 0, 89521764456, -2970267360, 0, 5058072024, 1614488304], [0, 0, 0, -92474725857, -7130268525, 0, 5719389309, -1858337946], [0, 0, 0, -6691873233, -10908470466, 0, -726745611, -2327153958], [-37003378452750, 1537577075120, 179450620, 0, -10341432, 20682864, 10341432, 0], [28875701026206, 1154269204588, 831654989, 0, 149170410, -298340820, -149170410, 0], [0, 0, 0, 97067762462, 9667085015, 0, 154737109, 284288570], [0, 0, 0, 67669637923, 18086237084, 0, -5407642284, 3106544232], [0, 0, 0, 76117605828, 1007569950, 0, -7726290150, -3457843500], [164195120313990, -1693311813884, -349018540, 0, -919025433, 1838050866, 919025433, 0], [0, 0, 0, -25937352079, 1318776622, 0, -15031847553, 1537669326], [0, 0, 0, -12129633560, 3579204142, 0, 12256129730, 4874831356], [228432107184530, 7094609836856, -1416327930, 0, 1908475142, -3816950284, -1908475142, 0], [-87402177794430, -4816770775616, -81165928, 0, 3738648960, -7477297920, -3738648960, 0], [0, 0, 0, -262241934333, -23466567240, 0, 9075530928, 18058434048], [0, 0, 0, -90716084521, -11065620110, 0, -20909396631, -5263947966], [0, 0, 0, 198638108193, 9485032110, 0, 7458522354, 6232891884], [0, 0, 0, -652726855280, 71044751327, 0, -10280515155, -10798411434], [0, 0, 0, 1533404613754, -13163374310, 0, 18490038956, -5705906744], [-488554409366910, -5519558943096, 2383581750, 0, 845930466, -1691860932, -845930466, 0], [117117539966662, -7570767631308, 4284490221, 0, 2868774780, -5737549560, -2868774780, 0], [567818076934690, -14806573535676, -3780333585, 0, -9913561401, 19827122802, 9913561401, 0], [-649035284866650, 1935844646324, 3958912795, 0, 12356421858, -24712843716, -12356421858, 0], [0, 0, 0, -736935503029, -27856815229, 0, 8017578322, 35803375988], [0, 0, 0, 1470796543264, -66093348340, 0, 9512419908, 77609194248], [838499354262990, 4441264414876, -10872919567, 0, -7376779350, 14753558700, 7376779350, 0], [0, 0, 0, 1433264604328, 201279318490, 0, -43052670274, -1262127164], [657385530475250, -24417330954840, 8037902970, 0, 10775842722, -21551685444, -10775842722, 0], [-948283749481754, -15768649449900, 16104656925, 0, 5784494580, -11568989160, -5784494580, 0], [0, 0, 0, -2687116546954, -140931816965, 0, -70340226855, 14760128910], [1345304674087938, -17424003194680, -9934580810, 0, -4507506630, 9015013260, 4507506630, 0], [0, 0, 0, 1893597987195, 369467654025, 0, -97833787800, 2024549040], [-654769695308814, -15520931085068, 15174900971, 0, 6119583615, -12239167230, -6119583615, 0], [0, 0, 0, 1260967085534, 219167747924, 0, 119672010418, 37918006292], [0, 0, 0, 2676157439509, -62890935322, 0, 90087930378, 7255501884], [-277708794317182, 33610397376736, 22161879288, 0, -4939513700, 9879027400, 4939513700, 0], [4723945259742270, -64719132449044, 10349160793, 0, 6486553710, -12973107420, -6486553710, 0], [0, 0, 0, 1770170915682, -2014410195, 0, 117021307095, 193916451870], [0, 0, 0, -1134971532276, 74188664973, 0, 117145509663, -211010701806], [1684374111803430, 79642326914580, -11364830895, 0, 44068403160, -88136806320, -44068403160, 0], [-5531012439301710, 89022970064608, 2905151504, 0, -25922136780, 51844273560, 25922136780, 0], [2275148900259970, 38583175141692, 35970452865, 0, -3681852183, 7363704366, 3681852183, 0], [0, 0, 0, -620789323513, 480740400595, 0, -284159304786, -81366184020], [-1383914584937770, 121894821740292, -4276591830, 0, 6409931649, -12819863298, -6409931649, 0], [0, 0, 0, -7776852403065, -185953110795, 0, 57469452891, -100343985654], [0, 0, 0, -2124203818510, 190243885861, 0, 237368592975, -24826124382], [-2188116108050930, -98181490317124, -31315815, 0, -63119234302, 126238468604, 63119234302, 0], [-13704345426098682, 108566555844372, -7916273529, 0, -60571716570, 121143433140, 60571716570, 0], [5843013419792758, 9438737977828, 1040931729, 0, 116254991020, -232509982040, -116254991020, 0], [0, 0, 0, 397486698308, -1083966537455, 0, 226800184395, 122975845050], [0, 0, 0, -17102968960357, -588369989321, 0, -451008179394, 84118479132], [0, 0, 0, -14053622602870, 932495055652, 0, 311875466070, 200644419036], [0, 0, 0, 7673340626953, -485356287935, 0, 572893462583, 264670216498], [-3822054516109726, 196319663024448, -21582742896, 0, 10221455460, -20442910920, -10221455460, 0], [5791969511120630, -502610191980732, -76272747255, 0, -90207978444, 180415956888, 90207978444, 0], [9475238192254290, 120820341780752, 135230726440, 0, 81399670848, -162799341696, -81399670848, 0], [0, 0, 0, -332006278689, -1171298092155, 0, 983407916715, -370580063430], [-17408052210305790, -168729929854628, 48528811841, 0, -137656821735, 275313643470, 137656821735, 0], [8191359119490950, 163081320000948, 53379864999, 0, 143154582390, -286309164780, -143154582390, 0], [0, 0, 0, 38578475202068, -887353812130, 0, 1151838658570, -520735341580], [0, 0, 0, -319426938267, 2004280789935, 0, -619976691807, 1244372935278], [0, 0, 0, -16921215109900, -708079276040, 0, 1433257154388, 369309684168], [26824242045236598, 421625647155236, -114289085552, 0, 131127819975, -262255639950, -131127819975, 0], [0, 0, 0, -6388227659976, -1421261853729, 0, 1678808812263, 788991642318], [0, 0, 0, 50629128412312, -83470115720, 0, -997239696496, -204075390176], [-656767299581470, 45723010084288, -179489043720, 0, -307071570140, 614143140280, 307071570140, 0], [1920863245799250, 348806683589868, 97897833045, 0, -26003544615, 52007089230, 26003544615, 0], [0, 0, 0, 14102838408259, 171758348410, 0, -1840648851802, -487558764380], [6364858993766966, 52825421083620, 148986865620, 0, 117064946235, -234129892470, -117064946235, 0], [-11705324364323406, -641651553783580, 190409985895, 0, -242674348005, 485348696010, 242674348005, 0], [0, 0, 0, 37998297444339, 2153383986705, 0, -2579421527409, -1781868884574], [0, 0, 0, -21014847823590, -511787661450, 0, -1111310246190, -1234480101780], [-40849095725936190, 386491258204736, -104615744000, 0, 287457199596, -574914399192, -287457199596, 0], [-45441073824673482, 207353953035652, 50202709091, 0, -53922339090, 107844678180, 53922339090, 0], [0, 0, 0, -105876985840817, -2482932960020, 0, 74443677251, -168453795770], [71971152426814690, 1033804521008144, 452428722180, 0, -234834202228, 469668404456, 234834202228, 0], [0, 0, 0, 40711776308409, 1548320871345, 0, 68344098174, 1206671837724], [45983938422825270, -1108706444055612, -444465817545, 0, -675685240614, 1351370481228, 675685240614, 0], [0, 0, 0, 26411189561433, -5073068444166, 0, 1551357739566, 857482778772], [54308917300106178, 2740408132777632, -333719729904, 0, 387474592140, -774949184280, -387474592140, 0], [-25228837403474510, 121458929666304, 121062568572, 0, 34748590980, -69497181960, -34748590980, 0], [0, 0, 0, 60075742868006, 137660668645, 0, 1634994109047, -1836660084270], [0, 0, 0, 43512947653110, 10503760319190, 0, -2117427955734, 3262016928636], [0, 0, 0, -60901110897789, 5094640855335, 0, -4436678125098, -3963949576548], [97904306587931318, 1095513705602532, 683414957781, 0, -445889447280, 891778894560, 445889447280, 0], [-119712420133499250, 2876715950731868, -57798893495, 0, -624910008942, 1249820017884, 624910008942, 0], [-107277721064045954, 1105511977575596, 17475883893, 0, 244423187450, -488846374900, -244423187450, 0], [82510668419099650, -1519684505148096, 178706460600, 0, 683090701164, -1366181402328, -683090701164, 0], [0, 0, 0, -64442317423090, -8319888955448, 0, 678447094470, -354623660004], [0, 0, 0, 12084691796954, -7973342238445, 0, -3632365534547, -3575011181590], [0, 0, 0, 137493946277605, 3195338969615, 0, -11225995558704, 151796574576], [0, 0, 0, -89849301069281, -17284638803975, 0, -147231347041, -702486366206], [0, 0, 0, -50475780170007, -15723024023340, 0, -6312504035163, 1089592675962], [-84128758904443518, 3545701376702364, -405357817143, 0, 1152095327505, -2304190655010, -1152095327505, 0], [0, 0, 0, 380889571791999, -2986300647576, 0, 9994527599088, -239699695968], [104935812437537874, -2718872895584424, 428772106518, 0, 358579864710, -717159729420, -358579864710, 0], [128314773061384070, 1469425600654116, 1254992520420, 0, -391602933273, 783205866546, 391602933273, 0], [-190374540064573770, -2931967976732988, 26099957205, 0, 266433098472, -532866196944, -266433098472, 0], [0, 0, 0, -182748797473913, 8445772705537, 0, 8157323910884, 3474771769336], [0, 0, 0, 225424836835858, -4379950320982, 0, -1434778467234, -10273528618476], [0, 0, 0, 224951276646103, 17390944750840, 0, 3870205337039, 389191363534], [0, 0, 0, -287252048185094, -8359785575650, 0, -11511685146384, -9940292187984], [0, 0, 0, -286791578201429, -23801657155148, 0, -1103705318788, -1906449963704], [157736710162211670, -8376176737896476, 1465224585710, 0, 1392966774837, -2785933549674, -1392966774837, 0], [391745432165336930, 6640307838407928, -510748279110, 0, 510956284062, -1021912568124, -510956284062, 0], [0, 0, 0, 3437453151156, 3354502759260, 0, -3090517240968, 5065992198000], [-525542793295421450, -2794549977967548, -1372750234965, 0, -177809183706, 355618367412, 177809183706, 0], [0, 0, 0, 457811192687350, 8280254382890, 0, -3244778924826, -10662209139036], [226440312556237990, -1214995422349644, -453512148615, 0, 4535207135472, -9070414270944, -4535207135472, 0], [-55568660617655874, 6325020963511820, -326983306235, 0, -2411539911270, 4823079822540, 2411539911270, 0], [29859164768834950, 11761062582772036, -1877789653272, 0, 1656084448075, -3312168896150, -1656084448075, 0], [0, 0, 0, 187898661879130, -5265253415737, 0, -31494531975015, -9488438741406], [0, 0, 0, -324897254489404, 26365118161835, 0, -8916482007713, 16276177019582], [0, 0, 0, -399174327697159, 18667580269246, 0, 28775068195767, -2658661120002], [-507177150507542250, -6152928243111836, 1247856570455, 0, 1105910040618, -2211820081236, -1105910040618, 0], [586006522712009730, 14359663370608320, 182514671520, 0, 1368401165064, -2736802330128, -1368401165064, 0], [-794342753572547890, -5922297163053860, 634109133825, 0, 3074153126362, -6148306252724, -3074153126362, 0], [0, 0, 0, -221661589781659, 10127304121567, 0, 11598511513017, 15899417329566], [-239501628339666030, -8918931280449584, -618242476420, 0, -724023174024, 1448046348048, 724023174024, 0], [0, 0, 0, -308873265639898, 54147036798910, 0, 9973695280650, 19810213303740], [719197880145522406, -10197858471311676, 68323240962, 0, -2283666449835, 4567332899670, 2283666449835, 0], [0, 0, 0, -635954472975975, 10089949051545, 0, 2838933621990, 13865362488780]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_14_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_14_13_b_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_14_13_b_a(:prec:=8)
    chi := MakeCharacter_14_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 13));
    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_14_13_b_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_14_13_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_14_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,13,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;