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

Update to pynac-0.6.9 #21369

Closed
rwst opened this issue Aug 30, 2016 · 36 comments
Closed

Update to pynac-0.6.9 #21369

rwst opened this issue Aug 30, 2016 · 36 comments

Comments

@rwst
Copy link

rwst commented Aug 30, 2016

Changelog:

https://github.com/pynac/pynac/releases/download/pynac-0.6.9/pynac-0.6.9.tar.bz2

CC: @embray @tscrim @kiwifb

Component: packages: standard

Author: Ralf Stephan, Erik Bray, Jeroen Demeyer

Branch: b06cfa0

Reviewer: Jeroen Demeyer, Ralf Stephan

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

@rwst rwst added this to the sage-7.4 milestone Aug 30, 2016
@rwst
Copy link
Author

rwst commented Aug 30, 2016

Branch: u/rws/update_to_pynac_0_6_9

@rwst
Copy link
Author

rwst commented Aug 30, 2016

Commit: a4f58d7

@rwst
Copy link
Author

rwst commented Aug 30, 2016

New commits:

b996f4fversion/chksum
91a08d2changes affecting Sage behaviour or interface
a4f58d7doctest fixes

@jdemeyer
Copy link

comment:3

This is a regression (based on a doctest you removed):

Before:

sage: k = GF(7); expand((k(1)*x^2 + k(1)*x)^7)
x^14 + x^7

After:

sage: k = GF(7); expand((k(1)*x^2 + k(1)*x)^7)
x^14 + 0*x^13 + 0*x^12 + 0*x^11 + 0*x^10 + 0*x^9 + 0*x^8 + x^7

@jdemeyer
Copy link

comment:4

In general, for any doctest that you remove, it should be clearly justified why that doctest can be removed.

@rwst
Copy link
Author

rwst commented Aug 30, 2016

comment:5

Oh well, an impasse. My justification to me personally is that I do not want to fix a feature of symbolics that is better served by algebraic structures in Sage. As it is buggy already now, and we see no complaints, I also suspect that symbolic Mod is used by a negligible number of people.

I offer to start a sage-devel thread, and to work on a deprecation ticket in case others agree.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 30, 2016

Changed commit from a4f58d7 to ac7d971

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 30, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

ac7d971revert removal of pos.char. doctests; add "known bug"

@tscrim
Copy link
Collaborator

tscrim commented Aug 30, 2016

comment:7

For # known bug, you should put in the correct answer.

@jdemeyer
Copy link

comment:8

Replying to @tscrim:

For # known bug, you should put in the correct answer.

That is the case here if I'm not mistaken.

@jdemeyer
Copy link

comment:9

Replying to @rwst:

I offer to start a sage-devel thread

Please do!

@tscrim
Copy link
Collaborator

tscrim commented Aug 30, 2016

comment:10

Replying to @jdemeyer:

Replying to @tscrim:

For # known bug, you should put in the correct answer.

That is the case here if I'm not mistaken.

Ah, yes; sorry, I flopped comment:3.

@rwst
Copy link
Author

rwst commented Aug 30, 2016

@jdemeyer
Copy link

comment:13

Thanks!

@jdemeyer
Copy link

comment:14
  1. The changes to simplify_rational() seem more than just a Pynac update. For easier review, I suggest to move those changes to Extend normalize() and use it instead of Maxima in simplify_rational() #21335 and focus on the upgrade.

  2. Why this?

