Skip to main content

An Rust-backed implementation of the Xenakis Sieve

Project description

xensieve-py

An implementation of the Xenakis Sieve, providing a Sieve from a string expression that filters integer sequences into iterators of integers, Boolean states, or interval widths. Sieves are built from Residuals, defined as a modulus (M) and a shift (S), notated M@S. Sieve string expressions, and Sieve structs, support complementation, intersection, symmetric difference, and union operations on Residuals with operators !, &, ^ and |, respectively.

The Xenakis Sieve is a tool for generating discrete interval patterns. Such patterns have boundless applications in creative domains: the Xenakis Sieve can be used to generate scales or multi-octave pitch sequences, rhythms and polyrhythms, and used to control countless other aspects of pictorial or architectural design.

This Python implementation wraps a Rust implementation and follows the Python implementation in Ariza (2005), with significant performance and interface enhancements: https://direct.mit.edu/comj/article/29/2/40/93957

Code: https://github.com/flexatone/xensieve-py

Rust Implementation

The Python implementation is built with PyO3, which wraps the Rust core library xensieve.

Code: https://github.com/flexatone/xensieve-rs

Docs: https://docs.rs/xensieve

Crate: https://crates.io/crates/xensieve

Strategies for Creating Sieves

First, we can examine the output of Sieves built from a single Residual. As shown above, a Residual is defined as a modulus (M) and a shift (S), notated M@S. In the diagram below, three Residuals are shown: 5@0, 4@2, and 30@10. As can be seen, for every M units, a value is articulated at the shift S. The final example shows an application of the unary inversion operator !30@10.

Residual diagram

Complex Sieves combine Residuals with logical operators such as complementation, intersection, symmetric difference, and union. In the example below, Residuals 5@0 and 4@2 are combined by union with the expression 5@0|4@2. Combining many Residuals by union is a practical approach to building sequences. The final example, (5@0|4@2)&!30@10, shows "removing" selected values from these unioned components by intersecting them with an inverted Residual (!30@10)

Sieve diagram

While all Sieves are, by definition, periodic, combinations of Residuals can result in sequences with great local complexity and inner patterning.

The xensieve.Sieve Inteface

The Sieves shown above can be created with xensieve.Sieve and used to produce iterators of integers, Boolean states, or interval widths. The Sieve constructor accepts arbitrarily complex Sieve expressions.

>>> from xensieve import Sieve

>>> s1 = Sieve("5@0")
>>> s2 = Sieve("30@10")
>>> s3 = Sieve("(5@0|4@2)&!30@10")

The iter_value() method takes a range (defined by start and stop integers) that can be used to "drive" the Sieve. The iterator yields the subset of integers contained within the Sieve.

>>> s1.iter_value(0, 50)
<builtins.IterValue object at 0x7f538abdb9c0>
>>> list(s1.iter_value(0, 50))
[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]
>>> list(s2.iter_value(0, 50))
[10, 40]
>>> list(s3.iter_value(0, 50))
[0, 2, 5, 6, 14, 15, 18, 20, 22, 25, 26, 30, 34, 35, 38, 42, 45, 46]

The xensieve.Sieve features two alternative iterators to permit using Sieves in different contexts. The iter_state() iterator returns, for each provided integer, the resulting Boolean state.

>>> list(s1.iter_state(0, 10))
[True, False, False, False, False, True, False, False, False, False]
>>> list(s3.iter_state(0, 10))
[True, False, True, False, False, True, True, False, False, False]

The iter_interval() iterator returns, for sequential pairs of provided integers that are within the Sieve, the resulting interval.

>>> list(s2.iter_interval(0, 50))
[30]
>>> list(s3.iter_interval(0, 50))
[2, 3, 1, 8, 1, 3, 2, 2, 3, 1, 4, 4, 1, 3, 4, 3, 1]

The xensieve.Sieve instance implements __contains__() such that in can be used to test if arbitrary integers are contained within the Sieve:

