Transforming functions

I am not familiar with Mathematica but have the following question: I am trying to write Mathematica code that transforms xa+yax^a+y^a to (x+y)a(x+y)^a for any xx and yy and integer aa. I also need to transform f2(x)+f4(y)f^2(x)+f^4(y) to (f(x)+f2(y))2(f(x)+f^2(y))^2.

=================

=================

2 Answers
2

=================

I think we can just use basic pattern matching:

(* Freshman’s dream… ahhhhh *)

FrobeniusFactor[expr_] := expr //. x_^e1_ + y_^e2_ :>
With[{g = PolynomialGCD[e1, e2]},
(
(x^Cancel[e1/g] + y^Cancel[e2/g])^g
) /; g =!= 1
]

FrobeniusFactor[x^a + y^a]

(x + y)^a

FrobeniusFactor[f[x]^2 + f[y]^4]

(f[x] + f[y]^2)^2

This is not as versatile as Chip’s method but it might be sufficient:

rule = {x_^a_ + y_^b_ /; Divisible[a, b] :> (x^(a/b) + y)^b};

{q^3 + r^3, f[x]^2 + f[y]^4} /. rule

{(q + r)^3, (f[x] + f[y]^2)^2}