
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (((y - x) * 6.0d0) * ((2.0d0 / 3.0d0) - z))
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
def code(x, y, z): return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z))
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * ((2.0 / 3.0) - z)); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\end{array}
Herbie found 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 (if (or (<= z -0.6) (not (<= z 0.62))) (* (* -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.6) || !(z <= 0.62)) {
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.6) || !(z <= 0.62)) 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.6], N[Not[LessEqual[z, 0.62]], $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.6 \lor \neg \left(z \leq 0.62\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.599999999999999978 or 0.619999999999999996 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6497.5
Applied rewrites97.5%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lower-*.f6497.4
Applied rewrites97.4%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lift--.f6497.5
Applied rewrites97.5%
if -0.599999999999999978 < z < 0.619999999999999996Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6497.7
Applied rewrites97.7%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6497.7
Applied rewrites97.7%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.6e+38) (not (<= y 5.5e+62))) (* (fma -6.0 z 4.0) y) (* (- x) (fma -6.0 z 3.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.6e+38) || !(y <= 5.5e+62)) {
tmp = fma(-6.0, z, 4.0) * y;
} else {
tmp = -x * fma(-6.0, z, 3.0);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -1.6e+38) || !(y <= 5.5e+62)) tmp = Float64(fma(-6.0, z, 4.0) * y); else tmp = Float64(Float64(-x) * fma(-6.0, z, 3.0)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.6e+38], N[Not[LessEqual[y, 5.5e+62]], $MachinePrecision]], N[(N[(-6.0 * z + 4.0), $MachinePrecision] * y), $MachinePrecision], N[((-x) * N[(-6.0 * z + 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+38} \lor \neg \left(y \leq 5.5 \cdot 10^{+62}\right):\\
\;\;\;\;\mathsf{fma}\left(-6, z, 4\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(-x\right) \cdot \mathsf{fma}\left(-6, z, 3\right)\\
\end{array}
\end{array}
if y < -1.59999999999999993e38 or 5.4999999999999997e62 < y Initial program 99.6%
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.f6482.3
Applied rewrites82.3%
if -1.59999999999999993e38 < y < 5.4999999999999997e62Initial 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%
Taylor expanded in x around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
lower-fma.f6470.6
Applied rewrites70.6%
Final simplification75.5%
(FPCore (x y z) :precision binary64 (if (<= z -1020000000.0) (* y (* -6.0 z)) (if (<= z 0.6) (fma -3.0 x (* 4.0 y)) (* (* z 6.0) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1020000000.0) {
tmp = y * (-6.0 * z);
} else if (z <= 0.6) {
tmp = fma(-3.0, x, (4.0 * y));
} else {
tmp = (z * 6.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1020000000.0) tmp = Float64(y * Float64(-6.0 * z)); elseif (z <= 0.6) tmp = fma(-3.0, x, Float64(4.0 * y)); else tmp = Float64(Float64(z * 6.0) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1020000000.0], N[(y * N[(-6.0 * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.6], N[(-3.0 * x + N[(4.0 * y), $MachinePrecision]), $MachinePrecision], N[(N[(z * 6.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1020000000:\\
\;\;\;\;y \cdot \left(-6 \cdot z\right)\\
\mathbf{elif}\;z \leq 0.6:\\
\;\;\;\;\mathsf{fma}\left(-3, x, 4 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot 6\right) \cdot x\\
\end{array}
\end{array}
if z < -1.02e9Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6499.4
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites51.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f6451.1
Applied rewrites51.1%
if -1.02e9 < z < 0.599999999999999978Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6496.1
Applied rewrites96.1%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6496.1
Applied rewrites96.1%
if 0.599999999999999978 < 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-eval51.7
Applied rewrites51.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6450.9
Applied rewrites50.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 0.6))) (* (* z x) 6.0) (fma 4.0 (- y x) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 0.6)) {
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.0) || !(z <= 0.6)) 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.0], N[Not[LessEqual[z, 0.6]], $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 \lor \neg \left(z \leq 0.6\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 or 0.599999999999999978 < 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-eval52.5
Applied rewrites52.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6451.6
Applied rewrites51.6%
if -1 < z < 0.599999999999999978Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6497.6
Applied rewrites97.6%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (if (<= z -1020000000.0) (* y (* -6.0 z)) (if (<= z 0.6) (fma 4.0 (- y x) x) (* (* z 6.0) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1020000000.0) {
tmp = y * (-6.0 * z);
} else if (z <= 0.6) {
tmp = fma(4.0, (y - x), x);
} else {
tmp = (z * 6.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1020000000.0) tmp = Float64(y * Float64(-6.0 * z)); elseif (z <= 0.6) tmp = fma(4.0, Float64(y - x), x); else tmp = Float64(Float64(z * 6.0) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1020000000.0], N[(y * N[(-6.0 * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.6], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], N[(N[(z * 6.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1020000000:\\
\;\;\;\;y \cdot \left(-6 \cdot z\right)\\
\mathbf{elif}\;z \leq 0.6:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot 6\right) \cdot x\\
\end{array}
\end{array}
if z < -1.02e9Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6499.4
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites51.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f6451.1
Applied rewrites51.1%
if -1.02e9 < z < 0.599999999999999978Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6496.1
Applied rewrites96.1%
if 0.599999999999999978 < 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-eval51.7
Applied rewrites51.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6450.9
Applied rewrites50.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* (* z x) 6.0) (if (<= z 0.6) (fma 4.0 (- y x) x) (* (* z 6.0) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = (z * x) * 6.0;
} else if (z <= 0.6) {
tmp = fma(4.0, (y - x), x);
} else {
tmp = (z * 6.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(Float64(z * x) * 6.0); elseif (z <= 0.6) tmp = fma(4.0, Float64(y - x), x); else tmp = Float64(Float64(z * 6.0) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision], If[LessEqual[z, 0.6], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], N[(N[(z * 6.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\mathbf{elif}\;z \leq 0.6:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot 6\right) \cdot x\\
\end{array}
\end{array}
if z < -1Initial 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-eval53.3
Applied rewrites53.3%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6452.3
Applied rewrites52.3%
if -1 < z < 0.599999999999999978Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6497.6
Applied rewrites97.6%
if 0.599999999999999978 < 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-eval51.7
Applied rewrites51.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6450.9
Applied rewrites50.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.52e+54) (not (<= y 6.9e-65))) (* 4.0 y) (* -3.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.52e+54) || !(y <= 6.9e-65)) {
tmp = 4.0 * y;
} else {
tmp = -3.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.52d+54)) .or. (.not. (y <= 6.9d-65))) then
tmp = 4.0d0 * y
else
tmp = (-3.0d0) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.52e+54) || !(y <= 6.9e-65)) {
tmp = 4.0 * y;
} else {
tmp = -3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.52e+54) or not (y <= 6.9e-65): tmp = 4.0 * y else: tmp = -3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.52e+54) || !(y <= 6.9e-65)) tmp = Float64(4.0 * y); else tmp = Float64(-3.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.52e+54) || ~((y <= 6.9e-65))) tmp = 4.0 * y; else tmp = -3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.52e+54], N[Not[LessEqual[y, 6.9e-65]], $MachinePrecision]], N[(4.0 * y), $MachinePrecision], N[(-3.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.52 \cdot 10^{+54} \lor \neg \left(y \leq 6.9 \cdot 10^{-65}\right):\\
\;\;\;\;4 \cdot y\\
\mathbf{else}:\\
\;\;\;\;-3 \cdot x\\
\end{array}
\end{array}
if y < -1.51999999999999999e54 or 6.89999999999999991e-65 < y Initial program 99.6%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6451.1
Applied rewrites51.1%
Taylor expanded in x around 0
lower-*.f6438.8
Applied rewrites38.8%
if -1.51999999999999999e54 < y < 6.89999999999999991e-65Initial program 99.5%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval73.7
Applied rewrites73.7%
Taylor expanded in z around 0
Applied rewrites38.4%
Final simplification38.6%
(FPCore (x y z) :precision binary64 (if (<= y -1.52e+54) (fma 4.0 y x) (if (<= y 6.9e-65) (* -3.0 x) (* 4.0 y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.52e+54) {
tmp = fma(4.0, y, x);
} else if (y <= 6.9e-65) {
tmp = -3.0 * x;
} else {
tmp = 4.0 * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.52e+54) tmp = fma(4.0, y, x); elseif (y <= 6.9e-65) tmp = Float64(-3.0 * x); else tmp = Float64(4.0 * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.52e+54], N[(4.0 * y + x), $MachinePrecision], If[LessEqual[y, 6.9e-65], N[(-3.0 * x), $MachinePrecision], N[(4.0 * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.52 \cdot 10^{+54}:\\
\;\;\;\;\mathsf{fma}\left(4, y, x\right)\\
\mathbf{elif}\;y \leq 6.9 \cdot 10^{-65}:\\
\;\;\;\;-3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;4 \cdot y\\
\end{array}
\end{array}
if y < -1.51999999999999999e54Initial program 99.6%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6450.7
Applied rewrites50.7%
Taylor expanded in x around 0
Applied rewrites42.2%
if -1.51999999999999999e54 < y < 6.89999999999999991e-65Initial program 99.5%
Taylor expanded in x around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
metadata-eval73.7
Applied rewrites73.7%
Taylor expanded in z around 0
Applied rewrites38.4%
if 6.89999999999999991e-65 < y Initial program 99.6%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lift--.f6451.3
Applied rewrites51.3%
Taylor expanded in x around 0
lower-*.f6436.5
Applied rewrites36.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--.f6451.3
Applied rewrites51.3%
(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--.f6451.3
Applied rewrites51.3%
Taylor expanded in x around 0
lower-*.f6427.2
Applied rewrites27.2%
herbie shell --seed 2025086
(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))))