Ian Simplification

Percentage Accurate: 7.0% → 8.5%
Time: 7.0s
Alternatives: 7
Speedup: 1.1×

Specification

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

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

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 7 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} \\ \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
double code(double x) {
	return (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0))));
}
public static double code(double x) {
	return (Math.PI / 2.0) - (2.0 * Math.asin(Math.sqrt(((1.0 - x) / 2.0))));
}
def code(x):
	return (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(((1.0 - x) / 2.0))))
function code(x)
	return Float64(Float64(pi / 2.0) - Float64(2.0 * asin(sqrt(Float64(Float64(1.0 - x) / 2.0)))))
end
function tmp = code(x)
	tmp = (pi / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0))));
end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[Sqrt[N[(N[(1.0 - x), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 8.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-309}:\\ \;\;\;\;\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right), -2, 0.5 \cdot \pi\right)\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot 0.5 - 2 \cdot \sin^{-1} \left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -1e-309)
   (fma (asin (sqrt (* 0.5 (- 1.0 x)))) -2.0 (* 0.5 PI))
   (- (* PI 0.5) (* 2.0 (asin (/ (sqrt (- 1.0 x)) (sqrt 2.0)))))))
double code(double x) {
	double tmp;
	if (x <= -1e-309) {
		tmp = fma(asin(sqrt((0.5 * (1.0 - x)))), -2.0, (0.5 * ((double) M_PI)));
	} else {
		tmp = (((double) M_PI) * 0.5) - (2.0 * asin((sqrt((1.0 - x)) / sqrt(2.0))));
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= -1e-309)
		tmp = fma(asin(sqrt(Float64(0.5 * Float64(1.0 - x)))), -2.0, Float64(0.5 * pi));
	else
		tmp = Float64(Float64(pi * 0.5) - Float64(2.0 * asin(Float64(sqrt(Float64(1.0 - x)) / sqrt(2.0)))));
	end
	return tmp
end
code[x_] := If[LessEqual[x, -1e-309], N[(N[ArcSin[N[Sqrt[N[(0.5 * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * -2.0 + N[(0.5 * Pi), $MachinePrecision]), $MachinePrecision], N[(N[(Pi * 0.5), $MachinePrecision] - N[(2.0 * N[ArcSin[N[(N[Sqrt[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right), -2, 0.5 \cdot \pi\right)\\

\mathbf{else}:\\
\;\;\;\;\pi \cdot 0.5 - 2 \cdot \sin^{-1} \left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right)\\


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

    1. Initial program 7.0%

      \[\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\frac{\pi}{2} + \left(\mathsf{neg}\left(2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right)\right)} \]
      3. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right)\right) + \frac{\pi}{2}} \]
      4. lift-*.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)}\right)\right) + \frac{\pi}{2} \]
      5. *-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \cdot 2}\right)\right) + \frac{\pi}{2} \]
      6. distribute-rgt-neg-inN/A

        \[\leadsto \color{blue}{\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \cdot \left(\mathsf{neg}\left(2\right)\right)} + \frac{\pi}{2} \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right)} \]
      8. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1 - x}{2}}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right) \]
      9. div-flipN/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{\frac{2}{1 - x}}}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right) \]
      10. associate-/r/N/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2} \cdot \left(1 - x\right)}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2}} \cdot \left(1 - x\right)}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right) \]
      12. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2} \cdot \left(1 - x\right)}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right) \]
      13. metadata-eval7.0

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right), \color{blue}{-2}, \frac{\pi}{2}\right) \]
      14. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \color{blue}{\frac{\pi}{2}}\right) \]
      15. div-flipN/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \color{blue}{\frac{1}{\frac{2}{\pi}}}\right) \]
      16. associate-/r/N/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \color{blue}{\frac{1}{2} \cdot \pi}\right) \]
      17. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \color{blue}{\frac{1}{2}} \cdot \pi\right) \]
      18. lower-*.f647.0

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

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

    if -1.000000000000002e-309 < x

    1. Initial program 7.0%

      \[\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \]
    2. Step-by-step derivation
      1. lift-sqrt.f64N/A

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\sqrt{\frac{1 - x}{2}}\right)} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{\frac{1 - x}{2}}}\right) \]
      3. sqrt-divN/A

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right)} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right)} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{\color{blue}{\sqrt{1 - x}}}{\sqrt{2}}\right) \]
      6. lower-sqrt.f646.9

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

      \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right)} \]
    4. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\pi}{2}} - 2 \cdot \sin^{-1} \left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right) \]
      2. mult-flipN/A

        \[\leadsto \color{blue}{\pi \cdot \frac{1}{2}} - 2 \cdot \sin^{-1} \left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right) \]
      3. metadata-evalN/A

        \[\leadsto \pi \cdot \color{blue}{\frac{1}{2}} - 2 \cdot \sin^{-1} \left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right) \]
      4. lower-*.f646.9

        \[\leadsto \color{blue}{\pi \cdot 0.5} - 2 \cdot \sin^{-1} \left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right) \]
    5. Applied rewrites6.9%

      \[\leadsto \color{blue}{\pi \cdot 0.5} - 2 \cdot \sin^{-1} \left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 8.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \pi \cdot 0.5 - 2 \cdot \left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right)\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (- (* PI 0.5) (* 2.0 (- (* 0.5 PI) (acos (sqrt (* 0.5 (- 1.0 x))))))))
