GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Kuiper, cosmos and drawing engines / cosmic / tools/explore/periodic/furnace/positron

Positron Core and 26 more files

A Python module in the furnace folder of Cosmic that reads build graph. It loads graph (`load_graph`) and runs element (`run_element`).

688 lines of Python from cosmic, in 27 files. Topic: Kuiper, cosmos and drawing engines. Section 1119 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. P76 transform · cosmic / tools/explore/periodic/furnace/positron/p76.py lines 1–8
  2. P77 transform · cosmic / tools/explore/periodic/furnace/positron/p77.py lines 1–8
  3. P78 transform · cosmic / tools/explore/periodic/furnace/positron/p78.py lines 1–8
  4. P79 transform · cosmic / tools/explore/periodic/furnace/positron/p79.py lines 1–8
  5. P8 transform · cosmic / tools/explore/periodic/furnace/positron/p8.py lines 1–8
  6. P80 transform · cosmic / tools/explore/periodic/furnace/positron/p80.py lines 1–8
  7. P81 transform · cosmic / tools/explore/periodic/furnace/positron/p81.py lines 1–8
  8. P82 transform · cosmic / tools/explore/periodic/furnace/positron/p82.py lines 1–8
  9. P83 transform · cosmic / tools/explore/periodic/furnace/positron/p83.py lines 1–8
  10. P84 transform · cosmic / tools/explore/periodic/furnace/positron/p84.py lines 1–8
  11. P85 transform · cosmic / tools/explore/periodic/furnace/positron/p85.py lines 1–8
  12. P86 transform · cosmic / tools/explore/periodic/furnace/positron/p86.py lines 1–8
  13. P87 transform · cosmic / tools/explore/periodic/furnace/positron/p87.py lines 1–8
  14. P88 transform · cosmic / tools/explore/periodic/furnace/positron/p88.py lines 1–8
  15. P89 transform · cosmic / tools/explore/periodic/furnace/positron/p89.py lines 1–8
  16. P9 transform · cosmic / tools/explore/periodic/furnace/positron/p9.py lines 1–8
  17. P90 transform · cosmic / tools/explore/periodic/furnace/positron/p90.py lines 1–8
  18. P91 transform · cosmic / tools/explore/periodic/furnace/positron/p91.py lines 1–8
  19. P92 transform · cosmic / tools/explore/periodic/furnace/positron/p92.py lines 1–8
  20. P93 transform · cosmic / tools/explore/periodic/furnace/positron/p93.py lines 1–8
  21. P94 transform · cosmic / tools/explore/periodic/furnace/positron/p94.py lines 1–8
  22. P95 transform · cosmic / tools/explore/periodic/furnace/positron/p95.py lines 1–8
  23. P96 transform · cosmic / tools/explore/periodic/furnace/positron/p96.py lines 1–8
  24. P97 transform · cosmic / tools/explore/periodic/furnace/positron/p97.py lines 1–8
  25. P98 transform · cosmic / tools/explore/periodic/furnace/positron/p98.py lines 1–8
  26. P99 transform · cosmic / tools/explore/periodic/furnace/positron/p99.py lines 1–8
  27. Positron Core ingest · cosmic / tools/explore/periodic/furnace/positron/positron_core.py lines 1–480

P76

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p76.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p76 (ANTIPODE-26): independent second computation for Z=76; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p76.py:1-8 · blob ab9eeaaa58a2d01e8130fed3dd4e1423e65a4145 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p76 (ANTIPODE-26): independent second computation for Z=76; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(76, ctx, xp)

P77

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p77.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p77 (ANTIPODE-26): independent second computation for Z=77; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p77.py:1-8 · blob c7cc09d459aaa597fcc5a3cb2c5e5540185e4c03 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p77 (ANTIPODE-26): independent second computation for Z=77; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(77, ctx, xp)

P78

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p78.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p78 (ANTIPODE-26): independent second computation for Z=78; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p78.py:1-8 · blob 298582141305fd0a6a5ff8917a9e7c6d4412dc18 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p78 (ANTIPODE-26): independent second computation for Z=78; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(78, ctx, xp)

P79

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p79.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p79 (ANTIPODE-26): independent second computation for Z=79; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p79.py:1-8 · blob 34c5b927671f69986661053256a7657a65c240e8 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p79 (ANTIPODE-26): independent second computation for Z=79; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(79, ctx, xp)

