Completing square, cube



Chris I have tried completing square
but it is not correct.
I tried x^2-5*x+6 and the
out is:
 (x-5/2)^2- 99/4

The function correct is:

comp_square(ex,var) := block([vc],
   if not(atom(var)) or numberp(var)
 then (print("comp_square: var should be an atom but not a number.  "),
return(ex)),
   ex:ratsimp(expand(ex)),
   if not(polynomialp(ex,[var]))
 then (print("comp_square: ex should be a polynomial in var.  "),
return(ex)),
   if hipow(ex,var)#2 
then (print("comp_square: ex should be a quadratic.  "),
return(ex)),
   vc:coeff(ex,var,1)/(2*coeff(ex,var,2)),
   return(coeff(ex,var,2)*((var+vc)^2+coeff(ex,var,0)-coeff(ex,x,1)^2/4))
)$

Now the out is:
(x^2-5/2)^2 -1/4

that is correct.

Best.
Luigi Marino