12
$\begingroup$

Bug introduced in 11.3 or earlier and fixed on 12.0.


Sometimes get a results, sometimes left unevaluated.

For instance

 Area@Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}] 

12

Transpose@(a.b.Transpose[#]) & /@ Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}] 

(a,b - some 2x2 matrices)

Polygon[{{0, 0}, {8, -64}, {18, -24}, {36, -48}, {28, 16}}]

Area@(Transpose@(a.b.Transpose[#]) & /@ Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}] )

Area[Polygon[{{0, 0}, {8, -64}, {18, -24}, {36, -48}, {28, 16}}]]

Area@Polygon[{{0, 0}, {8, -64}, {18, -24}, {36, -48}, {28, 16}}]

(copy and paste)

1440

How to guess when a calculation will give a result and when it will not be evaluated? And why does it not evaluate?

$\endgroup$
2
  • 4
    $\begingroup$ What are the definitions of a and b? $\endgroup$
    – MarcoB
    Mar 22, 2019 at 14:36
  • $\begingroup$ If you want to experiment with this and I haven't made a mistake then it looks like his a.b == {{2,7},{-16,4}} This seems to reproduce his results. $\endgroup$
    – Bill
    Mar 22, 2019 at 16:15

2 Answers 2

10
$\begingroup$

This is a packed array issue:

Area @ Polygon[Developer`ToPackedArray @ {{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]

Area[Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]]

This will be fixed in M12.

$\endgroup$
1
  • $\begingroup$ It was a bug and it was fixed! It works expectionally at 12.0 Thank you, thank Mathematica, thank Wolfram! $\endgroup$ Apr 26, 2019 at 5:24
11
$\begingroup$

EDIT: Reported to WRI as CASE:4237867 - fixed on V12. :)

Seems like a bug in my opinion. Consider the following:

With[{poly0 = Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]}, 
 With[{poly = Transpose[IdentityMatrix[2].Transpose@#] & /@ poly0},
  {poly0 === poly, Area /@ {poly0, poly}}]]

{True, {12, Area[Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]]}}

Although the Mma considers poly0 and its transformed but identical copy (coordinates transformed using IdentityMatrix) identical, they produce different results.

Probably the internal representation of poly is not the same as poly0. At the same time its output form is identical, which actually transforms it to other form if you copy and paste it.

This can be further simplified to show that from the perspective of Polygon two semantically identical coordinate lists can differ:

With[{coord0 = {{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}}, 
 With[{coord = Transpose[IdentityMatrix[2].Transpose@coord0]},
  {coord0 === coord, Area@*Polygon /@ {coord0, coord}}]]

{True, {12, Area[Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]]}}

I suspect there's something wrong with the way Polygon reads the internal representation of a list!

EDIT: I think there's a good chance this problem is caused by the fact coord is a packed array, while coord0 is not:

With[{coord0 = {{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}}, 
 With[{coord = Transpose[IdentityMatrix[2].Transpose@coord0]},
  {coord0 === coord, Developer`PackedArrayQ /@ {coord0, coord}, 
   Area@*Polygon /@ {coord0, Developer`FromPackedArray@coord}}]]

{True, {False, True}, {12, 12}}

So, you can use FromPackedArray on the transformed coordinate list as a workaround.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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