
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * 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 * (1.0d0 - ((1.0d0 - y) * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * z));
}
def code(x, y, z): return x * (1.0 - ((1.0 - y) * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - ((1.0 - y) * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * 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 * (1.0d0 - ((1.0d0 - y) * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * z));
}
def code(x, y, z): return x * (1.0 - ((1.0 - y) * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - ((1.0 - y) * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fma (* (- y 1.0) x) z x)))
(if (<= z -3.6e-42)
t_0
(if (<= z 1.95e-93) (* x (- 1.0 (* (- y) z))) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(((y - 1.0) * x), z, x);
double tmp;
if (z <= -3.6e-42) {
tmp = t_0;
} else if (z <= 1.95e-93) {
tmp = x * (1.0 - (-y * z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(Float64(y - 1.0) * x), z, x) tmp = 0.0 if (z <= -3.6e-42) tmp = t_0; elseif (z <= 1.95e-93) tmp = Float64(x * Float64(1.0 - Float64(Float64(-y) * z))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[z, -3.6e-42], t$95$0, If[LessEqual[z, 1.95e-93], N[(x * N[(1.0 - N[((-y) * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left(y - 1\right) \cdot x, z, x\right)\\
\mathbf{if}\;z \leq -3.6 \cdot 10^{-42}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.95 \cdot 10^{-93}:\\
\;\;\;\;x \cdot \left(1 - \left(-y\right) \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.6000000000000002e-42 or 1.95000000000000009e-93 < z Initial program 93.5%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites99.4%
if -3.6000000000000002e-42 < z < 1.95000000000000009e-93Initial program 99.9%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (<= x 1.5e+28) (fma (* (- y 1.0) x) z x) (fma (- y 1.0) (* z x) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.5e+28) {
tmp = fma(((y - 1.0) * x), z, x);
} else {
tmp = fma((y - 1.0), (z * x), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= 1.5e+28) tmp = fma(Float64(Float64(y - 1.0) * x), z, x); else tmp = fma(Float64(y - 1.0), Float64(z * x), x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, 1.5e+28], N[(N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(y - 1.0), $MachinePrecision] * N[(z * x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5 \cdot 10^{+28}:\\
\;\;\;\;\mathsf{fma}\left(\left(y - 1\right) \cdot x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - 1, z \cdot x, x\right)\\
\end{array}
\end{array}
if x < 1.5e28Initial program 94.7%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites97.6%
if 1.5e28 < x Initial program 99.9%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* (- y 1.0) x) z))) (if (<= z -90.0) t_0 (if (<= z 1.0) (* x (- 1.0 (* (- y) z))) t_0))))
double code(double x, double y, double z) {
double t_0 = ((y - 1.0) * x) * z;
double tmp;
if (z <= -90.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = x * (1.0 - (-y * z));
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = ((y - 1.0d0) * x) * z
if (z <= (-90.0d0)) then
tmp = t_0
else if (z <= 1.0d0) then
tmp = x * (1.0d0 - (-y * z))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = ((y - 1.0) * x) * z;
double tmp;
if (z <= -90.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = x * (1.0 - (-y * z));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = ((y - 1.0) * x) * z tmp = 0 if z <= -90.0: tmp = t_0 elif z <= 1.0: tmp = x * (1.0 - (-y * z)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(Float64(y - 1.0) * x) * z) tmp = 0.0 if (z <= -90.0) tmp = t_0; elseif (z <= 1.0) tmp = Float64(x * Float64(1.0 - Float64(Float64(-y) * z))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = ((y - 1.0) * x) * z; tmp = 0.0; if (z <= -90.0) tmp = t_0; elseif (z <= 1.0) tmp = x * (1.0 - (-y * z)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -90.0], t$95$0, If[LessEqual[z, 1.0], N[(x * N[(1.0 - N[((-y) * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(y - 1\right) \cdot x\right) \cdot z\\
\mathbf{if}\;z \leq -90:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x \cdot \left(1 - \left(-y\right) \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -90 or 1 < z Initial program 92.1%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites99.9%
Taylor expanded in z around inf
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lift--.f64N/A
lift-*.f6499.1
Applied rewrites99.1%
if -90 < z < 1Initial program 99.9%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6498.5
Applied rewrites98.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* (- 1.0 y) z))) (t_1 (* (* (- y 1.0) x) z))) (if (<= t_0 -2e+14) t_1 (if (<= t_0 2.0) (- x (* z x)) t_1))))
double code(double x, double y, double z) {
double t_0 = 1.0 - ((1.0 - y) * z);
double t_1 = ((y - 1.0) * x) * z;
double tmp;
if (t_0 <= -2e+14) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x - (z * x);
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - ((1.0d0 - y) * z)
t_1 = ((y - 1.0d0) * x) * z
if (t_0 <= (-2d+14)) then
tmp = t_1
else if (t_0 <= 2.0d0) then
tmp = x - (z * x)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - ((1.0 - y) * z);
double t_1 = ((y - 1.0) * x) * z;
double tmp;
if (t_0 <= -2e+14) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x - (z * x);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - ((1.0 - y) * z) t_1 = ((y - 1.0) * x) * z tmp = 0 if t_0 <= -2e+14: tmp = t_1 elif t_0 <= 2.0: tmp = x - (z * x) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(Float64(1.0 - y) * z)) t_1 = Float64(Float64(Float64(y - 1.0) * x) * z) tmp = 0.0 if (t_0 <= -2e+14) tmp = t_1; elseif (t_0 <= 2.0) tmp = Float64(x - Float64(z * x)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - ((1.0 - y) * z); t_1 = ((y - 1.0) * x) * z; tmp = 0.0; if (t_0 <= -2e+14) tmp = t_1; elseif (t_0 <= 2.0) tmp = x - (z * x); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+14], t$95$1, If[LessEqual[t$95$0, 2.0], N[(x - N[(z * x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \left(1 - y\right) \cdot z\\
t_1 := \left(\left(y - 1\right) \cdot x\right) \cdot z\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+14}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;x - z \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < -2e14 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) Initial program 93.4%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites97.1%
Taylor expanded in z around inf
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lift--.f64N/A
lift-*.f6496.5
Applied rewrites96.5%
if -2e14 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < 2Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites99.1%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6496.9
Applied rewrites96.9%
lift-+.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lift-*.f6496.9
Applied rewrites96.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma y (* z x) x))) (if (<= y -1.0) t_0 (if (<= y 0.0011) (- x (* z x)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(y, (z * x), x);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 0.0011) {
tmp = x - (z * x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(y, Float64(z * x), x) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 0.0011) tmp = Float64(x - Float64(z * x)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z * x), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 0.0011], N[(x - N[(z * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, z \cdot x, x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0011:\\
\;\;\;\;x - z \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 0.00110000000000000007 < y Initial program 91.9%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites96.0%
Taylor expanded in y around inf
Applied rewrites95.0%
if -1 < y < 0.00110000000000000007Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6499.3
Applied rewrites99.3%
lift-+.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lift-*.f6499.3
Applied rewrites99.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (* x y) z x))) (if (<= (- 1.0 y) -4e+18) t_0 (if (<= (- 1.0 y) 1.02) (- x (* z x)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma((x * y), z, x);
double tmp;
if ((1.0 - y) <= -4e+18) {
tmp = t_0;
} else if ((1.0 - y) <= 1.02) {
tmp = x - (z * x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(x * y), z, x) tmp = 0.0 if (Float64(1.0 - y) <= -4e+18) tmp = t_0; elseif (Float64(1.0 - y) <= 1.02) tmp = Float64(x - Float64(z * x)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[N[(1.0 - y), $MachinePrecision], -4e+18], t$95$0, If[LessEqual[N[(1.0 - y), $MachinePrecision], 1.02], N[(x - N[(z * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x \cdot y, z, x\right)\\
\mathbf{if}\;1 - y \leq -4 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;1 - y \leq 1.02:\\
\;\;\;\;x - z \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) y) < -4e18 or 1.02 < (-.f64 #s(literal 1 binary64) y) Initial program 91.6%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites92.4%
Taylor expanded in y around inf
lower-*.f6491.9
Applied rewrites91.9%
if -4e18 < (-.f64 #s(literal 1 binary64) y) < 1.02Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6497.9
Applied rewrites97.9%
lift-+.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lift-*.f6497.9
Applied rewrites97.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* y x) z))) (if (<= y -1.55e+90) t_0 (if (<= y 4e+16) (- x (* z x)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y * x) * z;
double tmp;
if (y <= -1.55e+90) {
tmp = t_0;
} else if (y <= 4e+16) {
tmp = x - (z * x);
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (y * x) * z
if (y <= (-1.55d+90)) then
tmp = t_0
else if (y <= 4d+16) then
tmp = x - (z * x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * x) * z;
double tmp;
if (y <= -1.55e+90) {
tmp = t_0;
} else if (y <= 4e+16) {
tmp = x - (z * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y * x) * z tmp = 0 if y <= -1.55e+90: tmp = t_0 elif y <= 4e+16: tmp = x - (z * x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y * x) * z) tmp = 0.0 if (y <= -1.55e+90) tmp = t_0; elseif (y <= 4e+16) tmp = Float64(x - Float64(z * x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * x) * z; tmp = 0.0; if (y <= -1.55e+90) tmp = t_0; elseif (y <= 4e+16) tmp = x - (z * x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -1.55e+90], t$95$0, If[LessEqual[y, 4e+16], N[(x - N[(z * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot x\right) \cdot z\\
\mathbf{if}\;y \leq -1.55 \cdot 10^{+90}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+16}:\\
\;\;\;\;x - z \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.54999999999999994e90 or 4e16 < y Initial program 90.7%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites91.4%
Taylor expanded in z around inf
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lift--.f64N/A
lift-*.f6475.6
Applied rewrites75.6%
Taylor expanded in y around inf
Applied rewrites75.6%
if -1.54999999999999994e90 < y < 4e16Initial program 99.5%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6492.7
Applied rewrites92.7%
lift-+.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lift-*.f6492.7
Applied rewrites92.7%
(FPCore (x y z) :precision binary64 (- x (* z x)))
double code(double x, double y, double z) {
return x - (z * 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 = x - (z * x)
end function
public static double code(double x, double y, double z) {
return x - (z * x);
}
def code(x, y, z): return x - (z * x)
function code(x, y, z) return Float64(x - Float64(z * x)) end
function tmp = code(x, y, z) tmp = x - (z * x); end
code[x_, y_, z_] := N[(x - N[(z * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot x
\end{array}
Initial program 95.9%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
Applied rewrites98.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6466.1
Applied rewrites66.1%
lift-+.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lift-*.f6466.1
Applied rewrites66.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- z)))) (if (<= z -1.0) t_0 (if (<= z 0.0055) x t_0))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 0.0055) {
tmp = x;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = x * -z
if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 0.0055d0) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 0.0055) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 0.0055: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -1.0) tmp = t_0; elseif (z <= 0.0055) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -1.0) tmp = t_0; elseif (z <= 0.0055) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 0.0055], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.0055:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 0.0054999999999999997 < z Initial program 92.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6491.0
Applied rewrites91.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6455.9
Applied rewrites55.9%
if -1 < z < 0.0054999999999999997Initial program 99.9%
Taylor expanded in z around 0
Applied rewrites74.7%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return 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 = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 95.9%
Taylor expanded in z around 0
Applied rewrites38.2%
herbie shell --seed 2025120
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"
:precision binary64
(* x (- 1.0 (* (- 1.0 y) z))))