I need to compute the meet of two partitions λ=(λ1,…,λr) and μ=(μ1,…,μs) with respect to the dominance order. It's not a difficult thing to do and might be considered an oddity by most of you, but that doesn't bother me.
Let ϱ:=λ△μ be the meet of λ and μ. We Compute a partition α by setting α1:=min(λ1,μ1) and recursively setting
αi+1:=min{(λ1+⋯+λi+1)−(α1+⋯+αi),(μ1+⋯+μi+1)−(α1+⋯+αi),αi}.
Fundamental Theorem of computing the Meet in the Dominance Order. α=ϱ.
Proof. First, α⊴λ and α⊴μ holds for obvious reasons: To show e.g. that for all i, we have
α1+⋯+αi≤λ1+⋯+λi,
we induct on i with i=1 being trivial and the induction step also follows immediately from the definition. Therefore, to show that α=ϱ, we simply need to show that ϱ⊴α. If this is the case, then we must have ϱ=α by definition of the meet. Again, we induct on i. For i=1, we have ϱ1≤λ1 and ϱ1≤μ1, so we also have ϱ1≤min(λ1,μ1)=α1. In the induction step, we assume
α1+⋯+αi+di=ϱ1+⋯+ϱi
for some di≥0. Hence,
α1+⋯+αi+ϱi+1+di=ϱ1+⋯+ϱi+1≤λ1+⋯+λi+1
and it follows that
ϱi+1+di≤(λ1+⋯+λi+1)−(α1+⋯+αi)=αi+1,
in other words ϱi+1≤αi+1 which implies
ϱi+⋯+ϱi+1≤α1+⋯+αi+1
by again using the induction hypothesis. This concludes the proof. QED.
Python Implementation
>>> def dominanceMeet(p,q):
... n = max( sum(p), sum(q) )
... a = []
... sp, sq, sa, prev, i = 0, 0, 0, n, 0
... while prev:
... sp += p[i] if i < len(p) else 0
... sq += q[i] if i < len(q) else 0
... prev, i = min(sp-sa, sq-sa, prev), i+1
... sa += prev
... if prev: a.append(prev)
... return a
...
>>>
>>>
>>> dominanceMeet([3,1,1,1],[2,2,2])
[2, 2, 1, 1]
>>>
The code is written in a quite imperative style. That's because it's going to be C code rather soon.