Esempio n. 1
0
def test3():
    x, a, b, c = map(Symbol, ['x', 'a', 'b', 'c'])
    #f = x**3 - 8.99085235595703*x**2 + 14.963430343676*x + 24.954282699633
    f = x**3 - 8.990852355957031 * x**2 + 14.96343034367601 * x + 24.95428269963304
    #f = (x + 1) * (x - 4.995426177978516)**2
    f = expand(f)

    print('f : ', f)
    f_ = diff(f)
    print('f_ : ', f_)
    a0 = gcd(f, f_)
    print('a0 : ', a0)
    b1 = quo(f, a0)
    print('b1 : ', b1)
    c1 = quo(f_, a0)
    print('c1 : ', c1)
    d1 = c1 - diff(b1)
    print('d1 : ', d1)

    a1 = gcd(b1, d1)
    print('a1 : ', a1)
    b2 = quo(b1, a1)
    print('b2 : ', b2)

    L = sqf_list(f)
    #L = sqf(f)
    print(L)
Esempio n. 2
0
def test2():
    x, a, b, c = map(Symbol, ['x', 'a', 'b', 'c'])
    #f = 2*x**2 + 5*x**3 + 4*x**4 + x**5
    f = (x + 2) * x**2 * (x + 1)**2
    f = expand(f)

    #print('ex : ', expand((x + 2) * (x**2 + x)**2))
    print('f : ', f)
    f_ = diff(f)
    print('f_ : ', f_)
    a0 = gcd(f, f_)
    print('a0 : ', a0)
    b1 = quo(f, a0)
    print('b1 : ', b1)
    c1 = quo(f_, a0)
    print('c1 : ', c1)
    d1 = c1 - diff(b1)
    print('d1 : ', d1)

    a1 = gcd(b1, d1)
    print('a1 : ', a1)
    b2 = quo(b1, a1)
    print('b2 : ', b2)
    c2 = quo(d1, a1)
    print('c2 : ', c2)
    d2 = c2 - diff(b2)
    print('d2 : ', d2)

    a2 = gcd(b2, d2)
    print('a2 : ', a2)
    b3 = quo(b2, a2)
    print('b3 : ', b3)

    L = sqf_list(f)
    #sqf(f)
    print(L)
Esempio n. 3
0
def GPD_meth(poly, var, div, myorder):
    x, y = symbols('x y')
    zero = symbols('0')
    dlen = len(div)  # num of dividents
    q = []
    NotDivide = False
    divoccur = True

    for k in range(0, len(div)):  # init list of quos
        q.append(zero)
###############################################
    for i in range(0, len(div)):
        #print("iteration",i)
        if poly == 0:
            break

        if NotDivide == True:
            NotDivide = False

        while NotDivide == False:
            LTP = LT(poly, var, order=myorder)  # check if LTD divides LTP
            LTD = LT(div[i], var, order=myorder)
            #print("check3")

            if quo(LTP, LTD) != 0 and rem(LTP, LTD) == 0:
                #print("leading tems divisor/divident0:",LTP,LTD)
                divLT = simplify(LTP / LTD)  #works thatsgood

                #print(divLT)
                ##########check changes in quo rem################
                if q[i] == zero:  # if quo is initialized
                    q[i] = simplify(divLT)
                else:
                    q[i] = simplify(q[i] + divLT)
                poly = simplify(poly - simplify(divLT * div[i]))
                #print("check0",poly)
                #print("new poly,new quo",poly,q[i])
        ##################################################
            else:
                NotDivide = True
                break
    return poly, q  # final results
Esempio n. 4
0
def log_to_atan(f, g):
    """Convert complex logarithms to real arctangents.

       Given a real field K and polynomials f and g in K[x], with g != 0,
       returns a sum h of arctangents of polynomials in K[x], such that:

                       df   d         f + I g
                       -- = -- I log( ------- )
                       dx   dx        f - I g

    """
    if f.degree < g.degree:
        f, g = -g, f

    p, q = poly_div(f, g)

    if q.is_zero:
        return 2*atan(p.as_basic())
    else:
        s, t, h = poly_gcdex(g, -f)
        A = 2*atan(quo(f*s+g*t, h))

        return A + log_to_atan(s, t)
Esempio n. 5
0
def log_to_atan(f, g):
    """Convert complex logarithms to real arctangents.

       Given a real field K and polynomials f and g in K[x], with g != 0,
       returns a sum h of arctangents of polynomials in K[x], such that:

                       df   d         f + I g
                       -- = -- I log( ------- )
                       dx   dx        f - I g

    """
    if f.degree < g.degree:
        f, g = -g, f

    p, q = poly_div(f, g)

    if q.is_zero:
        return 2*atan(p.as_basic())
    else:
        s, t, h = poly_gcdex(g, -f)
        A = 2*atan(quo(f*s+g*t, h))

        return A + log_to_atan(s, t)