# How to treat indexed variables as Reals? Can they be symbolized?

First of all, this is quite related to this question here, however the solution given there does not apply to my issue.

I am generating a huge symbolic matrix, which has many (on the order of 50-100) indexed parameters originating in various sums. All of my symbols and indexed variables are real, so I would like to make use of that when I for instance perform a Conjugate operation on the matrix.

See below minimal working example:

test = Exp[I*k];
# + Conjugate[#] &@test
(* E^(-I Conjugate[k]) + E^(I k) *)
Refine[%, Assumptions -> k \[Element] Reals]
(* E^(-I Conjugate[k]) + E^(I k) *)
Refine[%, Assumptions -> k \[Element] Reals]
(* E^(-I k) + E^(I k)1 *)


An approach like Refine[...,Assumptions->_Symbol ∈ Reals] will also not work, since Head[k] is k, not Symbol. The list of all indexed variables is not known in advance and changes as soon as I play with certain parameters, so I cannot just retrieve them once in order to get a full list and use this in Assumptions.

Is there a way to tell mathematica that all Symbols and indexed variables are Reals? Presumably it can be done using Symbolize from the Notation package, but I don't know how (I have seen it for Subscripts but really want to avoid using them). How to deal with symbols is clear from the linked question, but achieving it for indexed variables is a myth for me right now.

• Can you use ComplexExpand? – Marius Ladegård Meyer Nov 22 '16 at 11:07
• @MariusLadegårdMeyer Right now, yes. But the size of my matrices will grow quite a lot in future work and also the "length" of each element. So I am unsure if ComplexExpand might take too long in those cases. I was thinking about using a rule like Complex[a_,b_]:>Complex[a,-b] instead of Conjugate but I have a feeling that this is not safe. – Lukas Nov 22 '16 at 12:00
• What are you going to do with the matrices? Look at them, solve equations involving them...? – Marius Ladegård Meyer Nov 22 '16 at 12:18
• @MariusLadegårdMeyer At first, it is mostly looking at them and transfering them to Matlab for further numerical simulations. However, depending on the numerical results, I might also try to work with the symbolic matrices in Mathematica which would for instance involve some series expansions and solving equations based on those matrices. – Lukas Nov 22 '16 at 12:21
• Assumptions -> _k ∈ Reals, or Assumptions -> (s_Symbol /; Context@s =!= "System")[_Integer? Positive] ∈ Reals? – jkuczm Nov 29 '16 at 17:17

An approach like Refine[...,Assumptions->_Symbol ∈ Reals] will also not work, since Head[k] is k, not Symbol.

You are almost there: just use a proper pattern to match objects with Head k. Here are several ways:

test = Exp[I*k];
expr = # + Conjugate[#] &@test;

Refine[expr, Assumptions -> _k ∈ Reals]
Refine[expr, Assumptions -> k[_] ∈ Reals]
Refine[expr, Assumptions -> k[_Integer] ∈ Reals]

E^(-I k) + E^(I k)

E^(-I k) + E^(I k)

E^(-I k) + E^(I k)


(checked with Mathematica versions 11.2.0, 8.0.4 and 5.2).

Is there a way to tell Mathematica that all Symbols and indexed variables are Reals?

Here is a way to declare that every Symbol or indexed object is Real:

Refine[expr, Assumptions -> _Symbol[_Integer] ∈ Reals && _Symbol ∈ Reals]

E^(-I k) + E^(I k)


A more restrictive approach to declare that every indexed variable is Real is suggested by jkuczm in the comments:

Refine[expr,
Assumptions -> (s_Symbol /; Context@s =!= "System")[_Integer?Positive] ∈ Reals]

E^(-I k) + E^(I k)


It can easily be extended to Symbols:

Refine[expr,
Assumptions -> ((s_Symbol[_Integer?Positive] | s_Symbol) /;
Context@s =!= "System") ∈ Reals]

E^(-I k) + E^(I k)


You can Symbolize classes of expressions based on rules. For example,

Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]], WorkingForm -> StandardForm]


will declare any subscripted expression to be considered a symbol and be subsequently treated as such. Also see the tutorial here.

Edit: Sorry, I realize I may have misunderstood your question. Do you want expressions such as k to be considered symbols? If so, then I don't think that can be done. You may be able to construct some notation for certain types of expressions, but not in the way it appears from your original post, since that would require modifying core WL syntax.

• Exactly, my idea for a solution was to symbolize k`. However, this is not mandatory... I thought it might be the easiest way to aim at declaring everything as real. – Lukas Nov 22 '16 at 17:40