Average Error: 59.6 → 57.3
Time: 9.3s
Precision: binary64
Cost: 208704
\[0 \leq x \land x \leq 0.5\]
\[\cos^{-1} \left(1 - x\right) \]
\[\begin{array}{l} t_0 := \left(\pi \cdot 0.5\right) \cdot \sqrt{\pi \cdot 0.5}\\ t_1 := \sin^{-1} \left(1 - x\right)\\ t_2 := {t_1}^{2}\\ t_3 := \sqrt{t_1}\\ t_4 := t_3 \cdot t_2\\ \frac{\mathsf{fma}\left(t_0, t_0, t_4 \cdot \left(-t_3\right)\right) + \mathsf{fma}\left(t_3 \cdot \left(-t_2\right), t_3, t_3 \cdot t_4\right)}{\left(\pi \cdot \pi\right) \cdot 0.25 + t_1 \cdot \mathsf{fma}\left(\pi, 0.5, t_1\right)} \end{array} \]
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* (* PI 0.5) (sqrt (* PI 0.5))))
        (t_1 (asin (- 1.0 x)))
        (t_2 (pow t_1 2.0))
        (t_3 (sqrt t_1))
        (t_4 (* t_3 t_2)))
   (/
    (+ (fma t_0 t_0 (* t_4 (- t_3))) (fma (* t_3 (- t_2)) t_3 (* t_3 t_4)))
    (+ (* (* PI PI) 0.25) (* t_1 (fma PI 0.5 t_1))))))
double code(double x) {
	return acos((1.0 - x));
}
double code(double x) {
	double t_0 = (((double) M_PI) * 0.5) * sqrt((((double) M_PI) * 0.5));
	double t_1 = asin((1.0 - x));
	double t_2 = pow(t_1, 2.0);
	double t_3 = sqrt(t_1);
	double t_4 = t_3 * t_2;
	return (fma(t_0, t_0, (t_4 * -t_3)) + fma((t_3 * -t_2), t_3, (t_3 * t_4))) / (((((double) M_PI) * ((double) M_PI)) * 0.25) + (t_1 * fma(((double) M_PI), 0.5, t_1)));
}
function code(x)
	return acos(Float64(1.0 - x))
end
function code(x)
	t_0 = Float64(Float64(pi * 0.5) * sqrt(Float64(pi * 0.5)))
	t_1 = asin(Float64(1.0 - x))
	t_2 = t_1 ^ 2.0
	t_3 = sqrt(t_1)
	t_4 = Float64(t_3 * t_2)
	return Float64(Float64(fma(t_0, t_0, Float64(t_4 * Float64(-t_3))) + fma(Float64(t_3 * Float64(-t_2)), t_3, Float64(t_3 * t_4))) / Float64(Float64(Float64(pi * pi) * 0.25) + Float64(t_1 * fma(pi, 0.5, t_1))))
