Data.Metrics.Snapshot:quantile from metrics-0.3.0.2

Percentage Accurate: 100.0% → 100.0%
Time: 3.0s
Alternatives: 8
Speedup: 1.1×

Specification

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

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

\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}

Alternative 1: 100.0% accurate, 1.1× speedup?

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

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

    \[x + \left(y - z\right) \cdot \left(t - x\right) \]
  2. Applied rewrites100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(y - z, t - x, x\right)} \]
  3. Add Preprocessing

Alternative 2: 75.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.6 \cdot 10^{+172}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{elif}\;y \leq 10^{+71}:\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t, y, -x \cdot y\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= y -1.6e+172)
   (* y (- t x))
   (if (<= y 1e+71) (+ x (* (- y z) t)) (fma t y (- (* x y))))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -1.6e+172) {
		tmp = y * (t - x);
	} else if (y <= 1e+71) {
		tmp = x + ((y - z) * t);
	} else {
		tmp = fma(t, y, -(x * y));
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (y <= -1.6e+172)
		tmp = Float64(y * Float64(t - x));
	elseif (y <= 1e+71)
		tmp = Float64(x + Float64(Float64(y - z) * t));
	else
		tmp = fma(t, y, Float64(-Float64(x * y)));
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.6e+172], N[(y * N[(t - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1e+71], N[(x + N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision], N[(t * y + (-N[(x * y), $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+172}:\\
\;\;\;\;y \cdot \left(t - x\right)\\

\mathbf{elif}\;y \leq 10^{+71}:\\
\;\;\;\;x + \left(y - z\right) \cdot t\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, y, -x \cdot y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.59999999999999993e172

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]
    3. Applied rewrites44.6%

      \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]

    if -1.59999999999999993e172 < y < 1e71

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto x + \left(y - z\right) \cdot \color{blue}{t} \]
    3. Applied rewrites65.1%

      \[\leadsto x + \left(y - z\right) \cdot \color{blue}{t} \]

    if 1e71 < y

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]
    3. Applied rewrites44.6%

      \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]
    4. Taylor expanded in x around 0

      \[\leadsto -1 \cdot \left(x \cdot y\right) + \color{blue}{t \cdot y} \]
    5. Applied rewrites42.8%

      \[\leadsto \mathsf{fma}\left(-1, \color{blue}{x \cdot y}, t \cdot y\right) \]
    6. Applied rewrites43.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(t, y, -x \cdot y\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 74.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.6 \cdot 10^{+172}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{elif}\;y \leq 10^{+71}:\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= y -1.6e+172)
   (* y (- t x))
   (if (<= y 1e+71) (+ x (* (- y z) t)) (fma (- t x) y x))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -1.6e+172) {
		tmp = y * (t - x);
	} else if (y <= 1e+71) {
		tmp = x + ((y - z) * t);
	} else {
		tmp = fma((t - x), y, x);
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (y <= -1.6e+172)
		tmp = Float64(y * Float64(t - x));
	elseif (y <= 1e+71)
		tmp = Float64(x + Float64(Float64(y - z) * t));
	else
		tmp = fma(Float64(t - x), y, x);
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.6e+172], N[(y * N[(t - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1e+71], N[(x + N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+172}:\\
\;\;\;\;y \cdot \left(t - x\right)\\

\mathbf{elif}\;y \leq 10^{+71}:\\
\;\;\;\;x + \left(y - z\right) \cdot t\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.59999999999999993e172

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]
    3. Applied rewrites44.6%

      \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]

    if -1.59999999999999993e172 < y < 1e71

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto x + \left(y - z\right) \cdot \color{blue}{t} \]
    3. Applied rewrites65.1%

      \[\leadsto x + \left(y - z\right) \cdot \color{blue}{t} \]

    if 1e71 < y

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
    3. Applied rewrites61.0%

      \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
    4. Applied rewrites61.0%

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

Alternative 4: 72.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := t \cdot \left(y - z\right)\\ \mathbf{if}\;z \leq -8 \cdot 10^{+42}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{+63}:\\ \;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* t (- y z))))
   (if (<= z -8e+42) t_1 (if (<= z 6.2e+63) (fma (- t x) y x) t_1))))
double code(double x, double y, double z, double t) {
	double t_1 = t * (y - z);
	double tmp;
	if (z <= -8e+42) {
		tmp = t_1;
	} else if (z <= 6.2e+63) {
		tmp = fma((t - x), y, x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = Float64(t * Float64(y - z))
	tmp = 0.0
	if (z <= -8e+42)
		tmp = t_1;
	elseif (z <= 6.2e+63)
		tmp = fma(Float64(t - x), y, x);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -8e+42], t$95$1, If[LessEqual[z, 6.2e+63], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := t \cdot \left(y - z\right)\\
\mathbf{if}\;z \leq -8 \cdot 10^{+42}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z \leq 6.2 \cdot 10^{+63}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\

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


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

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    3. Applied rewrites48.9%

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]

    if -8.00000000000000036e42 < z < 6.2000000000000001e63

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
    3. Applied rewrites61.0%

      \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
    4. Applied rewrites61.0%

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

Alternative 5: 60.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := t \cdot \left(y - z\right)\\ \mathbf{if}\;y \leq -1.6 \cdot 10^{+172}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -7.2 \cdot 10^{-276}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;y \leq 7.4 \cdot 10^{-137}:\\ \;\;\;\;\mathsf{fma}\left(t, y, x\right)\\ \mathbf{elif}\;y \leq 10^{+71}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* y (- t x))) (t_2 (* t (- y z))))
   (if (<= y -1.6e+172)
     t_1
     (if (<= y -7.2e-276)
       t_2
       (if (<= y 7.4e-137) (fma t y x) (if (<= y 1e+71) t_2 t_1))))))
