rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

multinomial handles only numeric arguments, was: error in subst,lratsubst #3314

Open rtoy opened 1 week ago

rtoy commented 1 week ago

Imported from SourceForge on 2024-07-07 20:50:59 Created by zmth on 2019-02-26 10:01:37 Original: https://sourceforge.net/p/maxima/bugs/3531


Error in lratsubst or subst:

(tt:sum(sum(multinomial(m2,[m21,m22])*sum(sum(multinomial(m1,[m11,m12])
*sum(binomial(m3,m31)*(-1)^m31*v^(2*(m12+m22+m31))*u^(2*(m1+m2
+m3-m31-m11-m12-m21-m22)),m31,0,m3),m12,0,m1-m11)*(-1)^m21*2
^(m11+m21)*(u.v)^(m11+m21),m11,0,m1) ,m22,0,m2-m21),m21,0,m2) 
,lratsubst([m12+m22+m31=n2,m1+m2+m3-m31-m11-m12-m21-m22=n1
,m11+m21=n3],tt))

Maxima encountered a Lisp error:
 Error in < [or a callee]: #:G621829 is not of type (OR RATIONAL
                                                     LISP:FLOAT).

get same message if just use subst instead of lratsubst

rtoy commented 1 week ago

Imported from SourceForge on 2024-07-07 20:51:00 Created by robert_dodier on 2019-03-02 00:38:29 Original: https://sourceforge.net/p/maxima/bugs/3531/#a32c


Diff:


--- old
+++ new
@@ -1,4 +1,5 @@
 Error in lratsubst or subst:
+~~~~
 (tt:sum(sum(multinomial(m2,[m21,m22])*sum(sum(multinomial(m1,[m11,m12])
 *sum(binomial(m3,m31)*(-1)^m31*v^(2*(m12+m22+m31))*u^(2*(m1+m2
 +m3-m31-m11-m12-m21-m22)),m31,0,m3),m12,0,m1-m11)*(-1)^m21*2
@@ -9,7 +10,7 @@
 Maxima encountered a Lisp error:
  Error in < [or a callee]: #:G621829 is not of type (OR RATIONAL
                                                      LISP:FLOAT).
-                                                     
+~~~~
 get same message if just use subst instead of lratsubst                                                     
rtoy commented 1 week ago

Imported from SourceForge on 2024-07-07 20:51:03 Created by robert_dodier on 2019-03-02 00:38:29 Original: https://sourceforge.net/p/maxima/bugs/3531/#db78


Running Maxima with maxima -g (to enable the debugger) I see from the stack trace after the error that the error is in multinomial.

Looking at the source code in share/sym/util.lisp, I see it's written so it can only handle numeric inputs; it can't handle symbols, and it doesn't produce a useful error message in that case. So the documentation and/or error handling for multinomial can be improved, and maybe even modify it to handle symbolic arguments.

I think you can make progress by calling multinomial_coeff instead of multinomial. Note that the arguments for multinomial_coeff are a little different. See ? multinomial_coeff for more information.

rtoy commented 1 week ago

Imported from SourceForge on 2024-07-07 20:51:07 Created by zmth on 2019-05-12 16:02:30 Original: https://sourceforge.net/p/maxima/bugs/3531/#e71b


yea i found that out myself to use multinomial_coeff instead. i don't really know what the use of multinomial would be