{"id":37671048,"url":"https://github.com/mike-gimelfarb/numerical-integration","last_synced_at":"2026-01-18T00:39:43.093Z","repository":{"id":97617051,"uuid":"336263433","full_name":"mike-gimelfarb/numerical-integration","owner":"mike-gimelfarb","description":"a curated collection of algorithms for performing numerical integration of black-box functions and estimating limits of series and sequences with high precision in Java","archived":false,"fork":false,"pushed_at":"2024-07-30T00:44:57.000Z","size":180,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-07T13:06:00.837Z","etag":null,"topics":["algorithms","convergence-acceleration-algorithm","estimating-integrals","estimating-limits","infinite-sequences","infinite-series","integrals","limits","numerical-integration","numerical-methods","quadrature"],"latest_commit_sha":null,"homepage":"","language":"Java","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/mike-gimelfarb.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2021-02-05T12:19:55.000Z","updated_at":"2024-12-25T06:32:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"6dc0159f-61af-4a46-885d-b9bdf0fd04f2","html_url":"https://github.com/mike-gimelfarb/numerical-integration","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mike-gimelfarb/numerical-integration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mike-gimelfarb%2Fnumerical-integration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mike-gimelfarb%2Fnumerical-integration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mike-gimelfarb%2Fnumerical-integration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mike-gimelfarb%2Fnumerical-integration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mike-gimelfarb","download_url":"https://codeload.github.com/mike-gimelfarb/numerical-integration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mike-gimelfarb%2Fnumerical-integration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["algorithms","convergence-acceleration-algorithm","estimating-integrals","estimating-limits","infinite-sequences","infinite-series","integrals","limits","numerical-integration","numerical-methods","quadrature"],"created_at":"2026-01-16T12:04:26.551Z","updated_at":"2026-01-16T12:04:27.175Z","avatar_url":"https://github.com/mike-gimelfarb.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Summary\nThis library contains standard and state-of-the-art algorithms for estimating integrals of functions in 1D and limits of sequences and series in Java, many of which are not currently implemented in Commons Math.\n\nThe main features are:\n- over a dozen algorithms for estimating integrals of 1D functions\n- support for variable transformations, oscillatory and indefinite integrals\n- algorithms for estimating limits of sequences and series in double and high (e.g. arbitrary) precision\n\n# Examples\n\nThe necessary packages from the library to run the examples can be imported as follows\n\n```java\nimport java.util.function.Function;\nimport integral.*;\nimport series.dp.*;\nimport utils.Sequences;\n```\n\n## Limits and Series -- Simple Example\nThe framework currently supports many algorithms for accelerating convergence of infinite series, including methods of Aitken, Cohen, Theta (Brezinski and iterated), Levin (D, T, U and V transforms), Richardson, Wynn's Epsilon and Wynn's Rho, and an ensemble method.\n\nConsider the following infinite series:\n\n$$\\sum_{k=1}^{\\infty}{\\frac{1}{k^2}}$$\n\nThe Ensemble algorithm is the best bet if additional information about the series is not provided:\n\n```java\n// define the series terms\nIterable\u003cDouble\u003e iter = Sequences.toIterable(k -\u003e 1.0 / Math.pow(k, 2), 1);\n\n// find limit\nSeriesAlgorithm alg = new Ensemble(1e-8, 1000, 5);\nSystem.out.println(alg.limit(iter, true));\n```\n\nThe estimate of the limit is 1.64493406, the exact value is 1.64493406 (to 8 decimal places).\n\n## Limits and Series -- Complex Example\nSometimes existing methods fail if the series is very slowly converging. Consider the following very difficult series:\n\n$$\\sum_{k=2}^{\\infty}{\\frac{1}{k (\\log{k})^2}}$$\n\nApplying the Ensemble algorithm directly will return 2.06035757 which is not the correct limit. However, using a trick of van Wijngaarden, we can convert the series to an alternating series with the same limit:\n\n```java\n// define the series terms\nFunction\u003cLong, Double\u003e f = k -\u003e 1.0 / k / Math.pow(Math.log(k), 2);\n\t\n// create transform of original series\nFunction\u003cLong, Double\u003e f2 = (new Ensemble(1e-8, 100, 2)).toAlternatingSeries(f, 2);\nIterable\u003cDouble\u003e iter = Sequences.toIterable(f2, 1);\n\t\n// find limit of transformed series\nSeriesAlgorithm alg = new Ensemble(1e-8, 1000, 5);\nSystem.out.println(alg.limit(iter, true));\n```\n\nNow, the estimate of the limit is 2.10973574, which is correct to 5 decimal places.\n\nHowever, for terms that are sufficiently smooth and have an analytic continuation to the real numbers, it is possible to use the Euler-Maclaurin method to approximate the series by an imporoper integral, which often provides a more precise result. To run this, a method for evaluating integrals must be defined, how to break the improper integral up into proper integrals, and how to accelerate the resulting sequence of integral estimates.\n\n```java\nimport series.special.EulerMaclaurin;\n\n// define the series terms\nFunction\u003cDouble, Double\u003e f = k -\u003e 1.0 / k / Math.pow(Math.log(k), 2);\n\t\n// find limit of transformed series\nEulerMaclaurin algorithm = new EulerMaclaurin(1e-8, new GaussKronrod(1e-8, 1000), new Ensemble(1e-8, 1000, 5), k -\u003e Math.pow(2, k));\nSystem.out.println(algorithm.limit(f, 2L));\n```\n\nThis time, the estimate of the limit is 2.10974280 and is correct to 8 decimals.\n\n## Definite Integrals -- Simple Example\nThe framework is also very capable of numerically evaluating integrals of 1d functions, including adaptive Clenshaw-Curtis, adaptive Gaussian (Gauss-Kronrod, Gauss-Legendre, Gauss-Lobatto, RMS improvement of Gauss-Kronrod), Newton-Cotes, Romberg, adaptive Simpson (global and local versions), and Tanh-Sinh quadrature schemes.\n\nConsider the following definite integral:\n\n$$\\int_{-100}^{100}\\frac{1}{1\u0026plus;x^2} \\mathrm{d}x$$\n\nWe will use Gaussian quadrature (Gauss-Kronrod) to evaluate this integral:\n\n```java\n// define the integrand\nFunction\u003cDouble, Double\u003e f = x -\u003e 1.0 / (1.0 + x * x);\n\t\n// integrate\nQuadrature integrator = new GaussKronrod(1e-8, 1000);\nSystem.out.println(integrator.integrate(f, -100.0, 100.0));\n```\n\nThe predicted value is 3.12159332, which is correct to 8 decimal places.\n\n## Definite Integrals -- Infinite Bounds Example\n\nThe following integral is improper and hard to evaluate directly:\n\n$$\\int_{-\\infty}^{-1}\\frac{e^x}{x} \\mathrm{d}x$$\n\nHowever, the package provides a transformation of variables to deal with integrals of this form:\n\n$$[a,\\infty]\u0026space;:\u0026space;t\u0026space;\\in\u0026space;[0,1]\u0026space;\\to\u0026space;(a\u0026space;-\u0026space;1)\u0026space;\u0026plus;\u0026space;\\frac{1}{t}\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?[a,\\infty]\u0026space;:\u0026space;t\u0026space;\\in\u0026space;[0,1]\u0026space;\\to\u0026space;(a\u0026space;-\u0026space;1)\u0026space;\u0026plus;\u0026space;\\frac{1}{t}\" title=\"[a,\\infty] : t \\in [0,1] \\to (a - 1) + \\frac{1}{t}\" /\u003e\u003c/a\u003e\n\u003cp\u003e\u003c/p\u003e\n\u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=[-\\infty,b]\u0026space;:\u0026space;t\u0026space;\\in\u0026space;[0,1]\u0026space;\\to\u0026space;(b\u0026space;\u0026plus;\u0026space;1)\u0026space;-\u0026space;\\frac{1}{t}\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?[-\\infty,b]\u0026space;:\u0026space;t\u0026space;\\in\u0026space;[0,1]\u0026space;\\to\u0026space;(b\u0026space;\u0026plus;\u0026space;1)\u0026space;-\u0026space;\\frac{1}{t}\" title=\"[-\\infty,b] : t \\in [0,1] \\to (b + 1) - \\frac{1}{t}\" /\u003e\u003c/a\u003e\n\nIntegrals over [-infinity, infinity] are broken into two intervals at zero.\n\n```java\n// define the integrand\nFunction\u003cDouble, Double\u003e f = x -\u003e Math.exp(x) / x;\n\n// split the integration region into subregions\nQuadrature integrator = new TanhSinh(1e-8, 1000);\nSystem.out.println(integrator.integrate(f, Double.NEGATIVE_INFINITY, -1.0));\n```\n\nThe estimated value of the integral is -0.21938393, correct to 8 decimals.\n\n## Definite Integrals -- Oscillatory with Infinite Bounds Example\n\nThe following integral is improper, and is also highly oscillatory:\n\n$$\\int_{0}^{\\infty}\\cos(x^2) \\mathrm{d}x$$\n\nIt is impossible to evaluate using any single integrator. However, it is possible to break up this integral over integration regions separated by the roots of the function, and estimate the above integral by evaluating an infinite series. The package provides a convenience method to do this, but requires the roots of the integrand to be fed to the method. The following example illustrates this:\n\n```java\n// define the integrand\nFunction\u003cDouble, Double\u003e f = x -\u003e Math.cos(x * x);\n\n// split the integration region into subregions\nIterable\u003cDouble\u003e roots = Sequences.toIterable(k -\u003e Math.sqrt(Math.PI * k), 0L);\nQuadrature integrator = new GaussKronrod(1e-8, 1000);\nIterable\u003cDouble\u003e integrals = integrator.integratePiecewise(f, roots);\n\t\n// evaluate the integral as an alternating series\nSeriesAlgorithm accelerator = new Cohen(1e-8, 1000, 1);\nSystem.out.println(accelerator.limit(integrals, true));\n```\n\nThe estimated value of the integral is 0.62665707, which is correct to 8 decimal places.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmike-gimelfarb%2Fnumerical-integration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmike-gimelfarb%2Fnumerical-integration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmike-gimelfarb%2Fnumerical-integration/lists"}