{"id":16763154,"url":"https://github.com/linas/anant","last_synced_at":"2025-07-09T07:36:30.917Z","repository":{"id":149559852,"uuid":"43644876","full_name":"linas/anant","owner":"linas","description":"Analytic Number Theory high-precision GnuMP routines","archived":false,"fork":false,"pushed_at":"2024-02-03T01:46:12.000Z","size":561,"stargazers_count":17,"open_issues_count":0,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-10T18:42:09.229Z","etag":null,"topics":["arbitrary-precision","combinatorics","complex-numbers","multiprecision","number-theory","numerical-algorithms","numerical-analysis","numerical-methods","special-functions","transcendental-functions"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linas.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-04T17:20:09.000Z","updated_at":"2025-04-08T11:34:55.000Z","dependencies_parsed_at":"2023-10-27T23:22:48.079Z","dependency_job_id":"53be8cc2-b873-4a03-a6de-360c292abd4b","html_url":"https://github.com/linas/anant","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/linas/anant","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linas%2Fanant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linas%2Fanant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linas%2Fanant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linas%2Fanant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linas","download_url":"https://codeload.github.com/linas/anant/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linas%2Fanant/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264414560,"owners_count":23604425,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arbitrary-precision","combinatorics","complex-numbers","multiprecision","number-theory","numerical-algorithms","numerical-analysis","numerical-methods","special-functions","transcendental-functions"],"created_at":"2024-10-13T05:05:44.962Z","updated_at":"2025-07-09T07:36:30.891Z","avatar_url":"https://github.com/linas.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nAnant  -- Algorithmic 'n Analytic Number Theory\n===============================================\n\n\u003cp style=\"text-align: center;\"\u003e\u003cb\u003e\n\u003ci\u003eVersion 0.3.0\u003c/i\u003e\u003cbr\u003e\nLinas Vepstas February 2024\u003cbr\u003e\nlinasvepstas@gmail.com\n\u003c/b\u003e\u003c/p\u003e\n\n\nThis project contains ad-hoc implementations of assorted analytic\nfunctions of interest in number theory, including the gamma function,\nthe Riemann zeta function, the polylogarithm, and the Minkowski\nquestion mark function. The implementation uses the Gnu Multi-Precision\nlibrary (GMP) to perform all low-level operations.  The code herein\nis licensed under the terms of the Gnu GPLv3 license.\n\nThis project is *NOT* meant to be a replacement for other, more\nestablished multi-precision systems, such as MPFR or PARI/GP.  It is\nmeant to be a staging area for implementations of functions that have\nnot (yet!) received much attention in the more established packages.\nUsers are strongly encouraged to port the contents of this package\nto other systems. Please! \nSeriously: the stuff here is still cutting-edge, fifteen years on.\nI really would like to see the \"serious\" math packages actually\nimplement these functions!\n\nA note about floating-point exceptions: many of the special functions\ncomputed here have poles at various values.  These will show up as\nmysterious floating-point exceptions deep within the code.  If you\nget an exception, make sure you are not evaluating a function at a pole!\n\nThis package has its origins as a collection of tools \u0026 utilities for\nthe benefit of the author.  As such, it was never really intended for\npublic consumption, and thus, will not have the usual amenities of\nestablished projects, such as clear documentation, a website, unit\ntest cases, or even a robust build system.  Caveat Emptor! It works\ngreat for me, and I use it all the time; but I am me, and not you.\n\nThere are several publications that describe this code, or make use of\nit. The most notable is this:\n\nVepstas, L. (2008) [\"An efficient algorithm for accelerating\nthe convergence of oscillatory series, useful for computing the\npolylogarithm and Hurwitz zeta functions\"]\n(http://link.springer.com/article/10.1007/s11075-007-9153-8).\n*Numerical Algorithms* vol. **47** issue 3: pp. 211-252.\n[arXiv:math.CA/0702243](https://arxiv.org/abs/math/0702243).\ndoi:10.1007/s11075-007-9153-8.\n\nThe most fun thing created with this code is this:\n[Linas' Art Gallery](https://linas.org/art-gallery).\n\nThe most verbose thing created with this code is this:\n[The Modular Group and Fractals](https://linas.org/math/sl2z.html)\n\u003ci\u003eAn exploration of the relationship between Fractals, the Riemann Zeta,\nthe Modular Group Gamma, the Farey Fractions and the Minkowski Question\nMark.\u003c/i\u003e\n\nSupported functions\n-------------------\nMany of the functions below are not \"difficult\"; what makes the code\nhere unique is that many of these use caching and partial computation\nto avoid repeated computations. In some cases, this caching allows the\nfunctions to be particularly fast when called in \"sequential\" order,\nas would naturally occur in summations. This can provide speedups of\nover a thousand-fold, when used correctly!\n\nAnother, apparently \"unique\" feature, as compared to established\nlibraries, is that most of the functions are handled on the complex\nplane.  Thus, the system comes with basic complex-number support.\n\nSome, but not all of the code is protected by spinlocks, and so can be\nused in parallel, i.e. in a multi-threaded setting. This can also give\na big boost in performance.  This code is used regularly on a 24-core\nCPU. It works.\n\nArbitrary precision constants\n-----------------------------\n* sqrt(3)/2, log(2)\n* e, e^pi\n* pi, 2pi, pi/2, sqrt(2pi), log(2pi), 2/pi\n* Euler-Mascheroni const\n* Riemann zeta(1/2)\n\nCombinatorial functions:\n------------------------\n* Rising pochhammer symbol (integer)\n* Partition function (integer)\n* Reciprocal factorial\n* Sequential binomial coefficient\n* Stirling Numbers of the First Kind\n* Stirling Numbers of the Second Kind\n* Bernoulli Numbers\n* Binomial transform of power sum\n* Rising pochhammer symbol (real)    i.e. (s)_n for real s\n* Rising pochhammer symbol (complex) i.e. (s)_n for complex s\n* Binomial coefficient (complex)     i.e. (s choose n) for complex s\n* High-speed, cached sequential-access binomial coefficient.\n\nElementary functions:\n---------------------\n* pow, exp, log, sine, cosine, tangent for real, complex arguments\n* arctan, arctan2 for real argument\n* log(1-x) for real, complex x\n* sqrt for complex argument\n\nClassical functions:\n--------------------\n* gamma (factorial) for real, complex argument\n* polylogarithm, using multiple algorithms: Borwein-style, Euler-Maclaurin\n* polylogarithm on multiple sheets (monodromy)\n* Periodic zeta function\n* Hurwitz zeta function, using multiple algorithms; complex arguments.\n* Riemann zeta function, using multiple algorithms: Borwein, Hasse, brute-force\n  for integer, real and complex arguments.\n* Confluent hypergeometric function, complex arguments\n\nNumber-theoretic functions:\n---------------------------\n* General complex-valued harmonic number\n* Gauss-Kuzmin-Wirsing operator matrix elements\n* Minkowski Question Mark function (Stern-Brocot tree), and its inverse\n* Taylor's series coefficients for the topologist's sin -- sin(2pi/(1+x))\n\nUtilities:\n----------\n* Fill in values of completely multiplicative arithmetic function.\n* Ordinary and exponential generating functions for arithmetic functions.\n* Euler re-summation of convergent series (speeds convergence).\n* Newton series interpolation of arithmetic series.\n* Powell's method for zero-finding on complex plane (noise-cancelling variant).\n* Root isolation on complex plane using Sagraloff-Yap (2011) algorithm.\n\n\nPre-requisites, Compiling, Installing, Testing\n----------------------------------------------\nThis package requires a copy of the Berkeley DB database to be\navailable. The database is used to cache certain intermediate values, to\nimprove performance of various internal algorithms.\n\nThis package has minimal build support. `cd` to the src directory, and\n`make`.  If you want to install the files somewhere, you will have to do\nthis by hand, or custom-tailor to suit your needs.\n\nThere is a unit test, rather ad-hoc in nature, and it is not\n\"user-friendly\".  It will report some errors in the last few decimal\nplaces of various routines, depending on how it was invoked. It is up\nto you to figure out if these are serious errors or not.  Caveat Emptor!\n\n(I mean, its 'error-free' for me, i.e. 'good enough'.  There is nothing\nin here that is horribly broken, as far as I know.  If quibbling over\nthe last few decimal places is important to you, you might have a\ndifferent opinion. If you're reasonably careful, and actually think\nabout what you are actually doing, things will go well.)\n\nPatches to improve the build system (and anything else that annoys you)\nare gladly accepted.\n\nPrecision\n---------\nMost of the algorithms deal with precision issues in a fairly ad-hoc\nkind of way.  Many/most routines require an argument specifying the\nnumber of decimal places of desired precision, and will typically\nreturn answers that are accurate from about 90% to 100% of the specified\nprecision. However, many of the algorithms use internal, intermediate\nresults that need to be maintained at a higher level of precision than\nthe \"desired\" precision. Thus, correct usage requires that the user\nspecify an mpf_set_default_prec() that is 10% to 50% larger than the\ndesired precision of the results.  The proper amount to use is up to\nyou to figure out!  A reasonable rule-of-thumb seems to be to use\nmpf_set_default_prec(5*desired_decimal_places) -- noting that log_2(10)\nis 2.3.\n\nAgain -- this may strike you as hacky; its good enough for what I need.\nPatches to improve the state of things are accepted.\n\nExample Usage\n-------------\nThe below provides an example of how to use the functions in this\nlibrary.\n\n      // Standard include headers\n      #include \u003cgmp.h\u003e\n      #include \u003cstdio.h\u003e\n      #include \"mp-polylog.h\"\n      #include \"mp-misc.h\"\n\n      int main()\n      {\n         cpx_t plog, ess, zee;  // Complex variant of mpf_t\n         int nbits;\n         int decimal_prec;\n\n         // decimal_prec is the number of decimal places of desired\n         // precision.\n         //\n         // 3.3 is equal to log_2(10), and is used to convert decimal\n         // places to number of binary bits.\n         //\n         // The +600 adds some extra \"padding precision\" for\n         // intermediate calculations. Most algorithms require some\n         // fair amount of additional bits of precision to be used in\n         // computing intermediate results.  The precise amount needed\n         // is somewhat ad-hoc, and not well-characterized for the\n         // different functions; typically, an extra 20% to 50% is\n         // needed.\n         //\n         decimal_prec = 500;\n         nbits = 3.3*decimal_prec + 600;\n         mpf_set_default_prec (nbits);\n\n         // Initialization\n         cpx_init (plog);\n         cpx_init (ess);\n         cpx_init (zee);\n\n         // Set values for which computation will be done.\n         cpx_set_d(ess, 2.1, 0.0);\n         cpx_set_d(zee, 0.5, 0.0);\n\n         // Compute ...\n         int rc = cpx_polylog(plog, ess, zee, decimal_prec);\n\n         // Check for error conditions\n         if (0 != rc)\n         {\n             printf(\"Error occurred during computation! rc=%d\\n\", rc);\n             return 1;\n         }\n         cpx_prt(\"Answer is \", plog);\n         printf(\"\\n\");\n\n         return 0;\n      }\n\n\nCurrent repository:\n-------------------\nin Git, on Github:\n   https://github.com/linas/anant\n\nOlder versions (2005 through 2012) can be found in Bazaar, on Launchpad:\n   https://launchpad.net/anant\n\nSource tarballs are available there too.\n\nRelated projects:\n-----------------\n* [C library for arbitrary-precision interval arithmetic](http://arblib.org/)\n  from Fredrik Johansson.  This library includes Airy and Bessel\n  functions, the error function, as well as the modular j-function and\n  others. [Github repo](https://github.com/fredrik-johansson/arb/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinas%2Fanant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinas%2Fanant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinas%2Fanant/lists"}