Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversion of binomial fails #6197

Closed
sagetrac-whuss mannequin opened this issue Jun 3, 2009 · 10 comments
Closed

conversion of binomial fails #6197

sagetrac-whuss mannequin opened this issue Jun 3, 2009 · 10 comments

Comments

@sagetrac-whuss
Copy link
Mannequin

sagetrac-whuss mannequin commented Jun 3, 2009

Converting symbolic expressions containing binomial coefficients
to maxima elements does not work.

sage: maxima(binomial(2*x, x))
sage1

Also the conversions to mathematica and maple fail:

sage: mathematica(binomial(2*x, x))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/huss/.sage/temp/bernoulli/6709/_home_huss__sage_init_sage_0.py in <module>()

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/interfaces/expect.pyc in __call__(self, x, name)                                                                                                    
   1024             return cls(self, x, name=name)                                                               
   1025         try:                                                                                             
-> 1026             return self._coerce_from_special_method(x)                                                   
   1027         except TypeError:                                                                                
   1028             raise                                                                                        

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/interfaces/expect.pyc in _coerce_from_special_method(self, x)                                                                                       
   1048             s = '_gp_'                                                                                   
   1049         try:                                                                                             
-> 1050             return (x.__getattribute__(s))(self)                                                         
   1051         except AttributeError:                                                                           
   1052             return self(x._interface_init_())                                                            

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/structure/sage_object.so in sage.structure.sage_object.SageObject._mathematica_ (sage/structure/sage_object.c:5033)()                               

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._interface_ (sage/symbolic/expression.cpp:3293)()                                     

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/structure/sage_object.so in sage.structure.sage_object.SageObject._interface_ (sage/structure/sage_object.c:2828)()                                 

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/interfaces/expect.pyc in __call__(self, x, name)                                                                                                    
   1022                                                                                                          
   1023         if isinstance(x, basestring):                                                                    
-> 1024             return cls(self, x, name=name)                                                               
   1025         try:                                                                                             
   1026             return self._coerce_from_special_method(x)                                                   

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/interfaces/expect.pyc in __init__(self, parent, value, is_name, name)
   1426             except (TypeError, KeyboardInterrupt, RuntimeError, ValueError), x:
   1427                 self._session_number = -1
-> 1428                 raise TypeError, x
   1429         self._session_number = parent._session_number
   1430

TypeError: Error executing code in Mathematica
CODE:
        sage1=<function binomial at 0x917ddbc>[(x)*(2),x];
Mathematica ERROR:
        Syntax::sntxf: "sage1=" cannot be followed by
    "<function binomial at 0x917ddbc>[(x)*(2),x];".
sage: maple(binomial(2*x, x))                       
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/huss/.sage/temp/bernoulli/6709/_home_huss__sage_init_sage_0.py in <module>()

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/interfaces/expect.pyc in __call__(self, x, name)                                                                                                    
   1024             return cls(self, x, name=name)                                                               
   1025         try:                                                                                             
-> 1026             return self._coerce_from_special_method(x)                                                   
   1027         except TypeError:                                                                                
   1028             raise                                                                                        

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/interfaces/expect.pyc in _coerce_from_special_method(self, x)                                                                                       
   1048             s = '_gp_'                                                                                   
   1049         try:                                                                                             
-> 1050             return (x.__getattribute__(s))(self)                                                         
   1051         except AttributeError:                                                                           
   1052             return self(x._interface_init_())                                                            

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/structure/sage_object.so in sage.structure.sage_object.SageObject._maple_ (sage/structure/sage_object.c:4795)()                                     

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._interface_ (sage/symbolic/expression.cpp:3293)()                                     

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/structure/sage_object.so in sage.structure.sage_object.SageObject._interface_ (sage/structure/sage_object.c:2828)()                                 

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/interfaces/expect.pyc in __call__(self, x, name)                                                                                                    
   1022                                                                                                          
   1023         if isinstance(x, basestring):                                                                    
-> 1024             return cls(self, x, name=name)                                                               
   1025         try:                                                                                             
   1026             return self._coerce_from_special_method(x)                                                   

/local/data/huss/software/sage-4.0.rc0/local/lib/python2.5/site-packages/sage/interfaces/expect.pyc in __init__(self, parent, value, is_name, name)                                                                               
   1426             except (TypeError, KeyboardInterrupt, RuntimeError, ValueError), x:                          
   1427                 self._session_number = -1
-> 1428                 raise TypeError, x
   1429         self._session_number = parent._session_number
   1430

