Numeric.SpecFunctions:choose from math-functions-0.1.5.2

Percentage Accurate: 83.9% → 97.8%
Time: 7.5s
Alternatives: 8
Speedup: 0.6×

Specification

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

\\
\frac{x \cdot \left(y + z\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 8 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: 83.9% accurate, 1.0× speedup?

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

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

Alternative 1: 97.8% accurate, 0.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;x\_m \leq 1.6 \cdot 10^{-48}:\\ \;\;\;\;x\_m + \frac{1}{\frac{z}{x\_m \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x\_m, \frac{y}{z}, x\_m\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= x_m 1.6e-48) (+ x_m (/ 1.0 (/ z (* x_m y)))) (fma x_m (/ y z) x_m))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 1.6e-48) {
		tmp = x_m + (1.0 / (z / (x_m * y)));
	} else {
		tmp = fma(x_m, (y / z), x_m);
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (x_m <= 1.6e-48)
		tmp = Float64(x_m + Float64(1.0 / Float64(z / Float64(x_m * y))));
	else
		tmp = fma(x_m, Float64(y / z), x_m);
	end
	return Float64(x_s * tmp)
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 1.6e-48], N[(x$95$m + N[(1.0 / N[(z / N[(x$95$m * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m * N[(y / z), $MachinePrecision] + x$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 1.6 \cdot 10^{-48}:\\
\;\;\;\;x\_m + \frac{1}{\frac{z}{x\_m \cdot y}}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, \frac{y}{z}, x\_m\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.5999999999999999e-48

    1. Initial program 86.4%

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

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

        \[\leadsto \frac{-\color{blue}{\left(-x\right) \cdot \left(y + z\right)}}{z} \]
      3. *-commutative86.4%

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

        \[\leadsto \frac{\color{blue}{\left(-\left(y + z\right)\right) \cdot \left(-x\right)}}{z} \]
      5. associate-/l*83.4%

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

        \[\leadsto \frac{\color{blue}{\left(-y\right) + \left(-z\right)}}{\frac{z}{-x}} \]
      7. unsub-neg83.4%

        \[\leadsto \frac{\color{blue}{\left(-y\right) - z}}{\frac{z}{-x}} \]
      8. div-sub80.3%

        \[\leadsto \color{blue}{\frac{-y}{\frac{z}{-x}} - \frac{z}{\frac{z}{-x}}} \]
      9. distribute-frac-neg80.3%

        \[\leadsto \color{blue}{\left(-\frac{y}{\frac{z}{-x}}\right)} - \frac{z}{\frac{z}{-x}} \]
      10. associate-/r/74.9%

        \[\leadsto \left(-\color{blue}{\frac{y}{z} \cdot \left(-x\right)}\right) - \frac{z}{\frac{z}{-x}} \]
      11. distribute-rgt-neg-out74.9%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot \left(-\left(-x\right)\right)} - \frac{z}{\frac{z}{-x}} \]
      12. remove-double-neg74.9%

        \[\leadsto \frac{y}{z} \cdot \color{blue}{x} - \frac{z}{\frac{z}{-x}} \]
      13. associate-/r/90.6%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\frac{z}{z} \cdot \left(-x\right)} \]
      14. *-inverses90.6%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{1} \cdot \left(-x\right) \]
      15. *-lft-identity90.6%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\left(-x\right)} \]
      16. *-commutative90.6%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, -\left(-x\right)\right)} \]
      18. remove-double-neg90.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-udef90.6%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
    6. Applied egg-rr90.6%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
    7. Step-by-step derivation
      1. associate-*r/92.3%

        \[\leadsto \color{blue}{\frac{x \cdot y}{z}} + x \]
      2. clear-num92.3%

        \[\leadsto \color{blue}{\frac{1}{\frac{z}{x \cdot y}}} + x \]
    8. Applied egg-rr92.3%

      \[\leadsto \color{blue}{\frac{1}{\frac{z}{x \cdot y}}} + x \]

    if 1.5999999999999999e-48 < x

    1. Initial program 70.9%

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

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

        \[\leadsto \frac{-\color{blue}{\left(-x\right) \cdot \left(y + z\right)}}{z} \]
      3. *-commutative70.9%

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

        \[\leadsto \frac{\color{blue}{\left(-\left(y + z\right)\right) \cdot \left(-x\right)}}{z} \]
      5. associate-/l*94.3%

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

        \[\leadsto \frac{\color{blue}{\left(-y\right) + \left(-z\right)}}{\frac{z}{-x}} \]
      7. unsub-neg94.3%

        \[\leadsto \frac{\color{blue}{\left(-y\right) - z}}{\frac{z}{-x}} \]
      8. div-sub89.3%

        \[\leadsto \color{blue}{\frac{-y}{\frac{z}{-x}} - \frac{z}{\frac{z}{-x}}} \]
      9. distribute-frac-neg89.3%

        \[\leadsto \color{blue}{\left(-\frac{y}{\frac{z}{-x}}\right)} - \frac{z}{\frac{z}{-x}} \]
      10. associate-/r/90.0%

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

        \[\leadsto \color{blue}{\frac{y}{z} \cdot \left(-\left(-x\right)\right)} - \frac{z}{\frac{z}{-x}} \]
      12. remove-double-neg90.0%

        \[\leadsto \frac{y}{z} \cdot \color{blue}{x} - \frac{z}{\frac{z}{-x}} \]
      13. associate-/r/99.8%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\frac{z}{z} \cdot \left(-x\right)} \]
      14. *-inverses99.8%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{1} \cdot \left(-x\right) \]
      15. *-lft-identity99.8%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\left(-x\right)} \]
      16. *-commutative99.8%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z}} - \left(-x\right) \]
      17. fma-neg99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, -\left(-x\right)\right)} \]
      18. remove-double-neg99.9%

        \[\leadsto \mathsf{fma}\left(x, \frac{y}{z}, \color{blue}{x}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    4. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification94.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.6 \cdot 10^{-48}:\\ \;\;\;\;x + \frac{1}{\frac{z}{x \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.2% accurate, 0.4× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;z \leq -1.45 \cdot 10^{-61} \lor \neg \left(z \leq 2.5 \cdot 10^{-7}\right):\\ \;\;\;\;x\_m + x\_m \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(z + y\right) \cdot \frac{x\_m}{z}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (or (<= z -1.45e-61) (not (<= z 2.5e-7)))
    (+ x_m (* x_m (/ y z)))
    (* (+ z y) (/ x_m z)))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((z <= -1.45e-61) || !(z <= 2.5e-7)) {
		tmp = x_m + (x_m * (y / z));
	} else {
		tmp = (z + y) * (x_m / z);
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-1.45d-61)) .or. (.not. (z <= 2.5d-7))) then
        tmp = x_m + (x_m * (y / z))
    else
        tmp = (z + y) * (x_m / z)
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((z <= -1.45e-61) || !(z <= 2.5e-7)) {
		tmp = x_m + (x_m * (y / z));
	} else {
		tmp = (z + y) * (x_m / z);
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if (z <= -1.45e-61) or not (z <= 2.5e-7):
		tmp = x_m + (x_m * (y / z))
	else:
		tmp = (z + y) * (x_m / z)
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if ((z <= -1.45e-61) || !(z <= 2.5e-7))
		tmp = Float64(x_m + Float64(x_m * Float64(y / z)));
	else
		tmp = Float64(Float64(z + y) * Float64(x_m / z));
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if ((z <= -1.45e-61) || ~((z <= 2.5e-7)))
		tmp = x_m + (x_m * (y / z));
	else
		tmp = (z + y) * (x_m / z);
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[Or[LessEqual[z, -1.45e-61], N[Not[LessEqual[z, 2.5e-7]], $MachinePrecision]], N[(x$95$m + N[(x$95$m * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z + y), $MachinePrecision] * N[(x$95$m / z), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{-61} \lor \neg \left(z \leq 2.5 \cdot 10^{-7}\right):\\
\;\;\;\;x\_m + x\_m \cdot \frac{y}{z}\\

\mathbf{else}:\\
\;\;\;\;\left(z + y\right) \cdot \frac{x\_m}{z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.45e-61 or 2.49999999999999989e-7 < z

    1. Initial program 78.0%

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

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

        \[\leadsto \frac{-\color{blue}{\left(-x\right) \cdot \left(y + z\right)}}{z} \]
      3. *-commutative78.0%

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

        \[\leadsto \frac{\color{blue}{\left(-\left(y + z\right)\right) \cdot \left(-x\right)}}{z} \]
      5. associate-/l*79.1%

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

        \[\leadsto \frac{\color{blue}{\left(-y\right) + \left(-z\right)}}{\frac{z}{-x}} \]
      7. unsub-neg79.1%

        \[\leadsto \frac{\color{blue}{\left(-y\right) - z}}{\frac{z}{-x}} \]
      8. div-sub78.4%

        \[\leadsto \color{blue}{\frac{-y}{\frac{z}{-x}} - \frac{z}{\frac{z}{-x}}} \]
      9. distribute-frac-neg78.4%

        \[\leadsto \color{blue}{\left(-\frac{y}{\frac{z}{-x}}\right)} - \frac{z}{\frac{z}{-x}} \]
      10. associate-/r/83.5%

        \[\leadsto \left(-\color{blue}{\frac{y}{z} \cdot \left(-x\right)}\right) - \frac{z}{\frac{z}{-x}} \]
      11. distribute-rgt-neg-out83.5%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot \left(-\left(-x\right)\right)} - \frac{z}{\frac{z}{-x}} \]
      12. remove-double-neg83.5%

        \[\leadsto \frac{y}{z} \cdot \color{blue}{x} - \frac{z}{\frac{z}{-x}} \]
      13. associate-/r/99.8%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\frac{z}{z} \cdot \left(-x\right)} \]
      14. *-inverses99.8%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{1} \cdot \left(-x\right) \]
      15. *-lft-identity99.8%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\left(-x\right)} \]
      16. *-commutative99.8%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z}} - \left(-x\right) \]
      17. fma-neg99.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, -\left(-x\right)\right)} \]
      18. remove-double-neg99.8%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-udef99.8%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
    6. Applied egg-rr99.8%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]

    if -1.45e-61 < z < 2.49999999999999989e-7

    1. Initial program 88.8%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/93.9%

        \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
      2. *-commutative93.9%

        \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    3. Simplified93.9%

      \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    4. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification97.3%

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

