Skip to content

Add Young discrete mathematics structures (Diagrams, Tableaux, Lattice)#823

Open
Copilot wants to merge 3 commits intoproductionfrom
copilot/formalize-young-ring-concepts
Open

Add Young discrete mathematics structures (Diagrams, Tableaux, Lattice)#823
Copilot wants to merge 3 commits intoproductionfrom
copilot/formalize-young-ring-concepts

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 2, 2025

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):

  • YoungDiagram: Integer partition representation with conjugate/transpose, containment ordering, and successor/predecessor operations for lattice navigation
  • YoungTableau: Standard/semi-standard tableaux with Robinson-Schensted insertion algorithm and validation
  • YoungLattice: Complete partition enumeration with partition function p(n), covering relations, and Hasse diagram generation
  • YoungsRule: Hook length formula for representation dimensions, self-conjugate detection, tensor product decomposition

Integration:

  • Exports added to index.js alongside existing Young Ring/Field classes
  • Test suite: 24 test sections covering all operations and mathematical properties
  • Documentation: YOUNG_DISCRETE_MATH.md with API reference, YOUNG_CONCEPTS_REFERENCE.md unifying all Young concepts

Usage

const { YoungDiagram, YoungTableau, YoungLattice, YoungsRule } = require('reality-simulation-code');

// Partition operations
const diagram = new YoungDiagram([4, 3, 1]);
diagram.conjugate().toArray();  // [3, 2, 2, 1]

// Standard Young Tableaux with validation
const tableau = new YoungTableau([[1,2,5], [3,4], [6]], true);
tableau.isValid();  // true

// Partition enumeration
const lattice = new YoungLattice();
lattice.countPartitions(5);  // p(5) = 7

// Representation dimensions via hook length
YoungsRule.hookLengthFormula([3,2,1]);  // 16

// Robinson-Schensted correspondence
createStandardTableauFromPermutation([3,1,4,2]);

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

Generate/Formalize the common situation and area for "Young", such as Young Ring etc in the area of Discrete Math


💡 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.

Co-authored-by: professoroakz <6593422+professoroakz@users.noreply.github.com>
Comment thread young-discrete-math.js
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

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.

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 set method, before reading or writing to this.filling[row][col], check that row and col are 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 set method (lines 271-277) in young-discrete-math.js.

No external libraries are needed; only standard JavaScript validation.


Suggested changeset 1
young-discrete-math.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/young-discrete-math.js b/young-discrete-math.js
--- a/young-discrete-math.js
+++ b/young-discrete-math.js
@@ -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;
EOF
@@ -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;
Copilot is powered by AI and may make mistakes. Always verify output.
Co-authored-by: professoroakz <6593422+professoroakz@users.noreply.github.com>
Copilot AI changed the title [WIP] Formalize common situation and area for Young in Discrete Math Add Young discrete mathematics structures (Diagrams, Tableaux, Lattice) Dec 2, 2025
Copilot AI requested a review from professoroakz December 2, 2025 11:41
@professoroakz professoroakz marked this pull request as ready for review December 3, 2025 14:27
@professoroakz professoroakz requested a review from Copilot December 3, 2025 14:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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])
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// [3,2,1] is not self-conjugate (conjugate is [3,2,1])
// [3,2,1] is self-conjugate (conjugate is [3,2,1])

Copilot uses AI. Check for mistakes.
Comment thread young-discrete-math.js
Comment on lines +247 to +252
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;
}
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
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.

4 participants