// verify-the-gasp-that-isnt-for-air.mjs — the arithmetic behind the stratum
// "The Yawn That Was Never About Oxygen" (prose, /strata/the-gasp-that-isnt-for-air/).
//
// The claim the page corrects: the popular "you yawn because you need oxygen" story
// was falsified by a controlled experiment. Provine, Tate & Geldmacher (1987) fed
// people 100% O2 and CO2-rich air; breathing rate rose, yawning did NOT. The page
// also reports the best-supported (but contested) positive account — Gallup &
// Gallup (2007), brain-cooling — with its measured contagious-yawn percentages.
//
// This script restates sourced inputs and calculates selected arithmetic:
//   1. The 1987 conditions stated correctly (3% & 5% CO2, 100% O2, exercise→2× breathing).
//   2. How many times ambient those CO2 levels are (the "~100×" claim), from real
//      atmospheric CO2; computed for 1987 and September 2026, so the
//      "up to ~100×" wording is honest, not rounded into a corner.
//   3. The dissociation: breathing rate moved (e.g. doubled) while yawning's change
//      was not statistically significant; the whole citable check.
//   4. Gallup & Gallup (2007) abstract percentages: nasal 0%, oral ~48%,
//      warm/room-temp pack 41%, cold pack (4 °C) 9% — and the relative drops.
//   5. The publication facts: years, journal volume/pages, the span 1987→2007 = 20 yr,
//      and "decades" since the 1987 falsification (as of the page's 2026 date).
//   6. The honesty bound: cooling is the LEADING but CONTESTED account — stated, not
//      sold as proven; nothing here computes it "true".
//
//   run:  node research/the-gasp-that-isnt-for-air/verify-the-gasp-that-isnt-for-air.mjs
//
// No dependencies. This reads neither the source papers nor the page.
// Study figures and qualitative results below are transcribed inputs, not independent checks.

let fails = 0;
const ok = (name, cond, extra = '') => {
  if (!cond) fails++;
  console.log(`${cond ? '  ok' : 'FAIL'}  ${name}${extra ? '   ' + extra : ''}`);
};
const approx = (a, b, eps) => Math.abs(a - b) <= eps;

// ── 1. The 1987 experimental conditions, stated exactly ──────────────────────
// Provine RR, Tate BC, Geldmacher LL (1987), "Yawning: no effect of 3-5% CO2,
// 100% O2, and exercise," Behavioral and Neural Biology 48(3):382-393. PMID 3120687.
console.log('\n— Provine, Tate & Geldmacher (1987): the conditions —');
const CO2_low_pct = 3;     // % CO2 in the low-CO2 gas mixture
const CO2_high_pct = 5;    // % CO2 in the high-CO2 gas mixture
const O2_pct = 100;        // % O2 (pure oxygen) condition
const breathing_multiple = 2; // exercise sufficient to double breathing rate
console.log(`  CO2 conditions: ${CO2_low_pct}% and ${CO2_high_pct}%;  O2 condition: ${O2_pct}%;  exercise → ${breathing_multiple}× breathing rate`);
ok('CO2 range is 3–5% (the title figure)', CO2_low_pct === 3 && CO2_high_pct === 5);
ok('O2 condition is 100% (pure oxygen)', O2_pct === 100);
ok('exercise doubled breathing rate', breathing_multiple === 2);

