Opened 14 years ago

Closed 9 years ago

# mathematical functions should remain symbolic

Reported by: Owned by: zimmerma gfurnish minor sage-duplicate/invalid/wontfix symbolics Karl-Dieter Crisman N/A

### Description

Some mathematical functions automatically evaluate to floating-point, even for a symbolic input (integer or variable):

```sage: Ei(10)
2492.22897624
sage: bessel_J(0,10)
-0.245935764451348
sage: bessel_J(0,x)
---------------------------------------------------------------------------
<type 'exceptions.TypeError'>             Traceback (most recent call last)

/tmp/gmp-4.2.2/tune/<ipython console> in <module>()

/usr/local/sage-2.8.12/sage/local/lib/python2.5/site-packages/sage/functions/special.py in bessel_J(nu, z, alg, prec)
492         else:
493             K,a = _setup(prec)
--> 494         b = K(nu.besselj(z))
495         pari.set_real_precision(a)
496         return b

/tmp/gmp-4.2.2/tune/real_mpfr.pyx in sage.rings.real_mpfr.RealField.__call__()

/tmp/gmp-4.2.2/tune/real_mpfr.pyx in sage.rings.real_mpfr.RealNumber._set()

<type 'exceptions.TypeError'>: Unable to convert x (='1-1/4*x^2+1/64*x^4-1/2304*x^6+1/147456*x^8-1/14745600*x^10+1/2123366400*x^12-1/416179814400*x^14+1/106542032486400*x^16+O(x^17)') to real number.
```

In my opinion, foo(10) should evaluate to foo(10), and similarly foo(x).

### comment:1 Changed 13 years ago by mabshoff

• Milestone changed from sage-2.10 to sage-2.9.2

### comment:2 Changed 13 years ago by mhansen

This requires going through and look at all the numerical (special) functions we have an making a SymbolicFunction? wrapper class around them. Some thoughts need to be given how to handle the case where we have a function that Maxima does not.

### comment:3 Changed 13 years ago by gfurnish

• Owner changed from was to gfurnish

### comment:4 Changed 13 years ago by gfurnish

• Status changed from new to assigned

### comment:5 Changed 12 years ago by burcin

This is fixed in the new symbolics with #5777.

### comment:6 Changed 12 years ago by mvngu

What is the status of this ticket? Can it be closed as fixed? In Sage 4.1, I get this:

```----------------------------------------------------------------------
| Sage Version 4.1, Release Date: 2009-07-09                         |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: Ei(10)
2492.22897624
sage: bessel_J(0,10)
-0.245935764451348
sage: bessel_J(0,x)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (1171, 0))

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/mvngu/.sage/temp/sage.math.washington.edu/12800/_home_mvngu__sage_init_sage_0.py in <module>()

/usr/local/sage/local/lib/python2.6/site-packages/sage/functions/special.pyc in bessel_J(nu, z, algorithm, prec)
753             C = ComplexField(prec)
754             nu = C(nu)
--> 755             z = C(z)
756             K = C
757         if nu == 0:

/usr/local/sage/local/lib/python2.6/site-packages/sage/rings/complex_field.pyc in __call__(self, x, im)
265         if im is not None:
266             x = x, im
--> 267         return Parent.__call__(self, x)
268
269     def _element_constructor_(self, x):

/usr/local/sage/local/lib/python2.6/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:4130)()

/usr/local/sage/local/lib/python2.6/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3058)()

/usr/local/sage/local/lib/python2.6/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps._call_ (sage/structure/coerce_maps.c:2949)()

/usr/local/sage/local/lib/python2.6/site-packages/sage/rings/complex_field.pyc in _element_constructor_(self, x)
289
290             try:
--> 291                 return x._complex_mpfr_field_( self )
292             except AttributeError:
293                 pass

/usr/local/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._complex_mpfr_field_ (sage/symbolic/expression.cpp:5371)()

/usr/local/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._eval_self (sage/symbolic/expression.cpp:4825)()

TypeError: Cannot evaluate symbolic expression to a numeric value.
```

