
(FPCore (x y) :precision binary64 (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)))
double code(double x, double y) {
return fmax(((pow(y, 2.0) + pow(x, 2.0)) - 0.5), 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((((y ** 2.0d0) + (x ** 2.0d0)) - 0.5d0), fmax(x, y))
end function
public static double code(double x, double y) {
return fmax(((Math.pow(y, 2.0) + Math.pow(x, 2.0)) - 0.5), fmax(x, y));
}
def code(x, y): return fmax(((math.pow(y, 2.0) + math.pow(x, 2.0)) - 0.5), fmax(x, y))
function code(x, y) return fmax(Float64(Float64((y ^ 2.0) + (x ^ 2.0)) - 0.5), fmax(x, y)) end
function tmp = code(x, y) tmp = max((((y ^ 2.0) + (x ^ 2.0)) - 0.5), max(x, y)); end
code[x_, y_] := N[Max[N[(N[(N[Power[y, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)))
double code(double x, double y) {
return fmax(((pow(y, 2.0) + pow(x, 2.0)) - 0.5), 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((((y ** 2.0d0) + (x ** 2.0d0)) - 0.5d0), fmax(x, y))
end function
public static double code(double x, double y) {
return fmax(((Math.pow(y, 2.0) + Math.pow(x, 2.0)) - 0.5), fmax(x, y));
}
def code(x, y): return fmax(((math.pow(y, 2.0) + math.pow(x, 2.0)) - 0.5), fmax(x, y))
function code(x, y) return fmax(Float64(Float64((y ^ 2.0) + (x ^ 2.0)) - 0.5), fmax(x, y)) end
function tmp = code(x, y) tmp = max((((y ^ 2.0) + (x ^ 2.0)) - 0.5), max(x, y)); end
code[x_, y_] := N[Max[N[(N[(N[Power[y, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right)
\end{array}
(FPCore (x y) :precision binary64 (fmax (fma x x (fma y y -0.5)) (fmax x y)))
double code(double x, double y) {
return fmax(fma(x, x, fma(y, y, -0.5)), fmax(x, y));
}
function code(x, y) return fmax(fma(x, x, fma(y, y, -0.5)), fmax(x, y)) end
code[x_, y_] := N[Max[N[(x * x + N[(y * y + -0.5), $MachinePrecision]), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, -0.5\right)\right), \mathsf{max}\left(x, y\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)) 500000000.0) (fmax (fma x x -0.5) (fmax x y)) (fmax (fma x x (* y y)) (fmax x y))))
double code(double x, double y) {
double tmp;
if (fmax(((pow(y, 2.0) + pow(x, 2.0)) - 0.5), fmax(x, y)) <= 500000000.0) {
tmp = fmax(fma(x, x, -0.5), fmax(x, y));
} else {
tmp = fmax(fma(x, x, (y * y)), fmax(x, y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (fmax(Float64(Float64((y ^ 2.0) + (x ^ 2.0)) - 0.5), fmax(x, y)) <= 500000000.0) tmp = fmax(fma(x, x, -0.5), fmax(x, y)); else tmp = fmax(fma(x, x, Float64(y * y)), fmax(x, y)); end return tmp end
code[x_, y_] := If[LessEqual[N[Max[N[(N[(N[Power[y, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], 500000000.0], N[Max[N[(x * x + -0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(x * x + N[(y * y), $MachinePrecision]), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \leq 500000000:\\
\;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, y \cdot y\right), \mathsf{max}\left(x, y\right)\right)\\
\end{array}
\end{array}
if (fmax.f64 (-.f64 (+.f64 (pow.f64 y #s(literal 2 binary64)) (pow.f64 x #s(literal 2 binary64))) #s(literal 1/2 binary64)) (fmax.f64 x y)) < 5e8Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.6%
if 5e8 < (fmax.f64 (-.f64 (+.f64 (pow.f64 y #s(literal 2 binary64)) (pow.f64 x #s(literal 2 binary64))) #s(literal 1/2 binary64)) (fmax.f64 x y)) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites99.9%
(FPCore (x y) :precision binary64 (if (<= (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)) 2.0) (fmax -0.5 (fmax x y)) (fmax (* x x) (fmax x y))))
double code(double x, double y) {
double tmp;
if (fmax(((pow(y, 2.0) + pow(x, 2.0)) - 0.5), fmax(x, y)) <= 2.0) {
tmp = fmax(-0.5, fmax(x, y));
} else {
tmp = fmax((x * x), 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 (fmax((((y ** 2.0d0) + (x ** 2.0d0)) - 0.5d0), fmax(x, y)) <= 2.0d0) then
tmp = fmax((-0.5d0), fmax(x, y))
else
tmp = fmax((x * x), fmax(x, y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (fmax(((Math.pow(y, 2.0) + Math.pow(x, 2.0)) - 0.5), fmax(x, y)) <= 2.0) {
tmp = fmax(-0.5, fmax(x, y));
} else {
tmp = fmax((x * x), fmax(x, y));
}
return tmp;
}
def code(x, y): tmp = 0 if fmax(((math.pow(y, 2.0) + math.pow(x, 2.0)) - 0.5), fmax(x, y)) <= 2.0: tmp = fmax(-0.5, fmax(x, y)) else: tmp = fmax((x * x), fmax(x, y)) return tmp
function code(x, y) tmp = 0.0 if (fmax(Float64(Float64((y ^ 2.0) + (x ^ 2.0)) - 0.5), fmax(x, y)) <= 2.0) tmp = fmax(-0.5, fmax(x, y)); else tmp = fmax(Float64(x * x), fmax(x, y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (max((((y ^ 2.0) + (x ^ 2.0)) - 0.5), max(x, y)) <= 2.0) tmp = max(-0.5, max(x, y)); else tmp = max((x * x), max(x, y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Max[N[(N[(N[Power[y, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], 2.0], N[Max[-0.5, N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(x * x), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \leq 2:\\
\;\;\;\;\mathsf{max}\left(-0.5, \mathsf{max}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(x \cdot x, \mathsf{max}\left(x, y\right)\right)\\
\end{array}
\end{array}
if (fmax.f64 (-.f64 (+.f64 (pow.f64 y #s(literal 2 binary64)) (pow.f64 x #s(literal 2 binary64))) #s(literal 1/2 binary64)) (fmax.f64 x y)) < 2Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.8%
Taylor expanded in y around 0
Applied rewrites98.8%
if 2 < (fmax.f64 (-.f64 (+.f64 (pow.f64 y #s(literal 2 binary64)) (pow.f64 x #s(literal 2 binary64))) #s(literal 1/2 binary64)) (fmax.f64 x y)) Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites51.8%
(FPCore (x y) :precision binary64 (if (or (<= y -22500000.0) (not (<= y 1.85e+85))) (fmax (* y y) (fmax x y)) (fmax (fma x x -0.5) (fmax x y))))
double code(double x, double y) {
double tmp;
if ((y <= -22500000.0) || !(y <= 1.85e+85)) {
tmp = fmax((y * y), fmax(x, y));
} else {
tmp = fmax(fma(x, x, -0.5), fmax(x, y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -22500000.0) || !(y <= 1.85e+85)) tmp = fmax(Float64(y * y), fmax(x, y)); else tmp = fmax(fma(x, x, -0.5), fmax(x, y)); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -22500000.0], N[Not[LessEqual[y, 1.85e+85]], $MachinePrecision]], N[Max[N[(y * y), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(x * x + -0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -22500000 \lor \neg \left(y \leq 1.85 \cdot 10^{+85}\right):\\
\;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\
\end{array}
\end{array}
if y < -2.25e7 or 1.8500000000000001e85 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites88.9%
if -2.25e7 < y < 1.8500000000000001e85Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites94.3%
Final simplification91.9%
(FPCore (x y)
:precision binary64
(if (<= y -1.5)
(fmax (fma y y -0.5) (fmax x y))
(if (<= y 1.85e+85)
(fmax (fma x x -0.5) (fmax x y))
(fmax (* y y) (fmax x y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.5) {
tmp = fmax(fma(y, y, -0.5), fmax(x, y));
} else if (y <= 1.85e+85) {
tmp = fmax(fma(x, x, -0.5), fmax(x, y));
} else {
tmp = fmax((y * y), fmax(x, y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.5) tmp = fmax(fma(y, y, -0.5), fmax(x, y)); elseif (y <= 1.85e+85) tmp = fmax(fma(x, x, -0.5), fmax(x, y)); else tmp = fmax(Float64(y * y), fmax(x, y)); end return tmp end
code[x_, y_] := If[LessEqual[y, -1.5], N[Max[N[(y * y + -0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], If[LessEqual[y, 1.85e+85], N[Max[N[(x * x + -0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(y * y), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5:\\
\;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(y, y, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+85}:\\
\;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\
\end{array}
\end{array}
if y < -1.5Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites84.8%
if -1.5 < y < 1.8500000000000001e85Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites94.9%
if 1.8500000000000001e85 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites93.8%
(FPCore (x y) :precision binary64 (if (or (<= x -7.5e+125) (not (<= x 1.4e+45))) (fmax (* x x) (fmax x y)) (fmax (* y y) (fmax x y))))
double code(double x, double y) {
double tmp;
if ((x <= -7.5e+125) || !(x <= 1.4e+45)) {
tmp = fmax((x * x), fmax(x, y));
} else {
tmp = fmax((y * y), 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 ((x <= (-7.5d+125)) .or. (.not. (x <= 1.4d+45))) then
tmp = fmax((x * x), fmax(x, y))
else
tmp = fmax((y * y), fmax(x, y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -7.5e+125) || !(x <= 1.4e+45)) {
tmp = fmax((x * x), fmax(x, y));
} else {
tmp = fmax((y * y), fmax(x, y));
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -7.5e+125) or not (x <= 1.4e+45): tmp = fmax((x * x), fmax(x, y)) else: tmp = fmax((y * y), fmax(x, y)) return tmp
function code(x, y) tmp = 0.0 if ((x <= -7.5e+125) || !(x <= 1.4e+45)) tmp = fmax(Float64(x * x), fmax(x, y)); else tmp = fmax(Float64(y * y), fmax(x, y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -7.5e+125) || ~((x <= 1.4e+45))) tmp = max((x * x), max(x, y)); else tmp = max((y * y), max(x, y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -7.5e+125], N[Not[LessEqual[x, 1.4e+45]], $MachinePrecision]], N[Max[N[(x * x), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(y * y), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+125} \lor \neg \left(x \leq 1.4 \cdot 10^{+45}\right):\\
\;\;\;\;\mathsf{max}\left(x \cdot x, \mathsf{max}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\
\end{array}
\end{array}
if x < -7.5000000000000006e125 or 1.4e45 < x Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites90.8%
if -7.5000000000000006e125 < x < 1.4e45Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites83.1%
Final simplification85.8%
(FPCore (x y) :precision binary64 (fmax -0.5 (fmax x y)))
double code(double x, double y) {
return fmax(-0.5, 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((-0.5d0), fmax(x, y))
end function
public static double code(double x, double y) {
return fmax(-0.5, fmax(x, y));
}
def code(x, y): return fmax(-0.5, fmax(x, y))
function code(x, y) return fmax(-0.5, fmax(x, y)) end
function tmp = code(x, y) tmp = max(-0.5, max(x, y)); end
code[x_, y_] := N[Max[-0.5, N[Max[x, y], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(-0.5, \mathsf{max}\left(x, y\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites69.1%
Taylor expanded in y around 0
Applied rewrites29.2%
herbie shell --seed 2025020
(FPCore (x y)
:name "A quarter-circle in the lower-left quadrant"
:precision binary64
(fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)))