Esempio n. 1
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);
Esempio n. 2
0
def makeJasArith(item):
    '''Construct a jas.arith object.
    If item is a python tuple or list then a BigRational, BigComplex is constructed. 
    If item is a python float then a BigDecimal is constructed. 
    '''
    #print "item type(%s) = %s" % (item,type(item));
    if isinstance(item,PyInteger) or isinstance(item,PyLong):
        return BigInteger( item );
    if isinstance(item,PyFloat): # ?? what to do ??
        return BigDecimal( str(item) );
    if isinstance(item,PyTuple) or isinstance(item,PyList):
        if len(item) > 2:
            print "len(item) > 2, remaining items ignored";
        #print "item[0] type(%s) = %s" % (item[0],type(item[0]));
        isc = isinstance(item[0],PyTuple) or isinstance(item[0],PyList)
        if len(item) > 1:
            isc = isc or isinstance(item[1],PyTuple) or isinstance(item[1],PyList);
        if isc:
            if len(item) > 1:
                re = makeJasArith( item[0] );
                if not re.isField():
                    re = BigRational( re.val );
                im = makeJasArith( item[1] );
                if not im.isField():
                    im = BigRational( im.val );
                jasArith = BigComplex( re, im );
            else:
                re = makeJasArith( item[0] );
                jasArith = BigComplex( re );
        else:
            if len(item) > 1:
                jasArith = BigRational( item[0], item[1] );
            else:
                jasArith = BigRational( item[0] );
        return jasArith;
    print "unknown item type(%s) = %s" % (item,type(item));
    return item;
Esempio n. 3
0
print "r = " + str(r);
[e,a] = r.gens();
print "e     = " + str(e);
print "a     = " + str(a);
sqrt2 = a**2 - 2;
print "sqrt2 = " + str(sqrt2);
Qs2r = RealN(sqrt2,(1,2));
print "Qs2r   = " + str(Qs2r.factory());
[one,alpha] = Qs2r.gens();
print "one   = " + str(one);
print "alpha = " + str(alpha);
b = 7 * alpha - 10;
print "b     = " + str(b);
print "b.factory()  = " + str(b.factory());
print "sign(b)      = " + str(b.signum());
print "magnitude(b) = " + str(BigDecimal(b.elem.magnitude()));
c = 1 / b;
print "c     = " + str(c);
print "sign(c)      = " + str(c.signum());
print "magnitude(c) = " + str(BigDecimal(c.elem.magnitude()));
Qs2rx = RealN( alpha**2 - 2, ( 1, 2 )  );
print "Qs2rx  = " + str(Qs2rx.factory());
print;


print "------- PolyRing(PolyRing(QQ(),\"a,b,c\"),\"x,y,z\") ---------";
r = PolyRing(QQ(),"a,b,c",PolyRing.grad);
print "r  = " + str(r);
pr = PolyRing(r,"x,y,z",PolyRing.lex);
print "pr = " + str(pr);
[one,a,b,c,x,y,z] = pr.gens();