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

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

Specification

?
\[\begin{array}{l} \\ x + \frac{y - x}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
	return x + ((y - x) / z);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
	return x + ((y - x) / z);
}
def code(x, y, z):
	return x + ((y - x) / z)
function code(x, y, z)
	return Float64(x + Float64(Float64(y - x) / z))
end
function tmp = code(x, y, z)
	tmp = x + ((y - x) / z);
end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \frac{y - x}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
	return x + ((y - x) / z);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
	return x + ((y - x) / z);
}
def code(x, y, z):
	return x + ((y - x) / z)
function code(x, y, z)
	return Float64(x + Float64(Float64(y - x) / z))
end
function tmp = code(x, y, z)
	tmp = x + ((y - x) / z);
end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \frac{y - x}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
	return x + ((y - x) / z);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
	return x + ((y - x) / z);
}
def code(x, y, z):
	return x + ((y - x) / z)
function code(x, y, z)
	return Float64(x + Float64(Float64(y - x) / z))
end
function tmp = code(x, y, z)
	tmp = x + ((y - x) / z);
end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

Alternative 2: 61.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-x}{z}\\ \mathbf{if}\;z \leq -2 \cdot 10^{+25}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-62}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-190}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-246}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{-222}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-89}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (- x) z)))
   (if (<= z -2e+25)
     x
     (if (<= z -5e-62)
       (/ y z)
       (if (<= z -4.2e-190)
         t_0
         (if (<= z -3.4e-246)
           (/ y z)
           (if (<= z 8.8e-222)
             t_0
             (if (<= z 4.5e-89) (/ y z) (if (<= z 1.0) t_0 x)))))))))
