
(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}
Sampling outcomes in binary64 precision:
Herbie found 12 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 (+ 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}
Initial program 100.0%
(FPCore (x y z t)
:precision binary64
(if (<= y -4.5e+64)
(* (- t x) y)
(if (<= y -3.2e-223)
(* (- y z) t)
(if (<= y 7.2e-110) (fma z x x) (fma (- t x) y x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -4.5e+64) {
tmp = (t - x) * y;
} else if (y <= -3.2e-223) {
tmp = (y - z) * t;
} else if (y <= 7.2e-110) {
tmp = fma(z, x, x);
} else {
tmp = fma((t - x), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -4.5e+64) tmp = Float64(Float64(t - x) * y); elseif (y <= -3.2e-223) tmp = Float64(Float64(y - z) * t); elseif (y <= 7.2e-110) tmp = fma(z, x, x); else tmp = fma(Float64(t - x), y, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -4.5e+64], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, -3.2e-223], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[y, 7.2e-110], N[(z * x + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+64}:\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{elif}\;y \leq -3.2 \cdot 10^{-223}:\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{-110}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\end{array}
\end{array}
if y < -4.49999999999999973e64Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites87.8%
if -4.49999999999999973e64 < y < -3.2000000000000001e-223Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites66.0%
if -3.2000000000000001e-223 < y < 7.1999999999999999e-110Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites70.2%
Taylor expanded in y around 0
Applied rewrites70.3%
if 7.1999999999999999e-110 < y Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites76.2%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- t x) y)))
(if (<= y -4.5e+64)
t_1
(if (<= y -3.2e-223) (* (- y z) t) (if (<= y 9.6e-15) (fma z x x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double tmp;
if (y <= -4.5e+64) {
tmp = t_1;
} else if (y <= -3.2e-223) {
tmp = (y - z) * t;
} else if (y <= 9.6e-15) {
tmp = fma(z, x, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(t - x) * y) tmp = 0.0 if (y <= -4.5e+64) tmp = t_1; elseif (y <= -3.2e-223) tmp = Float64(Float64(y - z) * t); elseif (y <= 9.6e-15) tmp = fma(z, x, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -4.5e+64], t$95$1, If[LessEqual[y, -3.2e-223], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[y, 9.6e-15], N[(z * x + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
\mathbf{if}\;y \leq -4.5 \cdot 10^{+64}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -3.2 \cdot 10^{-223}:\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{elif}\;y \leq 9.6 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -4.49999999999999973e64 or 9.5999999999999998e-15 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites85.3%
if -4.49999999999999973e64 < y < -3.2000000000000001e-223Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites66.0%
if -3.2000000000000001e-223 < y < 9.5999999999999998e-15Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites65.4%
Taylor expanded in y around 0
Applied rewrites65.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- t x) y)))
(if (<= y -8.5e+59)
t_1
(if (<= y -1.8e-110) (* (- z) t) (if (<= y 9.6e-15) (fma z x x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double tmp;
if (y <= -8.5e+59) {
tmp = t_1;
} else if (y <= -1.8e-110) {
tmp = -z * t;
} else if (y <= 9.6e-15) {
tmp = fma(z, x, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(t - x) * y) tmp = 0.0 if (y <= -8.5e+59) tmp = t_1; elseif (y <= -1.8e-110) tmp = Float64(Float64(-z) * t); elseif (y <= 9.6e-15) tmp = fma(z, x, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -8.5e+59], t$95$1, If[LessEqual[y, -1.8e-110], N[((-z) * t), $MachinePrecision], If[LessEqual[y, 9.6e-15], N[(z * x + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{+59}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -1.8 \cdot 10^{-110}:\\
\;\;\;\;\left(-z\right) \cdot t\\
\mathbf{elif}\;y \leq 9.6 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -8.4999999999999999e59 or 9.5999999999999998e-15 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites85.3%
if -8.4999999999999999e59 < y < -1.79999999999999997e-110Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites77.8%
Taylor expanded in y around 0
Applied rewrites67.1%
if -1.79999999999999997e-110 < y < 9.5999999999999998e-15Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites61.5%
Taylor expanded in y around 0
Applied rewrites61.6%
(FPCore (x y z t) :precision binary64 (if (<= y -2.9e+88) (* (- t x) y) (if (<= y 1.65e+50) (- x (* (- t x) z)) (fma (- t x) y x))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.9e+88) {
tmp = (t - x) * y;
} else if (y <= 1.65e+50) {
tmp = x - ((t - x) * z);
} else {
tmp = fma((t - x), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -2.9e+88) tmp = Float64(Float64(t - x) * y); elseif (y <= 1.65e+50) tmp = Float64(x - Float64(Float64(t - x) * z)); else tmp = fma(Float64(t - x), y, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -2.9e+88], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, 1.65e+50], N[(x - N[(N[(t - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+88}:\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{+50}:\\
\;\;\;\;x - \left(t - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\end{array}
\end{array}
if y < -2.9e88Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites91.8%
if -2.9e88 < y < 1.65e50Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites88.7%
if 1.65e50 < y Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites88.8%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.4e+119) (not (<= z 1.05e-7))) (* (- z) (- t x)) (fma (- t x) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.4e+119) || !(z <= 1.05e-7)) {
tmp = -z * (t - x);
} else {
tmp = fma((t - x), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.4e+119) || !(z <= 1.05e-7)) tmp = Float64(Float64(-z) * Float64(t - x)); else tmp = fma(Float64(t - x), y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.4e+119], N[Not[LessEqual[z, 1.05e-7]], $MachinePrecision]], N[((-z) * N[(t - x), $MachinePrecision]), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+119} \lor \neg \left(z \leq 1.05 \cdot 10^{-7}\right):\\
\;\;\;\;\left(-z\right) \cdot \left(t - x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\end{array}
\end{array}
if z < -2.4e119 or 1.05e-7 < z Initial program 100.0%
Taylor expanded in z around inf
Applied rewrites99.9%
Taylor expanded in z around inf
Applied rewrites85.6%
if -2.4e119 < z < 1.05e-7Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites82.9%
Final simplification83.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.4e+52) (not (<= z 1.05e-7))) (* (- z) t) (fma t y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.4e+52) || !(z <= 1.05e-7)) {
tmp = -z * t;
} else {
tmp = fma(t, y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.4e+52) || !(z <= 1.05e-7)) tmp = Float64(Float64(-z) * t); else tmp = fma(t, y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.4e+52], N[Not[LessEqual[z, 1.05e-7]], $MachinePrecision]], N[((-z) * t), $MachinePrecision], N[(t * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+52} \lor \neg \left(z \leq 1.05 \cdot 10^{-7}\right):\\
\;\;\;\;\left(-z\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\
\end{array}
\end{array}
if z < -1.4e52 or 1.05e-7 < z Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites57.3%
Taylor expanded in y around 0
Applied rewrites49.5%
if -1.4e52 < z < 1.05e-7Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites85.8%
Taylor expanded in x around 0
Applied rewrites63.7%
Final simplification57.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -9.5e+78) (not (<= y 3.45e+16))) (* y t) (fma z x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -9.5e+78) || !(y <= 3.45e+16)) {
tmp = y * t;
} else {
tmp = fma(z, x, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -9.5e+78) || !(y <= 3.45e+16)) tmp = Float64(y * t); else tmp = fma(z, x, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -9.5e+78], N[Not[LessEqual[y, 3.45e+16]], $MachinePrecision]], N[(y * t), $MachinePrecision], N[(z * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+78} \lor \neg \left(y \leq 3.45 \cdot 10^{+16}\right):\\
\;\;\;\;y \cdot t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\end{array}
\end{array}
if y < -9.5000000000000006e78 or 3.45e16 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites55.6%
Taylor expanded in y around inf
Applied rewrites48.1%
if -9.5000000000000006e78 < y < 3.45e16Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites54.5%
Taylor expanded in y around 0
Applied rewrites53.2%
Final simplification50.9%
(FPCore (x y z t) :precision binary64 (if (<= z -3e+119) (* z x) (if (<= z 1.6e-10) (fma t y x) (fma z x x))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3e+119) {
tmp = z * x;
} else if (z <= 1.6e-10) {
tmp = fma(t, y, x);
} else {
tmp = fma(z, x, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -3e+119) tmp = Float64(z * x); elseif (z <= 1.6e-10) tmp = fma(t, y, x); else tmp = fma(z, x, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -3e+119], N[(z * x), $MachinePrecision], If[LessEqual[z, 1.6e-10], N[(t * y + x), $MachinePrecision], N[(z * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{+119}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\end{array}
\end{array}
if z < -3.00000000000000001e119Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites42.5%
Taylor expanded in z around inf
Applied rewrites42.3%
if -3.00000000000000001e119 < z < 1.5999999999999999e-10Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites83.8%
Taylor expanded in x around 0
Applied rewrites60.3%
if 1.5999999999999999e-10 < z Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites54.8%
Taylor expanded in y around 0
Applied rewrites43.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -5.2e-5) (not (<= y 9e-121))) (* y t) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5.2e-5) || !(y <= 9e-121)) {
tmp = y * t;
} 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, 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
real(8) :: tmp
if ((y <= (-5.2d-5)) .or. (.not. (y <= 9d-121))) then
tmp = y * t
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5.2e-5) || !(y <= 9e-121)) {
tmp = y * t;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -5.2e-5) or not (y <= 9e-121): tmp = y * t else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -5.2e-5) || !(y <= 9e-121)) tmp = Float64(y * t); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -5.2e-5) || ~((y <= 9e-121))) tmp = y * t; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -5.2e-5], N[Not[LessEqual[y, 9e-121]], $MachinePrecision]], N[(y * t), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-5} \lor \neg \left(y \leq 9 \cdot 10^{-121}\right):\\
\;\;\;\;y \cdot t\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.19999999999999968e-5 or 9.0000000000000007e-121 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites55.8%
Taylor expanded in y around inf
Applied rewrites43.7%
if -5.19999999999999968e-5 < y < 9.0000000000000007e-121Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites36.3%
Taylor expanded in y around 0
Applied rewrites33.3%
Final simplification39.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* z x) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = z * x;
} 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, 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
real(8) :: tmp
if ((z <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = z * x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = z * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = z * x else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(z * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.0) || ~((z <= 1.0))) tmp = z * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites51.2%
Taylor expanded in z around inf
Applied rewrites35.9%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites88.0%
Taylor expanded in y around 0
Applied rewrites30.8%
Final simplification33.3%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
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, 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
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites60.3%
Taylor expanded in y around 0
Applied rewrites16.9%
(FPCore (x y z t) :precision binary64 (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
double code(double x, double y, double z, double t) {
return x + ((t * (y - z)) + (-x * (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, 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 + ((t * (y - z)) + (-x * (y - z)))
end function
public static double code(double x, double y, double z, double t) {
return x + ((t * (y - z)) + (-x * (y - z)));
}
def code(x, y, z, t): return x + ((t * (y - z)) + (-x * (y - z)))
function code(x, y, z, t) return Float64(x + Float64(Float64(t * Float64(y - z)) + Float64(Float64(-x) * Float64(y - z)))) end
function tmp = code(x, y, z, t) tmp = x + ((t * (y - z)) + (-x * (y - z))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision] + N[((-x) * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right)
\end{array}
herbie shell --seed 2025019
(FPCore (x y z t)
:name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
(+ x (* (- y z) (- t x))))