
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (((y - x) * 6.0d0) * ((2.0d0 / 3.0d0) - z))
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
def code(x, y, z): return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z))
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * ((2.0 / 3.0) - z)); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (((y - x) * 6.0d0) * ((2.0d0 / 3.0d0) - z))
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
def code(x, y, z): return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z))
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * ((2.0 / 3.0) - z)); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\end{array}
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (((y - x) * 6.0d0) * ((2.0d0 / 3.0d0) - z))
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
def code(x, y, z): return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z))
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * ((2.0 / 3.0) - z)); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\end{array}
Initial program 99.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (/ 2.0 3.0) z)))
(if (or (<= t_0 -5000000.0) (not (<= t_0 1.0)))
(* (* x z) 6.0)
(fma 4.0 (- y x) x))))
double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double tmp;
if ((t_0 <= -5000000.0) || !(t_0 <= 1.0)) {
tmp = (x * z) * 6.0;
} else {
tmp = fma(4.0, (y - x), x);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(2.0 / 3.0) - z) tmp = 0.0 if ((t_0 <= -5000000.0) || !(t_0 <= 1.0)) tmp = Float64(Float64(x * z) * 6.0); else tmp = fma(4.0, Float64(y - x), x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -5000000.0], N[Not[LessEqual[t$95$0, 1.0]], $MachinePrecision]], N[(N[(x * z), $MachinePrecision] * 6.0), $MachinePrecision], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
\mathbf{if}\;t\_0 \leq -5000000 \lor \neg \left(t\_0 \leq 1\right):\\
\;\;\;\;\left(x \cdot z\right) \cdot 6\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < -5e6 or 1 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites46.1%
Taylor expanded in z around inf
Applied rewrites46.0%
if -5e6 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 1Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites97.6%
Final simplification69.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* z y) -6.0)))
(if (<= z -61000000.0)
t_0
(if (<= z 0.62)
(fma x -3.0 (* 4.0 y))
(if (<= z 5e+200) (* (* x z) 6.0) t_0)))))
double code(double x, double y, double z) {
double t_0 = (z * y) * -6.0;
double tmp;
if (z <= -61000000.0) {
tmp = t_0;
} else if (z <= 0.62) {
tmp = fma(x, -3.0, (4.0 * y));
} else if (z <= 5e+200) {
tmp = (x * z) * 6.0;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z * y) * -6.0) tmp = 0.0 if (z <= -61000000.0) tmp = t_0; elseif (z <= 0.62) tmp = fma(x, -3.0, Float64(4.0 * y)); elseif (z <= 5e+200) tmp = Float64(Float64(x * z) * 6.0); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * y), $MachinePrecision] * -6.0), $MachinePrecision]}, If[LessEqual[z, -61000000.0], t$95$0, If[LessEqual[z, 0.62], N[(x * -3.0 + N[(4.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 5e+200], N[(N[(x * z), $MachinePrecision] * 6.0), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z \cdot y\right) \cdot -6\\
\mathbf{if}\;z \leq -61000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.62:\\
\;\;\;\;\mathsf{fma}\left(x, -3, 4 \cdot y\right)\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+200}:\\
\;\;\;\;\left(x \cdot z\right) \cdot 6\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -6.1e7 or 5.00000000000000019e200 < z Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-/.f64N/A
metadata-eval99.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites64.2%
Taylor expanded in z around inf
Applied rewrites63.9%
if -6.1e7 < z < 0.619999999999999996Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites96.8%
Taylor expanded in x around inf
Applied rewrites88.9%
Applied rewrites88.9%
Taylor expanded in x around 0
Applied rewrites96.9%
if 0.619999999999999996 < z < 5.00000000000000019e200Initial program 99.7%
Taylor expanded in x around inf
Applied rewrites57.1%
Taylor expanded in z around inf
Applied rewrites56.0%
Final simplification77.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* z y) -6.0)))
(if (<= z -61000000.0)
t_0
(if (<= z 0.62)
(fma 4.0 (- y x) x)
(if (<= z 5e+200) (* (* x z) 6.0) t_0)))))
double code(double x, double y, double z) {
double t_0 = (z * y) * -6.0;
double tmp;
if (z <= -61000000.0) {
tmp = t_0;
} else if (z <= 0.62) {
tmp = fma(4.0, (y - x), x);
} else if (z <= 5e+200) {
tmp = (x * z) * 6.0;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z * y) * -6.0) tmp = 0.0 if (z <= -61000000.0) tmp = t_0; elseif (z <= 0.62) tmp = fma(4.0, Float64(y - x), x); elseif (z <= 5e+200) tmp = Float64(Float64(x * z) * 6.0); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * y), $MachinePrecision] * -6.0), $MachinePrecision]}, If[LessEqual[z, -61000000.0], t$95$0, If[LessEqual[z, 0.62], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 5e+200], N[(N[(x * z), $MachinePrecision] * 6.0), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z \cdot y\right) \cdot -6\\
\mathbf{if}\;z \leq -61000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.62:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+200}:\\
\;\;\;\;\left(x \cdot z\right) \cdot 6\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -6.1e7 or 5.00000000000000019e200 < z Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-/.f64N/A
metadata-eval99.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites64.2%
Taylor expanded in z around inf
Applied rewrites63.9%
if -6.1e7 < z < 0.619999999999999996Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites96.8%
if 0.619999999999999996 < z < 5.00000000000000019e200Initial program 99.7%
Taylor expanded in x around inf
Applied rewrites57.1%
Taylor expanded in z around inf
Applied rewrites56.0%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.6) (not (<= z 0.62))) (* (* (- y x) z) -6.0) (fma x -3.0 (* 4.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.6) || !(z <= 0.62)) {
tmp = ((y - x) * z) * -6.0;
} else {
tmp = fma(x, -3.0, (4.0 * y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -0.6) || !(z <= 0.62)) tmp = Float64(Float64(Float64(y - x) * z) * -6.0); else tmp = fma(x, -3.0, Float64(4.0 * y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.6], N[Not[LessEqual[z, 0.62]], $MachinePrecision]], N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] * -6.0), $MachinePrecision], N[(x * -3.0 + N[(4.0 * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.6 \lor \neg \left(z \leq 0.62\right):\\
\;\;\;\;\left(\left(y - x\right) \cdot z\right) \cdot -6\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, -3, 4 \cdot y\right)\\
\end{array}
\end{array}
if z < -0.599999999999999978 or 0.619999999999999996 < z Initial program 99.8%
Taylor expanded in z around inf
Applied rewrites98.6%
if -0.599999999999999978 < z < 0.619999999999999996Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites97.6%
Taylor expanded in x around inf
Applied rewrites89.5%
Applied rewrites89.6%
Taylor expanded in x around 0
Applied rewrites97.6%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (<= z -0.68) (fma (* -6.0 z) (- y x) x) (if (<= z 0.62) (fma x -3.0 (* 4.0 y)) (* (* (- y x) z) -6.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.68) {
tmp = fma((-6.0 * z), (y - x), x);
} else if (z <= 0.62) {
tmp = fma(x, -3.0, (4.0 * y));
} else {
tmp = ((y - x) * z) * -6.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -0.68) tmp = fma(Float64(-6.0 * z), Float64(y - x), x); elseif (z <= 0.62) tmp = fma(x, -3.0, Float64(4.0 * y)); else tmp = Float64(Float64(Float64(y - x) * z) * -6.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -0.68], N[(N[(-6.0 * z), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 0.62], N[(x * -3.0 + N[(4.0 * y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] * -6.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.68:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot z, y - x, x\right)\\
\mathbf{elif}\;z \leq 0.62:\\
\;\;\;\;\mathsf{fma}\left(x, -3, 4 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(y - x\right) \cdot z\right) \cdot -6\\
\end{array}
\end{array}
if z < -0.680000000000000049Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites98.9%
if -0.680000000000000049 < z < 0.619999999999999996Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites97.6%
Taylor expanded in x around inf
Applied rewrites89.5%
Applied rewrites89.6%
Taylor expanded in x around 0
Applied rewrites97.6%
if 0.619999999999999996 < z Initial program 99.8%
Taylor expanded in z around inf
Applied rewrites98.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -250000000000.0) (not (<= y 1.35e-9))) (* (fma -6.0 z 4.0) y) (* (fma 6.0 z -3.0) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -250000000000.0) || !(y <= 1.35e-9)) {
tmp = fma(-6.0, z, 4.0) * y;
} else {
tmp = fma(6.0, z, -3.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -250000000000.0) || !(y <= 1.35e-9)) tmp = Float64(fma(-6.0, z, 4.0) * y); else tmp = Float64(fma(6.0, z, -3.0) * x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -250000000000.0], N[Not[LessEqual[y, 1.35e-9]], $MachinePrecision]], N[(N[(-6.0 * z + 4.0), $MachinePrecision] * y), $MachinePrecision], N[(N[(6.0 * z + -3.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -250000000000 \lor \neg \left(y \leq 1.35 \cdot 10^{-9}\right):\\
\;\;\;\;\mathsf{fma}\left(-6, z, 4\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(6, z, -3\right) \cdot x\\
\end{array}
\end{array}
if y < -2.5e11 or 1.3500000000000001e-9 < y Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites81.1%
if -2.5e11 < y < 1.3500000000000001e-9Initial program 99.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.5
lift-/.f64N/A
metadata-eval99.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.5
Applied rewrites99.5%
Taylor expanded in x around inf
Applied rewrites77.5%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.9e-8) (not (<= z 0.0004))) (* (fma -6.0 z 4.0) y) (fma x -3.0 (* 4.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.9e-8) || !(z <= 0.0004)) {
tmp = fma(-6.0, z, 4.0) * y;
} else {
tmp = fma(x, -3.0, (4.0 * y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -5.9e-8) || !(z <= 0.0004)) tmp = Float64(fma(-6.0, z, 4.0) * y); else tmp = fma(x, -3.0, Float64(4.0 * y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.9e-8], N[Not[LessEqual[z, 0.0004]], $MachinePrecision]], N[(N[(-6.0 * z + 4.0), $MachinePrecision] * y), $MachinePrecision], N[(x * -3.0 + N[(4.0 * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.9 \cdot 10^{-8} \lor \neg \left(z \leq 0.0004\right):\\
\;\;\;\;\mathsf{fma}\left(-6, z, 4\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, -3, 4 \cdot y\right)\\
\end{array}
\end{array}
if z < -5.8999999999999999e-8 or 4.00000000000000019e-4 < z Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites57.9%
if -5.8999999999999999e-8 < z < 4.00000000000000019e-4Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites99.3%
Taylor expanded in x around inf
Applied rewrites91.1%
Applied rewrites91.1%
Taylor expanded in x around 0
Applied rewrites99.4%
Final simplification76.5%
(FPCore (x y z) :precision binary64 (if (<= y -2800.0) (* 4.0 y) (if (<= y 2.6e-19) (* -3.0 x) (fma 4.0 y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2800.0) {
tmp = 4.0 * y;
} else if (y <= 2.6e-19) {
tmp = -3.0 * x;
} else {
tmp = fma(4.0, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -2800.0) tmp = Float64(4.0 * y); elseif (y <= 2.6e-19) tmp = Float64(-3.0 * x); else tmp = fma(4.0, y, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2800.0], N[(4.0 * y), $MachinePrecision], If[LessEqual[y, 2.6e-19], N[(-3.0 * x), $MachinePrecision], N[(4.0 * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2800:\\
\;\;\;\;4 \cdot y\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-19}:\\
\;\;\;\;-3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(4, y, x\right)\\
\end{array}
\end{array}
if y < -2800Initial program 99.7%
Taylor expanded in z around 0
Applied rewrites47.2%
Taylor expanded in x around 0
Applied rewrites31.9%
if -2800 < y < 2.60000000000000013e-19Initial program 99.5%
Taylor expanded in x around inf
Applied rewrites77.9%
Taylor expanded in z around 0
Applied rewrites39.9%
if 2.60000000000000013e-19 < y Initial program 99.6%
Taylor expanded in z around 0
Applied rewrites46.1%
Taylor expanded in x around 0
Applied rewrites39.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -2800.0) (not (<= y 2.6e-19))) (* 4.0 y) (* -3.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2800.0) || !(y <= 2.6e-19)) {
tmp = 4.0 * y;
} else {
tmp = -3.0 * 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-2800.0d0)) .or. (.not. (y <= 2.6d-19))) then
tmp = 4.0d0 * y
else
tmp = (-3.0d0) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2800.0) || !(y <= 2.6e-19)) {
tmp = 4.0 * y;
} else {
tmp = -3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2800.0) or not (y <= 2.6e-19): tmp = 4.0 * y else: tmp = -3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2800.0) || !(y <= 2.6e-19)) tmp = Float64(4.0 * y); else tmp = Float64(-3.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2800.0) || ~((y <= 2.6e-19))) tmp = 4.0 * y; else tmp = -3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2800.0], N[Not[LessEqual[y, 2.6e-19]], $MachinePrecision]], N[(4.0 * y), $MachinePrecision], N[(-3.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2800 \lor \neg \left(y \leq 2.6 \cdot 10^{-19}\right):\\
\;\;\;\;4 \cdot y\\
\mathbf{else}:\\
\;\;\;\;-3 \cdot x\\
\end{array}
\end{array}
if y < -2800 or 2.60000000000000013e-19 < y Initial program 99.6%
Taylor expanded in z around 0
Applied rewrites46.6%
Taylor expanded in x around 0
Applied rewrites35.9%
if -2800 < y < 2.60000000000000013e-19Initial program 99.5%
Taylor expanded in x around inf
Applied rewrites77.9%
Taylor expanded in z around 0
Applied rewrites39.9%
Final simplification37.7%
(FPCore (x y z) :precision binary64 (fma (- 0.6666666666666666 z) (* 6.0 (- y x)) x))
double code(double x, double y, double z) {
return fma((0.6666666666666666 - z), (6.0 * (y - x)), x);
}
function code(x, y, z) return fma(Float64(0.6666666666666666 - z), Float64(6.0 * Float64(y - x)), x) end
code[x_, y_, z_] := N[(N[(0.6666666666666666 - z), $MachinePrecision] * N[(6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.6666666666666666 - z, 6 \cdot \left(y - x\right), x\right)
\end{array}
Initial program 99.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.6
lift-/.f64N/A
metadata-eval99.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
(FPCore (x y z) :precision binary64 (fma (* (- 0.6666666666666666 z) (- y x)) 6.0 x))
double code(double x, double y, double z) {
return fma(((0.6666666666666666 - z) * (y - x)), 6.0, x);
}
function code(x, y, z) return fma(Float64(Float64(0.6666666666666666 - z) * Float64(y - x)), 6.0, x) end
code[x_, y_, z_] := N[(N[(N[(0.6666666666666666 - z), $MachinePrecision] * N[(y - x), $MachinePrecision]), $MachinePrecision] * 6.0 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(0.6666666666666666 - z\right) \cdot \left(y - x\right), 6, x\right)
\end{array}
Initial program 99.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.5
lift-/.f64N/A
metadata-eval99.5
Applied rewrites99.5%
(FPCore (x y z) :precision binary64 (fma (fma -6.0 z 4.0) (- y x) x))
double code(double x, double y, double z) {
return fma(fma(-6.0, z, 4.0), (y - x), x);
}
function code(x, y, z) return fma(fma(-6.0, z, 4.0), Float64(y - x), x) end
code[x_, y_, z_] := N[(N[(-6.0 * z + 4.0), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(-6, z, 4\right), y - x, x\right)
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites99.4%
(FPCore (x y z) :precision binary64 (fma 4.0 (- y x) x))
double code(double x, double y, double z) {
return fma(4.0, (y - x), x);
}
function code(x, y, z) return fma(4.0, Float64(y - x), x) end
code[x_, y_, z_] := N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(4, y - x, x\right)
\end{array}
Initial program 99.6%
Taylor expanded in z around 0
Applied rewrites47.0%
(FPCore (x y z) :precision binary64 (* 4.0 y))
double code(double x, double y, double z) {
return 4.0 * y;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 4.0d0 * y
end function
public static double code(double x, double y, double z) {
return 4.0 * y;
}
def code(x, y, z): return 4.0 * y
function code(x, y, z) return Float64(4.0 * y) end
function tmp = code(x, y, z) tmp = 4.0 * y; end
code[x_, y_, z_] := N[(4.0 * y), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot y
\end{array}
Initial program 99.6%
Taylor expanded in z around 0
Applied rewrites47.0%
Taylor expanded in x around 0
Applied rewrites23.6%
herbie shell --seed 2025019
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, D"
:precision binary64
(+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))