Fix any/all reductions for the numeric boolean convention#28
Merged
Conversation
Comparison ops across the library consistently encode booleans as numeric true=1, false=0 (float arms, uint arms via `!`, the C jets, and the saloon docs all agree). But `any` and `all` were written for the opposite (true=0) assumption: `any` tested cumsum < count and `all` tested cumsum == 0, so both were inverted for every boolean ray. Reformulate in terms of min/max, which reduce correctly across kinds: any = the max element is nonzero (some element truthy); all = the min element is nonzero (every element truthy). Both compare against 0, which is encoding-agnostic (false and +0.0 are both 0x0). Index the scalar result with a rank-matched zero index instead of a hardcoded ~[0], so it works for arrays of any dimensionality. These arms were previously unreachable from any test (the is-close helper that calls `all` is defined but never invoked), and saloon's all-close/any-close delegate here, so they were broken too. Add a direct any/all test over all-true / mixed / all-false boolean rays. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
83dabad to
0ec034b
Compare
This was referenced May 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A gnome investigation established that comparison ops across the library consistently encode booleans as numeric
true=1,false=0:1.0/0.0(lagoon.hoon:1048–1095),!(^op b c)which — since Hoon's%.y=0 — yieldstrue→1,false→0(lagoon.hoon:1029–1032),? REAL_ONE : REAL_ZERO, and the saloon docs / tinygrad consumer agree.So there is no convention clash (correcting an earlier hypothesis). The only broken code was
any/all(lagoon.hoon:994, 999), written for the oppositetrue=0assumption:anytestedcumsum < countandalltestedcumsum == 0— both inverted for every boolean ray. (The gnome's first-pass=(sum,count)idea is also unusable: it would compare a float bit-pattern sum to an integer count.)Fix
Reformulate in terms of
min/max, which reduce correctly across kinds (they compare encoded values directly and seed at the first element):any= the max element is nonzero (some element truthy)all= the min element is nonzero (every element truthy)The
!= 0test is encoding-agnostic — both integer0and float+0.0are0x0. The scalar result is indexed with a rank-matched zero index ((reap (lent shape) 0)) instead of a hardcoded~[0], so it works for arrays of any dimensionality (the old~[0]only worked for vectors).Impact
These arms were unreachable from any test (the
is-closehelper that callsallis defined but never invoked), andsaloon'sall-close/any-closedelegate here — so they were broken too, and are now fixed. Added a directany/alltest over all-true / mixed / all-false rays.lagoon-old.hoonhas the same bug but is a dead legacy file (slated for removal) and is left untouched.🤖 Generated with Claude Code