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

Percentage Accurate: 100.0% → 100.0%
Time: 5.7s
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. Add Preprocessing
  3. Final simplification100.0%

    \[\leadsto x + \frac{y - x}{z} \]
  4. Add Preprocessing

Alternative 2: 60.4% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-x}{z}\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-153}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -6.8 \cdot 10^{-197}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-200}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-152}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-91}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 10500000000:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (- x) z)))
   (if (<= z -1.0)
     x
     (if (<= z -1.05e-153)
       t_0
       (if (<= z -6.8e-197)
         (/ y z)
         (if (<= z 6e-200)
           t_0
           (if (<= z 4.8e-152)
             (/ y z)
             (if (<= z 4.5e-91) t_0 (if (<= z 10500000000.0) (/ y z) x)))))))))
double code(double x, double y, double z) {
	double t_0 = -x / z;
	double tmp;
	if (z <= -1.0) {
		tmp = x;
	} else if (z <= -1.05e-153) {
		tmp = t_0;
	} else if (z <= -6.8e-197) {
		tmp = y / z;
	} else if (z <= 6e-200) {
		tmp = t_0;
	} else if (z <= 4.8e-152) {
		tmp = y / z;
	} else if (z <= 4.5e-91) {
		tmp = t_0;
	} else if (z <= 10500000000.0) {
		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.0d0)) then
        tmp = x
    else if (z <= (-1.05d-153)) then
        tmp = t_0
    else if (z <= (-6.8d-197)) then
        tmp = y / z
    else if (z <= 6d-200) then
        tmp = t_0
    else if (z <= 4.8d-152) then
        tmp = y / z
    else if (z <= 4.5d-91) then
        tmp = t_0
    else if (z <= 10500000000.0d0) 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.0) {
		tmp = x;
	} else if (z <= -1.05e-153) {
		tmp = t_0;
	} else if (z <= -6.8e-197) {
		tmp = y / z;
	} else if (z <= 6e-200) {
		tmp = t_0;
	} else if (z <= 4.8e-152) {
		tmp = y / z;
	} else if (z <= 4.5e-91) {
		tmp = t_0;
	} else if (z <= 10500000000.0) {
		tmp = y / z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = -x / z
	tmp = 0
	if z <= -1.0:
		tmp = x
	elif z <= -1.05e-153:
		tmp = t_0
	elif z <= -6.8e-197:
		tmp = y / z
	elif z <= 6e-200:
		tmp = t_0
	elif z <= 4.8e-152:
		tmp = y / z
	elif z <= 4.5e-91:
		tmp = t_0
	elif z <= 10500000000.0:
		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.0)
		tmp = x;
	elseif (z <= -1.05e-153)
		tmp = t_0;
	elseif (z <= -6.8e-197)
		tmp = Float64(y / z);
	elseif (z <= 6e-200)
		tmp = t_0;
	elseif (z <= 4.8e-152)
		tmp = Float64(y / z);
	elseif (z <= 4.5e-91)
		tmp = t_0;
	elseif (z <= 10500000000.0)
		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.0)
		tmp = x;
	elseif (z <= -1.05e-153)
		tmp = t_0;
	elseif (z <= -6.8e-197)
		tmp = y / z;
	elseif (z <= 6e-200)
		tmp = t_0;
	elseif (z <= 4.8e-152)
		tmp = y / z;
	elseif (z <= 4.5e-91)
		tmp = t_0;
	elseif (z <= 10500000000.0)
		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.0], x, If[LessEqual[z, -1.05e-153], t$95$0, If[LessEqual[z, -6.8e-197], N[(y / z), $MachinePrecision], If[LessEqual[z, 6e-200], t$95$0, If[LessEqual[z, 4.8e-152], N[(y / z), $MachinePrecision], If[LessEqual[z, 4.5e-91], t$95$0, If[LessEqual[z, 10500000000.0], N[(y / z), $MachinePrecision], x]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq -1.05 \cdot 10^{-153}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq -6.8 \cdot 10^{-197}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq 6 \cdot 10^{-200}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 4.8 \cdot 10^{-152}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq 4.5 \cdot 10^{-91}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 10500000000:\\
\;\;\;\;\frac{y}{z}\\

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


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

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg100.0%

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

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

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

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

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} + \frac{-y}{z}\right)} \]
      8. distribute-frac-neg100.0%

        \[\leadsto x - \left(\frac{x}{z} + \color{blue}{\left(-\frac{y}{z}\right)}\right) \]
      9. sub-neg100.0%

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in z around inf 67.8%

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

    if -1 < z < -1.05000000000000002e-153 or -6.7999999999999996e-197 < z < 5.99999999999999989e-200 or 4.8e-152 < z < 4.49999999999999976e-91

    1. Initial program 100.0%

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

        \[\leadsto x + \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} \]
      2. associate-+r-95.2%

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg95.2%

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

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

        \[\leadsto \color{blue}{\left(x - \frac{-y}{z}\right)} - \frac{x}{z} \]
      6. associate--r+95.2%

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

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

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

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 71.9%

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

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

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

        \[\leadsto \color{blue}{\frac{-x}{z}} \]
    8. Simplified71.5%

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

    if -1.05000000000000002e-153 < z < -6.7999999999999996e-197 or 5.99999999999999989e-200 < z < 4.8e-152 or 4.49999999999999976e-91 < z < 1.05e10

    1. Initial program 99.9%

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

        \[\leadsto x + \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} \]
      2. associate-+r-96.0%

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg96.0%

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

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

        \[\leadsto \color{blue}{\left(x - \frac{-y}{z}\right)} - \frac{x}{z} \]
      6. associate--r+96.0%

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

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

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

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub99.9%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 71.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-153}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq -6.8 \cdot 10^{-197}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-200}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-152}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-91}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq 10500000000:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.9% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x + \frac{y}{z}\\ t_1 := \frac{-x}{z}\\ \mathbf{if}\;z \leq -1.35 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-154}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -9.8 \cdot 10^{-199}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{-198}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-148}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 9 \cdot 10^{-93}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ x (/ y z))) (t_1 (/ (- x) z)))
   (if (<= z -1.35e-43)
     t_0
     (if (<= z -7.2e-154)
       t_1
       (if (<= z -9.8e-199)
         (/ y z)
         (if (<= z 8.6e-198)
           t_1
           (if (<= z 1.35e-148) (/ y z) (if (<= z 9e-93) t_1 t_0))))))))
