Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1

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

Specification

?
\[\begin{array}{l} \\ \left(\frac{x}{2} + y \cdot x\right) + z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
	return ((x / 2.0) + (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 / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
	return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z):
	return ((x / 2.0) + (y * x)) + z
function code(x, y, z)
	return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z)
end
function tmp = code(x, y, z)
	tmp = ((x / 2.0) + (y * x)) + z;
end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}

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} \\ \left(\frac{x}{2} + y \cdot x\right) + z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
	return ((x / 2.0) + (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 / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
	return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z):
	return ((x / 2.0) + (y * x)) + z
function code(x, y, z)
	return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z)
end
function tmp = code(x, y, z)
	tmp = ((x / 2.0) + (y * x)) + z;
end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}

Alternative 1: 100.0% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(0.5, x, x \cdot y\right) + z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (fma 0.5 x (* x y)) z))
double code(double x, double y, double z) {
	return fma(0.5, x, (x * y)) + z;
}
function code(x, y, z)
	return Float64(fma(0.5, x, Float64(x * y)) + z)
end
code[x_, y_, z_] := N[(N[(0.5 * x + N[(x * y), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(0.5, x, x \cdot y\right) + z
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{x}{2} + y \cdot x\right) + z \]
  2. Taylor expanded in y around 0

    \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot x + x \cdot y\right)} + z \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, x, x \cdot y\right)} + z \]
  4. Add Preprocessing

Alternative 2: 100.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ x \cdot \left(0.5 + y\right) + z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x (+ 0.5 y)) z))
double code(double x, double y, double z) {
	return (x * (0.5 + y)) + 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 * (0.5d0 + y)) + z
end function
public static double code(double x, double y, double z) {
	return (x * (0.5 + y)) + z;
}
def code(x, y, z):
	return (x * (0.5 + y)) + z
function code(x, y, z)
	return Float64(Float64(x * Float64(0.5 + y)) + z)
end
function tmp = code(x, y, z)
	tmp = (x * (0.5 + y)) + z;
end
code[x_, y_, z_] := N[(N[(x * N[(0.5 + y), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(0.5 + y\right) + z
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{x}{2} + y \cdot x\right) + z \]
  2. Taylor expanded in x around 0

    \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + y\right)} + z \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{x \cdot \left(0.5 + y\right)} + z \]
  4. Add Preprocessing

Alternative 3: 85.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{2} + y \cdot x\\ t_1 := x \cdot \left(0.5 + y\right)\\ \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+107}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+57}:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (/ x 2.0) (* y x))) (t_1 (* x (+ 0.5 y))))
   (if (<= t_0 -1e+107) t_1 (if (<= t_0 5e+57) (fma x 0.5 z) t_1))))
