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]]} *)
  • $\begingroup$ what do you mean by "I want these symbols to be assumed real."? $\endgroup$ Apr 15, 2013 at 12:25
  • $\begingroup$ @belisarius Re[d[1]] should return d_1 $\endgroup$
    – Yrogirg
    Apr 15, 2013 at 12:38

3 Answers 3


You can create the following set of upvalues for Subscript:


if you want to clear the new rules run the command

UpValues[Subscript] = {}
  • $\begingroup$ It should be also complemented with Subscript /: Im[s_Subscript] := 0 $\endgroup$
    – Yrogirg
    Apr 15, 2013 at 13:55
  • $\begingroup$ @Yrogirg done!:) $\endgroup$
    – Spawn1701D
    Apr 15, 2013 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]}*)

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=..


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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