double code(double x, double y, double z) {
	double t_0 = x + (y / z);
	double t_1 = -x / z;
	double tmp;
	if (z <= -1.35e-43) {
		tmp = t_0;
	} else if (z <= -7.2e-154) {
		tmp = t_1;
	} else if (z <= -9.8e-199) {
		tmp = y / z;
	} else if (z <= 8.6e-198) {
		tmp = t_1;
	} else if (z <= 1.35e-148) {
		tmp = y / z;
	} else if (z <= 9e-93) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = x + (y / z)
    t_1 = -x / z
    if (z <= (-1.35d-43)) then
        tmp = t_0
    else if (z <= (-7.2d-154)) then
        tmp = t_1
    else if (z <= (-9.8d-199)) then
        tmp = y / z
    else if (z <= 8.6d-198) then
        tmp = t_1
    else if (z <= 1.35d-148) then
        tmp = y / z
    else if (z <= 9d-93) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x + (y / z);
	double t_1 = -x / z;
	double tmp;
	if (z <= -1.35e-43) {
		tmp = t_0;
	} else if (z <= -7.2e-154) {
		tmp = t_1;
	} else if (z <= -9.8e-199) {
		tmp = y / z;
	} else if (z <= 8.6e-198) {
		tmp = t_1;
	} else if (z <= 1.35e-148) {
		tmp = y / z;
	} else if (z <= 9e-93) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x + (y / z)
	t_1 = -x / z
	tmp = 0
	if z <= -1.35e-43:
		tmp = t_0
	elif z <= -7.2e-154:
		tmp = t_1
	elif z <= -9.8e-199:
		tmp = y / z
	elif z <= 8.6e-198:
		tmp = t_1
	elif z <= 1.35e-148:
		tmp = y / z
	elif z <= 9e-93:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x + Float64(y / z))
	t_1 = Float64(Float64(-x) / z)
	tmp = 0.0
	if (z <= -1.35e-43)
		tmp = t_0;
	elseif (z <= -7.2e-154)
		tmp = t_1;
	elseif (z <= -9.8e-199)
		tmp = Float64(y / z);
	elseif (z <= 8.6e-198)
		tmp = t_1;
	elseif (z <= 1.35e-148)
		tmp = Float64(y / z);
	elseif (z <= 9e-93)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x + (y / z);
	t_1 = -x / z;
	tmp = 0.0;
	if (z <= -1.35e-43)
		tmp = t_0;
	elseif (z <= -7.2e-154)
		tmp = t_1;
	elseif (z <= -9.8e-199)
		tmp = y / z;
	elseif (z <= 8.6e-198)
		tmp = t_1;
	elseif (z <= 1.35e-148)
		tmp = y / z;
	elseif (z <= 9e-93)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -1.35e-43], t$95$0, If[LessEqual[z, -7.2e-154], t$95$1, If[LessEqual[z, -9.8e-199], N[(y / z), $MachinePrecision], If[LessEqual[z, 8.6e-198], t$95$1, If[LessEqual[z, 1.35e-148], N[(y / z), $MachinePrecision], If[LessEqual[z, 9e-93], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -7.2 \cdot 10^{-154}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq -9.8 \cdot 10^{-199}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq 8.6 \cdot 10^{-198}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 1.35 \cdot 10^{-148}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq 9 \cdot 10^{-93}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.34999999999999996e-43 or 9.0000000000000004e-93 < z

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg100.0%

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

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

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

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

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} + \frac{-y}{z}\right)} \]
      8. distribute-frac-neg100.0%

        \[\leadsto x - \left(\frac{x}{z} + \color{blue}{\left(-\frac{y}{z}\right)}\right) \]
      9. sub-neg100.0%

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 91.7%

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

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

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

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

      \[\leadsto \color{blue}{x + \frac{y}{z}} \]
    9. Step-by-step derivation
      1. +-commutative91.7%

        \[\leadsto \color{blue}{\frac{y}{z} + x} \]
    10. Simplified91.7%

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

    if -1.34999999999999996e-43 < z < -7.2000000000000006e-154 or -9.8e-199 < z < 8.6000000000000007e-198 or 1.34999999999999994e-148 < z < 9.0000000000000004e-93

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Step-by-step derivation
      1. div-sub94.7%

        \[\leadsto x + \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} \]
      2. associate-+r-94.7%

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

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

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

        \[\leadsto \color{blue}{\left(x - \frac{-y}{z}\right)} - \frac{x}{z} \]
      6. associate--r+94.7%

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

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

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

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 75.2%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{z}} \]
    7. Step-by-step derivation
      1. mul-1-neg75.2%

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

        \[\leadsto \color{blue}{\frac{-x}{z}} \]
    8. Simplified75.2%

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

    if -7.2000000000000006e-154 < z < -9.8e-199 or 8.6000000000000007e-198 < z < 1.34999999999999994e-148

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Step-by-step derivation
      1. div-sub92.3%

        \[\leadsto x + \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} \]
      2. associate-+r-92.3%

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg92.3%

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

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

        \[\leadsto \color{blue}{\left(x - \frac{-y}{z}\right)} - \frac{x}{z} \]
      6. associate--r+92.3%

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

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

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

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 77.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.35 \cdot 10^{-43}:\\ \;\;\;\;x + \frac{y}{z}\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-154}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq -9.8 \cdot 10^{-199}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{-198}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-148}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 9 \cdot 10^{-93}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 86.1% accurate, 0.5× speedup?

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

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Step-by-step derivation
      1. div-sub95.5%

        \[\leadsto x + \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} \]
      2. associate-+r-95.5%

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg95.5%

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

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

        \[\leadsto \color{blue}{\left(x - \frac{-y}{z}\right)} - \frac{x}{z} \]
      6. associate--r+95.5%

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

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

        \[\leadsto x - \left(\frac{x}{z} + \color{blue}{\left(-\frac{y}{z}\right)}\right) \]
      9. sub-neg95.5%

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 88.5%

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

    if -3.8e13 < x < 0.209999999999999992

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg100.0%

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

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

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

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

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} + \frac{-y}{z}\right)} \]
      8. distribute-frac-neg100.0%

        \[\leadsto x - \left(\frac{x}{z} + \color{blue}{\left(-\frac{y}{z}\right)}\right) \]
      9. sub-neg100.0%

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 87.0%

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

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

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

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

      \[\leadsto \color{blue}{x + \frac{y}{z}} \]
    9. Step-by-step derivation
      1. +-commutative87.0%

        \[\leadsto \color{blue}{\frac{y}{z} + x} \]
    10. Simplified87.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -38000000000000 \lor \neg \left(x \leq 0.21\right):\\ \;\;\;\;x - \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 98.8% accurate, 0.5× speedup?

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

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg100.0%

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

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

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

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

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} + \frac{-y}{z}\right)} \]
      8. distribute-frac-neg100.0%

        \[\leadsto x - \left(\frac{x}{z} + \color{blue}{\left(-\frac{y}{z}\right)}\right) \]
      9. sub-neg100.0%

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 99.1%

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

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

        \[\leadsto x - \color{blue}{\frac{-y}{z}} \]
    7. Simplified99.1%

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

      \[\leadsto \color{blue}{x + \frac{y}{z}} \]
    9. Step-by-step derivation
      1. +-commutative99.1%

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

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

    if -1 < z < 0.204999999999999988

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Step-by-step derivation
      1. div-sub95.4%

        \[\leadsto x + \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} \]
      2. associate-+r-95.4%

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg95.4%

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

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

        \[\leadsto \color{blue}{\left(x - \frac{-y}{z}\right)} - \frac{x}{z} \]
      6. associate--r+95.4%

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

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

        \[\leadsto x - \left(\frac{x}{z} + \color{blue}{\left(-\frac{y}{z}\right)}\right) \]
      9. sub-neg95.4%

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in z around 0 99.4%

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

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

