
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x + 1} - \sqrt{x}
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x + 1} - \sqrt{x}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (pow (+ 1.0 x) 0.25)))
(if (<= x 850.0)
(fma t_0 t_0 (- (sqrt x)))
(/
(fma
-0.0390625
(pow x -2.5)
(fma
0.5
(sqrt x)
(fma (/ 1.0 (* (fabs x) (sqrt x))) 0.0625 (/ -0.125 (sqrt x)))))
x))))
double code(double x) {
double t_0 = pow((1.0 + x), 0.25);
double tmp;
if (x <= 850.0) {
tmp = fma(t_0, t_0, -sqrt(x));
} else {
tmp = fma(-0.0390625, pow(x, -2.5), fma(0.5, sqrt(x), fma((1.0 / (fabs(x) * sqrt(x))), 0.0625, (-0.125 / sqrt(x))))) / x;
}
return tmp;
}
function code(x) t_0 = Float64(1.0 + x) ^ 0.25 tmp = 0.0 if (x <= 850.0) tmp = fma(t_0, t_0, Float64(-sqrt(x))); else tmp = Float64(fma(-0.0390625, (x ^ -2.5), fma(0.5, sqrt(x), fma(Float64(1.0 / Float64(abs(x) * sqrt(x))), 0.0625, Float64(-0.125 / sqrt(x))))) / x); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 0.25], $MachinePrecision]}, If[LessEqual[x, 850.0], N[(t$95$0 * t$95$0 + (-N[Sqrt[x], $MachinePrecision])), $MachinePrecision], N[(N[(-0.0390625 * N[Power[x, -2.5], $MachinePrecision] + N[(0.5 * N[Sqrt[x], $MachinePrecision] + N[(N[(1.0 / N[(N[Abs[x], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.0625 + N[(-0.125 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(1 + x\right)}^{0.25}\\
\mathbf{if}\;x \leq 850:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_0, -\sqrt{x}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.0390625, {x}^{-2.5}, \mathsf{fma}\left(0.5, \sqrt{x}, \mathsf{fma}\left(\frac{1}{\left|x\right| \cdot \sqrt{x}}, 0.0625, \frac{-0.125}{\sqrt{x}}\right)\right)\right)}{x}\\
\end{array}
\end{array}
if x < 850Initial program 99.9%
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
lower-*.f64N/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-eval99.9
Applied rewrites99.9%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
pow1/2N/A
sqr-powN/A
lower-fma.f64N/A
metadata-evalN/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f64N/A
metadata-evalN/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f64N/A
distribute-lft-neg-outN/A
lift-pow.f64N/A
lift-pow.f64N/A
pow-prod-upN/A
metadata-evalN/A
pow1/2N/A
lower-neg.f64N/A
lift-sqrt.f6499.8
Applied rewrites99.8%
if 850 < x Initial program 5.9%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f6499.2
Applied rewrites99.2%
Taylor expanded in x around inf
lift-sqrt.f64N/A
lift-*.f6498.3
Applied rewrites98.3%
Taylor expanded in x around inf
Applied rewrites99.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (pow (+ 1.0 x) 0.25)))
(if (<= x 5400.0)
(fma t_0 t_0 (- (sqrt x)))
(/
(fma
(sqrt (/ 1.0 (* (* x x) x)))
0.0625
(fma 0.5 (sqrt x) (/ -0.125 (sqrt x))))
x))))
double code(double x) {
double t_0 = pow((1.0 + x), 0.25);
double tmp;
if (x <= 5400.0) {
tmp = fma(t_0, t_0, -sqrt(x));
} else {
tmp = fma(sqrt((1.0 / ((x * x) * x))), 0.0625, fma(0.5, sqrt(x), (-0.125 / sqrt(x)))) / x;
}
return tmp;
}
function code(x) t_0 = Float64(1.0 + x) ^ 0.25 tmp = 0.0 if (x <= 5400.0) tmp = fma(t_0, t_0, Float64(-sqrt(x))); else tmp = Float64(fma(sqrt(Float64(1.0 / Float64(Float64(x * x) * x))), 0.0625, fma(0.5, sqrt(x), Float64(-0.125 / sqrt(x)))) / x); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 0.25], $MachinePrecision]}, If[LessEqual[x, 5400.0], N[(t$95$0 * t$95$0 + (-N[Sqrt[x], $MachinePrecision])), $MachinePrecision], N[(N[(N[Sqrt[N[(1.0 / N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.0625 + N[(0.5 * N[Sqrt[x], $MachinePrecision] + N[(-0.125 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(1 + x\right)}^{0.25}\\
\mathbf{if}\;x \leq 5400:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_0, -\sqrt{x}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sqrt{\frac{1}{\left(x \cdot x\right) \cdot x}}, 0.0625, \mathsf{fma}\left(0.5, \sqrt{x}, \frac{-0.125}{\sqrt{x}}\right)\right)}{x}\\
\end{array}
\end{array}
if x < 5400Initial program 99.8%
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
lower-*.f64N/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-eval99.8
Applied rewrites99.8%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
pow1/2N/A
sqr-powN/A
lower-fma.f64N/A
metadata-evalN/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f64N/A
metadata-evalN/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f64N/A
distribute-lft-neg-outN/A
lift-pow.f64N/A
lift-pow.f64N/A
pow-prod-upN/A
metadata-evalN/A
pow1/2N/A
lower-neg.f64N/A
lift-sqrt.f6499.8
Applied rewrites99.8%
if 5400 < x Initial program 5.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6498.5
Applied rewrites98.5%
Taylor expanded in x around inf
pow1/2N/A
metadata-evalN/A
pow-prod-upN/A
lower-/.f64N/A
Applied rewrites99.5%
(FPCore (x)
:precision binary64
(if (<= x 6200.0)
(- (sqrt (+ x 1.0)) (sqrt x))
(/
(fma
(sqrt x)
0.5
(fma (/ 1.0 (* (fabs x) (sqrt x))) 0.0625 (/ -0.125 (sqrt x))))
x)))
double code(double x) {
double tmp;
if (x <= 6200.0) {
tmp = sqrt((x + 1.0)) - sqrt(x);
} else {
tmp = fma(sqrt(x), 0.5, fma((1.0 / (fabs(x) * sqrt(x))), 0.0625, (-0.125 / sqrt(x)))) / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 6200.0) tmp = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)); else tmp = Float64(fma(sqrt(x), 0.5, fma(Float64(1.0 / Float64(abs(x) * sqrt(x))), 0.0625, Float64(-0.125 / sqrt(x)))) / x); end return tmp end
code[x_] := If[LessEqual[x, 6200.0], N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[x], $MachinePrecision] * 0.5 + N[(N[(1.0 / N[(N[Abs[x], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.0625 + N[(-0.125 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6200:\\
\;\;\;\;\sqrt{x + 1} - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sqrt{x}, 0.5, \mathsf{fma}\left(\frac{1}{\left|x\right| \cdot \sqrt{x}}, 0.0625, \frac{-0.125}{\sqrt{x}}\right)\right)}{x}\\
\end{array}
\end{array}
if x < 6200Initial program 99.8%
if 6200 < x Initial program 5.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6498.5
Applied rewrites98.5%
Taylor expanded in x around inf
pow1/2N/A
metadata-evalN/A
pow-prod-upN/A
lower-/.f64N/A
Applied rewrites99.6%
Applied rewrites99.6%
(FPCore (x)
:precision binary64
(if (<= x 6200.0)
(- (sqrt (+ x 1.0)) (sqrt x))
(/
(fma
(sqrt (/ 1.0 (* (* x x) x)))
0.0625
(fma 0.5 (sqrt x) (/ -0.125 (sqrt x))))
x)))
double code(double x) {
double tmp;
if (x <= 6200.0) {
tmp = sqrt((x + 1.0)) - sqrt(x);
} else {
tmp = fma(sqrt((1.0 / ((x * x) * x))), 0.0625, fma(0.5, sqrt(x), (-0.125 / sqrt(x)))) / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 6200.0) tmp = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)); else tmp = Float64(fma(sqrt(Float64(1.0 / Float64(Float64(x * x) * x))), 0.0625, fma(0.5, sqrt(x), Float64(-0.125 / sqrt(x)))) / x); end return tmp end
code[x_] := If[LessEqual[x, 6200.0], N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(1.0 / N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.0625 + N[(0.5 * N[Sqrt[x], $MachinePrecision] + N[(-0.125 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6200:\\
\;\;\;\;\sqrt{x + 1} - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sqrt{\frac{1}{\left(x \cdot x\right) \cdot x}}, 0.0625, \mathsf{fma}\left(0.5, \sqrt{x}, \frac{-0.125}{\sqrt{x}}\right)\right)}{x}\\
\end{array}
\end{array}
if x < 6200Initial program 99.8%
if 6200 < x Initial program 5.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6498.5
Applied rewrites98.5%
Taylor expanded in x around inf
pow1/2N/A
metadata-evalN/A
pow-prod-upN/A
lower-/.f64N/A
Applied rewrites99.6%
(FPCore (x) :precision binary64 (if (<= x 128000.0) (- (sqrt (+ x 1.0)) (sqrt x)) (/ (fma 0.5 (sqrt x) (/ -0.125 (sqrt x))) x)))
double code(double x) {
double tmp;
if (x <= 128000.0) {
tmp = sqrt((x + 1.0)) - sqrt(x);
} else {
tmp = fma(0.5, sqrt(x), (-0.125 / sqrt(x))) / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 128000.0) tmp = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)); else tmp = Float64(fma(0.5, sqrt(x), Float64(-0.125 / sqrt(x))) / x); end return tmp end
code[x_] := If[LessEqual[x, 128000.0], N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Sqrt[x], $MachinePrecision] + N[(-0.125 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 128000:\\
\;\;\;\;\sqrt{x + 1} - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.5, \sqrt{x}, \frac{-0.125}{\sqrt{x}}\right)}{x}\\
\end{array}
\end{array}
if x < 128000Initial program 99.7%
if 128000 < x Initial program 5.3%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f6499.5
Applied rewrites99.5%
pow1/299.5
metadata-eval99.5
pow-prod-up99.5
Applied rewrites99.5%
(FPCore (x) :precision binary64 (if (<= x 49000000.0) (- (sqrt (+ x 1.0)) (sqrt x)) (* (sqrt (/ 1.0 x)) 0.5)))
double code(double x) {
double tmp;
if (x <= 49000000.0) {
tmp = sqrt((x + 1.0)) - sqrt(x);
} else {
tmp = sqrt((1.0 / x)) * 0.5;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 49000000.0d0) then
tmp = sqrt((x + 1.0d0)) - sqrt(x)
else
tmp = sqrt((1.0d0 / x)) * 0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 49000000.0) {
tmp = Math.sqrt((x + 1.0)) - Math.sqrt(x);
} else {
tmp = Math.sqrt((1.0 / x)) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 49000000.0: tmp = math.sqrt((x + 1.0)) - math.sqrt(x) else: tmp = math.sqrt((1.0 / x)) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 49000000.0) tmp = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)); else tmp = Float64(sqrt(Float64(1.0 / x)) * 0.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 49000000.0) tmp = sqrt((x + 1.0)) - sqrt(x); else tmp = sqrt((1.0 / x)) * 0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 49000000.0], N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 49000000:\\
\;\;\;\;\sqrt{x + 1} - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{x}} \cdot 0.5\\
\end{array}
\end{array}
if x < 4.9e7Initial program 99.4%
if 4.9e7 < x Initial program 4.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6499.2
Applied rewrites99.2%
lift-/.f64N/A
lift-sqrt.f64N/A
metadata-evalN/A
sqrt-divN/A
lower-sqrt.f64N/A
lower-/.f6499.4
Applied rewrites99.4%
(FPCore (x) :precision binary64 (if (<= x 0.36) (- 1.0 (sqrt x)) (* (sqrt (/ 1.0 x)) 0.5)))
double code(double x) {
double tmp;
if (x <= 0.36) {
tmp = 1.0 - sqrt(x);
} else {
tmp = sqrt((1.0 / x)) * 0.5;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.36d0) then
tmp = 1.0d0 - sqrt(x)
else
tmp = sqrt((1.0d0 / x)) * 0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.36) {
tmp = 1.0 - Math.sqrt(x);
} else {
tmp = Math.sqrt((1.0 / x)) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.36: tmp = 1.0 - math.sqrt(x) else: tmp = math.sqrt((1.0 / x)) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 0.36) tmp = Float64(1.0 - sqrt(x)); else tmp = Float64(sqrt(Float64(1.0 / x)) * 0.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.36) tmp = 1.0 - sqrt(x); else tmp = sqrt((1.0 / x)) * 0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.36], N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.36:\\
\;\;\;\;1 - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{x}} \cdot 0.5\\
\end{array}
\end{array}
if x < 0.35999999999999999Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.1%
if 0.35999999999999999 < x Initial program 6.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6497.5
Applied rewrites97.5%
lift-/.f64N/A
lift-sqrt.f64N/A
metadata-evalN/A
sqrt-divN/A
lower-sqrt.f64N/A
lower-/.f6497.7
Applied rewrites97.7%
(FPCore (x) :precision binary64 (if (<= x 0.36) (- 1.0 (sqrt x)) (/ 0.5 (sqrt x))))
double code(double x) {
double tmp;
if (x <= 0.36) {
tmp = 1.0 - sqrt(x);
} else {
tmp = 0.5 / sqrt(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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.36d0) then
tmp = 1.0d0 - sqrt(x)
else
tmp = 0.5d0 / sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.36) {
tmp = 1.0 - Math.sqrt(x);
} else {
tmp = 0.5 / Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.36: tmp = 1.0 - math.sqrt(x) else: tmp = 0.5 / math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (x <= 0.36) tmp = Float64(1.0 - sqrt(x)); else tmp = Float64(0.5 / sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.36) tmp = 1.0 - sqrt(x); else tmp = 0.5 / sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.36], N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(0.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.36:\\
\;\;\;\;1 - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\sqrt{x}}\\
\end{array}
\end{array}
if x < 0.35999999999999999Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.1%
if 0.35999999999999999 < x Initial program 6.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6497.5
Applied rewrites97.5%
pow1/297.5
metadata-eval97.5
pow-prod-up97.5
lift-*.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
associate-*l/N/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6497.5
Applied rewrites97.5%
(FPCore (x) :precision binary64 (- 1.0 (sqrt x)))
double code(double x) {
return 1.0 - sqrt(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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 1.0d0 - sqrt(x)
end function
public static double code(double x) {
return 1.0 - Math.sqrt(x);
}
def code(x): return 1.0 - math.sqrt(x)
function code(x) return Float64(1.0 - sqrt(x)) end
function tmp = code(x) tmp = 1.0 - sqrt(x); end
code[x_] := N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{x}
\end{array}
Initial program 52.4%
Taylor expanded in x around 0
Applied rewrites48.8%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 52.4%
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
lower-*.f64N/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-eval52.3
Applied rewrites52.3%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
sqr-abs-revN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
Applied rewrites52.3%
Taylor expanded in x around inf
*-commutativeN/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
metadata-evalN/A
sqrt-pow2N/A
mul-1-negN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
sqrt-pow2N/A
Applied rewrites3.5%
*-commutative3.5
+-commutative3.5
fp-cancel-sub-sign-inv3.5
+-commutative3.5
rem-square-sqrt3.5
pow1/23.5
metadata-eval3.5
pow-prod-up3.5
lift-*.f64N/A
mul0-lft3.5
Applied rewrites3.5%
herbie shell --seed 2025130
(FPCore (x)
:name "Main:bigenough3 from C"
:precision binary64
(- (sqrt (+ x 1.0)) (sqrt x)))