2isqrt (example 3.6)

Percentage Accurate: 38.3% → 99.6%
Time: 23.3s
Alternatives: 10
Speedup: 1.0×

Specification

?
\[x > 1 \land x < 10^{+308}\]
\[\begin{array}{l} \\ \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
	return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x):
	return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x)
	return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0))))
end
function tmp = code(x)
	tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
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]
\begin{array}{l}

\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 38.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
	return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x):
	return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x)
	return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0))))
end
function tmp = code(x)
	tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
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]
\begin{array}{l}

\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}

Alternative 1: 99.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (/ 1.0 (hypot (sqrt x) x)) (+ (sqrt x) (sqrt (+ 1.0 x)))))
double code(double x) {
	return (1.0 / hypot(sqrt(x), x)) / (sqrt(x) + sqrt((1.0 + x)));
}
public static double code(double x) {
	return (1.0 / Math.hypot(Math.sqrt(x), x)) / (Math.sqrt(x) + Math.sqrt((1.0 + x)));
}
def code(x):
	return (1.0 / math.hypot(math.sqrt(x), x)) / (math.sqrt(x) + math.sqrt((1.0 + x)))
function code(x)
	return Float64(Float64(1.0 / hypot(sqrt(x), x)) / Float64(sqrt(x) + sqrt(Float64(1.0 + x))))
end
function tmp = code(x)
	tmp = (1.0 / hypot(sqrt(x), x)) / (sqrt(x) + sqrt((1.0 + x)));
end
code[x_] := N[(N[(1.0 / N[Sqrt[N[Sqrt[x], $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}}
\end{array}
Derivation
  1. Initial program 38.4%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-cbrt-cube7.9%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{\left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right) \cdot \sqrt{x + 1}}}} \]
    2. pow1/35.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left(\left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right) \cdot \sqrt{x + 1}\right)}^{0.3333333333333333}}} \]
    3. add-sqr-sqrt5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left(\color{blue}{\left(x + 1\right)} \cdot \sqrt{x + 1}\right)}^{0.3333333333333333}} \]
    4. pow15.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left(\color{blue}{{\left(x + 1\right)}^{1}} \cdot \sqrt{x + 1}\right)}^{0.3333333333333333}} \]
    5. pow1/25.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left({\left(x + 1\right)}^{1} \cdot \color{blue}{{\left(x + 1\right)}^{0.5}}\right)}^{0.3333333333333333}} \]
    6. pow-prod-up5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\color{blue}{\left({\left(x + 1\right)}^{\left(1 + 0.5\right)}\right)}}^{0.3333333333333333}} \]
    7. +-commutative5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left({\color{blue}{\left(1 + x\right)}}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333}} \]
    8. metadata-eval5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left({\left(1 + x\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333}} \]
  4. Applied egg-rr5.8%

    \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left({\left(1 + x\right)}^{1.5}\right)}^{0.3333333333333333}}} \]
  5. Step-by-step derivation
    1. unpow1/37.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{{\left(1 + x\right)}^{1.5}}}} \]
  6. Simplified7.8%

    \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{{\left(1 + x\right)}^{1.5}}}} \]
  7. Step-by-step derivation
    1. pow1/35.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left({\left(1 + x\right)}^{1.5}\right)}^{0.3333333333333333}}} \]
    2. pow-pow38.4%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left(1 + x\right)}^{\left(1.5 \cdot 0.3333333333333333\right)}}} \]
    3. metadata-eval38.4%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left(1 + x\right)}^{\color{blue}{0.5}}} \]
    4. pow1/238.4%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt{1 + x}}} \]
    5. frac-sub38.5%

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{1 + x} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{1 + x}}} \]
    6. *-un-lft-identity38.5%

      \[\leadsto \frac{\color{blue}{\sqrt{1 + x}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{1 + x}} \]
    7. *-rgt-identity38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \color{blue}{\sqrt{x}}}{\sqrt{x} \cdot \sqrt{1 + x}} \]
    8. sqrt-prod38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x \cdot \left(1 + x\right)}}} \]
    9. div-inv38.5%

      \[\leadsto \color{blue}{\left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \frac{1}{\sqrt{x \cdot \left(1 + x\right)}}} \]
    10. flip--38.9%

      \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}} \cdot \frac{1}{\sqrt{x \cdot \left(1 + x\right)}} \]
    11. frac-times38.9%

      \[\leadsto \color{blue}{\frac{\left(\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}\right) \cdot 1}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \sqrt{x \cdot \left(1 + x\right)}}} \]
  8. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\frac{\left(1 + \left(x - x\right)\right) \cdot 1}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)}} \]
  9. Step-by-step derivation
    1. *-rgt-identity99.1%

      \[\leadsto \frac{\color{blue}{1 + \left(x - x\right)}}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)} \]
    2. +-inverses99.1%

      \[\leadsto \frac{1 + \color{blue}{0}}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)} \]
    3. metadata-eval99.1%

      \[\leadsto \frac{\color{blue}{1}}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)} \]
    4. *-commutative99.1%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}} \]
  10. Simplified99.1%

    \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}} \]
  11. Step-by-step derivation
    1. expm1-log1p-u99.1%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}\right)\right)} \]
    2. expm1-udef37.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}\right)} - 1} \]
    3. associate-/r*37.4%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{1 + x} + \sqrt{x}}}\right)} - 1 \]
    4. +-commutative37.4%

      \[\leadsto e^{\mathsf{log1p}\left(\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\color{blue}{\sqrt{x} + \sqrt{1 + x}}}\right)} - 1 \]
  12. Applied egg-rr37.4%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}}\right)} - 1} \]
  13. Step-by-step derivation
    1. expm1-def99.7%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}}\right)\right)} \]
    2. expm1-log1p99.7%

      \[\leadsto \color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}}} \]
  14. Simplified99.7%

    \[\leadsto \color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}}} \]
  15. Final simplification99.7%

    \[\leadsto \frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}} \]
  16. Add Preprocessing

