| Alternative 1 | |
|---|---|
| Error | 11.5 |
| Cost | 20424 |
\[\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;-z\\
\mathbf{elif}\;t_0 \leq \infty:\\
\;\;\;\;t_0 - z\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
(FPCore (x y z) :precision binary64 (if (<= y -5e-309) (- (* x (+ (log (/ -1.0 y)) (log (- x)))) z) (- (* (- (log x) (log y)) x) z)))
double code(double x, double y, double z) {
return (x * log((x / y))) - z;
}
double code(double x, double y, double z) {
double tmp;
if (y <= -5e-309) {
tmp = (x * (log((-1.0 / y)) + log(-x))) - z;
} else {
tmp = ((log(x) - log(y)) * x) - z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * log((x / y))) - z
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-5d-309)) then
tmp = (x * (log(((-1.0d0) / y)) + log(-x))) - z
else
tmp = ((log(x) - log(y)) * x) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return (x * Math.log((x / y))) - z;
}
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5e-309) {
tmp = (x * (Math.log((-1.0 / y)) + Math.log(-x))) - z;
} else {
tmp = ((Math.log(x) - Math.log(y)) * x) - z;
}
return tmp;
}
def code(x, y, z): return (x * math.log((x / y))) - z
def code(x, y, z): tmp = 0 if y <= -5e-309: tmp = (x * (math.log((-1.0 / y)) + math.log(-x))) - z else: tmp = ((math.log(x) - math.log(y)) * x) - z return tmp
function code(x, y, z) return Float64(Float64(x * log(Float64(x / y))) - z) end
function code(x, y, z) tmp = 0.0 if (y <= -5e-309) tmp = Float64(Float64(x * Float64(log(Float64(-1.0 / y)) + log(Float64(-x)))) - z); else tmp = Float64(Float64(Float64(log(x) - log(y)) * x) - z); end return tmp end
function tmp = code(x, y, z) tmp = (x * log((x / y))) - z; end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5e-309) tmp = (x * (log((-1.0 / y)) + log(-x))) - z; else tmp = ((log(x) - log(y)) * x) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[y, -5e-309], N[(N[(x * N[(N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision] + N[Log[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]]
x \cdot \log \left(\frac{x}{y}\right) - z
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-309}:\\
\;\;\;\;x \cdot \left(\log \left(\frac{-1}{y}\right) + \log \left(-x\right)\right) - z\\
\mathbf{else}:\\
\;\;\;\;\left(\log x - \log y\right) \cdot x - z\\
\end{array}
Results
| Original | 15.0 |
|---|---|
| Target | 7.9 |
| Herbie | 0.3 |
if y < -4.9999999999999995e-309Initial program 15.4
Taylor expanded in y around -inf 0.3
Simplified0.3
[Start]0.3 | \[ x \cdot \left(\log \left(\frac{-1}{y}\right) + \log \left(-1 \cdot x\right)\right) - z
\] |
|---|---|
rational.json-simplify-2 [=>]0.3 | \[ x \cdot \left(\log \left(\frac{-1}{y}\right) + \log \color{blue}{\left(x \cdot -1\right)}\right) - z
\] |
rational.json-simplify-9 [=>]0.3 | \[ x \cdot \left(\log \left(\frac{-1}{y}\right) + \log \color{blue}{\left(-x\right)}\right) - z
\] |
if -4.9999999999999995e-309 < y Initial program 14.7
Taylor expanded in y around 0 0.3
Simplified0.3
[Start]0.3 | \[ x \cdot \left(-1 \cdot \log y + \log x\right) - z
\] |
|---|---|
rational.json-simplify-1 [=>]0.3 | \[ x \cdot \color{blue}{\left(\log x + -1 \cdot \log y\right)} - z
\] |
rational.json-simplify-2 [=>]0.3 | \[ x \cdot \left(\log x + \color{blue}{\log y \cdot -1}\right) - z
\] |
rational.json-simplify-9 [=>]0.3 | \[ x \cdot \left(\log x + \color{blue}{\left(-\log y\right)}\right) - z
\] |
Taylor expanded in x around 0 0.3
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 11.5 |
| Cost | 20424 |
| Alternative 2 | |
|---|---|
| Error | 4.3 |
| Cost | 13644 |
| Alternative 3 | |
|---|---|
| Error | 6.2 |
| Cost | 13512 |
| Alternative 4 | |
|---|---|
| Error | 24.1 |
| Cost | 7512 |
| Alternative 5 | |
|---|---|
| Error | 31.9 |
| Cost | 128 |
herbie shell --seed 2023077
(FPCore (x y z)
:name "Numeric.SpecFunctions.Extra:bd0 from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(if (< y 7.595077799083773e-308) (- (* x (log (/ x y))) z) (- (* x (- (log x) (log y))) z))
(- (* x (log (/ x y))) z))