Average Error: 19.2 → 4.7
Time: 14.8s
Precision: binary64
Cost: 104264
\[\left(\left(0 \leq d \land d \leq 1000000000\right) \land \left(0 \leq y \land y \leq 1000000000\right)\right) \land \left(0 \leq x \land x \leq 1000000000\right)\]
\[\sqrt{{d}^{2} + {y}^{2}} - \sqrt{{d}^{2} + {x}^{2}} \]
\[\begin{array}{l} t_0 := \sqrt{{d}^{2} + {y}^{2}} - \sqrt{{d}^{2} + {x}^{2}}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-161}:\\ \;\;\;\;\mathsf{hypot}\left(d, y\right) - \mathsf{hypot}\left(d, x\right)\\ \mathbf{elif}\;t_0 \leq 10^{-164}:\\ \;\;\;\;0.5 \cdot \left(\left(y - x\right) \cdot \frac{y + x}{d}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(d, y\right) - e^{\log \left(\mathsf{hypot}\left(d, x\right)\right)}\\ \end{array} \]
(FPCore (d y x)
 :precision binary64
 (- (sqrt (+ (pow d 2.0) (pow y 2.0))) (sqrt (+ (pow d 2.0) (pow x 2.0)))))
(FPCore (d y x)
 :precision binary64
 (let* ((t_0
         (-
          (sqrt (+ (pow d 2.0) (pow y 2.0)))
          (sqrt (+ (pow d 2.0) (pow x 2.0))))))
   (if (<= t_0 -5e-161)
     (- (hypot d y) (hypot d x))
     (if (<= t_0 1e-164)
       (* 0.5 (* (- y x) (/ (+ y x) d)))
       (- (hypot d y) (exp (log (hypot d x))))))))
double code(double d, double y, double x) {
	return sqrt((pow(d, 2.0) + pow(y, 2.0))) - sqrt((pow(d, 2.0) + pow(x, 2.0)));
}
double code(double d, double y, double x) {
	double t_0 = sqrt((pow(d, 2.0) + pow(y, 2.0))) - sqrt((pow(d, 2.0) + pow(x, 2.0)));
	double tmp;
	if (t_0 <= -5e-161) {
		tmp = hypot(d, y) - hypot(d, x);
	} else if (t_0 <= 1e-164) {
		tmp = 0.5 * ((y - x) * ((y + x) / d));
	} else {
		tmp = hypot(d, y) - exp(log(hypot(d, x)));
	}
	return tmp;
}
public static double code(double d, double y, double x) {
	return Math.sqrt((Math.pow(d, 2.0) + Math.pow(y, 2.0))) - Math.sqrt((Math.pow(d, 2.0) + Math.pow(x, 2.0)));
}
public static double code(double d, double y, double x) {
	double t_0 = Math.sqrt((Math.pow(d, 2.0) + Math.pow(y, 2.0))) - Math.sqrt((Math.pow(d, 2.0) + Math.pow(x, 2.0)));
	double tmp;
	if (t_0 <= -5e-161) {
		tmp = Math.hypot(d, y) - Math.hypot(d, x);
	} else if (t_0 <= 1e-164) {
		tmp = 0.5 * ((y - x) * ((y + x) / d));
	} else {
		tmp = Math.hypot(d, y) - Math.exp(Math.log(Math.hypot(d, x)));
	}
	return tmp;
}
def code(d, y, x):
	return math.sqrt((math.pow(d, 2.0) + math.pow(y, 2.0))) - math.sqrt((math.pow(d, 2.0) + math.pow(x, 2.0)))
def code(d, y, x):
	t_0 = math.sqrt((math.pow(d, 2.0) + math.pow(y, 2.0))) - math.sqrt((math.pow(d, 2.0) + math.pow(x, 2.0)))
	tmp = 0
	if t_0 <= -5e-161:
		tmp = math.hypot(d, y) - math.hypot(d, x)
	elif t_0 <= 1e-164:
		tmp = 0.5 * ((y - x) * ((y + x) / d))
	else:
		tmp = math.hypot(d, y) - math.exp(math.log(math.hypot(d, x)))
	return tmp
function code(d, y, x)
	return Float64(sqrt(Float64((d ^ 2.0) + (y ^ 2.0))) - sqrt(Float64((d ^ 2.0) + (x ^ 2.0))))
end
function code(d, y, x)
	t_0 = Float64(sqrt(Float64((d ^ 2.0) + (y ^ 2.0))) - sqrt(Float64((d ^ 2.0) + (x ^ 2.0))))
	tmp = 0.0
	if (t_0 <= -5e-161)
		tmp = Float64(hypot(d, y) - hypot(d, x));
	elseif (t_0 <= 1e-164)
		tmp = Float64(0.5 * Float64(Float64(y - x) * Float64(Float64(y + x) / d)));
	else
		tmp = Float64(hypot(d, y) - exp(log(hypot(d, x))));
	end
	return tmp