P8

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p8.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p8 (ANTIPODE-26): independent second computation for Z=8; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p8.py:1-8 · blob 631fa7413b524ceb39a8553d5f066aad2bb73beb · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p8 (ANTIPODE-26): independent second computation for Z=8; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(8, ctx, xp)

P80

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p80.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p80 (ANTIPODE-26): independent second computation for Z=80; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p80.py:1-8 · blob 8add6cb444b9b4325d929e0f88c56607f879bbf7 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p80 (ANTIPODE-26): independent second computation for Z=80; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(80, ctx, xp)

P81

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p81.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p81 (ANTIPODE-26): independent second computation for Z=81; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p81.py:1-8 · blob f7fd1af7eb517dd5b2142edfc2166c2fe3e98c18 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p81 (ANTIPODE-26): independent second computation for Z=81; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(81, ctx, xp)

P82

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p82.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p82 (ANTIPODE-26): independent second computation for Z=82; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p82.py:1-8 · blob edad1c9944758c5543ad02709424768f250ffc01 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p82 (ANTIPODE-26): independent second computation for Z=82; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(82, ctx, xp)

P83

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p83.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p83 (ANTIPODE-26): independent second computation for Z=83; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p83.py:1-8 · blob b332f27b1b7afdeff1b0cfe0d3ad9ce84abc0a7a · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p83 (ANTIPODE-26): independent second computation for Z=83; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(83, ctx, xp)

P84

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p84.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p84 (ANTIPODE-26): independent second computation for Z=84; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p84.py:1-8 · blob 0198caab24a663bffaeab07e1d600c5206640a97 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p84 (ANTIPODE-26): independent second computation for Z=84; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(84, ctx, xp)

P85

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p85.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p85 (ANTIPODE-26): independent second computation for Z=85; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p85.py:1-8 · blob 8a93251ea47afac80c661bb76bb0f692601126d0 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p85 (ANTIPODE-26): independent second computation for Z=85; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(85, ctx, xp)

P86

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p86.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p86 (ANTIPODE-26): independent second computation for Z=86; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p86.py:1-8 · blob 107f7805aaa2b8f8fb1d8dad25925e793fcbbe80 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p86 (ANTIPODE-26): independent second computation for Z=86; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(86, ctx, xp)

P87

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p87.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p87 (ANTIPODE-26): independent second computation for Z=87; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p87.py:1-8 · blob cde2e52cef44fd9494bac208a007ab875941a199 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p87 (ANTIPODE-26): independent second computation for Z=87; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(87, ctx, xp)

P88

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p88.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p88 (ANTIPODE-26): independent second computation for Z=88; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p88.py:1-8 · blob 48c40ebe7e32366231cffc650a2a0ed17791278a · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p88 (ANTIPODE-26): independent second computation for Z=88; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(88, ctx, xp)

P89

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p89.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p89 (ANTIPODE-26): independent second computation for Z=89; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p89.py:1-8 · blob 97bb9f932bff2150adabfe6ca00b47d9f160143c · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p89 (ANTIPODE-26): independent second computation for Z=89; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(89, ctx, xp)

P9

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p9.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p9 (ANTIPODE-26): independent second computation for Z=9; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p9.py:1-8 · blob 30e885cece4b00d335336629607c513fb3f8da6c · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p9 (ANTIPODE-26): independent second computation for Z=9; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(9, ctx, xp)

P90

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p90.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p90 (ANTIPODE-26): independent second computation for Z=90; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p90.py:1-8 · blob 24e95b0e8eaede575f44256ce72dc0cb15d0275e · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p90 (ANTIPODE-26): independent second computation for Z=90; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(90, ctx, xp)

P91

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p91.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p91 (ANTIPODE-26): independent second computation for Z=91; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p91.py:1-8 · blob 911fbc47ab67d8722ac6ff9ed609f1928d6823ef · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p91 (ANTIPODE-26): independent second computation for Z=91; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(91, ctx, xp)

P92

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p92.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p92 (ANTIPODE-26): independent second computation for Z=92; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p92.py:1-8 · blob 2b80e07024447273edb50b229b0d16b11127e505 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p92 (ANTIPODE-26): independent second computation for Z=92; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(92, ctx, xp)

P93

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p93.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p93 (ANTIPODE-26): independent second computation for Z=93; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p93.py:1-8 · blob fc6ad957bcef9a17b9f299403caf6b22f67b5c4e · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p93 (ANTIPODE-26): independent second computation for Z=93; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(93, ctx, xp)

