Main:bigenough3 from C

?

Percentage Accurate: 52.1% → 99.7%
Time: 6.2s
Precision: binary64
Cost: 19584

?

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

\\
\frac{1}{\sqrt{x} + \mathsf{hypot}\left(1, \sqrt{x}\right)}
\end{array}

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.

Herbie found 7 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original52.1%
Target99.7%
Herbie99.7%
\[\frac{1}{\sqrt{x + 1} + \sqrt{x}} \]

Derivation?

  1. Initial program 56.5%

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Applied egg-rr57.1%

    \[\leadsto \color{blue}{\left(\left(x + 1\right) - x\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
    Step-by-step derivation

    [Start]56.5%

    \[ \sqrt{x + 1} - \sqrt{x} \]

    flip-- [=>]56.7%

    \[ \color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}} \]

    div-inv [=>]56.7%

    \[ \color{blue}{\left(\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]

    add-sqr-sqrt [<=]56.8%

    \[ \left(\color{blue}{\left(x + 1\right)} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]

    add-sqr-sqrt [<=]57.1%

    \[ \left(\left(x + 1\right) - \color{blue}{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + x} + \sqrt{x}}} \]
    Step-by-step derivation

    [Start]57.1%

    \[ \left(\left(x + 1\right) - x\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]

    associate-*r/ [=>]57.1%

    \[ \color{blue}{\frac{\left(\left(x + 1\right) - x\right) \cdot 1}{\sqrt{x + 1} + \sqrt{x}}} \]

    *-rgt-identity [=>]57.1%

    \[ \frac{\color{blue}{\left(x + 1\right) - x}}{\sqrt{x + 1} + \sqrt{x}} \]

    remove-double-neg [<=]57.1%

    \[ \frac{\left(x + 1\right) - x}{\sqrt{x + 1} + \color{blue}{\left(-\left(-\sqrt{x}\right)\right)}} \]

    sub-neg [<=]57.1%

    \[ \frac{\left(x + 1\right) - x}{\color{blue}{\sqrt{x + 1} - \left(-\sqrt{x}\right)}} \]

    div-sub [=>]56.5%

    \[ \color{blue}{\frac{x + 1}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} - \frac{x}{\sqrt{x + 1} - \left(-\sqrt{x}\right)}} \]

    rem-square-sqrt [<=]56.4%

    \[ \frac{x + 1}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} - \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} \]

    sqr-neg [<=]56.4%

    \[ \frac{x + 1}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} - \frac{\color{blue}{\left(-\sqrt{x}\right) \cdot \left(-\sqrt{x}\right)}}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} \]

    div-sub [<=]56.8%

    \[ \color{blue}{\frac{\left(x + 1\right) - \left(-\sqrt{x}\right) \cdot \left(-\sqrt{x}\right)}{\sqrt{x + 1} - \left(-\sqrt{x}\right)}} \]

    sqr-neg [=>]56.8%

    \[ \frac{\left(x + 1\right) - \color{blue}{\sqrt{x} \cdot \sqrt{x}}}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} \]

    +-commutative [=>]56.8%

    \[ \frac{\color{blue}{\left(1 + x\right)} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} \]

    rem-square-sqrt [=>]57.1%

    \[ \frac{\left(1 + x\right) - \color{blue}{x}}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} \]

    associate--l+ [=>]99.7%

    \[ \frac{\color{blue}{1 + \left(x - x\right)}}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} \]

    +-inverses [=>]99.7%

    \[ \frac{1 + \color{blue}{0}}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} \]

    metadata-eval [=>]99.7%

    \[ \frac{\color{blue}{1}}{\sqrt{x + 1} - \left(-\sqrt{x}\right)} \]

    sub-neg [=>]99.7%

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

    \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(1, \sqrt{x}\right)} + \sqrt{x}} \]
    Step-by-step derivation

    [Start]99.7%

    \[ \frac{1}{\sqrt{1 + x} + \sqrt{x}} \]

    add-sqr-sqrt [=>]99.7%

    \[ \frac{1}{\sqrt{1 + \color{blue}{\sqrt{x} \cdot \sqrt{x}}} + \sqrt{x}} \]

    hypot-1-def [=>]99.7%

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

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

Alternatives

Alternative 1
Accuracy99.7%
Cost19584
\[\frac{1}{\sqrt{x} + \mathsf{hypot}\left(1, \sqrt{x}\right)} \]
Alternative 2
Accuracy99.4%
Cost26308
\[\begin{array}{l} t_0 := \sqrt{1 + x} - \sqrt{x}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-6}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Accuracy99.7%
Cost13248
\[\frac{1}{\sqrt{x} + \sqrt{1 + x}} \]
Alternative 4
Accuracy98.6%
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\left(1 - \sqrt{x}\right) + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1}{x}}\\ \end{array} \]
Alternative 5
Accuracy96.9%
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 0.25:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1}{x}}\\ \end{array} \]
Alternative 6
Accuracy98.0%
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{1}{1 + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1}{x}}\\ \end{array} \]
Alternative 7
Accuracy50.1%
Cost64
\[1 \]

Reproduce?

herbie shell --seed 2023167 
(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)))