bug323 (missed optimization)

Percentage Accurate: 7.0% → 10.4%
Time: 8.9s
Alternatives: 13
Speedup: 0.9×

Specification

?
\[0 \leq x \land x \leq 0.5\]
\[\begin{array}{l} \\ \cos^{-1} \left(1 - x\right) \end{array} \]
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
double code(double x) {
	return acos((1.0 - x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = acos((1.0d0 - x))
end function
public static double code(double x) {
	return Math.acos((1.0 - x));
}
def code(x):
	return math.acos((1.0 - x))
function code(x)
	return acos(Float64(1.0 - x))
end
function tmp = code(x)
	tmp = acos((1.0 - x));
end
code[x_] := N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(1 - x\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 13 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 7.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(1 - x\right) \end{array} \]
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
double code(double x) {
	return acos((1.0 - x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = acos((1.0d0 - x))
end function
public static double code(double x) {
	return Math.acos((1.0 - x));
}
def code(x):
	return math.acos((1.0 - x))
function code(x)
	return acos(Float64(1.0 - x))
end
function tmp = code(x)
	tmp = acos((1.0 - x));
end
code[x_] := N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(1 - x\right)
\end{array}

Alternative 1: 10.4% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt[3]{t\_0}\\
\mathsf{fma}\left(\pi, 0.5, t\_1 \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{t\_0}\right)}^{2}}, {t\_1}^{2}, {t\_1}^{3}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 7.4%

    \[\cos^{-1} \left(1 - x\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. acos-asin7.4%

      \[\leadsto \color{blue}{\frac{\pi}{2} - \sin^{-1} \left(1 - x\right)} \]
    2. div-inv7.4%

      \[\leadsto \color{blue}{\pi \cdot \frac{1}{2}} - \sin^{-1} \left(1 - x\right) \]
    3. metadata-eval7.4%

      \[\leadsto \pi \cdot \color{blue}{0.5} - \sin^{-1} \left(1 - x\right) \]
    4. add-cube-cbrt10.9%

      \[\leadsto \pi \cdot 0.5 - \color{blue}{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right) \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}} \]
    5. prod-diff10.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right)} \]
    6. pow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \color{blue}{{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right) \]
    7. pow210.9%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right)} \]
  5. Step-by-step derivation
    1. add-sqr-sqrt10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{\sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    2. pow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  6. Applied egg-rr10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  7. Step-by-step derivation
    1. asin-acos10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\frac{\pi}{2} - \cos^{-1} \left(1 - x\right)}}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    2. div-inv10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\pi \cdot \frac{1}{2}} - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    3. metadata-eval10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot \color{blue}{0.5} - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  8. Applied egg-rr10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  9. Step-by-step derivation
    1. unpow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \color{blue}{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}\right) \]
    2. cube-unmult10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \color{blue}{{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{3}}\right) \]
  10. Applied egg-rr10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \color{blue}{{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{3}}\right) \]
  11. Final simplification10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{3}\right) \]
  12. Add Preprocessing

Alternative 2: 10.4% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
t_1 := \sin^{-1} \left(1 - x\right)\\
t_2 := \sqrt[3]{t\_1}\\
\mathsf{fma}\left(\pi, 0.5, t\_2 \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - t\_0}\right)}^{2}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{t\_1}\right)}^{2}}, {t\_2}^{2}, \frac{\pi}{2} - t\_0\right)
\end{array}
\end{array}
Derivation
  1. Initial program 7.4%

    \[\cos^{-1} \left(1 - x\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. acos-asin7.4%

      \[\leadsto \color{blue}{\frac{\pi}{2} - \sin^{-1} \left(1 - x\right)} \]
    2. div-inv7.4%

      \[\leadsto \color{blue}{\pi \cdot \frac{1}{2}} - \sin^{-1} \left(1 - x\right) \]
    3. metadata-eval7.4%

      \[\leadsto \pi \cdot \color{blue}{0.5} - \sin^{-1} \left(1 - x\right) \]
    4. add-cube-cbrt10.9%

      \[\leadsto \pi \cdot 0.5 - \color{blue}{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right) \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}} \]
    5. prod-diff10.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right)} \]
    6. pow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \color{blue}{{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right) \]
    7. pow210.9%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right)} \]
  5. Step-by-step derivation
    1. add-sqr-sqrt10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{\sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    2. pow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  6. Applied egg-rr10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  7. Step-by-step derivation
    1. asin-acos10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\frac{\pi}{2} - \cos^{-1} \left(1 - x\right)}}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    2. div-inv10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\pi \cdot \frac{1}{2}} - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    3. metadata-eval10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot \color{blue}{0.5} - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  8. Applied egg-rr10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  9. Step-by-step derivation
    1. unpow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \color{blue}{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}\right) \]
    2. rem-3cbrt-rft10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \color{blue}{\sin^{-1} \left(1 - x\right)}\right) \]
    3. asin-acos10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \color{blue}{\frac{\pi}{2} - \cos^{-1} \left(1 - x\right)}\right) \]
  10. Applied egg-rr10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \color{blue}{\frac{\pi}{2} - \cos^{-1} \left(1 - x\right)}\right) \]
  11. Final simplification10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \frac{\pi}{2} - \cos^{-1} \left(1 - x\right)\right) \]
  12. Add Preprocessing

