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

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

Alternative 2: 57.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -3.3 \cdot 10^{+210}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -8 \cdot 10^{+145} \lor \neg \left(z \leq -3.5 \cdot 10^{+47}\right) \land \left(z \leq 1.3 \cdot 10^{-38} \lor \neg \left(z \leq 7.5 \cdot 10^{+35}\right) \land \left(z \leq 1.85 \cdot 10^{+56} \lor \neg \left(z \leq 9 \cdot 10^{+192}\right) \land z \leq 9.2 \cdot 10^{+192}\right)\right):\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -3.3e+210)
   x
   (if (or (<= z -8e+145)
           (and (not (<= z -3.5e+47))
                (or (<= z 1.3e-38)
                    (and (not (<= z 7.5e+35))
                         (or (<= z 1.85e+56)
                             (and (not (<= z 9e+192)) (<= z 9.2e+192)))))))
     (/ y z)
     x)))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -3.3e+210) {
		tmp = x;
	} else if ((z <= -8e+145) || (!(z <= -3.5e+47) && ((z <= 1.3e-38) || (!(z <= 7.5e+35) && ((z <= 1.85e+56) || (!(z <= 9e+192) && (z <= 9.2e+192))))))) {
		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 <= (-3.3d+210)) then
        tmp = x
    else if ((z <= (-8d+145)) .or. (.not. (z <= (-3.5d+47))) .and. (z <= 1.3d-38) .or. (.not. (z <= 7.5d+35)) .and. (z <= 1.85d+56) .or. (.not. (z <= 9d+192)) .and. (z <= 9.2d+192)) 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 <= -3.3e+210) {
		tmp = x;
	} else if ((z <= -8e+145) || (!(z <= -3.5e+47) && ((z <= 1.3e-38) || (!(z <= 7.5e+35) && ((z <= 1.85e+56) || (!(z <= 9e+192) && (z <= 9.2e+192))))))) {
		tmp = y / z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -3.3e+210:
		tmp = x
	elif (z <= -8e+145) or (not (z <= -3.5e+47) and ((z <= 1.3e-38) or (not (z <= 7.5e+35) and ((z <= 1.85e+56) or (not (z <= 9e+192) and (z <= 9.2e+192)))))):
		tmp = y / z
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -3.3e+210)
		tmp = x;
	elseif ((z <= -8e+145) || (!(z <= -3.5e+47) && ((z <= 1.3e-38) || (!(z <= 7.5e+35) && ((z <= 1.85e+56) || (!(z <= 9e+192) && (z <= 9.2e+192)))))))
		tmp = Float64(y / z);
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -3.3e+210)
		tmp = x;
	elseif ((z <= -8e+145) || (~((z <= -3.5e+47)) && ((z <= 1.3e-38) || (~((z <= 7.5e+35)) && ((z <= 1.85e+56) || (~((z <= 9e+192)) && (z <= 9.2e+192)))))))
		tmp = y / z;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -3.3e+210], x, If[Or[LessEqual[z, -8e+145], And[N[Not[LessEqual[z, -3.5e+47]], $MachinePrecision], Or[LessEqual[z, 1.3e-38], And[N[Not[LessEqual[z, 7.5e+35]], $MachinePrecision], Or[LessEqual[z, 1.85e+56], And[N[Not[LessEqual[z, 9e+192]], $MachinePrecision], LessEqual[z, 9.2e+192]]]]]]], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -8 \cdot 10^{+145} \lor \neg \left(z \leq -3.5 \cdot 10^{+47}\right) \land \left(z \leq 1.3 \cdot 10^{-38} \lor \neg \left(z \leq 7.5 \cdot 10^{+35}\right) \land \left(z \leq 1.85 \cdot 10^{+56} \lor \neg \left(z \leq 9 \cdot 10^{+192}\right) \land z \leq 9.2 \cdot 10^{+192}\right)\right):\\
\;\;\;\;\frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.29999999999999995e210 or -7.9999999999999999e145 < z < -3.50000000000000015e47 or 1.30000000000000005e-38 < z < 7.4999999999999999e35 or 1.84999999999999998e56 < z < 9e192 or 9.1999999999999997e192 < 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 z around inf 74.8%

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

    if -3.29999999999999995e210 < z < -7.9999999999999999e145 or -3.50000000000000015e47 < z < 1.30000000000000005e-38 or 7.4999999999999999e35 < z < 1.84999999999999998e56 or 9e192 < z < 9.1999999999999997e192

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(x - \frac{x}{z}\right)} + \frac{y}{z} \]
      8. associate--r-97.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 50.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.3 \cdot 10^{+210}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -8 \cdot 10^{+145} \lor \neg \left(z \leq -3.5 \cdot 10^{+47}\right) \land \left(z \leq 1.3 \cdot 10^{-38} \lor \neg \left(z \leq 7.5 \cdot 10^{+35}\right) \land \left(z \leq 1.85 \cdot 10^{+56} \lor \neg \left(z \leq 9 \cdot 10^{+192}\right) \land z \leq 9.2 \cdot 10^{+192}\right)\right):\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 58.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{-z}\\ \mathbf{if}\;z \leq -3.3 \cdot 10^{+210}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -8 \cdot 10^{+145}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq -1.65 \cdot 10^{+21}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-56}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-151}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-54}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 9.8 \cdot 10^{-26}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ x (- z))))
   (if (<= z -3.3e+210)
     x
     (if (<= z -8e+145)
       (/ y z)
       (if (<= z -1.65e+21)
         x
         (if (<= z -1.1e-56)
           (/ y z)
           (if (<= z 2.3e-151)
             t_0
             (if (<= z 2.4e-54) (/ y z) (if (<= z 9.8e-26) t_0 x)))))))))
