3
$\begingroup$

I would like to use FactorTerms to factor out constant numerical terms out of an expression, this works as follows:

2 x^2 + 2 y^2 + 4 x y // FactorTerms
(* = 2 (x^2 + 2 x y + y^2) *)

However, this doesn't seem to work if there are square roots:

Sqrt[2] x^2 + Sqrt[2] y^2 + 2 Sqrt[2] x y // FactorTerms
(* = Sqrt[2] x^2 + 2 Sqrt[2] x y + Sqrt[2] y^2 *)

I'm not sure whether that's the way it's supposed to behave or a bug. If that's the desired behaviour, then what is the correct way of factoring out constant numerical terms containing square roots?

$Version gives 11.2.0 for Mac OS X x86 (64-bit) (September 11, 2017).

$\endgroup$
5
$\begingroup$

It seems it works when you specify the variables in your term:

FactorTerms[Sqrt[2] x^2 + Sqrt[2] y^2 + 2 Sqrt[2] x y, {x, y}]
(* Sqrt[2] (x^2 + 2 x y + y^2) *)

To include JM's answer to your comment: If you have several variables and don't want to type them by hand, you can use

FactorTerms[poly, Variables[poly]]

to use them automatically.

$\endgroup$
  • $\begingroup$ This works indeed, thanks! Even though it can be quite clumsy for a large number of variables. The description in the documentation does sound like it should do it also without specifying the variables explicitly. $\endgroup$ – Stan Mar 5 '18 at 11:29
  • 2
    $\begingroup$ @Stan, in that case, you could do FactorTerms[poly, Variables[poly]] so that you don't have to bother with manually getting the variables. $\endgroup$ – J. M. will be back soon Mar 5 '18 at 11:54
1
$\begingroup$
Factor[Sqrt[2] x^2 + Sqrt[2] y^2 + 2 Sqrt[2] x y ]
(* Sqrt[2] (x + y)^2*)

works too!

$\endgroup$
  • $\begingroup$ Hi Ulrich, thanks for the answer, but I explicitly do not want that x^2 + 2 x y + y^2 is transformed to (x + y)^2. I only want to factor out constant numerical terms without performing other possible factorisations. $\endgroup$ – Stan Mar 5 '18 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.