Example #1
0
 def zero(self):
     '''Zero element of this ring.
     '''
     if self.isFactory():
         return RingElem( self.elem.getZERO() );
     else:
         return RingElem( self.elem.ring.getZERO() );
Example #2
0
 def one(self):
     '''One element of this ring.
     '''
     if self.isFactory():
         return RingElem( self.elem.getONE() );
     else:
         return RingElem( self.elem.ring.getONE() );
Example #3
0
 def element(self,polystr):
     '''Create an element from a string.
     '''
     I = Ideal(self, "( " + polystr + " )");
     list = I.pset.list;
     if len(list) > 0:
         return RingElem( list[0] );
Example #4
0
def CC(re=BigRational(),im=BigRational()):
    '''Create JAS BigComplex as ring element.
    '''
    if isinstance(re,PyTuple) or isinstance(re,PyList):
        if isinstance(re[0],PyTuple) or isinstance(re[0],PyList):
            if len(re) > 1:
                im = QQ( re[1] );
            re = QQ( re[0] );
        else:
            re = QQ(re);
#        re = makeJasArith( re );
    if isinstance(im,PyTuple) or isinstance(im,PyList):
        im = QQ( im );
#        im = makeJasArith( im );
    if isinstance(re,RingElem):
        re = re.elem;
    if isinstance(im,RingElem):
        im = im.elem;
    if im.isZERO():
        if re.isZERO():
            c = BigComplex();
        else:
            c = BigComplex(re);
    else:
        c = BigComplex(re,im);
    return RingElem(c);
Example #5
0
 def random(self,k=5,l=7,d=3,q=0.3):
     '''Get a random polynomial.
     '''
     r = self.ring.random(k,l,d,q);
     if self.ring.coFac.isField():
         r = r.monic();
     return RingElem( r );
Example #6
0
    def fixPoint(self,psmap):
        '''Create a power series as fixed point of the given mapping.

        psmap must implement the PowerSeriesMap interface.
        '''
        ps = self.ring.fixPoint( psmap );
        return RingElem( ps );
Example #7
0
 def differentiate(self):
     '''Differentiate a power series.
     '''
     try:
         e = self.elem.differentiate();
     except:
         e = None;            
     return RingElem( e );
Example #8
0
 def gcd(self,a,b):
     '''Compute the greatest common divisor of a and b.
     '''
     if isinstance(a,RingElem):
         a = a.elem;
     if isinstance(b,RingElem):
         b = b.elem;
     return RingElem( a.gcd(b) );
Example #9
0
 def coerce(self,other):
     '''Coerce other to self.
     '''
     #print "self  type(%s) = %s" % (self,type(self));
     #print "other type(%s) = %s" % (other,type(other));
     if isinstance(other,RingElem):
         if self.isPolynomial() and not other.isPolynomial():
             o = self.ring.parse( str(other) );
             return RingElem( o );
         return other;
     #print "--1";
     if isinstance(other,PyTuple) or isinstance(other,PyList):
         # assume BigRational or BigComplex
         # assume self will be compatible with them. todo: check this
         o = makeJasArith(other);
         return RingElem(o);
     #print "--2";
     # test if self.elem is a factory itself
     if self.isFactory():
         if isinstance(other,PyInteger) or isinstance(other,PyLong):
             o = self.elem.fromInteger(other);
         else:
             if isinstance(other,PyFloat): # ?? what to do ??
                 o = self.elem.fromInteger( int(other) );
             else:
                 print "unknown other type(%s) = %s" % (other,type(other));
                 o = other;
         return RingElem(o);
     #print "--3";
     # self.elem has a ring factory
     if isinstance(other,PyInteger) or isinstance(other,PyLong):
         o = self.elem.ring.fromInteger(other);
     else:
         if isinstance(other,PyFloat): # ?? what to do ??
             o = self.elem.ring.fromInteger( int(other) );
         else:
             print "unknown other type(%s) = %s" % (other,type(other));
             o = other;
     #print "--4";
     return RingElem(o);
Example #10
0
def DD(d=0):
    '''Create JAS BigDecimal as ring element.
    '''
    if isinstance(d,RingElem):
        d = d.elem;
    if isinstance(d,PyFloat):
        d = str(d);
    #print "d type(%s) = %s" % (d,type(d));
    if d == 0:
       r = BigDecimal();
    else:
       r = BigDecimal(d);
    return RingElem(r);
Example #11
0
 def gcd(self,a,b):
     '''Compute the greatest common divisor of a and b.
     '''
     if isinstance(a,RingElem):
         a = a.elem;
     else:
         a = self.element( str(a) );
         a = a.elem;
     if isinstance(b,RingElem):
         b = b.elem;
     else:
         b = self.element( str(b) );
         b = b.elem;
     return RingElem( self.engine.gcd(a,b) );
Example #12
0
 def integrate(self,a):
     '''Integrate a power series with constant a.
     '''
     #print "self  type(%s) = %s" % (self,type(self));
     #print "a     type(%s) = %s" % (a,type(a));
     x = None;
     if isinstance(a,RingElem):
         x = a.elem;
     if isinstance(a,PyTuple) or isinstance(a,PyList):
         # assume BigRational or BigComplex
         # assume self will be compatible with them. todo: check this
         x = makeJasArith(a);
     try:
         e = self.elem.integrate(x);
     except:
         e = None;            
     return RingElem( e );
