2

How can I simplify the expressions of the values in an association in a simple way?

For example,

as = <|c1 -> x, c2 -> y x + y x + x x + y y , c3 -> z|> ;

as// Simplify 

does not give the result

<|c1 -> x, c2 -> (x + y)^2, c3 -> z|>

in Ver 11.0.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Orders
  • 1,247
  • 11
  • 20

2 Answers2

2

Simplify threads over lists, but not over associations, so

as // Normal // Simplify

{c1 -> x, c2 -> (x + y)^2, c3 -> z}

works, but

as // Simplify

doesn't. Recommend using Map

Simplify /@ as

Association[c1 -> x, c2 -> (x + y)^2, c3 -> z]

as suggested in the comments to your question.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
1
AssociationMap[Simplify][as]

<|c1 -> x, c2 -> (x + y)^2, c3 -> z|>

kglr
  • 394,356
  • 18
  • 477
  • 896