Re: Q: Factor with Polynominals?
- To: mathgroup at smc.vnet.net
- Subject: [mg26732] Re: Q: Factor with Polynominals?
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Fri, 19 Jan 2001 02:14:10 -0500 (EST)
- References: <943d4e$chm@smc.vnet.net> <9461cq$gaa@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Jens,
The problem with the first approach lies in the pattern matching and full
form:
FullForm[x + y + x y]
Plus[x, y, Times[x, y]]
So we get
x + y + x y /. {Plus[a__, b___] :> Plus[a, F[b]]}
x + F[y, x*y]
And with F = Factor,
x + y + x y /. {Plus[a__, b___] :> Plus[a, Factor[b]]}
Factor::nonopt:
Options expected (instead of x y) beyond position 1 in
Factor[y, x y]. An option must be a rule or a list of
rules.
x + Factor[y, x*y]
We can deal with this by introducing a Plus
x + y + x y /. {Plus[a__, b___] :> Plus[a, Factor[Plus[b]]]}
x + (1 + x)*y
Applied this to the original polynomial, and using ReplaceList, we get
ReplaceList[3 x^2 + 3 y^2 + x + y^3 + y x^2, a___ + b___ + c___ :> a +
Factor[Plus[b]] + c] ;
First[Sort[%, Length[#1] <= Length[#2] &]]
x + (3 + y)*(x^2 + y^2)
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de> wrote in message
news:9461cq$gaa at smc.vnet.net...
> Hi,
>
> witch one of the printed forms in:
>
> 3 x^2 + 3 y^2 + x + y^3 + y x^2 /.
> a__ + b__ /; ( Print[a + Factor[Plus[b]]]; False) :> "never come here"
>
> ???
>
> Ok. Lets take the LeafCount[] to choose the most simple case
>
> lst = {};
> 3 x^2 + 3 y^2 + x + y^3 + y x^2 /.
> a__ + b__ /; ( AppendTo[lst, a + Factor[Plus[b]]]; False) :> "also
> never come here";
> Last[First[Sort[{LeafCount[#], #} & /@ lst, First[#1] < First[#2] &]]]
>
>
> Regards
> Jens
>
> Robert wrote:
> >
> > hello!
> > i'd like to factor polynominals, e. g. if i have an exspression like
> >
> > 3 x^2 + 3 y^2 + x + y^3 + y x^2,
> >
> > i'd like to get (i want to factor x^2+y^2):
> >
> > (x^2+y^2) (3 + y) + x.
> >
> > how can i achieve a result like this (also with other, more complicated
> > polynominals)?
> >
> > thanks, robert
>