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

Percentage Accurate: 100.0% → 100.0%
Time: 6.8s
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: 98.8% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
\mathbf{if}\;z \leq -1.1 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\

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

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


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

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto x + \color{blue}{\frac{y}{z}} \]
    4. Step-by-step derivation
      1. lower-/.f6499.2

        \[\leadsto x + \color{blue}{\frac{y}{z}} \]
    5. Applied rewrites99.2%

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

    if -1.1e14 < z < 1

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in z around 0

      \[\leadsto \color{blue}{\frac{y - x}{z}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{y - x}{z}} \]
      2. lower--.f6499.3

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

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

Alternative 3: 86.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x - \frac{x}{z}\\ \mathbf{if}\;x \leq -5.6 \cdot 10^{+42}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 58000:\\ \;\;\;\;x + \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- x (/ x z))))
   (if (<= x -5.6e+42) t_0 (if (<= x 58000.0) (+ x (/ y z)) t_0))))
double code(double x, double y, double z) {
	double t_0 = x - (x / z);
	double tmp;
	if (x <= -5.6e+42) {
		tmp = t_0;
	} else if (x <= 58000.0) {
		tmp = x + (y / z);
	} 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) :: tmp
    t_0 = x - (x / z)
    if (x <= (-5.6d+42)) then
        tmp = t_0
    else if (x <= 58000.0d0) then
        tmp = x + (y / z)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x - (x / z);
	double tmp;
	if (x <= -5.6e+42) {
		tmp = t_0;
	} else if (x <= 58000.0) {
		tmp = x + (y / z);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x - (x / z)
	tmp = 0
	if x <= -5.6e+42:
		tmp = t_0
	elif x <= 58000.0:
		tmp = x + (y / z)
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x - Float64(x / z))
	tmp = 0.0
	if (x <= -5.6e+42)
		tmp = t_0;
	elseif (x <= 58000.0)
		tmp = Float64(x + Float64(y / z));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x - (x / z);
	tmp = 0.0;
	if (x <= -5.6e+42)
		tmp = t_0;
	elseif (x <= 58000.0)
		tmp = x + (y / z);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.6e+42], t$95$0, If[LessEqual[x, 58000.0], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x - \frac{x}{z}\\
\mathbf{if}\;x \leq -5.6 \cdot 10^{+42}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 58000:\\
\;\;\;\;x + \frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.5999999999999999e42 or 58000 < x

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(1 - \frac{1}{z}\right)} \]
    4. Step-by-step derivation
      1. distribute-lft-out--N/A

        \[\leadsto \color{blue}{x \cdot 1 - x \cdot \frac{1}{z}} \]
      2. *-rgt-identityN/A

        \[\leadsto \color{blue}{x} - x \cdot \frac{1}{z} \]
      3. associate-*r/N/A

        \[\leadsto x - \color{blue}{\frac{x \cdot 1}{z}} \]
      4. *-rgt-identityN/A

        \[\leadsto x - \frac{\color{blue}{x}}{z} \]
      5. lower--.f64N/A

        \[\leadsto \color{blue}{x - \frac{x}{z}} \]
      6. lower-/.f6489.4

        \[\leadsto x - \color{blue}{\frac{x}{z}} \]
    5. Applied rewrites89.4%

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

    if -5.5999999999999999e42 < x < 58000

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto x + \color{blue}{\frac{y}{z}} \]
    4. Step-by-step derivation
      1. lower-/.f6490.6

        \[\leadsto x + \color{blue}{\frac{y}{z}} \]
    5. Applied rewrites90.6%

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

Alternative 4: 76.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x + \frac{y}{z}\\ \mathbf{if}\;z \leq -6.3 \cdot 10^{-301}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-128}:\\ \;\;\;\;-\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ x (/ y z))))
   (if (<= z -6.3e-301) t_0 (if (<= z 5e-128) (- (/ x z)) t_0))))
