Skip to main content

Generates and verifies Aronson sequences

Project description

Aronson Sequence Generator

Tests

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

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

aron_gen-0.1.7.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aron_gen-0.1.7-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file aron_gen-0.1.7.tar.gz.

File metadata

  • Download URL: aron_gen-0.1.7.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for aron_gen-0.1.7.tar.gz
Algorithm Hash digest
SHA256 c39eca8a031875006e5e31116e2c1601734540515d0ce8880fcb1c1ee3aecc12
MD5 6ffe9bc61191f8516fe9e1a58c04916f
BLAKE2b-256 383747edbb7ed11c79d486fc64ca16ca43dd2dd41c4262056c068ccfae164f51

See more details on using hashes here.

File details

Details for the file aron_gen-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: aron_gen-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for aron_gen-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d499a95a097287b2785f176df9b62485f987e8925aa670db2a192ed2870e18d6
MD5 8e0d3bd3c904404263339ad71da96584
BLAKE2b-256 9693fd8be285442a9ebf5a689c28929de31ea8a0310ffc733e5a4be97abbd50f

See more details on using hashes here.

Supported by

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