seth

seth.core.Bij(A: Representable, B: Representable) → NamedSet[source]

Return the set of bijections from A to B as a NamedSet.

seth.core.Bij_inclusion(A: Representable, B: Representable) → Injection[source]

Return the inclusion of bijections into the homset as an Injection.

class seth.core.Bijection(dom: Representable, cod: Representable, table: Mapping | Callable, name: str)[source]

Bases: NamedFunction

A bijection is a function that is bijective, hence the class of bijections inherits from NamedFunction and adds a test for bijectivity in the constructor.

classmethod from_bijection_index(dom: Representable, cod: Representable, index: int, name: str = None) → Bijection[source]

Factory method to create a bijection from an index with the rustic encoding.

classmethod from_function(f: NamedFunction) → Bijection[source]

Factory method to create a bijection from a function that has tested bijective

classmethod from_raw(dom: Representable, cod: Representable, raw_liste: Sequence[int], name: str) → Bijection[source]

Factory method to create a bijection from a raw list of image ranks.

inverse_test() → bool[source]

Test that the backward function is indeed the inverse of the forward function.

symbolic_repr() → str[source]

Return a symbolic representation of the bijection, e.g.,

f : X ≃ Y

class seth.core.Coequalizer(f0: NamedFunction, f1: NamedFunction)[source]

Bases: Construct

The coequalizer of f0 : X → Y and f1 : X → Y is the quotient of Y by the gluing conditions

f0(x) ~ f1(x) for all x in X.

Enumeration is induced from the enumeration method of setoids.

projection() → NamedFunction[source]

Return the projection from Y to the coequalizer, defined by proj(y) = [y].

test_coequalize(g: NamedFunction) → bool[source]
universal_solution(f: NamedFunction) → NamedFunction[source]

For f : Y → C such that f ∘ f0 = f ∘ f1, return the unique function

u : Coeq(f0, f1) → C

such that

u ∘ proj = f

class seth.core.Construct[source]

Bases: Representable

A construct represents the result of a universal construction It is a representable, hence has a name, .obj returns an underlying object which is always a NamedSet. It is eligible as a domain or codomain of functions, and can be used in further constructions. It factorizes the method for iter, repr and len

property enumeration: tuple

Return the enumeration of the underlying set.

property name: str
property obj: NamedSet

Underlying representing object.

rank(x) → int[source]

Return the rank of an element in the underlying set.

unrank(n: int)[source]

Return the element of rank n in the underlying set.

class seth.core.Coproduct(X0: Representable, X1: Representable)[source]

Bases: Construct

The coproduct of two named sets X0 and X1 This is the disjoint union of X0 and X1, which can be represented as the set of pairs :

  • (0, a) with a in X0

  • (1, b) with b in X1

where the first component indicates the origin of the element. Obvious enumeration.

braiding() → Bijection[source]

Returns the braiding isomorphism

β : X0 + X1 ≃ X1 + X0

defined by

  • β(0, a) = (1, a)

  • β(1, b) = (0, b)

inj_0() → Injection[source]

Return the first injection

q0 : X0 ↣ X0 + X1,

defined by

q0(a) = (0, a)

inj_1() → Injection[source]

Return the second injection

q1 : X1 ↣ X0 + X1

defined by

q1(b) = (1, b)

universal_solution(f0: NamedFunction, f1: NamedFunction) → NamedFunction[source]

For f0 : X0 → C and f1 : X1 → C with same codomain C. Returns the unique function

u : X0 + X1 → C

such that

u ∘ q0 = f0 and u ∘ q1 = f1

class seth.core.Equalizer(f0: NamedFunction, g0: NamedFunction)[source]

Bases: Construct

The equalizer of two functions f0 : X → Y and g0 : X → Y This is the set of elements x in X such that f0(x) = g0(x).

inclusion() → NamedFunction[source]

Return the inclusion map

i : eq(f0,f1) ↣ X

universal_solution(h: NamedFunction) → NamedFunction[source]

Suppose h : C → X is a function such that f0 ∘ h = g0 ∘ h. Return the unique function u : C → Eq(f0, g0) such that incl ∘ u = h.

class seth.core.FiniteCoproduct(liste: Sequence[Representable])[source]

Bases: Construct

Return the finite coproduct of a list of named sets X0, …, X_{n-1}, whose elements are pairs (i, x) with i in {0, …, n-1} and x in X_i.

inj(i: int) → Injection[source]

Return the i-th injection from X_i to the coproduct, defined by q_i(x) = (i, x).

universal_solution(list_f: list[NamedFunction]) → NamedFunction[source]

Suppose list_f is a list of functions f_i : X_i -> C where X_i are the operands of the coproduct. Return the unique function u : X_0 + … + X_{n-1} -> C such that u ∘ q_i = f_i for all i.

class seth.core.FiniteProduct(liste: Sequence[Representable])[source]

Bases: Construct

