Skip to content

Numerator for symbolic expression shouldn't use maxima #12068

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

Closed
hivert opened this issue Nov 21, 2011 · 28 comments
Closed

Numerator for symbolic expression shouldn't use maxima #12068

hivert opened this issue Nov 21, 2011 · 28 comments

Comments

@hivert
Copy link
Contributor

hivert commented Nov 21, 2011

The code for numerator is currently

def numerator(self):
        """
        Returns the numerator of this symbolic expression.  If the
[...]
        """
        return self.parent()(self._maxima_().num())

Using Pynac should be much faster.

The patch wraps numer, denom, numer_denom and normal from GiNaC and fixes a
bunch of wrong sphinx markup in expression.pyx.

Apply attachment: trac_12068-numer_denom_normal-ginac-fh.patch and attachment: trac_12068-reviewer.patch.

Component: symbolics

Keywords: numerator, denominator

Author: Florent Hivert, Burcin Erocal

Reviewer: Burcin Erocal, Florent Hivert, Karl-Dieter Crisman

Merged: sage-5.0.beta2

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

@hivert hivert added this to the sage-5.0 milestone Nov 21, 2011
@hivert
Copy link
Contributor Author

hivert commented Nov 22, 2011

comment:1

Ginac's behavior is not the same has Maxima: given 1 + 1/(x + 1)

  • Maxima returns 1 + 1/(x + 1) as numerator and 1 as denominator;

  • Ginac returns x + 2 as numerator and x + 1 as denominator.

I think both are useful. My patch keeps the current behavior. Is this what we want ?

Florent

@hivert
Copy link
Contributor Author

hivert commented Nov 22, 2011

Author: Florent Hivert

@hivert hivert assigned hivert and unassigned burcin Nov 22, 2011
@burcin
Copy link
Contributor

burcin commented Nov 22, 2011

Reviewer: Burcin Erocal

@burcin
Copy link
Contributor

burcin commented Nov 22, 2011

comment:3

Looks good to me. It would be better to use elif in line 6480 and 6481. Otherwise, positive review once the tests pass.

Thank you for working on this.

@burcin burcin changed the title Numerator for symbolic expression should'nt use maxima Numerator for symbolic expression shouldn't use maxima Nov 22, 2011
@hivert
Copy link
Contributor Author

hivert commented Nov 22, 2011

Attachment: trac_12068-numer_denom_ginac-fh.patch.gz

@hivert
Copy link
Contributor Author

hivert commented Nov 22, 2011

comment:4

Replying to @burcin:

Looks good to me. It would be better to use elif in line 6480 and 6481. Otherwise, positive review once the tests pass.

Done !

@hivert
Copy link
Contributor Author

hivert commented Nov 22, 2011

comment:5

I got a all test passed on my laptop except a timeout in sage/schemes/elliptic_curves/ell_rational_field.py however relaunching a non parallel test on this single file gives:

sage -t  "sage/schemes/elliptic_curves/ell_rational_field.py"
         [89.8 s]
 
----------------------------------------------------------------------
All tests passed!
Total time for all tests: 89.8 seconds

@burcin

This comment has been minimized.

@burcin
Copy link
Contributor

burcin commented Nov 23, 2011

comment:6

Attachment: trac_12068-denominator.patch.gz

Declaring py_pow as an int caused problems with attachment: trac_12068-numer_denom_ginac-fh.patchpy_object_from_numeric() returns a PyObject. Assigning the return value to an int worked because Cython was creating a temporary PyObject and trying to convert that to an int. This failed if the exponent was not an integer.

attachment: trac_12068-denominator.patch fixes this problem and handles expressions which contain only a power.

Florent can you review my patch?

Apply attachment: trac_12068-numer_denom_ginac-fh.patch, attachment: trac_12068-denominator.patch

@burcin
Copy link
Contributor

burcin commented Nov 23, 2011

Changed author from Florent Hivert to Florent Hivert, Burcin Erocal

@hivert
Copy link
Contributor Author

hivert commented Nov 24, 2011

comment:7

Replying to @burcin:

Florent can you review my patch?

Thanks for fixing my mistake. Unfortunately, because I choose to duplicate the code to speedup numerator_denominator, I also duplicate the mistake. You corrected only one. I'll upload a patch fixing everything.

@hivert
Copy link
Contributor Author

hivert commented Nov 24, 2011

Attachment: trac_12068-numer_denom_fix-fh.patch.gz

@hivert

This comment has been minimized.

@hivert
Copy link
Contributor Author

hivert commented Nov 24, 2011

comment:8

