Numeric.SpecFunctions.Extra:bd0 from math-functions-0.1.5.2

Percentage Accurate: 77.8% → 99.5%
Time: 9.6s
Alternatives: 9
Speedup: 0.5×

Specification

?
\[\begin{array}{l} \\ x \cdot \log \left(\frac{x}{y}\right) - z \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
double code(double x, double y, double z) {
	return (x * log((x / y))) - z;
}
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
public static double code(double x, double y, double z) {
	return (x * Math.log((x / y))) - z;
}
def code(x, y, z):
	return (x * math.log((x / y))) - z
function code(x, y, z)
	return Float64(Float64(x * log(Float64(x / y))) - z)
end
function tmp = code(x, y, z)
	tmp = (x * log((x / y))) - z;
end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \log \left(\frac{x}{y}\right) - z
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 77.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot \log \left(\frac{x}{y}\right) - z \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
double code(double x, double y, double z) {
	return (x * log((x / y))) - z;
}
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
public static double code(double x, double y, double z) {
	return (x * Math.log((x / y))) - z;
}
def code(x, y, z):
	return (x * math.log((x / y))) - z
function code(x, y, z)
	return Float64(Float64(x * log(Float64(x / y))) - z)
end
function tmp = code(x, y, z)
	tmp = (x * log((x / y))) - z;
end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \log \left(\frac{x}{y}\right) - z
\end{array}

Alternative 1: 99.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -5 \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} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -5e-310)
   (- (* x (- (log (- x)) (log (- y)))) z)
   (- (* x (- (log x) (log y))) z)))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -5e-310) {
		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
    real(8) :: tmp
    if (y <= (-5d-310)) 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) {
	double tmp;
	if (y <= -5e-310) {
		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):
	tmp = 0
	if y <= -5e-310:
		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)
	tmp = 0.0
	if (y <= -5e-310)
		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_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -5e-310)
		tmp = (x * (log(-x) - log(-y))) - z;
	else
		tmp = (x * (log(x) - log(y))) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -5e-310], 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]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \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}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.999999999999985e-310

    1. Initial program 79.7%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. frac-2neg79.7%

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

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

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

    if -4.999999999999985e-310 < y

    1. Initial program 76.8%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log-div99.5%

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
    4. Applied egg-rr99.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5 \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} \]
  5. Add Preprocessing

Alternative 2: 89.1% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \log \left(\frac{x}{y}\right)\\ t_1 := x \cdot \log \left(y \cdot x\right)\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1 - z\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+296}:\\ \;\;\;\;t_0 - z\\ \mathbf{else}:\\ \;\;\;\;\left|t_1\right| - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (log (/ x y)))) (t_1 (* x (log (* y x)))))
   (if (<= t_0 (- INFINITY))
     (- t_1 z)
     (if (<= t_0 5e+296) (- t_0 z) (- (fabs t_1) z)))))
