23

Total has been changed in Mathematica 12.0. The documentation seems to contradict itself. In one line it states:

Total[ $f[ e_1,e_2,...]$ ] gives the sum of the $e_i$ for any head $f$

In the next line one reads:

By default, Total only adds up elements inside List, SparseArray, StructuredArray and Association.

As a matter of fact, in Mathematica 12.0 Total[ f[a,b] ] does not evaluate to a+b as it did in Mathematica 11.3. Instead, the new option AllowedHeads was introduced and one can for example write now Total[f[a,b], AllowedHeads->Inherited] for obtaining the old output.

This is a breaking change. I wonder if this was intended by Wolfram?

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
dnet
  • 958
  • 4
  • 12
  • 7
    Given that the option AllowedHeads is illegal in V11.3 and permissible now in V12, I'd say the change was clearly intended. You could use SetOptions[Total, AllowedHeads -> Inherited] as a general workaround. (It seems the documentation could use a good copy editor.) – Michael E2 May 22 '19 at 16:00
  • 7
    Consider adding this here – Michael E2 May 22 '19 at 16:01
  • 7
    I've always thought the M11 behavior was just a bug, and a pain to workaround. – Carl Woll May 22 '19 at 17:53
  • 2
    @CarlWoll No, it was a feature not a bug. Total[expr] was supposed to be equivalent to Plus @@ epxr. – Anton Antonov May 23 '19 at 08:10
  • 2
    Please always use full version numbers. There is no Mathematica 11, but there are 11.0, 11.1, etc. I corrected this in the post for now. – Szabolcs May 23 '19 at 08:19
  • Actually there seems to be version changes across product types as well. For example latest version of Mathematica is 12.0.0-6206958 while for Wolfram desktop is 12.0.0-6209708 and for free Wolfram engine is 12.0.0-6237879. Clearly larger build number means later build with more commits since latest build for 11.3 was 5944644. The latest version of the kernel is coming with free Wolfram engine and might have fixed some bugs of the other two products. – user13892 May 27 '19 at 14:10
  • 1
    In the function page for Total there is (still) the line "Total[list] is equivalent to Apply[Plus,list]." So, as I have mentioned earlier, the 11.3 behavior was a specially designed and adhered to feature (not a bug.) – Anton Antonov May 28 '20 at 09:36

0 Answers0