
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
double code(double x, double y) {
return 1.0 - log((1.0 - ((x - y) / (1.0 - y))));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - log((1.0d0 - ((x - y) / (1.0d0 - y))))
end function
public static double code(double x, double y) {
return 1.0 - Math.log((1.0 - ((x - y) / (1.0 - y))));
}
def code(x, y): return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
function code(x, y) return Float64(1.0 - log(Float64(1.0 - Float64(Float64(x - y) / Float64(1.0 - y))))) end
function tmp = code(x, y) tmp = 1.0 - log((1.0 - ((x - y) / (1.0 - y)))); end
code[x_, y_] := N[(1.0 - N[Log[N[(1.0 - N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
double code(double x, double y) {
return 1.0 - log((1.0 - ((x - y) / (1.0 - y))));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - log((1.0d0 - ((x - y) / (1.0d0 - y))))
end function
public static double code(double x, double y) {
return 1.0 - Math.log((1.0 - ((x - y) / (1.0 - y))));
}
def code(x, y): return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
function code(x, y) return Float64(1.0 - log(Float64(1.0 - Float64(Float64(x - y) / Float64(1.0 - y))))) end
function tmp = code(x, y) tmp = 1.0 - log((1.0 - ((x - y) / (1.0 - y)))); end
code[x_, y_] := N[(1.0 - N[Log[N[(1.0 - N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\end{array}
(FPCore (x y)
:precision binary64
(if (<= y -420000.0)
(+ (- 1.0 (log1p (- x))) (- (/ -1.0 y) (log (/ -1.0 y))))
(if (<= y 1.45e+28)
(- 1.0 (log1p (/ (- y x) (- 1.0 y))))
(- 1.0 (- (log x) (log y))))))
double code(double x, double y) {
double tmp;
if (y <= -420000.0) {
tmp = (1.0 - log1p(-x)) + ((-1.0 / y) - log((-1.0 / y)));
} else if (y <= 1.45e+28) {
tmp = 1.0 - log1p(((y - x) / (1.0 - y)));
} else {
tmp = 1.0 - (log(x) - log(y));
}
return tmp;
}
public static double code(double x, double y) {
double tmp;
if (y <= -420000.0) {
tmp = (1.0 - Math.log1p(-x)) + ((-1.0 / y) - Math.log((-1.0 / y)));
} else if (y <= 1.45e+28) {
tmp = 1.0 - Math.log1p(((y - x) / (1.0 - y)));
} else {
tmp = 1.0 - (Math.log(x) - Math.log(y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -420000.0: tmp = (1.0 - math.log1p(-x)) + ((-1.0 / y) - math.log((-1.0 / y))) elif y <= 1.45e+28: tmp = 1.0 - math.log1p(((y - x) / (1.0 - y))) else: tmp = 1.0 - (math.log(x) - math.log(y)) return tmp
function code(x, y) tmp = 0.0 if (y <= -420000.0) tmp = Float64(Float64(1.0 - log1p(Float64(-x))) + Float64(Float64(-1.0 / y) - log(Float64(-1.0 / y)))); elseif (y <= 1.45e+28) tmp = Float64(1.0 - log1p(Float64(Float64(y - x) / Float64(1.0 - y)))); else tmp = Float64(1.0 - Float64(log(x) - log(y))); end return tmp end
code[x_, y_] := If[LessEqual[y, -420000.0], N[(N[(1.0 - N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 / y), $MachinePrecision] - N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.45e+28], N[(1.0 - N[Log[1 + N[(N[(y - x), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -420000:\\
\;\;\;\;\left(1 - \mathsf{log1p}\left(-x\right)\right) + \left(\frac{-1}{y} - \log \left(\frac{-1}{y}\right)\right)\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+28}:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \left(\log x - \log y\right)\\
\end{array}
\end{array}
if y < -4.2e5Initial program 19.7%
sub-neg19.7%
log1p-def19.7%
distribute-neg-frac19.7%
sub-neg19.7%
distribute-neg-in19.7%
remove-double-neg19.7%
+-commutative19.7%
sub-neg19.7%
Simplified19.7%
flip--18.7%
associate-/r/19.8%
metadata-eval19.8%
+-commutative19.8%
Applied egg-rr19.8%
Taylor expanded in y around -inf 99.4%
associate--r+99.4%
log1p-def99.4%
mul-1-neg99.4%
+-commutative99.4%
Simplified99.4%
if -4.2e5 < y < 1.4500000000000001e28Initial program 100.0%
sub-neg100.0%
log1p-def100.0%
distribute-neg-frac100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
if 1.4500000000000001e28 < y Initial program 57.9%
sub-neg57.9%
log1p-def57.9%
distribute-neg-frac57.9%
sub-neg57.9%
distribute-neg-in57.9%
remove-double-neg57.9%
+-commutative57.9%
sub-neg57.9%
Simplified57.9%
Taylor expanded in y around inf 58.0%
Taylor expanded in x around inf 98.6%
+-commutative98.6%
log-rec98.6%
unsub-neg98.6%
mul-1-neg98.6%
log-rec98.6%
remove-double-neg98.6%
Simplified98.6%
Final simplification99.7%
(FPCore (x y)
:precision binary64
(if (<= y -1600000000.0)
(- (- 1.0 (log1p (- x))) (log (/ -1.0 y)))
(if (<= y 2.3e+21)
(- 1.0 (log1p (/ (- y x) (- 1.0 y))))
(- 1.0 (- (log x) (log y))))))
double code(double x, double y) {
double tmp;
if (y <= -1600000000.0) {
tmp = (1.0 - log1p(-x)) - log((-1.0 / y));
} else if (y <= 2.3e+21) {
tmp = 1.0 - log1p(((y - x) / (1.0 - y)));
} else {
tmp = 1.0 - (log(x) - log(y));
}
return tmp;
}
public static double code(double x, double y) {
double tmp;
if (y <= -1600000000.0) {
tmp = (1.0 - Math.log1p(-x)) - Math.log((-1.0 / y));
} else if (y <= 2.3e+21) {
tmp = 1.0 - Math.log1p(((y - x) / (1.0 - y)));
} else {
tmp = 1.0 - (Math.log(x) - Math.log(y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1600000000.0: tmp = (1.0 - math.log1p(-x)) - math.log((-1.0 / y)) elif y <= 2.3e+21: tmp = 1.0 - math.log1p(((y - x) / (1.0 - y))) else: tmp = 1.0 - (math.log(x) - math.log(y)) return tmp
function code(x, y) tmp = 0.0 if (y <= -1600000000.0) tmp = Float64(Float64(1.0 - log1p(Float64(-x))) - log(Float64(-1.0 / y))); elseif (y <= 2.3e+21) tmp = Float64(1.0 - log1p(Float64(Float64(y - x) / Float64(1.0 - y)))); else tmp = Float64(1.0 - Float64(log(x) - log(y))); end return tmp end
code[x_, y_] := If[LessEqual[y, -1600000000.0], N[(N[(1.0 - N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision] - N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.3e+21], N[(1.0 - N[Log[1 + N[(N[(y - x), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1600000000:\\
\;\;\;\;\left(1 - \mathsf{log1p}\left(-x\right)\right) - \log \left(\frac{-1}{y}\right)\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+21}:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \left(\log x - \log y\right)\\
\end{array}
\end{array}
if y < -1.6e9Initial program 19.7%
sub-neg19.7%
log1p-def19.7%
distribute-neg-frac19.7%
sub-neg19.7%
distribute-neg-in19.7%
remove-double-neg19.7%
+-commutative19.7%
sub-neg19.7%
Simplified19.7%
Taylor expanded in y around -inf 99.2%
associate--r+99.2%
sub-neg99.2%
metadata-eval99.2%
distribute-lft-in99.2%
metadata-eval99.2%
+-commutative99.2%
log1p-def99.2%
mul-1-neg99.2%
Simplified99.2%
if -1.6e9 < y < 2.3e21Initial program 100.0%
sub-neg100.0%
log1p-def100.0%
distribute-neg-frac100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
if 2.3e21 < y Initial program 57.9%
sub-neg57.9%
log1p-def57.9%
distribute-neg-frac57.9%
sub-neg57.9%
distribute-neg-in57.9%
remove-double-neg57.9%
+-commutative57.9%
sub-neg57.9%
Simplified57.9%
Taylor expanded in y around inf 58.0%
Taylor expanded in x around inf 98.6%
+-commutative98.6%
log-rec98.6%
unsub-neg98.6%
mul-1-neg98.6%
log-rec98.6%
remove-double-neg98.6%
Simplified98.6%
Final simplification99.6%
(FPCore (x y) :precision binary64 (if (<= (+ 1.0 (/ (- y x) (- 1.0 y))) 0.0) (- 1.0 (log (/ -1.0 y))) (- 1.0 (log1p (* (- y x) (/ 1.0 (- 1.0 y)))))))
double code(double x, double y) {
double tmp;
if ((1.0 + ((y - x) / (1.0 - y))) <= 0.0) {
tmp = 1.0 - log((-1.0 / y));
} else {
tmp = 1.0 - log1p(((y - x) * (1.0 / (1.0 - y))));
}
return tmp;
}
public static double code(double x, double y) {
double tmp;
if ((1.0 + ((y - x) / (1.0 - y))) <= 0.0) {
tmp = 1.0 - Math.log((-1.0 / y));
} else {
tmp = 1.0 - Math.log1p(((y - x) * (1.0 / (1.0 - y))));
}
return tmp;
}
def code(x, y): tmp = 0 if (1.0 + ((y - x) / (1.0 - y))) <= 0.0: tmp = 1.0 - math.log((-1.0 / y)) else: tmp = 1.0 - math.log1p(((y - x) * (1.0 / (1.0 - y)))) return tmp
function code(x, y) tmp = 0.0 if (Float64(1.0 + Float64(Float64(y - x) / Float64(1.0 - y))) <= 0.0) tmp = Float64(1.0 - log(Float64(-1.0 / y))); else tmp = Float64(1.0 - log1p(Float64(Float64(y - x) * Float64(1.0 / Float64(1.0 - y))))); end return tmp end
code[x_, y_] := If[LessEqual[N[(1.0 + N[(N[(y - x), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(1.0 - N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Log[1 + N[(N[(y - x), $MachinePrecision] * N[(1.0 / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 + \frac{y - x}{1 - y} \leq 0:\\
\;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \mathsf{log1p}\left(\left(y - x\right) \cdot \frac{1}{1 - y}\right)\\
\end{array}
\end{array}
if (-.f64 1 (/.f64 (-.f64 x y) (-.f64 1 y))) < 0.0Initial program 3.1%
sub-neg3.1%
log1p-def3.1%
distribute-neg-frac3.1%
sub-neg3.1%
distribute-neg-in3.1%
remove-double-neg3.1%
+-commutative3.1%
sub-neg3.1%
Simplified3.1%
Taylor expanded in y around inf 3.1%
Taylor expanded in x around 0 73.5%
distribute-neg-frac73.5%
metadata-eval73.5%
Simplified73.5%
if 0.0 < (-.f64 1 (/.f64 (-.f64 x y) (-.f64 1 y))) Initial program 98.7%
sub-neg98.7%
log1p-def98.7%
distribute-neg-frac98.7%
sub-neg98.7%
distribute-neg-in98.7%
remove-double-neg98.7%
+-commutative98.7%
sub-neg98.7%
Simplified98.7%
clear-num98.8%
associate-/r/98.8%
Applied egg-rr98.8%
Final simplification91.6%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (- y x) (- 1.0 y)))) (if (<= (+ 1.0 t_0) 0.0) (- 1.0 (log (/ -1.0 y))) (- 1.0 (log1p t_0)))))
double code(double x, double y) {
double t_0 = (y - x) / (1.0 - y);
double tmp;
if ((1.0 + t_0) <= 0.0) {
tmp = 1.0 - log((-1.0 / y));
} else {
tmp = 1.0 - log1p(t_0);
}
return tmp;
}
public static double code(double x, double y) {
double t_0 = (y - x) / (1.0 - y);
double tmp;
if ((1.0 + t_0) <= 0.0) {
tmp = 1.0 - Math.log((-1.0 / y));
} else {
tmp = 1.0 - Math.log1p(t_0);
}
return tmp;
}
def code(x, y): t_0 = (y - x) / (1.0 - y) tmp = 0 if (1.0 + t_0) <= 0.0: tmp = 1.0 - math.log((-1.0 / y)) else: tmp = 1.0 - math.log1p(t_0) return tmp
function code(x, y) t_0 = Float64(Float64(y - x) / Float64(1.0 - y)) tmp = 0.0 if (Float64(1.0 + t_0) <= 0.0) tmp = Float64(1.0 - log(Float64(-1.0 / y))); else tmp = Float64(1.0 - log1p(t_0)); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 + t$95$0), $MachinePrecision], 0.0], N[(1.0 - N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Log[1 + t$95$0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y - x}{1 - y}\\
\mathbf{if}\;1 + t_0 \leq 0:\\
\;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \mathsf{log1p}\left(t_0\right)\\
\end{array}
\end{array}
if (-.f64 1 (/.f64 (-.f64 x y) (-.f64 1 y))) < 0.0Initial program 3.1%
sub-neg3.1%
log1p-def3.1%
distribute-neg-frac3.1%
sub-neg3.1%
distribute-neg-in3.1%
remove-double-neg3.1%
+-commutative3.1%
sub-neg3.1%
Simplified3.1%
Taylor expanded in y around inf 3.1%
Taylor expanded in x around 0 73.5%
distribute-neg-frac73.5%
metadata-eval73.5%
Simplified73.5%
if 0.0 < (-.f64 1 (/.f64 (-.f64 x y) (-.f64 1 y))) Initial program 98.7%
sub-neg98.7%
log1p-def98.7%
distribute-neg-frac98.7%
sub-neg98.7%
distribute-neg-in98.7%
remove-double-neg98.7%
+-commutative98.7%
sub-neg98.7%
Simplified98.7%
Final simplification91.6%
(FPCore (x y) :precision binary64 (if (<= y -30000.0) (- 1.0 (log (/ -1.0 y))) (- 1.0 (log1p (/ (- x) (- 1.0 y))))))
double code(double x, double y) {
double tmp;
if (y <= -30000.0) {
tmp = 1.0 - log((-1.0 / y));
} else {
tmp = 1.0 - log1p((-x / (1.0 - y)));
}
return tmp;
}
public static double code(double x, double y) {
double tmp;
if (y <= -30000.0) {
tmp = 1.0 - Math.log((-1.0 / y));
} else {
tmp = 1.0 - Math.log1p((-x / (1.0 - y)));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -30000.0: tmp = 1.0 - math.log((-1.0 / y)) else: tmp = 1.0 - math.log1p((-x / (1.0 - y))) return tmp
function code(x, y) tmp = 0.0 if (y <= -30000.0) tmp = Float64(1.0 - log(Float64(-1.0 / y))); else tmp = Float64(1.0 - log1p(Float64(Float64(-x) / Float64(1.0 - y)))); end return tmp end
code[x_, y_] := If[LessEqual[y, -30000.0], N[(1.0 - N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Log[1 + N[((-x) / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -30000:\\
\;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{-x}{1 - y}\right)\\
\end{array}
\end{array}
if y < -3e4Initial program 19.7%
sub-neg19.7%
log1p-def19.7%
distribute-neg-frac19.7%
sub-neg19.7%
distribute-neg-in19.7%
remove-double-neg19.7%
+-commutative19.7%
sub-neg19.7%
Simplified19.7%
Taylor expanded in y around inf 19.7%
Taylor expanded in x around 0 72.2%
distribute-neg-frac72.2%
metadata-eval72.2%
Simplified72.2%
if -3e4 < y Initial program 93.5%
sub-neg93.5%
log1p-def93.5%
distribute-neg-frac93.5%
sub-neg93.5%
distribute-neg-in93.5%
remove-double-neg93.5%
+-commutative93.5%
sub-neg93.5%
Simplified93.5%
Taylor expanded in x around inf 92.0%
neg-mul-192.0%
distribute-neg-frac92.0%
Simplified92.0%
Final simplification86.2%
(FPCore (x y) :precision binary64 (if (<= y -6.5) (- 1.0 (log (/ -1.0 y))) (- 1.0 (+ y (log1p (- x))))))
double code(double x, double y) {
double tmp;
if (y <= -6.5) {
tmp = 1.0 - log((-1.0 / y));
} else {
tmp = 1.0 - (y + log1p(-x));
}
return tmp;
}
public static double code(double x, double y) {
double tmp;
if (y <= -6.5) {
tmp = 1.0 - Math.log((-1.0 / y));
} else {
tmp = 1.0 - (y + Math.log1p(-x));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.5: tmp = 1.0 - math.log((-1.0 / y)) else: tmp = 1.0 - (y + math.log1p(-x)) return tmp
function code(x, y) tmp = 0.0 if (y <= -6.5) tmp = Float64(1.0 - log(Float64(-1.0 / y))); else tmp = Float64(1.0 - Float64(y + log1p(Float64(-x)))); end return tmp end
code[x_, y_] := If[LessEqual[y, -6.5], N[(1.0 - N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(y + N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5:\\
\;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \left(y + \mathsf{log1p}\left(-x\right)\right)\\
\end{array}
\end{array}
if y < -6.5Initial program 19.7%
sub-neg19.7%
log1p-def19.7%
distribute-neg-frac19.7%
sub-neg19.7%
distribute-neg-in19.7%
remove-double-neg19.7%
+-commutative19.7%
sub-neg19.7%
Simplified19.7%
Taylor expanded in y around inf 19.7%
Taylor expanded in x around 0 72.2%
distribute-neg-frac72.2%
metadata-eval72.2%
Simplified72.2%
if -6.5 < y Initial program 93.5%
sub-neg93.5%
log1p-def93.5%
distribute-neg-frac93.5%
sub-neg93.5%
distribute-neg-in93.5%
remove-double-neg93.5%
+-commutative93.5%
sub-neg93.5%
Simplified93.5%
Taylor expanded in y around 0 82.6%
+-commutative82.6%
div-sub82.6%
mul-1-neg82.6%
sub-neg82.6%
*-inverses82.6%
*-rgt-identity82.6%
log1p-def82.6%
mul-1-neg82.6%
Simplified82.6%
Final simplification79.5%
(FPCore (x y) :precision binary64 (if (<= y -270.0) (- 1.0 (log (/ -1.0 y))) (- 1.0 (log1p (- x)))))
double code(double x, double y) {
double tmp;
if (y <= -270.0) {
tmp = 1.0 - log((-1.0 / y));
} else {
tmp = 1.0 - log1p(-x);
}
return tmp;
}
public static double code(double x, double y) {
double tmp;
if (y <= -270.0) {
tmp = 1.0 - Math.log((-1.0 / y));
} else {
tmp = 1.0 - Math.log1p(-x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -270.0: tmp = 1.0 - math.log((-1.0 / y)) else: tmp = 1.0 - math.log1p(-x) return tmp
function code(x, y) tmp = 0.0 if (y <= -270.0) tmp = Float64(1.0 - log(Float64(-1.0 / y))); else tmp = Float64(1.0 - log1p(Float64(-x))); end return tmp end
code[x_, y_] := If[LessEqual[y, -270.0], N[(1.0 - N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -270:\\
\;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\
\end{array}
\end{array}
if y < -270Initial program 19.7%
sub-neg19.7%
log1p-def19.7%
distribute-neg-frac19.7%
sub-neg19.7%
distribute-neg-in19.7%
remove-double-neg19.7%
+-commutative19.7%
sub-neg19.7%
Simplified19.7%
Taylor expanded in y around inf 19.7%
Taylor expanded in x around 0 72.2%
distribute-neg-frac72.2%
metadata-eval72.2%
Simplified72.2%
if -270 < y Initial program 93.5%
sub-neg93.5%
log1p-def93.5%
distribute-neg-frac93.5%
sub-neg93.5%
distribute-neg-in93.5%
remove-double-neg93.5%
+-commutative93.5%
sub-neg93.5%
Simplified93.5%
Taylor expanded in y around 0 81.9%
log1p-def81.9%
mul-1-neg81.9%
Simplified81.9%
Final simplification79.1%
(FPCore (x y) :precision binary64 (- 1.0 (log1p (- x))))
double code(double x, double y) {
return 1.0 - log1p(-x);
}
public static double code(double x, double y) {
return 1.0 - Math.log1p(-x);
}
def code(x, y): return 1.0 - math.log1p(-x)
function code(x, y) return Float64(1.0 - log1p(Float64(-x))) end
code[x_, y_] := N[(1.0 - N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \mathsf{log1p}\left(-x\right)
\end{array}
Initial program 71.8%
sub-neg71.8%
log1p-def71.9%
distribute-neg-frac71.9%
sub-neg71.9%
distribute-neg-in71.9%
remove-double-neg71.9%
+-commutative71.9%
sub-neg71.9%
Simplified71.9%
Taylor expanded in y around 0 61.7%
log1p-def61.7%
mul-1-neg61.7%
Simplified61.7%
Final simplification61.7%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 71.8%
sub-neg71.8%
log1p-def71.9%
distribute-neg-frac71.9%
sub-neg71.9%
distribute-neg-in71.9%
remove-double-neg71.9%
+-commutative71.9%
sub-neg71.9%
Simplified71.9%
Taylor expanded in x around inf 72.6%
neg-mul-172.6%
distribute-neg-frac72.6%
Simplified72.6%
Taylor expanded in x around 0 42.5%
Final simplification42.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (log (- (/ x (* y y)) (- (/ 1.0 y) (/ x y)))))))
(if (< y -81284752.61947241)
t_0
(if (< y 3.0094271212461764e+25)
(log (/ (exp 1.0) (- 1.0 (/ (- x y) (- 1.0 y)))))
t_0))))
double code(double x, double y) {
double t_0 = 1.0 - log(((x / (y * y)) - ((1.0 / y) - (x / y))));
double tmp;
if (y < -81284752.61947241) {
tmp = t_0;
} else if (y < 3.0094271212461764e+25) {
tmp = log((exp(1.0) / (1.0 - ((x - y) / (1.0 - y)))));
} 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) :: tmp
t_0 = 1.0d0 - log(((x / (y * y)) - ((1.0d0 / y) - (x / y))))
if (y < (-81284752.61947241d0)) then
tmp = t_0
else if (y < 3.0094271212461764d+25) then
tmp = log((exp(1.0d0) / (1.0d0 - ((x - y) / (1.0d0 - y)))))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 - Math.log(((x / (y * y)) - ((1.0 / y) - (x / y))));
double tmp;
if (y < -81284752.61947241) {
tmp = t_0;
} else if (y < 3.0094271212461764e+25) {
tmp = Math.log((Math.exp(1.0) / (1.0 - ((x - y) / (1.0 - y)))));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - math.log(((x / (y * y)) - ((1.0 / y) - (x / y)))) tmp = 0 if y < -81284752.61947241: tmp = t_0 elif y < 3.0094271212461764e+25: tmp = math.log((math.exp(1.0) / (1.0 - ((x - y) / (1.0 - y))))) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - log(Float64(Float64(x / Float64(y * y)) - Float64(Float64(1.0 / y) - Float64(x / y))))) tmp = 0.0 if (y < -81284752.61947241) tmp = t_0; elseif (y < 3.0094271212461764e+25) tmp = log(Float64(exp(1.0) / Float64(1.0 - Float64(Float64(x - y) / Float64(1.0 - y))))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - log(((x / (y * y)) - ((1.0 / y) - (x / y)))); tmp = 0.0; if (y < -81284752.61947241) tmp = t_0; elseif (y < 3.0094271212461764e+25) tmp = log((exp(1.0) / (1.0 - ((x - y) / (1.0 - y))))); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[Log[N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 / y), $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Less[y, -81284752.61947241], t$95$0, If[Less[y, 3.0094271212461764e+25], N[Log[N[(N[Exp[1.0], $MachinePrecision] / N[(1.0 - N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \log \left(\frac{x}{y \cdot y} - \left(\frac{1}{y} - \frac{x}{y}\right)\right)\\
\mathbf{if}\;y < -81284752.61947241:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y < 3.0094271212461764 \cdot 10^{+25}:\\
\;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
herbie shell --seed 2023275
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, B"
:precision binary64
:herbie-target
(if (< y -81284752.61947241) (- 1.0 (log (- (/ x (* y y)) (- (/ 1.0 y) (/ x y))))) (if (< y 3.0094271212461764e+25) (log (/ (exp 1.0) (- 1.0 (/ (- x y) (- 1.0 y))))) (- 1.0 (log (- (/ x (* y y)) (- (/ 1.0 y) (/ x y)))))))
(- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))