#![allow(
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::cast_possible_wrap
)]
use crate::partition::Partition;
fn as_rectangle(lambda: &Partition) -> Option<(u32, usize)> {
let a = *lambda.parts().first()?;
lambda
.parts()
.iter()
.all(|&x| x == a)
.then(|| (a, lambda.len()))
}
fn both_rectangles(mu: &Partition, nu: &Partition) -> Option<(u32, usize, u32, usize)> {
let (a, p) = as_rectangle(mu)?;
let (b, q) = as_rectangle(nu)?;
Some(if p >= q { (a, p, b, q) } else { (b, q, a, p) })
}
pub fn okada_product(mu: &Partition, nu: &Partition) -> Option<Vec<(Partition, u128)>> {
let (a, p, b, q) = both_rectangles(mu, nu)?;
let mut out = Vec::new();
let mut head = vec![0u32; q];
extend(0, a + b, &mut head, a, b, p, q, &mut out);
out.sort_by(|x: &(Partition, u128), y| x.0.cmp(&y.0));
Some(out)
}
#[allow(clippy::too_many_arguments)]
fn extend(
i: usize,
hi: u32,
head: &mut Vec<u32>,
a: u32,
b: u32,
p: usize,
q: usize,
out: &mut Vec<(Partition, u128)>,
) {
if i == q {
out.push((assemble(head, a, b, p, q), 1));
return;
}
for v in (a.max(b)..=hi).rev() {
head[i] = v;
extend(i + 1, v, head, a, b, p, q, out);
}
}
fn assemble(head: &[u32], a: u32, b: u32, p: usize, q: usize) -> Partition {
let mut full = vec![0u32; p + q];
full[..q].copy_from_slice(head);
full[q..p].fill(a);
for (i, &v) in head.iter().enumerate() {
full[p + q - 1 - i] = a + b - v;
}
while full.last() == Some(&0) {
full.pop();
}
Partition::new(full)
}
pub fn okada_coeff(lambda: &Partition, mu: &Partition, nu: &Partition) -> Option<u128> {
let (a, p, b, q) = both_rectangles(mu, nu)?;
if lambda.len() > p + q {
return Some(0);
}
let at = |i: usize| lambda.parts().get(i - 1).copied().unwrap_or(0);
let occurs = (q + 1..=p).all(|i| at(i) == a)
&& at(q) >= a.max(b)
&& (1..=q).all(|i| at(i) + at(p + q + 1 - i) == a + b);
Some(u128::from(occurs))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::lr::LrBackend;
use crate::skew_lr::SkewLr;
fn rect(rows: usize, part: u32) -> Partition {
Partition::new(std::iter::repeat_n(part, rows))
}
#[test]
fn agrees_with_skew_lr_on_all_small_rectangle_pairs() {
let mut cases = 0;
for a in 1..=4u32 {
for p in 1..=4usize {
for b in 1..=4u32 {
for q in 1..=4usize {
let (mu, nu) = (rect(p, a), rect(q, b));
let want = SkewLr.schur_product(&mu, &nu);
assert_eq!(
okada_product(&mu, &nu).as_ref(),
Some(&want),
"s({a}^{p}) · s({b}^{q})"
);
assert_eq!(
okada_product(&nu, &mu).as_ref(),
Some(&SkewLr.schur_product(&nu, &mu)),
"s({b}^{q}) · s({a}^{p}) (swapped)"
);
cases += 1;
}
}
}
}
assert_eq!(cases, 256);
}
#[test]
fn coefficients_including_zeros_agree_with_skew_lr() {
for a in 1..=3u32 {
for p in 1..=3usize {
for b in 1..=3u32 {
for q in 1..=3usize {
let (mu, nu) = (rect(p, a), rect(q, b));
let n = a * p as u32 + b * q as u32;
for lambda in crate::partition::partitions_of(n) {
assert_eq!(
okada_coeff(&lambda, &mu, &nu),
Some(SkewLr.lr_coeff(&lambda, &mu, &nu)),
"c^{lambda}_{{({a}^{p}),({b}^{q})}}"
);
}
}
}
}
}
}
#[test]
fn wrong_size_lambda_is_zero() {
let (mu, nu) = (rect(2, 3), rect(2, 3)); for lambda in crate::partition::partitions_of(11) {
assert_eq!(okada_coeff(&lambda, &mu, &nu), Some(0), "λ = {lambda}");
}
for lambda in crate::partition::partitions_of(13) {
assert_eq!(okada_coeff(&lambda, &mu, &nu), Some(0), "λ = {lambda}");
}
}
#[test]
fn declines_when_a_factor_is_not_a_rectangle() {
let r = rect(2, 2);
for other in [Partition::new([3u32, 1]), Partition::default()] {
assert_eq!(okada_product(&r, &other), None, "{other}");
assert_eq!(okada_product(&other, &r), None, "{other}");
assert_eq!(okada_coeff(&Partition::new([4u32, 3]), &r, &other), None);
}
}
#[test]
fn pieri_cases_are_rectangles() {
let got = okada_product(&Partition::new([3u32]), &rect(2, 1)).expect("rectangles");
assert_eq!(
got,
SkewLr.schur_product(&Partition::new([3u32]), &rect(2, 1))
);
}
#[test]
fn support_size_is_the_expected_binomial() {
for (a, p, b, q) in [
(4u32, 4usize, 4u32, 4usize),
(8, 5, 8, 5),
(12, 6, 12, 6),
(3, 5, 7, 2),
] {
let n = okada_product(&rect(p, a), &rect(q, b))
.expect("rectangles")
.len();
let (m, k) = (a.min(b) as u128, q.min(p) as u128);
let want = (1..=k).fold(1u128, |acc, i| acc * (m + i) / i);
assert_eq!(n as u128, want, "s({a}^{p})·s({b}^{q})");
}
}
}