?

Average Error: 23.94% → 0.16%
Time: 12.0s
Precision: binary64
Cost: 32900

?

\[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
\[\begin{array}{l} t_0 := 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\ \;\;\;\;\mathsf{fma}\left(0.0673828125, {x}^{6}, \mathsf{fma}\left(-0.0859375, {x}^{4}, x \cdot \left(x \cdot 0.125\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 + \frac{-0.25}{1 + x \cdot x}}{t_0 + {t_0}^{1.5}}\\ \end{array} \]
(FPCore (x)
 :precision binary64
 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ 0.5 (/ 0.5 (hypot 1.0 x)))))
   (if (<= (hypot 1.0 x) 1.2)
     (fma
      0.0673828125
      (pow x 6.0)
      (fma -0.0859375 (pow x 4.0) (* x (* x 0.125))))
     (/ (+ 0.25 (/ -0.25 (+ 1.0 (* x x)))) (+ t_0 (pow t_0 1.5))))))
double code(double x) {
	return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
double code(double x) {
	double t_0 = 0.5 + (0.5 / hypot(1.0, x));
	double tmp;
	if (hypot(1.0, x) <= 1.2) {
		tmp = fma(0.0673828125, pow(x, 6.0), fma(-0.0859375, pow(x, 4.0), (x * (x * 0.125))));
	} else {
		tmp = (0.25 + (-0.25 / (1.0 + (x * x)))) / (t_0 + pow(t_0, 1.5));
	}
	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)
	t_0 = Float64(0.5 + Float64(0.5 / hypot(1.0, x)))
	tmp = 0.0
	if (hypot(1.0, x) <= 1.2)
		tmp = fma(0.0673828125, (x ^ 6.0), fma(-0.0859375, (x ^ 4.0), Float64(x * Float64(x * 0.125))));
	else
		tmp = Float64(Float64(0.25 + Float64(-0.25 / Float64(1.0 + Float64(x * x)))) / Float64(t_0 + (t_0 ^ 1.5)));
	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_] := Block[{t$95$0 = N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.2], N[(0.0673828125 * N[Power[x, 6.0], $MachinePrecision] + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision] + N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.25 + N[(-0.25 / N[(1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 + N[Power[t$95$0, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
t_0 := 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\
\;\;\;\;\mathsf{fma}\left(0.0673828125, {x}^{6}, \mathsf{fma}\left(-0.0859375, {x}^{4}, x \cdot \left(x \cdot 0.125\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{0.25 + \frac{-0.25}{1 + x \cdot x}}{t_0 + {t_0}^{1.5}}\\


\end{array}

Error?

Derivation?

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

    1. Initial program 47.15

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

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      Proof

      [Start]47.15

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

      distribute-lft-in [=>]47.15

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

      metadata-eval [=>]47.15

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

      associate-*r/ [=>]47.15

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

      metadata-eval [=>]47.15

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

      \[\leadsto \color{blue}{0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)} \]
    4. Applied egg-rr47.39

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\mathsf{fma}\left(0.125, x \cdot x, \mathsf{fma}\left(-0.0859375, {x}^{4}, 0.0673828125 \cdot {x}^{6}\right)\right)\right)} - 1} \]
    5. Simplified0.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.0673828125, {x}^{6}, \mathsf{fma}\left(-0.0859375, {x}^{4}, x \cdot \left(x \cdot 0.125\right)\right)\right)} \]
      Proof

      [Start]47.39

      \[ e^{\mathsf{log1p}\left(\mathsf{fma}\left(0.125, x \cdot x, \mathsf{fma}\left(-0.0859375, {x}^{4}, 0.0673828125 \cdot {x}^{6}\right)\right)\right)} - 1 \]

      expm1-def [=>]0.3

      \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(0.125, x \cdot x, \mathsf{fma}\left(-0.0859375, {x}^{4}, 0.0673828125 \cdot {x}^{6}\right)\right)\right)\right)} \]

      expm1-log1p [=>]0.3

      \[ \color{blue}{\mathsf{fma}\left(0.125, x \cdot x, \mathsf{fma}\left(-0.0859375, {x}^{4}, 0.0673828125 \cdot {x}^{6}\right)\right)} \]

      fma-udef [=>]0.3

      \[ \color{blue}{0.125 \cdot \left(x \cdot x\right) + \mathsf{fma}\left(-0.0859375, {x}^{4}, 0.0673828125 \cdot {x}^{6}\right)} \]

      *-commutative [=>]0.3

      \[ \color{blue}{\left(x \cdot x\right) \cdot 0.125} + \mathsf{fma}\left(-0.0859375, {x}^{4}, 0.0673828125 \cdot {x}^{6}\right) \]

      associate-*r* [<=]0.3

      \[ \color{blue}{x \cdot \left(x \cdot 0.125\right)} + \mathsf{fma}\left(-0.0859375, {x}^{4}, 0.0673828125 \cdot {x}^{6}\right) \]

      fma-udef [=>]0.3

      \[ x \cdot \left(x \cdot 0.125\right) + \color{blue}{\left(-0.0859375 \cdot {x}^{4} + 0.0673828125 \cdot {x}^{6}\right)} \]

      associate-+r+ [=>]0.3

      \[ \color{blue}{\left(x \cdot \left(x \cdot 0.125\right) + -0.0859375 \cdot {x}^{4}\right) + 0.0673828125 \cdot {x}^{6}} \]

      +-commutative [<=]0.3

      \[ \color{blue}{\left(-0.0859375 \cdot {x}^{4} + x \cdot \left(x \cdot 0.125\right)\right)} + 0.0673828125 \cdot {x}^{6} \]

      +-commutative [<=]0.3

      \[ \color{blue}{0.0673828125 \cdot {x}^{6} + \left(-0.0859375 \cdot {x}^{4} + x \cdot \left(x \cdot 0.125\right)\right)} \]

      fma-def [=>]0.3

      \[ \color{blue}{\mathsf{fma}\left(0.0673828125, {x}^{6}, -0.0859375 \cdot {x}^{4} + x \cdot \left(x \cdot 0.125\right)\right)} \]

      fma-def [=>]0.3

      \[ \mathsf{fma}\left(0.0673828125, {x}^{6}, \color{blue}{\mathsf{fma}\left(-0.0859375, {x}^{4}, x \cdot \left(x \cdot 0.125\right)\right)}\right) \]

    if 1.19999999999999996 < (hypot.f64 1 x)

    1. Initial program 1.52

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

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      Proof

      [Start]1.52

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

      distribute-lft-in [=>]1.52

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

      metadata-eval [=>]1.52

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

      associate-*r/ [=>]1.52

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

      metadata-eval [=>]1.52

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

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

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

      [Start]0.04

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

      /-rgt-identity [<=]0.04

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

      /-rgt-identity [=>]0.04

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

      +-commutative [=>]0.04

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

      *-commutative [=>]0.04

      \[ \frac{0.25 - \frac{0.25}{x \cdot x + 1}}{\color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}} \]
    5. Applied egg-rr0.03

      \[\leadsto \frac{0.25 - \frac{0.25}{x \cdot x + 1}}{\color{blue}{{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{1.5} + \left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.16

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\ \;\;\;\;\mathsf{fma}\left(0.0673828125, {x}^{6}, \mathsf{fma}\left(-0.0859375, {x}^{4}, x \cdot \left(x \cdot 0.125\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 + \frac{-0.25}{1 + x \cdot x}}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) + {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{1.5}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.16%
Cost27332
\[\begin{array}{l} t_0 := 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 + \frac{-0.25}{1 + x \cdot x}}{t_0 + {t_0}^{1.5}}\\ \end{array} \]
Alternative 2
Error0.16%
Cost26948
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - \sqrt{\frac{0.25}{1 + x \cdot x}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]
Alternative 3
Error0.16%
Cost26884
\[\begin{array}{l} t_0 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \sqrt{0.5 + t_0}} \cdot \left(0.5 - t_0\right)\\ \end{array} \]
Alternative 4
Error0.16%
Cost26756
\[\begin{array}{l} t_0 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - t_0}{1 + \sqrt{0.5 + t_0}}\\ \end{array} \]
Alternative 5
Error0.91%
Cost26692
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\ \end{array} \]
Alternative 6
Error0.99%
Cost20292
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\ \end{array} \]
Alternative 7
Error1.06%
Cost13828
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 2:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - \frac{-0.5}{x}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\ \end{array} \]
Alternative 8
Error1.41%
Cost7305
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1 \lor \neg \left(x \leq 1.12\right):\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{else}:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + x \cdot \left(x \cdot 0.125\right)\\ \end{array} \]
Alternative 9
Error1.67%
Cost6985
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \lor \neg \left(x \leq 1.52\right):\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{else}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \end{array} \]
Alternative 10
Error2.42%
Cost6857
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \lor \neg \left(x \leq 1.52\right):\\ \;\;\;\;1 - \sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \end{array} \]
Alternative 11
Error41.98%
Cost969
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{-5} \lor \neg \left(x \leq 0.00011\right):\\ \;\;\;\;\frac{0.25 + \frac{-0.25}{1 + x \cdot x}}{2}\\ \mathbf{else}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \end{array} \]
Alternative 12
Error41.99%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;0.125\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;0.125\\ \end{array} \]
Alternative 13
Error88.54%
Cost64
\[0.125 \]

Error

Reproduce?

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