
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) z)))
double code(double x, double y, double z) {
return x + (((y - x) * 6.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) * z)
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * z);
}
def code(x, y, z): return x + (((y - x) * 6.0) * z)
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * z)) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * z); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) z)))
double code(double x, double y, double z) {
return x + (((y - x) * 6.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) * z)
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * z);
}
def code(x, y, z): return x + (((y - x) * 6.0) * z)
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * z)) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * z); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (* z (- y x)) 6.0 x))
double code(double x, double y, double z) {
return fma((z * (y - x)), 6.0, x);
}
function code(x, y, z) return fma(Float64(z * Float64(y - x)), 6.0, x) end
code[x_, y_, z_] := N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] * 6.0 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z \cdot \left(y - x\right), 6, x\right)
\end{array}
Initial program 99.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(if (<= y -1.66e-44)
(* (* z y) 6.0)
(if (<= y -3e-305)
(* 1.0 x)
(if (<= y 1.22e-27) (* (* -6.0 z) x) (* (* 6.0 z) y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.66e-44) {
tmp = (z * y) * 6.0;
} else if (y <= -3e-305) {
tmp = 1.0 * x;
} else if (y <= 1.22e-27) {
tmp = (-6.0 * z) * x;
} else {
tmp = (6.0 * z) * 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 (y <= (-1.66d-44)) then
tmp = (z * y) * 6.0d0
else if (y <= (-3d-305)) then
tmp = 1.0d0 * x
else if (y <= 1.22d-27) then
tmp = ((-6.0d0) * z) * x
else
tmp = (6.0d0 * z) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.66e-44) {
tmp = (z * y) * 6.0;
} else if (y <= -3e-305) {
tmp = 1.0 * x;
} else if (y <= 1.22e-27) {
tmp = (-6.0 * z) * x;
} else {
tmp = (6.0 * z) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.66e-44: tmp = (z * y) * 6.0 elif y <= -3e-305: tmp = 1.0 * x elif y <= 1.22e-27: tmp = (-6.0 * z) * x else: tmp = (6.0 * z) * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.66e-44) tmp = Float64(Float64(z * y) * 6.0); elseif (y <= -3e-305) tmp = Float64(1.0 * x); elseif (y <= 1.22e-27) tmp = Float64(Float64(-6.0 * z) * x); else tmp = Float64(Float64(6.0 * z) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.66e-44) tmp = (z * y) * 6.0; elseif (y <= -3e-305) tmp = 1.0 * x; elseif (y <= 1.22e-27) tmp = (-6.0 * z) * x; else tmp = (6.0 * z) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.66e-44], N[(N[(z * y), $MachinePrecision] * 6.0), $MachinePrecision], If[LessEqual[y, -3e-305], N[(1.0 * x), $MachinePrecision], If[LessEqual[y, 1.22e-27], N[(N[(-6.0 * z), $MachinePrecision] * x), $MachinePrecision], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.66 \cdot 10^{-44}:\\
\;\;\;\;\left(z \cdot y\right) \cdot 6\\
\mathbf{elif}\;y \leq -3 \cdot 10^{-305}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{-27}:\\
\;\;\;\;\left(-6 \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(6 \cdot z\right) \cdot y\\
\end{array}
\end{array}
if y < -1.6600000000000001e-44Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6471.2
Applied rewrites71.2%
if -1.6600000000000001e-44 < y < -3.0000000000000001e-305Initial program 98.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6490.5
Applied rewrites90.5%
Taylor expanded in z around 0
Applied rewrites69.6%
if -3.0000000000000001e-305 < y < 1.22e-27Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6494.4
Applied rewrites94.4%
Taylor expanded in z around inf
Applied rewrites58.5%
if 1.22e-27 < y Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6471.3
Applied rewrites71.3%
Applied rewrites71.3%
Final simplification68.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.8e-174) (not (<= y 1.22e-27))) (fma (* y z) 6.0 x) (* (fma -6.0 z 1.0) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e-174) || !(y <= 1.22e-27)) {
tmp = fma((y * z), 6.0, x);
} else {
tmp = fma(-6.0, z, 1.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -2.8e-174) || !(y <= 1.22e-27)) tmp = fma(Float64(y * z), 6.0, x); else tmp = Float64(fma(-6.0, z, 1.0) * x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.8e-174], N[Not[LessEqual[y, 1.22e-27]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * 6.0 + x), $MachinePrecision], N[(N[(-6.0 * z + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-174} \lor \neg \left(y \leq 1.22 \cdot 10^{-27}\right):\\
\;\;\;\;\mathsf{fma}\left(y \cdot z, 6, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-6, z, 1\right) \cdot x\\
\end{array}
\end{array}
if y < -2.79999999999999999e-174 or 1.22e-27 < y Initial program 99.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
lower-*.f6488.3
Applied rewrites88.3%
if -2.79999999999999999e-174 < y < 1.22e-27Initial program 98.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6496.2
Applied rewrites96.2%
Final simplification90.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.02e+99) (* (* z y) 6.0) (if (<= y 2.2e+55) (* (fma -6.0 z 1.0) x) (* (* 6.0 z) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.02e+99) {
tmp = (z * y) * 6.0;
} else if (y <= 2.2e+55) {
tmp = fma(-6.0, z, 1.0) * x;
} else {
tmp = (6.0 * z) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.02e+99) tmp = Float64(Float64(z * y) * 6.0); elseif (y <= 2.2e+55) tmp = Float64(fma(-6.0, z, 1.0) * x); else tmp = Float64(Float64(6.0 * z) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.02e+99], N[(N[(z * y), $MachinePrecision] * 6.0), $MachinePrecision], If[LessEqual[y, 2.2e+55], N[(N[(-6.0 * z + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.02 \cdot 10^{+99}:\\
\;\;\;\;\left(z \cdot y\right) \cdot 6\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+55}:\\
\;\;\;\;\mathsf{fma}\left(-6, z, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(6 \cdot z\right) \cdot y\\
\end{array}
\end{array}
if y < -1.01999999999999998e99Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6488.1
Applied rewrites88.1%
if -1.01999999999999998e99 < y < 2.2000000000000001e55Initial program 99.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6485.2
Applied rewrites85.2%
if 2.2000000000000001e55 < y Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6478.9
Applied rewrites78.9%
Applied rewrites78.9%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.66e-44) (not (<= y 2.3e-87))) (* (* 6.0 y) z) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.66e-44) || !(y <= 2.3e-87)) {
tmp = (6.0 * y) * z;
} else {
tmp = 1.0 * x;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-1.66d-44)) .or. (.not. (y <= 2.3d-87))) then
tmp = (6.0d0 * y) * z
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.66e-44) || !(y <= 2.3e-87)) {
tmp = (6.0 * y) * z;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.66e-44) or not (y <= 2.3e-87): tmp = (6.0 * y) * z else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.66e-44) || !(y <= 2.3e-87)) tmp = Float64(Float64(6.0 * y) * z); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.66e-44) || ~((y <= 2.3e-87))) tmp = (6.0 * y) * z; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.66e-44], N[Not[LessEqual[y, 2.3e-87]], $MachinePrecision]], N[(N[(6.0 * y), $MachinePrecision] * z), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.66 \cdot 10^{-44} \lor \neg \left(y \leq 2.3 \cdot 10^{-87}\right):\\
\;\;\;\;\left(6 \cdot y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -1.6600000000000001e-44 or 2.3000000000000001e-87 < y Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6469.0
Applied rewrites69.0%
Applied rewrites68.9%
if -1.6600000000000001e-44 < y < 2.3000000000000001e-87Initial program 99.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6494.1
Applied rewrites94.1%
Taylor expanded in z around 0
Applied rewrites58.7%
Final simplification64.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.66e-44) (* (* z y) 6.0) (if (<= y 2.3e-87) (* 1.0 x) (* (* 6.0 z) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.66e-44) {
tmp = (z * y) * 6.0;
} else if (y <= 2.3e-87) {
tmp = 1.0 * x;
} else {
tmp = (6.0 * z) * 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 (y <= (-1.66d-44)) then
tmp = (z * y) * 6.0d0
else if (y <= 2.3d-87) then
tmp = 1.0d0 * x
else
tmp = (6.0d0 * z) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.66e-44) {
tmp = (z * y) * 6.0;
} else if (y <= 2.3e-87) {
tmp = 1.0 * x;
} else {
tmp = (6.0 * z) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.66e-44: tmp = (z * y) * 6.0 elif y <= 2.3e-87: tmp = 1.0 * x else: tmp = (6.0 * z) * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.66e-44) tmp = Float64(Float64(z * y) * 6.0); elseif (y <= 2.3e-87) tmp = Float64(1.0 * x); else tmp = Float64(Float64(6.0 * z) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.66e-44) tmp = (z * y) * 6.0; elseif (y <= 2.3e-87) tmp = 1.0 * x; else tmp = (6.0 * z) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.66e-44], N[(N[(z * y), $MachinePrecision] * 6.0), $MachinePrecision], If[LessEqual[y, 2.3e-87], N[(1.0 * x), $MachinePrecision], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.66 \cdot 10^{-44}:\\
\;\;\;\;\left(z \cdot y\right) \cdot 6\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{-87}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(6 \cdot z\right) \cdot y\\
\end{array}
\end{array}
if y < -1.6600000000000001e-44Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6471.2
Applied rewrites71.2%
if -1.6600000000000001e-44 < y < 2.3000000000000001e-87Initial program 99.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6494.1
Applied rewrites94.1%
Taylor expanded in z around 0
Applied rewrites58.7%
if 2.3000000000000001e-87 < y Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6467.0
Applied rewrites67.0%
Applied rewrites67.0%
Final simplification64.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.66e-44) (* (* 6.0 y) z) (if (<= y 2.3e-87) (* 1.0 x) (* (* 6.0 z) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.66e-44) {
tmp = (6.0 * y) * z;
} else if (y <= 2.3e-87) {
tmp = 1.0 * x;
} else {
tmp = (6.0 * z) * 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 (y <= (-1.66d-44)) then
tmp = (6.0d0 * y) * z
else if (y <= 2.3d-87) then
tmp = 1.0d0 * x
else
tmp = (6.0d0 * z) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.66e-44) {
tmp = (6.0 * y) * z;
} else if (y <= 2.3e-87) {
tmp = 1.0 * x;
} else {
tmp = (6.0 * z) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.66e-44: tmp = (6.0 * y) * z elif y <= 2.3e-87: tmp = 1.0 * x else: tmp = (6.0 * z) * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.66e-44) tmp = Float64(Float64(6.0 * y) * z); elseif (y <= 2.3e-87) tmp = Float64(1.0 * x); else tmp = Float64(Float64(6.0 * z) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.66e-44) tmp = (6.0 * y) * z; elseif (y <= 2.3e-87) tmp = 1.0 * x; else tmp = (6.0 * z) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.66e-44], N[(N[(6.0 * y), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[y, 2.3e-87], N[(1.0 * x), $MachinePrecision], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.66 \cdot 10^{-44}:\\
\;\;\;\;\left(6 \cdot y\right) \cdot z\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{-87}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(6 \cdot z\right) \cdot y\\
\end{array}
\end{array}
if y < -1.6600000000000001e-44Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6471.2
Applied rewrites71.2%
Applied rewrites71.1%
if -1.6600000000000001e-44 < y < 2.3000000000000001e-87Initial program 99.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6494.1
Applied rewrites94.1%
Taylor expanded in z around 0
Applied rewrites58.7%
if 2.3000000000000001e-87 < y Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6467.0
Applied rewrites67.0%
Applied rewrites67.0%
Final simplification64.4%
(FPCore (x y z) :precision binary64 (fma (* 6.0 (- y x)) z x))
double code(double x, double y, double z) {
return fma((6.0 * (y - x)), z, x);
}
function code(x, y, z) return fma(Float64(6.0 * Float64(y - x)), z, x) end
code[x_, y_, z_] := N[(N[(6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(6 \cdot \left(y - x\right), z, x\right)
\end{array}
Initial program 99.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.4
Applied rewrites99.4%
(FPCore (x y z) :precision binary64 (* 1.0 x))
double code(double x, double y, double z) {
return 1.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 = 1.0d0 * x
end function
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 99.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6461.0
Applied rewrites61.0%
Taylor expanded in z around 0
Applied rewrites35.8%
(FPCore (x y z) :precision binary64 (- x (* (* 6.0 z) (- x y))))
double code(double x, double y, double z) {
return x - ((6.0 * z) * (x - 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 = x - ((6.0d0 * z) * (x - y))
end function
public static double code(double x, double y, double z) {
return x - ((6.0 * z) * (x - y));
}
def code(x, y, z): return x - ((6.0 * z) * (x - y))
function code(x, y, z) return Float64(x - Float64(Float64(6.0 * z) * Float64(x - y))) end
function tmp = code(x, y, z) tmp = x - ((6.0 * z) * (x - y)); end
code[x_, y_, z_] := N[(x - N[(N[(6.0 * z), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(6 \cdot z\right) \cdot \left(x - y\right)
\end{array}
herbie shell --seed 2024359
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E"
:precision binary64
:alt
(! :herbie-platform default (- x (* (* 6 z) (- x y))))
(+ x (* (* (- y x) 6.0) z)))