| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 6984 |
(FPCore (x y) :precision binary64 (/ (exp (* x (log (/ x (+ x y))))) x))
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (+ x y)))
(t_1 (log t_0))
(t_2 (/ (exp (* x t_1)) x))
(t_3 (/ (pow (exp x) t_1) x)))
(if (<= t_2 -50000000000000.0)
t_3
(if (<= t_2 -4e-304)
(/ (exp (- y)) x)
(if (<= t_2 0.0)
t_3
(if (<= t_2 5e-13) (/ (/ 1.0 x) (exp y)) (/ (pow t_0 x) x)))))))double code(double x, double y) {
return exp((x * log((x / (x + y))))) / x;
}
double code(double x, double y) {
double t_0 = x / (x + y);
double t_1 = log(t_0);
double t_2 = exp((x * t_1)) / x;
double t_3 = pow(exp(x), t_1) / x;
double tmp;
if (t_2 <= -50000000000000.0) {
tmp = t_3;
} else if (t_2 <= -4e-304) {
tmp = exp(-y) / x;
} else if (t_2 <= 0.0) {
tmp = t_3;
} else if (t_2 <= 5e-13) {
tmp = (1.0 / x) / exp(y);
} else {
tmp = pow(t_0, x) / x;
}
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) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = x / (x + y)
t_1 = log(t_0)
t_2 = exp((x * t_1)) / x
t_3 = (exp(x) ** t_1) / x
if (t_2 <= (-50000000000000.0d0)) then
tmp = t_3
else if (t_2 <= (-4d-304)) then
tmp = exp(-y) / x
else if (t_2 <= 0.0d0) then
tmp = t_3
else if (t_2 <= 5d-13) then
tmp = (1.0d0 / x) / exp(y)
else
tmp = (t_0 ** x) / x
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 t_0 = x / (x + y);
double t_1 = Math.log(t_0);
double t_2 = Math.exp((x * t_1)) / x;
double t_3 = Math.pow(Math.exp(x), t_1) / x;
double tmp;
if (t_2 <= -50000000000000.0) {
tmp = t_3;
} else if (t_2 <= -4e-304) {
tmp = Math.exp(-y) / x;
} else if (t_2 <= 0.0) {
tmp = t_3;
} else if (t_2 <= 5e-13) {
tmp = (1.0 / x) / Math.exp(y);
} else {
tmp = Math.pow(t_0, x) / x;
}
return tmp;
}
def code(x, y): return math.exp((x * math.log((x / (x + y))))) / x
def code(x, y): t_0 = x / (x + y) t_1 = math.log(t_0) t_2 = math.exp((x * t_1)) / x t_3 = math.pow(math.exp(x), t_1) / x tmp = 0 if t_2 <= -50000000000000.0: tmp = t_3 elif t_2 <= -4e-304: tmp = math.exp(-y) / x elif t_2 <= 0.0: tmp = t_3 elif t_2 <= 5e-13: tmp = (1.0 / x) / math.exp(y) else: tmp = math.pow(t_0, x) / x return tmp
function code(x, y) return Float64(exp(Float64(x * log(Float64(x / Float64(x + y))))) / x) end
function code(x, y) t_0 = Float64(x / Float64(x + y)) t_1 = log(t_0) t_2 = Float64(exp(Float64(x * t_1)) / x) t_3 = Float64((exp(x) ^ t_1) / x) tmp = 0.0 if (t_2 <= -50000000000000.0) tmp = t_3; elseif (t_2 <= -4e-304) tmp = Float64(exp(Float64(-y)) / x); elseif (t_2 <= 0.0) tmp = t_3; elseif (t_2 <= 5e-13) tmp = Float64(Float64(1.0 / x) / exp(y)); else tmp = Float64((t_0 ^ x) / x); end return tmp end
function tmp = code(x, y) tmp = exp((x * log((x / (x + y))))) / x; end
function tmp_2 = code(x, y) t_0 = x / (x + y); t_1 = log(t_0); t_2 = exp((x * t_1)) / x; t_3 = (exp(x) ^ t_1) / x; tmp = 0.0; if (t_2 <= -50000000000000.0) tmp = t_3; elseif (t_2 <= -4e-304) tmp = exp(-y) / x; elseif (t_2 <= 0.0) tmp = t_3; elseif (t_2 <= 5e-13) tmp = (1.0 / x) / exp(y); else tmp = (t_0 ^ x) / x; 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_] := Block[{t$95$0 = N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Log[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[N[(x * t$95$1), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[N[Exp[x], $MachinePrecision], t$95$1], $MachinePrecision] / x), $MachinePrecision]}, If[LessEqual[t$95$2, -50000000000000.0], t$95$3, If[LessEqual[t$95$2, -4e-304], N[(N[Exp[(-y)], $MachinePrecision] / x), $MachinePrecision], If[LessEqual[t$95$2, 0.0], t$95$3, If[LessEqual[t$95$2, 5e-13], N[(N[(1.0 / x), $MachinePrecision] / N[Exp[y], $MachinePrecision]), $MachinePrecision], N[(N[Power[t$95$0, x], $MachinePrecision] / x), $MachinePrecision]]]]]]]]]
\frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\begin{array}{l}
t_0 := \frac{x}{x + y}\\
t_1 := \log t_0\\
t_2 := \frac{e^{x \cdot t_1}}{x}\\
t_3 := \frac{{\left(e^{x}\right)}^{t_1}}{x}\\
\mathbf{if}\;t_2 \leq -50000000000000:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_2 \leq -4 \cdot 10^{-304}:\\
\;\;\;\;\frac{e^{-y}}{x}\\
\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{-13}:\\
\;\;\;\;\frac{\frac{1}{x}}{e^{y}}\\
\mathbf{else}:\\
\;\;\;\;\frac{{t_0}^{x}}{x}\\
\end{array}
Results
| Original | 78.6% |
|---|---|
| Target | 77.6% |
| Herbie | 99.2% |
if (/.f64 (exp.f64 (*.f64 x (log.f64 (/.f64 x (+.f64 x y))))) x) < -5e13 or -3.99999999999999988e-304 < (/.f64 (exp.f64 (*.f64 x (log.f64 (/.f64 x (+.f64 x y))))) x) < 0.0Initial program 78.7%
Simplified99.9%
[Start]78.7 | \[ \frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\] |
|---|---|
exp-prod [=>]99.9 | \[ \frac{\color{blue}{{\left(e^{x}\right)}^{\log \left(\frac{x}{x + y}\right)}}}{x}
\] |
if -5e13 < (/.f64 (exp.f64 (*.f64 x (log.f64 (/.f64 x (+.f64 x y))))) x) < -3.99999999999999988e-304Initial program 66.0%
Simplified66.0%
[Start]66.0 | \[ \frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\] |
|---|---|
*-commutative [=>]66.0 | \[ \frac{e^{\color{blue}{\log \left(\frac{x}{x + y}\right) \cdot x}}}{x}
\] |
exp-to-pow [=>]66.0 | \[ \frac{\color{blue}{{\left(\frac{x}{x + y}\right)}^{x}}}{x}
\] |
Taylor expanded in x around inf 98.4%
Simplified98.4%
[Start]98.4 | \[ \frac{e^{-1 \cdot y}}{x}
\] |
|---|---|
mul-1-neg [=>]98.4 | \[ \frac{e^{\color{blue}{-y}}}{x}
\] |
if 0.0 < (/.f64 (exp.f64 (*.f64 x (log.f64 (/.f64 x (+.f64 x y))))) x) < 4.9999999999999999e-13Initial program 60.4%
Simplified60.4%
[Start]60.4 | \[ \frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\] |
|---|---|
*-commutative [=>]60.4 | \[ \frac{e^{\color{blue}{\log \left(\frac{x}{x + y}\right) \cdot x}}}{x}
\] |
exp-to-pow [=>]60.4 | \[ \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-rr100.0%
[Start]99.9 | \[ \frac{e^{-y}}{x}
\] |
|---|---|
clear-num [=>]100.0 | \[ \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 [=>]52.5 | \[ {\left(x \cdot \frac{1}{e^{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}}\right)}^{-1}
\] |
sqrt-unprod [=>]84.2 | \[ {\left(x \cdot \frac{1}{e^{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}}\right)}^{-1}
\] |
sqr-neg [=>]84.2 | \[ {\left(x \cdot \frac{1}{e^{\sqrt{\color{blue}{y \cdot y}}}}\right)}^{-1}
\] |
sqrt-unprod [<=]31.7 | \[ {\left(x \cdot \frac{1}{e^{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}}\right)}^{-1}
\] |
add-sqr-sqrt [<=]59.3 | \[ {\left(x \cdot \frac{1}{e^{\color{blue}{y}}}\right)}^{-1}
\] |
exp-neg [<=]59.3 | \[ {\left(x \cdot \color{blue}{e^{-y}}\right)}^{-1}
\] |
add-sqr-sqrt [=>]27.6 | \[ {\left(x \cdot e^{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}\right)}^{-1}
\] |
sqrt-unprod [=>]75.1 | \[ {\left(x \cdot e^{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}\right)}^{-1}
\] |
sqr-neg [=>]75.1 | \[ {\left(x \cdot e^{\sqrt{\color{blue}{y \cdot y}}}\right)}^{-1}
\] |
sqrt-unprod [<=]47.4 | \[ {\left(x \cdot e^{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}\right)}^{-1}
\] |
add-sqr-sqrt [<=]100.0 | \[ {\left(x \cdot e^{\color{blue}{y}}\right)}^{-1}
\] |
Taylor expanded in x around 0 100.0%
Simplified100.0%
[Start]100.0 | \[ \frac{1}{e^{y} \cdot x}
\] |
|---|---|
associate-/l/ [<=]100.0 | \[ \color{blue}{\frac{\frac{1}{x}}{e^{y}}}
\] |
if 4.9999999999999999e-13 < (/.f64 (exp.f64 (*.f64 x (log.f64 (/.f64 x (+.f64 x y))))) x) Initial program 100.0%
Simplified100.0%
[Start]100.0 | \[ \frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\] |
|---|---|
*-commutative [=>]100.0 | \[ \frac{e^{\color{blue}{\log \left(\frac{x}{x + y}\right) \cdot x}}}{x}
\] |
exp-to-pow [=>]100.0 | \[ \frac{\color{blue}{{\left(\frac{x}{x + y}\right)}^{x}}}{x}
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 6984 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 6921 |
| Alternative 3 | |
|---|---|
| Accuracy | 86.9% |
| Cost | 964 |
| Alternative 4 | |
|---|---|
| Accuracy | 77.5% |
| Cost | 852 |
| Alternative 5 | |
|---|---|
| Accuracy | 85.4% |
| Cost | 580 |
| Alternative 6 | |
|---|---|
| Accuracy | 15.3% |
| Cost | 64 |
herbie shell --seed 2023159
(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))