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 patch for abstract function #23496

Closed
man74cio mannequin opened this issue Jul 20, 2017 · 92 comments
Closed

sympy patch for abstract function #23496

man74cio mannequin opened this issue Jul 20, 2017 · 92 comments

Comments

@man74cio
Copy link
Mannequin

man74cio mannequin commented Jul 20, 2017

Generic function are not transformed from sympy to sage.
this patch implement the PR sympy/sympy#12826

Upstream: Fixed upstream, but not in a stable release.

CC: @tscrim @egourgoulhon @rwst

Component: symbolics

Author: Marco Mancini

Branch/Commit: bc21300

Reviewer: Travis Scrimshaw, Marcelo Forets

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

@man74cio man74cio mannequin added this to the sage-8.0 milestone Jul 20, 2017
@man74cio man74cio mannequin added p: major / 3 labels Jul 20, 2017
@man74cio
Copy link
Mannequin Author

man74cio mannequin commented Jul 20, 2017

@man74cio man74cio mannequin self-assigned this Jul 20, 2017
@man74cio man74cio mannequin added the c: symbolics label Jul 20, 2017
@man74cio
Copy link
Mannequin Author

man74cio mannequin commented Jul 20, 2017

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 20, 2017

Commit: b764ebe

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 20, 2017

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

b764ebeBetter sympy patch taken from #12826 PR in sympy

@man74cio
Copy link
Mannequin Author

man74cio mannequin commented Jul 20, 2017

Changed dependencies from 22802 to none

@tscrim
Copy link
Collaborator

tscrim commented Jul 20, 2017

Changed reviewer from tscrim to Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Jul 20, 2017

comment:6

Is this ready for review?

@man74cio
Copy link
Mannequin Author

man74cio mannequin commented Jul 21, 2017

comment:7

Yes, pleiade

@man74cio man74cio mannequin added the s: needs review label Jul 21, 2017
@man74cio
Copy link
Mannequin Author

man74cio mannequin commented Jul 21, 2017

comment:8

Yes, please

@man74cio man74cio mannequin added s: needs work and removed s: needs review labels Jul 21, 2017
@tscrim
Copy link
Collaborator

tscrim commented Jul 21, 2017

comment:9

Is the setting this to needs_work a double-post-type error or is there an actual issue?

Also, could you ping upstream again? It would be good to know that they accepted the patch as-is.

@man74cio
Copy link
Mannequin Author

man74cio mannequin commented Jul 22, 2017

comment:10

Double error, sorry

@man74cio
Copy link
Mannequin Author

man74cio mannequin commented Jul 22, 2017

Upstream: Reported upstream. No feedback yet.

@man74cio man74cio mannequin added s: needs review and removed s: needs work labels Jul 22, 2017
@tscrim
Copy link
Collaborator

tscrim commented Jul 24, 2017

comment:11

You need to also bump the patch level in package-version.txt so that it rebuilds sympy.

Did you send another message to upstream asking about the status of the patch?

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 24, 2017

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

9d16a70Lost package-version.txt modifications : restored

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 24, 2017

Changed commit from b764ebe to 9d16a70

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 24, 2017

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

d5d6b67Corrected error on patcj version

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 24, 2017

Changed commit from 9d16a70 to d5d6b67

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 24, 2017

Changed commit from d5d6b67 to 462bd68

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 24, 2017

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

462bd68test is not corrected at this point

@man74cio
Copy link
Mannequin Author

man74cio mannequin commented Jul 25, 2017

comment:15

Replying to @tscrim:

You need to also bump the patch level in package-version.txt so that it rebuilds sympy.

Did you send another message to upstream asking about the status of the patch?

The referee said me that tests are still falling on travis. I asked to see the report (I have not access to travis).

@egourgoulhon
Copy link
Member

comment:62

Replying to @tscrim:

I'm also a little more open to just fixing the test

Indeed, the test, as it is, is quite unnatural from a Sage's user point of view: the import of specific Sympy objects (in the line from sympy import Function, Symbol) and their mixing with some Sage objects (in the line f = u(n+2)-(3/2)*u(n+1)+(1/2)*u(n)), with implicit conversions Sage <--> Sympy involved, without any user control on them, is not something desirable. The change proposed in comment:50 seems much more reasonable: one defines first f entirely as a Sage object and then explicitely convert it to a Sympy object before passing it to Sympy's rsolve, because there is no Sage's rsolve yet.

@egourgoulhon
Copy link
Member

comment:63

Replying to @tscrim:

I guess what I am asking is do we want to fix the problem of comment:59 here or just push it to a later ticket?

+1 for a later ticket.

@tscrim
Copy link
Collaborator

tscrim commented Sep 2, 2017

comment:64

Replying to @egourgoulhon:

Replying to @tscrim:

I'm also a little more open to just fixing the test

Indeed, the test, as it is, is quite unnatural from a Sage's user point of view: the import of specific Sympy objects (in the line from sympy import Function, Symbol) and their mixing with some Sage objects (in the line f = u(n+2)-(3/2)*u(n+1)+(1/2)*u(n)), with implicit conversions Sage <--> Sympy involved, without any user control on them, is not something desirable. The change proposed in comment:50 seems much more reasonable: one defines first f entirely as a Sage object and then explicitely convert it to a Sympy object before passing it to Sympy's rsolve, because there is no Sage's rsolve yet.

