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

Coercion problem with Algebraic Real Field #12745

Open
loefflerd mannequin opened this issue Mar 25, 2012 · 8 comments · Fixed by #36942 · May be fixed by #38564
Open

Coercion problem with Algebraic Real Field #12745

loefflerd mannequin opened this issue Mar 25, 2012 · 8 comments · Fixed by #36942 · May be fixed by #38564

Comments

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 25, 2012

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.

Component: symbolics

Author: Marc Mezzarobba

Branch/Commit: u/mmezzarobba/12745-SR_to_AA @ 8f74a7b

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

@loefflerd loefflerd mannequin added this to the sage-5.11 milestone Mar 25, 2012
@loefflerd loefflerd mannequin added c: algebra labels Mar 25, 2012
@loefflerd loefflerd mannequin assigned aghitza Mar 25, 2012
@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@mezzarobba
Copy link
Member

comment:2

Here's an attempt to fix the bug.


New commits:

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

@mezzarobba
Copy link
Member

Commit: 8f74a7b

@mezzarobba
Copy link
Member

Branch: u/mmezzarobba/12745-SR_to_AA

@mezzarobba
Copy link
Member

Author: Marc Mezzarobba

@mezzarobba
Copy link
Member

comment:3

Missed some test failures in qqbar.py.

@mezzarobba
Copy link
Member

comment:4

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., (-1)^(2/3) evaluates to 1 #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.
    Note added 2021-08-23: → real nth root function #12074.
    I'm giving up, at least for now.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@videlec
Copy link
Contributor

videlec commented Aug 31, 2016

comment:8

see also the task ticket #18333

@user202729
Copy link
Contributor

Can we reopen this? As explained in the pull request, it was erroneously merged. (I think it's reverted now?)

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