Download it now!
Bug 43135 - MULTINOMIAL only supports parameters up to 170
Summary: MULTINOMIAL only supports parameters up to 170
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
(earliest affected)
3.3.2 release
Hardware: Other All
: low enhancement
Assignee: Albert Thuswaldner
Whiteboard: target:3.7.0
Depends on:
Reported: 2011-11-21 03:02 UTC by Björn Michaelsen
Modified: 2012-08-10 14:12 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:

Test file to check algorithm (15.26 KB, application/vnd.oasis.opendocument.spreadsheet)
2012-08-02 23:17 UTC, Albert Thuswaldner

Note You need to log in before you can comment on or make changes to this bug.
Description Björn Michaelsen 2011-11-21 03:02:07 UTC
What is expected to happen in a blank LibreOffice Calc document is when one types in a cell:


it returns 1.

What happens instead is it returns Err:502.

More information about multinomial may be found at:

Original bug at launchpad filed against 3.4, but also reproducible in master.
Comment 1 Björn Michaelsen 2011-11-21 03:04:47 UTC
@Kohei, Eike: Please reassign (or self-assign) as appropriate.

Also: Possible regression?
Comment 2 Christopher M. Penalver 2011-11-21 03:16:54 UTC
Reproducible in LibreOffice 3.3.2.

lsb_release -rd
Description: Ubuntu 10.04.3 LTS
Release: 10.04

apt-cache policy libreoffice-calc
  Installed: 1:3.3.2-1ubuntu2~lucid1
  Candidate: 1:3.3.2-1ubuntu2~lucid1
  Version table:
 *** 1:3.3.2-1ubuntu2~lucid1 0
        500 lucid/main Packages
        100 /var/lib/dpkg/status
Comment 3 Markus Mohrhard 2011-11-21 16:23:57 UTC
Ok, problem is just that we only support values up to 170 as paramters of MULTINOMIAL, I don't think that this is a regression.
Comment 4 Björn Michaelsen 2011-11-24 10:15:51 UTC
Thanks Markus.
Adjusting importance accordingly.
Comment 5 Bas Braams 2011-11-25 11:33:42 UTC
The presumed cause of the bug is that the multinomial is computed as a ratio of factorials; this would indeed cause an overflow when the sum of the arguments exceeds 170. Please note that for the implementation of the Binomial in LibreOffice Calc (function COMBIN) no such restriction applies; it is computed carefully to avoid unnecessary overflow.

Please note also that the bug with multinomial would be almost trivial to fix.

A recurrence for computing the multinomial function as a product of
binomials may be found in the description of the multinomial function in
the Sage mathematics system:

The associated 5-line Python code by Gabriel Ebner may be found here:

I believe that this is a very natural way to compute the multinomial, and it would completely remove the problem of unnecessary overflow.
Comment 6 Markus Mohrhard 2011-11-25 21:57:43 UTC
Feel free to implement it. Source code for this function is at:

I'm looking forward to your contribution.
Comment 7 Albert Thuswaldner 2012-07-31 23:43:33 UTC
Proposed fix:
Comment 8 Albert Thuswaldner 2012-08-02 23:17:02 UTC
Created attachment 65063 [details]
Test file to check algorithm
Comment 9 Not Assigned 2012-08-10 14:11:49 UTC
Albert Thuswaldner committed a patch related to this issue.
It has been pushed to "master":

fdo#43135 - fix for MULTINOMIAL only supporting parameters up to 170