Average Error: 15.5 → 0.1
Time: 11.7s
Precision: binary64
Cost: 26756
\[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.1:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.0859375, 0.125\right), 0.0673828125 \cdot {x}^{6}\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} \]
(FPCore (x)
 :precision binary64
 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
(FPCore (x)
 :precision binary64
 (if (<= (hypot 1.0 x) 1.1)
   (fma (* x x) (fma (* x x) -0.0859375 0.125) (* 0.0673828125 (pow x 6.0)))
   (/
    (+ 0.5 (/ -0.5 (hypot 1.0 x)))
    (+ 1.0 (sqrt (+ 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 (hypot(1.0, x) <= 1.1) {
		tmp = fma((x * x), fma((x * x), -0.0859375, 0.125), (0.0673828125 * pow(x, 6.0)));
	} else {
		tmp = (0.5 + (-0.5 / hypot(1.0, x))) / (1.0 + sqrt((0.5 + (0.5 / 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 (hypot(1.0, x) <= 1.1)
		tmp = fma(Float64(x * x), fma(Float64(x * x), -0.0859375, 0.125), Float64(0.0673828125 * (x ^ 6.0)));
	else
		tmp = Float64(Float64(0.5 + Float64(-0.5 / hypot(1.0, x))) / Float64(1.0 + sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x))))));
	end
	return 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[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.1], N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * -0.0859375 + 0.125), $MachinePrecision] + N[(0.0673828125 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $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}\;\mathsf{hypot}\left(1, x\right) \leq 1.1:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.0859375, 0.125\right), 0.0673828125 \cdot {x}^{6}\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}

Error

Derivation

  1. Split input into 2 regimes
  2. if (hypot.f64 1 x) < 1.1000000000000001

    1. Initial program 30.0

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

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      Proof
      (-.f64 1 (sqrt.f64 (+.f64 1/2 (/.f64 1/2 (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (Rewrite<= metadata-eval (*.f64 1 1/2)) (/.f64 1/2 (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (*.f64 1 1/2) (/.f64 (Rewrite<= metadata-eval (*.f64 1 1/2)) (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (*.f64 1 1/2) (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (hypot.f64 1 x)) 1/2))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 1/2 (+.f64 1 (/.f64 1 (hypot.f64 1 x))))))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr30.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. Applied egg-rr30.0

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

      \[\leadsto {\color{blue}{\left(5.5 + \left(8 \cdot \frac{1}{{x}^{2}} + -0.53125 \cdot {x}^{2}\right)\right)}}^{-1} \]
    6. Simplified0.9

      \[\leadsto {\color{blue}{\left(5.5 + \mathsf{fma}\left(x, x \cdot -0.53125, \frac{8}{x \cdot x}\right)\right)}}^{-1} \]
      Proof
      (+.f64 11/2 (fma.f64 x (*.f64 x -17/32) (/.f64 8 (*.f64 x x)))): 0 points increase in error, 0 points decrease in error
      (+.f64 11/2 (fma.f64 x (*.f64 x -17/32) (/.f64 8 (Rewrite<= unpow2_binary64 (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
      (+.f64 11/2 (fma.f64 x (*.f64 x -17/32) (/.f64 (Rewrite<= metadata-eval (*.f64 8 1)) (pow.f64 x 2)))): 0 points increase in error, 0 points decrease in error
      (+.f64 11/2 (fma.f64 x (*.f64 x -17/32) (Rewrite<= associate-*r/_binary64 (*.f64 8 (/.f64 1 (pow.f64 x 2)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 11/2 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (*.f64 x -17/32)) (*.f64 8 (/.f64 1 (pow.f64 x 2)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 11/2 (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x x) -17/32)) (*.f64 8 (/.f64 1 (pow.f64 x 2))))): 12 points increase in error, 10 points decrease in error
      (+.f64 11/2 (+.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) -17/32) (*.f64 8 (/.f64 1 (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
      (+.f64 11/2 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -17/32 (pow.f64 x 2))) (*.f64 8 (/.f64 1 (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
      (+.f64 11/2 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 8 (/.f64 1 (pow.f64 x 2))) (*.f64 -17/32 (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
    7. Taylor expanded in x around 0 0.1

      \[\leadsto \color{blue}{0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)} \]
    8. Simplified0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.0859375, 0.125\right), 0.0673828125 \cdot {x}^{6}\right)} \]
      Proof
      (fma.f64 (*.f64 x x) (fma.f64 (*.f64 x x) -11/128 1/8) (*.f64 69/1024 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) (fma.f64 (*.f64 x x) -11/128 1/8) (*.f64 69/1024 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (pow.f64 x 2) (fma.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) -11/128 1/8) (*.f64 69/1024 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (pow.f64 x 2) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (pow.f64 x 2) -11/128) 1/8)) (*.f64 69/1024 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (pow.f64 x 2) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -11/128 (pow.f64 x 2))) 1/8) (*.f64 69/1024 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (pow.f64 x 2) (Rewrite<= +-commutative_binary64 (+.f64 1/8 (*.f64 -11/128 (pow.f64 x 2)))) (*.f64 69/1024 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (pow.f64 x 2) (+.f64 1/8 (*.f64 -11/128 (pow.f64 x 2)))) (*.f64 69/1024 (pow.f64 x 6)))): 0 points increase in error, 1 points decrease in error
      (+.f64 (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 1/8 (pow.f64 x 2)) (*.f64 (*.f64 -11/128 (pow.f64 x 2)) (pow.f64 x 2)))) (*.f64 69/1024 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (*.f64 1/8 (pow.f64 x 2)) (Rewrite<= associate-*r*_binary64 (*.f64 -11/128 (*.f64 (pow.f64 x 2) (pow.f64 x 2))))) (*.f64 69/1024 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (*.f64 1/8 (pow.f64 x 2)) (*.f64 -11/128 (Rewrite=> pow-sqr_binary64 (pow.f64 x (*.f64 2 2))))) (*.f64 69/1024 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (*.f64 1/8 (pow.f64 x 2)) (*.f64 -11/128 (pow.f64 x (Rewrite=> metadata-eval 4)))) (*.f64 69/1024 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 1/8 (pow.f64 x 2)) (+.f64 (*.f64 -11/128 (pow.f64 x 4)) (*.f64 69/1024 (pow.f64 x 6))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 1/8 (pow.f64 x 2)) (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 69/1024 (pow.f64 x 6)) (*.f64 -11/128 (pow.f64 x 4))))): 0 points increase in error, 0 points decrease in error

    if 1.1000000000000001 < (hypot.f64 1 x)

    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)}}} \]
      Proof
      (-.f64 1 (sqrt.f64 (+.f64 1/2 (/.f64 1/2 (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (Rewrite<= metadata-eval (*.f64 1 1/2)) (/.f64 1/2 (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (*.f64 1 1/2) (/.f64 (Rewrite<= metadata-eval (*.f64 1 1/2)) (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (*.f64 1 1/2) (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (hypot.f64 1 x)) 1/2))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 1/2 (+.f64 1 (/.f64 1 (hypot.f64 1 x))))))): 0 points increase in error, 0 points decrease in error
    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)}}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.1:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.0859375, 0.125\right), 0.0673828125 \cdot {x}^{6}\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} \]

Alternatives

Alternative 1
Error0.6
Cost26564
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.1:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.0859375, 0.125\right), 0.0673828125 \cdot {x}^{6}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}\\ \end{array} \]
Alternative 2
Error0.6
Cost20164
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.1:\\ \;\;\;\;x \cdot \mathsf{fma}\left(0.125, x, -0.0859375 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}\\ \end{array} \]
Alternative 3
Error0.6
Cost19908
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.1:\\ \;\;\;\;x \cdot \mathsf{fma}\left(0.125, x, -0.0859375 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \end{array} \]
Alternative 4
Error0.9
Cost13576
\[\begin{array}{l} t_0 := 0.5 + \frac{-0.5}{x}\\ \mathbf{if}\;x \leq -2825946.7282828824:\\ \;\;\;\;1 - \sqrt{t_0}\\ \mathbf{elif}\;x \leq 0.6180735205572689:\\ \;\;\;\;x \cdot \mathsf{fma}\left(0.125, x, -0.0859375 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{1 + \sqrt{0.5 + \frac{0.5}{x}}}\\ \end{array} \]
Alternative 5
Error0.9
Cost7496
\[\begin{array}{l} t_0 := 0.5 + \frac{-0.5}{x}\\ \mathbf{if}\;x \leq -2825946.7282828824:\\ \;\;\;\;1 - \sqrt{t_0}\\ \mathbf{elif}\;x \leq 0.6180735205572689:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right) + -0.0859375 \cdot {x}^{4}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{1 + \sqrt{0.5 + \frac{0.5}{x}}}\\ \end{array} \]
Alternative 6
Error1.1
Cost7368
\[\begin{array}{l} \mathbf{if}\;x \leq -2825946.7282828824:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{-0.5}{x}}\\ \mathbf{elif}\;x \leq 0.6180735205572689:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right) + -0.0859375 \cdot {x}^{4}\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{x + \frac{0.5}{x}}}\\ \end{array} \]
Alternative 7
Error1.1
Cost7304
\[\begin{array}{l} \mathbf{if}\;x \leq -2825946.7282828824:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{-0.5}{x}}\\ \mathbf{elif}\;x \leq 0.6180735205572689:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right) + -0.0859375 \cdot {x}^{4}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \end{array} \]
Alternative 8
Error1.1
Cost6984
\[\begin{array}{l} t_0 := \frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{if}\;x \leq -2825946.7282828824:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.6180735205572689:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error1.2
Cost6984
\[\begin{array}{l} \mathbf{if}\;x \leq -2825946.7282828824:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{-0.5}{x}}\\ \mathbf{elif}\;x \leq 0.6180735205572689:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \end{array} \]
Alternative 10
Error1.6
Cost6856
\[\begin{array}{l} t_0 := 1 - \sqrt{0.5}\\ \mathbf{if}\;x \leq -2825946.7282828824:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.6180735205572689:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error25.0
Cost712
\[\begin{array}{l} t_0 := \frac{0.5 + \frac{-0.5}{x}}{2}\\ \mathbf{if}\;x \leq -2825946.7282828824:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.6180735205572689:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Error25.0
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2825946.7282828824:\\ \;\;\;\;0.25\\ \mathbf{elif}\;x \leq 0.6180735205572689:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;0.25\\ \end{array} \]
Alternative 13
Error26.2
Cost576
\[\frac{1}{5.5 + \frac{8}{x \cdot x}} \]
Alternative 14
Error39.9
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2.871991457103693 \cdot 10^{-72}:\\ \;\;\;\;0.25\\ \mathbf{elif}\;x \leq 4.701998421141907 \cdot 10^{-80}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.25\\ \end{array} \]
Alternative 15
Error46.4
Cost64
\[0 \]

Error

Reproduce

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