Alternative 3: 10.4% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt[3]{t\_0}\\
\mathsf{fma}\left(\pi, 0.5, t\_1 \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{t\_0}\right)}^{2}}, {t\_1}^{2}, t\_0\right)
\end{array}
\end{array}
Derivation
  1. Initial program 7.4%

    \[\cos^{-1} \left(1 - x\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. acos-asin7.4%

      \[\leadsto \color{blue}{\frac{\pi}{2} - \sin^{-1} \left(1 - x\right)} \]
    2. div-inv7.4%

      \[\leadsto \color{blue}{\pi \cdot \frac{1}{2}} - \sin^{-1} \left(1 - x\right) \]
    3. metadata-eval7.4%

      \[\leadsto \pi \cdot \color{blue}{0.5} - \sin^{-1} \left(1 - x\right) \]
    4. add-cube-cbrt10.9%

      \[\leadsto \pi \cdot 0.5 - \color{blue}{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right) \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}} \]
    5. prod-diff10.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right)} \]
    6. pow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \color{blue}{{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right) \]
    7. pow210.9%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right)} \]
  5. Step-by-step derivation
    1. add-sqr-sqrt10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{\sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    2. pow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  6. Applied egg-rr10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  7. Step-by-step derivation
    1. asin-acos10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\frac{\pi}{2} - \cos^{-1} \left(1 - x\right)}}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    2. div-inv10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\pi \cdot \frac{1}{2}} - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    3. metadata-eval10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot \color{blue}{0.5} - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  8. Applied egg-rr10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  9. Taylor expanded in x around 0 10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \color{blue}{\sin^{-1} \left(1 - x\right)}\right) \]
  10. Final simplification10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sin^{-1} \left(1 - x\right)\right) \]
  11. Add Preprocessing

Alternative 4: 10.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin^{-1} \left(1 - x\right)\\ t_1 := \sqrt{t\_0}\\ \cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-t\_1, t\_1, \sqrt[3]{{t\_0}^{3}}\right) \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (asin (- 1.0 x))) (t_1 (sqrt t_0)))
   (+ (acos (- 1.0 x)) (fma (- t_1) t_1 (cbrt (pow t_0 3.0))))))
double code(double x) {
	double t_0 = asin((1.0 - x));
	double t_1 = sqrt(t_0);
	return acos((1.0 - x)) + fma(-t_1, t_1, cbrt(pow(t_0, 3.0)));
}
function code(x)
	t_0 = asin(Float64(1.0 - x))
	t_1 = sqrt(t_0)
	return Float64(acos(Float64(1.0 - x)) + fma(Float64(-t_1), t_1, cbrt((t_0 ^ 3.0))))
end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + N[((-t$95$1) * t$95$1 + N[Power[N[Power[t$95$0, 3.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt{t\_0}\\
\cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-t\_1, t\_1, \sqrt[3]{{t\_0}^{3}}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 7.4%

    \[\cos^{-1} \left(1 - x\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. acos-asin7.4%

      \[\leadsto \color{blue}{\frac{\pi}{2} - \sin^{-1} \left(1 - x\right)} \]
    2. *-un-lft-identity7.4%

      \[\leadsto \color{blue}{1 \cdot \frac{\pi}{2}} - \sin^{-1} \left(1 - x\right) \]
    3. add-sqr-sqrt10.8%

      \[\leadsto 1 \cdot \frac{\pi}{2} - \color{blue}{\sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}} \]
    4. prod-diff10.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{\pi}{2}, -\sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}\right) + \mathsf{fma}\left(-\sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}\right)} \]
    5. add-sqr-sqrt10.9%

      \[\leadsto \mathsf{fma}\left(1, \frac{\pi}{2}, -\color{blue}{\sin^{-1} \left(1 - x\right)}\right) + \mathsf{fma}\left(-\sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}\right) \]
    6. fma-neg10.9%

      \[\leadsto \color{blue}{\left(1 \cdot \frac{\pi}{2} - \sin^{-1} \left(1 - x\right)\right)} + \mathsf{fma}\left(-\sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}\right) \]
    7. *-un-lft-identity10.9%

      \[\leadsto \left(\color{blue}{\frac{\pi}{2}} - \sin^{-1} \left(1 - x\right)\right) + \mathsf{fma}\left(-\sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}\right) \]
    8. acos-asin10.9%

      \[\leadsto \color{blue}{\cos^{-1} \left(1 - x\right)} + \mathsf{fma}\left(-\sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}\right) \]
    9. add-sqr-sqrt10.8%

      \[\leadsto \cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-\sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)}, \color{blue}{\sin^{-1} \left(1 - x\right)}\right) \]
  4. Applied egg-rr10.8%

    \[\leadsto \color{blue}{\cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-\sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)}, \sin^{-1} \left(1 - x\right)\right)} \]
  5. Step-by-step derivation
    1. add-cbrt-cube10.9%

      \[\leadsto \cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-\sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)}, \color{blue}{\sqrt[3]{\left(\sin^{-1} \left(1 - x\right) \cdot \sin^{-1} \left(1 - x\right)\right) \cdot \sin^{-1} \left(1 - x\right)}}\right) \]
    2. pow310.9%

      \[\leadsto \cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-\sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\color{blue}{{\sin^{-1} \left(1 - x\right)}^{3}}}\right) \]
  6. Applied egg-rr10.9%

    \[\leadsto \cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-\sqrt{\sin^{-1} \left(1 - x\right)}, \sqrt{\sin^{-1} \left(1 - x\right)}, \color{blue}{\sqrt[3]{{\sin^{-1} \left(1 - x\right)}^{3}}}\right) \]
  7. Add Preprocessing

