{"id":16918140,"url":"https://github.com/cshaa/arithmetic-types","last_synced_at":"2025-03-20T22:24:41.284Z","repository":{"id":69942955,"uuid":"366702795","full_name":"cshaa/arithmetic-types","owner":"cshaa","description":"Interfaces for mathematical data-types to implement","archived":false,"fork":false,"pushed_at":"2021-06-08T01:38:11.000Z","size":46,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-19T17:08:16.432Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/cshaa.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-05-12T12:09:58.000Z","updated_at":"2021-06-08T01:37:02.000Z","dependencies_parsed_at":"2023-02-24T18:30:11.804Z","dependency_job_id":null,"html_url":"https://github.com/cshaa/arithmetic-types","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"bd075cd825dc5f003d817617c386daf4cb5d9ccb"},"previous_names":["cshaa/arithmetic-types"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cshaa%2Farithmetic-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cshaa%2Farithmetic-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cshaa%2Farithmetic-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cshaa%2Farithmetic-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cshaa","download_url":"https://codeload.github.com/cshaa/arithmetic-types/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244701632,"owners_count":20495739,"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":[],"created_at":"2024-10-13T19:38:57.855Z","updated_at":"2025-03-20T22:24:41.259Z","avatar_url":"https://github.com/cshaa.png","language":"TypeScript","readme":"# Arithmetic Types\nStandardized interfaces for mathematical data types, such as Complex, Fraction and Matrix.\n**This repository is a draft, the standard has not been adopted anywhere yet.**\n\n# Overview\n * Every implementation of an _Arithmetic Types_ interface **must** provide an `Arithmetics` object with static methods such as `add(x, y)` which accept arguments of a single data type and perform arithmetic operations on it.\n * The available interfaces are in [`scalar-arithmetic.ts`](https://github.com/m93a/arithmetic-types/blob/main/lib/scalar-arithmetic.ts) and [`tensor-arithmetic.ts`](https://github.com/m93a/arithmetic-types/blob/main/lib/tensor-arithmetic.ts).\n * The methods of `Arithmetics` **must** treat the arguments as immutable and return a new instance where applicable.\n * Every instance of the data type **must** provide a `x.clone()` method and a reference to the `Arithmetics` object using `x[Symbol.for('arithmetics')]`.\n\n\n# Example usage\n\n## Static methods\nThis is how one can implement an arithmetic and geometric mean for fractions, decimals, complex numbers and quaternions etc., regardless of their implementation.\n```typescript\nimport { NormedDivisionRing, InstanceOf, symbols } from 'arithmetic-types'\n\nconst { Arithmetics } = symbols\ntype Numeric\u003cT, F\u003e = InstanceOf\u003c NormedDivisionRing\u003cT, F\u003e \u003e\n\n\nfunction arithmeticMean\u003cT, F\u003e(first: Numeric\u003cT, F\u003e, ...args: Numeric\u003cT, F\u003e[])\n{\n  const arithmetics = first[Arithmetics]\n\n  const sum = args.reduce( (a, b) =\u003e arithmetics.add(a, b), first )\n  const count = args.length + 1\n\n  return arithmetics.scale(sum, 1/count)\n}\n\n\nfunction geometricMean\u003cT, F\u003e(first: Numeric\u003cT, F\u003e, ...args: Numeric\u003cT, F\u003e[])\n{\n  const arithmetics = first[Arithmetics]\n  if (!arithmetics.isCommutative) throw new TypeError('Geometric mean of non-commutative numbers is not supported.')\n\n  const product = args.reduce( (a, b) =\u003e arithmetics.mul(a, b), first )\n  const count = args.length + 1\n\n  return arithmetics.pow(product, 1/count)\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcshaa%2Farithmetic-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcshaa%2Farithmetic-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcshaa%2Farithmetic-types/lists"}