Alternative 6: 62.3% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;z \leq 22000000000:\\
\;\;\;\;\frac{y}{z}\\

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


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

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg100.0%

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

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

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

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

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} + \frac{-y}{z}\right)} \]
      8. distribute-frac-neg100.0%

        \[\leadsto x - \left(\frac{x}{z} + \color{blue}{\left(-\frac{y}{z}\right)}\right) \]
      9. sub-neg100.0%

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in z around inf 69.2%

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

    if -8.6e14 < z < 2.2e10

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Step-by-step derivation
      1. div-sub95.6%

        \[\leadsto x + \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} \]
      2. associate-+r-95.6%

        \[\leadsto \color{blue}{\left(x + \frac{y}{z}\right) - \frac{x}{z}} \]
      3. remove-double-neg95.6%

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

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

        \[\leadsto \color{blue}{\left(x - \frac{-y}{z}\right)} - \frac{x}{z} \]
      6. associate--r+95.6%

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

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

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

        \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
      10. div-sub100.0%

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

      \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 48.5%

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

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

Alternative 7: 36.6% 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. Step-by-step derivation
    1. div-sub97.7%

      \[\leadsto x + \color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} \]
    2. associate-+r-97.7%

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

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

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

      \[\leadsto \color{blue}{\left(x - \frac{-y}{z}\right)} - \frac{x}{z} \]
    6. associate--r+97.7%

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

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

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

      \[\leadsto x - \color{blue}{\left(\frac{x}{z} - \frac{y}{z}\right)} \]
    10. div-sub100.0%

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

    \[\leadsto \color{blue}{x - \frac{x - y}{z}} \]
  4. Add Preprocessing
  5. Taylor expanded in z around inf 33.9%

    \[\leadsto \color{blue}{x} \]
  6. Final simplification33.9%

    \[\leadsto x \]
  7. Add Preprocessing

Reproduce

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