Ask Your Question

Revision history [back]

I see 3 issues in your code:

First, the append method for lists adds an element as the last entry of the list, for example if L = [1,2,3], then L.append([4,5,6]) will lead to L being equal to [1,2,3,[4,5,6]] (see the lists are nested). Here, it seems you want to catenate a new list of pairs to the existing list, hence you should probably replace pairs.append((f, h) for f in F) with pairs += [(f, h) for f in F]

Now that this error is fixed, another error appears:

AttributeError: 'NoneType' object has no attribute 'lm'

This is due to the following fact: in the line h = s_poly(f1, f2).reduce(), the reduce method works in place, which means that the object to which it is applied is modified, but nothing is returned, hence h will be None after that line. If you want to reduce s_poly(f1, f2) and give it the name h, you should do something like:

h = s_poly(f1, f2)
h.reduce()`

Now that this error is fixed, another error appears:

AttributeError: 'sage.rings.fraction_field_element.FractionFieldElement' object has no attribute 'lm'

The reason is that when you divide polynomials with eachother in the definition of s_poly, the parent of what is returned is a fraction field. It seems that you want to deal with fractions that are actually polynomials, so that their denominator is 1. If you want to work with actual polynomials and not fractions that look like polynomials, you can convert them back to polynomials (that is elements of the ring R), for example by replacing return lcm(f1.lm(),f2.lm())*(1/f1.lt()*f1-1/f2.lt()*f2) with R(return lcm(f1.lm(),f2.lm())*(1/f1.lt()*f1-1/f2.lt()*f2)) in the definition of s_poly. By doing that, there is no need to reduce anymore, so you can just define h = s_poly(f1, f2).

I see 3 issues in your code:

First, the append method for lists adds an element as the last entry of the list, for example if L = [1,2,3], then L.append([4,5,6]) will lead to L being equal to [1,2,3,[4,5,6]] (see the lists are nested). Here, it seems you want to catenate a new list of pairs to the existing list, hence you should probably replace pairs.append((f, h) for f in F) with pairs += [(f, h) for f in F]

Now that this error is fixed, another error appears:

AttributeError: 'NoneType' object has no attribute 'lm'

This is due to the following fact: in the line h = s_poly(f1, f2).reduce(), the reduce method works in place, which means that the object to which it is applied is modified, but nothing is returned, hence h will be None after that line. If you want to reduce s_poly(f1, f2) and give it the name h, you should do something like:

h = s_poly(f1, f2)
h.reduce()`

Now that this error is fixed, another error appears:

AttributeError: 'sage.rings.fraction_field_element.FractionFieldElement' object has no attribute 'lm'

The reason is that when you divide polynomials with eachother in the definition of s_poly, the parent of what is returned is a fraction field. It seems that you want to deal with fractions that are actually polynomials, so that their denominator is 1. If you want to work with actual polynomials and not fractions that look like polynomials, you can convert them back to genuine polynomials (that is elements of the ring R), for example by replacing return lcm(f1.lm(),f2.lm())*(1/f1.lt()*f1-1/f2.lt()*f2) with R(return lcm(f1.lm(),f2.lm())*(1/f1.lt()*f1-1/f2.lt()*f2)) in the definition of s_poly. By doing that, there is no need to reduce anymore, so you can just define h = s_poly(f1, f2).

I see 3 issues in your code:

First, the append method for lists adds an element as the last entry of the list, for example if L = [1,2,3], then L.append([4,5,6]) will lead to L being equal to [1,2,3,[4,5,6]] (see the lists are nested). Here, it seems you want to catenate a new list of pairs to the existing list, hence you should probably replace pairs.append((f, h) for f in F) with pairs += [(f, h) for f in F]

Now that this error is fixed, another error appears:

AttributeError: 'NoneType' object has no attribute 'lm'

This is due to the following fact: in the line h = s_poly(f1, f2).reduce(), the reduce method works in place, which means that the object to which it is applied is modified, but nothing is returned, hence h will be None after that line. If you want to reduce s_poly(f1, f2) and give it the name h, you should do something like:

h = s_poly(f1, f2)
h.reduce()`

Now that this error is fixed, another error appears:

AttributeError: 'sage.rings.fraction_field_element.FractionFieldElement' object has no attribute 'lm'

The reason is that when you divide polynomials with eachother in the definition of s_poly, the parent of what is returned is a fraction field. It seems that you want to deal with fractions that are actually polynomials, so that their denominator is 1. If you want to work with actual polynomials and not fractions that look like polynomials, you can convert them back to genuine polynomials (that is is, elements of the ring R), for example by replacing return lcm(f1.lm(),f2.lm())*(1/f1.lt()*f1-1/f2.lt()*f2) with R(return lcm(f1.lm(),f2.lm())*(1/f1.lt()*f1-1/f2.lt()*f2)) in the definition of s_poly. By doing that, there is no need to reduce anymore, so you can just define h = s_poly(f1, f2).

I see 3 issues in your code:

First, the append method for lists adds an element as the last entry of the list, for example if L = [1,2,3], then L.append([4,5,6]) will lead to L being equal to [1,2,3,[4,5,6]] (see the lists are nested). Here, it seems you want to catenate a new list of pairs to the existing list, hence you should probably replace pairs.append((f, h) for f in F) with pairs += [(f, h) for f in F]

Now that this error is fixed, another error appears:

AttributeError: 'NoneType' object has no attribute 'lm'

This is due to the following fact: in the line h = s_poly(f1, f2).reduce(), the reduce method works in place, which means that the object to which it is applied is modified, but nothing is returned, hence h will be None after that line. If you want to reduce s_poly(f1, f2) and give it the name h, you should do something like:

h = s_poly(f1, f2)
h.reduce()`

Now that this error is fixed, another error appears:

AttributeError: 'sage.rings.fraction_field_element.FractionFieldElement' object has no attribute 'lm'

The reason is that when you divide polynomials with eachother in the definition of s_poly, the parent of what is returned is a fraction field. It seems that you want to deal with fractions that are actually polynomials, so that their denominator is 1. If you want to work with actual polynomials and not fractions that look like polynomials, you can convert them back to genuine polynomials (that is, elements of the ring R), for example by replacing return lcm(f1.lm(),f2.lm())*(1/f1.lt()*f1-1/f2.lt()*f2) with R(return lcm(f1.lm(),f2.lm())*(1/f1.lt()*f1-1/f2.lt()*f2))return R(lcm(f1.lm(),f2.lm())*(1/f1.lt()*f1-1/f2.lt()*f2)) in the definition of s_poly. By doing that, there is no need to reduce anymore, so you can just define h = s_poly(f1, f2).