Numeric.SpecFunctions:choose from math-functions-0.1.5.2

Percentage Accurate: 85.4% → 95.9%
Time: 5.2s
Alternatives: 7
Speedup: 1.0×

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: 85.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: 95.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq 2 \cdot 10^{-14}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{else}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (/ (* x (+ y z)) z) 2e-14) (/ x (/ z (+ y z))) (* (+ y z) (/ x z))))
double code(double x, double y, double z) {
	double tmp;
	if (((x * (y + z)) / z) <= 2e-14) {
		tmp = x / (z / (y + z));
	} else {
		tmp = (y + z) * (x / z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (((x * (y + z)) / z) <= 2d-14) then
        tmp = x / (z / (y + z))
    else
        tmp = (y + z) * (x / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (((x * (y + z)) / z) <= 2e-14) {
		tmp = x / (z / (y + z));
	} else {
		tmp = (y + z) * (x / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if ((x * (y + z)) / z) <= 2e-14:
		tmp = x / (z / (y + z))
	else:
		tmp = (y + z) * (x / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(Float64(x * Float64(y + z)) / z) <= 2e-14)
		tmp = Float64(x / Float64(z / Float64(y + z)));
	else
		tmp = Float64(Float64(y + z) * Float64(x / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (((x * (y + z)) / z) <= 2e-14)
		tmp = x / (z / (y + z));
	else
		tmp = (y + z) * (x / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], 2e-14], N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq 2 \cdot 10^{-14}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < 2e-14

    1. Initial program 87.3%

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

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Step-by-step derivation
      1. associate-/r/99.3%

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

        \[\leadsto \frac{x}{\frac{z}{\color{blue}{z + y}}} \]
    5. Applied egg-rr99.3%

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

    if 2e-14 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 82.1%

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

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

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

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

Alternative 2: 69.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{+131} \lor \neg \left(y \leq -5.5 \cdot 10^{+87}\right) \land \left(y \leq -1950 \lor \neg \left(y \leq 6.2 \cdot 10^{+55}\right)\right):\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.45e+131)
         (and (not (<= y -5.5e+87)) (or (<= y -1950.0) (not (<= y 6.2e+55)))))
   (* x (/ y z))
   x))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.45e+131) || (!(y <= -5.5e+87) && ((y <= -1950.0) || !(y <= 6.2e+55)))) {
		tmp = x * (y / z);
	} else {
		tmp = 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 ((y <= (-1.45d+131)) .or. (.not. (y <= (-5.5d+87))) .and. (y <= (-1950.0d0)) .or. (.not. (y <= 6.2d+55))) then
        tmp = x * (y / z)
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.45e+131) || (!(y <= -5.5e+87) && ((y <= -1950.0) || !(y <= 6.2e+55)))) {
		tmp = x * (y / z);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -1.45e+131) or (not (y <= -5.5e+87) and ((y <= -1950.0) or not (y <= 6.2e+55))):
		tmp = x * (y / z)
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.45e+131) || (!(y <= -5.5e+87) && ((y <= -1950.0) || !(y <= 6.2e+55))))
		tmp = Float64(x * Float64(y / z));
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -1.45e+131) || (~((y <= -5.5e+87)) && ((y <= -1950.0) || ~((y <= 6.2e+55)))))
		tmp = x * (y / z);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e+131], And[N[Not[LessEqual[y, -5.5e+87]], $MachinePrecision], Or[LessEqual[y, -1950.0], N[Not[LessEqual[y, 6.2e+55]], $MachinePrecision]]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+131} \lor \neg \left(y \leq -5.5 \cdot 10^{+87}\right) \land \left(y \leq -1950 \lor \neg \left(y \leq 6.2 \cdot 10^{+55}\right)\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.45000000000000005e131 or -5.50000000000000022e87 < y < -1950 or 6.19999999999999987e55 < y

    1. Initial program 92.4%

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

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

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

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

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

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

    if -1.45000000000000005e131 < y < -5.50000000000000022e87 or -1950 < y < 6.19999999999999987e55

    1. Initial program 79.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{+131} \lor \neg \left(y \leq -5.5 \cdot 10^{+87}\right) \land \left(y \leq -1950 \lor \neg \left(y \leq 6.2 \cdot 10^{+55}\right)\right):\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 3: 89.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.55 \cdot 10^{+123}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{+212}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{x}}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.55e+123)
   x
   (if (<= z 1.05e+212) (* (+ y z) (/ x z)) (/ 1.0 (/ 1.0 x)))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.55e+123) {
		tmp = x;
	} else if (z <= 1.05e+212) {
		tmp = (y + z) * (x / z);
	} else {
		tmp = 1.0 / (1.0 / 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.55d+123)) then
        tmp = x
    else if (z <= 1.05d+212) then
        tmp = (y + z) * (x / z)
    else
        tmp = 1.0d0 / (1.0d0 / x)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.55e+123) {
		tmp = x;
	} else if (z <= 1.05e+212) {
		tmp = (y + z) * (x / z);
	} else {
		tmp = 1.0 / (1.0 / x);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.55e+123:
		tmp = x
	elif z <= 1.05e+212:
		tmp = (y + z) * (x / z)
	else:
		tmp = 1.0 / (1.0 / x)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.55e+123)
		tmp = x;
	elseif (z <= 1.05e+212)
		tmp = Float64(Float64(y + z) * Float64(x / z));
	else
		tmp = Float64(1.0 / Float64(1.0 / x));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -1.55e+123)
		tmp = x;
	elseif (z <= 1.05e+212)
		tmp = (y + z) * (x / z);
	else
		tmp = 1.0 / (1.0 / x);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -1.55e+123], x, If[LessEqual[z, 1.05e+212], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{+123}:\\
\;\;\;\;x\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1}{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.55000000000000003e123

    1. Initial program 63.3%

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

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

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

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

    if -1.55000000000000003e123 < z < 1.05e212

    1. Initial program 89.8%

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

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

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

    if 1.05e212 < z

    1. Initial program 75.0%

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

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

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

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(y + z\right) \cdot \frac{x}{z}}}\right)}^{3} \]
      4. clear-num58.6%

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\frac{y + z}{\frac{z}{x}}}}\right)}^{3} \]
      6. +-commutative58.6%

        \[\leadsto {\left(\sqrt[3]{\frac{\color{blue}{z + y}}{\frac{z}{x}}}\right)}^{3} \]
    5. Applied egg-rr58.6%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\frac{z + y}{\frac{z}{x}}}\right)}^{3}} \]
    6. Step-by-step derivation
      1. rem-cube-cbrt60.0%

        \[\leadsto \color{blue}{\frac{z + y}{\frac{z}{x}}} \]
      2. div-inv59.9%

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

        \[\leadsto \color{blue}{\frac{\frac{z + y}{z}}{\frac{1}{x}}} \]
      4. +-commutative99.8%

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

      \[\leadsto \color{blue}{\frac{\frac{y + z}{z}}{\frac{1}{x}}} \]
    8. Taylor expanded in y around 0 90.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.55 \cdot 10^{+123}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{+212}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{x}}\\ \end{array} \]

