?

Average Error: 18.4 → 0.3
Time: 13.7s
Precision: binary64
Cost: 46276

?

$\left(0 \leq x \land x \leq 1.79 \cdot 10^{+308}\right) \land \left(0 \leq y \land y \leq 1.79 \cdot 10^{+308}\right)$
${x}^{y} - {y}^{x}$
$\begin{array}{l} \mathbf{if}\;x \leq 1.9 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{expm1}\left(\log x \cdot y\right) - x \cdot \log y\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}}{\mathsf{fma}\left({y}^{x}, {y}^{x} + {x}^{y}, {x}^{\left(y \cdot 2\right)}\right)}\\ \end{array}$
(FPCore (x y) :precision binary64 (- (pow x y) (pow y x)))
(FPCore (x y)
:precision binary64
(if (<= x 1.9e-11)
(- (expm1 (* (log x) y)) (* x (log y)))
(/
(- (pow x (* y 3.0)) (pow y (* x 3.0)))
(fma (pow y x) (+ (pow y x) (pow x y)) (pow x (* y 2.0))))))
double code(double x, double y) {
return pow(x, y) - pow(y, x);
}

double code(double x, double y) {
double tmp;
if (x <= 1.9e-11) {
tmp = expm1((log(x) * y)) - (x * log(y));
} else {
tmp = (pow(x, (y * 3.0)) - pow(y, (x * 3.0))) / fma(pow(y, x), (pow(y, x) + pow(x, y)), pow(x, (y * 2.0)));
}
return tmp;
}

function code(x, y)
return Float64((x ^ y) - (y ^ x))
end

function code(x, y)
tmp = 0.0
if (x <= 1.9e-11)
tmp = Float64(expm1(Float64(log(x) * y)) - Float64(x * log(y)));
else
tmp = Float64(Float64((x ^ Float64(y * 3.0)) - (y ^ Float64(x * 3.0))) / fma((y ^ x), Float64((y ^ x) + (x ^ y)), (x ^ Float64(y * 2.0))));
end
return tmp
end

code[x_, y_] := N[(N[Power[x, y], $MachinePrecision] - N[Power[y, x],$MachinePrecision]), $MachinePrecision]  code[x_, y_] := If[LessEqual[x, 1.9e-11], N[(N[(Exp[N[(N[Log[x],$MachinePrecision] * y), $MachinePrecision]] - 1),$MachinePrecision] - N[(x * N[Log[y], $MachinePrecision]),$MachinePrecision]), $MachinePrecision], N[(N[(N[Power[x, N[(y * 3.0),$MachinePrecision]], $MachinePrecision] - N[Power[y, N[(x * 3.0),$MachinePrecision]], $MachinePrecision]),$MachinePrecision] / N[(N[Power[y, x], $MachinePrecision] * N[(N[Power[y, x],$MachinePrecision] + N[Power[x, y], $MachinePrecision]),$MachinePrecision] + N[Power[x, N[(y * 2.0), $MachinePrecision]],$MachinePrecision]), $MachinePrecision]),$MachinePrecision]]

{x}^{y} - {y}^{x}

\begin{array}{l}
\mathbf{if}\;x \leq 1.9 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{expm1}\left(\log x \cdot y\right) - x \cdot \log y\\

\mathbf{else}:\\
\;\;\;\;\frac{{x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}}{\mathsf{fma}\left({y}^{x}, {y}^{x} + {x}^{y}, {x}^{\left(y \cdot 2\right)}\right)}\\

\end{array}


Derivation?

1. Split input into 2 regimes
2. if x < 1.8999999999999999e-11

1. Initial program 28.8

${x}^{y} - {y}^{x}$
2. Taylor expanded in x around 0 28.8

$\leadsto \color{blue}{\left(-1 \cdot \left(\log y \cdot x\right) + {x}^{y}\right) - 1}$
3. Simplified15.5

