{"id":15009551,"url":"https://github.com/morwenn/prime_multiset","last_synced_at":"2026-01-28T07:15:33.200Z","repository":{"id":141999136,"uuid":"86260261","full_name":"Morwenn/prime_multiset","owner":"Morwenn","description":"A multiset of prime numbers represented by a single integer","archived":false,"fork":false,"pushed_at":"2017-03-26T19:58:50.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-19T07:42:28.022Z","etag":null,"topics":["data-structures","python","python-3-5"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Morwenn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","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":"2017-03-26T19:48:11.000Z","updated_at":"2023-06-16T11:39:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"f7d896c0-be08-4259-8190-fd7d6c3fa49d","html_url":"https://github.com/Morwenn/prime_multiset","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"5ec21d4d474b1f2196aa2fed15cf1dc138e0adfe"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morwenn%2Fprime_multiset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morwenn%2Fprime_multiset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morwenn%2Fprime_multiset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morwenn%2Fprime_multiset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morwenn","download_url":"https://codeload.github.com/Morwenn/prime_multiset/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243234100,"owners_count":20258393,"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":["data-structures","python","python-3-5"],"created_at":"2024-09-24T19:26:34.778Z","updated_at":"2026-01-28T07:15:33.172Z","avatar_url":"https://github.com/Morwenn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Python version](https://img.shields.io/badge/python-3.5-blue.svg)\n[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)\n\n## A multiset of prime numbers\n\nThe `prime_multiset` module contains a `PrimeMultiset` class that represents a multiset that can only store prime\nnumbers. Under the hood, the prime multiset is represented by a single positive integer. This is possible thanks to the\ninteresting observation that any natural number can be decomposed in a unique collection of prime factors. In other\nwords, [any natural number is a unique multiset of prime integers][1]. The underlying integer is accessible through the\n`value` member of a `PrimeMultiset`.\n\nThis single-integer representation has some fun \u0026 unique properties:\n* Most set operations can be computed with operations on integers (multiplication, gcd...)\n* The complexity of some operations becomes funny (*e.g* `discard` is a mere division)\n* Listing the elements is very expensive because it involves prime decomposition (hence not provided)\n* The `len` method isn't available for the same reason, but `is_empty` is provided\n* The storage for the underlying integer can be higher or lower than for a classic multiset implementation\n\nYou can read more about the operations equivalence in the article linked in the first paragraph.\n\n## The `PrimeMultiset` API\n\n### Initialization of the prime multiset\n\n```python\nPrimeMultiset(sequence=(), initial_value=1)\n```\n\nThe constructor initializes the `value` member with `initial_value`, which is the initial integer multiset\nrepresentation (`1` represents an empty multiset), to which are added the prime numbers contained in `sequence`.\n\n### Usual multiset operations\n\n```python\nmultiset \u0026 other\nmultiset \u0026= other\n```\n\nComputes the multiset intersection of `multiset` and `other` (retaining the lesser multiplicity per element).\n\n```python\nmultiset | other\nmultiset |= other\n```\n\nComputes the multiset union of `multiset` and `other` (retaining the greater multiplicity per element).\n\n```python\nmultiset + other\nmultiset += other\n```\n\nComputes the multiset addition of `multiset` and `other` (retaining the sum of multiplicities per element).\n\n```python\nmultiset - other\nmultiset -= other\n```\n\nComputes the multiset subtraction of `multiset` and `other` (retaining the differences of multiplicities per element\nbetween one multiset and another). If `other` contains prime numbers that are not in `multiset`, the subtraction is\ncomputed *as if* `other` did not contain those additional prime numbers.\n\n### Multiset equality operations\n\n```python\nmultiset == other\n```\n\nReturns whether `multiset` and `other` contain the same elements.\n\n```python\nmultiset != other\n```\n\nReturns whether `multiset` and `other` contain different elements.\n\n### Multiset inclusion operations\n\n```python\nmultiset \u003c= other\n```\n\nReturns whether every element in `multiset` is also in `other`.\n\n```python\nmultiset \u003c other\n```\n\nReturns whether `multiset` is a proper subset of `other`, that is, whether `multiset \u003c= other and multiset != other`.\n\n```python\nmultiset \u003e= other\n```\n\nReturns whether every element in `other` is also in `multiset`.\n\n```python\nmultiset \u003e other\n```\n\nReturns whether `multiset` is a proper superset of `other`, that is, whether `multiset \u003e= other and multiset != other`.\n\n### Modifying multiset operations\n\n```python\nadd(element)\n```\n\nAdds the prime number `element` to the multiset.\n\n```python\nremove(element)\n```\n\nRemoves the prime number `element` from the multiset. Raises `KeyError` if `element` is not contained in the multiset.\n\n```python\ndiscard(element)\n```\n\nRemoves the prime number `element` from the multiset if it is present.\n\n```python\nclear()\n```\n\nRemoves all elements from the multiset.\n\n### Non-modifying multiset operations\n\n```python\nelement in multiset\nelement not in multiset\n```\n\nReturns whether `multiset` contains the prime number `element`.\n\n```python\nis_empty\n```\n\nReturns whether the multiset does not contain any element.\n\n## Error handling in the API\n\nChecking whether a given integer is a prime number or not is rather expensive, therefore the `PrimeMultiset` API does\nnot validate its inputs. If integers other than prime numbers are passed to functions expecting prime numbers, the\nbehaviour of the operations is not guaranteed.\n\n\n  [1]: http://psmay.com/2012/02/17/fun-with-math-a-natural-number-is-a-multiset-of-prime-factors/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorwenn%2Fprime_multiset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorwenn%2Fprime_multiset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorwenn%2Fprime_multiset/lists"}