Case 876

The radius was a square

the_radius_was_a_square.eml - A locator lists the stores within 10 km of a customer, and it applies its filter to the real coordinates of every store. What shape 'within 10 km' was implemented as is computed below.

ok: true — round-trip fixpoint reached (python1 == python2)updated 2026-09-16

EML

eml
# Self-authored for the EML case corpus (no external origin). A locator lists the
# stores within 10 km of a customer, and it applies its filter to the real
# coordinates of every store. What shape 'within 10 km' was implemented as is
# computed below.
#
# The filter is careful. It reads the real coordinates of every store, not a
# cached list; it uses the engine's own range filter on latitude and longitude;
# it checks every store; and the intent is exactly 'the stores within 10 km'.
#
# The filter keeps stores whose latitude and longitude are each within 10 km of
# the customer's, which is a square of half-width 10 km, and a square's corners
# are 14 km from its center.

10 => radius_km
314 => circle_area_km2
14 => corner_distance_km
1 => stores_per_km2

4 * radius_km * radius_km => square_area_km2
square_area_km2 - circle_area_km2 => area_outside_the_radius_km2
circle_area_km2 * stores_per_km2 => stores_truly_within_10_km
square_area_km2 * stores_per_km2 => stores_the_filter_returned
stores_the_filter_returned - stores_truly_within_10_km => stores_wrongly_included
int(stores_wrongly_included * 10000 / stores_the_filter_returned) => wrongly_included_per_myriad

"radius asked for                : " + str(radius_km) + " km" ^0
"area of that circle             : " + str(circle_area_km2) + " km2" ^0
"area the filter covers (square) : " + str(square_area_km2) + " km2" ^0
"farthest point the filter keeps : " + str(corner_distance_km) + " km, the corner" ^0
"" ^0
"stores truly within 10 km       : " + str(stores_truly_within_10_km) ^0
"stores the filter returned      : " + str(stores_the_filter_returned) ^0
"stores wrongly included         : " + str(stores_wrongly_included) ^0
"wrongly included                : " + str(wrongly_included_per_myriad) + " per ten thousand" ^0
"" ^0

# ---- what the filter verified ----

"the within-10-km filter" ^0
"  reads : the real coordinates of every store" ^0
"  uses : the engine's own range filter on lat and lon" ^0
"  checks : every store" ^0
"  intent : the stores within 10 km" ^0
"  stores skipped : 0" ^0
"  verdict : EVERY RETURNED STORE IS WITHIN 10 KM ON EACH AXIS" ^0
"" ^0
"  using the engine's range filter over the real coordinates" ^0
"  of every store is the part done right here, and it is why" ^0
"  no store beyond 10 km on either axis is ever returned" ^0
"" ^0

# ---- what shape the filter is ----

"within 10 km on each axis" ^0
"  what that keeps : latitude within 10 km AND longitude" ^0
"    within 10 km" ^0
"  the shape that describes : a square of half-width 10" ^0
"  the shape 'within 10 km' means : a circle of radius 10" ^0
"  the square's corners : " + str(corner_distance_km) + " km from the center" ^0
"  the area between them : " + str(area_outside_the_radius_km2) + " km2 of the square's " + str(square_area_km2) ^0
"" ^0

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

"the store list" ^0
"  stores within 10 km : " + str(stores_truly_within_10_km) ^0
"  stores listed : " + str(stores_the_filter_returned) ^0
"  listed stores that are 10 to 14 km away : " + str(stores_wrongly_included) ^0
"  is the range filter wrong : no; every listed store is" ^0
"    within 10 km on each axis" ^0
"  is 'each axis within 10' the same as 'within 10' : no; the" ^0
"    corners are where they differ" ^0
"" ^0

# ---- null control ----

# The same filter as a pre-pass, followed by a true distance check that keeps
# only stores at 10 km or less.
400 => nc_stores_after_the_box
314 => nc_stores_after_the_distance_check
86 => nc_corner_stores_the_check_removes