Take a list of NamedSet and build their finite product, ‘ with projections and universal solution. Enumeration of the product is the lexicographic order of the enumerations of the operands.

proj(i: int) → Surjection[source]

Return the i-th projection from the product to the i-th operand, defined by p_i(a_0, …, a_{n-1}) = a_i.

universal_solution(list_f: list[NamedFunction]) → NamedFunction[source]

Suppose list_f is a list of functions f_i : C -> A_i where A_i are the operands of the product. Return the unique function

u : C -> A_0 x … x A_{n-1}

such that

p_i ∘ u = f_i for all i.

class seth.core.FrozenSetAffiche[source]

Bases: frozenset

A frozenset with a custom display method.

display()[source]

Display the elements of the frozenset in a sorted order with indentation. .. rubric:: Example

{a, b, c} will be displayed as:

a b c

class seth.core.HomSet(A: Representable, B: Representable)[source]

Bases: Construct

HomSet(A, B) is the NamedSet of all functions from A to B. The object is only produced by a property method called on demand, which generates all the functions from A to B

access(i: int) → NamedFunction[source]

Access the i-th function in the homset, based on the rustic encoding.

card() → int[source]
generate()[source]

Generate all functions from A to B as a NamedSet of NamedFunctions. use the rustic decoding for a quick enumeration.

generate_lazy() → Generator[NamedFunction, None, None][source]

Generate all functions from A to B as a generator of NamedFunctions. use the rustic decoding for a quick enumeration.

generate_list_tables() → list[dict][source]

Generate the table from indexes by rustic decoding

property name: str

Return the name of the homset.

property obj: NamedSet

Realizes Hom[A,B] as a NamedSet.

seth.core.Hom_left(f: NamedFunction, B: Representable) → NamedFunction[source]

Given f : A → A’ and B, return the function

Hom(f, B) : Hom(A’, B) → Hom(A, B)

defined by

Hom(f, B)(g) = g ∘ f

seth.core.Hom_right(A: Representable, g: NamedFunction) → NamedFunction[source]

Given A and g : B → B’, return the function

Hom(A, g) : Hom(A, B) → Hom(A, B’)

defined by

Hom(A, g)(f) = g ∘ f

class seth.core.Initial[source]

Bases: Construct

The initial object in the category of sets This is the empty set, which we denote by ∅.

unique_map(A: Representable) → NamedFunction[source]

Return the unique function

!_A : ∅ → A

which is the empty function since there are no elements in the domain.

seth.core.Inj(A: Representable, B: Representable) → NamedSet[source]

Return the set of injections from A to B as a NamedSet.

seth.core.Inj_inclusion(A: Representable, B: Representable) → Injection[source]

Return the inclusion of injections into the homset as an Injection.

class seth.core.Injection(dom: Representable, cod: Representable, table: Mapping | Callable, name=None)[source]

Bases: NamedFunction

An injection is a function that is injective, hence the class of injections inherits from NamedFunction and adds a test for injectivity in the constructor.

classmethod from_function(f: NamedFunction) → Injection[source]

Factory method to create an injection from a function that has tested injective

classmethod from_injection_index(dom: Representable, cod: Representable, index: int, name: str = None) → Injection[source]
classmethod from_raw(dom: Representable, cod: Representable, raw_liste: Sequence[int], name: str) → Injection[source]

Factory method to create a NamedFunction from a raw list of indices corresponding to the images of the elements of the domain in the codomain. The raw list must have the same length as the domain and contain indices that are valid for the codomain.

symbolic_repr() → str[source]

Return a symbolic representation of the injection, e.g.,

f : X ↣ Y

class seth.core.NamedFunction(dom: Representable, cod: Representable, table: Mapping | Callable, name: str = '')[source]

Bases: object

A function f : X -> Y is represented by a rule or a table that assigns to each element x of X an element f(x) of Y.

Parameters:
  • dom – the domain as a Representable

  • cod – the codomain as a Representable

  • table –

    a mapping defining the function; be given as :

    • a mapping (e.g., dict)

    • or as a callable (e.g., lambda).

  • name – an optional name for the function

V1 : all sets are finite, so we can always define the function by enumerating the domain and codomain.

_raw is the tuple of ranks of the images of the elements of the domain, and rustic_code is the integer encoding of the function as a base-|Y| number.

bijectivity_test() → bool[source]

Test bijectivity by checking both injectivity and surjectivity.

bijectivity_test_fast() → bool[source]

Fast test for bijectivity based on the sizes of the domain and codomain.

display() → str[source]

Return a display of the function that includes its name, domain, codomain, and graph.

fiber(y) → NamedSet[source]

Return the pre-image of y.

fibers() → dict[object, NamedSet][source]

Return the dictionary of fibers, i.e., the pre-images of all elements of the codomain.

fibers_decomposition() → FiniteCoproduct[source]

Fiber decomposition of the domain indexed over the codomain For f : X -> Y, return the coproduct of f⁻¹(y) for y in Y, which is isomorphic to X.

