Re: Factor and/or Rules replacements

*To*: mathgroup at smc.vnet.net*Subject*: [mg104502] Re: Factor and/or Rules replacements*From*: Szabolcs Horvát <szhorvat at gmail.com>*Date*: Sun, 1 Nov 2009 17:57:56 -0500 (EST)*References*: <hcjjbj$js5$1@smc.vnet.net>

On 2009.11.01. 10:11, yves wrote: > Hello everybody, > > Here is the model problem: > I tried to obtain the factorisation of x^2+b x +c and expected to get something like (x-1/2(-b+Sqrt[b^2-4 c))((x-1/2(-b-Sqrt[b^2-4 c)). > > So I tried > in:Factor[x^2+b x + c] and get > out: c + b x + x^2 Note that Factor[] works over the integers by default, and also that there's no way for Mathematica to know that you meant x to be the variable and {b,c} the coefficients. It assumed that all of them are variables. Factoring over the complexes amounts to simply finding all roots. > So my first question what should I have done? > > I tried another way > in:sol=Solve[x^2+b x + c == 0,{x}]; and get the couple of replacement rules. > Next I defined > in: f=(x-x1)(x-x2) > and finally I replaced x1 and x2 in succession by > in:f /. {(sol[[1]] /. x -> x1), (sol[[2]] /. x -> x2)} > which gave the expected factorisation but enclosed in {}. > My second question is : > Is there a simpler way or more compact to replace x1 and x2? > You could do Solve[x^2 + b x + c == 0, x] Times @@ (x - (x /. %)) Expand[%]