bug323 (missed optimization)

Percentage Accurate: 7.0% → 10.6%
Time: 3.7s
Alternatives: 6
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 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 7.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \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.6% accurate, 0.1× speedup?

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

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

    \[\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--.f647.0

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

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

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

      \[\leadsto \mathsf{fma}\left(\left(\pi \cdot \pi\right) \cdot \pi, \frac{\frac{1}{8}}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \color{blue}{\left(\frac{1}{4} \cdot \pi\right)} \cdot \pi\right)}, \frac{{\sin^{-1} \left(x - 1\right)}^{3}}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \left(\frac{1}{4} \cdot \pi\right) \cdot \pi\right)}\right) \]
    2. rem-square-sqrtN/A

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\left(\pi \cdot \pi\right) \cdot \pi, \frac{\frac{1}{8}}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \color{blue}{\left(\left(\frac{1}{4} \cdot \sqrt{\pi}\right) \cdot \sqrt{\pi}\right)} \cdot \pi\right)}, \frac{{\sin^{-1} \left(x - 1\right)}^{3}}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \left(\frac{1}{4} \cdot \pi\right) \cdot \pi\right)}\right) \]
    7. lower-*.f6410.5

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

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

      \[\leadsto \mathsf{fma}\left(\left(\pi \cdot \pi\right) \cdot \pi, \frac{\frac{1}{8}}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \left(\left(\frac{1}{4} \cdot \sqrt{\pi}\right) \cdot \sqrt{\pi}\right) \cdot \pi\right)}, \frac{{\sin^{-1} \left(x - 1\right)}^{3}}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \color{blue}{\left(\frac{1}{4} \cdot \pi\right)} \cdot \pi\right)}\right) \]
    2. rem-square-sqrtN/A

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\left(\pi \cdot \pi\right) \cdot \pi, \frac{\frac{1}{8}}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \left(\left(\frac{1}{4} \cdot \sqrt{\pi}\right) \cdot \sqrt{\pi}\right) \cdot \pi\right)}, \frac{{\sin^{-1} \left(x - 1\right)}^{3}}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \color{blue}{\left(\left(\frac{1}{4} \cdot \sqrt{\pi}\right) \cdot \sqrt{\pi}\right)} \cdot \pi\right)}\right) \]
    7. lower-*.f6410.6

      \[\leadsto \mathsf{fma}\left(\left(\pi \cdot \pi\right) \cdot \pi, \frac{0.125}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \left(\left(0.25 \cdot \sqrt{\pi}\right) \cdot \sqrt{\pi}\right) \cdot \pi\right)}, \frac{{\sin^{-1} \left(x - 1\right)}^{3}}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \left(\color{blue}{\left(0.25 \cdot \sqrt{\pi}\right)} \cdot \sqrt{\pi}\right) \cdot \pi\right)}\right) \]
  8. Applied rewrites10.6%

    \[\leadsto \mathsf{fma}\left(\left(\pi \cdot \pi\right) \cdot \pi, \frac{0.125}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \left(\left(0.25 \cdot \sqrt{\pi}\right) \cdot \sqrt{\pi}\right) \cdot \pi\right)}, \frac{{\sin^{-1} \left(x - 1\right)}^{3}}{\mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \color{blue}{\left(\left(0.25 \cdot \sqrt{\pi}\right) \cdot \sqrt{\pi}\right)} \cdot \pi\right)}\right) \]
  9. Add Preprocessing

Alternative 2: 10.6% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\cos^{-1} \left(x - 1\right), \sin^{-1} \left(1 - x\right), \left(0.25 \cdot \pi\right) \cdot \pi\right)\\
\mathsf{fma}\left(\left(\pi \cdot \pi\right) \cdot \pi, \frac{0.125}{t\_0}, \frac{{\sin^{-1} \left(x - 1\right)}^{3}}{t\_0}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 7.0%

    \[\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--.f647.0

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

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

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

Alternative 3: 10.6% accurate, 0.2× speedup?

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

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

    \[\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. 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)}} \]
    4. 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)}} \]
    5. 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)} \]
    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. mult-flipN/A

      \[\leadsto \frac{\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right)} \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}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right)} \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{\left(\color{blue}{\pi} \cdot \frac{1}{2}\right) \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. metadata-evalN/A

      \[\leadsto \frac{\left(\pi \cdot \color{blue}{\frac{1}{2}}\right) \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)} \]
    11. mult-flipN/A

      \[\leadsto \frac{\left(\pi \cdot \frac{1}{2}\right) \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right)} - \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{\left(\pi \cdot \frac{1}{2}\right) \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right)} - \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-PI.f64N/A

      \[\leadsto \frac{\left(\pi \cdot \frac{1}{2}\right) \cdot \left(\color{blue}{\pi} \cdot \frac{1}{2}\right) - \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. metadata-evalN/A

      \[\leadsto \frac{\left(\pi \cdot \frac{1}{2}\right) \cdot \left(\pi \cdot \color{blue}{\frac{1}{2}}\right) - \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)} \]
    15. lower-*.f64N/A

      \[\leadsto \frac{\left(\pi \cdot \frac{1}{2}\right) \cdot \left(\pi \cdot \frac{1}{2}\right) - \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)} \]
    16. lower-asin.f64N/A

      \[\leadsto \frac{\left(\pi \cdot \frac{1}{2}\right) \cdot \left(\pi \cdot \frac{1}{2}\right) - \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)} \]
    17. lower-asin.f64N/A

      \[\leadsto \frac{\left(\pi \cdot \frac{1}{2}\right) \cdot \left(\pi \cdot \frac{1}{2}\right) - \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)} \]
  3. Applied rewrites7.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\mathsf{fma}\left(\sin^{-1} \color{blue}{\left(x - 1\right)}, \sin^{-1} \left(1 - x\right), \left(\pi \cdot \frac{1}{2}\right) \cdot \left(\pi \cdot \frac{1}{2}\right)\right)}{\mathsf{fma}\left(\pi, \frac{1}{2}, \sin^{-1} \left(1 - x\right)\right)} \]
    12. lower-asin.f6410.6

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

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

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

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

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

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

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

Alternative 4: 10.5% accurate, 0.3× speedup?

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

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

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

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

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

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

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

      \[\leadsto \pi \cdot \color{blue}{\frac{1}{2}} - \sin^{-1} \left(1 - x\right) \]
    8. lower-asin.f647.0

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \pi \cdot \frac{1}{2} - \left(\pi \cdot \frac{1}{2} - \cos^{-1} \left(\mathsf{neg}\left(\color{blue}{\left(x - 1\right)}\right)\right)\right) \]
    10. acos-neg-revN/A

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

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

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

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

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

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

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

      \[\leadsto \pi \cdot \frac{1}{2} - \left(\frac{1}{2} \cdot \color{blue}{\mathsf{PI}\left(\right)} + \left(\cos^{-1} \left(x - 1\right) - \pi\right)\right) \]
    18. add-sqr-sqrtN/A

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

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

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

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

      \[\leadsto \pi \cdot \frac{1}{2} - \left(\left(\frac{1}{2} \cdot \sqrt{\mathsf{PI}\left(\right)}\right) \cdot \sqrt{\mathsf{PI}\left(\right)} + \left(\mathsf{neg}\left(\left(\mathsf{PI}\left(\right) - \color{blue}{\cos^{-1} \left(x - 1\right)}\right)\right)\right)\right) \]
    23. acos-neg-revN/A

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

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

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

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

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

Alternative 5: 7.4% accurate, 0.4× speedup?

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

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

    \[\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--.f647.0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \mathsf{fma}\left(\pi, \frac{1}{2}, \sin^{-1} \color{blue}{\left(x \cdot \left(1 - \frac{1}{x}\right)\right)}\right) \]
  7. Step-by-step derivation
    1. *-commutativeN/A

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

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

      \[\leadsto \mathsf{fma}\left(\pi, \frac{1}{2}, \sin^{-1} \left(\left(1 - \frac{1}{x}\right) \cdot x\right)\right) \]
    4. lower-/.f647.4

      \[\leadsto \mathsf{fma}\left(\pi, 0.5, \sin^{-1} \left(\left(1 - \frac{1}{x}\right) \cdot x\right)\right) \]
  8. Applied rewrites7.4%

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

Alternative 6: 7.0% 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}
Derivation
  1. Initial program 7.0%

    \[\cos^{-1} \left(1 - x\right) \]
  2. Add Preprocessing

Reproduce

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