Average Error: 15.7 → 0.1
Time: 12.1s
Precision: binary64
Cost: 26884
\[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 2:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right) + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{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) 2.0)
   (+
    (* x (* x 0.125))
    (+ (* 0.0673828125 (pow x 6.0)) (* -0.0859375 (pow x 4.0))))
   (*
    (+ 0.5 (/ -0.5 (hypot 1.0 x)))
    (/ 1.0 (+ 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) <= 2.0) {
		tmp = (x * (x * 0.125)) + ((0.0673828125 * pow(x, 6.0)) + (-0.0859375 * pow(x, 4.0)));
	} else {
		tmp = (0.5 + (-0.5 / hypot(1.0, x))) * (1.0 / (1.0 + sqrt((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 (Math.hypot(1.0, x) <= 2.0) {
		tmp = (x * (x * 0.125)) + ((0.0673828125 * Math.pow(x, 6.0)) + (-0.0859375 * Math.pow(x, 4.0)));
	} else {
		tmp = (0.5 + (-0.5 / Math.hypot(1.0, x))) * (1.0 / (1.0 + Math.sqrt((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 math.hypot(1.0, x) <= 2.0:
		tmp = (x * (x * 0.125)) + ((0.0673828125 * math.pow(x, 6.0)) + (-0.0859375 * math.pow(x, 4.0)))
	else:
		tmp = (0.5 + (-0.5 / math.hypot(1.0, x))) * (1.0 / (1.0 + math.sqrt((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 (hypot(1.0, x) <= 2.0)
		tmp = Float64(Float64(x * Float64(x * 0.125)) + Float64(Float64(0.0673828125 * (x ^ 6.0)) + Float64(-0.0859375 * (x ^ 4.0))));
	else
		tmp = Float64(Float64(0.5 + Float64(-0.5 / hypot(1.0, x))) * Float64(1.0 / Float64(1.0 + sqrt(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 (hypot(1.0, x) <= 2.0)
		tmp = (x * (x * 0.125)) + ((0.0673828125 * (x ^ 6.0)) + (-0.0859375 * (x ^ 4.0)));
	else
		tmp = (0.5 + (-0.5 / hypot(1.0, x))) * (1.0 / (1.0 + sqrt((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[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 2.0], N[(N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision] + N[(N[(0.0673828125 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $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 2:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right) + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\

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

    1. Initial program 30.1

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

      \[\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. 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. Taylor expanded in x around inf 0.5

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

      \[\leadsto \color{blue}{x \cdot \left(x \cdot 0.125\right)} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right) \]
      Proof
      (*.f64 x (*.f64 x 1/8)): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= remove-double-div_binary64 (/.f64 1 (/.f64 1 x))) (*.f64 x 1/8)): 15 points increase in error, 4 points decrease in error
      (*.f64 (Rewrite<= unpow-1_binary64 (pow.f64 (/.f64 1 x) -1)) (*.f64 x 1/8)): 0 points increase in error, 0 points decrease in error
      (*.f64 (pow.f64 (/.f64 1 x) (Rewrite<= metadata-eval (/.f64 -2 2))) (*.f64 x 1/8)): 0 points increase in error, 0 points decrease in error
      (*.f64 (pow.f64 (/.f64 1 x) (/.f64 -2 2)) (*.f64 (Rewrite<= remove-double-div_binary64 (/.f64 1 (/.f64 1 x))) 1/8)): 14 points increase in error, 5 points decrease in error
      (*.f64 (pow.f64 (/.f64 1 x) (/.f64 -2 2)) (*.f64 (Rewrite<= unpow-1_binary64 (pow.f64 (/.f64 1 x) -1)) 1/8)): 0 points increase in error, 0 points decrease in error
      (*.f64 (pow.f64 (/.f64 1 x) (/.f64 -2 2)) (*.f64 (pow.f64 (/.f64 1 x) (Rewrite<= metadata-eval (/.f64 -2 2))) 1/8)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (pow.f64 (/.f64 1 x) (/.f64 -2 2)) (pow.f64 (/.f64 1 x) (/.f64 -2 2))) 1/8)): 2 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= sqr-pow_binary64 (pow.f64 (/.f64 1 x) -2)) 1/8): 45 points increase in error, 22 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 1/8 (pow.f64 (/.f64 1 x) -2))): 0 points increase in error, 0 points decrease in error

    if 2 < (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}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{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 2:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right) + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.1
Cost20424
\[\begin{array}{l} \mathbf{if}\;x \leq -1.2:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 - \frac{0.5}{x}}}{0.5 + \frac{0.5}{x}}}\\ \mathbf{elif}\;x \leq 0.0108:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right) + \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}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]
Alternative 2
Error0.3
Cost14088
\[\begin{array}{l} t_0 := 0.5 + \frac{0.5}{x}\\ \mathbf{if}\;x \leq -1.2:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 - \frac{0.5}{x}}}{t_0}}\\ \mathbf{elif}\;x \leq 0.72:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right) + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{t_0}}\\ \end{array} \]
Alternative 3
Error0.3
Cost14024
\[\begin{array}{l} t_0 := 0.5 - \frac{0.5}{x}\\ t_1 := 0.5 + \frac{0.5}{x}\\ \mathbf{if}\;x \leq -1.2:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{t_0}}{t_1}}\\ \mathbf{elif}\;x \leq 1.2:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right) + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \sqrt{t_1}} \cdot t_0\\ \end{array} \]
Alternative 4
Error0.6
Cost7624
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(\left(1 + \mathsf{fma}\left(-0.0859375, x \cdot x, 0.125\right)\right) + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \sqrt{0.5 + \frac{0.5}{x}}} \cdot \left(0.5 - \frac{0.5}{x}\right)\\ \end{array} \]
Alternative 5
Error0.4
Cost7624
\[\begin{array}{l} t_0 := 0.5 - \frac{0.5}{x}\\ t_1 := 0.5 + \frac{0.5}{x}\\ \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{t_0}}{t_1}}\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(\left(1 + \mathsf{fma}\left(-0.0859375, x \cdot x, 0.125\right)\right) + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \sqrt{t_1}} \cdot t_0\\ \end{array} \]
Alternative 6
Error0.9
Cost7496
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(\left(1 + \mathsf{fma}\left(-0.0859375, x \cdot x, 0.125\right)\right) + -1\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{x}}\\ \end{array} \]
Alternative 7
Error0.6
Cost7496
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(\left(1 + \mathsf{fma}\left(-0.0859375, x \cdot x, 0.125\right)\right) + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - \frac{0.5}{x}}{1 + \sqrt{0.5 + \frac{0.5}{x}}}\\ \end{array} \]
Alternative 8
Error0.8
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(0.125 + x \cdot \left(x \cdot -0.0859375\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{x}}\\ \end{array} \]
Alternative 9
Error0.9
Cost6984
\[\begin{array}{l} t_0 := \frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(0.125 + x \cdot \left(x \cdot -0.0859375\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error1.3
Cost6856
\[\begin{array}{l} t_0 := 1 - \sqrt{0.5}\\ \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(0.125 + x \cdot \left(x \cdot -0.0859375\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error31.2
Cost320
\[0.125 \cdot \left(x \cdot x\right) \]
Alternative 12
Error31.2
Cost320
\[x \cdot \left(x \cdot 0.125\right) \]
Alternative 13
Error46.4
Cost64
\[0 \]

Error

Reproduce

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