
(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 5 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 (/ 1.0 (/ (- (sqrt (- x -1.0)) -1.0) x)))
double code(double x) {
return 1.0 / ((sqrt((x - -1.0)) - -1.0) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / ((sqrt((x - (-1.0d0))) - (-1.0d0)) / x)
end function
public static double code(double x) {
return 1.0 / ((Math.sqrt((x - -1.0)) - -1.0) / x);
}
def code(x): return 1.0 / ((math.sqrt((x - -1.0)) - -1.0) / x)
function code(x) return Float64(1.0 / Float64(Float64(sqrt(Float64(x - -1.0)) - -1.0) / x)) end
function tmp = code(x) tmp = 1.0 / ((sqrt((x - -1.0)) - -1.0) / x); end
code[x_] := N[(1.0 / N[(N[(N[Sqrt[N[(x - -1.0), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\frac{1}{\frac{\sqrt{x - -1} - -1}{x}}
Initial program 8.5%
Applied rewrites8.5%
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
div-flipN/A
lower-unsound-/.f32N/A
lower-unsound-/.f32N/A
lower-/.f32N/A
metadata-evalN/A
frac-2negN/A
lift-fma.f64N/A
add-flipN/A
*-commutativeN/A
lift-sqrt.f64N/A
pow1/2N/A
lift--.f64N/A
sub-flipN/A
metadata-evalN/A
+-commutativeN/A
pow1/2N/A
metadata-evalN/A
sub-to-fraction-revN/A
metadata-evalN/A
Applied rewrites8.5%
lift--.f64N/A
sub-negate-revN/A
sub-negate-revN/A
lift--.f64N/A
lift--.f64N/A
sub-flipN/A
metadata-evalN/A
distribute-neg-inN/A
metadata-evalN/A
flip-+N/A
lower-unsound--.f32N/A
lower--.f32N/A
metadata-evalN/A
add-flipN/A
metadata-evalN/A
distribute-neg-inN/A
lift-+.f64N/A
lower-unsound-/.f64N/A
Applied rewrites99.7%
lift-/.f64N/A
lift-/.f64N/A
div-flip-revN/A
lower-/.f6499.7%
Applied rewrites99.7%
(FPCore (x) :precision binary64 (* (fma (fma 0.0625 x -0.125) x 0.5) x))
double code(double x) {
return fma(fma(0.0625, x, -0.125), x, 0.5) * x;
}
function code(x) return Float64(fma(fma(0.0625, x, -0.125), x, 0.5) * x) end
code[x_] := N[(N[(N[(0.0625 * x + -0.125), $MachinePrecision] * x + 0.5), $MachinePrecision] * x), $MachinePrecision]
\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x, -0.125\right), x, 0.5\right) \cdot x
Initial program 8.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6499.4%
Applied rewrites99.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.4%
lift--.f64N/A
sub-flipN/A
lift-*.f64N/A
metadata-evalN/A
lower-fma.f6499.4%
Applied rewrites99.4%
(FPCore (x) :precision binary64 (fma (* x x) -0.125 (* 0.5 x)))
double code(double x) {
return fma((x * x), -0.125, (0.5 * x));
}
function code(x) return fma(Float64(x * x), -0.125, Float64(0.5 * x)) end
code[x_] := N[(N[(x * x), $MachinePrecision] * -0.125 + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(x \cdot x, -0.125, 0.5 \cdot x\right)
Initial program 8.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6499.0%
Applied rewrites99.0%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.0%
Applied rewrites99.0%
(FPCore (x) :precision binary64 (* (fma -0.125 x 0.5) x))
double code(double x) {
return fma(-0.125, x, 0.5) * x;
}
function code(x) return Float64(fma(-0.125, x, 0.5) * x) end
code[x_] := N[(N[(-0.125 * x + 0.5), $MachinePrecision] * x), $MachinePrecision]
\mathsf{fma}\left(-0.125, x, 0.5\right) \cdot x
Initial program 8.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6499.0%
Applied rewrites99.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.0%
Applied rewrites99.0%
(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 8.5%
Taylor expanded in x around 0
lower-*.f6498.0%
Applied rewrites98.0%
herbie shell --seed 1
(FPCore (x)
:name "sqrt(1 + x) - 1"
:precision binary64
:pre (and (<= -1.0 x) (<= x 1.0))
(- (sqrt (+ 1.0 x)) 1.0))