Average Error: 24.3 → 0.3
Time: 7.8s
Precision: binary64
Cost: 6976
\[\left(0 \leq x \land x \leq 1000000000\right) \land \left(-1 \leq \varepsilon \land \varepsilon \leq 1\right)\]
\[x - \sqrt{x \cdot x - \varepsilon} \]
\[\frac{\varepsilon}{x + \sqrt{x \cdot x - \varepsilon}} \]
(FPCore (x eps) :precision binary64 (- x (sqrt (- (* x x) eps))))
(FPCore (x eps) :precision binary64 (/ eps (+ x (sqrt (- (* x x) eps)))))
double code(double x, double eps) {
	return x - sqrt(((x * x) - eps));
}
double code(double x, double eps) {
	return eps / (x + sqrt(((x * x) - eps)));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = x - sqrt(((x * x) - eps))
end function
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = eps / (x + sqrt(((x * x) - eps)))
end function
public static double code(double x, double eps) {
	return x - Math.sqrt(((x * x) - eps));
}
public static double code(double x, double eps) {
	return eps / (x + Math.sqrt(((x * x) - eps)));
}
def code(x, eps):
	return x - math.sqrt(((x * x) - eps))
def code(x, eps):
	return eps / (x + math.sqrt(((x * x) - eps)))
function code(x, eps)
	return Float64(x - sqrt(Float64(Float64(x * x) - eps)))
end
function code(x, eps)
	return Float64(eps / Float64(x + sqrt(Float64(Float64(x * x) - eps))))
end
function tmp = code(x, eps)
	tmp = x - sqrt(((x * x) - eps));
end
function tmp = code(x, eps)
	tmp = eps / (x + sqrt(((x * x) - eps)));
end
code[x_, eps_] := N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := N[(eps / N[(x + N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x - \sqrt{x \cdot x - \varepsilon}
\frac{\varepsilon}{x + \sqrt{x \cdot x - \varepsilon}}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original24.3
Target0.3
Herbie0.3
\[\frac{\varepsilon}{x + \sqrt{x \cdot x - \varepsilon}} \]

Derivation

  1. Initial program 24.3

    \[x - \sqrt{x \cdot x - \varepsilon} \]
  2. Applied egg-rr0.4

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

    \[\leadsto \color{blue}{\frac{\varepsilon + 0}{x + \sqrt{x \cdot x - \varepsilon}}} \]
    Proof
    (/.f64 (+.f64 eps 0) (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps)))): 0 points increase in error, 0 points decrease in error
    (/.f64 (+.f64 eps (Rewrite<= mul0-rgt_binary64 (*.f64 x 0))) (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps)))): 4 points increase in error, 0 points decrease in error
    (/.f64 (+.f64 eps (*.f64 x (Rewrite<= +-inverses_binary64 (-.f64 x x)))) (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps)))): 0 points increase in error, 6 points decrease in error
    (/.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (+.f64 eps (*.f64 x (-.f64 x x))))) (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps)))): 6 points increase in error, 0 points decrease in error
    (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps)))) (+.f64 eps (*.f64 x (-.f64 x x))))): 0 points increase in error, 6 points decrease in error
    (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 eps (*.f64 x (-.f64 x x))) (/.f64 1 (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps)))))): 0 points increase in error, 0 points decrease in error
  4. Applied egg-rr58.0

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\varepsilon}{x + \sqrt{x \cdot x - \varepsilon}}\right)} - 1} \]
  5. Simplified0.3

    \[\leadsto \color{blue}{\frac{\varepsilon}{x + \sqrt{x \cdot x - \varepsilon}}} \]
    Proof
    (/.f64 eps (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= expm1-log1p_binary64 (expm1.f64 (log1p.f64 (/.f64 eps (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))))))): 2 points increase in error, 1 points decrease in error
    (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 (log1p.f64 (/.f64 eps (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps)))))) 1)): 1 points increase in error, 2 points decrease in error
  6. Final simplification0.3

    \[\leadsto \frac{\varepsilon}{x + \sqrt{x \cdot x - \varepsilon}} \]

Alternatives

Alternative 1
Error1.3
Cost13764
\[\begin{array}{l} t_0 := x - \sqrt{x \cdot x - \varepsilon}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{-150}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\varepsilon}{-0.5 \cdot \frac{\varepsilon}{x} + x \cdot 2}\\ \end{array} \]
Alternative 2
Error8.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 2.3 \cdot 10^{-108}:\\ \;\;\;\;x - \sqrt{-\varepsilon}\\ \mathbf{else}:\\ \;\;\;\;\frac{\varepsilon}{x + \left(x + -0.5 \cdot \frac{\varepsilon}{x}\right)}\\ \end{array} \]
Alternative 3
Error35.2
Cost704
\[\frac{\varepsilon}{x + \left(x + -0.5 \cdot \frac{\varepsilon}{x}\right)} \]
Alternative 4
Error35.2
Cost704
\[\frac{\varepsilon}{-0.5 \cdot \frac{\varepsilon}{x} + x \cdot 2} \]
Alternative 5
Error35.7
Cost320
\[\frac{\varepsilon}{x} \cdot 0.5 \]
Alternative 6
Error60.6
Cost192
\[x \cdot -2 \]
Alternative 7
Error56.7
Cost192
\[\frac{\varepsilon}{x} \]
Alternative 8
Error61.2
Cost64
\[0 \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x eps)
  :name "ENA, Section 1.4, Exercise 4d"
  :precision binary64
  :pre (and (and (<= 0.0 x) (<= x 1000000000.0)) (and (<= -1.0 eps) (<= eps 1.0)))

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

  (- x (sqrt (- (* x x) eps))))