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

Percentage Accurate: 100.0% → 100.0%
Time: 5.6s
Alternatives: 6
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 6 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. Add Preprocessing

Alternative 2: 60.1% accurate, 0.2× speedup?

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

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

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

\mathbf{elif}\;z \leq -180:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq -4.5 \cdot 10^{-276}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq 0.00082:\\
\;\;\;\;\frac{x}{-z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -6.00000000000000014e110 or -2.4e37 < z < -180 or 8.1999999999999998e-4 < 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. sub-neg100.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
      9. 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 76.8%

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

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

    if -6.00000000000000014e110 < z < -2.4e37 or -180 < z < -4.49999999999999962e-276

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
      9. 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 71.2%

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

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

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

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

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

    if -4.49999999999999962e-276 < z < 8.1999999999999998e-4

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
      9. 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 67.9%

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

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

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

        \[\leadsto \color{blue}{\frac{x}{-z}} \]
    8. Simplified66.1%

      \[\leadsto \color{blue}{\frac{x}{-z}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 76.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x + \frac{y}{z}\\ t_1 := \frac{x}{-z}\\ \mathbf{if}\;z \leq -2.9 \cdot 10^{-287}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-138}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{-79}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-11}:\\ \;\;\;\;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 -2.9e-287)
     t_0
     (if (<= z 1.15e-138)
       t_1
       (if (<= z 1.05e-79) (/ y z) (if (<= z 2.4e-11) 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 <= -2.9e-287) {
		tmp = t_0;
	} else if (z <= 1.15e-138) {
		tmp = t_1;
	} else if (z <= 1.05e-79) {
		tmp = y / z;
	} else if (z <= 2.4e-11) {
		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 <= (-2.9d-287)) then
        tmp = t_0
    else if (z <= 1.15d-138) then
        tmp = t_1
    else if (z <= 1.05d-79) then
        tmp = y / z
    else if (z <= 2.4d-11) 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 <= -2.9e-287) {
		tmp = t_0;
	} else if (z <= 1.15e-138) {
		tmp = t_1;
	} else if (z <= 1.05e-79) {
		tmp = y / z;
	} else if (z <= 2.4e-11) {
		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 <= -2.9e-287:
		tmp = t_0
	elif z <= 1.15e-138:
		tmp = t_1
	elif z <= 1.05e-79:
		tmp = y / z
	elif z <= 2.4e-11:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x + Float64(y / z))
	t_1 = Float64(x / Float64(-z))
	tmp = 0.0
	if (z <= -2.9e-287)
		tmp = t_0;
	elseif (z <= 1.15e-138)
		tmp = t_1;
	elseif (z <= 1.05e-79)
		tmp = Float64(y / z);
	elseif (z <= 2.4e-11)
		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 <= -2.9e-287)
		tmp = t_0;
	elseif (z <= 1.15e-138)
		tmp = t_1;
	elseif (z <= 1.05e-79)
		tmp = y / z;
	elseif (z <= 2.4e-11)
		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, -2.9e-287], t$95$0, If[LessEqual[z, 1.15e-138], t$95$1, If[LessEqual[z, 1.05e-79], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.4e-11], 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 -2.9 \cdot 10^{-287}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 1.15 \cdot 10^{-138}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;z \leq 2.4 \cdot 10^{-11}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -2.8999999999999998e-287 or 2.4000000000000001e-11 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
      9. 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 86.5%

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

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

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

      \[\leadsto x - \color{blue}{\frac{-y}{z}} \]
    8. Step-by-step derivation
      1. sub-neg86.5%

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

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

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

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

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

    if -2.8999999999999998e-287 < z < 1.14999999999999995e-138 or 1.05e-79 < z < 2.4000000000000001e-11

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
      9. 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.9%

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

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

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

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

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

    if 1.14999999999999995e-138 < z < 1.05e-79

    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. sub-neg100.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
      9. 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 85.7%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.9 \cdot 10^{-287}:\\ \;\;\;\;x + \frac{y}{z}\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-138}:\\ \;\;\;\;\frac{x}{-z}\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{-79}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-11}:\\ \;\;\;\;\frac{x}{-z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 59.5% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;z \leq -2.15 \cdot 10^{+37} \lor \neg \left(z \leq -180\right) \land z \leq 2.5 \cdot 10^{+20}:\\
\;\;\;\;\frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -9.80000000000000003e110 or -2.1499999999999998e37 < z < -180 or 2.5e20 < 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. sub-neg100.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
      9. 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 78.5%

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

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

    if -9.80000000000000003e110 < z < -2.1499999999999998e37 or -180 < z < 2.5e20

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
      9. 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 57.8%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9.8 \cdot 10^{+110}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.15 \cdot 10^{+37} \lor \neg \left(z \leq -180\right) \land z \leq 2.5 \cdot 10^{+20}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 87.1% accurate, 0.5× speedup?

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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
      9. 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 89.6%

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

    if -2.25e15 < x < 5.79999999999999986e64

    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. sub-neg100.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
      9. 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 89.7%

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

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

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

      \[\leadsto x - \color{blue}{\frac{-y}{z}} \]
    8. Step-by-step derivation
      1. sub-neg89.7%

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

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

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

        \[\leadsto \color{blue}{\frac{y}{z}} + x \]
    9. Applied egg-rr89.7%

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

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

Alternative 6: 36.7% 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. sub-neg97.7%

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

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

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

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

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

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

      \[\leadsto \color{blue}{x - \left(\frac{x}{z} - \frac{y}{z}\right)} \]
    9. 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 62.8%

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

    \[\leadsto \color{blue}{x} \]
  7. Add Preprocessing

Reproduce

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