Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a function returning subscripted symbols and I want these symbols to be assumed real. How do I do that?




(* {Re[Subscript[d, 1]],0,Re[Subscript[d, 3]],0,Re[Subscript[d, 5]]} *)
share|improve this question
what do you mean by "I want these symbols to be assumed real."? – Dr. belisarius Apr 15 '13 at 12:25
@belisarius Re[d[1]] should return d_1 – Yrogirg Apr 15 '13 at 12:38

You can create the following set of upvalues for Subscript:


if you want to clear the new rules run the command

UpValues[Subscript] = {}
share|improve this answer
It should be also complemented with Subscript /: Im[s_Subscript] := 0 – Yrogirg Apr 15 '13 at 13:55
@Yrogirg done!:) – Spawn1701D Apr 15 '13 at 14:59

Although @Spawn1701D 's solution seems to be working for simple cases, I couldn't make Mathematica to take Re of more bulky expressions. However there is an easy workaround via ComplexExpand :

ClearAll[Evaluate[Context[] <> "*"]]

d[n_] := If[OddQ[n], Subscript[d, n], 0]

Map[ComplexExpand[Re[d[#]]] &, Range[1, 5]]

(*{Subscript[d, 1], 0, Subscript[d, 3], 0, Subscript[d, 5]}*)
share|improve this answer

The following function createVars creates a specified number of subscripted variables, adds the appropriate assumptions to $Assumtpions and returns the variable list:

createVars[name_String, i_Integer] := With[{
   vars = Array[Subscript[ToExpression@name, #] &, i]},
  If[$Assumptions === True,
    $Assumptions = {vars \[Element] Reals},
    AppendTo[$Assumptions, vars \[Element] Reals]];

To make use of the assumptions, just apply Simplify:

enter image description here

If you want to remove the assumptions at some point, use $Assumptions=..

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.