
(FPCore (x y z t a b) :precision binary64 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x + (y * z)) + (t * a)) + ((a * z) * b);
}
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, b)
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), intent (in) :: b
code = ((x + (y * z)) + (t * a)) + ((a * z) * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x + (y * z)) + (t * a)) + ((a * z) * b);
}
def code(x, y, z, t, a, b): return ((x + (y * z)) + (t * a)) + ((a * z) * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x + Float64(y * z)) + Float64(t * a)) + Float64(Float64(a * z) * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x + (y * z)) + (t * a)) + ((a * z) * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x + (y * z)) + (t * a)) + ((a * z) * b);
}
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, b)
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), intent (in) :: b
code = ((x + (y * z)) + (t * a)) + ((a * z) * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x + (y * z)) + (t * a)) + ((a * z) * b);
}
def code(x, y, z, t, a, b): return ((x + (y * z)) + (t * a)) + ((a * z) * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x + Float64(y * z)) + Float64(t * a)) + Float64(Float64(a * z) * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x + (y * z)) + (t * a)) + ((a * z) * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\end{array}
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))) (if (<= t_1 1e+304) t_1 (* (+ (fma b a (/ (fma a t x) z)) y) z))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = ((x + (y * z)) + (t * a)) + ((a * z) * b);
double tmp;
if (t_1 <= 1e+304) {
tmp = t_1;
} else {
tmp = (fma(b, a, (fma(a, t, x) / z)) + y) * z;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(Float64(Float64(x + Float64(y * z)) + Float64(t * a)) + Float64(Float64(a * z) * b)) tmp = 0.0 if (t_1 <= 1e+304) tmp = t_1; else tmp = Float64(Float64(fma(b, a, Float64(fma(a, t, x) / z)) + y) * z); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 1e+304], t$95$1, N[(N[(N[(b * a + N[(N[(a * t + x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\
\mathbf{if}\;t\_1 \leq 10^{+304}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(b, a, \frac{\mathsf{fma}\left(a, t, x\right)}{z}\right) + y\right) \cdot z\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < 9.9999999999999994e303Initial program 99.4%
if 9.9999999999999994e303 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) Initial program 76.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-fma.f64N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))) (if (<= t_1 INFINITY) t_1 (* (fma b z t) a))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = ((x + (y * z)) + (t * a)) + ((a * z) * b);
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = fma(b, z, t) * a;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(Float64(Float64(x + Float64(y * z)) + Float64(t * a)) + Float64(Float64(a * z) * b)) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(fma(b, z, t) * a); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(N[(b * z + t), $MachinePrecision] * a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, z, t\right) \cdot a\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < +inf.0Initial program 99.5%
if +inf.0 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) Initial program 0.0%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6490.0
Applied rewrites90.0%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -190000000000.0) (not (<= z 3.7e-60))) (fma (fma b a y) z (* a t)) (fma (fma b z t) a x)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z <= -190000000000.0) || !(z <= 3.7e-60)) {
tmp = fma(fma(b, a, y), z, (a * t));
} else {
tmp = fma(fma(b, z, t), a, x);
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((z <= -190000000000.0) || !(z <= 3.7e-60)) tmp = fma(fma(b, a, y), z, Float64(a * t)); else tmp = fma(fma(b, z, t), a, x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[z, -190000000000.0], N[Not[LessEqual[z, 3.7e-60]], $MachinePrecision]], N[(N[(b * a + y), $MachinePrecision] * z + N[(a * t), $MachinePrecision]), $MachinePrecision], N[(N[(b * z + t), $MachinePrecision] * a + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -190000000000 \lor \neg \left(z \leq 3.7 \cdot 10^{-60}\right):\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(b, a, y\right), z, a \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(b, z, t\right), a, x\right)\\
\end{array}
\end{array}
if z < -1.9e11 or 3.70000000000000025e-60 < z Initial program 93.4%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-fma.f64N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
lower-fma.f6499.2
Applied rewrites99.2%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
*-commutativeN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
lift-fma.f64N/A
lower-*.f6487.1
Applied rewrites87.1%
if -1.9e11 < z < 3.70000000000000025e-60Initial program 98.2%
Taylor expanded in y around 0
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6495.1
Applied rewrites95.1%
Final simplification90.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= a -5.6e+16) (not (<= a 2.8e-8))) (fma (fma b z t) a x) (fma a t (fma z y x))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a <= -5.6e+16) || !(a <= 2.8e-8)) {
tmp = fma(fma(b, z, t), a, x);
} else {
tmp = fma(a, t, fma(z, y, x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((a <= -5.6e+16) || !(a <= 2.8e-8)) tmp = fma(fma(b, z, t), a, x); else tmp = fma(a, t, fma(z, y, x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[a, -5.6e+16], N[Not[LessEqual[a, 2.8e-8]], $MachinePrecision]], N[(N[(b * z + t), $MachinePrecision] * a + x), $MachinePrecision], N[(a * t + N[(z * y + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5.6 \cdot 10^{+16} \lor \neg \left(a \leq 2.8 \cdot 10^{-8}\right):\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(b, z, t\right), a, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, y, x\right)\right)\\
\end{array}
\end{array}
if a < -5.6e16 or 2.7999999999999999e-8 < a Initial program 92.3%
Taylor expanded in y around 0
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6490.0
Applied rewrites90.0%
if -5.6e16 < a < 2.7999999999999999e-8Initial program 98.5%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6485.6
Applied rewrites85.6%
Final simplification87.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -3.6e+91) (not (<= z 1.2e+41))) (* (fma b a y) z) (fma a t (fma z y x))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z <= -3.6e+91) || !(z <= 1.2e+41)) {
tmp = fma(b, a, y) * z;
} else {
tmp = fma(a, t, fma(z, y, x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((z <= -3.6e+91) || !(z <= 1.2e+41)) tmp = Float64(fma(b, a, y) * z); else tmp = fma(a, t, fma(z, y, x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[z, -3.6e+91], N[Not[LessEqual[z, 1.2e+41]], $MachinePrecision]], N[(N[(b * a + y), $MachinePrecision] * z), $MachinePrecision], N[(a * t + N[(z * y + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.6 \cdot 10^{+91} \lor \neg \left(z \leq 1.2 \cdot 10^{+41}\right):\\
\;\;\;\;\mathsf{fma}\left(b, a, y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, y, x\right)\right)\\
\end{array}
\end{array}
if z < -3.6e91 or 1.2000000000000001e41 < z Initial program 92.4%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6481.5
Applied rewrites81.5%
if -3.6e91 < z < 1.2000000000000001e41Initial program 97.9%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6486.4
Applied rewrites86.4%
Final simplification84.3%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -13000000000.0) (not (<= z 1.36e-47))) (* (fma b a y) z) (fma a t x)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z <= -13000000000.0) || !(z <= 1.36e-47)) {
tmp = fma(b, a, y) * z;
} else {
tmp = fma(a, t, x);
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((z <= -13000000000.0) || !(z <= 1.36e-47)) tmp = Float64(fma(b, a, y) * z); else tmp = fma(a, t, x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[z, -13000000000.0], N[Not[LessEqual[z, 1.36e-47]], $MachinePrecision]], N[(N[(b * a + y), $MachinePrecision] * z), $MachinePrecision], N[(a * t + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -13000000000 \lor \neg \left(z \leq 1.36 \cdot 10^{-47}\right):\\
\;\;\;\;\mathsf{fma}\left(b, a, y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, t, x\right)\\
\end{array}
\end{array}
if z < -1.3e10 or 1.36000000000000011e-47 < z Initial program 93.3%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6478.3
Applied rewrites78.3%
if -1.3e10 < z < 1.36000000000000011e-47Initial program 98.2%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f6483.4
Applied rewrites83.4%
Final simplification80.7%
(FPCore (x y z t a b) :precision binary64 (if (<= z -2.2e-15) (* z y) (if (<= z -6e-249) (* a t) (if (<= z 3.6e-60) x (* z y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (z <= -2.2e-15) {
tmp = z * y;
} else if (z <= -6e-249) {
tmp = a * t;
} else if (z <= 3.6e-60) {
tmp = x;
} else {
tmp = z * 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, b)
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), intent (in) :: b
real(8) :: tmp
if (z <= (-2.2d-15)) then
tmp = z * y
else if (z <= (-6d-249)) then
tmp = a * t
else if (z <= 3.6d-60) then
tmp = x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (z <= -2.2e-15) {
tmp = z * y;
} else if (z <= -6e-249) {
tmp = a * t;
} else if (z <= 3.6e-60) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if z <= -2.2e-15: tmp = z * y elif z <= -6e-249: tmp = a * t elif z <= 3.6e-60: tmp = x else: tmp = z * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (z <= -2.2e-15) tmp = Float64(z * y); elseif (z <= -6e-249) tmp = Float64(a * t); elseif (z <= 3.6e-60) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (z <= -2.2e-15) tmp = z * y; elseif (z <= -6e-249) tmp = a * t; elseif (z <= 3.6e-60) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[z, -2.2e-15], N[(z * y), $MachinePrecision], If[LessEqual[z, -6e-249], N[(a * t), $MachinePrecision], If[LessEqual[z, 3.6e-60], x, N[(z * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-15}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq -6 \cdot 10^{-249}:\\
\;\;\;\;a \cdot t\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{-60}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -2.19999999999999986e-15 or 3.6e-60 < z Initial program 93.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6445.3
Applied rewrites45.3%
if -2.19999999999999986e-15 < z < -6.00000000000000008e-249Initial program 97.8%
Taylor expanded in t around inf
lower-*.f6459.2
Applied rewrites59.2%
if -6.00000000000000008e-249 < z < 3.6e-60Initial program 98.2%
Taylor expanded in x around inf
Applied rewrites58.2%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -2.2e-15) (not (<= z 6.8e-49))) (fma z y x) (fma a t x)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z <= -2.2e-15) || !(z <= 6.8e-49)) {
tmp = fma(z, y, x);
} else {
tmp = fma(a, t, x);
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((z <= -2.2e-15) || !(z <= 6.8e-49)) tmp = fma(z, y, x); else tmp = fma(a, t, x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[z, -2.2e-15], N[Not[LessEqual[z, 6.8e-49]], $MachinePrecision]], N[(z * y + x), $MachinePrecision], N[(a * t + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-15} \lor \neg \left(z \leq 6.8 \cdot 10^{-49}\right):\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, t, x\right)\\
\end{array}
\end{array}
if z < -2.19999999999999986e-15 or 6.8000000000000001e-49 < z Initial program 93.7%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6459.7
Applied rewrites59.7%
if -2.19999999999999986e-15 < z < 6.8000000000000001e-49Initial program 98.1%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f6484.8
Applied rewrites84.8%
Final simplification70.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -5e+197) (not (<= z 1.6e-53))) (* z y) (fma a t x)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z <= -5e+197) || !(z <= 1.6e-53)) {
tmp = z * y;
} else {
tmp = fma(a, t, x);
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((z <= -5e+197) || !(z <= 1.6e-53)) tmp = Float64(z * y); else tmp = fma(a, t, x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[z, -5e+197], N[Not[LessEqual[z, 1.6e-53]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(a * t + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+197} \lor \neg \left(z \leq 1.6 \cdot 10^{-53}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, t, x\right)\\
\end{array}
\end{array}
if z < -5.00000000000000009e197 or 1.6e-53 < z Initial program 93.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6452.4
Applied rewrites52.4%
if -5.00000000000000009e197 < z < 1.6e-53Initial program 96.8%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f6471.1
Applied rewrites71.1%
Final simplification64.2%
(FPCore (x y z t a b) :precision binary64 (if (or (<= t -8.5e-52) (not (<= t 5e+29))) (* a t) x))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t <= -8.5e-52) || !(t <= 5e+29)) {
tmp = a * 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, b)
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), intent (in) :: b
real(8) :: tmp
if ((t <= (-8.5d-52)) .or. (.not. (t <= 5d+29))) then
tmp = a * 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 b) {
double tmp;
if ((t <= -8.5e-52) || !(t <= 5e+29)) {
tmp = a * t;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t <= -8.5e-52) or not (t <= 5e+29): tmp = a * t else: tmp = x return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((t <= -8.5e-52) || !(t <= 5e+29)) tmp = Float64(a * t); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((t <= -8.5e-52) || ~((t <= 5e+29))) tmp = a * t; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[t, -8.5e-52], N[Not[LessEqual[t, 5e+29]], $MachinePrecision]], N[(a * t), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -8.5 \cdot 10^{-52} \lor \neg \left(t \leq 5 \cdot 10^{+29}\right):\\
\;\;\;\;a \cdot t\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -8.50000000000000006e-52 or 5.0000000000000001e29 < t Initial program 93.4%
Taylor expanded in t around inf
lower-*.f6448.5
Applied rewrites48.5%
if -8.50000000000000006e-52 < t < 5.0000000000000001e29Initial program 97.6%
Taylor expanded in x around inf
Applied rewrites38.1%
Final simplification43.1%
(FPCore (x y z t a b) :precision binary64 x)
double code(double x, double y, double z, double t, double a, double b) {
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, b)
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), intent (in) :: b
code = x
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return x;
}
def code(x, y, z, t, a, b): return x
function code(x, y, z, t, a, b) return x end
function tmp = code(x, y, z, t, a, b) tmp = x; end
code[x_, y_, z_, t_, a_, b_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 95.6%
Taylor expanded in x around inf
Applied rewrites28.2%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (+ (* z (+ (* b a) y)) (+ x (* t a)))))
(if (< z -11820553527347888000.0)
t_1
(if (< z 4.7589743188364287e-122)
(+ (* (+ (* b z) t) a) (+ (* z y) x))
t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (z * ((b * a) + y)) + (x + (t * a));
double tmp;
if (z < -11820553527347888000.0) {
tmp = t_1;
} else if (z < 4.7589743188364287e-122) {
tmp = (((b * z) + t) * a) + ((z * y) + x);
} else {
tmp = t_1;
}
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, b)
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), intent (in) :: b
real(8) :: t_1
real(8) :: tmp
t_1 = (z * ((b * a) + y)) + (x + (t * a))
if (z < (-11820553527347888000.0d0)) then
tmp = t_1
else if (z < 4.7589743188364287d-122) then
tmp = (((b * z) + t) * a) + ((z * y) + x)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (z * ((b * a) + y)) + (x + (t * a));
double tmp;
if (z < -11820553527347888000.0) {
tmp = t_1;
} else if (z < 4.7589743188364287e-122) {
tmp = (((b * z) + t) * a) + ((z * y) + x);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (z * ((b * a) + y)) + (x + (t * a)) tmp = 0 if z < -11820553527347888000.0: tmp = t_1 elif z < 4.7589743188364287e-122: tmp = (((b * z) + t) * a) + ((z * y) + x) else: tmp = t_1 return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(z * Float64(Float64(b * a) + y)) + Float64(x + Float64(t * a))) tmp = 0.0 if (z < -11820553527347888000.0) tmp = t_1; elseif (z < 4.7589743188364287e-122) tmp = Float64(Float64(Float64(Float64(b * z) + t) * a) + Float64(Float64(z * y) + x)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (z * ((b * a) + y)) + (x + (t * a)); tmp = 0.0; if (z < -11820553527347888000.0) tmp = t_1; elseif (z < 4.7589743188364287e-122) tmp = (((b * z) + t) * a) + ((z * y) + x); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(z * N[(N[(b * a), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision] + N[(x + N[(t * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[z, -11820553527347888000.0], t$95$1, If[Less[z, 4.7589743188364287e-122], N[(N[(N[(N[(b * z), $MachinePrecision] + t), $MachinePrecision] * a), $MachinePrecision] + N[(N[(z * y), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\
\mathbf{if}\;z < -11820553527347888000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z < 4.7589743188364287 \cdot 10^{-122}:\\
\;\;\;\;\left(b \cdot z + t\right) \cdot a + \left(z \cdot y + x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
herbie shell --seed 2025080
(FPCore (x y z t a b)
:name "Graphics.Rasterific.CubicBezier:cachedBezierAt from Rasterific-0.6.1"
:precision binary64
:alt
(! :herbie-platform default (if (< z -11820553527347888000) (+ (* z (+ (* b a) y)) (+ x (* t a))) (if (< z 47589743188364287/1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (+ (* (+ (* b z) t) a) (+ (* z y) x)) (+ (* z (+ (* b a) y)) (+ x (* t a))))))
(+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))