double code(double x, double y, double z) {
	double t_0 = -x / z;
	double tmp;
	if (z <= -2e+25) {
		tmp = x;
	} else if (z <= -5e-62) {
		tmp = y / z;
	} else if (z <= -4.2e-190) {
		tmp = t_0;
	} else if (z <= -3.4e-246) {
		tmp = y / z;
	} else if (z <= 8.8e-222) {
		tmp = t_0;
	} else if (z <= 4.5e-89) {
		tmp = y / z;
	} else if (z <= 1.0) {
		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 <= (-2d+25)) then
        tmp = x
    else if (z <= (-5d-62)) then
        tmp = y / z
    else if (z <= (-4.2d-190)) then
        tmp = t_0
    else if (z <= (-3.4d-246)) then
        tmp = y / z
    else if (z <= 8.8d-222) then
        tmp = t_0
    else if (z <= 4.5d-89) then
        tmp = y / z
    else if (z <= 1.0d0) 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 <= -2e+25) {
		tmp = x;
	} else if (z <= -5e-62) {
		tmp = y / z;
	} else if (z <= -4.2e-190) {
		tmp = t_0;
	} else if (z <= -3.4e-246) {
		tmp = y / z;
	} else if (z <= 8.8e-222) {
		tmp = t_0;
	} else if (z <= 4.5e-89) {
		tmp = y / z;
	} else if (z <= 1.0) {
		tmp = t_0;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = -x / z
	tmp = 0
	if z <= -2e+25:
		tmp = x
	elif z <= -5e-62:
		tmp = y / z
	elif z <= -4.2e-190:
		tmp = t_0
	elif z <= -3.4e-246:
		tmp = y / z
	elif z <= 8.8e-222:
		tmp = t_0
	elif z <= 4.5e-89:
		tmp = y / z
	elif z <= 1.0:
		tmp = t_0
	else:
		tmp = x
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(-x) / z)
	tmp = 0.0
	if (z <= -2e+25)
		tmp = x;
	elseif (z <= -5e-62)
		tmp = Float64(y / z);
	elseif (z <= -4.2e-190)
		tmp = t_0;
	elseif (z <= -3.4e-246)
		tmp = Float64(y / z);
	elseif (z <= 8.8e-222)
		tmp = t_0;
	elseif (z <= 4.5e-89)
		tmp = Float64(y / z);
	elseif (z <= 1.0)
		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 <= -2e+25)
		tmp = x;
	elseif (z <= -5e-62)
		tmp = y / z;
	elseif (z <= -4.2e-190)
		tmp = t_0;
	elseif (z <= -3.4e-246)
		tmp = y / z;
	elseif (z <= 8.8e-222)
		tmp = t_0;
	elseif (z <= 4.5e-89)
		tmp = y / z;
	elseif (z <= 1.0)
		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, -2e+25], x, If[LessEqual[z, -5e-62], N[(y / z), $MachinePrecision], If[LessEqual[z, -4.2e-190], t$95$0, If[LessEqual[z, -3.4e-246], N[(y / z), $MachinePrecision], If[LessEqual[z, 8.8e-222], t$95$0, If[LessEqual[z, 4.5e-89], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], t$95$0, x]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -5 \cdot 10^{-62}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq -4.2 \cdot 10^{-190}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;z \leq 8.8 \cdot 10^{-222}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 100.0%

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

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

    if -2.00000000000000018e25 < z < -5.0000000000000002e-62 or -4.19999999999999983e-190 < z < -3.4000000000000001e-246 or 8.8000000000000001e-222 < z < 4.4999999999999999e-89

    1. Initial program 100.0%

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

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

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

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

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

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

    if -5.0000000000000002e-62 < z < -4.19999999999999983e-190 or -3.4000000000000001e-246 < z < 8.8000000000000001e-222 or 4.4999999999999999e-89 < z < 1

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\left(1 - \frac{1}{z}\right) \cdot x} \]
    3. Taylor expanded in z around 0 68.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+25}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-62}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-190}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-246}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{-222}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-89}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 3: 76.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x + \frac{y}{z}\\ t_1 := \frac{-x}{z}\\ \mathbf{if}\;z \leq -3.5 \cdot 10^{-61}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-188}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-245}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{-227}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-89}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 4.7 \cdot 10^{-36}:\\ \;\;\;\;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 -3.5e-61)
     t_0
     (if (<= z -4.8e-188)
       t_1
       (if (<= z -2.2e-245)
         (/ y z)
         (if (<= z 7.6e-227)
           t_1
           (if (<= z 7e-89) (/ y z) (if (<= z 4.7e-36) 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 <= -3.5e-61) {
		tmp = t_0;
	} else if (z <= -4.8e-188) {
		tmp = t_1;
	} else if (z <= -2.2e-245) {
		tmp = y / z;
	} else if (z <= 7.6e-227) {
		tmp = t_1;
	} else if (z <= 7e-89) {
		tmp = y / z;
	} else if (z <= 4.7e-36) {
		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 <= (-3.5d-61)) then
        tmp = t_0
    else if (z <= (-4.8d-188)) then
        tmp = t_1
    else if (z <= (-2.2d-245)) then
        tmp = y / z
    else if (z <= 7.6d-227) then
        tmp = t_1
    else if (z <= 7d-89) then
        tmp = y / z
    else if (z <= 4.7d-36) 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 <= -3.5e-61) {
		tmp = t_0;
	} else if (z <= -4.8e-188) {
		tmp = t_1;
	} else if (z <= -2.2e-245) {
		tmp = y / z;
	} else if (z <= 7.6e-227) {
		tmp = t_1;
	} else if (z <= 7e-89) {
		tmp = y / z;
	} else if (z <= 4.7e-36) {
		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 <= -3.5e-61:
		tmp = t_0
	elif z <= -4.8e-188:
		tmp = t_1
	elif z <= -2.2e-245:
		tmp = y / z
	elif z <= 7.6e-227:
		tmp = t_1
	elif z <= 7e-89:
		tmp = y / z
	elif z <= 4.7e-36:
		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 <= -3.5e-61)
		tmp = t_0;
	elseif (z <= -4.8e-188)
		tmp = t_1;
	elseif (z <= -2.2e-245)
		tmp = Float64(y / z);
	elseif (z <= 7.6e-227)
		tmp = t_1;
	elseif (z <= 7e-89)
		tmp = Float64(y / z);
	elseif (z <= 4.7e-36)
		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 <= -3.5e-61)
		tmp = t_0;
	elseif (z <= -4.8e-188)
		tmp = t_1;
	elseif (z <= -2.2e-245)
		tmp = y / z;
	elseif (z <= 7.6e-227)
		tmp = t_1;
	elseif (z <= 7e-89)
		tmp = y / z;
	elseif (z <= 4.7e-36)
		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, -3.5e-61], t$95$0, If[LessEqual[z, -4.8e-188], t$95$1, If[LessEqual[z, -2.2e-245], N[(y / z), $MachinePrecision], If[LessEqual[z, 7.6e-227], t$95$1, If[LessEqual[z, 7e-89], N[(y / z), $MachinePrecision], If[LessEqual[z, 4.7e-36], 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 -3.5 \cdot 10^{-61}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq -4.8 \cdot 10^{-188}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq -2.2 \cdot 10^{-245}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq 7.6 \cdot 10^{-227}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 7 \cdot 10^{-89}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq 4.7 \cdot 10^{-36}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -3.5000000000000003e-61 or 4.7000000000000003e-36 < z

    1. Initial program 100.0%

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

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

    if -3.5000000000000003e-61 < z < -4.8e-188 or -2.19999999999999993e-245 < z < 7.60000000000000019e-227 or 6.9999999999999994e-89 < z < 4.7000000000000003e-36

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\left(1 - \frac{1}{z}\right) \cdot x} \]
    3. Taylor expanded in z around 0 71.1%

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

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

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

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

    if -4.8e-188 < z < -2.19999999999999993e-245 or 7.60000000000000019e-227 < z < 6.9999999999999994e-89

    1. Initial program 100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{-61}:\\ \;\;\;\;x + \frac{y}{z}\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-188}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-245}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{-227}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-89}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;z \leq 4.7 \cdot 10^{-36}:\\ \;\;\;\;\frac{-x}{z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z}\\ \end{array} \]

Alternative 4: 86.5% accurate, 0.8× speedup?

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

    1. Initial program 100.0%

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

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

    if -9.2e-63 < y < 4.59999999999999958e-13

    1. Initial program 100.0%

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

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

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

Alternative 5: 98.9% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

    if -1 < z < 1

    1. Initial program 100.0%

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

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

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

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

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

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

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

Alternative 6: 62.3% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;z \leq 3 \cdot 10^{+44}:\\
\;\;\;\;\frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.79999999999999975e23 or 2.99999999999999987e44 < z

    1. Initial program 100.0%

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

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

    if -3.79999999999999975e23 < z < 2.99999999999999987e44

    1. Initial program 100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{+23}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+44}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

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. Taylor expanded in z around inf 41.0%

    \[\leadsto \color{blue}{x} \]
  3. Final simplification41.0%

    \[\leadsto x \]

Reproduce

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