# Equivalent command to the Maple indets command

This carries on the discussion here and here.

I had mistaken Variable[] to give you ALL variables in an expression, but apparently, it is not meant for that.

Needs["Notation"]

Symbolize[ParsedBoxWrapper[SubscriptBox["x", "_"]]]
Symbolize[ParsedBoxWrapper[SubscriptBox["y", "_"]]]
var1 = Table[ToExpression["Subscript[x, " <> ToString[i] <> "]"], {i, 10}]
var2 = Table[ToExpression["Subscript[y, " <> ToString[i] <> "]"], {i, 10}]

expr = var1*Exp[var2]^var1

Variables[Level[expr, 1]]
Variables[Level[expr, -1]]


I have tried to Level it our with many different values. But none seem to be working.

Basically, I am looking for an equivalent command in Mathematica to the Maple indets.

• What is the desired result? – Kuba Oct 15 '14 at 20:00
• Cases[expr, Subscript[__], Infinity] // Union – Bob Hanlon Oct 15 '14 at 20:27
• @Kuba The desired result would be all the variables considered, i.e. everything in var1 and var2. – Chen Stats Yu Oct 15 '14 at 22:18

The problem you are having is to do with the way Symbolize works ...I think, specifically I am pretty sure the actual symbolized expression has to be typeset in your cell rather than referring to it via another variable. Someone else might like to explain that more elegantly.

Firstly you don't need to use strings:

Clear[x, y, var1, var2];

var1 = Table[Subscript[x, i], {i, 10}]
var2 = Table[Subscript[y, i], {i, 10}]

expr = var1*Exp[var2]^var1


Next step is to see what the problem is:

Head /@ var1
(* {Subscript, Subscript, Subscript, Subscript, Subscript, Subscript,
Subscript, Subscript, Subscript, Subscript} *)


and

AtomQ /@ var1
{False, False, False, False, False, False, False, False, False, False}


So for your subscripted variables to be "scraped" in some way from expr you need them to be recognised as symbols and as atoms. I am not 100% sure on why there is a difference -- probably something obvious I have overlooked -- but in any case consider the following:

so therefore try:

and

Union@Cases[expr1, _Symbol, \[Infinity]]
(* {E, Subscript[x, 1], Subscript[x, 10], Subscript[x, 2], Subscript[x, \
3], Subscript[x, 4], Subscript[x, 5], Subscript[x, 6], Subscript[x, \
7], Subscript[x, 8], Subscript[x, 9], Subscript[y, 1], Subscript[y, \
10], Subscript[y, 2], Subscript[y, 3], Subscript[y, 4], Subscript[y, \
5], Subscript[y, 6], Subscript[y, 7], Subscript[y, 8], Subscript[y, 9]
} *)


Edit

As per Rolfs suggestion to screen out system variables:

Union@Cases[expr1, z_Symbol /; Context[z] =!= "System", \[Infinity]]


or alternatively if everything is in a global context only:

Union@Cases[expr1, z_Symbol /; Context[z] === "Global", \[Infinity]]

• But E is not considered to be a variable by Variables. Maybe add something like Function[z, Context[z] =!= "System"] or some such. – Rolf Mertig Oct 15 '14 at 21:33
• Yes good idea @RolfMertig. Do you have a more elegant explanation of the way Symbolize works? My attempted comment in my answer is rather clumsy. But it is still breakfast time here and my brain is foggy – Mike Honeychurch Oct 15 '14 at 21:41
• @Mike I share the same option with @RolfMertig, E should not be a variable. Just to comment on the Variable[] function, I still don't get it, why Mathematica does not have a "straightforward" function, returns all variables in a general expression. Instead, MMA decided that "variables" are only important in "polynomials". Just so weird. For the example above, I have made it more "complicated" than the actual problem I need, but again, I can make it more complicated, just to make a particular solution fail. But the Maple indets() command, always give you what you would expect. – Chen Stats Yu Oct 15 '14 at 21:43
• @ChenStatsYu Mma is really poor with subscripted variables ..surprising for a software that many would say is the best computer algebra software. Mathcad is great for subscripted variable, easily the best on the market, but of course it has other deficiencies relative to Mma. As a Maple user you would know that Maple also is much better than Mma for subscripted variables, but not as good as Mathcad. – Mike Honeychurch Oct 15 '14 at 21:48
• Do not use Subscript and do not use Notation for anything non-trivial. What I sometimes do is something like MakeBoxes[x1, _] := InterpretationBox[SubscriptBox["x", 1], x1] and then you can input x1 and get displayed a subscripted x1 and it also behaves nice w.r.t. to InputForm and Variables etc. – Rolf Mertig Oct 15 '14 at 22:03