fibers_decomposition_isomorphism() → Bijection[source]

Return the isomorphism between the domain and the fibers decomposition.

classmethod from_index(dom: Representable, cod: Representable, index: int, name: str) → NamedFunction[source]

Factory method to create a NamedFunction from an index corresponding to the images of the elements of the domain in the codomain. The index must be valid for the number of functions from dom to cod.

classmethod from_raw(dom: Representable, cod: Representable, raw_liste: Sequence[int], name: str) → NamedFunction[source]

Factory method to create a NamedFunction from a raw list of indices corresponding to the images of the elements of the domain in the codomain. The raw list must have the same length as the domain and contain indices that are valid for the codomain.

graph_repr() → str[source]

Return a representation of the graph of the function where each line is of the form “x ↦ f(x)”.

image() → NamedSet[source]

Return the image as a named set.

image_factorization() → tuple[NamedFunction, NamedFunction][source]
injective_part() → NamedFunction[source]

Return the injective part of the function

Im(f) → Y,

defined by the same rule as f but with domain restricted to the image.

injectivity_test() → bool[source]

Test injectivity checking that no two distinct elements of the domain have the same image.

injectivity_test_fast() → bool[source]

Fast test for injectivity trim redundancy in the raw list and compare.

kernel() → Pullback[source]

Return the kernel pair of the function, i.e., the pullback of f along itself. for f : X → Y, this is the set of pairs (x1, x2) in X x X such that f(x1) = f(x2).

kernel_pair() → tuple[NamedFunction, NamedFunction][source]

Return the kernel pair of the function, i.e., the two projections from the pullback of f along itself.

rename(new_name: str) → NamedFunction[source]

Return a new NamedFunction with the same domain, codomain and values but a new name.

surjectivity_test() → bool[source]

Test surjectivity checking that every element of the codomain has a pre-image in the domain.

surjectivity_test_fast() → bool[source]

Fast test for surjectivity based on the sizes of the domain and codomain.

symbolic_repr() → str[source]

Return a symbolic representation of the function, e.g.,

f : X → Y

class seth.core.NamedSet(elements: set | frozenset | FrozenSetAffiche, name: str, enum: tuple | None = None)[source]

Bases: Representable

A named set is a FrozensetAffiche equipped with a name. Named sets are immutable, hence hashable; they have an extensional equality and can be themselves elements of other sets, or be keys in dictionnaries. Named sets will also be provided with enumeration of their elements, which will be used to allow for light representations of functions and other constructions.

add(x) → NamedSet[source]

Return a new NamedSet with the same name and the element x added to the underlying set.

content() → str[source]

Display the name and the elements of the set in a sorted order.

display()[source]

Display the elements of the frozenset in a sorted order with indentation. .. rubric:: Example

{a, b, c} will be displayed as:

a b c

property enumeration

Return the enumeration of the underlying set.

classmethod from_list(elements: list, name: str) → NamedSet[source]

Create a NamedSet from a list of elements, preserving the order of the list.

property name: str
property obj: NamedSet

Underlying representing object.

rank(x)[source]

Return the rank of an element in the underlying set.

remove(x) → NamedSet[source]

Return a new NamedSet with the same name and the element x removed from the underlying set.

rename(new_name: str) → NamedSet[source]

Return a new NamedSet with the same underlying set but a new name.

rename_elements(rename_func: Callable | dict) → NamedSet[source]

Return a new NamedSet with the same name but with the elements renamed according to rename_func.

restrict_enum(subset: set | frozenset | FrozenSetAffiche) → tuple[source]

Return the enumeration of the subset, preserving the order of the original enumeration.

unfreeze() → set[source]

Return the underlying set as a regular set (not frozenset).

unrank(i)[source]

Return the element of the underlying set with the given rank.

seth.core.Omega_set() → NamedSet[source]

Subobject classifier Ω, aka 2. Its elements are the native booleans False and True.

class seth.core.Product(X0: Representable, X1: Representable)[source]

Bases: Construct

Return the binary product X0 x X1 of two named sets X0 and X1, that is the set of pairs (a, b) with a in X0 and b in X1, endowed with the two projections p0 and p1 and the universal solution property. The enumeration of the product is the lexicographic order of the enumerations of X0 and X1.

braiding() → Bijection[source]

Return the braiding isomorphism

β : X0 x X1 ≃ X1 x X0

defined by

β(a, b) = (b, a)

proj_0() → Surjection[source]

Return the first projection

proj_0 : X0 x X1 → X0

defined by

p0(a, b) = a

proj_1() → Surjection[source]

Return the second projection

proj_1 : X0 x X1 → X1

defined by

p1(a, b) = b

universal_solution(f0: NamedFunction, f1: NamedFunction) → NamedFunction[source]

Suppose f0 : C → X0 and f1 : C → X1 are two functions with the same domain C. Returns the unique function

u : C → X0 x X1

such that

p0 ∘ u = f0 and p1 ∘ u = f1

