{"id":15288131,"url":"https://github.com/stla/numerical-integration","last_synced_at":"2026-02-03T13:02:24.977Z","repository":{"id":191140000,"uuid":"684005808","full_name":"stla/numerical-integration","owner":"stla","description":"Numerical integration in Haskell.","archived":false,"fork":false,"pushed_at":"2023-11-06T08:35:51.000Z","size":3694,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-19T15:35:28.190Z","etag":null,"topics":["haskell","numerical-integration"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stla.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2023-08-28T08:51:00.000Z","updated_at":"2023-09-15T13:53:42.000Z","dependencies_parsed_at":"2024-01-02T01:13:21.281Z","dependency_job_id":"969d8051-96e0-47a4-a98b-148e15f38c60","html_url":"https://github.com/stla/numerical-integration","commit_stats":{"total_commits":42,"total_committers":1,"mean_commits":42.0,"dds":0.0,"last_synced_commit":"5d1e034adc5e9351ae0b976d46e5053dc30b0302"},"previous_names":["stla/numerical-integration"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stla/numerical-integration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2Fnumerical-integration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2Fnumerical-integration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2Fnumerical-integration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2Fnumerical-integration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stla","download_url":"https://codeload.github.com/stla/numerical-integration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2Fnumerical-integration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29046503,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T10:09:22.136Z","status":"ssl_error","status_checked_at":"2026-02-03T10:09:16.814Z","response_time":96,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["haskell","numerical-integration"],"created_at":"2024-09-30T15:44:14.553Z","updated_at":"2026-02-03T13:02:21.815Z","avatar_url":"https://github.com/stla.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# numerical-integration\n\n\n\u003c!-- badges: start --\u003e\n[![Stack-lts](https://github.com/stla/numerical-integration/actions/workflows/Stack-lts.yml/badge.svg)](https://github.com/stla/numerical-integration/actions/workflows/Stack-lts.yml)\n[![Stack-lts-Mac](https://github.com/stla/numerical-integration/actions/workflows/Stack-lts-Mac.yml/badge.svg)](https://github.com/stla/numerical-integration/actions/workflows/Stack-lts-Mac.yml)\n[![Stack-nightly](https://github.com/stla/numerical-integration/actions/workflows/Stack-nightly.yml/badge.svg)](https://github.com/stla/numerical-integration/actions/workflows/Stack-nightly.yml)\n\u003c!-- badges: end --\u003e\n\nOne-dimensional numerical integration using the \n['NumericalIntegration'](https://github.com/tbs1980/NumericalIntegration) C++ library.\n\n___\n\n***Example.*** Integrate x² between 0 and 1 with desired absolute error 0, \ndesired relative error 1e-5 and using 200 subdivisions. Exact value: 1/3.\n\n```haskell\nexample :: IO IntegralResult -- value, error estimate, error code\nexample = integration (\\x -\u003e x*x) 0 1 0.0 1e-5 200\n-- IntegralResult {\n--   _value = 0.3333333333333334, \n--   _error = 3.7007434154171895e-15, \n--   _code = 0\n-- }\n```\n\nThe error code 0 indicates the success.\n\n___\n\n***A highly oscillatory function.*** The function shown below is highly \noscillatory. It is know that the exact value of its integral from `0` to `1` \nis `π exp(-10) / 2 ≈ 7.131404e-05`.\n\n![](https://raw.githubusercontent.com/stla/numerical-integration/main/images/oscillatoryFunction.gif)\n\nLet's try to evaluate it with R with 200000 subdivisions. \n\n```r\nf \u003c- function(x) {\n  5*cos(2*x/(1-x)) / (25*(1-x)**2 + x**2)\n}\nintegrate(f, 0, 1, subdivisions = 200000)\n# 7.76249e-05 with absolute error \u003c 3.7e-05\n```\nR does not complain, however the result is not very good. \n\nNow let's try with the present library, with 100000 subdivisions.\n\n```haskell\nintgr :: IO IntegralResult \nintgr = integration (\\t -\u003e 5 * cos(2*t/(1-t)) / (25*(1-t)**2 + t**2)) 0 1 0.0 1e-4 100000\n-- IntegralResult {\n--    _value = 7.131328051415349e-5, \n--    _error = 4.991435083852171e-7, \n--    _code = 2\n-- }\n```\nAs compared to R, the computation is very slow. But the result is quite better. \nNote that the error code is 2, thereby indicating a failure of convergence. \nSo let's try 250000 subdivisions. This will take a while.\n\n```haskell\nintgr :: IO IntegralResult \nintgr = integration (\\t -\u003e 5 * cos(2*t/(1-t)) / (25*(1-t)**2 + t**2)) 0 1 0.0 1e-4 250000\n-- IntegralResult {\n--   _value = 7.131328051415349e-5, \n--   _error = 4.991435083852171e-7, \n--   _code = 2\n-- }\n```\n\nThe result is the same!\n\n___\n\n***The tanh-sinh procedure.***\nI don't master the Haskell library 'integration' but I give it a try below. \nIt implements the tanh-sinh quadrature.\n\n```haskell\nimport Numeric.Integration.TanhSinh\n\ntanhsinh :: Result\ntanhsinh = absolute 1e-6 $ parTrap (\\t -\u003e 5 * cos(2*t/(1-t)) / (25*(1-t)**2 + t**2)) 0 1\n-- Result {\n--   result = -6.463872646093162e-3, \n--   errorEstimate = 2.577460946077898e-2, \n--   evaluations = 769\n-- }\n```\nThe result is totally wrong, which is not surprising in view of the weak \nnumber of evaluations. But again, I don't master this library so I will\nnot conclude anything from this result.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Fnumerical-integration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstla%2Fnumerical-integration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Fnumerical-integration/lists"}