Turning arguments into exponents
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}