
(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 7 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 53.6%
flip--54.5%
div-inv54.5%
add-sqr-sqrt54.0%
add-sqr-sqrt54.5%
Applied egg-rr54.5%
associate-*r/54.5%
*-rgt-identity54.5%
remove-double-neg54.5%
sub-neg54.5%
div-sub53.6%
rem-square-sqrt53.5%
sqr-neg53.5%
div-sub54.0%
+-commutative54.0%
sqr-neg54.0%
rem-square-sqrt54.5%
associate--l+99.7%
+-inverses99.7%
metadata-eval99.7%
sub-neg99.7%
remove-double-neg99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (let* ((t_0 (- (sqrt (+ 1.0 x)) (sqrt x)))) (if (<= t_0 0.0) (sqrt (/ 0.5 x)) t_0)))
double code(double x) {
double t_0 = sqrt((1.0 + x)) - sqrt(x);
double tmp;
if (t_0 <= 0.0) {
tmp = sqrt((0.5 / x));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x)) - sqrt(x)
if (t_0 <= 0.0d0) then
tmp = sqrt((0.5d0 / x))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x)) - Math.sqrt(x);
double tmp;
if (t_0 <= 0.0) {
tmp = Math.sqrt((0.5 / x));
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) - math.sqrt(x) tmp = 0 if t_0 <= 0.0: tmp = math.sqrt((0.5 / x)) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) tmp = 0.0 if (t_0 <= 0.0) tmp = sqrt(Float64(0.5 / x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)) - sqrt(x); tmp = 0.0; if (t_0 <= 0.0) tmp = sqrt((0.5 / x)); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[Sqrt[N[(0.5 / x), $MachinePrecision]], $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;\sqrt{\frac{0.5}{x}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 0.0Initial program 3.9%
flip--3.9%
div-inv3.9%
add-sqr-sqrt3.8%
add-sqr-sqrt3.9%
Applied egg-rr3.9%
associate-*r/3.9%
*-rgt-identity3.9%
remove-double-neg3.9%
sub-neg3.9%
div-sub3.9%
rem-square-sqrt3.8%
sqr-neg3.8%
div-sub3.8%
+-commutative3.8%
sqr-neg3.8%
rem-square-sqrt3.9%
associate--l+99.5%
+-inverses99.5%
metadata-eval99.5%
sub-neg99.5%
remove-double-neg99.5%
Simplified99.5%
add-sqr-sqrt98.9%
sqrt-unprod99.5%
+-commutative99.5%
clear-num99.5%
frac-times99.4%
metadata-eval99.4%
+-commutative99.4%
/-rgt-identity99.4%
+-commutative99.4%
Applied egg-rr20.3%
Taylor expanded in x around inf 20.3%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 98.1%
Final simplification61.4%
(FPCore (x) :precision binary64 (let* ((t_0 (- (sqrt (+ 1.0 x)) (sqrt x)))) (if (<= t_0 2e-5) (/ 1.0 (+ (sqrt x) (sqrt x))) t_0)))
double code(double x) {
double t_0 = sqrt((1.0 + x)) - sqrt(x);
double tmp;
if (t_0 <= 2e-5) {
tmp = 1.0 / (sqrt(x) + sqrt(x));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x)) - sqrt(x)
if (t_0 <= 2d-5) then
tmp = 1.0d0 / (sqrt(x) + sqrt(x))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x)) - Math.sqrt(x);
double tmp;
if (t_0 <= 2e-5) {
tmp = 1.0 / (Math.sqrt(x) + Math.sqrt(x));
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) - math.sqrt(x) tmp = 0 if t_0 <= 2e-5: tmp = 1.0 / (math.sqrt(x) + math.sqrt(x)) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) tmp = 0.0 if (t_0 <= 2e-5) tmp = Float64(1.0 / Float64(sqrt(x) + sqrt(x))); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)) - sqrt(x); tmp = 0.0; if (t_0 <= 2e-5) tmp = 1.0 / (sqrt(x) + sqrt(x)); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-5], N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{\sqrt{x} + \sqrt{x}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 2.00000000000000016e-5Initial program 5.1%
flip--6.9%
div-inv6.9%
add-sqr-sqrt5.8%
add-sqr-sqrt6.9%
Applied egg-rr6.9%
associate-*r/6.9%
*-rgt-identity6.9%
remove-double-neg6.9%
sub-neg6.9%
div-sub5.1%
rem-square-sqrt5.0%
sqr-neg5.0%
div-sub5.8%
+-commutative5.8%
sqr-neg5.8%
rem-square-sqrt6.9%
associate--l+99.5%
+-inverses99.5%
metadata-eval99.5%
sub-neg99.5%
remove-double-neg99.5%
Simplified99.5%
pow1/299.5%
+-commutative99.5%
metadata-eval99.5%
pow-prod-up99.2%
pow299.2%
+-commutative99.2%
Applied egg-rr99.2%
Taylor expanded in x around inf 99.0%
if 2.00000000000000016e-5 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 99.9%
Final simplification99.4%
(FPCore (x) :precision binary64 (if (<= x 0.75) (- 1.0 x) (sqrt (/ 0.5 x))))
double code(double x) {
double tmp;
if (x <= 0.75) {
tmp = 1.0 - x;
} else {
tmp = sqrt((0.5 / x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.75d0) then
tmp = 1.0d0 - x
else
tmp = sqrt((0.5d0 / x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.75) {
tmp = 1.0 - x;
} else {
tmp = Math.sqrt((0.5 / x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.75: tmp = 1.0 - x else: tmp = math.sqrt((0.5 / x)) return tmp
function code(x) tmp = 0.0 if (x <= 0.75) tmp = Float64(1.0 - x); else tmp = sqrt(Float64(0.5 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.75) tmp = 1.0 - x; else tmp = sqrt((0.5 / x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.75], N[(1.0 - x), $MachinePrecision], N[Sqrt[N[(0.5 / x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.75:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{0.5}{x}}\\
\end{array}
\end{array}
if x < 0.75Initial program 99.9%
flip--99.9%
div-inv99.9%
add-sqr-sqrt99.9%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
associate-*r/99.9%
*-rgt-identity99.9%
remove-double-neg99.9%
sub-neg99.9%
div-sub99.9%
rem-square-sqrt99.9%
sqr-neg99.9%
div-sub99.9%
+-commutative99.9%
sqr-neg99.9%
rem-square-sqrt99.9%
associate--l+99.9%
+-inverses99.9%
metadata-eval99.9%
sub-neg99.9%
remove-double-neg99.9%
Simplified99.9%
add-sqr-sqrt99.9%
sqrt-unprod99.9%
+-commutative99.9%
clear-num99.9%
frac-times99.9%
metadata-eval99.9%
+-commutative99.9%
/-rgt-identity99.9%
+-commutative99.9%
Applied egg-rr95.9%
Taylor expanded in x around 0 95.9%
mul-1-neg95.9%
sub-neg95.9%
Simplified95.9%
if 0.75 < x Initial program 5.8%
flip--7.6%
div-inv7.6%
add-sqr-sqrt6.6%
add-sqr-sqrt7.7%
Applied egg-rr7.7%
associate-*r/7.7%
*-rgt-identity7.7%
remove-double-neg7.7%
sub-neg7.7%
div-sub5.8%
rem-square-sqrt5.7%
sqr-neg5.7%
div-sub6.6%
+-commutative6.6%
sqr-neg6.6%
rem-square-sqrt7.7%
associate--l+99.5%
+-inverses99.5%
metadata-eval99.5%
sub-neg99.5%
remove-double-neg99.5%
Simplified99.5%
add-sqr-sqrt98.9%
sqrt-unprod99.5%
+-commutative99.5%
clear-num99.5%
frac-times99.4%
metadata-eval99.4%
+-commutative99.4%
/-rgt-identity99.4%
+-commutative99.4%
Applied egg-rr20.3%
Taylor expanded in x around inf 20.3%
Final simplification58.7%
(FPCore (x) :precision binary64 (/ 1.0 (+ 1.0 (sqrt x))))
double code(double x) {
return 1.0 / (1.0 + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (1.0d0 + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (1.0 + Math.sqrt(x));
}
def code(x): return 1.0 / (1.0 + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(1.0 + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (1.0 + sqrt(x)); end
code[x_] := N[(1.0 / N[(1.0 + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + \sqrt{x}}
\end{array}
Initial program 53.6%
flip--54.5%
div-inv54.5%
add-sqr-sqrt54.0%
add-sqr-sqrt54.5%
Applied egg-rr54.5%
associate-*r/54.5%
*-rgt-identity54.5%
remove-double-neg54.5%
sub-neg54.5%
div-sub53.6%
rem-square-sqrt53.5%
sqr-neg53.5%
div-sub54.0%
+-commutative54.0%
sqr-neg54.0%
rem-square-sqrt54.5%
associate--l+99.7%
+-inverses99.7%
metadata-eval99.7%
sub-neg99.7%
remove-double-neg99.7%
Simplified99.7%
pow1/299.7%
+-commutative99.7%
metadata-eval99.7%
pow-prod-up99.6%
pow299.6%
+-commutative99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 59.2%
Final simplification59.2%
(FPCore (x) :precision binary64 (/ 1.0 (+ 1.0 x)))
double code(double x) {
return 1.0 / (1.0 + x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (1.0d0 + x)
end function
public static double code(double x) {
return 1.0 / (1.0 + x);
}
def code(x): return 1.0 / (1.0 + x)
function code(x) return Float64(1.0 / Float64(1.0 + x)) end
function tmp = code(x) tmp = 1.0 / (1.0 + x); end
code[x_] := N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + x}
\end{array}
Initial program 53.6%
flip--54.5%
div-inv54.5%
add-sqr-sqrt54.0%
add-sqr-sqrt54.5%
Applied egg-rr54.5%
associate-*r/54.5%
*-rgt-identity54.5%
remove-double-neg54.5%
sub-neg54.5%
div-sub53.6%
rem-square-sqrt53.5%
sqr-neg53.5%
div-sub54.0%
+-commutative54.0%
sqr-neg54.0%
rem-square-sqrt54.5%
associate--l+99.7%
+-inverses99.7%
metadata-eval99.7%
sub-neg99.7%
remove-double-neg99.7%
Simplified99.7%
expm1-log1p-u99.7%
expm1-udef54.9%
Applied egg-rr51.3%
expm1-def58.7%
expm1-log1p58.7%
Simplified58.7%
Taylor expanded in x around 0 52.1%
Final simplification52.1%
(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 53.6%
Taylor expanded in x around 0 52.0%
Final simplification52.0%
(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 2023285
(FPCore (x)
:name "Main:bigenough3 from C"
:precision binary64
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))