Numeric.SpecFunctions:choose from math-functions-0.1.5.2

Percentage Accurate: 84.9% → 96.1%
Time: 3.9s
Alternatives: 8
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 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: 84.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: 96.1% accurate, 0.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.70000000000000009e-68 or 2e-3 < z

    1. Initial program 82.5%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified99.9%

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

    if -1.70000000000000009e-68 < z < 2e-3

    1. Initial program 90.8%

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

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

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

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

Alternative 2: 96.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq 5 \cdot 10^{-18}:\\ \;\;\;\;\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) 5e-18) (/ x (/ z (+ y z))) (* (+ y z) (/ x z))))
double code(double x, double y, double z) {
	double tmp;
	if (((x * (y + z)) / z) <= 5e-18) {
		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) <= 5d-18) 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) <= 5e-18) {
		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) <= 5e-18:
		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) <= 5e-18)
		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) <= 5e-18)
		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], 5e-18], 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 5 \cdot 10^{-18}:\\
\;\;\;\;\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) < 5.00000000000000036e-18

    1. Initial program 88.4%

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

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{y + z}}} \]
    3. Simplified97.4%

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

    if 5.00000000000000036e-18 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 82.5%

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

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

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

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

Alternative 3: 69.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.1 \cdot 10^{+26} \lor \neg \left(y \leq 5.5 \cdot 10^{-147}\right) \land \left(y \leq 7.2 \cdot 10^{-124} \lor \neg \left(y \leq 2 \cdot 10^{+40}\right)\right):\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.1e+26)
         (and (not (<= y 5.5e-147)) (or (<= y 7.2e-124) (not (<= y 2e+40)))))
   (* x (/ y z))
   x))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.1e+26) || (!(y <= 5.5e-147) && ((y <= 7.2e-124) || !(y <= 2e+40)))) {
		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.1d+26)) .or. (.not. (y <= 5.5d-147)) .and. (y <= 7.2d-124) .or. (.not. (y <= 2d+40))) 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.1e+26) || (!(y <= 5.5e-147) && ((y <= 7.2e-124) || !(y <= 2e+40)))) {
		tmp = x * (y / z);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -1.1e+26) or (not (y <= 5.5e-147) and ((y <= 7.2e-124) or not (y <= 2e+40))):
		tmp = x * (y / z)
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.1e+26) || (!(y <= 5.5e-147) && ((y <= 7.2e-124) || !(y <= 2e+40))))
		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.1e+26) || (~((y <= 5.5e-147)) && ((y <= 7.2e-124) || ~((y <= 2e+40)))))
		tmp = x * (y / z);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e+26], And[N[Not[LessEqual[y, 5.5e-147]], $MachinePrecision], Or[LessEqual[y, 7.2e-124], N[Not[LessEqual[y, 2e+40]], $MachinePrecision]]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+26} \lor \neg \left(y \leq 5.5 \cdot 10^{-147}\right) \land \left(y \leq 7.2 \cdot 10^{-124} \lor \neg \left(y \leq 2 \cdot 10^{+40}\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.10000000000000004e26 or 5.5e-147 < y < 7.20000000000000019e-124 or 2.00000000000000006e40 < y

    1. Initial program 91.6%

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

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

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around inf 79.6%

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

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

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

    if -1.10000000000000004e26 < y < 5.5e-147 or 7.20000000000000019e-124 < y < 2.00000000000000006e40

    1. Initial program 81.4%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified98.5%

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around 0 76.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.1 \cdot 10^{+26} \lor \neg \left(y \leq 5.5 \cdot 10^{-147}\right) \land \left(y \leq 7.2 \cdot 10^{-124} \lor \neg \left(y \leq 2 \cdot 10^{+40}\right)\right):\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 4: 70.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -1.7 \cdot 10^{+26}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.55 \cdot 10^{-147}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-125}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-99}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (/ x z))))
   (if (<= y -1.7e+26)
     t_0
     (if (<= y 4.55e-147)
       x
       (if (<= y 6.5e-125) (* x (/ y z)) (if (<= y 2e-99) x t_0))))))
