Average Error: 15.4 → 0.8
Time: 7.6s
Precision: binary64
Cost: 20552
\[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -5535816155.602623:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{\left(\sqrt{0.5} + 1\right) - 0.25 \cdot \frac{1}{x \cdot \sqrt{0.5}}}\\ \mathbf{elif}\;x \leq 8.846986576458453 \cdot 10^{-7}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]
(FPCore (x)
 :precision binary64
 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
(FPCore (x)
 :precision binary64
 (if (<= x -5535816155.602623)
   (/
    (+ 0.5 (/ 0.5 x))
    (- (+ (sqrt 0.5) 1.0) (* 0.25 (/ 1.0 (* x (sqrt 0.5))))))
   (if (<= x 8.846986576458453e-7)
     (* 0.125 (* x x))
     (/
      1.0
      (/
       (+ 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x)))))
       (+ 0.5 (/ -0.5 (hypot 1.0 x))))))))
double code(double x) {
	return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
double code(double x) {
	double tmp;
	if (x <= -5535816155.602623) {
		tmp = (0.5 + (0.5 / x)) / ((sqrt(0.5) + 1.0) - (0.25 * (1.0 / (x * sqrt(0.5)))));
	} else if (x <= 8.846986576458453e-7) {
		tmp = 0.125 * (x * x);
	} else {
		tmp = 1.0 / ((1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x))))) / (0.5 + (-0.5 / hypot(1.0, x))));
	}
	return tmp;
}
public static double code(double x) {
	return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
public static double code(double x) {
	double tmp;
	if (x <= -5535816155.602623) {
		tmp = (0.5 + (0.5 / x)) / ((Math.sqrt(0.5) + 1.0) - (0.25 * (1.0 / (x * Math.sqrt(0.5)))));
	} else if (x <= 8.846986576458453e-7) {
		tmp = 0.125 * (x * x);
	} else {
		tmp = 1.0 / ((1.0 + Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, x))))) / (0.5 + (-0.5 / Math.hypot(1.0, x))));
	}
	return tmp;
}
def code(x):
	return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
def code(x):
	tmp = 0
	if x <= -5535816155.602623:
		tmp = (0.5 + (0.5 / x)) / ((math.sqrt(0.5) + 1.0) - (0.25 * (1.0 / (x * math.sqrt(0.5)))))
	elif x <= 8.846986576458453e-7:
		tmp = 0.125 * (x * x)
	else:
		tmp = 1.0 / ((1.0 + math.sqrt((0.5 + (0.5 / math.hypot(1.0, x))))) / (0.5 + (-0.5 / math.hypot(1.0, x))))
	return tmp
function code(x)
	return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x))))))
end
function code(x)
	tmp = 0.0
	if (x <= -5535816155.602623)
		tmp = Float64(Float64(0.5 + Float64(0.5 / x)) / Float64(Float64(sqrt(0.5) + 1.0) - Float64(0.25 * Float64(1.0 / Float64(x * sqrt(0.5))))));
	elseif (x <= 8.846986576458453e-7)
		tmp = Float64(0.125 * Float64(x * x));
	else
		tmp = Float64(1.0 / Float64(Float64(1.0 + sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x))))) / Float64(0.5 + Float64(-0.5 / hypot(1.0, x)))));
	end
	return tmp
end
function tmp = code(x)
	tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -5535816155.602623)
		tmp = (0.5 + (0.5 / x)) / ((sqrt(0.5) + 1.0) - (0.25 * (1.0 / (x * sqrt(0.5)))));
	elseif (x <= 8.846986576458453e-7)
		tmp = 0.125 * (x * x);
	else
		tmp = 1.0 / ((1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x))))) / (0.5 + (-0.5 / hypot(1.0, x))));
	end
	tmp_2 = tmp;
