I think I figured out how this can be expressed mathematically. The units can be thought as mathematical constants and physical quantities as numbers multiplied by that constants (units). So when we add two same quantities with same units we can add the numbers, for example:
$2\hspace{0.2cm} apples + 5\hspace{0.2cm} apples = 2\cdot a +5\cdot a = (2+5)\cdot a=7\cdot a = 7\hspace{0.2cm} apples $
But for different quantities we can't add the numbers:
$2\hspace{0.2cm} apples + 5\hspace{0.2cm} oranges = 2\cdot a +5\cdot o $
therefore we can't write 2 apples + 5 oranges = 7 apples + oranges
However we can multiply (and divide) them, multiplying the numbers and the units:
$2\hspace{0.2cm} apples \cdot 5\hspace{0.2cm} oranges = (2\cdot a) \cdot (5\cdot o) = (2\ \cdot 5) \cdot (a\cdot o) =10 \cdot (a\cdot o)=10\hspace{0.2cm} apples \cdot oranges$
This seems to work.