?

Average Error: 91.77% → 0.01%
Time: 6.0s
Precision: binary64
Cost: 20032

?

\[-1 \leq x \land x \leq 1\]
\[\sqrt{1 + x} - \sqrt{1 - x} \]
\[\frac{x + x}{{\left({\left(x + 1\right)}^{1.5}\right)}^{0.3333333333333333} + \sqrt{1 - x}} \]
(FPCore (x) :precision binary64 (- (sqrt (+ 1.0 x)) (sqrt (- 1.0 x))))
(FPCore (x)
 :precision binary64
 (/ (+ x x) (+ (pow (pow (+ x 1.0) 1.5) 0.3333333333333333) (sqrt (- 1.0 x)))))
double code(double x) {
	return sqrt((1.0 + x)) - sqrt((1.0 - x));
}
double code(double x) {
	return (x + x) / (pow(pow((x + 1.0), 1.5), 0.3333333333333333) + sqrt((1.0 - x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt((1.0d0 + x)) - sqrt((1.0d0 - x))
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x + x) / ((((x + 1.0d0) ** 1.5d0) ** 0.3333333333333333d0) + sqrt((1.0d0 - x)))
end function
public static double code(double x) {
	return Math.sqrt((1.0 + x)) - Math.sqrt((1.0 - x));
}
public static double code(double x) {
	return (x + x) / (Math.pow(Math.pow((x + 1.0), 1.5), 0.3333333333333333) + Math.sqrt((1.0 - x)));
}
def code(x):
	return math.sqrt((1.0 + x)) - math.sqrt((1.0 - x))
def code(x):
	return (x + x) / (math.pow(math.pow((x + 1.0), 1.5), 0.3333333333333333) + math.sqrt((1.0 - x)))
function code(x)
	return Float64(sqrt(Float64(1.0 + x)) - sqrt(Float64(1.0 - x)))
end
function code(x)
	return Float64(Float64(x + x) / Float64(((Float64(x + 1.0) ^ 1.5) ^ 0.3333333333333333) + sqrt(Float64(1.0 - x))))
end
function tmp = code(x)
	tmp = sqrt((1.0 + x)) - sqrt((1.0 - x));
end
function tmp = code(x)
	tmp = (x + x) / ((((x + 1.0) ^ 1.5) ^ 0.3333333333333333) + sqrt((1.0 - x)));
end
code[x_] := N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x + x), $MachinePrecision] / N[(N[Power[N[Power[N[(x + 1.0), $MachinePrecision], 1.5], $MachinePrecision], 0.3333333333333333], $MachinePrecision] + N[Sqrt[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sqrt{1 + x} - \sqrt{1 - x}
\frac{x + x}{{\left({\left(x + 1\right)}^{1.5}\right)}^{0.3333333333333333} + \sqrt{1 - x}}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original91.77%
Target0.02%
Herbie0.01%
\[\frac{2 \cdot x}{\sqrt{1 + x} + \sqrt{1 - x}} \]

Derivation?

  1. Initial program 91.77

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

    \[\leadsto \color{blue}{\left(x + x\right) \cdot \frac{1}{\sqrt{1 + x} + \sqrt{1 - x}}} \]
  3. Simplified0.02

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

    [Start]0.02

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

    associate-*r/ [=>]0.02

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

    associate-/l* [=>]0.02

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

    /-rgt-identity [=>]0.02

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

    +-commutative [=>]0.02

    \[ \frac{x + x}{\sqrt{\color{blue}{x + 1}} + \sqrt{1 - x}} \]
  4. Applied egg-rr0.01

    \[\leadsto \frac{x + x}{\color{blue}{{\left({\left(x + 1\right)}^{1.5}\right)}^{0.3333333333333333}} + \sqrt{1 - x}} \]
  5. Final simplification0.01

    \[\leadsto \frac{x + x}{{\left({\left(x + 1\right)}^{1.5}\right)}^{0.3333333333333333} + \sqrt{1 - x}} \]

Alternatives

Alternative 1
Error0.02%
Cost13504
\[\frac{x + x}{\sqrt{1 - x} + \sqrt{x + 1}} \]
Alternative 2
Error0.38%
Cost6784
\[x + 0.125 \cdot {x}^{3} \]
Alternative 3
Error0.86%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023090 
(FPCore (x)
  :name "bug333 (missed optimization)"
  :precision binary64
  :pre (and (<= -1.0 x) (<= x 1.0))

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

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