# Solve with a non-numerical-index constant

I have 4 different constants in a given expression. Due to their physical interpretation, it makes sense to label them with non numerical indices, such as $$r_+$$. The problem is that they prevent even simple commands from working, like Solve[A (r - r_+)== B , r] (imagine the "plus sign" as an index of the second "r").

Is there any elegant way out of this? I certainly cannot name my variable $$r+$$ and I would like to avoid large names (since my expressions are already too large).

Thanks in advance!

• Just call it rp. You could also use r₊ (U+208A) subscript plus sign, but I recommend against that. Also Subscript[r, "+"], but I don't like subscripts as they can cause problems - search for why. – flinty May 26 at 21:00
• Could also use r["+"]. – Daniel Lichtblau May 27 at 1:46
• Dear Lichtblau, that does NOT qualify as an index, right? I guess that will solve my issue, in spite of not being so clean as an actual subscript. – Sergio Jorás May 27 at 11:49
• If i use both suggestions I've received, i.e, Format[r["+"]] = Subscript["r", "+"]; Solve[A (x - r["+"]) == B, r["+"]] Then I'll get exactly what I was looking for: $r_+= \frac{A x-B}{A}$. – Sergio Jorás May 27 at 11:51
• However, it's not possible to calculate the derivative with a ('), since it will derive only the "r" in $r_+$, leaving a [["+"]]! The full command D[r-r[["+"]],r] works just fine. – Sergio Jorás May 28 at 11:22

## 2 Answers

Clear["Global*"]


Use Format to format output display of variables, e.g., rm and rp

Format[rm] = Subscript["r", "-"];
Format[rp] = Subscript["r", "+"];

Solve[A (r - rp) == B, r][[1]]


• Dear Hanlon, if I use "Format" I'll have to use rm in every input formula and it's only the output that will show $r_+$, right? – Sergio Jorás May 27 at 11:46
• Yes, Format only affects output display. – Bob Hanlon May 27 at 13:53

You could modify how Solve works with subscripts:

Unprotect[Solve];
Solve /: Solve[a__] /; !FreeQ[{a}, _Subscript] := Block[{CompressedData},
With[
{z = Unevaluated[Solve[a]] /. s_Subscript :> CompressedData[Compress[s]]},
z /; !MatchQ[z, _Solve]
]
]
Protect[Solve];


Then:

Solve[A (r - Subscript[r, "+"]) == B, r]


{{r -> (B + A Subscript[r, "+"])/A}}

Another example:

Solve[1/r == 1/Subscript[r, 1] + 1/Subscript[r, 2], r] //TeXForm
`

$$\left\{\left\{r\to \frac{r_1 r_2}{r_1+r_2}\right\}\right\}$$