| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 58688 |
\[\begin{array}{l}
t_0 := \sqrt{x} + \sqrt{1 + x}\\
\frac{\frac{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}}{\sqrt[3]{{t_0}^{2}}}}{\sqrt[3]{t_0}}
\end{array}
\]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 0.0)
(* 0.5 (pow x -1.5))
(/ (* (+ 1.0 (- x x)) (/ 1.0 (sqrt (+ x (* x x))))) (+ (sqrt x) t_0)))))double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
tmp = 0.5 * pow(x, -1.5);
} else {
tmp = ((1.0 + (x - x)) * (1.0 / sqrt((x + (x * x))))) / (sqrt(x) + t_0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
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))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 0.0d0) then
tmp = 0.5d0 * (x ** (-1.5d0))
else
tmp = ((1.0d0 + (x - x)) * (1.0d0 / sqrt((x + (x * x))))) / (sqrt(x) + t_0)
end if
code = tmp
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
tmp = 0.5 * Math.pow(x, -1.5);
} else {
tmp = ((1.0 + (x - x)) * (1.0 / Math.sqrt((x + (x * x))))) / (Math.sqrt(x) + t_0);
}
return tmp;
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 0.0: tmp = 0.5 * math.pow(x, -1.5) else: tmp = ((1.0 + (x - x)) * (1.0 / math.sqrt((x + (x * x))))) / (math.sqrt(x) + t_0) return tmp
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 0.0) tmp = Float64(0.5 * (x ^ -1.5)); else tmp = Float64(Float64(Float64(1.0 + Float64(x - x)) * Float64(1.0 / sqrt(Float64(x + Float64(x * x))))) / Float64(sqrt(x) + t_0)); end return tmp end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) tmp = 0.5 * (x ^ -1.5); else tmp = ((1.0 + (x - x)) * (1.0 / sqrt((x + (x * x))))) / (sqrt(x) + t_0); end tmp_2 = tmp; end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 0.0], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sqrt[N[(x + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 0:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{\sqrt{x + x \cdot x}}}{\sqrt{x} + t_0}\\
\end{array}
Results
| Original | 20.0 |
|---|---|
| Target | 0.7 |
| Herbie | 0.2 |
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0Initial program 40.0
Applied egg-rr40.0
Taylor expanded in x around inf 21.8
Applied egg-rr0.8
Simplified1.0
[Start]0.8 | \[ {\left(\frac{\sqrt[3]{0.5}}{\sqrt{x}}\right)}^{3}
\] |
|---|---|
cube-div [=>]1.6 | \[ \color{blue}{\frac{{\left(\sqrt[3]{0.5}\right)}^{3}}{{\left(\sqrt{x}\right)}^{3}}}
\] |
rem-cube-cbrt [=>]1.3 | \[ \frac{\color{blue}{0.5}}{{\left(\sqrt{x}\right)}^{3}}
\] |
unpow3 [=>]1.3 | \[ \frac{0.5}{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \sqrt{x}}}
\] |
rem-square-sqrt [=>]1.0 | \[ \frac{0.5}{\color{blue}{x} \cdot \sqrt{x}}
\] |
Applied egg-rr40.0
Simplified0.0
[Start]40.0 | \[ \left(1 + \frac{0.5}{{x}^{1.5}}\right) - 1
\] |
|---|---|
+-commutative [=>]40.0 | \[ \color{blue}{\left(\frac{0.5}{{x}^{1.5}} + 1\right)} - 1
\] |
associate--l+ [=>]1.0 | \[ \color{blue}{\frac{0.5}{{x}^{1.5}} + \left(1 - 1\right)}
\] |
metadata-eval [=>]1.0 | \[ \frac{0.5}{{x}^{1.5}} + \color{blue}{0}
\] |
+-rgt-identity [=>]1.0 | \[ \color{blue}{\frac{0.5}{{x}^{1.5}}}
\] |
metadata-eval [<=]1.0 | \[ \frac{\color{blue}{0.5 \cdot 1}}{{x}^{1.5}}
\] |
associate-*r/ [<=]1.0 | \[ \color{blue}{0.5 \cdot \frac{1}{{x}^{1.5}}}
\] |
rem-exp-log [<=]4.7 | \[ 0.5 \cdot \frac{1}{\color{blue}{e^{\log \left({x}^{1.5}\right)}}}
\] |
rec-exp [=>]4.7 | \[ 0.5 \cdot \color{blue}{e^{-\log \left({x}^{1.5}\right)}}
\] |
log-pow [=>]4.1 | \[ 0.5 \cdot e^{-\color{blue}{1.5 \cdot \log x}}
\] |
distribute-lft-neg-in [=>]4.1 | \[ 0.5 \cdot e^{\color{blue}{\left(-1.5\right) \cdot \log x}}
\] |
*-commutative [=>]4.1 | \[ 0.5 \cdot e^{\color{blue}{\log x \cdot \left(-1.5\right)}}
\] |
exp-prod [=>]3.9 | \[ 0.5 \cdot \color{blue}{{\left(e^{\log x}\right)}^{\left(-1.5\right)}}
\] |
rem-exp-log [=>]0.0 | \[ 0.5 \cdot {\color{blue}{x}}^{\left(-1.5\right)}
\] |
metadata-eval [=>]0.0 | \[ 0.5 \cdot {x}^{\color{blue}{-1.5}}
\] |
if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 1.6
Applied egg-rr0.3
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 58688 |
| Alternative 2 | |
|---|---|
| Error | 0.5 |
| Cost | 39424 |
| Alternative 3 | |
|---|---|
| Error | 0.2 |
| Cost | 33476 |
| Alternative 4 | |
|---|---|
| Error | 0.4 |
| Cost | 26692 |
| Alternative 5 | |
|---|---|
| Error | 0.7 |
| Cost | 26240 |
| Alternative 6 | |
|---|---|
| Error | 0.2 |
| Cost | 14276 |
| Alternative 7 | |
|---|---|
| Error | 0.2 |
| Cost | 14020 |
| Alternative 8 | |
|---|---|
| Error | 0.2 |
| Cost | 13764 |
| Alternative 9 | |
|---|---|
| Error | 1.0 |
| Cost | 7236 |
| Alternative 10 | |
|---|---|
| Error | 1.0 |
| Cost | 7108 |
| Alternative 11 | |
|---|---|
| Error | 1.1 |
| Cost | 6788 |
| Alternative 12 | |
|---|---|
| Error | 31.0 |
| Cost | 6656 |
| Alternative 13 | |
|---|---|
| Error | 49.6 |
| Cost | 836 |
| Alternative 14 | |
|---|---|
| Error | 49.9 |
| Cost | 708 |
| Alternative 15 | |
|---|---|
| Error | 50.0 |
| Cost | 452 |
| Alternative 16 | |
|---|---|
| Error | 60.3 |
| Cost | 64 |
herbie shell --seed 2023060
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))