double code(double x) {
	return (((double) M_PI) * 0.5) - (2.0 * ((0.5 * ((double) M_PI)) - acos(sqrt((0.5 * (1.0 - x))))));
}
public static double code(double x) {
	return (Math.PI * 0.5) - (2.0 * ((0.5 * Math.PI) - Math.acos(Math.sqrt((0.5 * (1.0 - x))))));
}
def code(x):
	return (math.pi * 0.5) - (2.0 * ((0.5 * math.pi) - math.acos(math.sqrt((0.5 * (1.0 - x))))))
function code(x)
	return Float64(Float64(pi * 0.5) - Float64(2.0 * Float64(Float64(0.5 * pi) - acos(sqrt(Float64(0.5 * Float64(1.0 - x)))))))
end
function tmp = code(x)
	tmp = (pi * 0.5) - (2.0 * ((0.5 * pi) - acos(sqrt((0.5 * (1.0 - x))))));
end
code[x_] := N[(N[(Pi * 0.5), $MachinePrecision] - N[(2.0 * N[(N[(0.5 * Pi), $MachinePrecision] - N[ArcCos[N[Sqrt[N[(0.5 * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\pi \cdot 0.5 - 2 \cdot \left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right)\right)
\end{array}
Derivation
  1. Initial program 7.0%

    \[\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \]
  2. Step-by-step derivation
    1. lift-asin.f64N/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \color{blue}{\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)} \]
    2. asin-acosN/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} - \cos^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right)} \]
    3. lift-PI.f64N/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\frac{\color{blue}{\pi}}{2} - \cos^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right) \]
    4. lift-/.f64N/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\color{blue}{\frac{\pi}{2}} - \cos^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right) \]
    5. lower--.f64N/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \color{blue}{\left(\frac{\pi}{2} - \cos^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right)} \]
    6. lift-/.f64N/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\color{blue}{\frac{\pi}{2}} - \cos^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right) \]
    7. div-flipN/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\color{blue}{\frac{1}{\frac{2}{\pi}}} - \cos^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right) \]
    8. associate-/r/N/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\color{blue}{\frac{1}{2} \cdot \pi} - \cos^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right) \]
    9. metadata-evalN/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\color{blue}{\frac{1}{2}} \cdot \pi - \cos^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right) \]
    10. lower-*.f64N/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\color{blue}{\frac{1}{2} \cdot \pi} - \cos^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right) \]
    11. lower-acos.f648.5

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(0.5 \cdot \pi - \color{blue}{\cos^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)}\right) \]
    12. lift-/.f64N/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\frac{1}{2} \cdot \pi - \cos^{-1} \left(\sqrt{\color{blue}{\frac{1 - x}{2}}}\right)\right) \]
    13. div-flipN/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\frac{1}{2} \cdot \pi - \cos^{-1} \left(\sqrt{\color{blue}{\frac{1}{\frac{2}{1 - x}}}}\right)\right) \]
    14. associate-/r/N/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\frac{1}{2} \cdot \pi - \cos^{-1} \left(\sqrt{\color{blue}{\frac{1}{2} \cdot \left(1 - x\right)}}\right)\right) \]
    15. metadata-evalN/A

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(\frac{1}{2} \cdot \pi - \cos^{-1} \left(\sqrt{\color{blue}{\frac{1}{2}} \cdot \left(1 - x\right)}\right)\right) \]
    16. lower-*.f648.5

      \[\leadsto \frac{\pi}{2} - 2 \cdot \left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{\color{blue}{0.5 \cdot \left(1 - x\right)}}\right)\right) \]
  3. Applied rewrites8.5%

    \[\leadsto \frac{\pi}{2} - 2 \cdot \color{blue}{\left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right)\right)} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{\pi}{2}} - 2 \cdot \left(\frac{1}{2} \cdot \pi - \cos^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right)\right) \]
    2. mult-flipN/A

      \[\leadsto \color{blue}{\pi \cdot \frac{1}{2}} - 2 \cdot \left(\frac{1}{2} \cdot \pi - \cos^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right)\right) \]
    3. metadata-evalN/A

      \[\leadsto \pi \cdot \color{blue}{\frac{1}{2}} - 2 \cdot \left(\frac{1}{2} \cdot \pi - \cos^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right)\right) \]
    4. lower-*.f648.5

      \[\leadsto \color{blue}{\pi \cdot 0.5} - 2 \cdot \left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right)\right) \]
  5. Applied rewrites8.5%

    \[\leadsto \color{blue}{\pi \cdot 0.5} - 2 \cdot \left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right)\right) \]
  6. Add Preprocessing