Attachment: trac_12068-numer_denom_ginac-folded-fh.patch.gz

Hi Burcin,

The uploaded patch should fix everything. attachment: trac_12068-numer_denom_fix-fh.patch
contains my modifications on top of yours and attachment: trac_12068-numer_denom_ginac-folded-fh.patch contains everything folded.

Your turn to review ;-)

@burcin
Copy link
Contributor

burcin commented Nov 24, 2011

comment:9

It all looks good. The declaration cdef int py_pow is redundant in numerator_denominator(), but I'll switch to positive review anyway.

@burcin
Copy link
Contributor

burcin commented Nov 24, 2011

Changed reviewer from Burcin Erocal to Burcin Erocal, Florent Hivert

@hivert
Copy link
Contributor Author

hivert commented Nov 24, 2011

comment:10

Bi Burcin,

Replying to @burcin:

It all looks good. The declaration cdef int py_pow is redundant in numerator_denominator(), but I'll switch to positive review anyway.

The following diff

diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
--- a/sage/symbolic/expression.pyx
+++ b/sage/symbolic/expression.pyx
@@ -1867,7 +1867,7 @@ cdef class Expression(CommutativeRingEle
         assured that if True or False is returned (and proof is False) then 
         the answer is correct. 
 
-        INPUT::
+        INPUT:
         
            ntests -- (default 20) the number of iterations to run
            domain -- (optional) the domain from which to draw the random values

broke the doc. So I had to fix my patch. Doing so I discovered a few more typos and fixed them once for all. In the process I ended up folding the patch for #12072.

So please re review. Sorry for the double review.

Florent

@hivert
Copy link
Contributor Author

hivert commented Nov 24, 2011

@hivert
Copy link
Contributor Author

hivert commented Nov 24, 2011

comment:11

Please re-review. Compared to my previous patch, I

  • wrapped normal;
  • removed the unused py_pow declaration;
  • fixed a bunch of doc typos.

Again sorry for the extra work,

Florent

@hivert

This comment has been minimized.

@kcrisman
Copy link
Member

Changed reviewer from Burcin Erocal, Florent Hivert to Burcin Erocal, Florent Hivert, Karl-Dieter Crisman

@kcrisman
Copy link
Member

comment:12

The changes to the previous patch seem fine, docs are good, tests pass. In fact, it's a very nice patch.

The only problem I spied is in the last hunk:

         - ``self`` -- the symbolic expression converting from 
         - ``target`` -- (default None) the symbolic expression

is too far indented. If you're going to fix all of this stuff, you might as well make these at the same indentation level as INPUT, such as in the second-to-last hunk.

In fact, I'm attaching a reviewer patch to fix this.

I wonder if there is a more 'obvious' name for normalize that could be an alias... anyway, not for this ticket. Assuming that Burcin has no objections, positive review other than this.

@kcrisman
Copy link
Member

Attachment: trac_12068-reviewer.patch.gz

reviewer patch

@kcrisman

This comment has been minimized.

@kcrisman
Copy link
Member

@hivert
Copy link
Contributor Author

hivert commented Jan 27, 2012

comment:14

Hi Karl-Dieter,

Replying to @kcrisman:

The changes to the previous patch seem fine, docs are good, tests pass. In fact, it's a very nice patch.

Thanks !

The only problem I spied is in the last hunk:

         - ``self`` -- the symbolic expression converting from 
         - ``target`` -- (default None) the symbolic expression

is too far indented. If you're going to fix all of this stuff, you might as well make these at the same indentation level as INPUT, such as in the second-to-last hunk.

In fact, I'm attaching a reviewer patch to fix this.

Should't someone review your trivial reviewer patch before putting positive review ? Anyway, It is an obvious patch and I did review it. So I confirm your positive review.

I wonder if there is a more 'obvious' name for normalize that could be an alias... anyway, not for this ticket. Assuming that Burcin has no objections, positive review other than this.

In every CAS I used, I've always been confused by simplify, normal, combine... I guess Sage isn't an exception.

@kcrisman
Copy link
Member

comment:15

In fact, I'm attaching a reviewer patch to fix this.

Should't someone review your trivial reviewer patch before putting positive review ? Anyway, It is an obvious patch and I did review it. So I confirm your positive review.

No, reviewers are usually allowed to make VERY trivial changes, esp. to fix doc, without 'formal' other review, otherwise we would take even longer to review things than normal. Naturally, anyone could decide that "reviewer patch X needs review" if they felt it was nontrivial.

@jdemeyer
Copy link
Contributor

jdemeyer commented Feb 2, 2012

Merged: sage-5.0.beta2

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