# Ticket #2336(closed defect: fixed)

Opened 5 years ago

## [with patch, positive review] hermite -- this function in sage is broken in more ways than it has lines of code

Reported by: Owned by: was was major sage-2.10.3 calculus

```- Hide quoted text -
On Wed, Feb 27, 2008 at 12:03 PM, Jason Bandlow <jbandlow@gmail.com> wrote:
>
>  Hi all,
>
>  Can someone explain the following error?  I can create a Hermite
>  polynomial over QQ...
>
>
>  sage: R.<x> = PolynomialRing(QQ)
>  sage: rat_herm = hermite(3,x); rat_herm
>  8*x^3 - 12*x
>
>
>  But the same construction fails over RR:
>
>  sage: S.<y> = PolynomialRing(RR)
>  sage: real_herm = hermite(3,y)
>  ---------------------------------------------------------------------------
>  <type 'exceptions.NameError'>             Traceback (most recent call last)
>
>  /home/jason/<ipython console> in <module>()
>
>  /home/jason/sage-2.8.13-i686-Linux/local/lib/python2.5/site-packages/sage/functions/orthogonal_polys.py in hermite(n, x)
>     449     R = x.parent()
>     450     y = R.gen()
>  --> 451     return sage_eval(maxima.eval("hermite(%s,%s)"%(n0,y)),locals={str(y):y})
>     452
>     453 def jacobi_P(n,a,b,x):
>
>  /home/jason/sage-2.8.13-i686-Linux/local/lib/python2.5/site-packages/sage/misc/sage_eval.py in sage_eval(source, locals)
>     108     p = preparse(source)
>     109     try:
>  --> 110         return eval(p, sage.all.__dict__, locals)
>     111     except SyntaxError, msg:
>     112         raise SyntaxError, "%s\nError using SAGE to evaluate '%s'"%(msg, p)
>
>  /home/jason/<string> in <module>()
>
>  <type 'exceptions.NameError'>: name 'y' is not defined
>
>
>  For what I'm doing, I've found a simple work around:
>
>  sage: real_herm = S(rat_herm.subs({x:y}))
>  sage: real_herm
>  8.00000000000000*y^3 - 12.0000000000000*y
>
>
>
>  But this certainly isn't the "natural" way to do things.  Any thoughts?
>

This in sage/functions/orthogonal_polys.py is just wrong in multiple ways:

R = x.parent()
y = R.gen()
return sage_eval(maxima.eval("hermite(%s,%s)"%(n0,y)),locals={str(y):y})

(1) str(y) results in
'1.00000000000000*y'

When R is QQ it results in 'y', which works, but in general there is no
guarantee that str(R.gen()) is the variable name.   One could do

ystr = R.variable_name()

instead of str(y), which would work if R happens to be a univariate polynomial
ring, and would break otherwise.

(2) As suggested above the hermite function is broken if it doesn't
happen to be that the first variable of a poly ring is being substituted in.
E.g.,
sage: R.<x,y> = QQ[]
sage: hermite(3,y)
BOOM!

It also fails if x is symbolic:
sage: x = var('x')
sage: hermite(3,x)

(3)The function is also buggy, because:
sage: R.<x> = QQ[]
sage: hermite(3,x)
8*x^3 - 12*x
sage: hermite(3,x^2)
8*x^3 - 12*x

In the second case, one would expect to get either 8*x^6 - 12*x^2 or
an error message.

----

So this function hermite is buggy as hell.
```

## Change History

### comment:1 Changed 5 years ago by was

• Description modified (diff)

### comment:2 Changed 5 years ago by was

• Summary changed from hermite -- this function in sage is broken in more ways than it has lines of code to [with patch; needs review] hermite -- this function in sage is broken in more ways than it has lines of code

I replaced the whole function by one line, which fixes all the bugs too...

### comment:3 Changed 5 years ago by mhansen

• Summary changed from [with patch; needs review] hermite -- this function in sage is broken in more ways than it has lines of code to [with patch, positive review] hermite -- this function in sage is broken in more ways than it has lines of code

Applies against 2.10.3.alpha0 and passes tests for me.

### comment:4 Changed 5 years ago by mabshoff

• Status changed from new to closed
• Resolution set to fixed

Merged in Sage 2.10.3.rc0

Note: See TracTickets for help on using tickets.