Alternative 4: 73.3% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -26000 \lor \neg \left(y \leq 2.45 \cdot 10^{+56}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -26000 or 2.4500000000000001e56 < y

    1. Initial program 91.6%

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

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

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

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

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

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

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

    if -26000 < y < 2.4500000000000001e56

    1. Initial program 79.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -26000 \lor \neg \left(y \leq 2.45 \cdot 10^{+56}\right):\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 5: 73.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.1:\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+56}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -2.1) (/ (* x y) z) (if (<= y 2.6e+56) x (* y (/ x z)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -2.1) {
		tmp = (x * y) / z;
	} else if (y <= 2.6e+56) {
		tmp = x;
	} else {
		tmp = y * (x / z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-2.1d0)) then
        tmp = (x * y) / z
    else if (y <= 2.6d+56) then
        tmp = x
    else
        tmp = y * (x / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -2.1) {
		tmp = (x * y) / z;
	} else if (y <= 2.6e+56) {
		tmp = x;
	} else {
		tmp = y * (x / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -2.1:
		tmp = (x * y) / z
	elif y <= 2.6e+56:
		tmp = x
	else:
		tmp = y * (x / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -2.1)
		tmp = Float64(Float64(x * y) / z);
	elseif (y <= 2.6e+56)
		tmp = x;
	else
		tmp = Float64(y * Float64(x / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -2.1)
		tmp = (x * y) / z;
	elseif (y <= 2.6e+56)
		tmp = x;
	else
		tmp = y * (x / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -2.1], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 2.6e+56], x, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1:\\
\;\;\;\;\frac{x \cdot y}{z}\\

\mathbf{elif}\;y \leq 2.6 \cdot 10^{+56}:\\
\;\;\;\;x\\

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


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

    1. Initial program 93.9%

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

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

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

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

    if -2.10000000000000009 < y < 2.60000000000000011e56

    1. Initial program 79.3%

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

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

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

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

    if 2.60000000000000011e56 < y

    1. Initial program 89.3%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.1:\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+56}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]

Alternative 6: 95.7% accurate, 1.0× speedup?

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

\\
x + x \cdot \frac{y}{z}
\end{array}
Derivation
  1. Initial program 85.3%

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

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    2. remove-double-neg96.6%

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

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

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

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

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

      \[\leadsto x \cdot \left(\frac{y}{z} - \color{blue}{-1}\right) \]
    8. sub-neg96.5%

      \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} + \left(--1\right)\right)} \]
    9. metadata-eval96.5%

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

      \[\leadsto x \cdot \left(\frac{y}{z} + \color{blue}{\frac{z}{z}}\right) \]
    11. distribute-lft-out96.6%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x \cdot \frac{z}{z}} \]
    12. *-inverses96.6%

      \[\leadsto x \cdot \frac{y}{z} + x \cdot \color{blue}{1} \]
    13. *-rgt-identity96.6%

      \[\leadsto x \cdot \frac{y}{z} + \color{blue}{x} \]
    14. fma-def96.6%

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

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

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

    \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
  6. Final simplification96.6%

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

Alternative 7: 50.2% accurate, 7.0× speedup?

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

\\
x
\end{array}
Derivation
  1. Initial program 85.3%

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

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

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

    \[\leadsto \color{blue}{x} \]
  5. Final simplification51.3%

    \[\leadsto x \]

Developer target: 96.0% 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 2023320 
(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))