
(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 9 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 (fabs (- y x)) 0.5 x))
double code(double x, double y) {
return fma(fabs((y - x)), 0.5, x);
}
function code(x, y) return fma(abs(Float64(y - x)), 0.5, x) end
code[x_, y_] := N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left|y - x\right|, 0.5, 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)) 2e-160) (* 0.5 x) (* 0.5 y)))
double code(double x, double y) {
double tmp;
if ((x + (fabs((y - x)) / 2.0)) <= 2e-160) {
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)) <= 2d-160) 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)) <= 2e-160) {
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)) <= 2e-160: 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)) <= 2e-160) 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)) <= 2e-160) 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], 2e-160], 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 2 \cdot 10^{-160}:\\
\;\;\;\;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))) < 2e-160Initial program 100.0%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt87.3
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6487.3
Applied rewrites87.3%
Taylor expanded in x around inf
lower-*.f6487.3
Applied rewrites87.3%
if 2e-160 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.9%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt40.5
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6440.5
Applied rewrites40.5%
Taylor expanded in x around 0
lower-*.f6434.2
Applied rewrites34.2%
(FPCore (x y) :precision binary64 (if (<= x -1.2e-84) (* 0.5 x) (if (<= x -7.5e-232) (* -0.5 y) (if (<= x 3.4e-214) (* 0.5 y) (* 1.5 x)))))
double code(double x, double y) {
double tmp;
if (x <= -1.2e-84) {
tmp = 0.5 * x;
} else if (x <= -7.5e-232) {
tmp = -0.5 * y;
} else if (x <= 3.4e-214) {
tmp = 0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.2d-84)) then
tmp = 0.5d0 * x
else if (x <= (-7.5d-232)) then
tmp = (-0.5d0) * y
else if (x <= 3.4d-214) then
tmp = 0.5d0 * y
else
tmp = 1.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.2e-84) {
tmp = 0.5 * x;
} else if (x <= -7.5e-232) {
tmp = -0.5 * y;
} else if (x <= 3.4e-214) {
tmp = 0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.2e-84: tmp = 0.5 * x elif x <= -7.5e-232: tmp = -0.5 * y elif x <= 3.4e-214: tmp = 0.5 * y else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.2e-84) tmp = Float64(0.5 * x); elseif (x <= -7.5e-232) tmp = Float64(-0.5 * y); elseif (x <= 3.4e-214) tmp = Float64(0.5 * y); else tmp = Float64(1.5 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.2e-84) tmp = 0.5 * x; elseif (x <= -7.5e-232) tmp = -0.5 * y; elseif (x <= 3.4e-214) tmp = 0.5 * y; else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.2e-84], N[(0.5 * x), $MachinePrecision], If[LessEqual[x, -7.5e-232], N[(-0.5 * y), $MachinePrecision], If[LessEqual[x, 3.4e-214], N[(0.5 * y), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-84}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq -7.5 \cdot 10^{-232}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{elif}\;x \leq 3.4 \cdot 10^{-214}:\\
\;\;\;\;0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if x < -1.20000000000000009e-84Initial program 100.0%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt90.8
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6490.8
Applied rewrites90.8%
Taylor expanded in x around inf
lower-*.f6475.1
Applied rewrites75.1%
if -1.20000000000000009e-84 < x < -7.5000000000000006e-232Initial program 99.9%
Applied rewrites55.8%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6457.2
Applied rewrites57.2%
if -7.5000000000000006e-232 < x < 3.3999999999999999e-214Initial program 100.0%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt64.4
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6464.4
Applied rewrites64.4%
Taylor expanded in x around 0
lower-*.f6464.2
Applied rewrites64.2%
if 3.3999999999999999e-214 < x Initial program 99.8%
Applied rewrites85.0%
Taylor expanded in x around inf
+-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f6463.9
Applied rewrites63.9%
(FPCore (x y) :precision binary64 (if (<= x -3.2e-84) (* (+ y x) 0.5) (if (<= x 1.4e-195) (fma (fabs (- y)) 0.5 x) (fma (- y x) -0.5 x))))
double code(double x, double y) {
double tmp;
if (x <= -3.2e-84) {
tmp = (y + x) * 0.5;
} else if (x <= 1.4e-195) {
tmp = fma(fabs(-y), 0.5, x);
} else {
tmp = fma((y - x), -0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -3.2e-84) tmp = Float64(Float64(y + x) * 0.5); elseif (x <= 1.4e-195) tmp = fma(abs(Float64(-y)), 0.5, x); else tmp = fma(Float64(y - x), -0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[x, -3.2e-84], N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 1.4e-195], N[(N[Abs[(-y)], $MachinePrecision] * 0.5 + x), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * -0.5 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{-84}:\\
\;\;\;\;\left(y + x\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-195}:\\
\;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - x, -0.5, x\right)\\
\end{array}
\end{array}
if x < -3.1999999999999999e-84Initial program 100.0%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt90.8
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6490.8
Applied rewrites90.8%
Taylor expanded in x around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6490.8
Applied rewrites90.8%
if -3.1999999999999999e-84 < x < 1.40000000000000002e-195Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites91.9%
if 1.40000000000000002e-195 < x Initial program 99.8%
Applied rewrites85.7%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6422.1
Applied rewrites22.1%
Taylor expanded in x around 0
Applied rewrites86.2%
(FPCore (x y) :precision binary64 (if (<= x -1.2e-84) (* (+ y x) 0.5) (if (<= x 1.4e-195) (* (fabs (- y x)) 0.5) (fma (- y x) -0.5 x))))
double code(double x, double y) {
double tmp;
if (x <= -1.2e-84) {
tmp = (y + x) * 0.5;
} else if (x <= 1.4e-195) {
tmp = fabs((y - x)) * 0.5;
} else {
tmp = fma((y - x), -0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.2e-84) tmp = Float64(Float64(y + x) * 0.5); elseif (x <= 1.4e-195) tmp = Float64(abs(Float64(y - x)) * 0.5); else tmp = fma(Float64(y - x), -0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.2e-84], N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 1.4e-195], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * -0.5 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-84}:\\
\;\;\;\;\left(y + x\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-195}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - x, -0.5, x\right)\\
\end{array}
\end{array}
if x < -1.20000000000000009e-84Initial program 100.0%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt90.8
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6490.8
Applied rewrites90.8%
Taylor expanded in x around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6490.8
Applied rewrites90.8%
if -1.20000000000000009e-84 < x < 1.40000000000000002e-195Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites91.1%
if 1.40000000000000002e-195 < x Initial program 99.8%
Applied rewrites85.7%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6422.1
Applied rewrites22.1%
Taylor expanded in x around 0
Applied rewrites86.2%
Final simplification89.0%
(FPCore (x y) :precision binary64 (if (<= y -9e-5) (* -0.5 y) (if (<= y 6e-189) (* 1.5 x) (* (+ y x) 0.5))))
double code(double x, double y) {
double tmp;
if (y <= -9e-5) {
tmp = -0.5 * y;
} else if (y <= 6e-189) {
tmp = 1.5 * x;
} else {
tmp = (y + x) * 0.5;
}
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 (y <= (-9d-5)) then
tmp = (-0.5d0) * y
else if (y <= 6d-189) then
tmp = 1.5d0 * x
else
tmp = (y + x) * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -9e-5) {
tmp = -0.5 * y;
} else if (y <= 6e-189) {
tmp = 1.5 * x;
} else {
tmp = (y + x) * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9e-5: tmp = -0.5 * y elif y <= 6e-189: tmp = 1.5 * x else: tmp = (y + x) * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= -9e-5) tmp = Float64(-0.5 * y); elseif (y <= 6e-189) tmp = Float64(1.5 * x); else tmp = Float64(Float64(y + x) * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -9e-5) tmp = -0.5 * y; elseif (y <= 6e-189) tmp = 1.5 * x; else tmp = (y + x) * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9e-5], N[(-0.5 * y), $MachinePrecision], If[LessEqual[y, 6e-189], N[(1.5 * x), $MachinePrecision], N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-5}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-189}:\\
\;\;\;\;1.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(y + x\right) \cdot 0.5\\
\end{array}
\end{array}
if y < -9.00000000000000057e-5Initial program 100.0%
Applied rewrites89.1%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6477.3
Applied rewrites77.3%
if -9.00000000000000057e-5 < y < 6e-189Initial program 99.9%
Applied rewrites64.2%
Taylor expanded in x around inf
+-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f6454.8
Applied rewrites54.8%
if 6e-189 < y Initial program 99.9%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt84.2
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6484.2
Applied rewrites84.2%
Taylor expanded in x around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6484.2
Applied rewrites84.2%
(FPCore (x y) :precision binary64 (if (<= y -8.5e-5) (* -0.5 y) (if (<= y 2.4e-117) (* 0.5 x) (* 0.5 y))))
double code(double x, double y) {
double tmp;
if (y <= -8.5e-5) {
tmp = -0.5 * y;
} else if (y <= 2.4e-117) {
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 (y <= (-8.5d-5)) then
tmp = (-0.5d0) * y
else if (y <= 2.4d-117) 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 (y <= -8.5e-5) {
tmp = -0.5 * y;
} else if (y <= 2.4e-117) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8.5e-5: tmp = -0.5 * y elif y <= 2.4e-117: tmp = 0.5 * x else: tmp = 0.5 * y return tmp
function code(x, y) tmp = 0.0 if (y <= -8.5e-5) tmp = Float64(-0.5 * y); elseif (y <= 2.4e-117) 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 (y <= -8.5e-5) tmp = -0.5 * y; elseif (y <= 2.4e-117) tmp = 0.5 * x; else tmp = 0.5 * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8.5e-5], N[(-0.5 * y), $MachinePrecision], If[LessEqual[y, 2.4e-117], N[(0.5 * x), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{-5}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-117}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\
\end{array}
\end{array}
if y < -8.500000000000001e-5Initial program 100.0%
Applied rewrites89.1%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6477.3
Applied rewrites77.3%
if -8.500000000000001e-5 < y < 2.40000000000000014e-117Initial program 99.9%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt49.1
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6449.1
Applied rewrites49.1%
Taylor expanded in x around inf
lower-*.f6446.9
Applied rewrites46.9%
if 2.40000000000000014e-117 < y Initial program 99.9%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt86.6
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6486.6
Applied rewrites86.6%
Taylor expanded in x around 0
lower-*.f6469.0
Applied rewrites69.0%
(FPCore (x y) :precision binary64 (if (<= y 6e-189) (fma (- y x) -0.5 x) (* (+ y x) 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 6e-189) {
tmp = fma((y - x), -0.5, x);
} else {
tmp = (y + x) * 0.5;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 6e-189) tmp = fma(Float64(y - x), -0.5, x); else tmp = Float64(Float64(y + x) * 0.5); end return tmp end
code[x_, y_] := If[LessEqual[y, 6e-189], N[(N[(y - x), $MachinePrecision] * -0.5 + x), $MachinePrecision], N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{-189}:\\
\;\;\;\;\mathsf{fma}\left(y - x, -0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y + x\right) \cdot 0.5\\
\end{array}
\end{array}
if y < 6e-189Initial program 99.9%
Applied rewrites73.9%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6440.5
Applied rewrites40.5%
Taylor expanded in x around 0
Applied rewrites78.8%
if 6e-189 < y Initial program 99.9%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt84.2
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6484.2
Applied rewrites84.2%
Taylor expanded in x around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6484.2
Applied rewrites84.2%
(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%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt53.3
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6453.3
Applied rewrites53.3%
Taylor expanded in x around inf
lower-*.f6430.1
Applied rewrites30.1%
herbie shell --seed 2024364
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))