Ian Simplification

Percentage Accurate: 6.8% → 8.2%
Time: 5.8s
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: 6.8% 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.2% accurate, 0.4× speedup?

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

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

    \[\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. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\frac{\sin^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right)}{\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right)}}\right)\right) + 1\right) \cdot \cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right) \]
    5. mult-flipN/A

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sin^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right), \mathsf{neg}\left(\frac{1}{\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right)}\right), 1\right)} \cdot \cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right) \]
  5. Applied rewrites6.8%

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{\mathsf{PI}\left(\right)}{2} - \color{blue}{\cos^{-1} \left(\sqrt{\mathsf{fma}\left(\frac{-1}{2}, x, \frac{1}{2}\right)}\right)}, -\frac{1}{\cos^{-1} \left(\sqrt{\mathsf{fma}\left(\frac{-1}{2}, x, \frac{1}{2}\right)}\right)}, 1\right) \cdot \cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right) \]
    4. sub-to-multN/A

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(1 - \frac{\cos^{-1} \left(\sqrt{\mathsf{fma}\left(\frac{-1}{2}, x, \frac{1}{2}\right)}\right)}{\frac{\mathsf{PI}\left(\right)}{2}}\right) \cdot \left(\frac{1}{2} \cdot \pi\right)}, -\frac{1}{\cos^{-1} \left(\sqrt{\mathsf{fma}\left(\frac{-1}{2}, x, \frac{1}{2}\right)}\right)}, 1\right) \cdot \cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right) \]
  7. Applied rewrites6.8%

    \[\leadsto \mathsf{fma}\left(\color{blue}{\left(1 - \frac{\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right)}{\pi \cdot 0.5}\right) \cdot \left(\pi \cdot 0.5\right)}, -\frac{1}{\cos^{-1} \left(\sqrt{\mathsf{fma}\left(-0.5, x, 0.5\right)}\right)}, 1\right) \cdot \cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right) \]
  8. Taylor expanded in x around inf

    \[\leadsto \color{blue}{\left(1 + \frac{-1}{2} \cdot \frac{\mathsf{PI}\left(\right) \cdot \left(1 - 2 \cdot \frac{\cos^{-1} \left(\sqrt{\frac{1}{2} - \frac{1}{2} \cdot x}\right)}{\mathsf{PI}\left(\right)}\right)}{\cos^{-1} \left(\sqrt{\frac{1}{2} - \frac{1}{2} \cdot x}\right)}\right)} \cdot \cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right) \]
  9. Step-by-step derivation
    1. lower-+.f64N/A

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

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

      \[\leadsto \left(1 + \frac{-1}{2} \cdot \frac{\mathsf{PI}\left(\right) \cdot \left(1 - 2 \cdot \frac{\cos^{-1} \left(\sqrt{\frac{1}{2} - \frac{1}{2} \cdot x}\right)}{\mathsf{PI}\left(\right)}\right)}{\color{blue}{\cos^{-1} \left(\sqrt{\frac{1}{2} - \frac{1}{2} \cdot x}\right)}}\right) \cdot \cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right) \]
  10. Applied rewrites8.2%

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

Alternative 2: 8.2% accurate, 0.7× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(1 - \frac{\left(-\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right)\right) \cdot 2}{\frac{\pi}{2} - \pi}\right) \cdot \left(\frac{\pi}{2} - \pi\right)} \]
  4. Applied rewrites8.2%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(1 - \frac{\cos^{-1} \left(\sqrt{\mathsf{fma}\left(\frac{-1}{2}, x, \frac{1}{2}\right)}\right) \cdot -2}{\frac{1}{2} \cdot \pi - \pi}\right) \cdot \left(\frac{1}{2} \cdot \pi - \pi\right)} \]
  6. Applied rewrites8.2%

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

Alternative 3: 8.2% accurate, 1.0× speedup?

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \pi} - \left(\pi + \left(-\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right)\right) \cdot 2\right) \]
    5. lift-*.f648.2

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \pi - \left(\color{blue}{\left(\mathsf{neg}\left(\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right)\right)\right)} \cdot 2 + \pi\right) \]
    10. distribute-lft-neg-outN/A

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

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \pi - \mathsf{fma}\left(\cos^{-1} \left(\sqrt{\color{blue}{\mathsf{fma}\left(\frac{-1}{2}, x, \frac{1}{2}\right)}}\right), \mathsf{neg}\left(2\right), \pi\right) \]
    16. metadata-eval8.2

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

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

Alternative 4: 6.8% accurate, 1.1× speedup?

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

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

    \[\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. lift-*.f64N/A

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

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

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

      \[\leadsto \color{blue}{\sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right) \cdot \left(\mathsf{neg}\left(2\right)\right)} + \frac{\pi}{2} \]
    6. 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)} \]
  3. Applied rewrites6.8%

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

Alternative 5: 5.3% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{\pi}{2} - \left(-\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right)\right) \cdot 2\right) - \pi} \]
  4. Applied rewrites8.1%

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

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

      \[\leadsto \left(0.5 \cdot \pi - \cos^{-1} \left(\sqrt{\color{blue}{0.5}}\right) \cdot -2\right) - \pi \]
    2. 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 6.8%

      \[\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 6.8%

        \[\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. fp-cancel-sub-sign-invN/A

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

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

            \[\leadsto \color{blue}{\sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \cdot \left(\mathsf{neg}\left(2\right)\right)} + \frac{\pi}{2} \]
          6. 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)} \]
          7. metadata-eval4.1

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2}}\right), -2, \color{blue}{\frac{1}{2} \cdot \pi}\right) \]
          12. 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 2025159 
        (FPCore (x)
          :name "Ian Simplification"
          :precision binary64
          (- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))