| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 6920 |
\[\begin{array}{l}
t_0 := \frac{e^{-y}}{x}\\
\mathbf{if}\;x \leq -7.2 \cdot 10^{+45}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 190:\\
\;\;\;\;\frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
(FPCore (x y) :precision binary64 (/ (exp (* x (log (/ x (+ x y))))) x))
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (exp (- y)) x))
(t_1 (/ x (+ x y)))
(t_2 (/ (exp (* x (log t_1))) x)))
(if (<= t_2 -1000.0)
(/ 1.0 x)
(if (<= t_2 -1e-300)
t_0
(if (<= t_2 0.0)
(+ (+ 1.0 (/ 1.0 x)) -1.0)
(if (<= t_2 1e-113) t_0 (* (/ 1.0 x) (pow t_1 x))))))))double code(double x, double y) {
return exp((x * log((x / (x + y))))) / x;
}
double code(double x, double y) {
double t_0 = exp(-y) / x;
double t_1 = x / (x + y);
double t_2 = exp((x * log(t_1))) / x;
double tmp;
if (t_2 <= -1000.0) {
tmp = 1.0 / x;
} else if (t_2 <= -1e-300) {
tmp = t_0;
} else if (t_2 <= 0.0) {
tmp = (1.0 + (1.0 / x)) + -1.0;
} else if (t_2 <= 1e-113) {
tmp = t_0;
} else {
tmp = (1.0 / x) * pow(t_1, 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) :: tmp
t_0 = exp(-y) / x
t_1 = x / (x + y)
t_2 = exp((x * log(t_1))) / x
if (t_2 <= (-1000.0d0)) then
tmp = 1.0d0 / x
else if (t_2 <= (-1d-300)) then
tmp = t_0
else if (t_2 <= 0.0d0) then
tmp = (1.0d0 + (1.0d0 / x)) + (-1.0d0)
else if (t_2 <= 1d-113) then
tmp = t_0
else
tmp = (1.0d0 / x) * (t_1 ** 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 = Math.exp(-y) / x;
double t_1 = x / (x + y);
double t_2 = Math.exp((x * Math.log(t_1))) / x;
double tmp;
if (t_2 <= -1000.0) {
tmp = 1.0 / x;
} else if (t_2 <= -1e-300) {
tmp = t_0;
} else if (t_2 <= 0.0) {
tmp = (1.0 + (1.0 / x)) + -1.0;
} else if (t_2 <= 1e-113) {
tmp = t_0;
} else {
tmp = (1.0 / x) * Math.pow(t_1, x);
}
return tmp;
}
def code(x, y): return math.exp((x * math.log((x / (x + y))))) / x
def code(x, y): t_0 = math.exp(-y) / x t_1 = x / (x + y) t_2 = math.exp((x * math.log(t_1))) / x tmp = 0 if t_2 <= -1000.0: tmp = 1.0 / x elif t_2 <= -1e-300: tmp = t_0 elif t_2 <= 0.0: tmp = (1.0 + (1.0 / x)) + -1.0 elif t_2 <= 1e-113: tmp = t_0 else: tmp = (1.0 / x) * math.pow(t_1, 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(exp(Float64(-y)) / x) t_1 = Float64(x / Float64(x + y)) t_2 = Float64(exp(Float64(x * log(t_1))) / x) tmp = 0.0 if (t_2 <= -1000.0) tmp = Float64(1.0 / x); elseif (t_2 <= -1e-300) tmp = t_0; elseif (t_2 <= 0.0) tmp = Float64(Float64(1.0 + Float64(1.0 / x)) + -1.0); elseif (t_2 <= 1e-113) tmp = t_0; else tmp = Float64(Float64(1.0 / x) * (t_1 ^ 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 = exp(-y) / x; t_1 = x / (x + y); t_2 = exp((x * log(t_1))) / x; tmp = 0.0; if (t_2 <= -1000.0) tmp = 1.0 / x; elseif (t_2 <= -1e-300) tmp = t_0; elseif (t_2 <= 0.0) tmp = (1.0 + (1.0 / x)) + -1.0; elseif (t_2 <= 1e-113) tmp = t_0; else tmp = (1.0 / x) * (t_1 ^ 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[(N[Exp[(-y)], $MachinePrecision] / x), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[N[(x * N[Log[t$95$1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]}, If[LessEqual[t$95$2, -1000.0], N[(1.0 / x), $MachinePrecision], If[LessEqual[t$95$2, -1e-300], t$95$0, If[LessEqual[t$95$2, 0.0], N[(N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[t$95$2, 1e-113], t$95$0, N[(N[(1.0 / x), $MachinePrecision] * N[Power[t$95$1, x], $MachinePrecision]), $MachinePrecision]]]]]]]]
\frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\begin{array}{l}
t_0 := \frac{e^{-y}}{x}\\
t_1 := \frac{x}{x + y}\\
t_2 := \frac{e^{x \cdot \log t_1}}{x}\\
\mathbf{if}\;t_2 \leq -1000:\\
\;\;\;\;\frac{1}{x}\\
\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-300}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\left(1 + \frac{1}{x}\right) + -1\\
\mathbf{elif}\;t_2 \leq 10^{-113}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} \cdot {t_1}^{x}\\
\end{array}
Results
| Original | 11.5 |
|---|---|
| Target | 7.9 |
| Herbie | 1.2 |
if (/.f64 (exp.f64 (*.f64 x (log.f64 (/.f64 x (+.f64 x y))))) x) < -1e3Initial program 12.8
Simplified12.8
Taylor expanded in x around 0 0.7
if -1e3 < (/.f64 (exp.f64 (*.f64 x (log.f64 (/.f64 x (+.f64 x y))))) x) < -1.00000000000000003e-300 or 0.0 < (/.f64 (exp.f64 (*.f64 x (log.f64 (/.f64 x (+.f64 x y))))) x) < 9.99999999999999979e-114Initial program 13.9
Simplified13.9
Taylor expanded in x around inf 0.1
Simplified0.1
if -1.00000000000000003e-300 < (/.f64 (exp.f64 (*.f64 x (log.f64 (/.f64 x (+.f64 x y))))) x) < 0.0Initial program 24.8
Simplified24.8
Taylor expanded in y around 0 60.0
Simplified60.0
Applied egg-rr63.0
Taylor expanded in y around 0 43.3
Applied egg-rr5.9
if 9.99999999999999979e-114 < (/.f64 (exp.f64 (*.f64 x (log.f64 (/.f64 x (+.f64 x y))))) x) Initial program 1.3
Simplified1.3
Applied egg-rr1.3
Final simplification1.2
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 6920 |
| Alternative 2 | |
|---|---|
| Error | 8.0 |
| Cost | 584 |
| Alternative 3 | |
|---|---|
| Error | 1.5 |
| Cost | 580 |
| Alternative 4 | |
|---|---|
| Error | 10.0 |
| Cost | 192 |

herbie shell --seed 2022300
(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))