double code(double x, double y, double z) {
	double t_0 = y * (x / z);
	double tmp;
	if (y <= -1.7e+26) {
		tmp = t_0;
	} else if (y <= 4.55e-147) {
		tmp = x;
	} else if (y <= 6.5e-125) {
		tmp = x * (y / z);
	} else if (y <= 2e-99) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = y * (x / z)
    if (y <= (-1.7d+26)) then
        tmp = t_0
    else if (y <= 4.55d-147) then
        tmp = x
    else if (y <= 6.5d-125) then
        tmp = x * (y / z)
    else if (y <= 2d-99) then
        tmp = x
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * (x / z);
	double tmp;
	if (y <= -1.7e+26) {
		tmp = t_0;
	} else if (y <= 4.55e-147) {
		tmp = x;
	} else if (y <= 6.5e-125) {
		tmp = x * (y / z);
	} else if (y <= 2e-99) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (x / z)
	tmp = 0
	if y <= -1.7e+26:
		tmp = t_0
	elif y <= 4.55e-147:
		tmp = x
	elif y <= 6.5e-125:
		tmp = x * (y / z)
	elif y <= 2e-99:
		tmp = x
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(x / z))
	tmp = 0.0
	if (y <= -1.7e+26)
		tmp = t_0;
	elseif (y <= 4.55e-147)
		tmp = x;
	elseif (y <= 6.5e-125)
		tmp = Float64(x * Float64(y / z));
	elseif (y <= 2e-99)
		tmp = x;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (x / z);
	tmp = 0.0;
	if (y <= -1.7e+26)
		tmp = t_0;
	elseif (y <= 4.55e-147)
		tmp = x;
	elseif (y <= 6.5e-125)
		tmp = x * (y / z);
	elseif (y <= 2e-99)
		tmp = x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.7e+26], t$95$0, If[LessEqual[y, 4.55e-147], x, If[LessEqual[y, 6.5e-125], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2e-99], x, t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \frac{x}{z}\\
\mathbf{if}\;y \leq -1.7 \cdot 10^{+26}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 4.55 \cdot 10^{-147}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 6.5 \cdot 10^{-125}:\\
\;\;\;\;x \cdot \frac{y}{z}\\

\mathbf{elif}\;y \leq 2 \cdot 10^{-99}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.7000000000000001e26 or 2e-99 < y

    1. Initial program 90.9%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified89.9%

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around inf 74.2%

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

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

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

    if -1.7000000000000001e26 < y < 4.54999999999999977e-147 or 6.4999999999999999e-125 < y < 2e-99

    1. Initial program 79.8%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified99.1%

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around 0 81.7%

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

    if 4.54999999999999977e-147 < y < 6.4999999999999999e-125

    1. Initial program 99.8%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around inf 85.6%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.7 \cdot 10^{+26}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;y \leq 4.55 \cdot 10^{-147}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-125}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-99}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]

Alternative 5: 70.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{y}{\frac{z}{x}}\\ \mathbf{if}\;y \leq -1.15 \cdot 10^{+26}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-147}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-125}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-98}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ y (/ z x))))
   (if (<= y -1.15e+26)
     t_0
     (if (<= y 5.5e-147)
       x
       (if (<= y 6.5e-125) (* x (/ y z)) (if (<= y 2.5e-98) x t_0))))))
