median(a)/median(b) not equal median(a/b) I'm sure this is a very straightforward question but it came up in my work today and I could not think of the reasoning behind it.
I had two sets of numeric values (A & B) and was looking at the median of their ratio and noticed that median(A)/median(B) is not equal to median(A/B) and I was wondering if someone could explain why not. Seems like one might assume they are equal, but this is not true. I also noted that it seems when the range of A & B respectively are small the median(A/B) is quite near median(A)/median(B), but with a large range the two values seem to diverge.  
 A: This is a property of mathematics, it is actually rare that the order of operations does not matter, e.g. the log of the square root is not the same as the square root of the log (except for a few special cases).
We often focus on some of those special cases where due to operations distributing, associating, and commuting (flashbacks to algebra, oh no!) we can do things in either order.  For example to compute a mean we can either add the numbers together then divide the sum by $n$, or we can divide each number by $n$ then sum those values.  This is because division (multiplication) distributes over addition.  With paired data we have the fact that the mean of the differences is the difference of the means.  But these are the rarer cases, not the rule.
So in general you should not expect to get the same result when you do things in a different order, it is also not true that the mean of the ratios is the ratio of the means, so why should it be true for the median?
A: You might find it even more surprising to discover that even with a nice linear operator like expectation, you still have this issue (median is non linear, mean is linear):
$$\text{mean}(A)/\text{mean}(B) \neq \text{mean}(A/B)$$
For example:
 a=1:5
 b=6:10
 mean(a)/mean(b)
[1] 0.375
 mean(a/b)
[1] 0.3543651

But then you should already know that in general $E(XY)\neq E(X)E(Y)$, so perhaps this shouldn't surprise at all!
A: Erm, for the (obvious?) reason that the fractional representation of a number is not unique, the medians can't be the same. 
EDIT: as per Glen's request
The location of the median relies on the ordering of numbers in your set. Suppose you order your numbers from smallest to largest, so you have something like this {1,2,3}. You can maintain the same median if you perform a transformation only if that transformation preserves the ordering. For example, if you add 1 to every single number in your set, location of the median doesn't change: {2, 3, 4}, i.e. it is still located in the second position. 
Any linear transformation maintains the order. The maintenance of order is key. That's the "property of mathematics" that's really being referred to below. (And how you define order is also key. Note that order is essentially a notion of distance. 2 is closer to 3 than to 4 because the distance between 2 and 3 is smaller than the distance between 2 and 4). That's why, for positive data, in some instances, it is allowed to apply a log transform of your data - you haven't fundamentally altered the ordering of the numbers, and thus you haven't changed the underlying relationship between your variables. You can do a log transform for say, income data, but you can't do it for inflation data.
If a transformation is not linear, the order is not necessarily maintained. Transforming every number into a fraction is not a linear transformation because the fractional representation of a number is not unique. 1/2 is the same as 2/4. That's why for "large" sets the location of the median changes if you transform your numbers into fractions in the way that you described. For large enough sets, you're eventually going to run into a situation where you have the same fraction in multiple places.If that happens, your set "shrinks" and so the median must change.
