
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\left(x + y\right) - x \cdot y
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\left(x + y\right) - x \cdot y
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (fmin x y) (fmax x y))))
(if (<= (- (+ (fmin x y) (fmax x y)) t_0) -5e-278)
(* (fmin x y) (- 1.0 (fmax x y)))
(- (fmax x y) t_0))))double code(double x, double y) {
double t_0 = fmin(x, y) * fmax(x, y);
double tmp;
if (((fmin(x, y) + fmax(x, y)) - t_0) <= -5e-278) {
tmp = fmin(x, y) * (1.0 - fmax(x, y));
} else {
tmp = fmax(x, y) - 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = fmin(x, y) * fmax(x, y)
if (((fmin(x, y) + fmax(x, y)) - t_0) <= (-5d-278)) then
tmp = fmin(x, y) * (1.0d0 - fmax(x, y))
else
tmp = fmax(x, y) - t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = fmin(x, y) * fmax(x, y);
double tmp;
if (((fmin(x, y) + fmax(x, y)) - t_0) <= -5e-278) {
tmp = fmin(x, y) * (1.0 - fmax(x, y));
} else {
tmp = fmax(x, y) - t_0;
}
return tmp;
}
def code(x, y): t_0 = fmin(x, y) * fmax(x, y) tmp = 0 if ((fmin(x, y) + fmax(x, y)) - t_0) <= -5e-278: tmp = fmin(x, y) * (1.0 - fmax(x, y)) else: tmp = fmax(x, y) - t_0 return tmp
function code(x, y) t_0 = Float64(fmin(x, y) * fmax(x, y)) tmp = 0.0 if (Float64(Float64(fmin(x, y) + fmax(x, y)) - t_0) <= -5e-278) tmp = Float64(fmin(x, y) * Float64(1.0 - fmax(x, y))); else tmp = Float64(fmax(x, y) - t_0); end return tmp end
function tmp_2 = code(x, y) t_0 = min(x, y) * max(x, y); tmp = 0.0; if (((min(x, y) + max(x, y)) - t_0) <= -5e-278) tmp = min(x, y) * (1.0 - max(x, y)); else tmp = max(x, y) - t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[Min[x, y], $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], -5e-278], N[(N[Min[x, y], $MachinePrecision] * N[(1.0 - N[Max[x, y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Max[x, y], $MachinePrecision] - t$95$0), $MachinePrecision]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right)\\
\mathbf{if}\;\left(\mathsf{min}\left(x, y\right) + \mathsf{max}\left(x, y\right)\right) - t\_0 \leq -5 \cdot 10^{-278}:\\
\;\;\;\;\mathsf{min}\left(x, y\right) \cdot \left(1 - \mathsf{max}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(x, y\right) - t\_0\\
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -4.9999999999999998e-278Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f6462.4%
Applied rewrites62.4%
if -4.9999999999999998e-278 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites62.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- (+ (fmin x y) (fmax x y)) (* (fmin x y) (fmax x y))))
(t_1 (* (fmin x y) (- 1.0 (fmax x y)))))
(if (<= t_0 -5e-278) t_1 (if (<= t_0 INFINITY) (fmax x y) t_1))))double code(double x, double y) {
double t_0 = (fmin(x, y) + fmax(x, y)) - (fmin(x, y) * fmax(x, y));
double t_1 = fmin(x, y) * (1.0 - fmax(x, y));
double tmp;
if (t_0 <= -5e-278) {
tmp = t_1;
} else if (t_0 <= ((double) INFINITY)) {
tmp = fmax(x, y);
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double x, double y) {
double t_0 = (fmin(x, y) + fmax(x, y)) - (fmin(x, y) * fmax(x, y));
double t_1 = fmin(x, y) * (1.0 - fmax(x, y));
double tmp;
if (t_0 <= -5e-278) {
tmp = t_1;
} else if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = fmax(x, y);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = (fmin(x, y) + fmax(x, y)) - (fmin(x, y) * fmax(x, y)) t_1 = fmin(x, y) * (1.0 - fmax(x, y)) tmp = 0 if t_0 <= -5e-278: tmp = t_1 elif t_0 <= math.inf: tmp = fmax(x, y) else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(Float64(fmin(x, y) + fmax(x, y)) - Float64(fmin(x, y) * fmax(x, y))) t_1 = Float64(fmin(x, y) * Float64(1.0 - fmax(x, y))) tmp = 0.0 if (t_0 <= -5e-278) tmp = t_1; elseif (t_0 <= Inf) tmp = fmax(x, y); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = (min(x, y) + max(x, y)) - (min(x, y) * max(x, y)); t_1 = min(x, y) * (1.0 - max(x, y)); tmp = 0.0; if (t_0 <= -5e-278) tmp = t_1; elseif (t_0 <= Inf) tmp = max(x, y); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[Min[x, y], $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision] - N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Min[x, y], $MachinePrecision] * N[(1.0 - N[Max[x, y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-278], t$95$1, If[LessEqual[t$95$0, Infinity], N[Max[x, y], $MachinePrecision], t$95$1]]]]
\begin{array}{l}
t_0 := \left(\mathsf{min}\left(x, y\right) + \mathsf{max}\left(x, y\right)\right) - \mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right)\\
t_1 := \mathsf{min}\left(x, y\right) \cdot \left(1 - \mathsf{max}\left(x, y\right)\right)\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{-278}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\mathsf{max}\left(x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -4.9999999999999998e-278 or +inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f6462.4%
Applied rewrites62.4%
if -4.9999999999999998e-278 < (-.f64 (+.f64 x y) (*.f64 x y)) < +inf.0Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f6462.4%
Applied rewrites62.4%
Taylor expanded in x around 0
Applied rewrites39.1%
(FPCore (x y)
:precision binary64
(if (<=
(- (+ (fmin x y) (fmax x y)) (* (fmin x y) (fmax x y)))
-5e-278)
(* (fmin x y) 1.0)
(fmax x y)))double code(double x, double y) {
double tmp;
if (((fmin(x, y) + fmax(x, y)) - (fmin(x, y) * fmax(x, y))) <= -5e-278) {
tmp = fmin(x, y) * 1.0;
} else {
tmp = fmax(x, 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((fmin(x, y) + fmax(x, y)) - (fmin(x, y) * fmax(x, y))) <= (-5d-278)) then
tmp = fmin(x, y) * 1.0d0
else
tmp = fmax(x, y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((fmin(x, y) + fmax(x, y)) - (fmin(x, y) * fmax(x, y))) <= -5e-278) {
tmp = fmin(x, y) * 1.0;
} else {
tmp = fmax(x, y);
}
return tmp;
}
def code(x, y): tmp = 0 if ((fmin(x, y) + fmax(x, y)) - (fmin(x, y) * fmax(x, y))) <= -5e-278: tmp = fmin(x, y) * 1.0 else: tmp = fmax(x, y) return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(fmin(x, y) + fmax(x, y)) - Float64(fmin(x, y) * fmax(x, y))) <= -5e-278) tmp = Float64(fmin(x, y) * 1.0); else tmp = fmax(x, y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((min(x, y) + max(x, y)) - (min(x, y) * max(x, y))) <= -5e-278) tmp = min(x, y) * 1.0; else tmp = max(x, y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(N[Min[x, y], $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision] - N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -5e-278], N[(N[Min[x, y], $MachinePrecision] * 1.0), $MachinePrecision], N[Max[x, y], $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left(\mathsf{min}\left(x, y\right) + \mathsf{max}\left(x, y\right)\right) - \mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right) \leq -5 \cdot 10^{-278}:\\
\;\;\;\;\mathsf{min}\left(x, y\right) \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(x, y\right)\\
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -4.9999999999999998e-278Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f6462.4%
Applied rewrites62.4%
Taylor expanded in y around 0
Applied rewrites38.7%
if -4.9999999999999998e-278 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f6462.4%
Applied rewrites62.4%
Taylor expanded in x around 0
Applied rewrites39.1%
(FPCore (x y) :precision binary64 (fmax x y))
double code(double x, double y) {
return fmax(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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = fmax(x, y)
end function
public static double code(double x, double y) {
return fmax(x, y);
}
def code(x, y): return fmax(x, y)
function code(x, y) return fmax(x, y) end
function tmp = code(x, y) tmp = max(x, y); end
code[x_, y_] := N[Max[x, y], $MachinePrecision]
\mathsf{max}\left(x, y\right)
Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f6462.4%
Applied rewrites62.4%
Taylor expanded in x around 0
Applied rewrites39.1%
herbie shell --seed 2025258
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))