mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 17:12:06 +02:00
19.0 vanilla
This commit is contained in:
parent
0a7ae8db93
commit
991d2234ca
416 changed files with 646602 additions and 300844 deletions
|
|
@ -23,8 +23,8 @@ class SetDefinitions:
|
|||
(value is a collection of set ids).
|
||||
|
||||
Here is an example of set definitions, with natural numbers (N), integer
|
||||
numbers (Z), rational numbers (Q), real numbers (R), imaginary numbers
|
||||
(I) and complex numbers (C)::
|
||||
numbers (Z), rational numbers (Q), irrational numbers (R\\Q), real
|
||||
numbers (R), imaginary numbers (I) and complex numbers (C)::
|
||||
|
||||
{
|
||||
1: {"ref": "N", "supersets": [2]},
|
||||
|
|
@ -33,7 +33,23 @@ class SetDefinitions:
|
|||
4: {"ref": "R", "supersets": [6]},
|
||||
5: {"ref": "I", "supersets": [6], "disjoints": [4]},
|
||||
6: {"ref": "C"},
|
||||
7: {"ref": "R\\Q", "supersets": [4]},
|
||||
}
|
||||
Representation:
|
||||
┌──────────────────────────────────────────┐
|
||||
│ C ┌──────────────────────────┐ │
|
||||
│ │ R ┌───────────────────┐ │ ┌──────┐ | "C"
|
||||
│ │ │ Q ┌────────────┐ │ │ │ I | | "I" implied "C"
|
||||
│ │ │ │ Z ┌─────┐ │ │ │ │ | | "R" implied "C"
|
||||
│ │ │ │ │ N │ │ │ │ │ │ │ "Q" implied "R"
|
||||
│ │ │ │ └─────┘ │ │ │ │ │ │ "R\\Q" implied "R"
|
||||
│ │ │ └────────────┘ │ │ │ │ │ "Z" implied "Q"
|
||||
│ │ └───────────────────┘ │ │ │ │ "N" implied "Z"
|
||||
│ │ ┌───────────────┐ │ │ │ │
|
||||
│ │ │ R\\Q │ │ │ │ │
|
||||
│ │ └───────────────┘ │ └──────┘ │
|
||||
│ └──────────────────────────┘ │
|
||||
└──────────────────────────────────────────┘
|
||||
"""
|
||||
self.__leaves: dict[int | str, Leaf] = {}
|
||||
|
||||
|
|
@ -137,6 +153,47 @@ class SetDefinitions:
|
|||
return Leaf(UnknownId(ref), ref)
|
||||
return self.__leaves[ref]
|
||||
|
||||
def get_superset_ids(self, ids: Iterable[int]) -> list[int]:
|
||||
""" Returns the supersets matching the provided list of ids.
|
||||
|
||||
Following example defined in this set definitions constructor::
|
||||
The supersets of "Q" (id 3) is "R" and "C" with ids [4, 6]
|
||||
"""
|
||||
return sorted({
|
||||
sup_id
|
||||
for id_ in ids
|
||||
if id_ in self.__leaves
|
||||
for sup_id in self.__leaves[id_].supersets
|
||||
if sup_id != id_
|
||||
})
|
||||
|
||||
def get_subset_ids(self, ids: Iterable[int]) -> list[int]:
|
||||
""" Returns the subsets matching the provided list of ids.
|
||||
|
||||
Following example defined in this set definitions constructor::
|
||||
The subsets of "Q" (id 3) is "Z" and "N" with ids [1, 2]
|
||||
"""
|
||||
return sorted({
|
||||
sub_id
|
||||
for id_ in ids
|
||||
if id_ in self.__leaves
|
||||
for sub_id in self.__leaves[id_].subsets
|
||||
if sub_id != id_
|
||||
})
|
||||
|
||||
def get_disjoint_ids(self, ids: Iterable[int]) -> list[int]:
|
||||
""" Returns the disjoints set matching the provided list of ids.
|
||||
|
||||
Following example defined in this set definitions constructor::
|
||||
The disjoint set of "Q" (id 3) is "R\\Q" and "I" with ids [7, 5]
|
||||
"""
|
||||
return sorted({
|
||||
disjoint_id
|
||||
for id_ in ids
|
||||
if id_ in self.__leaves
|
||||
for disjoint_id in self.__leaves[id_].disjoints
|
||||
})
|
||||
|
||||
|
||||
class SetExpression(ABC):
|
||||
""" An object that represents a combination of named sets with union,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue