Aronson Sequence Generator
A Python implementation of two classes representing self-referential sentences (AronsonSequence), and collections thereof (AronsonSet).
The prototype which inspired the AronsonSequence class is Aronson's sequence, first coined by J. K. Aronson, and quoted by D. R. Hofstadter in his book "Methamagical Themas" (1983). The AronsonSequence class takes this idea further by generalizing over all sentences of the form "Ω is the X, Y, Z... letter", where Ω $\in$ Σ is a letter in the alphabet and X, Y, Z are ordinals.
The AronsonSet class constitutes a collection over AronsonSequence instances, where these are constrainted to be semantically correct (meaning ordinals X, Y, Z map to occurrences of the letter Ω in the sentence representation) with respect to the same letter Ω and scanning direction (left-to-right or right-to-left).
See this blogpost for more details.
Features
AronsonSequence Class
Models self-referential sentences with:
- Positional reference tracking (forward/backward/self)
- Automatic sentence generation & validation
- Element manipulation (append/swap/clear)
- Direction flipping (forward ↔ backward)
- Comprehensive correctness checks
# Create and validate sequence
letter = 't'
aronson_initial = [1, 4, 11] # first three terms in Aronson's sequence
seq1 = AronsonSequence(letter, aronson_initial) # Forward
print(seq1) # "T is the first, fourth, eleventh letter in this sentence, not counting commas and spaces"
seq1.is_correct() # True
{seq1.get_ref(elem) for elem in aronson_initial} # {Refer.BACKWARD}
seq.is_prefix_complete() # True
seq.is_complete() # False
seq1.append_elements([16]) # Next element in Aronson
seq1.is_correct() # True
AronsonSet Class
Manages collections of valid sequences with:
- Multiple generation strategies (pruned brute-force/fast rule-based)
- Set operations (union/intersection/difference)
- Filter operations (by element/reference/symmetry)
# Generate and analyze sequences
aset1 = AronsonSet('t', Direction.BACKWARD) # Backward
empty_seq = aset1.peek()
print(empty_seq) # "T is the letter"
seq1 = aset1.generate_aronson(3).pop() # AronsonSequence('t', [3, 4, 11], Direction.BACKWARD)
aset1.is_correct(seq1) # True
aset2 = AronsonSet('t') # Forward
aset2.is_correct(seq1) # False, sequence is incorrect w.r.t. set direction
Advanced Usage
Hybrid Generation
aset = AronsonSet('t', Direction.BACKWARD)
aset.generate_full(2) # Exhaustively generate all correct AronsonSequences up to length 2
len(aset) # 67
aset_cpy = aset.copy()
aset.generate_fast(3, forward_generate=True) # Optimized continuation to sequences of length 3
len(aset) # 198
aset_cpy.generate_full(3, error_rate = 0.25) # Find at least 75% of all correct sequences
len(aset_cpy) # 843 (out of 955)
Set Operations
# Combine sequence sets
seq1 = AronsonSequence('t', [1, 4, 11])
seq2 = AronsonSequence('t', [10, 12])
set1 = AronsonSet.from_sequence(seq1)
set2 = AronsonSet.from_sequence(seq2)
# set operators |, &, -
union_set = set1 | set2
assert(union_set == AronsonSet.from_set({seq1, seq2})) # same as from_set() constructor
intersection_set = set1 & set2
assert(intersection_set == AronsonSet('t')) # intersection is empty forward set
difference_set = set1 - set2
assert(difference_set == set1) # sets are complementary
Filter Operations
# Extract AronsonSequence instances from an AronsonSet instance via filtering
aset = AronsonSet('t')
n_iters = 2
aset.generate_full(n_iters)
len(aset) # 73
filter1 = aset.filter_symmetric(n_iters) # get length-2 sequences for which all permutations also in set
filter2 = filter1.filter_elements(filter1.max) # get all such sequences containing maximum element
[seq for seq in filter2 if not seq.is_empty()]
# ["T is the thirty-second, thirty-third letter in this sentence, not counting commas and spaces",
# "T is the thirty-third, thirty-second letter in this sentence, not counting commas and spaces"]
Installation
git clone https://github.com/ikavodo/aron-gen.git
cd aron_gen
pip install -r requirements.txt # Requires num2words
Testing Framework
Comprehensive test suite covering:
- Sequence validation and reference resolution
- Set operation correctness
- Edge case handling
- Performance benchmarks
Run tests with:
python -m unittest test_AronsonSet.py test_AronsonSequence.py
For running an optional, slower test regarding performance benchmarks run
RUN_OPTIONAL_TEST=True python -m unittest test_AronsonSet.py test_AronsonSequence.py
Metadata
Release files for aron-gen 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aron_gen-0.1.7.tar.gz | 28.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aron_gen-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.0 kB
Release files / aron_gen-0.1.7.tar.gz
| Download URL | aron_gen-0.1.7.tar.gz |
|---|---|
| Size | 28.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c39eca8a031875006e5e31116e2c1601734540515d0ce8880fcb1c1ee3aecc12
|
|
BLAKE2b-256 checksum How to use checksums |
383747edbb7ed11c79d486fc64ca16ca43dd2dd41c4262056c068ccfae164f51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / aron_gen-0.1.7-py3-none-any.whl
| Download URL | aron_gen-0.1.7-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d499a95a097287b2785f176df9b62485f987e8925aa670db2a192ed2870e18d6
|
|
BLAKE2b-256 checksum How to use checksums |
9693fd8be285442a9ebf5a689c28929de31ea8a0310ffc733e5a4be97abbd50f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Security for aron-gen 0.1.7
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.