Alternative 3: 7.0% accurate, 1.1× speedup?

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

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

    \[\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \]
  2. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)} \]
    2. sub-flipN/A

      \[\leadsto \color{blue}{\frac{\pi}{2} + \left(\mathsf{neg}\left(2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right)\right)} \]
    3. +-commutativeN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\right)\right) + \frac{\pi}{2}} \]
    4. lift-*.f64N/A

      \[\leadsto \left(\mathsf{neg}\left(\color{blue}{2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)}\right)\right) + \frac{\pi}{2} \]
    5. *-commutativeN/A

      \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \cdot 2}\right)\right) + \frac{\pi}{2} \]
    6. distribute-rgt-neg-inN/A

      \[\leadsto \color{blue}{\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \cdot \left(\mathsf{neg}\left(2\right)\right)} + \frac{\pi}{2} \]
    7. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right)} \]
    8. lift-/.f64N/A

      \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1 - x}{2}}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right) \]
    9. div-flipN/A

      \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{\frac{2}{1 - x}}}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right) \]
    10. associate-/r/N/A

      \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2} \cdot \left(1 - x\right)}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right) \]
    11. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2}} \cdot \left(1 - x\right)}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right) \]
    12. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2} \cdot \left(1 - x\right)}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right) \]
    13. metadata-eval7.0

      \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right), \color{blue}{-2}, \frac{\pi}{2}\right) \]
    14. lift-/.f64N/A

      \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \color{blue}{\frac{\pi}{2}}\right) \]
    15. div-flipN/A

      \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \color{blue}{\frac{1}{\frac{2}{\pi}}}\right) \]
    16. associate-/r/N/A

      \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \color{blue}{\frac{1}{2} \cdot \pi}\right) \]
    17. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \color{blue}{\frac{1}{2}} \cdot \pi\right) \]
    18. lower-*.f647.0

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

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