double code(double x, double y, double z) {
	double t_0 = (x / 2.0) + (y * x);
	double t_1 = x * (0.5 + y);
	double tmp;
	if (t_0 <= -1e+107) {
		tmp = t_1;
	} else if (t_0 <= 5e+57) {
		tmp = fma(x, 0.5, z);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(Float64(x / 2.0) + Float64(y * x))
	t_1 = Float64(x * Float64(0.5 + y))
	tmp = 0.0
	if (t_0 <= -1e+107)
		tmp = t_1;
	elseif (t_0 <= 5e+57)
		tmp = fma(x, 0.5, z);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(0.5 + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+107], t$95$1, If[LessEqual[t$95$0, 5e+57], N[(x * 0.5 + z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{2} + y \cdot x\\
t_1 := x \cdot \left(0.5 + y\right)\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+107}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+57}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -9.9999999999999997e106 or 4.99999999999999972e57 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x))

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \left(y + \frac{z}{x}\right)\right)} \]
    3. Applied rewrites87.7%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(y + \frac{z}{x}\right)\right)} \]
    4. Taylor expanded in x around inf

      \[\leadsto x \cdot \left(\frac{1}{2} + y\right) \]
    5. Applied rewrites60.6%

      \[\leadsto x \cdot \left(0.5 + y\right) \]

    if -9.9999999999999997e106 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 4.99999999999999972e57

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{z + \frac{1}{2} \cdot x} \]
    3. Applied rewrites64.6%

      \[\leadsto \color{blue}{z + 0.5 \cdot x} \]
    4. Applied rewrites64.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 85.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -8200000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 3200:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -8200000.0) (* x y) (if (<= y 3200.0) (fma x 0.5 z) (* x y))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -8200000.0) {
		tmp = x * y;
	} else if (y <= 3200.0) {
		tmp = fma(x, 0.5, z);
	} else {
		tmp = x * y;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= -8200000.0)
		tmp = Float64(x * y);
	elseif (y <= 3200.0)
		tmp = fma(x, 0.5, z);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, -8200000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 3200.0], N[(x * 0.5 + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8200000:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq 3200:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -8.2e6 or 3200 < y

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \left(y + \frac{z}{x}\right)\right)} \]
    3. Applied rewrites87.7%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(y + \frac{z}{x}\right)\right)} \]
    4. Taylor expanded in x around inf

      \[\leadsto x \cdot \left(\frac{1}{2} + y\right) \]
    5. Applied rewrites60.6%

      \[\leadsto x \cdot \left(0.5 + y\right) \]
    6. Taylor expanded in y around inf

      \[\leadsto \color{blue}{x \cdot y} \]
    7. Applied rewrites37.1%

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

    if -8.2e6 < y < 3200

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{z + \frac{1}{2} \cdot x} \]
    3. Applied rewrites64.6%

      \[\leadsto \color{blue}{z + 0.5 \cdot x} \]
    4. Applied rewrites64.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 61.8% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{2} + y \cdot x\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t\_0 \leq -3 \cdot 10^{+217}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;t\_0 \leq -1 \cdot 10^{+107}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+132}:\\ \;\;\;\;z\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+193}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (/ x 2.0) (* y x))))
   (if (<= t_0 (- INFINITY))
     (* x y)
     (if (<= t_0 -3e+217)
       (* 0.5 x)
       (if (<= t_0 -1e+107)
         (* x y)
         (if (<= t_0 2e+132) z (if (<= t_0 2e+193) (* 0.5 x) (* x y))))))))
