
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((y - x)) / 2.0);
}
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 + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|y - x\right|}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((y - x)) / 2.0);
}
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 + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|y - x\right|}{2}
\end{array}
(FPCore (x y) :precision binary64 (fma 0.5 (fabs (- y x)) x))
double code(double x, double y) {
return fma(0.5, fabs((y - x)), x);
}
function code(x, y) return fma(0.5, abs(Float64(y - x)), x) end
code[x_, y_] := N[(0.5 * N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.5, \left|y - x\right|, x\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (+ x (/ (fabs (- y x)) 2.0)) 4e-239) (* 0.5 x) (fma y 0.5 x)))
double code(double x, double y) {
double tmp;
if ((x + (fabs((y - x)) / 2.0)) <= 4e-239) {
tmp = 0.5 * x;
} else {
tmp = fma(y, 0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(x + Float64(abs(Float64(y - x)) / 2.0)) <= 4e-239) tmp = Float64(0.5 * x); else tmp = fma(y, 0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], 4e-239], N[(0.5 * x), $MachinePrecision], N[(y * 0.5 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + \frac{\left|y - x\right|}{2} \leq 4 \cdot 10^{-239}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 0.5, x\right)\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < 4.0000000000000003e-239Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Applied rewrites98.7%
Taylor expanded in x around inf
Applied rewrites94.8%
if 4.0000000000000003e-239 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites99.9%
Applied rewrites43.2%
Taylor expanded in x around 0
Applied rewrites43.8%
(FPCore (x y) :precision binary64 (if (<= (+ x (/ (fabs (- y x)) 2.0)) 4e-201) (* 0.5 x) (* 0.5 y)))
double code(double x, double y) {
double tmp;
if ((x + (fabs((y - x)) / 2.0)) <= 4e-201) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * 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 ((x + (abs((y - x)) / 2.0d0)) <= 4d-201) then
tmp = 0.5d0 * x
else
tmp = 0.5d0 * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x + (Math.abs((y - x)) / 2.0)) <= 4e-201) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x + (math.fabs((y - x)) / 2.0)) <= 4e-201: tmp = 0.5 * x else: tmp = 0.5 * y return tmp
function code(x, y) tmp = 0.0 if (Float64(x + Float64(abs(Float64(y - x)) / 2.0)) <= 4e-201) tmp = Float64(0.5 * x); else tmp = Float64(0.5 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x + (abs((y - x)) / 2.0)) <= 4e-201) tmp = 0.5 * x; else tmp = 0.5 * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], 4e-201], N[(0.5 * x), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + \frac{\left|y - x\right|}{2} \leq 4 \cdot 10^{-201}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < 3.99999999999999978e-201Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Applied rewrites96.5%
Taylor expanded in x around inf
Applied rewrites92.7%
if 3.99999999999999978e-201 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites99.9%
Applied rewrites43.5%
Taylor expanded in x around 0
Applied rewrites38.1%
(FPCore (x y) :precision binary64 (if (<= x -1.15e-71) (* (+ y x) 0.5) (if (<= x 9e-68) (fma 0.5 (fabs (- y)) x) (fma 0.5 (fabs x) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.15e-71) {
tmp = (y + x) * 0.5;
} else if (x <= 9e-68) {
tmp = fma(0.5, fabs(-y), x);
} else {
tmp = fma(0.5, fabs(x), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.15e-71) tmp = Float64(Float64(y + x) * 0.5); elseif (x <= 9e-68) tmp = fma(0.5, abs(Float64(-y)), x); else tmp = fma(0.5, abs(x), x); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.15e-71], N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 9e-68], N[(0.5 * N[Abs[(-y)], $MachinePrecision] + x), $MachinePrecision], N[(0.5 * N[Abs[x], $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-71}:\\
\;\;\;\;\left(y + x\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-68}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|-y\right|, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|x\right|, x\right)\\
\end{array}
\end{array}
if x < -1.1499999999999999e-71Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Applied rewrites88.4%
Taylor expanded in x around 0
Applied rewrites88.4%
if -1.1499999999999999e-71 < x < 8.99999999999999998e-68Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites89.6%
if 8.99999999999999998e-68 < x Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites80.5%
(FPCore (x y) :precision binary64 (if (<= x -1.15e-71) (* (+ y x) 0.5) (if (<= x 9e-68) (* 0.5 (fabs (- y x))) (fma 0.5 (fabs x) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.15e-71) {
tmp = (y + x) * 0.5;
} else if (x <= 9e-68) {
tmp = 0.5 * fabs((y - x));
} else {
tmp = fma(0.5, fabs(x), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.15e-71) tmp = Float64(Float64(y + x) * 0.5); elseif (x <= 9e-68) tmp = Float64(0.5 * abs(Float64(y - x))); else tmp = fma(0.5, abs(x), x); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.15e-71], N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 9e-68], N[(0.5 * N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Abs[x], $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-71}:\\
\;\;\;\;\left(y + x\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-68}:\\
\;\;\;\;0.5 \cdot \left|y - x\right|\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|x\right|, x\right)\\
\end{array}
\end{array}
if x < -1.1499999999999999e-71Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Applied rewrites88.4%
Taylor expanded in x around 0
Applied rewrites88.4%
if -1.1499999999999999e-71 < x < 8.99999999999999998e-68Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites88.5%
if 8.99999999999999998e-68 < x Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites80.5%
Final simplification86.1%
(FPCore (x y) :precision binary64 (if (<= x -1.15e-71) (* (+ y x) 0.5) (if (<= x 9e-68) (* 0.5 (fabs (- y))) (fma 0.5 (fabs x) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.15e-71) {
tmp = (y + x) * 0.5;
} else if (x <= 9e-68) {
tmp = 0.5 * fabs(-y);
} else {
tmp = fma(0.5, fabs(x), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.15e-71) tmp = Float64(Float64(y + x) * 0.5); elseif (x <= 9e-68) tmp = Float64(0.5 * abs(Float64(-y))); else tmp = fma(0.5, abs(x), x); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.15e-71], N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 9e-68], N[(0.5 * N[Abs[(-y)], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Abs[x], $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-71}:\\
\;\;\;\;\left(y + x\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-68}:\\
\;\;\;\;0.5 \cdot \left|-y\right|\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|x\right|, x\right)\\
\end{array}
\end{array}
if x < -1.1499999999999999e-71Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Applied rewrites88.4%
Taylor expanded in x around 0
Applied rewrites88.4%
if -1.1499999999999999e-71 < x < 8.99999999999999998e-68Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites88.5%
Taylor expanded in x around 0
Applied rewrites87.7%
if 8.99999999999999998e-68 < x Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites80.5%
(FPCore (x y) :precision binary64 (if (<= x 1.3e-79) (* (+ y x) 0.5) (fma 0.5 (fabs x) x)))
double code(double x, double y) {
double tmp;
if (x <= 1.3e-79) {
tmp = (y + x) * 0.5;
} else {
tmp = fma(0.5, fabs(x), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= 1.3e-79) tmp = Float64(Float64(y + x) * 0.5); else tmp = fma(0.5, abs(x), x); end return tmp end
code[x_, y_] := If[LessEqual[x, 1.3e-79], N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[Abs[x], $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.3 \cdot 10^{-79}:\\
\;\;\;\;\left(y + x\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|x\right|, x\right)\\
\end{array}
\end{array}
if x < 1.29999999999999997e-79Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Applied rewrites74.2%
Taylor expanded in x around 0
Applied rewrites74.3%
if 1.29999999999999997e-79 < x Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites79.8%
(FPCore (x y) :precision binary64 (* (+ y x) 0.5))
double code(double x, double y) {
return (y + x) * 0.5;
}
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 = (y + x) * 0.5d0
end function
public static double code(double x, double y) {
return (y + x) * 0.5;
}
def code(x, y): return (y + x) * 0.5
function code(x, y) return Float64(Float64(y + x) * 0.5) end
function tmp = code(x, y) tmp = (y + x) * 0.5; end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x\right) \cdot 0.5
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites99.9%
Applied rewrites58.8%
Taylor expanded in x around 0
Applied rewrites58.8%
(FPCore (x y) :precision binary64 (* 0.5 x))
double code(double x, double y) {
return 0.5 * 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 * x
end function
public static double code(double x, double y) {
return 0.5 * x;
}
def code(x, y): return 0.5 * x
function code(x, y) return Float64(0.5 * x) end
function tmp = code(x, y) tmp = 0.5 * x; end
code[x_, y_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites99.9%
Applied rewrites58.8%
Taylor expanded in x around inf
Applied rewrites32.7%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites11.9%
herbie shell --seed 2025019
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))