
(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 13 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 2e+305)
t_1
(* (fma y (/ (fma (/ (fma b z t) y) a z) x) 1.0) x))))
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 <= 2e+305) {
tmp = t_1;
} else {
tmp = fma(y, (fma((fma(b, z, t) / y), a, z) / x), 1.0) * x;
}
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 <= 2e+305) tmp = t_1; else tmp = Float64(fma(y, Float64(fma(Float64(fma(b, z, t) / y), a, z) / x), 1.0) * x); 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, 2e+305], t$95$1, N[(N[(y * N[(N[(N[(N[(b * z + t), $MachinePrecision] / y), $MachinePrecision] * a + z), $MachinePrecision] / x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $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 2 \cdot 10^{+305}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(b, z, t\right)}{y}, a, z\right)}{x}, 1\right) \cdot x\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < 1.9999999999999999e305Initial program 99.4%
if 1.9999999999999999e305 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) Initial program 60.5%
Taylor expanded in y around inf
*-commutativeN/A
div-add-revN/A
div-addN/A
lower-*.f64N/A
Applied rewrites96.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.2%
Final simplification99.1%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))) (if (<= t_1 1e+298) t_1 (* (+ (/ (fma (fma b z t) a x) y) z) y))))
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+298) {
tmp = t_1;
} else {
tmp = ((fma(fma(b, z, t), a, x) / y) + z) * y;
}
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+298) tmp = t_1; else tmp = Float64(Float64(Float64(fma(fma(b, z, t), a, x) / y) + z) * y); 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+298], t$95$1, N[(N[(N[(N[(N[(b * z + t), $MachinePrecision] * a + x), $MachinePrecision] / y), $MachinePrecision] + z), $MachinePrecision] * y), $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^{+298}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(b, z, t\right), a, x\right)}{y} + z\right) \cdot y\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < 9.9999999999999996e297Initial program 99.4%
if 9.9999999999999996e297 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) Initial program 63.1%
Taylor expanded in y around inf
*-commutativeN/A
div-add-revN/A
div-addN/A
lower-*.f64N/A
Applied rewrites96.8%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))) (if (<= t_1 1e+303) t_1 (fma (fma b a y) z (* a t)))))
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+303) {
tmp = t_1;
} else {
tmp = fma(fma(b, a, y), z, (a * t));
}
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+303) tmp = t_1; else tmp = fma(fma(b, a, y), z, Float64(a * t)); 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+303], t$95$1, N[(N[(b * a + y), $MachinePrecision] * z + N[(a * t), $MachinePrecision]), $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^{+303}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(b, a, y\right), z, a \cdot t\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < 1e303Initial program 99.4%
if 1e303 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) Initial program 61.8%
Taylor expanded in y around inf
*-commutativeN/A
div-add-revN/A
div-addN/A
lower-*.f64N/A
Applied rewrites96.7%
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-*.f6491.7
Applied rewrites91.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= x -1.6e-55) (not (<= x 70.0))) (fma a t (fma z y x)) (fma (fma b a y) z (* a t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x <= -1.6e-55) || !(x <= 70.0)) {
tmp = fma(a, t, fma(z, y, x));
} else {
tmp = fma(fma(b, a, y), z, (a * t));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((x <= -1.6e-55) || !(x <= 70.0)) tmp = fma(a, t, fma(z, y, x)); else tmp = fma(fma(b, a, y), z, Float64(a * t)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[x, -1.6e-55], N[Not[LessEqual[x, 70.0]], $MachinePrecision]], N[(a * t + N[(z * y + x), $MachinePrecision]), $MachinePrecision], N[(N[(b * a + y), $MachinePrecision] * z + N[(a * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-55} \lor \neg \left(x \leq 70\right):\\
\;\;\;\;\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, y, x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(b, a, y\right), z, a \cdot t\right)\\
\end{array}
\end{array}
if x < -1.6000000000000001e-55 or 70 < x Initial program 91.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.f6489.4
Applied rewrites89.4%
if -1.6000000000000001e-55 < x < 70Initial program 89.1%
Taylor expanded in y around inf
*-commutativeN/A
div-add-revN/A
div-addN/A
lower-*.f64N/A
Applied rewrites85.7%
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-*.f6491.0
Applied rewrites91.0%
Final simplification90.2%
(FPCore (x y z t a b) :precision binary64 (if (or (<= b -3.7e+117) (not (<= b 1.4e+146))) (fma (* a z) b 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 ((b <= -3.7e+117) || !(b <= 1.4e+146)) {
tmp = fma((a * z), b, x);
} else {
tmp = fma(a, t, fma(z, y, x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((b <= -3.7e+117) || !(b <= 1.4e+146)) tmp = fma(Float64(a * z), b, x); else tmp = fma(a, t, fma(z, y, x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[b, -3.7e+117], N[Not[LessEqual[b, 1.4e+146]], $MachinePrecision]], N[(N[(a * z), $MachinePrecision] * b + x), $MachinePrecision], N[(a * t + N[(z * y + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.7 \cdot 10^{+117} \lor \neg \left(b \leq 1.4 \cdot 10^{+146}\right):\\
\;\;\;\;\mathsf{fma}\left(a \cdot z, b, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, y, x\right)\right)\\
\end{array}
\end{array}
if b < -3.6999999999999999e117 or 1.4e146 < b Initial program 85.8%
Taylor expanded in x around inf
Applied rewrites79.7%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lift-*.f6479.7
+-commutative79.7
*-commutative79.7
*-commutative79.7
+-commutative79.7
Applied rewrites79.7%
if -3.6999999999999999e117 < b < 1.4e146Initial program 92.4%
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.f6490.4
Applied rewrites90.4%
Final simplification87.4%
(FPCore (x y z t a b) :precision binary64 (if (or (<= a -4.4e+117) (not (<= a 1.2e+64))) (* (fma b z t) a) (fma z y x)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a <= -4.4e+117) || !(a <= 1.2e+64)) {
tmp = fma(b, z, t) * a;
} else {
tmp = fma(z, y, x);
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((a <= -4.4e+117) || !(a <= 1.2e+64)) tmp = Float64(fma(b, z, t) * a); else tmp = fma(z, y, x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[a, -4.4e+117], N[Not[LessEqual[a, 1.2e+64]], $MachinePrecision]], N[(N[(b * z + t), $MachinePrecision] * a), $MachinePrecision], N[(z * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.4 \cdot 10^{+117} \lor \neg \left(a \leq 1.2 \cdot 10^{+64}\right):\\
\;\;\;\;\mathsf{fma}\left(b, z, t\right) \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\end{array}
\end{array}
if a < -4.40000000000000028e117 or 1.2e64 < a Initial program 79.6%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6483.7
Applied rewrites83.7%
if -4.40000000000000028e117 < a < 1.2e64Initial program 96.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6476.0
Applied rewrites76.0%
Final simplification78.8%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -0.12) (not (<= z 1.75e+17))) (* (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 <= -0.12) || !(z <= 1.75e+17)) {
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 <= -0.12) || !(z <= 1.75e+17)) 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, -0.12], N[Not[LessEqual[z, 1.75e+17]], $MachinePrecision]], N[(N[(b * a + y), $MachinePrecision] * z), $MachinePrecision], N[(a * t + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.12 \lor \neg \left(z \leq 1.75 \cdot 10^{+17}\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 < -0.12 or 1.75e17 < z Initial program 83.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6476.7
Applied rewrites76.7%
if -0.12 < z < 1.75e17Initial program 98.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f6471.8
Applied rewrites71.8%
Final simplification74.3%
(FPCore (x y z t a b) :precision binary64 (if (or (<= a -9.4e+79) (not (<= a 1.85e+54))) (fma a t x) (fma z y x)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a <= -9.4e+79) || !(a <= 1.85e+54)) {
tmp = fma(a, t, x);
} else {
tmp = fma(z, y, x);
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((a <= -9.4e+79) || !(a <= 1.85e+54)) tmp = fma(a, t, x); else tmp = fma(z, y, x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[a, -9.4e+79], N[Not[LessEqual[a, 1.85e+54]], $MachinePrecision]], N[(a * t + x), $MachinePrecision], N[(z * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -9.4 \cdot 10^{+79} \lor \neg \left(a \leq 1.85 \cdot 10^{+54}\right):\\
\;\;\;\;\mathsf{fma}\left(a, t, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\end{array}
\end{array}
if a < -9.40000000000000045e79 or 1.8500000000000001e54 < a Initial program 82.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f6458.7
Applied rewrites58.7%
if -9.40000000000000045e79 < a < 1.8500000000000001e54Initial program 96.6%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6476.3
Applied rewrites76.3%
Final simplification69.0%
(FPCore (x y z t a b) :precision binary64 (if (or (<= y -7.6e+152) (not (<= y 6.2e+121))) (* z y) (fma a t x)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((y <= -7.6e+152) || !(y <= 6.2e+121)) {
tmp = z * y;
} else {
tmp = fma(a, t, x);
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((y <= -7.6e+152) || !(y <= 6.2e+121)) tmp = Float64(z * y); else tmp = fma(a, t, x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[y, -7.6e+152], N[Not[LessEqual[y, 6.2e+121]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(a * t + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.6 \cdot 10^{+152} \lor \neg \left(y \leq 6.2 \cdot 10^{+121}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, t, x\right)\\
\end{array}
\end{array}
if y < -7.6000000000000001e152 or 6.20000000000000016e121 < y Initial program 84.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6461.9
Applied rewrites61.9%
if -7.6000000000000001e152 < y < 6.20000000000000016e121Initial program 93.6%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f6459.5
Applied rewrites59.5%
Final simplification60.3%
(FPCore (x y z t a b) :precision binary64 (if (<= a -4.1e+120) (* (* b a) z) (if (<= a 1.85e+54) (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 (a <= -4.1e+120) {
tmp = (b * a) * z;
} else if (a <= 1.85e+54) {
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 (a <= -4.1e+120) tmp = Float64(Float64(b * a) * z); elseif (a <= 1.85e+54) tmp = fma(z, y, x); else tmp = fma(a, t, x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[a, -4.1e+120], N[(N[(b * a), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[a, 1.85e+54], N[(z * y + x), $MachinePrecision], N[(a * t + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.1 \cdot 10^{+120}:\\
\;\;\;\;\left(b \cdot a\right) \cdot z\\
\mathbf{elif}\;a \leq 1.85 \cdot 10^{+54}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, t, x\right)\\
\end{array}
\end{array}
if a < -4.1e120Initial program 81.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6462.3
Applied rewrites62.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6456.3
Applied rewrites56.3%
if -4.1e120 < a < 1.8500000000000001e54Initial program 96.8%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6476.3
Applied rewrites76.3%
if 1.8500000000000001e54 < a Initial program 79.2%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f6459.1
Applied rewrites59.1%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -6.2e+45) (not (<= z 1.8e+17))) (* z y) x))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z <= -6.2e+45) || !(z <= 1.8e+17)) {
tmp = z * y;
} 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 ((z <= (-6.2d+45)) .or. (.not. (z <= 1.8d+17))) then
tmp = z * y
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 ((z <= -6.2e+45) || !(z <= 1.8e+17)) {
tmp = z * y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z <= -6.2e+45) or not (z <= 1.8e+17): tmp = z * y else: tmp = x return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((z <= -6.2e+45) || !(z <= 1.8e+17)) tmp = Float64(z * y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((z <= -6.2e+45) || ~((z <= 1.8e+17))) tmp = z * y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[z, -6.2e+45], N[Not[LessEqual[z, 1.8e+17]], $MachinePrecision]], N[(z * y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \cdot 10^{+45} \lor \neg \left(z \leq 1.8 \cdot 10^{+17}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.19999999999999975e45 or 1.8e17 < z Initial program 82.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6447.8
Applied rewrites47.8%
if -6.19999999999999975e45 < z < 1.8e17Initial program 98.4%
Taylor expanded in x around inf
Applied rewrites45.0%
Final simplification46.3%
(FPCore (x y z t a b) :precision binary64 (if (<= x -110000000.0) x (if (<= x 0.018) (* a t) x)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (x <= -110000000.0) {
tmp = x;
} else if (x <= 0.018) {
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 (x <= (-110000000.0d0)) then
tmp = x
else if (x <= 0.018d0) 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 (x <= -110000000.0) {
tmp = x;
} else if (x <= 0.018) {
tmp = a * t;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if x <= -110000000.0: tmp = x elif x <= 0.018: tmp = a * t else: tmp = x return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (x <= -110000000.0) tmp = x; elseif (x <= 0.018) 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 (x <= -110000000.0) tmp = x; elseif (x <= 0.018) tmp = a * t; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[x, -110000000.0], x, If[LessEqual[x, 0.018], N[(a * t), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -110000000:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 0.018:\\
\;\;\;\;a \cdot t\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.1e8 or 0.0179999999999999986 < x Initial program 92.8%
Taylor expanded in x around inf
Applied rewrites51.4%
if -1.1e8 < x < 0.0179999999999999986Initial program 88.5%
Taylor expanded in t around inf
lower-*.f6431.2
Applied rewrites31.2%
(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 90.6%
Taylor expanded in x around inf
Applied rewrites28.3%
(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 2025051
(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)))