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

Percentage Accurate: 100.0% → 100.0%
Time: 2.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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    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: 61.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-x}{z}\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{-271}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-104}:\\ \;\;\;\;\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 -1.0)
     x
     (if (<= z -1.5e-271)
       t_0
       (if (<= z 1.8e-104) (/ 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 <= -1.0) {
		tmp = x;
	} else if (z <= -1.5e-271) {
		tmp = t_0;
	} else if (z <= 1.8e-104) {
		tmp = y / z;
	} else if (z <= 1.0) {
		tmp = t_0;
	} else {
		tmp = x;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = -x / z
    if (z <= (-1.0d0)) then
        tmp = x
    else if (z <= (-1.5d-271)) then
        tmp = t_0
    else if (z <= 1.8d-104) 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 <= -1.0) {
		tmp = x;
	} else if (z <= -1.5e-271) {
		tmp = t_0;
	} else if (z <= 1.8e-104) {
		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 <= -1.0:
		tmp = x
	elif z <= -1.5e-271:
		tmp = t_0
	elif z <= 1.8e-104:
		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 <= -1.0)
		tmp = x;
	elseif (z <= -1.5e-271)
		tmp = t_0;
	elseif (z <= 1.8e-104)
		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 <= -1.0)
		tmp = x;
	elseif (z <= -1.5e-271)
		tmp = t_0;
	elseif (z <= 1.8e-104)
		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, -1.0], x, If[LessEqual[z, -1.5e-271], t$95$0, If[LessEqual[z, 1.8e-104], 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 -1:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq -1.5 \cdot 10^{-271}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 1.8 \cdot 10^{-104}:\\
\;\;\;\;\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 < -1 or 1 < z

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x} \]
    4. Step-by-step derivation
      1. Applied rewrites69.8%

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

      if -1 < z < -1.50000000000000001e-271 or 1.7999999999999999e-104 < z < 1

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{x - \frac{x}{z}} \]
      4. Step-by-step derivation
        1. Applied rewrites69.6%

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

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

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

          if -1.50000000000000001e-271 < z < 1.7999999999999999e-104

          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. Applied rewrites79.7%

              \[\leadsto \color{blue}{\frac{y}{z}} \]
          5. Recombined 3 regimes into one program.
          6. Add Preprocessing

          Alternative 3: 99.1% accurate, 0.7× 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;
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(x, y, z)
          use fmin_fmax_functions
              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. Add Preprocessing
            3. Taylor expanded in x around 0

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

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

              if -1 < 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. Applied rewrites98.7%

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

                \[\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} \]
              7. Add Preprocessing

              Alternative 4: 75.7% accurate, 0.7× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -9.5 \cdot 10^{+70} \lor \neg \left(y \leq 1.4 \cdot 10^{+85}\right):\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{z}\\ \end{array} \end{array} \]
              (FPCore (x y z)
               :precision binary64
               (if (or (<= y -9.5e+70) (not (<= y 1.4e+85))) (/ y z) (- x (/ x z))))
              double code(double x, double y, double z) {
              	double tmp;
              	if ((y <= -9.5e+70) || !(y <= 1.4e+85)) {
              		tmp = y / z;
              	} else {
              		tmp = x - (x / z);
              	}
              	return tmp;
              }
              
              module fmin_fmax_functions
                  implicit none
                  private
                  public fmax
                  public fmin
              
                  interface fmax
                      module procedure fmax88
                      module procedure fmax44
                      module procedure fmax84
                      module procedure fmax48
                  end interface
                  interface fmin
                      module procedure fmin88
                      module procedure fmin44
                      module procedure fmin84
                      module procedure fmin48
                  end interface
              contains
                  real(8) function fmax88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmax44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmax84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmax48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                  end function
                  real(8) function fmin88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmin44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmin84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmin48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                  end function
              end module
              
              real(8) function code(x, y, z)
              use fmin_fmax_functions
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  real(8), intent (in) :: z
                  real(8) :: tmp
                  if ((y <= (-9.5d+70)) .or. (.not. (y <= 1.4d+85))) then
                      tmp = 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.5e+70) || !(y <= 1.4e+85)) {
              		tmp = y / z;
              	} else {
              		tmp = x - (x / z);
              	}
              	return tmp;
              }
              
              def code(x, y, z):
              	tmp = 0
              	if (y <= -9.5e+70) or not (y <= 1.4e+85):
              		tmp = y / z
              	else:
              		tmp = x - (x / z)
              	return tmp
              
              function code(x, y, z)
              	tmp = 0.0
              	if ((y <= -9.5e+70) || !(y <= 1.4e+85))
              		tmp = 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.5e+70) || ~((y <= 1.4e+85)))
              		tmp = y / z;
              	else
              		tmp = x - (x / z);
              	end
              	tmp_2 = tmp;
              end
              
              code[x_, y_, z_] := If[Or[LessEqual[y, -9.5e+70], N[Not[LessEqual[y, 1.4e+85]], $MachinePrecision]], N[(y / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;y \leq -9.5 \cdot 10^{+70} \lor \neg \left(y \leq 1.4 \cdot 10^{+85}\right):\\
              \;\;\;\;\frac{y}{z}\\
              
              \mathbf{else}:\\
              \;\;\;\;x - \frac{x}{z}\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if y < -9.5000000000000002e70 or 1.4e85 < 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. Applied rewrites74.1%

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

                  if -9.5000000000000002e70 < y < 1.4e85

                  1. Initial program 100.0%

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

                    \[\leadsto \color{blue}{x - \frac{x}{z}} \]
                  4. Step-by-step derivation
                    1. Applied rewrites85.2%

                      \[\leadsto \color{blue}{x - \frac{x}{z}} \]
                  5. Recombined 2 regimes into one program.
                  6. Final simplification80.8%

                    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9.5 \cdot 10^{+70} \lor \neg \left(y \leq 1.4 \cdot 10^{+85}\right):\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{z}\\ \end{array} \]
                  7. Add Preprocessing

                  Alternative 5: 84.9% accurate, 0.7× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -6.2 \cdot 10^{+39}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 0.00075:\\ \;\;\;\;\frac{y - x}{z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{z}\\ \end{array} \end{array} \]
                  (FPCore (x y z)
                   :precision binary64
                   (if (<= z -6.2e+39) x (if (<= z 0.00075) (/ (- y x) z) (- x (/ x z)))))
                  double code(double x, double y, double z) {
                  	double tmp;
                  	if (z <= -6.2e+39) {
                  		tmp = x;
                  	} else if (z <= 0.00075) {
                  		tmp = (y - x) / z;
                  	} else {
                  		tmp = x - (x / z);
                  	}
                  	return tmp;
                  }
                  
                  module fmin_fmax_functions
                      implicit none
                      private
                      public fmax
                      public fmin
                  
                      interface fmax
                          module procedure fmax88
                          module procedure fmax44
                          module procedure fmax84
                          module procedure fmax48
                      end interface
                      interface fmin
                          module procedure fmin88
                          module procedure fmin44
                          module procedure fmin84
                          module procedure fmin48
                      end interface
                  contains
                      real(8) function fmax88(x, y) result (res)
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                      end function
                      real(4) function fmax44(x, y) result (res)
                          real(4), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                      end function
                      real(8) function fmax84(x, y) result(res)
                          real(8), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                      end function
                      real(8) function fmax48(x, y) result(res)
                          real(4), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                      end function
                      real(8) function fmin88(x, y) result (res)
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                      end function
                      real(4) function fmin44(x, y) result (res)
                          real(4), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                      end function
                      real(8) function fmin84(x, y) result(res)
                          real(8), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                      end function
                      real(8) function fmin48(x, y) result(res)
                          real(4), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                      end function
                  end module
                  
                  real(8) function code(x, y, z)
                  use fmin_fmax_functions
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      real(8), intent (in) :: z
                      real(8) :: tmp
                      if (z <= (-6.2d+39)) then
                          tmp = x
                      else if (z <= 0.00075d0) then
                          tmp = (y - x) / 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 (z <= -6.2e+39) {
                  		tmp = x;
                  	} else if (z <= 0.00075) {
                  		tmp = (y - x) / z;
                  	} else {
                  		tmp = x - (x / z);
                  	}
                  	return tmp;
                  }
                  
                  def code(x, y, z):
                  	tmp = 0
                  	if z <= -6.2e+39:
                  		tmp = x
                  	elif z <= 0.00075:
                  		tmp = (y - x) / z
                  	else:
                  		tmp = x - (x / z)
                  	return tmp
                  
                  function code(x, y, z)
                  	tmp = 0.0
                  	if (z <= -6.2e+39)
                  		tmp = x;
                  	elseif (z <= 0.00075)
                  		tmp = Float64(Float64(y - x) / z);
                  	else
                  		tmp = Float64(x - Float64(x / z));
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(x, y, z)
                  	tmp = 0.0;
                  	if (z <= -6.2e+39)
                  		tmp = x;
                  	elseif (z <= 0.00075)
                  		tmp = (y - x) / z;
                  	else
                  		tmp = x - (x / z);
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[x_, y_, z_] := If[LessEqual[z, -6.2e+39], x, If[LessEqual[z, 0.00075], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;z \leq -6.2 \cdot 10^{+39}:\\
                  \;\;\;\;x\\
                  
                  \mathbf{elif}\;z \leq 0.00075:\\
                  \;\;\;\;\frac{y - x}{z}\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;x - \frac{x}{z}\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if z < -6.2000000000000005e39

                    1. Initial program 100.0%

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

                      \[\leadsto \color{blue}{x} \]
                    4. Step-by-step derivation
                      1. Applied rewrites73.3%

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

                      if -6.2000000000000005e39 < z < 7.5000000000000002e-4

                      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. Applied rewrites95.7%

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

                        if 7.5000000000000002e-4 < z

                        1. Initial program 100.0%

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

                          \[\leadsto \color{blue}{x - \frac{x}{z}} \]
                        4. Step-by-step derivation
                          1. Applied rewrites74.8%

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

                        Alternative 6: 61.9% accurate, 0.7× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{+39}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2 \cdot 10^{+30}:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
                        (FPCore (x y z)
                         :precision binary64
                         (if (<= z -6e+39) x (if (<= z 2e+30) (/ y z) x)))
                        double code(double x, double y, double z) {
                        	double tmp;
                        	if (z <= -6e+39) {
                        		tmp = x;
                        	} else if (z <= 2e+30) {
                        		tmp = y / z;
                        	} else {
                        		tmp = x;
                        	}
                        	return tmp;
                        }
                        
                        module fmin_fmax_functions
                            implicit none
                            private
                            public fmax
                            public fmin
                        
                            interface fmax
                                module procedure fmax88
                                module procedure fmax44
                                module procedure fmax84
                                module procedure fmax48
                            end interface
                            interface fmin
                                module procedure fmin88
                                module procedure fmin44
                                module procedure fmin84
                                module procedure fmin48
                            end interface
                        contains
                            real(8) function fmax88(x, y) result (res)
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                            end function
                            real(4) function fmax44(x, y) result (res)
                                real(4), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                            end function
                            real(8) function fmax84(x, y) result(res)
                                real(8), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                            end function
                            real(8) function fmax48(x, y) result(res)
                                real(4), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                            end function
                            real(8) function fmin88(x, y) result (res)
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                            end function
                            real(4) function fmin44(x, y) result (res)
                                real(4), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                            end function
                            real(8) function fmin84(x, y) result(res)
                                real(8), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                            end function
                            real(8) function fmin48(x, y) result(res)
                                real(4), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                            end function
                        end module
                        
                        real(8) function code(x, y, z)
                        use fmin_fmax_functions
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            real(8), intent (in) :: z
                            real(8) :: tmp
                            if (z <= (-6d+39)) then
                                tmp = x
                            else if (z <= 2d+30) 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 <= -6e+39) {
                        		tmp = x;
                        	} else if (z <= 2e+30) {
                        		tmp = y / z;
                        	} else {
                        		tmp = x;
                        	}
                        	return tmp;
                        }
                        
                        def code(x, y, z):
                        	tmp = 0
                        	if z <= -6e+39:
                        		tmp = x
                        	elif z <= 2e+30:
                        		tmp = y / z
                        	else:
                        		tmp = x
                        	return tmp
                        
                        function code(x, y, z)
                        	tmp = 0.0
                        	if (z <= -6e+39)
                        		tmp = x;
                        	elseif (z <= 2e+30)
                        		tmp = Float64(y / z);
                        	else
                        		tmp = x;
                        	end
                        	return tmp
                        end
                        
                        function tmp_2 = code(x, y, z)
                        	tmp = 0.0;
                        	if (z <= -6e+39)
                        		tmp = x;
                        	elseif (z <= 2e+30)
                        		tmp = y / z;
                        	else
                        		tmp = x;
                        	end
                        	tmp_2 = tmp;
                        end
                        
                        code[x_, y_, z_] := If[LessEqual[z, -6e+39], x, If[LessEqual[z, 2e+30], N[(y / z), $MachinePrecision], x]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;z \leq -6 \cdot 10^{+39}:\\
                        \;\;\;\;x\\
                        
                        \mathbf{elif}\;z \leq 2 \cdot 10^{+30}:\\
                        \;\;\;\;\frac{y}{z}\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;x\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if z < -5.9999999999999999e39 or 2e30 < z

                          1. Initial program 100.0%

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

                            \[\leadsto \color{blue}{x} \]
                          4. Step-by-step derivation
                            1. Applied rewrites74.8%

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

                            if -5.9999999999999999e39 < z < 2e30

                            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. Applied rewrites50.8%

                                \[\leadsto \color{blue}{\frac{y}{z}} \]
                            5. Recombined 2 regimes into one program.
                            6. Add Preprocessing

                            Alternative 7: 36.8% accurate, 18.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;
                            }
                            
                            module fmin_fmax_functions
                                implicit none
                                private
                                public fmax
                                public fmin
                            
                                interface fmax
                                    module procedure fmax88
                                    module procedure fmax44
                                    module procedure fmax84
                                    module procedure fmax48
                                end interface
                                interface fmin
                                    module procedure fmin88
                                    module procedure fmin44
                                    module procedure fmin84
                                    module procedure fmin48
                                end interface
                            contains
                                real(8) function fmax88(x, y) result (res)
                                    real(8), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                end function
                                real(4) function fmax44(x, y) result (res)
                                    real(4), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                end function
                                real(8) function fmax84(x, y) result(res)
                                    real(8), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                end function
                                real(8) function fmax48(x, y) result(res)
                                    real(4), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                end function
                                real(8) function fmin88(x, y) result (res)
                                    real(8), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                end function
                                real(4) function fmin44(x, y) result (res)
                                    real(4), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                end function
                                real(8) function fmin84(x, y) result(res)
                                    real(8), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                end function
                                real(8) function fmin48(x, y) result(res)
                                    real(4), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                end function
                            end module
                            
                            real(8) function code(x, y, z)
                            use fmin_fmax_functions
                                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. Add Preprocessing
                            3. Taylor expanded in z around inf

                              \[\leadsto \color{blue}{x} \]
                            4. Step-by-step derivation
                              1. Applied rewrites40.4%

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

                              Reproduce

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