double code(double x, double y, double z) {
	double t_0 = x / -z;
	double tmp;
	if (z <= -3.3e+210) {
		tmp = x;
	} else if (z <= -8e+145) {
		tmp = y / z;
	} else if (z <= -1.65e+21) {
		tmp = x;
	} else if (z <= -1.1e-56) {
		tmp = y / z;
	} else if (z <= 2.3e-151) {
		tmp = t_0;
	} else if (z <= 2.4e-54) {
		tmp = y / z;
	} else if (z <= 9.8e-26) {
		tmp = t_0;
	} 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 <= (-3.3d+210)) then
        tmp = x
    else if (z <= (-8d+145)) then
        tmp = y / z
    else if (z <= (-1.65d+21)) then
        tmp = x
    else if (z <= (-1.1d-56)) then
        tmp = y / z
    else if (z <= 2.3d-151) then
        tmp = t_0
    else if (z <= 2.4d-54) then
        tmp = y / z
    else if (z <= 9.8d-26) then
        tmp = t_0
    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 <= -3.3e+210) {
		tmp = x;
	} else if (z <= -8e+145) {
		tmp = y / z;
	} else if (z <= -1.65e+21) {
		tmp = x;
	} else if (z <= -1.1e-56) {
		tmp = y / z;
	} else if (z <= 2.3e-151) {
		tmp = t_0;
	} else if (z <= 2.4e-54) {
		tmp = y / z;
	} else if (z <= 9.8e-26) {
		tmp = t_0;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x / -z
	tmp = 0
	if z <= -3.3e+210:
		tmp = x
	elif z <= -8e+145:
		tmp = y / z
	elif z <= -1.65e+21:
		tmp = x
	elif z <= -1.1e-56:
		tmp = y / z
	elif z <= 2.3e-151:
		tmp = t_0
	elif z <= 2.4e-54:
		tmp = y / z
	elif z <= 9.8e-26:
		tmp = t_0
	else:
		tmp = x
	return tmp
function code(x, y, z)
	t_0 = Float64(x / Float64(-z))
	tmp = 0.0
	if (z <= -3.3e+210)
		tmp = x;
	elseif (z <= -8e+145)
		tmp = Float64(y / z);
	elseif (z <= -1.65e+21)
		tmp = x;
	elseif (z <= -1.1e-56)
		tmp = Float64(y / z);
	elseif (z <= 2.3e-151)
		tmp = t_0;
	elseif (z <= 2.4e-54)
		tmp = Float64(y / z);
	elseif (z <= 9.8e-26)
		tmp = t_0;
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x / -z;
	tmp = 0.0;
	if (z <= -3.3e+210)
		tmp = x;
	elseif (z <= -8e+145)
		tmp = y / z;
	elseif (z <= -1.65e+21)
		tmp = x;
	elseif (z <= -1.1e-56)
		tmp = y / z;
	elseif (z <= 2.3e-151)
		tmp = t_0;
	elseif (z <= 2.4e-54)
		tmp = y / z;
	elseif (z <= 9.8e-26)
		tmp = t_0;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / (-z)), $MachinePrecision]}, If[LessEqual[z, -3.3e+210], x, If[LessEqual[z, -8e+145], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.65e+21], x, If[LessEqual[z, -1.1e-56], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.3e-151], t$95$0, If[LessEqual[z, 2.4e-54], N[(y / z), $MachinePrecision], If[LessEqual[z, 9.8e-26], t$95$0, x]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;z \leq -1.65 \cdot 10^{+21}:\\
\;\;\;\;x\\

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

\mathbf{elif}\;z \leq 2.3 \cdot 10^{-151}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;z \leq 9.8 \cdot 10^{-26}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -3.29999999999999995e210 or -7.9999999999999999e145 < z < -1.65e21 or 9.7999999999999998e-26 < 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 z around inf 75.5%

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

    if -3.29999999999999995e210 < z < -7.9999999999999999e145 or -1.65e21 < z < -1.10000000000000002e-56 or 2.29999999999999996e-151 < z < 2.40000000000000013e-54

    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 63.9%

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

    if -1.10000000000000002e-56 < z < 2.29999999999999996e-151 or 2.40000000000000013e-54 < z < 9.7999999999999998e-26

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\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 z around 0 100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.3 \cdot 10^{+210}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -8 \cdot 10^{+145}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq -1.65 \cdot 10^{+21}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-56}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-151}:\\ \;\;\;\;\frac{x}{-z}\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-54}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 9.8 \cdot 10^{-26}:\\ \;\;\;\;\frac{x}{-z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 73.7% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.06 \cdot 10^{+225} \lor \neg \left(x \leq 2.3 \cdot 10^{+34}\right) \land x \leq 3.4 \cdot 10^{+121}:\\
\;\;\;\;\frac{x}{-z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.06e225 or 2.2999999999999998e34 < x < 3.4000000000000001e121

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(x - \frac{x}{z}\right)} + \frac{y}{z} \]
      8. associate--r-94.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 z around 0 77.6%

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

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

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

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

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

    if -1.06e225 < x < 2.2999999999999998e34 or 3.4000000000000001e121 < x

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\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 74.1%

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

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

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

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

      \[\leadsto \color{blue}{x - -1 \cdot \frac{y}{z}} \]
    9. Step-by-step derivation
      1. cancel-sign-sub-inv74.1%

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

        \[\leadsto x + \color{blue}{1} \cdot \frac{y}{z} \]
      3. *-lft-identity74.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.06 \cdot 10^{+225} \lor \neg \left(x \leq 2.3 \cdot 10^{+34}\right) \land x \leq 3.4 \cdot 10^{+121}:\\ \;\;\;\;\frac{x}{-z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 96.9% accurate, 0.5× speedup?

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

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

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

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

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

      \[\leadsto \color{blue}{x - -1 \cdot \frac{y}{z}} \]
    9. Step-by-step derivation
      1. cancel-sign-sub-inv97.8%

        \[\leadsto \color{blue}{x + \left(--1\right) \cdot \frac{y}{z}} \]
      2. metadata-eval97.8%

        \[\leadsto x + \color{blue}{1} \cdot \frac{y}{z} \]
      3. *-lft-identity97.8%

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

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

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

    if -4.79999999999999985e36 < z < 9.7999999999999998e-26

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\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 z around 0 97.5%

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

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

Alternative 6: 86.9% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -6.2e5 or 3.60000000000000034e-33 < y

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(x - \frac{x}{z}\right)} + \frac{y}{z} \]
      8. associate--r-97.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 84.0%

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

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

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

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

      \[\leadsto \color{blue}{x - -1 \cdot \frac{y}{z}} \]
    9. Step-by-step derivation
      1. cancel-sign-sub-inv84.0%

        \[\leadsto \color{blue}{x + \left(--1\right) \cdot \frac{y}{z}} \]
      2. metadata-eval84.0%

        \[\leadsto x + \color{blue}{1} \cdot \frac{y}{z} \]
      3. *-lft-identity84.0%

        \[\leadsto x + \color{blue}{\frac{y}{z}} \]
      4. +-commutative84.0%

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

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

    if -6.2e5 < y < 3.60000000000000034e-33

    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 83.8%

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

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

Alternative 7: 37.1% 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-sub98.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(x - \frac{x}{z}\right)} + \frac{y}{z} \]
    8. associate--r-98.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 z around inf 32.8%

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

Reproduce

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