P94

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p94.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p94 (ANTIPODE-26): independent second computation for Z=94; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p94.py:1-8 · blob 1c80b8556f7c1fb93212dbb48d8889252241db2f · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p94 (ANTIPODE-26): independent second computation for Z=94; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(94, ctx, xp)

P95

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p95.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p95 (ANTIPODE-26): independent second computation for Z=95; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p95.py:1-8 · blob 6ed840daf116e2dcbcbda644443b0c74cdefba2d · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p95 (ANTIPODE-26): independent second computation for Z=95; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(95, ctx, xp)

P96

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p96.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p96 (ANTIPODE-26): independent second computation for Z=96; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p96.py:1-8 · blob 265694accb7ac927685e32d9c64c4b91b63e7eb4 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p96 (ANTIPODE-26): independent second computation for Z=96; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(96, ctx, xp)

P97

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p97.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p97 (ANTIPODE-26): independent second computation for Z=97; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p97.py:1-8 · blob 811654b6e113e85fcaf43d696b41a6c59759df23 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p97 (ANTIPODE-26): independent second computation for Z=97; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(97, ctx, xp)

P98

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p98.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p98 (ANTIPODE-26): independent second computation for Z=98; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p98.py:1-8 · blob 6f47ecffd94de9536bf5f1083871afa24585024d · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p98 (ANTIPODE-26): independent second computation for Z=98; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(98, ctx, xp)

P99

A Python module in the positron folder of Cosmic. It is built from the run step (`run`).

transformcosmic / tools/explore/periodic/furnace/positron/p99.py · lines 1–8 of 8 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines run.
What it achieves
POSITRON p99 (ANTIPODE-26): independent second computation for Z=99; see `positron_core.py` and `electron/GRID.md`.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
Positron Core (import)
Used by
none found
Produces
run
Defines here
run
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/p99.py:1-8 · blob 5d816edd1d3c4d840e9300c0db8460f4fd900662 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: unknown · users: none · canonical: unreached_review
"""POSITRON p99 (ANTIPODE-26): independent second computation for Z=99; see positron_core.py and electron/GRID.md."""
from positron_core import run_element

EVIDENCE = ["build_graph.json:edges", "build_graph.json:files[]", "electron/GRID.md"]


def run(ctx, xp):
    return run_element(99, ctx, xp)

Positron Core

A Python module in the furnace folder of Cosmic that reads build graph. It loads graph (`load_graph`) and runs element (`run_element`).

ingestcosmic / tools/explore/periodic/furnace/positron/positron_core.py · lines 1–480 of 480 · pattern fam_isolation (shared by 2 files)

What it does
It loads build graph. Defines 46 functions or classes, including _graph_path, load_graph, element_of, _layout_from_z, View. Uses libraries __future__, json, os, collections, fractions. Side effects: reads or writes files.
Inputs & outputs
In: JSON file build_graph.json.
Downstream impact
Used directly by 119 files: P1 (cosmic); P10 (cosmic); P100 (cosmic); P101 (cosmic); and 115 more.
What it achieves
POSITRON core (ANTIPODE-26): an independent second computation of the 118 furnace experiments.
Why it matters
Imported by 118 files, including P1, P10 and P100. Checked by Test Positron.
Application
cosmic · tools/explore/periodic/furnace/positron · Python module
Uses
__future__, json, os, collections, fractions, math
Used by
imported by P1 (import), imported by P10 (import), imported by P100 (import), imported by P101 (import), imported by P102 (import), imported by P103 (import), imported by P104 (import), imported by P105 (import), and 111 more
Produces
load_graph, element_of, View, ranked, share, bfs_within, fam_fanout, fam_fanin, fam_forward_reach, fam_impact, fam_weak_components, fam_short_cycles
Defines here
_graph_path, load_graph, element_of, _layout_from_z, View, __init__, outdeg, indeg, total, _view, ranked, share, bfs_within, fam_fanout, fam_fanin, fam_forward_reach, fam_impact, fam_weak_components, find, fam_short_cycles, fam_folder_crossing, _common_prefix, fam_folder_distance, fam_role_cohesion, fam_domain_crossing, fam_dup_by_role, gini_pairwise, fam_gini, language_rank, fam_lang_crossing
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/periodic/furnace/positron/positron_core.py:1-480 · blob 88ffeff3e572c332e823a9c2143b03b9a3acfeca · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: ingest · effects: filesystem · domain stage: unknown · users: none · canonical: unknown
"""POSITRON core (ANTIPODE-26): an independent second computation of the 118 furnace experiments.

Written from electron/GRID.md only; the electron's code was not read. Method differences on purpose:
- parses build_graph.json itself (pure Python json), never the furnace's xp arrays, so a ctx loading
  bug shows up as an annihilation instead of being shared by both channels;
- edges are a Python set of (a, b) tuples; adjacency is dict-of-sets; no matrices, no numpy;
- BFS with collections.deque and explicit distance dicts (electron: boolean frontier arrays);
- weak components by union-find with path halving and union by size (electron: label propagation);
- short cycles by one BFS per file measuring the shortest closed walk dist(v -> v) (electron: batched);
- Gini by the mean absolute pairwise difference, sum |xi - xj| / (2 m^2 mean), in exact integers
  (electron: the ranked formula 2 sum i x(i) / (m sum x) - (m+1)/m);
- shares and medians in fractions.Fraction, converted to float only at the end;
- signature width by a character scanner, word ranks by a sort over (-count, first_seen) keys.

Ambiguities in GRID.md are recorded in AMBIGUITIES.md; where a choice is needed, the choice is named here.
"""
from __future__ import annotations

