Opened 10 years ago

Last modified 10 years ago

#12068 closed enhancement

Numerator for symbolic expression shouldn't use maxima — at Version 6

Reported by: hivert Owned by: hivert
Priority: major Milestone: sage-5.0
Component: symbolics Keywords: numerator, denominator
Cc: Merged in:
Authors: Florent Hivert, Burcin Erocal Reviewers: Burcin Erocal
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by burcin)

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.

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

Change History (8)

comment:1 Changed 10 years ago by hivert

  • Authors set to Florent Hivert
  • Owner changed from burcin to hivert

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

comment:2 Changed 10 years ago by hivert

  • Status changed from new to needs_review

comment:3 follow-up: Changed 10 years ago by burcin

  • Reviewers set to Burcin Erocal
  • Summary changed from Numerator for symbolic expression should'nt use maxima to Numerator for symbolic expression shouldn't use maxima

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.

Changed 10 years ago by hivert

comment:4 in reply to: ↑ 3 Changed 10 years ago by hivert

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 !

comment:5 Changed 10 years ago by hivert

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

Changed 10 years ago by burcin

comment:6 Changed 10 years ago by burcin

  • Authors changed from Florent Hivert to Florent Hivert, Burcin Erocal
  • Description modified (diff)

Declaring py_pow as an int caused problems with attachment:trac_12068-numer_denom_ginac-fh.patch. py_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

Note: See TracTickets for help on using tickets.