2
$\begingroup$

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.

$\endgroup$
4
  • 2
    $\begingroup$ AssociationThread[Keys[as], Simplify[Values[as]]], among others... $\endgroup$
    – ciao
    Mar 3 '17 at 1:28
  • 1
    $\begingroup$ In version 10.1 Simplify /@ as returns <|c1 -> x, c2 -> (x + y)^2, c3 -> z|> -- what do you get? $\endgroup$
    – Mr.Wizard
    Mar 3 '17 at 1:31
  • $\begingroup$ @Mr.Wizard - beat me to it, you sly fox. Same in 10.3 $\endgroup$
    – ciao
    Mar 3 '17 at 1:32
  • $\begingroup$ @ciao I am wondering how mathematica.stackexchange.com/q/124603/121 affects this, or if it does at all. $\endgroup$
    – Mr.Wizard
    Mar 3 '17 at 1:34
2
$\begingroup$

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.

$\endgroup$
1
$\begingroup$
AssociationMap[Simplify][as]

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.