double code(double x, double y, double z) {
	double t_0 = (x / 2.0) + (y * x);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = x * y;
	} else if (t_0 <= -3e+217) {
		tmp = 0.5 * x;
	} else if (t_0 <= -1e+107) {
		tmp = x * y;
	} else if (t_0 <= 2e+132) {
		tmp = z;
	} else if (t_0 <= 2e+193) {
		tmp = 0.5 * x;
	} else {
		tmp = x * y;
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	double t_0 = (x / 2.0) + (y * x);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = x * y;
	} else if (t_0 <= -3e+217) {
		tmp = 0.5 * x;
	} else if (t_0 <= -1e+107) {
		tmp = x * y;
	} else if (t_0 <= 2e+132) {
		tmp = z;
	} else if (t_0 <= 2e+193) {
		tmp = 0.5 * x;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (x / 2.0) + (y * x)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = x * y
	elif t_0 <= -3e+217:
		tmp = 0.5 * x
	elif t_0 <= -1e+107:
		tmp = x * y
	elif t_0 <= 2e+132:
		tmp = z
	elif t_0 <= 2e+193:
		tmp = 0.5 * x
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(x / 2.0) + Float64(y * x))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(x * y);
	elseif (t_0 <= -3e+217)
		tmp = Float64(0.5 * x);
	elseif (t_0 <= -1e+107)
		tmp = Float64(x * y);
	elseif (t_0 <= 2e+132)
		tmp = z;
	elseif (t_0 <= 2e+193)
		tmp = Float64(0.5 * x);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (x / 2.0) + (y * x);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = x * y;
	elseif (t_0 <= -3e+217)
		tmp = 0.5 * x;
	elseif (t_0 <= -1e+107)
		tmp = x * y;
	elseif (t_0 <= 2e+132)
		tmp = z;
	elseif (t_0 <= 2e+193)
		tmp = 0.5 * x;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(x * y), $MachinePrecision], If[LessEqual[t$95$0, -3e+217], N[(0.5 * x), $MachinePrecision], If[LessEqual[t$95$0, -1e+107], N[(x * y), $MachinePrecision], If[LessEqual[t$95$0, 2e+132], z, If[LessEqual[t$95$0, 2e+193], N[(0.5 * x), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{2} + y \cdot x\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;t\_0 \leq -3 \cdot 10^{+217}:\\
\;\;\;\;0.5 \cdot x\\

\mathbf{elif}\;t\_0 \leq -1 \cdot 10^{+107}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+132}:\\
\;\;\;\;z\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+193}:\\
\;\;\;\;0.5 \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -inf.0 or -2.99999999999999976e217 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -9.9999999999999997e106 or 2.00000000000000013e193 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x))

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \left(y + \frac{z}{x}\right)\right)} \]
    3. Applied rewrites87.7%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(y + \frac{z}{x}\right)\right)} \]
    4. Taylor expanded in x around inf

      \[\leadsto x \cdot \left(\frac{1}{2} + y\right) \]
    5. Applied rewrites60.6%

      \[\leadsto x \cdot \left(0.5 + y\right) \]
    6. Taylor expanded in y around inf

      \[\leadsto \color{blue}{x \cdot y} \]
    7. Applied rewrites37.1%

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

    if -inf.0 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -2.99999999999999976e217 or 1.99999999999999998e132 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 2.00000000000000013e193

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{z + \frac{1}{2} \cdot x} \]
    3. Applied rewrites64.6%

      \[\leadsto \color{blue}{z + 0.5 \cdot x} \]
    4. Applied rewrites64.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, z\right)} \]
    5. Taylor expanded in x around inf

      \[\leadsto \frac{1}{2} \cdot \color{blue}{x} \]
    6. Applied rewrites25.7%

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

    if -9.9999999999999997e106 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 1.99999999999999998e132

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{z} \]
    3. Applied rewrites40.9%

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

Alternative 6: 61.6% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{x}{2} + y \cdot x\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+107}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+64}:\\
\;\;\;\;z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -9.9999999999999997e106 or 5e64 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x))

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \left(y + \frac{z}{x}\right)\right)} \]
    3. Applied rewrites87.7%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(y + \frac{z}{x}\right)\right)} \]
    4. Taylor expanded in x around inf

      \[\leadsto x \cdot \left(\frac{1}{2} + y\right) \]
    5. Applied rewrites60.6%

      \[\leadsto x \cdot \left(0.5 + y\right) \]
    6. Taylor expanded in y around inf

      \[\leadsto \color{blue}{x \cdot y} \]
    7. Applied rewrites37.1%

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

    if -9.9999999999999997e106 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 5e64

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{z} \]
    3. Applied rewrites40.9%

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

Alternative 7: 40.9% accurate, 12.8× speedup?

\[\begin{array}{l} \\ z \end{array} \]
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
	return 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 = z
end function
public static double code(double x, double y, double z) {
	return z;
}
def code(x, y, z):
	return z
function code(x, y, z)
	return z
end
function tmp = code(x, y, z)
	tmp = z;
end
code[x_, y_, z_] := z
\begin{array}{l}

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

    \[\left(\frac{x}{2} + y \cdot x\right) + z \]
  2. Taylor expanded in x around 0

    \[\leadsto \color{blue}{z} \]
  3. Applied rewrites40.9%

    \[\leadsto \color{blue}{z} \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2025159 
(FPCore (x y z)
  :name "Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1"
  :precision binary64
  (+ (+ (/ x 2.0) (* y x)) z))