class seth.core.Pullback(f0: NamedFunction, f1: NamedFunction)[source]

Bases: Construct

braiding()[source]

Return the braiding isomorphism of the pullback

β : X0 x_{X2} X1 ≃ X1 x_{X2} X0

defined by

i(x, y) = (y, x)

proj_0()[source]

Return the first projection

p0 : X0 x_{X2} X1 → X0

defined by

p0(x, y) = x.

proj_1()[source]

Return the second projection

p1 : X0 x_{X2} X1 → X1

defined by

p1(x, y) = y.

test_codomain()[source]

Ensure that the codomains of f0 and f1 are the same, otherwise the pullback is not defined.

universal_solution(f: NamedFunction, g: NamedFunction) → NamedFunction[source]

For f : C → X0 and g : C → X1 such that f0 ∘ f = f1 ∘ g, return the unique function u : C → X0 x_{X2} X1 such that

p0 ∘ u = f and p1 ∘ u = g

defined as

u(x) = (f(x), g(x)) for all x in C.

class seth.core.Pushout(f0: NamedFunction, f1: NamedFunction)[source]

Bases: Construct

Return the pushout of f0 : X2 → X0 and f1 : X2 → X1 as the quotient of the coproduct X0 + X1 by the equivalence relation generated by the gluing conditions

(0, f0(x)) ~ (1, f1(x)) for all x in X2.

constructed from a setoid on the coproduct, where the equivalence relation is generated by the gluing conditions. Enumeration induced from the enumeration of the coproduct and setoid.

braiding() → Bijection[source]

Return the braiding isomorphism of the pushout,

β : X0 +_{X2} X1 ≃ X1 +_{X2} X0

defined by

  • β([(0, a)]) = [(1, a)]

  • β([(1, b)]) = [(0, b)]

inj_0() → NamedFunction[source]

Return the injection

q_0 : X0 → X0 +_{X2} X1

defined by

q_0(a) = [ (0, a) ]

inj_1() → NamedFunction[source]

Return the injection

q_1 : X1 → X0 +_{X2} X1

defined by

q_1(b) = [ (1, b) ]

test_domain() → None[source]

Ensure that the domains of f0 and f1 are the same, otherwise the pushout is not defined.

universal_solution(f: NamedFunction, g: NamedFunction) → NamedFunction[source]

For f : X0 → C and g : X1 → C such that f ∘ f0 = g ∘ f1, returns the universal solution

u : X0 +_{X2} X1 → C

defined by

  • u([0, a]) = f(a)

  • u([1, b]) = g(b)

class seth.core.Rel(dom: Representable, cod: Representable)[source]

Bases: Construct

The homset of relations from A to B is the set of all relations on A x B, ordered by inclusion. It can be represented as a NamedSet of Relation objects.

class seth.core.Relation(dom: Representable, cod: Representable, table: set[tuple], name: str)[source]

Bases: object

A binary relation R on a set A is a subset of the Cartesian product A x B. We can represent it as a set of pairs (a, b) with a in A and b in B such that (a, b) ∈ R.

display()[source]

Print the relation as a list a R b for each pair (a, b) in R.

classmethod from_function(f: NamedFunction)[source]

Given a function f : A → B, return the graph of f as a relation on A x B.

classmethod from_subobject(A: Representable, B: Representable, subobject: FrozenSetAffiche, name: str | None = None)[source]

Given a subobject of A x B, return the corresponding relation.

gluing()[source]

Return the setoid on A x B generated by the pairs of the relation, i.e., the smallest equivalence relation on A x B that contains the pairs of R

class seth.core.Representable[source]

Bases: ABC

A representable is an object that can be represented by an underlying set. It will be the parent class of:

  • NamedSet, which is a set with a name and a custom display method;

  • Classes for universal constructions like limits and colimits, which will have an underlying NamedSet together with structure

  • homsets and some distributors

This superclass promises:

  • that the underlying set is accessible via the obj property

  • that this underlying set is a NamedSet

  • that the representable has a name, which is the name of the underlying set

content() → str[source]
display() → str[source]
property enumeration: tuple

Return the enumeration of the underlying set.

property identity: Bijection

Return the identity function on the named set.

property name: str
abstract property obj: NamedSet

Underlying representing object.

rank(x) → int[source]

Return the rank of an element in the underlying set.

rename(new_name: str) → Representable[source]
rename_elements(rename_func: Callable | dict) → Representable[source]
unrank(n: int)[source]

Return the element of rank n in the underlying set.

class seth.core.Setoid(X: Representable, eq: set[tuple])[source]

Bases: Construct

A setoid is a set equipped with an equivalence relation, represented by a set of generating equalities. The quotient is represented by the set of equivalence classes, which are frozensets of elements of X. The projection is the function that sends each element of X to its equivalence class. Uses a union-find data structure to compute the equivalence classes efficiently. Used to compute colimits of sets or present structures by generators and relations.

