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

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

Specification

?
\[\begin{array}{l} \\ x + \frac{y - x}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
	return x + ((y - x) / z);
}
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.9% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;z \leq 9.5 \cdot 10^{-264}:\\
\;\;\;\;\frac{y}{z}\\

\mathbf{elif}\;z \leq 1.1 \cdot 10^{-113}:\\
\;\;\;\;\frac{-x}{z}\\

\mathbf{elif}\;z \leq 1400000:\\
\;\;\;\;\frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -3.69999999999999997e59 or 1.4e6 < 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 rewrites75.5%

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

      if -3.69999999999999997e59 < z < 9.50000000000000012e-264 or 1.10000000000000002e-113 < z < 1.4e6

      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 rewrites68.4%

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

        if 9.50000000000000012e-264 < z < 1.10000000000000002e-113

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

            \[\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 rewrites70.1%

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

          Alternative 3: 98.8% accurate, 0.7× speedup?

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

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

              if -36000 < z < 6.3999999999999997e-6

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

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

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

            Alternative 4: 75.3% accurate, 0.7× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -6.2 \cdot 10^{+39} \lor \neg \left(y \leq 1.55 \cdot 10^{+68}\right):\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{z}\\ \end{array} \end{array} \]
            (FPCore (x y z)
             :precision binary64
             (if (or (<= y -6.2e+39) (not (<= y 1.55e+68))) (/ y z) (- x (/ x z))))
            double code(double x, double y, double z) {
            	double tmp;
            	if ((y <= -6.2e+39) || !(y <= 1.55e+68)) {
            		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 <= (-6.2d+39)) .or. (.not. (y <= 1.55d+68))) 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 <= -6.2e+39) || !(y <= 1.55e+68)) {
            		tmp = y / z;
            	} else {
            		tmp = x - (x / z);
            	}
            	return tmp;
            }
            
            def code(x, y, z):
            	tmp = 0
            	if (y <= -6.2e+39) or not (y <= 1.55e+68):
            		tmp = y / z
            	else:
            		tmp = x - (x / z)
            	return tmp
            
            function code(x, y, z)
            	tmp = 0.0
            	if ((y <= -6.2e+39) || !(y <= 1.55e+68))
            		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 <= -6.2e+39) || ~((y <= 1.55e+68)))
            		tmp = y / z;
            	else
            		tmp = x - (x / z);
            	end
            	tmp_2 = tmp;
            end
            
            code[x_, y_, z_] := If[Or[LessEqual[y, -6.2e+39], N[Not[LessEqual[y, 1.55e+68]], $MachinePrecision]], N[(y / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;y \leq -6.2 \cdot 10^{+39} \lor \neg \left(y \leq 1.55 \cdot 10^{+68}\right):\\
            \;\;\;\;\frac{y}{z}\\
            
            \mathbf{else}:\\
            \;\;\;\;x - \frac{x}{z}\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if y < -6.2000000000000005e39 or 1.5499999999999999e68 < 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 rewrites82.1%

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

                if -6.2000000000000005e39 < y < 1.5499999999999999e68

                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. Applied rewrites82.2%

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

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

                Alternative 5: 84.8% accurate, 0.7× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -3.7 \cdot 10^{+59}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 50:\\ \;\;\;\;\frac{y - x}{z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{z}\\ \end{array} \end{array} \]
                (FPCore (x y z)
                 :precision binary64
                 (if (<= z -3.7e+59) x (if (<= z 50.0) (/ (- y x) z) (- x (/ x z)))))
                double code(double x, double y, double z) {
                	double tmp;
                	if (z <= -3.7e+59) {
                		tmp = x;
                	} else if (z <= 50.0) {
                		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 <= (-3.7d+59)) then
                        tmp = x
                    else if (z <= 50.0d0) 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 <= -3.7e+59) {
                		tmp = x;
                	} else if (z <= 50.0) {
                		tmp = (y - x) / z;
                	} else {
                		tmp = x - (x / z);
                	}
                	return tmp;
                }
                
                def code(x, y, z):
                	tmp = 0
                	if z <= -3.7e+59:
                		tmp = x
                	elif z <= 50.0:
                		tmp = (y - x) / z
                	else:
                		tmp = x - (x / z)
                	return tmp
                
                function code(x, y, z)
                	tmp = 0.0
                	if (z <= -3.7e+59)
                		tmp = x;
                	elseif (z <= 50.0)
                		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 <= -3.7e+59)
                		tmp = x;
                	elseif (z <= 50.0)
                		tmp = (y - x) / z;
                	else
                		tmp = x - (x / z);
                	end
                	tmp_2 = tmp;
                end
                
                code[x_, y_, z_] := If[LessEqual[z, -3.7e+59], x, If[LessEqual[z, 50.0], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;z \leq -3.7 \cdot 10^{+59}:\\
                \;\;\;\;x\\
                
                \mathbf{elif}\;z \leq 50:\\
                \;\;\;\;\frac{y - x}{z}\\
                
                \mathbf{else}:\\
                \;\;\;\;x - \frac{x}{z}\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 3 regimes
                2. if z < -3.69999999999999997e59

                  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.5%

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

                    if -3.69999999999999997e59 < z < 50

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

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

                    if 50 < z

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

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

                    Alternative 6: 61.0% accurate, 0.7× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -3.7 \cdot 10^{+59}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1400000:\\ \;\;\;\;\frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
                    (FPCore (x y z)
                     :precision binary64
                     (if (<= z -3.7e+59) x (if (<= z 1400000.0) (/ y z) x)))
                    double code(double x, double y, double z) {
                    	double tmp;
                    	if (z <= -3.7e+59) {
                    		tmp = x;
                    	} else if (z <= 1400000.0) {
                    		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 <= (-3.7d+59)) then
                            tmp = x
                        else if (z <= 1400000.0d0) 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.7e+59) {
                    		tmp = x;
                    	} else if (z <= 1400000.0) {
                    		tmp = y / z;
                    	} else {
                    		tmp = x;
                    	}
                    	return tmp;
                    }
                    
                    def code(x, y, z):
                    	tmp = 0
                    	if z <= -3.7e+59:
                    		tmp = x
                    	elif z <= 1400000.0:
                    		tmp = y / z
                    	else:
                    		tmp = x
                    	return tmp
                    
                    function code(x, y, z)
                    	tmp = 0.0
                    	if (z <= -3.7e+59)
                    		tmp = x;
                    	elseif (z <= 1400000.0)
                    		tmp = Float64(y / z);
                    	else
                    		tmp = x;
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(x, y, z)
                    	tmp = 0.0;
                    	if (z <= -3.7e+59)
                    		tmp = x;
                    	elseif (z <= 1400000.0)
                    		tmp = y / z;
                    	else
                    		tmp = x;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[x_, y_, z_] := If[LessEqual[z, -3.7e+59], x, If[LessEqual[z, 1400000.0], N[(y / z), $MachinePrecision], x]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;z \leq -3.7 \cdot 10^{+59}:\\
                    \;\;\;\;x\\
                    
                    \mathbf{elif}\;z \leq 1400000:\\
                    \;\;\;\;\frac{y}{z}\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;x\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if z < -3.69999999999999997e59 or 1.4e6 < 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 rewrites75.5%

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

                        if -3.69999999999999997e59 < z < 1.4e6

                        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 rewrites59.9%

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

                        Alternative 7: 37.1% 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 rewrites39.9%

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

                          Reproduce

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