double code(double x, double y, double z) {
	double t_0 = y / (z / x);
	double tmp;
	if (y <= -1.15e+26) {
		tmp = t_0;
	} else if (y <= 5.5e-147) {
		tmp = x;
	} else if (y <= 6.5e-125) {
		tmp = x * (y / z);
	} else if (y <= 2.5e-98) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = y / (z / x)
    if (y <= (-1.15d+26)) then
        tmp = t_0
    else if (y <= 5.5d-147) then
        tmp = x
    else if (y <= 6.5d-125) then
        tmp = x * (y / z)
    else if (y <= 2.5d-98) then
        tmp = x
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y / (z / x);
	double tmp;
	if (y <= -1.15e+26) {
		tmp = t_0;
	} else if (y <= 5.5e-147) {
		tmp = x;
	} else if (y <= 6.5e-125) {
		tmp = x * (y / z);
	} else if (y <= 2.5e-98) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y / (z / x)
	tmp = 0
	if y <= -1.15e+26:
		tmp = t_0
	elif y <= 5.5e-147:
		tmp = x
	elif y <= 6.5e-125:
		tmp = x * (y / z)
	elif y <= 2.5e-98:
		tmp = x
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(y / Float64(z / x))
	tmp = 0.0
	if (y <= -1.15e+26)
		tmp = t_0;
	elseif (y <= 5.5e-147)
		tmp = x;
	elseif (y <= 6.5e-125)
		tmp = Float64(x * Float64(y / z));
	elseif (y <= 2.5e-98)
		tmp = x;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y / (z / x);
	tmp = 0.0;
	if (y <= -1.15e+26)
		tmp = t_0;
	elseif (y <= 5.5e-147)
		tmp = x;
	elseif (y <= 6.5e-125)
		tmp = x * (y / z);
	elseif (y <= 2.5e-98)
		tmp = x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.15e+26], t$95$0, If[LessEqual[y, 5.5e-147], x, If[LessEqual[y, 6.5e-125], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.5e-98], x, t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{y}{\frac{z}{x}}\\
\mathbf{if}\;y \leq -1.15 \cdot 10^{+26}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 5.5 \cdot 10^{-147}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 6.5 \cdot 10^{-125}:\\
\;\;\;\;x \cdot \frac{y}{z}\\

\mathbf{elif}\;y \leq 2.5 \cdot 10^{-98}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.15e26 or 2.50000000000000009e-98 < y

    1. Initial program 90.9%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified89.9%

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around inf 74.2%

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

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

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

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

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

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

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

    if -1.15e26 < y < 5.5e-147 or 6.4999999999999999e-125 < y < 2.50000000000000009e-98

    1. Initial program 79.8%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified99.1%

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around 0 81.7%

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

    if 5.5e-147 < y < 6.4999999999999999e-125

    1. Initial program 99.8%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around inf 85.6%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{+26}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-147}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-125}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-98}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \end{array} \]

Alternative 6: 70.5% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{+26}:\\
\;\;\;\;\frac{x \cdot y}{z}\\

\mathbf{elif}\;y \leq 5.5 \cdot 10^{-147}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 1.05 \cdot 10^{-123}:\\
\;\;\;\;x \cdot \frac{y}{z}\\

\mathbf{elif}\;y \leq 1.32 \cdot 10^{-98}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -1.15e26

    1. Initial program 91.6%

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

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

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around inf 77.9%

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

    if -1.15e26 < y < 5.5e-147 or 1.05e-123 < y < 1.31999999999999995e-98

    1. Initial program 79.8%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified99.1%

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around 0 81.7%

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

    if 5.5e-147 < y < 1.05e-123

    1. Initial program 99.8%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around inf 85.6%

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

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

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

    if 1.31999999999999995e-98 < y

    1. Initial program 90.3%

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

        \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Simplified90.9%

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
    4. Taylor expanded in y around inf 71.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{+26}:\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-147}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-123}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq 1.32 \cdot 10^{-98}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \end{array} \]

Alternative 7: 95.8% accurate, 1.0× speedup?

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

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

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

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

    \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
  4. Final simplification94.1%

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

Alternative 8: 50.5% 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 86.4%

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

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

    \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
  4. Taylor expanded in y around 0 47.0%

    \[\leadsto \color{blue}{x} \]
  5. Final simplification47.0%

    \[\leadsto x \]

Developer target: 96.2% 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 2023290 
(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))