{"id":17166402,"url":"https://github.com/andreaferretti/emmy","last_synced_at":"2025-04-09T16:17:46.899Z","repository":{"id":66316526,"uuid":"49215302","full_name":"andreaferretti/emmy","owner":"andreaferretti","description":null,"archived":false,"fork":false,"pushed_at":"2019-11-08T15:25:18.000Z","size":136,"stargazers_count":38,"open_issues_count":1,"forks_count":0,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-09T16:17:40.076Z","etag":null,"topics":["algebra","algebraic-structures","concepts","nim"],"latest_commit_sha":null,"homepage":null,"language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreaferretti.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":"2016-01-07T16:13:41.000Z","updated_at":"2024-09-17T10:36:59.000Z","dependencies_parsed_at":"2023-02-25T05:00:13.091Z","dependency_job_id":null,"html_url":"https://github.com/andreaferretti/emmy","commit_stats":{"total_commits":92,"total_committers":1,"mean_commits":92.0,"dds":0.0,"last_synced_commit":"c135a25cc9e899a4c231b6d2a42dd911581d82f0"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaferretti%2Femmy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaferretti%2Femmy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaferretti%2Femmy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaferretti%2Femmy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreaferretti","download_url":"https://codeload.github.com/andreaferretti/emmy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065282,"owners_count":21041872,"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":["algebra","algebraic-structures","concepts","nim"],"created_at":"2024-10-14T23:05:28.938Z","updated_at":"2025-04-09T16:17:46.843Z","avatar_url":"https://github.com/andreaferretti.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Emmy\n\nAlgebraic structures and related operations for Nim.\n\n![logo](https://raw.githubusercontent.com/unicredit/emmy/master/emmy.png)\n\n\u003c!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 --\u003e\n\n- [Emmy](#emmy)\n\t- [Status](#status)\n\t- [Algebraic structures](#algebraic-structures)\n\t\t- [Default instances](#default-instances)\n\t\t- [Making your own algebraic structures](#making-your-own-algebraic-structures)\n\t- [Modular rings](#modular-rings)\n\t- [Quotient rings](#quotient-rings)\n\t- [Primality](#primality)\n\t- [Polynomials](#polynomials)\n\t- [Linear algebra](#linear-algebra)\n\t- [Finite fields](#finite-fields)\n\n\u003c!-- /TOC --\u003e\n\n## Status\n\nThis library was extracted from a separate project, and will require some\npolish. Expect the API to change (hopefully for the better!) until further\nnotice. :-)\n\nThere is not too much in terms of documentation yet, but you can see the tests\nto get an idea.\n\n## Algebraic structures\n\nThe first building block for Emmy are definitions for common algebraic\nstructures, such as monoids or Euclidean rings. Such structures are encoded\nusing [concepts](http://nim-lang.org/docs/manual.html#generics-concepts),\nwhich means that they can be used as generic constraints (say, a certain\noperation only works over fields).\n\nThe definitions for those concepts follow closely the usual definitions in\nmathematics:\n\n```nim\ntype\n  AdditiveMonoid* = concept x, y, type T\n    x + y is T\n    zero(T) is T\n  AdditiveGroup* = concept x, y, type T\n    T is AdditiveMonoid\n    -x is T\n    x - y is T\n  MultiplicativeMonoid* = concept x, y, type T\n    x * y is T\n    id(T) is T\n  MultiplicativeGroup* = concept x, y, type T\n    T is MultiplicativeMonoid\n    x / y is T\n  Ring* = concept type T\n    T is AdditiveGroup\n    T is MultiplicativeMonoid\n  EuclideanRing* = concept x, y, type T\n    T is Ring\n    x div y is T\n    x mod y is T\n  Field* = concept type T\n    T is Ring\n    T is MultiplicativeGroup\n```\n\nWe notice a couple of ways where the mechanical encoding strays from the\nmathematical idea:\n\n* first, the definition above only requires the existence of appropriate\n  operations, and we cannot say anything in general about the various axioms\n  that these structures satisfy, such as associativity or commutativity;\n* second, the division is mathematically only defined for non-zero\n  denominators, but we have no way to enforce this at the level of types.\n\n### Default instances\n\nA few common data types implement the above concepts:\n\n* all standard integer types (`int`, `int32`, `int64`) are instances of\n  `EuclideanRing`;\n* Emmy depends on [bigints](https://github.com/def-/nim-bigints), and\n  `BigInt` is an `EuclideanRing` as well;\n* all float types are instances of `Field`;\n* `TableRef[K, V]` is an instance of `AdditiveMonoid`, provided `V` is.\n\nThe latter uses the sum on values corresponding to the same keys, so that for\ninstance\n\n```nim\n{ \"a\": 1, \"b\": 2 }.newTable + { \"c\": 3, \"b\": 5 }.newTable == { \"a\": 1, \"c\": 3, \"b\": 7 }.newTable\n```\n\n### Making your own algebraic structures\n\nIn order to make your data types a member of these concepts, just give\ndefinitions for the appropriate operations.\n\nThe line `zero(type(x)) is type(x)` may look confusing at first. This means\nthat - in order for a type `A` to be a monoid - you have to implement a function\nof type `proc(x: typedesc[A]): A`. For instance, for `int` we have\n\n```nim\nproc zero*(x: typedesc[int]): int = 0\n```\n\nand this allows us to call it like\n\n```nim\nzero(int) # returns 0\n```\n\nA similar remark holds for `id(type(x)) is type(x)`.\n\n### Cartesian products\n\nThe product of two additive (resp. multiplicative) monoids is itself an\nadditive (resp. multiplicative) monoid. The same holds for additive\ngroups and for rings (but not for fields!).\n\nEmmy defines suitable operations on pairs of elements, so that tuples with\ntwo elements live in an appropriate algebraic structure, provided each\ncomponent does. Hence, for instance, `(int, float64)` is a ring, and\n\n```nim\n(1, 2.0) + (3, 4.0) == (4, 6.0)\n(1, 2.0) * (3, 4.0) == (3, 8.0)\nzero((int, float64)) == (0, 0.0)\n```\n\nFor products with more than two factors, you can either define your own\ninstances or work recursively, using the isomorphism between `(A, B, C)` and\n`((A, B), C)`.\n\n## Modular rings\n\nTo be documented, see [tests](https://github.com/unicredit/emmy/blob/master/tests/tmodular.nim)\n\n## Fraction rings\n\nTo be documented, see [tests](https://github.com/unicredit/emmy/blob/master/tests/tfractions.nim)\n\n## Primality\n\nTo be documented, see [tests](https://github.com/unicredit/emmy/blob/master/tests/tprimality.nim)\n\n## Polynomials\n\nTo be documented, see [tests](https://github.com/unicredit/emmy/blob/master/tests/tpolynomials.nim)\n\n## Linear algebra\n\nTo be documented, see [tests](https://github.com/unicredit/emmy/blob/master/tests/tlinear.nim)\n\n## Finite fields\n\nTo be documented, see [tests](https://github.com/unicredit/emmy/blob/master/tests/tfinite_fields.nim)\n\n## Normal forms of matrices\n\nTo be documented, see [tests](https://github.com/unicredit/emmy/blob/master/tests/tnormal_forms.nim)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreaferretti%2Femmy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreaferretti%2Femmy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreaferretti%2Femmy/lists"}