import json
import os
from collections import deque
from fractions import Fraction

DEFAULT_GRAPH = "/tmp/site8/explore-code/build_graph.json"

# GRID.md "block" row (electron's mapping, deliberately not ctx["block_kinds"]).
BLOCK_KINDS = {
    "s": ("script-src", "stylesheet", "iframe", "modulepreload", "import-map"),
    "p": ("import", "python-relative", "sys-path", "require", "dynamic-import", "url-import-meta"),
    "d": ("workflow-run", "script-call", "worker"),
    "f": ("link", "estate-url", "fetch", "comment-url"),
}
BLOCK_LABEL = {"s": "page-load", "p": "code-import", "d": "run/orchestration", "f": "reference"}

_CACHE: dict = {}


# ----------------------------------------------------------------------------------------- loading
def _graph_path(ctx) -> str:
    for p in (ctx.get("inputs") or {}):
        if str(p).endswith("build_graph.json") and os.path.exists(str(p)):
            return str(p)
    return ctx.get("graph_path") or DEFAULT_GRAPH


def load_graph(ctx) -> dict:
    """The raw build_graph dict: ctx["graph"] (tests) or the file named in ctx["inputs"]."""
    if isinstance(ctx.get("graph"), dict):
        return ctx["graph"]
    path = _graph_path(ctx)
    st = os.stat(path)
    key = (path, st.st_size, st.st_mtime_ns)
    if key not in _CACHE:
        _CACHE.clear()
        with open(path, "r", encoding="utf-8") as fh:
            _CACHE[key] = json.load(fh)
    return _CACHE[key]


def element_of(ctx, z: int) -> dict:
    el = dict(ctx.get("element") or {})
    if not el or el.get("period") is None or el.get("block") is None:
        el.update(_layout_from_z(z))
    el.setdefault("Z", z)
    return el


def _layout_from_z(z: int) -> dict:
    """IUPAC layout from Z alone (fallback only; Lu, Lr in group 3, La-Yb / Ac-No in f rows)."""
    starts = [(1, 1), (3, 2), (11, 3), (19, 4), (37, 5), (55, 6), (87, 7), (119, 8)]
    period = max(p for s, p in starts if z >= s)
    first = dict((p, s) for s, p in starts)[period]
    pos = z - first + 1
    if period == 1:
        return {"period": 1, "group": 1 if z == 1 else 18, "block": "s"}
    if period in (6, 7):
        if pos <= 2:
            return {"period": period, "group": pos, "block": "s"}
        if 3 <= pos <= 16:
            return {"period": period, "group": None, "block": "f"}
        pos -= 14
    if period <= 3:
        group = pos if pos <= 2 else pos + 10
    else:
        group = pos
    block = "s" if group <= 2 else ("d" if group <= 12 else "p")
    return {"period": period, "group": group, "block": block}