Alternative 5: 10.4% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt{\pi \cdot 0.5}\\
{\left(\sqrt[3]{1 + \mathsf{fma}\left(t\_0, t\_0, -\sin^{-1} \left(1 - x\right)\right)}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} + -1
\end{array}
\end{array}
Derivation
  1. Initial program 7.4%

    \[\cos^{-1} \left(1 - x\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. expm1-log1p-u7.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(1 - x\right)\right)\right)} \]
    2. expm1-undefine7.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos^{-1} \left(1 - x\right)\right)} - 1} \]
    3. log1p-undefine7.4%

      \[\leadsto e^{\color{blue}{\log \left(1 + \cos^{-1} \left(1 - x\right)\right)}} - 1 \]
    4. rem-exp-log7.4%

      \[\leadsto \color{blue}{\left(1 + \cos^{-1} \left(1 - x\right)\right)} - 1 \]
  4. Applied egg-rr7.4%

    \[\leadsto \color{blue}{\left(1 + \cos^{-1} \left(1 - x\right)\right) - 1} \]
  5. Step-by-step derivation
    1. add-cube-cbrt7.4%

      \[\leadsto \color{blue}{\left(\sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)}\right) \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)}} - 1 \]
    2. pow27.4%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{1 + \cos^{-1} \left(1 - x\right)}\right)}^{2}} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} - 1 \]
  6. Applied egg-rr7.4%

    \[\leadsto \color{blue}{{\left(\sqrt[3]{1 + \cos^{-1} \left(1 - x\right)}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)}} - 1 \]
  7. Step-by-step derivation
    1. acos-asin7.4%

      \[\leadsto {\left(\sqrt[3]{1 + \color{blue}{\left(\frac{\pi}{2} - \sin^{-1} \left(1 - x\right)\right)}}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} - 1 \]
    2. add-sqr-sqrt10.9%

      \[\leadsto {\left(\sqrt[3]{1 + \left(\color{blue}{\sqrt{\frac{\pi}{2}} \cdot \sqrt{\frac{\pi}{2}}} - \sin^{-1} \left(1 - x\right)\right)}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} - 1 \]
    3. fma-neg10.9%

      \[\leadsto {\left(\sqrt[3]{1 + \color{blue}{\mathsf{fma}\left(\sqrt{\frac{\pi}{2}}, \sqrt{\frac{\pi}{2}}, -\sin^{-1} \left(1 - x\right)\right)}}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} - 1 \]
    4. div-inv10.9%

      \[\leadsto {\left(\sqrt[3]{1 + \mathsf{fma}\left(\sqrt{\color{blue}{\pi \cdot \frac{1}{2}}}, \sqrt{\frac{\pi}{2}}, -\sin^{-1} \left(1 - x\right)\right)}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} - 1 \]
    5. metadata-eval10.9%

      \[\leadsto {\left(\sqrt[3]{1 + \mathsf{fma}\left(\sqrt{\pi \cdot \color{blue}{0.5}}, \sqrt{\frac{\pi}{2}}, -\sin^{-1} \left(1 - x\right)\right)}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} - 1 \]
    6. div-inv10.9%

      \[\leadsto {\left(\sqrt[3]{1 + \mathsf{fma}\left(\sqrt{\pi \cdot 0.5}, \sqrt{\color{blue}{\pi \cdot \frac{1}{2}}}, -\sin^{-1} \left(1 - x\right)\right)}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} - 1 \]
    7. metadata-eval10.9%

      \[\leadsto {\left(\sqrt[3]{1 + \mathsf{fma}\left(\sqrt{\pi \cdot 0.5}, \sqrt{\pi \cdot \color{blue}{0.5}}, -\sin^{-1} \left(1 - x\right)\right)}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} - 1 \]
  8. Applied egg-rr10.9%

    \[\leadsto {\left(\sqrt[3]{1 + \color{blue}{\mathsf{fma}\left(\sqrt{\pi \cdot 0.5}, \sqrt{\pi \cdot 0.5}, -\sin^{-1} \left(1 - x\right)\right)}}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} - 1 \]
  9. Final simplification10.9%

    \[\leadsto {\left(\sqrt[3]{1 + \mathsf{fma}\left(\sqrt{\pi \cdot 0.5}, \sqrt{\pi \cdot 0.5}, -\sin^{-1} \left(1 - x\right)\right)}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} + -1 \]
  10. Add Preprocessing

Alternative 6: 10.4% accurate, 0.2× speedup?

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

\\
\mathsf{fma}\left(\pi, 0.5, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right)\right)
\end{array}
Derivation
  1. Initial program 7.4%

    \[\cos^{-1} \left(1 - x\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. acos-asin7.4%

      \[\leadsto \color{blue}{\frac{\pi}{2} - \sin^{-1} \left(1 - x\right)} \]
    2. div-inv7.4%

      \[\leadsto \color{blue}{\pi \cdot \frac{1}{2}} - \sin^{-1} \left(1 - x\right) \]
    3. metadata-eval7.4%

      \[\leadsto \pi \cdot \color{blue}{0.5} - \sin^{-1} \left(1 - x\right) \]
    4. add-cube-cbrt10.9%

      \[\leadsto \pi \cdot 0.5 - \color{blue}{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right) \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}} \]
    5. prod-diff10.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right)} \]
    6. pow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \color{blue}{{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right) \]
    7. pow210.9%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right)} \]
  5. Step-by-step derivation
    1. add-sqr-sqrt10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{\sqrt{\sin^{-1} \left(1 - x\right)} \cdot \sqrt{\sin^{-1} \left(1 - x\right)}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    2. pow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  6. Applied egg-rr10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\color{blue}{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  7. Step-by-step derivation
    1. asin-acos10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\frac{\pi}{2} - \cos^{-1} \left(1 - x\right)}}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    2. div-inv10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\pi \cdot \frac{1}{2}} - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
    3. metadata-eval10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot \color{blue}{0.5} - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  8. Applied egg-rr10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\color{blue}{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) \]
  9. Taylor expanded in x around 0 10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \color{blue}{\left(\sin^{-1} \left(1 - x\right) + -1 \cdot \sin^{-1} \left(1 - x\right)\right)} \]
  10. Step-by-step derivation
    1. distribute-rgt1-in10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \color{blue}{\left(-1 + 1\right) \cdot \sin^{-1} \left(1 - x\right)} \]
    2. metadata-eval10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \color{blue}{0} \cdot \sin^{-1} \left(1 - x\right) \]
    3. sub-neg10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + 0 \cdot \sin^{-1} \color{blue}{\left(1 + \left(-x\right)\right)} \]
    4. mul-1-neg10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + 0 \cdot \sin^{-1} \left(1 + \color{blue}{-1 \cdot x}\right) \]
    5. mul0-lft10.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \color{blue}{0} \]
  11. Simplified10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right) + \color{blue}{0} \]
  12. Final simplification10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right)\right) \]
  13. Add Preprocessing