"null control - check the true distance after the box" ^0
"  stores after the box : " + str(nc_stores_after_the_box) ^0
"  stores after the distance check : " + str(nc_stores_after_the_distance_check) ^0
"  corner stores the check removes : " + str(nc_corner_stores_the_check_removes) ^0
"  no store and no coordinate changed; the corners stopped" ^0
"  counting as inside the radius" ^0
"" ^0

# ---- the rule ----

"what a per-axis range filter guarantees" ^0
"  every result is within 10 km north-south and within 10" ^0
"    km east-west : exactly, the engine's own range test" ^0
"  every result is within 10 km : not addressed; two axis" ^0
"    limits make a square, whose corners reach " + str(corner_distance_km) + " km, so" ^0
"    " + str(stores_wrongly_included) + " of the " + str(stores_the_filter_returned) + " listed stores are outside the radius" ^0
"" ^0

"a limit on each axis is a box, and a distance is a circle; the box holds the" ^0
"circle and four corners besides, so 'within r on each axis' admits everything up" ^0
"to r times root two along the diagonals" ^0
"" ^0

"It applies the engine's range filter to the real coordinates of every store -" ^0
"nothing beyond 10 km on either axis comes back. But two axis limits are a" ^0
"square whose corners reach " + str(corner_distance_km) + " km, so " + str(stores_wrongly_included) + " of the " + str(stores_the_filter_returned) + " listed stores are" ^0
"outside the radius, " + str(wrongly_included_per_myriad) + " per ten thousand, until the true distance is checked." ^0

Python (deterministic transpilation)

python
radius_km = 10
circle_area_km2 = 314
corner_distance_km = 14
stores_per_km2 = 1
square_area_km2 = 4 * radius_km * radius_km
area_outside_the_radius_km2 = square_area_km2 - circle_area_km2
stores_truly_within_10_km = circle_area_km2 * stores_per_km2
stores_the_filter_returned = square_area_km2 * stores_per_km2
stores_wrongly_included = stores_the_filter_returned - stores_truly_within_10_km
wrongly_included_per_myriad = int(stores_wrongly_included * 10000 / stores_the_filter_returned)
print("radius asked for                : " + str(radius_km) + " km")
print("area of that circle             : " + str(circle_area_km2) + " km2")
print("area the filter covers (square) : " + str(square_area_km2) + " km2")
print("farthest point the filter keeps : " + str(corner_distance_km) + " km, the corner")
print("")
print("stores truly within 10 km       : " + str(stores_truly_within_10_km))
print("stores the filter returned      : " + str(stores_the_filter_returned))
print("stores wrongly included         : " + str(stores_wrongly_included))
print("wrongly included                : " + str(wrongly_included_per_myriad) + " per ten thousand")
print("")
print("the within-10-km filter")
print("  reads : the real coordinates of every store")
print("  uses : the engine's own range filter on lat and lon")
print("  checks : every store")
print("  intent : the stores within 10 km")
print("  stores skipped : 0")
print("  verdict : EVERY RETURNED STORE IS WITHIN 10 KM ON EACH AXIS")
print("")
print("  using the engine's range filter over the real coordinates")
print("  of every store is the part done right here, and it is why")
print("  no store beyond 10 km on either axis is ever returned")
print("")
print("within 10 km on each axis")
print("  what that keeps : latitude within 10 km AND longitude")
print("    within 10 km")
print("  the shape that describes : a square of half-width 10")
print("  the shape 'within 10 km' means : a circle of radius 10")
print("  the square's corners : " + str(corner_distance_km) + " km from the center")
print("  the area between them : " + str(area_outside_the_radius_km2) + " km2 of the square's " + str(square_area_km2))
print("")
print("the store list")
print("  stores within 10 km : " + str(stores_truly_within_10_km))
print("  stores listed : " + str(stores_the_filter_returned))
print("  listed stores that are 10 to 14 km away : " + str(stores_wrongly_included))
print("  is the range filter wrong : no; every listed store is")
print("    within 10 km on each axis")
print("  is 'each axis within 10' the same as 'within 10' : no; the")
print("    corners are where they differ")
print("")
nc_stores_after_the_box = 400
nc_stores_after_the_distance_check = 314
nc_corner_stores_the_check_removes = 86
print("null control - check the true distance after the box")
print("  stores after the box : " + str(nc_stores_after_the_box))
print("  stores after the distance check : " + str(nc_stores_after_the_distance_check))
print("  corner stores the check removes : " + str(nc_corner_stores_the_check_removes))
print("  no store and no coordinate changed; the corners stopped")
print("  counting as inside the radius")
print("")
print("what a per-axis range filter guarantees")
print("  every result is within 10 km north-south and within 10")
print("    km east-west : exactly, the engine's own range test")
print("  every result is within 10 km : not addressed; two axis")
print("    limits make a square, whose corners reach " + str(corner_distance_km) + " km, so")
print("    " + str(stores_wrongly_included) + " of the " + str(stores_the_filter_returned) + " listed stores are outside the radius")
print("")
print("a limit on each axis is a box, and a distance is a circle; the box holds the")
print("circle and four corners besides, so 'within r on each axis' admits everything up")
print("to r times root two along the diagonals")
print("")
print("It applies the engine's range filter to the real coordinates of every store -")
print("nothing beyond 10 km on either axis comes back. But two axis limits are a")
print("square whose corners reach " + str(corner_distance_km) + " km, so " + str(stores_wrongly_included) + " of the " + str(stores_the_filter_returned) + " listed stores are")
print("outside the radius, " + str(wrongly_included_per_myriad) + " per ten thousand, until the true distance is checked.")

