?

Average Error: 15.3 → 0.3
Time: 11.0s
Precision: binary64
Cost: 13700

?

\[x \cdot \log \left(\frac{x}{y}\right) - z \]
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-308}:\\ \;\;\;\;\left(\log \left(\frac{-1}{y}\right) \cdot x + x \cdot \log \left(-x\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(\log x - \log y\right) \cdot x - z\\ \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
(FPCore (x y z)
 :precision binary64
 (if (<= y -2e-308)
   (- (+ (* (log (/ -1.0 y)) x) (* x (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 <= -2e-308) {
		tmp = ((log((-1.0 / y)) * x) + (x * 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 <= (-2d-308)) then
        tmp = ((log(((-1.0d0) / y)) * x) + (x * 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 <= -2e-308) {
		tmp = ((Math.log((-1.0 / y)) * x) + (x * 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 <= -2e-308:
		tmp = ((math.log((-1.0 / y)) * x) + (x * 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 <= -2e-308)
		tmp = Float64(Float64(Float64(log(Float64(-1.0 / y)) * x) + Float64(x * 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 <= -2e-308)
		tmp = ((log((-1.0 / y)) * x) + (x * 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, -2e-308], N[(N[(N[(N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision] * x), $MachinePrecision] + N[(x * 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 -2 \cdot 10^{-308}:\\
\;\;\;\;\left(\log \left(\frac{-1}{y}\right) \cdot x + x \cdot \log \left(-x\right)\right) - z\\

\mathbf{else}:\\
\;\;\;\;\left(\log x - \log y\right) \cdot x - z\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.3
Target7.8
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;y < 7.595077799083773 \cdot 10^{-308}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if y < -1.9999999999999998e-308

    1. Initial program 15.1

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in y around -inf 0.3

      \[\leadsto x \cdot \color{blue}{\left(\log \left(\frac{-1}{y}\right) + \log \left(-1 \cdot x\right)\right)} - z \]
    3. Simplified0.3

      \[\leadsto x \cdot \color{blue}{\left(\log \left(\frac{-1}{y}\right) + \log \left(-x\right)\right)} - z \]
      Proof

      [Start]0.3

      \[ x \cdot \left(\log \left(\frac{-1}{y}\right) + \log \left(-1 \cdot x\right)\right) - z \]

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.3

      \[ x \cdot \left(\log \left(\frac{-1}{y}\right) + \log \color{blue}{\left(x \cdot -1\right)}\right) - z \]

      rational_best_oopsla_all_46_json_45_simplify-94 [<=]0.3

      \[ x \cdot \left(\log \left(\frac{-1}{y}\right) + \log \color{blue}{\left(-x\right)}\right) - z \]
    4. Applied egg-rr0.3

      \[\leadsto \color{blue}{\left(\log \left(\frac{-1}{y}\right) \cdot x + x \cdot \log \left(-x\right)\right)} - z \]

    if -1.9999999999999998e-308 < y

    1. Initial program 15.6

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in y around 0 0.3

      \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \log y + \log x\right)} - z \]
    3. Simplified0.3

      \[\leadsto x \cdot \color{blue}{\left(\log x + \left(-\log y\right)\right)} - z \]
      Proof

      [Start]0.3

      \[ x \cdot \left(-1 \cdot \log y + \log x\right) - z \]

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.3

      \[ x \cdot \color{blue}{\left(\log x + -1 \cdot \log y\right)} - z \]

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.3

      \[ x \cdot \left(\log x + \color{blue}{\log y \cdot -1}\right) - z \]

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]0.3

      \[ x \cdot \left(\log x + \color{blue}{\left(-\log y\right)}\right) - z \]
    4. Taylor expanded in x around 0 0.3

      \[\leadsto \color{blue}{\left(\log x - \log y\right) \cdot x} - z \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-308}:\\ \;\;\;\;\left(\log \left(\frac{-1}{y}\right) \cdot x + x \cdot \log \left(-x\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(\log x - \log y\right) \cdot x - z\\ \end{array} \]

Alternatives

Alternative 1
Error7.7
Cost20424
\[\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 10^{+308}:\\ \;\;\;\;t_0 - z\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 2
Error4.5
Cost13644
\[\begin{array}{l} \mathbf{if}\;x \leq -2.55 \cdot 10^{+213}:\\ \;\;\;\;\left(\log \left(\frac{-1}{y}\right) + \log \left(-x\right)\right) \cdot x\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{-159}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-308}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;\left(\log x - \log y\right) \cdot x - z\\ \end{array} \]
Alternative 3
Error4.5
Cost13644
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+212}:\\ \;\;\;\;\log \left(\frac{-1}{y}\right) \cdot x + x \cdot \log \left(-x\right)\\ \mathbf{elif}\;x \leq -4.4 \cdot 10^{-159}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-308}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;\left(\log x - \log y\right) \cdot x - z\\ \end{array} \]
Alternative 4
Error0.3
Cost13572
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-308}:\\ \;\;\;\;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} \]
Alternative 5
Error6.1
Cost13512
\[\begin{array}{l} \mathbf{if}\;x \leq -6.6 \cdot 10^{-159}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-308}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;\left(\log x - \log y\right) \cdot x - z\\ \end{array} \]
Alternative 6
Error21.3
Cost7512
\[\begin{array}{l} t_0 := \log \left(\frac{x}{y}\right) \cdot x\\ \mathbf{if}\;z \leq -1.65 \cdot 10^{+70}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -4.4 \cdot 10^{+53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-33}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{-132}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.15 \cdot 10^{-86}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-32}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Error30.7
Cost128
\[-z \]

Error

Reproduce?

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