Alternative 3: 90.2% accurate, 0.4× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;z \leq -4.6 \cdot 10^{+164}:\\ \;\;\;\;x\_m\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{+146}:\\ \;\;\;\;\left(z + y\right) \cdot \frac{x\_m}{z}\\ \mathbf{else}:\\ \;\;\;\;x\_m\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= z -4.6e+164) x_m (if (<= z 2.4e+146) (* (+ z y) (/ x_m z)) x_m))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (z <= -4.6e+164) {
		tmp = x_m;
	} else if (z <= 2.4e+146) {
		tmp = (z + y) * (x_m / z);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-4.6d+164)) then
        tmp = x_m
    else if (z <= 2.4d+146) then
        tmp = (z + y) * (x_m / z)
    else
        tmp = x_m
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (z <= -4.6e+164) {
		tmp = x_m;
	} else if (z <= 2.4e+146) {
		tmp = (z + y) * (x_m / z);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if z <= -4.6e+164:
		tmp = x_m
	elif z <= 2.4e+146:
		tmp = (z + y) * (x_m / z)
	else:
		tmp = x_m
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (z <= -4.6e+164)
		tmp = x_m;
	elseif (z <= 2.4e+146)
		tmp = Float64(Float64(z + y) * Float64(x_m / z));
	else
		tmp = x_m;
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (z <= -4.6e+164)
		tmp = x_m;
	elseif (z <= 2.4e+146)
		tmp = (z + y) * (x_m / z);
	else
		tmp = x_m;
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, -4.6e+164], x$95$m, If[LessEqual[z, 2.4e+146], N[(N[(z + y), $MachinePrecision] * N[(x$95$m / z), $MachinePrecision]), $MachinePrecision], x$95$m]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+164}:\\
\;\;\;\;x\_m\\

