
(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}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(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}
Initial program 100.0%
Applied rewrites100.0%
(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}
if y < -1.59999999999999993e172Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites44.6%
if -1.59999999999999993e172 < y < 1e71Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites65.1%
if 1e71 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites44.6%
Taylor expanded in x around 0
Applied rewrites42.8%
Applied rewrites43.7%
(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}
if y < -1.59999999999999993e172Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites44.6%
if -1.59999999999999993e172 < y < 1e71Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites65.1%
if 1e71 < y Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites61.0%
Applied rewrites61.0%
(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}
if z < -8.00000000000000036e42 or 6.2000000000000001e63 < z Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites48.9%
if -8.00000000000000036e42 < z < 6.2000000000000001e63Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites61.0%
Applied rewrites61.0%
(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}
if y < -1.59999999999999993e172 or 1e71 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites44.6%
if -1.59999999999999993e172 < y < -7.19999999999999988e-276 or 7.4e-137 < y < 1e71Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites48.9%
if -7.19999999999999988e-276 < y < 7.4e-137Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites61.0%
Applied rewrites61.0%
Taylor expanded in x around 0
Applied rewrites42.8%
(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}
if z < -8.99999999999999936e-21 or 2.7000000000000001e-85 < z Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites48.9%
if -8.99999999999999936e-21 < z < 2.7000000000000001e-85Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites61.0%
Applied rewrites61.0%
Taylor expanded in x around 0
Applied rewrites42.8%
(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}
Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites61.0%
Applied rewrites61.0%
Taylor expanded in x around 0
Applied rewrites42.8%
(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}
Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites44.6%
Taylor expanded in x around 0
Applied rewrites26.7%
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))))