# Amelioration of a Karush-Kuhn-Tucker nice code

In what concerns the resolution of a Karush-Kuhn-Tucker condition, this wonderful code borrowed to Parreiras (The Mathematica Journal 16 2014) which is a correction of another code by Kampas (The Mathematica Journal 9 2005) works nicely and should be publicized:

kkt[obj_, cons_, vars_, paramcons_: True] := Module[
{stdcons, eqcons, ineqcons, lambdas, mus, eqs1, eqs2, eqs3},
stdcons = cons /. {x_ >= y_ -> y - x <= 0, x_ > y_ -> y - x > 0,
x_ == y_ -> x - y == 0, x_ <= y_ -> x - y <= 0};
eqcons = Cases[stdcons, x_ == 0 -> x];
ineqcons = Cases[stdcons, x_ <= 0 -> x];
lambdas = Array[λ, Length[ineqcons]];
mus = Array[μ, Length[eqcons]];

eqs1 = D[(*Lagrangian*)obj + mus.eqcons - lambdas.ineqcons == 0, {vars}];
eqs3 = Table[lambdas[[i]] ineqcons[[i]] == 0, {i, Length[ineqcons]}];

Assuming[paramcons,
Refine[
Reduce[
Join[eqs1, eqs2, eqs3, cons],
Join[vars, lambdas , mus], Reals, Backsubstitution -> True
]
]
]
]


But --- there is always at least a but in MSE --- it works only if the first order conditions which underlies Reduce are algebraic.

For instance, the following gives a solution in a very short time because the derivative of a log has such a structure:

u[x_, y_, z_] := α Log[x] + β Log[y] + γ Log[z];
constraint := px * x + py * y + pz * z ==  rev

kkt[
u[x, y, z], {constraint}, {x, y, z},
{α > 0, β > 0, γ > 0, rev > 0, px > 0, py > 0, pz > 0}
]


But if the function or the constraint incorporate a transcendance --- for instance a term of the form $x^\alpha$ for $\alpha \in \mathbb{R}$ --- then it fails.

For instance, if U[x_, y_]:= x^α y^β, then kkt[] fails. But it is known that $U_x = \alpha U/x$, $U_y = \beta U/x$ so if at a certain stage of the algorithm the substitutions $\alpha x^{\alpha -1}y^\beta$ and $\beta x^{\alpha} y^{\beta-1}$ were made, it should be possible to obtain step by step the desired result. It is the same for a function of the type U[x_, y_]:= (α x^ρ+ (1-α) y^ρ)^(1/ρ)

So I wonder if there is a way to adapt the Kampa-Parreiras code to cope with those cases without been obliged to explicitly derive the KKT conditions.