Parameters:
  • X – a Representable representing the underlying set of the setoid.

  • eq – a set of pairs (x, y) of elements of X representing the generating equalities x = y.

  • name – an optional name for the setoid.

  • set. (The underlying object is the quotient)

  • classes (The enumeration of the quotient is computed by sorting the equivalence)

  • X. (by the rank of their minimal element in the enumeration of)

card() → int[source]

Return the cardinality of the quotient, i.e., the number of equivalence classes.

class_of(x) → FrozenSetAffiche[source]

Return the equivalence class of x as a frozenset.

closure()[source]

Return the explicit closure of eq, i.e., the set of all pairs (x, y) such that x and y are in the same equivalence class.

created_equalities(x) → str[source]

Return a string representation of the equivalence class of x.

created_equality(x, y) → bool[source]

Return True if x and y are in the same equivalence class, i.e., if they are created equalities.

equalities() → str[source]

Return a string representation of all the equivalence classes, sorted by their minimal element.

find(x)[source]

Find the representative of the class of x, with path compression.

projection() → NamedFunction[source]

Return the projection function from X to the quotient, sending each element to its class

q : X -> X/eq

defined as

q(x) = [x]

quotient() → NamedSet[source]

Return the quotient set as a NamedSet, where the elements are the equivalence classes.

representation() → set[str][source]

Return a set of string representations of the equivalence classes. Represent each class by its minimal element (in sorted order) between brackets.

sorted_class(x) → tuple[source]

Return the equivalence class of x as a sorted tuple by restricting the enumeration of X to the class of x.

seth.core.Surj(A: Representable, B: Representable) → NamedSet[source]

Return the set of surjections from A to B as a NamedSet.

seth.core.Surj_inclusion(A: Representable, B: Representable) → Injection[source]

Return the inclusion of surjections into the homset as an Injection.

class seth.core.Surjection(dom: Representable, cod: Representable, table: Mapping | Callable, name=None)[source]

Bases: NamedFunction

A surjection is a function that is surjective, hence the class of surjections inherits from NamedFunction and adds a test for surjectivity in the constructor.

fibers_raw() → list[list[int]][source]

Return the fibers as domain ranks, ordered by codomain rank.

classmethod from_function(f: NamedFunction) → Surjection[source]

Factory method to create a surjection from a function that has tested surjective

classmethod from_raw(dom: Representable, cod: Representable, raw_liste: Sequence[int], name: str) → Surjection[source]

Factory method to create a NamedFunction from a raw list of indices corresponding to the images of the elements of the domain in the codomain. The raw list must have the same length as the domain and contain indices that are valid for the codomain.

classmethod from_surjection_index(dom: Representable, cod: Representable, index: int, name: str = None) → Surjection[source]
number_of_sections() → int[source]

Return the cardinality of the set of sections of this surjection.

section_code_to_injection_code(section_code: int) → int[source]

Convert a local section code to its global injection code.

section_from_index(index: int) → NamedFunction[source]

Decode the locally indexed section with code index.

section_index(section: NamedFunction) → int[source]

Encode one of this surjection’s sections by its local index.

sections() → NamedSet[source]

Return the set of sections of the surjection, i.e., the functions

s : cod -> dom

such that

f ∘ s = id_cod

symbolic_repr() → str[source]

Return a symbolic representation of the surjection, e.g.,

f : X ↠ Y

class seth.core.Terminal[source]

Bases: Construct

The terminal object in the category of sets is the singleton set, which we denote by 1.

unique_map(A: Representable) → NamedFunction[source]

Return the unique function

!_A : A → 1

defined by f(a) = *.

seth.core.Top() → Injection[source]

Return the top map from the terminal object to Ω

seth.core.associator_cartesian(X: Representable, Y: Representable, Z: Representable) → Bijection[source]

Return the associator isomorphism

α : (X x Y) x Z ≃ X x (Y x Z)

defined by

α((x, y), z) = (x, (y, z))

seth.core.associator_coproduct(X: Representable, Y: Representable, Z: Representable) → Bijection[source]

Return the associator isomorphism

α :(X + Y) + Z ≃ X + (Y + Z)

defined by:

  • α((0, (0, x))) = (0, x)

  • α((0, (1, y))) = (1, (0, y))

  • α((1, z)) = (1, (1, z))

seth.core.binary_to_charmap(A: Representable, index: int) → NamedFunction[source]

Build the characteristic function represented by a subset index.

seth.core.chaines(D: set, n: int) → set[tuple[NamedFunction, ...]][source]

D: set of named functions set of composable chains of length n, i.e., tuples (f_0, …, f_{n-1}) such that for all i

cod(f_i) = dom(f_{i+1})

seth.core.charmap(inclusion: Injection) → NamedFunction[source]

Given a subobject (inclusion) S → A, returns the characteristic function χ_S : A → Ω.

seth.core.charmap_int(inclusion: Injection) → int[source]

Compatibility alias for subobject_to_index().

seth.core.charmap_list(inclusion: Injection) → list[int][source]