### comment:7 Changed 12 years ago by zimmerma

What is the status of this ticket? Can it be closed as fixed?

no, the status is still the same (here with 3.4 since I cannot compile 4.1 from source on my laptop, but I guess the behaviour in 4.1 is still the same):

```sage: sin(10)
sin(10)
sage: Ei(10)
2492.22897624
sage: sin(x)
sin(x)
sage: Ei(x)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/zimmerma/.sage/temp/toto.loria.fr/6274/_home_zimmerma__sage_init_sage_0.py in <module>()

/usr/local/sage-3.4/sage/local/lib/python2.5/site-packages/sage/functions/transcendental.pyc in Ei(z)

TypeError: complex() argument must be a string or a number
```

To be coherent, Ei(10) should return Ei(10) as sin(10) returns sin(10), and Ei(x) should return Ei(x) as sin(x) does return sin(x).

### comment:8 Changed 12 years ago by mvngu

OK, I get the same inconsistent behaviour:

```----------------------------------------------------------------------
| Sage Version 4.1, Release Date: 2009-07-09                         |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: sin(10)
sin(10)
sage: Ei(10)
2492.22897624
sage: sin(x)
sin(x)
sage: Ei(x)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/mvngu/.sage/temp/sage.math.washington.edu/32665/_home_mvngu__sage_init_sage_0.py in <module>()

/usr/local/sage/local/lib/python2.6/site-packages/sage/functions/transcendental.pyc in Ei(z)
261     """
262     import scipy.special, math
--> 263     return CDF(-scipy.special.exp1(-complex(z)) + complex(0,math.pi))
264
265 def Li(x, eps_rel=None, err_bound=False):

/usr/local/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.__complex__ (sage/symbolic/expression.cpp:5609)()

TypeError: unable to simplify to complex approximation
```

### comment:9 Changed 11 years ago by kcrisman

• Component changed from calculus to symbolics
• Report Upstream set to N/A

Note that Pynac does have a lot of our as-yet-un-symbolic functions available, though not all, so this is a feasible goal.

### comment:10 Changed 11 years ago by zimmerma

any progress on that issue?

### comment:11 Changed 11 years ago by mhansen

Hi Paul,

I could work on this if you need/want things for your talk. It really is just a matter of going through the functions one by one and switching them over / adding more features.

### comment:12 Changed 11 years ago by zimmerma

Hi Mike,

my talk is over, see http://www.loria.fr/~zimmerma/talks/sage-20100204.pdf (in french). However it would be useful to fix that issue. If you can describe what is needed to fix a particular function, then we could share the work.

Paul

### comment:13 Changed 11 years ago by burcin

Hi Paul,

#7748 has patches that make `Ei()` and `gamma_inc()` symbolic. The conversion process is not very smooth yet, but we're getting there slowly. My deadline for the conversion of all the functions to new symbolics and addition of other special functions is the Sage Days 24 workshop at RISC. Hopefully then we can get Sage included in the software list of the DLMF.

Any help is greatly appreciated of course.

### comment:14 Changed 9 years ago by kcrisman

• Milestone changed from sage-5.0 to sage-duplicate/invalid/wontfix
• Reviewers set to Karl-Dieter Crisman
• Status changed from new to needs_review

### comment:15 Changed 9 years ago by kcrisman

• Status changed from needs_review to positive_review

We now have

```sage: Ei(10)
Ei(10)
```

but the rest aren't there yet...

But the problem is that this ticket is WAY too broad, at least in the current framework of how we deal with tickets. We now have an entire metapage on the wiki devoted to this topic! Bessel J is #4102, log gamma is #10075, etc.

So I recommend that this ticket be closed as far too broad (in retrospect - somehow it seemed easier two years ago!) and adequately replaced by a slew of tickets already opened.

### comment:16 Changed 9 years ago by jdemeyer

• Resolution set to invalid
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.