\mathbf{elif}\;z \leq 2.4 \cdot 10^{+146}:\\
\;\;\;\;\left(z + y\right) \cdot \frac{x\_m}{z}\\

\mathbf{else}:\\
\;\;\;\;x\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -4.5999999999999999e164 or 2.4000000000000002e146 < z

    1. Initial program 66.3%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/64.2%

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

        \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    3. Simplified64.2%

      \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 86.2%

      \[\leadsto \color{blue}{x} \]

    if -4.5999999999999999e164 < z < 2.4000000000000002e146

    1. Initial program 88.1%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/93.6%

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

        \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    3. Simplified93.6%

      \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    4. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification91.8%

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

Alternative 4: 73.0% accurate, 0.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{-19}:\\ \;\;\;\;x\_m\\ \mathbf{elif}\;z \leq 2.75 \cdot 10^{+63}:\\ \;\;\;\;y \cdot \frac{x\_m}{z}\\ \mathbf{else}:\\ \;\;\;\;x\_m\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m y z)
 :precision binary64
 (* x_s (if (<= z -7.8e-19) x_m (if (<= z 2.75e+63) (* y (/ x_m z)) x_m))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (z <= -7.8e-19) {
		tmp = x_m;
	} else if (z <= 2.75e+63) {
		tmp = y * (x_m / z);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-7.8d-19)) then
        tmp = x_m
    else if (z <= 2.75d+63) then
        tmp = y * (x_m / z)
    else
        tmp = x_m
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (z <= -7.8e-19) {
		tmp = x_m;
	} else if (z <= 2.75e+63) {
		tmp = y * (x_m / z);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if z <= -7.8e-19:
		tmp = x_m
	elif z <= 2.75e+63:
		tmp = y * (x_m / z)
	else:
		tmp = x_m
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (z <= -7.8e-19)
		tmp = x_m;
	elseif (z <= 2.75e+63)
		tmp = Float64(y * Float64(x_m / z));
	else
		tmp = x_m;
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (z <= -7.8e-19)
		tmp = x_m;
	elseif (z <= 2.75e+63)
		tmp = y * (x_m / z);
	else
		tmp = x_m;
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, -7.8e-19], x$95$m, If[LessEqual[z, 2.75e+63], N[(y * N[(x$95$m / z), $MachinePrecision]), $MachinePrecision], x$95$m]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -7.8 \cdot 10^{-19}:\\
\;\;\;\;x\_m\\

\mathbf{elif}\;z \leq 2.75 \cdot 10^{+63}:\\
\;\;\;\;y \cdot \frac{x\_m}{z}\\

\mathbf{else}:\\
\;\;\;\;x\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -7.7999999999999999e-19 or 2.75000000000000002e63 < z

    1. Initial program 74.2%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/77.3%

        \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
      2. *-commutative77.3%

        \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    3. Simplified77.3%

      \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 74.0%

      \[\leadsto \color{blue}{x} \]

    if -7.7999999999999999e-19 < z < 2.75000000000000002e63

    1. Initial program 90.2%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/94.1%

        \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
      2. *-commutative94.1%

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

      \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 78.2%

      \[\leadsto \color{blue}{\frac{x \cdot y}{z}} \]
    6. Step-by-step derivation
      1. associate-*l/78.2%

        \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
      2. *-commutative78.2%

        \[\leadsto \color{blue}{y \cdot \frac{x}{z}} \]
    7. Simplified78.2%

      \[\leadsto \color{blue}{y \cdot \frac{x}{z}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{-19}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.75 \cdot 10^{+63}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 73.1% accurate, 0.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{-19}:\\ \;\;\;\;x\_m\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+64}:\\ \;\;\;\;\frac{y}{\frac{z}{x\_m}}\\ \mathbf{else}:\\ \;\;\;\;x\_m\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m y z)
 :precision binary64
 (* x_s (if (<= z -7.8e-19) x_m (if (<= z 1.45e+64) (/ y (/ z x_m)) x_m))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (z <= -7.8e-19) {
		tmp = x_m;
	} else if (z <= 1.45e+64) {
		tmp = y / (z / x_m);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-7.8d-19)) then
        tmp = x_m
    else if (z <= 1.45d+64) then
        tmp = y / (z / x_m)
    else
        tmp = x_m
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (z <= -7.8e-19) {
		tmp = x_m;
	} else if (z <= 1.45e+64) {
		tmp = y / (z / x_m);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if z <= -7.8e-19:
		tmp = x_m
	elif z <= 1.45e+64:
		tmp = y / (z / x_m)
	else:
		tmp = x_m
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (z <= -7.8e-19)
		tmp = x_m;
	elseif (z <= 1.45e+64)
		tmp = Float64(y / Float64(z / x_m));
	else
		tmp = x_m;
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (z <= -7.8e-19)
		tmp = x_m;
	elseif (z <= 1.45e+64)
		tmp = y / (z / x_m);
	else
		tmp = x_m;
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, -7.8e-19], x$95$m, If[LessEqual[z, 1.45e+64], N[(y / N[(z / x$95$m), $MachinePrecision]), $MachinePrecision], x$95$m]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -7.8 \cdot 10^{-19}:\\
\;\;\;\;x\_m\\

\mathbf{elif}\;z \leq 1.45 \cdot 10^{+64}:\\
\;\;\;\;\frac{y}{\frac{z}{x\_m}}\\

\mathbf{else}:\\
\;\;\;\;x\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -7.7999999999999999e-19 or 1.44999999999999997e64 < z

    1. Initial program 74.2%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/77.3%

        \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
      2. *-commutative77.3%

        \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    3. Simplified77.3%

      \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 74.0%

      \[\leadsto \color{blue}{x} \]

    if -7.7999999999999999e-19 < z < 1.44999999999999997e64

    1. Initial program 90.2%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/94.1%

        \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
      2. *-commutative94.1%

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

      \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 78.2%

      \[\leadsto \color{blue}{\frac{x \cdot y}{z}} \]
    6. Step-by-step derivation
      1. associate-/l*70.0%

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} \]
    7. Simplified70.0%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} \]
    8. Step-by-step derivation
      1. associate-/l*78.2%

        \[\leadsto \color{blue}{\frac{x \cdot y}{z}} \]
      2. associate-*r/70.0%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z}} \]
      3. *-commutative70.0%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
    9. Applied egg-rr70.0%

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
    10. Step-by-step derivation
      1. associate-/r/78.8%

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
    11. Applied egg-rr78.8%

      \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{-19}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+64}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 97.9% accurate, 0.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;x\_m \leq 10^{-46}:\\ \;\;\;\;x\_m + \frac{1}{\frac{z}{x\_m \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;x\_m + x\_m \cdot \frac{y}{z}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= x_m 1e-46) (+ x_m (/ 1.0 (/ z (* x_m y)))) (+ x_m (* x_m (/ y z))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 1e-46) {
		tmp = x_m + (1.0 / (z / (x_m * y)));
	} else {
		tmp = x_m + (x_m * (y / z));
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x_m <= 1d-46) then
        tmp = x_m + (1.0d0 / (z / (x_m * y)))
    else
        tmp = x_m + (x_m * (y / z))
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 1e-46) {
		tmp = x_m + (1.0 / (z / (x_m * y)));
	} else {
		tmp = x_m + (x_m * (y / z));
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if x_m <= 1e-46:
		tmp = x_m + (1.0 / (z / (x_m * y)))
	else:
		tmp = x_m + (x_m * (y / z))
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (x_m <= 1e-46)
		tmp = Float64(x_m + Float64(1.0 / Float64(z / Float64(x_m * y))));
	else
		tmp = Float64(x_m + Float64(x_m * Float64(y / z)));
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (x_m <= 1e-46)
		tmp = x_m + (1.0 / (z / (x_m * y)));
	else
		tmp = x_m + (x_m * (y / z));
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 1e-46], N[(x$95$m + N[(1.0 / N[(z / N[(x$95$m * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m + N[(x$95$m * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 10^{-46}:\\
\;\;\;\;x\_m + \frac{1}{\frac{z}{x\_m \cdot y}}\\

\mathbf{else}:\\
\;\;\;\;x\_m + x\_m \cdot \frac{y}{z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.00000000000000002e-46

    1. Initial program 86.4%

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

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

        \[\leadsto \frac{-\color{blue}{\left(-x\right) \cdot \left(y + z\right)}}{z} \]
      3. *-commutative86.4%

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

        \[\leadsto \frac{\color{blue}{\left(-\left(y + z\right)\right) \cdot \left(-x\right)}}{z} \]
      5. associate-/l*83.4%

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

        \[\leadsto \frac{\color{blue}{\left(-y\right) + \left(-z\right)}}{\frac{z}{-x}} \]
      7. unsub-neg83.4%

        \[\leadsto \frac{\color{blue}{\left(-y\right) - z}}{\frac{z}{-x}} \]
      8. div-sub80.3%

        \[\leadsto \color{blue}{\frac{-y}{\frac{z}{-x}} - \frac{z}{\frac{z}{-x}}} \]
      9. distribute-frac-neg80.3%

        \[\leadsto \color{blue}{\left(-\frac{y}{\frac{z}{-x}}\right)} - \frac{z}{\frac{z}{-x}} \]
      10. associate-/r/74.9%

        \[\leadsto \left(-\color{blue}{\frac{y}{z} \cdot \left(-x\right)}\right) - \frac{z}{\frac{z}{-x}} \]
      11. distribute-rgt-neg-out74.9%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot \left(-\left(-x\right)\right)} - \frac{z}{\frac{z}{-x}} \]
      12. remove-double-neg74.9%

        \[\leadsto \frac{y}{z} \cdot \color{blue}{x} - \frac{z}{\frac{z}{-x}} \]
      13. associate-/r/90.6%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\frac{z}{z} \cdot \left(-x\right)} \]
      14. *-inverses90.6%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{1} \cdot \left(-x\right) \]
      15. *-lft-identity90.6%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\left(-x\right)} \]
      16. *-commutative90.6%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, -\left(-x\right)\right)} \]
      18. remove-double-neg90.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-udef90.6%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
    6. Applied egg-rr90.6%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
    7. Step-by-step derivation
      1. associate-*r/92.3%

        \[\leadsto \color{blue}{\frac{x \cdot y}{z}} + x \]
      2. clear-num92.3%

        \[\leadsto \color{blue}{\frac{1}{\frac{z}{x \cdot y}}} + x \]
    8. Applied egg-rr92.3%

      \[\leadsto \color{blue}{\frac{1}{\frac{z}{x \cdot y}}} + x \]

    if 1.00000000000000002e-46 < x

    1. Initial program 70.9%

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

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

        \[\leadsto \frac{-\color{blue}{\left(-x\right) \cdot \left(y + z\right)}}{z} \]
      3. *-commutative70.9%

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

        \[\leadsto \frac{\color{blue}{\left(-\left(y + z\right)\right) \cdot \left(-x\right)}}{z} \]
      5. associate-/l*94.3%

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

        \[\leadsto \frac{\color{blue}{\left(-y\right) + \left(-z\right)}}{\frac{z}{-x}} \]
      7. unsub-neg94.3%

        \[\leadsto \frac{\color{blue}{\left(-y\right) - z}}{\frac{z}{-x}} \]
      8. div-sub89.3%

        \[\leadsto \color{blue}{\frac{-y}{\frac{z}{-x}} - \frac{z}{\frac{z}{-x}}} \]
      9. distribute-frac-neg89.3%

        \[\leadsto \color{blue}{\left(-\frac{y}{\frac{z}{-x}}\right)} - \frac{z}{\frac{z}{-x}} \]
      10. associate-/r/90.0%

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

        \[\leadsto \color{blue}{\frac{y}{z} \cdot \left(-\left(-x\right)\right)} - \frac{z}{\frac{z}{-x}} \]
      12. remove-double-neg90.0%

        \[\leadsto \frac{y}{z} \cdot \color{blue}{x} - \frac{z}{\frac{z}{-x}} \]
      13. associate-/r/99.8%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\frac{z}{z} \cdot \left(-x\right)} \]
      14. *-inverses99.8%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{1} \cdot \left(-x\right) \]
      15. *-lft-identity99.8%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\left(-x\right)} \]
      16. *-commutative99.8%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z}} - \left(-x\right) \]
      17. fma-neg99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, -\left(-x\right)\right)} \]
      18. remove-double-neg99.9%

        \[\leadsto \mathsf{fma}\left(x, \frac{y}{z}, \color{blue}{x}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-udef99.8%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
    6. Applied egg-rr99.8%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 10^{-46}:\\ \;\;\;\;x + \frac{1}{\frac{z}{x \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 97.0% accurate, 0.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;x\_m \leq 2.1 \cdot 10^{-127}:\\ \;\;\;\;x\_m + \frac{y}{\frac{z}{x\_m}}\\ \mathbf{else}:\\ \;\;\;\;x\_m + x\_m \cdot \frac{y}{z}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= x_m 2.1e-127) (+ x_m (/ y (/ z x_m))) (+ x_m (* x_m (/ y z))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 2.1e-127) {
		tmp = x_m + (y / (z / x_m));
	} else {
		tmp = x_m + (x_m * (y / z));
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x_m <= 2.1d-127) then
        tmp = x_m + (y / (z / x_m))
    else
        tmp = x_m + (x_m * (y / z))
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 2.1e-127) {
		tmp = x_m + (y / (z / x_m));
	} else {
		tmp = x_m + (x_m * (y / z));
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if x_m <= 2.1e-127:
		tmp = x_m + (y / (z / x_m))
	else:
		tmp = x_m + (x_m * (y / z))
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (x_m <= 2.1e-127)
		tmp = Float64(x_m + Float64(y / Float64(z / x_m)));
	else
		tmp = Float64(x_m + Float64(x_m * Float64(y / z)));
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (x_m <= 2.1e-127)
		tmp = x_m + (y / (z / x_m));
	else
		tmp = x_m + (x_m * (y / z));
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 2.1e-127], N[(x$95$m + N[(y / N[(z / x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m + N[(x$95$m * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 2.1 \cdot 10^{-127}:\\
\;\;\;\;x\_m + \frac{y}{\frac{z}{x\_m}}\\

\mathbf{else}:\\
\;\;\;\;x\_m + x\_m \cdot \frac{y}{z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2.1000000000000001e-127

    1. Initial program 85.3%

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

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

        \[\leadsto \frac{-\color{blue}{\left(-x\right) \cdot \left(y + z\right)}}{z} \]
      3. *-commutative85.3%

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

        \[\leadsto \frac{\color{blue}{\left(-\left(y + z\right)\right) \cdot \left(-x\right)}}{z} \]
      5. associate-/l*83.7%

        \[\leadsto \color{blue}{\frac{-\left(y + z\right)}{\frac{z}{-x}}} \]
      6. distribute-neg-in83.7%

        \[\leadsto \frac{\color{blue}{\left(-y\right) + \left(-z\right)}}{\frac{z}{-x}} \]
      7. unsub-neg83.7%

        \[\leadsto \frac{\color{blue}{\left(-y\right) - z}}{\frac{z}{-x}} \]
      8. div-sub80.4%

        \[\leadsto \color{blue}{\frac{-y}{\frac{z}{-x}} - \frac{z}{\frac{z}{-x}}} \]
      9. distribute-frac-neg80.4%

        \[\leadsto \color{blue}{\left(-\frac{y}{\frac{z}{-x}}\right)} - \frac{z}{\frac{z}{-x}} \]
      10. associate-/r/75.1%

        \[\leadsto \left(-\color{blue}{\frac{y}{z} \cdot \left(-x\right)}\right) - \frac{z}{\frac{z}{-x}} \]
      11. distribute-rgt-neg-out75.1%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot \left(-\left(-x\right)\right)} - \frac{z}{\frac{z}{-x}} \]
      12. remove-double-neg75.1%

        \[\leadsto \frac{y}{z} \cdot \color{blue}{x} - \frac{z}{\frac{z}{-x}} \]
      13. associate-/r/90.4%

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

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{1} \cdot \left(-x\right) \]
      15. *-lft-identity90.4%

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

        \[\leadsto \color{blue}{x \cdot \frac{y}{z}} - \left(-x\right) \]
      17. fma-neg90.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, -\left(-x\right)\right)} \]
      18. remove-double-neg90.4%

        \[\leadsto \mathsf{fma}\left(x, \frac{y}{z}, \color{blue}{x}\right) \]
    3. Simplified90.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-udef90.4%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
    6. Applied egg-rr90.4%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
    7. Step-by-step derivation
      1. associate-*r/91.7%

        \[\leadsto \color{blue}{\frac{x \cdot y}{z}} + x \]
      2. *-commutative91.7%

        \[\leadsto \frac{\color{blue}{y \cdot x}}{z} + x \]
      3. associate-/l*94.1%

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} + x \]
    8. Applied egg-rr94.1%

      \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} + x \]

    if 2.1000000000000001e-127 < x

    1. Initial program 76.3%

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

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

        \[\leadsto \frac{-\color{blue}{\left(-x\right) \cdot \left(y + z\right)}}{z} \]
      3. *-commutative76.3%

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

        \[\leadsto \frac{\color{blue}{\left(-\left(y + z\right)\right) \cdot \left(-x\right)}}{z} \]
      5. associate-/l*91.5%

        \[\leadsto \color{blue}{\frac{-\left(y + z\right)}{\frac{z}{-x}}} \]
      6. distribute-neg-in91.5%

        \[\leadsto \frac{\color{blue}{\left(-y\right) + \left(-z\right)}}{\frac{z}{-x}} \]
      7. unsub-neg91.5%

        \[\leadsto \frac{\color{blue}{\left(-y\right) - z}}{\frac{z}{-x}} \]
      8. div-sub87.4%

        \[\leadsto \color{blue}{\frac{-y}{\frac{z}{-x}} - \frac{z}{\frac{z}{-x}}} \]
      9. distribute-frac-neg87.4%

        \[\leadsto \color{blue}{\left(-\frac{y}{\frac{z}{-x}}\right)} - \frac{z}{\frac{z}{-x}} \]
      10. associate-/r/86.8%

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

        \[\leadsto \color{blue}{\frac{y}{z} \cdot \left(-\left(-x\right)\right)} - \frac{z}{\frac{z}{-x}} \]
      12. remove-double-neg86.8%

        \[\leadsto \frac{y}{z} \cdot \color{blue}{x} - \frac{z}{\frac{z}{-x}} \]
      13. associate-/r/98.6%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\frac{z}{z} \cdot \left(-x\right)} \]
      14. *-inverses98.6%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{1} \cdot \left(-x\right) \]
      15. *-lft-identity98.6%

        \[\leadsto \frac{y}{z} \cdot x - \color{blue}{\left(-x\right)} \]
      16. *-commutative98.6%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, -\left(-x\right)\right)} \]
      18. remove-double-neg98.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-udef98.6%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
    6. Applied egg-rr98.6%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.1 \cdot 10^{-127}:\\ \;\;\;\;x + \frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 51.1% accurate, 7.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot x\_m \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m y z) :precision binary64 (* x_s x_m))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	return x_s * x_m;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x_s * x_m
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	return x_s * x_m;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	return x_s * x_m
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	return Float64(x_s * x_m)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp = code(x_s, x_m, y, z)
	tmp = x_s * x_m;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * x$95$m), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x\_s \cdot x\_m
\end{array}
Derivation
  1. Initial program 82.7%

    \[\frac{x \cdot \left(y + z\right)}{z} \]
  2. Step-by-step derivation
    1. associate-*l/86.3%

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    2. *-commutative86.3%

      \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
  3. Simplified86.3%

    \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
  4. Add Preprocessing
  5. Taylor expanded in y around 0 44.5%

    \[\leadsto \color{blue}{x} \]
  6. Final simplification44.5%

    \[\leadsto x \]
  7. Add Preprocessing

Developer target: 96.4% accurate, 1.0× speedup?

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

\\
\frac{x}{\frac{z}{y + z}}
\end{array}

Reproduce

?
herbie shell --seed 2024096 
(FPCore (x y z)
  :name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (/ x (/ z (+ y z)))

  (/ (* x (+ y z)) z))