?

Average Error: 35.0 → 4.8
Time: 16.6s
Precision: binary64
Cost: 26372

?

\[\left(-1.79 \cdot 10^{+308} \leq x \land x \leq 1.79 \cdot 10^{+308}\right) \land \left(-1.79 \cdot 10^{+308} \leq y \land y \leq 1.79 \cdot 10^{+308}\right)\]
\[\sqrt{{x}^{2} + {y}^{2}} - x \]
\[\begin{array}{l} \mathbf{if}\;\sqrt{{x}^{2} + {y}^{2}} - x \leq 0:\\ \;\;\;\;\frac{0.5}{\frac{x}{y} \cdot \frac{1}{y}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(x, y\right) - x\\ \end{array} \]
(FPCore (x y) :precision binary64 (- (sqrt (+ (pow x 2.0) (pow y 2.0))) x))
(FPCore (x y)
 :precision binary64
 (if (<= (- (sqrt (+ (pow x 2.0) (pow y 2.0))) x) 0.0)
   (/ 0.5 (* (/ x y) (/ 1.0 y)))
   (- (hypot x y) x)))
double code(double x, double y) {
	return sqrt((pow(x, 2.0) + pow(y, 2.0))) - x;
}
double code(double x, double y) {
	double tmp;
	if ((sqrt((pow(x, 2.0) + pow(y, 2.0))) - x) <= 0.0) {
		tmp = 0.5 / ((x / y) * (1.0 / y));
	} else {
		tmp = hypot(x, y) - x;
	}
	return tmp;
}
public static double code(double x, double y) {
	return Math.sqrt((Math.pow(x, 2.0) + Math.pow(y, 2.0))) - x;
}
public static double code(double x, double y) {
	double tmp;
	if ((Math.sqrt((Math.pow(x, 2.0) + Math.pow(y, 2.0))) - x) <= 0.0) {
		tmp = 0.5 / ((x / y) * (1.0 / y));
	} else {
		tmp = Math.hypot(x, y) - x;
	}
	return tmp;
}
def code(x, y):
	return math.sqrt((math.pow(x, 2.0) + math.pow(y, 2.0))) - x
def code(x, y):
	tmp = 0
	if (math.sqrt((math.pow(x, 2.0) + math.pow(y, 2.0))) - x) <= 0.0:
		tmp = 0.5 / ((x / y) * (1.0 / y))
	else:
		tmp = math.hypot(x, y) - x
	return tmp
function code(x, y)
	return Float64(sqrt(Float64((x ^ 2.0) + (y ^ 2.0))) - x)
end
function code(x, y)
	tmp = 0.0
	if (Float64(sqrt(Float64((x ^ 2.0) + (y ^ 2.0))) - x) <= 0.0)
		tmp = Float64(0.5 / Float64(Float64(x / y) * Float64(1.0 / y)));
	else
		tmp = Float64(hypot(x, y) - x);
	end
	return tmp
end
function tmp = code(x, y)
	tmp = sqrt(((x ^ 2.0) + (y ^ 2.0))) - x;
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((sqrt(((x ^ 2.0) + (y ^ 2.0))) - x) <= 0.0)
		tmp = 0.5 / ((x / y) * (1.0 / y));
	else
		tmp = hypot(x, y) - x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := N[(N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] + N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]
code[x_, y_] := If[LessEqual[N[(N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] + N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision], 0.0], N[(0.5 / N[(N[(x / y), $MachinePrecision] * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] - x), $MachinePrecision]]
\sqrt{{x}^{2} + {y}^{2}} - x
\begin{array}{l}
\mathbf{if}\;\sqrt{{x}^{2} + {y}^{2}} - x \leq 0:\\
\;\;\;\;\frac{0.5}{\frac{x}{y} \cdot \frac{1}{y}}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if (-.f64 (sqrt.f64 (+.f64 (pow.f64 x 2) (pow.f64 y 2))) x) < 0.0

    1. Initial program 36.4

      \[\sqrt{{x}^{2} + {y}^{2}} - x \]
    2. Simplified27.0

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

      [Start]36.4

      \[ \sqrt{{x}^{2} + {y}^{2}} - x \]

      unpow2 [=>]36.4

      \[ \sqrt{\color{blue}{x \cdot x} + {y}^{2}} - x \]

      unpow2 [=>]36.4

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

      hypot-def [=>]27.0

      \[ \color{blue}{\mathsf{hypot}\left(x, y\right)} - x \]
    3. Taylor expanded in x around inf 11.8

      \[\leadsto \color{blue}{0.5 \cdot \frac{{y}^{2}}{x}} \]
    4. Simplified12.2

      \[\leadsto \color{blue}{\frac{0.5}{\frac{x}{y \cdot y}}} \]
      Proof

      [Start]11.8

      \[ 0.5 \cdot \frac{{y}^{2}}{x} \]

      associate-*r/ [=>]11.8

      \[ \color{blue}{\frac{0.5 \cdot {y}^{2}}{x}} \]

      associate-/l* [=>]12.2

      \[ \color{blue}{\frac{0.5}{\frac{x}{{y}^{2}}}} \]

      unpow2 [=>]12.2

      \[ \frac{0.5}{\frac{x}{\color{blue}{y \cdot y}}} \]
    5. Applied egg-rr7.0

      \[\leadsto \frac{0.5}{\color{blue}{\frac{x}{y} \cdot \frac{1}{y}}} \]

    if 0.0 < (-.f64 (sqrt.f64 (+.f64 (pow.f64 x 2) (pow.f64 y 2))) x)

    1. Initial program 34.8

      \[\sqrt{{x}^{2} + {y}^{2}} - x \]
    2. Simplified4.4

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

      [Start]34.8

      \[ \sqrt{{x}^{2} + {y}^{2}} - x \]

      unpow2 [=>]34.8

      \[ \sqrt{\color{blue}{x \cdot x} + {y}^{2}} - x \]

      unpow2 [=>]34.8

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

      hypot-def [=>]4.4

      \[ \color{blue}{\mathsf{hypot}\left(x, y\right)} - x \]
  3. Recombined 2 regimes into one program.
  4. Final simplification4.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt{{x}^{2} + {y}^{2}} - x \leq 0:\\ \;\;\;\;\frac{0.5}{\frac{x}{y} \cdot \frac{1}{y}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(x, y\right) - x\\ \end{array} \]

Alternatives

Alternative 1
Error25.5
Cost1900
\[\begin{array}{l} t_0 := \left(-x\right) - y\\ t_1 := y \cdot \left(0.5 \cdot \frac{y}{x}\right)\\ t_2 := 0.5 \cdot \frac{y \cdot y}{x}\\ \mathbf{if}\;y \leq -2.2 \cdot 10^{-46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -6.6 \cdot 10^{-120}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5.8 \cdot 10^{-157}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq -1.38 \cdot 10^{-204}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-213}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1 \cdot 10^{-254}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{-304}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-183}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-96}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 7 \cdot 10^{-86}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \]
Alternative 2
Error25.6
Cost1900
\[\begin{array}{l} t_0 := \left(-x\right) - y\\ t_1 := y \cdot \left(0.5 \cdot \frac{y}{x}\right)\\ \mathbf{if}\;y \leq -2.2 \cdot 10^{-46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-116}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot y}{x}\\ \mathbf{elif}\;y \leq -7.5 \cdot 10^{-158}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq -7.6 \cdot 10^{-203}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -8.2 \cdot 10^{-212}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-255}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-304}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.1 \cdot 10^{-183}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-145}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-95}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-80}:\\ \;\;\;\;y \cdot \left(y \cdot \frac{0.5}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \]
Alternative 3
Error25.6
Cost1900
\[\begin{array}{l} t_0 := \left(-x\right) - y\\ t_1 := y \cdot \left(0.5 \cdot \frac{y}{x}\right)\\ \mathbf{if}\;y \leq -5.8 \cdot 10^{-46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -9.5 \cdot 10^{-120}:\\ \;\;\;\;\frac{0.5}{x} \cdot \left(y \cdot y\right)\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-157}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-204}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-211}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{-255}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-304}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{-179}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{-95}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-85}:\\ \;\;\;\;y \cdot \left(y \cdot \frac{0.5}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \]
Alternative 4
Error25.6
Cost1900
\[\begin{array}{l} t_0 := \left(-x\right) - y\\ t_1 := \frac{0.5}{\frac{x}{y} \cdot \frac{1}{y}}\\ \mathbf{if}\;y \leq -2.5 \cdot 10^{-46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{-117}:\\ \;\;\;\;\frac{0.5}{x} \cdot \left(y \cdot y\right)\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-156}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{-204}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-212}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{-254}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 8.8 \cdot 10^{-304}:\\ \;\;\;\;y \cdot \left(0.5 \cdot \frac{y}{x}\right)\\ \mathbf{elif}\;y \leq 1.08 \cdot 10^{-178}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-143}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-99}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-85}:\\ \;\;\;\;y \cdot \left(y \cdot \frac{0.5}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \]
Alternative 5
Error25.6
Cost976
\[\begin{array}{l} t_0 := 0.5 \cdot \frac{y \cdot y}{x}\\ \mathbf{if}\;y \leq -2.3 \cdot 10^{-46}:\\ \;\;\;\;\left(-x\right) - y\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{-118}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-179}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-141}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8.8 \cdot 10^{-95}:\\ \;\;\;\;x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \]
Alternative 6
Error26.0
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.95 \cdot 10^{-103}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 10^{-99}:\\ \;\;\;\;x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 7
Error25.6
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{-103}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 1.42 \cdot 10^{-98}:\\ \;\;\;\;x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \]
Alternative 8
Error25.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -9.6 \cdot 10^{-103}:\\ \;\;\;\;\left(-x\right) - y\\ \mathbf{elif}\;y \leq 3.55 \cdot 10^{-99}:\\ \;\;\;\;x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \]
Alternative 9
Error30.7
Cost260
\[\begin{array}{l} \mathbf{if}\;y \leq -2.05 \cdot 10^{-296}:\\ \;\;\;\;-y\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 10
Error46.3
Cost64
\[y \]

Error

Reproduce?

herbie shell --seed 1 
(FPCore (x y)
  :name "sqrt(pow(x,2) + pow(y,2)) - x"
  :precision binary64
  :pre (and (and (<= -1.79e+308 x) (<= x 1.79e+308)) (and (<= -1.79e+308 y) (<= y 1.79e+308)))
  (- (sqrt (+ (pow x 2.0) (pow y 2.0))) x))