Symbols
opulse.generation.symbols ¶
Generated operator names and arities.
Shape and index names use neutral glyphs and serial indices. Legacy random
symbols keep the whole symbol set prefix-free (no symbol is a prefix of
another), so any run of adjacent legacy symbols splits in exactly one way.
:func:uniquely_decodable checks the general property.
The legacy alphabet is the union of named character sets (symbol_sets, see
:data:NAMED_SETS: readable symbols that common fonts draw), characters listed
directly (symbol_chars), and, for advanced use, raw Unicode ranges
(symbol_blocks, hex start-end). With
exclude_confusable (default) characters whose Unicode name marks them as
look-alikes are removed: minus/division/asterisk/set-minus signs (they read as
- / * \), anything named EQUAL/LESS-THAN/GREATER-THAN/EQUIVALENT
(they read as comparisons inside if conditions), bars and dots.
ShapeIndexFactory ¶
Names made from a drawn shape and a serial index, independent of the draft.
SymbolFactory ¶
new_symbol ¶
new_symbol(
taken: set[str] | None = None, max_attempts: int = 10000
) -> str
A symbol that keeps taken (default: the symbols :meth:reserve recorded) prefix-free.
The length is drawn in proportion to the number of strings of that length, so a set
can grow close to the capacity k ** max_len; short symbols, which block every
longer symbol they start, stay rare. Checking a candidate costs O(max_len).
reserve ¶
reserve(symbols) -> None
Record symbols in use (the registry's, then each accepted operator's).
capacity ¶
capacity() -> int
Upper bound on the size of a prefix-free set over this alphabet: k ** max_len.
new_shape ¶
new_shape() -> tuple[int, str | None]
(n_ary, unary_position) drawn by operators.arity_weights; a unary operator is
prefix or postfix with equal chance. The default weights draw exactly as earlier
releases: binary with probability 1/2, else prefix or postfix.
draw_shape ¶
draw_shape(
weights: dict[int, float], rng
) -> tuple[int, str | None]
Draw (n_ary, unary_position) by operators.arity_weights. The default weights draw
binary with probability 1/2, else prefix or postfix, as earlier releases did.
uniquely_decodable ¶
uniquely_decodable(symbols: set[str]) -> bool
Sardinas-Patterson test: every concatenation of symbols splits in one way.