1
$\begingroup$

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

$\endgroup$
0

2 Answers 2

3
$\begingroup$

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
$\endgroup$
2
$\begingroup$

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}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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