{"id":23509372,"url":"https://github.com/paulnorthrop/itp","last_synced_at":"2025-07-29T19:38:45.295Z","repository":{"id":41347745,"uuid":"496805021","full_name":"paulnorthrop/itp","owner":"paulnorthrop","description":"The Interpolate, Truncate, Project (ITP) Root-Finding Algorithm","archived":false,"fork":false,"pushed_at":"2025-05-07T14:58:44.000Z","size":2252,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-18T09:27:08.640Z","etag":null,"topics":["algorithm","bracketing","itp","itp-method","root-finding"],"latest_commit_sha":null,"homepage":"https://paulnorthrop.github.io/itp/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paulnorthrop.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2022-05-26T23:49:02.000Z","updated_at":"2025-05-07T14:58:48.000Z","dependencies_parsed_at":"2024-06-11T21:21:42.198Z","dependency_job_id":null,"html_url":"https://github.com/paulnorthrop/itp","commit_stats":{"total_commits":172,"total_committers":1,"mean_commits":172.0,"dds":0.0,"last_synced_commit":"b4732b2ad278d8bd6bab81581adbad5297a33348"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/paulnorthrop/itp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulnorthrop%2Fitp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulnorthrop%2Fitp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulnorthrop%2Fitp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulnorthrop%2Fitp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulnorthrop","download_url":"https://codeload.github.com/paulnorthrop/itp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulnorthrop%2Fitp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262212802,"owners_count":23275988,"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":["algorithm","bracketing","itp","itp-method","root-finding"],"created_at":"2024-12-25T11:40:54.908Z","updated_at":"2025-06-27T07:33:28.247Z","avatar_url":"https://github.com/paulnorthrop.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.width = 5, \n  fig.height = 3,\n  fig.align='center',\n  fig.path = \"man/figures/README-\"\n)\n```\n\n# itp\n\n[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/paulnorthrop/itp?branch=main\u0026svg=true)](https://ci.appveyor.com/project/paulnorthrop/itp)\n[![R-CMD-check](https://github.com/paulnorthrop/itp/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/paulnorthrop/itp/actions/workflows/R-CMD-check.yaml)\n[![Coverage Status](https://codecov.io/github/paulnorthrop/itp/coverage.svg?branch=main)](https://app.codecov.io/github/paulnorthrop/itp?branch=main)\n[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/itp)](https://cran.r-project.org/package=itp)\n[![Downloads (monthly)](https://cranlogs.r-pkg.org/badges/itp?color=brightgreen)](https://cran.r-project.org/package=itp)\n[![Downloads (total)](https://cranlogs.r-pkg.org/badges/grand-total/itp?color=brightgreen)](https://cran.r-project.org/package=itp)\n\n## The Interpolate, Truncate, Project (ITP) Root-Finding Algorithm\n\nThe **itp** package implements the Interpolate, Truncate, Project (ITP) root-finding algorithm of [Oliveira and Takahashi (2021)](https://doi.org/10.1145/3423597). Each iteration of the algorithm results in a bracketing interval for the root that is narrower than the previous interval. It's performance compares favourably with existing methods on both well-behaved functions and ill-behaved functions while retaining the worst-case reliability of the bisection method. For details see the authors' [Kudos summary](https://www.growkudos.com/publications/10.1145%25252F3423597/reader) and the Wikipedia article [ITP method](https://en.wikipedia.org/wiki/ITP_method).\n\n### Examples\n\nWe use three examples from Section 3 of [Oliveira and Takahashi (2021)](https://doi.org/10.1145/3423597) to illustrate the use of the `itp` function.  Each of these functions has a root in the interval $(-1, 1)$. The function can be supplied either as an R function or as an external pointer to a C++ function.\n\n```{r}\nlibrary(itp)\n```\n\n#### A continuous function\n\nThe Lambert function $l(x) = xe^x - 1$ is continuous.\n\n```{r lambert, echo = FALSE}\noldpar \u003c- par(mar = c(4.5, 4, 1, 1))\nlambert \u003c- function(x) x * exp(x) - 1\ncurve(lambert, -1, 1, main = \"Lambert\")\nabline(h = 0, lty = 2)\nabline(v = itp(lambert, c(-1, 1))$root, lty = 2)\npar(oldpar)\n```\n\nThe `itp` function finds an estimate of the root, that is, $x^{\\ast}$ for which $f(x^{\\ast})$ is (approximately) equal to 0.  The algorithm continues until the length of the interval that brackets the root is smaller than $2 \\epsilon$, where $\\epsilon$ is a user-supplied tolerance.  The default is $\\epsilon = 10^{-10}$.\n\nFirst, we supply an R function that evaluates the Lambert function.\n\n```{r lambert_root_r}\n# Lambert, using an R function\nlambert \u003c- function(x) x * exp(x) - 1\nitp(lambert, c(-1, 1))\n```\n\nNow, we create an external pointer to a C++ function that has been provided in the `itp` package and pass this pointer to the function `itp()`.  For more information see the [Overview of the itp package](https://paulnorthrop.github.io/itp/articles/itp-vignette.html) vignette.\n\n```{r lambert_root_Cpp}\n# Lambert, using an external pointer to a C++ function\nlambert_ptr \u003c- xptr_create(\"lambert\")\nitp(lambert_ptr, c(-1, 1))\n```\n\n#### The function `itp_c`\n\nAlso provided is the function `itp_c`, which is equivalent to `itp`, but the calculations are performed entirely using C++, and the arguments differ slightly: `itp_c` has a named required argument `pars` rather than `...` and it does not have the arguments `interval`, `f.a` or `f.b`.\n\n```{r lambert_root_itp_c}\n# Calling itp_c()\nres \u003c- itp_c(lambert_ptr, pars = list(), a = -1, b = 1)\nres\n```\n\n#### A discontinuous function\n\nThe staircase function $s(x) = \\lceil 10 x - 1 \\rceil + 1/2$ is discontinuous.\n\n```{r staircase, echo = FALSE}\noldpar \u003c- par(mar = c(4.5, 4, 1, 1))\nstaircase \u003c- function(x) ceiling(10 * x - 1) + 1 / 2\ncurve(staircase, -1, 1, main = \"Staircase\", n = 10000)\nabline(h = 0, lty = 2)\nabline(v = itp(staircase, c(-1, 1))$root, lty = 2)\npar(oldpar)\n```\n\nThe `itp` function finds the discontinuity at $x = 0$ at which the sign of the function changes. The value of 0.5 returned for the root `res$root` is the midpoint of the bracketing interval `[res$a, res$b]` at convergence.  \n\n```{r staircase_root}\n# Staircase\nstaircase \u003c- function(x) ceiling(10 * x - 1) + 1 / 2\nres \u003c- itp(staircase, c(-1, 1))\nprint(res, all = TRUE)\n```\n\n#### A function with multiple roots\n\nThe Warsaw function $w(x) = I(x \u003e -1)\\left(1 + \\sin\\left(\\frac{1}{1+x}\\right)\\right)-1$ has multiple roots.\n\n```{r warsaw, echo = FALSE}\noldpar \u003c- par(mar = c(4.5, 4, 1, 1))\nwarsaw \u003c- function(x) ifelse(x \u003e -1, sin(1 / (x + 1)), -1)\ncurve(warsaw, -0.9999999, 1, main = \"Warsaw\", n = 1000)\nabline(h = 0, lty = 2)\nabline(v = itp(warsaw, c(-1, 1))$root, lty = 2)\npar(oldpar)\n```\n\nWhen the initial interval is $[-1, 1]$ the `itp` function finds the root $x \\approx -0.6817$.  There are other roots that could be found from a different initial interval.\n\n```{r warsaw_root}\n# Warsaw\nwarsaw \u003c- function(x) ifelse(x \u003e -1, sin(1 / (x + 1)), -1)\nitp(warsaw, c(-1, 1))\n```\n\n### Installation\n\nTo get the current released version from CRAN:\n\n```{r installation, eval = FALSE}\ninstall.packages(\"itp\")\n```\n\n### Vignette\n\nSee the [Overview of the itp package](https://paulnorthrop.github.io/itp/articles/itp-vignette.html) vignette, which can also be accessed using `vignette(\"itp-vignette\", package = \"itp\")`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulnorthrop%2Fitp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulnorthrop%2Fitp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulnorthrop%2Fitp/lists"}