?

Average Error: 20.0 → 0.2
Time: 10.8s
Precision: binary64
Cost: 33860

?

\[\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} \]
(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}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.0
Target0.7
Herbie0.2
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation?

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0

    1. Initial program 40.0

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr40.0

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

      \[\leadsto \frac{1}{\color{blue}{2 \cdot \sqrt{{x}^{3}}}} \]
    4. Applied egg-rr0.8

      \[\leadsto \color{blue}{{\left(\frac{\sqrt[3]{0.5}}{\sqrt{x}}\right)}^{3}} \]
    5. Simplified1.0

      \[\leadsto \color{blue}{\frac{0.5}{x \cdot \sqrt{x}}} \]
      Proof

      [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}} \]
    6. Applied egg-rr40.0

      \[\leadsto \color{blue}{\left(1 + \frac{0.5}{{x}^{1.5}}\right) - 1} \]
    7. Simplified0.0

      \[\leadsto \color{blue}{0.5 \cdot {x}^{-1.5}} \]
      Proof

      [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))))

    1. Initial program 1.6

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr0.3

      \[\leadsto \color{blue}{\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{\sqrt{x + x \cdot x}}}{\sqrt{x} + \sqrt{1 + x}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \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} + \sqrt{1 + x}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost58688
\[\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} \]
Alternative 2
Error0.5
Cost39424
\[\frac{\left(1 + \left(x - x\right)\right) \cdot {\left({\left(\mathsf{hypot}\left(x, \sqrt{x}\right)\right)}^{-0.5}\right)}^{2}}{\sqrt{x} + \sqrt{1 + x}} \]
Alternative 3
Error0.2
Cost33476
\[\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{1}{\left(\sqrt{x} + t_0\right) \cdot \sqrt{x + x \cdot x}}\\ \end{array} \]
Alternative 4
Error0.4
Cost26692
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 5 \cdot 10^{-15}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 5
Error0.7
Cost26240
\[\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right) \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)} \]
Alternative 6
Error0.2
Cost14276
\[\begin{array}{l} \mathbf{if}\;x \leq 6500:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + \left(0.5 - \frac{0.125}{x}\right)}}{\sqrt{x} + \sqrt{1 + x}}\\ \end{array} \]
Alternative 7
Error0.2
Cost14020
\[\begin{array}{l} \mathbf{if}\;x \leq 180000:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + 0.5}}{\sqrt{x} + \sqrt{1 + x}}\\ \end{array} \]
Alternative 8
Error0.2
Cost13764
\[\begin{array}{l} \mathbf{if}\;x \leq 180000:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 + \frac{-0.5}{x}}{x}}{\sqrt{x} + \sqrt{1 + x}}\\ \end{array} \]
Alternative 9
Error1.0
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \leq 1.7:\\ \;\;\;\;\frac{1}{\sqrt{x}} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 10
Error1.0
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{1}{\sqrt{x}} + \left(-1 + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 11
Error1.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.66:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 12
Error31.0
Cost6656
\[0.5 \cdot {x}^{-1.5} \]
Alternative 13
Error49.6
Cost836
\[\begin{array}{l} \mathbf{if}\;x \leq 4.7 \cdot 10^{+153}:\\ \;\;\;\;\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + 0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{-0.5}{x \cdot x}\right) + -1\\ \end{array} \]
Alternative 14
Error49.9
Cost708
\[\begin{array}{l} \mathbf{if}\;x \leq 2.25 \cdot 10^{+102}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{-0.5}{x \cdot x}\right) + -1\\ \end{array} \]
Alternative 15
Error50.0
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq 8.5 \cdot 10^{+122}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5}{x \cdot x}\\ \end{array} \]
Alternative 16
Error60.3
Cost64
\[2 \]

Error

Reproduce?

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)))))