
(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 y y (fma x x -0.5)) (fmax x y)))
double code(double x, double y) {
return fmax(fma(y, y, fma(x, x, -0.5)), fmax(x, y));
}
function code(x, y) return fmax(fma(y, y, fma(x, x, -0.5)), fmax(x, y)) end
code[x_, y_] := N[Max[N[(y * y + N[(x * x + -0.5), $MachinePrecision]), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, -0.5\right)\right), \mathsf{max}\left(x, y\right)\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
lift-+.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
associate--l+N/A
unpow2N/A
lower-fma.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(if (<=
(fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y))
50000000000000.0)
(fmax (fma y y -0.5) (fmax x y))
(fmax (fma y y (* 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)) <= 50000000000000.0) {
tmp = fmax(fma(y, y, -0.5), fmax(x, y));
} else {
tmp = fmax(fma(y, y, (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)) <= 50000000000000.0) tmp = fmax(fma(y, y, -0.5), fmax(x, y)); else tmp = fmax(fma(y, y, Float64(x * x)), 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], 50000000000000.0], N[Max[N[(y * y + -0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(y * y + N[(x * x), $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 50000000000000:\\
\;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(y, y, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(y, y, x \cdot x\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)) < 5e13Initial program 100.0%
Taylor expanded in x around 0
metadata-evalN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval98.9
Applied rewrites98.9%
if 5e13 < (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%
lift--.f64N/A
lift-+.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
associate--l+N/A
unpow2N/A
lower-fma.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Taylor expanded in x around inf
pow2N/A
lift-*.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)) 1e-119) (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)) <= 1e-119) {
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)) <= 1d-119) 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)) <= 1e-119) {
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)) <= 1e-119: 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)) <= 1e-119) 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)) <= 1e-119) 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], 1e-119], 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 10^{-119}:\\
\;\;\;\;\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)) < 1.00000000000000001e-119Initial program 100.0%
Taylor expanded in x around 0
metadata-evalN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites100.0%
if 1.00000000000000001e-119 < (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
unpow2N/A
lower-*.f6461.6
Applied rewrites61.6%
(FPCore (x y) :precision binary64 (if (or (<= x -2.2e+34) (not (<= x 4.2e+34))) (fmax (* x x) (fmax x y)) (fmax (fma y y -0.5) (fmax x y))))
double code(double x, double y) {
double tmp;
if ((x <= -2.2e+34) || !(x <= 4.2e+34)) {
tmp = fmax((x * x), fmax(x, y));
} else {
tmp = fmax(fma(y, y, -0.5), fmax(x, y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -2.2e+34) || !(x <= 4.2e+34)) tmp = fmax(Float64(x * x), fmax(x, y)); else tmp = fmax(fma(y, y, -0.5), fmax(x, y)); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -2.2e+34], N[Not[LessEqual[x, 4.2e+34]], $MachinePrecision]], N[Max[N[(x * x), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(y * y + -0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{+34} \lor \neg \left(x \leq 4.2 \cdot 10^{+34}\right):\\
\;\;\;\;\mathsf{max}\left(x \cdot x, \mathsf{max}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(y, y, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\
\end{array}
\end{array}
if x < -2.2000000000000002e34 or 4.20000000000000035e34 < x Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6490.8
Applied rewrites90.8%
if -2.2000000000000002e34 < x < 4.20000000000000035e34Initial program 100.0%
Taylor expanded in x around 0
metadata-evalN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval96.1
Applied rewrites96.1%
Final simplification93.8%
(FPCore (x y) :precision binary64 (if (or (<= y -9.6e+32) (not (<= y 4.5e+25))) (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 <= -9.6e+32) || !(y <= 4.5e+25)) {
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 <= -9.6e+32) || !(y <= 4.5e+25)) 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, -9.6e+32], N[Not[LessEqual[y, 4.5e+25]], $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 -9.6 \cdot 10^{+32} \lor \neg \left(y \leq 4.5 \cdot 10^{+25}\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 < -9.59999999999999965e32 or 4.5000000000000003e25 < y Initial program 100.0%
Taylor expanded in y around inf
unpow2N/A
lower-*.f6486.9
Applied rewrites86.9%
if -9.59999999999999965e32 < y < 4.5000000000000003e25Initial program 100.0%
Taylor expanded in y around 0
metadata-evalN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval96.6
Applied rewrites96.6%
Final simplification92.4%
(FPCore (x y) :precision binary64 (if (or (<= x -2.2e+34) (not (<= x 4.2e+34))) (fmax (* x x) (fmax x y)) (fmax (* y y) (fmax x y))))
double code(double x, double y) {
double tmp;
if ((x <= -2.2e+34) || !(x <= 4.2e+34)) {
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 <= (-2.2d+34)) .or. (.not. (x <= 4.2d+34))) 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 <= -2.2e+34) || !(x <= 4.2e+34)) {
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 <= -2.2e+34) or not (x <= 4.2e+34): 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 <= -2.2e+34) || !(x <= 4.2e+34)) 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 <= -2.2e+34) || ~((x <= 4.2e+34))) 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, -2.2e+34], N[Not[LessEqual[x, 4.2e+34]], $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 -2.2 \cdot 10^{+34} \lor \neg \left(x \leq 4.2 \cdot 10^{+34}\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 < -2.2000000000000002e34 or 4.20000000000000035e34 < x Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6490.8
Applied rewrites90.8%
if -2.2000000000000002e34 < x < 4.20000000000000035e34Initial program 100.0%
Taylor expanded in y around inf
unpow2N/A
lower-*.f6480.5
Applied rewrites80.5%
Final simplification85.0%
(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
metadata-evalN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval67.0
Applied rewrites67.0%
Taylor expanded in y around 0
Applied rewrites29.3%
herbie shell --seed 2025051
(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)))