# ----------------------------------------------------------------------------------------- graph views
class View:
    """Everything one block needs, built with sets and dicts."""

    def __init__(self, g: dict, block: str):
        files = g["files"]
        self.files = files
        self.n = len(files)
        kinds = set(BLOCK_KINDS[block])
        pairs = set()
        for e in g["edges"]:
            a, b, kind = e[0], e[1], e[2]
            if kind in kinds and a != b:
                pairs.add((a, b))
        self.pairs = sorted(pairs)
        self.out = {}
        self.inn = {}
        for a, b in self.pairs:
            self.out.setdefault(a, set()).add(b)
            self.inn.setdefault(b, set()).add(a)

    def outdeg(self, i):
        return len(self.out.get(i, ()))

    def indeg(self, i):
        return len(self.inn.get(i, ()))

    def total(self, i):
        return self.outdeg(i) + self.indeg(i)


def _view(g, block):
    key = ("view", id(g), block)
    if key not in _CACHE:
        _CACHE[key] = View(g, block)
    return _CACHE[key]


def ranked(ids, score):
    """GRID ranking: score descending, then file id ascending."""
    return sorted(ids, key=lambda i: (-score(i), i))


def share(hits: int, den: int) -> float:
    return float(Fraction(hits, den)) if den else 0.0


def bfs_within(adj: dict, sources, hops: int) -> set:
    """All nodes at distance 1..hops from any source (sources themselves only if re-reached)."""
    dist = {s: 0 for s in sources}
    q = deque(sources)
    reached = set()
    while q:
        u = q.popleft()
        du = dist[u]
        if du == hops:
            continue
        for w in adj.get(u, ()):
            reached.add(w)
            if w not in dist:
                dist[w] = du + 1
                q.append(w)
    return reached


# ----------------------------------------------------------------------------------------- families
def fam_fanout(g, v, d, **_):
    return sum(1 for i in range(v.n) if v.outdeg(i) >= d)


def fam_fanin(g, v, d, **_):
    return sum(1 for i in range(v.n) if v.indeg(i) >= d)


def fam_forward_reach(g, v, d, z, **_):
    have_out = [i for i in range(v.n) if v.outdeg(i) > 0]
    k = min(z, len(have_out))
    seeds = ranked(have_out, v.outdeg)[:k]
    reached = bfs_within(v.out, seeds, d)
    return len(reached - set(seeds))


def fam_impact(g, v, d, **_):
    rank = d - 3  # 1-based (period 4 -> top hub)
    order = ranked(range(v.n), v.indeg)
    hub = order[rank - 1]
    reached = bfs_within(v.inn, [hub], d)
    reached.discard(hub)
    return len(reached)


def fam_weak_components(g, v, d, **_):
    parent = list(range(v.n))
    size = [1] * v.n

    def find(x):
        while parent[x] != x:
            parent[x] = parent[parent[x]]
            x = parent[x]
        return x

    for a, b in v.pairs:
        ra, rb = find(a), find(b)
        if ra != rb:
            if size[ra] < size[rb]:
                ra, rb = rb, ra
            parent[rb] = ra
            size[ra] += size[rb]
    return sum(1 for i in range(v.n) if parent[i] == i and size[i] >= d + 1)


def fam_short_cycles(g, v, d, **_):
    L = max(2, d - 2)
    count = 0
    for s in sorted(v.out):
        # shortest closed walk through s: 1 + min dist(w -> s) over successors w
        dist = {}
        q = deque()
        for w in v.out[s]:
            if w not in dist:
                dist[w] = 1
                q.append(w)
        found = False
        while q:
            u = q.popleft()
            if u == s:
                found = dist[u] <= L
                break
            if dist[u] >= L:
                continue
            for w in v.out.get(u, ()):
                if w not in dist:
                    dist[w] = dist[u] + 1
                    q.append(w)
        if found:
            count += 1
    return count


def fam_folder_crossing(g, v, d, **_):
    lv = max(1, d - 2)
    fh = [tuple(f["folder_hierarchy"]) for f in v.files]
    hits = sum(1 for a, b in v.pairs if fh[a][:lv] != fh[b][:lv])
    return share(hits, len(v.pairs))


def _common_prefix(x, y):
    c = 0
    for p, q in zip(x, y):
        if p != q:
            break
        c += 1
    return c


def fam_folder_distance(g, v, d, **_):
    fh = [f["folder_hierarchy"] for f in v.files]
    hits = 0
    for a, b in v.pairs:
        x, y = fh[a], fh[b]
        if len(x) + len(y) - 2 * _common_prefix(x, y) <= d:
            hits += 1
    return share(hits, len(v.pairs))