Alternative 2: 98.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ 1.0 (* (hypot (sqrt x) x) (+ (sqrt x) (sqrt (+ 1.0 x))))))
double code(double x) {
	return 1.0 / (hypot(sqrt(x), x) * (sqrt(x) + sqrt((1.0 + x))));
}
public static double code(double x) {
	return 1.0 / (Math.hypot(Math.sqrt(x), x) * (Math.sqrt(x) + Math.sqrt((1.0 + x))));
}
def code(x):
	return 1.0 / (math.hypot(math.sqrt(x), x) * (math.sqrt(x) + math.sqrt((1.0 + x))))
function code(x)
	return Float64(1.0 / Float64(hypot(sqrt(x), x) * Float64(sqrt(x) + sqrt(Float64(1.0 + x)))))
end
function tmp = code(x)
	tmp = 1.0 / (hypot(sqrt(x), x) * (sqrt(x) + sqrt((1.0 + x))));
end
code[x_] := N[(1.0 / N[(N[Sqrt[N[Sqrt[x], $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision] * N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}
\end{array}
Derivation
  1. Initial program 38.4%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-cbrt-cube7.9%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{\left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right) \cdot \sqrt{x + 1}}}} \]
    2. pow1/35.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left(\left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right) \cdot \sqrt{x + 1}\right)}^{0.3333333333333333}}} \]
    3. add-sqr-sqrt5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left(\color{blue}{\left(x + 1\right)} \cdot \sqrt{x + 1}\right)}^{0.3333333333333333}} \]
    4. pow15.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left(\color{blue}{{\left(x + 1\right)}^{1}} \cdot \sqrt{x + 1}\right)}^{0.3333333333333333}} \]
    5. pow1/25.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left({\left(x + 1\right)}^{1} \cdot \color{blue}{{\left(x + 1\right)}^{0.5}}\right)}^{0.3333333333333333}} \]
    6. pow-prod-up5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\color{blue}{\left({\left(x + 1\right)}^{\left(1 + 0.5\right)}\right)}}^{0.3333333333333333}} \]
    7. +-commutative5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left({\color{blue}{\left(1 + x\right)}}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333}} \]
    8. metadata-eval5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left({\left(1 + x\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333}} \]
  4. Applied egg-rr5.8%

    \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left({\left(1 + x\right)}^{1.5}\right)}^{0.3333333333333333}}} \]
  5. Step-by-step derivation
    1. unpow1/37.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{{\left(1 + x\right)}^{1.5}}}} \]
  6. Simplified7.8%

    \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{{\left(1 + x\right)}^{1.5}}}} \]
  7. Step-by-step derivation
    1. pow1/35.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left({\left(1 + x\right)}^{1.5}\right)}^{0.3333333333333333}}} \]
    2. pow-pow38.4%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left(1 + x\right)}^{\left(1.5 \cdot 0.3333333333333333\right)}}} \]
    3. metadata-eval38.4%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left(1 + x\right)}^{\color{blue}{0.5}}} \]
    4. pow1/238.4%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt{1 + x}}} \]
    5. frac-sub38.5%

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{1 + x} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{1 + x}}} \]
    6. *-un-lft-identity38.5%

      \[\leadsto \frac{\color{blue}{\sqrt{1 + x}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{1 + x}} \]
    7. *-rgt-identity38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \color{blue}{\sqrt{x}}}{\sqrt{x} \cdot \sqrt{1 + x}} \]
    8. sqrt-prod38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x \cdot \left(1 + x\right)}}} \]
    9. div-inv38.5%

      \[\leadsto \color{blue}{\left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \frac{1}{\sqrt{x \cdot \left(1 + x\right)}}} \]
    10. flip--38.9%

      \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}} \cdot \frac{1}{\sqrt{x \cdot \left(1 + x\right)}} \]
    11. frac-times38.9%

      \[\leadsto \color{blue}{\frac{\left(\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}\right) \cdot 1}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \sqrt{x \cdot \left(1 + x\right)}}} \]
  8. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\frac{\left(1 + \left(x - x\right)\right) \cdot 1}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)}} \]
  9. Step-by-step derivation
    1. *-rgt-identity99.1%

      \[\leadsto \frac{\color{blue}{1 + \left(x - x\right)}}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)} \]
    2. +-inverses99.1%

      \[\leadsto \frac{1 + \color{blue}{0}}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)} \]
    3. metadata-eval99.1%

      \[\leadsto \frac{\color{blue}{1}}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)} \]
    4. *-commutative99.1%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}} \]
  10. Simplified99.1%

    \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}} \]
  11. Final simplification99.1%

    \[\leadsto \frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)} \]
  12. Add Preprocessing

