<!-- canonical: efficientnewlanguage.org/ai/examples/874-the-nearest-was-across-the-river | ai_layer_version: 0.1.0 | updated: 2026-09-16 -->

# Example 874 — The nearest was across the river

`the_nearest_was_across_the_river.eml` - A delivery service fulfils each order from the nearest store, and it measures the distance from the real coordinates of every store correctly. What kind of distance it measures is computed below.

## EML

```eml
# Self-authored for the EML case corpus (no external origin). A delivery service
# fulfils each order from the nearest store, and it measures the distance from
# the real coordinates of every store correctly. What kind of distance it
# measures is computed below.
#
# The choice is careful. It reads the real coordinates of the customer and of
# every store; it uses a true great-circle distance, not a flat approximation; it
# compares every store; and the intent is exactly 'the store closest to the
# customer'.
#
# The nearest store by straight line is across the river, and the nearest bridge
# is five kilometres away, so the road distance to it is eleven times the
# straight-line distance.

1 => store_a_straight_line_km
11 => store_a_road_km
3 => store_b_straight_line_km
4 => store_b_road_km
20000 => deliveries_routed_to_a

store_a_road_km - store_a_straight_line_km => a_km_the_straight_line_did_not_see
int(a_km_the_straight_line_did_not_see * 10000 / store_a_road_km) => a_understated_per_myriad
store_a_road_km - store_b_road_km => extra_road_km_per_delivery
extra_road_km_per_delivery * deliveries_routed_to_a => extra_road_km_total

"store A, straight line          : " + str(store_a_straight_line_km) + " km" ^0
"store A, by road                : " + str(store_a_road_km) + " km" ^0
"store B, straight line          : " + str(store_b_straight_line_km) + " km" ^0
"store B, by road                : " + str(store_b_road_km) + " km" ^0
"" ^0
"chosen by straight line         : A" ^0
"nearest by road                 : B" ^0
"A understated by straight line  : " + str(a_understated_per_myriad) + " per ten thousand" ^0
"extra road per delivery         : " + str(extra_road_km_per_delivery) + " km" ^0
"extra road over all deliveries  : " + str(extra_road_km_total) + " km" ^0
"" ^0

# ---- what the choice verified ----

"the nearest-store choice" ^0
"  reads : the real coordinates of customer and every store" ^0
"  distance : a true great-circle distance, not a flat one" ^0
"  compares : every store" ^0
"  intent : the store closest to the customer" ^0
"  stores skipped : 0" ^0
"  verdict : A IS CLOSEST, AT 1 KM" ^0
"" ^0
"  using a true great-circle distance over every store is the" ^0
"  part done right here, and it is why 1 km is exactly how" ^0
"  far apart the two points are" ^0
"" ^0

# ---- what kind of distance ----

"straight line and road" ^0
"  what the straight line answers : how far apart two points" ^0
"    are" ^0
"  what the delivery needs : how far a van must drive" ^0
"  what lies between customer and A : a river, bridged five" ^0
"    kilometres away" ^0
"  so A by road : " + str(store_a_road_km) + " km, from a straight line of " + str(store_a_straight_line_km) ^0
"  and B by road : " + str(store_b_road_km) + " km, from a straight line of " + str(store_b_straight_line_km) ^0
"" ^0

# ---- what the caller got ----

"the dispatch" ^0
"  store chosen : A, " + str(store_a_road_km) + " km by road" ^0
"  store nearest by road : B, " + str(store_b_road_km) + " km" ^0
"  extra driving per delivery : " + str(extra_road_km_per_delivery) + " km" ^0
"  is the great-circle distance wrong : no; it is exact" ^0
"  is it the distance a van drives : no; the river is not on" ^0
"    a great circle" ^0
"" ^0

# ---- null control ----

# The same choice, made on road-network distance (routing) instead of
# straight-line distance.
1 => nc_a_km_by_straight_line
11 => nc_a_km_by_road
1 => nc_picks_b_once_routed

"null control - choose by road-network distance" ^0
"  A by straight line : " + str(nc_a_km_by_straight_line) + " km" ^0
"  A by road : " + str(nc_a_km_by_road) + " km" ^0
"  picks B once routed : " + str(nc_picks_b_once_routed) ^0
"  no store and no coordinate changed; the distance stopped" ^0
"  being the one between the points and started being the" ^0
"  one along the roads" ^0
"" ^0

# ---- the rule ----

"what a nearest-by-great-circle choice guarantees" ^0
"  the chosen store is the closest as the crow flies :" ^0
"    exactly, true distance over every store" ^0
"  the chosen store is the closest to deliver from : not" ^0
"    addressed; a river with a distant bridge makes A's road" ^0
"    distance " + str(store_a_road_km) + " km from a straight line of " + str(store_a_straight_line_km) + ", so the" ^0
"    farther-by-crow B at " + str(store_b_road_km) + " km by road was the real nearest" ^0
"" ^0

"distance between two points and distance along the ways between them are" ^0
"different quantities, and the second is what anything that has to travel pays;" ^0
"a barrier the straight line crosses freely is the whole difference" ^0
"" ^0

"It uses a true great-circle distance over every store - A really is 1 km away." ^0
"But a river with the bridge five kilometres off makes A " + str(store_a_road_km) + " km by road," ^0
"" + str(a_understated_per_myriad) + " per ten thousand understated, while B is " + str(store_b_road_km) + " km; " + str(deliveries_routed_to_a) + " deliveries" ^0
"drove " + str(extra_road_km_total) + " extra km, until the choice was made on road distance." ^0
```