Compatibility alias for subobject_to_subset_charmap().

seth.core.charmap_to_subset(chi: NamedFunction) → NamedSet[source]

Given a characteristic function χ : A → Ω, return the corresponding subset of A as a NamedSet.

seth.core.codiagonal(X: Representable) → NamedFunction[source]

Return the codiagonal function

∇ : X + X → X

defined by

  • ∇(0, x) = x

  • ∇(1, x) = x

seth.core.complement_subobject(A: Representable, inj: Injection) → Injection[source]

Return the complement of a subobject of A as an Injection.

seth.core.complement_subset(subset: Injection, A: Representable)[source]

Given a subset of A as a Representable, return its complement in A as a NamedSet.

seth.core.composition(f: NamedFunction, g: NamedFunction) → NamedFunction[source]

Return the composition g ∘ f, defined by (g ∘ f)(x) = g(f(x)). Beware of the order of composition: composition(f,g) means “apply f first, then g”.

seth.core.composition_chaine(chaine: Sequence[NamedFunction]) → NamedFunction[source]

Return the composition of a chain of composable functions, defined by

(f_{n-1} ∘ … ∘ f_0)(x) = f_{n-1}(…(f_0(x))…)

seth.core.composition_relations(R: Relation, S: Relation) → Relation[source]

Given two relations R on A x B and S on B x C, return their composition S ∘ R on A x C defined by

S ∘ R = { (a, c) | ∃b ∈ B, (a, b) ∈ R and (b, c) ∈ S }

seth.core.coproduct_maps(f: NamedFunction, g: NamedFunction)[source]

Return the coproduct of two functions f : A0 → B0 and g : A1 → B1, defined by

  • (f + g)(0, a) = (0, f(a))

  • (f + g)(1, b) = (1, g(b))

seth.core.currying(A: Representable, B: Representable, C: Representable) → Bijection[source]

Return the currying isomorphism

Hom(A x B, C) ≃ Hom(A, Hom(B, C))

seth.core.decode_function_raw(dom: Representable, cod: Representable, index: int) → tuple[int][source]

Decode a function from its rustic index to a raw list of codomain indices.

seth.core.decode_function_to_dict(dom: Representable, cod: Representable, index: int) → dict[source]

Decode a function from its rustic index to a dictionary representation.

seth.core.decode_injection_raw(dom: Representable, cod: Representable, index: int) → tuple[int][source]

Decode an injection from its rustic index to a raw list of codomain indices.

seth.core.decode_injection_to_dict(dom: Representable, cod: Representable, index: int) → dict[source]

Decode an injection from its rustic index to a dictionary representation.

seth.core.decode_surjection_raw(dom: Representable, cod: Representable, index: int) → tuple[int][source]

Decode a surjection from its rustic index to a raw list of codomain indices.

seth.core.decode_surjection_to_dict(dom: Representable, cod: Representable, index: int) → dict[source]

Decode a surjection from its rustic index to a dictionary representation.

seth.core.decomposition_binary_product(candidate: Representable) → Product[source]

Return the decomposition of candidate as a binary product.

seth.core.detection_binary_product(candidate: Representable) → bool[source]

Return True if obj is isomorphic to a binary product, i.e., if it is a set of pairs (a, b) such that for any a in the first component and b in the second component, (a, b) is in the set.

seth.core.diagonal(X: Representable) → NamedFunction[source]

Return the diagonal function

Δ : X → X x X

defined by

Δ(x) = (x, x)

seth.core.difference_subobjects(A: Representable, inj0: Injection, inj1: Injection) → Injection[source]

Return the difference of two subobjects of A as an Injection.

seth.core.equalities(D: set, n: int) → set[str][source]

Return the set of equalities between distinct composable chains of length n.

seth.core.finite_coproduct_maps(list_f: list[NamedFunction]) → NamedFunction[source]

Return the coproduct of a list of functions f_i : A_i → B_i, defined by

(f_0 + … + f_{n-1})(i, a) = (i, f_i(a))

seth.core.finite_product_decomposition(candidate: Representable) → FiniteProduct[source]

Return the decomposition of candidate as a finite product

seth.core.finite_product_detection(candidate: Representable) → bool[source]

Return True if obj is isomorphic to a finite product

seth.core.finite_product_maps(list_f: list[NamedFunction]) → NamedFunction[source]

Return the product of a list of functions f_i : A_i → B_i, defined by

(f_0 x … x f_{n-1})(a_0, …, a_{n-1}) = (f_0(a_0), …, f_{n-1}(a_{n-1})).

seth.core.finset(n: int) → NamedSet[source]

Return the finite set {0, 1, …, n-1} as a NamedSet.

seth.core.inclusion(subset0: Representable, subset1: Representable) → Injection[source]

Return the inclusion of subset0 in subset1 as an Injection, if subset0 is included in subset1, otherwise raise an error.

seth.core.inclusion_subset(subset_brut: set, A: Representable) → Injection[source]

