
(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 4 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 (+ 1.0 x)) (sqrt x))))
double code(double x) {
return 1.0 / (sqrt((1.0 + x)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt((1.0d0 + x)) + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt((1.0 + x)) + Math.sqrt(x));
}
def code(x): return 1.0 / (math.sqrt((1.0 + x)) + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(sqrt(Float64(1.0 + x)) + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (sqrt((1.0 + x)) + sqrt(x)); end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{1 + x} + \sqrt{x}}
\end{array}
Initial program 7.7%
flip--8.4%
div-inv8.4%
add-sqr-sqrt8.4%
add-sqr-sqrt10.2%
associate--l+10.2%
Applied egg-rr10.2%
associate-*r/10.2%
*-rgt-identity10.2%
+-commutative10.2%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (/ 1.0 (* (sqrt x) 2.0)))
double code(double x) {
return 1.0 / (sqrt(x) * 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt(x) * 2.0d0)
end function
public static double code(double x) {
return 1.0 / (Math.sqrt(x) * 2.0);
}
def code(x): return 1.0 / (math.sqrt(x) * 2.0)
function code(x) return Float64(1.0 / Float64(sqrt(x) * 2.0)) end
function tmp = code(x) tmp = 1.0 / (sqrt(x) * 2.0); end
code[x_] := N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x} \cdot 2}
\end{array}
Initial program 7.7%
flip--8.4%
div-inv8.4%
add-sqr-sqrt8.4%
add-sqr-sqrt10.2%
associate--l+10.2%
Applied egg-rr10.2%
associate-*r/10.2%
*-rgt-identity10.2%
+-commutative10.2%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
flip3-+70.1%
clear-num70.0%
Applied egg-rr51.0%
Taylor expanded in x around inf 96.9%
Final simplification96.9%
(FPCore (x) :precision binary64 (/ 2.0 x))
double code(double x) {
return 2.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / x
end function
public static double code(double x) {
return 2.0 / x;
}
def code(x): return 2.0 / x
function code(x) return Float64(2.0 / x) end
function tmp = code(x) tmp = 2.0 / x; end
code[x_] := N[(2.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{x}
\end{array}
Initial program 7.7%
flip--8.4%
div-inv8.4%
add-sqr-sqrt8.4%
add-sqr-sqrt10.2%
associate--l+10.2%
Applied egg-rr10.2%
associate-*r/10.2%
*-rgt-identity10.2%
+-commutative10.2%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around 0 7.2%
Taylor expanded in x around inf 7.2%
Final simplification7.2%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 7.7%
Taylor expanded in x around 0 7.1%
Final simplification7.1%
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x))))
double code(double x) {
return 1.0 / (sqrt((x + 1.0)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt((x + 1.0d0)) + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt((x + 1.0)) + Math.sqrt(x));
}
def code(x): return 1.0 / (math.sqrt((x + 1.0)) + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(sqrt(Float64(x + 1.0)) + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (sqrt((x + 1.0)) + sqrt(x)); end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x + 1} + \sqrt{x}}
\end{array}
herbie shell --seed 2024027
(FPCore (x)
:name "2sqrt (example 3.1)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))