# full_simplify produces unexpected result

I applied full_simplify to an expression obtained by substituting a quotient of two polynomials in a polynomial expression, as illustrated below.

The highest degree in the result was expected to be 8, but I get an output where the highest degree is 20.

Can anyone help me find what is the mistake i have done?

Code:

var('s,z')
g1 = 12108.8236080100*s^4 + 3016.35528790190*s^3 + 10600.0709715245*s^2 + 1937.60970085071*s + 409.016662847740/s + 472.343751699259/s^2 + 28.3730874809756/s^3 + 24.0436698653890/s^4 + 3397.06167138687
g2 = g1.subs(s=(z-1)/(z+1))
g2.full_simplify()


Output:

(31993.69841156735*z^20 - 158174.2276629893*z^19 + 216392.4500464178*z^18 + 280148.4057432631*z^17 - 1211263.434674058*z^16 + 1037191.771384268*z^15 + 1264180.797481716*z^14 - 3364714.4688927*z^13 + 1723475.12974153*z^12 + 2648901.578200325*z^11 - 4385755.889381289*z^10 + 1244061.427447394*z^9 + 2634639.643830222*z^8 - 2874359.710320266*z^7 + 417712.5402619956*z^6 + 1209501.453649961*z^5 - 917808.742510938*z^4 + 93647.83955663575*z^3 + 205222.817859467*z^2 - 116204.0691059264*z + 21210.98893340469)/(z^20 - 10.0*z^18 + 45.0*z^16 - 120.0*z^14 + 210.0*z^12 - 252.0*z^10 + 210.0*z^8 - 120.0*z^6 + 45.0*z^4 - 10.0*z^2 + 1.0)

edit retag close merge delete

Note that if you ask for g2 you will see that the problem does not come from the substitution step. The problem comes from the simplification step with full_simplify.

( 2015-02-18 18:25:54 +0100 )edit

Sort by ยป oldest newest most voted

Here is a simpler example showing the problem (which comes from using floating-point entries).

sage: s, z = var('s z')
sage: f = s^2 + s + 1/s + 1/s^2 + 1.
sage: g = f.subs(s=(z-1)/(z+1))
sage: g.full_simplify()
(5.0*z^6 + 5.0*z^4 - 9.0*z^2 - 1.0)/(z^6 - 3.0*z^4 + 3.0*z^2 - 1.0)


By contrast, with integer entries:

sage: s, z = var('s z')
sage: f = s^2 + s + 1/s + 1/s^2 + 1
sage: g = f.subs(s=(z-1)/(z+1))
sage: g = f.subs(s=(z-1)/(z+1))
sage: g.full_simplify()
(5*z^4 + 10*z^2 + 1)/(z^4 - 2*z^2 + 1)


So applying simplify_full in the first seems to introduce an extra factor (z^2-1) in the numerator and denominator.

Exercise: find out what simplify_full does, follow each step and figure out where things go wrong.

more

The problem is that you use floating point numbers. For them the operation are unexact and lcm(p^2, p) is likely to be p^3 rather than being p^2 even with simple expressions

sage: p = 2.1*z^2 + 0.1
sage: f = (1/p + 1/p**2).full_simplify()
sage: f
(4.41*z^4 + 2.52*z^2 + 0.11)/(9.261000000000001*z^6 + 1.323*z^4 + 0.06300000000000001*z^2 + 0.001)
sage: (p^3).expand()
9.26100000000000*z^6 + 1.32300000000000*z^4 + 0.0630000000000000*z^2 + 0.00100000000000000


If you exact numbers like integers or rationals this is fine

sage: g1=12108*s^4 + 3016*s^3 + 10600*s^2 + 1937*s + 409/s + 472/s^2 + 28/s^3 + 24/s^4 + 3397
sage: g2=g1.subs(s=((z-1)/(z+1)))
sage: g2.full_simplify()
(31991*z^8 - 158168*z^7 + 408320*z^6 - 668856*z^5 + 758902*z^4 - 603528*z^3 + 332472*z^2 - 116200*z + 21211)/(z^8 - 4*z^6 + 6*z^4 - 4*z^2 + 1)

more

But is there any way to expand polynomials correctly with decimal coefficients?

( 2015-02-19 13:38:49 +0100 )edit

What do you mean by decimal coefficients ? What you used are called floating point numbers and are (binary) approximations of real numbers.

( 2015-02-19 19:58:35 +0100 )edit

One way is to use rationals if your decimals have only few digits, like 21/10 and 1/10 in your example. Floating point is inexact, rational is exact, see https://en.wikipedia.org/wiki/Floatin...

( 2015-02-20 10:38:44 +0100 )edit