Alternative 3: 98.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{x + 0.5} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (/ 1.0 (+ (sqrt x) (sqrt (+ 1.0 x)))) (+ x 0.5)))
double code(double x) {
	return (1.0 / (sqrt(x) + sqrt((1.0 + x)))) / (x + 0.5);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / (sqrt(x) + sqrt((1.0d0 + x)))) / (x + 0.5d0)
end function
public static double code(double x) {
	return (1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x)))) / (x + 0.5);
}
def code(x):
	return (1.0 / (math.sqrt(x) + math.sqrt((1.0 + x)))) / (x + 0.5)
function code(x)
	return Float64(Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) / Float64(x + 0.5))
end
function tmp = code(x)
	tmp = (1.0 / (sqrt(x) + sqrt((1.0 + x)))) / (x + 0.5);
end
code[x_] := N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{x + 0.5}
\end{array}
Derivation
  1. Initial program 38.4%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. frac-sub38.5%

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
    2. *-un-lft-identity38.5%

      \[\leadsto \frac{\color{blue}{\sqrt{x + 1}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    3. +-commutative38.5%

      \[\leadsto \frac{\sqrt{\color{blue}{1 + x}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    4. *-rgt-identity38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \color{blue}{\sqrt{x}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    5. sqrt-unprod38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x \cdot \left(x + 1\right)}}} \]
    6. +-commutative38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x \cdot \color{blue}{\left(1 + x\right)}}} \]
  4. Applied egg-rr38.5%

    \[\leadsto \color{blue}{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x \cdot \left(1 + x\right)}}} \]
  5. Taylor expanded in x around inf 38.1%

    \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{0.5 + x}} \]
  6. Step-by-step derivation
    1. +-commutative38.1%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{x + 0.5}} \]
  7. Simplified38.1%

    \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{x + 0.5}} \]
  8. Step-by-step derivation
    1. flip--38.4%

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}}}{x + 0.5} \]
    2. div-inv38.4%

      \[\leadsto \frac{\color{blue}{\left(\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{1 + x} + \sqrt{x}}}}{x + 0.5} \]
    3. add-sqr-sqrt22.1%

      \[\leadsto \frac{\left(\color{blue}{\left(1 + x\right)} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{1 + x} + \sqrt{x}}}{x + 0.5} \]
    4. add-sqr-sqrt40.7%

      \[\leadsto \frac{\left(\left(1 + x\right) - \color{blue}{x}\right) \cdot \frac{1}{\sqrt{1 + x} + \sqrt{x}}}{x + 0.5} \]
    5. associate--l+99.0%

      \[\leadsto \frac{\color{blue}{\left(1 + \left(x - x\right)\right)} \cdot \frac{1}{\sqrt{1 + x} + \sqrt{x}}}{x + 0.5} \]
  9. Applied egg-rr99.0%

    \[\leadsto \frac{\color{blue}{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{\sqrt{1 + x} + \sqrt{x}}}}{x + 0.5} \]
  10. Step-by-step derivation
    1. +-inverses99.0%

      \[\leadsto \frac{\left(1 + \color{blue}{0}\right) \cdot \frac{1}{\sqrt{1 + x} + \sqrt{x}}}{x + 0.5} \]
    2. metadata-eval99.0%

      \[\leadsto \frac{\color{blue}{1} \cdot \frac{1}{\sqrt{1 + x} + \sqrt{x}}}{x + 0.5} \]
    3. *-lft-identity99.0%

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}}{x + 0.5} \]
  11. Simplified99.0%

    \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}}{x + 0.5} \]
  12. Final simplification99.0%

    \[\leadsto \frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{x + 0.5} \]
  13. Add Preprocessing

