mathset is an open source Python module with MathSet class that inherits methods and properties from built-in class Set. The code is made available on terms of The Mozilla Public License Version 2.0 described precisely in the LICENSE file. Due to limitations of modern computers, so far the module can handle only finite sets.
I guarantee it works with Python 3.10.12 and later versions. However, fell free to test it with earlier versions. If you have any problems with the module on your computer, please contact me so I can fix the bug.
Call class constructor to create new object. It should be passed one iterable parameter, preferably a set or a list. If no parameter is passed, the empty set is created. Since sets are unhashable in Python, if you want to create family of sets, make sure you pass list of sets to the constructor.
Returns true if the set is empty and false in any other case.
Returns true if every element of the first set belongs to the second set.
Returns true if every element of the set is a set itself.
Returns union of all sets in the set. Note that the starting set must be a family of sets.
Returns intersection of all sets in the set. Note that the starting set must be a non-empty family of sets.
Returns family of all subsets of given set.
Returns cartesian product of the starting set and set A. As Python has built-in tuples, they are used as ordered pairs in this module.
Returns true if the set is a subset of cartesian product of some two sets.
Returns domain of the relation. Note that the starting set must be relation.
Returns range of the relation. Note that the starting set must be relation.
When called on R set, returns image of A under R. Note that R must be relation.
Returns true if the set is a function.
When called on set f that is a function, returns y such that f(x) = y.
When called on set f, that is a function from X to Y and A is a subset of X, the method returns restriction of f to A.
When called on set f, that is a function from X to Y, the method returns true if f is injection.
When called on set f, that is a function from X to Y, the method returns true if f is surjection.
When called on set f, that is a function from X to Y, the method returns true if f is bijection.
When called on relation R, returns the inverse of R.
In this example, A is the multiplicative group of non-zero elements of field of integers modulo 13. f is bijection from A to A. Each element of A is paired with its multiplicative inverse.
When called on relation R, returns true if R is reflective relation on A.
When called on relation R, returns true if R is symmetric relation on A.
When called on relation R, returns true if R is transitive relation on A.
When called on relation R, returns true if R equivalence relation relation on A.
When called on relation R, returns true if R is irreflective relation on A.
When called on relation R, returns true if R is total relation on A.
When called on relation R, returns true if R is is strict linear ordering on A.
When called on equivalence relation R, returns equivalence class of element x.
When called on R which is equivalence relation on A, returns quotient set A/R.
When called on family of sets B, returns true is B is partition of A.
Formal definition of natural numbers
Relation of inclusion is a partial order on the power set
The author thanks Aleksander Bąba for help in this project.
My name is Krzysztof Karczewski. I am not a professional programmer and I have created this project, as well as the documentation, in my free time. If you want to contact me in the matter of the module or any other, send me an email please.