// ── 2. How many times "ambient" those CO2 levels are (the "~100×" claim) ─────
// Atmospheric CO2 is a known, dated quantity. The hook says "up to ~100× ambient".
// We compute the multiple against BOTH the 1987 level and September 2026, so the word
// "~100×" is shown to be honest for the 5% mixture and the era of the experiment.
console.log('\n— how many times ambient is the CO2? (the "~100×" wording) —');
const CO2_ambient_1987_ppm = 349;  // rounded from NOAA's 1987 annual mean of 349.31 ppm
const CO2_ambient_2026_ppm = 426.07; // September 2026 Mauna Loa monthly mean, NOAA co2_mm_mlo.txt
const ppm_to_pct = (ppm) => ppm / 1e4;          // 10000 ppm = 1%
const amb87 = ppm_to_pct(CO2_ambient_1987_ppm); // % CO2 in 1987 air
const amb26 = ppm_to_pct(CO2_ambient_2026_ppm); // % CO2 in the September 2026 monthly mean
const mult_5_1987 = CO2_high_pct / amb87;       // 5% vs 1987 ambient
const mult_3_1987 = CO2_low_pct  / amb87;       // 3% vs 1987 ambient
const mult_5_2026 = CO2_high_pct / amb26;       // 5% vs September 2026 Mauna Loa
console.log(`  1987 ambient ≈ ${CO2_ambient_1987_ppm} ppm (${amb87.toFixed(4)}%)`);
console.log(`  5% / 1987 ambient = ${mult_5_1987.toFixed(0)}×   3% / 1987 ambient = ${mult_3_1987.toFixed(0)}×`);
console.log(`  5% / September 2026 Mauna Loa (${CO2_ambient_2026_ppm} ppm) = ${mult_5_2026.toFixed(0)}×`);
// The page says the strongest CO2 mixture was "well over a hundred times" the CO2 in
// ordinary air, and "roughly 100×" as a round headline. Both must be true.
ok('5% CO2 is well over 100× the 1987 ambient (~143×)', mult_5_1987 > 100, `${mult_5_1987.toFixed(0)}×`);
ok('5% CO2 is over 100× September 2026 Mauna Loa (~117×)', mult_5_2026 > 100, `${mult_5_2026.toFixed(0)}×`);
ok('3% CO2 is ~86× the 1987 ambient (so "up to ~100×" across the range is honest)',
   approx(mult_3_1987, 86, 2), `${mult_3_1987.toFixed(0)}×`);
ok('"roughly 100×" is a fair round headline for the CO2 enrichment (range 86–143×)',
   mult_3_1987 < 100 && mult_5_1987 > 100);

// ── 3. The dissociation: breathing changed, yawning didn't ──────────────────
// The citable check is a DISSOCIATION, not a single value: every manipulation that
// SHOULD matter if yawning regulated blood gases (more CO2, pure O2, exercise) moved
// breathing rate, yet none significantly changed yawning. We encode the qualitative
// result the paper reports: a nonzero breathing-rate response vs a null yawn response.
console.log('\n— the dissociation (breathing moved; yawning did not) —');
const breathing_rate_changed = true;  // "both increased breathing rate" (paper)
const yawning_significantly_changed = false; // "no significant effect on yawning" (paper)
ok('breathing rate responded to the manipulations', breathing_rate_changed === true);
ok('yawning did NOT significantly respond — the CO2/O2 hypothesis is rejected',
   yawning_significantly_changed === false);
ok('the two responses are dissociated (the citable refutation)',
   breathing_rate_changed !== yawning_significantly_changed);

// ── 4. Gallup & Gallup (2007) measured percentages ──────────────────────────
// Gallup AC & Gallup GG Jr (2007), "Yawning as a Brain Cooling Mechanism: Nasal
// Breathing and Forehead Cooling Diminish the Incidence of Contagious Yawning,"
// Evolutionary Psychology 5(1):92-101. Abstract figures, quoted verbatim:
//   oral / undirected breathing → ~48% contagious yawning
//   nasal breathing            →   0%
//   warm (46 °C) OR room-temp pack → 41%
//   cold (4 °C) pack           →   9%
console.log('\n— Gallup & Gallup (2007): measured contagious-yawn percentages —');
const yawn_oral_pct = 48;       // "about 48%"
const yawn_nasal_pct = 0;       // "no participants exhibited contagious yawning"
const yawn_warm_or_room_pct = 41; // warm 46 °C OR room-temp pack
const yawn_cold_pct = 9;        // cold 4 °C pack
const T_warm_C = 46, T_cold_C = 4, T_room_ref = 'room';
console.log(`  oral/undirected: ${yawn_oral_pct}%   nasal: ${yawn_nasal_pct}%`);
console.log(`  warm(${T_warm_C}°C)/room pack: ${yawn_warm_or_room_pct}%   cold(${T_cold_C}°C) pack: ${yawn_cold_pct}%`);
ok('oral/undirected breathing ≈ 48% contagious yawning', yawn_oral_pct === 48);
ok('nasal breathing → 0% (eliminated entirely)', yawn_nasal_pct === 0);
ok('warm/room pack → 41%', yawn_warm_or_room_pct === 41);
ok('cold (4 °C) pack → 9%', yawn_cold_pct === 9);
ok('cold-pack temperature is 4 °C, warm is 46 °C', T_cold_C === 4 && T_warm_C === 46);
// the page describes the cold pack "more than quartering" contagious yawning vs warm/room:
const cold_vs_warm_ratio = yawn_warm_or_room_pct / yawn_cold_pct;
console.log(`  cold pack vs warm/room: ${yawn_warm_or_room_pct}% → ${yawn_cold_pct}% = ÷${cold_vs_warm_ratio.toFixed(2)}`);
ok('cold pack more than quarters the rate vs warm/room (41→9, ÷4.6)',
   cold_vs_warm_ratio > 4, `÷${cold_vs_warm_ratio.toFixed(2)}`);
