Statistics.Sample:$swelfordMean from math-functions-0.1.5.2

Percentage Accurate: 100.0% → 100.0%
Time: 5.1s
Alternatives: 7
Speedup: 1.0×

Specification

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

\\
x + \frac{y - x}{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: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.0× speedup?

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

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

    \[x + \frac{y - x}{z} \]
  2. Final simplification100.0%

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

Alternative 2: 60.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-x}{z}\\ \mathbf{if}\;z \leq -1.7 \cdot 10^{+126}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{+90}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq -4.1 \cdot 10^{+49}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-236}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 10^{-271}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{-143}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{-127}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{+26}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (- x) z)))
   (if (<= z -1.7e+126)
     x
     (if (<= z -3.4e+90)
       (/ y z)
       (if (<= z -4.1e+49)
         x
         (if (<= z -1.1e-236)
           (/ y z)
           (if (<= z 1e-271)
             t_0
             (if (<= z 1.55e-143)
               (/ y z)
               (if (<= z 1.75e-127) t_0 (if (<= z 4.6e+26) (/ y z) x))))))))))
double code(double x, double y, double z) {
	double t_0 = -x / z;
	double tmp;
	if (z <= -1.7e+126) {
		tmp = x;
	} else if (z <= -3.4e+90) {
		tmp = y / z;
	} else if (z <= -4.1e+49) {
		tmp = x;
	} else if (z <= -1.1e-236) {
		tmp = y / z;
	} else if (z <= 1e-271) {
		tmp = t_0;
	} else if (z <= 1.55e-143) {
		tmp = y / z;
	} else if (z <= 1.75e-127) {
		tmp = t_0;
	} else if (z <= 4.6e+26) {
		tmp = 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) :: t_0
    real(8) :: tmp
    t_0 = -x / z
    if (z <= (-1.7d+126)) then
        tmp = x
    else if (z <= (-3.4d+90)) then
        tmp = y / z
    else if (z <= (-4.1d+49)) then
        tmp = x
    else if (z <= (-1.1d-236)) then
        tmp = y / z
    else if (z <= 1d-271) then
        tmp = t_0
    else if (z <= 1.55d-143) then
        tmp = y / z
    else if (z <= 1.75d-127) then
        tmp = t_0
    else if (z <= 4.6d+26) then
        tmp = y / z
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = -x / z;
	double tmp;
	if (z <= -1.7e+126) {
		tmp = x;
	} else if (z <= -3.4e+90) {
		tmp = y / z;
	} else if (z <= -4.1e+49) {
		tmp = x;
	} else if (z <= -1.1e-236) {
		tmp = y / z;
	} else if (z <= 1e-271) {
		tmp = t_0;
	} else if (z <= 1.55e-143) {
		tmp = y / z;
	} else if (z <= 1.75e-127) {
		tmp = t_0;
	} else if (z <= 4.6e+26) {
		tmp = y / z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = -x / z
	tmp = 0
	if z <= -1.7e+126:
		tmp = x
	elif z <= -3.4e+90:
		tmp = y / z
	elif z <= -4.1e+49:
		tmp = x
	elif z <= -1.1e-236:
		tmp = y / z
	elif z <= 1e-271:
		tmp = t_0
	elif z <= 1.55e-143:
		tmp = y / z
	elif z <= 1.75e-127:
		tmp = t_0
	elif z <= 4.6e+26:
		tmp = y / z
	else:
		tmp = x
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(-x) / z)
	tmp = 0.0
	if (z <= -1.7e+126)
		tmp = x;
	elseif (z <= -3.4e+90)
		tmp = Float64(y / z);
	elseif (z <= -4.1e+49)
		tmp = x;
	elseif (z <= -1.1e-236)
		tmp = Float64(y / z);
	elseif (z <= 1e-271)
		tmp = t_0;
	elseif (z <= 1.55e-143)
		tmp = Float64(y / z);
	elseif (z <= 1.75e-127)
		tmp = t_0;
	elseif (z <= 4.6e+26)
		tmp = Float64(y / z);
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = -x / z;
	tmp = 0.0;
	if (z <= -1.7e+126)
		tmp = x;
	elseif (z <= -3.4e+90)
		tmp = y / z;
	elseif (z <= -4.1e+49)
		tmp = x;
	elseif (z <= -1.1e-236)
		tmp = y / z;
	elseif (z <= 1e-271)
		tmp = t_0;
	elseif (z <= 1.55e-143)
		tmp = y / z;
	elseif (z <= 1.75e-127)
		tmp = t_0;
	elseif (z <= 4.6e+26)
		tmp = y / z;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -1.7e+126], x, If[LessEqual[z, -3.4e+90], N[(y / z), $MachinePrecision], If[LessEqual[z, -4.1e+49], x, If[LessEqual[z, -1.1e-236], N[(y / z), $MachinePrecision], If[LessEqual[z, 1e-271], t$95$0, If[LessEqual[z, 1.55e-143], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.75e-127], t$95$0, If[LessEqual[z, 4.6e+26], N[(y / z), $MachinePrecision], x]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -3.4 \cdot 10^{+90}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq -4.1 \cdot 10^{+49}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq -1.1 \cdot 10^{-236}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq 10^{-271}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 1.55 \cdot 10^{-143}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq 1.75 \cdot 10^{-127}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 4.6 \cdot 10^{+26}:\\
\;\;\;\;\frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.69999999999999995e126 or -3.40000000000000018e90 < z < -4.1e49 or 4.6000000000000001e26 < z

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Taylor expanded in z around inf 79.9%

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

    if -1.69999999999999995e126 < z < -3.40000000000000018e90 or -4.1e49 < z < -1.09999999999999996e-236 or 9.99999999999999963e-272 < z < 1.55000000000000004e-143 or 1.74999999999999995e-127 < z < 4.6000000000000001e26

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Taylor expanded in x around 0 62.0%

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

    if -1.09999999999999996e-236 < z < 9.99999999999999963e-272 or 1.55000000000000004e-143 < z < 1.74999999999999995e-127

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Taylor expanded in y around 0 78.3%

      \[\leadsto \color{blue}{x - \frac{x}{z}} \]
    3. Taylor expanded in z around 0 78.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{z}} \]
    4. Step-by-step derivation
      1. mul-1-neg78.3%

        \[\leadsto \color{blue}{-\frac{x}{z}} \]
      2. distribute-frac-neg78.3%

        \[\leadsto \color{blue}{\frac{-x}{z}} \]
    5. Simplified78.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{+126}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{+90}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq -4.1 \cdot 10^{+49}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-236}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 10^{-271}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{-143}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{-127}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{+26}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 3: 60.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.8 \cdot 10^{+126}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{+90}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq -2.75 \cdot 10^{+45}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{+26}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.8e+126)
   x
   (if (<= z -3.4e+90)
     (/ y z)
     (if (<= z -2.75e+45) x (if (<= z 4.8e+26) (/ y z) x)))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.8e+126) {
		tmp = x;
	} else if (z <= -3.4e+90) {
		tmp = y / z;
	} else if (z <= -2.75e+45) {
		tmp = x;
	} else if (z <= 4.8e+26) {
		tmp = 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 (z <= (-1.8d+126)) then
        tmp = x
    else if (z <= (-3.4d+90)) then
        tmp = y / z
    else if (z <= (-2.75d+45)) then
        tmp = x
    else if (z <= 4.8d+26) then
        tmp = y / z
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.8e+126) {
		tmp = x;
	} else if (z <= -3.4e+90) {
		tmp = y / z;
	} else if (z <= -2.75e+45) {
		tmp = x;
	} else if (z <= 4.8e+26) {
		tmp = y / z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.8e+126:
		tmp = x
	elif z <= -3.4e+90:
		tmp = y / z
	elif z <= -2.75e+45:
		tmp = x
	elif z <= 4.8e+26:
		tmp = y / z
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.8e+126)
		tmp = x;
	elseif (z <= -3.4e+90)
		tmp = Float64(y / z);
	elseif (z <= -2.75e+45)
		tmp = x;
	elseif (z <= 4.8e+26)
		tmp = Float64(y / z);
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -1.8e+126)
		tmp = x;
	elseif (z <= -3.4e+90)
		tmp = y / z;
	elseif (z <= -2.75e+45)
		tmp = x;
	elseif (z <= 4.8e+26)
		tmp = y / z;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -1.8e+126], x, If[LessEqual[z, -3.4e+90], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.75e+45], x, If[LessEqual[z, 4.8e+26], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -3.4 \cdot 10^{+90}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq -2.75 \cdot 10^{+45}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 4.8 \cdot 10^{+26}:\\
\;\;\;\;\frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.8e126 or -3.40000000000000018e90 < z < -2.75e45 or 4.80000000000000009e26 < z

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Taylor expanded in z around inf 79.9%

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

    if -1.8e126 < z < -3.40000000000000018e90 or -2.75e45 < z < 4.80000000000000009e26

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Taylor expanded in x around 0 56.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.8 \cdot 10^{+126}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{+90}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq -2.75 \cdot 10^{+45}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{+26}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 4: 85.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+31} \lor \neg \left(x \leq 5.1 \cdot 10^{+135}\right):\\ \;\;\;\;x - \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -9.5e+31) (not (<= x 5.1e+135))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -9.5e+31) || !(x <= 5.1e+135)) {
		tmp = x - (x / z);
	} else {
		tmp = x + (y / z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-9.5d+31)) .or. (.not. (x <= 5.1d+135))) then
        tmp = x - (x / z)
    else
        tmp = x + (y / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -9.5e+31) || !(x <= 5.1e+135)) {
		tmp = x - (x / z);
	} else {
		tmp = x + (y / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -9.5e+31) or not (x <= 5.1e+135):
		tmp = x - (x / z)
	else:
		tmp = x + (y / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -9.5e+31) || !(x <= 5.1e+135))
		tmp = Float64(x - Float64(x / z));
	else
		tmp = Float64(x + Float64(y / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -9.5e+31) || ~((x <= 5.1e+135)))
		tmp = x - (x / z);
	else
		tmp = x + (y / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e+31], N[Not[LessEqual[x, 5.1e+135]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+31} \lor \neg \left(x \leq 5.1 \cdot 10^{+135}\right):\\
\;\;\;\;x - \frac{x}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -9.5000000000000008e31 or 5.09999999999999982e135 < x

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Taylor expanded in y around 0 89.8%

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

    if -9.5000000000000008e31 < x < 5.09999999999999982e135

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

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

        \[\leadsto \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} + x \]
      3. associate-+l-100.0%

        \[\leadsto \color{blue}{\frac{y}{z} - \left(\frac{x}{z} - x\right)} \]
    3. Applied egg-rr100.0%

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

      \[\leadsto \frac{y}{z} - \color{blue}{-1 \cdot x} \]
    5. Step-by-step derivation
      1. neg-mul-187.1%

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

      \[\leadsto \frac{y}{z} - \color{blue}{\left(-x\right)} \]
    7. Taylor expanded in y around 0 87.1%

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

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

