
(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 11 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) (fma -6.0 z 4.0) x))
double code(double x, double y, double z) {
return fma((y - x), fma(-6.0, z, 4.0), x);
}
function code(x, y, z) return fma(Float64(y - x), fma(-6.0, z, 4.0), x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * N[(-6.0 * z + 4.0), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, \mathsf{fma}\left(-6, z, 4\right), x\right)
\end{array}
Initial program 99.5%
Taylor expanded in z around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lift--.f64N/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (/ 2.0 3.0) z)) (t_1 (* (fma -6.0 z 4.0) y)))
(if (<= t_0 -1.0)
t_1
(if (<= t_0 0.66667)
(fma -3.0 x (* 4.0 y))
(if (<= t_0 2e+90) t_1 (* (* z x) 6.0))))))
double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = fma(-6.0, z, 4.0) * y;
double tmp;
if (t_0 <= -1.0) {
tmp = t_1;
} else if (t_0 <= 0.66667) {
tmp = fma(-3.0, x, (4.0 * y));
} else if (t_0 <= 2e+90) {
tmp = t_1;
} else {
tmp = (z * x) * 6.0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(2.0 / 3.0) - z) t_1 = Float64(fma(-6.0, z, 4.0) * y) tmp = 0.0 if (t_0 <= -1.0) tmp = t_1; elseif (t_0 <= 0.66667) tmp = fma(-3.0, x, Float64(4.0 * y)); elseif (t_0 <= 2e+90) tmp = t_1; else tmp = Float64(Float64(z * x) * 6.0); 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[(N[(-6.0 * z + 4.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -1.0], t$95$1, If[LessEqual[t$95$0, 0.66667], N[(-3.0 * x + N[(4.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+90], t$95$1, N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
t_1 := \mathsf{fma}\left(-6, z, 4\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -1:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.66667:\\
\;\;\;\;\mathsf{fma}\left(-3, x, 4 \cdot y\right)\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+90}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < -1 or 0.666669999999999985 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 1.99999999999999993e90Initial program 99.7%
Taylor expanded in z around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lift--.f64N/A
lower-fma.f6499.7
Applied rewrites99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lift-fma.f6465.9
Applied rewrites65.9%
if -1 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 0.666669999999999985Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6499.0
Applied rewrites99.0%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6499.1
Applied rewrites99.1%
if 1.99999999999999993e90 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6464.4
Applied rewrites64.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (/ 2.0 3.0) z)))
(if (or (<= t_0 -1.0) (not (<= t_0 1.0)))
(* (* -6.0 (- y x)) z)
(fma -3.0 x (* 4.0 y)))))
double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double tmp;
if ((t_0 <= -1.0) || !(t_0 <= 1.0)) {
tmp = (-6.0 * (y - x)) * z;
} else {
tmp = fma(-3.0, x, (4.0 * y));
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(2.0 / 3.0) - z) tmp = 0.0 if ((t_0 <= -1.0) || !(t_0 <= 1.0)) tmp = Float64(Float64(-6.0 * Float64(y - x)) * z); else tmp = fma(-3.0, x, Float64(4.0 * y)); 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, -1.0], N[Not[LessEqual[t$95$0, 1.0]], $MachinePrecision]], N[(N[(-6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], N[(-3.0 * x + N[(4.0 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
\mathbf{if}\;t\_0 \leq -1 \lor \neg \left(t\_0 \leq 1\right):\\
\;\;\;\;\left(-6 \cdot \left(y - x\right)\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-3, x, 4 \cdot y\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < -1 or 1 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6497.8
Applied rewrites97.8%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lower-*.f6497.8
Applied rewrites97.8%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lift--.f6497.7
Applied rewrites97.7%
if -1 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 1Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6497.6
Applied rewrites97.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6497.8
Applied rewrites97.8%
Final simplification97.7%
(FPCore (x y z)
:precision binary64
(if (<= z -3.25e+90)
(* (* z x) 6.0)
(if (or (<= z -12.0) (not (<= z 0.66)))
(* (* y z) -6.0)
(fma -3.0 x (* 4.0 y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.25e+90) {
tmp = (z * x) * 6.0;
} else if ((z <= -12.0) || !(z <= 0.66)) {
tmp = (y * z) * -6.0;
} else {
tmp = fma(-3.0, x, (4.0 * y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -3.25e+90) tmp = Float64(Float64(z * x) * 6.0); elseif ((z <= -12.0) || !(z <= 0.66)) tmp = Float64(Float64(y * z) * -6.0); else tmp = fma(-3.0, x, Float64(4.0 * y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -3.25e+90], N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision], If[Or[LessEqual[z, -12.0], N[Not[LessEqual[z, 0.66]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * -6.0), $MachinePrecision], N[(-3.0 * x + N[(4.0 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.25 \cdot 10^{+90}:\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\mathbf{elif}\;z \leq -12 \lor \neg \left(z \leq 0.66\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot -6\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-3, x, 4 \cdot y\right)\\
\end{array}
\end{array}
if z < -3.25e90Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6464.4
Applied rewrites64.4%
if -3.25e90 < z < -12 or 0.660000000000000031 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6496.6
Applied rewrites96.6%
Taylor expanded in x around 0
Applied rewrites63.4%
if -12 < z < 0.660000000000000031Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6497.6
Applied rewrites97.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6497.8
Applied rewrites97.8%
Final simplification82.5%
(FPCore (x y z)
:precision binary64
(if (<= z -3.25e+90)
(* (* z x) 6.0)
(if (or (<= z -12.0) (not (<= z 0.66)))
(* (* y z) -6.0)
(fma 4.0 (- y x) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.25e+90) {
tmp = (z * x) * 6.0;
} else if ((z <= -12.0) || !(z <= 0.66)) {
tmp = (y * z) * -6.0;
} else {
tmp = fma(4.0, (y - x), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -3.25e+90) tmp = Float64(Float64(z * x) * 6.0); elseif ((z <= -12.0) || !(z <= 0.66)) tmp = Float64(Float64(y * z) * -6.0); else tmp = fma(4.0, Float64(y - x), x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -3.25e+90], N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision], If[Or[LessEqual[z, -12.0], N[Not[LessEqual[z, 0.66]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * -6.0), $MachinePrecision], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.25 \cdot 10^{+90}:\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\mathbf{elif}\;z \leq -12 \lor \neg \left(z \leq 0.66\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot -6\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\end{array}
\end{array}
if z < -3.25e90Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6464.4
Applied rewrites64.4%
if -3.25e90 < z < -12 or 0.660000000000000031 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6496.6
Applied rewrites96.6%
Taylor expanded in x around 0
Applied rewrites63.4%
if -12 < z < 0.660000000000000031Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6497.6
Applied rewrites97.6%
Final simplification82.4%
(FPCore (x y z)
:precision binary64
(if (<= z -3.25e+90)
(* (* z x) 6.0)
(if (or (<= z -12.0) (not (<= z 0.66)))
(* y (* -6.0 z))
(fma 4.0 (- y x) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.25e+90) {
tmp = (z * x) * 6.0;
} else if ((z <= -12.0) || !(z <= 0.66)) {
tmp = y * (-6.0 * z);
} else {
tmp = fma(4.0, (y - x), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -3.25e+90) tmp = Float64(Float64(z * x) * 6.0); elseif ((z <= -12.0) || !(z <= 0.66)) tmp = Float64(y * Float64(-6.0 * z)); else tmp = fma(4.0, Float64(y - x), x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -3.25e+90], N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision], If[Or[LessEqual[z, -12.0], N[Not[LessEqual[z, 0.66]], $MachinePrecision]], N[(y * 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 -3.25 \cdot 10^{+90}:\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\mathbf{elif}\;z \leq -12 \lor \neg \left(z \leq 0.66\right):\\
\;\;\;\;y \cdot \left(-6 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\end{array}
\end{array}
if z < -3.25e90Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6464.4
Applied rewrites64.4%
if -3.25e90 < z < -12 or 0.660000000000000031 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6496.6
Applied rewrites96.6%
Taylor expanded in x around 0
Applied rewrites63.4%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6463.2
Applied rewrites63.2%
if -12 < z < 0.660000000000000031Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6497.6
Applied rewrites97.6%
Final simplification82.4%
(FPCore (x y z) :precision binary64 (if (<= z -0.58) (* (* (- y x) z) -6.0) (if (<= z 0.52) (fma -3.0 x (* 4.0 y)) (* (* -6.0 (- y x)) z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.58) {
tmp = ((y - x) * z) * -6.0;
} else if (z <= 0.52) {
tmp = fma(-3.0, x, (4.0 * y));
} else {
tmp = (-6.0 * (y - x)) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -0.58) tmp = Float64(Float64(Float64(y - x) * z) * -6.0); elseif (z <= 0.52) tmp = fma(-3.0, x, Float64(4.0 * y)); else tmp = Float64(Float64(-6.0 * Float64(y - x)) * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -0.58], N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] * -6.0), $MachinePrecision], If[LessEqual[z, 0.52], N[(-3.0 * x + N[(4.0 * y), $MachinePrecision]), $MachinePrecision], N[(N[(-6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.58:\\
\;\;\;\;\left(\left(y - x\right) \cdot z\right) \cdot -6\\
\mathbf{elif}\;z \leq 0.52:\\
\;\;\;\;\mathsf{fma}\left(-3, x, 4 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-6 \cdot \left(y - x\right)\right) \cdot z\\
\end{array}
\end{array}
if z < -0.57999999999999996Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6497.9
Applied rewrites97.9%
if -0.57999999999999996 < z < 0.52000000000000002Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6497.6
Applied rewrites97.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6497.8
Applied rewrites97.8%
if 0.52000000000000002 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6497.8
Applied rewrites97.8%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lower-*.f6497.7
Applied rewrites97.7%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lift--.f6497.8
Applied rewrites97.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.5e+26) (not (<= z 0.52))) (* (* z x) 6.0) (fma 4.0 (- y x) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.5e+26) || !(z <= 0.52)) {
tmp = (z * x) * 6.0;
} else {
tmp = fma(4.0, (y - x), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -1.5e+26) || !(z <= 0.52)) tmp = Float64(Float64(z * x) * 6.0); else tmp = fma(4.0, Float64(y - x), x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.5e+26], N[Not[LessEqual[z, 0.52]], $MachinePrecision]], N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+26} \lor \neg \left(z \leq 0.52\right):\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\end{array}
\end{array}
if z < -1.49999999999999999e26 or 0.52000000000000002 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6498.8
Applied rewrites98.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6448.3
Applied rewrites48.3%
if -1.49999999999999999e26 < z < 0.52000000000000002Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6495.9
Applied rewrites95.9%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.32e+50) (not (<= x 84000.0))) (* -3.0 x) (* 4.0 y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.32e+50) || !(x <= 84000.0)) {
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 <= (-1.32d+50)) .or. (.not. (x <= 84000.0d0))) 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 <= -1.32e+50) || !(x <= 84000.0)) {
tmp = -3.0 * x;
} else {
tmp = 4.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.32e+50) or not (x <= 84000.0): tmp = -3.0 * x else: tmp = 4.0 * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.32e+50) || !(x <= 84000.0)) 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 <= -1.32e+50) || ~((x <= 84000.0))) tmp = -3.0 * x; else tmp = 4.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.32e+50], N[Not[LessEqual[x, 84000.0]], $MachinePrecision]], N[(-3.0 * x), $MachinePrecision], N[(4.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.32 \cdot 10^{+50} \lor \neg \left(x \leq 84000\right):\\
\;\;\;\;-3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;4 \cdot y\\
\end{array}
\end{array}
if x < -1.3199999999999999e50 or 84000 < x Initial program 99.5%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6459.2
Applied rewrites59.2%
Taylor expanded in x around inf
lower-*.f6452.0
Applied rewrites52.0%
if -1.3199999999999999e50 < x < 84000Initial program 99.6%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6452.8
Applied rewrites52.8%
Taylor expanded in x around 0
lower-*.f6442.7
Applied rewrites42.7%
Final simplification46.5%
(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.5%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6455.4
Applied rewrites55.4%
(FPCore (x y z) :precision binary64 (* -3.0 x))
double code(double x, double y, double z) {
return -3.0 * x;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (-3.0d0) * x
end function
public static double code(double x, double y, double z) {
return -3.0 * x;
}
def code(x, y, z): return -3.0 * x
function code(x, y, z) return Float64(-3.0 * x) end
function tmp = code(x, y, z) tmp = -3.0 * x; end
code[x_, y_, z_] := N[(-3.0 * x), $MachinePrecision]
\begin{array}{l}
\\
-3 \cdot x
\end{array}
Initial program 99.5%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6455.4
Applied rewrites55.4%
Taylor expanded in x around inf
lower-*.f6429.0
Applied rewrites29.0%
herbie shell --seed 2025051
(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))))