bug323 (missed optimization)

Percentage Accurate: 6.7% → 10.2%
Time: 4.3s
Alternatives: 12
Speedup: 1.0×

Specification

?
\[0 \leq x \land x \leq 0.5\]
\[\begin{array}{l} \\ \cos^{-1} \left(1 - x\right) \end{array} \]
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
double code(double x) {
	return acos((1.0 - x));
}
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 12 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.7% 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.2% 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)\\ t_2 := t\_1 + \frac{\pi}{2}\\ t_3 := \pi \cdot \frac{\pi}{4}\\ t_4 := {t\_1}^{4} + t\_3 \cdot \left(t\_3 - \left(-{t\_0}^{2}\right)\right)\\ \mathsf{fma}\left(\frac{\frac{\pi}{4}}{t\_4}, \frac{\left(\pi \cdot \frac{\pi \cdot \pi}{16}\right) \cdot \left(\pi \cdot \pi\right)}{t\_2}, \frac{-{t\_0}^{6}}{t\_4 \cdot t\_2}\right) \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (asin (- x 1.0)))
        (t_1 (asin (- 1.0 x)))
        (t_2 (+ t_1 (/ PI 2.0)))
        (t_3 (* PI (/ PI 4.0)))
        (t_4 (+ (pow t_1 4.0) (* t_3 (- t_3 (- (pow t_0 2.0)))))))
   (fma
    (/ (/ PI 4.0) t_4)
    (/ (* (* PI (/ (* PI PI) 16.0)) (* PI PI)) t_2)
    (/ (- (pow t_0 6.0)) (* t_4 t_2)))))
double code(double x) {
	double t_0 = asin((x - 1.0));
	double t_1 = asin((1.0 - x));
	double t_2 = t_1 + (((double) M_PI) / 2.0);
	double t_3 = ((double) M_PI) * (((double) M_PI) / 4.0);
	double t_4 = pow(t_1, 4.0) + (t_3 * (t_3 - -pow(t_0, 2.0)));
	return fma(((((double) M_PI) / 4.0) / t_4), (((((double) M_PI) * ((((double) M_PI) * ((double) M_PI)) / 16.0)) * (((double) M_PI) * ((double) M_PI))) / t_2), (-pow(t_0, 6.0) / (t_4 * t_2)));
}
function code(x)
	t_0 = asin(Float64(x - 1.0))
	t_1 = asin(Float64(1.0 - x))
	t_2 = Float64(t_1 + Float64(pi / 2.0))
	t_3 = Float64(pi * Float64(pi / 4.0))
	t_4 = Float64((t_1 ^ 4.0) + Float64(t_3 * Float64(t_3 - Float64(-(t_0 ^ 2.0)))))
	return fma(Float64(Float64(pi / 4.0) / t_4), Float64(Float64(Float64(pi * Float64(Float64(pi * pi) / 16.0)) * Float64(pi * pi)) / t_2), Float64(Float64(-(t_0 ^ 6.0)) / Float64(t_4 * t_2)))
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]}, Block[{t$95$2 = N[(t$95$1 + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(Pi * N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Power[t$95$1, 4.0], $MachinePrecision] + N[(t$95$3 * N[(t$95$3 - (-N[Power[t$95$0, 2.0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(Pi / 4.0), $MachinePrecision] / t$95$4), $MachinePrecision] * N[(N[(N[(Pi * N[(N[(Pi * Pi), $MachinePrecision] / 16.0), $MachinePrecision]), $MachinePrecision] * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision] + N[((-N[Power[t$95$0, 6.0], $MachinePrecision]) / N[(t$95$4 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin^{-1} \left(x - 1\right)\\
t_1 := \sin^{-1} \left(1 - x\right)\\
t_2 := t\_1 + \frac{\pi}{2}\\
t_3 := \pi \cdot \frac{\pi}{4}\\
t_4 := {t\_1}^{4} + t\_3 \cdot \left(t\_3 - \left(-{t\_0}^{2}\right)\right)\\
\mathsf{fma}\left(\frac{\frac{\pi}{4}}{t\_4}, \frac{\left(\pi \cdot \frac{\pi \cdot \pi}{16}\right) \cdot \left(\pi \cdot \pi\right)}{t\_2}, \frac{-{t\_0}^{6}}{t\_4 \cdot t\_2}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 6.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 10.2% accurate, 0.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\mathsf{fma}\left(\left(\left(\pi \cdot \pi\right) \cdot \frac{\pi \cdot \pi}{16}\right) \cdot \pi, \frac{\pi}{4}, {\left(-{\color{blue}{\sin^{-1} \left(x + -1\right)}}^{2}\right)}^{3}\right)}{\left(\mathsf{fma}\left(\pi \cdot \pi, \frac{\pi \cdot \pi}{16}, {\sin^{-1} \left(1 - x\right)}^{4}\right) - \left(-{\sin^{-1} \left(x + -1\right)}^{2}\right) \cdot \left(\pi \cdot \frac{\pi}{4}\right)\right) \cdot \left(\sin^{-1} \left(1 - x\right) + \frac{\pi}{2}\right)} \]
    3. remove-double-negN/A

      \[\leadsto \frac{\mathsf{fma}\left(\left(\left(\pi \cdot \pi\right) \cdot \frac{\pi \cdot \pi}{16}\right) \cdot \pi, \frac{\pi}{4}, {\left(-{\sin^{-1} \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)} + -1\right)}^{2}\right)}^{3}\right)}{\left(\mathsf{fma}\left(\pi \cdot \pi, \frac{\pi \cdot \pi}{16}, {\sin^{-1} \left(1 - x\right)}^{4}\right) - \left(-{\sin^{-1} \left(x + -1\right)}^{2}\right) \cdot \left(\pi \cdot \frac{\pi}{4}\right)\right) \cdot \left(\sin^{-1} \left(1 - x\right) + \frac{\pi}{2}\right)} \]
    4. mul-1-negN/A

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

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

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

      \[\leadsto \frac{\mathsf{fma}\left(\left(\left(\pi \cdot \pi\right) \cdot \frac{\pi \cdot \pi}{16}\right) \cdot \pi, \frac{\pi}{4}, {\left(-{\sin^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(1 + -1 \cdot x\right)}\right)\right)}^{2}\right)}^{3}\right)}{\left(\mathsf{fma}\left(\pi \cdot \pi, \frac{\pi \cdot \pi}{16}, {\sin^{-1} \left(1 - x\right)}^{4}\right) - \left(-{\sin^{-1} \left(x + -1\right)}^{2}\right) \cdot \left(\pi \cdot \frac{\pi}{4}\right)\right) \cdot \left(\sin^{-1} \left(1 - x\right) + \frac{\pi}{2}\right)} \]
    8. unpow1N/A

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

      \[\leadsto \frac{\mathsf{fma}\left(\left(\left(\pi \cdot \pi\right) \cdot \frac{\pi \cdot \pi}{16}\right) \cdot \pi, \frac{\pi}{4}, {\left(-{\left({\sin^{-1} \left(\mathsf{neg}\left(\left(1 + -1 \cdot x\right)\right)\right)}^{\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)}}\right)}^{2}\right)}^{3}\right)}{\left(\mathsf{fma}\left(\pi \cdot \pi, \frac{\pi \cdot \pi}{16}, {\sin^{-1} \left(1 - x\right)}^{4}\right) - \left(-{\sin^{-1} \left(x + -1\right)}^{2}\right) \cdot \left(\pi \cdot \frac{\pi}{4}\right)\right) \cdot \left(\sin^{-1} \left(1 - x\right) + \frac{\pi}{2}\right)} \]
    10. pow-negN/A

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

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

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

    \[\leadsto \frac{\mathsf{fma}\left(\left(\left(\pi \cdot \pi\right) \cdot \frac{\pi \cdot \pi}{16}\right) \cdot \pi, \frac{\pi}{4}, {\left(-{\color{blue}{\left(\frac{1}{{\sin^{-1} \left(x - 1\right)}^{-1}}\right)}}^{2}\right)}^{3}\right)}{\left(\mathsf{fma}\left(\pi \cdot \pi, \frac{\pi \cdot \pi}{16}, {\sin^{-1} \left(1 - x\right)}^{4}\right) - \left(-{\sin^{-1} \left(x + -1\right)}^{2}\right) \cdot \left(\pi \cdot \frac{\pi}{4}\right)\right) \cdot \left(\sin^{-1} \left(1 - x\right) + \frac{\pi}{2}\right)} \]
  8. Add Preprocessing

Alternative 3: 10.2% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{\pi \cdot \pi}{16}\\
t_1 := \sin^{-1} \left(1 - x\right)\\
t_2 := -{\sin^{-1} \left(x + -1\right)}^{2}\\
\frac{\mathsf{fma}\left(\left(\left(\pi \cdot \pi\right) \cdot t\_0\right) \cdot \pi, \frac{\pi}{4}, {t\_2}^{3}\right)}{\left(\mathsf{fma}\left(\pi \cdot \pi, t\_0, {t\_1}^{4}\right) - t\_2 \cdot \left(\pi \cdot \frac{\pi}{4}\right)\right) \cdot \left(t\_1 + \frac{\pi}{2}\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 6.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 10.2% accurate, 0.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 10.2% accurate, 0.3× speedup?

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

\\
\frac{\mathsf{fma}\left(\sin^{-1} \left(\frac{\mathsf{fma}\left(x \cdot x, x, -1\right)}{\mathsf{fma}\left(-x, x - -1, -1\right)}\right), \sin^{-1} \left(-1 + x\right), \pi \cdot \frac{\pi}{4}\right)}{\frac{\pi}{2} + \sin^{-1} \left(1 - x\right)}
\end{array}
Derivation
  1. Initial program 6.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 10.2% accurate, 0.3× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 10.1% accurate, 0.5× speedup?

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

\\
\frac{\pi}{2} - {\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}
\end{array}
Derivation
  1. Initial program 6.7%

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

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

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

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

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

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

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

      \[\leadsto \frac{\pi}{2} - \color{blue}{\sin^{-1} \left(1 - x\right)} \]
    8. lift--.f646.7

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\pi}{2} - {\sin^{-1} \left(1 - x\right)}^{\frac{1}{2}} \cdot {\color{blue}{\sin^{-1} \left(1 - x\right)}}^{\frac{1}{2}} \]
    13. lift--.f6410.1

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\pi}{2} - \color{blue}{{\left({\sin^{-1} \left(1 - x\right)}^{\frac{1}{2}}\right)}^{2}} \]
    10. pow1/2N/A

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

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

      \[\leadsto \frac{\pi}{2} - {\left(\sqrt{\color{blue}{\sin^{-1} \left(1 - x\right)}}\right)}^{2} \]
    13. lift--.f6410.1

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

    \[\leadsto \frac{\pi}{2} - \color{blue}{{\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}} \]
  8. Add Preprocessing

Alternative 8: 9.2% accurate, 0.4× 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}:\\ \;\;\;\;0.5 \cdot \pi - \left(\frac{\pi}{2} - t\_0\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (acos (- 1.0 x))))
   (if (<= t_0 0.0) (acos (- x)) (- (* 0.5 PI) (- (/ PI 2.0) t_0)))))
double code(double x) {
	double t_0 = acos((1.0 - x));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = acos(-x);
	} else {
		tmp = (0.5 * ((double) M_PI)) - ((((double) M_PI) / 2.0) - t_0);
	}
	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 = (0.5 * Math.PI) - ((Math.PI / 2.0) - t_0);
	}
	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 = (0.5 * math.pi) - ((math.pi / 2.0) - t_0)
	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(Float64(0.5 * pi) - Float64(Float64(pi / 2.0) - t_0));
	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 = (0.5 * pi) - ((pi / 2.0) - t_0);
	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[(N[(0.5 * Pi), $MachinePrecision] - N[(N[(Pi / 2.0), $MachinePrecision] - t$95$0), $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}:\\
\;\;\;\;0.5 \cdot \pi - \left(\frac{\pi}{2} - t\_0\right)\\


\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 3.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. mul-1-negN/A

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

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

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

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

    1. Initial program 63.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\pi}{2} - \color{blue}{\sin^{-1} \left(1 - x\right)} \]
      8. lift--.f6463.8

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \pi - \sin^{-1} \left(1 - x\right) \]
      5. lift--.f6463.8

        \[\leadsto 0.5 \cdot \pi - \sin^{-1} \left(1 - x\right) \]
    6. Applied rewrites63.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \pi - \left(\frac{\pi}{2} - \cos^{-1} \left(1 - x\right)\right) \]
      8. lift--.f6463.8

        \[\leadsto 0.5 \cdot \pi - \left(\frac{\pi}{2} - \cos^{-1} \left(1 - x\right)\right) \]
    8. Applied rewrites63.8%

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

Alternative 9: 9.2% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\cos^{-1} \left(1 - x\right) \leq 0:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\

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


\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 3.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. mul-1-negN/A

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

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

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

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

    1. Initial program 63.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\pi}{2} - \color{blue}{\sin^{-1} \left(1 - x\right)} \]
      8. lift--.f6463.8

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \pi - \sin^{-1} \left(1 - x\right) \]
      5. lift--.f6463.8

        \[\leadsto 0.5 \cdot \pi - \sin^{-1} \left(1 - x\right) \]
    6. Applied rewrites63.8%

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

Alternative 10: 9.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - x \leq 0.9999999999999997:\\ \;\;\;\;\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.9999999999999997) (acos (- 1.0 x)) (acos (- x))))
double code(double x) {
	double tmp;
	if ((1.0 - x) <= 0.9999999999999997) {
		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.9999999999999997d0) 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.9999999999999997) {
		tmp = Math.acos((1.0 - x));
	} else {
		tmp = Math.acos(-x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (1.0 - x) <= 0.9999999999999997:
		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.9999999999999997)
		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.9999999999999997)
		tmp = acos((1.0 - x));
	else
		tmp = acos(-x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 0.9999999999999997], N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], N[ArcCos[(-x)], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 0.9999999999999997:\\
\;\;\;\;\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.999999999999999667

    1. Initial program 64.7%

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

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

    1. Initial program 3.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. mul-1-negN/A

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

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

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

Alternative 11: 6.9% accurate, 1.0× 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.7%

    \[\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. mul-1-negN/A

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

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

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

Alternative 12: 3.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos^{-1} 1 \end{array} \]
(FPCore (x) :precision binary64 (acos 1.0))
double code(double x) {
	return acos(1.0);
}
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.7%

    \[\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 2025101 
    (FPCore (x)
      :name "bug323 (missed optimization)"
      :precision binary64
      :pre (and (<= 0.0 x) (<= x 0.5))
      (acos (- 1.0 x)))