end
code[x_] := N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[(Pi * 0.5), $MachinePrecision] * N[Sqrt[N[(Pi * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, 2.0], $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[t$95$1], $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 * t$95$2), $MachinePrecision]}, N[(N[(N[(t$95$0 * t$95$0 + N[(t$95$4 * (-t$95$3)), $MachinePrecision]), $MachinePrecision] + N[(N[(t$95$3 * (-t$95$2)), $MachinePrecision] * t$95$3 + N[(t$95$3 * t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(Pi * Pi), $MachinePrecision] * 0.25), $MachinePrecision] + N[(t$95$1 * N[(Pi * 0.5 + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\cos^{-1} \left(1 - x\right)
\begin{array}{l}
t_0 := \left(\pi \cdot 0.5\right) \cdot \sqrt{\pi \cdot 0.5}\\
t_1 := \sin^{-1} \left(1 - x\right)\\
t_2 := {t_1}^{2}\\
t_3 := \sqrt{t_1}\\
t_4 := t_3 \cdot t_2\\
\frac{\mathsf{fma}\left(t_0, t_0, t_4 \cdot \left(-t_3\right)\right) + \mathsf{fma}\left(t_3 \cdot \left(-t_2\right), t_3, t_3 \cdot t_4\right)}{\left(\pi \cdot \pi\right) \cdot 0.25 + t_1 \cdot \mathsf{fma}\left(\pi, 0.5, t_1\right)}
\end{array}

Error

Target

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

Derivation

  1. Initial program 59.6

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

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

    \[\leadsto \color{blue}{\frac{{\left(\pi \cdot 0.5\right)}^{3} - {\sin^{-1} \left(1 - x\right)}^{3}}{\left(\pi \cdot \pi\right) \cdot 0.25 + \sin^{-1} \left(1 - x\right) \cdot \mathsf{fma}\left(\pi, 0.5, \sin^{-1} \left(1 - x\right)\right)}} \]
    Proof
    (/.f64 (-.f64 (pow.f64 (*.f64 (PI.f64) 1/2) 3) (pow.f64 (asin.f64 (-.f64 1 x)) 3)) (+.f64 (*.f64 (*.f64 (PI.f64) (PI.f64)) 1/4) (*.f64 (asin.f64 (-.f64 1 x)) (fma.f64 (PI.f64) 1/2 (asin.f64 (-.f64 1 x)))))): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (pow.f64 (*.f64 (PI.f64) 1/2) 3) (pow.f64 (asin.f64 (-.f64 1 x)) 3)) (+.f64 (*.f64 (*.f64 (PI.f64) (PI.f64)) (Rewrite<= metadata-eval (*.f64 1/2 1/2))) (*.f64 (asin.f64 (-.f64 1 x)) (fma.f64 (PI.f64) 1/2 (asin.f64 (-.f64 1 x)))))): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (pow.f64 (*.f64 (PI.f64) 1/2) 3) (pow.f64 (asin.f64 (-.f64 1 x)) 3)) (+.f64 (Rewrite<= swap-sqr_binary64 (*.f64 (*.f64 (PI.f64) 1/2) (*.f64 (PI.f64) 1/2))) (*.f64 (asin.f64 (-.f64 1 x)) (fma.f64 (PI.f64) 1/2 (asin.f64 (-.f64 1 x)))))): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (pow.f64 (*.f64 (PI.f64) 1/2) 3) (pow.f64 (asin.f64 (-.f64 1 x)) 3)) (+.f64 (*.f64 (*.f64 (PI.f64) 1/2) (*.f64 (PI.f64) 1/2)) (*.f64 (asin.f64 (-.f64 1 x)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (PI.f64) 1/2) (asin.f64 (-.f64 1 x))))))): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (pow.f64 (*.f64 (PI.f64) 1/2) 3) (pow.f64 (asin.f64 (-.f64 1 x)) 3)) (+.f64 (*.f64 (*.f64 (PI.f64) 1/2) (*.f64 (PI.f64) 1/2)) (*.f64 (asin.f64 (-.f64 1 x)) (Rewrite=> +-commutative_binary64 (+.f64 (asin.f64 (-.f64 1 x)) (*.f64 (PI.f64) 1/2)))))): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (pow.f64 (*.f64 (PI.f64) 1/2) 3) (pow.f64 (asin.f64 (-.f64 1 x)) 3)) (+.f64 (*.f64 (*.f64 (PI.f64) 1/2) (*.f64 (PI.f64) 1/2)) (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (asin.f64 (-.f64 1 x)) (asin.f64 (-.f64 1 x))) (*.f64 (*.f64 (PI.f64) 1/2) (asin.f64 (-.f64 1 x))))))): 1 points increase in error, 0 points decrease in error
  4. Applied egg-rr57.3

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

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

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

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

Alternatives

