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

Sympy-conversion of complex numbers #28903

Closed
mwageringel opened this issue Dec 20, 2019 · 12 comments
Closed

Sympy-conversion of complex numbers #28903

mwageringel opened this issue Dec 20, 2019 · 12 comments

Comments

@mwageringel
Copy link

This ticket implements conversions to Sympy of elements of ComplexField, CDF and QuadraticNumberField(-1). This solves some inconsistencies with the unicode art of symbolic expressions involving complex numbers.

Most symbolic expressions use the Sympy symbol for the unicode art of the imaginary unit, but some do not:

sage: unicode_art(sqrt(3) * I)  # correct
√3⋅ⅈ
sage: unicode_art(I)  # should use symbol ⅈ
I
sage: unicode_art(cos(I)), cos(I)  # should render the same
(1.54308063481524, cosh(1))
sage: unicode_art(SR(CC(1/3 + I)))  # should use symbol ⅈ
0.333333333333333 + 1.00000000000000*I
sage: unicode_art(SR(CDF(1/3 + I)))  # should use symbol ⅈ
0.3333333333333333 + 1.0*I

The underlying problem is that these complex numbers cannot be converted to Sympy, currently, which is what the unicode_art method of symbolic expressions would need. In that case, the fallback is the usual string representation, which does not use the symbol . Hence, this is solved by implementing the conversions above.

Additionally, this ticket improves the conversion to Sympy of elements of RealField by taking into account the precision of the field.

sage: a = SR(RealField(100)(1/3))
sage: a, unicode_art(a)  # unicode art loses precision
(0.33333333333333333333333333333, 0.333333333333333)

Note that other implementations of complex numbers (QQbar, CIF, CBF), that cannot meaningfully by converted to Sympy in general, are not affected by this ticket. For example, the following symbolic expressions still render the same:

sage: unicode_art(SR(QQbar(1 + I)))
I + 1
sage: unicode_art(SR(CBF(1/3 + I)))
[0.3333333333333333 +/- 7.04e-17] + 1.000000000000000*I

Depends on #28891

Component: symbolics

Keywords: sympy, unicode_art

Author: Markus Wageringel

Branch/Commit: a6ed554

Reviewer: Travis Scrimshaw

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

@mwageringel mwageringel added this to the sage-9.0 milestone Dec 20, 2019
@mwageringel
Copy link
Author

Dependencies: #28891

@mwageringel
Copy link
Author

Branch: u/gh-mwageringel/28903

@mwageringel
Copy link
Author

comment:1

This branch is based on #28891 to avoid a merge conflict.


New commits:

8bdd72d28891: character art/sympy-conversion of symbolic series
7e7d3d328903: unicode_art/sympy-conversion of (symbolic) complex numbers

@mwageringel
Copy link
Author

Author: Markus Wageringel

@mwageringel
Copy link
Author

Commit: 7e7d3d3

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 21, 2019

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

a6ed55428903: unicode_art/sympy-conversion of (symbolic) complex numbers

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 21, 2019

Changed commit from 7e7d3d3 to a6ed554

@mwageringel
Copy link
Author

comment:3

I added another test case:

sage: (10.0^400)._sympy_()  # used to be `inf`
1.00000000000000e+400

@tscrim
Copy link
Collaborator

tscrim commented Dec 27, 2019

comment:4

LGTM.

@tscrim
Copy link
Collaborator

tscrim commented Dec 27, 2019

Reviewer: Travis Scrimshaw

@fchapoton
Copy link
Contributor

comment:5

9.0 is out

@fchapoton fchapoton modified the milestones: sage-9.0, sage-9.1 Jan 1, 2020
@vbraun
Copy link
Member

vbraun commented Jan 5, 2020

Changed branch from u/gh-mwageringel/28903 to a6ed554

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

No branches or pull requests

4 participants