Alternative 4: 97.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\frac{1}{x}}{\sqrt{x} + \sqrt{1 + x}} \end{array} \]
(FPCore (x) :precision binary64 (/ (/ 1.0 x) (+ (sqrt x) (sqrt (+ 1.0 x)))))
double code(double x) {
	return (1.0 / x) / (sqrt(x) + sqrt((1.0 + x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / x) / (sqrt(x) + sqrt((1.0d0 + x)))
end function
public static double code(double x) {
	return (1.0 / x) / (Math.sqrt(x) + Math.sqrt((1.0 + x)));
}
def code(x):
	return (1.0 / x) / (math.sqrt(x) + math.sqrt((1.0 + x)))
function code(x)
	return Float64(Float64(1.0 / x) / Float64(sqrt(x) + sqrt(Float64(1.0 + x))))
end
function tmp = code(x)
	tmp = (1.0 / x) / (sqrt(x) + sqrt((1.0 + x)));
end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{1}{x}}{\sqrt{x} + \sqrt{1 + x}}
\end{array}
Derivation
  1. Initial program 38.4%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-cbrt-cube7.9%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{\left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right) \cdot \sqrt{x + 1}}}} \]
    2. pow1/35.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left(\left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right) \cdot \sqrt{x + 1}\right)}^{0.3333333333333333}}} \]
    3. add-sqr-sqrt5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left(\color{blue}{\left(x + 1\right)} \cdot \sqrt{x + 1}\right)}^{0.3333333333333333}} \]
    4. pow15.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left(\color{blue}{{\left(x + 1\right)}^{1}} \cdot \sqrt{x + 1}\right)}^{0.3333333333333333}} \]
    5. pow1/25.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left({\left(x + 1\right)}^{1} \cdot \color{blue}{{\left(x + 1\right)}^{0.5}}\right)}^{0.3333333333333333}} \]
    6. pow-prod-up5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\color{blue}{\left({\left(x + 1\right)}^{\left(1 + 0.5\right)}\right)}}^{0.3333333333333333}} \]
    7. +-commutative5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left({\color{blue}{\left(1 + x\right)}}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333}} \]
    8. metadata-eval5.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left({\left(1 + x\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333}} \]
  4. Applied egg-rr5.8%

    \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left({\left(1 + x\right)}^{1.5}\right)}^{0.3333333333333333}}} \]
  5. Step-by-step derivation
    1. unpow1/37.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{{\left(1 + x\right)}^{1.5}}}} \]
  6. Simplified7.8%

    \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{{\left(1 + x\right)}^{1.5}}}} \]
  7. Step-by-step derivation
    1. pow1/35.8%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left({\left(1 + x\right)}^{1.5}\right)}^{0.3333333333333333}}} \]
    2. pow-pow38.4%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left(1 + x\right)}^{\left(1.5 \cdot 0.3333333333333333\right)}}} \]
    3. metadata-eval38.4%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{{\left(1 + x\right)}^{\color{blue}{0.5}}} \]
    4. pow1/238.4%

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt{1 + x}}} \]
    5. frac-sub38.5%

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{1 + x} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{1 + x}}} \]
    6. *-un-lft-identity38.5%

      \[\leadsto \frac{\color{blue}{\sqrt{1 + x}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{1 + x}} \]
    7. *-rgt-identity38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \color{blue}{\sqrt{x}}}{\sqrt{x} \cdot \sqrt{1 + x}} \]
    8. sqrt-prod38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x \cdot \left(1 + x\right)}}} \]
    9. div-inv38.5%

      \[\leadsto \color{blue}{\left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \frac{1}{\sqrt{x \cdot \left(1 + x\right)}}} \]
    10. flip--38.9%

      \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}} \cdot \frac{1}{\sqrt{x \cdot \left(1 + x\right)}} \]
    11. frac-times38.9%

      \[\leadsto \color{blue}{\frac{\left(\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}\right) \cdot 1}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \sqrt{x \cdot \left(1 + x\right)}}} \]
  8. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\frac{\left(1 + \left(x - x\right)\right) \cdot 1}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)}} \]
  9. Step-by-step derivation
    1. *-rgt-identity99.1%

      \[\leadsto \frac{\color{blue}{1 + \left(x - x\right)}}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)} \]
    2. +-inverses99.1%

      \[\leadsto \frac{1 + \color{blue}{0}}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)} \]
    3. metadata-eval99.1%

      \[\leadsto \frac{\color{blue}{1}}{\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \mathsf{hypot}\left(\sqrt{x}, x\right)} \]
    4. *-commutative99.1%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}} \]
  10. Simplified99.1%

    \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}} \]
  11. Step-by-step derivation
    1. expm1-log1p-u99.1%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}\right)\right)} \]
    2. expm1-udef37.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}\right)} - 1} \]
    3. associate-/r*37.4%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{1 + x} + \sqrt{x}}}\right)} - 1 \]
    4. +-commutative37.4%

      \[\leadsto e^{\mathsf{log1p}\left(\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\color{blue}{\sqrt{x} + \sqrt{1 + x}}}\right)} - 1 \]
  12. Applied egg-rr37.4%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}}\right)} - 1} \]
  13. Step-by-step derivation
    1. expm1-def99.7%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}}\right)\right)} \]
    2. expm1-log1p99.7%

      \[\leadsto \color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}}} \]
  14. Simplified99.7%

    \[\leadsto \color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(\sqrt{x}, x\right)}}{\sqrt{x} + \sqrt{1 + x}}} \]
  15. Taylor expanded in x around inf 97.9%

    \[\leadsto \frac{\color{blue}{\frac{1}{x}}}{\sqrt{x} + \sqrt{1 + x}} \]
  16. Final simplification97.9%

    \[\leadsto \frac{\frac{1}{x}}{\sqrt{x} + \sqrt{1 + x}} \]
  17. Add Preprocessing

