
(FPCore (x) :precision binary64 (- (/ (PI) 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
\begin{array}{l}
\\
\frac{\mathsf{PI}\left(\right)}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ (PI) 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
\begin{array}{l}
\\
\frac{\mathsf{PI}\left(\right)}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (sqrt (fma x -0.5 0.5))))
(t_1 (* 0.5 (PI)))
(t_2 (fma t_0 2.0 t_1)))
(/
(-
(* t_2 (* (* (cbrt (pow (PI) 3.0)) (PI)) 0.25))
(* (* 4.0 (pow t_0 2.0)) t_2))
(*
(fma
(fma
(pow (/ (cbrt (* 2.0 (PI))) (cbrt 2.0)) 2.0)
(* (cbrt (PI)) 0.5)
(- (acos (sqrt (fma -0.5 x 0.5)))))
2.0
t_1)
t_2))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right)\\
t_1 := 0.5 \cdot \mathsf{PI}\left(\right)\\
t_2 := \mathsf{fma}\left(t\_0, 2, t\_1\right)\\
\frac{t\_2 \cdot \left(\left(\sqrt[3]{{\mathsf{PI}\left(\right)}^{3}} \cdot \mathsf{PI}\left(\right)\right) \cdot 0.25\right) - \left(4 \cdot {t\_0}^{2}\right) \cdot t\_2}{\mathsf{fma}\left(\mathsf{fma}\left({\left(\frac{\sqrt[3]{2 \cdot \mathsf{PI}\left(\right)}}{\sqrt[3]{2}}\right)}^{2}, \sqrt[3]{\mathsf{PI}\left(\right)} \cdot 0.5, -\cos^{-1} \left(\sqrt{\mathsf{fma}\left(-0.5, x, 0.5\right)}\right)\right), 2, t\_1\right) \cdot t\_2}
\end{array}
\end{array}
Initial program 6.0%
Applied rewrites6.1%
rem-cbrt-cubeN/A
lower-cbrt.f64N/A
lower-pow.f647.6
Applied rewrites7.6%
lift-asin.f64N/A
asin-acosN/A
lift-fma.f64N/A
*-commutativeN/A
lift-fma.f64N/A
lift-acos.f64N/A
lift-PI.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
sub-negN/A
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites7.6%
lift-cbrt.f64N/A
*-lft-identityN/A
*-commutativeN/A
metadata-evalN/A
associate-*l*N/A
metadata-evalN/A
div-invN/A
associate-*l/N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f647.6
Applied rewrites7.6%
Final simplification7.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (PI)))
(t_1 (sqrt (fma x -0.5 0.5)))
(t_2 (asin t_1))
(t_3 (* 0.5 (PI)))
(t_4 (fma t_2 2.0 t_3))
(t_5 (sqrt (PI))))
(/
(-
(* t_4 (* (* (cbrt (pow (PI) 3.0)) (PI)) 0.25))
(* (* 4.0 (pow t_2 2.0)) t_4))
(*
(fma (fma (* t_5 0.5) t_5 (- (acos t_1))) 2.0 t_3)
(fma
(fma (pow t_0 2.0) (* t_0 0.5) (- (acos (sqrt (fma -0.5 x 0.5)))))
2.0
t_3)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
t_1 := \sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\\
t_2 := \sin^{-1} t\_1\\
t_3 := 0.5 \cdot \mathsf{PI}\left(\right)\\
t_4 := \mathsf{fma}\left(t\_2, 2, t\_3\right)\\
t_5 := \sqrt{\mathsf{PI}\left(\right)}\\
\frac{t\_4 \cdot \left(\left(\sqrt[3]{{\mathsf{PI}\left(\right)}^{3}} \cdot \mathsf{PI}\left(\right)\right) \cdot 0.25\right) - \left(4 \cdot {t\_2}^{2}\right) \cdot t\_4}{\mathsf{fma}\left(\mathsf{fma}\left(t\_5 \cdot 0.5, t\_5, -\cos^{-1} t\_1\right), 2, t\_3\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left({t\_0}^{2}, t\_0 \cdot 0.5, -\cos^{-1} \left(\sqrt{\mathsf{fma}\left(-0.5, x, 0.5\right)}\right)\right), 2, t\_3\right)}
\end{array}
\end{array}
Initial program 6.0%
Applied rewrites6.1%
rem-cbrt-cubeN/A
lower-cbrt.f64N/A
lower-pow.f647.6
Applied rewrites7.6%
lift-asin.f64N/A
asin-acosN/A
lift-fma.f64N/A
*-commutativeN/A
lift-fma.f64N/A
lift-acos.f64N/A
lift-PI.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
sub-negN/A
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites7.6%
lift-asin.f64N/A
asin-acosN/A
lift-acos.f64N/A
unsub-negN/A
lift-acos.f64N/A
lift-sqrt.f64N/A
lift-fma.f64N/A
lift-PI.f64N/A
clear-numN/A
associate-/r/N/A
metadata-evalN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
Applied rewrites7.6%
Final simplification7.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (* 0.5 (PI)))
(t_1 (asin (sqrt (fma x -0.5 0.5))))
(t_2 (fma t_1 2.0 t_0))
(t_3 (cbrt (PI))))
(/
(-
(* (* (* (cbrt (* (* (PI) (PI)) (PI))) (PI)) 0.25) t_2)
(* (* 4.0 (pow t_1 2.0)) t_2))
(*
(fma
(fma (pow t_3 2.0) (* t_3 0.5) (- (acos (sqrt (fma -0.5 x 0.5)))))
2.0
t_0)
t_2))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \mathsf{PI}\left(\right)\\
t_1 := \sin^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right)\\
t_2 := \mathsf{fma}\left(t\_1, 2, t\_0\right)\\
t_3 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
\frac{\left(\left(\sqrt[3]{\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)} \cdot \mathsf{PI}\left(\right)\right) \cdot 0.25\right) \cdot t\_2 - \left(4 \cdot {t\_1}^{2}\right) \cdot t\_2}{\mathsf{fma}\left(\mathsf{fma}\left({t\_3}^{2}, t\_3 \cdot 0.5, -\cos^{-1} \left(\sqrt{\mathsf{fma}\left(-0.5, x, 0.5\right)}\right)\right), 2, t\_0\right) \cdot t\_2}
\end{array}
\end{array}
Initial program 6.0%
Applied rewrites6.1%
rem-cbrt-cubeN/A
lower-cbrt.f64N/A
lower-pow.f647.6
Applied rewrites7.6%
lift-asin.f64N/A
asin-acosN/A
lift-fma.f64N/A
*-commutativeN/A
lift-fma.f64N/A
lift-acos.f64N/A
lift-PI.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
sub-negN/A
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites7.6%
lift-pow.f64N/A
unpow3N/A
lift-*.f64N/A
lower-*.f647.6
Applied rewrites7.6%
Final simplification7.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (sqrt (fma x -0.5 0.5)))) (t_1 (fma t_0 2.0 (* 0.5 (PI)))))
(/
(-
(* t_1 (* (* (cbrt (pow (PI) 3.0)) (PI)) 0.25))
(* (* 4.0 (pow t_0 2.0)) t_1))
(* t_1 t_1))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right)\\
t_1 := \mathsf{fma}\left(t\_0, 2, 0.5 \cdot \mathsf{PI}\left(\right)\right)\\
\frac{t\_1 \cdot \left(\left(\sqrt[3]{{\mathsf{PI}\left(\right)}^{3}} \cdot \mathsf{PI}\left(\right)\right) \cdot 0.25\right) - \left(4 \cdot {t\_0}^{2}\right) \cdot t\_1}{t\_1 \cdot t\_1}
\end{array}
\end{array}
Initial program 6.0%
Applied rewrites6.1%
rem-cbrt-cubeN/A
lower-cbrt.f64N/A
lower-pow.f647.6
Applied rewrites7.6%
Final simplification7.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (fma (asin (sqrt (fma x -0.5 0.5))) 2.0 (* 0.5 (PI)))))
(fma
(PI)
(/ (* (PI) 0.25) t_0)
(*
(/ (- 4.0) t_0)
(pow (fma (PI) 0.5 (- (acos (sqrt (fma -0.5 x 0.5))))) 2.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right), 2, 0.5 \cdot \mathsf{PI}\left(\right)\right)\\
\mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{\mathsf{PI}\left(\right) \cdot 0.25}{t\_0}, \frac{-4}{t\_0} \cdot {\left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.5, -\cos^{-1} \left(\sqrt{\mathsf{fma}\left(-0.5, x, 0.5\right)}\right)\right)\right)}^{2}\right)
\end{array}
\end{array}
Initial program 6.0%
Applied rewrites6.0%
lift-asin.f64N/A
asin-acosN/A
lift-PI.f64N/A
lift-/.f64N/A
lift-acos.f64N/A
unsub-negN/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lift-neg.f64N/A
lift-fma.f647.6
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f647.6
Applied rewrites7.6%
Final simplification7.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (acos (sqrt (fma x -0.5 0.5)))))
(/
(- (* (* (PI) (PI)) 0.25) (* (pow t_0 2.0) 4.0))
(fma -0.5 (PI) (* -2.0 t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right)\\
\frac{\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 0.25 - {t\_0}^{2} \cdot 4}{\mathsf{fma}\left(-0.5, \mathsf{PI}\left(\right), -2 \cdot t\_0\right)}
\end{array}
\end{array}
Initial program 6.0%
lift-asin.f64N/A
asin-acosN/A
lift-PI.f64N/A
lift-/.f64N/A
sub-negN/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-acos.f647.5
lift-/.f64N/A
lift--.f64N/A
div-subN/A
metadata-evalN/A
sub-negN/A
+-commutativeN/A
div-invN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
Applied rewrites7.5%
Taylor expanded in x around 0
cancel-sign-sub-invN/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
cancel-sign-sub-invN/A
distribute-lft-inN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
neg-mul-1N/A
distribute-lft-neg-inN/A
metadata-evalN/A
Applied rewrites7.5%
Applied rewrites7.5%
(FPCore (x) :precision binary64 (fma -0.5 (PI) (* (acos (sqrt (fma x -0.5 0.5))) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(-0.5, \mathsf{PI}\left(\right), \cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right) \cdot 2\right)
\end{array}
Initial program 6.0%
lift-asin.f64N/A
asin-acosN/A
lift-PI.f64N/A
lift-/.f64N/A
sub-negN/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-acos.f647.5
lift-/.f64N/A
lift--.f64N/A
div-subN/A
metadata-evalN/A
sub-negN/A
+-commutativeN/A
div-invN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
Applied rewrites7.5%
Taylor expanded in x around 0
cancel-sign-sub-invN/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
cancel-sign-sub-invN/A
distribute-lft-inN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
neg-mul-1N/A
distribute-lft-neg-inN/A
metadata-evalN/A
Applied rewrites7.5%
(FPCore (x) :precision binary64 (fma -0.5 (PI) (* (acos (sqrt 0.5)) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(-0.5, \mathsf{PI}\left(\right), \cos^{-1} \left(\sqrt{0.5}\right) \cdot 2\right)
\end{array}
Initial program 6.0%
lift-asin.f64N/A
asin-acosN/A
lift-PI.f64N/A
lift-/.f64N/A
sub-negN/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-acos.f647.5
lift-/.f64N/A
lift--.f64N/A
div-subN/A
metadata-evalN/A
sub-negN/A
+-commutativeN/A
div-invN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
Applied rewrites7.5%
Taylor expanded in x around 0
cancel-sign-sub-invN/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
cancel-sign-sub-invN/A
distribute-lft-inN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
neg-mul-1N/A
distribute-lft-neg-inN/A
metadata-evalN/A
Applied rewrites7.5%
Taylor expanded in x around 0
Applied rewrites5.4%
(FPCore (x) :precision binary64 (asin x))
double code(double x) {
return asin(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = asin(x)
end function
public static double code(double x) {
return Math.asin(x);
}
def code(x): return math.asin(x)
function code(x) return asin(x) end
function tmp = code(x) tmp = asin(x); end
code[x_] := N[ArcSin[x], $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} x
\end{array}
herbie shell --seed 2024268
(FPCore (x)
:name "Ian Simplification"
:precision binary64
:alt
(! :herbie-platform default (asin x))
(- (/ (PI) 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))