Alternative 7: 10.4% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt[3]{\sin^{-1} \left(1 - x\right)}\\
\mathsf{fma}\left(\pi, 0.5, t\_0 \cdot \left(-{t\_0}^{2}\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 7.4%

    \[\cos^{-1} \left(1 - x\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. acos-asin7.4%

      \[\leadsto \color{blue}{\frac{\pi}{2} - \sin^{-1} \left(1 - x\right)} \]
    2. div-inv7.4%

      \[\leadsto \color{blue}{\pi \cdot \frac{1}{2}} - \sin^{-1} \left(1 - x\right) \]
    3. metadata-eval7.4%

      \[\leadsto \pi \cdot \color{blue}{0.5} - \sin^{-1} \left(1 - x\right) \]
    4. add-cube-cbrt10.9%

      \[\leadsto \pi \cdot 0.5 - \color{blue}{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right) \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}} \]
    5. prod-diff10.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right)} \]
    6. pow210.9%

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \color{blue}{{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)\right) \]
    7. pow210.9%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(1 - x\right)}, {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right)} \]
  5. Taylor expanded in x around 0 10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \color{blue}{\left(\sin^{-1} \left(1 - x\right) + -1 \cdot \sin^{-1} \left(1 - x\right)\right)} \]
  6. Simplified10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, -\sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right) + \color{blue}{0} \]
  7. Final simplification10.9%

    \[\leadsto \mathsf{fma}\left(\pi, 0.5, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(-{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right)\right) \]
  8. Add Preprocessing

Alternative 8: 9.5% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(1 - x\right)\\ \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;\cos^{-1} x\\ \mathbf{else}:\\ \;\;\;\;{\left(\mathsf{hypot}\left(1, \sqrt{t\_0}\right)\right)}^{2} + -1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (acos (- 1.0 x))))
   (if (<= t_0 0.0) (acos x) (+ (pow (hypot 1.0 (sqrt t_0)) 2.0) -1.0))))
double code(double x) {
	double t_0 = acos((1.0 - x));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = acos(x);
	} else {
		tmp = pow(hypot(1.0, sqrt(t_0)), 2.0) + -1.0;
	}
	return tmp;
}
public static double code(double x) {
	double t_0 = Math.acos((1.0 - x));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = Math.acos(x);
	} else {
		tmp = Math.pow(Math.hypot(1.0, Math.sqrt(t_0)), 2.0) + -1.0;
	}
	return tmp;
}
def code(x):
	t_0 = math.acos((1.0 - x))
	tmp = 0
	if t_0 <= 0.0:
		tmp = math.acos(x)
	else:
		tmp = math.pow(math.hypot(1.0, math.sqrt(t_0)), 2.0) + -1.0
	return tmp