Alternative 5: 65.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \sqrt{\frac{1}{{x}^{3}}} \end{array} \]
(FPCore (x) :precision binary64 (* 0.5 (sqrt (/ 1.0 (pow x 3.0)))))
double code(double x) {
	return 0.5 * sqrt((1.0 / pow(x, 3.0)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 0.5d0 * sqrt((1.0d0 / (x ** 3.0d0)))
end function
public static double code(double x) {
	return 0.5 * Math.sqrt((1.0 / Math.pow(x, 3.0)));
}
def code(x):
	return 0.5 * math.sqrt((1.0 / math.pow(x, 3.0)))
function code(x)
	return Float64(0.5 * sqrt(Float64(1.0 / (x ^ 3.0))))
end
function tmp = code(x)
	tmp = 0.5 * sqrt((1.0 / (x ^ 3.0)));
end
code[x_] := N[(0.5 * N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}
\end{array}
Derivation
  1. Initial program 38.4%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. flip--38.4%

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}} \]
    2. frac-times20.6%

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1}{\sqrt{x} \cdot \sqrt{x}}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    3. metadata-eval20.6%

      \[\leadsto \frac{\frac{\color{blue}{1}}{\sqrt{x} \cdot \sqrt{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    4. add-sqr-sqrt19.2%

      \[\leadsto \frac{\frac{1}{\color{blue}{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    5. frac-times24.4%

      \[\leadsto \frac{\frac{1}{x} - \color{blue}{\frac{1 \cdot 1}{\sqrt{x + 1} \cdot \sqrt{x + 1}}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    6. metadata-eval24.4%

      \[\leadsto \frac{\frac{1}{x} - \frac{\color{blue}{1}}{\sqrt{x + 1} \cdot \sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    7. add-sqr-sqrt38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{\color{blue}{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    8. +-commutative38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{\color{blue}{1 + x}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    9. pow1/238.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{\frac{1}{\color{blue}{{x}^{0.5}}} + \frac{1}{\sqrt{x + 1}}} \]
    10. pow-flip38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{\color{blue}{{x}^{\left(-0.5\right)}} + \frac{1}{\sqrt{x + 1}}} \]
    11. metadata-eval38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{\color{blue}{-0.5}} + \frac{1}{\sqrt{x + 1}}} \]
    12. inv-pow38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + \color{blue}{{\left(\sqrt{x + 1}\right)}^{-1}}} \]
    13. sqrt-pow238.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + \color{blue}{{\left(x + 1\right)}^{\left(\frac{-1}{2}\right)}}} \]
    14. +-commutative38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + {\color{blue}{\left(1 + x\right)}}^{\left(\frac{-1}{2}\right)}} \]
    15. metadata-eval38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + {\left(1 + x\right)}^{\color{blue}{-0.5}}} \]
  4. Applied egg-rr38.5%

    \[\leadsto \color{blue}{\frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
  5. Taylor expanded in x around inf 66.1%

    \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}} \]
  6. Final simplification66.1%

    \[\leadsto 0.5 \cdot \sqrt{\frac{1}{{x}^{3}}} \]
  7. Add Preprocessing

Alternative 6: 37.4% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \frac{\frac{1}{x} + \frac{-1}{1 + x}}{2 \cdot \sqrt{\frac{1}{x}}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (+ (/ 1.0 x) (/ -1.0 (+ 1.0 x))) (* 2.0 (sqrt (/ 1.0 x)))))
double code(double x) {
	return ((1.0 / x) + (-1.0 / (1.0 + x))) / (2.0 * sqrt((1.0 / x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = ((1.0d0 / x) + ((-1.0d0) / (1.0d0 + x))) / (2.0d0 * sqrt((1.0d0 / x)))
end function
public static double code(double x) {
	return ((1.0 / x) + (-1.0 / (1.0 + x))) / (2.0 * Math.sqrt((1.0 / x)));
}
def code(x):
	return ((1.0 / x) + (-1.0 / (1.0 + x))) / (2.0 * math.sqrt((1.0 / x)))
function code(x)
	return Float64(Float64(Float64(1.0 / x) + Float64(-1.0 / Float64(1.0 + x))) / Float64(2.0 * sqrt(Float64(1.0 / x))))
end
function tmp = code(x)
	tmp = ((1.0 / x) + (-1.0 / (1.0 + x))) / (2.0 * sqrt((1.0 / x)));
end
code[x_] := N[(N[(N[(1.0 / x), $MachinePrecision] + N[(-1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{1}{x} + \frac{-1}{1 + x}}{2 \cdot \sqrt{\frac{1}{x}}}
\end{array}
Derivation
  1. Initial program 38.4%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. flip--38.4%

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}} \]
    2. frac-times20.6%

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1}{\sqrt{x} \cdot \sqrt{x}}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    3. metadata-eval20.6%

      \[\leadsto \frac{\frac{\color{blue}{1}}{\sqrt{x} \cdot \sqrt{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    4. add-sqr-sqrt19.2%

      \[\leadsto \frac{\frac{1}{\color{blue}{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    5. frac-times24.4%

      \[\leadsto \frac{\frac{1}{x} - \color{blue}{\frac{1 \cdot 1}{\sqrt{x + 1} \cdot \sqrt{x + 1}}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    6. metadata-eval24.4%

      \[\leadsto \frac{\frac{1}{x} - \frac{\color{blue}{1}}{\sqrt{x + 1} \cdot \sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    7. add-sqr-sqrt38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{\color{blue}{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    8. +-commutative38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{\color{blue}{1 + x}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}} \]
    9. pow1/238.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{\frac{1}{\color{blue}{{x}^{0.5}}} + \frac{1}{\sqrt{x + 1}}} \]
    10. pow-flip38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{\color{blue}{{x}^{\left(-0.5\right)}} + \frac{1}{\sqrt{x + 1}}} \]
    11. metadata-eval38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{\color{blue}{-0.5}} + \frac{1}{\sqrt{x + 1}}} \]
    12. inv-pow38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + \color{blue}{{\left(\sqrt{x + 1}\right)}^{-1}}} \]
    13. sqrt-pow238.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + \color{blue}{{\left(x + 1\right)}^{\left(\frac{-1}{2}\right)}}} \]
    14. +-commutative38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + {\color{blue}{\left(1 + x\right)}}^{\left(\frac{-1}{2}\right)}} \]
    15. metadata-eval38.5%

      \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + {\left(1 + x\right)}^{\color{blue}{-0.5}}} \]
  4. Applied egg-rr38.5%

    \[\leadsto \color{blue}{\frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
  5. Taylor expanded in x around inf 37.7%

    \[\leadsto \frac{\frac{1}{x} - \frac{1}{1 + x}}{\color{blue}{2 \cdot \sqrt{\frac{1}{x}}}} \]
  6. Final simplification37.7%

    \[\leadsto \frac{\frac{1}{x} + \frac{-1}{1 + x}}{2 \cdot \sqrt{\frac{1}{x}}} \]
  7. Add Preprocessing

Alternative 7: 37.5% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\sqrt{x \cdot \left(1 + x\right)}} \end{array} \]
(FPCore (x) :precision binary64 (/ 1.0 (sqrt (* x (+ 1.0 x)))))
double code(double x) {
	return 1.0 / sqrt((x * (1.0 + x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 / sqrt((x * (1.0d0 + x)))
end function
public static double code(double x) {
	return 1.0 / Math.sqrt((x * (1.0 + x)));
}
def code(x):
	return 1.0 / math.sqrt((x * (1.0 + x)))
function code(x)
	return Float64(1.0 / sqrt(Float64(x * Float64(1.0 + x))))
end
function tmp = code(x)
	tmp = 1.0 / sqrt((x * (1.0 + x)));
end
code[x_] := N[(1.0 / N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\sqrt{x \cdot \left(1 + x\right)}}
\end{array}
Derivation
  1. Initial program 38.4%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. frac-sub38.5%

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
    2. *-un-lft-identity38.5%

      \[\leadsto \frac{\color{blue}{\sqrt{x + 1}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    3. +-commutative38.5%

      \[\leadsto \frac{\sqrt{\color{blue}{1 + x}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    4. *-rgt-identity38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \color{blue}{\sqrt{x}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    5. sqrt-unprod38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x \cdot \left(x + 1\right)}}} \]
    6. +-commutative38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x \cdot \color{blue}{\left(1 + x\right)}}} \]
  4. Applied egg-rr38.5%

    \[\leadsto \color{blue}{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x \cdot \left(1 + x\right)}}} \]
  5. Taylor expanded in x around 0 37.7%

    \[\leadsto \frac{\color{blue}{1}}{\sqrt{x \cdot \left(1 + x\right)}} \]
  6. Final simplification37.7%

    \[\leadsto \frac{1}{\sqrt{x \cdot \left(1 + x\right)}} \]
  7. Add Preprocessing

Alternative 8: 36.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \left(1 + {x}^{-0.5}\right) + -1 \end{array} \]
(FPCore (x) :precision binary64 (+ (+ 1.0 (pow x -0.5)) -1.0))
double code(double x) {
	return (1.0 + pow(x, -0.5)) + -1.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 + (x ** (-0.5d0))) + (-1.0d0)
end function
public static double code(double x) {
	return (1.0 + Math.pow(x, -0.5)) + -1.0;
}
def code(x):
	return (1.0 + math.pow(x, -0.5)) + -1.0
function code(x)
	return Float64(Float64(1.0 + (x ^ -0.5)) + -1.0)
end
function tmp = code(x)
	tmp = (1.0 + (x ^ -0.5)) + -1.0;
end
code[x_] := N[(N[(1.0 + N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}

\\
\left(1 + {x}^{-0.5}\right) + -1
\end{array}
Derivation
  1. Initial program 38.4%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. expm1-log1p-u38.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{x}}\right)\right)} - \frac{1}{\sqrt{x + 1}} \]
    2. expm1-udef5.2%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x}}\right)} - 1\right)} - \frac{1}{\sqrt{x + 1}} \]
    3. pow1/25.2%

      \[\leadsto \left(e^{\mathsf{log1p}\left(\frac{1}{\color{blue}{{x}^{0.5}}}\right)} - 1\right) - \frac{1}{\sqrt{x + 1}} \]
    4. pow-flip5.2%

      \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{{x}^{\left(-0.5\right)}}\right)} - 1\right) - \frac{1}{\sqrt{x + 1}} \]
    5. metadata-eval5.2%

      \[\leadsto \left(e^{\mathsf{log1p}\left({x}^{\color{blue}{-0.5}}\right)} - 1\right) - \frac{1}{\sqrt{x + 1}} \]
  4. Applied egg-rr5.2%

    \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{-0.5}\right)} - 1\right)} - \frac{1}{\sqrt{x + 1}} \]
  5. Step-by-step derivation
    1. expm1-def31.2%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{-0.5}\right)\right)} - \frac{1}{\sqrt{x + 1}} \]
    2. expm1-log1p31.2%

      \[\leadsto \color{blue}{{x}^{-0.5}} - \frac{1}{\sqrt{x + 1}} \]
  6. Simplified31.2%

    \[\leadsto \color{blue}{{x}^{-0.5}} - \frac{1}{\sqrt{x + 1}} \]
  7. Taylor expanded in x around inf 5.6%

    \[\leadsto \color{blue}{\sqrt{\frac{1}{x}}} \]
  8. Step-by-step derivation
    1. inv-pow5.6%

      \[\leadsto \sqrt{\color{blue}{{x}^{-1}}} \]
    2. sqrt-pow15.6%

      \[\leadsto \color{blue}{{x}^{\left(\frac{-1}{2}\right)}} \]
    3. metadata-eval5.6%

      \[\leadsto {x}^{\color{blue}{-0.5}} \]
    4. expm1-log1p-u5.6%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{-0.5}\right)\right)} \]
    5. expm1-udef36.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left({x}^{-0.5}\right)} - 1} \]
    6. log1p-udef36.4%

      \[\leadsto e^{\color{blue}{\log \left(1 + {x}^{-0.5}\right)}} - 1 \]
    7. add-exp-log36.4%

      \[\leadsto \color{blue}{\left(1 + {x}^{-0.5}\right)} - 1 \]
  9. Applied egg-rr36.4%

    \[\leadsto \color{blue}{\left(1 + {x}^{-0.5}\right) - 1} \]
  10. Final simplification36.4%

    \[\leadsto \left(1 + {x}^{-0.5}\right) + -1 \]
  11. Add Preprocessing

