
(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}
Herbie found 14 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 (fma (- y x) (* (- (/ 2.0 3.0) z) 6.0) x))
double code(double x, double y, double z) {
return fma((y - x), (((2.0 / 3.0) - z) * 6.0), x);
}
function code(x, y, z) return fma(Float64(y - x), Float64(Float64(Float64(2.0 / 3.0) - z) * 6.0), x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * N[(N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision] * 6.0), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, \left(\frac{2}{3} - z\right) \cdot 6, x\right)
\end{array}
Initial program 99.5%
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (fma (* (- (/ 2.0 3.0) z) (- y x)) 6.0 x))
double code(double x, double y, double z) {
return fma((((2.0 / 3.0) - z) * (y - x)), 6.0, x);
}
function code(x, y, z) return fma(Float64(Float64(Float64(2.0 / 3.0) - z) * Float64(y - x)), 6.0, x) end
code[x_, y_, z_] := N[(N[(N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision] * N[(y - x), $MachinePrecision]), $MachinePrecision] * 6.0 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\frac{2}{3} - z\right) \cdot \left(y - x\right), 6, x\right)
\end{array}
Initial program 99.5%
Applied rewrites99.5%
(FPCore (x y z) :precision binary64 (if (<= z -0.62) (* (- x y) (* z 6.0)) (if (<= z 0.55) (fma (- y x) 4.0 x) (* (* (- x y) 6.0) z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.62) {
tmp = (x - y) * (z * 6.0);
} else if (z <= 0.55) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = ((x - y) * 6.0) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -0.62) tmp = Float64(Float64(x - y) * Float64(z * 6.0)); elseif (z <= 0.55) tmp = fma(Float64(y - x), 4.0, x); else tmp = Float64(Float64(Float64(x - y) * 6.0) * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -0.62], N[(N[(x - y), $MachinePrecision] * N[(z * 6.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.55], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], N[(N[(N[(x - y), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.62:\\
\;\;\;\;\left(x - y\right) \cdot \left(z \cdot 6\right)\\
\mathbf{elif}\;z \leq 0.55:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(x - y\right) \cdot 6\right) \cdot z\\
\end{array}
\end{array}
if z < -0.619999999999999996Initial program 99.5%
Applied rewrites99.5%
Applied rewrites99.6%
Taylor expanded in z around inf
Applied rewrites51.0%
Applied rewrites51.0%
if -0.619999999999999996 < z < 0.55000000000000004Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
if 0.55000000000000004 < z Initial program 99.5%
Applied rewrites99.5%
Applied rewrites99.6%
Taylor expanded in z around inf
Applied rewrites51.0%
Applied rewrites51.0%
(FPCore (x y z) :precision binary64 (if (<= z -0.62) (* (- x y) (* z 6.0)) (if (<= z 0.55) (fma (- y x) 4.0 x) (+ x (* (* (- y x) 6.0) (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.62) {
tmp = (x - y) * (z * 6.0);
} else if (z <= 0.55) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = x + (((y - x) * 6.0) * -z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -0.62) tmp = Float64(Float64(x - y) * Float64(z * 6.0)); elseif (z <= 0.55) tmp = fma(Float64(y - x), 4.0, x); else tmp = Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(-z))); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -0.62], N[(N[(x - y), $MachinePrecision] * N[(z * 6.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.55], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.62:\\
\;\;\;\;\left(x - y\right) \cdot \left(z \cdot 6\right)\\
\mathbf{elif}\;z \leq 0.55:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < -0.619999999999999996Initial program 99.5%
Applied rewrites99.5%
Applied rewrites99.6%
Taylor expanded in z around inf
Applied rewrites51.0%
Applied rewrites51.0%
if -0.619999999999999996 < z < 0.55000000000000004Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
if 0.55000000000000004 < z Initial program 99.5%
Taylor expanded in z around inf
Applied rewrites50.5%
Applied rewrites50.5%
(FPCore (x y z) :precision binary64 (if (<= z -0.62) (* -6.0 (* z (- y x))) (if (<= z 0.55) (fma (- y x) 4.0 x) (* (* (- x y) 6.0) z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.62) {
tmp = -6.0 * (z * (y - x));
} else if (z <= 0.55) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = ((x - y) * 6.0) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -0.62) tmp = Float64(-6.0 * Float64(z * Float64(y - x))); elseif (z <= 0.55) tmp = fma(Float64(y - x), 4.0, x); else tmp = Float64(Float64(Float64(x - y) * 6.0) * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -0.62], N[(-6.0 * N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.55], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], N[(N[(N[(x - y), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.62:\\
\;\;\;\;-6 \cdot \left(z \cdot \left(y - x\right)\right)\\
\mathbf{elif}\;z \leq 0.55:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(x - y\right) \cdot 6\right) \cdot z\\
\end{array}
\end{array}
if z < -0.619999999999999996Initial program 99.5%
Taylor expanded in z around inf
Applied rewrites51.0%
if -0.619999999999999996 < z < 0.55000000000000004Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
if 0.55000000000000004 < z Initial program 99.5%
Applied rewrites99.5%
Applied rewrites99.6%
Taylor expanded in z around inf
Applied rewrites51.0%
Applied rewrites51.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* -6.0 (* z (- y x))))) (if (<= z -0.62) t_0 (if (<= z 0.55) (fma (- y x) 4.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = -6.0 * (z * (y - x));
double tmp;
if (z <= -0.62) {
tmp = t_0;
} else if (z <= 0.55) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(-6.0 * Float64(z * Float64(y - x))) tmp = 0.0 if (z <= -0.62) tmp = t_0; elseif (z <= 0.55) tmp = fma(Float64(y - x), 4.0, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(-6.0 * N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -0.62], t$95$0, If[LessEqual[z, 0.55], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -6 \cdot \left(z \cdot \left(y - x\right)\right)\\
\mathbf{if}\;z \leq -0.62:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.55:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -0.619999999999999996 or 0.55000000000000004 < z Initial program 99.5%
Taylor expanded in z around inf
Applied rewrites51.0%
if -0.619999999999999996 < z < 0.55000000000000004Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fma y (* -6.0 z) x)))
(if (<= z -1.75e+254)
t_0
(if (<= z -21.0)
(fma (* x z) 6.0 x)
(if (<= z 0.55) (fma (- y x) 4.0 x) t_0)))))
double code(double x, double y, double z) {
double t_0 = fma(y, (-6.0 * z), x);
double tmp;
if (z <= -1.75e+254) {
tmp = t_0;
} else if (z <= -21.0) {
tmp = fma((x * z), 6.0, x);
} else if (z <= 0.55) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(y, Float64(-6.0 * z), x) tmp = 0.0 if (z <= -1.75e+254) tmp = t_0; elseif (z <= -21.0) tmp = fma(Float64(x * z), 6.0, x); elseif (z <= 0.55) tmp = fma(Float64(y - x), 4.0, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(-6.0 * z), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[z, -1.75e+254], t$95$0, If[LessEqual[z, -21.0], N[(N[(x * z), $MachinePrecision] * 6.0 + x), $MachinePrecision], If[LessEqual[z, 0.55], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, -6 \cdot z, x\right)\\
\mathbf{if}\;z \leq -1.75 \cdot 10^{+254}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -21:\\
\;\;\;\;\mathsf{fma}\left(x \cdot z, 6, x\right)\\
\mathbf{elif}\;z \leq 0.55:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.75000000000000008e254 or 0.55000000000000004 < z Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
Taylor expanded in x around 0
Applied rewrites25.9%
Taylor expanded in z around inf
Applied rewrites27.1%
if -1.75000000000000008e254 < z < -21Initial program 99.5%
Applied rewrites99.5%
Taylor expanded in z around inf
Applied rewrites50.4%
Taylor expanded in x around inf
Applied rewrites27.2%
if -21 < z < 0.55000000000000004Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* -6.0 (* y z))))
(if (<= z -1.75e+254)
t_0
(if (<= z -21.0)
(fma (* x z) 6.0 x)
(if (<= z 0.66) (fma (- y x) 4.0 x) t_0)))))
double code(double x, double y, double z) {
double t_0 = -6.0 * (y * z);
double tmp;
if (z <= -1.75e+254) {
tmp = t_0;
} else if (z <= -21.0) {
tmp = fma((x * z), 6.0, x);
} else if (z <= 0.66) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(-6.0 * Float64(y * z)) tmp = 0.0 if (z <= -1.75e+254) tmp = t_0; elseif (z <= -21.0) tmp = fma(Float64(x * z), 6.0, x); elseif (z <= 0.66) tmp = fma(Float64(y - x), 4.0, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(-6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.75e+254], t$95$0, If[LessEqual[z, -21.0], N[(N[(x * z), $MachinePrecision] * 6.0 + x), $MachinePrecision], If[LessEqual[z, 0.66], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -6 \cdot \left(y \cdot z\right)\\
\mathbf{if}\;z \leq -1.75 \cdot 10^{+254}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -21:\\
\;\;\;\;\mathsf{fma}\left(x \cdot z, 6, x\right)\\
\mathbf{elif}\;z \leq 0.66:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.75000000000000008e254 or 0.660000000000000031 < z Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites51.2%
Taylor expanded in z around inf
Applied rewrites27.3%
if -1.75000000000000008e254 < z < -21Initial program 99.5%
Applied rewrites99.5%
Taylor expanded in z around inf
Applied rewrites50.4%
Taylor expanded in x around inf
Applied rewrites27.2%
if -21 < z < 0.660000000000000031Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* -6.0 (* y z))))
(if (<= z -1.75e+254)
t_0
(if (<= z -11.0)
(* 6.0 (* x z))
(if (<= z 0.66) (fma (- y x) 4.0 x) t_0)))))
double code(double x, double y, double z) {
double t_0 = -6.0 * (y * z);
double tmp;
if (z <= -1.75e+254) {
tmp = t_0;
} else if (z <= -11.0) {
tmp = 6.0 * (x * z);
} else if (z <= 0.66) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(-6.0 * Float64(y * z)) tmp = 0.0 if (z <= -1.75e+254) tmp = t_0; elseif (z <= -11.0) tmp = Float64(6.0 * Float64(x * z)); elseif (z <= 0.66) tmp = fma(Float64(y - x), 4.0, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(-6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.75e+254], t$95$0, If[LessEqual[z, -11.0], N[(6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.66], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -6 \cdot \left(y \cdot z\right)\\
\mathbf{if}\;z \leq -1.75 \cdot 10^{+254}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -11:\\
\;\;\;\;6 \cdot \left(x \cdot z\right)\\
\mathbf{elif}\;z \leq 0.66:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.75000000000000008e254 or 0.660000000000000031 < z Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites51.2%
Taylor expanded in z around inf
Applied rewrites27.3%
if -1.75000000000000008e254 < z < -11Initial program 99.5%
Applied rewrites99.5%
Applied rewrites99.6%
Taylor expanded in z around inf
Applied rewrites51.0%
Taylor expanded in x around inf
Applied rewrites27.7%
if -11 < z < 0.660000000000000031Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (/ 2.0 3.0) z)) (t_1 (* -6.0 (* y z))))
(if (<= t_0 -20000.0)
t_1
(if (<= t_0 0.667)
(* 6.0 (* 0.6666666666666666 y))
(if (<= t_0 4e+247) (* 6.0 (* x z)) t_1)))))
double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = -6.0 * (y * z);
double tmp;
if (t_0 <= -20000.0) {
tmp = t_1;
} else if (t_0 <= 0.667) {
tmp = 6.0 * (0.6666666666666666 * y);
} else if (t_0 <= 4e+247) {
tmp = 6.0 * (x * z);
} 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (2.0d0 / 3.0d0) - z
t_1 = (-6.0d0) * (y * z)
if (t_0 <= (-20000.0d0)) then
tmp = t_1
else if (t_0 <= 0.667d0) then
tmp = 6.0d0 * (0.6666666666666666d0 * y)
else if (t_0 <= 4d+247) then
tmp = 6.0d0 * (x * z)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = -6.0 * (y * z);
double tmp;
if (t_0 <= -20000.0) {
tmp = t_1;
} else if (t_0 <= 0.667) {
tmp = 6.0 * (0.6666666666666666 * y);
} else if (t_0 <= 4e+247) {
tmp = 6.0 * (x * z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = (2.0 / 3.0) - z t_1 = -6.0 * (y * z) tmp = 0 if t_0 <= -20000.0: tmp = t_1 elif t_0 <= 0.667: tmp = 6.0 * (0.6666666666666666 * y) elif t_0 <= 4e+247: tmp = 6.0 * (x * z) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(Float64(2.0 / 3.0) - z) t_1 = Float64(-6.0 * Float64(y * z)) tmp = 0.0 if (t_0 <= -20000.0) tmp = t_1; elseif (t_0 <= 0.667) tmp = Float64(6.0 * Float64(0.6666666666666666 * y)); elseif (t_0 <= 4e+247) tmp = Float64(6.0 * Float64(x * z)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (2.0 / 3.0) - z; t_1 = -6.0 * (y * z); tmp = 0.0; if (t_0 <= -20000.0) tmp = t_1; elseif (t_0 <= 0.667) tmp = 6.0 * (0.6666666666666666 * y); elseif (t_0 <= 4e+247) tmp = 6.0 * (x * z); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$1 = N[(-6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -20000.0], t$95$1, If[LessEqual[t$95$0, 0.667], N[(6.0 * N[(0.6666666666666666 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e+247], N[(6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
t_1 := -6 \cdot \left(y \cdot z\right)\\
\mathbf{if}\;t\_0 \leq -20000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.667:\\
\;\;\;\;6 \cdot \left(0.6666666666666666 \cdot y\right)\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+247}:\\
\;\;\;\;6 \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < -2e4 or 3.99999999999999981e247 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites51.2%
Taylor expanded in z around inf
Applied rewrites27.3%
if -2e4 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 0.66700000000000004Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites51.2%
Taylor expanded in z around 0
Applied rewrites26.0%
if 0.66700000000000004 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 3.99999999999999981e247Initial program 99.5%
Applied rewrites99.5%
Applied rewrites99.6%
Taylor expanded in z around inf
Applied rewrites51.0%
Taylor expanded in x around inf
Applied rewrites27.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (/ 2.0 3.0) z)) (t_1 (* -6.0 (* y z))))
(if (<= t_0 -20000.0)
t_1
(if (<= t_0 40.0) (* 6.0 (* 0.6666666666666666 y)) t_1))))
double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = -6.0 * (y * z);
double tmp;
if (t_0 <= -20000.0) {
tmp = t_1;
} else if (t_0 <= 40.0) {
tmp = 6.0 * (0.6666666666666666 * y);
} 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (2.0d0 / 3.0d0) - z
t_1 = (-6.0d0) * (y * z)
if (t_0 <= (-20000.0d0)) then
tmp = t_1
else if (t_0 <= 40.0d0) then
tmp = 6.0d0 * (0.6666666666666666d0 * y)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = -6.0 * (y * z);
double tmp;
if (t_0 <= -20000.0) {
tmp = t_1;
} else if (t_0 <= 40.0) {
tmp = 6.0 * (0.6666666666666666 * y);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = (2.0 / 3.0) - z t_1 = -6.0 * (y * z) tmp = 0 if t_0 <= -20000.0: tmp = t_1 elif t_0 <= 40.0: tmp = 6.0 * (0.6666666666666666 * y) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(Float64(2.0 / 3.0) - z) t_1 = Float64(-6.0 * Float64(y * z)) tmp = 0.0 if (t_0 <= -20000.0) tmp = t_1; elseif (t_0 <= 40.0) tmp = Float64(6.0 * Float64(0.6666666666666666 * y)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (2.0 / 3.0) - z; t_1 = -6.0 * (y * z); tmp = 0.0; if (t_0 <= -20000.0) tmp = t_1; elseif (t_0 <= 40.0) tmp = 6.0 * (0.6666666666666666 * y); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$1 = N[(-6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -20000.0], t$95$1, If[LessEqual[t$95$0, 40.0], N[(6.0 * N[(0.6666666666666666 * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
t_1 := -6 \cdot \left(y \cdot z\right)\\
\mathbf{if}\;t\_0 \leq -20000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 40:\\
\;\;\;\;6 \cdot \left(0.6666666666666666 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < -2e4 or 40 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites51.2%
Taylor expanded in z around inf
Applied rewrites27.3%
if -2e4 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 40Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites51.2%
Taylor expanded in z around 0
Applied rewrites26.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (/ 2.0 3.0) z)) (t_1 (* -6.0 (* y z)))) (if (<= t_0 -20000.0) t_1 (if (<= t_0 0.667) (fma y 4.0 x) t_1))))
double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = -6.0 * (y * z);
double tmp;
if (t_0 <= -20000.0) {
tmp = t_1;
} else if (t_0 <= 0.667) {
tmp = fma(y, 4.0, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(2.0 / 3.0) - z) t_1 = Float64(-6.0 * Float64(y * z)) tmp = 0.0 if (t_0 <= -20000.0) tmp = t_1; elseif (t_0 <= 0.667) tmp = fma(y, 4.0, x); else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$1 = N[(-6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -20000.0], t$95$1, If[LessEqual[t$95$0, 0.667], N[(y * 4.0 + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
t_1 := -6 \cdot \left(y \cdot z\right)\\
\mathbf{if}\;t\_0 \leq -20000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.667:\\
\;\;\;\;\mathsf{fma}\left(y, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < -2e4 or 0.66700000000000004 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites51.2%
Taylor expanded in z around inf
Applied rewrites27.3%
if -2e4 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 0.66700000000000004Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
Taylor expanded in x around 0
Applied rewrites25.9%
(FPCore (x y z) :precision binary64 (if (<= y -6.8e-62) (fma y 4.0 x) (if (<= y 4.9e+87) (+ x (* -4.0 x)) (fma y 4.0 x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e-62) {
tmp = fma(y, 4.0, x);
} else if (y <= 4.9e+87) {
tmp = x + (-4.0 * x);
} else {
tmp = fma(y, 4.0, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -6.8e-62) tmp = fma(y, 4.0, x); elseif (y <= 4.9e+87) tmp = Float64(x + Float64(-4.0 * x)); else tmp = fma(y, 4.0, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -6.8e-62], N[(y * 4.0 + x), $MachinePrecision], If[LessEqual[y, 4.9e+87], N[(x + N[(-4.0 * x), $MachinePrecision]), $MachinePrecision], N[(y * 4.0 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-62}:\\
\;\;\;\;\mathsf{fma}\left(y, 4, x\right)\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{+87}:\\
\;\;\;\;x + -4 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 4, x\right)\\
\end{array}
\end{array}
if y < -6.79999999999999975e-62 or 4.89999999999999971e87 < y Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
Taylor expanded in x around 0
Applied rewrites25.9%
if -6.79999999999999975e-62 < y < 4.89999999999999971e87Initial program 99.5%
Taylor expanded in z around 0
Applied rewrites50.4%
Taylor expanded in x around inf
Applied rewrites26.1%
(FPCore (x y z) :precision binary64 (fma y 4.0 x))
double code(double x, double y, double z) {
return fma(y, 4.0, x);
}
function code(x, y, z) return fma(y, 4.0, x) end
code[x_, y_, z_] := N[(y * 4.0 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, 4, x\right)
\end{array}
Initial program 99.5%
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites50.4%
Taylor expanded in x around 0
Applied rewrites25.9%
herbie shell --seed 2025153
(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))))