I don't think it is that unnatural as someone who wants to use sympy, something that we do suggest to people, would construct something in that fashion. One of the benefits of Sage are those implicit conversions so that users should not have to worry about them.

However, that discussion aside, I think that we should keep as close to the original doctest because it is in Calcul Mathématique avec Sage (even if it is out of date). So I believe we should just change the order of multiplication of the coefficients as in comment:56 and add a warning about it.

@mforets
Copy link
Mannequin

mforets mannequin commented Sep 2, 2017

comment:65

hi, thank you all for the help debugging. with this sympy patch (at sympy/core/function.py and on top of #20204), it works for me:

class AppliedUndef(Function):
    """
    Base class for expressions resulting from the application of an undefined
    function.
    """
    .
    .
    .
    def _sage_(self):
        import sage.all as sage
        fname = self.func.__name__
        func = getattr(sage, fname)
        args = [arg._sage_() for arg in self.args]
        return func

do you already have the same _sage_ there?

@egourgoulhon
Copy link
Member

comment:66

Replying to @tscrim:

I don't think it is that unnatural as someone who wants to use sympy, something that we do suggest to people, would construct something in that fashion. One of the benefits of Sage are those implicit conversions so that users should not have to worry about them.

Well, there is some degree of arbitrariness in these implicit conversions: if a is a Sage object and b a Sympy object, what a*b shall be? For the example of the French textbook as it is now, with a=3/2 and b=u(n+1), we want a*b to be a Sympy object, so that the final f is a Sympy object. But in other cases?

@mforets
Copy link
Mannequin

mforets mannequin commented Sep 2, 2017

comment:67

So I believe we should just change the order of multiplication of the coefficients as in comment:56 and add a warning about it.

it seems that game was played before:

$ git show 12cdb58d7a02391224477d0d99312be8fc03f678
@@ -379,7 +379,7 @@ Sage example in ./recequadiff.tex, line 1197::

 Sage example in ./recequadiff.tex, line 1208::


-  sage: f = u(n+2)-u(n+1)*(3/2)+u(n)*(1/2)
+  sage: f = u(n+2)-(3/2)*u(n+1)+(1/2)*u(n)

this is a commit by Ralph.

@tscrim
Copy link
Collaborator

tscrim commented Sep 2, 2017

comment:68

@mforets comment:67 - All the more reason to just do the minimal change. IIRC, we needed to do that in order for the construction of f to not fail, but with this patch, it is okay.

@egourgoulhon comment:66 - Yes, there is currently some ambiguity because of things are done, but ultimately it shouldn't matter. Although if I really had to decide, I would say everything should go to Sympy objects because we cannot expect Sympy objects to work with our coercion system.

@mforets
Copy link
Mannequin

mforets mannequin commented Sep 3, 2017

Changed commit from 1b5227d to d76caea

@mforets
Copy link
Mannequin

mforets mannequin commented Sep 3, 2017

@mforets
Copy link
Mannequin

mforets mannequin commented Sep 3, 2017

comment:69

ok, let's do it => needs review

note: this does not depend on #20204.

(@marco : sorry, i did not intend to create a new branch, just after pushing i realized the current says "abstact" instead of "abstract")


New commits:

018d753Merge branch 'develop' into t/23496/public/23496_patch_sympy_abstact_function
94af74b#23496 : (temp) revert order in rsolve recequadiff.tex test
d76caea#23496 : add message for change in doctest

@mforets mforets mannequin added s: needs review and removed s: needs info labels Sep 3, 2017
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 3, 2017

Changed commit from d76caea to bc21300

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 3, 2017

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

bc21300#23496 : fix a `_sympy_init_` doctest

@mforets
Copy link
Mannequin

mforets mannequin commented Sep 3, 2017

comment:71

We need to do another ticket?

IMHO yes, because this is a different issue; the new ticket could be about implementing rsolve in Sage, as an interface to sympy's rsolve.

yes, that would be a nice feature. we can use ticket #1291. also open is the sage interface to sympy's solve (#22322).

@man74cio
Copy link
Mannequin Author

man74cio mannequin commented Sep 3, 2017

comment:72

Replying to @mforets:

ok, let's do it => needs review

note: this does not depend on #20204.

(@marco : sorry, i did not intend to create a new branch, just after pushing i realized the current says "abstact" instead of "abstract")

No problem, thanks.

@mforets
Copy link
Mannequin

mforets mannequin commented Sep 4, 2017

comment:73

the patchbot errrors seem to be unrelated to our patch, but on a GLPK update.

@tscrim
Copy link
Collaborator

tscrim commented Sep 4, 2017

Changed reviewer from Travis Scrimshaw to Travis Scrimshaw, Marcelo Forets

@tscrim
Copy link
Collaborator

tscrim commented Sep 4, 2017

comment:74

Positive review. Thanks for your work on this.

@rwst
Copy link

rwst commented Sep 4, 2017

comment:75

Thanks from me as well.

@man74cio
Copy link
Mannequin Author

man74cio mannequin commented Sep 5, 2017

comment:76

Thank you for the review

@vbraun
Copy link
Member

vbraun commented Sep 10, 2017

Changed branch from public/23496_patch_sympy_abstract_function to bc21300

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