Ticket #4282 (new enhancement)

Opened 2 months ago

Last modified 5 days ago

[with patch, needs work] symbolic minpoly

Reported by: robertwb Assigned to: burcin
Priority: major Milestone: sage-3.2.2
Component: calculus Keywords:
Cc:

Description

The current minpoly algorithm on symbolic objects is slow and often fails. This patch makes it work in many more cases, as well as implementing better conversion into QQbar.

Attachments

4282-symbolic-minpoly.patch (7.8 kB) - added by robertwb on 10/14/2008 07:20:01 AM.
4282-sqrt-fix.patch (1.4 kB) - added by robertwb on 11/13/2008 03:12:22 PM.

Change History

10/14/2008 07:20:01 AM changed by robertwb

  • attachment 4282-symbolic-minpoly.patch added.

10/14/2008 07:21:04 AM changed by robertwb

It's still not super fast, but it's a lot better. Perhaps working with resultants directly could be faster (or improving QQbar's implementation, though I'm not sure how much is overhead vs. being a hard computational problem).

10/23/2008 08:23:58 PM changed by mhampton

  • summary changed from [with patch, needs review] symbolic minpoly to [with patch, needs work] symbolic minpoly.

There's a problem that comes up testing this, which may be something the improved doctests are exposing rather than causing:

sage: sin(pi/7).minpoly()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/Users/mh/sagestuff/sage-3.1.4/<ipython console> in <module>()

/Users/mh/sagestuff/sage-3.1.4/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc in minpoly(self, *args, **kwds)
   1343         from sage.rings.all import QQbar
   1344         try:
-> 1345             return QQbar(self).minpoly()
   1346         except TypeError, ValueError:
   1347             return self.minpoly_numeric(*args, **kwds)

/Users/mh/sagestuff/sage-3.1.4/local/lib/python2.5/site-packages/sage/rings/qqbar.pyc in __call__(self, x)
    661             return AlgebraicNumber(x._descr)
    662         elif hasattr(x, '_algebraic_'):
--> 663             return x._algebraic_(QQbar)
    664         return AlgebraicNumber(x)
    665 

/Users/mh/sagestuff/sage-3.1.4/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc in _algebraic_(self, field)
   6432                 res = mag * QQbar.zeta(rat_arg.denom())**rat_arg.numer()
   6433             elif func_name in ['sin', 'cos', 'tan']:
-> 6434                 exp_ia = exp(SR(-1).sqrt()*operand)._algebraic_(QQbar)
   6435                 if func_name == 'sin':
   6436                     res = (exp_ia - ~exp_ia)/(2*QQbar.zeta(4))

AttributeError: 'SymbolicConstant' object has no attribute 'sqrt'

11/03/2008 01:47:52 PM changed by robertwb

Ah. That should be an easy fix... (must have fixed it in my branch elsewhere, perhaps in the process of #4276)

11/13/2008 03:12:22 PM changed by robertwb

  • attachment 4282-sqrt-fix.patch added.

11/13/2008 03:12:53 PM changed by robertwb

  • summary changed from [with patch, needs work] symbolic minpoly to [with patch, needs review] symbolic minpoly.

I fixed the above bug.

11/27/2008 08:56:24 AM changed by was

  • summary changed from [with patch, needs review] symbolic minpoly to [with patch, needs work] symbolic minpoly.

Referee report:

I applied the patch to sage-3.2.1.alpha2.

1. A doctest fails in calculus.py:

sage -t  devel/sage/sage/calculus/calculus.py
**********************************************************************
File "/home/was/build/sage-3.2.1.alpha1/devel/sage-main/sage/calculus/calculus.py", line 1337:
    sage: sin(pi/7).minpoly()
Exception raised:
    Traceback (most recent call last):
      File "/home/was/build/sage-3.2.1.alpha1/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/home/was/build/sage-3.2.1.alpha1/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/home/was/build/sage-3.2.1.alpha1/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_43[5]>", line 1, in <module>
        sin(pi/Integer(7)).minpoly()###line 1337:
    sage: sin(pi/7).minpoly()
      File "/home/was/build/sage-3.2.1.alpha1/local/lib/python2.5/site-packages/sage/calculus/calculus.py", line 1345, in minpoly
        return QQbar(self).minpoly()
      File "/home/was/build/sage-3.2.1.alpha1/local/lib/python2.5/site-packages/sage/rings/qqbar.py", line 663, in __call__
        return x._algebraic_(QQbar)
      File "/home/was/build/sage-3.2.1.alpha1/local/lib/python2.5/site-packages/sage/calculus/calculus.py", line 6471, in _algebraic_
        exp_ia = exp(SR(-1).sqrt()*operand)._algebraic_(QQbar)
      File "/home/was/build/sage-3.2.1.alpha1/local/lib/python2.5/site-packages/sage/calculus/calculus.py", line 6460, in _algebraic_
        rat_arg = (operand.imag()/(2*self.parent().pi()))._rational_()
    AttributeError: 'SymbolicExpressionRing_class' object has no attribute 'pi'
**********************************************************************
1 items had failures:
   1 of   6 in __main__.example_43
***Test Failed*** 1 failures.
For whitespace errors, see the file /home/was/build/sage-3.2.1.alpha1/tmp/.doctest_calculus.py

         [114.8 s]

The following tests failed:

        sage -t  devel/sage/sage/calculus/calculus.py # 1 doctests failed

2. This sentence sounds like nonsense:

 	1335	        NOTE: Failure of this function does not prove self is 
 	1336	              not algebraic.  

3. There are now only three boring tests of symbolic minpoly. All the old interesting tests are now tests of minpoly_numeric. I think all the minpoly_numeric tests should *also* be copied to the docstring for minpoly and tested using the new non-numerical algorithm.