Dimension combineWith(Optional<Dimension> other, boolean allowDifferentSizes) {
            if (other.isEmpty()) return this;
            if (this instanceof MappedDimension) return this;
            if (other.get() instanceof MappedDimension) return other.get();
            // both are indexed
            if (this instanceof IndexedUnboundDimension) return this;
            if (other.get() instanceof IndexedUnboundDimension) return other.get();
            // both are indexed bound
            IndexedBoundDimension thisIb = (IndexedBoundDimension)this;
            IndexedBoundDimension otherIb = (IndexedBoundDimension)other.get();
            if (allowDifferentSizes)
                return thisIb.size().get() < otherIb.size().get() ? thisIb : otherIb;
            if (  ! thisIb.size().equals(otherIb.size()))
                throw new IllegalArgumentException("Unequal dimension sizes in " + thisIb + " and " + otherIb);
            return thisIb;
        }
Returns the dimension resulting from combining two dimensions having the same name but possibly different
types:

[N] + [M] = [ min(N, M) ]
[N] + [] = []
[] + {} = {}
vespajlib/src/main/java/com/yahoo/tensor/TensorType.java