end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -5535816155.602623], N[(N[(0.5 + N[(0.5 / x), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Sqrt[0.5], $MachinePrecision] + 1.0), $MachinePrecision] - N[(0.25 * N[(1.0 / N[(x * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 8.846986576458453e-7], N[(0.125 * N[(x * x), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(0.5 + N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
\mathbf{if}\;x \leq -5535816155.602623:\\
\;\;\;\;\frac{0.5 + \frac{0.5}{x}}{\left(\sqrt{0.5} + 1\right) - 0.25 \cdot \frac{1}{x \cdot \sqrt{0.5}}}\\

\mathbf{elif}\;x \leq 8.846986576458453 \cdot 10^{-7}:\\
\;\;\;\;0.125 \cdot \left(x \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\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 x < -5535816155.602623

    1. Initial program 1.0

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Simplified1.0

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    3. Applied egg-rr0.0

      \[\leadsto \color{blue}{\frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    4. Taylor expanded in x around -inf 0.0

      \[\leadsto \frac{\color{blue}{0.5 + 0.5 \cdot \frac{1}{x}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    5. Simplified0.0

      \[\leadsto \frac{\color{blue}{0.5 + \frac{0.5}{x}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Taylor expanded in x around -inf 0.0

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

    if -5535816155.602623 < x < 8.8469865764584534e-7

    1. Initial program 29.2

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Simplified29.2

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    3. Taylor expanded in x around 0 1.3

      \[\leadsto \color{blue}{0.125 \cdot {x}^{2}} \]
    4. Simplified1.3

      \[\leadsto \color{blue}{0.125 \cdot \left(x \cdot x\right)} \]

    if 8.8469865764584534e-7 < x

    1. Initial program 1.4

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Simplified1.4

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    3. Applied egg-rr0.4

      \[\leadsto \color{blue}{\frac{1}{\frac{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5535816155.602623:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{\left(\sqrt{0.5} + 1\right) - 0.25 \cdot \frac{1}{x \cdot \sqrt{0.5}}}\\ \mathbf{elif}\;x \leq 8.846986576458453 \cdot 10^{-7}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.8
Cost20424
\[\begin{array}{l} \mathbf{if}\;x \leq -5535816155.602623:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{\left(\sqrt{0.5} + 1\right) - 0.25 \cdot \frac{1}{x \cdot \sqrt{0.5}}}\\ \mathbf{elif}\;x \leq 8.846986576458453 \cdot 10^{-7}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]
Alternative 2
Error1.0
Cost14020
\[\begin{array}{l} \mathbf{if}\;x \leq -5535816155.602623:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{\left(\sqrt{0.5} + 1\right) - 0.25 \cdot \frac{1}{x \cdot \sqrt{0.5}}}\\ \mathbf{elif}\;x \leq 8.846986576458453 \cdot 10^{-7}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}\\ \end{array} \]
Alternative 3
Error1.0
Cost13832
\[\begin{array}{l} \mathbf{if}\;x \leq -5535816155.602623:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\ \mathbf{elif}\;x \leq 8.846986576458453 \cdot 10^{-7}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}\\ \end{array} \]
Alternative 4
Error1.0
Cost13576
\[\begin{array}{l} \mathbf{if}\;x \leq -5535816155.602623:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\ \mathbf{elif}\;x \leq 8.846986576458453 \cdot 10^{-7}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \end{array} \]
Alternative 5
Error1.1
Cost7364
\[\begin{array}{l} \mathbf{if}\;x \leq -5535816155.602623:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\ \mathbf{elif}\;x \leq 1.248670561374677:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\sqrt{0.5} + 1}\\ \end{array} \]
Alternative 6
Error1.2
Cost6984
\[\begin{array}{l} t_0 := \frac{0.5}{\sqrt{0.5} + 1}\\ \mathbf{if}\;x \leq -5535816155.602623:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.248670561374677:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error1.7
Cost6856
\[\begin{array}{l} t_0 := 1 - \sqrt{0.5}\\ \mathbf{if}\;x \leq -5535816155.602623:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.248670561374677:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error24.9
Cost584
\[\begin{array}{l} t_0 := 0.25 + \frac{0.25}{x}\\ \mathbf{if}\;x \leq -5535816155.602623:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.248670561374677:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error26.1
Cost576
\[\frac{1}{\frac{\frac{8}{x}}{x} + 5.5} \]
Alternative 10
Error31.2
Cost320
\[0.125 \cdot \left(x \cdot x\right) \]
Alternative 11
Error62.0
Cost192
\[\frac{0.25}{x} \]
Alternative 12
Error46.1
Cost64
\[0 \]

Error

Reproduce

herbie shell --seed 2022228 
(FPCore (x)
  :name "Given's Rotation SVD example, simplified"
  :precision binary64
  (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))