# Apply tranformation to particular list elements

I have a list with elements

{a -> -1, b -> -2, c -> -3}


If I now wanted to apply a tranformation to b and c so that they would give the tranformation b -> 1-10^val and c -> 1-10^val, yielding

{a -> -1, b -> 0.99, c -> 0.999}


How would I do this in Mathematica?

• Ha yes apologies that's what I meant I changed my question accordingly - thanks for both of your answers they work perfectly! – Tom Wenseleers Nov 20 '15 at 16:02

## 2 Answers

I'm not sure whether you mean something different by 1-b^-2 or you just miscalculated, because your result is not the correct result. In general, you can transform transformation-rules like this:

{a -> -1, b -> -2, c -> -3} /.
{
(b -> val_) :> (b -> 1 - val^-2),
(c -> val_) :> (c -> 1 - val^-3)
}


And in case Kuba is right about what you really want, then you can use

{a -> -1, b -> -2, c -> -3} /.
{
(b -> val_) :> (b -> 1 - 10.0^val),
(c -> val_) :> (c -> 1 - 10.0^val)
}
(* {a -> -1, b -> 0.99, c -> 0.999} *)


Or

{a -> -1, b -> -2, c -> -3} /.
{(key : b | c -> val_) :> (key -> 1 - 10.0^val)}

• Also, val are equal to powers, which is suspicious. I suppose to formula is 1-10^val. – Kuba Nov 20 '15 at 11:59
• Was already adding it :-) – halirutan Nov 20 '15 at 12:11
• Many thanks for this - works perfectly! 2nd solution is what I was looking for - sorry for the typo in my question! – Tom Wenseleers Nov 20 '15 at 16:04
list = {a -> -1, b -> -2, c -> -3}


The quesiton is unclear but let's say I know what you want :)

MapAt[
1. - 10^# &,
Association[list],
List@*Key /@ {b, c}] // Normal


{a -> -1, b -> 0.99, c -> 0.999}

You could work on Association from the begining, then you can skip Association[] and Normal which makes it even more compact.

Other way, if you know positions and don't want to use Associations:

MapAt[
1. - 10^# &,
list,
{2 ;; 3, 2}]

• Many thanks for this - works perfectly! – Tom Wenseleers Nov 20 '15 at 16:04