| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 13248 |
\[\frac{1}{\sqrt{1 + x} + \sqrt{x}}
\]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (let* ((t_0 (- (sqrt (+ 1.0 x)) (sqrt x)))) (if (<= t_0 4e-5) (* 0.5 (pow x -0.5)) t_0)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
double t_0 = sqrt((1.0 + x)) - sqrt(x);
double tmp;
if (t_0 <= 4e-5) {
tmp = 0.5 * pow(x, -0.5);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
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 <= 4d-5) then
tmp = 0.5d0 * (x ** (-0.5d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x)) - Math.sqrt(x);
double tmp;
if (t_0 <= 4e-5) {
tmp = 0.5 * Math.pow(x, -0.5);
} else {
tmp = t_0;
}
return tmp;
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x): t_0 = math.sqrt((1.0 + x)) - math.sqrt(x) tmp = 0 if t_0 <= 4e-5: tmp = 0.5 * math.pow(x, -0.5) else: tmp = t_0 return tmp
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function code(x) t_0 = Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) tmp = 0.0 if (t_0 <= 4e-5) tmp = Float64(0.5 * (x ^ -0.5)); else tmp = t_0; end return tmp end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)) - sqrt(x); tmp = 0.0; if (t_0 <= 4e-5) tmp = 0.5 * (x ^ -0.5); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
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, 4e-5], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], t$95$0]]
\sqrt{x + 1} - \sqrt{x}
\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t_0 \leq 4 \cdot 10^{-5}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
Results
| Original | 30.1 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 4.00000000000000033e-5Initial program 60.9
Applied egg-rr61.8
Taylor expanded in x around inf 0.4
Applied egg-rr59.2
Simplified0.3
[Start]59.2 | \[ 0.5 \cdot \left(\left(1 + \sqrt{\frac{1}{x}}\right) - 1\right)
\] |
|---|---|
+-commutative [=>]59.2 | \[ 0.5 \cdot \left(\color{blue}{\left(\sqrt{\frac{1}{x}} + 1\right)} - 1\right)
\] |
associate--l+ [=>]0.4 | \[ 0.5 \cdot \color{blue}{\left(\sqrt{\frac{1}{x}} + \left(1 - 1\right)\right)}
\] |
metadata-eval [=>]0.4 | \[ 0.5 \cdot \left(\sqrt{\frac{1}{x}} + \color{blue}{0}\right)
\] |
+-rgt-identity [=>]0.4 | \[ 0.5 \cdot \color{blue}{\sqrt{\frac{1}{x}}}
\] |
unpow-1 [<=]0.4 | \[ 0.5 \cdot \sqrt{\color{blue}{{x}^{-1}}}
\] |
metadata-eval [<=]0.4 | \[ 0.5 \cdot \sqrt{{x}^{\color{blue}{\left(2 \cdot -0.5\right)}}}
\] |
pow-sqr [<=]0.3 | \[ 0.5 \cdot \sqrt{\color{blue}{{x}^{-0.5} \cdot {x}^{-0.5}}}
\] |
rem-sqrt-square [=>]0.3 | \[ 0.5 \cdot \color{blue}{\left|{x}^{-0.5}\right|}
\] |
sqr-pow [=>]0.8 | \[ 0.5 \cdot \left|\color{blue}{{x}^{\left(\frac{-0.5}{2}\right)} \cdot {x}^{\left(\frac{-0.5}{2}\right)}}\right|
\] |
fabs-sqr [=>]0.8 | \[ 0.5 \cdot \color{blue}{\left({x}^{\left(\frac{-0.5}{2}\right)} \cdot {x}^{\left(\frac{-0.5}{2}\right)}\right)}
\] |
sqr-pow [<=]0.3 | \[ 0.5 \cdot \color{blue}{{x}^{-0.5}}
\] |
if 4.00000000000000033e-5 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 0.4
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Error | 1.0 |
| Cost | 6980 |
| Alternative 3 | |
|---|---|
| Error | 1.0 |
| Cost | 6980 |
| Alternative 4 | |
|---|---|
| Error | 1.4 |
| Cost | 6852 |
| Alternative 5 | |
|---|---|
| Error | 2.1 |
| Cost | 6788 |
| Alternative 6 | |
|---|---|
| Error | 31.5 |
| Cost | 448 |
| Alternative 7 | |
|---|---|
| Error | 31.5 |
| Cost | 64 |
herbie shell --seed 2023031
(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)))