7
$\begingroup$

Version 11.3 introduces ApplySides for situations where I usually use Map. What is an example where ApplySides cannot be replaced by Map?

$\endgroup$
7
  • 1
    $\begingroup$ My understanding is that these functions were introduced for the main purpose to make it easier for new users and school/college students to use Mathematica to work with and manipulate basic equations. Wolfram himself said something to this effect in one of his design review videos on these functions twitch.tv/videos/207012986 (45:05). They are higher level, more abstract than manipulating the structure directly using map and threading and pure functions. I do not think there is a performance advantage, but they simplify common operations on equations. No time to give examples. $\endgroup$
    – Nasser
    Jul 18 '18 at 21:27
  • 6
    $\begingroup$ This function will behave differently for expressions with Piecewise or ConditionalExpression for example. Also, examine the FullForm of 0 < x <= 1 and note that Map would not do what you want in this case. $\endgroup$
    – Chip Hurst
    Jul 18 '18 at 21:29
  • 1
    $\begingroup$ Yes, for Equal then it is equivalent to Map. Would it make sense to turn my above comment into an answer? $\endgroup$
    – Chip Hurst
    Jul 18 '18 at 22:53
  • 1
    $\begingroup$ @Nasser This could turn into a teacher's nightmare when students start doing ApplySides[ Minus, x > y]... because all the other *Sides operations work differently (they don't just do mapping)... $\endgroup$
    – Jens
    Jul 18 '18 at 23:30
  • 1
    $\begingroup$ @Nasser Quite; that's what I had in mind as a "risky application". $\endgroup$
    – Alan
    Jul 18 '18 at 23:38
7
$\begingroup$

ApplySides knows more about mathematical expressions than Map, which is a structural operation. For example it knows how to handle heads like Piecewise, ConditionalExpression, Inequality, etc.

ApplySides[Sin, Piecewise[{{x^2 < 1, x > 2}}, x^3 > 1]]
Piecewise[{{Sin[x^2] < Sin[1], x > 2}}, Sin[x^3] > Sin[1]]
ApplySides[Sin, ConditionalExpression[x^2 == 1, x != 0]]
 ConditionalExpression[Sin[x^2] == Sin[1], x != 0]
ApplySides[Sin, 0 < x <= 1]
0 < Sin[x] <= Sin[1]

And here's Map (at level 1):

Map[Sin, Piecewise[{{x^2 < 1, x > 2}}, x^3 > 1]]
Piecewise[{{Sin[x^2 < 1], Sin[x > 2]}}, Sin[x^3 > 1]]
Map[Sin, ConditionalExpression[x^2 == 1, x != 0]]
ConditionalExpression[Sin[x^2 == 1], Sin[x != 0]]
Map[Sin, 0 < x <= 1]
Inequality[0, Sin[Less], Sin[x]] && Inequality[Sin[x], Sin[LessEqual], Sin[1]]

Additionally note that ApplySides cousins AddSides, SubtractSides, MultiplySides, DivideSides will never give a wrong answer, whereas ApplySides (and Map) can.

ApplySides[a*# &, b < c]
a b < a c
Map[a*# &, b < c]
a b < a c
MultiplySides[b < c, a]
Piecewise[{{a*b < a*c, a > 0}, {a*c < a*b, a < 0}}, b < c]
$\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.