
(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 12 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))))))
(if (or (<= t_1 -5e-308) (not (<= t_1 0.0)))
(fma (- t x) (/ (- y z) (- a z)) x)
(fma (/ (- t x) (- z)) (- y a) 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 <= -5e-308) || !(t_1 <= 0.0)) {
tmp = fma((t - x), ((y - z) / (a - z)), x);
} else {
tmp = fma(((t - x) / -z), (y - a), 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 <= -5e-308) || !(t_1 <= 0.0)) tmp = fma(Float64(t - x), Float64(Float64(y - z) / Float64(a - z)), x); else tmp = fma(Float64(Float64(t - x) / Float64(-z)), Float64(y - a), 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, -5e-308], 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[(t - x), $MachinePrecision] / (-z)), $MachinePrecision] * N[(y - a), $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 -5 \cdot 10^{-308} \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(\frac{t - x}{-z}, y - a, t\right)\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -4.99999999999999955e-308 or 0.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) Initial program 89.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-/.f6493.9
Applied rewrites93.9%
if -4.99999999999999955e-308 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 0.0Initial program 3.6%
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.6
Applied rewrites3.6%
Taylor expanded in z around inf
Applied rewrites99.8%
Final simplification94.7%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (* (- t x) (/ y (- a z))))
(t_2 (+ x (* (- y z) (/ (- t x) (- a z)))))
(t_3 (fma t (/ (- y z) (- a z)) x)))
(if (<= t_2 (- INFINITY))
t_1
(if (<= t_2 -5e-308)
t_3
(if (<= t_2 0.0)
(fma (/ (- t x) (- z)) (- y a) t)
(if (<= t_2 4e+302) t_3 t_1))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (t - x) * (y / (a - z));
double t_2 = x + ((y - z) * ((t - x) / (a - z)));
double t_3 = fma(t, ((y - z) / (a - z)), x);
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_2 <= -5e-308) {
tmp = t_3;
} else if (t_2 <= 0.0) {
tmp = fma(((t - x) / -z), (y - a), t);
} else if (t_2 <= 4e+302) {
tmp = t_3;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(t - x) * Float64(y / Float64(a - z))) t_2 = Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z)))) t_3 = fma(t, Float64(Float64(y - z) / Float64(a - z)), x) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = t_1; elseif (t_2 <= -5e-308) tmp = t_3; elseif (t_2 <= 0.0) tmp = fma(Float64(Float64(t - x) / Float64(-z)), Float64(y - a), t); elseif (t_2 <= 4e+302) tmp = t_3; else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * N[(y / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t * N[(N[(y - z), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$1, If[LessEqual[t$95$2, -5e-308], t$95$3, If[LessEqual[t$95$2, 0.0], N[(N[(N[(t - x), $MachinePrecision] / (-z)), $MachinePrecision] * N[(y - a), $MachinePrecision] + t), $MachinePrecision], If[LessEqual[t$95$2, 4e+302], t$95$3, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot \frac{y}{a - z}\\
t_2 := x + \left(y - z\right) \cdot \frac{t - x}{a - z}\\
t_3 := \mathsf{fma}\left(t, \frac{y - z}{a - z}, x\right)\\
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq -5 \cdot 10^{-308}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_2 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(\frac{t - x}{-z}, y - a, t\right)\\
\mathbf{elif}\;t\_2 \leq 4 \cdot 10^{+302}:\\
\;\;\;\;t\_3\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -inf.0 or 4.0000000000000003e302 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) Initial program 87.2%
Taylor expanded in y around inf
Applied rewrites95.6%
if -inf.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -4.99999999999999955e-308 or 0.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 4.0000000000000003e302Initial program 89.5%
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 rewrites80.9%
if -4.99999999999999955e-308 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 0.0Initial program 3.6%
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.6
Applied rewrites3.6%
Taylor expanded in z around inf
Applied rewrites99.8%
Final simplification85.8%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (* t (/ y a))) (t_2 (+ x (* (- y z) (/ (- t x) (- a z))))))
(if (<= t_2 (- INFINITY))
t_1
(if (<= t_2 -2e-151)
(fma t 1.0 x)
(if (<= t_2 1e-184) t (if (<= t_2 4e+291) (fma t 1.0 x) t_1))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = t * (y / a);
double t_2 = x + ((y - z) * ((t - x) / (a - z)));
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_2 <= -2e-151) {
tmp = fma(t, 1.0, x);
} else if (t_2 <= 1e-184) {
tmp = t;
} else if (t_2 <= 4e+291) {
tmp = fma(t, 1.0, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(t * Float64(y / a)) t_2 = Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z)))) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = t_1; elseif (t_2 <= -2e-151) tmp = fma(t, 1.0, x); elseif (t_2 <= 1e-184) tmp = t; elseif (t_2 <= 4e+291) tmp = fma(t, 1.0, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(t * N[(y / a), $MachinePrecision]), $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, (-Infinity)], t$95$1, If[LessEqual[t$95$2, -2e-151], N[(t * 1.0 + x), $MachinePrecision], If[LessEqual[t$95$2, 1e-184], t, If[LessEqual[t$95$2, 4e+291], N[(t * 1.0 + x), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := t \cdot \frac{y}{a}\\
t_2 := x + \left(y - z\right) \cdot \frac{t - x}{a - z}\\
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq -2 \cdot 10^{-151}:\\
\;\;\;\;\mathsf{fma}\left(t, 1, x\right)\\
\mathbf{elif}\;t\_2 \leq 10^{-184}:\\
\;\;\;\;t\\
\mathbf{elif}\;t\_2 \leq 4 \cdot 10^{+291}:\\
\;\;\;\;\mathsf{fma}\left(t, 1, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -inf.0 or 3.9999999999999998e291 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) Initial program 87.4%
Taylor expanded in y around inf
Applied rewrites93.7%
Taylor expanded in z around 0
Applied rewrites76.3%
Taylor expanded in x around 0
Applied rewrites63.6%
if -inf.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -1.9999999999999999e-151 or 1.0000000000000001e-184 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 3.9999999999999998e291Initial program 94.6%
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.0
Applied rewrites94.0%
Taylor expanded in x around 0
Applied rewrites81.7%
Taylor expanded in z around inf
Applied rewrites48.5%
if -1.9999999999999999e-151 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 1.0000000000000001e-184Initial program 22.4%
Taylor expanded in z around inf
Applied rewrites39.9%
Final simplification49.4%
(FPCore (x y z t a)
:precision binary64
(if (<= z -8e+112)
t
(if (<= z 2.3e-166)
(fma (- t x) (/ y a) x)
(if (<= z 6.5e+107) (* (- t x) (/ y (- a z))) t))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -8e+112) {
tmp = t;
} else if (z <= 2.3e-166) {
tmp = fma((t - x), (y / a), x);
} else if (z <= 6.5e+107) {
tmp = (t - x) * (y / (a - z));
} else {
tmp = t;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -8e+112) tmp = t; elseif (z <= 2.3e-166) tmp = fma(Float64(t - x), Float64(y / a), x); elseif (z <= 6.5e+107) tmp = Float64(Float64(t - x) * Float64(y / Float64(a - z))); else tmp = t; end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -8e+112], t, If[LessEqual[z, 2.3e-166], N[(N[(t - x), $MachinePrecision] * N[(y / a), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 6.5e+107], N[(N[(t - x), $MachinePrecision] * N[(y / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+112}:\\
\;\;\;\;t\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-166}:\\
\;\;\;\;\mathsf{fma}\left(t - x, \frac{y}{a}, x\right)\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{+107}:\\
\;\;\;\;\left(t - x\right) \cdot \frac{y}{a - z}\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -7.9999999999999994e112 or 6.5000000000000006e107 < z Initial program 57.6%
Taylor expanded in z around inf
Applied rewrites60.1%
if -7.9999999999999994e112 < z < 2.29999999999999999e-166Initial 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.7
Applied rewrites92.7%
Taylor expanded in z around 0
Applied rewrites79.6%
if 2.29999999999999999e-166 < z < 6.5000000000000006e107Initial program 82.7%
Taylor expanded in y around inf
Applied rewrites61.5%
Final simplification69.8%
(FPCore (x y z t a) :precision binary64 (if (or (<= y -1.08e+151) (not (<= y 9e+69))) (* (- t x) (/ y (- a z))) (fma t (/ (- y z) (- a z)) x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((y <= -1.08e+151) || !(y <= 9e+69)) {
tmp = (t - x) * (y / (a - z));
} else {
tmp = fma(t, ((y - z) / (a - z)), x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((y <= -1.08e+151) || !(y <= 9e+69)) tmp = Float64(Float64(t - x) * Float64(y / Float64(a - z))); else tmp = fma(t, Float64(Float64(y - z) / Float64(a - z)), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[y, -1.08e+151], N[Not[LessEqual[y, 9e+69]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * N[(y / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(N[(y - z), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.08 \cdot 10^{+151} \lor \neg \left(y \leq 9 \cdot 10^{+69}\right):\\
\;\;\;\;\left(t - x\right) \cdot \frac{y}{a - z}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y - z}{a - z}, x\right)\\
\end{array}
\end{array}
if y < -1.08000000000000003e151 or 8.9999999999999999e69 < y Initial program 83.6%
Taylor expanded in y around inf
Applied rewrites86.8%
if -1.08000000000000003e151 < y < 8.9999999999999999e69Initial program 76.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-/.f6481.1
Applied rewrites81.1%
Taylor expanded in x around 0
Applied rewrites75.0%
Final simplification78.6%
(FPCore (x y z t a) :precision binary64 (if (<= z -2.7e+144) t (if (<= z 4.6e+86) (fma (- y z) (/ (- t x) a) x) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -2.7e+144) {
tmp = t;
} else if (z <= 4.6e+86) {
tmp = fma((y - z), ((t - x) / a), x);
} else {
tmp = t;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -2.7e+144) tmp = t; elseif (z <= 4.6e+86) tmp = fma(Float64(y - z), Float64(Float64(t - x) / a), x); else tmp = t; end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -2.7e+144], t, If[LessEqual[z, 4.6e+86], N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / a), $MachinePrecision] + x), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+144}:\\
\;\;\;\;t\\
\mathbf{elif}\;z \leq 4.6 \cdot 10^{+86}:\\
\;\;\;\;\mathsf{fma}\left(y - z, \frac{t - x}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -2.70000000000000015e144 or 4.59999999999999979e86 < z Initial program 56.6%
Taylor expanded in z around inf
Applied rewrites61.7%
if -2.70000000000000015e144 < z < 4.59999999999999979e86Initial program 88.2%
Taylor expanded in a around inf
Applied rewrites73.5%
Final simplification69.8%
(FPCore (x y z t a) :precision binary64 (if (or (<= y -1.1e+54) (not (<= y 1.05e+32))) (* (- t x) (/ y (- a z))) (fma t (/ (- z) (- a z)) x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((y <= -1.1e+54) || !(y <= 1.05e+32)) {
tmp = (t - x) * (y / (a - z));
} else {
tmp = fma(t, (-z / (a - z)), x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((y <= -1.1e+54) || !(y <= 1.05e+32)) tmp = Float64(Float64(t - x) * Float64(y / Float64(a - z))); else tmp = fma(t, Float64(Float64(-z) / Float64(a - z)), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[y, -1.1e+54], N[Not[LessEqual[y, 1.05e+32]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * N[(y / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[((-z) / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+54} \lor \neg \left(y \leq 1.05 \cdot 10^{+32}\right):\\
\;\;\;\;\left(t - x\right) \cdot \frac{y}{a - z}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{-z}{a - z}, x\right)\\
\end{array}
\end{array}
if y < -1.09999999999999995e54 or 1.05e32 < y Initial program 83.1%
Taylor expanded in y around inf
Applied rewrites78.3%
if -1.09999999999999995e54 < y < 1.05e32Initial program 75.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-/.f6479.7
Applied rewrites79.7%
Taylor expanded in x around 0
Applied rewrites74.4%
Taylor expanded in y around 0
Applied rewrites62.6%
Final simplification69.1%
(FPCore (x y z t a) :precision binary64 (if (<= z -8e+112) t (if (<= z 5.5e+107) (fma (- t x) (/ y a) x) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -8e+112) {
tmp = t;
} else if (z <= 5.5e+107) {
tmp = fma((t - x), (y / a), x);
} else {
tmp = t;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -8e+112) tmp = t; elseif (z <= 5.5e+107) tmp = fma(Float64(t - x), Float64(y / a), x); else tmp = t; end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -8e+112], t, If[LessEqual[z, 5.5e+107], N[(N[(t - x), $MachinePrecision] * N[(y / a), $MachinePrecision] + x), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+112}:\\
\;\;\;\;t\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+107}:\\
\;\;\;\;\mathsf{fma}\left(t - x, \frac{y}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -7.9999999999999994e112 or 5.5000000000000003e107 < z Initial program 57.6%
Taylor expanded in z around inf
Applied rewrites60.1%
if -7.9999999999999994e112 < z < 5.5000000000000003e107Initial program 88.5%
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-/.f6491.5
Applied rewrites91.5%
Taylor expanded in z around 0
Applied rewrites70.7%
Final simplification67.2%
(FPCore (x y z t a) :precision binary64 (if (<= z -8e+112) t (if (<= z 8.8e+80) (fma (/ (- t x) a) y x) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -8e+112) {
tmp = t;
} else if (z <= 8.8e+80) {
tmp = fma(((t - x) / a), y, x);
} else {
tmp = t;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -8e+112) tmp = t; elseif (z <= 8.8e+80) tmp = fma(Float64(Float64(t - x) / a), y, x); else tmp = t; end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -8e+112], t, If[LessEqual[z, 8.8e+80], N[(N[(N[(t - x), $MachinePrecision] / a), $MachinePrecision] * y + x), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+112}:\\
\;\;\;\;t\\
\mathbf{elif}\;z \leq 8.8 \cdot 10^{+80}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t - x}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -7.9999999999999994e112 or 8.80000000000000011e80 < z Initial program 57.3%
Taylor expanded in z around inf
Applied rewrites58.6%
if -7.9999999999999994e112 < z < 8.80000000000000011e80Initial program 89.4%
Taylor expanded in z around 0
Applied rewrites69.5%
Final simplification65.8%
(FPCore (x y z t a) :precision binary64 (if (<= z -8e+112) t (if (<= z 5.5e+107) (fma t (/ y a) x) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -8e+112) {
tmp = t;
} else if (z <= 5.5e+107) {
tmp = fma(t, (y / a), x);
} else {
tmp = t;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -8e+112) tmp = t; elseif (z <= 5.5e+107) tmp = fma(t, Float64(y / a), x); else tmp = t; end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -8e+112], t, If[LessEqual[z, 5.5e+107], N[(t * N[(y / a), $MachinePrecision] + x), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+112}:\\
\;\;\;\;t\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+107}:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -7.9999999999999994e112 or 5.5000000000000003e107 < z Initial program 57.6%
Taylor expanded in z around inf
Applied rewrites60.1%
if -7.9999999999999994e112 < z < 5.5000000000000003e107Initial program 88.5%
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-/.f6491.5
Applied rewrites91.5%
Taylor expanded in x around 0
Applied rewrites73.9%
Taylor expanded in z around 0
Applied rewrites60.2%
Final simplification60.2%
(FPCore (x y z t a) :precision binary64 (if (<= z -2.6e+23) t (if (<= z 3.6e+84) x t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -2.6e+23) {
tmp = t;
} else if (z <= 3.6e+84) {
tmp = x;
} else {
tmp = t;
}
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 (z <= (-2.6d+23)) then
tmp = t
else if (z <= 3.6d+84) then
tmp = x
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -2.6e+23) {
tmp = t;
} else if (z <= 3.6e+84) {
tmp = x;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if z <= -2.6e+23: tmp = t elif z <= 3.6e+84: tmp = x else: tmp = t return tmp
function code(x, y, z, t, a) tmp = 0.0 if (z <= -2.6e+23) tmp = t; elseif (z <= 3.6e+84) tmp = x; else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (z <= -2.6e+23) tmp = t; elseif (z <= 3.6e+84) tmp = x; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -2.6e+23], t, If[LessEqual[z, 3.6e+84], x, t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{+23}:\\
\;\;\;\;t\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+84}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -2.59999999999999992e23 or 3.5999999999999999e84 < z Initial program 60.3%
Taylor expanded in z around inf
Applied rewrites54.1%
if -2.59999999999999992e23 < z < 3.5999999999999999e84Initial program 91.7%
Taylor expanded in a around inf
Applied rewrites33.3%
Final simplification42.2%
(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 78.3%
Taylor expanded in z around inf
Applied rewrites27.7%
Final simplification27.7%
herbie shell --seed 2025018
(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)))))