(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) { return sqrt((x + 1.0)) - sqrt(x); }
real(8) function code(x) 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}
Sampling outcomes in binary64 precision:
Herbie found 5 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); }
real(8) function code(x) 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 (/ 1.0 (+ (sqrt x) (sqrt (+ 1.0 x)))))
double code(double x) { return 1.0 / (sqrt(x) + sqrt((1.0 + x))); }
real(8) function code(x) real(8), intent (in) :: x code = 1.0d0 / (sqrt(x) + sqrt((1.0d0 + x))) end function
public static double code(double x) { return 1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x))); }
def code(x): return 1.0 / (math.sqrt(x) + math.sqrt((1.0 + x)))
function code(x) return Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) end
function tmp = code(x) tmp = 1.0 / (sqrt(x) + sqrt((1.0 + x))); end
code[x_] := N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \frac{1}{\sqrt{x} + \sqrt{1 + x}} \end{array}
Initial program 90.9%
lift--.f64
N/A
flip--
N/A
lower-/.f64
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
lower--.f64
N/A
lift-+.f64
N/A
+-commutative
N/A
lower-+.f64
N/A
+-commutative
N/A
lower-+.f64
99.3
lift-+.f64
N/A
+-commutative
N/A
lower-+.f64
99.3
Applied rewrites99.3%
Taylor expanded in x around 0
Applied rewrites99.5%
(FPCore (x) :precision binary64 (pow (+ (sqrt x) 1.0) -1.0))
double code(double x) { return pow((sqrt(x) + 1.0), -1.0); }
real(8) function code(x) real(8), intent (in) :: x code = (sqrt(x) + 1.0d0) ** (-1.0d0) end function
public static double code(double x) { return Math.pow((Math.sqrt(x) + 1.0), -1.0); }
def code(x): return math.pow((math.sqrt(x) + 1.0), -1.0)
function code(x) return Float64(sqrt(x) + 1.0) ^ -1.0 end
function tmp = code(x) tmp = (sqrt(x) + 1.0) ^ -1.0; end
code[x_] := N[Power[N[(N[Sqrt[x], $MachinePrecision] + 1.0), $MachinePrecision], -1.0], $MachinePrecision]
\begin{array}{l} \\ {\left(\sqrt{x} + 1\right)}^{-1} \end{array}
Initial program 90.9%
lift--.f64
N/A
flip--
N/A
lower-/.f64
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
lower--.f64
N/A
lift-+.f64
N/A
+-commutative
N/A
lower-+.f64
N/A
+-commutative
N/A
lower-+.f64
99.3
lift-+.f64
N/A
+-commutative
N/A
lower-+.f64
99.3
Applied rewrites99.3%
Taylor expanded in x around 0
lower-/.f64
N/A
+-commutative
N/A
lower-+.f64
N/A
lower-sqrt.f64
19.4
Applied rewrites19.4%
Final simplification19.4%
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) { return sqrt((x + 1.0)) - sqrt(x); }
real(8) function code(x) 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}
Initial program 90.9%
(FPCore (x) :precision binary64 (fma 0.5 x (- 1.0 (sqrt x))))
double code(double x) { return fma(0.5, x, (1.0 - sqrt(x))); }
function code(x) return fma(0.5, x, Float64(1.0 - sqrt(x))) end
code[x_] := N[(0.5 * x + N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(0.5, x, 1 - \sqrt{x}\right) \end{array}
Initial program 90.9%
Taylor expanded in x around 0
+-commutative
N/A
associate--l+
N/A
lower-fma.f64
N/A
lower--.f64
N/A
lower-sqrt.f64
14.4
Applied rewrites14.4%
(FPCore (x) :precision binary64 0.0)
double code(double x) { return 0.0; }
real(8) function code(x) 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 90.9%
lift--.f64
N/A
flip--
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
div-sub
N/A
sub-neg
N/A
lift-+.f64
N/A
flip-+
N/A
div-inv
N/A
associate-/l*
N/A
lower-fma.f64
N/A
Applied rewrites91.7%
Taylor expanded in x around -inf
distribute-rgt-out
N/A
metadata-eval
N/A
mul0-rgt
3.1
Applied rewrites3.1%
herbie shell --seed 1
(FPCore (x)
:name "sqrt(x + 1) - sqrt(x)"
:precision binary64
:pre (and (<= 1.0 x) (<= x 10000.0))
(- (sqrt (+ x 1.0)) (sqrt x)))