// the absolute drop the page may cite:
const cold_drop_points = yawn_warm_or_room_pct - yawn_cold_pct;
ok('cold pack drops contagious yawning by 32 percentage points (41 − 9)',
   cold_drop_points === 32, `${cold_drop_points} pts`);

// ── 5. Publication facts and elapsed-time arithmetic ────────────────────────
console.log('\n— publication facts & elapsed time —');
const provine_year = 1987, provine_vol = 48, provine_p1 = 382, provine_p2 = 393;
const gallup_year = 2007, gallup_vol = 5, gallup_p1 = 92, gallup_p2 = 101;
const page_year = 2026; // the stratum's date: 2026-06-27
const gap_provine_to_gallup = gallup_year - provine_year;
const years_since_falsification = page_year - provine_year;
const decades_since = Math.floor(years_since_falsification / 10);
console.log(`  Provine 1987: Behav. Neural Biol. ${provine_vol}:${provine_p1}-${provine_p2}`);
console.log(`  Gallup 2007: Evol. Psychol. ${gallup_vol}(1):${gallup_p1}-${gallup_p2}`);
console.log(`  1987 → 2007 = ${gap_provine_to_gallup} yr;  1987 → ${page_year} = ${years_since_falsification} yr (${decades_since} decades)`);
ok('Provine 1987 is Behav. Neural Biol. vol 48, pp 382–393', provine_vol === 48 && provine_p1 === 382 && provine_p2 === 393);
ok('Gallup 2007 is Evol. Psychol. 5(1):92–101', gallup_vol === 5 && gallup_p1 === 92 && gallup_p2 === 101);
ok('falsification → cooling proposal spans 20 years (1987→2007)', gap_provine_to_gallup === 20);
ok('falsification is ~four decades old as of the page (1987→2026 = 39 yr)',
   years_since_falsification === 39 && decades_since === 3, `${years_since_falsification} yr`);
ok('"decades ago" is literally true (≥ 2 decades since 1987)', decades_since >= 2);

// ── 6. The honesty bound: negative result strong, positive account contested ─
// Nothing in this script computes brain-cooling to be TRUE. The page's epistemic
// split must be explicit: the oxygen refutation is robust; cooling is leading-but-
// -contested. We assert the framing, not a proof of the positive theory.
console.log('\n— honesty bound: what is settled vs what is not —');
const oxygen_hypothesis_refuted = true;          // qualitative conclusion transcribed from Provine 1987
const cooling_theory_proven = false;             // leading but NOT settled
ok('the oxygen/blood-gas hypothesis is refuted (strong claim)', oxygen_hypothesis_refuted === true);
ok('brain-cooling is NOT asserted as proven (it is leading-but-contested)',
   cooling_theory_proven === false);
ok('the page makes a strong negative claim and a hedged positive one',
   oxygen_hypothesis_refuted === true && cooling_theory_proven === false);

console.log(`\n${fails === 0 ? 'ALL CHECKS PASSED' : fails + ' CHECK(S) FAILED'}\n`);
process.exit(fails === 0 ? 0 : 1);
