Skip to content

Lower Pine relationals na-aware: comparisons with an na operand are falsy#57

Merged
luisleo526 merged 1 commit into
mainfrom
fix/ki71-na-relational
Jul 11, 2026
Merged

Lower Pine relationals na-aware: comparisons with an na operand are falsy#57
luisleo526 merged 1 commit into
mainfrom
fix/ki71-na-relational

Conversation

@luisleo526

Copy link
Copy Markdown
Contributor

Summary

TradingView evaluates every relational comparison (==, !=, <, >, <=, >=) with an na operand as falsy. The naive C++ lowering diverges on the int na sentinel (INT_MIN != x → TRUE, NA == NA → TRUE, ordered ops leak) and on float x != NaN (IEEE TRUE); float ==/</>/<=/>= already match TV via IEEE NaN semantics and stay naive.

Pinned by a dedicated clean-room probe at 792/792 events: an na latched into a var int at bar 0 through an isfirst ternary stays na forever on TV — every later comparison falsy — while the naive lowering let the engine heal the latch and over-fire ~1,300 entries on the exemplar strategy.

Implementation

  • Shared _lower_relational wraps only diverging cells — any na-capable int operand; != with an na-capable float operand — in a single-evaluation nz-style lambda: !is_na(l) && !is_na(r) && (l op r). Operands hoisted to temporaries (mutating operands evaluated exactly once).
  • Applied at both relational emission sites: _visit_binop and the request.security expression builder.
  • bool/string/color relationals stay naive (no na sentinel). Monotone-safe: for non-na operands the lambda is bit-identical to the naive comparison.

Verification

  • pytest 1510 passed + 1 skipped (13 new diverging-cell tests RED on base).
  • Whole-corpus differential transpile: 73 changed .cpp, all wrap-only — independently collapse-audited (each wrap unwrapped and asserted equal to the baseline emission; no operator flips/reorders/dropped negations).
  • 73/73 changed strategies byte-identical engine output; corpus tiers 240/11/1 preserved.
  • Sentinels byte-identical incl. the na-int :=-retype exemplar and float-relational probes; !=-as-change-detector idiom A/B'd at trade level (byte-identical).
  • Private validation set: mover strategies reach exact TV parity (canonical excellent, 100% match/px, P90s 0); full 412-slug sweep 2 up / 0 down.
  • Fresh-context adversarial review: PASS (ARM64; single-eval, emission-site completeness incl. the non-diverging switch value-equality site, KI-70 orthogonality all verified).

Known residuals (non-blocking, recorded)

  • Type-inference misses can leave an na-capable operand unwrapped — an incomplete-fix direction only, never a new wrong answer; none surfaced across 254 transpiled strategies.
  • Inherited engine-wide na sentinel assumption (a genuine INT_MIN value reads as na) — pre-existing, not introduced here.

🤖 Generated with Claude Code

…alsy

TradingView evaluates every relational comparison (==, !=, <, >, <=, >=)
with an na operand as falsy. The naive C++ lowering diverges on the int na
sentinel (INT_MIN != x is TRUE, NA == NA is TRUE, ordered ops leak) and on
float x != NaN (IEEE TRUE); float ==/</>/<=/>= already match via IEEE NaN
semantics and stay naive.

Pinned by pf-probe-concord-lockedregime-composed (792/792 events): a bar-0
na latched into `var int locked_regime` via an isfirst ternary stays na
forever on TV — every later comparison is falsy — while the naive lowering
let the engine heal the latch and over-fire ~1,300 entries on the exemplar
strategy.

Implementation: shared _lower_relational wraps only diverging cells (any
na-capable int operand; != with an na-capable float operand) in a
single-evaluation nz-style lambda (!is_na(l) && !is_na(r) && (l op r)),
applied at both relational emission sites (visit_binop and the
request.security expression builder). bool/string/color relationals stay
naive (no na sentinel). Monotone-safe: for non-na operands the lambda is
bit-identical to the naive comparison.

Gates: pytest 1510 + 1 skipped (13 new cells RED on base); whole-corpus
differential transpile 73 changed .cpp, all wrap-only (collapse-audited);
73/73 changed strategies byte-identical engine output; corpus tiers
240/11/1; sentinel set byte-identical incl. the KI-68 na-int exemplar;
mover strategies reach exact TV parity (private-set canonical excellent,
full 412-slug sweep 2 up / 0 down). Reviewed fresh-context, ARM64.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@luisleo526 luisleo526 merged commit 5417fbf into main Jul 11, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant