Numeric.SpecFunctions:choose from math-functions-0.1.5.2

Percentage Accurate: 84.4% → 97.1%
Time: 4.2s
Alternatives: 7
Speedup: 0.4×

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 7 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: 84.4% 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.1% 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}\;\frac{x\_m \cdot \left(y + z\right)}{z} \leq -5 \cdot 10^{+35}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x\_m}{z}\\ \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 (+ y z)) z) -5e+35)
    (* (+ y z) (/ x_m z))
    (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 * (y + z)) / z) <= -5e+35) {
		tmp = (y + z) * (x_m / z);
	} 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 (Float64(Float64(x_m * Float64(y + z)) / z) <= -5e+35)
		tmp = Float64(Float64(y + z) * Float64(x_m / z));
	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[N[(N[(x$95$m * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], -5e+35], N[(N[(y + z), $MachinePrecision] * N[(x$95$m / z), $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}\;\frac{x\_m \cdot \left(y + z\right)}{z} \leq -5 \cdot 10^{+35}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x\_m}{z}\\

\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 (/.f64 (*.f64 x (+.f64 y z)) z) < -5.00000000000000021e35

    1. Initial program 79.4%

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

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

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

      \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    4. Add Preprocessing

    if -5.00000000000000021e35 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 85.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 96.0% accurate, 0.2× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ \begin{array}{l} t_0 := \frac{x\_m \cdot \left(y + z\right)}{z}\\ x\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq 10^{+234}\right):\\ \;\;\;\;\left(y + z\right) \cdot \frac{x\_m}{z}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m y z)
 :precision binary64
 (let* ((t_0 (/ (* x_m (+ y z)) z)))
   (*
    x_s
    (if (or (<= t_0 0.0) (not (<= t_0 1e+234))) (* (+ y z) (/ x_m z)) t_0))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double t_0 = (x_m * (y + z)) / z;
	double tmp;
	if ((t_0 <= 0.0) || !(t_0 <= 1e+234)) {
		tmp = (y + z) * (x_m / z);
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (x_m * (y + z)) / z
    if ((t_0 <= 0.0d0) .or. (.not. (t_0 <= 1d+234))) then
        tmp = (y + z) * (x_m / z)
    else
        tmp = t_0
    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 t_0 = (x_m * (y + z)) / z;
	double tmp;
	if ((t_0 <= 0.0) || !(t_0 <= 1e+234)) {
		tmp = (y + z) * (x_m / z);
	} else {
		tmp = t_0;
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	t_0 = (x_m * (y + z)) / z
	tmp = 0
	if (t_0 <= 0.0) or not (t_0 <= 1e+234):
		tmp = (y + z) * (x_m / z)
	else:
		tmp = t_0
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	t_0 = Float64(Float64(x_m * Float64(y + z)) / z)
	tmp = 0.0
	if ((t_0 <= 0.0) || !(t_0 <= 1e+234))
		tmp = Float64(Float64(y + z) * Float64(x_m / z));
	else
		tmp = t_0;
	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)
	t_0 = (x_m * (y + z)) / z;
	tmp = 0.0;
	if ((t_0 <= 0.0) || ~((t_0 <= 1e+234)))
		tmp = (y + z) * (x_m / z);
	else
		tmp = t_0;
	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_] := Block[{t$95$0 = N[(N[(x$95$m * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, N[(x$95$s * If[Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, 1e+234]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * N[(x$95$m / z), $MachinePrecision]), $MachinePrecision], t$95$0]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
\begin{array}{l}
t_0 := \frac{x\_m \cdot \left(y + z\right)}{z}\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq 10^{+234}\right):\\
\;\;\;\;\left(y + z\right) \cdot \frac{x\_m}{z}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < 0.0 or 1.00000000000000002e234 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 75.6%

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

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

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

      \[\leadsto \color{blue}{\left(y + z\right) \cdot \frac{x}{z}} \]
    4. Add Preprocessing

    if 0.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1.00000000000000002e234

    1. Initial program 99.5%

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

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

Alternative 3: 89.5% 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 -3.9 \cdot 10^{+214}:\\ \;\;\;\;x\_m\\ \mathbf{elif}\;z \leq 1.18 \cdot 10^{+145}:\\ \;\;\;\;\left(y + z\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 -3.9e+214) x_m (if (<= z 1.18e+145) (* (+ y z) (/ 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 <= -3.9e+214) {
		tmp = x_m;
	} else if (z <= 1.18e+145) {
		tmp = (y + z) * (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 <= (-3.9d+214)) then
        tmp = x_m
    else if (z <= 1.18d+145) then
        tmp = (y + z) * (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 <= -3.9e+214) {
		tmp = x_m;
	} else if (z <= 1.18e+145) {
		tmp = (y + z) * (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 <= -3.9e+214:
		tmp = x_m
	elif z <= 1.18e+145:
		tmp = (y + z) * (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 <= -3.9e+214)
		tmp = x_m;
	elseif (z <= 1.18e+145)
		tmp = Float64(Float64(y + z) * 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 <= -3.9e+214)
		tmp = x_m;
	elseif (z <= 1.18e+145)
		tmp = (y + z) * (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, -3.9e+214], x$95$m, If[LessEqual[z, 1.18e+145], N[(N[(y + z), $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 -3.9 \cdot 10^{+214}:\\
\;\;\;\;x\_m\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.90000000000000013e214 or 1.17999999999999998e145 < z

    1. Initial program 63.6%

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

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

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

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

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

    if -3.90000000000000013e214 < z < 1.17999999999999998e145

    1. Initial program 89.5%

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

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

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

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

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

Alternative 4: 69.4% 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}\;y \leq -6.8 \cdot 10^{+47} \lor \neg \left(y \leq 9.8 \cdot 10^{-76}\right):\\ \;\;\;\;x\_m \cdot \frac{y}{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 (or (<= y -6.8e+47) (not (<= y 9.8e-76))) (* 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 ((y <= -6.8e+47) || !(y <= 9.8e-76)) {
		tmp = x_m * (y / 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 ((y <= (-6.8d+47)) .or. (.not. (y <= 9.8d-76))) then
        tmp = x_m * (y / 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 ((y <= -6.8e+47) || !(y <= 9.8e-76)) {
		tmp = x_m * (y / 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 (y <= -6.8e+47) or not (y <= 9.8e-76):
		tmp = x_m * (y / 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 ((y <= -6.8e+47) || !(y <= 9.8e-76))
		tmp = Float64(x_m * Float64(y / 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 ((y <= -6.8e+47) || ~((y <= 9.8e-76)))
		tmp = x_m * (y / 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[Or[LessEqual[y, -6.8e+47], N[Not[LessEqual[y, 9.8e-76]], $MachinePrecision]], N[(x$95$m * N[(y / 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}\;y \leq -6.8 \cdot 10^{+47} \lor \neg \left(y \leq 9.8 \cdot 10^{-76}\right):\\
\;\;\;\;x\_m \cdot \frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -6.7999999999999996e47 or 9.79999999999999944e-76 < y

    1. Initial program 87.0%

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

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

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

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

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

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

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

    if -6.7999999999999996e47 < y < 9.79999999999999944e-76

    1. Initial program 79.4%

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

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

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

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

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

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

Alternative 5: 71.4% 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}\;y \leq -9.2 \cdot 10^{+35} \lor \neg \left(y \leq 5.1 \cdot 10^{-76}\right):\\ \;\;\;\;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 (or (<= y -9.2e+35) (not (<= y 5.1e-76))) (* 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 ((y <= -9.2e+35) || !(y <= 5.1e-76)) {
		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 ((y <= (-9.2d+35)) .or. (.not. (y <= 5.1d-76))) 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 ((y <= -9.2e+35) || !(y <= 5.1e-76)) {
		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 (y <= -9.2e+35) or not (y <= 5.1e-76):
		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 ((y <= -9.2e+35) || !(y <= 5.1e-76))
		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 ((y <= -9.2e+35) || ~((y <= 5.1e-76)))
		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[Or[LessEqual[y, -9.2e+35], N[Not[LessEqual[y, 5.1e-76]], $MachinePrecision]], 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}\;y \leq -9.2 \cdot 10^{+35} \lor \neg \left(y \leq 5.1 \cdot 10^{-76}\right):\\
\;\;\;\;y \cdot \frac{x\_m}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -9.1999999999999993e35 or 5.09999999999999986e-76 < y

    1. Initial program 87.2%

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

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

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

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{z}} \]
    6. Step-by-step derivation
      1. *-commutative74.8%

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

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

      \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
    8. Step-by-step derivation
      1. clear-num75.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{z}{x}}{y}}} \]
      2. associate-/r/75.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{z}{x}} \cdot y} \]
      3. clear-num75.8%

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

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

    if -9.1999999999999993e35 < y < 5.09999999999999986e-76

    1. Initial program 79.0%

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

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

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

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.6%

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

Alternative 6: 71.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}\;y \leq -3.25 \cdot 10^{+44}:\\ \;\;\;\;y \cdot \frac{x\_m}{z}\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-75}:\\ \;\;\;\;x\_m\\ \mathbf{else}:\\ \;\;\;\;\frac{x\_m \cdot 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 (<= y -3.25e+44)
    (* y (/ x_m z))
    (if (<= y 1.2e-75) 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 (y <= -3.25e+44) {
		tmp = y * (x_m / z);
	} else if (y <= 1.2e-75) {
		tmp = x_m;
	} else {
		tmp = (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 (y <= (-3.25d+44)) then
        tmp = y * (x_m / z)
    else if (y <= 1.2d-75) then
        tmp = x_m
    else
        tmp = (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 (y <= -3.25e+44) {
		tmp = y * (x_m / z);
	} else if (y <= 1.2e-75) {
		tmp = x_m;
	} else {
		tmp = (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 y <= -3.25e+44:
		tmp = y * (x_m / z)
	elif y <= 1.2e-75:
		tmp = x_m
	else:
		tmp = (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 (y <= -3.25e+44)
		tmp = Float64(y * Float64(x_m / z));
	elseif (y <= 1.2e-75)
		tmp = x_m;
	else
		tmp = Float64(Float64(x_m * 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 (y <= -3.25e+44)
		tmp = y * (x_m / z);
	elseif (y <= 1.2e-75)
		tmp = x_m;
	else
		tmp = (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[y, -3.25e+44], N[(y * N[(x$95$m / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.2e-75], x$95$m, N[(N[(x$95$m * y), $MachinePrecision] / z), $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}\;y \leq -3.25 \cdot 10^{+44}:\\
\;\;\;\;y \cdot \frac{x\_m}{z}\\

\mathbf{elif}\;y \leq 1.2 \cdot 10^{-75}:\\
\;\;\;\;x\_m\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.25000000000000009e44

    1. Initial program 80.1%

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

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

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

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{z}} \]
    6. Step-by-step derivation
      1. *-commutative71.4%

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

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
    7. Simplified76.3%

      \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
    8. Step-by-step derivation
      1. clear-num76.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{z}{x}}{y}}} \]
      2. associate-/r/76.3%

        \[\leadsto \color{blue}{\frac{1}{\frac{z}{x}} \cdot y} \]
      3. clear-num76.3%

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

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

    if -3.25000000000000009e44 < y < 1.2000000000000001e-75

    1. Initial program 79.0%

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

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

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

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

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

    if 1.2000000000000001e-75 < y

    1. Initial program 92.9%

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

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

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

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

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

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

Alternative 7: 51.2% 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 83.7%

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

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

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

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

    \[\leadsto \color{blue}{x} \]
  6. Final simplification48.3%

    \[\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 2024027 
(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))