# Turning arguments into exponents

I'd like to replace every instance of L[stuff], e.g.,

L[-1,-2,-2]


in an expression with x^(-FromDigits[{stuff}]), e.g.

x^122


. But I'm running into an issue-- I'd like to do this with the code

L[-1, -2, -2] /. L[a___] -> x^(FromDigits[-{a}])


but this produces

2/x^6 + x^4 + x^5.


In trouble-shooting, I noticed that while

L[-1, -2, -2] /. L[a___] -> {a}


produces the output I expected, namely {-1,-2,-2}, I found that

L[-1, -2, -2] /. L[a___] -> -{a}


just produces {4} rather than {1,2,2}. I must be misunderstanding how Sequence behaves when it shows up in the right side of a Rule since when I try just inputting -{Sequence[-1,-2,-2]} I get the expected result {1,2,2}. Does anyone see where I'm going wrong? Thanks!

• funny, I asked a very similar question last week, I wonder if its the same issue. Anyway, here is a possible workaround: L[-1, -2, -2] /. L[a___] :> x^(FromDigits[-{a}]). – AccidentalFourierTransform Jul 11 at 20:12
• @AccidentalFourierTransform yup it would appear to be exactly the same issue and my reaction to FullForm[-b] was exactly the same as yours lol – Diffycue Jul 11 at 20:18

## 2 Answers

Here's an explanation of why you get {4}. As mentioned above, your problem is the use of Rule instead of RuleDelayed, which means the RHS of the rule evaluates before the rule is used. So, let's see what the RHS of the rule evaluates to:

-{a} //FullForm


List[Times[-1,a]]

So, when evaluated, the rule becomes:

L[a___] -> {Times[-1, a]}


Now, it should be clear what happens. When the rule is applied, a gets bound to the sequence -1, -2, -2, and so the output (before evaluation) is:

{Times[-1, -1, -2, -2]}


which evaluates to:

{4}

It's just a matter of using RuleDelayed, or rather :> instead of ->.

L[-1, -2, -2] /. L[a___] :> x^(FromDigits[-{a}])


x^122

L[-1, -2, -2] /. L[a___] :> -{a}


{1, 2, 2}