
(FPCore (x y) :precision binary64 (/ (exp (* x (log (/ x (+ x y))))) x))
double code(double x, double y) {
return exp((x * log((x / (x + y))))) / x;
}
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
public static double code(double x, double y) {
return Math.exp((x * Math.log((x / (x + y))))) / x;
}
def code(x, y): return math.exp((x * math.log((x / (x + y))))) / x
function code(x, y) return Float64(exp(Float64(x * log(Float64(x / Float64(x + y))))) / x) end
function tmp = code(x, y) tmp = exp((x * log((x / (x + y))))) / x; end
code[x_, y_] := N[(N[Exp[N[(x * N[Log[N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (exp (* x (log (/ x (+ x y))))) x))
double code(double x, double y) {
return exp((x * log((x / (x + y))))) / x;
}
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
public static double code(double x, double y) {
return Math.exp((x * Math.log((x / (x + y))))) / x;
}
def code(x, y): return math.exp((x * math.log((x / (x + y))))) / x
function code(x, y) return Float64(exp(Float64(x * log(Float64(x / Float64(x + y))))) / x) end
function tmp = code(x, y) tmp = exp((x * log((x / (x + y))))) / x; end
code[x_, y_] := N[(N[Exp[N[(x * N[Log[N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= x -1e+25) (not (<= x 0.1))) (/ (exp (- y)) x) (/ (pow (exp x) (log (/ x (+ x y)))) x)))
double code(double x, double y) {
double tmp;
if ((x <= -1e+25) || !(x <= 0.1)) {
tmp = exp(-y) / x;
} else {
tmp = pow(exp(x), log((x / (x + y)))) / x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1d+25)) .or. (.not. (x <= 0.1d0))) then
tmp = exp(-y) / x
else
tmp = (exp(x) ** log((x / (x + y)))) / x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1e+25) || !(x <= 0.1)) {
tmp = Math.exp(-y) / x;
} else {
tmp = Math.pow(Math.exp(x), Math.log((x / (x + y)))) / x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1e+25) or not (x <= 0.1): tmp = math.exp(-y) / x else: tmp = math.pow(math.exp(x), math.log((x / (x + y)))) / x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1e+25) || !(x <= 0.1)) tmp = Float64(exp(Float64(-y)) / x); else tmp = Float64((exp(x) ^ log(Float64(x / Float64(x + y)))) / x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1e+25) || ~((x <= 0.1))) tmp = exp(-y) / x; else tmp = (exp(x) ^ log((x / (x + y)))) / x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1e+25], N[Not[LessEqual[x, 0.1]], $MachinePrecision]], N[(N[Exp[(-y)], $MachinePrecision] / x), $MachinePrecision], N[(N[Power[N[Exp[x], $MachinePrecision], N[Log[N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+25} \lor \neg \left(x \leq 0.1\right):\\
\;\;\;\;\frac{e^{-y}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{{\left(e^{x}\right)}^{\log \left(\frac{x}{x + y}\right)}}{x}\\
\end{array}
\end{array}
if x < -1.00000000000000009e25 or 0.10000000000000001 < x Initial program 72.1%
*-commutative72.1%
exp-to-pow72.1%
Simplified72.1%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
Simplified100.0%
if -1.00000000000000009e25 < x < 0.10000000000000001Initial program 89.9%
exp-prod99.6%
Simplified99.6%
Final simplification99.8%
(FPCore (x y) :precision binary64 (if (or (<= x -0.72) (not (<= x 1.65))) (/ (exp (- y)) x) (/ 1.0 x)))
double code(double x, double y) {
double tmp;
if ((x <= -0.72) || !(x <= 1.65)) {
tmp = exp(-y) / x;
} else {
tmp = 1.0 / x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-0.72d0)) .or. (.not. (x <= 1.65d0))) then
tmp = exp(-y) / x
else
tmp = 1.0d0 / x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -0.72) || !(x <= 1.65)) {
tmp = Math.exp(-y) / x;
} else {
tmp = 1.0 / x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -0.72) or not (x <= 1.65): tmp = math.exp(-y) / x else: tmp = 1.0 / x return tmp
function code(x, y) tmp = 0.0 if ((x <= -0.72) || !(x <= 1.65)) tmp = Float64(exp(Float64(-y)) / x); else tmp = Float64(1.0 / x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -0.72) || ~((x <= 1.65))) tmp = exp(-y) / x; else tmp = 1.0 / x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -0.72], N[Not[LessEqual[x, 1.65]], $MachinePrecision]], N[(N[Exp[(-y)], $MachinePrecision] / x), $MachinePrecision], N[(1.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.72 \lor \neg \left(x \leq 1.65\right):\\
\;\;\;\;\frac{e^{-y}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x}\\
\end{array}
\end{array}
if x < -0.71999999999999997 or 1.6499999999999999 < x Initial program 73.7%
*-commutative73.7%
exp-to-pow73.8%
Simplified73.8%
Taylor expanded in x around inf 99.4%
mul-1-neg99.4%
Simplified99.4%
if -0.71999999999999997 < x < 1.6499999999999999Initial program 89.1%
exp-prod99.7%
Simplified99.7%
Taylor expanded in x around 0 98.6%
Final simplification99.0%
(FPCore (x y) :precision binary64 (if (or (<= x -5.5e+26) (not (<= x 1.6e+73))) (/ (/ 1.0 x) (+ y 1.0)) (/ 1.0 x)))
double code(double x, double y) {
double tmp;
if ((x <= -5.5e+26) || !(x <= 1.6e+73)) {
tmp = (1.0 / x) / (y + 1.0);
} else {
tmp = 1.0 / x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-5.5d+26)) .or. (.not. (x <= 1.6d+73))) then
tmp = (1.0d0 / x) / (y + 1.0d0)
else
tmp = 1.0d0 / x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -5.5e+26) || !(x <= 1.6e+73)) {
tmp = (1.0 / x) / (y + 1.0);
} else {
tmp = 1.0 / x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5.5e+26) or not (x <= 1.6e+73): tmp = (1.0 / x) / (y + 1.0) else: tmp = 1.0 / x return tmp
function code(x, y) tmp = 0.0 if ((x <= -5.5e+26) || !(x <= 1.6e+73)) tmp = Float64(Float64(1.0 / x) / Float64(y + 1.0)); else tmp = Float64(1.0 / x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -5.5e+26) || ~((x <= 1.6e+73))) tmp = (1.0 / x) / (y + 1.0); else tmp = 1.0 / x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5.5e+26], N[Not[LessEqual[x, 1.6e+73]], $MachinePrecision]], N[(N[(1.0 / x), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+26} \lor \neg \left(x \leq 1.6 \cdot 10^{+73}\right):\\
\;\;\;\;\frac{\frac{1}{x}}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x}\\
\end{array}
\end{array}
if x < -5.4999999999999997e26 or 1.59999999999999991e73 < x Initial program 69.1%
exp-prod69.1%
Simplified69.1%
clear-num69.1%
inv-pow69.1%
add-exp-log32.5%
add-exp-log32.5%
div-exp32.5%
pow-exp32.5%
add-log-exp32.5%
log-pow32.5%
div-exp32.5%
add-exp-log69.1%
add-exp-log69.1%
Applied egg-rr69.1%
div-inv69.1%
unpow-prod-down69.1%
inv-pow69.1%
pow-flip69.1%
Applied egg-rr69.1%
associate-*l/69.1%
*-lft-identity69.1%
unpow-169.1%
associate-/r*69.1%
associate-/l/69.1%
Simplified69.1%
Taylor expanded in y around 0 66.6%
if -5.4999999999999997e26 < x < 1.59999999999999991e73Initial program 91.0%
exp-prod99.6%
Simplified99.6%
Taylor expanded in x around 0 95.8%
Final simplification81.3%
(FPCore (x y) :precision binary64 (if (<= y 6.5e+108) (/ 1.0 x) (/ 1.0 (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 6.5e+108) {
tmp = 1.0 / x;
} else {
tmp = 1.0 / (x * y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 6.5d+108) then
tmp = 1.0d0 / x
else
tmp = 1.0d0 / (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6.5e+108) {
tmp = 1.0 / x;
} else {
tmp = 1.0 / (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6.5e+108: tmp = 1.0 / x else: tmp = 1.0 / (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 6.5e+108) tmp = Float64(1.0 / x); else tmp = Float64(1.0 / Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6.5e+108) tmp = 1.0 / x; else tmp = 1.0 / (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6.5e+108], N[(1.0 / x), $MachinePrecision], N[(1.0 / N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.5 \cdot 10^{+108}:\\
\;\;\;\;\frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot y}\\
\end{array}
\end{array}
if y < 6.4999999999999996e108Initial program 83.6%
exp-prod86.0%
Simplified86.0%
Taylor expanded in x around 0 79.1%
if 6.4999999999999996e108 < y Initial program 55.8%
exp-prod73.8%
Simplified73.8%
clear-num73.8%
inv-pow73.8%
add-exp-log67.1%
add-exp-log67.1%
div-exp67.1%
pow-exp50.7%
add-log-exp50.7%
log-pow50.7%
div-exp50.7%
add-exp-log55.8%
add-exp-log55.8%
Applied egg-rr55.8%
div-inv55.7%
unpow-prod-down55.7%
inv-pow55.7%
pow-flip55.7%
Applied egg-rr55.7%
associate-*l/55.7%
*-lft-identity55.7%
unpow-155.7%
associate-/r*55.7%
associate-/l/55.7%
Simplified55.7%
Taylor expanded in y around 0 58.3%
Taylor expanded in y around inf 58.3%
Final simplification76.5%
(FPCore (x y) :precision binary64 (/ 1.0 x))
double code(double x, double y) {
return 1.0 / x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 / x
end function
public static double code(double x, double y) {
return 1.0 / x;
}
def code(x, y): return 1.0 / x
function code(x, y) return Float64(1.0 / x) end
function tmp = code(x, y) tmp = 1.0 / x; end
code[x_, y_] := N[(1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x}
\end{array}
Initial program 80.1%
exp-prod84.5%
Simplified84.5%
Taylor expanded in x around 0 73.5%
Final simplification73.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (exp (/ -1.0 y)) x)) (t_1 (/ (pow (/ x (+ y x)) x) x)))
(if (< y -3.7311844206647956e+94)
t_0
(if (< y 2.817959242728288e+37)
t_1
(if (< y 2.347387415166998e+178) (log (exp t_1)) t_0)))))
double code(double x, double y) {
double t_0 = exp((-1.0 / y)) / x;
double t_1 = pow((x / (y + x)), x) / x;
double tmp;
if (y < -3.7311844206647956e+94) {
tmp = t_0;
} else if (y < 2.817959242728288e+37) {
tmp = t_1;
} else if (y < 2.347387415166998e+178) {
tmp = log(exp(t_1));
} else {
tmp = t_0;
}
return tmp;
}
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) :: tmp
t_0 = exp(((-1.0d0) / y)) / x
t_1 = ((x / (y + x)) ** x) / x
if (y < (-3.7311844206647956d+94)) then
tmp = t_0
else if (y < 2.817959242728288d+37) then
tmp = t_1
else if (y < 2.347387415166998d+178) then
tmp = log(exp(t_1))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = Math.exp((-1.0 / y)) / x;
double t_1 = Math.pow((x / (y + x)), x) / x;
double tmp;
if (y < -3.7311844206647956e+94) {
tmp = t_0;
} else if (y < 2.817959242728288e+37) {
tmp = t_1;
} else if (y < 2.347387415166998e+178) {
tmp = Math.log(Math.exp(t_1));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = math.exp((-1.0 / y)) / x t_1 = math.pow((x / (y + x)), x) / x tmp = 0 if y < -3.7311844206647956e+94: tmp = t_0 elif y < 2.817959242728288e+37: tmp = t_1 elif y < 2.347387415166998e+178: tmp = math.log(math.exp(t_1)) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(exp(Float64(-1.0 / y)) / x) t_1 = Float64((Float64(x / Float64(y + x)) ^ x) / x) tmp = 0.0 if (y < -3.7311844206647956e+94) tmp = t_0; elseif (y < 2.817959242728288e+37) tmp = t_1; elseif (y < 2.347387415166998e+178) tmp = log(exp(t_1)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = exp((-1.0 / y)) / x; t_1 = ((x / (y + x)) ^ x) / x; tmp = 0.0; if (y < -3.7311844206647956e+94) tmp = t_0; elseif (y < 2.817959242728288e+37) tmp = t_1; elseif (y < 2.347387415166998e+178) tmp = log(exp(t_1)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Exp[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision], x], $MachinePrecision] / x), $MachinePrecision]}, If[Less[y, -3.7311844206647956e+94], t$95$0, If[Less[y, 2.817959242728288e+37], t$95$1, If[Less[y, 2.347387415166998e+178], N[Log[N[Exp[t$95$1], $MachinePrecision]], $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{e^{\frac{-1}{y}}}{x}\\
t_1 := \frac{{\left(\frac{x}{y + x}\right)}^{x}}{x}\\
\mathbf{if}\;y < -3.7311844206647956 \cdot 10^{+94}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y < 2.817959242728288 \cdot 10^{+37}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y < 2.347387415166998 \cdot 10^{+178}:\\
\;\;\;\;\log \left(e^{t_1}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
herbie shell --seed 2024018
(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))