{"id":28937323,"url":"https://github.com/tomstuart/dual_number","last_synced_at":"2025-09-22T03:47:46.856Z","repository":{"id":56844412,"uuid":"51309277","full_name":"tomstuart/dual_number","owner":"tomstuart","description":"A Ruby implementation of dual numbers.","archived":false,"fork":false,"pushed_at":"2019-09-07T21:12:49.000Z","size":13,"stargazers_count":17,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-27T15:03:37.196Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomstuart.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":"2016-02-08T16:21:09.000Z","updated_at":"2024-02-15T15:48:10.000Z","dependencies_parsed_at":"2022-09-09T04:11:25.045Z","dependency_job_id":null,"html_url":"https://github.com/tomstuart/dual_number","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tomstuart/dual_number","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomstuart%2Fdual_number","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomstuart%2Fdual_number/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomstuart%2Fdual_number/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomstuart%2Fdual_number/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomstuart","download_url":"https://codeload.github.com/tomstuart/dual_number/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomstuart%2Fdual_number/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276342531,"owners_count":25625581,"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","status":"online","status_checked_at":"2025-09-22T02:00:08.972Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-06-22T21:05:21.189Z","updated_at":"2025-09-22T03:47:46.846Z","avatar_url":"https://github.com/tomstuart.png","language":"Ruby","readme":"# dual_number\n\n![](https://github.com/tomstuart/dual_number/workflows/Ruby/badge.svg)\n\nThis library provides a Ruby implementation of [dual numbers](https://en.wikipedia.org/wiki/Automatic_differentiation), which are useful for forward mode [automatic differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation).\n\nIt is intended to accompany the article [“Automatic differentiation in Ruby”](http://codon.com/automatic-differentiation-in-ruby).\n\nThat article explains the details, but here’s a brief demonstration:\n\n```irb\n$ irb -Ilib\n\u003e\u003e require 'dual_number'\n=\u003e true\n\n\u003e\u003e x = DualNumber(1, 2)\n=\u003e (1+2ε)\n\n\u003e\u003e y = DualNumber(3, 4)\n=\u003e (3+4ε)\n\n\u003e\u003e x + y\n=\u003e (4+6ε)\n\n\u003e\u003e x * y\n=\u003e (3+10ε)\n\n\u003e\u003e (x + 3) * 4\n=\u003e (16+8ε)\n\n\u003e\u003e 3 + (4 * x)\n=\u003e (7+8ε)\n```\n\nOne application of dual numbers is to use the second (“dual”) component to represent the derivative of the first (“real”) component. This lets us find the derivative of a function at a particular value by just passing in a dual number instead of a normal number:\n\n```irb\n\u003e\u003e def distance(time:)\n     time * Math.sin(time * time) + 1\n   end\n=\u003e :distance\n\n\u003e\u003e value_and_derivative = distance(time: DualNumber(3, 1))\n=\u003e (2.2363554557252696-15.988226228682427ε)\n\n\u003e\u003e value_and_derivative.real\n=\u003e 2.2363554557252696\n\n\u003e\u003e value_and_derivative.dual\n=\u003e -15.988226228682427\n```\n\nIf you have any questions, please get in touch via [Twitter](http://twitter.com/tomstuart) or [email](mailto:tom@codon.com). If you find any bugs or other problems with the code, please [open an issue](https://github.com/tomstuart/dual_number/issues/new).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomstuart%2Fdual_number","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomstuart%2Fdual_number","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomstuart%2Fdual_number/lists"}