{"id":17317284,"url":"https://github.com/mauriciopoppe/interval-arithmetic","last_synced_at":"2025-05-05T22:20:23.929Z","repository":{"id":31898653,"uuid":"35467538","full_name":"mauriciopoppe/interval-arithmetic","owner":"mauriciopoppe","description":"An implementation of an algebraically closed interval system of the extended real number set","archived":false,"fork":false,"pushed_at":"2025-04-21T22:37:29.000Z","size":1589,"stargazers_count":91,"open_issues_count":1,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-21T23:31:33.010Z","etag":null,"topics":["interval","interval-arithmetic","interval-arithmetic-evaluator","math","precision"],"latest_commit_sha":null,"homepage":"https://mauriciopoppe.github.io/interval-arithmetic/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mauriciopoppe.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}},"created_at":"2015-05-12T04:50:59.000Z","updated_at":"2025-04-21T22:37:32.000Z","dependencies_parsed_at":"2022-09-22T01:52:55.654Z","dependency_job_id":null,"html_url":"https://github.com/mauriciopoppe/interval-arithmetic","commit_stats":null,"previous_names":["maurizzzio/interval-arithmetic"],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauriciopoppe%2Finterval-arithmetic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauriciopoppe%2Finterval-arithmetic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauriciopoppe%2Finterval-arithmetic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauriciopoppe%2Finterval-arithmetic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mauriciopoppe","download_url":"https://codeload.github.com/mauriciopoppe/interval-arithmetic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252584468,"owners_count":21771969,"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":["interval","interval-arithmetic","interval-arithmetic-evaluator","math","precision"],"created_at":"2024-10-15T13:16:06.864Z","updated_at":"2025-05-05T22:20:23.910Z","avatar_url":"https://github.com/mauriciopoppe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# interval-arithmetic\n\n[![NPM][npm-image]][npm-url]\n[![codecov](https://codecov.io/gh/mauriciopoppe/interval-arithmetic/branch/master/graph/badge.svg)](https://codecov.io/gh/mauriciopoppe/interval-arithmetic)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)\n\n\u003e An implementation of an algebraically closed interval system of the extended real number set\n\n- [Description](#description)\n  - [floating point operations](#floating-point-operations)\n  - [Interval arithmetic](#interval-arithmetic)\n  - [Notable modifications](#notable-modifications)\n- [Interval arithmetic evaluator](#interval-arithmetic-evaluator)\n- [Installation](#installation)\n- [API](#api)\n- [Development](#development)\n\n\n## Description\n\nAn `interval` is a pair of numbers which represents all the numbers between them, `closed`\nmeans that the bounds are also included in the representation, `extended real` because the\n`real number system` is extended with two elements: `-∞` and `+∞` representing negative infinity\nand positive infinity respectively.\n\nThe implementation is a modified port of the [Boost's interval arithmetic library](http://www.boost.org/doc/libs/1_58_0/libs/numeric/interval/doc/interval.htm),\nthe modifications are based on some guidelines from the following papers/presentations:\n\n- [Interval Arithmetic: from Principles to Implementation - T. Hickey, Q. Ju, M.H. van Emden](http://fab.cba.mit.edu/classes/S62.12/docs/Hickey_interval.pdf)\n- [Interval Arithmetic: Python Implementation and Applications - Stefano Taschini](http://conference.scipy.org/proceedings/scipy2008/paper_3/full_text.pdf)\n- [The Boost interval arithmetic library - Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion](https://www.lri.fr/~melquion/doc/03-rnc5-expose.pdf)\n- [Graphing equations with generalized interval arithmetic - Jeffrey Allen Tupper](http://www.dgp.toronto.edu/~mooncake/thesis.pdf)\n\n### floating point operations\n\nFloating point is a way to represent a real number in an approximate way (due to the finite\nspace existing on a computer), most calculations with real numbers will produce quantities that\ncannot be exactly represented with the space allocated and therefore this operation needs\nto be rounded in order to fit back into its finite representation, such errors are described in\nmore detail [here](http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html#689)\n\n### Interval arithmetic\n\nInstead of using a single floating point number as an approximation of a real number, interval\narithmetic represents the approximated value as a set of possible values (considering the numbers\nthat floating point cannot represent), let's say we want to represent the number `1 / 3`, as a single\nfloating point number it's approximated as `0.333333333333...`, in the end there will be some `333...`\ndecimals that will be lost due to the nature of floating point, instead we can represent this\nnumber with the interval `[0.2, 0.4]`, with this interval we're completely sure that `1 / 3` is within\nthe interval (although the interval is also representing many more numbers), to improve the `scope`\nof the interval we have to understand that numbers in JavaScript are represented with 64 bits,\ntherefore to get the next floating point number of a single precision number the last bit\nneeds to be incremented to get the upper bound, and the last bit also needs to be decremented\nto get the lower point\n\n### Notable modifications\n\n- next/previous IEEE754 floating point number implementation based on [Typed Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays)\n- `division` when both intervals contain zero creates a whole interval\n- `cosine, tangent` works with positive/negative values out of the box\n\n## Interval arithmetic evaluator\n\nDue to the expressive nature of the way the methods interact with intervals it's sad that even the simplest\noperation needs a lot of characters to be typed, let's consider evaluating the result of `1 + 2` expressed\nwith intervals\n\n```javascript\nInterval.add(new Interval(1, 1), new Interval(2, 2))\n```\n\nThis gets worse when the expression to be evaluated becomes complex like `sin(exp(x)) + tan(x) - 1/cos(PI) * [1, 3]^2`:\n\n```javascript\nconst x = Interval(0, 1);\nInterval.add(\n  Interval.sin(Interval.exp(x)),\n  Interval.sub(\n    Interval.tan(x),\n    Interval.mul(\n      Interval.div(Interval.ONE, Interval.cos(Interval.PI)),\n      Interval.pow(Interval(1, 3), 2)\n    )\n  )\n);\n```\n\nTo avoid this 'expressiveness' mess there's an [interval arithmetic evaluator module](https://github.com/maurizzzio/interval-arithmetic-eval)\nwhich I've created to deal with all the work of parsing/evaluating expressions like the one above\n\n```javascript\nconst compile = require('interval-arithmetic-eval');\ncompile('sin(exp(x)) + tan(x) - 1/cos(PI) * [1, 3]^2').eval({ x: [0, 1] })\n```\n\n## Installation \u0026 Usage\n\n```sh\n$ npm install --save interval-arithmetic\n```\n\n```js\nimport Interval from 'interval-arithmetic'\nInterval.add(Interval(1), Interval(2))\n```\n\n## API\n\nSee the [homepage](http://mauriciopoppe.github.io/interval-arithmetic/)\n\n## Development\n\n```sh\nnpm test\n```\n\nDeployment steps\n\n```sh\n// after the working directory is clean\nnpm test\nnpm run build\nnpm version (major|minor|patch)\ngit push origin master\n\n// if everything went well\nnpm publish\nnpm run deploy\n```\n\n\n2015-2022 © Mauricio Poppe\n\n[npm-image]: https://img.shields.io/npm/v/interval-arithmetic.svg?style=flat\n[npm-url]: https://npmjs.org/package/interval-arithmetic\n\n\n## License\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmauriciopoppe%2Finterval-arithmetic.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmauriciopoppe%2Finterval-arithmetic?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauriciopoppe%2Finterval-arithmetic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmauriciopoppe%2Finterval-arithmetic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauriciopoppe%2Finterval-arithmetic/lists"}