11
$\begingroup$

Using Mathematica 11 when I define a list

yy = {x*43, 32*y};

and then convert it to a sum

yy[[0]] = Plus;
yy

I get, as expected, x*43 + 32*y.

However, as soon as I try to multiply my sum with a minus sign, i.e. when I execute

-yy

my kernel quits without any error message.

Any ideas why this happens and how to avoid it?


The problem can be avoided by converting the list using a Do loop:

sum = 0;
Do[
  sum = sum + yy[[i]],
  {i, Length[yy]}
  ];
sum
-sum
(* 43 x + 32 y *)
(* -43 x - 32 y *)
$\endgroup$
9
  • 3
    $\begingroup$ I can reproduce it on Win10 V10.4 - V11.3 $\endgroup$
    – Kuba
    Commented May 8, 2018 at 9:22
  • $\begingroup$ Same on win7 64 bit. $\endgroup$ Commented May 8, 2018 at 9:23
  • 3
    $\begingroup$ p.s. Tr or Total or Plus @@ are more idiomatic than Do. And all work. $\endgroup$
    – Kuba
    Commented May 8, 2018 at 10:29
  • 3
    $\begingroup$ Reproduced for V11.0.1 and V11.3 on macOS. Voting for bug tag. $\endgroup$ Commented May 8, 2018 at 10:38
  • 4
    $\begingroup$ Surely one of the weirdest bugs I've seen. -2 yy works just fine. -2 yy/2 crashes the kernel again, and so does I I yy. $\endgroup$ Commented May 8, 2018 at 13:36

0

Browse other questions tagged or ask your own question.