
(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 11 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
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (+ x (/ (fabs (- y x)) 2.0)) -4e-295) (* 0.5 x) (fma (- x y) 0.5 x)))
double code(double x, double y) {
double tmp;
if ((x + (fabs((y - x)) / 2.0)) <= -4e-295) {
tmp = 0.5 * x;
} else {
tmp = fma((x - y), 0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(x + Float64(abs(Float64(y - x)) / 2.0)) <= -4e-295) tmp = Float64(0.5 * x); else tmp = fma(Float64(x - 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-295], N[(0.5 * x), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + \frac{\left|y - x\right|}{2} \leq -4 \cdot 10^{-295}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - y, 0.5, x\right)\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < -4.00000000000000024e-295Initial program 100.0%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-fabs.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites31.7%
lift-pow.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6431.7
Applied rewrites31.7%
Taylor expanded in x around 0
rem-sqrt-square-revN/A
sqrt-unprodN/A
rem-square-sqrtN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6494.8
Applied rewrites94.8%
Taylor expanded in x around inf
lower-*.f6495.0
Applied rewrites95.0%
if -4.00000000000000024e-295 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.8%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-fabs.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites35.8%
lift-pow.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6435.8
Applied rewrites35.8%
Taylor expanded in x around 0
+-commutativeN/A
rem-sqrt-square-revN/A
sqrt-unprodN/A
rem-square-sqrtN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6468.6
Applied rewrites68.6%
(FPCore (x y) :precision binary64 (if (<= x -5.8) (* (- x y) 0.5) (if (<= x 2.8e-66) (fma 0.5 (fabs (- y)) x) (fma 1.5 x (* -0.5 y)))))
double code(double x, double y) {
double tmp;
if (x <= -5.8) {
tmp = (x - y) * 0.5;
} else if (x <= 2.8e-66) {
tmp = fma(0.5, fabs(-y), x);
} else {
tmp = fma(1.5, x, (-0.5 * y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -5.8) tmp = Float64(Float64(x - y) * 0.5); elseif (x <= 2.8e-66) tmp = fma(0.5, abs(Float64(-y)), x); else tmp = fma(1.5, x, Float64(-0.5 * y)); end return tmp end
code[x_, y_] := If[LessEqual[x, -5.8], N[(N[(x - y), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 2.8e-66], N[(0.5 * N[Abs[(-y)], $MachinePrecision] + x), $MachinePrecision], N[(1.5 * x + N[(-0.5 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8:\\
\;\;\;\;\left(x - y\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-66}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|-y\right|, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1.5, x, -0.5 \cdot y\right)\\
\end{array}
\end{array}
if x < -5.79999999999999982Initial program 100.0%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-fabs.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites19.0%
lift-pow.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6418.9
Applied rewrites18.9%
Taylor expanded in x around 0
rem-sqrt-square-revN/A
sqrt-unprodN/A
rem-square-sqrtN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6485.3
Applied rewrites85.3%
if -5.79999999999999982 < x < 2.8e-66Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6484.3
Applied rewrites84.3%
if 2.8e-66 < x Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.7
Applied rewrites99.7%
lift--.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift--.f64N/A
lower-sqrt.f64N/A
lift--.f6490.5
Applied rewrites90.5%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-*.f6491.1
Applied rewrites91.1%
(FPCore (x y) :precision binary64 (if (<= x -5.8) (* (- x y) 0.5) (if (<= x 2.8e-66) (fma 0.5 (fabs (- y)) x) (fma (- x y) 0.5 x))))
double code(double x, double y) {
double tmp;
if (x <= -5.8) {
tmp = (x - y) * 0.5;
} else if (x <= 2.8e-66) {
tmp = fma(0.5, fabs(-y), x);
} else {
tmp = fma((x - y), 0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -5.8) tmp = Float64(Float64(x - y) * 0.5); elseif (x <= 2.8e-66) tmp = fma(0.5, abs(Float64(-y)), x); else tmp = fma(Float64(x - y), 0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[x, -5.8], N[(N[(x - y), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 2.8e-66], N[(0.5 * N[Abs[(-y)], $MachinePrecision] + x), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8:\\
\;\;\;\;\left(x - y\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-66}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|-y\right|, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - y, 0.5, x\right)\\
\end{array}
\end{array}
if x < -5.79999999999999982Initial program 100.0%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-fabs.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites19.0%
lift-pow.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6418.9
Applied rewrites18.9%
Taylor expanded in x around 0
rem-sqrt-square-revN/A
sqrt-unprodN/A
rem-square-sqrtN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6485.3
Applied rewrites85.3%
if -5.79999999999999982 < x < 2.8e-66Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6484.3
Applied rewrites84.3%
if 2.8e-66 < x Initial program 99.7%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-fabs.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites32.2%
lift-pow.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6432.2
Applied rewrites32.2%
Taylor expanded in x around 0
+-commutativeN/A
rem-sqrt-square-revN/A
sqrt-unprodN/A
rem-square-sqrtN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6490.8
Applied rewrites90.8%
(FPCore (x y) :precision binary64 (if (<= x -1.1e-131) (* (- x y) 0.5) (if (<= x 2.8e-66) (* 0.5 (fabs (- y x))) (fma (- x y) 0.5 x))))
double code(double x, double y) {
double tmp;
if (x <= -1.1e-131) {
tmp = (x - y) * 0.5;
} else if (x <= 2.8e-66) {
tmp = 0.5 * fabs((y - x));
} else {
tmp = fma((x - y), 0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.1e-131) tmp = Float64(Float64(x - y) * 0.5); elseif (x <= 2.8e-66) tmp = Float64(0.5 * abs(Float64(y - x))); else tmp = fma(Float64(x - y), 0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.1e-131], N[(N[(x - y), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 2.8e-66], N[(0.5 * N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-131}:\\
\;\;\;\;\left(x - y\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-66}:\\
\;\;\;\;0.5 \cdot \left|y - x\right|\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - y, 0.5, x\right)\\
\end{array}
\end{array}
if x < -1.1e-131Initial program 100.0%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-fabs.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites37.0%
lift-pow.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6437.0
Applied rewrites37.0%
Taylor expanded in x around 0
rem-sqrt-square-revN/A
sqrt-unprodN/A
rem-square-sqrtN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6479.0
Applied rewrites79.0%
if -1.1e-131 < x < 2.8e-66Initial program 100.0%
Taylor expanded in x around 0
lower-*.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6487.8
Applied rewrites87.8%
if 2.8e-66 < x Initial program 99.7%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-fabs.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites32.2%
lift-pow.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6432.2
Applied rewrites32.2%
Taylor expanded in x around 0
+-commutativeN/A
rem-sqrt-square-revN/A
sqrt-unprodN/A
rem-square-sqrtN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6490.8
Applied rewrites90.8%
Final simplification85.6%
(FPCore (x y) :precision binary64 (if (<= x -7.5e+21) (* 0.5 x) (if (<= x 9.7e-178) (* -0.5 y) (* 1.5 x))))
double code(double x, double y) {
double tmp;
if (x <= -7.5e+21) {
tmp = 0.5 * x;
} else if (x <= 9.7e-178) {
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 <= (-7.5d+21)) then
tmp = 0.5d0 * x
else if (x <= 9.7d-178) 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 <= -7.5e+21) {
tmp = 0.5 * x;
} else if (x <= 9.7e-178) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.5e+21: tmp = 0.5 * x elif x <= 9.7e-178: tmp = -0.5 * y else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (x <= -7.5e+21) tmp = Float64(0.5 * x); elseif (x <= 9.7e-178) 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 <= -7.5e+21) tmp = 0.5 * x; elseif (x <= 9.7e-178) tmp = -0.5 * y; else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.5e+21], N[(0.5 * x), $MachinePrecision], If[LessEqual[x, 9.7e-178], N[(-0.5 * y), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+21}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq 9.7 \cdot 10^{-178}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if x < -7.5e21Initial program 100.0%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-fabs.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites18.2%
lift-pow.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6418.2
Applied rewrites18.2%
Taylor expanded in x around 0
rem-sqrt-square-revN/A
sqrt-unprodN/A
rem-square-sqrtN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6484.5
Applied rewrites84.5%
Taylor expanded in x around inf
lower-*.f6477.4
Applied rewrites77.4%
if -7.5e21 < x < 9.7000000000000003e-178Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64100.0
Applied rewrites100.0%
lift--.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift--.f64N/A
lower-sqrt.f64N/A
lift--.f6445.4
Applied rewrites45.4%
Taylor expanded in x around 0
lower-*.f6445.0
Applied rewrites45.0%
if 9.7000000000000003e-178 < x Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.7
Applied rewrites99.7%
lift--.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift--.f64N/A
lower-sqrt.f64N/A
lift--.f6485.8
Applied rewrites85.8%
Taylor expanded in x around inf
lower-*.f6468.8
Applied rewrites68.8%
(FPCore (x y) :precision binary64 (if (<= x 1.6e-69) (* (- x y) 0.5) (* 1.5 x)))
double code(double x, double y) {
double tmp;
if (x <= 1.6e-69) {
tmp = (x - y) * 0.5;
} 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.6d-69) then
tmp = (x - y) * 0.5d0
else
tmp = 1.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.6e-69) {
tmp = (x - y) * 0.5;
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.6e-69: tmp = (x - y) * 0.5 else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (x <= 1.6e-69) tmp = Float64(Float64(x - y) * 0.5); else tmp = Float64(1.5 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.6e-69) tmp = (x - y) * 0.5; else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.6e-69], N[(N[(x - y), $MachinePrecision] * 0.5), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.6 \cdot 10^{-69}:\\
\;\;\;\;\left(x - y\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if x < 1.59999999999999999e-69Initial program 100.0%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-fabs.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites35.6%
lift-pow.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6435.6
Applied rewrites35.6%
Taylor expanded in x around 0
rem-sqrt-square-revN/A
sqrt-unprodN/A
rem-square-sqrtN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6464.6
Applied rewrites64.6%
if 1.59999999999999999e-69 < x Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.7
Applied rewrites99.7%
lift--.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift--.f64N/A
lower-sqrt.f64N/A
lift--.f6489.4
Applied rewrites89.4%
Taylor expanded in x around inf
lower-*.f6475.0
Applied rewrites75.0%
(FPCore (x y) :precision binary64 (if (<= y -3.5e-30) (* -0.5 y) (fma 0.5 (fabs x) x)))
double code(double x, double y) {
double tmp;
if (y <= -3.5e-30) {
tmp = -0.5 * y;
} else {
tmp = fma(0.5, fabs(x), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -3.5e-30) tmp = Float64(-0.5 * y); else tmp = fma(0.5, abs(x), x); end return tmp end
code[x_, y_] := If[LessEqual[y, -3.5e-30], N[(-0.5 * y), $MachinePrecision], N[(0.5 * N[Abs[x], $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{-30}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|x\right|, x\right)\\
\end{array}
\end{array}
if y < -3.5000000000000003e-30Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.9
Applied rewrites99.9%
lift--.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift--.f64N/A
lower-sqrt.f64N/A
lift--.f6488.8
Applied rewrites88.8%
Taylor expanded in x around 0
lower-*.f6474.5
Applied rewrites74.5%
if -3.5000000000000003e-30 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites58.1%
(FPCore (x y) :precision binary64 (if (<= y -4.5e-67) (* -0.5 y) (* 1.5 x)))
double code(double x, double y) {
double tmp;
if (y <= -4.5e-67) {
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 (y <= (-4.5d-67)) 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 (y <= -4.5e-67) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.5e-67: tmp = -0.5 * y else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (y <= -4.5e-67) 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 (y <= -4.5e-67) tmp = -0.5 * y; else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.5e-67], N[(-0.5 * y), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-67}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if y < -4.50000000000000015e-67Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.9
Applied rewrites99.9%
lift--.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift--.f64N/A
lower-sqrt.f64N/A
lift--.f6488.7
Applied rewrites88.7%
Taylor expanded in x around 0
lower-*.f6471.6
Applied rewrites71.6%
if -4.50000000000000015e-67 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.9
Applied rewrites99.9%
lift--.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift--.f64N/A
lower-sqrt.f64N/A
lift--.f6433.7
Applied rewrites33.7%
Taylor expanded in x around inf
lower-*.f6435.5
Applied rewrites35.5%
(FPCore (x y) :precision binary64 (if (<= y -1e-223) (* -0.5 y) x))
double code(double x, double y) {
double tmp;
if (y <= -1e-223) {
tmp = -0.5 * y;
} else {
tmp = 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 (y <= (-1d-223)) then
tmp = (-0.5d0) * y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1e-223) {
tmp = -0.5 * y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1e-223: tmp = -0.5 * y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if (y <= -1e-223) tmp = Float64(-0.5 * y); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1e-223) tmp = -0.5 * y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1e-223], N[(-0.5 * y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-223}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9.9999999999999997e-224Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
fabs-subN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-subN/A
lower-fabs.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.8
Applied rewrites99.8%
lift--.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift--.f64N/A
lower-sqrt.f64N/A
lift--.f6480.4
Applied rewrites80.4%
Taylor expanded in x around 0
lower-*.f6458.8
Applied rewrites58.8%
if -9.9999999999999997e-224 < y Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites12.0%
(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.0%
herbie shell --seed 2025043
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))