nmr 0.11.0__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nmr-1.1.0/.github/workflows/check.yml +66 -0
- nmr-1.1.0/PKG-INFO +546 -0
- nmr-1.1.0/README.md +524 -0
- nmr-1.1.0/nmr/__init__.py +1 -0
- nmr-1.1.0/nmr/__main__.py +4 -0
- nmr-1.1.0/nmr/_main.py +122 -0
- nmr-1.1.0/nmr/browser_build.py +60 -0
- nmr-1.1.0/nmr/category.py +93 -0
- nmr-1.1.0/nmr/nmr.py +150 -0
- nmr-1.1.0/nmr/pack_numbers.py +75 -0
- nmr-1.1.0/nmr/recognition.py +100 -0
- nmr-1.1.0/nmr/registry.py +41 -0
- nmr-1.1.0/nmr/type_name.py +19 -0
- nmr-1.1.0/nmr/types/__init__.py +1 -0
- nmr-1.1.0/nmr/types/bounded.py +38 -0
- nmr-1.1.0/nmr/types/cards.py +139 -0
- nmr-1.1.0/nmr/types/chess.py +73 -0
- nmr-1.1.0/nmr/types/chord.py +138 -0
- nmr-1.1.0/nmr/types/color.py +29 -0
- nmr-1.1.0/nmr/types/fraction.py +40 -0
- nmr-1.1.0/nmr/types/go.py +152 -0
- nmr-1.1.0/nmr/types/identifiers.py +69 -0
- nmr-1.1.0/nmr/types/integer.py +40 -0
- nmr-1.1.0/nmr/types/ip_address.py +43 -0
- nmr-1.1.0/nmr/types/lat_long.py +77 -0
- nmr-1.1.0/nmr/types/phone_number.py +45 -0
- nmr-1.1.0/nmr/types/sem_ver.py +52 -0
- nmr-1.1.0/nmr/types/string.py +98 -0
- nmr-1.1.0/nmr/types/temporal.py +94 -0
- nmr-1.1.0/nmr/types/tune.py +438 -0
- nmr-1.1.0/nmr/types/tune_count.py +164 -0
- nmr-1.1.0/nmr/types/uuid.py +17 -0
- nmr-1.1.0/nmr/web/.htaccess +13 -0
- nmr-1.1.0/nmr/web/academico-OFL.txt +93 -0
- nmr-1.1.0/nmr/web/app.js +417 -0
- nmr-1.1.0/nmr/web/bravura-OFL.txt +93 -0
- nmr-1.1.0/nmr/web/bridge.py +297 -0
- nmr-1.1.0/nmr/web/clock-time.mjs +25 -0
- nmr-1.1.0/nmr/web/count-runner.mjs +62 -0
- nmr-1.1.0/nmr/web/description.mjs +4 -0
- nmr-1.1.0/nmr/web/editor.mjs +47 -0
- nmr-1.1.0/nmr/web/help.js +57 -0
- nmr-1.1.0/nmr/web/help.md +60 -0
- nmr-1.1.0/nmr/web/index.html +120 -0
- nmr-1.1.0/nmr/web/music-notation.mjs +101 -0
- nmr-1.1.0/nmr/web/music_notation.py +114 -0
- nmr-1.1.0/nmr/web/presentation.mjs +8 -0
- nmr-1.1.0/nmr/web/runtime.js +29 -0
- nmr-1.1.0/nmr/web/style.css +165 -0
- nmr-1.1.0/nmr/web/truename-editor.mjs +108 -0
- nmr-1.1.0/nmr/web/tune.js +193 -0
- nmr-1.1.0/nmr/web/value-display.mjs +198 -0
- nmr-1.1.0/nmr/web/value_display.py +97 -0
- nmr-1.1.0/nmr/web/vexflow-LICENSE.txt +22 -0
- nmr-1.1.0/nmr/web/vexflow-NOTICE.txt +6 -0
- nmr-1.1.0/nmr/web/vexflow.js +6 -0
- nmr-1.1.0/nmr/web/volume.js +13 -0
- nmr-1.1.0/nmr/web/worker.js +28 -0
- nmr-1.1.0/nmr/web/world-map.svg +2 -0
- nmr-1.1.0/nmr/words.py +137 -0
- {nmr-0.11.0 → nmr-1.1.0/nmr}/words.txt +1126 -1213
- nmr-1.1.0/plan/nmr.md +833 -0
- {nmr-0.11.0 → nmr-1.1.0}/pyproject.toml +38 -23
- nmr-1.1.0/scripts/remove_homophones.py +33 -0
- nmr-1.1.0/test/browser_smoke.cjs +83 -0
- nmr-1.1.0/test/clock-time.test.mjs +74 -0
- nmr-1.1.0/test/count-runner.test.mjs +143 -0
- nmr-1.1.0/test/description.test.mjs +16 -0
- nmr-1.1.0/test/editor.test.mjs +128 -0
- nmr-1.1.0/test/format.json +299 -0
- nmr-1.1.0/test/help.test.mjs +63 -0
- nmr-1.1.0/test/integration.test.mjs +402 -0
- nmr-1.1.0/test/music-notation.test.mjs +106 -0
- nmr-1.1.0/test/presentation.test.mjs +26 -0
- nmr-1.1.0/test/runtime.test.mjs +44 -0
- nmr-1.1.0/test/runtime_smoke.cjs +194 -0
- nmr-1.1.0/test/test_browser_build.py +94 -0
- nmr-1.1.0/test/test_cards.py +133 -0
- nmr-1.1.0/test/test_category.py +136 -0
- nmr-1.1.0/test/test_chess.py +42 -0
- nmr-1.1.0/test/test_chord.py +73 -0
- nmr-1.1.0/test/test_codecs.py +179 -0
- nmr-1.1.0/test/test_color.py +51 -0
- nmr-1.1.0/test/test_count.py +175 -0
- nmr-1.1.0/test/test_format.py +64 -0
- nmr-1.1.0/test/test_go.py +92 -0
- nmr-1.1.0/test/test_homophones.py +10 -0
- nmr-1.1.0/test/test_huge.py +22 -0
- nmr-1.1.0/test/test_ip_address.py +56 -0
- nmr-1.1.0/test/test_lat_long.py +123 -0
- nmr-1.1.0/test/test_main.py +123 -0
- nmr-1.1.0/test/test_music_notation.py +100 -0
- nmr-1.1.0/test/test_nmr.py +162 -0
- nmr-1.1.0/test/test_pack_numbers.py +98 -0
- nmr-1.1.0/test/test_phone.py +57 -0
- nmr-1.1.0/test/test_recognition.py +309 -0
- nmr-1.1.0/test/test_sample_config.py +17 -0
- nmr-1.1.0/test/test_sign.py +14 -0
- nmr-1.1.0/test/test_string.py +138 -0
- nmr-1.1.0/test/test_temporal.py +147 -0
- nmr-1.1.0/test/test_tune.py +278 -0
- nmr-1.1.0/test/test_tune_count.py +103 -0
- nmr-1.1.0/test/test_tune_projection.py +86 -0
- nmr-1.1.0/test/test_types.py +32 -0
- nmr-1.1.0/test/test_value_display.py +121 -0
- nmr-1.1.0/test/test_words.py +91 -0
- nmr-1.1.0/test/truename-editor.test.mjs +201 -0
- nmr-1.1.0/test/tune-audio.cjs +154 -0
- nmr-1.1.0/test/tune-player.test.mjs +151 -0
- nmr-1.1.0/test/value-display.test.mjs +134 -0
- nmr-1.1.0/uv.lock +755 -0
- nmr-0.11.0/.travis.yml +0 -24
- nmr-0.11.0/CHANGELIST +0 -0
- nmr-0.11.0/FUNDING.yml +0 -1
- nmr-0.11.0/PKG-INFO +0 -148
- nmr-0.11.0/README.md +0 -127
- nmr-0.11.0/TAGS +0 -30280
- nmr-0.11.0/google-10000-english.txt +0 -9669
- nmr-0.11.0/nmr/__init__.py +0 -35
- nmr-0.11.0/nmr/__main__.py +0 -90
- nmr-0.11.0/nmr/_main.py +0 -94
- nmr-0.11.0/nmr/category.py +0 -104
- nmr-0.11.0/nmr/nmr.py +0 -27
- nmr-0.11.0/nmr/pack_numbers.py +0 -206
- nmr-0.11.0/nmr/radixes.py +0 -19
- nmr-0.11.0/nmr/type_namer.py +0 -69
- nmr-0.11.0/nmr/types/__init__.py +0 -37
- nmr-0.11.0/nmr/types/chess.py +0 -89
- nmr-0.11.0/nmr/types/fraction.py +0 -40
- nmr-0.11.0/nmr/types/integer.py +0 -17
- nmr-0.11.0/nmr/types/ip_address.py +0 -14
- nmr-0.11.0/nmr/types/lat_long.py +0 -50
- nmr-0.11.0/nmr/types/phone_number.py +0 -48
- nmr-0.11.0/nmr/types/sem_ver.py +0 -29
- nmr-0.11.0/nmr/types/time/constants.py +0 -87
- nmr-0.11.0/nmr/types/time/formats.py +0 -60
- nmr-0.11.0/nmr/types/time/time.py +0 -123
- nmr-0.11.0/nmr/types/uuid.py +0 -23
- nmr-0.11.0/nmr/words.py +0 -138
- nmr-0.11.0/poetry.lock +0 -7
- nmr-0.11.0/reflog.txt +0 -1000
- nmr-0.11.0/scripts/nmbr +0 -7
- nmr-0.11.0/scripts/remove_homophones.py +0 -34
- nmr-0.11.0/test/test_category.py +0 -45
- nmr-0.11.0/test/test_chess.py +0 -57
- nmr-0.11.0/test/test_huge.py +0 -84
- nmr-0.11.0/test/test_main.py +0 -51
- nmr-0.11.0/test/test_nmr.py +0 -57
- nmr-0.11.0/test/test_pack_numbers.py +0 -24
- nmr-0.11.0/test/test_radixes.py +0 -13
- nmr-0.11.0/test/test_sign.py +0 -22
- nmr-0.11.0/test/test_time_format.py +0 -9
- nmr-0.11.0/test/test_types.py +0 -60
- nmr-0.11.0/test/test_words.py +0 -53
- nmr-0.11.0/tox.ini +0 -10
- nmr-0.11.0/uv.lock +0 -300
- {nmr-0.11.0 → nmr-1.1.0}/.gitignore +0 -0
- {nmr-0.11.0 → nmr-1.1.0}/.python-version +0 -0
- {nmr-0.11.0 → nmr-1.1.0}/LICENSE +0 -0
- {nmr-0.11.0 → nmr-1.1.0}/nmr/count_words.py +0 -0
- {nmr-0.11.0/nmr/types/time → nmr-1.1.0/nmr/web}/__init__.py +0 -0
- {nmr-0.11.0 → nmr-1.1.0}/scripts/homophones.txt +0 -0
- {nmr-0.11.0 → nmr-1.1.0}/test/__init__.py +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
name: Check nmr
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
pull_request:
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
permissions:
|
|
7
|
+
contents: read
|
|
8
|
+
jobs:
|
|
9
|
+
python:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python: ["3.10", "3.13", "3.15"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v7.0.1
|
|
16
|
+
- uses: astral-sh/setup-uv@v10.3.0
|
|
17
|
+
with:
|
|
18
|
+
version: "0.13.1"
|
|
19
|
+
python-version: ${{ matrix.python }}
|
|
20
|
+
- run: uv sync --frozen
|
|
21
|
+
- run: uv run --frozen ruff check --select B,E,F,I nmr test scripts
|
|
22
|
+
- run: uv run --frozen ruff format --check nmr test scripts
|
|
23
|
+
- run: uv run --frozen ty check nmr
|
|
24
|
+
- run: uv run --frozen coverage run -m pytest -q
|
|
25
|
+
- run: uv run --frozen coverage report
|
|
26
|
+
- run: uv build
|
|
27
|
+
- run: uv run --frozen nmr --operation build-web
|
|
28
|
+
- name: Verify installed wheel outside the checkout
|
|
29
|
+
run: |
|
|
30
|
+
uv venv /tmp/nmr-installed
|
|
31
|
+
uv pip install --python /tmp/nmr-installed/bin/python dist/*.whl
|
|
32
|
+
cd /tmp
|
|
33
|
+
/tmp/nmr-installed/bin/nmr --operation decode --value 'pure:math:frac:now'
|
|
34
|
+
browser-runtime:
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v7.0.1
|
|
38
|
+
- uses: astral-sh/setup-uv@v10.3.0
|
|
39
|
+
with:
|
|
40
|
+
version: "0.13.1"
|
|
41
|
+
python-version: "3.13"
|
|
42
|
+
- run: uv sync --frozen
|
|
43
|
+
- run: node --test test/*.test.mjs
|
|
44
|
+
- run: uv run --frozen nmr --operation build-web
|
|
45
|
+
- run: npm install --prefix /tmp/nmr-js --no-audit --no-fund pyodide@0.29.3
|
|
46
|
+
- run: NODE_PATH=/tmp/nmr-js/node_modules node test/runtime_smoke.cjs
|
|
47
|
+
browser-ui:
|
|
48
|
+
if: github.event_name == 'workflow_dispatch'
|
|
49
|
+
runs-on: ubuntu-latest
|
|
50
|
+
steps:
|
|
51
|
+
- uses: actions/checkout@v7.0.1
|
|
52
|
+
- uses: astral-sh/setup-uv@v10.3.0
|
|
53
|
+
with:
|
|
54
|
+
version: "0.13.1"
|
|
55
|
+
python-version: "3.13"
|
|
56
|
+
- run: uv sync --frozen
|
|
57
|
+
- run: uv run --frozen nmr --operation build-web
|
|
58
|
+
- run: npm install --prefix /tmp/nmr-js --no-audit --no-fund playwright@1.64.1
|
|
59
|
+
- run: /tmp/nmr-js/node_modules/.bin/playwright install --with-deps chromium
|
|
60
|
+
- name: Browser interactions and local-only conversions
|
|
61
|
+
run: |
|
|
62
|
+
uv run --frozen python -m http.server 8765 --bind 127.0.0.1 --directory dist/web >/tmp/nmr-http.log 2>&1 &
|
|
63
|
+
server_pid=$!
|
|
64
|
+
trap 'kill "$server_pid"' EXIT
|
|
65
|
+
curl --retry-connrefused --retry 10 --retry-delay 1 -fsS http://127.0.0.1:8765/ >/dev/null
|
|
66
|
+
NODE_PATH=/tmp/nmr-js/node_modules NMR_BROWSER_CHANNEL=chromium node test/browser_smoke.cjs
|
nmr-1.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: nmr
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: 🌐 Name all canonical things 🌐
|
|
5
|
+
Author-email: Tom Ritchford <tom@swirly.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: chess<2,>=1.9.3
|
|
17
|
+
Requires-Dist: phonenumberslite<10,>=9
|
|
18
|
+
Requires-Dist: pydantic<3,>=2.10
|
|
19
|
+
Requires-Dist: semver<4,>=3.0.2
|
|
20
|
+
Requires-Dist: tyro<2,>=1.0
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# nmr
|
|
24
|
+
|
|
25
|
+
Find reversible truenames made from ordinary words for a birthday,
|
|
26
|
+
short tune, phone number, coordinate, fraction, identifier, or legal chess game,
|
|
27
|
+
then let a friend recover it with the same vocabulary and format settings.
|
|
28
|
+
|
|
29
|
+
A truename contains a readable type prefix and a payload without repeated words:
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
date:or each
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
That truename means `2000-02-29`. Canonical decoding is the default. Browsing is an
|
|
36
|
+
explicit operation for discovering objects from other word combinations.
|
|
37
|
+
|
|
38
|
+
## Install and try
|
|
39
|
+
|
|
40
|
+
Requires Python 3.10 or newer and [uv](https://docs.astral.sh/uv/).
|
|
41
|
+
This checkout contains the new 1.0 format; it has not been published to PyPI.
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
git clone git@github.com:rec/nmr.git
|
|
45
|
+
cd nmr
|
|
46
|
+
uv sync --frozen
|
|
47
|
+
uv run --frozen nmr --operation encode --type date --value 2000-02-29
|
|
48
|
+
uv run --frozen nmr --value 'date:or each'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
To install the CLI outside the checkout, run `uv tool install .`.
|
|
52
|
+
Use `nmr --help` for the complete options and `nmr --list-types` for type names.
|
|
53
|
+
Frozen development commands use the checked-in package versions independently of
|
|
54
|
+
machine-local resolution settings. Regenerate the lock deliberately when changing
|
|
55
|
+
dependencies.
|
|
56
|
+
|
|
57
|
+
## Encode, decode, and browse
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
# Preserve the actual fraction pair, including zero denominators.
|
|
61
|
+
nmr --operation encode --type frac --value '2/4'
|
|
62
|
+
# frac:his
|
|
63
|
+
nmr --value 'frac:his'
|
|
64
|
+
# 2/4
|
|
65
|
+
|
|
66
|
+
# The scope controls how much type information stays in the word payload.
|
|
67
|
+
nmr --operation encode --type chess --value 'e4 e5 Nf3'
|
|
68
|
+
# chess:in get
|
|
69
|
+
nmr --operation encode --type chess --value 'e4 e5 Nf3' --scope play
|
|
70
|
+
# play:year globe
|
|
71
|
+
nmr --operation encode --type chess --value 'e4 e5 Nf3' --scope ''
|
|
72
|
+
# nude beam
|
|
73
|
+
|
|
74
|
+
# Explore a noncanonical truename. The stable truename is printed to stderr.
|
|
75
|
+
nmr --operation browse --value 'pure:to'
|
|
76
|
+
# 0
|
|
77
|
+
# Canonical truename: pure:the
|
|
78
|
+
|
|
79
|
+
# One value per line; errors go to stderr and produce exit status 1.
|
|
80
|
+
printf '2000-02-29\n2024-12-31\n' | nmr --operation encode --type date
|
|
81
|
+
|
|
82
|
+
# JSON includes the canonical value, vocabulary ID, and date-centering setting.
|
|
83
|
+
nmr --operation encode --type phone --value '+442079460958' --json-output
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Without `--value`, the CLI reads stdin, or prompts when used in a terminal.
|
|
87
|
+
`--value` preserves its entire argument, including whitespace, `#`, and newlines.
|
|
88
|
+
There is no implicit type guessing or country inference.
|
|
89
|
+
|
|
90
|
+
The convenience marker `name:` explicitly identifies a truename. It adds no
|
|
91
|
+
category or radix step: `name:the of` and `the of` have the same index, as do
|
|
92
|
+
`name:tune:the` and `tune:the`. Matching the marker ignores case. Use `--scope name`
|
|
93
|
+
to encode a full root truename with the marker. In the browser, All types
|
|
94
|
+
uses the root scope and a selected type uses its type prefix.
|
|
95
|
+
|
|
96
|
+
Category and type names are unique except for the `time` category and Time type.
|
|
97
|
+
Bare `time:` selects the type; `real:time:` selects the category containing Date,
|
|
98
|
+
Time, and DateTime. DateTime combines calendar days and whole seconds before
|
|
99
|
+
centering the result on zoot, without a timezone in its input text.
|
|
100
|
+
It accepts `YYYY-MM-DDTHH:MM[:SS]` (or a space in place of `T`)
|
|
101
|
+
and prints the canonical form with `T`. Outputs use a single `time:` for the type and keep `real:time:`
|
|
102
|
+
when that category scope is needed. Parent categories
|
|
103
|
+
are optional in input: `chess:in get`, `game:chess:in get`, and
|
|
104
|
+
`:play:game:chess:in get` all read identically and print as `chess:in get`.
|
|
105
|
+
Category scopes behave the same way: `play:game:your tax` prints as
|
|
106
|
+
`game:your tax`, with the same payload. Results also use
|
|
107
|
+
short type labels. Internal tree paths still determine routing; shortening a
|
|
108
|
+
prefix never changes its scope or the encoded number.
|
|
109
|
+
|
|
110
|
+
Canonical decoding rejects unassigned type slots, invalid values, and
|
|
111
|
+
noncanonical encodings. It never silently switches to browsing. Browsing may
|
|
112
|
+
redirect those indices, returns a real supported object, and supplies its
|
|
113
|
+
canonical truename. Exploratory inputs can discover different objects as the tree
|
|
114
|
+
expands; save the canonical output instead.
|
|
115
|
+
|
|
116
|
+
## Supported details
|
|
117
|
+
|
|
118
|
+
See [type identity examples](doc/type-identity.md) for inputs that share a
|
|
119
|
+
name, distinctions that survive decoding, and the limits of coverage.
|
|
120
|
+
|
|
121
|
+
| Type or path | Input and identity |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| `int` | Signed decimal integer, including very large integers within vocabulary capacity. |
|
|
124
|
+
| `frac` | Signed numerator/denominator pair; `1/2`, `2/4`, `0/2`, `0/0`, and `1/0` are distinct objects. |
|
|
125
|
+
| `date` | Gregorian `YYYY-MM-DD`, years 0001 through 9999. |
|
|
126
|
+
| `time` | `HH:MM[:SS]`, no timezone, hours 00 through 23. |
|
|
127
|
+
| `datetime` | Gregorian date and time `YYYY-MM-DDTHH:MM[:SS]`, no timezone; a space may replace `T`. |
|
|
128
|
+
| `latlong` | `latitude,longitude` in decimal degrees, rounded to a globe-wide cube grid with less than 0.63 m of quantization error on WGS84. |
|
|
129
|
+
| `phone` | International `+` number of up to 15 digits, optional `;ext=004`; extension zeroes are preserved. |
|
|
130
|
+
| `ip` | IPv4 or IPv6 addresses, with a `use_ip6` family flag; interface scopes are unsupported. |
|
|
131
|
+
| `uuid` | All 128 bits, without imposing version restrictions. |
|
|
132
|
+
| `semver` | Complete semantic version, including prerelease and build metadata; optional input `v`. |
|
|
133
|
+
| `isbn` | ISBN-10 or ISBN-13 with check digits; ISBN-13 begins 978 or 979. |
|
|
134
|
+
| `upc` | UPC-A, including the check digit and leading zeroes. |
|
|
135
|
+
| `chess` | Legal SAN/UCI sequence or PGN main line from the standard starting position; output uses UCI. |
|
|
136
|
+
| `go` | Legal Go sequence from an empty 19×19 (default), 9×9, or 13×13 board. |
|
|
137
|
+
| `cards` | Every ordering of a 52-card deck, described by changed-position cycles; `()` is the ordered deck. |
|
|
138
|
+
| `color` | Opaque sRGB with three eight-bit channels. Accepts `#RGB` or `#RRGGBB` and returns lowercase six-digit hex. |
|
|
139
|
+
| `tune` | Monophonic melody and rhythm, using successive semitone steps and exact beat durations. |
|
|
140
|
+
| `chord` | Two or more simultaneous pitches such as `C4 E4 G4`, with whole-chord octave shifts treated as equivalent. |
|
|
141
|
+
| `string` | Unicode text, preserving case and allowed spaces; excludes U+0000–001F, U+007F–009F, and surrogates. The empty string is supported. No Unicode normalization is applied. |
|
|
142
|
+
|
|
143
|
+
String character indices count `a`–`z`, then `A`–`Z`, then the remaining allowed
|
|
144
|
+
U+0020–00FF characters in code-point order, then higher Unicode scalar values.
|
|
145
|
+
Strings are ordered by total character cost, then lexicographically by those
|
|
146
|
+
character indices. Character index `c` costs
|
|
147
|
+
`1 + floor(log2(1 + floor(c / 52)))`: all ASCII letters cost one, while later
|
|
148
|
+
characters cost progressively more. Longer common-letter strings therefore
|
|
149
|
+
precede rare single characters. Exact completion counts support direct ranking
|
|
150
|
+
and unranking. Every nonnegative index is canonical, including one empty string
|
|
151
|
+
at zero; Browse uses the same mapping. For example, `dfasdfasdf` is
|
|
152
|
+
`string:the fair age ear fun love`. This ordering changes previous string
|
|
153
|
+
truenames; other type mappings are unchanged.
|
|
154
|
+
|
|
155
|
+
Time and DateTime use whole seconds. Fractional-second input is
|
|
156
|
+
rejected, not rounded. Coordinates select a cube face, round each projected
|
|
157
|
+
coordinate to its nearest grid value, and print up to nine decimal places to recover the
|
|
158
|
+
same index. The first six positions are `0,0`, `0,90`, `0,-180`, `0,-90`,
|
|
159
|
+
`90,0`, and `-90,0`; later positions progressively fill gaps across all six faces.
|
|
160
|
+
The two antimeridian spellings and longitudes at either pole share one identity.
|
|
161
|
+
Phone and retail-code validity is structural;
|
|
162
|
+
no assignment, ownership, or reachability checks are made.
|
|
163
|
+
|
|
164
|
+
Date and DateTime default to `center_on_zoot=True`. Zoot is **2027-01-01
|
|
165
|
+
00:00:00 UTC**: Date counts days from that date, and DateTime counts seconds
|
|
166
|
+
from that instant. Their factor-three mapping orders offsets as
|
|
167
|
+
`0, 1, 2, -1, 3, 4, -2, 5, 6, -3, ...`. DateTime applies this mapping
|
|
168
|
+
once to the combined offset. This gives nearby values small indices and earlier
|
|
169
|
+
tunes in the musical-complexity enumeration. Time is unchanged.
|
|
170
|
+
|
|
171
|
+
Use `Nmr(center_on_zoot=False)` or the CLI flag `--no-center-on-zoot` to retain
|
|
172
|
+
the enumeration from `0001-01-01`. The browser bridge accepts the same boolean
|
|
173
|
+
in its configuration; the browser app uses the default. Encoding and decoding
|
|
174
|
+
must use the same setting. Years remain limited to 0001–9999; canonical decoding
|
|
175
|
+
rejects centered indices outside that range, while browsing wraps calendar values.
|
|
176
|
+
|
|
177
|
+
Formatted phone input is normalized with `phonenumberslite`, using international
|
|
178
|
+
E.164 digits plus our `;ext=digits` suffix. For example,
|
|
179
|
+
`+44 (0)20 7946 0958 ext. 004` becomes `+442079460958;ext=004`. The library
|
|
180
|
+
handles national trunk prefixes, significant leading zeroes, Unicode digits,
|
|
181
|
+
and vanity letters. Review the normalized result before sharing its truename.
|
|
182
|
+
An explicit `+` country code is still required; nmr does not guess a region.
|
|
183
|
+
Already canonical `+digits` values are literal identifiers, including unassigned
|
|
184
|
+
or short values, so established truenames do not depend on changing library metadata.
|
|
185
|
+
This is input normalization, not a check that a number is assigned or reachable.
|
|
186
|
+
|
|
187
|
+
Chess truenames preserve the move sequence, including unfinished games and the empty
|
|
188
|
+
game. PGN comments, headers, variations, and stated results are not included in the truename. Automatic
|
|
189
|
+
endings apply, including fivefold repetition and the 75-move rule; claimable draws
|
|
190
|
+
are not automatic endings. Moves are ordered lexically by UCI, independent of
|
|
191
|
+
library iteration order. Work is limited to 4096 plies per operation.
|
|
192
|
+
|
|
193
|
+
Go accepts coordinates with columns A through T, skipping I, rows counted from
|
|
194
|
+
the bottom, and `pass`. Black plays first. Use `9x9:D4 E4 pass pass` or
|
|
195
|
+
`13x13:J10`; an omitted size means 19×19. Canonical output always includes the
|
|
196
|
+
size. Captures apply before checking suicide, which is forbidden. Situational
|
|
197
|
+
superko forbids repeating a previous board with the same player to move; passes
|
|
198
|
+
are exempt, and two consecutive passes end the encoded play sequence. These move
|
|
199
|
+
legality conventions follow the [AGA rules](https://www.usgo-archive.org/files/pdf/conciserules.pdf).
|
|
200
|
+
Scoring, results, komi, handicap setups, SGF, and resumption after scoring are not
|
|
201
|
+
part of this format. Empty and unfinished sequences are supported, with a
|
|
202
|
+
4096-ply work limit. For example, `9x9:D4 E4 pass pass` has the truename
|
|
203
|
+
`go:they pal mega` with the default vocabulary.
|
|
204
|
+
|
|
205
|
+
Cards use `play:game:cards`. The baseline deck is clubs, diamonds, hearts,
|
|
206
|
+
then spades, each ordered A, 2, 3, …, 10, J, Q, K, without jokers. Positions
|
|
207
|
+
are numbered 1–52. Only displaced cards are described:
|
|
208
|
+
|
|
209
|
+
| Description | Meaning |
|
|
210
|
+
| --- | --- |
|
|
211
|
+
| `()` | The ordered deck. |
|
|
212
|
+
| `(1 2)` | Swap the first two cards, the ace and two of clubs. |
|
|
213
|
+
| `(1 2 3)` | Move the card originally at 1 to position 2, 2 to 3, and 3 to 1. |
|
|
214
|
+
| `(1 2) (3 4)` | Two independent swaps. |
|
|
215
|
+
|
|
216
|
+
Cycles must be disjoint and contain at least two positions. Canonical output
|
|
217
|
+
starts each cycle at its smallest position and sorts cycles by that position.
|
|
218
|
+
For example, `(4 3)(2 1)` normalizes to `(1 2) (3 4)`. In the browser,
|
|
219
|
+
select Cards to explore decks. In Name and Count, select two cards to swap them.
|
|
220
|
+
|
|
221
|
+
The enumeration first groups decks by displaced-card count. Within a group,
|
|
222
|
+
displaced-position subsets are ordered lexicographically, then the destination
|
|
223
|
+
positions of those cards, read in ascending original-position order, are ordered
|
|
224
|
+
lexicographically. Index 0 is `()`, index 1 is `(1 2)`, and indices 1–1326
|
|
225
|
+
cover all single swaps. All `52!` permutations occur exactly once. Canonical
|
|
226
|
+
indices stop at `52! - 1`; browsing wraps modulo `52!`.
|
|
227
|
+
|
|
228
|
+
Tunes use the `tune` prefix. For example:
|
|
229
|
+
|
|
230
|
+
```sh
|
|
231
|
+
nmr --operation encode --type tune --value '@1 2@1/2 r@1/3 -1@2/3'
|
|
232
|
+
# tune:made sell thin table
|
|
233
|
+
nmr --value 'tune:made sell thin table'
|
|
234
|
+
# @1 2@1/2 r@1/3 -1@2/3
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The first note starts with `@duration`. Later steps are signed semitone differences
|
|
238
|
+
from the previous sounding note; omit a zero step. `r@duration` adds a rest.
|
|
239
|
+
Durations are exact beats, with reduced denominators containing powers of two and
|
|
240
|
+
at most one factor of three. Thus `1/6` is allowed, `1/9` is not, and `3/9` becomes
|
|
241
|
+
`1/3`. Sounding notes must last at least `1/24` beat, a triplet 64th note;
|
|
242
|
+
rests may be shorter. Transposition, playback tempo, and the center note do not change a truename;
|
|
243
|
+
octave distances, beat scaling, and repeated attacks do. Adjacent rests merge,
|
|
244
|
+
trailing rests disappear, and a phrase must start with a sounding note.
|
|
245
|
+
|
|
246
|
+
To name a melody, use the CLI's tune encoder above. To open its result in the
|
|
247
|
+
browser, switch to Name, select `tune`, and paste its truename. The Python
|
|
248
|
+
library's `Nmr.to_tune()` supports both prefix-relative and absolute
|
|
249
|
+
interpretations. Browser playback runs at 180 BPM and defaults to F3 (MIDI 53)
|
|
250
|
+
as the center pitch.
|
|
251
|
+
|
|
252
|
+
Tunes are ordered by total complexity: one per attack, no extra pitch cost for
|
|
253
|
+
steps from -2 through +2 semitones, and `abs(step)-2` for larger steps,
|
|
254
|
+
duration weight `4h+a+3b`, and one plus duration weight for positive gaps. More
|
|
255
|
+
simple notes compete with fewer complicated ones. Exact rational generating
|
|
256
|
+
functions count all layers and completions; there is no separate length header.
|
|
257
|
+
The six weights and free-step radius are centralized in `nmr/types/tune_count.py` for design changes
|
|
258
|
+
before release. They are not runtime switches: changing them changes truenames.
|
|
259
|
+
|
|
260
|
+
Current codec work limits are 256 attacked notes, 20,000 text characters,
|
|
261
|
+
duration weight 512, total complexity 4,096, and tune indices of 4,096 bits.
|
|
262
|
+
A refusal reports a work limit and never substitutes another tune. Browser previews allow 20–400 BPM,
|
|
263
|
+
and MIDI pitches 0–127. Playback has no limit on total tune duration;
|
|
264
|
+
the minimum note length is in beats and follows the selected tempo.
|
|
265
|
+
A tune can receive a truename even when its preview is unavailable. Measured 4-, 8-, and
|
|
266
|
+
16-note motifs with the default vocabulary take 4, 10, and 19 payload words in
|
|
267
|
+
the examples in `plan/tunes.md`; these are measurements, not general bounds.
|
|
268
|
+
|
|
269
|
+
Prefixes remove type-routing overhead but cannot eliminate the information in
|
|
270
|
+
the value. A phone fits in four payload words in the example above.
|
|
271
|
+
|
|
272
|
+
Color uses `play:color`. Its index is the RGB value read as a 24-bit integer
|
|
273
|
+
in red, green, blue byte order. Indices start at 0 for `#000000` and end at
|
|
274
|
+
16,777,215 for `#ffffff`. Browsing wraps at 16,777,216. Use quotes around the
|
|
275
|
+
hex value in a shell command.
|
|
276
|
+
|
|
277
|
+
```sh
|
|
278
|
+
nmr --operation encode --type color --value '#AbC'
|
|
279
|
+
# color:to front blue
|
|
280
|
+
nmr --value 'color:to front blue'
|
|
281
|
+
# #aabbcc
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
In the browser, select Color to see its swatch and exact hex value in Name,
|
|
285
|
+
Count, or Clock.
|
|
286
|
+
|
|
287
|
+
## Chords
|
|
288
|
+
|
|
289
|
+
```sh
|
|
290
|
+
nmr --operation encode --type chord --value 'G3 C3 E3'
|
|
291
|
+
# chord:adult
|
|
292
|
+
nmr --value 'chord:adult'
|
|
293
|
+
# C4 E4 G4
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Input pitches use letter names, optional sharps or flats, and signed octave
|
|
297
|
+
numbers. Decoding prints pitches from low to high with sharps. Chord ignores
|
|
298
|
+
entry order and merges identical pitches. It preserves inversions and octave
|
|
299
|
+
doublings. A whole-chord octave shift places the exact median of the pitches
|
|
300
|
+
in the range from C4 inclusive to C5 exclusive.
|
|
301
|
+
|
|
302
|
+
Each voice beyond the first two adds two units of complexity. Every complete
|
|
303
|
+
extra octave of spacing between adjacent pitches adds one. Within a group
|
|
304
|
+
of equally spaced octave bands, the interval choices follow the circle of
|
|
305
|
+
fourths in alternating directions. The codec accepts costs through 8,192.
|
|
306
|
+
The complete ordering and inverse are in [the Chord plan](plan/chord.md).
|
|
307
|
+
|
|
308
|
+
In the browser, select Chord to hear all notes sound together for one beat
|
|
309
|
+
at their normalized register. The score shows the same pitches. Voicings
|
|
310
|
+
outside the MIDI preview range can still be encoded and decoded. In All types,
|
|
311
|
+
a displayed Chord uses the full-index tune projection for playback.
|
|
312
|
+
|
|
313
|
+
## Your own vocabulary
|
|
314
|
+
|
|
315
|
+
Use a UTF-8 file with one word per line. Order matters. Empty lines and lines
|
|
316
|
+
beginning with `#` are ignored. Tokens cannot contain whitespace or `:`.
|
|
317
|
+
NFC normalization and Unicode case folding are the defaults; `--case-sensitive`
|
|
318
|
+
retains case. Duplicate normalized words are rejected. The same policy and
|
|
319
|
+
selected word count must be used by both people.
|
|
320
|
+
|
|
321
|
+
```sh
|
|
322
|
+
nmr --word-file private.txt --vocabulary-info
|
|
323
|
+
nmr --word-file private.txt --operation encode --type phone --value '+442079460958'
|
|
324
|
+
nmr --word-file private.txt --value 'phone:YOUR WORDS HERE'
|
|
325
|
+
nmr --word-file private.txt --export-words normalized-private.txt
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
`--word-count N` selects the first N validated words. The default vocabulary uses
|
|
329
|
+
1,627 words. `--vocabulary-info` gives its SHA-256 identifier; a recipient can
|
|
330
|
+
require it with `--expect-vocabulary IDENTIFIER`. When sharing Date or DateTime,
|
|
331
|
+
send the `center_on_zoot` setting too. Both `--json-output` and
|
|
332
|
+
`--vocabulary-info` report it. Pass `--center-on-zoot` for `true` or
|
|
333
|
+
`--no-center-on-zoot` for `false`. For example, `date:the` means
|
|
334
|
+
2027-01-01 with the first flag and 0001-01-01 with the second, even when the
|
|
335
|
+
vocabulary identifier matches. The hosted browser always uses centering.
|
|
336
|
+
|
|
337
|
+
The bundled vocabulary treats **a/an** as one entry: it displays **an** before
|
|
338
|
+
a vowel letter (`a`, `e`, `i`, `o`, `u`), and **a** otherwise or at the end.
|
|
339
|
+
This spelling rule applies only to the bundled list; exported or custom word
|
|
340
|
+
lists use literal words. The identifier includes this rule as well as word
|
|
341
|
+
order and case policy. Export the normalized ordered list and share it through an
|
|
342
|
+
already trusted channel. Custom vocabulary tools are available through the CLI
|
|
343
|
+
and Python library; the minimal browser uses the default vocabulary.
|
|
344
|
+
|
|
345
|
+
A private vocabulary provides obscurity, not reliable encryption. Repeated values
|
|
346
|
+
produce repeated truenames; prefixes reveal types; a wrong vocabulary can produce a
|
|
347
|
+
plausible result. The vocabulary identifier detects a mismatch when supplied,
|
|
348
|
+
but does not authenticate the sender or the message. Verify important details.
|
|
349
|
+
|
|
350
|
+
Truenames never repeat a word, so a vocabulary has finite capacity:
|
|
351
|
+
`sum(W! / (W-k)!, k=1..W)`. Overflow produces an error; a larger vocabulary may be
|
|
352
|
+
needed. Many mistyped truenames are rejected, but another valid canonical truename cannot
|
|
353
|
+
be distinguished from an intentional one without additional information.
|
|
354
|
+
|
|
355
|
+
## Browser tool
|
|
356
|
+
|
|
357
|
+
Build a mobile-friendly static tool from the installed core:
|
|
358
|
+
|
|
359
|
+
```sh
|
|
360
|
+
nmr --operation build-web --destination dist/web
|
|
361
|
+
python -m http.server 8765 --bind 127.0.0.1 --directory dist/web
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Open `http://127.0.0.1:8765` locally, or host those files on an ordinary static
|
|
365
|
+
HTTPS server for friends. Direct `file:` loading does not support the worker and
|
|
366
|
+
asset loading used here. No conversion server or account is needed.
|
|
367
|
+
|
|
368
|
+
To build and deploy to `https://ax.to/nmr`, run from the checkout:
|
|
369
|
+
|
|
370
|
+
```sh
|
|
371
|
+
uv run --frozen python script/deploy.py
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
This uses your SSH keys for `root@ax.to`, uploads changed files with rsync to
|
|
375
|
+
`/home/ax/public_html/nmr/`, and sets the deployed directory and all its contents
|
|
376
|
+
to owner `ax` and group `ax`. Files already on the server are not deleted.
|
|
377
|
+
The deployment sets the asset base to `/nmr/` and includes `.htaccess`: Apache
|
|
378
|
+
serves `/nmr` directly and redirects `/nmr/` to `/nmr`, preserving the query.
|
|
379
|
+
Apache 2.4 must enable `mod_rewrite` and allow the `FileInfo`, `Indexes`, and
|
|
380
|
+
`Options` override classes for this directory. Local builds retain relative assets.
|
|
381
|
+
|
|
382
|
+
The page downloads pinned Pyodide 0.29.3 and its Pydantic packages. First load
|
|
383
|
+
requires a connection and a WebAssembly-capable modern browser. The project,
|
|
384
|
+
chess library, and semantic-version library are bundled from the same installation
|
|
385
|
+
that builds the site. Conversion runs locally in a worker. The heading is a button that cycles
|
|
386
|
+
through **Clock**, **Count**, and **Name**. A fresh page starts in Clock.
|
|
387
|
+
Click the date/time to alternate between the live time and its index.
|
|
388
|
+
|
|
389
|
+
To name a birthday, run the encode command in [Install and try](#install-and-try).
|
|
390
|
+
To recover that birthday in the browser, switch to **Name**, select `date`,
|
|
391
|
+
and paste `date:or each`. A recipient can open
|
|
392
|
+
`/nmr?mode=name&type=real%3Atime%3Adate&value=date%3Aor+each` on the deployed
|
|
393
|
+
site to see the same date. The page uses the default vocabulary and centering.
|
|
394
|
+
|
|
395
|
+
In Name mode, edit the true name to display its object. The name editor retains
|
|
396
|
+
vocabulary completion with Space, Left/Right, and Up/Down. Select a Type to edit
|
|
397
|
+
a short name, or select All types for full names.
|
|
398
|
+
|
|
399
|
+
Count continuously iterates an exact nonnegative integer. It plays the current index,
|
|
400
|
+
waits the configurable delay after the tune finishes, increments, and plays again.
|
|
401
|
+
Delay between tunes (s) defaults to two seconds and is shared with Clock. Increment
|
|
402
|
+
is a compact positive-integer setting in Settings. Changing Type preserves the
|
|
403
|
+
index and decodes it in the selected type. Finite types wrap using the codecs'
|
|
404
|
+
existing browsing rules; the source index is preserved.
|
|
405
|
+
|
|
406
|
+
Clock derives an index relative to Time or DateTime, controlled by Time only in
|
|
407
|
+
Settings. Entering Clock selects All types by default. It decodes that index
|
|
408
|
+
globally under All types or within the selected
|
|
409
|
+
Type otherwise, including non-temporal types. Display UTC affects presentation;
|
|
410
|
+
the source uses UTC. Clock plays its first tune immediately. After each tune
|
|
411
|
+
finishes, it waits the shared delay, then selects the tune for the next new
|
|
412
|
+
whole second. The clock display continues updating during playback and the wait.
|
|
413
|
+
All types follows numeric routing, so types occur at different frequencies.
|
|
414
|
+
For example, the 64 UTC seconds immediately before zoot display all 19 types
|
|
415
|
+
and include eight integers. The first 64 seconds starting at zoot display 18
|
|
416
|
+
types, including nine integers and no SemVer values. A playback model starting
|
|
417
|
+
a phrase at the first second of each interval, with the default delay and
|
|
418
|
+
zero worker latency, selects 18 phrases in each interval. Those phrases
|
|
419
|
+
correspond to nine object types before zoot and eleven starting at zoot.
|
|
420
|
+
|
|
421
|
+
The current object's bounded display supports chess moves and promotions, Go
|
|
422
|
+
moves, Pass and Undo, card interchanges, and the bundled world map. Interactive
|
|
423
|
+
changes work in Name and Count modes. Clock's object display is read-only.
|
|
424
|
+
|
|
425
|
+
The **Object name** below the displayed value is its canonical truename.
|
|
426
|
+
Copy the words and prefix shown there to send this exact object. A Count or
|
|
427
|
+
Clock index may browse to a different canonical index. The music area has its
|
|
428
|
+
own name, score and playback status. Selected types play short names, and
|
|
429
|
+
All types plays full names. Highlighting defaults to orange.
|
|
430
|
+
The current tune finishes when mode or Type changes. The speaker button starts
|
|
431
|
+
muted and toggles sound without stopping Count or Clock progression.
|
|
432
|
+
Keep last played music in Settings is enabled by default; disabling it
|
|
433
|
+
clears the name and score at playback end while reserving their space.
|
|
434
|
+
|
|
435
|
+
Settings also contains volume, root, position, time signature, and playing-note
|
|
436
|
+
color. Existing playback, notation, and codec work limits still apply and are
|
|
437
|
+
reported in the status region. VexFlow and its licensed fonts are bundled locally.
|
|
438
|
+
|
|
439
|
+
Evolve is enabled by default. The fundamental and total harmonic energy stay
|
|
440
|
+
steady while a 12-second cycle shifts the harmonic mix between odd and even
|
|
441
|
+
harmonics, including during held notes.
|
|
442
|
+
Slower native modulation varies stereo position and a quiet 190 ms echo across
|
|
443
|
+
tune boundaries. Note pitches, onsets, durations, and volume envelopes
|
|
444
|
+
are unchanged. Echo tails can continue after a note ends; mute silences the
|
|
445
|
+
effects as well as the notes. Disabling Evolve smoothly bypasses the effects and
|
|
446
|
+
returns to a fixed triangle-like tone, including during the current note.
|
|
447
|
+
|
|
448
|
+
The play/pause icon to the left of mute starts in the running state. Pausing
|
|
449
|
+
freezes Clock and Count and suspends the current audio. Resuming Clock catches
|
|
450
|
+
up to the current time; Count continues from its paused number. The button is
|
|
451
|
+
hidden in Name mode, which remains playable. Pause and mute are independent.
|
|
452
|
+
|
|
453
|
+
New share links use separate mode and type parameters, an index and increment,
|
|
454
|
+
and a Name value when applicable. Back and Forward restore the new link state.
|
|
455
|
+
Opening a Clock or running Count link starts progression. To share a fixed
|
|
456
|
+
object with the fewest moving parts, share its **Object name** as plain text.
|
|
457
|
+
A truename is reversible and can reveal a private coordinate or phone number.
|
|
458
|
+
Opening or reloading a link sends the query to the host. The worker processes
|
|
459
|
+
edits locally, and cold starts download runtime assets. Use the installed CLI
|
|
460
|
+
to decode offline.
|
|
461
|
+
|
|
462
|
+
Settings are kept in memory for the current page session.
|
|
463
|
+
|
|
464
|
+
Rebuild after source changes before testing the local site. Automated tests do
|
|
465
|
+
not establish audible quality or live visual synchronization. The browser smoke
|
|
466
|
+
check is separate: run test/browser_smoke.cjs against freshly built assets where
|
|
467
|
+
Playwright is available. The deployment helper script/deploy.py builds and
|
|
468
|
+
publishes to https://ax.to/nmr; a local rebuild does not deploy the hosted site.
|
|
469
|
+
|
|
470
|
+
## Python library
|
|
471
|
+
|
|
472
|
+
```python
|
|
473
|
+
from nmr.nmr import Nmr
|
|
474
|
+
from nmr.types.fraction import Frac
|
|
475
|
+
|
|
476
|
+
engine = Nmr()
|
|
477
|
+
encoded = engine.encode("2/4", "frac")
|
|
478
|
+
assert encoded.truename == "frac:his"
|
|
479
|
+
assert engine.decode(encoded.truename).value == "2/4"
|
|
480
|
+
|
|
481
|
+
explored = engine.decode("pure:to", browse=True)
|
|
482
|
+
assert engine.decode(explored.truename).value == explored.value
|
|
483
|
+
|
|
484
|
+
fraction = Frac(numerator=2, denominator=4)
|
|
485
|
+
assert fraction.float() == 0.5
|
|
486
|
+
assert fraction.fraction().numerator == 1
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
`Frac` has no arithmetic or implicit numerical conversion. Its identity is the
|
|
490
|
+
stored pair. `.float()` returns infinities or NaN for zero denominators, and
|
|
491
|
+
otherwise delegates to the standard rational conversion; finite overflow raises
|
|
492
|
+
`OverflowError`. `.fraction()` returns `fractions.Fraction` and raises
|
|
493
|
+
`ZeroDivisionError` for zero denominators. Neither method changes the pair.
|
|
494
|
+
`Int` lives in `nmr.types.integer`.
|
|
495
|
+
|
|
496
|
+
Integer tuples are ranked directly by total sum. For `n` nonnegative integers
|
|
497
|
+
with total `S`, preceding sum layers contain `comb(S + n - 1, n)` tuples; the
|
|
498
|
+
remaining offset is the rank of the tail tuple. For example, `(2, 1, 3)` has
|
|
499
|
+
rank 69. Inversion uses integer binomial comparisons and binary search. One-part
|
|
500
|
+
tuples are unchanged, and two-part tuples retain the Cantor pairing order.
|
|
501
|
+
Semantic versions pack major, minor, patch, prerelease, and build indices as five
|
|
502
|
+
components without nested pairing. This balances by sum, not by component bit
|
|
503
|
+
length; it does not guarantee a shorter truename for every object.
|
|
504
|
+
|
|
505
|
+
## Format and development
|
|
506
|
+
|
|
507
|
+
The four root slots are `pure`, `real`, `data`, and `play`. Every category has
|
|
508
|
+
radix four. Slots 0–2 may hold leaves or categories; slot 3 can only be empty or a
|
|
509
|
+
category. This rule applies at every depth, including the root. The unnamed root
|
|
510
|
+
cannot be nested. Published allocations never move, and leaves never turn into
|
|
511
|
+
categories.
|
|
512
|
+
|
|
513
|
+
The exact allocations are in `nmr/registry.py`, using positional constructors
|
|
514
|
+
such as `Category("game", Chess, Go)`. Children are stored in an immutable tuple
|
|
515
|
+
of categories or codec classes. Tuple positions define the slots; unused slots
|
|
516
|
+
follow the last child. Categories require one to four children, with no `None`
|
|
517
|
+
entries or empty placeholder categories. Prefixes are ordinary paths
|
|
518
|
+
through that tree. At each edge, `parent_index = slot + 4 * child_index`.
|
|
519
|
+
A fuller prefix removes more of those routing components from the word payload.
|
|
520
|
+
`test/format.json` freezes shared Python and WebAssembly examples.
|
|
521
|
+
|
|
522
|
+
```sh
|
|
523
|
+
uv sync --frozen
|
|
524
|
+
uv run --frozen pytest
|
|
525
|
+
uv run --frozen ruff check --select B,E,F,I nmr test scripts
|
|
526
|
+
uv run --frozen ruff format --check nmr test scripts
|
|
527
|
+
uv run --frozen ty check nmr
|
|
528
|
+
uv run --frozen coverage run -m pytest
|
|
529
|
+
uv run --frozen coverage report
|
|
530
|
+
uv build
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
For WebAssembly checks, install `pyodide@0.29.3` in a temporary npm directory,
|
|
534
|
+
make it available through `NODE_PATH`, build `dist/web`, and run
|
|
535
|
+
`node test/runtime_smoke.cjs`. Browser interaction checks also need Playwright and
|
|
536
|
+
Chrome, or `NMR_BROWSER_CHANNEL=chromium` with Playwright's Chromium installed.
|
|
537
|
+
The workflow in `.github/workflows/check.yml` runs WebAssembly checks automatically
|
|
538
|
+
and offers browser interactions as a manual workflow-dispatch job.
|
|
539
|
+
|
|
540
|
+
For native audio regression checks, run `node test/tune-audio.cjs` with Chrome
|
|
541
|
+
installed on macOS, or supply its executable path as the first argument.
|
|
542
|
+
This renders 48 kHz WAV files in a temporary directory and checks Evolve levels
|
|
543
|
+
and held-note variation, including switching Evolve during playback.
|
|
544
|
+
|
|
545
|
+
See [the implementation plan](plan/nmr.md) for the contract, design rationale,
|
|
546
|
+
and resolved first-release decisions.
|