
(FPCore (x y z t a) :precision binary64 (+ x (* y (/ (- z t) (- z a)))))
double code(double x, double y, double z, double t, double a) {
return x + (y * ((z - t) / (z - a)));
}
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) / (z - a)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y * ((z - t) / (z - a)));
}
def code(x, y, z, t, a): return x + (y * ((z - t) / (z - a)))
function code(x, y, z, t, a) return Float64(x + Float64(y * Float64(Float64(z - t) / Float64(z - a)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y * ((z - t) / (z - a))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y * N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \frac{z - t}{z - a}
\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) (- z a)))))
double code(double x, double y, double z, double t, double a) {
return x + (y * ((z - t) / (z - a)));
}
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) / (z - a)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y * ((z - t) / (z - a)));
}
def code(x, y, z, t, a): return x + (y * ((z - t) / (z - a)))
function code(x, y, z, t, a) return Float64(x + Float64(y * Float64(Float64(z - t) / Float64(z - a)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y * ((z - t) / (z - a))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y * N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \frac{z - t}{z - a}
\end{array}
(FPCore (x y z t a) :precision binary64 (fma (/ (- z t) (- z a)) y x))
double code(double x, double y, double z, double t, double a) {
return fma(((z - t) / (z - a)), y, x);
}
function code(x, y, z, t, a) return fma(Float64(Float64(z - t) / Float64(z - a)), y, x) end
code[x_, y_, z_, t_, a_] := N[(N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z - t}{z - a}, y, x\right)
\end{array}
Initial program 97.3%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift--.f6497.3
Applied rewrites97.3%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (- z t) (- z a))) (t_2 (fma (/ (- t) (- z a)) y x)))
(if (<= t_1 -2000000000.0)
t_2
(if (<= t_1 1e-29)
(fma (/ (- z t) (- a)) y x)
(if (<= t_1 1.00001) (fma y (/ z (- z a)) x) t_2)))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (z - t) / (z - a);
double t_2 = fma((-t / (z - a)), y, x);
double tmp;
if (t_1 <= -2000000000.0) {
tmp = t_2;
} else if (t_1 <= 1e-29) {
tmp = fma(((z - t) / -a), y, x);
} else if (t_1 <= 1.00001) {
tmp = fma(y, (z / (z - a)), x);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(z - t) / Float64(z - a)) t_2 = fma(Float64(Float64(-t) / Float64(z - a)), y, x) tmp = 0.0 if (t_1 <= -2000000000.0) tmp = t_2; elseif (t_1 <= 1e-29) tmp = fma(Float64(Float64(z - t) / Float64(-a)), y, x); elseif (t_1 <= 1.00001) tmp = fma(y, Float64(z / Float64(z - a)), x); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[((-t) / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]}, If[LessEqual[t$95$1, -2000000000.0], t$95$2, If[LessEqual[t$95$1, 1e-29], N[(N[(N[(z - t), $MachinePrecision] / (-a)), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[t$95$1, 1.00001], N[(y * N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z - t}{z - a}\\
t_2 := \mathsf{fma}\left(\frac{-t}{z - a}, y, x\right)\\
\mathbf{if}\;t\_1 \leq -2000000000:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 10^{-29}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - t}{-a}, y, x\right)\\
\mathbf{elif}\;t\_1 \leq 1.00001:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{z - a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (-.f64 z t) (-.f64 z a)) < -2e9 or 1.0000100000000001 < (/.f64 (-.f64 z t) (-.f64 z a)) Initial program 93.4%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift--.f6493.5
Applied rewrites93.5%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6492.1
Applied rewrites92.1%
if -2e9 < (/.f64 (-.f64 z t) (-.f64 z a)) < 9.99999999999999943e-30Initial program 98.7%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift--.f6498.7
Applied rewrites98.7%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6498.6
Applied rewrites98.6%
if 9.99999999999999943e-30 < (/.f64 (-.f64 z t) (-.f64 z a)) < 1.0000100000000001Initial program 100.0%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift--.f64100.0
Applied rewrites100.0%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (- z t) (- z a))) (t_2 (- (* t (/ y (- z a))))))
(if (<= t_1 -5e+209)
t_2
(if (<= t_1 1e-29)
(+ x (* y (/ t a)))
(if (<= t_1 5e+200) (fma y (/ (- z t) z) x) t_2)))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (z - t) / (z - a);
double t_2 = -(t * (y / (z - a)));
double tmp;
if (t_1 <= -5e+209) {
tmp = t_2;
} else if (t_1 <= 1e-29) {
tmp = x + (y * (t / a));
} else if (t_1 <= 5e+200) {
tmp = fma(y, ((z - t) / z), x);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(z - t) / Float64(z - a)) t_2 = Float64(-Float64(t * Float64(y / Float64(z - a)))) tmp = 0.0 if (t_1 <= -5e+209) tmp = t_2; elseif (t_1 <= 1e-29) tmp = Float64(x + Float64(y * Float64(t / a))); elseif (t_1 <= 5e+200) tmp = fma(y, Float64(Float64(z - t) / z), x); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = (-N[(t * N[(y / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])}, If[LessEqual[t$95$1, -5e+209], t$95$2, If[LessEqual[t$95$1, 1e-29], N[(x + N[(y * N[(t / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+200], N[(y * N[(N[(z - t), $MachinePrecision] / z), $MachinePrecision] + x), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z - t}{z - a}\\
t_2 := -t \cdot \frac{y}{z - a}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+209}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 10^{-29}:\\
\;\;\;\;x + y \cdot \frac{t}{a}\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+200}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z - t}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (-.f64 z t) (-.f64 z a)) < -4.99999999999999964e209 or 5.00000000000000019e200 < (/.f64 (-.f64 z t) (-.f64 z a)) Initial program 81.9%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift--.f6481.9
Applied rewrites81.9%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6476.1
Applied rewrites76.1%
Taylor expanded in t around inf
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lift--.f6482.7
Applied rewrites82.7%
if -4.99999999999999964e209 < (/.f64 (-.f64 z t) (-.f64 z a)) < 9.99999999999999943e-30Initial program 99.0%
Taylor expanded in z around 0
lower-/.f6483.7
Applied rewrites83.7%
if 9.99999999999999943e-30 < (/.f64 (-.f64 z t) (-.f64 z a)) < 5.00000000000000019e200Initial program 99.9%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift--.f6490.7
Applied rewrites90.7%
Final simplification86.7%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (- z t) (- z a))) (t_2 (/ (* (- t) y) (- z a))))
(if (<= t_1 -5e+209)
t_2
(if (<= t_1 1e-29)
(+ x (* y (/ t a)))
(if (<= t_1 5e+200) (fma y (/ (- z t) z) x) t_2)))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (z - t) / (z - a);
double t_2 = (-t * y) / (z - a);
double tmp;
if (t_1 <= -5e+209) {
tmp = t_2;
} else if (t_1 <= 1e-29) {
tmp = x + (y * (t / a));
} else if (t_1 <= 5e+200) {
tmp = fma(y, ((z - t) / z), x);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(z - t) / Float64(z - a)) t_2 = Float64(Float64(Float64(-t) * y) / Float64(z - a)) tmp = 0.0 if (t_1 <= -5e+209) tmp = t_2; elseif (t_1 <= 1e-29) tmp = Float64(x + Float64(y * Float64(t / a))); elseif (t_1 <= 5e+200) tmp = fma(y, Float64(Float64(z - t) / z), x); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[((-t) * y), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+209], t$95$2, If[LessEqual[t$95$1, 1e-29], N[(x + N[(y * N[(t / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+200], N[(y * N[(N[(z - t), $MachinePrecision] / z), $MachinePrecision] + x), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z - t}{z - a}\\
t_2 := \frac{\left(-t\right) \cdot y}{z - a}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+209}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 10^{-29}:\\
\;\;\;\;x + y \cdot \frac{t}{a}\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+200}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z - t}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (-.f64 z t) (-.f64 z a)) < -4.99999999999999964e209 or 5.00000000000000019e200 < (/.f64 (-.f64 z t) (-.f64 z a)) Initial program 81.9%
Taylor expanded in t around inf
associate-*r/N/A
lower-/.f64N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6482.5
Applied rewrites82.5%
if -4.99999999999999964e209 < (/.f64 (-.f64 z t) (-.f64 z a)) < 9.99999999999999943e-30Initial program 99.0%
Taylor expanded in z around 0
lower-/.f6483.7
Applied rewrites83.7%
if 9.99999999999999943e-30 < (/.f64 (-.f64 z t) (-.f64 z a)) < 5.00000000000000019e200Initial program 99.9%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift--.f6490.7
Applied rewrites90.7%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (- z t) (- z a))))
(if (or (<= t_1 1e-29) (not (<= t_1 1.00001)))
(fma (/ (- t) (- z a)) y x)
(fma y (/ z (- z a)) x))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (z - t) / (z - a);
double tmp;
if ((t_1 <= 1e-29) || !(t_1 <= 1.00001)) {
tmp = fma((-t / (z - a)), y, x);
} else {
tmp = fma(y, (z / (z - a)), x);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(z - t) / Float64(z - a)) tmp = 0.0 if ((t_1 <= 1e-29) || !(t_1 <= 1.00001)) tmp = fma(Float64(Float64(-t) / Float64(z - a)), y, x); else tmp = fma(y, Float64(z / Float64(z - a)), x); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 1e-29], N[Not[LessEqual[t$95$1, 1.00001]], $MachinePrecision]], N[(N[((-t) / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision], N[(y * N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z - t}{z - a}\\
\mathbf{if}\;t\_1 \leq 10^{-29} \lor \neg \left(t\_1 \leq 1.00001\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{-t}{z - a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{z - a}, x\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 z t) (-.f64 z a)) < 9.99999999999999943e-30 or 1.0000100000000001 < (/.f64 (-.f64 z t) (-.f64 z a)) Initial program 95.9%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift--.f6495.9
Applied rewrites95.9%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6490.9
Applied rewrites90.9%
if 9.99999999999999943e-30 < (/.f64 (-.f64 z t) (-.f64 z a)) < 1.0000100000000001Initial program 100.0%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift--.f64100.0
Applied rewrites100.0%
Final simplification93.9%
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (/ (- z t) (- z a)))) (if (or (<= t_1 1e-29) (not (<= t_1 10000.0))) (fma t (/ y a) x) (+ x y))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (z - t) / (z - a);
double tmp;
if ((t_1 <= 1e-29) || !(t_1 <= 10000.0)) {
tmp = fma(t, (y / a), x);
} else {
tmp = x + y;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(z - t) / Float64(z - a)) tmp = 0.0 if ((t_1 <= 1e-29) || !(t_1 <= 10000.0)) tmp = fma(t, Float64(y / a), x); else tmp = Float64(x + y); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 1e-29], N[Not[LessEqual[t$95$1, 10000.0]], $MachinePrecision]], N[(t * N[(y / a), $MachinePrecision] + x), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z - t}{z - a}\\
\mathbf{if}\;t\_1 \leq 10^{-29} \lor \neg \left(t\_1 \leq 10000\right):\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (/.f64 (-.f64 z t) (-.f64 z a)) < 9.99999999999999943e-30 or 1e4 < (/.f64 (-.f64 z t) (-.f64 z a)) Initial program 95.9%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6474.4
Applied rewrites74.4%
if 9.99999999999999943e-30 < (/.f64 (-.f64 z t) (-.f64 z a)) < 1e4Initial program 100.0%
Taylor expanded in z around inf
Applied rewrites96.6%
Final simplification81.9%
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (/ (- z t) (- z a)))) (if (<= t_1 -5e+214) (/ (* y t) a) (if (<= t_1 1e-51) x (+ x y)))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (z - t) / (z - a);
double tmp;
if (t_1 <= -5e+214) {
tmp = (y * t) / a;
} else if (t_1 <= 1e-51) {
tmp = x;
} else {
tmp = x + y;
}
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) :: t_1
real(8) :: tmp
t_1 = (z - t) / (z - a)
if (t_1 <= (-5d+214)) then
tmp = (y * t) / a
else if (t_1 <= 1d-51) then
tmp = x
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = (z - t) / (z - a);
double tmp;
if (t_1 <= -5e+214) {
tmp = (y * t) / a;
} else if (t_1 <= 1e-51) {
tmp = x;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = (z - t) / (z - a) tmp = 0 if t_1 <= -5e+214: tmp = (y * t) / a elif t_1 <= 1e-51: tmp = x else: tmp = x + y return tmp
function code(x, y, z, t, a) t_1 = Float64(Float64(z - t) / Float64(z - a)) tmp = 0.0 if (t_1 <= -5e+214) tmp = Float64(Float64(y * t) / a); elseif (t_1 <= 1e-51) tmp = x; else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = (z - t) / (z - a); tmp = 0.0; if (t_1 <= -5e+214) tmp = (y * t) / a; elseif (t_1 <= 1e-51) tmp = x; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+214], N[(N[(y * t), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[t$95$1, 1e-51], x, N[(x + y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z - t}{z - a}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+214}:\\
\;\;\;\;\frac{y \cdot t}{a}\\
\mathbf{elif}\;t\_1 \leq 10^{-51}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (/.f64 (-.f64 z t) (-.f64 z a)) < -4.99999999999999953e214Initial program 88.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift--.f6488.0
Applied rewrites88.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift--.f6487.8
Applied rewrites87.8%
Taylor expanded in z around inf
Applied rewrites61.1%
Taylor expanded in z around 0
lower-/.f64N/A
*-commutativeN/A
lift-*.f6446.2
Applied rewrites46.2%
if -4.99999999999999953e214 < (/.f64 (-.f64 z t) (-.f64 z a)) < 1e-51Initial program 98.9%
Taylor expanded in x around inf
Applied rewrites65.6%
if 1e-51 < (/.f64 (-.f64 z t) (-.f64 z a)) Initial program 97.1%
Taylor expanded in z around inf
Applied rewrites75.7%
Final simplification69.8%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -2.6e-42) (not (<= z 5e-75))) (fma y (/ z (- z a)) x) (fma t (/ y a) x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -2.6e-42) || !(z <= 5e-75)) {
tmp = fma(y, (z / (z - a)), x);
} else {
tmp = fma(t, (y / a), x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -2.6e-42) || !(z <= 5e-75)) tmp = fma(y, Float64(z / Float64(z - a)), x); else tmp = fma(t, Float64(y / a), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -2.6e-42], N[Not[LessEqual[z, 5e-75]], $MachinePrecision]], N[(y * N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(t * N[(y / a), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{-42} \lor \neg \left(z \leq 5 \cdot 10^{-75}\right):\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{z - a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y}{a}, x\right)\\
\end{array}
\end{array}
if z < -2.6e-42 or 4.99999999999999979e-75 < z Initial program 99.3%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift--.f6481.7
Applied rewrites81.7%
if -2.6e-42 < z < 4.99999999999999979e-75Initial program 94.0%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6484.4
Applied rewrites84.4%
Final simplification82.7%
(FPCore (x y z t a) :precision binary64 (if (<= z -2.6e-42) (fma y (/ z (- z a)) x) (if (<= z 8.2e-21) (fma t (/ y a) x) (fma y (/ (- z t) z) x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -2.6e-42) {
tmp = fma(y, (z / (z - a)), x);
} else if (z <= 8.2e-21) {
tmp = fma(t, (y / a), x);
} else {
tmp = fma(y, ((z - t) / z), x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -2.6e-42) tmp = fma(y, Float64(z / Float64(z - a)), x); elseif (z <= 8.2e-21) tmp = fma(t, Float64(y / a), x); else tmp = fma(y, Float64(Float64(z - t) / z), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -2.6e-42], N[(y * N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 8.2e-21], N[(t * N[(y / a), $MachinePrecision] + x), $MachinePrecision], N[(y * N[(N[(z - t), $MachinePrecision] / z), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{-42}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{z - a}, x\right)\\
\mathbf{elif}\;z \leq 8.2 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z - t}{z}, x\right)\\
\end{array}
\end{array}
if z < -2.6e-42Initial program 100.0%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift--.f6489.8
Applied rewrites89.8%
if -2.6e-42 < z < 8.19999999999999988e-21Initial program 93.9%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6480.6
Applied rewrites80.6%
if 8.19999999999999988e-21 < z Initial program 99.9%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift--.f6485.3
Applied rewrites85.3%
(FPCore (x y z t a) :precision binary64 (if (<= (/ (- z t) (- z a)) 2.35e-48) x (+ x y)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (((z - t) / (z - a)) <= 2.35e-48) {
tmp = x;
} else {
tmp = x + y;
}
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 - t) / (z - a)) <= 2.35d-48) then
tmp = x
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (((z - t) / (z - a)) <= 2.35e-48) {
tmp = x;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if ((z - t) / (z - a)) <= 2.35e-48: tmp = x else: tmp = x + y return tmp
function code(x, y, z, t, a) tmp = 0.0 if (Float64(Float64(z - t) / Float64(z - a)) <= 2.35e-48) tmp = x; else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (((z - t) / (z - a)) <= 2.35e-48) tmp = x; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision], 2.35e-48], x, N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{z - t}{z - a} \leq 2.35 \cdot 10^{-48}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (/.f64 (-.f64 z t) (-.f64 z a)) < 2.3499999999999999e-48Initial program 97.5%
Taylor expanded in x around inf
Applied rewrites58.8%
if 2.3499999999999999e-48 < (/.f64 (-.f64 z t) (-.f64 z a)) Initial program 97.1%
Taylor expanded in z around inf
Applied rewrites75.7%
Final simplification67.8%
(FPCore (x y z t a) :precision binary64 (if (or (<= x -2.05e-169) (not (<= x 1.1e-278))) x y))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((x <= -2.05e-169) || !(x <= 1.1e-278)) {
tmp = x;
} else {
tmp = y;
}
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 ((x <= (-2.05d-169)) .or. (.not. (x <= 1.1d-278))) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((x <= -2.05e-169) || !(x <= 1.1e-278)) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (x <= -2.05e-169) or not (x <= 1.1e-278): tmp = x else: tmp = y return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((x <= -2.05e-169) || !(x <= 1.1e-278)) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((x <= -2.05e-169) || ~((x <= 1.1e-278))) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[x, -2.05e-169], N[Not[LessEqual[x, 1.1e-278]], $MachinePrecision]], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{-169} \lor \neg \left(x \leq 1.1 \cdot 10^{-278}\right):\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.0499999999999999e-169 or 1.1e-278 < x Initial program 97.4%
Taylor expanded in x around inf
Applied rewrites59.1%
if -2.0499999999999999e-169 < x < 1.1e-278Initial program 96.5%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift--.f6473.0
Applied rewrites73.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f6473.0
Applied rewrites73.0%
Taylor expanded in z around inf
Applied rewrites50.4%
Final simplification58.1%
(FPCore (x y z t a) :precision binary64 x)
double code(double x, double y, double z, double t, double a) {
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, 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
end function
public static double code(double x, double y, double z, double t, double a) {
return x;
}
def code(x, y, z, t, a): return x
function code(x, y, z, t, a) return x end
function tmp = code(x, y, z, t, a) tmp = x; end
code[x_, y_, z_, t_, a_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 97.3%
Taylor expanded in x around inf
Applied rewrites52.7%
herbie shell --seed 2025085
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisLine from plot-0.2.3.4, A"
:precision binary64
:alt
(! :herbie-platform default (+ x (/ y (/ (- z a) (- z t)))))
(+ x (* y (/ (- z t) (- z a)))))