It appears that I was wrong about what was causing the problem as I still 
get the error. I've moved to using the cloud version as I had thought that 
there is a problem with my installation. Ideally I want to take a given 
integer and construct a polynomial from its base m expansion for some n. 
The code I have to do this is below.
def poly_coeffs(n,m,d):
    # Repeatedly subtract powers of m until polynomial expansion is found.
    coeffs = []
    while n > 0:
        c = 0
        while (m^d) <= n:
            n -= m^d
            c += 1
        coeffs += [int(c)]
        d -= 1
    return coeffs

def base_m_poly(n,m,d):
    coefficients = poly_coeffs(n,m,d)
    deg = d
    f = 0
    for c in coefficients: # Construct f using coefficients.
        f += c*(u^(int(deg)))
        deg -= 1
    f = R(f) # Make sure f in R.
    return f

This code contains the coercion f = R(f) to make sure that I can use the 
is_irreducible and factor methods for univariate polynomials. Everything 
works fine if called step-by-step as below.
R.<u> = ZZ['u']
S.<u,v> = ZZ['u,v']
f  = base_m_poly(1337,36,2); parent(f); f
g = S(f); parent(g)

In this case I get that R is the parent of f and S is the parent of g, as 
expected and desired. When I run this as part of a larger function building 
towards the number field sieve I get the parent sympy.core.add.Add for g. 
The current code for the sieve function is given below.
import time

def nfs(n,b,d,m):
    print("n=",str(n),",b=",str(b),",d=",str(d),",m=",str(m)) 
    n_factorization = []

    # Start timer.
    start = time.time()
    iterations = 0
    print("Checking primality.")
    while miller_rabin(n,10) == "composite" and iterations < b and n > 1:
        print("inside main iteration loop")
        iterations += 1
        # Find polynomial expansion of n.
        f = base_m_poly(n,m,d)
        # Check irreducibility of f.
        if f.is_irreducible():
            print("inside main loop")
            # Find homogenization of f
            g = S(f)
            print(parent(g))
    if n > 1:
        n_factorization += [int(n)]
    end = time.time()
    print("Total calculation took ", str(end-start), " seconds.")
    print("Final factorization:")
    print(n_factorization)

The function miller_rabin is given as Python code, could the change to 
Python scripting be causing a problem?

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to