double code(double x, double y, double z) {
	double t_0 = x * log((x / y));
	double t_1 = x * log((y * x));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1 - z;
	} else if (t_0 <= 5e+296) {
		tmp = t_0 - z;
	} else {
		tmp = fabs(t_1) - z;
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	double t_0 = x * Math.log((x / y));
	double t_1 = x * Math.log((y * x));
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1 - z;
	} else if (t_0 <= 5e+296) {
		tmp = t_0 - z;
	} else {
		tmp = Math.abs(t_1) - z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * math.log((x / y))
	t_1 = x * math.log((y * x))
	tmp = 0
	if t_0 <= -math.inf:
		tmp = t_1 - z
	elif t_0 <= 5e+296:
		tmp = t_0 - z
	else:
		tmp = math.fabs(t_1) - z
	return tmp
function code(x, y, z)
	t_0 = Float64(x * log(Float64(x / y)))
	t_1 = Float64(x * log(Float64(y * x)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(t_1 - z);
	elseif (t_0 <= 5e+296)
		tmp = Float64(t_0 - z);
	else
		tmp = Float64(abs(t_1) - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * log((x / y));
	t_1 = x * log((y * x));
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = t_1 - z;
	elseif (t_0 <= 5e+296)
		tmp = t_0 - z;
	else
		tmp = abs(t_1) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Log[N[(y * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(t$95$1 - z), $MachinePrecision], If[LessEqual[t$95$0, 5e+296], N[(t$95$0 - z), $MachinePrecision], N[(N[Abs[t$95$1], $MachinePrecision] - z), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right)\\
t_1 := x \cdot \log \left(y \cdot x\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1 - z\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+296}:\\
\;\;\;\;t_0 - z\\

\mathbf{else}:\\
\;\;\;\;\left|t_1\right| - z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0

    1. Initial program 8.2%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log-div40.7%

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
    4. Applied egg-rr40.7%

      \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
    5. Step-by-step derivation
      1. sub-neg40.7%

        \[\leadsto x \cdot \color{blue}{\left(\log x + \left(-\log y\right)\right)} - z \]
      2. distribute-rgt-in40.7%

        \[\leadsto \color{blue}{\left(\log x \cdot x + \left(-\log y\right) \cdot x\right)} - z \]
    6. Applied egg-rr40.7%

      \[\leadsto \color{blue}{\left(\log x \cdot x + \left(-\log y\right) \cdot x\right)} - z \]
    7. Step-by-step derivation
      1. distribute-rgt-out40.7%

        \[\leadsto \color{blue}{x \cdot \left(\log x + \left(-\log y\right)\right)} - z \]
      2. sub-neg40.7%

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
      3. log-div8.2%

        \[\leadsto x \cdot \color{blue}{\log \left(\frac{x}{y}\right)} - z \]
      4. *-commutative8.2%

        \[\leadsto \color{blue}{\log \left(\frac{x}{y}\right) \cdot x} - z \]
      5. log-div40.7%

        \[\leadsto \color{blue}{\left(\log x - \log y\right)} \cdot x - z \]
      6. sub-neg40.7%

        \[\leadsto \color{blue}{\left(\log x + \left(-\log y\right)\right)} \cdot x - z \]
      7. add-log-exp40.7%

        \[\leadsto \left(\log x + \color{blue}{\log \left(e^{-\log y}\right)}\right) \cdot x - z \]
      8. sum-log0.7%

        \[\leadsto \color{blue}{\log \left(x \cdot e^{-\log y}\right)} \cdot x - z \]
      9. add-sqr-sqrt0.0%

        \[\leadsto \log \left(x \cdot e^{\color{blue}{\sqrt{-\log y} \cdot \sqrt{-\log y}}}\right) \cdot x - z \]
      10. sqrt-unprod37.1%

        \[\leadsto \log \left(x \cdot e^{\color{blue}{\sqrt{\left(-\log y\right) \cdot \left(-\log y\right)}}}\right) \cdot x - z \]
      11. sqr-neg37.1%

        \[\leadsto \log \left(x \cdot e^{\sqrt{\color{blue}{\log y \cdot \log y}}}\right) \cdot x - z \]
      12. sqrt-unprod37.1%

        \[\leadsto \log \left(x \cdot e^{\color{blue}{\sqrt{\log y} \cdot \sqrt{\log y}}}\right) \cdot x - z \]
      13. add-sqr-sqrt37.1%

        \[\leadsto \log \left(x \cdot e^{\color{blue}{\log y}}\right) \cdot x - z \]
      14. add-exp-log49.2%

        \[\leadsto \log \left(x \cdot \color{blue}{y}\right) \cdot x - z \]
    8. Applied egg-rr49.2%

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

    if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 5.0000000000000001e296

    1. Initial program 99.6%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing

    if 5.0000000000000001e296 < (*.f64 x (log.f64 (/.f64 x y)))

    1. Initial program 4.1%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cube-cbrt4.1%

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

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

        \[\leadsto x \cdot \left(\log \color{blue}{\left({\left(\sqrt[3]{\frac{x}{y}}\right)}^{2}\right)} + \log \left(\sqrt[3]{\frac{x}{y}}\right)\right) - z \]
      4. metadata-eval4.1%

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

        \[\leadsto x \cdot \left(\color{blue}{\left(1 + 1\right) \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)} + \log \left(\sqrt[3]{\frac{x}{y}}\right)\right) - z \]
      6. metadata-eval4.1%

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

      \[\leadsto x \cdot \color{blue}{\left(2 \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right) + \log \left(\sqrt[3]{\frac{x}{y}}\right)\right)} - z \]
    5. Step-by-step derivation
      1. distribute-lft1-in4.1%

        \[\leadsto x \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)\right)} - z \]
      2. metadata-eval4.1%

        \[\leadsto x \cdot \left(\color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)\right) - z \]
      3. *-commutative4.1%

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

      \[\leadsto x \cdot \color{blue}{\left(\log \left(\sqrt[3]{\frac{x}{y}}\right) \cdot 3\right)} - z \]
    7. Step-by-step derivation
      1. add-log-exp4.1%

        \[\leadsto x \cdot \color{blue}{\log \left(e^{\log \left(\sqrt[3]{\frac{x}{y}}\right) \cdot 3}\right)} - z \]
      2. exp-to-pow4.1%

        \[\leadsto x \cdot \log \color{blue}{\left({\left(\sqrt[3]{\frac{x}{y}}\right)}^{3}\right)} - z \]
      3. pow34.1%

        \[\leadsto x \cdot \log \color{blue}{\left(\left(\sqrt[3]{\frac{x}{y}} \cdot \sqrt[3]{\frac{x}{y}}\right) \cdot \sqrt[3]{\frac{x}{y}}\right)} - z \]
      4. add-cube-cbrt4.1%

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{x}{y}\right)} - z \]
      5. add-sqr-sqrt4.1%

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

        \[\leadsto \color{blue}{\sqrt{\left(x \cdot \log \left(\frac{x}{y}\right)\right) \cdot \left(x \cdot \log \left(\frac{x}{y}\right)\right)}} - z \]
      7. pow24.1%

        \[\leadsto \sqrt{\color{blue}{{\left(x \cdot \log \left(\frac{x}{y}\right)\right)}^{2}}} - z \]
    8. Applied egg-rr50.8%

      \[\leadsto \color{blue}{\sqrt{{\left(x \cdot \log \left(x \cdot y\right)\right)}^{2}}} - z \]
    9. Step-by-step derivation
      1. unpow250.8%

        \[\leadsto \sqrt{\color{blue}{\left(x \cdot \log \left(x \cdot y\right)\right) \cdot \left(x \cdot \log \left(x \cdot y\right)\right)}} - z \]
      2. rem-sqrt-square54.8%

        \[\leadsto \color{blue}{\left|x \cdot \log \left(x \cdot y\right)\right|} - z \]
    10. Simplified54.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot \log \left(\frac{x}{y}\right) \leq -\infty:\\ \;\;\;\;x \cdot \log \left(y \cdot x\right) - z\\ \mathbf{elif}\;x \cdot \log \left(\frac{x}{y}\right) \leq 5 \cdot 10^{+296}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \log \left(y \cdot x\right)\right| - z\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 89.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \log \left(\frac{x}{y}\right)\\ t_1 := \log \left(y \cdot x\right)\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;x \cdot \left|t_1\right| - z\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+296}:\\ \;\;\;\;t_0 - z\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot t_1\right| - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (log (/ x y)))) (t_1 (log (* y x))))
   (if (<= t_0 (- INFINITY))
     (- (* x (fabs t_1)) z)
     (if (<= t_0 5e+296) (- t_0 z) (- (fabs (* x t_1)) z)))))