>>> 5 in s1
True
>>> 6 in s1
False
>>> 10 in s3
False
>>> 30 in s3
True

The xensieve.Sieve instance supports the same operators permitted in Sieve expressions, such that instances can be combined to build complex Sieves.

>>> s4 = (Sieve("5@0") | Sieve("4@2")) & ~Sieve("30@10")
>>> s4
Sieve{5@0|4@2&!(30@10)}
>>> list(s4.iter_value(0, 100)) == list(s3.iter_value(0, 100))
True

What is New in xensieve

0.8.0

Updated Rust back-end to 0.8.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xensieve-0.8.0.tar.gz (9.6 kB view hashes)

Uploaded Source

Built Distributions

xensieve-0.8.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

xensieve-0.8.0-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

xensieve-0.8.0-pp310-pypy310_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

xensieve-0.8.0-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

xensieve-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

xensieve-0.8.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

xensieve-0.8.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

xensieve-0.8.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

xensieve-0.8.0-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

xensieve-0.8.0-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

xensieve-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

xensieve-0.8.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

xensieve-0.8.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

xensieve-0.8.0-pp38-pypy38_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

xensieve-0.8.0-pp38-pypy38_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

xensieve-0.8.0-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

xensieve-0.8.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

xensieve-0.8.0-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

xensieve-0.8.0-cp312-none-win_amd64.whl (146.0 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

xensieve-0.8.0-cp312-none-win32.whl (142.4 kB view hashes)

Uploaded CPython 3.12 Windows x86

xensieve-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

xensieve-0.8.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

xensieve-0.8.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

xensieve-0.8.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.0 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

xensieve-0.8.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

xensieve-0.8.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.5+ i686

xensieve-0.8.0-cp312-cp312-macosx_11_0_arm64.whl (259.6 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

xensieve-0.8.0-cp312-cp312-macosx_10_12_x86_64.whl (262.3 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

xensieve-0.8.0-cp311-none-win_amd64.whl (145.8 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

xensieve-0.8.0-cp311-none-win32.whl (141.9 kB view hashes)

Uploaded CPython 3.11 Windows x86

xensieve-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

xensieve-0.8.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

xensieve-0.8.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

xensieve-0.8.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.0 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

xensieve-0.8.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

xensieve-0.8.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.5+ i686

xensieve-0.8.0-cp311-cp311-macosx_11_0_arm64.whl (260.2 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

xensieve-0.8.0-cp311-cp311-macosx_10_12_x86_64.whl (262.8 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

xensieve-0.8.0-cp310-none-win_amd64.whl (145.8 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

xensieve-0.8.0-cp310-none-win32.whl (141.9 kB view hashes)

Uploaded CPython 3.10 Windows x86

xensieve-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

xensieve-0.8.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

xensieve-0.8.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

xensieve-0.8.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

xensieve-0.8.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

xensieve-0.8.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

xensieve-0.8.0-cp310-cp310-macosx_11_0_arm64.whl (260.1 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

xensieve-0.8.0-cp310-cp310-macosx_10_12_x86_64.whl (262.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

xensieve-0.8.0-cp39-none-win_amd64.whl (145.7 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

xensieve-0.8.0-cp39-none-win32.whl (142.0 kB view hashes)

Uploaded CPython 3.9 Windows x86

xensieve-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

xensieve-0.8.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

xensieve-0.8.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

xensieve-0.8.0-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

xensieve-0.8.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

xensieve-0.8.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

xensieve-0.8.0-cp38-none-win_amd64.whl (145.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

xensieve-0.8.0-cp38-none-win32.whl (142.7 kB view hashes)

Uploaded CPython 3.8 Windows x86

xensieve-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

xensieve-0.8.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

xensieve-0.8.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

xensieve-0.8.0-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

xensieve-0.8.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

xensieve-0.8.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page