
(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 9 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}
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
:precision binary64
(*
x_s
(if (<= x_m 5e-56)
(fma (* (- y 1.0) x_m) z x_m)
(fma (* (- y 1.0) z) x_m x_m))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 5e-56) {
tmp = fma(((y - 1.0) * x_m), z, x_m);
} else {
tmp = fma(((y - 1.0) * z), x_m, x_m);
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (x_m <= 5e-56) tmp = fma(Float64(Float64(y - 1.0) * x_m), z, x_m); else tmp = fma(Float64(Float64(y - 1.0) * z), x_m, x_m); end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 5e-56], N[(N[(N[(y - 1.0), $MachinePrecision] * x$95$m), $MachinePrecision] * z + x$95$m), $MachinePrecision], N[(N[(N[(y - 1.0), $MachinePrecision] * z), $MachinePrecision] * x$95$m + x$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 5 \cdot 10^{-56}:\\
\;\;\;\;\mathsf{fma}\left(\left(y - 1\right) \cdot x\_m, z, x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(y - 1\right) \cdot z, x\_m, x\_m\right)\\
\end{array}
\end{array}
if x < 4.99999999999999997e-56Initial program 96.4%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift--.f64N/A
sub-negate-revN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.9
Applied rewrites95.9%
if 4.99999999999999997e-56 < x Initial program 96.4%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift--.f64N/A
sub-negate-revN/A
lower-*.f64N/A
lower--.f6496.4
Applied rewrites96.4%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
:precision binary64
(let* ((t_0 (fma (* x_m y) z x_m)) (t_1 (- 1.0 (* (- 1.0 y) z))))
(*
x_s
(if (<= t_1 (- INFINITY))
t_0
(if (<= t_1 -5000000.0)
(* x_m (- (* z y) z))
(if (<= t_1 400.0)
(* x_m (- 1.0 z))
(if (<= t_1 2e+294) (* x_m (* z (- y 1.0))) t_0)))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double t_0 = fma((x_m * y), z, x_m);
double t_1 = 1.0 - ((1.0 - y) * z);
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = t_0;
} else if (t_1 <= -5000000.0) {
tmp = x_m * ((z * y) - z);
} else if (t_1 <= 400.0) {
tmp = x_m * (1.0 - z);
} else if (t_1 <= 2e+294) {
tmp = x_m * (z * (y - 1.0));
} else {
tmp = t_0;
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) t_0 = fma(Float64(x_m * y), z, x_m) t_1 = Float64(1.0 - Float64(Float64(1.0 - y) * z)) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = t_0; elseif (t_1 <= -5000000.0) tmp = Float64(x_m * Float64(Float64(z * y) - z)); elseif (t_1 <= 400.0) tmp = Float64(x_m * Float64(1.0 - z)); elseif (t_1 <= 2e+294) tmp = Float64(x_m * Float64(z * Float64(y - 1.0))); else tmp = t_0; end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(N[(x$95$m * y), $MachinePrecision] * z + x$95$m), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$1, (-Infinity)], t$95$0, If[LessEqual[t$95$1, -5000000.0], N[(x$95$m * N[(N[(z * y), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 400.0], N[(x$95$m * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+294], N[(x$95$m * N[(z * N[(y - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]), $MachinePrecision]]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x\_m \cdot y, z, x\_m\right)\\
t_1 := 1 - \left(1 - y\right) \cdot z\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq -5000000:\\
\;\;\;\;x\_m \cdot \left(z \cdot y - z\right)\\
\mathbf{elif}\;t\_1 \leq 400:\\
\;\;\;\;x\_m \cdot \left(1 - z\right)\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+294}:\\
\;\;\;\;x\_m \cdot \left(z \cdot \left(y - 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < -inf.0 or 2.00000000000000013e294 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) Initial program 96.4%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift--.f64N/A
sub-negate-revN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.9
Applied rewrites95.9%
Taylor expanded in y around inf
lower-*.f6471.9
Applied rewrites71.9%
if -inf.0 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < -5e6Initial program 96.4%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6459.1
Applied rewrites59.1%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
lift-*.f64N/A
add-flipN/A
distribute-lft-neg-outN/A
remove-double-negN/A
*-lft-identityN/A
lower--.f6459.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.1
Applied rewrites59.1%
if -5e6 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < 400Initial program 96.4%
Taylor expanded in y around 0
Applied rewrites66.6%
if 400 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < 2.00000000000000013e294Initial program 96.4%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6459.1
Applied rewrites59.1%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
:precision binary64
(let* ((t_0 (fma (* x_m y) z x_m))
(t_1 (* x_m (* z (- y 1.0))))
(t_2 (- 1.0 (* (- 1.0 y) z))))
(*
x_s
(if (<= t_2 (- INFINITY))
t_0
(if (<= t_2 -5000000.0)
t_1
(if (<= t_2 400.0) (* x_m (- 1.0 z)) (if (<= t_2 2e+294) t_1 t_0)))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double t_0 = fma((x_m * y), z, x_m);
double t_1 = x_m * (z * (y - 1.0));
double t_2 = 1.0 - ((1.0 - y) * z);
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = t_0;
} else if (t_2 <= -5000000.0) {
tmp = t_1;
} else if (t_2 <= 400.0) {
tmp = x_m * (1.0 - z);
} else if (t_2 <= 2e+294) {
tmp = t_1;
} else {
tmp = t_0;
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) t_0 = fma(Float64(x_m * y), z, x_m) t_1 = Float64(x_m * Float64(z * Float64(y - 1.0))) t_2 = Float64(1.0 - Float64(Float64(1.0 - y) * z)) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = t_0; elseif (t_2 <= -5000000.0) tmp = t_1; elseif (t_2 <= 400.0) tmp = Float64(x_m * Float64(1.0 - z)); elseif (t_2 <= 2e+294) tmp = t_1; else tmp = t_0; end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(N[(x$95$m * y), $MachinePrecision] * z + x$95$m), $MachinePrecision]}, Block[{t$95$1 = N[(x$95$m * N[(z * N[(y - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$2, (-Infinity)], t$95$0, If[LessEqual[t$95$2, -5000000.0], t$95$1, If[LessEqual[t$95$2, 400.0], N[(x$95$m * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2e+294], t$95$1, t$95$0]]]]), $MachinePrecision]]]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x\_m \cdot y, z, x\_m\right)\\
t_1 := x\_m \cdot \left(z \cdot \left(y - 1\right)\right)\\
t_2 := 1 - \left(1 - y\right) \cdot z\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_2 \leq -5000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 400:\\
\;\;\;\;x\_m \cdot \left(1 - z\right)\\
\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{+294}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < -inf.0 or 2.00000000000000013e294 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) Initial program 96.4%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift--.f64N/A
sub-negate-revN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.9
Applied rewrites95.9%
Taylor expanded in y around inf
lower-*.f6471.9
Applied rewrites71.9%
if -inf.0 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < -5e6 or 400 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < 2.00000000000000013e294Initial program 96.4%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6459.1
Applied rewrites59.1%
if -5e6 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < 400Initial program 96.4%
Taylor expanded in y around 0
Applied rewrites66.6%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (fma (* (- y 1.0) x_m) z x_m)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
return x_s * fma(((y - 1.0) * x_m), z, x_m);
}
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) return Float64(x_s * fma(Float64(Float64(y - 1.0) * x_m), z, x_m)) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(N[(N[(y - 1.0), $MachinePrecision] * x$95$m), $MachinePrecision] * z + x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \mathsf{fma}\left(\left(y - 1\right) \cdot x\_m, z, x\_m\right)
\end{array}
Initial program 96.4%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift--.f64N/A
sub-negate-revN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.9
Applied rewrites95.9%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (let* ((t_0 (fma (* x_m y) z x_m))) (* x_s (if (<= y -600.0) t_0 (if (<= y 1.0) (fma (- z) x_m x_m) t_0)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double t_0 = fma((x_m * y), z, x_m);
double tmp;
if (y <= -600.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = fma(-z, x_m, x_m);
} else {
tmp = t_0;
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) t_0 = fma(Float64(x_m * y), z, x_m) tmp = 0.0 if (y <= -600.0) tmp = t_0; elseif (y <= 1.0) tmp = fma(Float64(-z), x_m, x_m); else tmp = t_0; end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(N[(x$95$m * y), $MachinePrecision] * z + x$95$m), $MachinePrecision]}, N[(x$95$s * If[LessEqual[y, -600.0], t$95$0, If[LessEqual[y, 1.0], N[((-z) * x$95$m + x$95$m), $MachinePrecision], t$95$0]]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x\_m \cdot y, z, x\_m\right)\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -600:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(-z, x\_m, x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if y < -600 or 1 < y Initial program 96.4%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift--.f64N/A
sub-negate-revN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.9
Applied rewrites95.9%
Taylor expanded in y around inf
lower-*.f6471.9
Applied rewrites71.9%
if -600 < y < 1Initial program 96.4%
Taylor expanded in y around 0
Applied rewrites66.6%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-neg.f6466.6
Applied rewrites66.6%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
:precision binary64
(let* ((t_0 (* x_m (* y z))))
(*
x_s
(if (<= y -1.2e+81) t_0 (if (<= y 8.2e+68) (fma (- z) x_m x_m) t_0)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double t_0 = x_m * (y * z);
double tmp;
if (y <= -1.2e+81) {
tmp = t_0;
} else if (y <= 8.2e+68) {
tmp = fma(-z, x_m, x_m);
} else {
tmp = t_0;
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) t_0 = Float64(x_m * Float64(y * z)) tmp = 0.0 if (y <= -1.2e+81) tmp = t_0; elseif (y <= 8.2e+68) tmp = fma(Float64(-z), x_m, x_m); else tmp = t_0; end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(x$95$m * N[(y * z), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[y, -1.2e+81], t$95$0, If[LessEqual[y, 8.2e+68], N[((-z) * x$95$m + x$95$m), $MachinePrecision], t$95$0]]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := x\_m \cdot \left(y \cdot z\right)\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+68}:\\
\;\;\;\;\mathsf{fma}\left(-z, x\_m, x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if y < -1.19999999999999995e81 or 8.1999999999999998e68 < y Initial program 96.4%
Taylor expanded in y around inf
lower-*.f6435.8
Applied rewrites35.8%
if -1.19999999999999995e81 < y < 8.1999999999999998e68Initial program 96.4%
Taylor expanded in y around 0
Applied rewrites66.6%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-neg.f6466.6
Applied rewrites66.6%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (let* ((t_0 (* x_m (* y z)))) (* x_s (if (<= y -1.2e+81) t_0 (if (<= y 8.2e+68) (* x_m (- 1.0 z)) t_0)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double t_0 = x_m * (y * z);
double tmp;
if (y <= -1.2e+81) {
tmp = t_0;
} else if (y <= 8.2e+68) {
tmp = x_m * (1.0 - z);
} else {
tmp = t_0;
}
return x_s * tmp;
}
x\_m = private
x\_s = private
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_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x_m * (y * z)
if (y <= (-1.2d+81)) then
tmp = t_0
else if (y <= 8.2d+68) then
tmp = x_m * (1.0d0 - z)
else
tmp = t_0
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double t_0 = x_m * (y * z);
double tmp;
if (y <= -1.2e+81) {
tmp = t_0;
} else if (y <= 8.2e+68) {
tmp = x_m * (1.0 - z);
} else {
tmp = t_0;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): t_0 = x_m * (y * z) tmp = 0 if y <= -1.2e+81: tmp = t_0 elif y <= 8.2e+68: tmp = x_m * (1.0 - z) else: tmp = t_0 return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) t_0 = Float64(x_m * Float64(y * z)) tmp = 0.0 if (y <= -1.2e+81) tmp = t_0; elseif (y <= 8.2e+68) tmp = Float64(x_m * Float64(1.0 - z)); else tmp = t_0; end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) t_0 = x_m * (y * z); tmp = 0.0; if (y <= -1.2e+81) tmp = t_0; elseif (y <= 8.2e+68) tmp = x_m * (1.0 - z); else tmp = t_0; end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(x$95$m * N[(y * z), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[y, -1.2e+81], t$95$0, If[LessEqual[y, 8.2e+68], N[(x$95$m * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], t$95$0]]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := x\_m \cdot \left(y \cdot z\right)\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+68}:\\
\;\;\;\;x\_m \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if y < -1.19999999999999995e81 or 8.1999999999999998e68 < y Initial program 96.4%
Taylor expanded in y around inf
lower-*.f6435.8
Applied rewrites35.8%
if -1.19999999999999995e81 < y < 8.1999999999999998e68Initial program 96.4%
Taylor expanded in y around 0
Applied rewrites66.6%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (* x_m (- 1.0 z))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
return x_s * (x_m * (1.0 - z));
}
x\_m = private
x\_s = private
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_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * (x_m * (1.0d0 - z))
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
return x_s * (x_m * (1.0 - z));
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): return x_s * (x_m * (1.0 - z))
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) return Float64(x_s * Float64(x_m * Float64(1.0 - z))) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m, y, z) tmp = x_s * (x_m * (1.0 - z)); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(x$95$m * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \left(x\_m \cdot \left(1 - z\right)\right)
\end{array}
Initial program 96.4%
Taylor expanded in y around 0
Applied rewrites66.6%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (* x_m 1.0)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
return x_s * (x_m * 1.0);
}
x\_m = private
x\_s = private
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_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * (x_m * 1.0d0)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
return x_s * (x_m * 1.0);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): return x_s * (x_m * 1.0)
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) return Float64(x_s * Float64(x_m * 1.0)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m, y, z) tmp = x_s * (x_m * 1.0); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(x$95$m * 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \left(x\_m \cdot 1\right)
\end{array}
Initial program 96.4%
Taylor expanded in y around 0
Applied rewrites66.6%
Taylor expanded in z around 0
Applied rewrites39.3%
herbie shell --seed 2025149
(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))))