factor



> When I type factor(x^2-5, a^2-5); I just get (x - a) (x + a) What 
> should I type to get the expected (x - sqrt(5))(x + sqrt(5))?

I'm not sure why you expect the expression with sqrt(5).  The second
argument adjoins an element whose representation in radicals may be
messy, and the representation in 'a' usually gives more insight into the
relationships among the factors.  Consider

  factor(x^10-1,a^4+a^3+a^2+a+1) =>
                                       2        2        3
 (x - 1) (x + 1) (x - a) (x + a) (x - a ) (x + a ) (x - a )

                    3    2                3        3    2
              (x - a  - a  - a - 1) (x + a ) (x + a  + a  + a + 1)

vs. your proposal, which would include ten factors including things like

                              3/4    1/4
          SQRT(SQRT(5) + 1) (5    - 5   ) %I   SQRT(5)   1
      x + ---------------------------------- + ------- + -
                      4 SQRT(2)                   4      4

and

                   1/4
          SQRT(2) 5    SQRT(SQRT(5) + 1) %I   SQRT(5)   1
      x + --------------------------------- - ------- + -
                          4                      4      4

Anyway, if you really DO want that form, you can use Solve on the
minimal polynomial and substitute (which is what I did to generate the
examples above).

That is, when the minimal polynomial's roots are expressible in
radicals.  What do you do when they are not, for example:

  p: x^10-x^2-1$

  factor(p, q^5-q-1) =>

        2        8      6    2  4    3  2    4
      (x  - q) (x  + q x  + q  x  + q  x  + q  - 1)

> What is the difference between factor and gfactor?

gfactor factors over the polynomials with coefficients in the Gaussian
integers.  It is essentially equivalent to factor(..., %i^2+1):

  simp: false;   /* prevent %i^2 from simplifying */

  factor(x^2+1,%i^2+1) =>

     (x-%i)*(x+%i)