function code(x)
	t_0 = acos(Float64(1.0 - x))
	tmp = 0.0
	if (t_0 <= 0.0)
		tmp = acos(x);
	else
		tmp = Float64((hypot(1.0, sqrt(t_0)) ^ 2.0) + -1.0);
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = acos((1.0 - x));
	tmp = 0.0;
	if (t_0 <= 0.0)
		tmp = acos(x);
	else
		tmp = (hypot(1.0, sqrt(t_0)) ^ 2.0) + -1.0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[ArcCos[x], $MachinePrecision], N[(N[Power[N[Sqrt[1.0 ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\cos^{-1} x\\

\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(1, \sqrt{t\_0}\right)\right)}^{2} + -1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (acos.f64 (-.f64 #s(literal 1 binary64) x)) < 0.0

    1. Initial program 3.9%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 6.5%

      \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
    4. Step-by-step derivation
      1. neg-mul-16.5%

        \[\leadsto \cos^{-1} \color{blue}{\left(-x\right)} \]
    5. Simplified6.5%

      \[\leadsto \cos^{-1} \color{blue}{\left(-x\right)} \]
    6. Step-by-step derivation
      1. *-un-lft-identity6.5%

        \[\leadsto \color{blue}{1 \cdot \cos^{-1} \left(-x\right)} \]
      2. add-sqr-sqrt0.0%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \]
      3. sqrt-unprod6.5%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{\left(-x\right) \cdot \left(-x\right)}\right)} \]
      4. sqr-neg6.5%

        \[\leadsto 1 \cdot \cos^{-1} \left(\sqrt{\color{blue}{x \cdot x}}\right) \]
      5. sqrt-unprod6.5%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \]
      6. add-sqr-sqrt6.5%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{x} \]
    7. Applied egg-rr6.5%

      \[\leadsto \color{blue}{1 \cdot \cos^{-1} x} \]
    8. Step-by-step derivation
      1. *-lft-identity6.5%

        \[\leadsto \color{blue}{\cos^{-1} x} \]
    9. Simplified6.5%

      \[\leadsto \color{blue}{\cos^{-1} x} \]

    if 0.0 < (acos.f64 (-.f64 #s(literal 1 binary64) x))

    1. Initial program 69.2%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u69.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(1 - x\right)\right)\right)} \]
      2. expm1-undefine69.2%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos^{-1} \left(1 - x\right)\right)} - 1} \]
      3. log1p-undefine69.2%

        \[\leadsto e^{\color{blue}{\log \left(1 + \cos^{-1} \left(1 - x\right)\right)}} - 1 \]
      4. rem-exp-log69.2%

        \[\leadsto \color{blue}{\left(1 + \cos^{-1} \left(1 - x\right)\right)} - 1 \]
    4. Applied egg-rr69.2%

      \[\leadsto \color{blue}{\left(1 + \cos^{-1} \left(1 - x\right)\right) - 1} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt69.1%

        \[\leadsto \color{blue}{\sqrt{1 + \cos^{-1} \left(1 - x\right)} \cdot \sqrt{1 + \cos^{-1} \left(1 - x\right)}} - 1 \]
      2. pow269.1%

        \[\leadsto \color{blue}{{\left(\sqrt{1 + \cos^{-1} \left(1 - x\right)}\right)}^{2}} - 1 \]
      3. rem-cbrt-cube69.1%

        \[\leadsto {\left(\sqrt{1 + \color{blue}{\sqrt[3]{{\cos^{-1} \left(1 - x\right)}^{3}}}}\right)}^{2} - 1 \]
      4. unpow1/369.3%

        \[\leadsto {\left(\sqrt{1 + \color{blue}{{\left({\cos^{-1} \left(1 - x\right)}^{3}\right)}^{0.3333333333333333}}}\right)}^{2} - 1 \]
      5. add-sqr-sqrt69.3%

        \[\leadsto {\left(\sqrt{1 + \color{blue}{\sqrt{{\left({\cos^{-1} \left(1 - x\right)}^{3}\right)}^{0.3333333333333333}} \cdot \sqrt{{\left({\cos^{-1} \left(1 - x\right)}^{3}\right)}^{0.3333333333333333}}}}\right)}^{2} - 1 \]
      6. hypot-1-def69.4%

        \[\leadsto {\color{blue}{\left(\mathsf{hypot}\left(1, \sqrt{{\left({\cos^{-1} \left(1 - x\right)}^{3}\right)}^{0.3333333333333333}}\right)\right)}}^{2} - 1 \]
      7. unpow1/369.4%

        \[\leadsto {\left(\mathsf{hypot}\left(1, \sqrt{\color{blue}{\sqrt[3]{{\cos^{-1} \left(1 - x\right)}^{3}}}}\right)\right)}^{2} - 1 \]
      8. rem-cbrt-cube69.4%

        \[\leadsto {\left(\mathsf{hypot}\left(1, \sqrt{\color{blue}{\cos^{-1} \left(1 - x\right)}}\right)\right)}^{2} - 1 \]
    6. Applied egg-rr69.4%

      \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left(1, \sqrt{\cos^{-1} \left(1 - x\right)}\right)\right)}^{2}} - 1 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification10.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos^{-1} \left(1 - x\right) \leq 0:\\ \;\;\;\;\cos^{-1} x\\ \mathbf{else}:\\ \;\;\;\;{\left(\mathsf{hypot}\left(1, \sqrt{\cos^{-1} \left(1 - x\right)}\right)\right)}^{2} + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 9.5% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(1 - x\right)\\ \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;\cos^{-1} x\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \log \left(e^{t\_0}\right)\right) + -1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (acos (- 1.0 x))))
   (if (<= t_0 0.0) (acos x) (+ (+ 1.0 (log (exp t_0))) -1.0))))