Example #13
0
def RF(d,n=1):
    '''Create JAS rational function Quotient as ring element.
    '''
    if isinstance(d,PyTuple) or isinstance(d,PyList):
        if n != 1:
            print "%s ignored" % n;
        if len(d) > 1:
            n = d[1];
        d = d[0];
    if isinstance(d,RingElem):
        d = d.elem;
    if isinstance(n,RingElem):
        n = n.elem;
    qr = QuotientRing(d.ring);
    if n == 1:
        r = Quotient(qr,d);
    else:
        r = Quotient(qr,d,n);
    return RingElem(r);
Example #14
0
 def __pow__(self,other):
     '''Power of this to other.
     '''
     #print "self  type(%s) = %s" % (self,type(self));
     #print "pow other type(%s) = %s" % (other,type(other));
     if isinstance(other,PyInteger):
         n = other;
     else:
         if isinstance(other,RingElem): 
             n = other.elem;
             if isinstance(n,BigRational): # does not work
                 n = n.numerator().intValue();
             if isinstance(n,BigInteger):  # does not work
                 n = n.intValue();
     if self.isFactory():
         p = Power(self.elem).power( self.elem, n );
     else:
         p = Power(self.elem.ring).power( self.elem, n );
     return RingElem( p ); 
Example #15
0
    def create(self,ifunc=None,jfunc=None,clazz=None):
        '''Create a power series with given generating function.

        ifunc(int i) must return a value which is used in RingFactory.fromInteger().
        jfunc(int i) must return a value of type ring.coFac.
        clazz must implement the Coefficients abstract class.
        '''
        class coeff( Coefficients ):
            def __init__(self,cofac):
                self.coFac = cofac;
            def generate(self,i):
                if jfunc == None:
                    return self.coFac.fromInteger( ifunc(i) );
                else:
                    return jfunc(i);
        if clazz == None:
            ps = UnivPowerSeries( self.ring, coeff(self.ring.coFac) );
        else:
            ps = UnivPowerSeries( self.ring, clazz );
        return RingElem( ps );
Example #16
0
def QQ(d=0,n=1):
    '''Create JAS BigRational as ring element.
    '''
    if isinstance(d,PyTuple) or isinstance(d,PyList):
        if n != 1:
            print "%s ignored" % n;
        if len(d) > 1:
            n = d[1];
        d = d[0];
    if isinstance(d,RingElem):
        d = d.elem;
    if isinstance(n,RingElem):
        n = n.elem;
    if n == 1:
        if d == 0:
            r = BigRational();
        else:
            r = BigRational(d);
    else:
        r = BigRational(d,n);
    return RingElem(r);
Example #17
0
 def gens(self):
     '''Get list of generators of the polynomial ring.
     '''
     L = self.ring.univariateList();
     c = self.ring.coFac;
     nv = None;
     try:
         nv = c.nvar;
     except:
         pass
     #print "type(coFac) = ", type(self.ring.coFac);
     #if isinstance(c,GenPolynomial): # does not work
     if nv:
         Lp = c.univariateList();
         #Ls = [ GenPolynomial(self.ring,l) for l in Lp ];
         i = 0;
         for l in Lp:
             L.add( i, GenPolynomial(self.ring,l) );
             i += 1;
     N = [ RingElem(e) for e in L ];
     return N;
Example #18
0
 def tan(self):
     '''Get the tangens power series.
     '''
     return RingElem( self.ring.getTAN() );
Example #19
0
 def cos(self):
     '''Get the cosinus power series.
     '''
     return RingElem( self.ring.getCOS() );
Example #20
0
 def sin(self):
     '''Get the sinus power series.
     '''
     return RingElem( self.ring.getSIN() );
Example #21
0
 def exp(self):
     '''Get the exponential power series.
     '''
     return RingElem( self.ring.getEXP() );
Example #22
0
 def random(self,n):
     '''Get a random power series.
     '''
     return RingElem( self.ring.random(n) );
Example #23
0
 def zero(self):
     '''Get the zero of the power series ring.
     '''
     return RingElem( self.ring.getZERO() );
Example #24
0
 def one(self):
     '''Get the one of the power series ring.
     '''
     return RingElem( self.ring.getONE() );
Example #25
0
 def gens(self):
     '''Get the generator of the power series ring.
     '''
     return RingElem( self.ring.getONE().shift(1) );
Example #26
0
 def zero(self):
     '''Get the zero of the solvable polynomial ring.
     '''
     return RingElem( self.ring.getZERO() );
Example #27
0
 def one(self):
     '''Get the one of the solvable polynomial ring.
     '''
     return RingElem( self.ring.getONE() );
Example #28
0
 def __sub__(self,other):
     '''Subtract two ring elements.
     '''
     [s,o] = coercePair(self,other);
     return RingElem( s.elem.subtract( o.elem ) ); 
Example #29
0
 def __div__(self,other):
     '''Divide two ring elements.
     '''
     [s,o] = coercePair(self,other);
     return RingElem( s.elem.divide( o.elem ) ); 
Example #30
0
 def __mod__(self,other):
     '''Modular remainder of two ring elements.
     '''
     [s,o] = coercePair(self,other);
     return RingElem( s.elem.remainder( o.elem ) );