Average Error: 15.5 → 0.1
Time: 12.7s
Precision: binary64
Cost: 20036
\[x \cdot \log \left(\frac{x}{y}\right) - z \]
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-310}:\\ \;\;\;\;\log \left(\frac{\sqrt{-y}}{\sqrt{-x}}\right) \cdot \left(x \cdot -2\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot -2\right) \cdot \log \left(\frac{\sqrt{y}}{\sqrt{x}}\right) - z\\ \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
(FPCore (x y z)
 :precision binary64
 (if (<= y -1e-310)
   (- (* (log (/ (sqrt (- y)) (sqrt (- x)))) (* x -2.0)) z)
   (- (* (* x -2.0) (log (/ (sqrt y) (sqrt 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 <= -1e-310) {
		tmp = (log((sqrt(-y) / sqrt(-x))) * (x * -2.0)) - z;
	} else {
		tmp = ((x * -2.0) * log((sqrt(y) / sqrt(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 <= (-1d-310)) then
        tmp = (log((sqrt(-y) / sqrt(-x))) * (x * (-2.0d0))) - z
    else
        tmp = ((x * (-2.0d0)) * log((sqrt(y) / sqrt(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 <= -1e-310) {
		tmp = (Math.log((Math.sqrt(-y) / Math.sqrt(-x))) * (x * -2.0)) - z;
	} else {
		tmp = ((x * -2.0) * Math.log((Math.sqrt(y) / Math.sqrt(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 <= -1e-310:
		tmp = (math.log((math.sqrt(-y) / math.sqrt(-x))) * (x * -2.0)) - z
	else:
		tmp = ((x * -2.0) * math.log((math.sqrt(y) / math.sqrt(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 <= -1e-310)
		tmp = Float64(Float64(log(Float64(sqrt(Float64(-y)) / sqrt(Float64(-x)))) * Float64(x * -2.0)) - z);
	else
		tmp = Float64(Float64(Float64(x * -2.0) * log(Float64(sqrt(y) / sqrt(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 <= -1e-310)
		tmp = (log((sqrt(-y) / sqrt(-x))) * (x * -2.0)) - z;
	else
		tmp = ((x * -2.0) * log((sqrt(y) / sqrt(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, -1e-310], N[(N[(N[Log[N[(N[Sqrt[(-y)], $MachinePrecision] / N[Sqrt[(-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(x * -2.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(N[(x * -2.0), $MachinePrecision] * N[Log[N[(N[Sqrt[y], $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
x \cdot \log \left(\frac{x}{y}\right) - z
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\log \left(\frac{\sqrt{-y}}{\sqrt{-x}}\right) \cdot \left(x \cdot -2\right) - z\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.5
Target7.8
Herbie0.1
\[\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 < -9.999999999999969e-311

    1. Initial program 15.4

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

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

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

      \[\leadsto \color{blue}{\log \left(\sqrt{\frac{y}{x}}\right) \cdot \left(x \cdot -2\right)} - z \]
      Proof
      (-.f64 (*.f64 (log.f64 (sqrt.f64 (/.f64 y x))) (*.f64 x -2)) z): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (log.f64 (sqrt.f64 (/.f64 y x))) (*.f64 x (Rewrite<= metadata-eval (+.f64 -1 -1)))) z): 6 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (log.f64 (sqrt.f64 (/.f64 y x))) (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 -1 x) (*.f64 -1 x)))) z): 0 points increase in error, 6 points decrease in error
      (-.f64 (*.f64 (log.f64 (sqrt.f64 (/.f64 y x))) (+.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 x)) (*.f64 -1 x))) z): 6 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (log.f64 (sqrt.f64 (/.f64 y x))) (+.f64 (neg.f64 x) (Rewrite<= neg-mul-1_binary64 (neg.f64 x)))) z): 0 points increase in error, 6 points decrease in error
      (-.f64 (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (neg.f64 x) (log.f64 (sqrt.f64 (/.f64 y x)))) (*.f64 (neg.f64 x) (log.f64 (sqrt.f64 (/.f64 y x)))))) z): 6 points increase in error, 0 points decrease in error
    5. Applied egg-rr0.1

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

    if -9.999999999999969e-311 < y

    1. Initial program 15.6

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

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

      \[\leadsto \color{blue}{\left(\left(-x\right) \cdot \log \left(\sqrt{\frac{y}{x}}\right) + \left(-x\right) \cdot \log \left(\sqrt{\frac{y}{x}}\right)\right)} - z \]
    4. Simplified15.8

      \[\leadsto \color{blue}{\log \left(\sqrt{\frac{y}{x}}\right) \cdot \left(x \cdot -2\right)} - z \]
      Proof
      (-.f64 (*.f64 (log.f64 (sqrt.f64 (/.f64 y x))) (*.f64 x -2)) z): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (log.f64 (sqrt.f64 (/.f64 y x))) (*.f64 x (Rewrite<= metadata-eval (+.f64 -1 -1)))) z): 6 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (log.f64 (sqrt.f64 (/.f64 y x))) (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 -1 x) (*.f64 -1 x)))) z): 0 points increase in error, 6 points decrease in error
      (-.f64 (*.f64 (log.f64 (sqrt.f64 (/.f64 y x))) (+.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 x)) (*.f64 -1 x))) z): 6 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (log.f64 (sqrt.f64 (/.f64 y x))) (+.f64 (neg.f64 x) (Rewrite<= neg-mul-1_binary64 (neg.f64 x)))) z): 0 points increase in error, 6 points decrease in error
      (-.f64 (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (neg.f64 x) (log.f64 (sqrt.f64 (/.f64 y x)))) (*.f64 (neg.f64 x) (log.f64 (sqrt.f64 (/.f64 y x)))))) z): 6 points increase in error, 0 points decrease in error
    5. Applied egg-rr0.1

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

      \[\leadsto \log \color{blue}{\left(\frac{\sqrt{y}}{\sqrt{x}}\right)} \cdot \left(x \cdot -2\right) - z \]
      Proof
      (-.f64 (*.f64 (log.f64 (/.f64 (sqrt.f64 y) (sqrt.f64 x))) (*.f64 x -2)) z): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (log.f64 (/.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (sqrt.f64 y) 1)) (sqrt.f64 x))) (*.f64 x -2)) z): 0 points increase in error, 3 points decrease in error
      (-.f64 (*.f64 (log.f64 (Rewrite<= associate-*r/_binary64 (*.f64 (sqrt.f64 y) (/.f64 1 (sqrt.f64 x))))) (*.f64 x -2)) z): 3 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

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

Alternatives

Alternative 1
Error7.9
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^{+305}:\\ \;\;\;\;t_0 - z\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 2
Error0.2
Cost19908
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-310}:\\ \;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot -2\right) \cdot \log \left(\frac{\sqrt{y}}{\sqrt{x}}\right) - z\\ \end{array} \]
Alternative 3
Error4.6
Cost13644
\[\begin{array}{l} \mathbf{if}\;x \leq -9.4 \cdot 10^{+232}:\\ \;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right)\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-186}:\\ \;\;\;\;\left(-x\right) \cdot \log \left(\frac{y}{x}\right) - z\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-307}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
Alternative 4
Error0.3
Cost13508
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-310}:\\ \;\;\;\;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} \]
Alternative 5
Error21.6
Cost7249
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{-12}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 3.45 \cdot 10^{-99} \lor \neg \left(z \leq 1.1 \cdot 10^{-55}\right) \land z \leq 1.5 \cdot 10^{-7}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Error21.6
Cost7248
\[\begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{-9}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-100}:\\ \;\;\;\;\left(-x\right) \cdot \log \left(\frac{y}{x}\right)\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-56}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{-7}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Error32.2
Cost128
\[-z \]

Error

Reproduce

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