
(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 (- 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.7
Applied rewrites99.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.58) (not (<= z 0.5))) (* (* -6.0 (- y x)) z) (fma -3.0 x (* 4.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.58) || !(z <= 0.5)) {
tmp = (-6.0 * (y - x)) * z;
} else {
tmp = fma(-3.0, x, (4.0 * y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -0.58) || !(z <= 0.5)) 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_] := If[Or[LessEqual[z, -0.58], N[Not[LessEqual[z, 0.5]], $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}
\mathbf{if}\;z \leq -0.58 \lor \neg \left(z \leq 0.5\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 z < -0.57999999999999996 or 0.5 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6498.5
Applied rewrites98.5%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lower-*.f6498.4
Applied rewrites98.4%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lift--.f6498.5
Applied rewrites98.5%
if -0.57999999999999996 < z < 0.5Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6498.3
Applied rewrites98.3%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6498.4
Applied rewrites98.4%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (<= z -0.58) (* (* -6.0 (- y x)) z) (if (<= z 0.5) (fma -3.0 x (* 4.0 y)) (* (* (- y x) z) -6.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.58) {
tmp = (-6.0 * (y - x)) * z;
} else if (z <= 0.5) {
tmp = fma(-3.0, x, (4.0 * y));
} else {
tmp = ((y - x) * z) * -6.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -0.58) tmp = Float64(Float64(-6.0 * Float64(y - x)) * z); elseif (z <= 0.5) tmp = fma(-3.0, x, 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.58], N[(N[(-6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 0.5], N[(-3.0 * x + 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.58:\\
\;\;\;\;\left(-6 \cdot \left(y - x\right)\right) \cdot z\\
\mathbf{elif}\;z \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(-3, x, 4 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(y - x\right) \cdot z\right) \cdot -6\\
\end{array}
\end{array}
if z < -0.57999999999999996Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6498.3
Applied rewrites98.3%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lower-*.f6498.3
Applied rewrites98.3%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lift--.f6498.5
Applied rewrites98.5%
if -0.57999999999999996 < z < 0.5Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6498.3
Applied rewrites98.3%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6498.4
Applied rewrites98.4%
if 0.5 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6498.6
Applied rewrites98.6%
(FPCore (x y z)
:precision binary64
(if (<= y -2.3e+57)
(* (fma -6.0 z 4.0) y)
(if (<= y 3.7e+69)
(* (fma 6.0 z -3.0) x)
(* (* (- 0.6666666666666666 z) 6.0) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.3e+57) {
tmp = fma(-6.0, z, 4.0) * y;
} else if (y <= 3.7e+69) {
tmp = fma(6.0, z, -3.0) * x;
} else {
tmp = ((0.6666666666666666 - z) * 6.0) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -2.3e+57) tmp = Float64(fma(-6.0, z, 4.0) * y); elseif (y <= 3.7e+69) tmp = Float64(fma(6.0, z, -3.0) * x); else tmp = Float64(Float64(Float64(0.6666666666666666 - z) * 6.0) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2.3e+57], N[(N[(-6.0 * z + 4.0), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, 3.7e+69], N[(N[(6.0 * z + -3.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(0.6666666666666666 - z), $MachinePrecision] * 6.0), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+57}:\\
\;\;\;\;\mathsf{fma}\left(-6, z, 4\right) \cdot y\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{+69}:\\
\;\;\;\;\mathsf{fma}\left(6, z, -3\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(\left(0.6666666666666666 - z\right) \cdot 6\right) \cdot y\\
\end{array}
\end{array}
if y < -2.2999999999999999e57Initial 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.9
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lift-fma.f6486.1
Applied rewrites86.1%
if -2.2999999999999999e57 < y < 3.6999999999999999e69Initial program 99.4%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval77.8
Applied rewrites77.8%
Taylor expanded in z around 0
Applied rewrites42.7%
Taylor expanded in z around 0
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6477.7
Applied rewrites77.7%
if 3.6999999999999999e69 < y Initial program 99.7%
Taylor expanded in y around inf
metadata-evalN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites95.9%
Taylor expanded in x around 0
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
metadata-eval84.7
Applied rewrites84.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.3e+57) (not (<= y 3.7e+69))) (* (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 <= -2.3e+57) || !(y <= 3.7e+69)) {
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 <= -2.3e+57) || !(y <= 3.7e+69)) 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, -2.3e+57], N[Not[LessEqual[y, 3.7e+69]], $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 -2.3 \cdot 10^{+57} \lor \neg \left(y \leq 3.7 \cdot 10^{+69}\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.2999999999999999e57 or 3.6999999999999999e69 < y Initial 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.9
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lift-fma.f6485.4
Applied rewrites85.4%
if -2.2999999999999999e57 < y < 3.6999999999999999e69Initial program 99.4%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval77.8
Applied rewrites77.8%
Taylor expanded in z around 0
Applied rewrites42.7%
Taylor expanded in z around 0
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6477.7
Applied rewrites77.7%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (<= z -13.0) (* (* 6.0 x) z) (if (<= z 5.5e-7) (fma -3.0 x (* 4.0 y)) (* (fma -6.0 z 4.0) y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -13.0) {
tmp = (6.0 * x) * z;
} else if (z <= 5.5e-7) {
tmp = fma(-3.0, x, (4.0 * y));
} else {
tmp = fma(-6.0, z, 4.0) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -13.0) tmp = Float64(Float64(6.0 * x) * z); elseif (z <= 5.5e-7) tmp = fma(-3.0, x, Float64(4.0 * y)); else tmp = Float64(fma(-6.0, z, 4.0) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -13.0], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 5.5e-7], N[(-3.0 * x + N[(4.0 * y), $MachinePrecision]), $MachinePrecision], N[(N[(-6.0 * z + 4.0), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -13:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(-3, x, 4 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-6, z, 4\right) \cdot y\\
\end{array}
\end{array}
if z < -13Initial program 99.8%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval60.9
Applied rewrites60.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6460.9
Applied rewrites60.9%
Taylor expanded in z around inf
lift-*.f6459.6
Applied rewrites59.6%
if -13 < z < 5.5000000000000003e-7Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6498.8
Applied rewrites98.8%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6498.9
Applied rewrites98.9%
if 5.5000000000000003e-7 < z Initial 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.6
Applied rewrites99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lift-fma.f6455.0
Applied rewrites55.0%
(FPCore (x y z) :precision binary64 (if (<= z -13.0) (* (* 6.0 x) z) (if (<= z 0.66) (fma -3.0 x (* 4.0 y)) (* (* y z) -6.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -13.0) {
tmp = (6.0 * x) * z;
} else if (z <= 0.66) {
tmp = fma(-3.0, x, (4.0 * y));
} else {
tmp = (y * z) * -6.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -13.0) tmp = Float64(Float64(6.0 * x) * z); elseif (z <= 0.66) tmp = fma(-3.0, x, Float64(4.0 * y)); else tmp = Float64(Float64(y * z) * -6.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -13.0], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 0.66], N[(-3.0 * x + N[(4.0 * y), $MachinePrecision]), $MachinePrecision], N[(N[(y * z), $MachinePrecision] * -6.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -13:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\mathbf{elif}\;z \leq 0.66:\\
\;\;\;\;\mathsf{fma}\left(-3, x, 4 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot -6\\
\end{array}
\end{array}
if z < -13Initial program 99.8%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval60.9
Applied rewrites60.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6460.9
Applied rewrites60.9%
Taylor expanded in z around inf
lift-*.f6459.6
Applied rewrites59.6%
if -13 < z < 0.660000000000000031Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6498.3
Applied rewrites98.3%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6498.4
Applied rewrites98.4%
if 0.660000000000000031 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6498.6
Applied rewrites98.6%
Taylor expanded in x around 0
Applied rewrites54.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -13.0) (not (<= z 0.5))) (* (* 6.0 x) z) (fma 4.0 (- y x) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -13.0) || !(z <= 0.5)) {
tmp = (6.0 * x) * z;
} else {
tmp = fma(4.0, (y - x), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -13.0) || !(z <= 0.5)) tmp = Float64(Float64(6.0 * x) * z); else tmp = fma(4.0, Float64(y - x), x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -13.0], N[Not[LessEqual[z, 0.5]], $MachinePrecision]], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -13 \lor \neg \left(z \leq 0.5\right):\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\end{array}
\end{array}
if z < -13 or 0.5 < z Initial program 99.8%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval56.1
Applied rewrites56.1%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6456.1
Applied rewrites56.1%
Taylor expanded in z around inf
lift-*.f6454.8
Applied rewrites54.8%
if -13 < z < 0.5Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6498.3
Applied rewrites98.3%
Final simplification77.4%
(FPCore (x y z) :precision binary64 (if (<= z -13.0) (* (* 6.0 x) z) (if (<= z 0.66) (fma 4.0 (- y x) x) (* (* y z) -6.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -13.0) {
tmp = (6.0 * x) * z;
} else if (z <= 0.66) {
tmp = fma(4.0, (y - x), x);
} else {
tmp = (y * z) * -6.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -13.0) tmp = Float64(Float64(6.0 * x) * z); elseif (z <= 0.66) tmp = fma(4.0, Float64(y - x), x); else tmp = Float64(Float64(y * z) * -6.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -13.0], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 0.66], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], N[(N[(y * z), $MachinePrecision] * -6.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -13:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\mathbf{elif}\;z \leq 0.66:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot -6\\
\end{array}
\end{array}
if z < -13Initial program 99.8%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval60.9
Applied rewrites60.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6460.9
Applied rewrites60.9%
Taylor expanded in z around inf
lift-*.f6459.6
Applied rewrites59.6%
if -13 < z < 0.660000000000000031Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6498.3
Applied rewrites98.3%
if 0.660000000000000031 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6498.6
Applied rewrites98.6%
Taylor expanded in x around 0
Applied rewrites54.3%
(FPCore (x y z) :precision binary64 (if (<= z -13.0) (* (* 6.0 x) z) (if (<= z 0.66) (fma 4.0 (- y x) x) (* y (* -6.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -13.0) {
tmp = (6.0 * x) * z;
} else if (z <= 0.66) {
tmp = fma(4.0, (y - x), x);
} else {
tmp = y * (-6.0 * z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -13.0) tmp = Float64(Float64(6.0 * x) * z); elseif (z <= 0.66) tmp = fma(4.0, Float64(y - x), x); else tmp = Float64(y * Float64(-6.0 * z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -13.0], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 0.66], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], N[(y * N[(-6.0 * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -13:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\mathbf{elif}\;z \leq 0.66:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-6 \cdot z\right)\\
\end{array}
\end{array}
if z < -13Initial program 99.8%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval60.9
Applied rewrites60.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6460.9
Applied rewrites60.9%
Taylor expanded in z around inf
lift-*.f6459.6
Applied rewrites59.6%
if -13 < z < 0.660000000000000031Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6498.3
Applied rewrites98.3%
if 0.660000000000000031 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6498.6
Applied rewrites98.6%
Taylor expanded in x around 0
Applied rewrites54.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f6454.3
Applied rewrites54.3%
(FPCore (x y z) :precision binary64 (if (<= z -13.0) (* (* 6.0 x) z) (if (<= z 0.5) (fma 4.0 (- y x) x) (* (* z x) 6.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -13.0) {
tmp = (6.0 * x) * z;
} else if (z <= 0.5) {
tmp = fma(4.0, (y - x), x);
} else {
tmp = (z * x) * 6.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -13.0) tmp = Float64(Float64(6.0 * x) * z); elseif (z <= 0.5) tmp = fma(4.0, Float64(y - x), x); else tmp = Float64(Float64(z * x) * 6.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -13.0], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 0.5], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -13:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\mathbf{elif}\;z \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\end{array}
\end{array}
if z < -13Initial program 99.8%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval60.9
Applied rewrites60.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6460.9
Applied rewrites60.9%
Taylor expanded in z around inf
lift-*.f6459.6
Applied rewrites59.6%
if -13 < z < 0.5Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6498.3
Applied rewrites98.3%
if 0.5 < z Initial program 99.7%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval51.4
Applied rewrites51.4%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6450.1
Applied rewrites50.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.75e-6) (not (<= x 1.45e+65))) (* -3.0 x) (* 4.0 y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.75e-6) || !(x <= 1.45e+65)) {
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 <= (-2.75d-6)) .or. (.not. (x <= 1.45d+65))) 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 <= -2.75e-6) || !(x <= 1.45e+65)) {
tmp = -3.0 * x;
} else {
tmp = 4.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.75e-6) or not (x <= 1.45e+65): tmp = -3.0 * x else: tmp = 4.0 * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.75e-6) || !(x <= 1.45e+65)) 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 <= -2.75e-6) || ~((x <= 1.45e+65))) tmp = -3.0 * x; else tmp = 4.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.75e-6], N[Not[LessEqual[x, 1.45e+65]], $MachinePrecision]], N[(-3.0 * x), $MachinePrecision], N[(4.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{-6} \lor \neg \left(x \leq 1.45 \cdot 10^{+65}\right):\\
\;\;\;\;-3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;4 \cdot y\\
\end{array}
\end{array}
if x < -2.7499999999999999e-6 or 1.45e65 < x Initial program 99.6%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval83.1
Applied rewrites83.1%
Taylor expanded in z around 0
Applied rewrites44.9%
if -2.7499999999999999e-6 < x < 1.45e65Initial program 99.5%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6453.5
Applied rewrites53.5%
Taylor expanded in x around 0
lower-*.f6440.0
Applied rewrites40.0%
Final simplification42.3%
(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--.f6452.7
Applied rewrites52.7%
(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.5%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6452.7
Applied rewrites52.7%
Taylor expanded in x around 0
lower-*.f6425.6
Applied rewrites25.6%
herbie shell --seed 2025037
(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))))