end
function tmp = code(d, y, x)
	tmp = sqrt(((d ^ 2.0) + (y ^ 2.0))) - sqrt(((d ^ 2.0) + (x ^ 2.0)));
end
function tmp_2 = code(d, y, x)
	t_0 = sqrt(((d ^ 2.0) + (y ^ 2.0))) - sqrt(((d ^ 2.0) + (x ^ 2.0)));
	tmp = 0.0;
	if (t_0 <= -5e-161)
		tmp = hypot(d, y) - hypot(d, x);
	elseif (t_0 <= 1e-164)
		tmp = 0.5 * ((y - x) * ((y + x) / d));
	else
		tmp = hypot(d, y) - exp(log(hypot(d, x)));
	end
	tmp_2 = tmp;
end
code[d_, y_, x_] := N[(N[Sqrt[N[(N[Power[d, 2.0], $MachinePrecision] + N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Sqrt[N[(N[Power[d, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[d_, y_, x_] := Block[{t$95$0 = N[(N[Sqrt[N[(N[Power[d, 2.0], $MachinePrecision] + N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Sqrt[N[(N[Power[d, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-161], N[(N[Sqrt[d ^ 2 + y ^ 2], $MachinePrecision] - N[Sqrt[d ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e-164], N[(0.5 * N[(N[(y - x), $MachinePrecision] * N[(N[(y + x), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[d ^ 2 + y ^ 2], $MachinePrecision] - N[Exp[N[Log[N[Sqrt[d ^ 2 + x ^ 2], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\sqrt{{d}^{2} + {y}^{2}} - \sqrt{{d}^{2} + {x}^{2}}
\begin{array}{l}
t_0 := \sqrt{{d}^{2} + {y}^{2}} - \sqrt{{d}^{2} + {x}^{2}}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{-161}:\\
\;\;\;\;\mathsf{hypot}\left(d, y\right) - \mathsf{hypot}\left(d, x\right)\\

\mathbf{elif}\;t_0 \leq 10^{-164}:\\
\;\;\;\;0.5 \cdot \left(\left(y - x\right) \cdot \frac{y + x}{d}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(d, y\right) - e^{\log \left(\mathsf{hypot}\left(d, x\right)\right)}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if (-.f64 (sqrt.f64 (+.f64 (pow.f64 d 2) (pow.f64 y 2))) (sqrt.f64 (+.f64 (pow.f64 d 2) (pow.f64 x 2)))) < -4.9999999999999999e-161

    1. Initial program 1.1

      \[\sqrt{{d}^{2} + {y}^{2}} - \sqrt{{d}^{2} + {x}^{2}} \]
    2. Simplified0.9

      \[\leadsto \color{blue}{\mathsf{hypot}\left(d, y\right) - \mathsf{hypot}\left(d, x\right)} \]

    if -4.9999999999999999e-161 < (-.f64 (sqrt.f64 (+.f64 (pow.f64 d 2) (pow.f64 y 2))) (sqrt.f64 (+.f64 (pow.f64 d 2) (pow.f64 x 2)))) < 9.99999999999999962e-165

    1. Initial program 47.8

      \[\sqrt{{d}^{2} + {y}^{2}} - \sqrt{{d}^{2} + {x}^{2}} \]
    2. Taylor expanded in d around inf 22.4

      \[\leadsto \color{blue}{\frac{0.5 \cdot {y}^{2} - 0.5 \cdot {x}^{2}}{d}} \]
    3. Simplified22.4

      \[\leadsto \color{blue}{\frac{0.5}{d} \cdot \left(y \cdot y - x \cdot x\right)} \]
    4. Taylor expanded in d around 0 22.3

      \[\leadsto \color{blue}{0.5 \cdot \frac{{y}^{2} - {x}^{2}}{d}} \]
    5. Simplified10.5

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(y - x\right) \cdot \frac{y + x}{d}\right)} \]

    if 9.99999999999999962e-165 < (-.f64 (sqrt.f64 (+.f64 (pow.f64 d 2) (pow.f64 y 2))) (sqrt.f64 (+.f64 (pow.f64 d 2) (pow.f64 x 2))))

    1. Initial program 1.3

      \[\sqrt{{d}^{2} + {y}^{2}} - \sqrt{{d}^{2} + {x}^{2}} \]
    2. Simplified0.8

      \[\leadsto \color{blue}{\mathsf{hypot}\left(d, y\right) - \mathsf{hypot}\left(d, x\right)} \]
    3. Applied egg-rr1.1

      \[\leadsto \mathsf{hypot}\left(d, y\right) - \color{blue}{e^{\log \left(\mathsf{hypot}\left(d, x\right)\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification4.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt{{d}^{2} + {y}^{2}} - \sqrt{{d}^{2} + {x}^{2}} \leq -5 \cdot 10^{-161}:\\ \;\;\;\;\mathsf{hypot}\left(d, y\right) - \mathsf{hypot}\left(d, x\right)\\ \mathbf{elif}\;\sqrt{{d}^{2} + {y}^{2}} - \sqrt{{d}^{2} + {x}^{2}} \leq 10^{-164}:\\ \;\;\;\;0.5 \cdot \left(\left(y - x\right) \cdot \frac{y + x}{d}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(d, y\right) - e^{\log \left(\mathsf{hypot}\left(d, x\right)\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error10.3
Cost14344
\[\begin{array}{l} t_0 := \mathsf{hypot}\left(d, y\right) - \mathsf{hypot}\left(d, x\right)\\ \mathbf{if}\;d \leq 1.2319179570799131 \cdot 10^{-88}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 8.9492477663499 \cdot 10^{-63}:\\ \;\;\;\;\mathsf{fma}\left(y + x, \left(y - x\right) \cdot \frac{0.5}{d}, \frac{0.5}{d} \cdot \mathsf{fma}\left(x, -x, x \cdot x\right)\right)\\ \mathbf{elif}\;d \leq 3.322343319429862 \cdot 10^{-54}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(y - x\right) \cdot \frac{y + x}{d}\right)\\ \end{array} \]
Alternative 2
Error10.3
Cost13516
\[\begin{array}{l} t_0 := \mathsf{hypot}\left(d, y\right) - \mathsf{hypot}\left(d, x\right)\\ t_1 := 0.5 \cdot \left(\left(y - x\right) \cdot \frac{y + x}{d}\right)\\ \mathbf{if}\;d \leq 1.2319179570799131 \cdot 10^{-88}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 8.9492477663499 \cdot 10^{-63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 3.322343319429862 \cdot 10^{-54}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error14.1
Cost1100
\[\begin{array}{l} t_0 := \frac{0.5 \cdot \left(y \cdot y - x \cdot x\right)}{d}\\ \mathbf{if}\;d \leq 1.2319179570799131 \cdot 10^{-88}:\\ \;\;\;\;y - x\\ \mathbf{elif}\;d \leq 8.9492477663499 \cdot 10^{-63}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 3.322343319429862 \cdot 10^{-54}:\\ \;\;\;\;y - x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error13.2
Cost1100
\[\begin{array}{l} t_0 := 0.5 \cdot \left(\left(y - x\right) \cdot \frac{y + x}{d}\right)\\ \mathbf{if}\;d \leq 4.298715974037927 \cdot 10^{-89}:\\ \;\;\;\;y - x\\ \mathbf{elif}\;d \leq 8.9492477663499 \cdot 10^{-63}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 3.322343319429862 \cdot 10^{-54}:\\ \;\;\;\;y - x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error18.1
Cost976
\[\begin{array}{l} t_0 := x \cdot \frac{-0.5}{\frac{d}{x}}\\ \mathbf{if}\;d \leq 1.2319179570799131 \cdot 10^{-88}:\\ \;\;\;\;y - x\\ \mathbf{elif}\;d \leq 8.9492477663499 \cdot 10^{-63}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.3218755534067286 \cdot 10^{-50}:\\ \;\;\;\;y - x\\ \mathbf{elif}\;d \leq 1.1168624181670499 \cdot 10^{-10}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot 0.5}{\frac{d}{y}}\\ \end{array} \]
Alternative 6
Error17.8
Cost580
\[\begin{array}{l} \mathbf{if}\;d \leq 1.3218755534067286 \cdot 10^{-50}:\\ \;\;\;\;y - x\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{d} \cdot \left(y \cdot y\right)\\ \end{array} \]
Alternative 7
Error17.6
Cost580
\[\begin{array}{l} \mathbf{if}\;d \leq 1.3218755534067286 \cdot 10^{-50}:\\ \;\;\;\;y - x\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot 0.5}{\frac{d}{y}}\\ \end{array} \]
Alternative 8
Error31.4
Cost524
\[\begin{array}{l} \mathbf{if}\;x \leq 4.595984908234627 \cdot 10^{-162}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 3.7908572321525334 \cdot 10^{-129}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 1.165 \cdot 10^{-113}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 9
Error21.5
Cost192
\[y - x \]
Alternative 10
Error41.8
Cost64
\[y \]

Error

Reproduce

herbie shell --seed 1 
(FPCore (d y x)
  :name "sqrt(d^2+y^2)-sqrt(d^2+x^2)"
  :precision binary64
  :pre (and (and (and (<= 0.0 d) (<= d 1000000000.0)) (and (<= 0.0 y) (<= y 1000000000.0))) (and (<= 0.0 x) (<= x 1000000000.0)))
  (- (sqrt (+ (pow d 2.0) (pow y 2.0))) (sqrt (+ (pow d 2.0) (pow x 2.0)))))