Skip to main content

pyrel

Pyrel is an efficient python library for working with and manipulating binary relations. Pyrel exposes the C library Kure which provides a very fast implementation of binary relations based on Binary Decision Diagrams.

The following operations of relation algebra are provided:

  • empty

  • universal

  • identity

  • meet (intersection)

  • join (union)

  • transpose (converse)

  • complement (negation)

  • compose (multiplication)

  • equals

  • isSuperset

  • isSubset

  • isStrictSuperset

  • isStrictSubset

Installation

using pip:

pip3 install pyrel

or downloading with git:

git clone https://github.com/Peter-Roger/pyrel.git
cd pyrel/
python3 setup.py build install

Requirements

Pyrel works on Ubuntu and macOS. It has not been tested on other systems but it is possible it could work, perhaps with some modification.

C Library Dependencies:

  • glib-2.0

  • gmp

If you are missing these libraries just install them with your package manager.

Pyrel includes a modified version of Kure and its dependency Cudd-2.5.1 (Colorado University Decision Diagram) as source. As long as the aforementioned dependencies are installed in standard locations on your system, Kure will be built automatically during installation.

Quick Start

The following provides some examples as a tutorial on how to use pyrel. For a complete description you should consult the documented module source code.

Relations are represented as boolean matrices and can be visualised by printing them. An ‘X’ at col x and row y denotes that x is related to y in the relation. Contrariwise a ‘.’ denotes that x is not related to y.

Creating relations

import pyrel

# create a pyrel context
context = pyrel.PyrelContext()

# create a new 3x3 empty relation
rel = context.new(3,3)
print(rel)
...
...
...

Setting bits

# a list of ordered pairs
bits = [(0,0),(0,1),(0,2)]
rel = context.new(3,3)
rel.set_bits(bits)
print(rel)

# set bits at random
rel.random()
print(rel)

# unsets all bits
rel.clear()
print(rel)
XXX
...
...

.X.
..X
X.X

...
...
...
# set bits at creation
bits = [(0,0),(0,1),(0,2)]
rel = context.new(3,3,bits)
print(rel)

# set single bit
rel.set_bit(2,2)
print(rel)

# unset bit
rel.set_bit(0,1,yesno=False)
print(rel)

# unset bits
rel.set_bits([(0,0),(2,2)],yesno=False)
print(rel)
XXX
...
...

XXX
...
..X

X.X
...
..X

..X
...
...

Operations

rel = context.new(3,3).identity()
print(rel)

r = context.new(3,3, [(0,0),(0,1),(0,2)])
print(r)

s = r.transpose()
print(s)

m = r1.meet(r2)
print(m)

j = r1.join(r2)
print(j)
X..
.X.
..X

XXX
...
...

X..
X..
X..

X..
...
...

XXX
X..
X..
r = context.new(3,3, [(0,1),(0,2),(2,1)])
print(r)

s = context.new(3,3, [(1,1),(2,2)])
print(s)

g = r.composition(s)
print(g)

g.isSubset(g.universal())
.XX
...
.X.

...
.X.
..X

.XX
...
.X.

>>> True

Vectors

A vector is a row constant relation. All columns are identical. It represents a subset.

rel = new(5,5)
rel.vector(2) # row 2 (0-indexed)
print(rel)
rel.vector_next()
print(rel)
.....
.....
XXXXX
.....
.....

.....
.....
.....
XXXXX
.....

Possible Future Work

  • import relations from a file

  • export relations to a file

  • extend support for more relation operations

Metadata

Release files for pyrel 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyrel 0.2.0
File Size Uploaded Provenance
pyrel-0.2.0.tar.gz 2.9 MB Without provenance Details

Release files / pyrel-0.2.0.tar.gz

Download URL pyrel-0.2.0.tar.gz
Size 2.9 MB
Tags Source
SHA-256 checksum
How to use checksums
0619806cfdaa5dec6de36dfd21ba6aeecd95ed07616449da1a70b8c7798dc3f3
BLAKE2b-256 checksum
How to use checksums
d4a16ad8134086b376c40ea3ec590cfdda2754bfa73a0d706c7e569251719505
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Security for pyrel 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page