double code(double x) {
	double t_0 = acos((1.0 - x));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = acos(x);
	} else {
		tmp = (1.0 + log(exp(t_0))) + -1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = acos((1.0d0 - x))
    if (t_0 <= 0.0d0) then
        tmp = acos(x)
    else
        tmp = (1.0d0 + log(exp(t_0))) + (-1.0d0)
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = Math.acos((1.0 - x));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = Math.acos(x);
	} else {
		tmp = (1.0 + Math.log(Math.exp(t_0))) + -1.0;
	}
	return tmp;
}
def code(x):
	t_0 = math.acos((1.0 - x))
	tmp = 0
	if t_0 <= 0.0:
		tmp = math.acos(x)
	else:
		tmp = (1.0 + math.log(math.exp(t_0))) + -1.0
	return tmp
function code(x)
	t_0 = acos(Float64(1.0 - x))
	tmp = 0.0
	if (t_0 <= 0.0)
		tmp = acos(x);
	else
		tmp = Float64(Float64(1.0 + log(exp(t_0))) + -1.0);
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = acos((1.0 - x));
	tmp = 0.0;
	if (t_0 <= 0.0)
		tmp = acos(x);
	else
		tmp = (1.0 + log(exp(t_0))) + -1.0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[ArcCos[x], $MachinePrecision], N[(N[(1.0 + N[Log[N[Exp[t$95$0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\cos^{-1} x\\

\mathbf{else}:\\
\;\;\;\;\left(1 + \log \left(e^{t\_0}\right)\right) + -1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (acos.f64 (-.f64 #s(literal 1 binary64) x)) < 0.0

    1. Initial program 3.9%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 6.5%

      \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
    4. Step-by-step derivation
      1. neg-mul-16.5%

        \[\leadsto \cos^{-1} \color{blue}{\left(-x\right)} \]
    5. Simplified6.5%

      \[\leadsto \cos^{-1} \color{blue}{\left(-x\right)} \]
    6. Step-by-step derivation
      1. *-un-lft-identity6.5%

        \[\leadsto \color{blue}{1 \cdot \cos^{-1} \left(-x\right)} \]
      2. add-sqr-sqrt0.0%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \]
      3. sqrt-unprod6.5%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{\left(-x\right) \cdot \left(-x\right)}\right)} \]
      4. sqr-neg6.5%

        \[\leadsto 1 \cdot \cos^{-1} \left(\sqrt{\color{blue}{x \cdot x}}\right) \]
      5. sqrt-unprod6.5%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \]
      6. add-sqr-sqrt6.5%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{x} \]
    7. Applied egg-rr6.5%

      \[\leadsto \color{blue}{1 \cdot \cos^{-1} x} \]
    8. Step-by-step derivation
      1. *-lft-identity6.5%

        \[\leadsto \color{blue}{\cos^{-1} x} \]
    9. Simplified6.5%

      \[\leadsto \color{blue}{\cos^{-1} x} \]

    if 0.0 < (acos.f64 (-.f64 #s(literal 1 binary64) x))

    1. Initial program 69.2%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u69.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(1 - x\right)\right)\right)} \]
      2. expm1-undefine69.2%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos^{-1} \left(1 - x\right)\right)} - 1} \]
      3. log1p-undefine69.2%

        \[\leadsto e^{\color{blue}{\log \left(1 + \cos^{-1} \left(1 - x\right)\right)}} - 1 \]
      4. rem-exp-log69.2%

        \[\leadsto \color{blue}{\left(1 + \cos^{-1} \left(1 - x\right)\right)} - 1 \]
    4. Applied egg-rr69.2%

      \[\leadsto \color{blue}{\left(1 + \cos^{-1} \left(1 - x\right)\right) - 1} \]
    5. Step-by-step derivation
      1. add-log-exp69.4%

        \[\leadsto \left(1 + \color{blue}{\log \left(e^{\cos^{-1} \left(1 - x\right)}\right)}\right) - 1 \]
    6. Applied egg-rr69.4%

      \[\leadsto \left(1 + \color{blue}{\log \left(e^{\cos^{-1} \left(1 - x\right)}\right)}\right) - 1 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification10.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos^{-1} \left(1 - x\right) \leq 0:\\ \;\;\;\;\cos^{-1} x\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \log \left(e^{\cos^{-1} \left(1 - x\right)}\right)\right) + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 7.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - x \leq 1:\\ \;\;\;\;\cos^{-1} \left(e^{\mathsf{log1p}\left(-x\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} x\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- 1.0 x) 1.0) (acos (exp (log1p (- x)))) (acos x)))