Alternative 1
Error57.3
Cost136320
\[\begin{array}{l} t_0 := {\left(\pi \cdot 0.5\right)}^{1.5}\\ t_1 := \sin^{-1} \left(1 - x\right)\\ t_2 := \sqrt[3]{t_1}\\ \frac{\mathsf{fma}\left(t_0, t_0, -\mathsf{expm1}\left(\mathsf{log1p}\left({t_1}^{3}\right)\right)\right)}{\left(\pi \cdot \pi\right) \cdot 0.25 + \mathsf{fma}\left(\pi, 0.5, t_1\right) \cdot \left(t_2 \cdot {\left({\left(\sqrt[3]{t_2}\right)}^{2}\right)}^{3}\right)} \end{array} \]
Alternative 2
Error57.3
Cost91264
\[\begin{array}{l} t_0 := {\left(\pi \cdot 0.5\right)}^{1.5}\\ t_1 := \sin^{-1} \left(1 - x\right)\\ \frac{\mathsf{fma}\left(t_0, t_0, -\mathsf{expm1}\left(\mathsf{log1p}\left({t_1}^{3}\right)\right)\right)}{t_1 \cdot \left(\pi \cdot 0.5 + t_1\right) + 0.25 \cdot {\pi}^{2}} \end{array} \]
Alternative 3
Error57.3
Cost78464
\[\begin{array}{l} t_0 := {\left(\pi \cdot 0.5\right)}^{1.5}\\ t_1 := \sin^{-1} \left(1 - x\right)\\ \frac{\mathsf{fma}\left(t_0, t_0, -{t_1}^{3}\right)}{t_1 \cdot \left(\pi \cdot 0.5 + t_1\right) + 0.25 \cdot {\pi}^{2}} \end{array} \]
Alternative 4
Error57.3
Cost78144
\[\begin{array}{l} t_0 := \sin^{-1} \left(1 - x\right)\\ \frac{{\left(\pi \cdot 0.5\right)}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({t_0}^{3}\right)\right)}{\left(\pi \cdot \pi\right) \cdot 0.25 + t_0 \cdot \mathsf{fma}\left(\pi, 0.5, t_0\right)} \end{array} \]
Alternative 5
Error57.3
Cost45760
\[\begin{array}{l} t_0 := \sin^{-1} \left(1 - x\right)\\ \mathsf{fma}\left(-3 \cdot \sqrt[3]{{t_0}^{2} \cdot 0.1111111111111111}, \sqrt[3]{t_0 \cdot 0.3333333333333333}, \pi \cdot 0.5\right) \end{array} \]
Alternative 6
Error57.9
Cost19844
\[\begin{array}{l} \mathbf{if}\;x \leq 5.6 \cdot 10^{-17}:\\ \;\;\;\;\pi \cdot 0.5 + \sin^{-1} \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;1 + {\left(\sqrt[3]{\cos^{-1} \left(1 - x\right) + -1}\right)}^{3}\\ \end{array} \]
Alternative 7
Error57.3
Cost19712
\[\mathsf{fma}\left(\sin^{-1} \left(1 - x\right) \cdot 0.3333333333333333, -3, \pi \cdot 0.5\right) \]
Alternative 8
Error59.6
Cost13444
\[\begin{array}{l} \mathbf{if}\;1 - x \leq 1:\\ \;\;\;\;2 \cdot \left(-1 + \left(1 + 0.5 \cdot \left(-1 + \left(1 + \cos^{-1} \left(1 - x\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot 0.5 + \sin^{-1} \left(1 - x\right)\\ \end{array} \]
Alternative 9
Error59.6
Cost7360
\[2 \cdot \left(-1 + \left(1 + 0.5 \cdot \left(-1 + \left(1 + \cos^{-1} \left(1 - x\right)\right)\right)\right)\right) \]
Alternative 10
Error59.6
Cost6848
\[-1 + \left(1 + \cos^{-1} \left(1 - x\right)\right) \]
Alternative 11
Error59.6
Cost6592
\[\cos^{-1} \left(1 - x\right) \]

Error

Reproduce

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

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

  (acos (- 1.0 x)))