$\leadsto \color{blue}{\mathsf{fma}\left(-\log y, x, {x}^{y} + -1\right)}$
Proof
[Start]28.8 $\left(-1 \cdot \left(\log y \cdot x\right) + {x}^{y}\right) - 1$ $\color{blue}{-1 \cdot \left(\log y \cdot x\right) + \left({x}^{y} - 1\right)}$ $\color{blue}{\left(-\log y \cdot x\right)} + \left({x}^{y} - 1\right)$ $\color{blue}{\left(-\log y\right) \cdot x} + \left({x}^{y} - 1\right)$ $\color{blue}{\log \left(\frac{1}{y}\right)} \cdot x + \left({x}^{y} - 1\right)$ $\color{blue}{\mathsf{fma}\left(\log \left(\frac{1}{y}\right), x, {x}^{y} - 1\right)}$ $\mathsf{fma}\left(\color{blue}{-\log y}, x, {x}^{y} - 1\right)$ $\mathsf{fma}\left(-\log y, x, \color{blue}{{x}^{y} + \left(-1\right)}\right)$ $\mathsf{fma}\left(-\log y, x, {x}^{y} + \color{blue}{-1}\right)$
4. Taylor expanded in x around inf 28.8

$\leadsto \color{blue}{\left(-1 \cdot \left(\log y \cdot x\right) + e^{-1 \cdot \left(y \cdot \log \left(\frac{1}{x}\right)\right)}\right) - 1}$
5. Simplified0.3

$\leadsto \color{blue}{\mathsf{expm1}\left(\left(-\log x\right) \cdot \left(-y\right)\right) - x \cdot \log y}$
Proof
[Start]28.8 $\left(-1 \cdot \left(\log y \cdot x\right) + e^{-1 \cdot \left(y \cdot \log \left(\frac{1}{x}\right)\right)}\right) - 1$ $\color{blue}{\left(-1 \cdot \left(\log y \cdot x\right) + e^{-1 \cdot \left(y \cdot \log \left(\frac{1}{x}\right)\right)}\right) + \left(-1\right)}$ $\left(-1 \cdot \left(\log y \cdot x\right) + e^{-1 \cdot \left(y \cdot \log \left(\frac{1}{x}\right)\right)}\right) + \color{blue}{-1}$ $\color{blue}{-1 + \left(-1 \cdot \left(\log y \cdot x\right) + e^{-1 \cdot \left(y \cdot \log \left(\frac{1}{x}\right)\right)}\right)}$ $-1 + \color{blue}{\left(e^{-1 \cdot \left(y \cdot \log \left(\frac{1}{x}\right)\right)} + -1 \cdot \left(\log y \cdot x\right)\right)}$ $-1 + \left(e^{-1 \cdot \left(y \cdot \log \left(\frac{1}{x}\right)\right)} + -1 \cdot \color{blue}{\left(x \cdot \log y\right)}\right)$ $-1 + \left(e^{-1 \cdot \left(y \cdot \log \left(\frac{1}{x}\right)\right)} + \color{blue}{\left(-x \cdot \log y\right)}\right)$ $-1 + \color{blue}{\left(e^{-1 \cdot \left(y \cdot \log \left(\frac{1}{x}\right)\right)} - x \cdot \log y\right)}$ $\color{blue}{\left(-1 + e^{-1 \cdot \left(y \cdot \log \left(\frac{1}{x}\right)\right)}\right) - x \cdot \log y}$

if 1.8999999999999999e-11 < x

1. Initial program 0.3

${x}^{y} - {y}^{x}$
2. Applied egg-rr0.4

$\leadsto \color{blue}{\left({x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}\right) \cdot \frac{1}{{x}^{\left(2 \cdot y\right)} + {y}^{x} \cdot \left({x}^{y} + {y}^{x}\right)}}$
3. Simplified0.4