double code(double x) {
	double tmp;
	if ((1.0 - x) <= 1.0) {
		tmp = acos(exp(log1p(-x)));
	} else {
		tmp = acos(x);
	}
	return tmp;
}
public static double code(double x) {
	double tmp;
	if ((1.0 - x) <= 1.0) {
		tmp = Math.acos(Math.exp(Math.log1p(-x)));
	} else {
		tmp = Math.acos(x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (1.0 - x) <= 1.0:
		tmp = math.acos(math.exp(math.log1p(-x)))
	else:
		tmp = math.acos(x)
	return tmp
function code(x)
	tmp = 0.0
	if (Float64(1.0 - x) <= 1.0)
		tmp = acos(exp(log1p(Float64(-x))));
	else
		tmp = acos(x);
	end
	return tmp
end
code[x_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 1.0], N[ArcCos[N[Exp[N[Log[1 + (-x)], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], N[ArcCos[x], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 1:\\
\;\;\;\;\cos^{-1} \left(e^{\mathsf{log1p}\left(-x\right)}\right)\\

\mathbf{else}:\\
\;\;\;\;\cos^{-1} x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 #s(literal 1 binary64) x) < 1

    1. Initial program 7.4%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-exp-log7.4%

        \[\leadsto \cos^{-1} \color{blue}{\left(e^{\log \left(1 - x\right)}\right)} \]
      2. sub-neg7.4%

        \[\leadsto \cos^{-1} \left(e^{\log \color{blue}{\left(1 + \left(-x\right)\right)}}\right) \]
      3. log1p-define7.4%

        \[\leadsto \cos^{-1} \left(e^{\color{blue}{\mathsf{log1p}\left(-x\right)}}\right) \]
    4. Applied egg-rr7.4%

      \[\leadsto \cos^{-1} \color{blue}{\left(e^{\mathsf{log1p}\left(-x\right)}\right)} \]

    if 1 < (-.f64 #s(literal 1 binary64) x)

    1. Initial program 7.4%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 6.9%

      \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
    4. Step-by-step derivation
      1. neg-mul-16.9%

        \[\leadsto \cos^{-1} \color{blue}{\left(-x\right)} \]
    5. Simplified6.9%

      \[\leadsto \cos^{-1} \color{blue}{\left(-x\right)} \]
    6. Step-by-step derivation
      1. *-un-lft-identity6.9%

        \[\leadsto \color{blue}{1 \cdot \cos^{-1} \left(-x\right)} \]
      2. add-sqr-sqrt0.0%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \]
      3. sqrt-unprod6.9%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{\left(-x\right) \cdot \left(-x\right)}\right)} \]
      4. sqr-neg6.9%

        \[\leadsto 1 \cdot \cos^{-1} \left(\sqrt{\color{blue}{x \cdot x}}\right) \]
      5. sqrt-unprod6.9%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \]
      6. add-sqr-sqrt6.9%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{x} \]
    7. Applied egg-rr6.9%

      \[\leadsto \color{blue}{1 \cdot \cos^{-1} x} \]
    8. Step-by-step derivation
      1. *-lft-identity6.9%

        \[\leadsto \color{blue}{\cos^{-1} x} \]
    9. Simplified6.9%

      \[\leadsto \color{blue}{\cos^{-1} x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 11: 7.0% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - x \leq 1:\\ \;\;\;\;\cos^{-1} \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} x\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- 1.0 x) 1.0) (acos (- 1.0 x)) (acos x)))
