
(FPCore (x y z t a) :precision binary64 (+ x (* (- y z) (/ (- t x) (- a z)))))
double code(double x, double y, double z, double t, double a) {
return x + ((y - z) * ((t - x) / (a - 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, a)
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), intent (in) :: a
code = x + ((y - z) * ((t - x) / (a - z)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y - z) * ((t - x) / (a - z)));
}
def code(x, y, z, t, a): return x + ((y - z) * ((t - x) / (a - z)))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z)))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y - z) * ((t - x) / (a - z))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \frac{t - x}{a - z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (* (- y z) (/ (- t x) (- a z)))))
double code(double x, double y, double z, double t, double a) {
return x + ((y - z) * ((t - x) / (a - 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, a)
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), intent (in) :: a
code = x + ((y - z) * ((t - x) / (a - z)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y - z) * ((t - x) / (a - z)));
}
def code(x, y, z, t, a): return x + ((y - z) * ((t - x) / (a - z)))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z)))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y - z) * ((t - x) / (a - z))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \frac{t - x}{a - z}
\end{array}
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (+ x (* (- y z) (/ (- t x) (- a z))))) (t_2 (/ (- t x) z)))
(if (or (<= t_1 -1e-277) (not (<= t_1 0.0)))
(fma (- t x) (/ (- y z) (- a z)) x)
(+
(+ (fma (- y) t_2 (* (* (/ (- y a) z) (- (- t x))) (/ a z))) t)
(* a t_2)))))
double code(double x, double y, double z, double t, double a) {
double t_1 = x + ((y - z) * ((t - x) / (a - z)));
double t_2 = (t - x) / z;
double tmp;
if ((t_1 <= -1e-277) || !(t_1 <= 0.0)) {
tmp = fma((t - x), ((y - z) / (a - z)), x);
} else {
tmp = (fma(-y, t_2, ((((y - a) / z) * -(t - x)) * (a / z))) + t) + (a * t_2);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z)))) t_2 = Float64(Float64(t - x) / z) tmp = 0.0 if ((t_1 <= -1e-277) || !(t_1 <= 0.0)) tmp = fma(Float64(t - x), Float64(Float64(y - z) / Float64(a - z)), x); else tmp = Float64(Float64(fma(Float64(-y), t_2, Float64(Float64(Float64(Float64(y - a) / z) * Float64(-Float64(t - x))) * Float64(a / z))) + t) + Float64(a * t_2)); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(x + N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t - x), $MachinePrecision] / z), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -1e-277], N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * N[(N[(y - z), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[((-y) * t$95$2 + N[(N[(N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision] * (-N[(t - x), $MachinePrecision])), $MachinePrecision] * N[(a / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision] + N[(a * t$95$2), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x + \left(y - z\right) \cdot \frac{t - x}{a - z}\\
t_2 := \frac{t - x}{z}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-277} \lor \neg \left(t\_1 \leq 0\right):\\
\;\;\;\;\mathsf{fma}\left(t - x, \frac{y - z}{a - z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(-y, t\_2, \left(\frac{y - a}{z} \cdot \left(-\left(t - x\right)\right)\right) \cdot \frac{a}{z}\right) + t\right) + a \cdot t\_2\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -9.99999999999999969e-278 or 0.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) Initial program 88.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6492.6
Applied rewrites92.6%
if -9.99999999999999969e-278 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 0.0Initial program 3.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f643.2
Applied rewrites3.2%
Taylor expanded in x around 0
Applied rewrites3.4%
Taylor expanded in z around inf
Applied rewrites99.8%
Final simplification93.5%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (fma t (/ (- y z) (- a z)) x))
(t_2 (+ x (* (- y z) (/ (- t x) (- a z))))))
(if (<= t_2 -1e-277)
t_1
(if (<= t_2 0.0)
(fma x (/ (- y a) z) t)
(if (<= t_2 2e+306) t_1 (/ (* (- t x) y) (- a z)))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = fma(t, ((y - z) / (a - z)), x);
double t_2 = x + ((y - z) * ((t - x) / (a - z)));
double tmp;
if (t_2 <= -1e-277) {
tmp = t_1;
} else if (t_2 <= 0.0) {
tmp = fma(x, ((y - a) / z), t);
} else if (t_2 <= 2e+306) {
tmp = t_1;
} else {
tmp = ((t - x) * y) / (a - z);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = fma(t, Float64(Float64(y - z) / Float64(a - z)), x) t_2 = Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z)))) tmp = 0.0 if (t_2 <= -1e-277) tmp = t_1; elseif (t_2 <= 0.0) tmp = fma(x, Float64(Float64(y - a) / z), t); elseif (t_2 <= 2e+306) tmp = t_1; else tmp = Float64(Float64(Float64(t - x) * y) / Float64(a - z)); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(t * N[(N[(y - z), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e-277], t$95$1, If[LessEqual[t$95$2, 0.0], N[(x * N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision] + t), $MachinePrecision], If[LessEqual[t$95$2, 2e+306], t$95$1, N[(N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, \frac{y - z}{a - z}, x\right)\\
t_2 := x + \left(y - z\right) \cdot \frac{t - x}{a - z}\\
\mathbf{if}\;t\_2 \leq -1 \cdot 10^{-277}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y - a}{z}, t\right)\\
\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{+306}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(t - x\right) \cdot y}{a - z}\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -9.99999999999999969e-278 or 0.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 2.00000000000000003e306Initial program 87.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6492.4
Applied rewrites92.4%
Taylor expanded in x around 0
Applied rewrites79.4%
if -9.99999999999999969e-278 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 0.0Initial program 3.2%
Taylor expanded in z around inf
Applied rewrites97.0%
Taylor expanded in x around inf
Applied rewrites97.0%
if 2.00000000000000003e306 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) Initial program 90.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6494.8
Applied rewrites94.8%
Taylor expanded in y around inf
Applied rewrites95.5%
Final simplification82.9%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (+ x (* (- y z) (/ (- t x) (- a z))))))
(if (or (<= t_1 -1e-277) (not (<= t_1 0.0)))
(fma (- t x) (/ (- y z) (- a z)) x)
(fma x (/ (- y a) z) t))))
double code(double x, double y, double z, double t, double a) {
double t_1 = x + ((y - z) * ((t - x) / (a - z)));
double tmp;
if ((t_1 <= -1e-277) || !(t_1 <= 0.0)) {
tmp = fma((t - x), ((y - z) / (a - z)), x);
} else {
tmp = fma(x, ((y - a) / z), t);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z)))) tmp = 0.0 if ((t_1 <= -1e-277) || !(t_1 <= 0.0)) tmp = fma(Float64(t - x), Float64(Float64(y - z) / Float64(a - z)), x); else tmp = fma(x, Float64(Float64(y - a) / z), t); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(x + N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -1e-277], N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * N[(N[(y - z), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(x * N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision] + t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x + \left(y - z\right) \cdot \frac{t - x}{a - z}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-277} \lor \neg \left(t\_1 \leq 0\right):\\
\;\;\;\;\mathsf{fma}\left(t - x, \frac{y - z}{a - z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y - a}{z}, t\right)\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -9.99999999999999969e-278 or 0.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) Initial program 88.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6492.6
Applied rewrites92.6%
if -9.99999999999999969e-278 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 0.0Initial program 3.2%
Taylor expanded in z around inf
Applied rewrites97.0%
Taylor expanded in x around inf
Applied rewrites97.0%
Final simplification93.2%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (- y a) z)))
(if (<= z -3.2e+263)
(fma x t_1 t)
(if (<= z -5.5e-158)
(fma t (/ (- y z) (- a z)) x)
(if (<= z 1.22e+37)
(+ x (* y (/ (- t x) (- a z))))
(fma (- (- t x)) t_1 t))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y - a) / z;
double tmp;
if (z <= -3.2e+263) {
tmp = fma(x, t_1, t);
} else if (z <= -5.5e-158) {
tmp = fma(t, ((y - z) / (a - z)), x);
} else if (z <= 1.22e+37) {
tmp = x + (y * ((t - x) / (a - z)));
} else {
tmp = fma(-(t - x), t_1, t);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(y - a) / z) tmp = 0.0 if (z <= -3.2e+263) tmp = fma(x, t_1, t); elseif (z <= -5.5e-158) tmp = fma(t, Float64(Float64(y - z) / Float64(a - z)), x); elseif (z <= 1.22e+37) tmp = Float64(x + Float64(y * Float64(Float64(t - x) / Float64(a - z)))); else tmp = fma(Float64(-Float64(t - x)), t_1, t); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[z, -3.2e+263], N[(x * t$95$1 + t), $MachinePrecision], If[LessEqual[z, -5.5e-158], N[(t * N[(N[(y - z), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 1.22e+37], N[(x + N[(y * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-N[(t - x), $MachinePrecision]) * t$95$1 + t), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y - a}{z}\\
\mathbf{if}\;z \leq -3.2 \cdot 10^{+263}:\\
\;\;\;\;\mathsf{fma}\left(x, t\_1, t\right)\\
\mathbf{elif}\;z \leq -5.5 \cdot 10^{-158}:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y - z}{a - z}, x\right)\\
\mathbf{elif}\;z \leq 1.22 \cdot 10^{+37}:\\
\;\;\;\;x + y \cdot \frac{t - x}{a - z}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-\left(t - x\right), t\_1, t\right)\\
\end{array}
\end{array}
if z < -3.2000000000000001e263Initial program 33.3%
Taylor expanded in z around inf
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites99.9%
if -3.2000000000000001e263 < z < -5.50000000000000025e-158Initial program 81.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6485.4
Applied rewrites85.4%
Taylor expanded in x around 0
Applied rewrites76.6%
if -5.50000000000000025e-158 < z < 1.22e37Initial program 93.7%
Taylor expanded in y around inf
Applied rewrites84.6%
if 1.22e37 < z Initial program 55.1%
Taylor expanded in z around inf
Applied rewrites87.4%
Final simplification83.4%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (fma t (/ y a) x)))
(if (<= a -3.5e+69)
t_1
(if (<= a 1.7e-60)
(fma (/ (- x t) z) y t)
(if (<= a 7.8e+174) (fma x (/ (- y a) z) t) t_1)))))
double code(double x, double y, double z, double t, double a) {
double t_1 = fma(t, (y / a), x);
double tmp;
if (a <= -3.5e+69) {
tmp = t_1;
} else if (a <= 1.7e-60) {
tmp = fma(((x - t) / z), y, t);
} else if (a <= 7.8e+174) {
tmp = fma(x, ((y - a) / z), t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = fma(t, Float64(y / a), x) tmp = 0.0 if (a <= -3.5e+69) tmp = t_1; elseif (a <= 1.7e-60) tmp = fma(Float64(Float64(x - t) / z), y, t); elseif (a <= 7.8e+174) tmp = fma(x, Float64(Float64(y - a) / z), t); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(t * N[(y / a), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[a, -3.5e+69], t$95$1, If[LessEqual[a, 1.7e-60], N[(N[(N[(x - t), $MachinePrecision] / z), $MachinePrecision] * y + t), $MachinePrecision], If[LessEqual[a, 7.8e+174], N[(x * N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision] + t), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, \frac{y}{a}, x\right)\\
\mathbf{if}\;a \leq -3.5 \cdot 10^{+69}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \leq 1.7 \cdot 10^{-60}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x - t}{z}, y, t\right)\\
\mathbf{elif}\;a \leq 7.8 \cdot 10^{+174}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y - a}{z}, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if a < -3.49999999999999987e69 or 7.79999999999999962e174 < a Initial program 87.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6488.6
Applied rewrites88.6%
Taylor expanded in x around 0
Applied rewrites83.9%
Taylor expanded in z around 0
Applied rewrites64.5%
if -3.49999999999999987e69 < a < 1.70000000000000003e-60Initial program 67.5%
Taylor expanded in z around inf
Applied rewrites82.1%
Taylor expanded in a around 0
Applied rewrites75.9%
if 1.70000000000000003e-60 < a < 7.79999999999999962e174Initial program 80.2%
Taylor expanded in z around inf
Applied rewrites52.3%
Taylor expanded in x around inf
Applied rewrites52.8%
Final simplification67.3%
(FPCore (x y z t a) :precision binary64 (if (or (<= a -8.2e+77) (not (<= a 1.05e-46))) (fma t (/ (- y z) (- a z)) x) (fma (- (- t x)) (/ (- y a) z) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((a <= -8.2e+77) || !(a <= 1.05e-46)) {
tmp = fma(t, ((y - z) / (a - z)), x);
} else {
tmp = fma(-(t - x), ((y - a) / z), t);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((a <= -8.2e+77) || !(a <= 1.05e-46)) tmp = fma(t, Float64(Float64(y - z) / Float64(a - z)), x); else tmp = fma(Float64(-Float64(t - x)), Float64(Float64(y - a) / z), t); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[a, -8.2e+77], N[Not[LessEqual[a, 1.05e-46]], $MachinePrecision]], N[(t * N[(N[(y - z), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[((-N[(t - x), $MachinePrecision]) * N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision] + t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -8.2 \cdot 10^{+77} \lor \neg \left(a \leq 1.05 \cdot 10^{-46}\right):\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y - z}{a - z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-\left(t - x\right), \frac{y - a}{z}, t\right)\\
\end{array}
\end{array}
if a < -8.2000000000000002e77 or 1.04999999999999994e-46 < a Initial program 85.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6488.7
Applied rewrites88.7%
Taylor expanded in x around 0
Applied rewrites80.6%
if -8.2000000000000002e77 < a < 1.04999999999999994e-46Initial program 67.0%
Taylor expanded in z around inf
Applied rewrites82.7%
Final simplification81.6%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -4.2e+68) (not (<= z 1.42e+37))) (fma x (/ (- y a) z) t) (fma (- y z) (/ (- t x) a) x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -4.2e+68) || !(z <= 1.42e+37)) {
tmp = fma(x, ((y - a) / z), t);
} else {
tmp = fma((y - z), ((t - x) / a), x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -4.2e+68) || !(z <= 1.42e+37)) tmp = fma(x, Float64(Float64(y - a) / z), t); else tmp = fma(Float64(y - z), Float64(Float64(t - x) / a), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -4.2e+68], N[Not[LessEqual[z, 1.42e+37]], $MachinePrecision]], N[(x * N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision] + t), $MachinePrecision], N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / a), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+68} \lor \neg \left(z \leq 1.42 \cdot 10^{+37}\right):\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y - a}{z}, t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - z, \frac{t - x}{a}, x\right)\\
\end{array}
\end{array}
if z < -4.20000000000000002e68 or 1.4199999999999999e37 < z Initial program 59.0%
Taylor expanded in z around inf
Applied rewrites82.1%
Taylor expanded in x around inf
Applied rewrites76.8%
if -4.20000000000000002e68 < z < 1.4199999999999999e37Initial program 91.7%
Taylor expanded in a around inf
Applied rewrites75.1%
Final simplification75.9%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -4.2e+68) (not (<= z 5.2e-7))) (fma x (/ (- y a) z) t) (fma (/ (- t x) a) y x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -4.2e+68) || !(z <= 5.2e-7)) {
tmp = fma(x, ((y - a) / z), t);
} else {
tmp = fma(((t - x) / a), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -4.2e+68) || !(z <= 5.2e-7)) tmp = fma(x, Float64(Float64(y - a) / z), t); else tmp = fma(Float64(Float64(t - x) / a), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -4.2e+68], N[Not[LessEqual[z, 5.2e-7]], $MachinePrecision]], N[(x * N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision] + t), $MachinePrecision], N[(N[(N[(t - x), $MachinePrecision] / a), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+68} \lor \neg \left(z \leq 5.2 \cdot 10^{-7}\right):\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y - a}{z}, t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t - x}{a}, y, x\right)\\
\end{array}
\end{array}
if z < -4.20000000000000002e68 or 5.19999999999999998e-7 < z Initial program 62.0%
Taylor expanded in z around inf
Applied rewrites78.4%
Taylor expanded in x around inf
Applied rewrites73.3%
if -4.20000000000000002e68 < z < 5.19999999999999998e-7Initial program 92.1%
Taylor expanded in z around 0
Applied rewrites69.9%
Final simplification71.6%
(FPCore (x y z t a) :precision binary64 (if (or (<= a -3.5e+69) (not (<= a 7.8e+174))) (fma t (/ y a) x) (fma (/ (- x t) z) y t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((a <= -3.5e+69) || !(a <= 7.8e+174)) {
tmp = fma(t, (y / a), x);
} else {
tmp = fma(((x - t) / z), y, t);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((a <= -3.5e+69) || !(a <= 7.8e+174)) tmp = fma(t, Float64(y / a), x); else tmp = fma(Float64(Float64(x - t) / z), y, t); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[a, -3.5e+69], N[Not[LessEqual[a, 7.8e+174]], $MachinePrecision]], N[(t * N[(y / a), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(x - t), $MachinePrecision] / z), $MachinePrecision] * y + t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.5 \cdot 10^{+69} \lor \neg \left(a \leq 7.8 \cdot 10^{+174}\right):\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x - t}{z}, y, t\right)\\
\end{array}
\end{array}
if a < -3.49999999999999987e69 or 7.79999999999999962e174 < a Initial program 87.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6488.6
Applied rewrites88.6%
Taylor expanded in x around 0
Applied rewrites83.9%
Taylor expanded in z around 0
Applied rewrites64.5%
if -3.49999999999999987e69 < a < 7.79999999999999962e174Initial program 71.5%
Taylor expanded in z around inf
Applied rewrites72.9%
Taylor expanded in a around 0
Applied rewrites65.8%
Final simplification65.3%
(FPCore (x y z t a) :precision binary64 (if (<= z -1.15e+76) t (if (<= z 1500000000.0) (fma t (/ y a) x) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -1.15e+76) {
tmp = t;
} else if (z <= 1500000000.0) {
tmp = fma(t, (y / a), x);
} else {
tmp = t;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -1.15e+76) tmp = t; elseif (z <= 1500000000.0) tmp = fma(t, Float64(y / a), x); else tmp = t; end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -1.15e+76], t, If[LessEqual[z, 1500000000.0], N[(t * N[(y / a), $MachinePrecision] + x), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+76}:\\
\;\;\;\;t\\
\mathbf{elif}\;z \leq 1500000000:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -1.15000000000000001e76 or 1.5e9 < z Initial program 61.5%
Taylor expanded in z around inf
Applied rewrites57.6%
if -1.15000000000000001e76 < z < 1.5e9Initial program 90.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6492.5
Applied rewrites92.5%
Taylor expanded in x around 0
Applied rewrites74.7%
Taylor expanded in z around 0
Applied rewrites54.2%
Final simplification55.8%
(FPCore (x y z t a) :precision binary64 (if (<= a -1.8e+79) x (if (<= a 1.35e-8) t (if (<= a 9.5e+179) (fma t 1.0 x) x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -1.8e+79) {
tmp = x;
} else if (a <= 1.35e-8) {
tmp = t;
} else if (a <= 9.5e+179) {
tmp = fma(t, 1.0, x);
} else {
tmp = x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (a <= -1.8e+79) tmp = x; elseif (a <= 1.35e-8) tmp = t; elseif (a <= 9.5e+179) tmp = fma(t, 1.0, x); else tmp = x; end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -1.8e+79], x, If[LessEqual[a, 1.35e-8], t, If[LessEqual[a, 9.5e+179], N[(t * 1.0 + x), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.8 \cdot 10^{+79}:\\
\;\;\;\;x\\
\mathbf{elif}\;a \leq 1.35 \cdot 10^{-8}:\\
\;\;\;\;t\\
\mathbf{elif}\;a \leq 9.5 \cdot 10^{+179}:\\
\;\;\;\;\mathsf{fma}\left(t, 1, x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if a < -1.8e79 or 9.5e179 < a Initial program 88.5%
Taylor expanded in a around inf
Applied rewrites52.9%
if -1.8e79 < a < 1.35000000000000001e-8Initial program 68.5%
Taylor expanded in z around inf
Applied rewrites45.3%
if 1.35000000000000001e-8 < a < 9.5e179Initial program 80.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.4
Applied rewrites89.4%
Taylor expanded in x around 0
Applied rewrites73.4%
Taylor expanded in z around inf
Applied rewrites49.0%
Final simplification48.4%
(FPCore (x y z t a) :precision binary64 (if (<= a -1.8e+79) x (if (<= a 1.7e+175) t x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -1.8e+79) {
tmp = x;
} else if (a <= 1.7e+175) {
tmp = 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, a)
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), intent (in) :: a
real(8) :: tmp
if (a <= (-1.8d+79)) then
tmp = x
else if (a <= 1.7d+175) then
tmp = t
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -1.8e+79) {
tmp = x;
} else if (a <= 1.7e+175) {
tmp = t;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if a <= -1.8e+79: tmp = x elif a <= 1.7e+175: tmp = t else: tmp = x return tmp
function code(x, y, z, t, a) tmp = 0.0 if (a <= -1.8e+79) tmp = x; elseif (a <= 1.7e+175) tmp = t; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (a <= -1.8e+79) tmp = x; elseif (a <= 1.7e+175) tmp = t; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -1.8e+79], x, If[LessEqual[a, 1.7e+175], t, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.8 \cdot 10^{+79}:\\
\;\;\;\;x\\
\mathbf{elif}\;a \leq 1.7 \cdot 10^{+175}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if a < -1.8e79 or 1.70000000000000014e175 < a Initial program 88.5%
Taylor expanded in a around inf
Applied rewrites52.9%
if -1.8e79 < a < 1.70000000000000014e175Initial program 71.4%
Taylor expanded in z around inf
Applied rewrites43.1%
Final simplification46.3%
(FPCore (x y z t a) :precision binary64 t)
double code(double x, double y, double z, double t, double a) {
return t;
}
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, a)
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), intent (in) :: a
code = t
end function
public static double code(double x, double y, double z, double t, double a) {
return t;
}
def code(x, y, z, t, a): return t
function code(x, y, z, t, a) return t end
function tmp = code(x, y, z, t, a) tmp = t; end
code[x_, y_, z_, t_, a_] := t
\begin{array}{l}
\\
t
\end{array}
Initial program 77.0%
Taylor expanded in z around inf
Applied rewrites32.6%
Final simplification32.6%
herbie shell --seed 2025019
(FPCore (x y z t a)
:name "Numeric.Signal:interpolate from hsignal-0.2.7.1"
:precision binary64
(+ x (* (- y z) (/ (- t x) (- a z)))))