Opened 7 years ago

Last modified 2 years ago

#12745 needs_work defect

Coercion problem with Algebraic Real Field

Reported by: davidloeffler Owned by: AlexGhitza
Priority: major Milestone: sage-6.4
Component: symbolics Keywords:
Cc: Merged in:
Authors: Marc Mezzarobba Reviewers:
Report Upstream: N/A Work issues:
Branch: u/mmezzarobba/12745-SR_to_AA (Commits) Commit: 8f74a7b8af077e27beff9b6f4b663d9deeea728b
Dependencies: Stopgaps:

Description

The following algebraic number is clearly real, but the AA class seems to have trouble digesting it:

----------------------------------------------------------------------
| Sage Version 5.0.beta10, Release Date: 2012-03-23                  |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
**********************************************************************
*                                                                    *
* Warning: this is a prerelease version, and it may be unstable.     *
*                                                                    *
**********************************************************************
sage: x = exp(2*I*pi/7) + exp(-2*I*pi/7)
sage: QQbar(x) in AA
True
sage: AA(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', (1327, 0))

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', (4541, 0))

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', (1327, 0))

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

/storage/masiao/sage-5.0.beta10/devel/sage-main/<ipython console> in <module>()

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:7940)()

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3344)()

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3247)()

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/rings/qqbar.pyc in _element_constructor_(self, x)
    689                 raise ValueError("Cannot coerce algebraic number with non-zero imaginary part to algebraic real")
    690         elif hasattr(x, '_algebraic_'):
--> 691             return x._algebraic_(AA)
    692         return AlgebraicReal(x)
    693 

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._algebraic_ (sage/symbolic/expression.cpp:6286)()

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.pyc in algebraic(ex, field)
    830         0
    831     """
--> 832     return AlgebraicConverter(field)(ex)
    833 
    834 ##############

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.pyc in __call__(self, ex)
    212                 div = self.get_fake_div(ex)
    213                 return self.arithmetic(div, div.operator())
--> 214             return self.arithmetic(ex, operator)
    215         elif operator in relation_operators:
    216             return self.relation(ex, operator)

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.pyc in arithmetic(self, ex, operator)
    717                 return self.field(base**expt)
    718             else:
--> 719                 return reduce(operator, map(self, ex.operands()))
    720         except TypeError:
    721             if operator is _operator.pow:

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.pyc in __call__(self, ex)
    218             return self.derivative(ex, operator)
    219         else:
--> 220             return self.composition(ex, operator)
    221 
    222     def get_fake_div(self, ex):

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.pyc in composition(self, ex, operator)
    787             if cmp(res, ex) == 0:
    788                 raise TypeError, "unable to convert %s to %s"%(ex, self.field)
--> 789         return self.field(res)
    790     
    791 def algebraic(ex, field):

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:7940)()

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3344)()

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3247)()

/storage/masiao/sage-5.0.beta10/local/lib/python2.7/site-packages/sage/rings/qqbar.pyc in _element_constructor_(self, x)
    687                 return x.real()
    688             else:
--> 689                 raise ValueError("Cannot coerce algebraic number with non-zero imaginary part to algebraic real")
    690         elif hasattr(x, '_algebraic_'):
    691             return x._algebraic_(AA)

ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real

This does not seem to be related to #12665 or to #12727 -- applying the patches at those tickets does not fix the problem.

Change History (8)

comment:1 Changed 6 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:2 Changed 5 years ago by mmezzarobba

  • Authors set to Marc Mezzarobba
  • Branch set to u/mmezzarobba/12745-SR_to_AA
  • Commit set to 8f74a7b8af077e27beff9b6f4b663d9deeea728b
  • Component changed from algebra to symbolics
  • Status changed from new to needs_review

Here's an attempt to fix the bug.


New commits:

8f74a7bFix conversion to AA of real symbolic expressions with non-real subexpressions

comment:3 Changed 5 years ago by mmezzarobba

  • Status changed from needs_review to needs_work

Missed some test failures in qqbar.py.

comment:4 Changed 5 years ago by mmezzarobba

I thought it would be a quick fix, but in fact there are at least two deeper issues here:

  • Simplification of symbolic powers of negative numbers is completely broken, with inconsistent interpretations all over the place (see, e.g., #15605).
  • Rational powers of negative numbers in AA are defined to choose real roots when possible (see the docstring of sage.rings.qqbar)
    sage: AA((-1)^(1/3))
    -1
    sage: AA(-1)^(1/3)
    -1
    

These semantics do not extend well to real expressions with non-real complex subexpressions.

I'm giving up, at least for now.

comment:5 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:6 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:7 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:8 Changed 2 years ago by vdelecroix

see also the task ticket #18333

Note: See TracTickets for help on using tickets.