double code(double x) {
	double tmp;
	if ((1.0 - x) <= 1.0) {
		tmp = acos((1.0 - x));
	} else {
		tmp = acos(x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((1.0d0 - x) <= 1.0d0) then
        tmp = acos((1.0d0 - x))
    else
        tmp = acos(x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((1.0 - x) <= 1.0) {
		tmp = Math.acos((1.0 - x));
	} else {
		tmp = Math.acos(x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (1.0 - x) <= 1.0:
		tmp = math.acos((1.0 - x))
	else:
		tmp = math.acos(x)
	return tmp
function code(x)
	tmp = 0.0
	if (Float64(1.0 - x) <= 1.0)
		tmp = acos(Float64(1.0 - x));
	else
		tmp = acos(x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((1.0 - x) <= 1.0)
		tmp = acos((1.0 - x));
	else
		tmp = acos(x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 1.0], N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], N[ArcCos[x], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 1:\\
\;\;\;\;\cos^{-1} \left(1 - x\right)\\

\mathbf{else}:\\
\;\;\;\;\cos^{-1} x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 #s(literal 1 binary64) x) < 1

    1. Initial program 7.4%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing

    if 1 < (-.f64 #s(literal 1 binary64) x)

    1. Initial program 7.4%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 6.9%

      \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
    4. Step-by-step derivation
      1. neg-mul-16.9%

        \[\leadsto \cos^{-1} \color{blue}{\left(-x\right)} \]
    5. Simplified6.9%

      \[\leadsto \cos^{-1} \color{blue}{\left(-x\right)} \]
    6. Step-by-step derivation
      1. *-un-lft-identity6.9%

        \[\leadsto \color{blue}{1 \cdot \cos^{-1} \left(-x\right)} \]
      2. add-sqr-sqrt0.0%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \]
      3. sqrt-unprod6.9%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{\left(-x\right) \cdot \left(-x\right)}\right)} \]
      4. sqr-neg6.9%

        \[\leadsto 1 \cdot \cos^{-1} \left(\sqrt{\color{blue}{x \cdot x}}\right) \]
      5. sqrt-unprod6.9%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \]
      6. add-sqr-sqrt6.9%

        \[\leadsto 1 \cdot \cos^{-1} \color{blue}{x} \]
    7. Applied egg-rr6.9%

      \[\leadsto \color{blue}{1 \cdot \cos^{-1} x} \]
    8. Step-by-step derivation
      1. *-lft-identity6.9%

        \[\leadsto \color{blue}{\cos^{-1} x} \]
    9. Simplified6.9%

      \[\leadsto \color{blue}{\cos^{-1} x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 12: 6.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos^{-1} x \end{array} \]
(FPCore (x) :precision binary64 (acos x))
double code(double x) {
	return acos(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = acos(x)
end function
public static double code(double x) {
	return Math.acos(x);
}
def code(x):
	return math.acos(x)
function code(x)
	return acos(x)
end
function tmp = code(x)
	tmp = acos(x);
end
code[x_] := N[ArcCos[x], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} x
\end{array}
Derivation
  1. Initial program 7.4%

    \[\cos^{-1} \left(1 - x\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf 6.9%

    \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
  4. Step-by-step derivation
    1. neg-mul-16.9%

      \[\leadsto \cos^{-1} \color{blue}{\left(-x\right)} \]
  5. Simplified6.9%

    \[\leadsto \cos^{-1} \color{blue}{\left(-x\right)} \]
  6. Step-by-step derivation
    1. *-un-lft-identity6.9%

      \[\leadsto \color{blue}{1 \cdot \cos^{-1} \left(-x\right)} \]
    2. add-sqr-sqrt0.0%

      \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \]
    3. sqrt-unprod6.9%

      \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{\left(-x\right) \cdot \left(-x\right)}\right)} \]
    4. sqr-neg6.9%

      \[\leadsto 1 \cdot \cos^{-1} \left(\sqrt{\color{blue}{x \cdot x}}\right) \]
    5. sqrt-unprod6.9%

      \[\leadsto 1 \cdot \cos^{-1} \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \]
    6. add-sqr-sqrt6.9%

      \[\leadsto 1 \cdot \cos^{-1} \color{blue}{x} \]
  7. Applied egg-rr6.9%

    \[\leadsto \color{blue}{1 \cdot \cos^{-1} x} \]
  8. Step-by-step derivation
    1. *-lft-identity6.9%

      \[\leadsto \color{blue}{\cos^{-1} x} \]
  9. Simplified6.9%

    \[\leadsto \color{blue}{\cos^{-1} x} \]
  10. Add Preprocessing

Alternative 13: 3.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos^{-1} 1 \end{array} \]
(FPCore (x) :precision binary64 (acos 1.0))
double code(double x) {
	return acos(1.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = acos(1.0d0)
end function
public static double code(double x) {
	return Math.acos(1.0);
}
def code(x):
	return math.acos(1.0)
function code(x)
	return acos(1.0)
end
function tmp = code(x)
	tmp = acos(1.0);
end
code[x_] := N[ArcCos[1.0], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} 1
\end{array}
Derivation
  1. Initial program 7.4%

    \[\cos^{-1} \left(1 - x\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 3.8%

    \[\leadsto \cos^{-1} \color{blue}{1} \]
  4. Add Preprocessing

Developer Target 1: 100.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ 2 \cdot \sin^{-1} \left(\sqrt{\frac{x}{2}}\right) \end{array} \]
(FPCore (x) :precision binary64 (* 2.0 (asin (sqrt (/ x 2.0)))))
double code(double x) {
	return 2.0 * asin(sqrt((x / 2.0)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 2.0d0 * asin(sqrt((x / 2.0d0)))
end function
public static double code(double x) {
	return 2.0 * Math.asin(Math.sqrt((x / 2.0)));
}
def code(x):
	return 2.0 * math.asin(math.sqrt((x / 2.0)))
function code(x)
	return Float64(2.0 * asin(sqrt(Float64(x / 2.0))))
end
function tmp = code(x)
	tmp = 2.0 * asin(sqrt((x / 2.0)));
end
code[x_] := N[(2.0 * N[ArcSin[N[Sqrt[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
2 \cdot \sin^{-1} \left(\sqrt{\frac{x}{2}}\right)
\end{array}

Reproduce

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

  :alt
  (! :herbie-platform default (* 2 (asin (sqrt (/ x 2)))))

  (acos (- 1.0 x)))