Average Error: 59.6 → 57.3
Time: 9.3s
Precision: binary64
Cost: 104064
\[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)\\ t_1 := {\left({t_0}^{0.16666666666666666}\right)}^{3}\\ \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_1 \cdot t_1} \end{array} \]
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (asin (- 1.0 x))) (t_1 (pow (pow t_0 0.16666666666666666) 3.0)))
   (/
    (fma
     (cbrt (pow (* PI 0.5) 4.0))
     (cbrt (* 0.25 (pow PI 2.0)))
     (- (pow t_0 2.0)))
    (+ (* PI 0.5) (* t_1 t_1)))))
double code(double x) {
	return acos((1.0 - x));
}
double code(double x) {
	double t_0 = asin((1.0 - x));
	double t_1 = pow(pow(t_0, 0.16666666666666666), 3.0);
	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) + (t_1 * t_1));
}
function code(x)
	return acos(Float64(1.0 - x))
end
function code(x)
	t_0 = asin(Float64(1.0 - x))
	t_1 = (t_0 ^ 0.16666666666666666) ^ 3.0
	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) + Float64(t_1 * t_1)))
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]}, Block[{t$95$1 = N[Power[N[Power[t$95$0, 0.16666666666666666], $MachinePrecision], 3.0], $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[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\cos^{-1} \left(1 - x\right)
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := {\left({t_0}^{0.16666666666666666}\right)}^{3}\\
\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_1 \cdot t_1}
\end{array}

Error

Target

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

Derivation

  1. Initial program 59.6

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

    \[\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.3

    \[\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.3

    \[\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. Applied egg-rr57.3

    \[\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({\sin^{-1} \left(1 - x\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({\sin^{-1} \left(1 - x\right)}^{0.16666666666666666}\right)}^{3}}} \]
  6. Final simplification57.3

    \[\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({\sin^{-1} \left(1 - x\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({\sin^{-1} \left(1 - x\right)}^{0.16666666666666666}\right)}^{3}} \]

Alternatives

Alternative 1
Error57.3
Cost84416
\[\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} \]
Alternative 2
Error57.3
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 3
Error57.3
Cost19712
\[3 \cdot \mathsf{fma}\left(\pi, 0.16666666666666666, \sin^{-1} \left(1 - x\right) \cdot -0.3333333333333333\right) \]
Alternative 4
Error59.6
Cost13700
\[\begin{array}{l} t_0 := \sin^{-1} \left(1 - x\right)\\ \mathbf{if}\;1 - x \leq 1:\\ \;\;\;\;\left(\pi \cdot 0.5 + 1\right) - \left(1 + t_0\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot t_0 + \cos^{-1} \left(1 - x\right)\\ \end{array} \]
Alternative 5
Error57.9
Cost13508
\[\begin{array}{l} t_0 := \cos^{-1} \left(1 - x\right)\\ \mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\ \;\;\;\;2 \cdot \sin^{-1} \left(1 - x\right) + t_0\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(-1 + \left(2 + \left(-1 + \left(1 + t_0\right)\right)\right)\right)\\ \end{array} \]
Alternative 6
Error59.6
Cost7232
\[-1 + \left(-1 + \left(2 + \left(-1 + \left(1 + \cos^{-1} \left(1 - x\right)\right)\right)\right)\right) \]
Alternative 7
Error59.6
Cost6848
\[1 + \left(-1 + \cos^{-1} \left(1 - x\right)\right) \]
Alternative 8
Error59.6
Cost6848
\[-1 + \left(1 + \cos^{-1} \left(1 - x\right)\right) \]
Alternative 9
Error59.6
Cost6592
\[\cos^{-1} \left(1 - x\right) \]

Error

Reproduce

herbie shell --seed 2023016 
(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)))