
(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 11 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.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
lower-fma.f64N/A
lift--.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(if (<= z -2.4e-25)
(* (* y 6.0) z)
(if (<= z 1.12e-17)
(* 1.0 x)
(if (<= z 1.5e+189) (* (* z 6.0) y) (* (* z x) -6.0)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e-25) {
tmp = (y * 6.0) * z;
} else if (z <= 1.12e-17) {
tmp = 1.0 * x;
} else if (z <= 1.5e+189) {
tmp = (z * 6.0) * y;
} else {
tmp = (z * x) * -6.0;
}
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 (z <= (-2.4d-25)) then
tmp = (y * 6.0d0) * z
else if (z <= 1.12d-17) then
tmp = 1.0d0 * x
else if (z <= 1.5d+189) then
tmp = (z * 6.0d0) * y
else
tmp = (z * x) * (-6.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e-25) {
tmp = (y * 6.0) * z;
} else if (z <= 1.12e-17) {
tmp = 1.0 * x;
} else if (z <= 1.5e+189) {
tmp = (z * 6.0) * y;
} else {
tmp = (z * x) * -6.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.4e-25: tmp = (y * 6.0) * z elif z <= 1.12e-17: tmp = 1.0 * x elif z <= 1.5e+189: tmp = (z * 6.0) * y else: tmp = (z * x) * -6.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.4e-25) tmp = Float64(Float64(y * 6.0) * z); elseif (z <= 1.12e-17) tmp = Float64(1.0 * x); elseif (z <= 1.5e+189) tmp = Float64(Float64(z * 6.0) * y); else tmp = Float64(Float64(z * x) * -6.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.4e-25) tmp = (y * 6.0) * z; elseif (z <= 1.12e-17) tmp = 1.0 * x; elseif (z <= 1.5e+189) tmp = (z * 6.0) * y; else tmp = (z * x) * -6.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.4e-25], N[(N[(y * 6.0), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 1.12e-17], N[(1.0 * x), $MachinePrecision], If[LessEqual[z, 1.5e+189], N[(N[(z * 6.0), $MachinePrecision] * y), $MachinePrecision], N[(N[(z * x), $MachinePrecision] * -6.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-25}:\\
\;\;\;\;\left(y \cdot 6\right) \cdot z\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{-17}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+189}:\\
\;\;\;\;\left(z \cdot 6\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot x\right) \cdot -6\\
\end{array}
\end{array}
if z < -2.40000000000000009e-25Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6461.8
Applied rewrites61.8%
Applied rewrites61.8%
if -2.40000000000000009e-25 < z < 1.12000000000000005e-17Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6470.8
Applied rewrites70.8%
Taylor expanded in z around 0
Applied rewrites70.8%
if 1.12000000000000005e-17 < z < 1.4999999999999999e189Initial program 99.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6467.6
Applied rewrites67.6%
Applied rewrites67.7%
if 1.4999999999999999e189 < z Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6461.3
Applied rewrites61.3%
Taylor expanded in z around 0
Applied rewrites1.5%
Taylor expanded in z around inf
Applied rewrites61.4%
Final simplification67.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.85e-12) (not (<= z 0.166))) (* (* z (- y x)) 6.0) (fma (* y 6.0) z x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.85e-12) || !(z <= 0.166)) {
tmp = (z * (y - x)) * 6.0;
} else {
tmp = fma((y * 6.0), z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -1.85e-12) || !(z <= 0.166)) tmp = Float64(Float64(z * Float64(y - x)) * 6.0); else tmp = fma(Float64(y * 6.0), z, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.85e-12], N[Not[LessEqual[z, 0.166]], $MachinePrecision]], N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] * 6.0), $MachinePrecision], N[(N[(y * 6.0), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{-12} \lor \neg \left(z \leq 0.166\right):\\
\;\;\;\;\left(z \cdot \left(y - x\right)\right) \cdot 6\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 6, z, x\right)\\
\end{array}
\end{array}
if z < -1.84999999999999999e-12 or 0.166000000000000009 < z Initial program 99.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift--.f64N/A
flip--N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
difference-of-squaresN/A
lift--.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6480.0
Applied rewrites80.0%
Taylor expanded in x around 0
unpow2N/A
lower-*.f6446.9
Applied rewrites46.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f6498.6
Applied rewrites98.6%
if -1.84999999999999999e-12 < z < 0.166000000000000009Initial program 99.8%
Taylor expanded in x around 0
lower-*.f6499.3
Applied rewrites99.3%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.3
Applied rewrites99.3%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.5e-102) (not (<= y 9e-56))) (fma (* y 6.0) z x) (fma (* x z) -6.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e-102) || !(y <= 9e-56)) {
tmp = fma((y * 6.0), z, x);
} else {
tmp = fma((x * z), -6.0, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -9.5e-102) || !(y <= 9e-56)) tmp = fma(Float64(y * 6.0), z, x); else tmp = fma(Float64(x * z), -6.0, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.5e-102], N[Not[LessEqual[y, 9e-56]], $MachinePrecision]], N[(N[(y * 6.0), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(x * z), $MachinePrecision] * -6.0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{-102} \lor \neg \left(y \leq 9 \cdot 10^{-56}\right):\\
\;\;\;\;\mathsf{fma}\left(y \cdot 6, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot z, -6, x\right)\\
\end{array}
\end{array}
if y < -9.50000000000000025e-102 or 9.0000000000000001e-56 < y Initial program 99.7%
Taylor expanded in x around 0
lower-*.f6493.2
Applied rewrites93.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6493.3
Applied rewrites93.3%
if -9.50000000000000025e-102 < y < 9.0000000000000001e-56Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6487.2
Applied rewrites87.2%
Applied rewrites87.2%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (<= y -9e-32) (* (* y 6.0) z) (if (<= y 2.4e+124) (fma (* -6.0 x) z x) (* (* z 6.0) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9e-32) {
tmp = (y * 6.0) * z;
} else if (y <= 2.4e+124) {
tmp = fma((-6.0 * x), z, x);
} else {
tmp = (z * 6.0) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -9e-32) tmp = Float64(Float64(y * 6.0) * z); elseif (y <= 2.4e+124) tmp = fma(Float64(-6.0 * x), z, x); else tmp = Float64(Float64(z * 6.0) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -9e-32], N[(N[(y * 6.0), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[y, 2.4e+124], N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(z * 6.0), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-32}:\\
\;\;\;\;\left(y \cdot 6\right) \cdot z\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+124}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot 6\right) \cdot y\\
\end{array}
\end{array}
if y < -9.00000000000000009e-32Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6470.5
Applied rewrites70.5%
Applied rewrites70.5%
if -9.00000000000000009e-32 < y < 2.40000000000000006e124Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
lower-*.f6478.3
Applied rewrites78.3%
if 2.40000000000000006e124 < y Initial program 99.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6482.5
Applied rewrites82.5%
Applied rewrites82.5%
Final simplification77.1%
(FPCore (x y z) :precision binary64 (if (<= y -9e-32) (* (* y 6.0) z) (if (<= y 2.4e+124) (fma (* x z) -6.0 x) (* (* z 6.0) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9e-32) {
tmp = (y * 6.0) * z;
} else if (y <= 2.4e+124) {
tmp = fma((x * z), -6.0, x);
} else {
tmp = (z * 6.0) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -9e-32) tmp = Float64(Float64(y * 6.0) * z); elseif (y <= 2.4e+124) tmp = fma(Float64(x * z), -6.0, x); else tmp = Float64(Float64(z * 6.0) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -9e-32], N[(N[(y * 6.0), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[y, 2.4e+124], N[(N[(x * z), $MachinePrecision] * -6.0 + x), $MachinePrecision], N[(N[(z * 6.0), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-32}:\\
\;\;\;\;\left(y \cdot 6\right) \cdot z\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+124}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot z, -6, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot 6\right) \cdot y\\
\end{array}
\end{array}
if y < -9.00000000000000009e-32Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6470.5
Applied rewrites70.5%
Applied rewrites70.5%
if -9.00000000000000009e-32 < y < 2.40000000000000006e124Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6478.3
Applied rewrites78.3%
Applied rewrites78.3%
if 2.40000000000000006e124 < y Initial program 99.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6482.5
Applied rewrites82.5%
Applied rewrites82.5%
Final simplification77.1%
(FPCore (x y z) :precision binary64 (if (<= y -9e-32) (* (* y 6.0) z) (if (<= y 2.4e+124) (* (fma -6.0 z 1.0) x) (* (* z 6.0) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9e-32) {
tmp = (y * 6.0) * z;
} else if (y <= 2.4e+124) {
tmp = fma(-6.0, z, 1.0) * x;
} else {
tmp = (z * 6.0) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -9e-32) tmp = Float64(Float64(y * 6.0) * z); elseif (y <= 2.4e+124) tmp = Float64(fma(-6.0, z, 1.0) * x); else tmp = Float64(Float64(z * 6.0) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -9e-32], N[(N[(y * 6.0), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[y, 2.4e+124], N[(N[(-6.0 * z + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(z * 6.0), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-32}:\\
\;\;\;\;\left(y \cdot 6\right) \cdot z\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+124}:\\
\;\;\;\;\mathsf{fma}\left(-6, z, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot 6\right) \cdot y\\
\end{array}
\end{array}
if y < -9.00000000000000009e-32Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6470.5
Applied rewrites70.5%
Applied rewrites70.5%
if -9.00000000000000009e-32 < y < 2.40000000000000006e124Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6478.3
Applied rewrites78.3%
if 2.40000000000000006e124 < y Initial program 99.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6482.5
Applied rewrites82.5%
Applied rewrites82.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.4e-25) (not (<= z 1.12e-17))) (* (* y 6.0) z) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e-25) || !(z <= 1.12e-17)) {
tmp = (y * 6.0) * 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 ((z <= (-2.4d-25)) .or. (.not. (z <= 1.12d-17))) then
tmp = (y * 6.0d0) * 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 ((z <= -2.4e-25) || !(z <= 1.12e-17)) {
tmp = (y * 6.0) * z;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.4e-25) or not (z <= 1.12e-17): tmp = (y * 6.0) * z else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.4e-25) || !(z <= 1.12e-17)) tmp = Float64(Float64(y * 6.0) * z); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.4e-25) || ~((z <= 1.12e-17))) tmp = (y * 6.0) * z; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.4e-25], N[Not[LessEqual[z, 1.12e-17]], $MachinePrecision]], N[(N[(y * 6.0), $MachinePrecision] * z), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-25} \lor \neg \left(z \leq 1.12 \cdot 10^{-17}\right):\\
\;\;\;\;\left(y \cdot 6\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -2.40000000000000009e-25 or 1.12000000000000005e-17 < z Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6460.1
Applied rewrites60.1%
Applied rewrites60.1%
if -2.40000000000000009e-25 < z < 1.12000000000000005e-17Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6470.8
Applied rewrites70.8%
Taylor expanded in z around 0
Applied rewrites70.8%
Final simplification65.1%
(FPCore (x y z) :precision binary64 (if (<= z -2.4e-25) (* (* y 6.0) z) (if (<= z 1.12e-17) (* 1.0 x) (* (* z 6.0) y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e-25) {
tmp = (y * 6.0) * z;
} else if (z <= 1.12e-17) {
tmp = 1.0 * x;
} else {
tmp = (z * 6.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 (z <= (-2.4d-25)) then
tmp = (y * 6.0d0) * z
else if (z <= 1.12d-17) then
tmp = 1.0d0 * x
else
tmp = (z * 6.0d0) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e-25) {
tmp = (y * 6.0) * z;
} else if (z <= 1.12e-17) {
tmp = 1.0 * x;
} else {
tmp = (z * 6.0) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.4e-25: tmp = (y * 6.0) * z elif z <= 1.12e-17: tmp = 1.0 * x else: tmp = (z * 6.0) * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.4e-25) tmp = Float64(Float64(y * 6.0) * z); elseif (z <= 1.12e-17) tmp = Float64(1.0 * x); else tmp = Float64(Float64(z * 6.0) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.4e-25) tmp = (y * 6.0) * z; elseif (z <= 1.12e-17) tmp = 1.0 * x; else tmp = (z * 6.0) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.4e-25], N[(N[(y * 6.0), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 1.12e-17], N[(1.0 * x), $MachinePrecision], N[(N[(z * 6.0), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-25}:\\
\;\;\;\;\left(y \cdot 6\right) \cdot z\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{-17}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot 6\right) \cdot y\\
\end{array}
\end{array}
if z < -2.40000000000000009e-25Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6461.8
Applied rewrites61.8%
Applied rewrites61.8%
if -2.40000000000000009e-25 < z < 1.12000000000000005e-17Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6470.8
Applied rewrites70.8%
Taylor expanded in z around 0
Applied rewrites70.8%
if 1.12000000000000005e-17 < z Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6458.7
Applied rewrites58.7%
Applied rewrites58.7%
Final simplification65.1%
(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.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(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.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6455.9
Applied rewrites55.9%
Taylor expanded in z around 0
Applied rewrites35.5%
Final simplification35.5%
(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 2024364
(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)))