Alternative 9: 7.8% accurate, 41.8× speedup?

\[\begin{array}{l} \\ \frac{1}{x + 0.5} \end{array} \]
(FPCore (x) :precision binary64 (/ 1.0 (+ x 0.5)))
double code(double x) {
	return 1.0 / (x + 0.5);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 / (x + 0.5d0)
end function
public static double code(double x) {
	return 1.0 / (x + 0.5);
}
def code(x):
	return 1.0 / (x + 0.5)
function code(x)
	return Float64(1.0 / Float64(x + 0.5))
end
function tmp = code(x)
	tmp = 1.0 / (x + 0.5);
end
code[x_] := N[(1.0 / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{x + 0.5}
\end{array}
Derivation
  1. Initial program 38.4%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. frac-sub38.5%

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
    2. *-un-lft-identity38.5%

      \[\leadsto \frac{\color{blue}{\sqrt{x + 1}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    3. +-commutative38.5%

      \[\leadsto \frac{\sqrt{\color{blue}{1 + x}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    4. *-rgt-identity38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \color{blue}{\sqrt{x}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    5. sqrt-unprod38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x \cdot \left(x + 1\right)}}} \]
    6. +-commutative38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x \cdot \color{blue}{\left(1 + x\right)}}} \]
  4. Applied egg-rr38.5%

    \[\leadsto \color{blue}{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x \cdot \left(1 + x\right)}}} \]
  5. Taylor expanded in x around inf 38.1%

    \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{0.5 + x}} \]
  6. Step-by-step derivation
    1. +-commutative38.1%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{x + 0.5}} \]
  7. Simplified38.1%

    \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{x + 0.5}} \]
  8. Taylor expanded in x around 0 7.7%

    \[\leadsto \frac{\color{blue}{1}}{x + 0.5} \]
  9. Final simplification7.7%

    \[\leadsto \frac{1}{x + 0.5} \]
  10. Add Preprocessing

