Add Young discrete mathematics structures (Diagrams, Tableaux, Lattice)#823
Add Young discrete mathematics structures (Diagrams, Tableaux, Lattice)#823Copilot wants to merge 3 commits intoproductionfrom
Conversation
Co-authored-by: professoroakz <6593422+professoroakz@users.noreply.github.com>
| if (row >= this.filling.length || col >= this.filling[row].length) { | ||
| return false; | ||
| } | ||
| this.filling[row][col] = value; |
Check warning
Code scanning / CodeQL
Prototype-polluting assignment Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 months ago
To fix prototype pollution, ensure that keys used to index into objects/arrays cannot be special object properties such as __proto__, constructor, or prototype. For the set(row, col, value) method, the cleanest approach is to validate that both row and col are numeric, integer indices before any assignment occurs. If either is not a finite integer or if the string representation matches dangerous JavaScript property names, return false or throw an error. Alternatively, you could convert these arguments to numbers with Number() and check for Number.isInteger, but it's best to explicitly guard against string keys.
Specifically:
- In the
setmethod, before reading or writing tothis.filling[row][col], check thatrowandcolare integers and not any of the forbidden property names ('__proto__','constructor','prototype'). - If either fails validation, abort the operation.
- The edits are limited to the
setmethod (lines 271-277) inyoung-discrete-math.js.
No external libraries are needed; only standard JavaScript validation.
| @@ -269,7 +269,18 @@ | ||
| * Set the value at position (row, col) | ||
| */ | ||
| set(row, col, value) { | ||
| if (row >= this.filling.length || col >= this.filling[row].length) { | ||
| // Prevent prototype pollution - allow only integer indices, disallow dangerous keys | ||
| const forbidden = ['__proto__', 'constructor', 'prototype']; | ||
| if ( | ||
| typeof row !== 'number' || | ||
| typeof col !== 'number' || | ||
| !Number.isInteger(row) || | ||
| !Number.isInteger(col) || | ||
| row < 0 || | ||
| col < 0 || | ||
| row >= this.filling.length || | ||
| col >= this.filling[row].length | ||
| ) { | ||
| return false; | ||
| } | ||
| this.filling[row][col] = value; |
Co-authored-by: professoroakz <6593422+professoroakz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR implements classical Young structures from combinatorics and representation theory to complement the existing Young Ring/Field algebraic framework. The implementation adds fundamental discrete mathematics concepts (diagrams, tableaux, lattices) with complete mathematical operations and integration capabilities.
Key Changes:
- Four new combinatorial classes implementing partition theory and representation theory concepts
- Robinson-Schensted correspondence for permutation-tableau bijection
- Partition enumeration with lattice structure and covering relations
- Hook length formula for representation dimension calculations
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| young-discrete-math.js | Core implementation of YoungDiagram, YoungTableau, YoungLattice, and YoungsRule with partition operations |
| test-young-discrete-math.js | Comprehensive test suite with 24 test sections covering all operations and mathematical properties |
| package.json | Updated test scripts to include discrete math tests alongside existing field tests |
| index.js | Export integration for new classes and factory functions |
| YOUNG_DISCRETE_MATH.md | Complete API reference and mathematical background documentation |
| YOUNG_CONCEPTS_REFERENCE.md | Unified reference showing integration between algebraic and combinatorial structures |
| README.md | Updated usage examples demonstrating partition operations and tableau construction |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // [2,2] is self-conjugate | ||
| assert(YoungsRule.isSelfConjugate([2, 2]), '[2,2] is self-conjugate'); | ||
|
|
||
| // [3,2,1] is not self-conjugate (conjugate is [3,2,1]) |
There was a problem hiding this comment.
The assertion is incorrect. The partition [3,2,1] is self-conjugate (equals its own transpose), so the test expectation is correct. However, the comment on line 346 states '[3,2,1] is not self-conjugate (conjugate is [3,2,1])', which contradicts the assertion. The conjugate of [3,2,1] is indeed [3,2,1], making it self-conjugate. Either the comment should be updated or the assertion should use ! to test for non-self-conjugate partitions.
| // [3,2,1] is not self-conjugate (conjugate is [3,2,1]) | |
| // [3,2,1] is self-conjugate (conjugate is [3,2,1]) |
| nums.sort((a, b) => a - b); | ||
| const expectedSize = this.size(); | ||
| if (nums.length !== expectedSize) return false; | ||
| for (let i = 0; i < expectedSize; i++) { | ||
| if (nums[i] !== i + 1) return false; | ||
| } |
There was a problem hiding this comment.
For standard tableau validation, the numbers are collected and sorted to verify they form the sequence 1..n. Since standard tableaux must contain consecutive integers starting from 1, you could avoid sorting by using a Set to check for duplicates and verifying min=1 and max=n in O(n) time instead of O(n log n) sorting.
| nums.sort((a, b) => a - b); | |
| const expectedSize = this.size(); | |
| if (nums.length !== expectedSize) return false; | |
| for (let i = 0; i < expectedSize; i++) { | |
| if (nums[i] !== i + 1) return false; | |
| } | |
| const expectedSize = this.size(); | |
| if (nums.length !== expectedSize) return false; | |
| const numSet = new Set(); | |
| let min = Infinity, max = -Infinity; | |
| for (const num of nums) { | |
| if (numSet.has(num)) return false; | |
| numSet.add(num); | |
| if (num < min) min = num; | |
| if (num > max) max = num; | |
| } | |
| if (min !== 1 || max !== expectedSize) return false; |
Implements classical Young structures from combinatorics and representation theory to complement the existing Young Ring/Field algebraic framework.
Changes
New structures (
young-discrete-math.js):Integration:
index.jsalongside existing Young Ring/Field classesYOUNG_DISCRETE_MATH.mdwith API reference,YOUNG_CONCEPTS_REFERENCE.mdunifying all Young conceptsUsage
These combinatorial structures enable partition enumeration, representation theory computations, and integrate with Young Field operations (e.g., normalizing partition dimensions to probability distributions).
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.