## Python (deterministic transpilation)

```python
store_a_straight_line_km = 1
store_a_road_km = 11
store_b_straight_line_km = 3
store_b_road_km = 4
deliveries_routed_to_a = 20000
a_km_the_straight_line_did_not_see = store_a_road_km - store_a_straight_line_km
a_understated_per_myriad = int(a_km_the_straight_line_did_not_see * 10000 / store_a_road_km)
extra_road_km_per_delivery = store_a_road_km - store_b_road_km
extra_road_km_total = extra_road_km_per_delivery * deliveries_routed_to_a
print("store A, straight line          : " + str(store_a_straight_line_km) + " km")
print("store A, by road                : " + str(store_a_road_km) + " km")
print("store B, straight line          : " + str(store_b_straight_line_km) + " km")
print("store B, by road                : " + str(store_b_road_km) + " km")
print("")
print("chosen by straight line         : A")
print("nearest by road                 : B")
print("A understated by straight line  : " + str(a_understated_per_myriad) + " per ten thousand")
print("extra road per delivery         : " + str(extra_road_km_per_delivery) + " km")
print("extra road over all deliveries  : " + str(extra_road_km_total) + " km")
print("")
print("the nearest-store choice")
print("  reads : the real coordinates of customer and every store")
print("  distance : a true great-circle distance, not a flat one")
print("  compares : every store")
print("  intent : the store closest to the customer")
print("  stores skipped : 0")
print("  verdict : A IS CLOSEST, AT 1 KM")
print("")
print("  using a true great-circle distance over every store is the")
print("  part done right here, and it is why 1 km is exactly how")
print("  far apart the two points are")
print("")
print("straight line and road")
print("  what the straight line answers : how far apart two points")
print("    are")
print("  what the delivery needs : how far a van must drive")
print("  what lies between customer and A : a river, bridged five")
print("    kilometres away")
print("  so A by road : " + str(store_a_road_km) + " km, from a straight line of " + str(store_a_straight_line_km))
print("  and B by road : " + str(store_b_road_km) + " km, from a straight line of " + str(store_b_straight_line_km))
print("")
print("the dispatch")
print("  store chosen : A, " + str(store_a_road_km) + " km by road")
print("  store nearest by road : B, " + str(store_b_road_km) + " km")
print("  extra driving per delivery : " + str(extra_road_km_per_delivery) + " km")
print("  is the great-circle distance wrong : no; it is exact")
print("  is it the distance a van drives : no; the river is not on")
print("    a great circle")
print("")
nc_a_km_by_straight_line = 1
nc_a_km_by_road = 11
nc_picks_b_once_routed = 1
print("null control - choose by road-network distance")
print("  A by straight line : " + str(nc_a_km_by_straight_line) + " km")
print("  A by road : " + str(nc_a_km_by_road) + " km")
print("  picks B once routed : " + str(nc_picks_b_once_routed))
print("  no store and no coordinate changed; the distance stopped")
print("  being the one between the points and started being the")
print("  one along the roads")
print("")
print("what a nearest-by-great-circle choice guarantees")
print("  the chosen store is the closest as the crow flies :")
print("    exactly, true distance over every store")
print("  the chosen store is the closest to deliver from : not")
print("    addressed; a river with a distant bridge makes A's road")
print("    distance " + str(store_a_road_km) + " km from a straight line of " + str(store_a_straight_line_km) + ", so the")
print("    farther-by-crow B at " + str(store_b_road_km) + " km by road was the real nearest")
print("")
print("distance between two points and distance along the ways between them are")
print("different quantities, and the second is what anything that has to travel pays;")
print("a barrier the straight line crosses freely is the whole difference")
print("")
print("It uses a true great-circle distance over every store - A really is 1 km away.")
print("But a river with the bridge five kilometres off makes A " + str(store_a_road_km) + " km by road,")
print("" + str(a_understated_per_myriad) + " per ten thousand understated, while B is " + str(store_b_road_km) + " km; " + str(deliveries_routed_to_a) + " deliveries")
print("drove " + str(extra_road_km_total) + " extra km, until the choice was made on road distance.")
```