double code(double x, double y, double z) {
	double t_0 = x * log((x / y));
	double t_1 = log((y * x));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (x * fabs(t_1)) - z;
	} else if (t_0 <= 5e+296) {
		tmp = t_0 - z;
	} else {
		tmp = fabs((x * t_1)) - z;
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	double t_0 = x * Math.log((x / y));
	double t_1 = Math.log((y * x));
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = (x * Math.abs(t_1)) - z;
	} else if (t_0 <= 5e+296) {
		tmp = t_0 - z;
	} else {
		tmp = Math.abs((x * t_1)) - z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * math.log((x / y))
	t_1 = math.log((y * x))
	tmp = 0
	if t_0 <= -math.inf:
		tmp = (x * math.fabs(t_1)) - z
	elif t_0 <= 5e+296:
		tmp = t_0 - z
	else:
		tmp = math.fabs((x * t_1)) - z
	return tmp
function code(x, y, z)
	t_0 = Float64(x * log(Float64(x / y)))
	t_1 = log(Float64(y * x))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(x * abs(t_1)) - z);
	elseif (t_0 <= 5e+296)
		tmp = Float64(t_0 - z);
	else
		tmp = Float64(abs(Float64(x * t_1)) - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * log((x / y));
	t_1 = log((y * x));
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = (x * abs(t_1)) - z;
	elseif (t_0 <= 5e+296)
		tmp = t_0 - z;
	else
		tmp = abs((x * t_1)) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Log[N[(y * x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(x * N[Abs[t$95$1], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[t$95$0, 5e+296], N[(t$95$0 - z), $MachinePrecision], N[(N[Abs[N[(x * t$95$1), $MachinePrecision]], $MachinePrecision] - z), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right)\\
t_1 := \log \left(y \cdot x\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;x \cdot \left|t_1\right| - z\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+296}:\\
\;\;\;\;t_0 - z\\

\mathbf{else}:\\
\;\;\;\;\left|x \cdot t_1\right| - z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0

    1. Initial program 8.2%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cube-cbrt8.2%

        \[\leadsto x \cdot \log \left(\frac{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}}{y}\right) - z \]
      2. *-un-lft-identity8.2%

        \[\leadsto x \cdot \log \left(\frac{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}{\color{blue}{1 \cdot y}}\right) - z \]
      3. times-frac8.2%

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{1} \cdot \frac{\sqrt[3]{x}}{y}\right)} - z \]
      4. log-prod64.4%

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

        \[\leadsto x \cdot \left(\log \left(\frac{\color{blue}{{\left(\sqrt[3]{x}\right)}^{2}}}{1}\right) + \log \left(\frac{\sqrt[3]{x}}{y}\right)\right) - z \]
    4. Applied egg-rr64.4%

      \[\leadsto x \cdot \color{blue}{\left(\log \left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{1}\right) + \log \left(\frac{\sqrt[3]{x}}{y}\right)\right)} - z \]
    5. Step-by-step derivation
      1. add-sqr-sqrt41.6%

        \[\leadsto x \cdot \color{blue}{\left(\sqrt{\log \left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{1}\right) + \log \left(\frac{\sqrt[3]{x}}{y}\right)} \cdot \sqrt{\log \left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{1}\right) + \log \left(\frac{\sqrt[3]{x}}{y}\right)}\right)} - z \]
      2. sqrt-unprod64.7%

        \[\leadsto x \cdot \color{blue}{\sqrt{\left(\log \left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{1}\right) + \log \left(\frac{\sqrt[3]{x}}{y}\right)\right) \cdot \left(\log \left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{1}\right) + \log \left(\frac{\sqrt[3]{x}}{y}\right)\right)}} - z \]
      3. pow264.7%

        \[\leadsto x \cdot \sqrt{\color{blue}{{\left(\log \left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{1}\right) + \log \left(\frac{\sqrt[3]{x}}{y}\right)\right)}^{2}}} - z \]
    6. Applied egg-rr53.6%

      \[\leadsto x \cdot \color{blue}{\sqrt{{\log \left(x \cdot y\right)}^{2}}} - z \]
    7. Step-by-step derivation
      1. unpow253.6%

        \[\leadsto x \cdot \sqrt{\color{blue}{\log \left(x \cdot y\right) \cdot \log \left(x \cdot y\right)}} - z \]
      2. rem-sqrt-square53.6%

        \[\leadsto x \cdot \color{blue}{\left|\log \left(x \cdot y\right)\right|} - z \]
    8. Simplified53.6%

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

    if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 5.0000000000000001e296

    1. Initial program 99.6%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing

    if 5.0000000000000001e296 < (*.f64 x (log.f64 (/.f64 x y)))

    1. Initial program 4.1%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cube-cbrt4.1%

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

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

        \[\leadsto x \cdot \left(\log \color{blue}{\left({\left(\sqrt[3]{\frac{x}{y}}\right)}^{2}\right)} + \log \left(\sqrt[3]{\frac{x}{y}}\right)\right) - z \]
      4. metadata-eval4.1%

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

        \[\leadsto x \cdot \left(\color{blue}{\left(1 + 1\right) \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)} + \log \left(\sqrt[3]{\frac{x}{y}}\right)\right) - z \]
      6. metadata-eval4.1%

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

      \[\leadsto x \cdot \color{blue}{\left(2 \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right) + \log \left(\sqrt[3]{\frac{x}{y}}\right)\right)} - z \]
    5. Step-by-step derivation
      1. distribute-lft1-in4.1%

        \[\leadsto x \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)\right)} - z \]
      2. metadata-eval4.1%

        \[\leadsto x \cdot \left(\color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)\right) - z \]
      3. *-commutative4.1%

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

      \[\leadsto x \cdot \color{blue}{\left(\log \left(\sqrt[3]{\frac{x}{y}}\right) \cdot 3\right)} - z \]
    7. Step-by-step derivation
      1. add-log-exp4.1%

        \[\leadsto x \cdot \color{blue}{\log \left(e^{\log \left(\sqrt[3]{\frac{x}{y}}\right) \cdot 3}\right)} - z \]
      2. exp-to-pow4.1%

        \[\leadsto x \cdot \log \color{blue}{\left({\left(\sqrt[3]{\frac{x}{y}}\right)}^{3}\right)} - z \]
      3. pow34.1%

        \[\leadsto x \cdot \log \color{blue}{\left(\left(\sqrt[3]{\frac{x}{y}} \cdot \sqrt[3]{\frac{x}{y}}\right) \cdot \sqrt[3]{\frac{x}{y}}\right)} - z \]
      4. add-cube-cbrt4.1%

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{x}{y}\right)} - z \]
      5. add-sqr-sqrt4.1%

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

        \[\leadsto \color{blue}{\sqrt{\left(x \cdot \log \left(\frac{x}{y}\right)\right) \cdot \left(x \cdot \log \left(\frac{x}{y}\right)\right)}} - z \]
      7. pow24.1%

        \[\leadsto \sqrt{\color{blue}{{\left(x \cdot \log \left(\frac{x}{y}\right)\right)}^{2}}} - z \]
    8. Applied egg-rr50.8%

      \[\leadsto \color{blue}{\sqrt{{\left(x \cdot \log \left(x \cdot y\right)\right)}^{2}}} - z \]
    9. Step-by-step derivation
      1. unpow250.8%

        \[\leadsto \sqrt{\color{blue}{\left(x \cdot \log \left(x \cdot y\right)\right) \cdot \left(x \cdot \log \left(x \cdot y\right)\right)}} - z \]
      2. rem-sqrt-square54.8%

        \[\leadsto \color{blue}{\left|x \cdot \log \left(x \cdot y\right)\right|} - z \]
    10. Simplified54.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot \log \left(\frac{x}{y}\right) \leq -\infty:\\ \;\;\;\;x \cdot \left|\log \left(y \cdot x\right)\right| - z\\ \mathbf{elif}\;x \cdot \log \left(\frac{x}{y}\right) \leq 5 \cdot 10^{+296}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \log \left(y \cdot x\right)\right| - z\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 87.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{+296}\right):\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;t_0 - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (log (/ x y)))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e+296))) (- z) (- t_0 z))))
