bug323 (missed optimization)

Percentage Accurate: 6.9% → 10.4%
Time: 4.0s
Alternatives: 11
Speedup: 1.3×

Specification

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

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

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 11 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.9% accurate, 1.0× speedup?

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

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

Alternative 1: 10.4% accurate, 0.1× speedup?

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

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

    \[\cos^{-1} \left(1 - x\right) \]
  2. Step-by-step derivation
    1. lift-acos.f64N/A

      \[\leadsto \color{blue}{\cos^{-1} \left(1 - x\right)} \]
    2. acos-asinN/A

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

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

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}} \]
    5. sum-to-multN/A

      \[\leadsto \color{blue}{\left(1 + \frac{\frac{\mathsf{PI}\left(\right)}{2}}{\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right)} \]
    6. lower-unsound-*.f64N/A

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

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

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

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

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

      \[\leadsto \left(1 + \frac{\color{blue}{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}}{\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) \]
    12. metadata-evalN/A

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

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

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

      \[\leadsto \left(1 + \frac{\frac{1}{2} \cdot \pi}{\sin^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(1 - x\right)}\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) \]
    16. sub-negate-revN/A

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

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

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

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

      \[\leadsto \left(1 + \frac{\frac{1}{2} \cdot \pi}{\sin^{-1} \left(x - 1\right)}\right) \cdot \sin^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(1 - x\right)}\right)\right) \]
    21. sub-negate-revN/A

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\frac{\sin^{-1} \left(x - 1\right)}{\sin^{-1} \left(x - 1\right)} + \frac{\mathsf{neg}\left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{2}\right)}{\mathsf{neg}\left(\sin^{-1} \left(x - 1\right)\right)}\right) \cdot \sin^{-1} \left(x - 1\right) \]
    12. common-denominatorN/A

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

      \[\leadsto \color{blue}{\frac{\sin^{-1} \left(x - 1\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(x - 1\right)\right)\right) + \left(\mathsf{neg}\left(\frac{\mathsf{PI}\left(\right)}{2}\right)\right) \cdot \sin^{-1} \left(x - 1\right)}{\sin^{-1} \left(x - 1\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(x - 1\right)\right)\right)}} \cdot \sin^{-1} \left(x - 1\right) \]
  5. Applied rewrites10.4%

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

Alternative 2: 10.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(1 - x\right)\\ \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;\mathsf{fma}\left(\frac{0.5}{\sin^{-1} -1}, \pi, 1\right) \cdot \sin^{-1} -1\\ \mathbf{else}:\\ \;\;\;\;\pi - \frac{\pi \cdot \pi - t\_0 \cdot \pi}{\pi}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (acos (- 1.0 x))))
   (if (<= t_0 0.0)
     (* (fma (/ 0.5 (asin -1.0)) PI 1.0) (asin -1.0))
     (- PI (/ (- (* PI PI) (* t_0 PI)) PI)))))
