?

Average Error: 24.1 → 0.7
Time: 1.7min
Precision: binary64
Cost: 14212

?

\[\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} \]
\[\begin{array}{l} t_0 := x - \sqrt{x \cdot x - \varepsilon}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{-154}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\frac{{\left(\frac{\varepsilon}{x}\right)}^{2} \cdot 0.25}{x} + \frac{\varepsilon}{x}\right)\\ \end{array} \]
(FPCore (x eps) :precision binary64 (- x (sqrt (- (* x x) eps))))
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (- x (sqrt (- (* x x) eps)))))
   (if (<= t_0 -2e-154)
     t_0
     (* 0.5 (+ (/ (* (pow (/ eps x) 2.0) 0.25) x) (/ eps x))))))
double code(double x, double eps) {
	return x - sqrt(((x * x) - eps));
}
double code(double x, double eps) {
	double t_0 = x - sqrt(((x * x) - eps));
	double tmp;
	if (t_0 <= -2e-154) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (((pow((eps / x), 2.0) * 0.25) / x) + (eps / x));
	}
	return tmp;
}
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x - sqrt(((x * x) - eps))
    if (t_0 <= (-2d-154)) then
        tmp = t_0
    else
        tmp = 0.5d0 * (((((eps / x) ** 2.0d0) * 0.25d0) / x) + (eps / x))
    end if
    code = tmp
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) {
	double t_0 = x - Math.sqrt(((x * x) - eps));
	double tmp;
	if (t_0 <= -2e-154) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (((Math.pow((eps / x), 2.0) * 0.25) / x) + (eps / x));
	}
	return tmp;
}
def code(x, eps):
	return x - math.sqrt(((x * x) - eps))
def code(x, eps):
	t_0 = x - math.sqrt(((x * x) - eps))
	tmp = 0
	if t_0 <= -2e-154:
		tmp = t_0
	else:
		tmp = 0.5 * (((math.pow((eps / x), 2.0) * 0.25) / x) + (eps / x))
	return tmp
function code(x, eps)
	return Float64(x - sqrt(Float64(Float64(x * x) - eps)))
end
function code(x, eps)
	t_0 = Float64(x - sqrt(Float64(Float64(x * x) - eps)))
	tmp = 0.0
	if (t_0 <= -2e-154)
		tmp = t_0;
	else
		tmp = Float64(0.5 * Float64(Float64(Float64((Float64(eps / x) ^ 2.0) * 0.25) / x) + Float64(eps / x)));
	end
	return tmp
end
function tmp = code(x, eps)
	tmp = x - sqrt(((x * x) - eps));
end
function tmp_2 = code(x, eps)
	t_0 = x - sqrt(((x * x) - eps));
	tmp = 0.0;
	if (t_0 <= -2e-154)
		tmp = t_0;
	else
		tmp = 0.5 * (((((eps / x) ^ 2.0) * 0.25) / x) + (eps / x));
	end
	tmp_2 = tmp;
end
code[x_, eps_] := N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := Block[{t$95$0 = N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-154], t$95$0, N[(0.5 * N[(N[(N[(N[Power[N[(eps / x), $MachinePrecision], 2.0], $MachinePrecision] * 0.25), $MachinePrecision] / x), $MachinePrecision] + N[(eps / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x - \sqrt{x \cdot x - \varepsilon}
\begin{array}{l}
t_0 := x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{-154}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\frac{{\left(\frac{\varepsilon}{x}\right)}^{2} \cdot 0.25}{x} + \frac{\varepsilon}{x}\right)\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Split input into 2 regimes
  2. if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.9999999999999999e-154

    1. Initial program 0.7

      \[x - \sqrt{x \cdot x - \varepsilon} \]

    if -1.9999999999999999e-154 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps)))

    1. Initial program 58.7

      \[x - \sqrt{x \cdot x - \varepsilon} \]
    2. Taylor expanded in x around inf 6.1

      \[\leadsto \color{blue}{0.5 \cdot \left({\left(\frac{1}{x}\right)}^{3} \cdot {\left(-0.5 \cdot \varepsilon\right)}^{2}\right) + 0.5 \cdot \frac{\varepsilon}{x}} \]
    3. Simplified5.0

      \[\leadsto \color{blue}{0.5 \cdot \left(\frac{0.25 \cdot {\varepsilon}^{2}}{{x}^{3}} + \frac{\varepsilon}{x}\right)} \]
      Proof
    4. Applied egg-rr0.7

      \[\leadsto 0.5 \cdot \left(\color{blue}{\frac{{\left(\frac{\varepsilon}{x}\right)}^{2} \cdot 0.25}{x}} + \frac{\varepsilon}{x}\right) \]
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error0.7
Cost13764
\[\begin{array}{l} t_0 := x - \sqrt{x \cdot x - \varepsilon}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{-154}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{\left(\frac{\frac{\varepsilon}{x}}{x} \cdot \varepsilon\right) \cdot 0.25 + \varepsilon}{x}\\ \end{array} \]
Alternative 2
Error8.3
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 1.6 \cdot 10^{-103}:\\ \;\;\;\;x - \sqrt{-\varepsilon}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 \cdot \varepsilon}{x}\\ \end{array} \]
Alternative 3
Error8.4
Cost6724
\[\begin{array}{l} \mathbf{if}\;x \leq 1.15 \cdot 10^{-103}:\\ \;\;\;\;-\sqrt{-\varepsilon}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 \cdot \varepsilon}{x}\\ \end{array} \]
Alternative 4
Error35.9
Cost320
\[\frac{0.5}{x} \cdot \varepsilon \]
Alternative 5
Error35.8
Cost320
\[\frac{0.5 \cdot \varepsilon}{x} \]
Alternative 6
Error61.2
Cost192
\[x - x \]
Alternative 7
Error61.7
Cost64
\[x \]

Error

Reproduce?

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