Skip to content

Commit

Permalink
sagemathgh-37218: Fix to ncsym.ncsym.nesting
Browse files Browse the repository at this point in the history
    
The nesting function in combinat.ncsym.ncsym.py does not operate as
described in its documentation.  As intended, it should compare all arcs
of two set partitions and count the number of times the second arc nests
in the first.  As written, there was a break statement caused many
(necessary) comparisons to be skipped, particularly for set partitions
with large blocks.

I have re-written the function so that all necessary comparisons are
made.  I have also added an example in the docstring that was computed
incorrectly by the old code, but is corrected by my fix.

This bug is not a previously known issue, and I have also confirmed with
the original author (@tscrim ) that no one else is currently working on
a fix.

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.

### ⌛ Dependencies

No dependencies
    
URL: sagemath#37218
Reported by: lucasgagnon
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Feb 7, 2024
2 parents 1d2b2e4 + 4e0bcf9 commit ad4cfc4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/sage/combinat/ncsym/ncsym.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ def nesting(la, nu):
sage: nesting(set(mu).difference(nu), nu)
1
sage: A = SetPartition([[1], [2,5], [3,4]])
sage: B = SetPartition([[1,3,4], [2,5]])
sage: nesting(A, B)
1
sage: nesting(B, A)
1
::
sage: lst = list(SetPartitions(4))
Expand Down Expand Up @@ -135,11 +142,13 @@ def nesting(la, nu):
nst = 0
for p in la:
p = sorted(p)
for i in range(len(p)-1):
for a in arcs:
if a[0] >= p[i]:
for a in arcs:
if p[-1] < a[0]:
continue
for i in range(len(p)-1):
if a[1] <= p[i+1]:
break
if p[i+1] < a[1]:
if a[0] < p[i]:
nst += 1
return nst

Expand Down

0 comments on commit ad4cfc4

Please sign in to comment.