
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.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 = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.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 = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
(FPCore (x)
:precision binary64
(/
(/
(fma
-0.125
(pow x -0.5)
(fma -0.0390625 (pow x -2.5) (fma 0.0625 (pow x -1.5) (* 0.5 (sqrt x)))))
x)
(* (sqrt x) (sqrt (+ x 1.0)))))
double code(double x) {
return (fma(-0.125, pow(x, -0.5), fma(-0.0390625, pow(x, -2.5), fma(0.0625, pow(x, -1.5), (0.5 * sqrt(x))))) / x) / (sqrt(x) * sqrt((x + 1.0)));
}
function code(x) return Float64(Float64(fma(-0.125, (x ^ -0.5), fma(-0.0390625, (x ^ -2.5), fma(0.0625, (x ^ -1.5), Float64(0.5 * sqrt(x))))) / x) / Float64(sqrt(x) * sqrt(Float64(x + 1.0)))) end
code[x_] := N[(N[(N[(-0.125 * N[Power[x, -0.5], $MachinePrecision] + N[(-0.0390625 * N[Power[x, -2.5], $MachinePrecision] + N[(0.0625 * N[Power[x, -1.5], $MachinePrecision] + N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\mathsf{fma}\left(-0.125, {x}^{-0.5}, \mathsf{fma}\left(-0.0390625, {x}^{-2.5}, \mathsf{fma}\left(0.0625, {x}^{-1.5}, 0.5 \cdot \sqrt{x}\right)\right)\right)}{x}}{\sqrt{x} \cdot \sqrt{x + 1}}
\end{array}
Initial program 37.6%
lift--.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
frac-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-+.f6437.7
Applied rewrites37.7%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites99.1%
(FPCore (x) :precision binary64 (/ (/ (fma -0.125 (pow x -0.5) (fma 0.0625 (pow x -1.5) (* 0.5 (sqrt x)))) x) (* (sqrt x) (sqrt (+ x 1.0)))))
double code(double x) {
return (fma(-0.125, pow(x, -0.5), fma(0.0625, pow(x, -1.5), (0.5 * sqrt(x)))) / x) / (sqrt(x) * sqrt((x + 1.0)));
}
function code(x) return Float64(Float64(fma(-0.125, (x ^ -0.5), fma(0.0625, (x ^ -1.5), Float64(0.5 * sqrt(x)))) / x) / Float64(sqrt(x) * sqrt(Float64(x + 1.0)))) end
code[x_] := N[(N[(N[(-0.125 * N[Power[x, -0.5], $MachinePrecision] + N[(0.0625 * N[Power[x, -1.5], $MachinePrecision] + N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\mathsf{fma}\left(-0.125, {x}^{-0.5}, \mathsf{fma}\left(0.0625, {x}^{-1.5}, 0.5 \cdot \sqrt{x}\right)\right)}{x}}{\sqrt{x} \cdot \sqrt{x + 1}}
\end{array}
Initial program 37.6%
lift--.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
frac-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-+.f6437.7
Applied rewrites37.7%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites98.9%
(FPCore (x) :precision binary64 (/ (fma (pow x -0.5) 0.5 (- (/ (* (/ 1.0 (sqrt x)) 0.375) x))) x))
double code(double x) {
return fma(pow(x, -0.5), 0.5, -(((1.0 / sqrt(x)) * 0.375) / x)) / x;
}
function code(x) return Float64(fma((x ^ -0.5), 0.5, Float64(-Float64(Float64(Float64(1.0 / sqrt(x)) * 0.375) / x))) / x) end
code[x_] := N[(N[(N[Power[x, -0.5], $MachinePrecision] * 0.5 + (-N[(N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * 0.375), $MachinePrecision] / x), $MachinePrecision])), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left({x}^{-0.5}, 0.5, -\frac{\frac{1}{\sqrt{x}} \cdot 0.375}{x}\right)}{x}
\end{array}
Initial program 37.6%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites82.6%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites98.6%
lift-pow.f64N/A
metadata-evalN/A
sqrt-pow2N/A
inv-powN/A
lower-/.f64N/A
lift-sqrt.f6498.6
Applied rewrites98.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ x 1.0))))
(if (<= x 100000000.0)
(/ (/ (- t_0 (sqrt x)) (sqrt x)) t_0)
(/ (/ (* 0.5 (sqrt x)) x) x))))
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if (x <= 100000000.0) {
tmp = ((t_0 - sqrt(x)) / sqrt(x)) / t_0;
} else {
tmp = ((0.5 * sqrt(x)) / x) / 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) :: t_0
real(8) :: tmp
t_0 = sqrt((x + 1.0d0))
if (x <= 100000000.0d0) then
tmp = ((t_0 - sqrt(x)) / sqrt(x)) / t_0
else
tmp = ((0.5d0 * sqrt(x)) / x) / x
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((x + 1.0));
double tmp;
if (x <= 100000000.0) {
tmp = ((t_0 - Math.sqrt(x)) / Math.sqrt(x)) / t_0;
} else {
tmp = ((0.5 * Math.sqrt(x)) / x) / x;
}
return tmp;
}
def code(x): t_0 = math.sqrt((x + 1.0)) tmp = 0 if x <= 100000000.0: tmp = ((t_0 - math.sqrt(x)) / math.sqrt(x)) / t_0 else: tmp = ((0.5 * math.sqrt(x)) / x) / x return tmp
function code(x) t_0 = sqrt(Float64(x + 1.0)) tmp = 0.0 if (x <= 100000000.0) tmp = Float64(Float64(Float64(t_0 - sqrt(x)) / sqrt(x)) / t_0); else tmp = Float64(Float64(Float64(0.5 * sqrt(x)) / x) / x); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((x + 1.0)); tmp = 0.0; if (x <= 100000000.0) tmp = ((t_0 - sqrt(x)) / sqrt(x)) / t_0; else tmp = ((0.5 * sqrt(x)) / x) / x; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 100000000.0], N[(N[(N[(t$95$0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;x \leq 100000000:\\
\;\;\;\;\frac{\frac{t\_0 - \sqrt{x}}{\sqrt{x}}}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5 \cdot \sqrt{x}}{x}}{x}\\
\end{array}
\end{array}
if x < 1e8Initial program 80.0%
lift--.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
frac-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-+.f6481.4
Applied rewrites81.4%
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
*-lft-identityN/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites81.4%
if 1e8 < x Initial program 36.4%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites83.2%
Applied rewrites99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lift-sqrt.f6499.2
Applied rewrites99.2%
(FPCore (x) :precision binary64 (let* ((t_0 (/ 1.0 (sqrt x)))) (/ (fma t_0 0.5 (- (/ (* t_0 0.375) x))) x)))
double code(double x) {
double t_0 = 1.0 / sqrt(x);
return fma(t_0, 0.5, -((t_0 * 0.375) / x)) / x;
}
function code(x) t_0 = Float64(1.0 / sqrt(x)) return Float64(fma(t_0, 0.5, Float64(-Float64(Float64(t_0 * 0.375) / x))) / x) end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$0 * 0.5 + (-N[(N[(t$95$0 * 0.375), $MachinePrecision] / x), $MachinePrecision])), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\sqrt{x}}\\
\frac{\mathsf{fma}\left(t\_0, 0.5, -\frac{t\_0 \cdot 0.375}{x}\right)}{x}
\end{array}
\end{array}
Initial program 37.6%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites82.6%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites98.6%
lift-pow.f64N/A
metadata-evalN/A
sqrt-pow2N/A
inv-powN/A
lower-/.f64N/A
lift-sqrt.f6498.6
Applied rewrites98.6%
lift-pow.f64N/A
metadata-evalN/A
sqrt-pow2N/A
inv-powN/A
lift-sqrt.f64N/A
lift-/.f6498.5
Applied rewrites98.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ x 1.0))))
(if (<= x 100000000.0)
(/ (- t_0 (sqrt x)) (* (sqrt x) t_0))
(/ (/ (* 0.5 (sqrt x)) x) x))))
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if (x <= 100000000.0) {
tmp = (t_0 - sqrt(x)) / (sqrt(x) * t_0);
} else {
tmp = ((0.5 * sqrt(x)) / x) / 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) :: t_0
real(8) :: tmp
t_0 = sqrt((x + 1.0d0))
if (x <= 100000000.0d0) then
tmp = (t_0 - sqrt(x)) / (sqrt(x) * t_0)
else
tmp = ((0.5d0 * sqrt(x)) / x) / x
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((x + 1.0));
double tmp;
if (x <= 100000000.0) {
tmp = (t_0 - Math.sqrt(x)) / (Math.sqrt(x) * t_0);
} else {
tmp = ((0.5 * Math.sqrt(x)) / x) / x;
}
return tmp;
}
def code(x): t_0 = math.sqrt((x + 1.0)) tmp = 0 if x <= 100000000.0: tmp = (t_0 - math.sqrt(x)) / (math.sqrt(x) * t_0) else: tmp = ((0.5 * math.sqrt(x)) / x) / x return tmp
function code(x) t_0 = sqrt(Float64(x + 1.0)) tmp = 0.0 if (x <= 100000000.0) tmp = Float64(Float64(t_0 - sqrt(x)) / Float64(sqrt(x) * t_0)); else tmp = Float64(Float64(Float64(0.5 * sqrt(x)) / x) / x); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((x + 1.0)); tmp = 0.0; if (x <= 100000000.0) tmp = (t_0 - sqrt(x)) / (sqrt(x) * t_0); else tmp = ((0.5 * sqrt(x)) / x) / x; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 100000000.0], N[(N[(t$95$0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;x \leq 100000000:\\
\;\;\;\;\frac{t\_0 - \sqrt{x}}{\sqrt{x} \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5 \cdot \sqrt{x}}{x}}{x}\\
\end{array}
\end{array}
if x < 1e8Initial program 80.0%
lift--.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
frac-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-+.f6481.4
Applied rewrites81.4%
lift-*.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
*-lft-identityN/A
lift-sqrt.f64N/A
lift-+.f6481.4
lift-*.f64N/A
lift-sqrt.f64N/A
*-rgt-identityN/A
lift-sqrt.f6481.4
Applied rewrites81.4%
if 1e8 < x Initial program 36.4%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites83.2%
Applied rewrites99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lift-sqrt.f6499.2
Applied rewrites99.2%
(FPCore (x) :precision binary64 (if (<= x 100000000.0) (/ (- (sqrt (+ x 1.0)) (sqrt x)) (sqrt (* x (+ x 1.0)))) (/ (/ (* 0.5 (sqrt x)) x) x)))
double code(double x) {
double tmp;
if (x <= 100000000.0) {
tmp = (sqrt((x + 1.0)) - sqrt(x)) / sqrt((x * (x + 1.0)));
} else {
tmp = ((0.5 * sqrt(x)) / x) / 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 <= 100000000.0d0) then
tmp = (sqrt((x + 1.0d0)) - sqrt(x)) / sqrt((x * (x + 1.0d0)))
else
tmp = ((0.5d0 * sqrt(x)) / x) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 100000000.0) {
tmp = (Math.sqrt((x + 1.0)) - Math.sqrt(x)) / Math.sqrt((x * (x + 1.0)));
} else {
tmp = ((0.5 * Math.sqrt(x)) / x) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 100000000.0: tmp = (math.sqrt((x + 1.0)) - math.sqrt(x)) / math.sqrt((x * (x + 1.0))) else: tmp = ((0.5 * math.sqrt(x)) / x) / x return tmp
function code(x) tmp = 0.0 if (x <= 100000000.0) tmp = Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) / sqrt(Float64(x * Float64(x + 1.0)))); else tmp = Float64(Float64(Float64(0.5 * sqrt(x)) / x) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 100000000.0) tmp = (sqrt((x + 1.0)) - sqrt(x)) / sqrt((x * (x + 1.0))); else tmp = ((0.5 * sqrt(x)) / x) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 100000000.0], N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 100000000:\\
\;\;\;\;\frac{\sqrt{x + 1} - \sqrt{x}}{\sqrt{x \cdot \left(x + 1\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5 \cdot \sqrt{x}}{x}}{x}\\
\end{array}
\end{array}
if x < 1e8Initial program 80.0%
lift--.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
frac-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-+.f6481.4
Applied rewrites81.4%
lift-*.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
*-lft-identityN/A
lift-sqrt.f64N/A
lift-+.f6481.4
lift-*.f64N/A
lift-sqrt.f64N/A
*-rgt-identityN/A
lift-sqrt.f6481.4
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-+.f6481.4
Applied rewrites81.4%
if 1e8 < x Initial program 36.4%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites83.2%
Applied rewrites99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lift-sqrt.f6499.2
Applied rewrites99.2%
(FPCore (x) :precision binary64 (if (<= x 65000000.0) (- (sqrt (/ 1.0 x)) (/ 1.0 (sqrt (+ x 1.0)))) (/ (/ (* 0.5 (sqrt x)) x) x)))
double code(double x) {
double tmp;
if (x <= 65000000.0) {
tmp = sqrt((1.0 / x)) - (1.0 / sqrt((x + 1.0)));
} else {
tmp = ((0.5 * sqrt(x)) / x) / 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 <= 65000000.0d0) then
tmp = sqrt((1.0d0 / x)) - (1.0d0 / sqrt((x + 1.0d0)))
else
tmp = ((0.5d0 * sqrt(x)) / x) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 65000000.0) {
tmp = Math.sqrt((1.0 / x)) - (1.0 / Math.sqrt((x + 1.0)));
} else {
tmp = ((0.5 * Math.sqrt(x)) / x) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 65000000.0: tmp = math.sqrt((1.0 / x)) - (1.0 / math.sqrt((x + 1.0))) else: tmp = ((0.5 * math.sqrt(x)) / x) / x return tmp
function code(x) tmp = 0.0 if (x <= 65000000.0) tmp = Float64(sqrt(Float64(1.0 / x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))); else tmp = Float64(Float64(Float64(0.5 * sqrt(x)) / x) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 65000000.0) tmp = sqrt((1.0 / x)) - (1.0 / sqrt((x + 1.0))); else tmp = ((0.5 * sqrt(x)) / x) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 65000000.0], N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 65000000:\\
\;\;\;\;\sqrt{\frac{1}{x}} - \frac{1}{\sqrt{x + 1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5 \cdot \sqrt{x}}{x}}{x}\\
\end{array}
\end{array}
if x < 6.5e7Initial program 80.3%
lift-/.f64N/A
metadata-evalN/A
lift-sqrt.f64N/A
sqrt-divN/A
lower-sqrt.f64N/A
inv-powN/A
lower-pow.f6480.9
Applied rewrites80.9%
lift-pow.f64N/A
inv-powN/A
lower-/.f6480.9
Applied rewrites80.9%
if 6.5e7 < x Initial program 36.5%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites83.2%
Applied rewrites99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lift-sqrt.f6499.2
Applied rewrites99.2%
(FPCore (x) :precision binary64 (/ (/ (* 0.5 (sqrt x)) x) x))
double code(double x) {
return ((0.5 * sqrt(x)) / x) / 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 = ((0.5d0 * sqrt(x)) / x) / x
end function
public static double code(double x) {
return ((0.5 * Math.sqrt(x)) / x) / x;
}
def code(x): return ((0.5 * math.sqrt(x)) / x) / x
function code(x) return Float64(Float64(Float64(0.5 * sqrt(x)) / x) / x) end
function tmp = code(x) tmp = ((0.5 * sqrt(x)) / x) / x; end
code[x_] := N[(N[(N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{0.5 \cdot \sqrt{x}}{x}}{x}
\end{array}
Initial program 37.6%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites82.6%
Applied rewrites98.6%
Taylor expanded in x around inf
lower-*.f64N/A
lift-sqrt.f6497.5
Applied rewrites97.5%
(FPCore (x) :precision binary64 (/ (* 0.5 (sqrt x)) (* x x)))
double code(double x) {
return (0.5 * sqrt(x)) / (x * 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 = (0.5d0 * sqrt(x)) / (x * x)
end function
public static double code(double x) {
return (0.5 * Math.sqrt(x)) / (x * x);
}
def code(x): return (0.5 * math.sqrt(x)) / (x * x)
function code(x) return Float64(Float64(0.5 * sqrt(x)) / Float64(x * x)) end
function tmp = code(x) tmp = (0.5 * sqrt(x)) / (x * x); end
code[x_] := N[(N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \sqrt{x}}{x \cdot x}
\end{array}
Initial program 37.6%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites82.6%
Taylor expanded in x around inf
lower-*.f64N/A
lift-sqrt.f6481.5
Applied rewrites81.5%
(FPCore (x) :precision binary64 (/ (sqrt x) x))
double code(double x) {
return sqrt(x) / 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) / x
end function
public static double code(double x) {
return Math.sqrt(x) / x;
}
def code(x): return math.sqrt(x) / x
function code(x) return Float64(sqrt(x) / x) end
function tmp = code(x) tmp = sqrt(x) / x; end
code[x_] := N[(N[Sqrt[x], $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{x}}{x}
\end{array}
Initial program 37.6%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-sqrt.f643.3
Applied rewrites3.3%
Taylor expanded in x around 0
lift-sqrt.f645.7
Applied rewrites5.7%
(FPCore (x) :precision binary64 (* 0.5 x))
double code(double x) {
return 0.5 * 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 = 0.5d0 * x
end function
public static double code(double x) {
return 0.5 * x;
}
def code(x): return 0.5 * x
function code(x) return Float64(0.5 * x) end
function tmp = code(x) tmp = 0.5 * x; end
code[x_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x
\end{array}
Initial program 37.6%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-sqrt.f643.3
Applied rewrites3.3%
Taylor expanded in x around inf
lift-*.f643.4
Applied rewrites3.4%
(FPCore (x) :precision binary64 (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0))))))
double code(double x) {
return 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.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 = 1.0d0 / (((x + 1.0d0) * sqrt(x)) + (x * sqrt((x + 1.0d0))))
end function
public static double code(double x) {
return 1.0 / (((x + 1.0) * Math.sqrt(x)) + (x * Math.sqrt((x + 1.0))));
}
def code(x): return 1.0 / (((x + 1.0) * math.sqrt(x)) + (x * math.sqrt((x + 1.0))))
function code(x) return Float64(1.0 / Float64(Float64(Float64(x + 1.0) * sqrt(x)) + Float64(x * sqrt(Float64(x + 1.0))))) end
function tmp = code(x) tmp = 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0)))); end
code[x_] := N[(1.0 / N[(N[(N[(x + 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}
\end{array}
(FPCore (x) :precision binary64 (- (pow x -0.5) (pow (+ x 1.0) -0.5)))
double code(double x) {
return pow(x, -0.5) - pow((x + 1.0), -0.5);
}
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 = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
end function
public static double code(double x) {
return Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
}
def code(x): return math.pow(x, -0.5) - math.pow((x + 1.0), -0.5)
function code(x) return Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)) end
function tmp = code(x) tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}
\end{array}
herbie shell --seed 2025100
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(! :herbie-platform default (/ 1 (+ (* (+ x 1) (sqrt x)) (* x (sqrt (+ x 1))))))
:alt
(! :herbie-platform default (- (pow x -1/2) (pow (+ x 1) -1/2)))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))