Given a subset of A as a set, return the corresponding inclusion as an Injection.

seth.core.inclusion_test(subset0: set, subset1: set) → bool[source]

Test if subset0 is included in subset1.

seth.core.inclusion_test_setnom(subset0: Representable, subset1: Representable) → bool[source]

Test if subset0 is included in subset1, for NamedSet objects.

seth.core.index_to_binary(A: Representable, index: int) → list[int][source]

Compatibility alias for the historical name used in examples.

seth.core.index_to_list(A: Representable, index: int) → list[int][source]

Compatibility alias for index_to_subset_charmap().

seth.core.index_to_subobject(A: Representable, index: int) → Injection[source]

Decode a subset index into the canonical inclusion S ↪ A.

seth.core.index_to_subset(A: Representable, index: int) → NamedSet[source]

Decode a subset index into a NamedSet.

seth.core.index_to_subset_charmap(A: Representable, index: int) → list[int][source]

Decode index into bits, with bit i attached to A.unrank(i).

seth.core.initial_detection(X: Representable) → bool[source]

Return True if X is an initial object, i.e., if the underlying set of X is empty

seth.core.initial_isomorphism(X: Representable) → Bijection[source]

Return the unique isomorphism from ∅ ≃ X if X is empty, otherwise raise an error.

seth.core.injections_factorization(A: Representable, inj0: Injection, inj1: Injection) → bool[source]

Test whether the subobject represented by inj0 factors through inj1.

seth.core.intersection_sets(index: Sequence[Representable]) → Representable | NamedSet[source]

The index is a set of subsets (NamedSet); return the intersection of these subsets as a NamedSet.

seth.core.intersection_subobjects(S0: Injection, S1: Injection) → Injection[source]

Given two subobjects S0 -> B and S1 -> B, return their intersection as a subobject of B.

seth.core.intersection_subsets(subset_A: Representable) → NamedSet[source]

The index is a set of subsets (NamedSet) of A; return the intersection of these subsets as a NamedSet.

seth.core.iterated_binary_product(liste: list[Representable]) → Representable[source]

Return the iterated binary product of a list of NamedSet (((A_0 x A_1) x A_2) x … ) x A_{n-1}

seth.core.join_relations(R: Relation, S: Relation) → Relation[source]

Given two relations R and S on the same sets A x B, return their join R ∨ S defined by

R ∨ S = { (a, b) | (a, b) ∈ R or (a, b) ∈ S }

seth.core.left_distributivity_isomorphism(ext: Representable, paire: tuple[Representable, Representable]) → Bijection[source]

Return the distributivity isomorphism

d : X x (Y + Z) ≃ (X x Y) + (X x Z)

defined by:

  • d(x, (0, y)) = (0, (x, y))

  • d(x, (1, z)) = (1, (x, z))

seth.core.list_to_charmap(A: Representable, bits: Sequence[int | bool], name: str | None = None) → NamedFunction[source]

Build the characteristic function represented by rank-ordered bits.

seth.core.list_to_subset(A: Representable, bits: Sequence[int | bool]) → NamedSet[source]

Compatibility alias for subset_charmap_to_subset().

seth.core.map_to_initial(X: Representable)[source]

Test if there is a function X → ∅, which is the case if and only if X is empty.

seth.core.meet_relations(R: Relation, S: Relation) → Relation[source]

Given two relations R and S on the same sets A x B, return their meet R ∧ S defined by

R ∧ S = { (a, b) | (a, b) ∈ R and (a, b) ∈ S }

seth.core.name_by_content(elements: set | frozenset | FrozenSetAffiche) → NamedSet[source]

Generate a name for a set based on its content. The name is generated by sorting the elements and joining their string representations with commas.

seth.core.name_by_rule(dom: Representable, cod: Representable, table: Mapping | Callable) → NamedFunction[source]

Generate a name for a function based on its rule or values.

seth.core.ordered_pair(a, b) → NamedSet[source]

Return the ordered pair (a, b) as a NamedSet, defined by

(a, b) = {{a}, {a, b}}

seth.core.ordinal(n: int) → Representable[source]

Return Von-Neumann ordinal n as a Representable, defined by:

  • 0 = ∅

  • n+1 = n ∪ {n}

seth.core.pair(a, b) → NamedSet[source]

Return the pair {a, b} as a NamedSet.

seth.core.parallel_chains(D: set, n: int) → set[tuple[NamedFunction, NamedFunction]][source]

Return the set of pairs of distinct composable chains of length n that have the same domain and codomain.

seth.core.powerset(A: Representable) → NamedSet[source]

Return P(A) enumerated by subset codes 0, ..., 2^|A| - 1.

seth.core.powerset_contravariant(f: NamedFunction) → NamedFunction[source]

Return the contravariant powerset map induced by f : A → B, defined by

f*(S) = {x in A | f(x) in S}

for any subset S of B.

