Repository navigation
Add the optional combinatorics library: statistics on permutations and integer partitions - #659
Closed
enumeratio wants to merge 1 commit into
Closed
enumeratio wants to merge 1 commit into
enumeratio wants to merge 1 commit into
Conversation
…binatorics): loadCombinatorics declares about 350 statistics of a permutation and about 195 of an integer partition as operators over the engine's own lists, each defined by an Epsil function literal precompiled to MathJSON, with an optional TypeScript kernel held equal to it, identified with a FindStat statistic and checked against its values; a list outside the domain stays unevaluated and a statistic declines compile(). Part of cortex-js#531
Member
|
Landed in f42a02d, with fixes made while landing (see the commit message). Thanks! |
arnog
added a commit
that referenced
this pull request
Nov 23, 2026
…(m, n, d), the optional combinatorics library, PiecewiseExpand - #657: @cortex-js/compute-engine/runtime exports sysHelpers, the stateless helpers that compiled code calls as _SYS.<name> (#527 item 1). - #658: Mod(m, n, d) is d + Mod(m - d, n), in [d, d + n) (#548). Every compile target declines the three-operand form; the derivative, limit, enclosure and measurement code leave it unevaluated. Fixed on landing: .N() reads exact operands exactly as the two-operand Mod does (exact cancellation of d, a symbol with an exact value near a jump, a dividend past the range of a double, no second evaluation of an impure operand); exact radicals stay exact; the type is real only for real operands. - #659: the optional combinatorics entry, loadCombinatorics(ce, { areas }), with about 350 permutation and 195 integer-partition statistics checked against FindStat (#531). Fixed on landing: the report of a re-load, a skipped head declared once the engine's definition is removed, the CI comment, string nodes without source offsets in compiled.ts, the synonym head LargestCycleLength removed (LongestCycleLength stays), one compiler decline test per area, and notes on list literals and time limits. - #660: PiecewiseExpand rewrites Abs, Sign, Min, Max and Heaviside into a Which (#516). Fixed on landing: an argument declared complex or number is not split; the arm limit is checked before the product is built; Max() and Min() with no operand; exact conditions between radicals; an impure expression is returned unchanged; the lazy-operator list and the search ranking test. - Issues CE-1734, CE-1735, CE-1736 filed from the decline census of #638. Co-authored-by: enumeratio <[email protected]>
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.
@cortex-js/compute-engine/combinatoricsis a new, opt-in entry point. Importing it declares nothing;loadCombinatorics(ce, { areas })is synchronous and idempotent per engine and area, and returns a report of the heads and types declared and any head skipped because the engine already defines it.areasis'permutations','partitions', or both (the default). Loading both takes about 10-25 ms; no definition is boxed until its head is first called. The new entry adds about 34 KB gzipped to the esm-min bundle only for those who import it.What is in the first slice
MajorIndex,Inversions,Denert, ...LargestPart,DurfeeSquare,AddableCells, ...Elements are the engine's own lists: a permutation is its one-line list (what
Permutationsyields), a partition is its list of parts (whatIntegerPartitionsyields). A group-theoryPermutation(...)is also read. The domains arepermutationandinteger_partition, declared as aliases oflist<integer>; the exact membership check (a bijection of 1..n, non-increasing positive parts) is in the handler, since a refinement type is not available yet.Each statistic is an Epsil function literal, compiled ahead of time by
scripts/combinatorics/generate.tsintosrc/compute-engine/combinatorics/compiled.tsas MathJSON, so the entry does not carry the Epsil parser or text. A few carry a TypeScript kernel that a test holds equal to the definition.Data and FindStat
data/combinatorics/examples/: one row per example, per area.data/combinatorics/findstat/: FindStat statistic identifiers, our match records (matches.json), and FindStat's values as test fixtures (values/St*.json), with a README crediting FindStat. The values are mathematical facts, credited to FindStat.data/combinatorics/MANIFEST.json: counts.All but a few statistics carry a FindStat identifier and equal its values on every permutation up to size 5 and every partition up to size 6 that FindStat tabulates; the others are held to their examples. A
generate.ts --checkstep in thecorpus-pipelinejob fails on drift.Tests
Jest runs the data directly (
test/compute-engine/combinatorics/): every example row throughevaluate(), with.N(), the Epsil route and the compiler's refusal on the first row of each head; each head against FindStat's values on small objects; each kernel against its definition; the loader; and the precompiled file against the sources. The standard run takes about 90 s.CE_NIGHTLY=1runs every row on every route and a sweep to size 7 (test/compute-engine/nightly/combinatorics-sweep.test.ts).What declines
evaluatereturnundefined, so the call stays unevaluated (MajorIndex([1, 1])). NoError, noNaN.Naming
A statistic defined on several collections gets one head per collection, because every domain is a
list<integer>alias and one operator could not tell them apart. The permutation statistic keeps the bare name (MajorIndex) and the others are prefixed by the collection (WordMajorIndex). The two areas in this slice share no head.Part of #531