
(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 6 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%
lift--.f64N/A
lift-+.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
+-commutativeN/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)) 1e+15) (fmax (fma y y -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)) <= 1e+15) {
tmp = fmax(fma(y, y, -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)) <= 1e+15) tmp = fmax(fma(y, y, -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], 1e+15], N[Max[N[(y * y + -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 10^{+15}:\\
\;\;\;\;\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(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)) < 1e15Initial 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%
if 1e15 < (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
+-commutativeN/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 y 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)) 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
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 rewrites98.7%
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
unpow2N/A
lower-*.f6456.6
Applied rewrites56.6%
(FPCore (x y) :precision binary64 (if (or (<= x -1120000000.0) (not (<= x 4.6e+101))) (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 <= -1120000000.0) || !(x <= 4.6e+101)) {
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 <= -1120000000.0) || !(x <= 4.6e+101)) 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, -1120000000.0], N[Not[LessEqual[x, 4.6e+101]], $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 -1120000000 \lor \neg \left(x \leq 4.6 \cdot 10^{+101}\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 < -1.12e9 or 4.6000000000000003e101 < x Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6493.4
Applied rewrites93.4%
if -1.12e9 < x < 4.6000000000000003e101Initial 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-eval91.8
Applied rewrites91.8%
Final simplification92.4%
(FPCore (x y) :precision binary64 (if (or (<= y -6.4e+63) (not (<= y 25000000.0))) (fmax (* y y) (fmax x y)) (fmax (* x x) (fmax x y))))
double code(double x, double y) {
double tmp;
if ((y <= -6.4e+63) || !(y <= 25000000.0)) {
tmp = fmax((y * y), 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 ((y <= (-6.4d+63)) .or. (.not. (y <= 25000000.0d0))) then
tmp = fmax((y * y), 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 ((y <= -6.4e+63) || !(y <= 25000000.0)) {
tmp = fmax((y * y), fmax(x, y));
} else {
tmp = fmax((x * x), fmax(x, y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.4e+63) or not (y <= 25000000.0): tmp = fmax((y * y), fmax(x, y)) else: tmp = fmax((x * x), fmax(x, y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.4e+63) || !(y <= 25000000.0)) tmp = fmax(Float64(y * y), 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 ((y <= -6.4e+63) || ~((y <= 25000000.0))) tmp = max((y * y), max(x, y)); else tmp = max((x * x), max(x, y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.4e+63], N[Not[LessEqual[y, 25000000.0]], $MachinePrecision]], N[Max[N[(y * y), $MachinePrecision], 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}\;y \leq -6.4 \cdot 10^{+63} \lor \neg \left(y \leq 25000000\right):\\
\;\;\;\;\mathsf{max}\left(y \cdot y, \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 y < -6.40000000000000022e63 or 2.5e7 < y Initial program 100.0%
Taylor expanded in y around inf
unpow2N/A
lower-*.f6490.2
Applied rewrites90.2%
if -6.40000000000000022e63 < y < 2.5e7Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6484.7
Applied rewrites84.7%
Final simplification87.2%
(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.3
Applied rewrites67.3%
Taylor expanded in y around 0
Applied rewrites27.0%
herbie shell --seed 2025080
(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)))