seth.core.powerset_contravariant_formel(f: NamedFunction) → NamedFunction[source]

Compatibility alias for powerset_contravariant().

seth.core.powerset_covariant(f: NamedFunction) → NamedFunction[source]

Return the covariant powerset map induced by f : A → B, defined by

Σf(S) = {f(x) | x in S}

for any subset S of A.

seth.core.powerset_formel(A: Representable) → NamedSet[source]

Powerset of a set A as a named set. Its elements are the subsets of A, represented as NamedSet objects. Constructs all the χ : A → Ω and take their fibers

seth.core.preim(f: NamedFunction, subset_index: int) → list[int][source]

Return the charmap of f⁻¹(S) from the subset code of S ⊆ cod(f).

If S_B is the rank-ordered charmap of S, the returned list is exactly [S_B[f._raw[i]] for i in range(len(f.dom))].

seth.core.product_maps(f: NamedFunction, g: NamedFunction) → NamedFunction[source]

Return the product of two functions f : A0 → B0 and g : A1 → B1, defined by

(f x g)(a0, a1) = (f(a0), g(a1))

seth.core.pullback_charmap(chi: NamedFunction) → Injection[source]

Given a characteristic function χ : A → Ω, return the corresponding subobject S → A as the pullback.

seth.core.right_distributivity_isomorphism(ext: Representable, paire: tuple[Representable, Representable]) → Bijection[source]

Return the distributivity isomorphism

d : (X + Y) x Z ≃ (X x Z) + (Y x Z)

defined by:

  • d((0, x), z) = (0, (x, z))

  • d((1, y), z) = (1, (y, z))

seth.core.singleton(a) → NamedSet[source]

Return the singleton set {a} as a NamedSet. a may be of any type: int, str, tuple, frozenset, etc. as long as it is hashable.

seth.core.subobject_to_index(inclusion: Injection) → int[source]

Encode the image of a subobject S ↪ A in range(2^|A|).

seth.core.subobject_to_subset_charmap(inclusion: Injection) → list[int][source]

Encode the image of a subobject S ↪ A as rank-ordered bits.

seth.core.subset_charmap(chi: NamedFunction) → NamedSet[source]

Compatibility alias for charmap_to_subset().

seth.core.subset_charmap_to_index(A: Representable, bits: Sequence[int | bool]) → int[source]

Encode rank-ordered subset bits as sum(bits[i] * 2**i).

seth.core.subset_charmap_to_subobject(A: Representable, bits: Sequence[int | bool]) → Injection[source]

Decode subset bits into the canonical inclusion S ↪ A.

seth.core.subset_charmap_to_subset(A: Representable, bits: Sequence[int | bool]) → FrozenSetAffiche[source]

Decode rank-ordered subset bits into a NamedSet.

seth.core.subset_to_index(A: Representable, subset: Representable) → int[source]

Encode a represented subset of A by its integer subset code.

seth.core.subset_to_subset_charmap(A: Representable, subset: Representable) → list[int][source]

Encode a represented subset of A as rank-ordered bits.

seth.core.terminal_detection(X: Representable) → bool[source]

Return True if X is a terminal object, i.e., if there is a unique function from any set to X.

seth.core.terminal_isomorphism(X: Representable) → Bijection[source]

Return the unique isomorphism from X ≃ 1 if X has exactly one element, otherwise raise an error.

seth.core.test_disjunction(A: Representable, inj0: Injection, inj1: Injection) → bool[source]

Test whether the subobjects represented by inj0 and inj1 are disjoint.

seth.core.union(X: Representable, Y: Representable) → NamedSet[source]

Return the union of two sets X and Y as a NamedSet, defined by

X ∪ Y = {x | x ∈ X or x ∈ Y}

seth.core.union_of_elements(X: Representable) → NamedSet[source]

Return the union of the elements of X as a NamedSet, defined by

⋃X = {x | ∃y ∈ X, x ∈ y}

seth.core.union_sets(index: Sequence[Representable]) → Representable | NamedSet[source]

The index is a set of subsets (NamedSet); return the union of these subsets as a NamedSet.

seth.core.union_subobjects(S0: Injection, S1: Injection) → Injection[source]

Given two subobjects S0 -> B and S1 -> B, return their union as a subobject of B.

seth.core.unitor_cartesian_left(X: Representable) → Bijection[source]

Return the left unitor isomorphism

λ : 1 x X ≃ X

defined by

λ(*, x) = x

seth.core.unitor_cartesian_right(X: Representable) → Bijection[source]

Return the right unitor isomorphism

ρ : X x 1 ≃ X

defined by

ρ(x, *) = x

seth.core.unitor_coproduct_left(X: Representable) → Bijection[source]

Return the left unitor isomorphism

λ : ∅ + X ≃ X

defined by

λ(1, x) = x

seth.core.unitor_coproduct_right(X: Representable) → Bijection[source]

Return the right unitor isomorphism

ρ : X + ∅ ≃ X

defined by

ρ(0, x) = x