
(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 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 (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.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (/ 2.0 3.0) z)))
(if (or (<= t_0 -2e+24) (not (<= t_0 4e+16)))
(* (* z x) 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 <= -2e+24) || !(t_0 <= 4e+16)) {
tmp = (z * x) * 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 <= -2e+24) || !(t_0 <= 4e+16)) tmp = Float64(Float64(z * x) * 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, -2e+24], N[Not[LessEqual[t$95$0, 4e+16]], $MachinePrecision]], N[(N[(z * x), $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 -2 \cdot 10^{+24} \lor \neg \left(t\_0 \leq 4 \cdot 10^{+16}\right):\\
\;\;\;\;\left(z \cdot x\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) < -2e24 or 4e16 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.7%
Taylor expanded in x around inf
Applied rewrites59.6%
Taylor expanded in z around inf
Applied rewrites59.6%
if -2e24 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 4e16Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites94.7%
Final simplification76.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (fma -6.0 z 4.0) y)))
(if (<= z -5.8e+93)
(* (* z x) 6.0)
(if (<= z -1.9e-7)
t_0
(if (<= z 1.8e-31)
(fma 4.0 (- y x) x)
(if (<= z 9.2e+140) t_0 (* (* 6.0 x) z)))))))
double code(double x, double y, double z) {
double t_0 = fma(-6.0, z, 4.0) * y;
double tmp;
if (z <= -5.8e+93) {
tmp = (z * x) * 6.0;
} else if (z <= -1.9e-7) {
tmp = t_0;
} else if (z <= 1.8e-31) {
tmp = fma(4.0, (y - x), x);
} else if (z <= 9.2e+140) {
tmp = t_0;
} else {
tmp = (6.0 * x) * z;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(fma(-6.0, z, 4.0) * y) tmp = 0.0 if (z <= -5.8e+93) tmp = Float64(Float64(z * x) * 6.0); elseif (z <= -1.9e-7) tmp = t_0; elseif (z <= 1.8e-31) tmp = fma(4.0, Float64(y - x), x); elseif (z <= 9.2e+140) tmp = t_0; else tmp = Float64(Float64(6.0 * x) * z); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-6.0 * z + 4.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[z, -5.8e+93], N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision], If[LessEqual[z, -1.9e-7], t$95$0, If[LessEqual[z, 1.8e-31], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 9.2e+140], t$95$0, N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-6, z, 4\right) \cdot y\\
\mathbf{if}\;z \leq -5.8 \cdot 10^{+93}:\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\mathbf{elif}\;z \leq -1.9 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{-31}:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{elif}\;z \leq 9.2 \cdot 10^{+140}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\end{array}
\end{array}
if z < -5.7999999999999997e93Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites61.5%
Taylor expanded in z around inf
Applied rewrites61.5%
if -5.7999999999999997e93 < z < -1.90000000000000007e-7 or 1.80000000000000002e-31 < z < 9.19999999999999961e140Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites59.0%
if -1.90000000000000007e-7 < z < 1.80000000000000002e-31Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites99.4%
if 9.19999999999999961e140 < z Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites99.8%
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites76.1%
Final simplification80.7%
(FPCore (x y z)
:precision binary64
(if (<= z -5.8e+93)
(* (* z x) 6.0)
(if (<= z -48.0)
(* (* -6.0 z) y)
(if (<= z 0.66)
(fma 4.0 (- y x) x)
(if (<= z 9.2e+140) (* (* -6.0 y) z) (* (* 6.0 x) z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.8e+93) {
tmp = (z * x) * 6.0;
} else if (z <= -48.0) {
tmp = (-6.0 * z) * y;
} else if (z <= 0.66) {
tmp = fma(4.0, (y - x), x);
} else if (z <= 9.2e+140) {
tmp = (-6.0 * y) * z;
} else {
tmp = (6.0 * x) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -5.8e+93) tmp = Float64(Float64(z * x) * 6.0); elseif (z <= -48.0) tmp = Float64(Float64(-6.0 * z) * y); elseif (z <= 0.66) tmp = fma(4.0, Float64(y - x), x); elseif (z <= 9.2e+140) tmp = Float64(Float64(-6.0 * y) * z); else tmp = Float64(Float64(6.0 * x) * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -5.8e+93], N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision], If[LessEqual[z, -48.0], N[(N[(-6.0 * z), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[z, 0.66], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 9.2e+140], N[(N[(-6.0 * y), $MachinePrecision] * z), $MachinePrecision], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{+93}:\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\mathbf{elif}\;z \leq -48:\\
\;\;\;\;\left(-6 \cdot z\right) \cdot y\\
\mathbf{elif}\;z \leq 0.66:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{elif}\;z \leq 9.2 \cdot 10^{+140}:\\
\;\;\;\;\left(-6 \cdot y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\end{array}
\end{array}
if z < -5.7999999999999997e93Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites61.5%
Taylor expanded in z around inf
Applied rewrites61.5%
if -5.7999999999999997e93 < z < -48Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in z around inf
Applied rewrites97.7%
Taylor expanded in x around 0
Applied rewrites64.0%
Applied rewrites64.1%
if -48 < z < 0.660000000000000031Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites96.8%
if 0.660000000000000031 < z < 9.19999999999999961e140Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites99.6%
Taylor expanded in z around inf
Applied rewrites97.7%
Taylor expanded in x around 0
Applied rewrites54.1%
if 9.19999999999999961e140 < z Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites99.8%
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites76.1%
Final simplification80.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* -6.0 y) z)))
(if (<= z -5.8e+93)
(* (* z x) 6.0)
(if (<= z -48.0)
t_0
(if (<= z 0.66)
(fma 4.0 (- y x) x)
(if (<= z 9.2e+140) t_0 (* (* 6.0 x) z)))))))
double code(double x, double y, double z) {
double t_0 = (-6.0 * y) * z;
double tmp;
if (z <= -5.8e+93) {
tmp = (z * x) * 6.0;
} else if (z <= -48.0) {
tmp = t_0;
} else if (z <= 0.66) {
tmp = fma(4.0, (y - x), x);
} else if (z <= 9.2e+140) {
tmp = t_0;
} else {
tmp = (6.0 * x) * z;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(-6.0 * y) * z) tmp = 0.0 if (z <= -5.8e+93) tmp = Float64(Float64(z * x) * 6.0); elseif (z <= -48.0) tmp = t_0; elseif (z <= 0.66) tmp = fma(4.0, Float64(y - x), x); elseif (z <= 9.2e+140) tmp = t_0; else tmp = Float64(Float64(6.0 * x) * z); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-6.0 * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -5.8e+93], N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision], If[LessEqual[z, -48.0], t$95$0, If[LessEqual[z, 0.66], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 9.2e+140], t$95$0, N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-6 \cdot y\right) \cdot z\\
\mathbf{if}\;z \leq -5.8 \cdot 10^{+93}:\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\mathbf{elif}\;z \leq -48:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.66:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{elif}\;z \leq 9.2 \cdot 10^{+140}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\end{array}
\end{array}
if z < -5.7999999999999997e93Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites61.5%
Taylor expanded in z around inf
Applied rewrites61.5%
if -5.7999999999999997e93 < z < -48 or 0.660000000000000031 < z < 9.19999999999999961e140Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites97.7%
Taylor expanded in x around 0
Applied rewrites57.1%
if -48 < z < 0.660000000000000031Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites96.8%
if 9.19999999999999961e140 < z Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites99.8%
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites76.1%
Final simplification80.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* z x) 6.0)) (t_1 (* (* -6.0 y) z)))
(if (<= z -5.8e+93)
t_0
(if (<= z -48.0)
t_1
(if (<= z 0.66) (fma 4.0 (- y x) x) (if (<= z 9.2e+140) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = (z * x) * 6.0;
double t_1 = (-6.0 * y) * z;
double tmp;
if (z <= -5.8e+93) {
tmp = t_0;
} else if (z <= -48.0) {
tmp = t_1;
} else if (z <= 0.66) {
tmp = fma(4.0, (y - x), x);
} else if (z <= 9.2e+140) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z * x) * 6.0) t_1 = Float64(Float64(-6.0 * y) * z) tmp = 0.0 if (z <= -5.8e+93) tmp = t_0; elseif (z <= -48.0) tmp = t_1; elseif (z <= 0.66) tmp = fma(4.0, Float64(y - x), x); elseif (z <= 9.2e+140) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-6.0 * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -5.8e+93], t$95$0, If[LessEqual[z, -48.0], t$95$1, If[LessEqual[z, 0.66], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 9.2e+140], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z \cdot x\right) \cdot 6\\
t_1 := \left(-6 \cdot y\right) \cdot z\\
\mathbf{if}\;z \leq -5.8 \cdot 10^{+93}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -48:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 0.66:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{elif}\;z \leq 9.2 \cdot 10^{+140}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.7999999999999997e93 or 9.19999999999999961e140 < z Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites68.4%
Taylor expanded in z around inf
Applied rewrites68.4%
if -5.7999999999999997e93 < z < -48 or 0.660000000000000031 < z < 9.19999999999999961e140Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites97.7%
Taylor expanded in x around 0
Applied rewrites57.1%
if -48 < z < 0.660000000000000031Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites96.8%
Final simplification80.1%
(FPCore (x y z) :precision binary64 (if (<= z -0.55) (* (- y x) (* -6.0 z)) (if (<= z 0.5) (fma 4.0 (- y x) x) (fma (* -6.0 z) (- y x) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.55) {
tmp = (y - x) * (-6.0 * z);
} else if (z <= 0.5) {
tmp = fma(4.0, (y - x), x);
} else {
tmp = fma((-6.0 * z), (y - x), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -0.55) tmp = Float64(Float64(y - x) * Float64(-6.0 * z)); elseif (z <= 0.5) tmp = fma(4.0, Float64(y - x), x); else tmp = fma(Float64(-6.0 * z), Float64(y - x), x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -0.55], N[(N[(y - x), $MachinePrecision] * N[(-6.0 * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.5], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], N[(N[(-6.0 * z), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.55:\\
\;\;\;\;\left(y - x\right) \cdot \left(-6 \cdot z\right)\\
\mathbf{elif}\;z \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot z, y - x, x\right)\\
\end{array}
\end{array}
if z < -0.55000000000000004Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites99.7%
Taylor expanded in z around inf
Applied rewrites96.7%
Applied rewrites96.7%
if -0.55000000000000004 < z < 0.5Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites98.1%
if 0.5 < z Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites99.7%
Taylor expanded in z around inf
Applied rewrites99.0%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.55) (not (<= z 0.5))) (* (- y x) (* -6.0 z)) (fma 4.0 (- y x) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.55) || !(z <= 0.5)) {
tmp = (y - x) * (-6.0 * z);
} else {
tmp = fma(4.0, (y - x), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -0.55) || !(z <= 0.5)) tmp = Float64(Float64(y - x) * Float64(-6.0 * z)); else tmp = fma(4.0, Float64(y - x), x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.55], N[Not[LessEqual[z, 0.5]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * N[(-6.0 * z), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.55 \lor \neg \left(z \leq 0.5\right):\\
\;\;\;\;\left(y - x\right) \cdot \left(-6 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\end{array}
\end{array}
if z < -0.55000000000000004 or 0.5 < z Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites99.7%
Taylor expanded in z around inf
Applied rewrites97.9%
Applied rewrites97.9%
if -0.55000000000000004 < z < 0.5Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites98.1%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.55) (not (<= z 0.5))) (* (* -6.0 (- y x)) z) (fma 4.0 (- y x) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.55) || !(z <= 0.5)) {
tmp = (-6.0 * (y - x)) * z;
} else {
tmp = fma(4.0, (y - x), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -0.55) || !(z <= 0.5)) tmp = Float64(Float64(-6.0 * Float64(y - x)) * z); else tmp = fma(4.0, Float64(y - x), x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.55], N[Not[LessEqual[z, 0.5]], $MachinePrecision]], N[(N[(-6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.55 \lor \neg \left(z \leq 0.5\right):\\
\;\;\;\;\left(-6 \cdot \left(y - x\right)\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\end{array}
\end{array}
if z < -0.55000000000000004 or 0.5 < z Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites99.7%
Taylor expanded in z around inf
Applied rewrites97.9%
Applied rewrites97.9%
if -0.55000000000000004 < z < 0.5Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites98.1%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.55) (not (<= z 0.5))) (* (* (- y x) z) -6.0) (fma 4.0 (- y x) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.55) || !(z <= 0.5)) {
tmp = ((y - x) * z) * -6.0;
} else {
tmp = fma(4.0, (y - x), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -0.55) || !(z <= 0.5)) tmp = Float64(Float64(Float64(y - x) * z) * -6.0); else tmp = fma(4.0, Float64(y - x), x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.55], N[Not[LessEqual[z, 0.5]], $MachinePrecision]], N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] * -6.0), $MachinePrecision], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.55 \lor \neg \left(z \leq 0.5\right):\\
\;\;\;\;\left(\left(y - x\right) \cdot z\right) \cdot -6\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\end{array}
\end{array}
if z < -0.55000000000000004 or 0.5 < z Initial program 99.7%
Taylor expanded in z around inf
Applied rewrites97.9%
if -0.55000000000000004 < z < 0.5Initial program 99.4%
Taylor expanded in z around 0
Applied rewrites98.1%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.15e+22) (not (<= y 190000000000.0))) (* (fma -6.0 z 4.0) y) (* (fma z 6.0 -3.0) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.15e+22) || !(y <= 190000000000.0)) {
tmp = fma(-6.0, z, 4.0) * y;
} else {
tmp = fma(z, 6.0, -3.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -1.15e+22) || !(y <= 190000000000.0)) tmp = Float64(fma(-6.0, z, 4.0) * y); else tmp = Float64(fma(z, 6.0, -3.0) * x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.15e+22], N[Not[LessEqual[y, 190000000000.0]], $MachinePrecision]], N[(N[(-6.0 * z + 4.0), $MachinePrecision] * y), $MachinePrecision], N[(N[(z * 6.0 + -3.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{+22} \lor \neg \left(y \leq 190000000000\right):\\
\;\;\;\;\mathsf{fma}\left(-6, z, 4\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, 6, -3\right) \cdot x\\
\end{array}
\end{array}
if y < -1.1500000000000001e22 or 1.9e11 < y Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites81.7%
if -1.1500000000000001e22 < y < 1.9e11Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites77.8%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -10500.0) (not (<= x 1.65e-129))) (* -3.0 x) (* 4.0 y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -10500.0) || !(x <= 1.65e-129)) {
tmp = -3.0 * x;
} else {
tmp = 4.0 * y;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-10500.0d0)) .or. (.not. (x <= 1.65d-129))) then
tmp = (-3.0d0) * x
else
tmp = 4.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -10500.0) || !(x <= 1.65e-129)) {
tmp = -3.0 * x;
} else {
tmp = 4.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -10500.0) or not (x <= 1.65e-129): tmp = -3.0 * x else: tmp = 4.0 * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -10500.0) || !(x <= 1.65e-129)) tmp = Float64(-3.0 * x); else tmp = Float64(4.0 * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -10500.0) || ~((x <= 1.65e-129))) tmp = -3.0 * x; else tmp = 4.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -10500.0], N[Not[LessEqual[x, 1.65e-129]], $MachinePrecision]], N[(-3.0 * x), $MachinePrecision], N[(4.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -10500 \lor \neg \left(x \leq 1.65 \cdot 10^{-129}\right):\\
\;\;\;\;-3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;4 \cdot y\\
\end{array}
\end{array}
if x < -10500 or 1.64999999999999994e-129 < x Initial program 99.6%
Taylor expanded in x around inf
Applied rewrites75.8%
Taylor expanded in z around 0
Applied rewrites33.6%
if -10500 < x < 1.64999999999999994e-129Initial program 99.5%
Taylor expanded in z around 0
Applied rewrites54.9%
Taylor expanded in x around 0
Applied rewrites44.8%
Final simplification37.9%
(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 rewrites48.1%
Final simplification48.1%
(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 rewrites48.1%
Taylor expanded in x around 0
Applied rewrites24.6%
Final simplification24.6%
herbie shell --seed 2025018
(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))))