?

Average Error: 76.3% → 99.7%
Time: 15.6s
Precision: binary64
Cost: 26884.00

?

\[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}^{4} \cdot -0.0859375 + x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 + \left(-0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\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) 2.0)
   (+ (* (pow x 4.0) -0.0859375) (* x (* x 0.125)))
   (/
    (+ 1.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) <= 2.0) {
		tmp = (pow(x, 4.0) * -0.0859375) + (x * (x * 0.125));
	} else {
		tmp = (1.0 + (-0.5 + (-0.5 / hypot(1.0, x)))) / (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 = (Math.pow(x, 4.0) * -0.0859375) + (x * (x * 0.125));
	} else {
		tmp = (1.0 + (-0.5 + (-0.5 / Math.hypot(1.0, x)))) / (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 = (math.pow(x, 4.0) * -0.0859375) + (x * (x * 0.125))
	else:
		tmp = (1.0 + (-0.5 + (-0.5 / math.hypot(1.0, x)))) / (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 ^ 4.0) * -0.0859375) + Float64(x * Float64(x * 0.125)));
	else
		tmp = Float64(Float64(1.0 + 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
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 ^ 4.0) * -0.0859375) + (x * (x * 0.125));
	else
		tmp = (1.0 + (-0.5 + (-0.5 / hypot(1.0, x)))) / (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[(N[Power[x, 4.0], $MachinePrecision] * -0.0859375), $MachinePrecision] + N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(-0.5 + N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $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 2:\\
\;\;\;\;{x}^{4} \cdot -0.0859375 + x \cdot \left(x \cdot 0.125\right)\\

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

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

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

      [Start]53.7

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

      distribute-lft-in [=>]53.7

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

      metadata-eval [=>]53.7

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

      associate-*r/ [=>]53.7

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

      metadata-eval [=>]53.7

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

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

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

      [Start]53.8

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

      sqr-neg [=>]53.8

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

      rem-square-sqrt [=>]53.8

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

      \[\leadsto \color{blue}{0.125 \cdot {x}^{2} + -0.0859375 \cdot {x}^{4}} \]
    6. Simplified99.5

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

      [Start]99.5

      \[ 0.125 \cdot {x}^{2} + -0.0859375 \cdot {x}^{4} \]

      fma-def [=>]99.5

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

      unpow2 [=>]99.5

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

      *-commutative [=>]99.5

      \[ \mathsf{fma}\left(0.125, x \cdot x, \color{blue}{{x}^{4} \cdot -0.0859375}\right) \]
    7. Applied egg-rr99.5

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

    if 2 < (hypot.f64 1 x)

    1. Initial program 98.5

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

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

      [Start]98.5

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

      distribute-lft-in [=>]98.5

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

      metadata-eval [=>]98.5

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

      associate-*r/ [=>]98.5

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

      metadata-eval [=>]98.5

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

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

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

      [Start]98.5

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

      sqr-neg [=>]98.5

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

      rem-square-sqrt [=>]100.0

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

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

Alternatives

Alternative 1
Error99.7%
Cost26756.00
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 2:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + 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}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]
Alternative 2
Error99.3%
Cost13576.00
\[\begin{array}{l} t_0 := 0.5 + \frac{-0.5}{x}\\ \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;\frac{1 - t_0}{1 + \sqrt{t_0}}\\ \mathbf{elif}\;x \leq 0.0032:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \end{array} \]
Alternative 3
Error99.0%
Cost7492.00
\[\begin{array}{l} t_0 := 0.5 + \frac{-0.5}{x}\\ \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;\frac{1 - t_0}{1 + \sqrt{t_0}}\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{x}}\\ \end{array} \]
Alternative 4
Error98.7%
Cost7304.00
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{x}}\\ \end{array} \]
Alternative 5
Error98.4%
Cost7112.00
\[\begin{array}{l} \mathbf{if}\;x \leq -1.52:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{elif}\;x \leq 1.2:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{x}}\\ \end{array} \]
Alternative 6
Error98.4%
Cost6985.00
\[\begin{array}{l} \mathbf{if}\;x \leq -1.52 \lor \neg \left(x \leq 1.55\right):\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{else}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \end{array} \]
Alternative 7
Error97.6%
Cost6857.00
\[\begin{array}{l} \mathbf{if}\;x \leq -1.52 \lor \neg \left(x \leq 1.55\right):\\ \;\;\;\;1 - \sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;0.125 \cdot \left(x \cdot x\right)\\ \end{array} \]
Alternative 8
Error50.4%
Cost320.00
\[0.125 \cdot \left(x \cdot x\right) \]
Alternative 9
Error27.5%
Cost64.00
\[0 \]

Error

Reproduce?

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