NHyDBrun4
R
u
v
Version of 1
lane
NLOverview

From N back to the address

The coordinates of a cell give its number N (see The address space). The way back is just as exact: the cell can be computed from N, without a table and without a search. All it takes is a square root in integers.

The idea: find the nearest square number

Every group G has the square number G² at its centre. To place N, you look for the largest square number that is not greater than N:

m = isqrt(N)      largest integer m with m² ≤ N
d = N − m²        distance to this square number

isqrt is the integer square root: isqrt(589) = 24, because 24² = 576 ≤ 589 < 625 = 25². The distance d always lies between 0 and 2m.

Four cases

The distance d decides where N lies:

d = 0          N is a square number              → not a cell
1 ≤ d < m      N lies right of the square m²     → NR, G = m
d = m          N is a boundary m(m + 1)          → not a cell
m < d ≤ 2m     N lies left of the square (m+1)²  → NL, G = m + 1

On NR the distance to the square is directly the coordinate v; on NL the distance to the next square is the coordinate u. The other coordinate follows from G = u + v.

Example 589

m = isqrt(589) = 24
d = 589 − 576  = 13          1 ≤ 13 < 24  →  NR
G = 24,  v = 13,  u = 24 − 13 = 11

Result: (1, 11, 13, NR). Check: 24² + 13 = 589.

Example 391

m = isqrt(391) = 19
d = 391 − 361  = 30          30 > 19  →  NL
G = 20,  u = 400 − 391 = 9,  v = 20 − 9 = 11

Result: (1, 9, 11, NL). Check: 20² − 9 = 391.

Rejected: 576 and 552

576:  m = 24,  d = 0          square number 24²   → not a cell
552:  m = 23,  d = 23 = m     boundary 23 · 24    → not a cell

These numbers are fixed markers between the cells. NHyDB reports an error for them and does not invent a substitute address.

Integers, not decimals

The whole calculation uses integers. A square root with decimal numbers would be inaccurate for large N – a single rounding error would already lead to the wrong cell. With the integer square root the result is exact for any size, even for numbers with hundreds of digits. In higher realms, R and v follow at the end from the global coordinate (see Realms).

# From N back to the address The coordinates of a cell give its number N (see [The address space](/en/address-space/)). The way back is just as exact: the cell can be computed from N, without a table and without a search. All it takes is a square root in integers. ## The idea: find the nearest square number Every group G has the square number G² at its centre. To place N, you look for the largest square number that is not greater than N: ```m = isqrt(N) largest integer m with m² ≤ Nd = N − m² distance to this square number``` `isqrt` is the integer square root: isqrt(589) = 24, because 24² = 576 ≤ 589 < 625 = 25². The distance d always lies between 0 and 2m. ## Four cases The distance d decides where N lies: ```d = 0 N is a square number → not a cell1 ≤ d < m N lies right of the square m² → NR, G = md = m N is a boundary m(m + 1) → not a cellm < d ≤ 2m N lies left of the square (m+1)² → NL, G = m + 1``` On NR the distance to the square is directly the coordinate v; on NL the distance to the next square is the coordinate u. The other coordinate follows from G = u + v. ## Example 589 ```m = isqrt(589) = 24d = 589 − 576 = 13 1 ≤ 13 < 24 → NRG = 24, v = 13, u = 24 − 13 = 11``` Result: **(1, 11, 13, NR)**. Check: 24² + 13 = 589. ## Example 391 ```m = isqrt(391) = 19d = 391 − 361 = 30 30 > 19 → NLG = 20, u = 400 − 391 = 9, v = 20 − 9 = 11``` Result: **(1, 9, 11, NL)**. Check: 20² − 9 = 391. ## Rejected: 576 and 552 ```576: m = 24, d = 0 square number 24² → not a cell552: m = 23, d = 23 = m boundary 23 · 24 → not a cell``` These numbers are fixed markers between the cells. NHyDB reports an error for them and does not invent a substitute address. ## Integers, not decimals The whole calculation uses integers. A square root with decimal numbers would be inaccurate for large N – a single rounding error would already lead to the wrong cell. With the integer square root the result is exact for any size, even for numbers with hundreds of digits. In higher realms, R and v follow at the end from the global coordinate (see [Realms](/en/realms/)).