| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 6984 |
(FPCore (x y) :precision binary64 (/ (exp (* x (log (/ x (+ x y))))) x))
(FPCore (x y)
:precision binary64
(if (<= x -4.1e+46)
(/ (exp (- y)) x)
(if (<= x 15.0)
(/ (pow (exp x) (log (/ x (+ x y)))) x)
(/ (/ 1.0 x) (exp y)))))double code(double x, double y) {
return exp((x * log((x / (x + y))))) / x;
}
double code(double x, double y) {
double tmp;
if (x <= -4.1e+46) {
tmp = exp(-y) / x;
} else if (x <= 15.0) {
tmp = pow(exp(x), log((x / (x + y)))) / x;
} else {
tmp = (1.0 / x) / exp(y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = exp((x * log((x / (x + y))))) / x
end function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-4.1d+46)) then
tmp = exp(-y) / x
else if (x <= 15.0d0) then
tmp = (exp(x) ** log((x / (x + y)))) / x
else
tmp = (1.0d0 / x) / exp(y)
end if
code = tmp
end function
public static double code(double x, double y) {
return Math.exp((x * Math.log((x / (x + y))))) / x;
}
public static double code(double x, double y) {
double tmp;
if (x <= -4.1e+46) {
tmp = Math.exp(-y) / x;
} else if (x <= 15.0) {
tmp = Math.pow(Math.exp(x), Math.log((x / (x + y)))) / x;
} else {
tmp = (1.0 / x) / Math.exp(y);
}
return tmp;
}
def code(x, y): return math.exp((x * math.log((x / (x + y))))) / x
def code(x, y): tmp = 0 if x <= -4.1e+46: tmp = math.exp(-y) / x elif x <= 15.0: tmp = math.pow(math.exp(x), math.log((x / (x + y)))) / x else: tmp = (1.0 / x) / math.exp(y) return tmp
function code(x, y) return Float64(exp(Float64(x * log(Float64(x / Float64(x + y))))) / x) end
function code(x, y) tmp = 0.0 if (x <= -4.1e+46) tmp = Float64(exp(Float64(-y)) / x); elseif (x <= 15.0) tmp = Float64((exp(x) ^ log(Float64(x / Float64(x + y)))) / x); else tmp = Float64(Float64(1.0 / x) / exp(y)); end return tmp end
function tmp = code(x, y) tmp = exp((x * log((x / (x + y))))) / x; end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.1e+46) tmp = exp(-y) / x; elseif (x <= 15.0) tmp = (exp(x) ^ log((x / (x + y)))) / x; else tmp = (1.0 / x) / exp(y); end tmp_2 = tmp; end
code[x_, y_] := N[(N[Exp[N[(x * N[Log[N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]
code[x_, y_] := If[LessEqual[x, -4.1e+46], N[(N[Exp[(-y)], $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, 15.0], N[(N[Power[N[Exp[x], $MachinePrecision], N[Log[N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / N[Exp[y], $MachinePrecision]), $MachinePrecision]]]
\frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{+46}:\\
\;\;\;\;\frac{e^{-y}}{x}\\
\mathbf{elif}\;x \leq 15:\\
\;\;\;\;\frac{{\left(e^{x}\right)}^{\log \left(\frac{x}{x + y}\right)}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{e^{y}}\\
\end{array}
Results
| Original | 82.4% |
|---|---|
| Target | 87.8% |
| Herbie | 99.8% |
if x < -4.1e46Initial program 80.1%
Simplified80.1%
[Start]80.1 | \[ \frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\] |
|---|---|
*-commutative [=>]80.1 | \[ \frac{e^{\color{blue}{\log \left(\frac{x}{x + y}\right) \cdot x}}}{x}
\] |
exp-to-pow [=>]80.1 | \[ \frac{\color{blue}{{\left(\frac{x}{x + y}\right)}^{x}}}{x}
\] |
Taylor expanded in x around inf 100.0%
Simplified100.0%
[Start]100.0 | \[ \frac{e^{-1 \cdot y}}{x}
\] |
|---|---|
mul-1-neg [=>]100.0 | \[ \frac{e^{\color{blue}{-y}}}{x}
\] |
if -4.1e46 < x < 15Initial program 82.5%
Simplified99.6%
[Start]82.5 | \[ \frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\] |
|---|---|
exp-prod [=>]99.6 | \[ \frac{\color{blue}{{\left(e^{x}\right)}^{\log \left(\frac{x}{x + y}\right)}}}{x}
\] |
if 15 < x Initial program 83.9%
Simplified83.9%
[Start]83.9 | \[ \frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\] |
|---|---|
*-commutative [=>]83.9 | \[ \frac{e^{\color{blue}{\log \left(\frac{x}{x + y}\right) \cdot x}}}{x}
\] |
exp-to-pow [=>]83.9 | \[ \frac{\color{blue}{{\left(\frac{x}{x + y}\right)}^{x}}}{x}
\] |
Taylor expanded in x around inf 99.9%
Simplified99.9%
[Start]99.9 | \[ \frac{e^{-1 \cdot y}}{x}
\] |
|---|---|
mul-1-neg [=>]99.9 | \[ \frac{e^{\color{blue}{-y}}}{x}
\] |
Applied egg-rr99.9%
[Start]99.9 | \[ \frac{e^{-y}}{x}
\] |
|---|---|
clear-num [=>]99.9 | \[ \color{blue}{\frac{1}{\frac{x}{e^{-y}}}}
\] |
inv-pow [=>]99.9 | \[ \color{blue}{{\left(\frac{x}{e^{-y}}\right)}^{-1}}
\] |
div-inv [=>]99.9 | \[ {\color{blue}{\left(x \cdot \frac{1}{e^{-y}}\right)}}^{-1}
\] |
add-sqr-sqrt [=>]32.3 | \[ {\left(x \cdot \frac{1}{e^{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}}\right)}^{-1}
\] |
sqrt-unprod [=>]65.2 | \[ {\left(x \cdot \frac{1}{e^{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}}\right)}^{-1}
\] |
sqr-neg [=>]65.2 | \[ {\left(x \cdot \frac{1}{e^{\sqrt{\color{blue}{y \cdot y}}}}\right)}^{-1}
\] |
sqrt-unprod [<=]32.9 | \[ {\left(x \cdot \frac{1}{e^{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}}\right)}^{-1}
\] |
add-sqr-sqrt [<=]63.9 | \[ {\left(x \cdot \frac{1}{e^{\color{blue}{y}}}\right)}^{-1}
\] |
exp-neg [<=]63.9 | \[ {\left(x \cdot \color{blue}{e^{-y}}\right)}^{-1}
\] |
add-sqr-sqrt [=>]31.0 | \[ {\left(x \cdot e^{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}\right)}^{-1}
\] |
sqrt-unprod [=>]98.6 | \[ {\left(x \cdot e^{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}\right)}^{-1}
\] |
sqr-neg [=>]98.6 | \[ {\left(x \cdot e^{\sqrt{\color{blue}{y \cdot y}}}\right)}^{-1}
\] |
sqrt-unprod [<=]67.6 | \[ {\left(x \cdot e^{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}\right)}^{-1}
\] |
add-sqr-sqrt [<=]99.9 | \[ {\left(x \cdot e^{\color{blue}{y}}\right)}^{-1}
\] |
Taylor expanded in x around 0 99.9%
Simplified99.9%
[Start]99.9 | \[ \frac{1}{e^{y} \cdot x}
\] |
|---|---|
associate-/l/ [<=]99.9 | \[ \color{blue}{\frac{\frac{1}{x}}{e^{y}}}
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 6984 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 6921 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 580 |
| Alternative 4 | |
|---|---|
| Accuracy | 84.4% |
| Cost | 452 |
| Alternative 5 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 192 |
herbie shell --seed 2023151
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, F"
:precision binary64
:herbie-target
(if (< y -3.7311844206647956e+94) (/ (exp (/ -1.0 y)) x) (if (< y 2.817959242728288e+37) (/ (pow (/ x (+ y x)) x) x) (if (< y 2.347387415166998e+178) (log (exp (/ (pow (/ x (+ y x)) x) x))) (/ (exp (/ -1.0 y)) x))))
(/ (exp (* x (log (/ x (+ x y))))) x))