Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Factorize parts of sums?

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1687] Re: Factorize parts of sums?
  • From: Bob Hanlon <hanlonbo at sgate.com>
  • Date: Mon, 17 Jul 1995 01:24:20 -0400

Following is a general approach.

Bob Hanlon
_______________


For forms as simple as (x^2 + 2x + 1 + p), factoring is straightforward

x^2 + 2x + 1 + p
(% - p // Factor) + p

               2
1 + p + 2 x + x

           2
p + (1 + x)

For less obvious cases, an automated approach is desired.

subFactor::usage = "subFactor[poly, var] factors an n-th order
	polynomial into the form (a (x + b)^n + c), when possible.";

subFactor[poly_, var_] := 
	Module[{coef = CoefficientList[poly, var], polyOrder, 
		a, b, c, thePoly, subst},
		a = Last[coef];  polyOrder = Length[coef] - 1;
		thePoly = Which[
			polyOrder == 0, a, polyOrder == 1, a var + c,
			True, a (var + b)^polyOrder + c ];
		subst = Solve[
			CoefficientList[thePoly, var] == coef, 
			Take[ {c, b}, Min[ polyOrder, 2 ] ] ];
		If[ subst == {}, poly, (thePoly /. subst)[[1]] ] ];

Examples:

subFactor[a x^2 + b x + c, x]

  2
-b  + 4 a c       b      2
----------- + a (--- + x)
    4 a          2 a

% // Expand  (*  verification  *)

             2
c + b x + a x

subFactor[x^2 + 2x + 1 + p, x]

           2
p + (1 + x)

subFactor[E^(2x) - 2E^x + 1 + p, E^x]

       x 2
(-1 + E )  + p

y (2x + 3y)^6 + p // Expand

        6          5  2         4  3         3  4         2  5
p + 64 x  y + 576 x  y  + 2160 x  y  + 4320 x  y  + 4860 x  y  + 
 
          6        7
  2916 x y  + 729 y

subFactor[%, x]

              3 y 6
p + 64 y (x + ---)
               2

If the polynomial cannot be expressed in the form (a (x + b)^n + c), the 
original polynomial is returned:

subFactor[a x^3 + b x^2 + c x + d , x]

             2      3
d + c x + b x  + a x

>  From: moellney at michi.bota.uni-bonn.de (Michael Moellney)
>  Newsgroups: comp.soft-sys.math.mathematica
>  Subject: Factorize parts of sums?
>  Date: 7 Jul 1995 01:20:49 GMT
>  
>  Hi!
>  
>  Has anybody any idea, how I might get
>  
>  a^2 + 2*a + 1 + p
>  
>  become
>  
>  (a+1)^2 + p
>  
>  with a Command in Maple V R2 or Mathematika (or Derive)?
>  
>  Something like
>  
>  ShowMePretty(a^2 + 2*a + 1 + p) ????
>  
>  Thank you very much...
>  
>  Michael
>  
>  PLEASE: send me E-Mail:  moellney at michi.bota.uni-bonn.de



  • Prev by Date: Re: Reverse order terms and 0-origin array.
  • Next by Date: Re: stat package
  • Previous by thread: Factorize parts of sums?
  • Next by thread: Does Mma solve INTEGER Problems