Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

method overloading error?

Hi all:

I made a class called RationalExpression that encodes a rational expression (ratio of polynomials). It contains a class method called 'numerator' that returns the numerator of a RationalExpression instance, but the method doesn't work when i work with a multivariate polynomial ring. The 'numerator' method appears to clash with another 'numerator' method. Do you know how i can fix my bug?

Here's my code snippet:

class RationalExpression(object):
    r"""
    Represents a rational expression `P/(Q_1^e_1 \cdots Q_m^e_m)` by storing the
    parts `P` and `[[Q_1,e_1], \ldots, [Q_m,e_m]]`, where
   `P, Q_1, \ldots, Q_m` are elements of a common polynomial ring, and
   `e_1, \ldots, e_m` are positive integers.
    """
    def __init__(self, num, *denoms):
        self.numerator = num
        self.base_ring = num.parent() 
        self.denominators = sorted(denoms) 

    def __str__(self):
        return str([self.numerator, self.denominators])

    def numerator(self):
        return self.numerator

And here's a failing example:

sage: R.<x,y>= PolynomialRing(QQ)
sage: P = x*y**2
sage: Qs = [x*y,3], [x,1]
sage: f = RationalExpression(P, *Qs)
sage: print f
[x*y^2, [[x, 1], [x*y, 3]]]
sage: type(f)
<class '__main__.RationalExpression'>
sage: f.numerator()
Traceback (most recent call last):    print f
  File "", line 1, in <module>

  File "/private/var/folders/bc/bc2aJOjCE20MqpWiFIh58++++TQ/-Tmp-/tmpcbitNd/___code___.py", line 10, in <module>
    exec compile(u'print f.numerator()' + '\n', '', 'single')
  File "", line 1, in <module>

  File "multi_polynomial_libsingular.pyx", line 2025, in     sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular.__call__ (sage/rings/polynomial/multi_polynomial_libsingular.cpp:14808)
TypeError: number of arguments does not match number of variables in parent

method overloading error?

Hi all:

I made a class called RationalExpression that encodes a rational expression (ratio of polynomials). It contains a class method called 'numerator' that returns the numerator of a RationalExpression instance, but the method doesn't work when i work with a multivariate polynomial ring. The 'numerator' method appears to clash with another 'numerator' method. Do you know how i can fix my bug?

Here's my the relevant code snippet:snippet from /Users/arai021/Dropbox/sage_projects/pfd.py:

class RationalExpression(object):
    r"""
    Represents a rational expression `P/(Q_1^e_1 \cdots Q_m^e_m)` by storing the
    parts `P` and `[[Q_1,e_1], \ldots, [Q_m,e_m]]`, where
   `P, Q_1, \ldots, Q_m` are elements of a common polynomial ring, and
   `e_1, \ldots, e_m` are positive integers.
    """
    def __init__(self, num, *denoms):
        self.numerator = num
        self.base_ring = num.parent() 
        self.denominators = sorted(denoms) 

    def __str__(self):
        return str([self.numerator, self.denominators])

    def numerator(self):
        return self.numerator

And here's a failing example:

sage: attach("/Users/arai021/Dropbox/sage_projects/pfd.py")
sage: R.<x,y>= PolynomialRing(QQ)
sage: P = x*y**2
sage: Qs = [x*y,3], [x,1]
sage: f = RationalExpression(P, *Qs)
sage: print f
[x*y^2, [[x, 1], [x*y, 3]]]
sage: type(f)
<class '__main__.RationalExpression'>
sage: f.numerator()
Traceback (most recent call last):    print f
  File "", line 1, in <module>

  File "/private/var/folders/bc/bc2aJOjCE20MqpWiFIh58++++TQ/-Tmp-/tmpcbitNd/___code___.py", line 10, in <module>
    exec compile(u'print f.numerator()' + '\n', '', 'single')
  File "", line 1, in <module>

  File "multi_polynomial_libsingular.pyx", line 2025, in     sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular.__call__ (sage/rings/polynomial/multi_polynomial_libsingular.cpp:14808)
TypeError: number of arguments does not match number of variables in parent