Python library to handle integer partitions and compute partitional analysis metrics.
Project description
Partitionπ
Partitionπ is a Python library to handle integer partitions as lists and compute partitional analysis metrics.
Instalation
pip install partitionpi
Get started
We are dealing with integer partitions as lists, for example:
import partitionpi as pp
p = [1,1,1,2,3]
Computing main metrics
We provide methods to compute the main metrics related to partitional_analysis, such as the indices of agglomeration and dispersion, number of children obtained by the operations of mute and join, translation between the list form and the exponential form (via tuple or latex string)... Examples of usage of such functions:
# Compute the dispertion and agglomeration of p, that can be used for plotting.
x = pp.disp(p)
y = pp.agg(p)
# Compute the number of children by each operation.
nr_of_muted_children = pp.n_muted(p)
nr_of_joint_children = pp.n_joint(p)
# Translate p to both exponential and tex string form.
exp = pp.exponential_form(p)
tex = pp.as_tex_str(p)
Operations
Also, our library furnishes operations between partitions, such as union, intersection, concatenation/sum, difference and the operators mute and join. Union, intersection, sum and difference are computed like the multiset operators.
p1 = [1,1,2]
p2 = [1,2,3]
# p1 + p2 = [1,1,1,2,2,3]
p_sum = pp.concat(p1, p2)
# p1 - p2 = [1]
p_diff = pp.diff(p1, p2)
# p1 intersection p2 = [1,2]
p_inter = pp.intersection(p1, p2)
# p1 union p2 = [1,1,2,3]
p_union = pp.union(p1, p2)
# join(p1, 1, 1) = [2,2,3]
p_join = pp.join(p1, 1, 1)
# mute(p1, 3) = [1,1,2]
p_mute = pp.mute(p1, 3)
Methods
Partitionπ gives some methods to enumerate objects, such as:
- All partitions with a limited density-number.
- All ancestors or children of a given partition.
- The partitional complex of a given partition.
Also, we furnish methods to compute the common parents of two partitions and the list of possible referential partitions of a set of partitions.
# Compute the ancestors with density number at most 7
ancestors = pp.all_ancestors(p, max_dn=7)
# Parents of p by each operation
mparents = pp.muted_parents(p, max_dn=7)
jparents = pp.joint_parents(p)
# Partitions with dn = 7 and with dn <= 7
p_eq_7 = partitions_of(7)
p_leq_7 = partitions_at_most(7)
# Partitional complex of p
comp = pp.partitional_complex(p)
# Common parents of p1 and p2
parents = pp.common_parents(p1, p2)
# List of possible referential partitions of [p, p1, p2]
ref = pp.referential_partition([p, p1, p2])
Graph and Diagram
Finally, we furnish tools for generating a networkx graph of the partitional complex with labelled nodes and edges, and to plot its diagram. In the graph, each node has an attribute pos, which gives the pair (agg, disp) of each partition, and an attribute label, with the tex-style form of the partition. Each edge has the attribute kinship, that tells if it represents a mute (M) or a join (J) relation.
# A nx.Graph modelling the partitional complex of g.
g = graph_complex(p)
# Plot diagram (can be called with the graph g or the partition p).
# Mute edges will be painted red and Join edges will be painted black.
draw_complex(g, {'M' : 'red', 'J' : 'black'})
Diagram for p:
Diagram for p2:
References
If you want to know more about Partitional Analysis, we refer to Pauxy Gentil-Nunes webpage and github page, where you can find publications, books and software about it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for partitionpi-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0e19e2d2b6f1bddb22e694b79baa3cbd990a0a8fe707ee3d515c5326c3ad468 |
|
MD5 | 855579acbab89032016f375131999a22 |
|
BLAKE2b-256 | a66e45a162f75b6545803d348106daee008dae9b8185e54fee0a09e1c717b02c |