In detail
Algorithm. Integer operations only, T = 10¹⁰⁰:
Input: N ≥ 1 (N = 0 is rejected)
m = isqrt(N) largest m with m² ≤ N
d = N − m² where 0 ≤ d ≤ 2m
d = 0 ⇒ N = GZ(m) = m² not a cell
1 ≤ d < m ⇒ NR: G = m, V = d, u = G − V
d = m ⇒ N = N0(m+1) = m(m+1) not a cell
m < d ≤ 2m ⇒ NL: G = m + 1, u = G² − N, V = G − u (= d − m)
R = ⌊(V − 1) / T⌋ + 1
v = ((V − 1) mod T) + 1
Check: N(R, u, v, lane) = N
Why the cases are right. For an NR cell, G² < N < G² + G, so isqrt(N) = G and d = V with 1 ≤ V ≤ G − 1. For an NL cell, (G − 1)² + (G − 1) < N < G², so isqrt(N) = G − 1 = m and d = N − m² lies between m + 1 and 2m. The value d = m corresponds exactly to N = m(m + 1), the boundary N0(m + 1); d = 0 corresponds to the square number. Since (m + 1)² = m² + 2m + 1, d can never be greater than 2m. So every N belongs to exactly one of the four cases, and every valid cell has exactly one inverse computation.
Integer square root. isqrt(N) is the unique number m with m² ≤ N < (m + 1)². NHyDB computes it exactly; a floating-point estimate serves at most as a starting value and is corrected in integers. For arbitrarily large N, the calculation uses arbitrarily large integers.
Worked examples.
| N |
m |
d |
Case |
Result |
| 589 |
24 |
13 |
1 ≤ 13 < 24 ⇒ NR |
G = 24, V = 13, u = 11 ⇒ (1, 11, 13, NR) |
| 565 |
23 |
36 |
36 > 23 ⇒ NL |
G = 24, u = 11, V = 13 ⇒ (1, 11, 13, NL) |
| 391 |
19 |
30 |
30 > 19 ⇒ NL |
G = 20, u = 9, V = 11 ⇒ (1, 9, 11, NL) |
| 553 |
23 |
24 |
24 > 23 ⇒ NL |
G = 24, u = 23, V = 1 (first NL cell) |
| 575 |
23 |
46 |
46 = 2m ⇒ NL |
G = 24, u = 1, V = 23 (last NL cell) |
| 577 |
24 |
1 |
NR |
G = 24, V = 1, u = 23 (first NR cell) |
| 599 |
24 |
23 |
NR |
G = 24, V = 23, u = 1 (last NR cell) |
| 576 |
24 |
0 |
GZ(24) |
rejected |
| 552 |
23 |
23 |
N0(24) |
rejected |
| 600 |
24 |
24 |
N0(25) |
rejected |
Edge cases. N = 1 is GZ(1), N = 2 is N0(2) – neither is a cell; the smallest cell is N = 3 = (1, 1, 1, NL). N = 0 is not a valid input. There is no substitute address for GZ and N0 numbers.
Large numbers. For N = (22 · T + 758)² − 14, a number with 203 decimal digits, the inverse computation yields G = 22 · T + 758, u = 14, V = 22 · T + 744 and from that exactly (23, 14, 744, NL).
In Python (without a database):
import nhydb
for n in (589, 391, 576, 552):
try:
a = nhydb.n_to_dynadron_address(n)
print(n, (a["realm"], a["u"], a["v_local"], a["lane_name"]), "G =", a["G"])
except nhydb.AddressError as e:
print(n, "AddressError:", e)
Output:
589 (1, 11, 13, 'NR') G = 24
391 (1, 9, 11, 'NL') G = 20
576 AddressError: N576 is a GZ point, not an NHyDB storage cell
552 AddressError: N552 is an N0 point, not an NHyDB storage cell
Mind the names: in the result, "v" holds the global coordinate V and "v_local" the local v. In realm 1 both are the same.
Read more: Technical documentation, section 2 · Python Cookbook, chapter 9 and chapter 10
# In detail **Algorithm.** Integer operations only, T = 10¹⁰⁰: ```Input: N ≥ 1 (N = 0 is rejected) m = isqrt(N) largest m with m² ≤ Nd = N − m² where 0 ≤ d ≤ 2m d = 0 ⇒ N = GZ(m) = m² not a cell1 ≤ d < m ⇒ NR: G = m, V = d, u = G − Vd = m ⇒ N = N0(m+1) = m(m+1) not a cellm < d ≤ 2m ⇒ NL: G = m + 1, u = G² − N, V = G − u (= d − m) R = ⌊(V − 1) / T⌋ + 1v = ((V − 1) mod T) + 1Check: N(R, u, v, lane) = N``` **Why the cases are right.** For an NR cell, G² < N < G² + G, so isqrt(N) = G and d = V with 1 ≤ V ≤ G − 1. For an NL cell, (G − 1)² + (G − 1) < N < G², so isqrt(N) = G − 1 = m and d = N − m² lies between m + 1 and 2m. The value d = m corresponds exactly to N = m(m + 1), the boundary N0(m + 1); d = 0 corresponds to the square number. Since (m + 1)² = m² + 2m + 1, d can never be greater than 2m. So every N belongs to exactly one of the four cases, and every valid cell has exactly one inverse computation. **Integer square root.** isqrt(N) is the unique number m with m² ≤ N < (m + 1)². NHyDB computes it exactly; a floating-point estimate serves at most as a starting value and is corrected in integers. For arbitrarily large N, the calculation uses arbitrarily large integers. **Worked examples.** | N | m | d | Case | Result ||---:|---:|---:|---|---|| 589 | 24 | 13 | 1 ≤ 13 < 24 ⇒ NR | G = 24, V = 13, u = 11 ⇒ (1, 11, 13, NR) || 565 | 23 | 36 | 36 > 23 ⇒ NL | G = 24, u = 11, V = 13 ⇒ (1, 11, 13, NL) || 391 | 19 | 30 | 30 > 19 ⇒ NL | G = 20, u = 9, V = 11 ⇒ (1, 9, 11, NL) || 553 | 23 | 24 | 24 > 23 ⇒ NL | G = 24, u = 23, V = 1 (first NL cell) || 575 | 23 | 46 | 46 = 2m ⇒ NL | G = 24, u = 1, V = 23 (last NL cell) || 577 | 24 | 1 | NR | G = 24, V = 1, u = 23 (first NR cell) || 599 | 24 | 23 | NR | G = 24, V = 23, u = 1 (last NR cell) || 576 | 24 | 0 | GZ(24) | rejected || 552 | 23 | 23 | N0(24) | rejected || 600 | 24 | 24 | N0(25) | rejected | **Edge cases.** N = 1 is GZ(1), N = 2 is N0(2) – neither is a cell; the smallest cell is N = 3 = (1, 1, 1, NL). N = 0 is not a valid input. There is no substitute address for GZ and N0 numbers. **Large numbers.** For N = (22 · T + 758)² − 14, a number with 203 decimal digits, the inverse computation yields G = 22 · T + 758, u = 14, V = 22 · T + 744 and from that exactly (23, 14, 744, NL). **In Python** (without a database): ```pythonimport nhydb for n in (589, 391, 576, 552): try: a = nhydb.n_to_dynadron_address(n) print(n, (a["realm"], a["u"], a["v_local"], a["lane_name"]), "G =", a["G"]) except nhydb.AddressError as e: print(n, "AddressError:", e)``` Output: ```text589 (1, 11, 13, 'NR') G = 24391 (1, 9, 11, 'NL') G = 20576 AddressError: N576 is a GZ point, not an NHyDB storage cell552 AddressError: N552 is an N0 point, not an NHyDB storage cell``` Mind the names: in the result, `"v"` holds the global coordinate V and `"v_local"` the local v. In realm 1 both are the same. **Read more:** Technical documentation, [section 2](https://github.com/nhydb-run4/NHyDB/blob/main/docs/en/NHyDB_Technical_Documentation.md#2-mathematical-foundations-of-addressing) · Python Cookbook, [chapter 9](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#9-addresses-and-the-number-n) and [chapter 10](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#10-reading-by-n-and-inspecting-addresses)