double code(double x, double y, double z) {
	double t_0 = x + (y / z);
	double tmp;
	if (z <= -6.3e-301) {
		tmp = t_0;
	} else if (z <= 5e-128) {
		tmp = -(x / z);
	} 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) :: tmp
    t_0 = x + (y / z)
    if (z <= (-6.3d-301)) then
        tmp = t_0
    else if (z <= 5d-128) then
        tmp = -(x / z)
    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 tmp;
	if (z <= -6.3e-301) {
		tmp = t_0;
	} else if (z <= 5e-128) {
		tmp = -(x / z);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x + (y / z)
	tmp = 0
	if z <= -6.3e-301:
		tmp = t_0
	elif z <= 5e-128:
		tmp = -(x / z)
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x + Float64(y / z))
	tmp = 0.0
	if (z <= -6.3e-301)
		tmp = t_0;
	elseif (z <= 5e-128)
		tmp = Float64(-Float64(x / z));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x + (y / z);
	tmp = 0.0;
	if (z <= -6.3e-301)
		tmp = t_0;
	elseif (z <= 5e-128)
		tmp = -(x / z);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6.3e-301], t$95$0, If[LessEqual[z, 5e-128], (-N[(x / z), $MachinePrecision]), t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
\mathbf{if}\;z \leq -6.3 \cdot 10^{-301}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 5 \cdot 10^{-128}:\\
\;\;\;\;-\frac{x}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -6.29999999999999961e-301 or 5.0000000000000001e-128 < z

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto x + \color{blue}{\frac{y}{z}} \]
    4. Step-by-step derivation
      1. lower-/.f6487.2

        \[\leadsto x + \color{blue}{\frac{y}{z}} \]
    5. Applied rewrites87.2%

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

    if -6.29999999999999961e-301 < z < 5.0000000000000001e-128

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(1 - \frac{1}{z}\right)} \]
    4. Step-by-step derivation
      1. distribute-lft-out--N/A

        \[\leadsto \color{blue}{x \cdot 1 - x \cdot \frac{1}{z}} \]
      2. *-rgt-identityN/A

        \[\leadsto \color{blue}{x} - x \cdot \frac{1}{z} \]
      3. associate-*r/N/A

        \[\leadsto x - \color{blue}{\frac{x \cdot 1}{z}} \]
      4. *-rgt-identityN/A

        \[\leadsto x - \frac{\color{blue}{x}}{z} \]
      5. lower--.f64N/A

        \[\leadsto \color{blue}{x - \frac{x}{z}} \]
      6. lower-/.f6466.5

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{z}} \]
    7. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{z}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(x\right)}}{z} \]
      3. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(x\right)}{z}} \]
      4. lower-neg.f6466.5

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

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

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

Alternative 5: 52.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{-94}:\\
\;\;\;\;\frac{y}{z}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.2e-94 or 4.49999999999999969e-117 < y

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{y}{z}} \]
    4. Step-by-step derivation
      1. lower-/.f6461.3

        \[\leadsto \color{blue}{\frac{y}{z}} \]
    5. Applied rewrites61.3%

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

    if -1.2e-94 < y < 4.49999999999999969e-117

    1. Initial program 100.0%

      \[x + \frac{y - x}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(1 - \frac{1}{z}\right)} \]
    4. Step-by-step derivation
      1. distribute-lft-out--N/A

        \[\leadsto \color{blue}{x \cdot 1 - x \cdot \frac{1}{z}} \]
      2. *-rgt-identityN/A

        \[\leadsto \color{blue}{x} - x \cdot \frac{1}{z} \]
      3. associate-*r/N/A

        \[\leadsto x - \color{blue}{\frac{x \cdot 1}{z}} \]
      4. *-rgt-identityN/A

        \[\leadsto x - \frac{\color{blue}{x}}{z} \]
      5. lower--.f64N/A

        \[\leadsto \color{blue}{x - \frac{x}{z}} \]
      6. lower-/.f6489.2

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{z}} \]
    7. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{z}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(x\right)}}{z} \]
      3. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(x\right)}{z}} \]
      4. lower-neg.f6442.9

        \[\leadsto \frac{\color{blue}{-x}}{z} \]
    8. Applied rewrites42.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.2 \cdot 10^{-94}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-117}:\\ \;\;\;\;-\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 42.2% accurate, 1.5× speedup?

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

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

    \[x + \frac{y - x}{z} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{y}{z}} \]
  4. Step-by-step derivation
    1. lower-/.f6445.8

      \[\leadsto \color{blue}{\frac{y}{z}} \]
  5. Applied rewrites45.8%

    \[\leadsto \color{blue}{\frac{y}{z}} \]
  6. Add Preprocessing

Reproduce

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