bug323 (missed optimization)

Percentage Accurate: 6.6% → 9.2%
Time: 5.6s
Alternatives: 5
Speedup: 1.0×

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 5 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: 6.6% 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: 9.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \pi + \cos^{-1} x\\ \mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\ \;\;\;\;\frac{{\left(\frac{\pi \cdot \pi}{t\_0}\right)}^{2} - \frac{{\cos^{-1} x}^{4}}{{\left(\cos^{-1} x - \pi\right)}^{2}}}{t\_0}\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(1 - x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ PI (acos x))))
   (if (<= x 5.5e-17)
     (/
      (-
       (pow (/ (* PI PI) t_0) 2.0)
       (/ (pow (acos x) 4.0) (pow (- (acos x) PI) 2.0)))
      t_0)
     (acos (- 1.0 x)))))
double code(double x) {
	double t_0 = ((double) M_PI) + acos(x);
	double tmp;
	if (x <= 5.5e-17) {
		tmp = (pow(((((double) M_PI) * ((double) M_PI)) / t_0), 2.0) - (pow(acos(x), 4.0) / pow((acos(x) - ((double) M_PI)), 2.0))) / t_0;
	} else {
		tmp = acos((1.0 - x));
	}
	return tmp;
}
public static double code(double x) {
	double t_0 = Math.PI + Math.acos(x);
	double tmp;
	if (x <= 5.5e-17) {
		tmp = (Math.pow(((Math.PI * Math.PI) / t_0), 2.0) - (Math.pow(Math.acos(x), 4.0) / Math.pow((Math.acos(x) - Math.PI), 2.0))) / t_0;
	} else {
		tmp = Math.acos((1.0 - x));
	}
	return tmp;
}
def code(x):
	t_0 = math.pi + math.acos(x)
	tmp = 0
	if x <= 5.5e-17:
		tmp = (math.pow(((math.pi * math.pi) / t_0), 2.0) - (math.pow(math.acos(x), 4.0) / math.pow((math.acos(x) - math.pi), 2.0))) / t_0
	else:
		tmp = math.acos((1.0 - x))
	return tmp