double code(double x) {
	double t_0 = acos((1.0 - x));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = fma((0.5 / asin(-1.0)), ((double) M_PI), 1.0) * asin(-1.0);
	} else {
		tmp = ((double) M_PI) - (((((double) M_PI) * ((double) M_PI)) - (t_0 * ((double) M_PI))) / ((double) M_PI));
	}
	return tmp;
}
function code(x)
	t_0 = acos(Float64(1.0 - x))
	tmp = 0.0
	if (t_0 <= 0.0)
		tmp = Float64(fma(Float64(0.5 / asin(-1.0)), pi, 1.0) * asin(-1.0));
	else
		tmp = Float64(pi - Float64(Float64(Float64(pi * pi) - Float64(t_0 * pi)) / pi));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(N[(0.5 / N[ArcSin[-1.0], $MachinePrecision]), $MachinePrecision] * Pi + 1.0), $MachinePrecision] * N[ArcSin[-1.0], $MachinePrecision]), $MachinePrecision], N[(Pi - N[(N[(N[(Pi * Pi), $MachinePrecision] - N[(t$95$0 * Pi), $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(\frac{0.5}{\sin^{-1} -1}, \pi, 1\right) \cdot \sin^{-1} -1\\

\mathbf{else}:\\
\;\;\;\;\pi - \frac{\pi \cdot \pi - t\_0 \cdot \pi}{\pi}\\


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

    1. Initial program 6.9%

      \[\cos^{-1} \left(1 - x\right) \]
    2. Step-by-step derivation
      1. lift-acos.f64N/A

        \[\leadsto \color{blue}{\cos^{-1} \left(1 - x\right)} \]
      2. acos-asinN/A

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

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

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}} \]
      5. sum-to-multN/A

        \[\leadsto \color{blue}{\left(1 + \frac{\frac{\mathsf{PI}\left(\right)}{2}}{\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right)} \]
      6. lower-unsound-*.f64N/A

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

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

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

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

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

        \[\leadsto \left(1 + \frac{\color{blue}{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}}{\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) \]
      12. metadata-evalN/A

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

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

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

        \[\leadsto \left(1 + \frac{\frac{1}{2} \cdot \pi}{\sin^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(1 - x\right)}\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) \]
      16. sub-negate-revN/A

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

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

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

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

        \[\leadsto \left(1 + \frac{\frac{1}{2} \cdot \pi}{\sin^{-1} \left(x - 1\right)}\right) \cdot \sin^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(1 - x\right)}\right)\right) \]
      21. sub-negate-revN/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{\sin^{-1} \left(x - 1\right)}{\sin^{-1} \left(x - 1\right)} + \frac{\mathsf{neg}\left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{2}\right)}{\mathsf{neg}\left(\sin^{-1} \left(x - 1\right)\right)}\right) \cdot \sin^{-1} \left(x - 1\right) \]
      12. common-denominatorN/A

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

        \[\leadsto \color{blue}{\frac{\sin^{-1} \left(x - 1\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(x - 1\right)\right)\right) + \left(\mathsf{neg}\left(\frac{\mathsf{PI}\left(\right)}{2}\right)\right) \cdot \sin^{-1} \left(x - 1\right)}{\sin^{-1} \left(x - 1\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(x - 1\right)\right)\right)}} \cdot \sin^{-1} \left(x - 1\right) \]
    5. Applied rewrites10.4%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\sin^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \left(-0.5 \cdot \pi\right) \cdot \sin^{-1} \left(x - 1\right)\right)}{\sin^{-1} \left(x - 1\right) \cdot \sin^{-1} \left(1 - x\right)}} \cdot \sin^{-1} \left(x - 1\right) \]
    6. Step-by-step derivation
      1. Applied rewrites10.3%

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

        \[\leadsto \mathsf{fma}\left(\frac{\frac{1}{2}}{\sin^{-1} \color{blue}{-1}}, \pi, 1\right) \cdot \sin^{-1} \left(x - 1\right) \]
      3. Step-by-step derivation
        1. Applied rewrites7.7%

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

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

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

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

          1. Initial program 6.9%

            \[\cos^{-1} \left(1 - x\right) \]
          2. Step-by-step derivation
            1. lift-acos.f64N/A

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

              \[\leadsto \cos^{-1} \color{blue}{\left(1 - x\right)} \]
            3. sub-negate-revN/A

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

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

              \[\leadsto \color{blue}{\mathsf{PI}\left(\right) - \cos^{-1} \left(x - 1\right)} \]
            6. lower-PI.f64N/A

              \[\leadsto \color{blue}{\pi} - \cos^{-1} \left(x - 1\right) \]
            7. lower-acos.f64N/A

              \[\leadsto \pi - \color{blue}{\cos^{-1} \left(x - 1\right)} \]
            8. lower--.f646.9

              \[\leadsto \pi - \cos^{-1} \color{blue}{\left(x - 1\right)} \]
          3. Applied rewrites6.9%

            \[\leadsto \color{blue}{\pi - \cos^{-1} \left(x - 1\right)} \]
          4. Applied rewrites6.9%

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

        Alternative 3: 10.3% accurate, 0.2× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(1 - x\right)\\ \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;\mathsf{fma}\left(\frac{0.5}{\sin^{-1} -1}, \pi, 1\right) \cdot \sin^{-1} -1\\ \mathbf{else}:\\ \;\;\;\;\pi - \left(1 - \frac{t\_0}{\pi}\right) \cdot \pi\\ \end{array} \end{array} \]
        (FPCore (x)
         :precision binary64
         (let* ((t_0 (acos (- 1.0 x))))
           (if (<= t_0 0.0)
             (* (fma (/ 0.5 (asin -1.0)) PI 1.0) (asin -1.0))
             (- PI (* (- 1.0 (/ t_0 PI)) PI)))))
        double code(double x) {
        	double t_0 = acos((1.0 - x));
        	double tmp;
        	if (t_0 <= 0.0) {
        		tmp = fma((0.5 / asin(-1.0)), ((double) M_PI), 1.0) * asin(-1.0);
        	} else {
        		tmp = ((double) M_PI) - ((1.0 - (t_0 / ((double) M_PI))) * ((double) M_PI));
        	}
        	return tmp;
        }
        
        function code(x)
        	t_0 = acos(Float64(1.0 - x))
        	tmp = 0.0
        	if (t_0 <= 0.0)
        		tmp = Float64(fma(Float64(0.5 / asin(-1.0)), pi, 1.0) * asin(-1.0));
        	else
        		tmp = Float64(pi - Float64(Float64(1.0 - Float64(t_0 / pi)) * pi));
        	end
        	return tmp
        end
        
        code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(N[(0.5 / N[ArcSin[-1.0], $MachinePrecision]), $MachinePrecision] * Pi + 1.0), $MachinePrecision] * N[ArcSin[-1.0], $MachinePrecision]), $MachinePrecision], N[(Pi - N[(N[(1.0 - N[(t$95$0 / Pi), $MachinePrecision]), $MachinePrecision] * Pi), $MachinePrecision]), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \cos^{-1} \left(1 - x\right)\\
        \mathbf{if}\;t\_0 \leq 0:\\
        \;\;\;\;\mathsf{fma}\left(\frac{0.5}{\sin^{-1} -1}, \pi, 1\right) \cdot \sin^{-1} -1\\
        
        \mathbf{else}:\\
        \;\;\;\;\pi - \left(1 - \frac{t\_0}{\pi}\right) \cdot \pi\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (acos.f64 (-.f64 #s(literal 1 binary64) x)) < 0.0

          1. Initial program 6.9%

            \[\cos^{-1} \left(1 - x\right) \]
          2. Step-by-step derivation
            1. lift-acos.f64N/A

              \[\leadsto \color{blue}{\cos^{-1} \left(1 - x\right)} \]
            2. acos-asinN/A

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

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

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}} \]
            5. sum-to-multN/A

              \[\leadsto \color{blue}{\left(1 + \frac{\frac{\mathsf{PI}\left(\right)}{2}}{\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right)} \]
            6. lower-unsound-*.f64N/A

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

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

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

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

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

              \[\leadsto \left(1 + \frac{\color{blue}{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}}{\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) \]
            12. metadata-evalN/A

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

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

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

              \[\leadsto \left(1 + \frac{\frac{1}{2} \cdot \pi}{\sin^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(1 - x\right)}\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) \]
            16. sub-negate-revN/A

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

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

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

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

              \[\leadsto \left(1 + \frac{\frac{1}{2} \cdot \pi}{\sin^{-1} \left(x - 1\right)}\right) \cdot \sin^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(1 - x\right)}\right)\right) \]
            21. sub-negate-revN/A

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \left(\frac{\sin^{-1} \left(x - 1\right)}{\sin^{-1} \left(x - 1\right)} + \frac{\mathsf{neg}\left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{2}\right)}{\mathsf{neg}\left(\sin^{-1} \left(x - 1\right)\right)}\right) \cdot \sin^{-1} \left(x - 1\right) \]
            12. common-denominatorN/A

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

              \[\leadsto \color{blue}{\frac{\sin^{-1} \left(x - 1\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(x - 1\right)\right)\right) + \left(\mathsf{neg}\left(\frac{\mathsf{PI}\left(\right)}{2}\right)\right) \cdot \sin^{-1} \left(x - 1\right)}{\sin^{-1} \left(x - 1\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(x - 1\right)\right)\right)}} \cdot \sin^{-1} \left(x - 1\right) \]
          5. Applied rewrites10.4%

            \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\sin^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \left(-0.5 \cdot \pi\right) \cdot \sin^{-1} \left(x - 1\right)\right)}{\sin^{-1} \left(x - 1\right) \cdot \sin^{-1} \left(1 - x\right)}} \cdot \sin^{-1} \left(x - 1\right) \]
          6. Step-by-step derivation
            1. Applied rewrites10.3%

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

              \[\leadsto \mathsf{fma}\left(\frac{\frac{1}{2}}{\sin^{-1} \color{blue}{-1}}, \pi, 1\right) \cdot \sin^{-1} \left(x - 1\right) \]
            3. Step-by-step derivation
              1. Applied rewrites7.7%

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

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

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

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

                1. Initial program 6.9%

                  \[\cos^{-1} \left(1 - x\right) \]
                2. Step-by-step derivation
                  1. lift-acos.f64N/A

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

                    \[\leadsto \cos^{-1} \color{blue}{\left(1 - x\right)} \]
                  3. sub-negate-revN/A

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

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

                    \[\leadsto \color{blue}{\mathsf{PI}\left(\right) - \cos^{-1} \left(x - 1\right)} \]
                  6. lower-PI.f64N/A

                    \[\leadsto \color{blue}{\pi} - \cos^{-1} \left(x - 1\right) \]
                  7. lower-acos.f64N/A

                    \[\leadsto \pi - \color{blue}{\cos^{-1} \left(x - 1\right)} \]
                  8. lower--.f646.9

                    \[\leadsto \pi - \cos^{-1} \color{blue}{\left(x - 1\right)} \]
                3. Applied rewrites6.9%

                  \[\leadsto \color{blue}{\pi - \cos^{-1} \left(x - 1\right)} \]
                4. Applied rewrites6.9%

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

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

              Alternative 4: 10.3% accurate, 0.2× speedup?

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

                \[\cos^{-1} \left(1 - x\right) \]
              2. Step-by-step derivation
                1. lift-acos.f64N/A

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

                  \[\leadsto \cos^{-1} \color{blue}{\left(1 - x\right)} \]
                3. sub-negate-revN/A

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

                  \[\leadsto \color{blue}{\mathsf{PI}\left(\right) - \cos^{-1} \left(x - 1\right)} \]
                5. sub-to-multN/A

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

                  \[\leadsto \color{blue}{\left(1 - \frac{\cos^{-1} \left(x - 1\right)}{\mathsf{PI}\left(\right)}\right) \cdot \mathsf{PI}\left(\right)} \]
                7. lower-unsound--.f64N/A

                  \[\leadsto \color{blue}{\left(1 - \frac{\cos^{-1} \left(x - 1\right)}{\mathsf{PI}\left(\right)}\right)} \cdot \mathsf{PI}\left(\right) \]
                8. lower-unsound-/.f64N/A

                  \[\leadsto \left(1 - \color{blue}{\frac{\cos^{-1} \left(x - 1\right)}{\mathsf{PI}\left(\right)}}\right) \cdot \mathsf{PI}\left(\right) \]
                9. lower-acos.f64N/A

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

                  \[\leadsto \left(1 - \frac{\cos^{-1} \color{blue}{\left(x - 1\right)}}{\mathsf{PI}\left(\right)}\right) \cdot \mathsf{PI}\left(\right) \]
                11. lower-PI.f64N/A

                  \[\leadsto \left(1 - \frac{\cos^{-1} \left(x - 1\right)}{\color{blue}{\pi}}\right) \cdot \mathsf{PI}\left(\right) \]
                12. lower-PI.f646.9

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

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

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

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

                  \[\leadsto \left(1 - \color{blue}{\frac{1}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}}}\right) \cdot \pi \]
                4. lower-unsound-/.f646.9

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

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

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

                  \[\leadsto \left(1 - \color{blue}{\frac{1}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}}}\right) \cdot \pi \]
                3. sub-to-fractionN/A

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

                  \[\leadsto \frac{\color{blue}{1 \cdot \frac{\pi}{\cos^{-1} \left(x - 1\right)} + \left(\mathsf{neg}\left(1\right)\right)}}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}} \cdot \pi \]
                5. *-lft-identityN/A

                  \[\leadsto \frac{\color{blue}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}} + \left(\mathsf{neg}\left(1\right)\right)}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}} \cdot \pi \]
                6. metadata-evalN/A

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

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

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

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

                  \[\leadsto \left(\frac{\color{blue}{\frac{1}{\cos^{-1} \left(x - 1\right)} \cdot \pi}}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}} + \frac{-1}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}}\right) \cdot \pi \]
                11. *-lft-identityN/A

                  \[\leadsto \left(\frac{\frac{1}{\cos^{-1} \left(x - 1\right)} \cdot \pi}{\color{blue}{1 \cdot \frac{\pi}{\cos^{-1} \left(x - 1\right)}}} + \frac{-1}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}}\right) \cdot \pi \]
                12. times-fracN/A

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

                  \[\leadsto \left(\frac{\frac{1}{\cos^{-1} \left(x - 1\right)}}{1} \cdot \frac{\pi}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}} + \frac{\color{blue}{\mathsf{neg}\left(1\right)}}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}}\right) \cdot \pi \]
                14. distribute-neg-fracN/A

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

                  \[\leadsto \left(\frac{\frac{1}{\cos^{-1} \left(x - 1\right)}}{1} \cdot \frac{\pi}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}} + \left(\mathsf{neg}\left(\color{blue}{\frac{1}{\frac{\pi}{\cos^{-1} \left(x - 1\right)}}}\right)\right)\right) \cdot \pi \]
              7. Applied rewrites10.3%

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

              Alternative 5: 10.3% accurate, 0.3× speedup?

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

                \[\cos^{-1} \left(1 - x\right) \]
              2. Step-by-step derivation
                1. lift-acos.f64N/A

                  \[\leadsto \color{blue}{\cos^{-1} \left(1 - x\right)} \]
                2. acos-asinN/A

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

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

                  \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}} \]
                5. sum-to-multN/A

                  \[\leadsto \color{blue}{\left(1 + \frac{\frac{\mathsf{PI}\left(\right)}{2}}{\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right)} \]
                6. lower-unsound-*.f64N/A

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

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

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

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

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

                  \[\leadsto \left(1 + \frac{\color{blue}{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}}{\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) \]
                12. metadata-evalN/A

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

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

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

                  \[\leadsto \left(1 + \frac{\frac{1}{2} \cdot \pi}{\sin^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(1 - x\right)}\right)\right)}\right) \cdot \left(\mathsf{neg}\left(\sin^{-1} \left(1 - x\right)\right)\right) \]
                16. sub-negate-revN/A

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

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

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

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

                  \[\leadsto \left(1 + \frac{\frac{1}{2} \cdot \pi}{\sin^{-1} \left(x - 1\right)}\right) \cdot \sin^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(1 - x\right)}\right)\right) \]
                21. sub-negate-revN/A

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

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

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

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

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

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

                  \[\leadsto \frac{1 \cdot \sin^{-1} \left(x - 1\right) + \color{blue}{\pi \cdot \frac{1}{2}}}{\sin^{-1} \left(x - 1\right)} \cdot \sin^{-1} \left(x - 1\right) \]
                6. *-lft-identityN/A

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

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

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

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

                  \[\leadsto \frac{\color{blue}{\frac{\mathsf{PI}\left(\right)}{2} + \sin^{-1} \left(x - 1\right)}}{\sin^{-1} \left(x - 1\right)} \cdot \sin^{-1} \left(x - 1\right) \]
                11. div-addN/A

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

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

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

                  \[\leadsto \left(\frac{\pi \cdot \color{blue}{\frac{1}{2}}}{\sin^{-1} \left(x - 1\right)} + \frac{\sin^{-1} \left(x - 1\right)}{\sin^{-1} \left(x - 1\right)}\right) \cdot \sin^{-1} \left(x - 1\right) \]
                15. associate-/l*N/A

                  \[\leadsto \left(\color{blue}{\pi \cdot \frac{\frac{1}{2}}{\sin^{-1} \left(x - 1\right)}} + \frac{\sin^{-1} \left(x - 1\right)}{\sin^{-1} \left(x - 1\right)}\right) \cdot \sin^{-1} \left(x - 1\right) \]
                16. *-inversesN/A

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

                  \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, \frac{\frac{1}{2}}{\sin^{-1} \left(x - 1\right)}, 1\right)} \cdot \sin^{-1} \left(x - 1\right) \]
              5. Applied rewrites10.3%

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

              Alternative 6: 10.3% accurate, 0.3× speedup?

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

                \[\cos^{-1} \left(1 - x\right) \]
              2. Step-by-step derivation
                1. lift-acos.f64N/A

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

                  \[\leadsto \cos^{-1} \color{blue}{\left(1 - x\right)} \]
                3. sub-negate-revN/A

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

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

                  \[\leadsto \color{blue}{\mathsf{PI}\left(\right) - \cos^{-1} \left(x - 1\right)} \]
                6. lower-PI.f64N/A

                  \[\leadsto \color{blue}{\pi} - \cos^{-1} \left(x - 1\right) \]
                7. lower-acos.f64N/A

                  \[\leadsto \pi - \color{blue}{\cos^{-1} \left(x - 1\right)} \]
                8. lower--.f646.9

                  \[\leadsto \pi - \cos^{-1} \color{blue}{\left(x - 1\right)} \]
              3. Applied rewrites6.9%

                \[\leadsto \color{blue}{\pi - \cos^{-1} \left(x - 1\right)} \]
              4. Applied rewrites6.9%

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

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

              Alternative 7: 9.4% accurate, 0.3× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos^{-1} \left(1 - x\right)\\ \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;\cos^{-1} \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\pi - \left(1 - \frac{t\_0}{\pi}\right) \cdot \pi\\ \end{array} \end{array} \]
              (FPCore (x)
               :precision binary64
               (let* ((t_0 (acos (- 1.0 x))))
                 (if (<= t_0 0.0) (acos (- x)) (- PI (* (- 1.0 (/ t_0 PI)) PI)))))
              double code(double x) {
              	double t_0 = acos((1.0 - x));
              	double tmp;
              	if (t_0 <= 0.0) {
              		tmp = acos(-x);
              	} else {
              		tmp = ((double) M_PI) - ((1.0 - (t_0 / ((double) M_PI))) * ((double) M_PI));
              	}
              	return tmp;
              }
              
              public static double code(double x) {
              	double t_0 = Math.acos((1.0 - x));
              	double tmp;
              	if (t_0 <= 0.0) {
              		tmp = Math.acos(-x);
              	} else {
              		tmp = Math.PI - ((1.0 - (t_0 / Math.PI)) * Math.PI);
              	}
              	return tmp;
              }
              
              def code(x):
              	t_0 = math.acos((1.0 - x))
              	tmp = 0
              	if t_0 <= 0.0:
              		tmp = math.acos(-x)
              	else:
              		tmp = math.pi - ((1.0 - (t_0 / math.pi)) * math.pi)
              	return tmp
              
              function code(x)
              	t_0 = acos(Float64(1.0 - x))
              	tmp = 0.0
              	if (t_0 <= 0.0)
              		tmp = acos(Float64(-x));
              	else
              		tmp = Float64(pi - Float64(Float64(1.0 - Float64(t_0 / pi)) * pi));
              	end
              	return tmp
              end
              
              function tmp_2 = code(x)
              	t_0 = acos((1.0 - x));
              	tmp = 0.0;
              	if (t_0 <= 0.0)
              		tmp = acos(-x);
              	else
              		tmp = pi - ((1.0 - (t_0 / pi)) * pi);
              	end
              	tmp_2 = tmp;
              end
              
              code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[ArcCos[(-x)], $MachinePrecision], N[(Pi - N[(N[(1.0 - N[(t$95$0 / Pi), $MachinePrecision]), $MachinePrecision] * Pi), $MachinePrecision]), $MachinePrecision]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_0 := \cos^{-1} \left(1 - x\right)\\
              \mathbf{if}\;t\_0 \leq 0:\\
              \;\;\;\;\cos^{-1} \left(-x\right)\\
              
              \mathbf{else}:\\
              \;\;\;\;\pi - \left(1 - \frac{t\_0}{\pi}\right) \cdot \pi\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if (acos.f64 (-.f64 #s(literal 1 binary64) x)) < 0.0

                1. Initial program 6.9%

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

                  \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
                3. Step-by-step derivation
                  1. lower-*.f646.9

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

                  \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
                5. Step-by-step derivation
                  1. lift-*.f64N/A

                    \[\leadsto \cos^{-1} \left(-1 \cdot \color{blue}{x}\right) \]
                  2. mul-1-negN/A

                    \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(x\right)\right) \]
                  3. lower-neg.f646.9

                    \[\leadsto \cos^{-1} \left(-x\right) \]
                6. Applied rewrites6.9%

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

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

                1. Initial program 6.9%

                  \[\cos^{-1} \left(1 - x\right) \]
                2. Step-by-step derivation
                  1. lift-acos.f64N/A

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

                    \[\leadsto \cos^{-1} \color{blue}{\left(1 - x\right)} \]
                  3. sub-negate-revN/A

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

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

                    \[\leadsto \color{blue}{\mathsf{PI}\left(\right) - \cos^{-1} \left(x - 1\right)} \]
                  6. lower-PI.f64N/A

                    \[\leadsto \color{blue}{\pi} - \cos^{-1} \left(x - 1\right) \]
                  7. lower-acos.f64N/A

                    \[\leadsto \pi - \color{blue}{\cos^{-1} \left(x - 1\right)} \]
                  8. lower--.f646.9

                    \[\leadsto \pi - \cos^{-1} \color{blue}{\left(x - 1\right)} \]
                3. Applied rewrites6.9%

                  \[\leadsto \color{blue}{\pi - \cos^{-1} \left(x - 1\right)} \]
                4. Applied rewrites6.9%

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

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

              Alternative 8: 9.4% accurate, 0.5× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 5.6 \cdot 10^{-17}:\\ \;\;\;\;\cos^{-1} \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\pi - \left(\pi - \cos^{-1} \left(1 - x\right)\right)\\ \end{array} \end{array} \]
              (FPCore (x)
               :precision binary64
               (if (<= x 5.6e-17) (acos (- x)) (- PI (- PI (acos (- 1.0 x))))))
              double code(double x) {
              	double tmp;
              	if (x <= 5.6e-17) {
              		tmp = acos(-x);
              	} else {
              		tmp = ((double) M_PI) - (((double) M_PI) - acos((1.0 - x)));
              	}
              	return tmp;
              }
              
              public static double code(double x) {
              	double tmp;
              	if (x <= 5.6e-17) {
              		tmp = Math.acos(-x);
              	} else {
              		tmp = Math.PI - (Math.PI - Math.acos((1.0 - x)));
              	}
              	return tmp;
              }
              
              def code(x):
              	tmp = 0
              	if x <= 5.6e-17:
              		tmp = math.acos(-x)
              	else:
              		tmp = math.pi - (math.pi - math.acos((1.0 - x)))
              	return tmp
              
              function code(x)
              	tmp = 0.0
              	if (x <= 5.6e-17)
              		tmp = acos(Float64(-x));
              	else
              		tmp = Float64(pi - Float64(pi - acos(Float64(1.0 - x))));
              	end
              	return tmp
              end
              
              function tmp_2 = code(x)
              	tmp = 0.0;
              	if (x <= 5.6e-17)
              		tmp = acos(-x);
              	else
              		tmp = pi - (pi - acos((1.0 - x)));
              	end
              	tmp_2 = tmp;
              end
              
              code[x_] := If[LessEqual[x, 5.6e-17], N[ArcCos[(-x)], $MachinePrecision], N[(Pi - N[(Pi - N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;x \leq 5.6 \cdot 10^{-17}:\\
              \;\;\;\;\cos^{-1} \left(-x\right)\\
              
              \mathbf{else}:\\
              \;\;\;\;\pi - \left(\pi - \cos^{-1} \left(1 - x\right)\right)\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if x < 5.5999999999999998e-17

                1. Initial program 6.9%

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

                  \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
                3. Step-by-step derivation
                  1. lower-*.f646.9

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

                  \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
                5. Step-by-step derivation
                  1. lift-*.f64N/A

                    \[\leadsto \cos^{-1} \left(-1 \cdot \color{blue}{x}\right) \]
                  2. mul-1-negN/A

                    \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(x\right)\right) \]
                  3. lower-neg.f646.9

                    \[\leadsto \cos^{-1} \left(-x\right) \]
                6. Applied rewrites6.9%

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

                if 5.5999999999999998e-17 < x

                1. Initial program 6.9%

                  \[\cos^{-1} \left(1 - x\right) \]
                2. Step-by-step derivation
                  1. lift-acos.f64N/A

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

                    \[\leadsto \cos^{-1} \color{blue}{\left(1 - x\right)} \]
                  3. sub-negate-revN/A

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

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

                    \[\leadsto \color{blue}{\mathsf{PI}\left(\right) - \cos^{-1} \left(x - 1\right)} \]
                  6. lower-PI.f64N/A

                    \[\leadsto \color{blue}{\pi} - \cos^{-1} \left(x - 1\right) \]
                  7. lower-acos.f64N/A

                    \[\leadsto \pi - \color{blue}{\cos^{-1} \left(x - 1\right)} \]
                  8. lower--.f646.9

                    \[\leadsto \pi - \cos^{-1} \color{blue}{\left(x - 1\right)} \]
                3. Applied rewrites6.9%

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

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

                    \[\leadsto \pi - \cos^{-1} \color{blue}{\left(x - 1\right)} \]
                  3. sub-negate-revN/A

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

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

                    \[\leadsto \pi - \left(\color{blue}{\pi} - \cos^{-1} \left(1 - x\right)\right) \]
                  6. acos-asinN/A

                    \[\leadsto \pi - \left(\pi - \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(1 - x\right)\right)}\right) \]
                  7. sub-negate-revN/A

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

                    \[\leadsto \pi - \left(\pi - \left(\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(x - 1\right)}\right)\right)\right)\right) \]
                  9. asin-neg-revN/A

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

                    \[\leadsto \pi - \left(\pi - \left(\frac{\mathsf{PI}\left(\right)}{2} - \left(\mathsf{neg}\left(\color{blue}{\sin^{-1} \left(x - 1\right)}\right)\right)\right)\right) \]
                  11. add-flip-revN/A

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

                    \[\leadsto \pi - \left(\pi - \color{blue}{\left(\sin^{-1} \left(x - 1\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)}\right) \]
                  13. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

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

              Alternative 9: 9.4% accurate, 0.5× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - x \leq 0.9999999999999996:\\ \;\;\;\;\cos^{-1} \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(-x\right)\\ \end{array} \end{array} \]
              (FPCore (x)
               :precision binary64
               (if (<= (- 1.0 x) 0.9999999999999996) (acos (- 1.0 x)) (acos (- x))))
              double code(double x) {
              	double tmp;
              	if ((1.0 - x) <= 0.9999999999999996) {
              		tmp = acos((1.0 - x));
              	} else {
              		tmp = acos(-x);
              	}
              	return tmp;
              }
              
              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
                  real(8) :: tmp
                  if ((1.0d0 - x) <= 0.9999999999999996d0) then
                      tmp = acos((1.0d0 - x))
                  else
                      tmp = acos(-x)
                  end if
                  code = tmp
              end function
              
              public static double code(double x) {
              	double tmp;
              	if ((1.0 - x) <= 0.9999999999999996) {
              		tmp = Math.acos((1.0 - x));
              	} else {
              		tmp = Math.acos(-x);
              	}
              	return tmp;
              }
              
              def code(x):
              	tmp = 0
              	if (1.0 - x) <= 0.9999999999999996:
              		tmp = math.acos((1.0 - x))
              	else:
              		tmp = math.acos(-x)
              	return tmp
              
              function code(x)
              	tmp = 0.0
              	if (Float64(1.0 - x) <= 0.9999999999999996)
              		tmp = acos(Float64(1.0 - x));
              	else
              		tmp = acos(Float64(-x));
              	end
              	return tmp
              end
              
              function tmp_2 = code(x)
              	tmp = 0.0;
              	if ((1.0 - x) <= 0.9999999999999996)
              		tmp = acos((1.0 - x));
              	else
              		tmp = acos(-x);
              	end
              	tmp_2 = tmp;
              end
              
              code[x_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 0.9999999999999996], N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], N[ArcCos[(-x)], $MachinePrecision]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;1 - x \leq 0.9999999999999996:\\
              \;\;\;\;\cos^{-1} \left(1 - x\right)\\
              
              \mathbf{else}:\\
              \;\;\;\;\cos^{-1} \left(-x\right)\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if (-.f64 #s(literal 1 binary64) x) < 0.99999999999999956

                1. Initial program 6.9%

                  \[\cos^{-1} \left(1 - x\right) \]

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

                1. Initial program 6.9%

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

                  \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
                3. Step-by-step derivation
                  1. lower-*.f646.9

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

                  \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
                5. Step-by-step derivation
                  1. lift-*.f64N/A

                    \[\leadsto \cos^{-1} \left(-1 \cdot \color{blue}{x}\right) \]
                  2. mul-1-negN/A

                    \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(x\right)\right) \]
                  3. lower-neg.f646.9

                    \[\leadsto \cos^{-1} \left(-x\right) \]
                6. Applied rewrites6.9%

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

              Alternative 10: 6.9% accurate, 1.3× speedup?

              \[\begin{array}{l} \\ \cos^{-1} \left(-x\right) \end{array} \]
              (FPCore (x) :precision binary64 (acos (- x)))
              double code(double x) {
              	return acos(-x);
              }
              
              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(-x)
              end function
              
              public static double code(double x) {
              	return Math.acos(-x);
              }
              
              def code(x):
              	return math.acos(-x)
              
              function code(x)
              	return acos(Float64(-x))
              end
              
              function tmp = code(x)
              	tmp = acos(-x);
              end
              
              code[x_] := N[ArcCos[(-x)], $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              \cos^{-1} \left(-x\right)
              \end{array}
              
              Derivation
              1. Initial program 6.9%

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

                \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
              3. Step-by-step derivation
                1. lower-*.f646.9

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

                \[\leadsto \cos^{-1} \color{blue}{\left(-1 \cdot x\right)} \]
              5. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \cos^{-1} \left(-1 \cdot \color{blue}{x}\right) \]
                2. mul-1-negN/A

                  \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(x\right)\right) \]
                3. lower-neg.f646.9

                  \[\leadsto \cos^{-1} \left(-x\right) \]
              6. Applied rewrites6.9%

                \[\leadsto \color{blue}{\cos^{-1} \left(-x\right)} \]
              7. Add Preprocessing

              Alternative 11: 3.8% accurate, 1.5× speedup?

              \[\begin{array}{l} \\ \cos^{-1} 1 \end{array} \]
              (FPCore (x) :precision binary64 (acos 1.0))
              double code(double x) {
              	return acos(1.0);
              }
              
              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(1.0d0)
              end function
              
              public static double code(double x) {
              	return Math.acos(1.0);
              }
              
              def code(x):
              	return math.acos(1.0)
              
              function code(x)
              	return acos(1.0)
              end
              
              function tmp = code(x)
              	tmp = acos(1.0);
              end
              
              code[x_] := N[ArcCos[1.0], $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              \cos^{-1} 1
              \end{array}
              
              Derivation
              1. Initial program 6.9%

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

                \[\leadsto \cos^{-1} \color{blue}{1} \]
              3. Step-by-step derivation
                1. Applied rewrites3.8%

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

                Reproduce

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