double code(double x, double y, double z) {
	double t_0 = x * log((x / y));
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 5e+296)) {
		tmp = -z;
	} else {
		tmp = t_0 - z;
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	double t_0 = x * Math.log((x / y));
	double tmp;
	if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 5e+296)) {
		tmp = -z;
	} else {
		tmp = t_0 - z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * math.log((x / y))
	tmp = 0
	if (t_0 <= -math.inf) or not (t_0 <= 5e+296):
		tmp = -z
	else:
		tmp = t_0 - z
	return tmp
function code(x, y, z)
	t_0 = Float64(x * log(Float64(x / y)))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 5e+296))
		tmp = Float64(-z);
	else
		tmp = Float64(t_0 - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * log((x / y));
	tmp = 0.0;
	if ((t_0 <= -Inf) || ~((t_0 <= 5e+296)))
		tmp = -z;
	else
		tmp = t_0 - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 5e+296]], $MachinePrecision]], (-z), N[(t$95$0 - z), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right)\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{+296}\right):\\
\;\;\;\;-z\\

\mathbf{else}:\\
\;\;\;\;t_0 - z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0 or 5.0000000000000001e296 < (*.f64 x (log.f64 (/.f64 x y)))

    1. Initial program 6.0%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. remove-double-neg6.0%

        \[\leadsto \color{blue}{-\left(-\left(x \cdot \log \left(\frac{x}{y}\right) - z\right)\right)} \]
      2. sub-neg6.0%

        \[\leadsto -\left(-\color{blue}{\left(x \cdot \log \left(\frac{x}{y}\right) + \left(-z\right)\right)}\right) \]
      3. distribute-neg-in6.0%

        \[\leadsto -\color{blue}{\left(\left(-x \cdot \log \left(\frac{x}{y}\right)\right) + \left(-\left(-z\right)\right)\right)} \]
      4. distribute-rgt-neg-in6.0%

        \[\leadsto -\left(\color{blue}{x \cdot \left(-\log \left(\frac{x}{y}\right)\right)} + \left(-\left(-z\right)\right)\right) \]
      5. remove-double-neg6.0%

        \[\leadsto -\left(x \cdot \left(-\log \left(\frac{x}{y}\right)\right) + \color{blue}{z}\right) \]
      6. fma-udef6.0%

        \[\leadsto -\color{blue}{\mathsf{fma}\left(x, -\log \left(\frac{x}{y}\right), z\right)} \]
      7. log-div46.5%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x - \log y\right)}, z\right) \]
      8. sub-neg46.5%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x + \left(-\log y\right)\right)}, z\right) \]
      9. distribute-neg-in46.5%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\left(-\log x\right) + \left(-\left(-\log y\right)\right)}, z\right) \]
      10. remove-double-neg46.5%

        \[\leadsto -\mathsf{fma}\left(x, \left(-\log x\right) + \color{blue}{\log y}, z\right) \]
      11. +-commutative46.5%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y + \left(-\log x\right)}, z\right) \]
      12. sub-neg46.5%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y - \log x}, z\right) \]
      13. log-div11.2%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log \left(\frac{y}{x}\right)}, z\right) \]
    3. Simplified11.2%

      \[\leadsto \color{blue}{-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 45.0%

      \[\leadsto -\color{blue}{z} \]

    if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 5.0000000000000001e296

    1. Initial program 99.6%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification87.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot \log \left(\frac{x}{y}\right) \leq -\infty \lor \neg \left(x \cdot \log \left(\frac{x}{y}\right) \leq 5 \cdot 10^{+296}\right):\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 88.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{+296}\right):\\ \;\;\;\;x \cdot \log \left(y \cdot x\right) - z\\ \mathbf{else}:\\ \;\;\;\;t_0 - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (log (/ x y)))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e+296)))
     (- (* x (log (* y x))) z)
     (- t_0 z))))