def fam_role_cohesion(g, v, d, **_):
    R = g["roles"][d - 1]["id"]
    role = [f["role"] for f in v.files]
    from_r = [(a, b) for a, b in v.pairs if role[a] == R]
    return share(sum(1 for a, b in from_r if role[b] == R), len(from_r))


def fam_domain_crossing(g, v, d, **_):
    D = g["domain_stages"][d - 1]["id"]
    ds = [f["domain_stage"] for f in v.files]
    return sum(1 for a, b in v.pairs if ds[a] == D and ds[b] != D)


def fam_dup_by_role(g, v, d, **_):
    R = g["roles"][d - 1]["id"]
    members = [f for f in v.files if f["role"] == R]
    return share(sum(1 for f in members if f["duplicate_of"] is not None), len(members))


def gini_pairwise(xs) -> float:
    """Mean absolute difference form, exact: sum_i sum_j |xi - xj| / (2 m^2 mean)."""
    m = len(xs)
    tot = sum(xs)
    if m == 0 or tot == 0:
        return 0.0
    # sum over unordered pairs of |xi - xj|, via counting how many values each value exceeds.
    # (computed by a running sum over a sorted copy; ordered-pair sum = 2 * unordered)
    s = sorted(xs)
    unordered = 0
    running = 0
    for j, x in enumerate(s):
        unordered += x * j - running
        running += x
    return float(Fraction(2 * unordered, 2 * m * tot))  # = sum|xi-xj| / (2 m^2 mean), m*mean = tot


def fam_gini(g, v, d, **_):
    floor = max(1, d - 3)
    xs = [f["lines"] for i, f in enumerate(v.files) if v.total(i) >= floor]
    return gini_pairwise(xs)


def language_rank(g):
    counts, first = {}, {}
    for idx, f in enumerate(g["files"]):
        counts[f["lang"]] = counts.get(f["lang"], 0) + 1
        first.setdefault(f["lang"], idx)
    return sorted(counts, key=lambda L: (-counts[L], first[L]))


def fam_lang_crossing(g, v, d, **_):
    langs = language_rank(g)
    r = d - 2  # 0-based: see AMBIGUITIES.md A3
    if r >= len(langs):
        return 0.0
    L = langs[r]
    lang = [f["lang"] for f in v.files]
    from_l = [(a, b) for a, b in v.pairs if lang[a] == L]
    return share(sum(1 for a, b in from_l if lang[b] != L), len(from_l))