TypeError: An error occured running a Maple command:
INPUT:
read "/home/huss/.sage//temp/bernoulli/6709//interface//tmp6709";
OUTPUT:
on line 1, syntax error, missing operator or `;`:
sage1:=<function binomial at 0x917ddbc>((x)*(2),x):;
                        ^
Error, while reading
`/home/huss/.sage//temp/bernoulli/6709//interface//tmp6709`

Component: symbolics

Author: Karl-Dieter Crisman

Reviewer: Mike Hansen

Merged: Sage 4.1.2.alpha2

Issue created by migration from https://trac.sagemath.org/ticket/6197

@sagetrac-whuss sagetrac-whuss mannequin added this to the sage-4.1.2 milestone Jun 3, 2009
@kcrisman
Copy link
Member

comment:1

The error for the original bug is now

sage: maxima(binomial(2*x,x))
Traceback
...
RuntimeError: cannot find SFunction in table

so the fix for this is to create a symbolic binomial and provide for this in the init method, the way factorial is done in functions/other.py (this works for Maxima; I don't have access to the others - but the fix would presumably be identical).

However, I can't get this to import properly so that the symbolic binomial is what you get from binomial? like you do for factorial?, even after adding it to the import list in functions/all.py, so I am reluctant to post anything at this point.

@kcrisman
Copy link
Member

kcrisman commented Sep 2, 2009

comment:2

This should fix the problem reported in the bug, also hopefully for Mathematica (and for factorial). It doesn't really help that much since Maxima doesn't automatically simplify binomials :) but that wasn't the ticket. Adding Maple to the list, or other functions one desires, would be very similar. The symbolic binomial wouldn't import properly, so this patch does not import it at all, but the bug is still fixed and the tests for these and a few related files pass.

@mwhansen
Copy link
Contributor

mwhansen commented Sep 8, 2009

comment:3

Looks good to me.

@mwhansen
Copy link
Contributor

mwhansen commented Sep 8, 2009

Author: Karl-Dieter Crisman

@mwhansen
Copy link
Contributor

mwhansen commented Sep 8, 2009

Reviewer: Mike Hansen

@sagetrac-mvngu
Copy link
Mannequin

sagetrac-mvngu mannequin commented Sep 8, 2009

comment:4

I received a doctest failure with the patch trac_6197-binomial-maxima.patch:

sage -t -long devel/sage-main/sage/symbolic/random_tests.py
**********************************************************************
File "/scratch/mvngu/release/sage-4.1.2.alpha1/devel/sage-main/sage/symbolic/random_tests.py", line 204:
    sage: random_expr(50, nvars=3, coeff_generator=CDF.random_element)
Expected:
    arctanh(sinh(-arcsech(v2)/floor(-(0.615863165633 + 0.879368031485*I)*v1^2*v3) - gamma(pi) + floor(-(0.708874026302 - 0.954135400334*I)*v3)))^arcsech(-cosh(-polylog((v2 + 0.913564344312 + 0.0898040160336*I)^(-(0.723896589334 - 0.799038508886*I)*v2),-v1 - v3))/sin(-(0.0263902659909 + 0.153261789843*I)*arctan2(pi, e^pi)))
Got:
    arctanh(sinh(-arcsech(v2)/csch(-(0.615863165633 + 0.879368031485*I)*v1^2*v3) - gamma(pi) + floor(-(0.708874026302 - 0.954135400334*I)*v3)))^arcsech(-cosh(-polylog((v2 + 0.913564344312 + 0.0898040160336*I)^(-(0.723896589334 - 0.799038508886*I)*v2),-v1 - v3))/arcsin(-(0.0263902659909 + 0.153261789843*I)*arctan2(pi, arccot(pi))))
**********************************************************************
1 items had failures:
   1 of   5 in __main__.example_4
***Test Failed*** 1 failures.
For whitespace errors, see the file /scratch/mvngu/release/sage-4.1.2.alpha1/tmp/.doctest_random_tests.py
	 [2.5 s]

@kcrisman
Copy link
Member

kcrisman commented Sep 8, 2009

comment:5

Adding a new function changes the list random_expr uses. This is actually fixed in #6636, though I guess it must have already been a problem in this one. I will try to separate that out from that patch and post updates to both.

@kcrisman
Copy link
Member

kcrisman commented Sep 8, 2009

comment:6

Attachment: trac_6197-binomial-maxima.patch.gz

Okay, this should do it. Literally the only change is that doctest, so hopefully just testing that should restore positive review.

@mwhansen
Copy link
Contributor

mwhansen commented Sep 8, 2009

comment:7

Looks good.

@sagetrac-mvngu
Copy link
Mannequin

sagetrac-mvngu mannequin commented Sep 9, 2009

Merged: Sage 4.1.2.alpha2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants