# Pattern matching in subscripted variables

I am trying to use subscripted variables as symbols and provide assumptions elegantly for them, e.g. in order to simplify logs, I'd like to have

Simplify[ Log[Subscript[x,1]^2] - Log[Subscript[x,2]^2], Assumptions -> Subscript[x,_] > 0]


be simplified to

Log[Subscript[x,1]^2 / Subscript[x,2]^2]


I am aware of the Notation package, but symbolizing any subscripted variable prevents me from pattern matching variable names. I am as well aware of the fact, that this is an incarnation of the same old story of "Don't put data in your variable names".

Apart from that it makes the output hard to read, I couldn't get

Simplify[Log[y^2] - Log[y^2], Assumptions -> y[_] > 0]


to make the desired simplification, either. Hence, putting the subscript as an extra parameter of a "function" fails as well.

What would be the elegant and formally correct way to implement the desired behaviour without enumerating the different variables as x1, x2, ... and having to explicitly state the assumption for every single variable in the game?

Scope: I have a whole lot of different masses in my calculation, hence I wanted to keep track of them by using subscripts. In the end, I'd like to give certain linear combinations of fundamental masses special names and have logarithms like the ones above simplified.

Thank you very much in advance!

Best Ben

• Sure! Sorry about that, fixed it in the original post. – Ben Nov 21 '12 at 12:56
• Simplify[Log[Subscript[x, 1]^2] + Log[Subscript[x, 2]^2], Table[Subscript[x, k] > 0, {k, 2}]] wouldn't be useful, then? – J. M.'s discontentment Nov 21 '12 at 12:56
• That works in the outlined example. Suppose I don't use numerical indices exclusively - that makes clear, this approach still is some kind of "brute force" method stating the assumption for every single variable. This might not be the way, subscripts are supposed to be used?! Thank you very much for that workable suggestion though, using numeric indices everything should thus work.. – Ben Nov 21 '12 at 13:11

This raises the question of how to generate a list of assumptions for a set of variables that's defined only by a pattern, not as an explicit list. One way you could achieve that is to use your pattern Subscript[x,_] to generate an explicit list from the expression first, and then use the latter for the Assumptions in Simplify:

    Simplify[#,
Thread[Cases[#, Subscript[x, _], Infinity] > 0]] &[
Log[Subscript[x, 1]^2] - Log[Subscript[x, 2]^2]]


$\log \left(\frac{x_1^2}{x_2^2}\right)$

This looks a little terse, so the cleaner thing would be to split it into two steps:

expr = Log[Subscript[x, 1]^2] - Log[Subscript[x, 2]^2];

Simplify[expr, Thread[Cases[expr, Subscript[x, _], Infinity] > 0]]


$\log \left(\frac{x_1^2}{x_2^2}\right)$

The Cases collects all the instances that match the pattern in your expression expr, and the Thread applies the (common) condition (being greater than zero) to all elements of the resulting list.