
(FPCore (g h) :precision binary64 (* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))
\begin{array}{l}
\\
2 \cdot \cos \left(\frac{2 \cdot \mathsf{PI}\left(\right)}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (g h) :precision binary64 (* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))
\begin{array}{l}
\\
2 \cdot \cos \left(\frac{2 \cdot \mathsf{PI}\left(\right)}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)
\end{array}
(FPCore (g h)
:precision binary64
(let* ((t_0 (sin (* 0.6666666666666666 (PI))))
(t_1 (sqrt (PI)))
(t_2 (/ (- g) h))
(t_3 (acos t_2))
(t_4 (sin (* 0.3333333333333333 t_3)))
(t_5 (* t_0 t_4))
(t_6
(*
(cos (* -0.6666666666666666 (PI)))
(cos (* t_3 -0.3333333333333333))))
(t_7 (pow t_6 2.0)))
(*
(-
(/
(pow t_6 3.0)
(+
(*
(fma
(sin (* (fma t_1 (/ t_1 2.0) (- (asin t_2))) 0.3333333333333333))
t_0
t_6)
t_5)
t_7))
(/ (pow t_5 3.0) (+ (* (fma t_4 t_0 t_6) t_5) t_7)))
2.0)))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.6666666666666666 \cdot \mathsf{PI}\left(\right)\right)\\
t_1 := \sqrt{\mathsf{PI}\left(\right)}\\
t_2 := \frac{-g}{h}\\
t_3 := \cos^{-1} t\_2\\
t_4 := \sin \left(0.3333333333333333 \cdot t\_3\right)\\
t_5 := t\_0 \cdot t\_4\\
t_6 := \cos \left(-0.6666666666666666 \cdot \mathsf{PI}\left(\right)\right) \cdot \cos \left(t\_3 \cdot -0.3333333333333333\right)\\
t_7 := {t\_6}^{2}\\
\left(\frac{{t\_6}^{3}}{\mathsf{fma}\left(\sin \left(\mathsf{fma}\left(t\_1, \frac{t\_1}{2}, -\sin^{-1} t\_2\right) \cdot 0.3333333333333333\right), t\_0, t\_6\right) \cdot t\_5 + t\_7} - \frac{{t\_5}^{3}}{\mathsf{fma}\left(t\_4, t\_0, t\_6\right) \cdot t\_5 + t\_7}\right) \cdot 2
\end{array}
\end{array}
Initial program 98.5%
Applied rewrites97.5%
lift-acos.f64N/A
acos-asinN/A
sub-negN/A
add-sqr-sqrtN/A
associate-/l*N/A
lower-fma.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-asin.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (g h)
:precision binary64
(let* ((t_0 (* 0.6666666666666666 (PI)))
(t_1 (acos (/ (- g) h)))
(t_2 (* -0.6666666666666666 (PI))))
(*
(-
(cos (fma 0.3333333333333333 t_1 t_2))
(cos (fma 0.3333333333333333 t_1 t_0)))
(fma
(/ 0.5 (sin t_0))
(/
(+
(cos (fma t_1 0.3333333333333333 t_2))
(cos (fma t_1 0.3333333333333333 t_0)))
(sin (* 0.3333333333333333 t_1)))
-1.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.6666666666666666 \cdot \mathsf{PI}\left(\right)\\
t_1 := \cos^{-1} \left(\frac{-g}{h}\right)\\
t_2 := -0.6666666666666666 \cdot \mathsf{PI}\left(\right)\\
\left(\cos \left(\mathsf{fma}\left(0.3333333333333333, t\_1, t\_2\right)\right) - \cos \left(\mathsf{fma}\left(0.3333333333333333, t\_1, t\_0\right)\right)\right) \cdot \mathsf{fma}\left(\frac{0.5}{\sin t\_0}, \frac{\cos \left(\mathsf{fma}\left(t\_1, 0.3333333333333333, t\_2\right)\right) + \cos \left(\mathsf{fma}\left(t\_1, 0.3333333333333333, t\_0\right)\right)}{\sin \left(0.3333333333333333 \cdot t\_1\right)}, -1\right)
\end{array}
\end{array}
Initial program 98.5%
lift-+.f64N/A
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
metadata-evalN/A
metadata-eval98.5
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval98.5
Applied rewrites98.5%
Applied rewrites98.5%
Applied rewrites99.9%
Taylor expanded in g around 0
Applied rewrites99.9%
Final simplification99.9%
(FPCore (g h) :precision binary64 (* (cos (* (* 0.2222222222222222 (PI)) (fma (/ 1.5 (PI)) (acos (/ (- g) h)) 3.0))) 2.0))
\begin{array}{l}
\\
\cos \left(\left(0.2222222222222222 \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{fma}\left(\frac{1.5}{\mathsf{PI}\left(\right)}, \cos^{-1} \left(\frac{-g}{h}\right), 3\right)\right) \cdot 2
\end{array}
Initial program 98.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-/.f64N/A
clear-numN/A
frac-addN/A
lower-/.f64N/A
metadata-evalN/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
metadata-evalN/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
metadata-eval98.5
Applied rewrites98.5%
lift-/.f64N/A
div-invN/A
lower-*.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-/r/N/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval98.5
Applied rewrites98.5%
Final simplification98.5%
(FPCore (g h) :precision binary64 (* (cos (fma (PI) 0.6666666666666666 (* 0.3333333333333333 (acos (/ (- g) h))))) 2.0))
\begin{array}{l}
\\
\cos \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.6666666666666666, 0.3333333333333333 \cdot \cos^{-1} \left(\frac{-g}{h}\right)\right)\right) \cdot 2
\end{array}
Initial program 98.5%
lift-+.f64N/A
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
metadata-evalN/A
metadata-eval98.5
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval98.5
Applied rewrites98.5%
Final simplification98.5%
herbie shell --seed 2024297
(FPCore (g h)
:name "2-ancestry mixing, negative discriminant"
:precision binary64
(* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))