@@ -1387,10 +1387,19 @@ cdef class Expression(CommutativeRingElement):
             ...
             TypeError: unable to simplify to float approximation
         """
+        from sage.functions.other import real, imag
         try:
-            return float(self._eval_self(float))
+            ret = float(self._eval_self(float))
         except TypeError:
-            raise TypeError("unable to simplify to float approximation")
+            try:
+                c = (self._eval_self(complex))
+                if imag(c) == 0:
+                    ret = real(c)
+                else:
+                    raise
+            except TypeError:
+                raise TypeError("unable to simplify to float approximation")
+        return ret
 
     def __complex__(self):

I understand and see that it makes sense, I am just wondering which bug it fixes.

  1. The code mentioned in 2. could be improved a bit. Instead of using the ret variable, I suggest just returning the value directly. In the complex case, I would use c = complex(self._eval_self(complex)) and then use the real and imag attributes (not functions).

  2. Can you justify

diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx
index 6c4171f..d780bbc 100644
--- a/src/sage/symbolic/expression.pyx
+++ b/src/sage/symbolic/expression.pyx
@@ -1191,7 +1191,7 @@ cdef class Expression(CommutativeRingElement):
         except TypeError as err:
             # try the evaluation again with the complex field
             # corresponding to the parent R
-            if R is float:
+            if R in (float, complex):
                 R_complex = complex
             else:
                 try:

It seems pointless to have R_complex == R.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2016

Changed commit from ac7d971 to 3dd8058

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

3dd8058address reviewer's comments

@rwst
Copy link
Author

rwst commented Aug 31, 2016

comment:16

Replying to @jdemeyer:

  1. The changes to simplify_rational() seem more than just a Pynac update. For easier review, I suggest to move those changes to Extend normalize() and use it instead of Maxima in simplify_rational() #21335 and focus on the upgrade.

OK.

  1. Why this?

...
I understand and see that it makes sense, I am just wondering which bug it fixes.

sage: float(sqrt(2)/sqrt(abs(-(I - 1)*sqrt(2) - I - 1)))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-5bba6e8d1a16> in <module>()
----> 1 float(sqrt(Integer(2))/sqrt(abs(-(I - Integer(1))*sqrt(Integer(2)) - I - Integer(1))))

/home/ralf/sage/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__float__ (build/cythonized/sage/symbolic/expression.cpp:10473)()
   1391             return float(self._eval_self(float))
   1392         except TypeError:
-> 1393             raise TypeError("unable to simplify to float approximation")
   1394
   1395     def __complex__(self):

TypeError: unable to simplify to float approximation

I was unable to find out why this bombed but it does so at least since Sage-7.1.

  1. Can you justify
+            if R in (float, complex):

It seems pointless to have R_complex == R.

Yes but this also prevents the else branch done (R.complex_field() with R being complex).


New commits:

3dd8058address reviewer's comments

New commits:

3dd8058address reviewer's comments

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2016

Changed commit from 3dd8058 to 1f29305

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

1f29305add doctest

@jdemeyer
Copy link

comment:18

Replying to @rwst:

sage: float(sqrt(2)/sqrt(abs(-(I - 1)*sqrt(2) - I - 1)))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-5bba6e8d1a16> in <module>()
----> 1 float(sqrt(Integer(2))/sqrt(abs(-(I - Integer(1))*sqrt(Integer(2)) - I - Integer(1))))

/home/ralf/sage/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__float__ (build/cythonized/sage/symbolic/expression.cpp:10473)()
   1391             return float(self._eval_self(float))
   1392         except TypeError:
-> 1393             raise TypeError("unable to simplify to float approximation")
   1394
   1395     def __complex__(self):

TypeError: unable to simplify to float approximation

I was unable to find out why this bombed but it does so at least since Sage-7.1.

Can you add this as doctest then?

And delete the line from sage.functions.other import real, imag

@jdemeyer
Copy link

comment:19

Replying to @rwst:

Yes but this also prevents the else branch done (R.complex_field() with R being complex).

And why is that a problem? Sure, it will raise an AttributeError, but that's caught. So I still don't see the point.

@jdemeyer
Copy link

comment:20

I am happy with the branch on this ticket except for the float/complex stuff in expression.pyx that I need to look at more.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

0065f62address reviewer's comments

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2016

Changed commit from 1f29305 to 0065f62

@jdemeyer
Copy link

Changed branch from u/rws/update_to_pynac_0_6_9 to u/jdemeyer/update_to_pynac_0_6_9

@jdemeyer
Copy link

Changed commit from 0065f62 to b06cfa0

@jdemeyer
Copy link

comment:23

I fixed the underlying cause of the float/complex problem which is in _eval_self. This way, no changes to __float__ are needed. If you agree with this, you can set the ticket to positive_review.


New commits:

b06cfa0Fix _eval_self(float) for "real" complex expressions

@jdemeyer
Copy link

Reviewer: Jeroen Demeyer

@rwst
Copy link
Author

rwst commented Aug 31, 2016

Changed author from Ralf Stephan, Erik M. Bray to Ralf Stephan, Erik M. Bray, Jeroen Demeyer

@rwst
Copy link
Author

rwst commented Aug 31, 2016

Changed reviewer from Jeroen Demeyer to Jeroen Demeyer, Ralf Stephan

@rwst
Copy link
Author

rwst commented Aug 31, 2016

comment:24

Is fine and passes tests. Thanks.

@tscrim
Copy link
Collaborator

tscrim commented Aug 31, 2016

comment:25

This also built without problems on Cygwin32/64 for me.

@vbraun
Copy link
Member

vbraun commented Sep 4, 2016

Changed branch from u/jdemeyer/update_to_pynac_0_6_9 to b06cfa0

@fchapoton
Copy link
Contributor

Changed author from Ralf Stephan, Erik M. Bray, Jeroen Demeyer to Ralf Stephan, Erik Bray, Jeroen Demeyer

@fchapoton
Copy link
Contributor

Changed commit from b06cfa0 to none

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

5 participants