stdout (executed)

text
radius asked for                : 10 km
area of that circle             : 314 km2
area the filter covers (square) : 400 km2
farthest point the filter keeps : 14 km, the corner

stores truly within 10 km       : 314
stores the filter returned      : 400
stores wrongly included         : 86
wrongly included                : 2150 per ten thousand

the within-10-km filter
  reads : the real coordinates of every store
  uses : the engine's own range filter on lat and lon
  checks : every store
  intent : the stores within 10 km
  stores skipped : 0
  verdict : EVERY RETURNED STORE IS WITHIN 10 KM ON EACH AXIS

  using the engine's range filter over the real coordinates
  of every store is the part done right here, and it is why
  no store beyond 10 km on either axis is ever returned

within 10 km on each axis
  what that keeps : latitude within 10 km AND longitude
    within 10 km
  the shape that describes : a square of half-width 10
  the shape 'within 10 km' means : a circle of radius 10
  the square's corners : 14 km from the center
  the area between them : 86 km2 of the square's 400

the store list
  stores within 10 km : 314
  stores listed : 400
  listed stores that are 10 to 14 km away : 86
  is the range filter wrong : no; every listed store is
    within 10 km on each axis
  is 'each axis within 10' the same as 'within 10' : no; the
    corners are where they differ

null control - check the true distance after the box
  stores after the box : 400
  stores after the distance check : 314
  corner stores the check removes : 86
  no store and no coordinate changed; the corners stopped
  counting as inside the radius

what a per-axis range filter guarantees
  every result is within 10 km north-south and within 10
    km east-west : exactly, the engine's own range test
  every result is within 10 km : not addressed; two axis
    limits make a square, whose corners reach 14 km, so
    86 of the 400 listed stores are outside the radius

a limit on each axis is a box, and a distance is a circle; the box holds the
circle and four corners besides, so 'within r on each axis' admits everything up
to r times root two along the diagonals

It applies the engine's range filter to the real coordinates of every store -
nothing beyond 10 km on either axis comes back. But two axis limits are a
square whose corners reach 14 km, so 86 of the 400 listed stores are
outside the radius, 2150 per ten thousand, until the true distance is checked.

Trace event types

eml:run:starteml:assigneml:outputeml:run:done