Alternative 4: 5.9% accurate, 0.9× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{1}{\sqrt{2}}\right)\\


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

    1. Initial program 7.0%

      \[\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2}}}\right) \]
    3. Step-by-step derivation
      1. Applied rewrites4.1%

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{0.5}}\right) \]
      2. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \color{blue}{\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)} \]
        2. lift-*.f64N/A

          \[\leadsto \frac{\pi}{2} - \color{blue}{2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)} \]
        3. count-2-revN/A

          \[\leadsto \frac{\pi}{2} - \color{blue}{\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right) + \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right)} \]
        4. associate--r+N/A

          \[\leadsto \color{blue}{\left(\frac{\pi}{2} - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right) - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)} \]
        5. lift-/.f64N/A

          \[\leadsto \left(\color{blue}{\frac{\pi}{2}} - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right) - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \]
        6. lift-PI.f64N/A

          \[\leadsto \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{2} - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right) - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \]
        7. lift-asin.f64N/A

          \[\leadsto \left(\frac{\mathsf{PI}\left(\right)}{2} - \color{blue}{\sin^{-1} \left(\sqrt{\frac{1}{2}}\right)}\right) - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \]
        8. acos-asinN/A

          \[\leadsto \color{blue}{\cos^{-1} \left(\sqrt{\frac{1}{2}}\right)} - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \]
        9. lower--.f64N/A

          \[\leadsto \color{blue}{\cos^{-1} \left(\sqrt{\frac{1}{2}}\right) - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)} \]
        10. lower-acos.f644.1

          \[\leadsto \color{blue}{\cos^{-1} \left(\sqrt{0.5}\right)} - \sin^{-1} \left(\sqrt{0.5}\right) \]
      3. Applied rewrites4.1%

        \[\leadsto \color{blue}{\cos^{-1} \left(\sqrt{0.5}\right) - \sin^{-1} \left(\sqrt{0.5}\right)} \]

      if 9.9999999999999991e-309 < x

      1. Initial program 7.0%

        \[\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \]
      2. Step-by-step derivation
        1. lift-sqrt.f64N/A

          \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\sqrt{\frac{1 - x}{2}}\right)} \]
        2. lift-/.f64N/A

          \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{\frac{1 - x}{2}}}\right) \]
        3. sqrt-divN/A

          \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right)} \]
        4. lower-/.f64N/A

          \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right)} \]
        5. lower-sqrt.f64N/A

          \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{\color{blue}{\sqrt{1 - x}}}{\sqrt{2}}\right) \]
        6. lower-sqrt.f646.9

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

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right)} \]
      4. Taylor expanded in x around 0

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{1}{\sqrt{2}}\right)} \]
      5. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{1}{\color{blue}{\sqrt{2}}}\right) \]
        2. lower-sqrt.f644.1

          \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{1}{\sqrt{2}}\right) \]
      6. Applied rewrites4.1%

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{1}{\sqrt{2}}\right)} \]
    4. Recombined 2 regimes into one program.
    5. Add Preprocessing

    Alternative 5: 5.3% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \mathsf{fma}\left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{0.5}\right), -2, 0.5 \cdot \pi\right) \end{array} \]
    (FPCore (x)
     :precision binary64
     (fma (- (* 0.5 PI) (acos (sqrt 0.5))) -2.0 (* 0.5 PI)))
    double code(double x) {
    	return fma(((0.5 * ((double) M_PI)) - acos(sqrt(0.5))), -2.0, (0.5 * ((double) M_PI)));
    }
    
    function code(x)
    	return fma(Float64(Float64(0.5 * pi) - acos(sqrt(0.5))), -2.0, Float64(0.5 * pi))
    end
    
    code[x_] := N[(N[(N[(0.5 * Pi), $MachinePrecision] - N[ArcCos[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -2.0 + N[(0.5 * Pi), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \mathsf{fma}\left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{0.5}\right), -2, 0.5 \cdot \pi\right)
    \end{array}
    
    Derivation
    1. Initial program 7.0%

      \[\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2}}}\right) \]
    3. Step-by-step derivation
      1. Applied rewrites4.1%

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{0.5}}\right) \]
      2. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \color{blue}{\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)} \]
        2. sub-flipN/A

          \[\leadsto \color{blue}{\frac{\pi}{2} + \left(\mathsf{neg}\left(2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right)\right)} \]
        3. +-commutativeN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right)\right) + \frac{\pi}{2}} \]
        4. lift-*.f64N/A

          \[\leadsto \left(\mathsf{neg}\left(\color{blue}{2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)}\right)\right) + \frac{\pi}{2} \]
        5. *-commutativeN/A

          \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \cdot 2}\right)\right) + \frac{\pi}{2} \]
        6. distribute-rgt-neg-inN/A

          \[\leadsto \color{blue}{\sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \cdot \left(\mathsf{neg}\left(2\right)\right)} + \frac{\pi}{2} \]
        7. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right)} \]
        8. metadata-eval4.1

          \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5}\right), \color{blue}{-2}, \frac{\pi}{2}\right) \]
        9. lift-/.f64N/A

          \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \color{blue}{\frac{\pi}{2}}\right) \]
        10. mult-flipN/A

          \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \color{blue}{\pi \cdot \frac{1}{2}}\right) \]
        11. metadata-evalN/A

          \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \pi \cdot \color{blue}{\frac{1}{2}}\right) \]
        12. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \color{blue}{\frac{1}{2} \cdot \pi}\right) \]
        13. lift-*.f644.1

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5}\right), -2, 0.5 \cdot \pi\right)} \]
      4. Step-by-step derivation
        1. lift-asin.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\sin^{-1} \left(\sqrt{\frac{1}{2}}\right)}, -2, \frac{1}{2} \cdot \pi\right) \]
        2. asin-acosN/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\mathsf{PI}\left(\right)}{2} - \cos^{-1} \left(\sqrt{\frac{1}{2}}\right)}, -2, \frac{1}{2} \cdot \pi\right) \]
        3. lift-PI.f64N/A

          \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\pi}}{2} - \cos^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \frac{1}{2} \cdot \pi\right) \]
        4. mult-flip-revN/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\pi \cdot \frac{1}{2}} - \cos^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \frac{1}{2} \cdot \pi\right) \]
        5. metadata-evalN/A

          \[\leadsto \mathsf{fma}\left(\pi \cdot \color{blue}{\frac{1}{2}} - \cos^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \frac{1}{2} \cdot \pi\right) \]
        6. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{2} \cdot \pi} - \cos^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \frac{1}{2} \cdot \pi\right) \]
        7. lift-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{2} \cdot \pi} - \cos^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \frac{1}{2} \cdot \pi\right) \]
        8. lower--.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{2} \cdot \pi - \cos^{-1} \left(\sqrt{\frac{1}{2}}\right)}, -2, \frac{1}{2} \cdot \pi\right) \]
        9. lower-acos.f645.3

          \[\leadsto \mathsf{fma}\left(0.5 \cdot \pi - \color{blue}{\cos^{-1} \left(\sqrt{0.5}\right)}, -2, 0.5 \cdot \pi\right) \]
      5. Applied rewrites5.3%

        \[\leadsto \mathsf{fma}\left(\color{blue}{0.5 \cdot \pi - \cos^{-1} \left(\sqrt{0.5}\right)}, -2, 0.5 \cdot \pi\right) \]
      6. Add Preprocessing

      Alternative 6: 4.1% accurate, 1.4× speedup?

      \[\begin{array}{l} \\ \cos^{-1} \left(\sqrt{0.5}\right) - \sin^{-1} \left(\sqrt{0.5}\right) \end{array} \]
      (FPCore (x) :precision binary64 (- (acos (sqrt 0.5)) (asin (sqrt 0.5))))
      double code(double x) {
      	return acos(sqrt(0.5)) - asin(sqrt(0.5));
      }
      
      module fmin_fmax_functions
          implicit none
          private
          public fmax
          public fmin
      
          interface fmax
              module procedure fmax88
              module procedure fmax44
              module procedure fmax84
              module procedure fmax48
          end interface
          interface fmin
              module procedure fmin88
              module procedure fmin44
              module procedure fmin84
              module procedure fmin48
          end interface
      contains
          real(8) function fmax88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(4) function fmax44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(8) function fmax84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmax48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
          end function
          real(8) function fmin88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(4) function fmin44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(8) function fmin84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmin48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
          end function
      end module
      
      real(8) function code(x)
      use fmin_fmax_functions
          real(8), intent (in) :: x
          code = acos(sqrt(0.5d0)) - asin(sqrt(0.5d0))
      end function
      
      public static double code(double x) {
      	return Math.acos(Math.sqrt(0.5)) - Math.asin(Math.sqrt(0.5));
      }
      
      def code(x):
      	return math.acos(math.sqrt(0.5)) - math.asin(math.sqrt(0.5))
      
      function code(x)
      	return Float64(acos(sqrt(0.5)) - asin(sqrt(0.5)))
      end
      
      function tmp = code(x)
      	tmp = acos(sqrt(0.5)) - asin(sqrt(0.5));
      end
      
      code[x_] := N[(N[ArcCos[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision] - N[ArcSin[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \cos^{-1} \left(\sqrt{0.5}\right) - \sin^{-1} \left(\sqrt{0.5}\right)
      \end{array}
      
      Derivation
      1. Initial program 7.0%

        \[\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \]
      2. Taylor expanded in x around 0

        \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2}}}\right) \]
      3. Step-by-step derivation
        1. Applied rewrites4.1%

          \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{0.5}}\right) \]
        2. Step-by-step derivation
          1. lift--.f64N/A

            \[\leadsto \color{blue}{\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)} \]
          2. lift-*.f64N/A

            \[\leadsto \frac{\pi}{2} - \color{blue}{2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)} \]
          3. count-2-revN/A

            \[\leadsto \frac{\pi}{2} - \color{blue}{\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right) + \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right)} \]
          4. associate--r+N/A

            \[\leadsto \color{blue}{\left(\frac{\pi}{2} - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right) - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)} \]
          5. lift-/.f64N/A

            \[\leadsto \left(\color{blue}{\frac{\pi}{2}} - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right) - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \]
          6. lift-PI.f64N/A

            \[\leadsto \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{2} - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right) - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \]
          7. lift-asin.f64N/A

            \[\leadsto \left(\frac{\mathsf{PI}\left(\right)}{2} - \color{blue}{\sin^{-1} \left(\sqrt{\frac{1}{2}}\right)}\right) - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \]
          8. acos-asinN/A

            \[\leadsto \color{blue}{\cos^{-1} \left(\sqrt{\frac{1}{2}}\right)} - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \]
          9. lower--.f64N/A

            \[\leadsto \color{blue}{\cos^{-1} \left(\sqrt{\frac{1}{2}}\right) - \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)} \]
          10. lower-acos.f644.1

            \[\leadsto \color{blue}{\cos^{-1} \left(\sqrt{0.5}\right)} - \sin^{-1} \left(\sqrt{0.5}\right) \]
        3. Applied rewrites4.1%

          \[\leadsto \color{blue}{\cos^{-1} \left(\sqrt{0.5}\right) - \sin^{-1} \left(\sqrt{0.5}\right)} \]
        4. Add Preprocessing

        Alternative 7: 4.1% accurate, 1.5× speedup?

        \[\begin{array}{l} \\ \mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5}\right), -2, 0.5 \cdot \pi\right) \end{array} \]
        (FPCore (x) :precision binary64 (fma (asin (sqrt 0.5)) -2.0 (* 0.5 PI)))
        double code(double x) {
        	return fma(asin(sqrt(0.5)), -2.0, (0.5 * ((double) M_PI)));
        }
        
        function code(x)
        	return fma(asin(sqrt(0.5)), -2.0, Float64(0.5 * pi))
        end
        
        code[x_] := N[(N[ArcSin[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision] * -2.0 + N[(0.5 * Pi), $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5}\right), -2, 0.5 \cdot \pi\right)
        \end{array}
        
        Derivation
        1. Initial program 7.0%

          \[\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \]
        2. Taylor expanded in x around 0

          \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{\frac{1}{2}}}\right) \]
        3. Step-by-step derivation
          1. Applied rewrites4.1%

            \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{0.5}}\right) \]
          2. Step-by-step derivation
            1. lift--.f64N/A

              \[\leadsto \color{blue}{\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)} \]
            2. sub-flipN/A

              \[\leadsto \color{blue}{\frac{\pi}{2} + \left(\mathsf{neg}\left(2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right)\right)} \]
            3. +-commutativeN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)\right)\right) + \frac{\pi}{2}} \]
            4. lift-*.f64N/A

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{2 \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right)}\right)\right) + \frac{\pi}{2} \]
            5. *-commutativeN/A

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \cdot 2}\right)\right) + \frac{\pi}{2} \]
            6. distribute-rgt-neg-inN/A

              \[\leadsto \color{blue}{\sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \cdot \left(\mathsf{neg}\left(2\right)\right)} + \frac{\pi}{2} \]
            7. lower-fma.f64N/A

              \[\leadsto \color{blue}{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), \mathsf{neg}\left(2\right), \frac{\pi}{2}\right)} \]
            8. metadata-eval4.1

              \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5}\right), \color{blue}{-2}, \frac{\pi}{2}\right) \]
            9. lift-/.f64N/A

              \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \color{blue}{\frac{\pi}{2}}\right) \]
            10. mult-flipN/A

              \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \color{blue}{\pi \cdot \frac{1}{2}}\right) \]
            11. metadata-evalN/A

              \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \pi \cdot \color{blue}{\frac{1}{2}}\right) \]
            12. *-commutativeN/A

              \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \color{blue}{\frac{1}{2} \cdot \pi}\right) \]
            13. lift-*.f644.1

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

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

          Reproduce

          ?
          herbie shell --seed 2025156 
          (FPCore (x)
            :name "Ian Simplification"
            :precision binary64
            (- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))