double code(double x, double y, double z, double t) {
	double t_1 = y * (t - x);
	double t_2 = t * (y - z);
	double tmp;
	if (y <= -1.6e+172) {
		tmp = t_1;
	} else if (y <= -7.2e-276) {
		tmp = t_2;
	} else if (y <= 7.4e-137) {
		tmp = fma(t, y, x);
	} else if (y <= 1e+71) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = Float64(y * Float64(t - x))
	t_2 = Float64(t * Float64(y - z))
	tmp = 0.0
	if (y <= -1.6e+172)
		tmp = t_1;
	elseif (y <= -7.2e-276)
		tmp = t_2;
	elseif (y <= 7.4e-137)
		tmp = fma(t, y, x);
	elseif (y <= 1e+71)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(t - x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.6e+172], t$95$1, If[LessEqual[y, -7.2e-276], t$95$2, If[LessEqual[y, 7.4e-137], N[(t * y + x), $MachinePrecision], If[LessEqual[y, 1e+71], t$95$2, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := y \cdot \left(t - x\right)\\
t_2 := t \cdot \left(y - z\right)\\
\mathbf{if}\;y \leq -1.6 \cdot 10^{+172}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq -7.2 \cdot 10^{-276}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;y \leq 7.4 \cdot 10^{-137}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\

\mathbf{elif}\;y \leq 10^{+71}:\\
\;\;\;\;t\_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.59999999999999993e172 or 1e71 < y

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]
    3. Applied rewrites44.6%

      \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]

    if -1.59999999999999993e172 < y < -7.19999999999999988e-276 or 7.4e-137 < y < 1e71

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    3. Applied rewrites48.9%

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]

    if -7.19999999999999988e-276 < y < 7.4e-137

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
    3. Applied rewrites61.0%

      \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
    4. Applied rewrites61.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(t - x, y, x\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{fma}\left(t, y, x\right) \]
    6. Applied rewrites42.8%

      \[\leadsto \mathsf{fma}\left(t, y, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 58.4% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := t \cdot \left(y - z\right)\\ \mathbf{if}\;z \leq -9 \cdot 10^{-21}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-85}:\\ \;\;\;\;\mathsf{fma}\left(t, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* t (- y z))))
   (if (<= z -9e-21) t_1 (if (<= z 2.7e-85) (fma t y x) t_1))))
double code(double x, double y, double z, double t) {
	double t_1 = t * (y - z);
	double tmp;
	if (z <= -9e-21) {
		tmp = t_1;
	} else if (z <= 2.7e-85) {
		tmp = fma(t, y, x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = Float64(t * Float64(y - z))
	tmp = 0.0
	if (z <= -9e-21)
		tmp = t_1;
	elseif (z <= 2.7e-85)
		tmp = fma(t, y, x);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -9e-21], t$95$1, If[LessEqual[z, 2.7e-85], N[(t * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := t \cdot \left(y - z\right)\\
\mathbf{if}\;z \leq -9 \cdot 10^{-21}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z \leq 2.7 \cdot 10^{-85}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -8.99999999999999936e-21 or 2.7000000000000001e-85 < z

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    3. Applied rewrites48.9%

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]

    if -8.99999999999999936e-21 < z < 2.7000000000000001e-85

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
    3. Applied rewrites61.0%

      \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
    4. Applied rewrites61.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(t - x, y, x\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{fma}\left(t, y, x\right) \]
    6. Applied rewrites42.8%

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

Alternative 7: 42.8% accurate, 2.0× speedup?

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

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

    \[x + \left(y - z\right) \cdot \left(t - x\right) \]
  2. Taylor expanded in z around 0

    \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
  3. Applied rewrites61.0%

    \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
  4. Applied rewrites61.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(t - x, y, x\right)} \]
  5. Taylor expanded in x around 0

    \[\leadsto \mathsf{fma}\left(t, y, x\right) \]
  6. Applied rewrites42.8%

    \[\leadsto \mathsf{fma}\left(t, y, x\right) \]
  7. Add Preprocessing

Alternative 8: 26.7% accurate, 3.0× speedup?

\[\begin{array}{l} \\ t \cdot y \end{array} \]
(FPCore (x y z t) :precision binary64 (* t y))
double code(double x, double y, double z, double t) {
	return t * y;
}
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, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = t * y
end function
public static double code(double x, double y, double z, double t) {
	return t * y;
}
def code(x, y, z, t):
	return t * y
function code(x, y, z, t)
	return Float64(t * y)
end
function tmp = code(x, y, z, t)
	tmp = t * y;
end
code[x_, y_, z_, t_] := N[(t * y), $MachinePrecision]
\begin{array}{l}

\\
t \cdot y
\end{array}
Derivation
  1. Initial program 100.0%

    \[x + \left(y - z\right) \cdot \left(t - x\right) \]
  2. Taylor expanded in y around inf

    \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]
  3. Applied rewrites44.6%

    \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]
  4. Taylor expanded in x around 0

    \[\leadsto t \cdot \color{blue}{y} \]
  5. Applied rewrites26.7%

    \[\leadsto t \cdot \color{blue}{y} \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2025161 
(FPCore (x y z t)
  :name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
  :precision binary64
  (+ x (* (- y z) (- t x))))