## stdout (executed)

```text
store A, straight line          : 1 km
store A, by road                : 11 km
store B, straight line          : 3 km
store B, by road                : 4 km

chosen by straight line         : A
nearest by road                 : B
A understated by straight line  : 9090 per ten thousand
extra road per delivery         : 7 km
extra road over all deliveries  : 140000 km

the nearest-store choice
  reads : the real coordinates of customer and every store
  distance : a true great-circle distance, not a flat one
  compares : every store
  intent : the store closest to the customer
  stores skipped : 0
  verdict : A IS CLOSEST, AT 1 KM

  using a true great-circle distance over every store is the
  part done right here, and it is why 1 km is exactly how
  far apart the two points are

straight line and road
  what the straight line answers : how far apart two points
    are
  what the delivery needs : how far a van must drive
  what lies between customer and A : a river, bridged five
    kilometres away
  so A by road : 11 km, from a straight line of 1
  and B by road : 4 km, from a straight line of 3

the dispatch
  store chosen : A, 11 km by road
  store nearest by road : B, 4 km
  extra driving per delivery : 7 km
  is the great-circle distance wrong : no; it is exact
  is it the distance a van drives : no; the river is not on
    a great circle

null control - choose by road-network distance
  A by straight line : 1 km
  A by road : 11 km
  picks B once routed : 1
  no store and no coordinate changed; the distance stopped
  being the one between the points and started being the
  one along the roads

what a nearest-by-great-circle choice guarantees
  the chosen store is the closest as the crow flies :
    exactly, true distance over every store
  the chosen store is the closest to deliver from : not
    addressed; a river with a distant bridge makes A's road
    distance 11 km from a straight line of 1, so the
    farther-by-crow B at 4 km by road was the real nearest

distance between two points and distance along the ways between them are
different quantities, and the second is what anything that has to travel pays;
a barrier the straight line crosses freely is the whole difference

It uses a true great-circle distance over every store - A really is 1 km away.
But a river with the bridge five kilometres off makes A 11 km by road,
9090 per ten thousand understated, while B is 4 km; 20000 deliveries
drove 140000 extra km, until the choice was made on road distance.
```

## Round-trip

`ok: true` — round-trip fixpoint reached (python1 == python2)

## Trace event types

eml:run:start · eml:assign · eml:output · eml:run:done
