?

Average Accuracy: 8.5% → 100.0%
Time: 5.1s
Precision: binary64
Cost: 13504

?

\[-1 \leq x \land x \leq 1\]
\[\sqrt{1 + x} - \sqrt{1 - x} \]
\[\frac{x + x}{\sqrt{x + 1} + \sqrt{1 - x}} \]
(FPCore (x) :precision binary64 (- (sqrt (+ 1.0 x)) (sqrt (- 1.0 x))))
(FPCore (x)
 :precision binary64
 (/ (+ x x) (+ (sqrt (+ x 1.0)) (sqrt (- 1.0 x)))))
double code(double x) {
	return sqrt((1.0 + x)) - sqrt((1.0 - x));
}
double code(double x) {
	return (x + x) / (sqrt((x + 1.0)) + 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) / (sqrt((x + 1.0d0)) + 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.sqrt((x + 1.0)) + 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.sqrt((x + 1.0)) + 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(sqrt(Float64(x + 1.0)) + 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) / (sqrt((x + 1.0)) + 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[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sqrt{1 + x} - \sqrt{1 - x}
\frac{x + x}{\sqrt{x + 1} + \sqrt{1 - x}}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original8.5%
Target100.0%
Herbie100.0%
\[\frac{2 \cdot x}{\sqrt{1 + x} + \sqrt{1 - x}} \]

Derivation?

  1. Initial program 8.5%

    \[\sqrt{1 + x} - \sqrt{1 - x} \]
  2. Simplified8.5%

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

    [Start]8.5

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

    +-commutative [=>]8.5

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

    metadata-eval [<=]8.5

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

    sub-neg [<=]8.5

    \[ \sqrt{\color{blue}{x - -1}} - \sqrt{1 - x} \]
  3. Applied egg-rr100.0%

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

    [Start]8.5

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

    flip-- [=>]8.5

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

    div-inv [=>]8.5

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

    add-sqr-sqrt [<=]8.5

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

    add-sqr-sqrt [<=]8.6

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

    associate--r- [=>]21.2

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

    sub-neg [=>]21.2

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

    metadata-eval [=>]21.2

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

    +-commutative [=>]21.2

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

    add-exp-log [=>]21.2

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

    log1p-udef [<=]21.2

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

    expm1-udef [<=]100.0

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

    expm1-log1p-u [<=]100.0

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

    sub-neg [=>]100.0

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

    metadata-eval [=>]100.0

    \[ \left(x + x\right) \cdot \frac{1}{\sqrt{x + \color{blue}{1}} + \sqrt{1 - x}} \]
  4. Simplified100.0%

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

    [Start]100.0

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

    associate-*r/ [=>]100.0

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

    *-rgt-identity [=>]100.0

    \[ \frac{\color{blue}{x + x}}{\sqrt{x + 1} + \sqrt{1 - x}} \]
  5. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy99.6%
Cost704
\[\frac{x + x}{2 + -0.25 \cdot \left(x \cdot x\right)} \]
Alternative 2
Accuracy99.0%
Cost64
\[x \]

Error

Reproduce?

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