function code(x)
	t_0 = Float64(pi + acos(x))
	tmp = 0.0
	if (x <= 5.5e-17)
		tmp = Float64(Float64((Float64(Float64(pi * pi) / t_0) ^ 2.0) - Float64((acos(x) ^ 4.0) / (Float64(acos(x) - pi) ^ 2.0))) / t_0);
	else
		tmp = acos(Float64(1.0 - x));
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = pi + acos(x);
	tmp = 0.0;
	if (x <= 5.5e-17)
		tmp = ((((pi * pi) / t_0) ^ 2.0) - ((acos(x) ^ 4.0) / ((acos(x) - pi) ^ 2.0))) / t_0;
	else
		tmp = acos((1.0 - x));
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(Pi + N[ArcCos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 5.5e-17], N[(N[(N[Power[N[(N[(Pi * Pi), $MachinePrecision] / t$95$0), $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Power[N[ArcCos[x], $MachinePrecision], 4.0], $MachinePrecision] / N[Power[N[(N[ArcCos[x], $MachinePrecision] - Pi), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \pi + \cos^{-1} x\\
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\frac{{\left(\frac{\pi \cdot \pi}{t\_0}\right)}^{2} - \frac{{\cos^{-1} x}^{4}}{{\left(\cos^{-1} x - \pi\right)}^{2}}}{t\_0}\\

\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(1 - x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 5.50000000000000001e-17

    1. Initial program 3.9%

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

      \[\leadsto \mathsf{acos.f64}\left(\color{blue}{\left(-1 \cdot x\right)}\right) \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{acos.f64}\left(\left(\mathsf{neg}\left(x\right)\right)\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{acos.f64}\left(\left(0 - x\right)\right) \]
      3. --lowering--.f646.5%

        \[\leadsto \mathsf{acos.f64}\left(\mathsf{\_.f64}\left(0, x\right)\right) \]
    5. Simplified6.5%

      \[\leadsto \cos^{-1} \color{blue}{\left(0 - x\right)} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(x\right)\right) \]
      2. acos-negN/A

        \[\leadsto \mathsf{PI}\left(\right) - \color{blue}{\cos^{-1} x} \]
      3. add-sqr-sqrtN/A

        \[\leadsto \sqrt{\mathsf{PI}\left(\right)} \cdot \sqrt{\mathsf{PI}\left(\right)} - \cos^{-1} \color{blue}{x} \]
      4. fmm-defN/A

        \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{PI}\left(\right)}, \color{blue}{\sqrt{\mathsf{PI}\left(\right)}}, \mathsf{neg}\left(\cos^{-1} x\right)\right) \]
      5. fma-lowering-fma.f64N/A

        \[\leadsto \mathsf{fma.f64}\left(\left(\sqrt{\mathsf{PI}\left(\right)}\right), \color{blue}{\left(\sqrt{\mathsf{PI}\left(\right)}\right)}, \left(\mathsf{neg}\left(\cos^{-1} x\right)\right)\right) \]
      6. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI}\left(\right)\right), \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right)}}\right), \left(\mathsf{neg}\left(\cos^{-1} x\right)\right)\right) \]
      7. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \left(\sqrt{\mathsf{PI}\left(\right)}\right), \left(\mathsf{neg}\left(\cos^{-1} x\right)\right)\right) \]
      8. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI}\left(\right)\right), \left(\mathsf{neg}\left(\cos^{-1} x\right)\right)\right) \]
      9. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \left(\mathsf{neg}\left(\cos^{-1} x\right)\right)\right) \]
      10. acos-asinN/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \left(\mathsf{neg}\left(\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} x\right)\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \left(\mathsf{neg}\left(\left(\frac{\mathsf{PI}\left(\right)}{2} + \left(\mathsf{neg}\left(\sin^{-1} x\right)\right)\right)\right)\right)\right) \]
      12. asin-negN/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \left(\mathsf{neg}\left(\left(\frac{\mathsf{PI}\left(\right)}{2} + \sin^{-1} \left(\mathsf{neg}\left(x\right)\right)\right)\right)\right)\right) \]
      13. sub0-negN/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \left(\mathsf{neg}\left(\left(\frac{\mathsf{PI}\left(\right)}{2} + \sin^{-1} \left(0 - x\right)\right)\right)\right)\right) \]
      14. neg-lowering-neg.f64N/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{neg.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2} + \sin^{-1} \left(0 - x\right)\right)\right)\right) \]
      15. sub0-negN/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{neg.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2} + \sin^{-1} \left(\mathsf{neg}\left(x\right)\right)\right)\right)\right) \]
      16. asin-negN/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{neg.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2} + \left(\mathsf{neg}\left(\sin^{-1} x\right)\right)\right)\right)\right) \]
      17. unsub-negN/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{neg.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} x\right)\right)\right) \]
      18. acos-asinN/A

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{neg.f64}\left(\cos^{-1} x\right)\right) \]
      19. acos-lowering-acos.f646.5%

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{sqrt.f64}\left(\mathsf{PI.f64}\left(\right)\right), \mathsf{neg.f64}\left(\mathsf{acos.f64}\left(x\right)\right)\right) \]
    7. Applied egg-rr6.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\pi}, \sqrt{\pi}, -\cos^{-1} x\right)} \]
    8. Applied egg-rr6.5%

      \[\leadsto \color{blue}{\frac{\frac{\pi \cdot \pi}{\cos^{-1} x + \pi} \cdot \frac{\pi \cdot \pi}{\cos^{-1} x + \pi} - \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \pi} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \pi}}{\cos^{-1} x + \pi}} \]
    9. Step-by-step derivation
      1. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{\cos^{-1} x + \mathsf{PI}\left(\right)} \cdot \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{\cos^{-1} x + \mathsf{PI}\left(\right)}\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\color{blue}{\mathsf{acos.f64}\left(x\right)}, \mathsf{PI.f64}\left(\right)\right)\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left({\left(\frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{\cos^{-1} x + \mathsf{PI}\left(\right)}\right)}^{2}\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(\color{blue}{x}\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      3. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{pow.f64}\left(\left(\frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{\cos^{-1} x + \mathsf{PI}\left(\right)}\right), 2\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(\color{blue}{x}\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{pow.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), \left(\cos^{-1} x + \mathsf{PI}\left(\right)\right)\right), 2\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{pow.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI}\left(\right), \mathsf{PI}\left(\right)\right), \left(\cos^{-1} x + \mathsf{PI}\left(\right)\right)\right), 2\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      6. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{pow.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{PI}\left(\right)\right), \left(\cos^{-1} x + \mathsf{PI}\left(\right)\right)\right), 2\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      7. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{pow.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{PI.f64}\left(\right)\right), \left(\cos^{-1} x + \mathsf{PI}\left(\right)\right)\right), 2\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      8. +-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{pow.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{PI.f64}\left(\right)\right), \left(\mathsf{PI}\left(\right) + \cos^{-1} x\right)\right), 2\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{pow.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{PI.f64}\left(\right)\right), \mathsf{+.f64}\left(\mathsf{PI}\left(\right), \cos^{-1} x\right)\right), 2\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      10. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{pow.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{PI.f64}\left(\right)\right), \mathsf{+.f64}\left(\mathsf{PI.f64}\left(\right), \cos^{-1} x\right)\right), 2\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      11. acos-lowering-acos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{pow.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{PI.f64}\left(\right)\right), \mathsf{+.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(x\right)\right)\right), 2\right), \left(\frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)} \cdot \frac{{\cos^{-1} x}^{2}}{\cos^{-1} x - \mathsf{PI}\left(\right)}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
    10. Applied egg-rr6.5%

      \[\leadsto \frac{\color{blue}{{\left(\frac{\pi \cdot \pi}{\pi + \cos^{-1} x}\right)}^{2} - \frac{{\cos^{-1} x}^{4}}{{\left(\cos^{-1} x - \pi\right)}^{2}}}}{\cos^{-1} x + \pi} \]

    if 5.50000000000000001e-17 < x

    1. Initial program 76.0%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification8.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\ \;\;\;\;\frac{{\left(\frac{\pi \cdot \pi}{\pi + \cos^{-1} x}\right)}^{2} - \frac{{\cos^{-1} x}^{4}}{{\left(\cos^{-1} x - \pi\right)}^{2}}}{\pi + \cos^{-1} x}\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(1 - x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 9.2% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\ \;\;\;\;\frac{\frac{\pi \cdot \pi}{4} - {\sin^{-1} x}^{2}}{\pi + \cos^{-1} x}\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(1 - x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 5.5e-17)
   (/ (- (/ (* PI PI) 4.0) (pow (asin x) 2.0)) (+ PI (acos x)))
   (acos (- 1.0 x))))
