Average Error: 15.4 → 0.3
Time: 10.3s
Precision: binary64
Cost: 13508
\[x \cdot \log \left(\frac{x}{y}\right) - z \]
\[\begin{array}{l} \mathbf{if}\;y \leq 0:\\ \;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
(FPCore (x y z)
 :precision binary64
 (if (<= y 0.0)
   (- (* x (- (log (- x)) (log (- y)))) z)
   (- (* x (- (log x) (log y))) 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 <= 0.0) {
		tmp = (x * (log(-x) - log(-y))) - z;
	} else {
		tmp = (x * (log(x) - log(y))) - 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 <= 0.0d0) then
        tmp = (x * (log(-x) - log(-y))) - z
    else
        tmp = (x * (log(x) - log(y))) - 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 <= 0.0) {
		tmp = (x * (Math.log(-x) - Math.log(-y))) - z;
	} else {
		tmp = (x * (Math.log(x) - Math.log(y))) - z;
	}
	return tmp;
}
def code(x, y, z):
	return (x * math.log((x / y))) - z
def code(x, y, z):
	tmp = 0
	if y <= 0.0:
		tmp = (x * (math.log(-x) - math.log(-y))) - z
	else:
		tmp = (x * (math.log(x) - math.log(y))) - 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 <= 0.0)
		tmp = Float64(Float64(x * Float64(log(Float64(-x)) - log(Float64(-y)))) - z);
	else
		tmp = Float64(Float64(x * Float64(log(x) - log(y))) - 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 <= 0.0)
		tmp = (x * (log(-x) - log(-y))) - z;
	else
		tmp = (x * (log(x) - log(y))) - 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, 0.0], N[(N[(x * N[(N[Log[(-x)], $MachinePrecision] - N[Log[(-y)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
x \cdot \log \left(\frac{x}{y}\right) - z
\begin{array}{l}
\mathbf{if}\;y \leq 0:\\
\;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right) - z\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.4
Target7.9
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 < 0.0

    1. Initial program 15.4

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Applied egg-rr0.3

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

    if 0.0 < y

    1. Initial program 15.5

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Applied egg-rr64.0

      \[\leadsto x \cdot \color{blue}{\left(\log \left(-x\right) - \log \left(-y\right)\right)} - z \]
    3. Applied egg-rr15.6

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

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

      \[\leadsto \color{blue}{x \cdot \left(\log x - \log y\right)} - z \]
      Proof
      (*.f64 x (-.f64 (log.f64 x) (log.f64 y))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= unsub-neg_binary64 (+.f64 (log.f64 x) (neg.f64 (log.f64 y))))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (+.f64 (log.f64 x) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (log.f64 y))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 (log.f64 x) (*.f64 -1 (log.f64 y))) x)): 0 points increase in error, 0 points decrease in error
      (*.f64 (+.f64 (log.f64 x) (Rewrite=> mul-1-neg_binary64 (neg.f64 (log.f64 y)))) x): 0 points increase in error, 0 points decrease in error
      (*.f64 (+.f64 (log.f64 x) (Rewrite<= log-rec_binary64 (log.f64 (/.f64 1 y)))) x): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= +-commutative_binary64 (+.f64 (log.f64 (/.f64 1 y)) (log.f64 x))) x): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 0:\\ \;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - 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
Error6.4
Cost13512
\[\begin{array}{l} \mathbf{if}\;x \leq -3.9 \cdot 10^{-239}:\\ \;\;\;\;x \cdot \left(-\log \left(\frac{y}{x}\right)\right) - z\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-308}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
Alternative 3
Error21.3
Cost7248
\[\begin{array}{l} t_0 := x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{if}\;z \leq -6692557039784151:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 3.124695509294319 \cdot 10^{-48}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 9.1298231502737 \cdot 10^{+36}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 6.296570304333316 \cdot 10^{+65}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 4
Error21.2
Cost7248
\[\begin{array}{l} \mathbf{if}\;z \leq -6692557039784151:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 3.124695509294319 \cdot 10^{-48}:\\ \;\;\;\;x \cdot \left(-\log \left(\frac{y}{x}\right)\right)\\ \mathbf{elif}\;z \leq 9.1298231502737 \cdot 10^{+36}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 6.296570304333316 \cdot 10^{+65}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 5
Error31.9
Cost128
\[-z \]
Alternative 6
Error62.6
Cost64
\[z \]

Error

Reproduce

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