
(FPCore (x) :precision binary64 (- (sqrt (+ 1.0 x)) 1.0))
double code(double x) {
return sqrt((1.0 + x)) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((1.0d0 + x)) - 1.0d0
end function
public static double code(double x) {
return Math.sqrt((1.0 + x)) - 1.0;
}
def code(x): return math.sqrt((1.0 + x)) - 1.0
function code(x) return Float64(sqrt(Float64(1.0 + x)) - 1.0) end
function tmp = code(x) tmp = sqrt((1.0 + x)) - 1.0; end
code[x_] := N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
\sqrt{1 + x} - 1
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (sqrt (+ 1.0 x)) 1.0))
double code(double x) {
return sqrt((1.0 + x)) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((1.0d0 + x)) - 1.0d0
end function
public static double code(double x) {
return Math.sqrt((1.0 + x)) - 1.0;
}
def code(x): return math.sqrt((1.0 + x)) - 1.0
function code(x) return Float64(sqrt(Float64(1.0 + x)) - 1.0) end
function tmp = code(x) tmp = sqrt((1.0 + x)) - 1.0; end
code[x_] := N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
\sqrt{1 + x} - 1
(FPCore (x) :precision binary64 (/ x (fma (/ (sqrt (- x -1.0)) x) x 1.0)))
double code(double x) {
return x / fma((sqrt((x - -1.0)) / x), x, 1.0);
}
function code(x) return Float64(x / fma(Float64(sqrt(Float64(x - -1.0)) / x), x, 1.0)) end
code[x_] := N[(x / N[(N[(N[Sqrt[N[(x - -1.0), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]
\frac{x}{\mathsf{fma}\left(\frac{\sqrt{x - -1}}{x}, x, 1\right)}
Initial program 85.1%
Applied rewrites85.6%
lift--.f64N/A
lift--.f64N/A
lift-*.f64N/A
metadata-evalN/A
associate--l-N/A
metadata-evalN/A
--rgt-identity99.3%
lift-+.f64N/A
add-flipN/A
metadata-evalN/A
lower--.f6499.3%
Applied rewrites99.3%
lift-/.f64N/A
div-flip-revN/A
lift--.f64N/A
div-subN/A
sub-to-fractionN/A
div-flip-revN/A
lower-/.f64N/A
metadata-evalN/A
add-flip-revN/A
lower-fma.f64N/A
lower-/.f6499.2%
Applied rewrites99.2%
(FPCore (x) :precision binary64 (/ (* x x) (fma (sqrt (- x -1.0)) x x)))
double code(double x) {
return (x * x) / fma(sqrt((x - -1.0)), x, x);
}
function code(x) return Float64(Float64(x * x) / fma(sqrt(Float64(x - -1.0)), x, x)) end
code[x_] := N[(N[(x * x), $MachinePrecision] / N[(N[Sqrt[N[(x - -1.0), $MachinePrecision]], $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]
\frac{x \cdot x}{\mathsf{fma}\left(\sqrt{x - -1}, x, x\right)}
Initial program 85.1%
Applied rewrites85.6%
lift--.f64N/A
lift--.f64N/A
lift-*.f64N/A
metadata-evalN/A
associate--l-N/A
metadata-evalN/A
--rgt-identity99.3%
lift-+.f64N/A
add-flipN/A
metadata-evalN/A
lower--.f6499.3%
Applied rewrites99.3%
lift-/.f64N/A
div-flip-revN/A
lift--.f64N/A
div-subN/A
frac-subN/A
div-flip-revN/A
lower-/.f64N/A
lower-*.f64N/A
sub-flipN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identityN/A
lower-fma.f6499.3%
Applied rewrites99.3%
(FPCore (x) :precision binary64 (/ x (- (sqrt (- x -1.0)) -1.0)))
double code(double x) {
return x / (sqrt((x - -1.0)) - -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x / (sqrt((x - (-1.0d0))) - (-1.0d0))
end function
public static double code(double x) {
return x / (Math.sqrt((x - -1.0)) - -1.0);
}
def code(x): return x / (math.sqrt((x - -1.0)) - -1.0)
function code(x) return Float64(x / Float64(sqrt(Float64(x - -1.0)) - -1.0)) end
function tmp = code(x) tmp = x / (sqrt((x - -1.0)) - -1.0); end
code[x_] := N[(x / N[(N[Sqrt[N[(x - -1.0), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]
\frac{x}{\sqrt{x - -1} - -1}
Initial program 85.1%
Applied rewrites85.6%
lift--.f64N/A
lift--.f64N/A
lift-*.f64N/A
metadata-evalN/A
associate--l-N/A
metadata-evalN/A
--rgt-identity99.3%
lift-+.f64N/A
add-flipN/A
metadata-evalN/A
lower--.f6499.3%
Applied rewrites99.3%
(FPCore (x) :precision binary64 (if (<= x 9.8e-6) (/ 1.0 (- (/ 2.0 x) -0.5)) (- (sqrt (+ 1.0 x)) 1.0)))
double code(double x) {
double tmp;
if (x <= 9.8e-6) {
tmp = 1.0 / ((2.0 / x) - -0.5);
} else {
tmp = sqrt((1.0 + x)) - 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 9.8d-6) then
tmp = 1.0d0 / ((2.0d0 / x) - (-0.5d0))
else
tmp = sqrt((1.0d0 + x)) - 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 9.8e-6) {
tmp = 1.0 / ((2.0 / x) - -0.5);
} else {
tmp = Math.sqrt((1.0 + x)) - 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 9.8e-6: tmp = 1.0 / ((2.0 / x) - -0.5) else: tmp = math.sqrt((1.0 + x)) - 1.0 return tmp
function code(x) tmp = 0.0 if (x <= 9.8e-6) tmp = Float64(1.0 / Float64(Float64(2.0 / x) - -0.5)); else tmp = Float64(sqrt(Float64(1.0 + x)) - 1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 9.8e-6) tmp = 1.0 / ((2.0 / x) - -0.5); else tmp = sqrt((1.0 + x)) - 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 9.8e-6], N[(1.0 / N[(N[(2.0 / x), $MachinePrecision] - -0.5), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 9.8 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{\frac{2}{x} - -0.5}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + x} - 1\\
\end{array}
if x < 9.7999999999999993e-6Initial program 85.1%
Applied rewrites85.0%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f64N/A
lower-*.f6445.6%
Applied rewrites45.6%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-/.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
metadata-eval45.6%
Applied rewrites45.6%
if 9.7999999999999993e-6 < x Initial program 85.1%
(FPCore (x) :precision binary64 (if (<= x 9.8e-6) (/ x (+ 2.0 (* 0.5 x))) (- (sqrt (+ 1.0 x)) 1.0)))
double code(double x) {
double tmp;
if (x <= 9.8e-6) {
tmp = x / (2.0 + (0.5 * x));
} else {
tmp = sqrt((1.0 + x)) - 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 9.8d-6) then
tmp = x / (2.0d0 + (0.5d0 * x))
else
tmp = sqrt((1.0d0 + x)) - 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 9.8e-6) {
tmp = x / (2.0 + (0.5 * x));
} else {
tmp = Math.sqrt((1.0 + x)) - 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 9.8e-6: tmp = x / (2.0 + (0.5 * x)) else: tmp = math.sqrt((1.0 + x)) - 1.0 return tmp
function code(x) tmp = 0.0 if (x <= 9.8e-6) tmp = Float64(x / Float64(2.0 + Float64(0.5 * x))); else tmp = Float64(sqrt(Float64(1.0 + x)) - 1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 9.8e-6) tmp = x / (2.0 + (0.5 * x)); else tmp = sqrt((1.0 + x)) - 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 9.8e-6], N[(x / N[(2.0 + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 9.8 \cdot 10^{-6}:\\
\;\;\;\;\frac{x}{2 + 0.5 \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + x} - 1\\
\end{array}
if x < 9.7999999999999993e-6Initial program 85.1%
Applied rewrites85.6%
lift--.f64N/A
lift--.f64N/A
lift-*.f64N/A
metadata-evalN/A
associate--l-N/A
metadata-evalN/A
--rgt-identity99.3%
lift-+.f64N/A
add-flipN/A
metadata-evalN/A
lower--.f6499.3%
Applied rewrites99.3%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f6445.6%
Applied rewrites45.6%
if 9.7999999999999993e-6 < x Initial program 85.1%
(FPCore (x) :precision binary64 (if (<= x 9.8e-6) (* x (+ 0.5 (* -0.125 x))) (- (sqrt (+ 1.0 x)) 1.0)))
double code(double x) {
double tmp;
if (x <= 9.8e-6) {
tmp = x * (0.5 + (-0.125 * x));
} else {
tmp = sqrt((1.0 + x)) - 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 9.8d-6) then
tmp = x * (0.5d0 + ((-0.125d0) * x))
else
tmp = sqrt((1.0d0 + x)) - 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 9.8e-6) {
tmp = x * (0.5 + (-0.125 * x));
} else {
tmp = Math.sqrt((1.0 + x)) - 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 9.8e-6: tmp = x * (0.5 + (-0.125 * x)) else: tmp = math.sqrt((1.0 + x)) - 1.0 return tmp
function code(x) tmp = 0.0 if (x <= 9.8e-6) tmp = Float64(x * Float64(0.5 + Float64(-0.125 * x))); else tmp = Float64(sqrt(Float64(1.0 + x)) - 1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 9.8e-6) tmp = x * (0.5 + (-0.125 * x)); else tmp = sqrt((1.0 + x)) - 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 9.8e-6], N[(x * N[(0.5 + N[(-0.125 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 9.8 \cdot 10^{-6}:\\
\;\;\;\;x \cdot \left(0.5 + -0.125 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + x} - 1\\
\end{array}
if x < 9.7999999999999993e-6Initial program 85.1%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6439.0%
Applied rewrites39.0%
if 9.7999999999999993e-6 < x Initial program 85.1%
(FPCore (x) :precision binary64 (if (<= x 1.32e-8) (* 0.5 x) (- (sqrt (+ 1.0 x)) 1.0)))
double code(double x) {
double tmp;
if (x <= 1.32e-8) {
tmp = 0.5 * x;
} else {
tmp = sqrt((1.0 + x)) - 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.32d-8) then
tmp = 0.5d0 * x
else
tmp = sqrt((1.0d0 + x)) - 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.32e-8) {
tmp = 0.5 * x;
} else {
tmp = Math.sqrt((1.0 + x)) - 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.32e-8: tmp = 0.5 * x else: tmp = math.sqrt((1.0 + x)) - 1.0 return tmp
function code(x) tmp = 0.0 if (x <= 1.32e-8) tmp = Float64(0.5 * x); else tmp = Float64(sqrt(Float64(1.0 + x)) - 1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.32e-8) tmp = 0.5 * x; else tmp = sqrt((1.0 + x)) - 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.32e-8], N[(0.5 * x), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 1.32 \cdot 10^{-8}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + x} - 1\\
\end{array}
if x < 1.3200000000000001e-8Initial program 85.1%
Taylor expanded in x around 0
lower-*.f6433.1%
Applied rewrites33.1%
if 1.3200000000000001e-8 < x Initial program 85.1%
(FPCore (x) :precision binary64 (* 0.5 x))
double code(double x) {
return 0.5 * x;
}
real(8) function code(x)
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]
0.5 \cdot x
Initial program 85.1%
Taylor expanded in x around 0
lower-*.f6433.1%
Applied rewrites33.1%
herbie shell --seed 1
(FPCore (x)
:name "sqrt(1+x)-1"
:precision binary64
:pre (and (<= 1e-12 x) (<= x 1000000000000.0))
(- (sqrt (+ 1.0 x)) 1.0))