double code(double x, double y, double z) {
	double t_0 = x * log((x / y));
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 5e+296)) {
		tmp = (x * log((y * x))) - z;
	} else {
		tmp = t_0 - z;
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	double t_0 = x * Math.log((x / y));
	double tmp;
	if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 5e+296)) {
		tmp = (x * Math.log((y * x))) - z;
	} else {
		tmp = t_0 - z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * math.log((x / y))
	tmp = 0
	if (t_0 <= -math.inf) or not (t_0 <= 5e+296):
		tmp = (x * math.log((y * x))) - z
	else:
		tmp = t_0 - z
	return tmp
function code(x, y, z)
	t_0 = Float64(x * log(Float64(x / y)))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 5e+296))
		tmp = Float64(Float64(x * log(Float64(y * x))) - z);
	else
		tmp = Float64(t_0 - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * log((x / y));
	tmp = 0.0;
	if ((t_0 <= -Inf) || ~((t_0 <= 5e+296)))
		tmp = (x * log((y * x))) - z;
	else
		tmp = t_0 - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 5e+296]], $MachinePrecision]], N[(N[(x * N[Log[N[(y * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(t$95$0 - z), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right)\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{+296}\right):\\
\;\;\;\;x \cdot \log \left(y \cdot x\right) - z\\

\mathbf{else}:\\
\;\;\;\;t_0 - z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0 or 5.0000000000000001e296 < (*.f64 x (log.f64 (/.f64 x y)))

    1. Initial program 6.0%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log-div46.5%

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
    4. Applied egg-rr46.5%

      \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
    5. Step-by-step derivation
      1. sub-neg46.5%

        \[\leadsto x \cdot \color{blue}{\left(\log x + \left(-\log y\right)\right)} - z \]
      2. distribute-rgt-in46.4%

        \[\leadsto \color{blue}{\left(\log x \cdot x + \left(-\log y\right) \cdot x\right)} - z \]
    6. Applied egg-rr46.4%

      \[\leadsto \color{blue}{\left(\log x \cdot x + \left(-\log y\right) \cdot x\right)} - z \]
    7. Step-by-step derivation
      1. distribute-rgt-out46.5%

        \[\leadsto \color{blue}{x \cdot \left(\log x + \left(-\log y\right)\right)} - z \]
      2. sub-neg46.5%

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
      3. log-div6.0%

        \[\leadsto x \cdot \color{blue}{\log \left(\frac{x}{y}\right)} - z \]
      4. *-commutative6.0%

        \[\leadsto \color{blue}{\log \left(\frac{x}{y}\right) \cdot x} - z \]
      5. log-div46.5%

        \[\leadsto \color{blue}{\left(\log x - \log y\right)} \cdot x - z \]
      6. sub-neg46.5%

        \[\leadsto \color{blue}{\left(\log x + \left(-\log y\right)\right)} \cdot x - z \]
      7. add-log-exp46.5%

        \[\leadsto \left(\log x + \color{blue}{\log \left(e^{-\log y}\right)}\right) \cdot x - z \]
      8. sum-log2.0%

        \[\leadsto \color{blue}{\log \left(x \cdot e^{-\log y}\right)} \cdot x - z \]
      9. add-sqr-sqrt1.7%

        \[\leadsto \log \left(x \cdot e^{\color{blue}{\sqrt{-\log y} \cdot \sqrt{-\log y}}}\right) \cdot x - z \]
      10. sqrt-unprod18.9%

        \[\leadsto \log \left(x \cdot e^{\color{blue}{\sqrt{\left(-\log y\right) \cdot \left(-\log y\right)}}}\right) \cdot x - z \]
      11. sqr-neg18.9%

        \[\leadsto \log \left(x \cdot e^{\sqrt{\color{blue}{\log y \cdot \log y}}}\right) \cdot x - z \]
      12. sqrt-unprod17.3%

        \[\leadsto \log \left(x \cdot e^{\color{blue}{\sqrt{\log y} \cdot \sqrt{\log y}}}\right) \cdot x - z \]
      13. add-sqr-sqrt22.3%

        \[\leadsto \log \left(x \cdot e^{\color{blue}{\log y}}\right) \cdot x - z \]
      14. add-exp-log48.7%

        \[\leadsto \log \left(x \cdot \color{blue}{y}\right) \cdot x - z \]
    8. Applied egg-rr48.7%

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

    if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 5.0000000000000001e296

    1. Initial program 99.6%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification88.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot \log \left(\frac{x}{y}\right) \leq -\infty \lor \neg \left(x \cdot \log \left(\frac{x}{y}\right) \leq 5 \cdot 10^{+296}\right):\\ \;\;\;\;x \cdot \log \left(y \cdot x\right) - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 92.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.5 \cdot 10^{+258}:\\ \;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right)\\ \mathbf{elif}\;x \leq -3.4 \cdot 10^{-198}:\\ \;\;\;\;-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -5.5e+258)
   (* x (- (log (- x)) (log (- y))))
   (if (<= x -3.4e-198)
     (- (fma x (log (/ y x)) z))
     (if (<= x -5e-309) (- z) (- (* x (- (log x) (log y))) z)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -5.5e+258) {
		tmp = x * (log(-x) - log(-y));
	} else if (x <= -3.4e-198) {
		tmp = -fma(x, log((y / x)), z);
	} else if (x <= -5e-309) {
		tmp = -z;
	} else {
		tmp = (x * (log(x) - log(y))) - z;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (x <= -5.5e+258)
		tmp = Float64(x * Float64(log(Float64(-x)) - log(Float64(-y))));
	elseif (x <= -3.4e-198)
		tmp = Float64(-fma(x, log(Float64(y / x)), z));
	elseif (x <= -5e-309)
		tmp = Float64(-z);
	else
		tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[x, -5.5e+258], N[(x * N[(N[Log[(-x)], $MachinePrecision] - N[Log[(-y)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -3.4e-198], (-N[(x * N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision] + z), $MachinePrecision]), If[LessEqual[x, -5e-309], (-z), N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+258}:\\
\;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right)\\

\mathbf{elif}\;x \leq -3.4 \cdot 10^{-198}:\\
\;\;\;\;-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)\\

\mathbf{elif}\;x \leq -5 \cdot 10^{-309}:\\
\;\;\;\;-z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -5.49999999999999978e258

    1. Initial program 54.8%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. remove-double-neg54.8%

        \[\leadsto \color{blue}{-\left(-\left(x \cdot \log \left(\frac{x}{y}\right) - z\right)\right)} \]
      2. sub-neg54.8%

        \[\leadsto -\left(-\color{blue}{\left(x \cdot \log \left(\frac{x}{y}\right) + \left(-z\right)\right)}\right) \]
      3. distribute-neg-in54.8%

        \[\leadsto -\color{blue}{\left(\left(-x \cdot \log \left(\frac{x}{y}\right)\right) + \left(-\left(-z\right)\right)\right)} \]
      4. distribute-rgt-neg-in54.8%

        \[\leadsto -\left(\color{blue}{x \cdot \left(-\log \left(\frac{x}{y}\right)\right)} + \left(-\left(-z\right)\right)\right) \]
      5. remove-double-neg54.8%

        \[\leadsto -\left(x \cdot \left(-\log \left(\frac{x}{y}\right)\right) + \color{blue}{z}\right) \]
      6. fma-udef54.8%

        \[\leadsto -\color{blue}{\mathsf{fma}\left(x, -\log \left(\frac{x}{y}\right), z\right)} \]
      7. log-div0.0%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x - \log y\right)}, z\right) \]
      8. sub-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x + \left(-\log y\right)\right)}, z\right) \]
      9. distribute-neg-in0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\left(-\log x\right) + \left(-\left(-\log y\right)\right)}, z\right) \]
      10. remove-double-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, \left(-\log x\right) + \color{blue}{\log y}, z\right) \]
      11. +-commutative0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y + \left(-\log x\right)}, z\right) \]
      12. sub-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y - \log x}, z\right) \]
      13. log-div57.8%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log \left(\frac{y}{x}\right)}, z\right) \]
    3. Simplified57.8%

      \[\leadsto \color{blue}{-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 0.0%

      \[\leadsto -\color{blue}{x \cdot \left(\log y + \log \left(\frac{1}{x}\right)\right)} \]
    6. Step-by-step derivation
      1. log-rec0.0%

        \[\leadsto -x \cdot \left(\log y + \color{blue}{\left(-\log x\right)}\right) \]
      2. sub-neg0.0%

        \[\leadsto -x \cdot \color{blue}{\left(\log y - \log x\right)} \]
      3. log-div57.8%

        \[\leadsto -x \cdot \color{blue}{\log \left(\frac{y}{x}\right)} \]
    7. Simplified57.8%

      \[\leadsto -\color{blue}{x \cdot \log \left(\frac{y}{x}\right)} \]
    8. Step-by-step derivation
      1. frac-2neg57.8%

        \[\leadsto -x \cdot \log \color{blue}{\left(\frac{-y}{-x}\right)} \]
      2. log-div98.7%

        \[\leadsto -x \cdot \color{blue}{\left(\log \left(-y\right) - \log \left(-x\right)\right)} \]
    9. Applied egg-rr98.7%

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

    if -5.49999999999999978e258 < x < -3.3999999999999998e-198

    1. Initial program 85.2%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. remove-double-neg85.2%

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

        \[\leadsto -\left(-\color{blue}{\left(x \cdot \log \left(\frac{x}{y}\right) + \left(-z\right)\right)}\right) \]
      3. distribute-neg-in85.2%

        \[\leadsto -\color{blue}{\left(\left(-x \cdot \log \left(\frac{x}{y}\right)\right) + \left(-\left(-z\right)\right)\right)} \]
      4. distribute-rgt-neg-in85.2%

        \[\leadsto -\left(\color{blue}{x \cdot \left(-\log \left(\frac{x}{y}\right)\right)} + \left(-\left(-z\right)\right)\right) \]
      5. remove-double-neg85.2%

        \[\leadsto -\left(x \cdot \left(-\log \left(\frac{x}{y}\right)\right) + \color{blue}{z}\right) \]
      6. fma-udef85.2%

        \[\leadsto -\color{blue}{\mathsf{fma}\left(x, -\log \left(\frac{x}{y}\right), z\right)} \]
      7. log-div0.0%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x - \log y\right)}, z\right) \]
      8. sub-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x + \left(-\log y\right)\right)}, z\right) \]
      9. distribute-neg-in0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\left(-\log x\right) + \left(-\left(-\log y\right)\right)}, z\right) \]
      10. remove-double-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, \left(-\log x\right) + \color{blue}{\log y}, z\right) \]
      11. +-commutative0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y + \left(-\log x\right)}, z\right) \]
      12. sub-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y - \log x}, z\right) \]
      13. log-div86.8%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log \left(\frac{y}{x}\right)}, z\right) \]
    3. Simplified86.8%

      \[\leadsto \color{blue}{-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)} \]
    4. Add Preprocessing

    if -3.3999999999999998e-198 < x < -4.9999999999999995e-309

    1. Initial program 73.0%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. remove-double-neg73.0%

        \[\leadsto \color{blue}{-\left(-\left(x \cdot \log \left(\frac{x}{y}\right) - z\right)\right)} \]
      2. sub-neg73.0%

        \[\leadsto -\left(-\color{blue}{\left(x \cdot \log \left(\frac{x}{y}\right) + \left(-z\right)\right)}\right) \]
      3. distribute-neg-in73.0%

        \[\leadsto -\color{blue}{\left(\left(-x \cdot \log \left(\frac{x}{y}\right)\right) + \left(-\left(-z\right)\right)\right)} \]
      4. distribute-rgt-neg-in73.0%

        \[\leadsto -\left(\color{blue}{x \cdot \left(-\log \left(\frac{x}{y}\right)\right)} + \left(-\left(-z\right)\right)\right) \]
      5. remove-double-neg73.0%

        \[\leadsto -\left(x \cdot \left(-\log \left(\frac{x}{y}\right)\right) + \color{blue}{z}\right) \]
      6. fma-udef73.0%

        \[\leadsto -\color{blue}{\mathsf{fma}\left(x, -\log \left(\frac{x}{y}\right), z\right)} \]
      7. log-div0.0%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x - \log y\right)}, z\right) \]
      8. sub-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x + \left(-\log y\right)\right)}, z\right) \]
      9. distribute-neg-in0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\left(-\log x\right) + \left(-\left(-\log y\right)\right)}, z\right) \]
      10. remove-double-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, \left(-\log x\right) + \color{blue}{\log y}, z\right) \]
      11. +-commutative0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y + \left(-\log x\right)}, z\right) \]
      12. sub-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y - \log x}, z\right) \]
      13. log-div69.6%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log \left(\frac{y}{x}\right)}, z\right) \]
    3. Simplified69.6%

      \[\leadsto \color{blue}{-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto -\color{blue}{z} \]

    if -4.9999999999999995e-309 < x

    1. Initial program 76.8%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log-div99.5%

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
    4. Applied egg-rr99.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.5 \cdot 10^{+258}:\\ \;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right)\\ \mathbf{elif}\;x \leq -3.4 \cdot 10^{-198}:\\ \;\;\;\;-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 91.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{-198}:\\ \;\;\;\;-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-306}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -3.4e-198)
   (- (fma x (log (/ y x)) z))
   (if (<= x -2e-306) (- z) (- (* x (- (log x) (log y))) z))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -3.4e-198) {
		tmp = -fma(x, log((y / x)), z);
	} else if (x <= -2e-306) {
		tmp = -z;
	} else {
		tmp = (x * (log(x) - log(y))) - z;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (x <= -3.4e-198)
		tmp = Float64(-fma(x, log(Float64(y / x)), z));
	elseif (x <= -2e-306)
		tmp = Float64(-z);
	else
		tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[x, -3.4e-198], (-N[(x * N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision] + z), $MachinePrecision]), If[LessEqual[x, -2e-306], (-z), N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{-198}:\\
\;\;\;\;-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)\\

