Re-writing $f(x, y)$ as $g(x)h(y)$ [duplicate]

Is there a general way of re-writing a function of two variables as a product of two functions,

$$f(x, y) = g(x)h(y)$$

Specifically, I’m trying to write an expression,

$$f(x, y) = \frac{a y - x}{y - 1} = g(x) h(y)$$

• Do you mean $f(x,y)=g(x)h(y)$? – SneezeFor16Min Jun 28 at 17:08
• Yes! Let me change – Daniel Farrell Jun 28 at 17:12
• I guess you can use Factor. If it doesn't work, decomposition may be difficult or impossible. – SneezeFor16Min Jun 28 at 17:17
• Ok will read about that function, thanks – Daniel Farrell Jun 28 at 17:17
• This is like the process in solving separable differential equations, but your specific example is not separable. A well-written function should so indicate. – Michael E2 Jun 28 at 17:32

decompose[
expr_,
vars_?(ListQ[#] && Length[#] >= 2 && VectorQ[#, AtomQ] &),
dom_ : Reals
] := If[
VectorQ[Keys[#], k \[Function] Length[k] <= 1],
{True, Times @@@ Apply[Power, #, {2}]},
(* Else, do some math.
True: Decomposable but FactorList failed.
(r \[Function] If[r,
{True, <||>},
(* False: Undecomposable *)
{False, Null},
(* Else: With condition *)
{ConditionalExpression[True, r],
Null}]
)@ Resolve[ForAll[vars,
FunctionDomain[expr, vars, dom],
Reduce[
expr^(Length[vars] - 1)*D @@
Flatten[{expr, vars}]
== Times @@ (D[expr, #] & /@ vars),
dom]], dom]
] &@GroupBy[
FactorList[expr],
vars \[Intersection] Level[#[[1]], {-1}] &
]


For example:

decompose[(a y - x)/(y - 1), {x, y}]

{ConditionalExpression[True, a == 0], Null}

decompose[
(Log[x] + (x - 1)/Sqrt[x]) (y^2 + Sqrt[y] + y) // Expand,
{x, y}
]

{True, <|{} -> 1, {x} -> (-1 + x + Sqrt[x] Log[x])/Sqrt[x], {y} ->
Sqrt[y] (1 + Sqrt[y] + y^(3/2))|>}

decompose[
(Log[x] + (x - 1)/Sqrt[x]) (y^2 + Sqrt[y] + x y) // Expand,
{x, y}
]

{False, Null}

decompose[
2 x^2 (1 + y) z Sqrt[z] // Expand,
{x, y, z}]

{True, <|{} -> 2, {x} -> x^2, {z} -> z^(3/2), {y} -> 1 + y|>}

decompose[
2 x^2 (1 + y) z Sqrt[x + z] // Expand,
{x, y, z}]

{False, Null}

• Thanks. It seems my expression is not decomposable. – Daniel Farrell Jun 28 at 18:15
• Your answer is very good. I would like to know if there is any theoretical proof for this question. If so, it is better to give a link to this textbook. – Ordinary users68 Jun 29 at 0:30
• @PleaseCorrectGrammarMistakes Thanks. But I am just taking advantage of FactorList and no math is involved. I've seen your answer and perhaps you can turn it into code. – SneezeFor16Min Jun 29 at 3:43

I found that there are similar questions in the course of mathematical analysis compiled by 史济怀 of China. I pasted the questions and the reference answers as follows:

On page 492 of this book, we can find a brief reference answer:

In short, if $$u(x,y)$$ can be decomposed into the product of two monomials, then the second mixed partial derivative of $$\ln u(x,y)$$ should be 0.

• 数学分析这块快忘光了.但如果$u(x,y)$可取负值,结论还成立吗? – SneezeFor16Min Jun 29 at 3:39
• @SneezeFor16Min 经过询问哆嗒数学群（群号128709478）里面的北京大学的小米（QQ2498412165），他说仍然成立，只是多一些讨论罢了。 – Ordinary users68 Jun 29 at 3:54
• Okay, I think we should stay in English. Will you post code from this proof? If not, I'll update my answer. :) – SneezeFor16Min Jun 29 at 4:06
• @SneezeFor16Min 我不贴了，你把你的答案更新就好了。 – Ordinary users68 Jun 29 at 4:18