How does "only" change the meaning of this sentence?

How do I interpret the same sentence but with "only" modifying different parts of it:

  1. You need math only when you are buying vegetables.
  2. You need math when you are buying vegetables only.
  3. You need math when you are buying only vegetables.
  4. You only need math when you are buying vegetables.

I understand 4. to imply that when buying vegetables, the purchaser needs math and nothing more—no money, shopping cart, etc.

I understand 3. to imply that math is needed in the singular context of buy vegetables.

I don't understand a difference, if there even is any, between 1. and 2.

Please correct me if I've misunderstood anything here.


Solution 1:

I agree with John Lawler. (But I'll see if I can stretch it out a bit!)

1) You need math only when you are buying vegetables might mean:
You need nothing but math when you are buying vegetables
OR
The only time you need math is when you are buying vegetables

2) You need math when you are buying vegetables only might mean:
You need math when you are buying nothing but vegetables
OR
You need math when all you are doing is buying vegetables
OR possibly
The only time you need math is when you are buying vegetables

3) You need math when you are buying only vegetables MEANS:
When you are buying nothing but vegetables you need math.

4) You only need math when you are buying vegetables. might mean:
Math is needed in the singular context of buying vegetables. (Your understanding of 3.)
OR
Math is the only thing you need when you are buying vegetables.

By the way, your own understanding of 4): 'when buying vegetables, the purchaser needs math and nothing more' would be better expressed as:
You need only math when buying vegetables.

When speaking, we might stress a particular word to make our meaning clearer. In writing, for absolute clarity we would re-phrase the sentence. You don't need math unless you're buying vegetables', for example.