\mathbf{elif}\;x \leq -2 \cdot 10^{-306}:\\
\;\;\;\;-z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.3999999999999998e-198

    1. Initial program 81.4%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. remove-double-neg81.4%

        \[\leadsto \color{blue}{-\left(-\left(x \cdot \log \left(\frac{x}{y}\right) - z\right)\right)} \]
      2. sub-neg81.4%

        \[\leadsto -\left(-\color{blue}{\left(x \cdot \log \left(\frac{x}{y}\right) + \left(-z\right)\right)}\right) \]
      3. distribute-neg-in81.4%

        \[\leadsto -\color{blue}{\left(\left(-x \cdot \log \left(\frac{x}{y}\right)\right) + \left(-\left(-z\right)\right)\right)} \]
      4. distribute-rgt-neg-in81.4%

        \[\leadsto -\left(\color{blue}{x \cdot \left(-\log \left(\frac{x}{y}\right)\right)} + \left(-\left(-z\right)\right)\right) \]
      5. remove-double-neg81.4%

        \[\leadsto -\left(x \cdot \left(-\log \left(\frac{x}{y}\right)\right) + \color{blue}{z}\right) \]
      6. fma-udef81.4%

        \[\leadsto -\color{blue}{\mathsf{fma}\left(x, -\log \left(\frac{x}{y}\right), z\right)} \]
      7. log-div0.0%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x - \log y\right)}, z\right) \]
      8. sub-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x + \left(-\log y\right)\right)}, z\right) \]
      9. distribute-neg-in0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\left(-\log x\right) + \left(-\left(-\log y\right)\right)}, z\right) \]
      10. remove-double-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, \left(-\log x\right) + \color{blue}{\log y}, z\right) \]
      11. +-commutative0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y + \left(-\log x\right)}, z\right) \]
      12. sub-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y - \log x}, z\right) \]
      13. log-div83.2%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log \left(\frac{y}{x}\right)}, z\right) \]
    3. Simplified83.2%

      \[\leadsto \color{blue}{-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)} \]
    4. Add Preprocessing

    if -3.3999999999999998e-198 < x < -2.00000000000000006e-306

    1. Initial program 73.0%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. remove-double-neg73.0%

        \[\leadsto \color{blue}{-\left(-\left(x \cdot \log \left(\frac{x}{y}\right) - z\right)\right)} \]
      2. sub-neg73.0%

        \[\leadsto -\left(-\color{blue}{\left(x \cdot \log \left(\frac{x}{y}\right) + \left(-z\right)\right)}\right) \]
      3. distribute-neg-in73.0%

        \[\leadsto -\color{blue}{\left(\left(-x \cdot \log \left(\frac{x}{y}\right)\right) + \left(-\left(-z\right)\right)\right)} \]
      4. distribute-rgt-neg-in73.0%

        \[\leadsto -\left(\color{blue}{x \cdot \left(-\log \left(\frac{x}{y}\right)\right)} + \left(-\left(-z\right)\right)\right) \]
      5. remove-double-neg73.0%

        \[\leadsto -\left(x \cdot \left(-\log \left(\frac{x}{y}\right)\right) + \color{blue}{z}\right) \]
      6. fma-udef73.0%

        \[\leadsto -\color{blue}{\mathsf{fma}\left(x, -\log \left(\frac{x}{y}\right), z\right)} \]
      7. log-div0.0%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x - \log y\right)}, z\right) \]
      8. sub-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x + \left(-\log y\right)\right)}, z\right) \]
      9. distribute-neg-in0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\left(-\log x\right) + \left(-\left(-\log y\right)\right)}, z\right) \]
      10. remove-double-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, \left(-\log x\right) + \color{blue}{\log y}, z\right) \]
      11. +-commutative0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y + \left(-\log x\right)}, z\right) \]
      12. sub-neg0.0%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y - \log x}, z\right) \]
      13. log-div69.6%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log \left(\frac{y}{x}\right)}, z\right) \]
    3. Simplified69.6%

      \[\leadsto \color{blue}{-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto -\color{blue}{z} \]

    if -2.00000000000000006e-306 < x

    1. Initial program 76.8%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log-div99.5%

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
    4. Applied egg-rr99.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{-198}:\\ \;\;\;\;-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-306}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 67.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.24 \cdot 10^{-54} \lor \neg \left(z \leq 6.2 \cdot 10^{-76}\right):\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;\left(-x\right) \cdot \log \left(\frac{y}{x}\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -1.24e-54) (not (<= z 6.2e-76))) (- z) (* (- x) (log (/ y x)))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.24e-54) || !(z <= 6.2e-76)) {
		tmp = -z;
	} else {
		tmp = -x * log((y / x));
	}
	return tmp;
}
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 ((z <= (-1.24d-54)) .or. (.not. (z <= 6.2d-76))) then
        tmp = -z
    else
        tmp = -x * log((y / x))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.24e-54) || !(z <= 6.2e-76)) {
		tmp = -z;
	} else {
		tmp = -x * Math.log((y / x));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -1.24e-54) or not (z <= 6.2e-76):
		tmp = -z
	else:
		tmp = -x * math.log((y / x))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.24e-54) || !(z <= 6.2e-76))
		tmp = Float64(-z);
	else
		tmp = Float64(Float64(-x) * log(Float64(y / x)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -1.24e-54) || ~((z <= 6.2e-76)))
		tmp = -z;
	else
		tmp = -x * log((y / x));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.24e-54], N[Not[LessEqual[z, 6.2e-76]], $MachinePrecision]], (-z), N[((-x) * N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.24 \cdot 10^{-54} \lor \neg \left(z \leq 6.2 \cdot 10^{-76}\right):\\
\;\;\;\;-z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.23999999999999999e-54 or 6.19999999999999939e-76 < z

    1. Initial program 79.6%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. remove-double-neg79.6%

        \[\leadsto \color{blue}{-\left(-\left(x \cdot \log \left(\frac{x}{y}\right) - z\right)\right)} \]
      2. sub-neg79.6%

        \[\leadsto -\left(-\color{blue}{\left(x \cdot \log \left(\frac{x}{y}\right) + \left(-z\right)\right)}\right) \]
      3. distribute-neg-in79.6%

        \[\leadsto -\color{blue}{\left(\left(-x \cdot \log \left(\frac{x}{y}\right)\right) + \left(-\left(-z\right)\right)\right)} \]
      4. distribute-rgt-neg-in79.6%

        \[\leadsto -\left(\color{blue}{x \cdot \left(-\log \left(\frac{x}{y}\right)\right)} + \left(-\left(-z\right)\right)\right) \]
      5. remove-double-neg79.6%

        \[\leadsto -\left(x \cdot \left(-\log \left(\frac{x}{y}\right)\right) + \color{blue}{z}\right) \]
      6. fma-udef79.6%

        \[\leadsto -\color{blue}{\mathsf{fma}\left(x, -\log \left(\frac{x}{y}\right), z\right)} \]
      7. log-div42.5%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x - \log y\right)}, z\right) \]
      8. sub-neg42.5%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x + \left(-\log y\right)\right)}, z\right) \]
      9. distribute-neg-in42.5%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\left(-\log x\right) + \left(-\left(-\log y\right)\right)}, z\right) \]
      10. remove-double-neg42.5%

        \[\leadsto -\mathsf{fma}\left(x, \left(-\log x\right) + \color{blue}{\log y}, z\right) \]
      11. +-commutative42.5%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y + \left(-\log x\right)}, z\right) \]
      12. sub-neg42.5%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y - \log x}, z\right) \]
      13. log-div79.8%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log \left(\frac{y}{x}\right)}, z\right) \]
    3. Simplified79.8%

      \[\leadsto \color{blue}{-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 77.7%

      \[\leadsto -\color{blue}{z} \]

    if -1.23999999999999999e-54 < z < 6.19999999999999939e-76

    1. Initial program 77.0%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. remove-double-neg77.0%

        \[\leadsto \color{blue}{-\left(-\left(x \cdot \log \left(\frac{x}{y}\right) - z\right)\right)} \]
      2. sub-neg77.0%

        \[\leadsto -\left(-\color{blue}{\left(x \cdot \log \left(\frac{x}{y}\right) + \left(-z\right)\right)}\right) \]
      3. distribute-neg-in77.0%

        \[\leadsto -\color{blue}{\left(\left(-x \cdot \log \left(\frac{x}{y}\right)\right) + \left(-\left(-z\right)\right)\right)} \]
      4. distribute-rgt-neg-in77.0%

        \[\leadsto -\left(\color{blue}{x \cdot \left(-\log \left(\frac{x}{y}\right)\right)} + \left(-\left(-z\right)\right)\right) \]
      5. remove-double-neg77.0%

        \[\leadsto -\left(x \cdot \left(-\log \left(\frac{x}{y}\right)\right) + \color{blue}{z}\right) \]
      6. fma-udef76.9%

        \[\leadsto -\color{blue}{\mathsf{fma}\left(x, -\log \left(\frac{x}{y}\right), z\right)} \]
      7. log-div46.6%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x - \log y\right)}, z\right) \]
      8. sub-neg46.6%

        \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x + \left(-\log y\right)\right)}, z\right) \]
      9. distribute-neg-in46.6%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\left(-\log x\right) + \left(-\left(-\log y\right)\right)}, z\right) \]
      10. remove-double-neg46.6%

        \[\leadsto -\mathsf{fma}\left(x, \left(-\log x\right) + \color{blue}{\log y}, z\right) \]
      11. +-commutative46.6%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y + \left(-\log x\right)}, z\right) \]
      12. sub-neg46.6%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y - \log x}, z\right) \]
      13. log-div77.2%

        \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log \left(\frac{y}{x}\right)}, z\right) \]
    3. Simplified77.2%

      \[\leadsto \color{blue}{-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 39.4%

      \[\leadsto -\color{blue}{x \cdot \left(\log y + \log \left(\frac{1}{x}\right)\right)} \]
    6. Step-by-step derivation
      1. log-rec39.4%

        \[\leadsto -x \cdot \left(\log y + \color{blue}{\left(-\log x\right)}\right) \]
      2. sub-neg39.4%

        \[\leadsto -x \cdot \color{blue}{\left(\log y - \log x\right)} \]
      3. log-div68.8%

        \[\leadsto -x \cdot \color{blue}{\log \left(\frac{y}{x}\right)} \]
    7. Simplified68.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.24 \cdot 10^{-54} \lor \neg \left(z \leq 6.2 \cdot 10^{-76}\right):\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;\left(-x\right) \cdot \log \left(\frac{y}{x}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 50.9% accurate, 53.5× speedup?

\[\begin{array}{l} \\ -z \end{array} \]
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
	return -z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = -z
end function
public static double code(double x, double y, double z) {
	return -z;
}
def code(x, y, z):
	return -z
function code(x, y, z)
	return Float64(-z)
end
function tmp = code(x, y, z)
	tmp = -z;
end
code[x_, y_, z_] := (-z)
\begin{array}{l}

\\
-z
\end{array}
Derivation
  1. Initial program 78.4%

    \[x \cdot \log \left(\frac{x}{y}\right) - z \]
  2. Step-by-step derivation
    1. remove-double-neg78.4%

      \[\leadsto \color{blue}{-\left(-\left(x \cdot \log \left(\frac{x}{y}\right) - z\right)\right)} \]
    2. sub-neg78.4%

      \[\leadsto -\left(-\color{blue}{\left(x \cdot \log \left(\frac{x}{y}\right) + \left(-z\right)\right)}\right) \]
    3. distribute-neg-in78.4%

      \[\leadsto -\color{blue}{\left(\left(-x \cdot \log \left(\frac{x}{y}\right)\right) + \left(-\left(-z\right)\right)\right)} \]
    4. distribute-rgt-neg-in78.4%

      \[\leadsto -\left(\color{blue}{x \cdot \left(-\log \left(\frac{x}{y}\right)\right)} + \left(-\left(-z\right)\right)\right) \]
    5. remove-double-neg78.4%

      \[\leadsto -\left(x \cdot \left(-\log \left(\frac{x}{y}\right)\right) + \color{blue}{z}\right) \]
    6. fma-udef78.4%

      \[\leadsto -\color{blue}{\mathsf{fma}\left(x, -\log \left(\frac{x}{y}\right), z\right)} \]
    7. log-div44.3%

      \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x - \log y\right)}, z\right) \]
    8. sub-neg44.3%

      \[\leadsto -\mathsf{fma}\left(x, -\color{blue}{\left(\log x + \left(-\log y\right)\right)}, z\right) \]
    9. distribute-neg-in44.3%

      \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\left(-\log x\right) + \left(-\left(-\log y\right)\right)}, z\right) \]
    10. remove-double-neg44.3%

      \[\leadsto -\mathsf{fma}\left(x, \left(-\log x\right) + \color{blue}{\log y}, z\right) \]
    11. +-commutative44.3%

      \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y + \left(-\log x\right)}, z\right) \]
    12. sub-neg44.3%

      \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log y - \log x}, z\right) \]
    13. log-div78.6%

      \[\leadsto -\mathsf{fma}\left(x, \color{blue}{\log \left(\frac{y}{x}\right)}, z\right) \]
  3. Simplified78.6%

    \[\leadsto \color{blue}{-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 50.4%

    \[\leadsto -\color{blue}{z} \]
  6. Final simplification50.4%

    \[\leadsto -z \]
  7. Add Preprocessing

Developer target: 89.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \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} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (< y 7.595077799083773e-308)
   (- (* x (log (/ x y))) z)
   (- (* x (- (log x) (log y))) z)))
double code(double x, double y, double z) {
	double tmp;
	if (y < 7.595077799083773e-308) {
		tmp = (x * log((x / 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
    real(8) :: tmp
    if (y < 7.595077799083773d-308) then
        tmp = (x * log((x / 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) {
	double tmp;
	if (y < 7.595077799083773e-308) {
		tmp = (x * Math.log((x / y))) - z;
	} else {
		tmp = (x * (Math.log(x) - Math.log(y))) - z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y < 7.595077799083773e-308:
		tmp = (x * math.log((x / y))) - z
	else:
		tmp = (x * (math.log(x) - math.log(y))) - z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y < 7.595077799083773e-308)
		tmp = Float64(Float64(x * log(Float64(x / y))) - z);
	else
		tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y < 7.595077799083773e-308)
		tmp = (x * log((x / y))) - z;
	else
		tmp = (x * (log(x) - log(y))) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Less[y, 7.595077799083773e-308], N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}

\\
\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}
\end{array}

Reproduce

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