$\leadsto \color{blue}{\frac{{x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}}{\mathsf{fma}\left({y}^{x}, {x}^{y} + {y}^{x}, {x}^{\left(y \cdot 2\right)}\right)}}$
Proof
[Start]0.4 $\left({x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}\right) \cdot \frac{1}{{x}^{\left(2 \cdot y\right)} + {y}^{x} \cdot \left({x}^{y} + {y}^{x}\right)}$ $\color{blue}{\frac{\left({x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}\right) \cdot 1}{{x}^{\left(2 \cdot y\right)} + {y}^{x} \cdot \left({x}^{y} + {y}^{x}\right)}}$ $\frac{\color{blue}{{x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}}}{{x}^{\left(2 \cdot y\right)} + {y}^{x} \cdot \left({x}^{y} + {y}^{x}\right)}$ $\frac{{x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}}{\color{blue}{{y}^{x} \cdot \left({x}^{y} + {y}^{x}\right) + {x}^{\left(2 \cdot y\right)}}}$ $\frac{{x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}}{\color{blue}{\mathsf{fma}\left({y}^{x}, {x}^{y} + {y}^{x}, {x}^{\left(2 \cdot y\right)}\right)}}$ $\frac{{x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}}{\mathsf{fma}\left({y}^{x}, {x}^{y} + {y}^{x}, {x}^{\color{blue}{\left(y \cdot 2\right)}}\right)}$
3. Recombined 2 regimes into one program.
4. Final simplification0.3

$\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.9 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{expm1}\left(\log x \cdot y\right) - x \cdot \log y\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}}{\mathsf{fma}\left({y}^{x}, {y}^{x} + {x}^{y}, {x}^{\left(y \cdot 2\right)}\right)}\\ \end{array}$

Alternatives

Alternative 1
Error0.3
Cost40004
$\begin{array}{l} \mathbf{if}\;x \leq 8.5 \cdot 10^{-12}:\\ \;\;\;\;\mathsf{expm1}\left(\log x \cdot y\right) - x \cdot \log y\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{\left(y \cdot 3\right)} - {y}^{\left(x \cdot 3\right)}}{{x}^{\left(y \cdot 2\right)} + {y}^{x} \cdot \left({y}^{x} + {x}^{y}\right)}\\ \end{array}$
Alternative 2
Error0.5
Cost39752
$\begin{array}{l} t_0 := {x}^{y} - {y}^{x}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-8}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 10^{-12}:\\ \;\;\;\;\log x \cdot y - x \cdot \log y\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{t_0}}\\ \end{array}$
Alternative 3
Error0.5
Cost39625
$\begin{array}{l} t_0 := {x}^{y} - {y}^{x}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-8} \lor \neg \left(t_0 \leq 10^{-12}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\log x \cdot y - x \cdot \log y\\ \end{array}$
Alternative 4
Error10.0
Cost39497
$\begin{array}{l} t_0 := {x}^{y} - {y}^{x}\\ \mathbf{if}\;t_0 \leq -4 \cdot 10^{-14} \lor \neg \left(t_0 \leq 10^{-12}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\log y \cdot \left(-x\right)\\ \end{array}$
Alternative 5
Error0.3
Cost19780
$\begin{array}{l} \mathbf{if}\;x \leq 2.35 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{expm1}\left(\log x \cdot y\right) - x \cdot \log y\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{{x}^{y} - {y}^{x}}}\\ \end{array}$
Alternative 6
Error19.9
Cost6920
$\begin{array}{l} \mathbf{if}\;x \leq 1.2 \cdot 10^{-30}:\\ \;\;\;\;{x}^{y} + -1\\ \mathbf{elif}\;x \leq 2.75 \cdot 10^{-11}:\\ \;\;\;\;\log y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - {y}^{x}\\ \end{array}$
Alternative 7
Error31.4
Cost6788
$\begin{array}{l} \mathbf{if}\;x \leq 2.2 \cdot 10^{-11}:\\ \;\;\;\;\log y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - {y}^{x}\\ \end{array}$
Alternative 8
Error52.0
Cost6656
$\log y \cdot \left(-x\right)$

Reproduce?

herbie shell --seed 1
(FPCore (x y)
:name "x^y - y^x"
:precision binary64
:pre (and (and (<= 0.0 x) (<= x 1.79e+308)) (and (<= 0.0 y) (<= y 1.79e+308)))
(- (pow x y) (pow y x)))