{"id":18552464,"url":"https://github.com/andrejewski/seth","last_synced_at":"2025-10-08T11:47:11.404Z","repository":{"id":18431078,"uuid":"21616094","full_name":"andrejewski/seth","owner":"andrejewski","description":"JavaScript DSL for functional Set Theory","archived":false,"fork":false,"pushed_at":"2017-04-10T17:02:45.000Z","size":11,"stargazers_count":114,"open_issues_count":0,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-05T00:02:40.365Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrejewski.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":"2014-07-08T14:37:15.000Z","updated_at":"2024-05-12T13:19:02.000Z","dependencies_parsed_at":"2022-09-02T07:12:00.846Z","dependency_job_id":null,"html_url":"https://github.com/andrejewski/seth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fseth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fseth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fseth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fseth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrejewski","download_url":"https://codeload.github.com/andrejewski/seth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247574085,"owners_count":20960496,"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-11-06T21:14:18.054Z","updated_at":"2025-10-08T11:47:06.368Z","avatar_url":"https://github.com/andrejewski.png","language":"JavaScript","readme":"Seth\n====\n\nSeth is JavaScript DSL for functional Set Theory. This DSL aims to present set theory in its abstract mathematical form instead of manually dealing with literal arrays and their elements in a programming environment.\n\nSeth is available on both [NPM](https://www.npmjs.org/package/seth) and Bower with support for AMD and contains tiny shims to support pre-ES6.\n\n```bash\nnpm install seth\nbower install seth\n``` \n\nSeth is pretty intuitive to use if already familiar with common set operations and comparisons. It looks like this, required in Node.js:\n\n```javascript\nvar Seth = require('seth'),\n\tSet = Seth.Set;\n\nvar C = Set([1,2,3]).union(Set([1,4,5]));\n//\u003e C = Set([1,2,3,4,5]);\n\nvar Zc = Seth.Integers.complement();\n// Numbers is the set of all Numbers. (U)\n// Integers is the set of all Integers within the Numbers universe. (A)\n// thus, Zc is the set of all Numbers that are not Integers. (U\\A)\n\nvar CAndZc = C.intersect(Zc);\n//\u003e CAndZc = Set([..all Numbers that are not Integers and are in C..]);\n// therefore, CAndZc is an empty set.\n\nvar proof = CAndZc.isSubsetOf(Seth.Nothing);\n// Nothing is an empty set.\n\n// Proofs allow assertions to be made more easily\nproof.confirms(2) //\u003e true\nproof.confirmsAll([1,2,3,4,5]) //\u003e true\n```\n\n## Features\n\nSeth is a set theory DSL with universe awareness that is composed functionally. Set Operations include `union`, `intersect`, `difference`, `symmetricDifference`, `cartesianProduct`, `complement`, and `inverse`. Comparisons include `isSupersetOf`, `isSubsetOf`, `isProperSubsetOf`, `isComplementOf`, and `isInverseOf`. All comparisons return Proofs that make assertions based on sets easier to handle and reason with methods like `confirms`, `confirmsAll`, `confirmsAllExcept`, and `testArray`.\n\nSeth includes common sets such as `Everything`, `Nothing` (alias `Empty`), `Numbers` (alias `R`), and `Integers` (alias `Z`) for convenience.\n\n## What is Functional Set Theory?\n\nI made it up.\n\nFunctional Set Theory is not a mathematical concept or a subset of set theory. When I say \"functional set theory,\" what I mean is set theory composed of functions instead of definite elements in a manner similarly expressed by functional programming languages. A functional set is not a list or range of elements, but it is instead a Boolean function that states whether a given element matches a given set's criteria of containment.\n\nWhy would I use such big words to construct an imaginary concept, one that is not even mathematically sound? Performance, duh. The real theory is computationally inefficient. For example, how would a computer store a set of everything, all combinations and deviations of numbers, strings, and objects? A computer will never have enough memory to capture everything. Even the smaller set of all numbers could not be stored in the memory of a computer. Yet Seth could not be limited to simple, short-length arrays of values.\n\nSeth needed something faster, more concise, and most importantly composable. The solution was functions and logic. Functions are awesome because they are lazy, exempt from depleting memory resources until they are evaluated. Logic is awesome because it is lightning fast and expressive. Combined they can efficiently express set theory.\n\nInstead of writing out every possible value in the universe, a set of everything in Seth can be expressed with one simple function.\n\n```javascript\n// The exact implementation of Seth.Everything\nvar Everything = Set(function(x) {\n\treturn true;\t\n});\n```\n\nNo matter what `x` is, the function returns `true` because the set contains everything. The set of all numbers is just as easy to create.\n\n```javascript\n// Seth.Numbers\nvar Numbers = Set(function(x) {\n\treturn typeof x === 'number';\n});\n```\n\nThese sets can then be composed into new sets with different meanings.\n\n```javascript\nvar NonNumbers = Numbers.complement();\n// Everything is the default universe.\n\n// NonNumbers is equivalent to:\nvar NonNumber = Set(function(x) {\n\treturn typeof x !== 'number';\n});\n```\n\nThat's amazing. What's more is the performance of this abstraction: in personal testing of Seth, 75 tests of the entire codebase only took 24ms. This is only the scratching surface of what is feasible with Seth. \n\n## Contributing\n\nI have never taken a class on set theory (heck I'm still in high school). I did read the [Wikipedia page](http://en.wikipedia.org/wiki/Set_theory) a few dozen times. This is just an interest of mine that I saw was lacking in implementation in the open-source community at large, so I wanted to attempt to fill the gap.\n\nIf you are a professional set theorist or even an amateur like me, if there is a bug please open an issue. If there is a feature this DSL should have, more common operations or comparisons, please point me to them or be hardcore and send me the pull request.\n\nContributions are incredibly welcome as long as they are standardly applicable and pass the tests (or break bad ones). Tests are written in Mocha and assertions are done with the Node.js core `assert` module.\n\n```bash\n# running tests\nnpm run test\nnpm run test-spec # spec reporter\n```\n\nFollow me on [Twitter](https://twitter.com/compooter) for updates or just for the lolz and please check out my other [repositories](https://github.com/andrejewski) if I have earned it. I thank you for reading.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Fseth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrejewski%2Fseth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Fseth/lists"}