?

Average Error: 59.7 → 57.4
Time: 9.7s
Precision: binary64
Cost: 84416

?

\[0 \leq x \land x \leq 0.5\]
\[\cos^{-1} \left(1 - x\right) \]
\[\begin{array}{l} t_0 := \sin^{-1} \left(1 - x\right)\\ \frac{\mathsf{fma}\left(\sqrt[3]{{\left(\pi \cdot 0.5\right)}^{4}}, \sqrt[3]{0.25 \cdot {\pi}^{2}}, -{t_0}^{2}\right)}{\pi \cdot 0.5 + {\left(\sqrt[3]{t_0}\right)}^{3}} \end{array} \]
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (asin (- 1.0 x))))
   (/
    (fma
     (cbrt (pow (* PI 0.5) 4.0))
     (cbrt (* 0.25 (pow PI 2.0)))
     (- (pow t_0 2.0)))
    (+ (* PI 0.5) (pow (cbrt t_0) 3.0)))))
double code(double x) {
	return acos((1.0 - x));
}
double code(double x) {
	double t_0 = asin((1.0 - x));
	return fma(cbrt(pow((((double) M_PI) * 0.5), 4.0)), cbrt((0.25 * pow(((double) M_PI), 2.0))), -pow(t_0, 2.0)) / ((((double) M_PI) * 0.5) + pow(cbrt(t_0), 3.0));
}
function code(x)
	return acos(Float64(1.0 - x))
end
function code(x)
	t_0 = asin(Float64(1.0 - x))
	return Float64(fma(cbrt((Float64(pi * 0.5) ^ 4.0)), cbrt(Float64(0.25 * (pi ^ 2.0))), Float64(-(t_0 ^ 2.0))) / Float64(Float64(pi * 0.5) + (cbrt(t_0) ^ 3.0)))
end
code[x_] := N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Power[N[Power[N[(Pi * 0.5), $MachinePrecision], 4.0], $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(0.25 * N[Power[Pi, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + (-N[Power[t$95$0, 2.0], $MachinePrecision])), $MachinePrecision] / N[(N[(Pi * 0.5), $MachinePrecision] + N[Power[N[Power[t$95$0, 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\cos^{-1} \left(1 - x\right)
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\frac{\mathsf{fma}\left(\sqrt[3]{{\left(\pi \cdot 0.5\right)}^{4}}, \sqrt[3]{0.25 \cdot {\pi}^{2}}, -{t_0}^{2}\right)}{\pi \cdot 0.5 + {\left(\sqrt[3]{t_0}\right)}^{3}}
\end{array}

Error?

Target

Original59.7
Target0.0
Herbie57.4
\[2 \cdot \sin^{-1} \left(\sqrt{\frac{x}{2}}\right) \]

Derivation?

  1. Initial program 59.7

    \[\cos^{-1} \left(1 - x\right) \]
  2. Applied egg-rr59.7

    \[\leadsto \color{blue}{\frac{\left(\pi \cdot 0.5\right) \cdot \left(\pi \cdot 0.5\right) - \sin^{-1} \left(1 - x\right) \cdot \sin^{-1} \left(1 - x\right)}{\pi \cdot 0.5 + \sin^{-1} \left(1 - x\right)}} \]
  3. Applied egg-rr57.4

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\sqrt[3]{{\left(\pi \cdot 0.5\right)}^{4}}, \sqrt[3]{0.25 \cdot {\pi}^{2}}, -{\sin^{-1} \left(1 - x\right)}^{2}\right)}}{\pi \cdot 0.5 + \sin^{-1} \left(1 - x\right)} \]
  4. Applied egg-rr57.4

    \[\leadsto \frac{\mathsf{fma}\left(\sqrt[3]{{\left(\pi \cdot 0.5\right)}^{4}}, \sqrt[3]{0.25 \cdot {\pi}^{2}}, -{\sin^{-1} \left(1 - x\right)}^{2}\right)}{\pi \cdot 0.5 + \color{blue}{{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{3}}} \]
  5. Final simplification57.4

    \[\leadsto \frac{\mathsf{fma}\left(\sqrt[3]{{\left(\pi \cdot 0.5\right)}^{4}}, \sqrt[3]{0.25 \cdot {\pi}^{2}}, -{\sin^{-1} \left(1 - x\right)}^{2}\right)}{\pi \cdot 0.5 + {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{3}} \]

Alternatives

Alternative 1
Error57.4
Cost71552
\[\begin{array}{l} t_0 := \sin^{-1} \left(1 - x\right)\\ \frac{\mathsf{fma}\left(\sqrt[3]{{\left(\pi \cdot 0.5\right)}^{4}}, \sqrt[3]{0.25 \cdot {\pi}^{2}}, -{t_0}^{2}\right)}{\pi \cdot 0.5 + t_0} \end{array} \]
Alternative 2
Error57.4
Cost52160
\[\begin{array}{l} t_0 := \sin^{-1} \left(1 - x\right)\\ \mathsf{fma}\left(-\sqrt[3]{t_0}, \sqrt[3]{{t_0}^{2}}, t_0\right) + \cos^{-1} \left(1 - x\right) \end{array} \]
Alternative 3
Error57.4
Cost32704
\[\begin{array}{l} t_0 := \sqrt{2 + \cos^{-1} \left(1 - x\right)}\\ \mathsf{fma}\left(t_0, t_0, -2\right) \end{array} \]
Alternative 4
Error58.0
Cost19908
\[\begin{array}{l} t_0 := \cos^{-1} \left(1 - x\right)\\ t_1 := t_0 + -1\\ \mathbf{if}\;t_0 \leq 0:\\ \;\;\;\;1 + \left|t_1\right|\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{1}{\frac{1}{t_1}}\\ \end{array} \]
Alternative 5
Error59.7
Cost19780
\[\begin{array}{l} t_0 := \cos^{-1} \left(1 - x\right)\\ \mathbf{if}\;1 - x \leq 1:\\ \;\;\;\;e^{\mathsf{log1p}\left(t_0 + -1\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \left(1 + \mathsf{expm1}\left(-6\right)\right)\\ \end{array} \]
Alternative 6
Error57.4
Cost19712
\[-2 + {\left(\sqrt[3]{2 + \cos^{-1} \left(1 - x\right)}\right)}^{3} \]
Alternative 7
Error57.4
Cost19712
\[-2 + {\left(\sqrt{2 + \cos^{-1} \left(1 - x\right)}\right)}^{2} \]
Alternative 8
Error59.7
Cost13508
\[\begin{array}{l} t_0 := \cos^{-1} \left(1 - x\right)\\ \mathbf{if}\;1 - x \leq 1:\\ \;\;\;\;1 + \frac{1}{\frac{1}{t_0 + -1}}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \left(1 + \mathsf{expm1}\left(-6\right)\right)\\ \end{array} \]
Alternative 9
Error59.7
Cost7104
\[1 + \frac{1}{\frac{1}{\cos^{-1} \left(1 - x\right) + -1}} \]
Alternative 10
Error59.7
Cost6848
\[1 + \left(\cos^{-1} \left(1 - x\right) + -1\right) \]
Alternative 11
Error59.7
Cost6592
\[\cos^{-1} \left(1 - x\right) \]

Error

Reproduce?

herbie shell --seed 2023018 
(FPCore (x)
  :name "bug323 (missed optimization)"
  :precision binary64
  :pre (and (<= 0.0 x) (<= x 0.5))

  :herbie-target
  (* 2.0 (asin (sqrt (/ x 2.0))))

  (acos (- 1.0 x)))