Alternative 10: 4.6% accurate, 209.0× speedup?

\[\begin{array}{l} \\ 2 \end{array} \]
(FPCore (x) :precision binary64 2.0)
double code(double x) {
	return 2.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 2.0d0
end function
public static double code(double x) {
	return 2.0;
}
def code(x):
	return 2.0
function code(x)
	return 2.0
end
function tmp = code(x)
	tmp = 2.0;
end
code[x_] := 2.0
\begin{array}{l}

\\
2
\end{array}
Derivation
  1. Initial program 38.4%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. frac-sub38.5%

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
    2. *-un-lft-identity38.5%

      \[\leadsto \frac{\color{blue}{\sqrt{x + 1}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    3. +-commutative38.5%

      \[\leadsto \frac{\sqrt{\color{blue}{1 + x}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    4. *-rgt-identity38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \color{blue}{\sqrt{x}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    5. sqrt-unprod38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x \cdot \left(x + 1\right)}}} \]
    6. +-commutative38.5%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x \cdot \color{blue}{\left(1 + x\right)}}} \]
  4. Applied egg-rr38.5%

    \[\leadsto \color{blue}{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x \cdot \left(1 + x\right)}}} \]
  5. Taylor expanded in x around inf 38.1%

    \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{0.5 + x}} \]
  6. Step-by-step derivation
    1. +-commutative38.1%

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{x + 0.5}} \]
  7. Simplified38.1%

    \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{x + 0.5}} \]
  8. Taylor expanded in x around 0 4.6%

    \[\leadsto \color{blue}{2} \]
  9. Final simplification4.6%

    \[\leadsto 2 \]
  10. Add Preprocessing

Developer target: 98.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0))))))
double code(double x) {
	return 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 / (((x + 1.0d0) * sqrt(x)) + (x * sqrt((x + 1.0d0))))
end function
public static double code(double x) {
	return 1.0 / (((x + 1.0) * Math.sqrt(x)) + (x * Math.sqrt((x + 1.0))));
}
def code(x):
	return 1.0 / (((x + 1.0) * math.sqrt(x)) + (x * math.sqrt((x + 1.0))))
function code(x)
	return Float64(1.0 / Float64(Float64(Float64(x + 1.0) * sqrt(x)) + Float64(x * sqrt(Float64(x + 1.0)))))
end
function tmp = code(x)
	tmp = 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0))));
end
code[x_] := N[(1.0 / N[(N[(N[(x + 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}
\end{array}

Reproduce

?
herbie shell --seed 2024031 
(FPCore (x)
  :name "2isqrt (example 3.6)"
  :precision binary64
  :pre (and (> x 1.0) (< x 1e+308))

  :herbie-target
  (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))

  (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))