double code(double x) {
	double tmp;
	if (x <= 5.5e-17) {
		tmp = (((((double) M_PI) * ((double) M_PI)) / 4.0) - pow(asin(x), 2.0)) / (((double) M_PI) + acos(x));
	} else {
		tmp = acos((1.0 - x));
	}
	return tmp;
}
public static double code(double x) {
	double tmp;
	if (x <= 5.5e-17) {
		tmp = (((Math.PI * Math.PI) / 4.0) - Math.pow(Math.asin(x), 2.0)) / (Math.PI + Math.acos(x));
	} else {
		tmp = Math.acos((1.0 - x));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 5.5e-17:
		tmp = (((math.pi * math.pi) / 4.0) - math.pow(math.asin(x), 2.0)) / (math.pi + math.acos(x))
	else:
		tmp = math.acos((1.0 - x))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 5.5e-17)
		tmp = Float64(Float64(Float64(Float64(pi * pi) / 4.0) - (asin(x) ^ 2.0)) / Float64(pi + acos(x)));
	else
		tmp = acos(Float64(1.0 - x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 5.5e-17)
		tmp = (((pi * pi) / 4.0) - (asin(x) ^ 2.0)) / (pi + acos(x));
	else
		tmp = acos((1.0 - x));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 5.5e-17], N[(N[(N[(N[(Pi * Pi), $MachinePrecision] / 4.0), $MachinePrecision] - N[Power[N[ArcSin[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(Pi + N[ArcCos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\frac{\frac{\pi \cdot \pi}{4} - {\sin^{-1} x}^{2}}{\pi + \cos^{-1} x}\\

\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(1 - x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 5.50000000000000001e-17

    1. Initial program 3.9%

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

      \[\leadsto \mathsf{acos.f64}\left(\color{blue}{\left(-1 \cdot x\right)}\right) \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{acos.f64}\left(\left(\mathsf{neg}\left(x\right)\right)\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{acos.f64}\left(\left(0 - x\right)\right) \]
      3. --lowering--.f646.5%

        \[\leadsto \mathsf{acos.f64}\left(\mathsf{\_.f64}\left(0, x\right)\right) \]
    5. Simplified6.5%

      \[\leadsto \cos^{-1} \color{blue}{\left(0 - x\right)} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(x\right)\right) \]
      2. +-lft-identityN/A

        \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(\left(0 + x\right)\right)\right) \]
      3. flip3-+N/A

        \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(\frac{{0}^{3} + {x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right)\right) \]
      4. distribute-neg-fracN/A

        \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left(\left({0}^{3} + {x}^{3}\right)\right)}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      5. metadata-evalN/A

        \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left(\left(0 + {x}^{3}\right)\right)}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      6. +-lft-identityN/A

        \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left({x}^{3}\right)}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      7. cube-negN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(\mathsf{neg}\left(x\right)\right)}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      8. sub0-negN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(0 - x\right)}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      9. sqr-powN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(0 - x\right)}^{\left(\frac{3}{2}\right)} \cdot {\left(0 - x\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      10. unpow-prod-downN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(\left(0 - x\right) \cdot \left(0 - x\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      11. sub0-negN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(\left(\mathsf{neg}\left(x\right)\right) \cdot \left(0 - x\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      12. sub0-negN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(\left(\mathsf{neg}\left(x\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      13. sqr-negN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(x \cdot x\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      14. pow-prod-downN/A

        \[\leadsto \cos^{-1} \left(\frac{{x}^{\left(\frac{3}{2}\right)} \cdot {x}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      15. sqr-powN/A

        \[\leadsto \cos^{-1} \left(\frac{{x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      16. +-lft-identityN/A

        \[\leadsto \cos^{-1} \left(\frac{0 + {x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      17. metadata-evalN/A

        \[\leadsto \cos^{-1} \left(\frac{{0}^{3} + {x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      18. flip3-+N/A

        \[\leadsto \cos^{-1} \left(0 + x\right) \]
      19. +-lft-identityN/A

        \[\leadsto \cos^{-1} x \]
      20. acos-lowering-acos.f646.5%

        \[\leadsto \mathsf{acos.f64}\left(x\right) \]
    7. Applied egg-rr6.5%

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

      \[\leadsto \color{blue}{\frac{\frac{\pi \cdot \pi}{4} - \left(0 - \sin^{-1} x\right) \cdot \left(0 - \sin^{-1} x\right)}{\cos^{-1} x + \pi}} \]
    9. Step-by-step derivation
      1. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{4}\right), \left(\left(0 - \sin^{-1} x\right) \cdot \left(0 - \sin^{-1} x\right)\right)\right), \mathsf{+.f64}\left(\color{blue}{\mathsf{acos.f64}\left(x\right)}, \mathsf{PI.f64}\left(\right)\right)\right) \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), 4\right), \left(\left(0 - \sin^{-1} x\right) \cdot \left(0 - \sin^{-1} x\right)\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(\color{blue}{x}\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI}\left(\right), \mathsf{PI}\left(\right)\right), 4\right), \left(\left(0 - \sin^{-1} x\right) \cdot \left(0 - \sin^{-1} x\right)\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{PI}\left(\right)\right), 4\right), \left(\left(0 - \sin^{-1} x\right) \cdot \left(0 - \sin^{-1} x\right)\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      5. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{PI.f64}\left(\right)\right), 4\right), \left(\left(0 - \sin^{-1} x\right) \cdot \left(0 - \sin^{-1} x\right)\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      6. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{PI.f64}\left(\right)\right), 4\right), \left({\left(0 - \sin^{-1} x\right)}^{2}\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
      7. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{PI.f64}\left(\right)\right), 4\right), \mathsf{pow.f64}\left(\left(0 - \sin^{-1} x\right), 2\right)\right), \mathsf{+.f64}\left(\mathsf{acos.f64}\left(x\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
    10. Applied egg-rr6.5%

      \[\leadsto \frac{\color{blue}{\frac{\pi \cdot \pi}{4} - {\sin^{-1} x}^{2}}}{\cos^{-1} x + \pi} \]

    if 5.50000000000000001e-17 < x

    1. Initial program 76.0%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification8.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\ \;\;\;\;\frac{\frac{\pi \cdot \pi}{4} - {\sin^{-1} x}^{2}}{\pi + \cos^{-1} x}\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(1 - x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 9.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} x\\

\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(1 - x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 5.50000000000000001e-17

    1. Initial program 3.9%

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

      \[\leadsto \mathsf{acos.f64}\left(\color{blue}{\left(-1 \cdot x\right)}\right) \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{acos.f64}\left(\left(\mathsf{neg}\left(x\right)\right)\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{acos.f64}\left(\left(0 - x\right)\right) \]
      3. --lowering--.f646.5%

        \[\leadsto \mathsf{acos.f64}\left(\mathsf{\_.f64}\left(0, x\right)\right) \]
    5. Simplified6.5%

      \[\leadsto \cos^{-1} \color{blue}{\left(0 - x\right)} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(x\right)\right) \]
      2. +-lft-identityN/A

        \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(\left(0 + x\right)\right)\right) \]
      3. flip3-+N/A

        \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(\frac{{0}^{3} + {x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right)\right) \]
      4. distribute-neg-fracN/A

        \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left(\left({0}^{3} + {x}^{3}\right)\right)}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      5. metadata-evalN/A

        \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left(\left(0 + {x}^{3}\right)\right)}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      6. +-lft-identityN/A

        \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left({x}^{3}\right)}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      7. cube-negN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(\mathsf{neg}\left(x\right)\right)}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      8. sub0-negN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(0 - x\right)}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      9. sqr-powN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(0 - x\right)}^{\left(\frac{3}{2}\right)} \cdot {\left(0 - x\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      10. unpow-prod-downN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(\left(0 - x\right) \cdot \left(0 - x\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      11. sub0-negN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(\left(\mathsf{neg}\left(x\right)\right) \cdot \left(0 - x\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      12. sub0-negN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(\left(\mathsf{neg}\left(x\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      13. sqr-negN/A

        \[\leadsto \cos^{-1} \left(\frac{{\left(x \cdot x\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      14. pow-prod-downN/A

        \[\leadsto \cos^{-1} \left(\frac{{x}^{\left(\frac{3}{2}\right)} \cdot {x}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      15. sqr-powN/A

        \[\leadsto \cos^{-1} \left(\frac{{x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      16. +-lft-identityN/A

        \[\leadsto \cos^{-1} \left(\frac{0 + {x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      17. metadata-evalN/A

        \[\leadsto \cos^{-1} \left(\frac{{0}^{3} + {x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
      18. flip3-+N/A

        \[\leadsto \cos^{-1} \left(0 + x\right) \]
      19. +-lft-identityN/A

        \[\leadsto \cos^{-1} x \]
      20. acos-lowering-acos.f646.5%

        \[\leadsto \mathsf{acos.f64}\left(x\right) \]
    7. Applied egg-rr6.5%

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

    if 5.50000000000000001e-17 < x

    1. Initial program 76.0%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 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 6.1%

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

    \[\leadsto \mathsf{acos.f64}\left(\color{blue}{\left(-1 \cdot x\right)}\right) \]
  4. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{acos.f64}\left(\left(\mathsf{neg}\left(x\right)\right)\right) \]
    2. neg-sub0N/A

      \[\leadsto \mathsf{acos.f64}\left(\left(0 - x\right)\right) \]
    3. --lowering--.f646.7%

      \[\leadsto \mathsf{acos.f64}\left(\mathsf{\_.f64}\left(0, x\right)\right) \]
  5. Simplified6.7%

    \[\leadsto \cos^{-1} \color{blue}{\left(0 - x\right)} \]
  6. Step-by-step derivation
    1. sub0-negN/A

      \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(x\right)\right) \]
    2. +-lft-identityN/A

      \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(\left(0 + x\right)\right)\right) \]
    3. flip3-+N/A

      \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(\frac{{0}^{3} + {x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right)\right) \]
    4. distribute-neg-fracN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left(\left({0}^{3} + {x}^{3}\right)\right)}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    5. metadata-evalN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left(\left(0 + {x}^{3}\right)\right)}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    6. +-lft-identityN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left({x}^{3}\right)}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    7. cube-negN/A

      \[\leadsto \cos^{-1} \left(\frac{{\left(\mathsf{neg}\left(x\right)\right)}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    8. sub0-negN/A

      \[\leadsto \cos^{-1} \left(\frac{{\left(0 - x\right)}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    9. sqr-powN/A

      \[\leadsto \cos^{-1} \left(\frac{{\left(0 - x\right)}^{\left(\frac{3}{2}\right)} \cdot {\left(0 - x\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    10. unpow-prod-downN/A

      \[\leadsto \cos^{-1} \left(\frac{{\left(\left(0 - x\right) \cdot \left(0 - x\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    11. sub0-negN/A

      \[\leadsto \cos^{-1} \left(\frac{{\left(\left(\mathsf{neg}\left(x\right)\right) \cdot \left(0 - x\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    12. sub0-negN/A

      \[\leadsto \cos^{-1} \left(\frac{{\left(\left(\mathsf{neg}\left(x\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    13. sqr-negN/A

      \[\leadsto \cos^{-1} \left(\frac{{\left(x \cdot x\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    14. pow-prod-downN/A

      \[\leadsto \cos^{-1} \left(\frac{{x}^{\left(\frac{3}{2}\right)} \cdot {x}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    15. sqr-powN/A

      \[\leadsto \cos^{-1} \left(\frac{{x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    16. +-lft-identityN/A

      \[\leadsto \cos^{-1} \left(\frac{0 + {x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    17. metadata-evalN/A

      \[\leadsto \cos^{-1} \left(\frac{{0}^{3} + {x}^{3}}{0 \cdot 0 + \left(x \cdot x - 0 \cdot x\right)}\right) \]
    18. flip3-+N/A

      \[\leadsto \cos^{-1} \left(0 + x\right) \]
    19. +-lft-identityN/A

      \[\leadsto \cos^{-1} x \]
    20. acos-lowering-acos.f646.7%

      \[\leadsto \mathsf{acos.f64}\left(x\right) \]
  7. Applied egg-rr6.7%

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

Alternative 5: 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 6.1%

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

    \[\leadsto \mathsf{acos.f64}\left(\color{blue}{1}\right) \]
  4. Step-by-step derivation
    1. Simplified3.9%

      \[\leadsto \cos^{-1} \color{blue}{1} \]
    2. 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 2024155 
    (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)))