Message Boards Message Boards

0
|
2044 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Bug in Distribute Function (?)

Posted 10 years ago

What's going on here: Distribute[(a - b)^2]

Output:a^2 + b^2

While Distribute[(a - b) (c - d)] gives

a c - b c - a d + b d

Mathematica Version 9.0.1

2 Replies
In[2]:= FullForm[(a - b)^2]

Out[2]= Power[Plus[a, Times[-1, b]], 2]

so the square operation is distributed over a and -b inside Plus.

For the desired result, try

In[4]:= Distribute[Unevaluated[(a - b) (a - b)]]

Out[4]= a^2 - 2 a b + b^2

see also 'Possible Issues' in the documentation of Distribute.

POSTED BY: Ilian Gachevski

Thank you. But in future I will use Expand instead of Distribute.

Best regards

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract