Ian Simplification

Percentage Accurate: 6.9% → 8.3%
Time: 6.3s
Alternatives: 6
Speedup: 1.2×

Specification

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

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: 6.9% accurate, 1.0× speedup?

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

Alternative 1: 8.3% accurate, 0.8× speedup?

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

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

    \[\leadsto \frac{\pi}{2} - \color{blue}{\left(\pi + \left(-\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right)\right) \cdot 2\right)} \]
  3. Evaluated real constant8.3%

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

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

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

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

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

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

Alternative 2: 8.3% accurate, 1.1× speedup?

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

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

    \[\leadsto \frac{\pi}{2} - \color{blue}{\left(\pi + \left(-\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right)\right) \cdot 2\right)} \]
  3. Evaluated real constant8.3%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right) \cdot 2\right)\right)}\right)\right) + \left(\mathsf{neg}\left(\left(\pi - \frac{884279719003555}{562949953421312}\right)\right)\right) \]
    11. remove-double-negN/A

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

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

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

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

Alternative 3: 6.9% accurate, 1.2× speedup?

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

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

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

      \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{0.5}}\right) \]
    2. Evaluated real constant4.1%

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

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

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

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

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2\right)\right) \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) + \frac{884279719003555}{562949953421312}} \]
      5. metadata-evalN/A

        \[\leadsto \color{blue}{-2} \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) + \frac{884279719003555}{562949953421312} \]
      6. *-commutativeN/A

        \[\leadsto \color{blue}{\sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \cdot -2} + \frac{884279719003555}{562949953421312} \]
      7. lower-fma.f644.1%

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

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

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

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \frac{884279719003555}{562949953421312}\right) \]
      2. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \frac{884279719003555}{562949953421312}\right) \]
      3. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\frac{1}{2} \cdot \left(1 - x\right)}\right), -2, \frac{884279719003555}{562949953421312}\right) \]
      4. lower--.f646.9%

        \[\leadsto \mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right), -2, 1.5707963267948966\right) \]
    7. Applied rewrites6.9%

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

    Alternative 4: 6.8% accurate, 1.3× speedup?

    \[\mathsf{fma}\left(\cos^{-1} \left(\sqrt{\mathsf{fma}\left(-0.5, x, 0.5\right)}\right), 2, -1.5707963267948968\right) \]
    (FPCore (x)
     :precision binary64
     (fma (acos (sqrt (fma -0.5 x 0.5))) 2.0 -1.5707963267948968))
    double code(double x) {
    	return fma(acos(sqrt(fma(-0.5, x, 0.5))), 2.0, -1.5707963267948968);
    }
    
    function code(x)
    	return fma(acos(sqrt(fma(-0.5, x, 0.5))), 2.0, -1.5707963267948968)
    end
    
    code[x_] := N[(N[ArcCos[N[Sqrt[N[(-0.5 * x + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0 + -1.5707963267948968), $MachinePrecision]
    
    \mathsf{fma}\left(\cos^{-1} \left(\sqrt{\mathsf{fma}\left(-0.5, x, 0.5\right)}\right), 2, -1.5707963267948968\right)
    
    Derivation
    1. Initial program 6.9%

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

      \[\leadsto \frac{\pi}{2} - \color{blue}{\left(\pi + \left(-\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right)\right) \cdot 2\right)} \]
    3. Evaluated real constant8.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right) \cdot 2\right)\right)}\right)\right) + \left(\mathsf{neg}\left(\left(\pi - \frac{884279719003555}{562949953421312}\right)\right)\right) \]
      11. remove-double-negN/A

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos^{-1} \left(\sqrt{\mathsf{fma}\left(-0.5, x, 0.5\right)}\right), 2, 1.5707963267948966 - \pi\right)} \]
    6. Evaluated real constant6.8%

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

    Alternative 5: 5.4% accurate, 1.5× speedup?

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

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

      \[\leadsto \frac{\pi}{2} - \color{blue}{\left(\pi + \left(-\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right)\right) \cdot 2\right)} \]
    3. Evaluated real constant8.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, \frac{-1}{2}, \frac{1}{2}\right)}\right) \cdot 2\right)\right)}\right)\right) + \left(\mathsf{neg}\left(\left(\pi - \frac{884279719003555}{562949953421312}\right)\right)\right) \]
      11. remove-double-negN/A

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\cos^{-1} \left(\sqrt{\color{blue}{\frac{1}{2}}}\right), 2, 1.5707963267948966 - \pi\right) \]
    7. Step-by-step derivation
      1. Applied rewrites5.4%

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

      Alternative 6: 4.1% accurate, 1.8× speedup?

      \[\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5}\right), -2, 1.5707963267948966\right) \]
      (FPCore (x)
       :precision binary64
       (fma (asin (sqrt 0.5)) -2.0 1.5707963267948966))
      double code(double x) {
      	return fma(asin(sqrt(0.5)), -2.0, 1.5707963267948966);
      }
      
      function code(x)
      	return fma(asin(sqrt(0.5)), -2.0, 1.5707963267948966)
      end
      
      code[x_] := N[(N[ArcSin[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision] * -2.0 + 1.5707963267948966), $MachinePrecision]
      
      \mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5}\right), -2, 1.5707963267948966\right)
      
      Derivation
      1. Initial program 6.9%

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

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

          \[\leadsto \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\color{blue}{0.5}}\right) \]
        2. Evaluated real constant4.1%

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

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

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

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

            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2\right)\right) \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) + \frac{884279719003555}{562949953421312}} \]
          5. metadata-evalN/A

            \[\leadsto \color{blue}{-2} \cdot \sin^{-1} \left(\sqrt{\frac{1}{2}}\right) + \frac{884279719003555}{562949953421312} \]
          6. *-commutativeN/A

            \[\leadsto \color{blue}{\sin^{-1} \left(\sqrt{\frac{1}{2}}\right) \cdot -2} + \frac{884279719003555}{562949953421312} \]
          7. lower-fma.f644.1%

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

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

        Reproduce

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