def median_fraction(vals):
    s = sorted(vals)
    m = len(s)
    if m == 0:
        return 0.0
    if m % 2:
        return float(s[m // 2])
    return float((s[m // 2 - 1] + s[m // 2]) / 2)


def fam_def_density(g, v, d, **_):
    floor = 10 * 2 ** (d - 1)
    vals = [Fraction(len(f["defines"]) * 100, max(f["lines"], 1))
            for i, f in enumerate(v.files) if f["lines"] >= floor and v.total(i) > 0]
    return median_fraction(vals)


def fam_hub_purity(g, v, d, **_):
    hubs = [i for i in range(v.n) if v.indeg(i) >= d]
    return share(sum(1 for i in hubs if v.files[i]["pure"] is True), len(hubs))


def fam_unreachable_depth(g, v, d, period, **_):
    def depth_ok(f):
        dep = len(f["folder_hierarchy"]) - 1
        return dep >= 5 if period == 7 else dep == d - 2

    sel = [i for i, f in enumerate(v.files) if depth_ok(f) and v.total(i) > 0]
    return share(sum(1 for i in sel if v.files[i]["reachable"] is False), len(sel))


def fam_status_pairing(g, v, d, period, **_):
    st = [f["canonical_status"] for f in v.files]
    if period == 7:
        hits = sum(1 for a, b in v.pairs if st[a] == st[b])
    else:
        S = g["canonical_statuses"][(d - 2) % 5]
        hits = sum(1 for a, b in v.pairs if st[a] == S and st[b] == S)
    return share(hits, len(v.pairs))


def fam_isolation(g, v, d, **_):
    R = g["roles"][d - 1]["id"]
    members = [i for i, f in enumerate(v.files) if f["role"] == R]
    return share(sum(1 for i in members if v.total(i) == 0), len(members))


OPEN, CLOSE = set("([{<"), set(")]}>")


def param_count(sig: str) -> int:
    lo, hi = sig.find("("), sig.rfind(")")
    if lo < 0 or hi < 0 or hi <= lo:
        inner = ""
    else:
        inner = sig[lo + 1:hi]
    inner = inner.strip()
    if not inner:
        return 0
    depth, commas = 0, 0
    for ch in inner:
        if ch in OPEN:
            depth += 1
        elif ch in CLOSE:
            depth -= 1  # literal reading: not clamped at 0 (AMBIGUITIES.md A7)
        elif ch == "," and depth == 0:
            commas += 1
    return 1 + commas


def width(f) -> int:
    sigs = f.get("signatures") or []
    return max((param_count(s) for s in sigs), default=-1)


def fam_signature(g, v, d, z, **_):
    i = z - 56
    t = (i + 1) // 2
    L = "JavaScript" if i % 2 == 1 else "Python"
    return sum(1 for f in g["files"] if f["lang"] == L and width(f) >= t)


def word_rank(g):
    counts, first, seen = {}, {}, 0
    for f in g["files"]:  # files in id order
        for w in sorted(set(f.get("name_words") or [])):
            if any(c.isdigit() for c in w):
                continue
            if w not in counts:
                counts[w] = 0
                first[w] = seen
                seen += 1
            counts[w] += 1
    return sorted(counts, key=lambda w: (-counts[w], first[w])), counts


def fam_vocabulary(g, v, d, z, **_):
    i = z - 88
    words, counts = word_rank(g)
    W = words[i - 1]
    return sum(1 for f in g["files"] if W in (f.get("name_words") or []))


FAMILIES = {
    1: fam_fanout, 2: fam_fanin, 3: fam_forward_reach, 4: fam_impact, 5: fam_weak_components,
    6: fam_short_cycles, 7: fam_folder_crossing, 8: fam_folder_distance, 9: fam_role_cohesion,
    10: fam_domain_crossing, 11: fam_dup_by_role, 12: fam_gini, 13: fam_lang_crossing,
    14: fam_def_density, 15: fam_hub_purity, 16: fam_unreachable_depth, 17: fam_status_pairing,
    18: fam_isolation, "L": fam_signature, "A": fam_vocabulary,
}

FAMILY_NAME = {
    1: "fan-out", 2: "fan-in", 3: "forward reach", 4: "impact", 5: "weak components",
    6: "short cycles", 7: "folder boundary crossing", 8: "folder distance", 9: "role cohesion",
    10: "domain stage crossing", 11: "duplication by role", 12: "size inequality",
    13: "language crossing", 14: "definition density", 15: "purity of hubs",
    16: "unreachable by depth", 17: "status pairing", 18: "isolation by role",
    "L": "signature width", "A": "name vocabulary",
}


def family_of(el) -> object:
    if el.get("group") is None:
        return "L" if el["period"] == 6 else "A"
    return int(el["group"])


def compute(z: int, g: dict, el: dict):
    fam = family_of(el)
    d = int(el["period"])
    v = _view(g, el["block"])
    value = FAMILIES[fam](g, v, d, z=z, period=d)
    return fam, value


# ----------------------------------------------------------------------------------------- picture
def picture(z: int, fam, value) -> list:
    """A small positron mark: a ring whose filled arc encodes a share, or a digit label for counts."""
    prims = [{"t": "circle", "x": 50, "y": 50, "r": 30, "c": "line", "fill": False}]
    if isinstance(value, float) and 0.0 <= value <= 1.0:
        import math
        steps = max(1, int(round(value * 36)))
        pts = [[50.0, 50.0]]
        for s in range(steps + 1):
            ang = -math.pi / 2 + 2 * math.pi * value * s / steps
            pts.append([round(50 + 30 * math.cos(ang), 3), round(50 + 30 * math.sin(ang), 3)])
        if value > 0:
            prims.append({"t": "poly", "pts": pts, "c": "blue", "fill": True})
        label = "%.3f" % value
    else:
        label = str(value) if isinstance(value, int) else "%.3f" % value
    prims.append({"t": "text", "x": 50, "y": 92, "s": "p%d %s" % (z, label), "c": "white", "h": 7})
    return prims


def run_element(z: int, ctx, xp=None) -> dict:
    g = load_graph(ctx)
    el = element_of(ctx, z)
    fam, value = compute(z, g, el)
    return {
        "value": value,
        "picture": picture(z, fam, value),
        "family": fam,
        "measures": "positron: %s (%s edges, d=%d)" % (FAMILY_NAME[fam], BLOCK_LABEL[el["block"]], el["period"]),
    }