Alternative 5: 98.7% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -34000000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.4e10 or 1 < z

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

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

        \[\leadsto \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} + x \]
      3. associate-+l-100.0%

        \[\leadsto \color{blue}{\frac{y}{z} - \left(\frac{x}{z} - x\right)} \]
    3. Applied egg-rr100.0%

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

      \[\leadsto \frac{y}{z} - \color{blue}{-1 \cdot x} \]
    5. Step-by-step derivation
      1. neg-mul-199.2%

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

      \[\leadsto \frac{y}{z} - \color{blue}{\left(-x\right)} \]
    7. Taylor expanded in y around 0 99.2%

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

    if -3.4e10 < z < 1

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Taylor expanded in z around 0 99.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -34000000000 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;x + \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y - x}{z}\\ \end{array} \]

Alternative 6: 75.7% accurate, 1.4× speedup?

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

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

    \[x + \frac{y - x}{z} \]
  2. Step-by-step derivation
    1. +-commutative100.0%

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

      \[\leadsto \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} + x \]
    3. associate-+l-98.0%

      \[\leadsto \color{blue}{\frac{y}{z} - \left(\frac{x}{z} - x\right)} \]
  3. Applied egg-rr98.0%

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

    \[\leadsto \frac{y}{z} - \color{blue}{-1 \cdot x} \]
  5. Step-by-step derivation
    1. neg-mul-177.5%

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

    \[\leadsto \frac{y}{z} - \color{blue}{\left(-x\right)} \]
  7. Taylor expanded in y around 0 77.5%

    \[\leadsto \color{blue}{\frac{y}{z} + x} \]
  8. Final simplification77.5%

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

Alternative 7: 36.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 100.0%

    \[x + \frac{y - x}{z} \]
  2. Taylor expanded in z around inf 38.4%

    \[\leadsto \color{blue}{x} \]
  3. Final simplification38.4%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023224 
(FPCore (x y z)
  :name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
  :precision binary64
  (+ x (/ (- y x) z)))